Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 154 lines (131 sloc) 5.605 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
74 (defun recentf-ido-find-file ()
75 "Find a recent file using ido."
76 (interactive)
77 (let ((file (ido-completing-read "Choose recent file: " recentf-list nil t)))
78 (when file
79 (find-file file))))
80
81 ;; Cosmetic
82
83 (defun pretty-lambdas ()
84 (font-lock-add-keywords
fa60db0 @technomancy Revert "Use rx for regex construction for great justice."
authored
85 nil `(("(?\\(lambda\\>\\)"
5fcb34d @technomancy initial commit
authored
86 (0 (progn (compose-region (match-beginning 1) (match-end 1)
87 ,(make-char 'greek-iso8859-7 107))
88 nil))))))
89
90 ;; Other
91
d7bdec6 @technomancy Rename some functions; remove mention of nxhtml until it's in ELPA.
authored
92 (defun eval-and-replace ()
5fcb34d @technomancy initial commit
authored
93 "Replace the preceding sexp with its value."
94 (interactive)
95 (backward-kill-sexp)
96 (condition-case nil
97 (prin1 (eval (read (current-kill 0)))
98 (current-buffer))
99 (error (message "Invalid expression")
100 (insert (current-kill 0)))))
101
d7bdec6 @technomancy Rename some functions; remove mention of nxhtml until it's in ELPA.
authored
102 (defun recompile-init ()
103 "Byte-compile all your dotfiles again."
5fcb34d @technomancy initial commit
authored
104 (interactive)
d7bdec6 @technomancy Rename some functions; remove mention of nxhtml until it's in ELPA.
authored
105 (byte-recompile-directory dotfiles-dir 0)
106 ;; TODO: remove elpa-to-submit once everything's submitted.
107 (byte-recompile-directory (concat dotfiles-dir "elpa-to-submit/" 0)))
5fcb34d @technomancy initial commit
authored
108
2304bab @technomancy Prefix arg allows regen-autoloads to force even if "up to date".
authored
109 (defun regen-autoloads (&optional force-regen)
420ef86 @technomancy Add cheat.el and lisppaste.el; clean up init.el.
authored
110 "Regenerate the autoload definitions file if necessary and load it."
6ebc4e8 @technomancy Make regen-autoloads backwards-compatible with 22.
authored
111 (interactive "P")
3967f4b @technomancy Remove ELPA'd ruby libs, clean up regen-autoloads.
authored
112 (let ((autoload-dir (concat dotfiles-dir "/elpa-to-submit"))
113 (generated-autoload-file autoload-file))
6ebc4e8 @technomancy Make regen-autoloads backwards-compatible with 22.
authored
114 (when (or force-regen
2304bab @technomancy Prefix arg allows regen-autoloads to force even if "up to date".
authored
115 (not (file-exists-p autoload-file))
cc5b4ee @technomancy Fix a bug in regen-autoloads.
authored
116 (some (lambda (f) (file-newer-than-file-p f autoload-file))
117 (directory-files autoload-dir t "\\.el$")))
118 (message "Updating autoloads...")
119 (update-directory-autoloads autoload-dir)))
420ef86 @technomancy Add cheat.el and lisppaste.el; clean up init.el.
authored
120 (load autoload-file))
121
5fcb34d @technomancy initial commit
authored
122 ;; TODO: fix this
123 (defun sudo-edit (&optional arg)
124 (interactive "p")
125 (if arg
126 (find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
127 (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
128
129 (defun lorem ()
130 "Insert a lorem ipsum."
131 (interactive)
132 (insert "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
133 "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim"
134 "ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
135 "aliquip ex ea commodo consequat. Duis aute irure dolor in "
136 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
137 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
138 "culpa qui officia deserunt mollit anim id est laborum."))
139
140 (defun switch-or-start (function buffer)
141 "If the buffer is current, bury it, otherwise invoke the function."
142 (if (equal (buffer-name (current-buffer)) buffer)
143 (bury-buffer)
144 (if (get-buffer buffer)
145 (switch-to-buffer buffer)
146 (funcall function))))
147
6c79eeb @technomancy Added pairing-bot function.
authored
148 (defun pairing-bot ()
149 "If you can't pair program with a human, use this instead."
150 (interactive)
151 (message (if (y-or-n-p "Do you have a test for that? ") "Good." "Bad!")))
152
5fcb34d @technomancy initial commit
authored
153 (provide 'starter-kit-defuns)
154 ;;; starter-kit-defuns.el ends here
Something went wrong with that request. Please try again.