Download
(defvar seinquote-window-old-config nil
"Window configuration before starting seinquote.")
(make-variable-frame-local 'seinquote-window-old-config)
(defvar seinquote-mode-font-lock
(list
'("^\\( -.*\\)$" 1 font-lock-constant-face))
"Default font lock expressions.")
(defvar seinquote-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "q" 'seinquote-kill)
(define-key map "r" 'seinquote-display-quote)
map)
"Keymap of `seinquote-mode'.")
(defun seinquote-restore-window-config()
"Restore window configuration on the current frame."
(when seinquote-window-old-config
(set-window-configuration seinquote-window-old-config)
(setq seinquote-window-old-config nil)))
(defun seinquote-kill()
"Bury buffer and return window's order to its old state."
(interactive)
(bury-buffer (current-buffer))
(seinquote-restore-window-config))
(defun seinquote-mode()
(interactive)
(kill-all-local-variables)
(use-local-map seinquote-mode-map)
(setq major-mode 'seinqoute-mode
mode-name "SeinQuote"
buffer-read-only t
font-lock-defaults '(seinquote-mode-font-lock t))
(run-mode-hooks 'seinquote-mode-hook))
(defun seinquote-get-random-quote()
"Load the file and return a random quote from it."
(with-temp-buffer
(insert-file-contents "seinquotes.txt")
(goto-char (point-min))
(setq n (random 1399))
(while (> n 0)
(setq n (- n 1))
(search-forward "---"))
(next-line)
(setq q-begin (line-beginning-position))
(search-forward "---")
(previous-line)
(setq q-end (line-end-position))
(setq quote (buffer-substring q-begin q-end))))
(defun seinquote-display-quote()
"Display the random quote in the current buffer."
(interactive)
(let* ((inhibit-read-only t))
(erase-buffer)
(insert (seinquote-get-random-quote))
(fit-window-to-buffer)))
(defun seinquote()
(interactive)
(unless (string= "*Seinfeld Quote*" (buffer-name))
(setq seinquote-window-old-config (current-window-configuration))
(split-window-vertically)
(other-window 1)
(switch-to-buffer (get-buffer-create "*Seinfeld Quote*"))
(seinquote-mode)
(seinquote-display-quote)))
(provide 'seinquote)