Alex Ragone

quotes.el

<2019-05-26 Sun>

My initial buffer displays a random quote from a list of programming/CS quotes. The complete list of quotes can be found here.

quote.png
(defvar ragone-quotes-file "~/.doom.d/quotes.txt"
  "File to lookup quotes.")

(defvar ragone-quotes-file-seperator-regex "\n%\n"
  "Delimiter for seperating the line in `ragone-quotes-file'.")

(defvar ragone-quotes-author-regex "^--"
  "Regex for getting the author of the quote.

Anything after this will be changed to face `font-lock-comment-face'.")

(defun ragone-get-quote (&optional nth)
  "Get a random quote from `ragone-quotes-file'.

Optionally get the NTH quote."
  (let* ((quotes (split-string
                  (with-temp-buffer
                    (insert-file-contents ragone-quotes-file)
                    (buffer-substring-no-properties
                     (point-min)
                     (point-max)))
                  ragone-quotes-file-seperator-regex t))
         (selected-quote (nth (or nth
                                  (random (length quotes)))
                              quotes)))
    (put-text-property
     (string-match ragone-quotes-author-regex selected-quote)
     (length selected-quote)
     'face
     'font-lock-comment-face
     selected-quote)
    selected-quote))

;; Update your scratch buffer
(setq initial-scratch-message (ragone-get-quote))
archive tags