Skip to content
Newer
Older
100644 163 lines (139 sloc) 5.29 KB
4dea1e3 @defunkt soft tabs
defunkt authored
1 (defun insert-soft-tab ()
2 (interactive)
3 (insert " "))
4
53d2757 @defunkt whitespace
defunkt authored
5 (defun defunkt-indent ()
932de70 @defunkt some random indent stuff i was playing with
defunkt authored
6 (interactive)
31bdd4a @defunkt indention in css
defunkt authored
7 (insert " "))
932de70 @defunkt some random indent stuff i was playing with
defunkt authored
8
8cbea9c @defunkt my first advice: vim style zap-to-char (doesn't kill the char)
defunkt authored
9 (defadvice zap-to-char (after dont-zap-char (arg char))
10 "Doesn't include the char - zaps to the char before it (like vim)."
11 (insert char)
12 (backward-char))
13 (ad-activate 'zap-to-char)
14
e9375aa @defunkt add jump to defunkt.el
defunkt authored
15 (defun defunkt-ido-find-config ()
d5d6e0a @defunkt Better organize directory layout
defunkt authored
16 (interactive)
57558e4 @defunkt few tweaks
defunkt authored
17 (find-file
860bfa9 @defunkt jump to project
defunkt authored
18 (concat "~/.emacs.d/defunkt/" (ido-completing-read "Config file: "
19 (directory-files "~/.emacs.d/defunkt/" nil "^[^.]")))))
57558e4 @defunkt few tweaks
defunkt authored
20
860bfa9 @defunkt jump to project
defunkt authored
21 (defun defunkt-ido-find-project ()
22 (interactive)
23 (find-file
24 (concat "~/Projects/" (ido-completing-read "Project: "
25 (directory-files "~/Projects/" nil "^[^.]")))))
e9375aa @defunkt add jump to defunkt.el
defunkt authored
26
27 (defun defunkt-goto-config ()
28 (interactive)
29 (find-file "~/.emacs.d/defunkt.el"))
d5d6e0a @defunkt Better organize directory layout
defunkt authored
30
fd92cd8 @defunkt add awesomer kill-word
defunkt authored
31 ;; fix kill-word
32 (defun defunkt-kill-word (arg)
33 "Special version of kill-word which swallows spaces separate from words"
34 (interactive "p")
35
36 (let ((whitespace-regexp "\\s-+"))
53d2757 @defunkt whitespace
defunkt authored
37 (kill-region (point)
38 (cond
6bb6268 @defunkt fixing kill stuff more
defunkt authored
39 ((looking-at whitespace-regexp) (re-search-forward whitespace-regexp) (point))
40 ((looking-at "\n") (kill-line) (defunkt-kill-word arg))
41 (t (forward-word arg) (point))))))
fd92cd8 @defunkt add awesomer kill-word
defunkt authored
42
43 (defun defunkt-backward-kill-word (arg)
44 "Special version of backward-kill-word which swallows spaces separate from words"
45 (interactive "p")
fde843c @defunkt simplify the d-back-kill-word
defunkt authored
46 (if (looking-back "\\s-+")
47 (kill-region (point) (progn (re-search-backward "\\S-") (forward-char 1) (point)))
48 (backward-kill-word arg)))
d5d6e0a @defunkt Better organize directory layout
defunkt authored
49
50 ; set the mode based on the shebang;
51 ; TODO: this sometimes breaks
d05292e @defunkt start namespacing my custom methods
defunkt authored
52 (defun defunkt-shebang-to-mode ()
d5d6e0a @defunkt Better organize directory layout
defunkt authored
53 (interactive)
54 (let*
ab81eb5 @defunkt fix shebang-to-mode so it actually works
defunkt authored
55 ((bang (buffer-substring (point-min) (prog2 (end-of-line) (point) (move-beginning-of-line 1))))
d5d6e0a @defunkt Better organize directory layout
defunkt authored
56 (mode (progn
57 (string-match "^#!.+[ /]\\(\\w+\\)$" bang)
58 (match-string 1 bang)))
59 (mode-fn (intern (concat mode "-mode"))))
60 (when (functionp mode-fn)
61 (funcall mode-fn))))
d05292e @defunkt start namespacing my custom methods
defunkt authored
62 ;(add-hook 'find-file-hook 'defunkt-shebang-to-mode)
d5d6e0a @defunkt Better organize directory layout
defunkt authored
63
7de3151 @defunkt duplicate-line (c-ret)
defunkt authored
64 ; duplicate the current line
53d2757 @defunkt whitespace
defunkt authored
65 (defun defunkt-duplicate-line ()
7de3151 @defunkt duplicate-line (c-ret)
defunkt authored
66 (interactive)
67 (beginning-of-line)
68 (copy-region-as-kill (point) (progn (end-of-line) (point)))
79bb5af @defunkt tweak for textmate function rename
defunkt authored
69 (textmate-next-line)
7de3151 @defunkt duplicate-line (c-ret)
defunkt authored
70 (yank)
79bb5af @defunkt tweak for textmate function rename
defunkt authored
71 (beginning-of-line)
72 (indent-according-to-mode))
7de3151 @defunkt duplicate-line (c-ret)
defunkt authored
73
d5d6e0a @defunkt Better organize directory layout
defunkt authored
74 ; for loading libraries in from the vendor directory
75 (defun vendor (library)
53d2757 @defunkt whitespace
defunkt authored
76 (let* ((file (symbol-name library))
77 (normal (concat "~/.emacs.d/vendor/" file))
d5d6e0a @defunkt Better organize directory layout
defunkt authored
78 (suffix (concat normal ".el"))
79 (defunkt (concat "~/.emacs.d/defunkt/" file)))
53d2757 @defunkt whitespace
defunkt authored
80 (cond
d5d6e0a @defunkt Better organize directory layout
defunkt authored
81 ((file-directory-p normal) (add-to-list 'load-path normal) (require library))
82 ((file-directory-p suffix) (add-to-list 'load-path suffix) (require library))
83 ((file-exists-p suffix) (require library)))
84 (when (file-exists-p (concat defunkt ".el"))
b0957c3 @defunkt find at point
defunkt authored
85 (load defunkt))))
86
c8227bd @defunkt backward kill line
defunkt authored
87 (defun defunkt-backward-kill-line ()
88 (interactive)
89 (kill-line 0))
90
5c15c13 @defunkt add my own version of inc/dec at point
defunkt authored
91 (require 'thingatpt)
92 (defun defunkt-change-num-at-point (fn)
93 (let* ((num (string-to-number (thing-at-point 'word)))
94 (bounds (bounds-of-thing-at-point 'word)))
95 (save-excursion
96 (goto-char (car bounds))
97 (defunkt-kill-word 1)
98 (insert (number-to-string (funcall fn num 1))))))
99
100 (defun defunkt-inc-num-at-point ()
101 (interactive)
102 (defunkt-change-num-at-point '+))
103
104 (defun defunkt-dec-num-at-point ()
105 (interactive)
56161d0 @defunkt throw it all in defuns for now
defunkt authored
106 (defunkt-change-num-at-point '-))
107
108 (defun url-fetch-into-buffer (url)
109 (interactive "sURL:")
110 (insert (concat "\n\n" ";; " url "\n"))
111 (insert (url-fetch-to-string url)))
112
113 (defun url-fetch-to-string (url)
114 (with-current-buffer (url-retrieve-synchronously url)
115 (beginning-of-buffer)
116 (search-forward-regexp "\n\n")
117 (delete-region (point-min) (point))
118 (buffer-string)))
119
55984ef @defunkt allow gist-buffer-preview to accept prefix
defunkt authored
120 (defun gist-buffer-confirm (&optional private)
121 (interactive "P")
53d2757 @defunkt whitespace
defunkt authored
122 (when (yes-or-no-p "Are you sure you want to Gist this buffer? ")
55984ef @defunkt allow gist-buffer-preview to accept prefix
defunkt authored
123 (gist-region-or-buffer private)))
e2ccccc @defunkt confirm before gisting buffer
defunkt authored
124
53d2757 @defunkt whitespace
defunkt authored
125 (defun defunkt-clean-slate ()
126 "Kills all buffers except *scratch*"
127 (interactive)
128 (let ((buffers (buffer-list)) (safe '("*scratch*")))
2421349 @defunkt simpler sanity check
defunkt authored
129 (while buffers
9123822 @defunkt add `defunkt-clean-slate` for clearing all buffers except scratch
defunkt authored
130 (when (not (member (car buffers) safe))
53d2757 @defunkt whitespace
defunkt authored
131 (kill-buffer (car buffers))
132 (setq buffers (cdr buffers))))))
133
134 (defun defunkt/c-electric-brace (arg)
135 "Inserts a closing curly, too."
136 (interactive "*P")
137 (c-electric-brace arg)
138 (save-excursion
139 (insert "\n")
140 (insert "}")
141 (indent-according-to-mode)))
d1e02ad @defunkt add a closing } when inserting an opening { in C
defunkt authored
142
56161d0 @defunkt throw it all in defuns for now
defunkt authored
143 ;; from http://platypope.org/blog/2007/8/5/a-compendium-of-awesomeness
144 ;; I-search with initial contents
145 (defvar isearch-initial-string nil)
146
147 (defun isearch-set-initial-string ()
148 (remove-hook 'isearch-mode-hook 'isearch-set-initial-string)
149 (setq isearch-string isearch-initial-string)
150 (isearch-search-and-update))
151
152 (defun isearch-forward-at-point (&optional regexp-p no-recursive-edit)
153 "Interactive search forward for the symbol at point."
154 (interactive "P\np")
155 (if regexp-p (isearch-forward regexp-p no-recursive-edit)
156 (let* ((end (progn (skip-syntax-forward "w_") (point)))
157 (begin (progn (skip-syntax-backward "w_") (point))))
158 (if (eq begin end)
159 (isearch-forward regexp-p no-recursive-edit)
160 (setq isearch-initial-string (buffer-substring begin end))
161 (add-hook 'isearch-mode-hook 'isearch-set-initial-string)
53d2757 @defunkt whitespace
defunkt authored
162 (isearch-forward regexp-p no-recursive-edit)))))
Something went wrong with that request. Please try again.