Skip to content
This repository
Newer
Older
100644 183 lines (157 sloc) 6.951 kb
5fcb34d0 »
2008-11-18 initial commit
1 ;;; starter-kit-defuns.el --- Define some custom functions
2 ;;
3 ;; Part of the Emacs Starter Kit
4
5 (require 'thingatpt)
d7bdec66 »
2008-12-10 Rename some functions; remove mention of nxhtml until it's in ELPA.
6 (require 'imenu)
7
8 ;; Network
5fcb34d0 »
2008-11-18 initial commit
9
10 (defun view-url ()
11 "Open a new buffer containing the contents of URL."
12 (interactive)
13 (let* ((default (thing-at-point-url-at-point))
14 (url (read-from-minibuffer "URL: " default)))
15 (switch-to-buffer (url-retrieve-synchronously url))
16 (rename-buffer url t)
17 ;; TODO: switch to nxml/nxhtml mode
18 (cond ((search-forward "<?xml" nil t) (xml-mode))
19 ((search-forward "<html" nil t) (html-mode)))))
20
21 ;; Buffer-related
22
d7bdec66 »
2008-12-10 Rename some functions; remove mention of nxhtml until it's in ELPA.
23 (defun ido-imenu ()
7408e2be » nonsequitur
2009-03-11 Make ido-imenu recognize the symbol at point.
24 "Update the imenu index and then use ido to select a symbol to navigate to.
25 Symbols matching the text at point are put first in the completion list."
5fcb34d0 »
2008-11-18 initial commit
26 (interactive)
27 (imenu--make-index-alist)
28 (let ((name-and-pos '())
29 (symbol-names '()))
30 (flet ((addsymbols (symbol-list)
31 (when (listp symbol-list)
32 (dolist (symbol symbol-list)
33 (let ((name nil) (position nil))
34 (cond
35 ((and (listp symbol) (imenu--subalist-p symbol))
36 (addsymbols symbol))
37
38 ((listp symbol)
39 (setq name (car symbol))
40 (setq position (cdr symbol)))
41
42 ((stringp symbol)
43 (setq name symbol)
44 (setq position (get-text-property 1 'org-imenu-marker symbol))))
45
46 (unless (or (null position) (null name))
47 (add-to-list 'symbol-names name)
48 (add-to-list 'name-and-pos (cons name position))))))))
49 (addsymbols imenu--index-alist))
7408e2be » nonsequitur
2009-03-11 Make ido-imenu recognize the symbol at point.
50 ;; If there are matching symbols at point, put them at the beginning of `symbol-names'.
51 (let ((symbol-at-point (thing-at-point 'symbol)))
52 (when symbol-at-point
53 (let* ((regexp (concat (regexp-quote symbol-at-point) "$"))
54 (matching-symbols (delq nil (mapcar (lambda (symbol)
55 (if (string-match regexp symbol) symbol))
56 symbol-names))))
57 (when matching-symbols
58 (sort matching-symbols (lambda (a b) (> (length a) (length b))))
59 (mapc (lambda (symbol) (setq symbol-names (cons symbol (delete symbol symbol-names))))
60 matching-symbols)))))
5fcb34d0 »
2008-11-18 initial commit
61 (let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names))
62 (position (cdr (assoc selected-symbol name-and-pos))))
63 (goto-char position))))
64
d7bdec66 »
2008-12-10 Rename some functions; remove mention of nxhtml until it's in ELPA.
65 (defun coding-hook ()
5fcb34d0 »
2008-11-18 initial commit
66 "Enable things that are convenient across all coding buffers."
67 (set (make-local-variable 'comment-auto-fill-only-comments) t)
68 (make-local-variable 'column-number-mode)
69 (column-number-mode t)
ac26be3f »
2008-12-03 Added clojure and markdown modes, fix save-place.
70 (setq save-place t)
5fcb34d0 »
2008-11-18 initial commit
71 (auto-fill-mode) ;; in comments only
72 (if window-system (hl-line-mode t))
73 (pretty-lambdas)
eb9eeb5c »
2008-12-11 Move lisp bindings and add in JS stuff.
74 ;; TODO: this breaks in js2-mode!
75 ;;(if (functionp 'idle-highlight) (idle-highlight))
76 )
5fcb34d0 »
2008-11-18 initial commit
77
78 (defun untabify-buffer ()
79 (interactive)
80 (untabify (point-min) (point-max)))
81
82 (defun indent-buffer ()
83 (interactive)
84 (indent-region (point-min) (point-max)))
85
1f6f58b4 »
2008-12-16 Extracted cleanup buffer function.
86 (defun cleanup-buffer ()
87 "Perform a bunch of operations on the whitespace content of a buffer."
88 (interactive)
89 (indent-buffer)
90 (untabify-buffer)
91 (delete-trailing-whitespace))
92
5fcb34d0 »
2008-11-18 initial commit
93 (defun recentf-ido-find-file ()
94 "Find a recent file using ido."
95 (interactive)
96 (let ((file (ido-completing-read "Choose recent file: " recentf-list nil t)))
97 (when file
98 (find-file file))))
99
100 ;; Cosmetic
101
102 (defun pretty-lambdas ()
103 (font-lock-add-keywords
fa60db0b »
2008-12-10 Revert "Use rx for regex construction for great justice."
104 nil `(("(?\\(lambda\\>\\)"
5fcb34d0 »
2008-11-18 initial commit
105 (0 (progn (compose-region (match-beginning 1) (match-end 1)
106 ,(make-char 'greek-iso8859-7 107))
107 nil))))))
108
109 ;; Other
110
d7bdec66 »
2008-12-10 Rename some functions; remove mention of nxhtml until it's in ELPA.
111 (defun eval-and-replace ()
5fcb34d0 »
2008-11-18 initial commit
112 "Replace the preceding sexp with its value."
113 (interactive)
114 (backward-kill-sexp)
115 (condition-case nil
116 (prin1 (eval (read (current-kill 0)))
117 (current-buffer))
118 (error (message "Invalid expression")
119 (insert (current-kill 0)))))
120
d7bdec66 »
2008-12-10 Rename some functions; remove mention of nxhtml until it's in ELPA.
121 (defun recompile-init ()
122 "Byte-compile all your dotfiles again."
5fcb34d0 »
2008-11-18 initial commit
123 (interactive)
d7bdec66 »
2008-12-10 Rename some functions; remove mention of nxhtml until it's in ELPA.
124 (byte-recompile-directory dotfiles-dir 0)
125 ;; TODO: remove elpa-to-submit once everything's submitted.
126 (byte-recompile-directory (concat dotfiles-dir "elpa-to-submit/" 0)))
5fcb34d0 »
2008-11-18 initial commit
127
2304babf »
2008-12-09 Prefix arg allows regen-autoloads to force even if "up to date".
128 (defun regen-autoloads (&optional force-regen)
420ef86d »
2008-12-03 Add cheat.el and lisppaste.el; clean up init.el.
129 "Regenerate the autoload definitions file if necessary and load it."
6ebc4e86 »
2008-12-09 Make regen-autoloads backwards-compatible with 22.
130 (interactive "P")
3967f4b7 »
2008-12-08 Remove ELPA'd ruby libs, clean up regen-autoloads.
131 (let ((autoload-dir (concat dotfiles-dir "/elpa-to-submit"))
132 (generated-autoload-file autoload-file))
6ebc4e86 »
2008-12-09 Make regen-autoloads backwards-compatible with 22.
133 (when (or force-regen
2304babf »
2008-12-09 Prefix arg allows regen-autoloads to force even if "up to date".
134 (not (file-exists-p autoload-file))
cc5b4ee6 »
2008-12-09 Fix a bug in regen-autoloads.
135 (some (lambda (f) (file-newer-than-file-p f autoload-file))
136 (directory-files autoload-dir t "\\.el$")))
137 (message "Updating autoloads...")
138 (update-directory-autoloads autoload-dir)))
420ef86d »
2008-12-03 Add cheat.el and lisppaste.el; clean up init.el.
139 (load autoload-file))
140
5fcb34d0 »
2008-11-18 initial commit
141 ;; TODO: fix this
142 (defun sudo-edit (&optional arg)
143 (interactive "p")
144 (if arg
145 (find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
146 (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
147
148 (defun lorem ()
149 "Insert a lorem ipsum."
150 (interactive)
151 (insert "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
152 "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim"
153 "ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
154 "aliquip ex ea commodo consequat. Duis aute irure dolor in "
155 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
156 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
157 "culpa qui officia deserunt mollit anim id est laborum."))
158
159 (defun switch-or-start (function buffer)
160 "If the buffer is current, bury it, otherwise invoke the function."
161 (if (equal (buffer-name (current-buffer)) buffer)
162 (bury-buffer)
163 (if (get-buffer buffer)
164 (switch-to-buffer buffer)
165 (funcall function))))
166
00d6b281 » mjm
2009-01-22 Added a space for insert-date fn
167 (defun insert-date ()
e9a61681 »
2009-01-21 Bring clojure-mode up-to-date (add imenu), add M-x insert-date.
168 "Insert a time-stamp according to locale's date and time format."
169 (interactive)
170 (insert (format-time-string "%c" (current-time))))
171
6c79eeb7 »
2008-12-15 Added pairing-bot function.
172 (defun pairing-bot ()
173 "If you can't pair program with a human, use this instead."
174 (interactive)
175 (message (if (y-or-n-p "Do you have a test for that? ") "Good." "Bad!")))
176
71f9f3d1 »
2009-02-19 Make git annotate ignore whitespace.
177 ;; A monkeypatch to cause annotate to ignore whitespace
178 (defun vc-git-annotate-command (file buf &optional rev)
179 (let ((name (file-relative-name file)))
180 (vc-git-command buf 0 name "blame" "-w" rev)))
181
5fcb34d0 »
2008-11-18 initial commit
182 (provide 'starter-kit-defuns)
183 ;;; starter-kit-defuns.el ends here
Something went wrong with that request. Please try again.