Skip to content
Newer
Older
100644 261 lines (229 sloc) 8.55 KB
7d6a2ca @chalmagean Update
authored
1 (defun my-goto-match-beginning ()
2 (when (and isearch-forward isearch-other-end)
3 (goto-char isearch-other-end)))
4 (add-hook 'isearch-mode-end-hook 'my-goto-match-beginning)
5 (defadvice isearch-exit (after my-goto-match-beginning activate)
6 "Go to beginning of match."
7 (when (and isearch-forward isearch-other-end)
8 (goto-char isearch-other-end)))
9
10 ;; Search back/forth for the symbol at point
11 ;; See http://www.emacswiki.org/emacs/SearchAtPoint
12 (defun isearch-yank-symbol ()
13 "*Put symbol at current point into search string."
14 (interactive)
15 (let ((sym (symbol-at-point)))
16 (if sym
17 (progn
18 (setq isearch-regexp t
19 isearch-string (concat "\\_<" (regexp-quote (symbol-name sym)) "\\_>")
20 isearch-message (mapconcat 'isearch-text-char-description isearch-string "")
21 isearch-yank-flag t))
22 (ding)))
23 (isearch-search-and-update))
24
25 (define-key isearch-mode-map "\C-w" 'isearch-yank-symbol)
26
27 ;; http://www.emacswiki.org/emacs/ZapToISearch
28 (defun zap-to-isearch (rbeg rend)
29 "Kill the region between the mark and the closest portion of
30 the isearch match string. The behaviour is meant to be analogous
31 to zap-to-char; let's call it zap-to-isearch. The deleted region
32 does not include the isearch word. This is meant to be bound only
33 in isearch mode. The point of this function is that oftentimes
34 you want to delete some portion of text, one end of which happens
35 to be an active isearch word. The observation to make is that if
36 you use isearch a lot to move the cursor around (as you should,
37 it is much more efficient than using the arrows), it happens a
38 lot that you could just delete the active region between the mark
39 and the point, not include the isearch word."
a09ae69 @chalmagean Added custom functions
authored
40 (interactive "r")
7d6a2ca @chalmagean Update
authored
41 (when (not mark-active)
42 (error "Mark is not active"))
43 (let* ((isearch-bounds (list isearch-other-end (point)))
44 (ismin (apply 'min isearch-bounds))
45 (ismax (apply 'max isearch-bounds))
46 )
47 (if (< (mark) ismin)
48 (kill-region (mark) ismin)
49 (if (> (mark) ismax)
50 (kill-region ismax (mark))
51 (error "Internal error in isearch kill function.")))
52 (isearch-exit)
53 ))
54
55 (define-key isearch-mode-map [(meta z)] 'zap-to-isearch)
a09ae69 @chalmagean Added custom functions
authored
56
57 (defun find-tag-at-point ()
58 "Runs find-tag with the word at point as the argument"
59 (interactive)
60 (find-tag
61 (funcall
62 (or
63 find-tag-default-function
64 (get major-mode 'find-tag-default-function)
65 'find-tag-default))))
66
67 (defun push-mark-no-activate ()
68 "Pushes `point' to `mark-ring' and does not activate the region
69 Equivalent to \\[set-mark-command] when \\[transient-mark-mode] is disabled"
70 (interactive)
71 (push-mark (point) t nil)
72 (message "Pushed mark to ring"))
73 (global-set-key (kbd "C-`") 'push-mark-no-activate)
74
75 (defun jump-to-mark ()
76 "Jumps to the local mark, respecting the `mark-ring' order.
77 This is the same as using \\[set-mark-command] with the prefix argument."
78 (interactive)
79 (set-mark-command 1))
80 (global-set-key (kbd "M-`") 'jump-to-mark)
81
82 (defun exchange-point-and-mark-no-activate ()
83 "Identical to \\[exchange-point-and-mark] but will not activate the region."
84 (interactive)
85 (exchange-point-and-mark)
86 (deactivate-mark nil))
87 (define-key global-map [remap exchange-point-and-mark] 'exchange-point-and-mark-no-activate)
88
89 (defun vi-open-line-above ()
90 "Insert a newline above the current line and put point at beginning."
91 (interactive)
92 (unless (bolp)
93 (beginning-of-line))
94 (newline)
95 (forward-line -1)
96 (indent-according-to-mode))
97
98 (defun vi-open-line-below ()
99 "Insert a newline below the current line and put point at beginning."
100 (interactive)
101 (unless (eolp)
102 (end-of-line))
103 (newline-and-indent))
104
105 ;; Kills live buffers, leaves some emacs work buffers
106 ;; optained from http://www.chrislott.org/geek/emacs/dotemacs.html
107 (defun nuke-all-buffers (&optional list)
108 "For each buffer in LIST, kill it silently if unmodified. Otherwise ask.
109 LIST defaults to all existing live buffers."
110 (interactive)
111 (if (null list)
112 (setq list (buffer-list)))
113 (while list
114 (let* ((buffer (car list))
115 (name (buffer-name buffer)))
116 (and (not (string-equal name ""))
117 (not (string-equal name "*Messages*"))
118 (not (string-equal name "*scratch*"))
119 (/= (aref name 0) ? )
120 (kill-buffer buffer)))
121 (setq list (cdr list))))
122
123 (defun duplicate-line()
124 (interactive)
125 (move-beginning-of-line 1)
126 (kill-line)
127 (yank)
128 (open-line 1)
129 (next-line 1)
130 (yank))
131
132 (defun rotate-windows ()
133 "Rotate your windows"
134 (interactive)
135 (cond ((not (> (count-windows)1))
136 (message "You can't rotate a single window!"))
137 (t
138 (setq i 1)
139 (setq numWindows (count-windows))
140 (while (< i numWindows)
141 (let* (
142 (w1 (elt (window-list) i))
143 (w2 (elt (window-list) (+ (% i numWindows) 1)))
144
145 (b1 (window-buffer w1))
146 (b2 (window-buffer w2))
147
148 (s1 (window-start w1))
149 (s2 (window-start w2))
150 )
151 (set-window-buffer w1 b2)
152 (set-window-buffer w2 b1)
153 (set-window-start w1 s2)
154 (set-window-start w2 s1)
155 (setq i (1+ i)))))))
156
157 (defun unword (start end)
158 (interactive "r")
159 (save-excursion
160 (save-restriction
161 (narrow-to-region start end)
162 (goto-char (point-min))
163 (replace-string "" "\"")
164 (goto-char (point-min))
165 (replace-string "" "\"")
166 (goto-char (point-min))
167 (replace-string "" "'")
168 (goto-char (point-min))
169 (replace-string "" "-")
170 (goto-char (point-min))
171 (replace-string "" "")
172 (goto-char (point-min))
173 (replace-string "" "&#x2122;")
174 (goto-char (point-min))
175 (replace-string "²" "&#x00b2;")
176 )))
177
178 (defun add-to-loadpath (&rest dirs)
179 (dolist (dir dirs load-path)
180 (add-to-list 'load-path (expand-file-name dir) nil #'string=)))
181
182 (defun smart-kill-whole-line (&optional arg)
183 "A simple wrapper around `kill-whole-line' that respects indentation."
184 (interactive "P")
185 (kill-whole-line arg)
186 (back-to-indentation))
187
188 (autoload 'zap-up-to-char "misc"
189 "Kill up to, but not including ARGth occurrence of CHAR.
190
191 \(fn arg char)"
192 'interactive)
193
194 ;; Tags
195 (setq tags-case-fold-search nil)
196
197 (defun visit-project-tags ()
198 (interactive)
199 (let ((tags-file (concat (eproject-root) "TAGS")))
200 (visit-tags-table tags-file)
201 (message (concat "Loaded " tags-file))))
202
203 (defun build-ctags ()
204 (interactive)
205 (message "building project tags")
206 (let ((default-directory (eproject-root)))
4e2eadd @chalmagean Updates
authored
207 (shell-command (concat "exctags -e -R --extra=+fq --exclude=db --exclude=test --exclude=.git --exclude=public -f TAGS * " (s-trim (shell-command-to-string "rvm gemdir")) "/gems/*"))
a09ae69 @chalmagean Added custom functions
authored
208 (visit-project-tags)
209 (message "tags built successfully")))
210
211 (defun my-find-tag ()
212 (interactive)
213 (if (file-exists-p (concat (eproject-root) "TAGS"))
214 (visit-project-tags)
215 (build-ctags))
216 (etags-select-find-tag-at-point))
217
218 ;; Load the tags file without asking
219 (setq tags-revert-without-query 1)
220
bf9f4df @chalmagean Updates
authored
221 (defun toggle-frame-split ()
222 "If the frame is split vertically, split it horizontally or vice versa.
223 Assumes that the frame is only split into two."
224 (interactive)
225 (unless (= (length (window-list)) 2) (error "Can only toggle a frame split in two"))
226 (let ((split-vertically-p (window-combined-p)))
227 (delete-window) ; closes current window
228 (if split-vertically-p
229 (split-window-horizontally)
230 (split-window-vertically)) ; gives us a split with the other window twice
231 (switch-to-buffer nil))) ; restore the original window in this part of the frame
232
4e2eadd @chalmagean Updates
authored
233 (defun git-extract-number-from-branch-name ()
e597472 @chalmagean More stuff
authored
234 (interactive)
235 (let ((current-branch-name (magit-get-current-branch)))
b00e682 @chalmagean Update
authored
236 (progn (string-match "\\([0-9A-Za-z]+\\)" current-branch-name)
e597472 @chalmagean More stuff
authored
237 (insert (concat "[#" (match-string 1 current-branch-name) "] ")))))
3c3fdb8 @chalmagean Updates and configs
authored
238
239 (defun ignore-error-wrapper (fn)
240 "Funtion return new function that ignore errors.
241 The function wraps a function with `ignore-errors' macro."
242 (lexical-let ((fn fn))
243 (lambda ()
244 (interactive)
245 (ignore-errors
246 (funcall fn)))))
247
f761447 @chalmagean Updates
authored
248
249 ;; Use M-x list-processes to get the running processes list
250 ;;(define-key process-menu-mode-map (kbd "C-k") 'joaot/delete-process-at-point)
251
252 (defun joaot/delete-process-at-point ()
253 (interactive)
254 (let ((process (get-text-property (point) 'tabulated-list-id)))
255 (cond ((and process
256 (processp process))
257 (delete-process process)
258 (revert-buffer))
259 (t
260 (error "no process at point!")))))
Something went wrong with that request. Please try again.