From 114998984acd8178774ca081f333733a873c2c79 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Mon, 18 Sep 2017 15:06:13 +0100 Subject: [PATCH] Emacs: Replace scratch message with a fortune --- .emacs.d/lisp/functions.el | 16 ++++++++++++++++ .emacs.d/lisp/main.el | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/.emacs.d/lisp/functions.el b/.emacs.d/lisp/functions.el index c6dd4fc6..078f8149 100644 --- a/.emacs.d/lisp/functions.el +++ b/.emacs.d/lisp/functions.el @@ -144,6 +144,22 @@ Work on buffer or region. Require `tabify-leading'." (whitespace-mode 'toggle)) (global-set-key (kbd "") 'flyspell-and-whitespace-mode) +;;; From https://www.reddit.com/r/emacs/comments/70bn7v/what_do_you_have_emacs_show_when_it_starts_up/. +;;; Supply a random fortune cookie as the *scratch* message. +(defun fortune-scratch-message () + (interactive) + (let ((fortune + (when (executable-find "fortune") + (with-temp-buffer + (shell-command "fortune" t) + (let ((comment-start ";;")) + (comment-region (point-min) (point-max))) + (delete-trailing-whitespace (point-min) (point-max)) + (concat (buffer-string) "\n"))))) + (if (called-interactively-p 'any) + (insert fortune) + fortune))) + (defun global-set-keys (key def &rest bindings) "Like `global-set-key' but allow for defining several bindings at once. `KEY' must be acceptable for `kbd'." diff --git a/.emacs.d/lisp/main.el b/.emacs.d/lisp/main.el index 2627e735..d1d03256 100644 --- a/.emacs.d/lisp/main.el +++ b/.emacs.d/lisp/main.el @@ -346,4 +346,10 @@ ;;; Frame title (setq frame-title-format (concat "%b" (unless (daemonp) " [serverless]"))) +;; Initial scratch buffer message. +(require 'functions) ; For `fortune-scratch-message'. +(let ((fortune (fortune-scratch-message))) + (when fortune + (setq initial-scratch-message fortune))) + (provide 'main)