General Emacs Configurations

Emacs Server

This sets it up such that, when C-x k is pressed, an active emacsclient session will be closed. First, it clones any active local keymaps if they exist.

(add-hook 'server-switch-hook
          (lambda ()
            (when (current-local-map)
              (use-local-map (copy-keymap (current-local-map))))
            (when server-buffer-clients
              (local-set-key (kbd "C-x k") 'server-edit))))

Start the emacs server, if it isn't running already.

(if (and (fboundp 'server-running-p)
         (not (server-running-p)))


(setq abbrev-file-name "~/.emacs.d/abbrev_defs")
(setq save-abbrevs t)
(setq abbrev-mode t)


(setq tab-width 2)

Change "yes or no" to "y or n"

(fset 'yes-or-no-p 'y-or-n-p)


Set native vs non-native fullscreen on the Mac:

;; (setq ns-use-native-fullscreen nil)
(setq ns-use-native-fullscreen t)

Be less aggressive when vertically splitting my windows: (default 80)

(setq split-height-threshold 110)

Minimum height for splitting windows sensibly. If this is an integer, ‘split-window-sensibly’ may split a window vertically only if it has at least this many lines.


(prefer-coding-system 'utf-8)
(when (display-graphic-p)
  (setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)))

Save Hooks

I don't like it when delete-trailing-whitespace moves my cursor around when it finds I'm sitting on some white-space. It just ends up kicking back my indentation for something I was just about to start typing.

(defun toby/delete-trailing-whitespace ()
  "Ignore current line when deleting trailing whitespace"
  (let ((first-part-start (point-min))
        (first-part-end   (point-at-bol))
        (second-part-start (point-at-eol))
        (second-part-end  (point-max)))
    (delete-trailing-whitespace first-part-start first-part-end)
    (delete-trailing-whitespace second-part-start second-part-end)))

Clean-up trailing white-space on save.

(add-hook 'before-save-hook 'toby/delete-trailing-whitespace)

Dired Mode

Set ls flags and load some dired extensions.

(setq dired-listing-switches "-alh")
(require 'dired-x)

(require-package 'dired+)
(require 'dired+)


(require-package 'browse-kill-ring)


(require-package 'ag)

(require-package 'isearch+)
(eval-after-load "isearch" '(require 'isearch+))

ADOPTED Multiple Cursors

  • State "ADOPTED" from "REJECTED" [2017-07-06 Thu 14:32]
(require-package 'multiple-cursors)
(autoload 'mc/edit-lines "multiple-cursors" "Multiple Cursors" t)

(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)

(autoload 'mc/mark-next-like-this "multiple-cursors" "Multiple Cursors" t)
(autoload 'mc/mark-previous-like-this "multiple-cursors" "Multiple Cursors" t)
(autoload 'mc/mark-all-like-this "multiple-cursors" "Multiple Cursors" t)

(global-set-key (kbd "C->") 'mc/mark-next-like-this)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)

ADOPTED Which-Key Mode

  • State "ADOPTED" from "REJECTED" [2017-07-06 Thu 14:31]
  • State "REJECTED" from "EXPERIMENTAL" [2017-07-06 Thu 14:31]
  • State "EXPERIMENTAL" from [2017-07-06 Thu 14:31]
(require-package 'which-key)


(defun toby/reload-config ()
  "Reload ~/.emacs.d/init.el"
  (load-file (concat user-emacs-directory "init.el")))

(global-set-key (kbd "C-x x r") 'toby/reload-config)
(provide 'emacs-init)

Author: Toby Tripp

Created: 2018-02-09 Fri 15:33