From 904bad6fd25c5f13cc06df1370c66372cc8dc0e2 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sat, 23 May 2015 21:15:44 -0400 Subject: emacs: Overhaul configuration. --- dotfiles/.emacs.d/erc.el | 2 - dotfiles/.emacs.d/init.el | 285 +++++++++++++++++++++++----------------------- 2 files changed, 145 insertions(+), 142 deletions(-) diff --git a/dotfiles/.emacs.d/erc.el b/dotfiles/.emacs.d/erc.el index 3709f55..2ccf963 100644 --- a/dotfiles/.emacs.d/erc.el +++ b/dotfiles/.emacs.d/erc.el @@ -86,8 +86,6 @@ (erc-services-mode t) (setq erc-prompt-for-nickserv-password nil) (setq erc-nickserv-identify-mode 'autodetect) -(setq erc-nickserv-passwords - `((Rizon (("davexunit" . ,rizon-password))))) ;; Start and stop erc (defun start-irc () diff --git a/dotfiles/.emacs.d/init.el b/dotfiles/.emacs.d/init.el index bdfcd9c..8dde4b8 100644 --- a/dotfiles/.emacs.d/init.el +++ b/dotfiles/.emacs.d/init.el @@ -6,15 +6,6 @@ ;; No splash screen. (setq inhibit-startup-message t) -;; Use /bin/sh for shell. -;; -;; I like to use fish shell as my login shell, but there are -;; incompatibilities with its scripting language. -(setq shell-file-name "/bin/bash") - -;; Use screen in ansi-term and co. -(setq explicit-shell-file-name "/usr/bin/screen") - ;;; ;;; Packages ;;; @@ -39,9 +30,7 @@ rainbow-delimiters smex web-mode - flx-ido - projectile - notmuch-unread)) + projectile)) (defun install-missing-packages () "Install all required packages that haven't been installed." @@ -52,11 +41,22 @@ required-packages) (message "Installed all missing packages!")) +(defmacro when-require (package &rest body) + "Evaluate BODY if and only if PACKAGE can be imported." + (declare (indent 1)) + `(when (require ,package nil t) ,@body)) + ;;; ;;; Look and Feel ;;; -(set-default-font "Inconsolata-11") +(defun font-exists-p (font) + "Return 't' if FONT exists." + (not (null (x-list-fonts font)))) + +(when (font-exists-p "Inconsolata") + (set-default-font "Inconsolata-11")) + (load-theme 'wombat t) (column-number-mode t) (which-function-mode t) @@ -100,17 +100,14 @@ (setq ido-everywhere t) (setq ido-enable-flex-matching t) (ido-mode t) -(ido-ubiquitous-mode t) -(flx-ido-mode t) +(when-require 'ido-ubiquitous + (ido-ubiquitous-mode t)) ;; Ignore compiled Guile files. This has the side-effect of looking ;; like I hate GoLang. (setq ido-ignore-files (cons "\\.go$" ido-ignore-files)) -(projectile-global-mode) - -;; Remember open buffers for next session. -(desktop-save-mode t) +(when-require 'projectile (projectile-global-mode)) ;; Kill buffers that haven't been modified in awhile. (require 'midnight) @@ -131,9 +128,6 @@ might be bad." ;; Various superfluous white-space. Just say no. (add-hook 'before-save-hook 'cleanup-buffer-safe) -;; Snippets. -(auto-insert-mode t) - (setq ibuffer-saved-filter-groups '(("default" ("guile-2d" (filename . "Code/guile-2d/")) @@ -150,27 +144,30 @@ might be bad." ;;; (setq-default indent-tabs-mode nil) -(setq indent-tabs-mode nil) -(setq tab-width 2) +(setf indent-tabs-mode nil + tab-width 2 + require-final-newline t) (electric-indent-mode t) -(setq require-final-newline t) ;;; ;;; Version Control ;;; -;; I don't like magit's default local tracking branch naming strategy. -(setq magit-default-tracking-name-function - 'magit-default-tracking-name-branch-only) +(when-require 'magit + ;; I don't like magit's default local tracking branch naming strategy. + (setf magit-default-tracking-name-function + 'magit-default-tracking-name-branch-only) + (setf magit-last-seen-setup-instructions "1.4.0") + + (global-set-key (kbd "C-c g") 'magit-status)) ;;; ;;; Ediff ;;; ;; Don't break out a separate frame for ediff. -(setq ediff-window-setup-function 'ediff-setup-windows-plain) - -(setq ediff-split-window-function 'split-window-horizontally) +(setf ediff-window-setup-function 'ediff-setup-windows-plain + ediff-split-window-function 'split-window-horizontally) ;;; ;;; C @@ -184,22 +181,24 @@ might be bad." ;;; Javascript ;;; -(setq js-indent-level 2) -(setq js2-basic-offset 2) -(add-to-list 'auto-mode-alist '("\\.js$" . js2-mode)) +(setf js-indent-level 2 + js2-basic-offset 2) +(when-require 'js2-mode + (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))) ;;; ;;; Web ;;; -(add-to-list 'auto-mode-alist '("\\.html$" . web-mode)) -(add-to-list 'auto-mode-alist '("\\.tpl$" . web-mode)) +(when-require 'web-mode + (add-to-list 'auto-mode-alist '("\\.html$" . web-mode)) + (add-to-list 'auto-mode-alist '("\\.tpl$" . web-mode))) ;;; ;;; PHP ;;; -(add-hook 'php-mode-hook (lambda () (setq c-basic-offset 2))) +(add-hook 'php-mode-hook (lambda () (setf c-basic-offset 2))) ;;; ;;; Lisp @@ -207,16 +206,26 @@ might be bad." ;; Highlight matching parens, automatically insert pairs, use rainbow ;; delimiters and use paredit for Lisp buffers. -(require 'rainbow-delimiters) -(require 'paredit) -(global-rainbow-delimiters-mode t) +(when-require 'rainbow-delimiters + (global-rainbow-delimiters-mode t)) + +(when-require 'paredit + (add-hook 'emacs-lisp-mode-hook (lambda () (paredit-mode t))) + (add-hook 'lisp-mode-hook (lambda () (paredit-mode t))) + (add-hook 'lisp-interaction-mode-hook (lambda () (paredit-mode t))) + (add-hook 'scheme-mode-hook (lambda () (paredit-mode t)))) + (show-paren-mode t) -(add-hook 'emacs-lisp-mode-hook (lambda () (paredit-mode t))) -(add-hook 'lisp-mode-hook (lambda () (paredit-mode t))) -(add-hook 'lisp-interaction-mode-hook (lambda () (paredit-mode t))) -(add-hook 'scheme-mode-hook (lambda () (paredit-mode t))) -(setq geiser-active-implementations '(guile)) +(when-require 'geiser + (setf geiser-active-implementations '(guile)) + + (global-set-key (kbd "C-c s") 'connect-to-guile)) + +(defun connect-to-guile-wm () + "Connect to guile-wm's REPL server." + (interactive) + (geiser-connect 'guile "localhost" "37147")) (put 'and-let* 'scheme-indent-function 1) (put 'syntax-parameterize 'scheme-indent-function 1) @@ -251,11 +260,6 @@ might be bad." (put 'call-with-port-or-input-file 'scheme-indent-function 1) (put 'call-with-port-or-output-file 'scheme-indent-function 1) -(defun connect-to-guile-wm () - "Connect to guile-wm's REPL server." - (interactive) - (geiser-connect 'guile "localhost" "37147")) - ;;; ;;; Ruby ;;; @@ -268,7 +272,8 @@ might be bad." (add-to-list 'auto-mode-alist '("Gemfile$" . ruby-mode)) ;; Use ruby-test-mode -(add-hook 'ruby-mode-hook 'ruby-test-mode) +(when-require 'ruby-test-mode + (add-hook 'ruby-mode-hook 'ruby-test-mode)) ;;; ;;; SQL @@ -283,111 +288,119 @@ might be bad." ;;; RSS ;;; -(setq elfeed-feeds - '("http://planet.gnu.org/rss20.xml" - "http://cs.worcester.edu/blog/feed/" - "https://hacks.mozilla.org/feed/" - "http://ebb.org/bkuhn/blog/rss.xml")) +(when-require 'elfeed + (setf elfeed-feeds + '("http://planet.gnu.org/rss20.xml" + "http://cs.worcester.edu/blog/feed/" + "https://hacks.mozilla.org/feed/" + "http://ebb.org/bkuhn/blog/rss.xml")) + + (global-set-key (kbd "C-c f") 'elfeed)) ;;; ;;; GPG ;;; - d + (setf epg-gpg-program "gpg2") ;;; ;;; Mail ;;; -(require 'notmuch) -(require 'notmuch-unread) +(when-require 'notmuch + (when-require 'notmuch-unread + (notmuch-unread-mode 1)) + + (global-set-key (kbd "C-c m") 'notmuch) + + (setf notmuch-fcc-dirs + '(("dthompson2@worcester.edu" . "WSU/Sent") + ("davet@fsf.org" . "FSF/INBOX.Sent") + ("davet@gnu.org" . "FSF/INBOX.Sent") + (".*" . "sent"))) + (setf notmuch-saved-searches + '((:name "unread" :query "tag:unread") + (:name "inbox" :query "tag:inbox") + (:name "important" :query "tag:important") + (:name "fsfsys" :query "tag:fsfsys"))) + + (define-key notmuch-search-mode-map "u" + (lambda () + "Remove 'unread' tag from message." + (interactive) + (notmuch-search-tag '("-unread")) + (notmuch-search-next-thread))) + + (define-key notmuch-search-mode-map "a" + (lambda () + "Remove 'unread' and 'inbox' tags from message." + (interactive) + (notmuch-search-tag '("-unread" "-inbox")) + (notmuch-search-next-thread))) + + (define-key notmuch-search-mode-map "d" + (lambda () + "Add 'deleted' tag to message." + (interactive) + (notmuch-search-tag '("+deleted")) + (notmuch-search-next-thread))) + + (define-key notmuch-search-mode-map "i" + (lambda () + "Remove 'unread' and 'inbox' tags from message, and add the +'important' tag." + (interactive) + (notmuch-search-tag '("-unread" "-inbox" "+important")) + (notmuch-search-next-thread))) + + (define-key notmuch-search-mode-map "s" + (lambda () + "Remove 'unread' and 'inbox' tags from message, and add the +'spam' tag." + (interactive) + (notmuch-search-tag '("-unread" "-inbox" "+spam")) + (notmuch-search-next-thread)))) -(notmuch-unread-mode 1) +(setf send-mail-function 'smtpmail-send-it + smtpmail-smtp-server "mail.fsf.org" + smtpmail-smtp-service 587 + smtpmail-stream-type 'starttls) -(setq notmuch-fcc-dirs - '(("dthompson2@worcester.edu" . "WSU/Sent") - ("davet@fsf.org" . "FSF/INBOX.Sent") - ("davet@gnu.org" . "FSF/INBOX.Sent") - (".*" . "sent"))) -(setq send-mail-function 'smtpmail-send-it) -(setq smtpmail-smtp-server "mail.fsf.org") -(setq smtpmail-smtp-service 587) -(setq smtpmail-stream-type 'starttls) ;; (setq smtpmail-smtp-server "smtp.gmail.com") ;; (setq smtpmail-smtp-service 465) ;; (setq smtpmail-stream-type 'ssl) -(setq notmuch-saved-searches - '((:name "unread" :query "tag:unread") - (:name "inbox" :query "tag:inbox") - (:name "important" :query "tag:important") - (:name "fsfsys" :query "tag:fsfsys"))) - -(define-key notmuch-search-mode-map "u" - (lambda () - "Remove 'unread' tag from message." - (interactive) - (notmuch-search-tag '("-unread")) - (notmuch-search-next-thread))) - -(define-key notmuch-search-mode-map "a" - (lambda () - "Remove 'unread' and 'inbox' tags from message." - (interactive) - (notmuch-search-tag '("-unread" "-inbox")) - (notmuch-search-next-thread))) - -(define-key notmuch-search-mode-map "d" - (lambda () - "Add 'deleted' tag to message." - (interactive) - (notmuch-search-tag '("+deleted")) - (notmuch-search-next-thread))) - -(define-key notmuch-search-mode-map "i" - (lambda () - "Remove 'unread' and 'inbox' tags from message, and add the -'important' tag." - (interactive) - (notmuch-search-tag '("-unread" "-inbox" "+important")) - (notmuch-search-next-thread))) - -(define-key notmuch-search-mode-map "s" - (lambda () - "Remove 'unread' and 'inbox' tags from message, and add the -'spam' tag." - (interactive) - (notmuch-search-tag '("-unread" "-inbox" "+spam")) - (notmuch-search-next-thread))) - ;;; ;;; Calendar ;;; -(require 'org-caldav) - -(setq org-caldav-url - "https://my.owndrive.com/remote.php/caldav/calendars/davexunit") -(setq org-caldav-calendar-id "defaultcalendar") -(setq org-caldav-inbox "~/Documents/calendar.org") -(setq org-caldav-files '()) -(setq org-icalendar-timezone "America/New_York") +(when-require 'org-caldav + (setf org-caldav-url + "https://my.owndrive.com/remote.php/caldav/calendars/davexunit" + org-caldav-calendar-id "defaultcalendar" + org-caldav-inbox "~/Documents/calendar.org" + org-caldav-files '() + org-icalendar-timezone "America/New_York")) ;;; ;;; Music ;;; -(require 'emms-player-mpd) -(require 'emms-mode-line) -(require 'emms-browser) +(when-require 'emms + (require 'emms-player-mpd) + (require 'emms-mode-line) + (require 'emms-browser) + + (emms-standard) + (emms-mode-line 1) + (setf emms-player-mpd-server-name "localhost" + emms-player-mpd-server-port "6600" + emms-volume-change-function 'emms-volume-mpd-change) + (add-to-list 'emms-info-functions 'emms-info-mpd) + (add-to-list 'emms-player-list 'emms-player-mpd) -(emms-standard) -(emms-mode-line 1) -(setq emms-player-mpd-server-name "localhost" - emms-player-mpd-server-port "6600" - emms-volume-change-function 'emms-volume-mpd-change) -(add-to-list 'emms-info-functions 'emms-info-mpd) -(add-to-list 'emms-player-list 'emms-player-mpd) + (global-set-key (kbd "C-c e e") 'emms) + (global-set-key (kbd "C-c e b") 'emms-browser)) ;;; ;;; Other @@ -421,23 +434,15 @@ might be bad." (forward-line -1) (indent-for-tab-command)) -;; Easy window movement. -(require 'windmove) -(windmove-default-keybindings 'meta) +(when-require 'smex + (global-set-key (kbd "M-x") 'smex)) -(global-set-key (kbd "M-x") 'smex) (global-set-key (kbd "RET") 'newline-and-indent) (global-set-key (kbd "") 'open-line-below) (global-set-key (kbd "") 'open-line-above) -(global-set-key (kbd "C-c g") 'magit-status) (global-set-key (kbd "C-c i") 'start-irc) (global-set-key (kbd "C-c p") 'package-list-packages) (global-set-key (kbd "C-c C-f") 'ff-find-other-file) -(global-set-key (kbd "C-c s") 'connect-to-guile) -(global-set-key (kbd "C-c e e") 'emms) -(global-set-key (kbd "C-c e b") 'emms-browser) -(global-set-key (kbd "C-c f") 'elfeed) -(global-set-key (kbd "C-c m") 'notmuch) (global-set-key (kbd "M-%") 'query-replace-regexp) ;; No more minimizing Emacs by accident. (global-unset-key (kbd "C-z")) -- cgit v1.2.3