jj-open-shell opens a new xterm in the directory of my current buffer
[emacs.git] / .emacs.d / elisp / local / ganneff.el
1 ;;; ganneff1.el --- Some functions and stuff I use
2
3 ;;; Copyright (C) 2012.2013 Joerg Jaspert
4
5 ;; Filename: ganneff.de
6 ;; Author: Joerg Jaspert <joerg@debian.org>
7
8 ;;; Commentary:
9 ;; This is just stuff I use in my emacs configuration.
10
11 ;;; Code:
12
13 ;;;###autoload
14 (defun my-dired-init ()
15 "Bunch of stuff to run for dired when it's loaded."
16 (define-key dired-mode-map [return] 'dired-single-buffer)
17 (define-key dired-mode-map [mouse-1] 'dired-single-buffer-mouse)
18 (define-key dired-mode-map "r" 'wdired-change-to-wdired-mode)
19 (define-key dired-mode-map "^"
20 (function
21 (lambda nil (interactive) (dired-single-buffer "..")))))
22
23 ;;;###autoload
24 (defun ido-disable-line-trucation () (set (make-local-variable 'truncate-lines) nil))
25
26
27 ;;;###autoload
28 (defun sacha/isearch-yank-current-word ()
29 "Pull current word from buffer into search string."
30 (interactive)
31 (save-excursion
32 (skip-syntax-backward "w_")
33 (isearch-yank-internal
34 (lambda ()
35 (skip-syntax-forward "w_")
36 (point)))))
37
38 ;;;###autoload
39 (defun sacha/search-word-backward ()
40 "Find the previous occurrence of the current word."
41 (interactive)
42 (let ((cur (point)))
43 (skip-syntax-backward "w_")
44 (goto-char
45 (if (re-search-backward (concat "\\_<" (current-word) "\\_>") nil t)
46 (match-beginning 0)
47 cur))))
48
49 ;;;###autoload
50 (defun sacha/search-word-forward ()
51 "Find the next occurrance of the current word."
52 (interactive)
53 (let ((cur (point)))
54 (skip-syntax-forward "w_")
55 (goto-char
56 (if (re-search-forward (concat "\\_<" (current-word) "\\_>") nil t)
57 (match-beginning 0)
58 cur))))
59
60 ;;;###autoload
61 (defun sacha/increase-font-size ()
62 (interactive)
63 (set-face-attribute 'default
64 nil
65 :height
66 (ceiling (* 1.10
67 (face-attribute 'default :height)))))
68 ;;;###autoload
69 (defun sacha/decrease-font-size ()
70 (interactive)
71 (set-face-attribute 'default
72 nil
73 :height
74 (floor (* 0.9
75 (face-attribute 'default :height)))))
76
77 ;;;###autoload
78 (defun epa-dired-mode-hook ()
79 (define-key dired-mode-map ":" 'epa-dired-prefix))
80
81 ;;;###autoload
82 (defun my-c-return ()
83 "When in minibuffer use `icicle-candidate-action', otherwise use `cua-set-rectangle-mark'."
84 (interactive)
85 (if (window-minibuffer-p (selected-window))
86 (call-interactively 'icicle-candidate-action)
87 (call-interactively 'cua-set-rectangle-mark)))
88
89 ;;; define filter. The filter is called on each entry in the agenda.
90 ;;; It defines a regexp to search for two timestamps, gets the start
91 ;;; and end point of the entry and does a regexp search. It also
92 ;;; checks if the category of the entry is in an exclude list and
93 ;;; returns either t or nil to skip or include the entry.
94
95 ;;;###autoload
96 (defun revert-all-buffers ()
97 "Refreshes all open buffers from their respective files."
98 (interactive)
99 (dolist (buf (buffer-list))
100 (with-current-buffer buf
101 (when (and (buffer-file-name) (not (buffer-modified-p)) (file-exists-p (buffer-file-name)))
102 (revert-buffer t t t) )))
103 (message "Refreshed open files.") )
104
105 ;;;###autoload
106 (defun move-line-up ()
107 "Move up the current line."
108 (interactive)
109 (transpose-lines 1)
110 (forward-line -2)
111 (indent-according-to-mode))
112
113 ;;;###autoload
114 (defun move-line-down ()
115 "Move down the current line."
116 (interactive)
117 (forward-line 1)
118 (transpose-lines 1)
119 (forward-line -1)
120 (indent-according-to-mode))
121
122 ;;;###autoload
123 (defun jj-untabify-buffer ()
124 "Get rid of all tabs"
125 (interactive)
126 (untabify (point-min) (point-max)))
127
128 ;;;###autoload
129 (defun prelude-sudo-edit (&optional arg)
130 "Edit currently visited file as root.
131
132 With a prefix ARG prompt for a file to visit.
133 Will also prompt for a file to visit if current
134 buffer is not visiting a file."
135 (interactive "P")
136 (if (or arg (not buffer-file-name))
137 (find-file (concat "/sudo:root@localhost:"
138 (icicle-find-file-of-content)))
139 (find-alternate-file (concat "/sudo:root@localhost:" buffer-file-name))))
140
141 ;; a great lisp coding hook
142 ;;;###autoload
143 (defun lisp-coding-defaults ()
144 (paredit-mode +1)
145 (rainbow-delimiters-mode +1))
146
147 ;;;###autoload
148 (defun interactive-lisp-coding-defaults ()
149 (paredit-mode +1)
150 (rainbow-delimiters-mode +1)
151 (whitespace-mode -1))
152
153 ;;;###autoload
154 (defun prelude-remove-elc-on-save ()
155 "If you're saving an elisp file, likely the .elc is no longer valid."
156 (make-local-variable 'after-save-hook)
157 (add-hook 'after-save-hook
158 (lambda ()
159 (if (file-exists-p (concat buffer-file-name "c"))
160 (delete-file (concat buffer-file-name "c"))))))
161
162 ;;;###autoload
163 (defun prelude-emacs-lisp-mode-defaults ()
164 (run-hooks 'lisp-coding-hook)
165 (turn-on-eldoc-mode)
166 (prelude-remove-elc-on-save)
167 (rainbow-mode +1)
168 (setq mode-name "EL"))
169
170 ;;;###autoload
171 (defun clean-mode-line ()
172 (interactive)
173 (loop for cleaner in mode-line-cleaner-alist
174 do (let* ((mode (car cleaner))
175 (mode-str (cdr cleaner))
176 (old-mode-str (cdr (assq mode minor-mode-alist))))
177 (when old-mode-str
178 (setcar old-mode-str mode-str))
179 ;; major mode
180 (when (eq mode major-mode)
181 (setq mode-name mode-str)))))
182
183 ;;;###autoload
184 (defun force-backup-of-buffer ()
185 (let ((buffer-backed-up nil))
186 (backup-buffer)))
187
188 ;;;###autoload
189 (defun prelude-kill-other-buffers ()
190 "Kill all buffers but the current one.
191 Doesn't mess with special buffers."
192 (interactive)
193 (require 'dash)
194 (-each
195 (->> (buffer-list)
196 (-filter #'buffer-file-name)
197 (--remove (eql (current-buffer) it)))
198 #'kill-buffer))
199
200 ;;;###autoload
201 (defun just-one-space-with-newline ()
202 "Call just-one-space with a negative argument"
203 (interactive)
204 (just-one-space -1))
205
206 ;(setq org-icalendar-verify-function 'org-mycal-export-limit)
207 ;(org-export-icalendar-combine-agenda-files)
208
209
210 ;;;###autoload
211 (defun font-lock-comment-annotations ()
212 "Highlight a bunch of well known comment annotations.
213
214 This functions should be added to the hooks of major modes for programming."
215 (font-lock-add-keywords
216 nil '(("\\<\\(FIX\\(ME\\)?\\|TODO\\|OPTIMIZE\\|HACK\\|REFACTOR\\):"
217 1 font-lock-warning-face t))))
218
219 ;;;###autoload
220 (defun jj-open-shell ()
221 "Open a shell in the directory of the current buffer file"
222
223 (interactive)
224 (when buffer-file-name
225 (setenv "ZSTARTDIR" (file-truename buffer-file-name)))
226 (when dired-directory
227 (message dired-directory)
228 (setenv "ZSTARTDIR" (concat (file-truename dired-directory) "/dired")))
229 (start-process "yay" nil "/usr/bin/x-terminal-emulator"))
230
231 (provide 'ganneff)
232
233 ;;; ganneff.el ends here