Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 147 lines (125 sloc) 5.36 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)
ce49c61 @technomancy Fix coding-hook to only enable idle-highlight if it's installed.
authored
62 (if (functionp 'idle-highlight) (idle-highlight)))
5fcb34d @technomancy initial commit
authored
63
64 (defun untabify-buffer ()
65 (interactive)
66 (untabify (point-min) (point-max)))
67
68 (defun indent-buffer ()
69 (interactive)
70 (indent-region (point-min) (point-max)))
71
72 (defun recentf-ido-find-file ()
73 "Find a recent file using ido."
74 (interactive)
75 (let ((file (ido-completing-read "Choose recent file: " recentf-list nil t)))
76 (when file
77 (find-file file))))
78
79 ;; Cosmetic
80
81 (defun pretty-lambdas ()
82 (font-lock-add-keywords
83 nil `(("(?\\(lambda\\>\\)"
84 (0 (progn (compose-region (match-beginning 1) (match-end 1)
85 ,(make-char 'greek-iso8859-7 107))
86 nil))))))
87
88 ;; Other
89
d7bdec6 @technomancy Rename some functions; remove mention of nxhtml until it's in ELPA.
authored
90 (defun eval-and-replace ()
5fcb34d @technomancy initial commit
authored
91 "Replace the preceding sexp with its value."
92 (interactive)
93 (backward-kill-sexp)
94 (condition-case nil
95 (prin1 (eval (read (current-kill 0)))
96 (current-buffer))
97 (error (message "Invalid expression")
98 (insert (current-kill 0)))))
99
d7bdec6 @technomancy Rename some functions; remove mention of nxhtml until it's in ELPA.
authored
100 (defun recompile-init ()
101 "Byte-compile all your dotfiles again."
5fcb34d @technomancy initial commit
authored
102 (interactive)
d7bdec6 @technomancy Rename some functions; remove mention of nxhtml until it's in ELPA.
authored
103 (byte-recompile-directory dotfiles-dir 0)
104 ;; TODO: remove elpa-to-submit once everything's submitted.
105 (byte-recompile-directory (concat dotfiles-dir "elpa-to-submit/" 0)))
5fcb34d @technomancy initial commit
authored
106
420ef86 @technomancy Add cheat.el and lisppaste.el; clean up init.el.
authored
107 (defun regen-autoloads ()
108 "Regenerate the autoload definitions file if necessary and load it."
109 (interactive)
110 (if (or (not (file-exists-p autoload-file))
111 ;; TODO: make this more readable
112 (< (+ (car (nth 5 (file-attributes autoload-file))) 20)
113 (car (current-time))))
114 (let ((generated-autoload-file autoload-file))
115 (message "Updating autoloads...")
116 (update-directory-autoloads dotfiles-dir
117 (concat dotfiles-dir "/elpa-to-submit"))))
118 (load autoload-file))
119
5fcb34d @technomancy initial commit
authored
120 ;; TODO: fix this
121 (defun sudo-edit (&optional arg)
122 (interactive "p")
123 (if arg
124 (find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
125 (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
126
127 (defun lorem ()
128 "Insert a lorem ipsum."
129 (interactive)
130 (insert "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "
131 "eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim"
132 "ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut "
133 "aliquip ex ea commodo consequat. Duis aute irure dolor in "
134 "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla "
135 "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in "
136 "culpa qui officia deserunt mollit anim id est laborum."))
137
138 (defun switch-or-start (function buffer)
139 "If the buffer is current, bury it, otherwise invoke the function."
140 (if (equal (buffer-name (current-buffer)) buffer)
141 (bury-buffer)
142 (if (get-buffer buffer)
143 (switch-to-buffer buffer)
144 (funcall function))))
145
146 (provide 'starter-kit-defuns)
147 ;;; starter-kit-defuns.el ends here
Something went wrong with that request. Please try again.