One way to go with it is to use the vim syntax highlighting mechanisms to do that. The first thing to do is to add
set filetype=cowfortune to your function:
for line in split(system('ls -l'), '\n')
call append('$', ' ' . l:line)
setlocal nomodifiable nomodified
This way the buffer you are creating with your message has a defined filetype
cowfortune. Now you can create the file
$HOME/.vim/after/syntax/cowfortune.vim which will contain the syntax instructions to be used in this buffer.
A very basic version of this file could be something like this:
" Guard to avoid loading the syntax file several times
let b:current_syntax = "potion"
" Match all the existing text
syntax match cowText ".*"
" And highlight it as an error
highlight link cowText Error
What it does is create a syntax group named
cowText and say that everything in the file should be attributed to this group (
Then it creates a link to say that the group
cowText should be shown like the group
With this code everything in your buffer will be highlighted in red (or however your colorscheme renders
Error). Now these are some building block, you will need to change the match to apply your new group only to the message you want (I don't remember what
cowfortune looks like but I think the message is displayed between
| chars so maybe something like
|\zs.*\ze|) and maybe you'll also want to create your own highlighting group.
To learn how to do all of that the help
:h syntax is a very good place to start and learnvimscriptthehard way has some very good material too.