Loading ...
Sorry, an error occurred while loading the content.

Re: [OT]Bram fortune file. Know your smileys.

Expand Messages
  • A.J.Mechelynck
    ... Here s a variation on Bram s fortunes.vim script for use when not using Vim to write mail: I wrote this into my vimrc and checked that it works: if
    Message 1 of 2 , Feb 5, 2007
      Kazuo Teramoto wrote:
      > Hi,
      > I love the Bram fortune file (I read it all, is fun) but now looks it
      > be updated (with From "know your smileys" and jokes about proofs...)
      > but it is not updated in Bram site, anyone know from are Bram take the
      > 'know your smileys'?
      > Bye.
      > PS. I love the vim list, really, I read it for fun, I don't post so
      > much but I think we have one of the best ml or better one of the best
      > user community.

      Here's a variation on Bram's "fortunes.vim" script for use when not using Vim
      to write mail: I wrote this into my vimrc and checked that it works:

      if has("autocmd")
      augroup vimrclocal
      " move first fortune (with initial sig delimiter)
      " to the bottom and the clipboard
      au BufRead fortunes.txt
      \ map <buffer> <F5>
      \ :1;/^-- $/-1d +
      \ <Bar>$put +
      \ <Bar>w
      \ <CR>
      augroup END

      This is not perfect: you may want to create a more complex mapping to insert
      your fixed sig after the "-- " line after moving the fortune. The above requires:

      1. modification of the fortunes.txt file (as follows) to use "proper" sig
      delimiters as separators:

      :1,$s/^--$/-- /

      This adds 529 (decimal) bytes to the file, which I think is acceptable.

      2. a Vim version with access to the clipboard (i.e., any version of gvim, or a
      console Vim compiled with clipboard support and running in a terminal with
      access to the clipboard). This should also be a Vim version 6.1 or later, and
      preferably 6.1.092 or later, because of the ":map <buffer>" command. ;-)

      To use it, open fortunes.txt in Vim, hit F5, then go to your mailer, place the
      cursor on an empty line after last line, and paste. You may then add the fixed
      part of your sig below the delimiter. (Of course, replace <F5> by another key
      to map it to something else.)

      Note: I just found that on Linux systems such as mine, the "fortune" shell
      command will deliver random aphorisms. Use "fortune -f" to list fortune files,
      "fortune" for a random non-offensive fortune, "man fortune" for details.
      However I don't know how to add a database (a pair of files, "something" in
      text format and "something.dat" in binary format) to the list. I think I'll
      write a function to get fortunes from both Bram's and the Linux lists.

      ... Done (I think I put the necessary safeguards into it to make it portable).
      Two status variables are remembered across Vim runs if the viminfo is enabled.
      Two more varaiables are initialized at first call. With the settings below,
      Bram's fortunes will happen 20% of the time (on Unix when both ~/fortunes.txt
      and the fortune program are present). Change g:FortuneCycle to alter that.
      Each call to the function Fortune() returns a new fortune both as the return
      value and in the clipboard, except when neither source of aphorisms is
      installed, in which case it returns the empty string.
      -- Replace ":echo" by ":call" in the mapping to avoid displaying the fortune
      in Vim.

      if has("viminfo") && (&viminfo != "")
      " append at left end because the viminfo name (if present)
      " must be last
      set viminfo-=!
      set viminfo^=!
      function Fortune()
      " In order to remember them in the viminfo,
      " the first two variables defined below
      " must have names starting with an uppercase letter
      " and containing no lowercase letters.
      if !exists("g:FORTUNE")
      let g:FORTUNE = 0
      if !exists("g:FORTUNECYCLE")
      let g:FORTUNECYCLE = 5
      if !exists("s:sysFortunes")
      let s:sysFortunes =
      \ (system("which fortune") != "") && (!v:shell_error)
      if !exists("s:bramFortunes")
      let s:bramFortunes =
      \ filereadeable(expand("~/fortunes.txt"))
      if s:sysFortunes && (g:FORTUNE || (!s:bramFortunes))
      let @+ = "-- \n" . system("fortune -a")
      elseif s:bramFortunes
      new ~/fortunes.txt
      silent 1;/^-- $/-1d +
      $put +
      let @+ = ""
      let g:FORTUNE = g:FORTUNE + 1
      let g:FORTUNE = 0
      return @+
      map <F5> :echo Fortune()<CR>

      Best regards,

      Too clever is dumb.
      -- Ogden Nash
    Your message has been successfully submitted and would be delivered to recipients shortly.