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)))

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

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


(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)
(provide 'emacs-init)

Author: Toby Tripp

Created: 2015-02-04 Wed 10:41

Emacs 24.3.1 (Org mode 8.2.10)