Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 161 lines (137 sloc) 5.79 kb
5fcb34d @technomancy initial commit
authored
1 ;;; starter-kit-defuns.el --- Define some custom functions
2 ;;
3 ;; Part of the Emacs Starter Kit
4
5 (require 'thingatpt)
d7bdec6 @technomancy Rename some functions; remove mention of nxhtml until it's in ELPA.
authored
6 (require 'imenu)
7
8 ;; Network
5fcb34d @technomancy initial commit
authored
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
d7bdec6 @technomancy Rename some functions; remove mention of nxhtml until it's in ELPA.
authored
23 (defun ido-imenu ()
5fcb34d @technomancy initial commit
authored
24 "Update the imenu index and then use ido to select a symbol to navigate to."
25 (interactive)
26 (imenu--make-index-alist)
27 (let ((name-and-pos '())
28 (symbol-names '()))
29 (flet ((addsymbols (symbol-list)
30 (when (listp symbol-list)
31 (dolist (symbol symbol-list)
32 (let ((name nil) (position nil))
33 (cond
34 ((and (listp symbol) (imenu--subalist-p symbol))
35 (addsymbols symbol))
36
37 ((listp symbol)
38 (setq name (car symbol))
39 (setq position (cdr symbol)))
40
41 ((stringp symbol)
42 (setq name symbol)
43 (setq position (get-text-property 1 'org-imenu-marker symbol))))
44
45 (unless (or (null position) (null name))
46 (add-to-list 'symbol-names name)
47 (add-to-list 'name-and-pos (cons name position))))))))
48 (addsymbols imenu--index-alist))
49 (let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names))
50 (position (cdr (assoc selected-symbol name-and-pos))))
51 (goto-char position))))
52
d7bdec6 @technomancy Rename some functions; remove mention of nxhtml until it's in ELPA.
authored
53 (defun coding-hook ()
5fcb34d @technomancy initial commit
authored
54 "Enable things that are convenient across all coding buffers."
55 (set (make-local-variable 'comment-auto-fill-only-comments) t)
56 (make-local-variable 'column-number-mode)
57 (column-number-mode t)
ac26be3 @technomancy Added clojure and markdown modes, fix save-place.
authored
58 (setq save-place t)
5fcb34d @technomancy initial commit
authored
59 (auto-fill-mode) ;; in comments only
60 (if window-system (hl-line-mode t))
61 (pretty-lambdas)
eb9eeb5 @technomancy Move lisp bindings and add in JS stuff.
authored
62 ;; TODO: this breaks in js2-mode!
63 ;;(if (functionp 'idle-highlight) (idle-highlight))
64 )
5fcb34d @technomancy initial commit
authored
65
66 (defun untabify-buffer ()
67 (interactive)
68 (untabify (point-min) (point-max)))
69
70 (defun indent-buffer ()
71 (interactive)
72 (indent-region (point-min) (point-max)))
73
1f6f58b @technomancy Extracted cleanup buffer function.
authored
74 (defun cleanup-buffer ()
75 "Perform a bunch of operations on the whitespace content of a buffer."
76 (interactive)
77 (indent-buffer)
78 (untabify-buffer)
79 (delete-trailing-whitespace))
80
5fcb34d @technomancy initial commit
authored
81 (defun recentf-ido-find-file ()
82 "Find a recent file using ido."
83 (interactive)
84 (let ((file (ido-completing-read "Choose recent file: " recentf-list nil t)))
85 (when file
86 (find-file file))))
87
88 ;; Cosmetic
89
90 (defun pretty-lambdas ()
91 (font-lock-add-keywords
fa60db0 @technomancy Revert "Use rx for regex construction for great justice."
authored
92 nil `(("(?\\(lambda\\>\\)"
5fcb34d @technomancy initial commit
authored
93 (0 (progn (compose-region (match-beginning 1) (match-end 1)
94 ,(make-char 'greek-iso8859-7 107))
95 nil))))))
96
97 ;; Other
98
d7bdec6 @technomancy Rename some functions; remove mention of nxhtml until it's in ELPA.
authored
99 (defun eval-and-replace ()
5fcb34d @technomancy initial commit
authored
100 "Replace the preceding sexp with its value."
101 (interactive)
102 (backward-kill-sexp)
103 (condition-case nil
104 (prin1 (eval (read (current-kill 0)))
105 (current-buffer))
106 (error (message "Invalid expression")
107 (insert (current-kill 0)))))
108
d7bdec6 @technomancy Rename some functions; remove mention of nxhtml until it's in ELPA.
authored
109 (defun recompile-init ()
110 "Byte-compile all your dotfiles again."
5fcb34d @technomancy initial commit
authored
111 (interactive)
d7bdec6 @technomancy Rename some functions; remove mention of nxhtml until it's in ELPA.
authored
112 (byte-recompile-directory dotfiles-dir 0)
113 ;; TODO: remove elpa-to-submit once everything's submitted.
114 (byte-recompile-directory (concat dotfiles-dir "elpa-to-submit/" 0)))
5fcb34d @technomancy initial commit
authored
115
2304bab @technomancy Prefix arg allows regen-autoloads to force even if "up to date".
authored
116 (defun regen-autoloads (&optional force-regen)
420ef86 @technomancy Add cheat.el and lisppaste.el; clean up init.el.
authored
117 "Regenerate the autoload definitions file if necessary and load it."
6ebc4e8 @technomancy Make regen-autoloads backwards-compatible with 22.
authored
118 (interactive "P")
3967f4b @technomancy Remove ELPA'd ruby libs, clean up regen-autoloads.
authored
119 (let ((autoload-dir (concat dotfiles-dir "/elpa-to-submit"))
120 (generated-autoload-file autoload-file))
6ebc4e8 @technomancy Make regen-autoloads backwards-compatible with 22.
authored
121 (when (or force-regen
2304bab @technomancy Prefix arg allows regen-autoloads to force even if "up to date".
authored
122 (not (file-exists-p autoload-file))
cc5b4ee @technomancy Fix a bug in regen-autoloads.
authored
123 (some (lambda (f) (file-newer-than-file-p f autoload-file))
124 (directory-files autoload-dir t "\\.el$")))
125 (message "Updating autoloads...")
126 (update-directory-autoloads autoload-dir)))
420ef86 @technomancy Add cheat.el and lisppaste.el; clean up init.el.
authored
127 (load autoload-file))
128
5fcb34d @technomancy initial commit
authored
129 ;; TODO: fix this
130 (defun sudo-edit (&optional arg)
131 (interactive "p")
132 (if arg
133 (find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
134 (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
135
136 (defun lorem ()
137 "Insert a lorem ipsum."
138 (interactive)
139 (insert "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
140 "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim"
141 "ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
142 "aliquip ex ea commodo consequat. Duis aute irure dolor in "
143 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
144 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
145 "culpa qui officia deserunt mollit anim id est laborum."))
146
147 (defun switch-or-start (function buffer)
148 "If the buffer is current, bury it, otherwise invoke the function."
149 (if (equal (buffer-name (current-buffer)) buffer)
150 (bury-buffer)
151 (if (get-buffer buffer)
152 (switch-to-buffer buffer)
153 (funcall function))))
154
6c79eeb @technomancy Added pairing-bot function.
authored
155 (defun pairing-bot ()
156 "If you can't pair program with a human, use this instead."
157 (interactive)
158 (message (if (y-or-n-p "Do you have a test for that? ") "Good." "Bad!")))
159
5fcb34d @technomancy initial commit
authored
160 (provide 'starter-kit-defuns)
161 ;;; starter-kit-defuns.el ends here
Something went wrong with that request. Please try again.