public
Created

My .emacs self installing portable config

  • Download Gist
nic-custom.el
Emacs Lisp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
:;exec emacs -batch -l "$0" -f nic-custom-self-install "$@"
;;; custom.el --- Nic's custom stuff for Emacs
 
;; Copyright (C) 2012 Nic Ferrier <nferrier@ferrier.me.uk>
 
;; Author: Nic Ferrier <nferrier@ferrier.me.uk>
;; Keywords: local
 
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation; either version 3
;; of the License, or (at your option) any later version.
 
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
 
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
 
;;; Commentary:
 
;; This is an attempt to finally make my emacs config portable.
 
;; The idea is that you set your init.el up by running the command in
;; here `nic-custom-self-install' which you can do by executing this
;; script as a shell script:
;;
;; bash ./nic-custom.el
 
;; Doing that makes this script the source of all knowledge. Put all
;; local hacks here or use packages.
 
;;; Code:
 
(defconst nic-custom-bootstrap
(list '(load-file
(setq custom-file
(concat
(file-name-directory
(or (buffer-file-name)
load-file-name))
"nic-custom.el"))))
"The lisp that will be used for the init.el.")
 
(defun nic-custom-self-install ()
"Self install this code into init.el"
(interactive)
(with-temp-buffer
(let ((fmt-obj
(format
";; Init file installed by niccustom.el
 
%s
;; End init file"
(pp-to-string
(car nic-custom-bootstrap)))))
(insert fmt-obj))
(write-file (or user-init-file "~/.emacs.d/init.el"))))
 
;; I really hate brief-mode's keybinding
(fmakunbound 'brief-mode)
 
;; No need for any other xml mode
(fset 'xml-mode 'nxml-mode)
 
 
(defun ispell-lookup (word)
"Lookup a word in the ispell dictionary.
 
Just uses the minibuffer to read the word."
(interactive "Mword: ")
(with-current-buffer (get-buffer-create "* ispell-lookup *")
(erase-buffer)
(insert word)
(goto-char (point-min))
(switch-to-buffer-other-window (current-buffer))
(ispell-word)))
 
(defadvice kill-ring-save (before slick-copy activate compile)
"When called interactively with no active region, copy a single line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(message "Copied line")
(list (line-beginning-position)
(line-beginning-position 2)))))
 
(defadvice kill-region (before slick-cut activate compile)
"When called interactively with no active region, kill a single line instead."
(interactive
(if mark-active (list (region-beginning) (region-end))
(list (line-beginning-position)
(line-beginning-position 2)))))
 
(defadvice server-start
(around nic-custome-detect-existing first activate compile)
"Detect if the Emacs server is already running.
 
If it's running then don't start it."
(unless (file-exists-p
(concat
"/tmp/emacs1000/"
server-name))
ad-do-it))
 
;; Otto work for groovy, Wolf's gradle code uses 4 wide tabs
(add-to-list 'auto-mode-alist '("\\.gradle" . groovy-mode))
(add-hook 'groovy-mode-hook (lambda () (setq tab-width 4)))
 
(add-hook 'js-mode-hook (lambda () (linum-mode 1)(flyspell-prog-mode)))
(add-hook
'css-mode-hook
(lambda () (linum-mode 1)(flyspell-prog-mode)(rainbow-mode 1)))
(add-hook 'nxml-mode-hook (lambda () (linum-mode 1)(flyspell-prog-mode)))
 
(add-to-list
'auto-mode-alist
'("\\.\\(xml\\|xslt\\|xsd\\|rng\\|xhtml\\|html\\)\\'" . nxml-mode))
(add-to-list 'auto-mode-alist '("\\.yml" . yaml-mode))
(add-to-list 'auto-mode-alist '("\\.pp" . conf-mode))
(add-to-list 'auto-mode-alist '("\\.rake" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.[^.]+rc" . shell-script-mode))
(add-to-list 'auto-mode-alist '("\\.\\(as\\|asant\\)\\'" . java-mode))
(add-to-list 'auto-mode-alist '("\\(Rakefile\\|Capfile\\)" . ruby-mode))
(add-to-list 'auto-mode-alist '("\\.md" . markdown-mode))
 
;; Use this for stuff which is in the package system and can't be
;; started any other way
(add-hook 'after-init-hook 'cycbuf-init)
 
;; Some personal keys for things that don't have them
(global-set-key
"\M-?"
(lambda ()
(interactive)
(call-interactively 'magit-status)))
 
;;(global-set-key "\M-P" 'mdmua-pull)
 
(global-set-key (kbd "C-'") 'shell-switcher-switch-buffer)
(global-set-key (kbd "C-x 4 '") 'shell-switcher-switch-buffer-other-window)
(global-set-key (kbd "C-M-'") 'shell-switcher-new-shell)
 
(require 'uniquify)
(require 'dired-x)
(provide 'nic-custom)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.