Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 176 lines (141 sloc) 6.033 kb
53627f5 @technomancy Clean up starter-kit-defuns.el.
technomancy authored
1 ;;; starter-kit-defuns.el --- Saner defaults and goodies: function defs.
5fcb34d @technomancy initial commit
technomancy authored
2 ;;
53627f5 @technomancy Clean up starter-kit-defuns.el.
technomancy authored
3 ;; Copyright (c) 2008-2010 Phil Hagelberg and contributors
4 ;;
5 ;; Author: Phil Hagelberg <technomancy@gmail.com>
6 ;; URL: http://www.emacswiki.org/cgi-bin/wiki/StarterKit
e0b9de2 @technomancy Version 2.0.2 of the base starter-kit.
technomancy authored
7 ;; Version: 2.0.2
53627f5 @technomancy Clean up starter-kit-defuns.el.
technomancy authored
8 ;; Keywords: convenience
9
10 ;; This file is not part of GNU Emacs.
11
12 ;;; Commentary:
13
14 ;; "Emacs outshines all other editing software in approximately the
15 ;; same way that the noonday sun does the stars. It is not just bigger
16 ;; and brighter; it simply makes everything else vanish."
17 ;; -Neal Stephenson, "In the Beginning was the Command Line"
18
19 ;; This file contains all the function definitions for the starter kit.
20
21 ;;; License:
22
23 ;; This program is free software; you can redistribute it and/or
24 ;; modify it under the terms of the GNU General Public License
25 ;; as published by the Free Software Foundation; either version 3
26 ;; of the License, or (at your option) any later version.
27 ;;
28 ;; This program is distributed in the hope that it will be useful,
29 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
30 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 ;; GNU General Public License for more details.
32 ;;
33 ;; You should have received a copy of the GNU General Public License
34 ;; along with GNU Emacs; see the file COPYING. If not, write to the
35 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
36 ;; Boston, MA 02110-1301, USA.
37
38 ;;; Code:
5fcb34d @technomancy initial commit
technomancy authored
39
8967c61 @technomancy Switch to using prog-mode-hook instead of our own coding-hook.
technomancy authored
40 ;;; These belong in prog-mode-hook:
b2ffdf1 @technomancy Make coding-hook a real hook instead of a defun.
technomancy authored
41
a4a57d5 @technomancy Add a whitespace-mode function.
technomancy authored
42 ;; We have a number of turn-on-* functions since it's advised that lambda
43 ;; functions not go in hooks. Repeatedly evaling an add-to-list with a
44 ;; hook value will repeatedly add it since there's no way to ensure
031dfc8 @technomancy Cleanup mostly for things that aren't necessary in 24 anymore.
technomancy authored
45 ;; that a byte-compiled lambda doesn't already exist in the list.
a4a57d5 @technomancy Add a whitespace-mode function.
technomancy authored
46
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
47 (defun esk-local-column-number-mode ()
5fcb34d @technomancy initial commit
technomancy authored
48 (make-local-variable 'column-number-mode)
b2ffdf1 @technomancy Make coding-hook a real hook instead of a defun.
technomancy authored
49 (column-number-mode t))
50
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
51 (defun esk-local-comment-auto-fill ()
b2ffdf1 @technomancy Make coding-hook a real hook instead of a defun.
technomancy authored
52 (set (make-local-variable 'comment-auto-fill-only-comments) t)
53 (auto-fill-mode t))
54
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
55 (defun esk-turn-on-hl-line-mode ()
6c214af @technomancy Activate hl-line based on colors available, not window-system.
technomancy authored
56 (when (> (display-color-cells) 8)
57 (hl-line-mode t)))
b2ffdf1 @technomancy Make coding-hook a real hook instead of a defun.
technomancy authored
58
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
59 (defun esk-turn-on-save-place-mode ()
df65c4b @technomancy Trim down loads, use esk- prefix in starter-kit.el.
technomancy authored
60 (require 'saveplace)
b2ffdf1 @technomancy Make coding-hook a real hook instead of a defun.
technomancy authored
61 (setq save-place t))
62
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
63 (defun esk-turn-on-whitespace ()
a4a57d5 @technomancy Add a whitespace-mode function.
technomancy authored
64 (whitespace-mode t))
65
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
66 (defun esk-turn-on-paredit ()
bc907d2 @technomancy Add org bindings; fix clojure-project root heuristic.
technomancy authored
67 (paredit-mode t))
68
8967c61 @technomancy Switch to using prog-mode-hook instead of our own coding-hook.
technomancy authored
69 (defun esk-turn-on-idle-highlight-mode ()
70 (idle-highlight-mode t))
71
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
72 (defun esk-pretty-lambdas ()
73 (font-lock-add-keywords
74 nil `(("(?\\(lambda\\>\\)"
75 (0 (progn (compose-region (match-beginning 1) (match-end 1)
76 ,(make-char 'greek-iso8859-7 107))
77 nil))))))
9e78e16 @technomancy Turn off toolbar even when in daemon-mode.
technomancy authored
78
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
79 (defun esk-add-watchwords ()
c0b7ae5 @technomancy Add watchwords to coding hook.
technomancy authored
80 (font-lock-add-keywords
8967c61 @technomancy Switch to using prog-mode-hook instead of our own coding-hook.
technomancy authored
81 nil '(("\\<\\(FIX\\|TODO\\|FIXME\\|HACK\\|REFACTOR\\|NOCOMMIT\\)"
c0b7ae5 @technomancy Add watchwords to coding hook.
technomancy authored
82 1 font-lock-warning-face t))))
83
8967c61 @technomancy Switch to using prog-mode-hook instead of our own coding-hook.
technomancy authored
84 (add-hook 'prog-mode-hook 'esk-local-column-number-mode)
85 (add-hook 'prog-mode-hook 'esk-local-comment-auto-fill)
86 (add-hook 'prog-mode-hook 'esk-turn-on-hl-line-mode)
87 (add-hook 'prog-mode-hook 'esk-turn-on-save-place-mode)
88 (add-hook 'prog-mode-hook 'esk-pretty-lambdas)
89 (add-hook 'prog-mode-hook 'esk-add-watchwords)
90 (add-hook 'prog-mode-hook 'esk-turn-on-idle-highlight-mode)
5fcb34d @technomancy initial commit
technomancy authored
91
1bc0998 @technomancy Add a defun for running prog-mode-hook.
technomancy authored
92 (defun esk-prog-mode-hook ()
93 (run-hooks 'prog-mode-hook))
94
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
95 (defun esk-turn-off-tool-bar ()
c405654 Ensure tool-bar-mode exists before running it (fixes emacsclient with no...
hellekin authored
96 (if (functionp 'tool-bar-mode) (tool-bar-mode -1)))
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
97
98 (defun esk-untabify-buffer ()
5fcb34d @technomancy initial commit
technomancy authored
99 (interactive)
100 (untabify (point-min) (point-max)))
101
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
102 (defun esk-indent-buffer ()
5fcb34d @technomancy initial commit
technomancy authored
103 (interactive)
104 (indent-region (point-min) (point-max)))
105
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
106 (defun esk-cleanup-buffer ()
1f6f58b @technomancy Extracted cleanup buffer function.
technomancy authored
107 "Perform a bunch of operations on the whitespace content of a buffer."
108 (interactive)
53627f5 @technomancy Clean up starter-kit-defuns.el.
technomancy authored
109 (esk-indent-buffer)
110 (esk-untabify-buffer)
1f6f58b @technomancy Extracted cleanup buffer function.
technomancy authored
111 (delete-trailing-whitespace))
112
031dfc8 @technomancy Cleanup mostly for things that aren't necessary in 24 anymore.
technomancy authored
113 ;; Commands
5fcb34d @technomancy initial commit
technomancy authored
114
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
115 (defun esk-eval-and-replace ()
5fcb34d @technomancy initial commit
technomancy authored
116 "Replace the preceding sexp with its value."
117 (interactive)
118 (backward-kill-sexp)
119 (condition-case nil
120 (prin1 (eval (read (current-kill 0)))
121 (current-buffer))
122 (error (message "Invalid expression")
123 (insert (current-kill 0)))))
124
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
125 (defun esk-sudo-edit (&optional arg)
5fcb34d @technomancy initial commit
technomancy authored
126 (interactive "p")
e404594 @technomancy Fix sudo-edit and turn off toolbar always.
technomancy authored
127 (if (or arg (not buffer-file-name))
5fcb34d @technomancy initial commit
technomancy authored
128 (find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
129 (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
130
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
131 (defun esk-lorem ()
5fcb34d @technomancy initial commit
technomancy authored
132 "Insert a lorem ipsum."
133 (interactive)
134 (insert "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
135 "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim"
136 "ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
137 "aliquip ex ea commodo consequat. Duis aute irure dolor in "
138 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
139 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
140 "culpa qui officia deserunt mollit anim id est laborum."))
141
ea2a11b @technomancy Add esk-suck-it defun thanks to David Leatherman.
technomancy authored
142 (defun esk-suck-it (suckee)
143 "Insert a comment of appropriate length about what can suck it."
144 (interactive "MWhat can suck it? ")
145 (let ((prefix (concat ";; " suckee " can s"))
146 (postfix "ck it!")
147 (col (current-column)))
148 (insert prefix)
149 (dotimes (_ (- 80 col (length prefix) (length postfix))) (insert "u"))
150 (insert postfix)))
151
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
152 (defun esk-insert-date ()
e9a6168 @technomancy Bring clojure-mode up-to-date (add imenu), add M-x insert-date.
technomancy authored
153 "Insert a time-stamp according to locale's date and time format."
154 (interactive)
155 (insert (format-time-string "%c" (current-time))))
156
3a979e0 @technomancy Add esk- prefixes; remove unneeded code.
technomancy authored
157 (defun esk-pairing-bot ()
6c79eeb @technomancy Added pairing-bot function.
technomancy authored
158 "If you can't pair program with a human, use this instead."
159 (interactive)
160 (message (if (y-or-n-p "Do you have a test for that? ") "Good." "Bad!")))
161
b418209 @technomancy Nonlisp paredit fixes; clojure-project bugfix.
technomancy authored
162 (defun esk-paredit-nonlisp ()
163 "Turn on paredit mode for non-lisps."
8967c61 @technomancy Switch to using prog-mode-hook instead of our own coding-hook.
technomancy authored
164 (interactive)
043ae0f @technomancy Fix esk-paredit-nonlisp for Paredit 22.
technomancy authored
165 (set (make-local-variable 'paredit-space-for-delimiter-predicates)
166 '((lambda (endp delimiter) nil)))
b418209 @technomancy Nonlisp paredit fixes; clojure-project bugfix.
technomancy authored
167 (paredit-mode 1))
168
71f9f3d @technomancy Make git annotate ignore whitespace.
technomancy authored
169 ;; A monkeypatch to cause annotate to ignore whitespace
170 (defun vc-git-annotate-command (file buf &optional rev)
171 (let ((name (file-relative-name file)))
172 (vc-git-command buf 0 name "blame" "-w" rev)))
173
5fcb34d @technomancy initial commit
technomancy authored
174 (provide 'starter-kit-defuns)
e3d337d Fixing mismatched parens in recompile-init
Alex Malinovich authored
175 ;;; starter-kit-defuns.el ends here
Something went wrong with that request. Please try again.