Skip to content

Instantly share code, notes, and snippets.

@edcrypt
Last active December 11, 2015 16:10
Show Gist options
  • Save edcrypt/077dcd917a522dff969e to your computer and use it in GitHub Desktop.
Save edcrypt/077dcd917a522dff969e to your computer and use it in GitHub Desktop.
Display a fortune, with commented lines, on the scratch buffer
;; Fortune on scratch buffer
;; Add this to your ~/.emacs.d/init.el
(require 'fortune)
(setq fortune-dir "/usr/local/Cellar/fortune/9708/share/games/fortunes/")
(setq fortune-file "/usr/local/Cellar/fortune/9708/share/games/fortunes/")
(setq fortune-program "/usr/local/bin/fortune")
;; next two funcs from http://datko.net/2013/07/08/slight-enhancement-to-fortune-el/
(defun fortune-message (&optional file)
"Display a fortune cookie to the mini-buffer.
If called with a prefix, it has the same behavior as `fortune'.
Optional FILE is a fortune file from which a cookie will be selected."
(interactive (list (if current-prefix-arg
(fortune-ask-file)
fortune-file)))
(message (fortune-generate)))
(defun fortune-generate (&optional file)
"Generate a new fortune and return it as a string.
Without an optional FILE argument it will use the value of `fortune-file'."
(save-excursion
(progn (fortune-in-buffer t file)
(with-current-buffer fortune-buffer-name
(buffer-string)))))
(defun fortune-lisp-comments (&optional file)
(concat (mapconcat (function (lambda (x) (concat ";; " x)))
(delete "" (split-string (fortune-generate file) "\n"))
"\n")
"\n"
))
(setq initial-scratch-message (fortune-lisp-comments))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment