SiteMap / AllPages / Out

FortuneCookieFunction

Start your Emacs session with one of the many FortuneCookies installed on your system. Usually that requires the fortune(6) program.

TheOneAndOnly editor should come with a cookie1.el file, however, which emulates the fortune(6) program. The following defun, however, uses the fortune program. The fortune cookie file is one of my own. See FortuneCookies for more.

Put this at the end of your ~/.emacs file. When you start, and everytime you run M-x shakespeare-romeo-and-juliet, you'll get a quote.

    ;; insert random Romeo and Juliet quote
    (defun shakespeare-romeo-and-juliet (&optional here)
      "Display a quote from Romeo And Juliet.
    With optional argument HERE, insert quote in current buffer."
      (interactive "P")
      (let ((buf (or here 
                     (set-buffer (get-buffer-create "*Fortune*")))))
        (setq buffer-read-only nil)
        (unless here
          (widen)
          (erase-buffer)
          (if (not (featurep 'xemacs))
              (view-buffer buf 'kill-buffer)
            (switch-to-buffer buf)
            (view-mode (get-buffer "*scratch*") 'kill-buffer))
          (delete-other-windows))
        (shell-command "fortune /usr/share/fortune/rj" buf)))
    (shakespeare-romeo-and-juliet)

Instead of using shell-command to insert the quote, you can also use the cookie function. Change

    (shell-command "fortune /usr/share/fortune/rj" buf)

to

    (insert (cookie "/usr/share/fortune/rj" 
                    "Cookie..."
                    "Cookie...done"))

SiteMap / AllPages / Out / kensanata@gmail.com / Last change: 2001-04-22