Skip to content
This repository
Newer
Older
100644 151 lines (128 sloc) 5.566 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 ;; Network
6
7 (require 'thingatpt)
8
9 (defun view-url ()
10 "Open a new buffer containing the contents of URL."
11 (interactive)
12 (let* ((default (thing-at-point-url-at-point))
13 (url (read-from-minibuffer "URL: " default)))
14 (switch-to-buffer (url-retrieve-synchronously url))
15 (rename-buffer url t)
16 ;; TODO: switch to nxml/nxhtml mode
17 (cond ((search-forward "<?xml" nil t) (xml-mode))
18 ((search-forward "<html" nil t) (html-mode)))))
19
20 (defun map-coords (lat lng)
21 "Show a Yahoo map marked with the point LAT by LNG."
22 (interactive "BLatitude: \nBLongitude")
23 (browse-url (format "http://maps.yahoo.com/maps_result?mag=12&lat=%s&lon=%s"
24 lat lng)))
25
26 ;; Buffer-related
27
28 (defun ido-goto-symbol ()
29 "Update the imenu index and then use ido to select a symbol to navigate to."
30 (interactive)
31 (imenu--make-index-alist)
32 (let ((name-and-pos '())
33 (symbol-names '()))
34 (flet ((addsymbols (symbol-list)
35 (when (listp symbol-list)
36 (dolist (symbol symbol-list)
37 (let ((name nil) (position nil))
38 (cond
39 ((and (listp symbol) (imenu--subalist-p symbol))
40 (addsymbols symbol))
41
42 ((listp symbol)
43 (setq name (car symbol))
44 (setq position (cdr symbol)))
45
46 ((stringp symbol)
47 (setq name symbol)
48 (setq position (get-text-property 1 'org-imenu-marker symbol))))
49
50 (unless (or (null position) (null name))
51 (add-to-list 'symbol-names name)
52 (add-to-list 'name-and-pos (cons name position))))))))
53 (addsymbols imenu--index-alist))
54 (let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names))
55 (position (cdr (assoc selected-symbol name-and-pos))))
56 (goto-char position))))
57
58 (defun my-coding-hook ()
59 "Enable things that are convenient across all coding buffers."
60 (set (make-local-variable 'comment-auto-fill-only-comments) t)
61 (make-local-variable 'column-number-mode)
62 (column-number-mode t)
ac26be3f »
2008-12-03 Added clojure and markdown modes, fix save-place.
63 (setq save-place t)
5fcb34d0 »
2008-11-18 initial commit
64 (auto-fill-mode) ;; in comments only
65 (if window-system (hl-line-mode t))
66 (pretty-lambdas)
ce49c61c »
2008-12-04 Fix coding-hook to only enable idle-highlight if it's installed.
67 (if (functionp 'idle-highlight) (idle-highlight)))
5fcb34d0 »
2008-11-18 initial commit
68
69 (defun untabify-buffer ()
70 (interactive)
71 (untabify (point-min) (point-max)))
72
73 (defun indent-buffer ()
74 (interactive)
75 (indent-region (point-min) (point-max)))
76
77 (defun recentf-ido-find-file ()
78 "Find a recent file using ido."
79 (interactive)
80 (let ((file (ido-completing-read "Choose recent file: " recentf-list nil t)))
81 (when file
82 (find-file file))))
83
84 ;; Cosmetic
85
86 (defun pretty-lambdas ()
87 (font-lock-add-keywords
88 nil `(("(?\\(lambda\\>\\)"
89 (0 (progn (compose-region (match-beginning 1) (match-end 1)
90 ,(make-char 'greek-iso8859-7 107))
91 nil))))))
92
93 ;; Other
94
95 (defun my-eval-and-replace ()
96 "Replace the preceding sexp with its value."
97 (interactive)
98 (backward-kill-sexp)
99 (condition-case nil
100 (prin1 (eval (read (current-kill 0)))
101 (current-buffer))
102 (error (message "Invalid expression")
103 (insert (current-kill 0)))))
104
105 (defun my-recompile-init ()
106 "Byte-compile everything in ~/.emacs.d again."
107 (interactive)
108 (byte-recompile-directory (expand-file-name "~/.emacs.d") 0))
109
2304babf »
2008-12-09 Prefix arg allows regen-autoloads to force even if "up to date".
110 (defun regen-autoloads (&optional force-regen)
420ef86d »
2008-12-03 Add cheat.el and lisppaste.el; clean up init.el.
111 "Regenerate the autoload definitions file if necessary and load it."
2304babf »
2008-12-09 Prefix arg allows regen-autoloads to force even if "up to date".
112 (interactive "p")
113 (setq reg force-regen)
3967f4b7 »
2008-12-08 Remove ELPA'd ruby libs, clean up regen-autoloads.
114 (let ((autoload-dir (concat dotfiles-dir "/elpa-to-submit"))
115 (generated-autoload-file autoload-file))
2304babf »
2008-12-09 Prefix arg allows regen-autoloads to force even if "up to date".
116 (when (or (> force-regen 1) ;; prefix arg used
117 (not (file-exists-p autoload-file))
cc5b4ee6 »
2008-12-09 Fix a bug in regen-autoloads.
118 (some (lambda (f) (file-newer-than-file-p f autoload-file))
119 (directory-files autoload-dir t "\\.el$")))
120 (message "Updating autoloads...")
121 (update-directory-autoloads autoload-dir)))
420ef86d »
2008-12-03 Add cheat.el and lisppaste.el; clean up init.el.
122 (load autoload-file))
123
5fcb34d0 »
2008-11-18 initial commit
124 ;; TODO: fix this
125 (defun sudo-edit (&optional arg)
126 (interactive "p")
127 (if arg
128 (find-file (concat "/sudo:root@localhost:" (ido-read-file-name "File: ")))
129 (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
130
131 (defun lorem ()
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
142 (defun switch-or-start (function buffer)
143 "If the buffer is current, bury it, otherwise invoke the function."
144 (if (equal (buffer-name (current-buffer)) buffer)
145 (bury-buffer)
146 (if (get-buffer buffer)
147 (switch-to-buffer buffer)
148 (funcall function))))
149
150 (provide 'starter-kit-defuns)
151 ;;; starter-kit-defuns.el ends here
Something went wrong with that request. Please try again.