71f3a9fccacb6cf83392947b3bdf6c7c201f8b8d
[emacs.git] / .emacs.d / config / emacs.org
1 #+TITLE: emacs.org - Ganneffs emacs configuration
2 #+DESCRIPTION: My current Emacs configuration
3 #+KEYWORDS: org-mode Emacs configuration
4 #+STARTUP: align fold nodlcheck hidestars oddeven lognotestate
5 #+SETUPFILE: ~/.emacs.d/elisp/org-templates/level-0.org
6 #+LATEX_CMD: xelatex
7
8 * Basic config
9 ** General functions
10 :PROPERTIES:
11 :ID: b6e6cf73-9802-4a7b-bd65-fdb6f9745319
12 :END:
13 The following functions are used throughout my config, and so I load
14 them first.
15 *** safe-load
16 safe-load does not break emacs initialization, should a file be
17 unreadable while emacs boots up.
18 #+BEGIN_SRC emacs-lisp :tangle yes
19 (defvar safe-load-error-list ""
20 "*List of files that reported errors when loaded via safe-load")
21
22 (defun safe-load (file &optional noerror nomessage nosuffix)
23 "Load a file. If error on load, report back, wait for
24 a key stroke then continue on"
25 (interactive "f")
26 (condition-case nil (load file noerror nomessage nosuffix)
27 (error
28 (progn
29 (setq safe-load-error-list (concat safe-load-error-list " " file))
30 (message "****** [Return to continue] Error loading %s" safe-load-error-list )
31 (sleep-for 1)
32 nil))))
33
34 (defun safe-load-check ()
35 "Check for any previous safe-load loading errors. (safe-load.el)"
36 (interactive)
37 (if (string-equal safe-load-error-list "") ()
38 (message (concat "****** error loading: " safe-load-error-list))))
39 #+END_SRC
40 *** Local autoloads
41 I have some stuff put away in my local dir. I don't want to load it all
42 at startup time, so it is using the autoload feature. For that to work
43 load the loaddefs, so autoload knows where to grab stuff
44 #+BEGIN_SRC emacs-lisp :tangle yes
45 (safe-load (concat jj-elisp-dir "/tiny/loaddefs.el"))
46 (safe-load (concat jj-elisp-local-dir "/loaddefs.el"))
47 #+END_SRC
48 *** Keep *scratch* around
49 Always ensure to have a scratch buffer around.
50 #+BEGIN_SRC emacs-lisp :tangle yes
51 (with-current-buffer (get-buffer-create "*scratch*")
52 (lisp-interaction-mode)
53 (make-local-variable 'kill-buffer-query-functions)
54 (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer))
55 #+END_SRC
56 *** add-auto-mode
57 Handier way to add modes to auto-mode-alist
58 #+BEGIN_SRC emacs-lisp :tangle yes
59 (defun add-auto-mode (mode &rest patterns)
60 "Add entries to `auto-mode-alist' to use `MODE' for all given file `PATTERNS'."
61 (dolist (pattern patterns)
62 (add-to-list 'auto-mode-alist (cons pattern mode))))
63 #+END_SRC
64 *** config helpers use-package/bind-key
65 Helpers for the config
66 https://github.com/jwiegley/use-package
67 #+BEGIN_SRC emacs-lisp :tangle yes
68 (require 'use-package)
69 (require 'bind-key)
70 #+END_SRC
71 *** hook-into-modes
72 [2014-05-20 Tue 22:36]
73 #+BEGIN_SRC emacs-lisp :tangle yes
74 (defmacro hook-into-modes (func modes)
75 `(dolist (mode-hook ,modes)
76 (add-hook mode-hook ,func)))
77 #+END_SRC
78
79 *** elpa
80 The Emacs Lisp Package Archive contains things I want.
81 #+BEGIN_SRC emacs-lisp :tangle yes
82 (when (> emacs-major-version 23)
83 (require 'package)
84 (setq package-user-dir (expand-file-name "elpa" jj-elisp-dir))
85 (package-initialize)
86 (add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
87 (add-to-list 'package-archives '("melpa-stable" . "http://melpa-stable.milkbox.net/packages/"))
88 (add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
89 (add-to-list 'package-archives '("elpy" . "http://jorgenschaefer.github.io/packages/"))
90 (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/"))
91 )
92 #+END_SRC
93
94 ** Path settings
95 *** Load path
96 We need to define the load-path. As I have lots of things I add
97 locally, its getting a few entries. I only leave out org-mode here, as
98 that is already done in =init.el=.
99
100 I also disliked the repeated /add-to-list/ lines, so I now just have
101 one variable and go over that in a loop.
102 #+BEGIN_SRC emacs-lisp :tangle yes
103 (defvar jj-elisp-subdirs '(local gnus icicle org/contrib tiny mo-git-blame cedet
104 cedet/eieio ecb jdee/lisp sunrise multiple-cursors
105 auto-complete yasnippet magit mmm emms/lisp
106 elpy find-file-in-project fuzzy idomenu nose
107 popup pyvenv git-rebase-mode git-commit-mode)
108 "List of subdirectories in jj-elisp-dir to add to load-path")
109
110 (let (dirval)
111 (dolist (dirval jj-elisp-subdirs)
112 (let ((name (expand-file-name (symbol-name dirval) jj-elisp-dir)))
113 (when (file-exists-p name)
114 (add-to-list 'load-path name)))))
115 ;; For older emacsen we need an extra directory, which should be at
116 ;; THE END of the load path
117 (when (version< emacs-version "24")
118 (add-to-list 'load-path (expand-file-name "emacs23" jj-elisp-dir) t))
119
120 #+END_SRC
121
122 *** Info path
123 Help emacs to find the info files
124 #+BEGIN_SRC emacs-lisp :tangle no
125 (setq Info-directory-list '("~/emacs/info"
126 "/usr/local/share/info/"
127 "/usr/local/info/"
128 "/usr/local/gnu/info/"
129 "/usr/local/gnu/lib/info/"
130 "/usr/local/gnu/lib/emacs/info/"
131 "/usr/local/emacs/info/"
132 "/usr/local/lib/info/"
133 "/usr/local/lib/emacs/info/"
134 "/usr/share/info/emacs-23"
135 "/usr/share/info/"
136 "/usr/share/info/"))
137 (setq Info-default-directory-list
138 (cons "~/emacs/info" Info-default-directory-list))
139 #+END_SRC
140
141 ** Interface related
142 *** General stuff
143 :PROPERTIES:
144 :ID: 0a1560d9-7e55-47ab-be52-b3a8b8eea4aa
145 :END:
146 I dislike the startup message
147 #+BEGIN_SRC emacs-lisp :tangle yes
148 (setq inhibit-splash-screen t)
149 (setq inhibit-startup-message t)
150 #+END_SRC
151
152 Usually I want the lines to break at 72 characters.
153 #+BEGIN_SRC emacs-lisp :tangle yes
154 (setq fill-column 72)
155 #+END_SRC
156
157 And it is nice to have a final newline in files.
158 #+BEGIN_SRC emacs-lisp :tangle yes
159 (setq require-final-newline t)
160 #+END_SRC
161
162 After I typed 300 characters or took a break for more than a minute it
163 would be nice of emacs to save whatever I am on in one of its auto-save
164 backups. See [[info:emacs#Auto%20Save%20Control][info:emacs#Auto Save Control]] for more details.
165 #+BEGIN_SRC emacs-lisp :tangle yes
166 (setq auto-save-interval 300)
167 (setq auto-save-timeout 60)
168 #+END_SRC
169
170 Set my full name and my default mail address - for whatever wants to use
171 it later. Also, I am using gnus.
172 #+BEGIN_SRC emacs-lisp :tangle yes
173 (setq user-full-name "Joerg Jaspert")
174 (setq user-mail-address "joerg@ganneff.de")
175 (setq mail-user-agent (quote gnus-user-agent))
176 #+END_SRC
177
178 My default mail server. Well, simply a localhost, I have a forwarder that
179 puts mail off the right way, no need for emacs to have any further
180 knowledge here.
181 #+BEGIN_SRC emacs-lisp :tangle yes
182 (setq smtpmail-default-smtp-server "localhost")
183 (setq smtpmail-smtp-server "localhost")
184 #+END_SRC
185
186 Enable automatic handling of compressed files.
187 #+BEGIN_SRC emacs-lisp :tangle yes
188 (auto-compression-mode 1)
189 #+END_SRC
190
191 Emacs forbids a certain set of commands, as they can be very confusing
192 for new users. Enable them.
193 #+BEGIN_SRC emacs-lisp :tangle yes
194 (put 'narrow-to-region 'disabled nil)
195 (put 'narrow-to-page 'disabled nil)
196 (put 'narrow-to-defun 'disabled nil)
197 (put 'upcase-region 'disabled nil)
198 (put 'downcase-region 'disabled nil)
199 #+END_SRC
200
201 *** Look / Theme
202 I've tried various different fonts and while I like the Terminus font
203 most for my shells, in Emacs Inconsolata clearly wins.
204 #+BEGIN_SRC emacs-lisp :tangle yes
205 (set-frame-font "Inconsolata-14")
206 #+END_SRC
207
208 I always use dark backgrounds, so tell Emacs about it. No need to
209 guess around.
210 #+BEGIN_SRC emacs-lisp :tangle yes
211 (setq-default frame-background-mode jj-color-style)
212 #+END_SRC
213
214 And I always liked dark backgrounds with colors setup for them. So I
215 switched through multiple themes doing it in emacs too, but never
216 entirely liked it. Until I found solarized, which is now not only my
217 emacs theme, but also for most of my other software too, especially my
218 shell. Consistent look is great.
219 #+BEGIN_SRC emacs-lisp :tangle no
220 (if (or (> emacs-major-version 23) (boundp 'custom-theme-load-path))
221 (progn
222 (defun jj-init-theme ()
223 (interactive)
224 (if (eq jj-color-style 'dark )(load-theme 'solarized-dark t)
225 (load-theme 'solarized-light t))
226 (set-face-attribute 'org-date nil :underline nil)
227 (message "Initializing theme solarized-dark")
228 )
229 (add-to-list 'custom-theme-load-path jj-theme-dir)
230 (add-hook 'after-init-hook 'jj-init-theme)
231 )
232 (add-to-list 'load-path (expand-file-name "emacs-color-theme-solarized" jj-elisp-dir))
233 (require 'color-theme-solarized)
234 (color-theme-solarized-dark)
235 )
236 #+END_SRC
237 #+BEGIN_SRC emacs-lisp :tangle yes
238 (use-package solarized
239 :load-path "elisp/emacs-color-theme-solarized"
240 :init
241 (progn
242 (defun jj-init-theme ()
243 (interactive)
244 (if (eq jj-color-style 'dark )(load-theme 'solarized-dark t)
245 (load-theme 'solarized-light t))
246 (set-face-attribute 'org-date nil :underline nil)
247 (message "Initializing theme solarized-dark")
248 )
249 (add-to-list 'custom-theme-load-path jj-theme-dir)
250 (add-hook 'after-init-hook 'jj-init-theme)
251 (jj-init-theme)))
252 #+END_SRC
253
254 Make the fringe (gutter) smaller, the argument is a width in pixels (the default is 8)
255 #+BEGIN_SRC emacs-lisp :tangle yes
256 (if (fboundp 'fringe-mode)
257 (fringe-mode 8))
258 #+END_SRC
259
260 A bit more spacing between buffer lines
261 #+BEGIN_SRC emacs-lisp :tangle yes
262 (setq-default line-spacing 0.1)
263 #+END_SRC
264 *** Cursor changes
265 [2013-04-21 So 20:54]
266 I do not want my cursor to blink.
267 #+BEGIN_SRC emacs-lisp :tangle yes
268 (blink-cursor-mode -1)
269 #+END_SRC
270 *** Menu, Tool and Scrollbar
271 I don't want to see the menu-bar, tool-bar or scrollbar.
272 #+BEGIN_SRC emacs-lisp :tangle yes
273 (when window-system
274 (menu-bar-mode -1)
275 (tool-bar-mode -1)
276 (set-scroll-bar-mode nil))
277 #+END_SRC
278 **** When using emacs in daemon mode
279 Emacs has a very nice mode where it detaches itself and runs as daemon -
280 and you can just open /frames/ (windows) from it by using [[http://www.emacswiki.org/emacs/EmacsClient][Emacs
281 Client]]. It's fast, it's nice, it's convinient.
282
283 Except that Emacs behaves stupid when you do that and ignores your
284 menu/tool/scrollbar settings. Sucks.
285
286 For them to work even then, we have to do two things.
287 1. We have to set the frame alist. We simple set both,
288 =initial-frame-alist= and =default-frame-alist= to the same value here.
289 #+BEGIN_SRC emacs-lisp :tangle yes
290 (setq initial-frame-alist '(
291 (horizontal-scroll-bars . nil)
292 (vertical-scroll-bars . nil)
293 (menu-bar-lines . 0)
294 ))
295 (setq default-frame-alist (copy-alist initial-frame-alist))
296 #+END_SRC
297 2. We have to disable the toolbar using the customize interface, so you
298 can find that in the [[id:0102208d-fdf6-4928-9e40-7e341bd3aa3a][Customized variables]] section.
299
300 *** Hilight current line in buffer
301 As it says, it does a hilight of the current line.
302 #+BEGIN_SRC emacs-lisp :tangle yes
303 (global-hl-line-mode +1)
304 #+END_SRC
305 *** Allow recursive minibuffers
306 This allows (additional) minibuffer commands while in the minibuffer.
307 #+BEGIN_SRC emacs-lisp :tangle yes
308 (setq enable-recursive-minibuffers 't)
309 #+END_SRC
310
311 *** Modeline related changes
312 I want to see line and column numbers, so turn them on.
313 Size indication lets me know how far I am in a buffer.
314
315 And modeline-posn is great. It will hilight the column number in the
316 modeline in red as soon as you are over the defined limit.
317
318 #+BEGIN_SRC emacs-lisp :tangle yes
319 (line-number-mode 1)
320 (column-number-mode 1)
321 (size-indication-mode 1)
322 (display-time-mode 1)
323 (setq display-time-day-and-date nil)
324 (setq display-time-24hr-format t)
325 (setq modelinepos-column-limit 72)
326
327 (use-package modeline-posn
328 :ensure modeline-posn
329 :config
330 (progn
331 (set-face-foreground 'modelinepos-column-warning "grey20")
332 (set-face-background 'modelinepos-column-warning "red")
333 (setq modelinepos-column-limit 72))
334 )
335 #+END_SRC
336
337 **** diminish
338 [2013-04-22 Mon 11:27]
339 The modeline is easily cluttered up with stuff I don't really need to
340 see. So lets hide those. There are two ways, one of them uses diminish
341 to get entirely rid of some modes, the other is a function taken from
342 "Mastering Emacs" which replaces the modes text with an own (set of)
343 character(s).
344 #+BEGIN_SRC emacs-lisp :tangle yes
345 (require 'diminish)
346 (diminish 'auto-fill-function)
347 (defvar mode-line-cleaner-alist
348 `((auto-complete-mode . " α")
349 (yas-minor-mode . " y")
350 (paredit-mode . " π")
351 (eldoc-mode . "")
352 (abbrev-mode . "")
353 ;; Major modes
354 (lisp-interaction-mode . "λ")
355 (hi-lock-mode . "")
356 (python-mode . "Py")
357 (emacs-lisp-mode . "EL")
358 (org-mode . "Ω")
359 (org-indent-mode . "")
360 (sh-mode . " Σ")
361 (nxhtml-mode . "nx"))
362
363 "Alist for `clean-mode-line'.
364
365 When you add a new element to the alist, keep in mind that you
366 must pass the correct minor/major mode symbol and a string you
367 want to use in the modeline *in lieu of* the original.
368
369 Want some symbols? Go:
370
371 ;ςερτζθιοπασδφγηξκλυχψωβνμ
372 :ΣΕΡΤΖΘΙΟΠΑΣΔΦΓΗΞΚΛΥΧΨΩΒΝΜ
373 @ł€¶ŧ←↓→øþ¨~æſðđŋħ̣ĸł˝^`|»«¢„“”µ·…
374 ☃⌕☥
375 ")
376
377 (add-hook 'after-change-major-mode-hook 'clean-mode-line)
378
379 #+END_SRC
380 Unfortunately icicles breaks this with the way it adds/removes itself,
381 so take it our for now...
382
383 *** Default mode
384 Back when I started with text-mode. But nowadays I want default mode to
385 be org-mode - it is just so much better to use. And does sensible things
386 with many README files out there, and various other "crap" you get to
387 read in emacs.
388 #+BEGIN_SRC emacs-lisp :tangle yes
389 (setq major-mode 'org-mode)
390 (setq initial-major-mode 'org-mode)
391 #+END_SRC
392
393 *** Shell
394 [2013-04-23 Tue 16:43]
395 Shell. zsh in my case.
396 #+BEGIN_SRC emacs-lisp :tangle yes
397 (setq shell-file-name "zsh")
398 (setq shell-command-switch "-c")
399 (setq explicit-shell-file-name shell-file-name)
400 (setenv "SHELL" shell-file-name)
401 (setq explicit-sh-args '("-login" "-i"))
402 (add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
403 (setq comint-scroll-to-bottom-on-input t) ; always insert at the bottom
404 (setq comint-scroll-to-bottom-on-output t) ; always add output at the bottom
405 (setq comint-scroll-show-maximum-output t) ; scroll to show max possible output
406 (setq comint-completion-autolist t) ; show completion list when ambiguous
407 (setq comint-input-ignoredups t) ; no duplicates in command history
408 (setq comint-completion-addsuffix t) ; insert space/slash after file completion
409 #+END_SRC
410
411 *** Emacs shell
412 Basic settings for emacs integrated shell
413 #+BEGIN_SRC emacs-lisp :tangle yes
414 (use-package eshell
415 :defer t
416 :init
417 (progn
418 (defun eshell-initialize ()
419 (defun eshell-spawn-external-command (beg end)
420 "Parse and expand any history references in current input."
421 (save-excursion
422 (goto-char end)
423 (when (looking-back "&!" beg)
424 (delete-region (match-beginning 0) (match-end 0))
425 (goto-char beg)
426 (insert "spawn "))))
427
428 (add-hook 'eshell-expand-input-functions 'eshell-spawn-external-command)
429
430 (eval-after-load "em-unix"
431 '(progn
432 (unintern 'eshell/su)
433 (unintern 'eshell/sudo))))
434
435 (add-hook 'eshell-first-time-mode-hook 'eshell-initialize)
436
437 (setq eshell-cmpl-cycle-completions nil
438 eshell-save-history-on-exit t
439 eshell-cmpl-dir-ignore "\\`\\(\\.\\.?\\|CVS\\|\\.svn\\|\\.git\\)/\\'")
440 )
441 :config
442 (progn
443 (require 'em-cmpl)
444 (require 'em-prompt)
445 (require 'em-term)
446
447 (setenv "PAGER" "cat")
448 (add-to-list 'eshell-visual-commands "ssh")
449 (add-to-list 'eshell-visual-commands "tail")
450 (add-to-list 'eshell-command-completions-alist
451 '("gunzip" "gz\\'"))
452 (add-to-list 'eshell-command-completions-alist
453 '("tar" "\\(\\.tar|\\.tgz\\|\\.tar\\.gz\\)\\'"))
454
455 ;(set-face-attribute 'eshell-prompt nil :foreground "turquoise1")
456 (add-hook 'eshell-mode-hook ;; for some reason this needs to be a hook
457 '(lambda () (define-key eshell-mode-map "\C-a" 'eshell-bol)))
458 (add-hook 'eshell-preoutput-filter-functions
459 'ansi-color-filter-apply)
460 ))
461 #+END_SRC
462
463 *** Isearch related
464 Incremental search is great, but annoyingly you need to type whatever
465 you want. If you want to search for just the next (or previous)
466 occurence of what is at your cursor position use the following.
467 *C-x* will insert the current word while *M-up* and *M-down* will just
468 jump to the next/previous occurence of it.
469 #+BEGIN_SRC emacs-lisp :tangle yes
470 (bind-key "C-x" 'sacha/isearch-yank-current-word isearch-mode-map)
471 (bind-key* "<M-up>" 'sacha/search-word-backward)
472 (bind-key* "<M-down>" 'sacha/search-word-forward)
473 #+END_SRC
474
475 *** Frame configuration
476 I want to see the buffername and its size, not the host I am on in my
477 frame title.
478 #+BEGIN_SRC emacs-lisp :tangle yes
479 (setq frame-title-format "%b (%i)")
480 #+END_SRC
481
482 *** Protect some buffers
483 I don't want some buffers to be killed, **scratch** for example.
484 In the past I had a long function that just recreated them, but the
485 =keep-buffers= package is easier.
486 #+BEGIN_SRC emacs-lisp :tangle yes
487 (use-package keep-buffers
488 :init
489 (progn
490 (keep-buffers-mode 1)
491 (push '("\\`*scratch" . erase) keep-buffers-protected-alist)
492 (push '("\\`*Org Agenda" . nil) keep-buffers-protected-alist)
493 (push '("\\`*Group" . nil) keep-buffers-protected-alist)
494 ))
495 #+END_SRC
496
497 *** yes-or-no-p
498 Emas usually wants you to type /yes/ or /no/ fully. What a mess, I am
499 lazy.
500 #+BEGIN_SRC emacs-lisp :tangle yes
501 (defalias 'yes-or-no-p 'y-or-n-p)
502 #+END_SRC
503
504 *** Language/i18n stuff
505 In this day and age, UTF-8 is the way to go.
506 #+BEGIN_SRC emacs-lisp :tangle yes
507 (set-language-environment 'utf-8)
508 (set-default-coding-systems 'utf-8)
509 (set-terminal-coding-system 'utf-8)
510 (set-keyboard-coding-system 'utf-8)
511 (set-clipboard-coding-system 'utf-8)
512 (prefer-coding-system 'utf-8)
513 (set-charset-priority 'unicode)
514 (setq default-process-coding-system '(utf-8-unix . utf-8-unix))
515 #+END_SRC
516
517 *** Hilight matching parentheses
518 While I do have the nifty shortcut to jump to the other parentheses,
519 hilighting them makes it obvious where they are.
520 #+BEGIN_SRC emacs-lisp :tangle yes
521 (unless
522 (use-package mic-paren
523 :init
524 (paren-activate))
525
526 (use-package paren
527 :init
528 (progn
529 (show-paren-mode +1)
530 (setq show-paren-style 'parenthesis)
531 )
532 )
533 )
534 #+END_SRC
535 *** Kill other buffers
536 While many editors allow you to close "all the other files, not the one
537 you are in", emacs doesn't have this... Except, now it will.
538 #+BEGIN_SRC emacs-lisp :tangle yes
539 (bind-key "C-c k" 'prelude-kill-other-buffers)
540 #+END_SRC
541 *** Scrolling
542 Default scrolling behaviour in emacs is a bit annoying, who wants to
543 jump half-windows?
544 #+BEGIN_SRC emacs-lisp :tangle yes
545 (setq scroll-margin 0)
546 (setq scroll-conservatively 100000)
547 (setq scroll-up-aggressively 0.0)
548 (setq scroll-down-aggressively 0.0)
549 (setq scroll-preserve-screen-position t)
550 #+END_SRC
551
552 *** Copy/Paste with X
553 [2013-04-09 Di 23:31]
554 The default how emacs handles cutting/pasting with the primary selection
555 changed in emacs24. I am used to the old way, so get it back.
556 #+BEGIN_SRC emacs-lisp :tangle yes
557 (setq x-select-enable-primary t)
558 (setq x-select-enable-clipboard t ;; copy-paste should work ...
559 interprogram-paste-function ;; ...with...
560 'x-cut-buffer-or-selection-value) ;; ...other X clients
561
562 #+END_SRC
563
564 *** Global keyboard changes not directly related to a mode
565 Disable /suspend_frame/ function, I dislike it.
566 #+BEGIN_SRC emacs-lisp :tangle yes
567 (unbind-key "C-z")
568 (unbind-key "C-x C-z")
569 #+END_SRC
570
571 Default of *C-k* is to kill from the point to the end of line. If
572 'kill-whole-line' (see [[id:0a1560d9-7e55-47ab-be52-b3a8b8eea4aa][the kill-whole-line part in "General stuff"]]) is
573 set, including newline. But to kill the entire line, one still needs a
574 *C-a* in front of it. So I change it, by defining a function to do just this for
575 me. Lazyness++.
576 #+BEGIN_SRC emacs-lisp :tangle yes
577 (defun kill-entire-line ()
578 "Kill this entire line (including newline), regardless of where point is within the line."
579 (interactive)
580 (beginning-of-line)
581 (kill-line)
582 (back-to-indentation))
583
584 (unbind-key "C-z")
585 (bind-key* "C-k" 'kill-entire-line)
586 (global-set-key [remap kill-whole-line] 'kill-entire-line)
587 #+END_SRC
588
589 And the same is true when I'm in org-mode, which has an own kill function...
590 (the keybinding happens later, after org-mode is loaded fully)
591 #+BEGIN_SRC emacs-lisp :tangle yes
592 (defun jj-org-kill-line (&optional arg)
593 "Kill the entire line, regardless of where point is within the line, org-mode-version"
594 (interactive "P")
595 (beginning-of-line)
596 (org-kill-line arg)
597 (back-to-indentation)
598 )
599 #+END_SRC
600
601 I really hate tabs, so I don't want any indentation to try using them.
602 And in case a project really needs them, I can change it just for that
603 file/project, but luckily none of those I work in is as broken.
604 #+BEGIN_SRC emacs-lisp :tangle yes
605 (setq-default indent-tabs-mode nil)
606 #+END_SRC
607
608 Make the % key jump to the matching {}[]() if on another, like vi, see [[id:b6e6cf73-9802-4a7b-bd65-fdb6f9745319][the function]]
609 #+BEGIN_SRC emacs-lisp :tangle yes
610 (bind-key* "M-5" 'match-paren)
611 #+END_SRC
612
613 Instead of the default "mark-defun" I want a more readline-like setting.
614 #+BEGIN_SRC emacs-lisp :tangle yes
615 (bind-key "C-M-h" 'backward-kill-word)
616 #+END_SRC
617
618 Align whatever with a regexp.
619 #+BEGIN_SRC emacs-lisp :tangle yes
620 (bind-key "C-x \\" 'align-regexp)
621 #+END_SRC
622
623 Font size changes
624 #+BEGIN_SRC emacs-lisp :tangle yes
625 (bind-key "C-+" 'text-scale-increase)
626 (bind-key "C--" 'text-scale-decrease)
627 #+END_SRC
628
629 Regexes are too useful, so use the regex search by default.
630 #+begin_src emacs-lisp
631 (bind-key "C-s" 'isearch-forward-regexp)
632 (bind-key "C-r" 'isearch-backward-regexp)
633 (bind-key "C-M-s" 'isearch-forward)
634 (bind-key "C-M-r" 'isearch-backward)
635 #+end_src
636
637 Rgrep is infinitely useful in multi-file projects.
638 #+begin_src emacs-lisp
639 (bind-key "C-x C-g" 'rgrep)
640 #+end_src
641
642 Easy way to move a line up - or down. Simpler than dealing with C-x C-t
643 AKA transpose lines.
644 #+BEGIN_SRC emacs-lisp :tangle yes
645 (bind-key "<M-S-up>" 'move-line-up)
646 (bind-key "<M-S-down>" 'move-line-down)
647 #+END_SRC
648
649 "Pull" lines up, join them
650 #+BEGIN_SRC emacs-lisp :tangle yes
651 (bind-key "M-j"
652 (lambda ()
653 (interactive)
654 (join-line -1)))
655 #+END_SRC
656
657 When I press Enter I almost always want to go to the right indentation on the next line.
658 #+BEGIN_SRC emacs-lisp :tangle yes
659 (bind-key "RET" 'newline-and-indent)
660 #+END_SRC
661
662 Easier undo, and i don't need suspend-frame
663 #+BEGIN_SRC emacs-lisp :tangle yes
664 (bind-key "C-z" 'undo)
665 #+END_SRC
666
667 Window switching, go backwards. (C-x o goes to the next window)
668 #+BEGIN_SRC emacs-lisp :tangle yes
669 (bind-key "C-x O" (lambda ()
670 (interactive)
671 (other-window -1)))
672 #+END_SRC
673
674 Edit file as root
675 #+BEGIN_SRC emacs-lisp :tangle yes
676 (bind-key "C-x C-r" 'prelude-sudo-edit)
677 #+END_SRC
678
679 M-space is bound to just-one-space, which is great for programming. What
680 it does is remove all spaces around the cursor, except for one. But to
681 be really useful, it also should include newlines. It doesn’t do this by
682 default. Rather, you have to call it with a negative argument. Sure
683 not, bad Emacs.
684 #+BEGIN_SRC emacs-lisp :tangle yes
685 (bind-key "M-SPC" 'just-one-space-with-newline)
686 #+END_SRC
687
688 Count which commands I use how often.
689 #+BEGIN_SRC emacs-lisp :tangle yes
690 (use-package keyfreq
691 :ensure keyfreq
692 :init
693 (progn
694 (setq keyfreq-file (expand-file-name "keyfreq" jj-cache-dir))
695 (setq keyfreq-file-lock (expand-file-name "keyfreq.lock" jj-cache-dir))
696 (keyfreq-mode 1)
697 (keyfreq-autosave-mode 1)))
698 #+END_SRC
699
700 Duplicate current line
701 #+BEGIN_SRC emacs-lisp :tangle yes
702 (defun duplicate-line ()
703 "Insert a copy of the current line after the current line."
704 (interactive)
705 (save-excursion
706 (let ((line-text (buffer-substring-no-properties
707 (line-beginning-position)
708 (line-end-position))))
709 (move-end-of-line 1)
710 (newline)
711 (insert line-text))))
712
713 (bind-key "C-c p" 'duplicate-line)
714 #+END_SRC
715
716 Smarter move to the beginning of the line. That is, it first moves to
717 the beginning of the line - and on second keypress it goes to the
718 first character on line.
719 #+BEGIN_SRC emacs-lisp :tangle yes
720 (defun smarter-move-beginning-of-line (arg)
721 "Move point back to indentation of beginning of line.
722
723 Move point to the first non-whitespace character on this line.
724 If point is already there, move to the beginning of the line.
725 Effectively toggle between the first non-whitespace character and
726 the beginning of the line.
727
728 If ARG is not nil or 1, move forward ARG - 1 lines first. If
729 point reaches the beginning or end of the buffer, stop there."
730 (interactive "^p")
731 (setq arg (or arg 1))
732
733 ;; Move lines first
734 (when (/= arg 1)
735 (let ((line-move-visual nil))
736 (forward-line (1- arg))))
737
738 (let ((orig-point (point)))
739 (back-to-indentation)
740 (when (= orig-point (point))
741 (move-beginning-of-line 1))))
742
743 ;; remap C-a to `smarter-move-beginning-of-line'
744 (global-set-key [remap move-beginning-of-line]
745 'smarter-move-beginning-of-line)
746
747 #+END_SRC
748
749 Easily copy characters from the previous nonblank line, starting just
750 above point. With a prefix argument, only copy ARG characters (never
751 past EOL), no argument copies rest of line.
752 #+BEGIN_SRC emacs-lisp :tangle yes
753 (require 'misc)
754 (bind-key "H-y" 'copy-from-above-command)
755 #+END_SRC
756
757 Open a new X Terminal pointing to the directory of the current
758 buffers path.
759 #+BEGIN_SRC emacs-lisp :tangle yes
760 (bind-key "H-t" 'jj-open-shell)
761 #+END_SRC
762
763 Align code
764 #+BEGIN_SRC emacs-lisp :tangle yes
765 (bind-key "M-[" 'align-code)
766 #+END_SRC
767 **** Overwrite mode
768 Usually you can press the *Ins*ert key, to get into overwrite mode. I
769 don't like that, have broken much with it and so just forbid it by
770 disabling that.
771 #+BEGIN_SRC emacs-lisp :tangle yes
772 (unbind-key "<insert>")
773 (unbind-key "<kp-insert>")
774 #+END_SRC
775
776 ** Miscellaneous stuff
777 Weeks start on Monday, not sunday.
778 #+BEGIN_SRC emacs-lisp :tangle yes
779 (setq calendar-week-start-day 1)
780 #+END_SRC
781
782 Searches and matches should ignore case.
783 #+BEGIN_SRC emacs-lisp :tangle yes
784 (setq-default case-fold-search t)
785 #+END_SRC
786
787 Which buffers to get rid off at midnight.
788 #+BEGIN_SRC emacs-lisp :tangle yes
789 (setq clean-buffer-list-kill-buffer-names (quote ("*Help*" "*Apropos*"
790 "*Man " "*Buffer List*"
791 "*Compile-Log*"
792 "*info*" "*vc*"
793 "*vc-diff*" "*diff*"
794 "*Customize"
795 "*tramp/" "*debug "
796 "*magit" "*Calendar")))
797 #+END_SRC
798
799 Don't display a cursor in non-selected windows.
800 #+BEGIN_SRC emacs-lisp :tangle yes
801 (setq-default cursor-in-non-selected-windows nil)
802 #+END_SRC
803
804 What should be displayed in the mode-line for files with those types
805 of line endings.
806 #+BEGIN_SRC emacs-lisp :tangle yes
807 (setq eol-mnemonic-dos "(DOS)")
808 (setq eol-mnemonic-mac "(Mac)")
809 #+END_SRC
810
811 Much larger threshold for garbage collection prevents it to run too often.
812 #+BEGIN_SRC emacs-lisp :tangle yes
813 (setq gc-cons-threshold 48000000)
814 #+END_SRC
815
816 #+BEGIN_SRC emacs-lisp :tangle yes
817 (setq max-lisp-eval-depth 1000)
818 (setq max-specpdl-size 3000)
819 #+END_SRC
820
821 Unfill paragraph
822 From https://raw.github.com/qdot/conf_emacs/master/emacs_conf.org
823 #+BEGIN_SRC emacs-lisp :tangle yes
824 (defun unfill-paragraph ()
825 "Takes a multi-line paragraph and makes it into a single line of text."
826 (interactive)
827 (let ((fill-column (point-max)))
828 (fill-paragraph nil)))
829 (bind-key "H-u" 'unfill-paragraph)
830 #+END_SRC
831
832 #+BEGIN_SRC emacs-lisp :tangle yes
833 (setq-default indicate-empty-lines t)
834 #+END_SRC
835
836 Hilight annotations in comments, like FIXME/TODO/...
837 #+BEGIN_SRC emacs-lisp :tangle yes
838 (add-hook 'prog-mode-hook 'font-lock-comment-annotations)
839 #+END_SRC
840
841 *** Browser
842 #+BEGIN_SRC emacs-lisp :tangle yes
843 (setq browse-url-browser-function (quote browse-url-generic))
844 (setq browse-url-generic-program "/usr/bin/x-www-browser")
845 #+END_SRC
846
847 *** When saving a script - make it executable
848 #+BEGIN_SRC emacs-lisp :tangle yes
849 (add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p)
850 #+END_SRC
851
852 *** Emacs Server
853 #+BEGIN_SRC emacs-lisp :tangle yes
854 (use-package server
855 :init
856 (progn
857 (add-hook 'after-init-hook 'server-start)))
858 #+END_SRC
859
860 ** Customized variables
861 [2013-05-02 Thu 22:14]
862 The following contains a set of variables i may reasonably want to
863 change on other systems - which don't affect the init file loading
864 process. So I *can* use the customization interface for it...
865 #+BEGIN_SRC emacs-lisp :tangle yes
866 (defgroup ganneff nil
867 "Modify ganneffs settings"
868 :group 'environment)
869
870 (defgroup ganneff-org-mode nil
871 "Ganneffs org-mode settings"
872 :tag "Ganneffs org-mode settings"
873 :group 'ganneff
874 :link '(custom-group-link "ganneff"))
875
876 (defcustom bh/organization-task-id "d0db0d3c-f22e-42ff-a654-69524ff7cc91"
877 "ID of the organization task."
878 :tag "Organization Task ID"
879 :type 'string
880 :group 'ganneff-org-mode)
881
882 (defcustom org-my-archive-expiry-days 2
883 "The number of days after which a completed task should be auto-archived.
884 This can be 0 for immediate, or a floating point value."
885 :tag "Archive expiry days"
886 :type 'float
887 :group 'ganneff-org-mode)
888 #+END_SRC
889
890
891 ** Compatibility
892 [2013-05-21 Tue 23:22]
893 Restore removed var alias, used by ruby-electric-brace and others
894 #+BEGIN_SRC emacs-lisp :tangle yes
895 (unless (boundp 'last-command-char)
896 (defvaralias 'last-command-char 'last-command-event))
897 #+END_SRC
898
899 * Customized variables
900 :PROPERTIES:
901 :ID: 0102208d-fdf6-4928-9e40-7e341bd3aa3a
902 :END:
903 Of course I want to be able to use the customize interface, and some
904 things can only be set via it (or so they say). I usually prefer to put
905 things I keep for a long while into statements somewhere else, not just
906 custom-set here, but we need it anyways.
907
908 #+BEGIN_SRC emacs-lisp :tangle yes
909 (setq custom-file jj-custom-file)
910 (safe-load custom-file)
911 #+END_SRC
912
913 The source of this is:
914 #+INCLUDE: "~/.emacs.d/config/customized.el" src emacs-lisp
915
916
917 * Extra modes and their configuration
918 ** abbrev
919 A defined abbrev is a word which expands, if you insert it, into some
920 different text. Abbrevs are defined by the user to expand in specific
921 ways.
922 #+BEGIN_SRC emacs-lisp :tangle yes
923 (use-package abbrev
924 :commands abbrev-mode
925 :diminish abbrev-mode
926 :init
927 (hook-into-modes #'abbrev-mode '(text-mode-hook))
928
929 :config
930 (progn
931 (setq save-abbrevs 'silently)
932 (setq abbrev-file-name (expand-file-name "abbrev_defs" jj-cache-dir))
933 (if (file-exists-p abbrev-file-name)
934 (quietly-read-abbrev-file))
935
936 (add-hook 'expand-load-hook
937 (lambda ()
938 (add-hook 'expand-expand-hook 'indent-according-to-mode)
939 (add-hook 'expand-jump-hook 'indent-according-to-mode)))))
940 #+END_SRC
941
942 ** ace-jump-mode
943 [2013-04-28 So 11:26]
944 Quickly move around in buffers.
945 #+BEGIN_SRC emacs-lisp :tangle yes
946 (use-package ace-jump-mode
947 :ensure ace-jump-mode
948 :commands ace-jump-mode
949 :bind ("H-SPC" . ace-jump-mode))
950 #+END_SRC
951 ** ace-window
952 [2013-04-21 So 20:27]
953 Use H-w to switch windows
954 #+BEGIN_SRC emacs-lisp :tangle yes
955 (use-package ace-window
956 :ensure ace-window
957 :commands ace-window
958 :bind ("H-w" . ace-window))
959 #+END_SRC
960 ** ascii
961 [2014-05-21 Wed 00:33]
962 #+BEGIN_SRC emacs-lisp :tangle yes
963 (use-package ascii
964 :commands (ascii-on ascii-toggle)
965 :init
966 (progn
967 (defun ascii-toggle ()
968 (interactive)
969 (if ascii-display
970 (ascii-off)
971 (ascii-on)))
972
973 (bind-key "C-c e A" 'ascii-toggle)))
974 #+END_SRC
975 ** auctex
976 #+BEGIN_SRC emacs-lisp :tangle yes
977 (setq auto-mode-alist (cons '("\\.tex\\'" . latex-mode) auto-mode-alist))
978 (setq TeX-auto-save t)
979 (setq TeX-parse-self t)
980 (setq TeX-PDF-mode t)
981 #+END_SRC
982
983 ** auto-complete mode
984 [2013-04-27 Sa 16:33]
985 And aren't we all lazy? I definitely am, and I like my emacs doing as
986 much possible work for me as it can.
987 So here, auto-complete-mode, which lets emacs do this, based on what I
988 already had typed.
989 #+BEGIN_SRC emacs-lisp :tangle yes
990 (use-package auto-complete
991 :ensure auto-complete
992 :init
993 (progn
994 (global-auto-complete-mode t)
995 )
996 :config
997 (progn
998 (setq ac-comphist-file (expand-file-name "ac-comphist.dat" jj-cache-dir))
999
1000 (setq ac-expand-on-auto-complete nil)
1001 (setq ac-dwim t)
1002 (setq ac-auto-start t)
1003
1004 ;;----------------------------------------------------------------------------
1005 ;; Use Emacs' built-in TAB completion hooks to trigger AC (Emacs >= 23.2)
1006 ;;----------------------------------------------------------------------------
1007 (setq tab-always-indent 'complete) ;; use 't when auto-complete is disabled
1008 (add-to-list 'completion-styles 'initials t)
1009
1010 ;; hook AC into completion-at-point
1011 (defun sanityinc/auto-complete-at-point ()
1012 (when (and (not (minibufferp))
1013 (fboundp 'auto-complete-mode)
1014 auto-complete-mode)
1015 (auto-complete)))
1016
1017 (defun set-auto-complete-as-completion-at-point-function ()
1018 (add-to-list 'completion-at-point-functions 'sanityinc/auto-complete-at-point))
1019
1020 (add-hook 'auto-complete-mode-hook 'set-auto-complete-as-completion-at-point-function)
1021
1022 ;(require 'ac-dabbrev)
1023 (set-default 'ac-sources
1024 '(ac-source-imenu
1025 ac-source-dictionary
1026 ac-source-words-in-buffer
1027 ac-source-words-in-same-mode-buffers
1028 ac-source-words-in-all-buffer))
1029 ; ac-source-dabbrev))
1030
1031 (dolist (mode '(magit-log-edit-mode log-edit-mode org-mode text-mode haml-mode
1032 sass-mode yaml-mode csv-mode espresso-mode haskell-mode
1033 html-mode nxml-mode sh-mode smarty-mode clojure-mode
1034 lisp-mode textile-mode markdown-mode tuareg-mode python-mode
1035 js3-mode css-mode less-css-mode sql-mode ielm-mode))
1036 (add-to-list 'ac-modes mode))
1037
1038 ;; Exclude very large buffers from dabbrev
1039 (defun sanityinc/dabbrev-friend-buffer (other-buffer)
1040 (< (buffer-size other-buffer) (* 1 1024 1024)))
1041
1042 (setq dabbrev-friend-buffer-function 'sanityinc/dabbrev-friend-buffer)
1043
1044
1045 ;; custom keybindings to use tab, enter and up and down arrows
1046 (bind-key "\t" 'ac-expand ac-complete-mode-map)
1047 (bind-key "\r" 'ac-complete ac-complete-mode-map)
1048 (bind-key "M-n" 'ac-next ac-complete-mode-map)
1049 (bind-key "M-p" 'ac-previous ac-complete-mode-map)
1050 (bind-key "M-TAB" 'auto-complete ac-mode-map)
1051
1052 (setq auto-completion-syntax-alist (quote (global accept . word))) ;; Use space and punctuation to accept the current the most likely completion.
1053 (setq auto-completion-min-chars (quote (global . 3))) ;; Avoid completion for short trivial words.
1054 (setq completion-use-dynamic t)
1055
1056 (add-hook 'latex-mode-hook 'auto-complete-mode)
1057 (add-hook 'LaTeX-mode-hook 'auto-complete-mode)
1058 (add-hook 'prog-mode-hook 'auto-complete-mode)
1059 (add-hook 'org-mode-hook 'auto-complete-mode)))
1060 #+END_SRC
1061
1062 ** auto-revert
1063 When files change outside emacs for whatever reason I want emacs to deal
1064 with it. Not to have to revert buffers myself
1065 #+BEGIN_SRC emacs-lisp :tangle yes
1066 (use-package autorevert
1067 :commands auto-revert-mode
1068 :diminish auto-revert-mode
1069 :init
1070 (progn
1071 (setq global-auto-revert-mode t)
1072 (global-auto-revert-mode)))
1073 #+END_SRC
1074
1075 ** backups
1076 Emacs should keep backup copies of files I edit, but I do not want them
1077 to clutter up the filesystem everywhere. So I put them into one defined
1078 place, backup-directory, which even contains my username (for systems
1079 where =temporary-file-directory= is not inside my home).
1080 #+BEGIN_SRC emacs-lisp :tangle yes
1081 (use-package backups-mode
1082 :load-path "elisp/backups-mode"
1083 :bind (("\C-cv" . save-version)
1084 ("\C-cb" . list-backups)
1085 ("\C-ck" . kill-buffer-prompt)
1086 ("\C-cw" . backup-walker-start))
1087 :init
1088 (progn
1089 (setq backup-directory jj-backup-directory)
1090 (setq tramp-backup-directory (concat jj-backup-directory "/tramp"))
1091 (if (not (file-exists-p tramp-backup-directory))
1092 (make-directory tramp-backup-directory))
1093 (setq tramp-backup-directory-alist `((".*" . ,tramp-backup-directory)))
1094 (setq backup-directory-alist `(("." . ,jj-backup-directory)))
1095 (setq auto-save-list-file-prefix (concat jj-backup-directory ".auto-saves-"))
1096 (setq auto-save-file-name-transforms `((".*" ,jj-backup-directory t)))
1097
1098 (setq version-control t) ;; Use version numbers for backups
1099 (setq kept-new-versions 10) ;; Number of newest versions to keep
1100 (setq kept-old-versions 2) ;; Number of oldest versions to keep
1101 (setq delete-old-versions t) ;; Ask to delete excess backup versions?
1102 (setq backup-by-copying t)
1103 (setq backup-by-copying-when-linked t) ;; Copy linked files, don't rename.
1104 (setq make-backup-files t)
1105
1106 (defadvice kill-buffer (around kill-buffer)
1107 "Always save before killing a file buffer"
1108 (when (and (buffer-modified-p)
1109 (buffer-file-name)
1110 (file-exists-p (buffer-file-name)))
1111 (save-buffer))
1112 ad-do-it)
1113 (ad-activate 'kill-buffer)
1114
1115 (defadvice save-buffers-kill-emacs (around save-buffers-kill-emacs)
1116 "Always save before killing emacs"
1117 (save-some-buffers t)
1118 ad-do-it)
1119 (ad-activate 'save-buffers-kill-emacs)
1120
1121 (defun kill-buffer-prompt ()
1122 "Allows one to kill a buffer without saving it.
1123 This is necessary since once you start backups-mode all file based buffers
1124 are saved automatically when they are killed"
1125 (interactive)
1126 (if (and (buffer-modified-p) (buffer-file-name) (file-exists-p (buffer-file-name)) (y-or-n-p "Save buffer?"))
1127 (save-buffer)
1128 (set-buffer-modified-p nil))
1129 (kill-buffer))
1130
1131 (setq backup-enable-predicate
1132 (lambda (name)
1133 (and (normal-backup-enable-predicate name)
1134 (not
1135 (let ((method (file-remote-p name 'method)))
1136 (when (stringp method)
1137 (member method '("su" "sudo"))))))))))
1138
1139 #+END_SRC
1140 ** crontab-mode
1141 [2013-05-21 Tue 23:18]
1142 #+BEGIN_SRC emacs-lisp :tangle yes
1143 (use-package crontab-mode
1144 :ensure crontab-mode
1145 :commands crontab-mode
1146 :mode ("\\.?cron\\(tab\\)?\\'" . crontab-mode))
1147 #+END_SRC
1148
1149 ** css
1150 #+BEGIN_SRC emacs-lisp :tangle yes
1151 (use-package css-mode
1152 :mode ("\\.css\\'" . css-mode)
1153 :defer t
1154 :config
1155 (progn
1156 ;;; CSS flymake
1157 (use-package flymake-css
1158 :ensure flymake-css
1159 :config
1160 (progn
1161 (defun maybe-flymake-css-load ()
1162 "Activate flymake-css as necessary, but not in derived modes."
1163 (when (eq major-mode 'css-mode)
1164 (flymake-css-load)))
1165 (add-hook 'css-mode-hook 'maybe-flymake-css-load)))
1166 ;;; Auto-complete CSS keywords
1167 (eval-after-load 'auto-complete
1168 '(progn
1169 (dolist (hook '(css-mode-hook sass-mode-hook scss-mode-hook))
1170 (add-hook hook 'ac-css-mode-setup))))))
1171 #+END_SRC
1172
1173 ** cua
1174 I know that this lets it look "more like windows", but I don't much care
1175 about its paste/copy/cut keybindings, the really nice part is the great
1176 support for rectangular regions, which I started to use a lot since I
1177 know this mode. The normal keybindings for those are just to useless.
1178 #+BEGIN_SRC emacs-lisp :tangle yes
1179 (cua-mode t)
1180 (setq cua-enable-cua-keys (quote shift))
1181 #+END_SRC
1182
1183 Luckily cua-mode easily supports this, with the following line I just
1184 get the CUA selection and rectangle stuff, not the keybindings. Yes,
1185 even though the above =cua-enable-cua-keys= setting would only enable
1186 them if the selection is done when the region was marked with a shifted
1187 movement keys.
1188 #+BEGIN_SRC emacs-lisp :tangle yes
1189 (cua-selection-mode t)
1190 #+END_SRC
1191
1192 ** Debian related
1193 #+BEGIN_SRC emacs-lisp :tangle yes
1194 (require 'dpkg-dev-el-loaddefs nil 'noerror)
1195 (require 'debian-el-loaddefs nil 'noerror)
1196
1197 (setq debian-changelog-full-name "Joerg Jaspert")
1198 (setq debian-changelog-mailing-address "joerg@debian.org")
1199 #+END_SRC
1200
1201 ** diff-mode
1202 #+BEGIN_SRC emacs-lisp :tangle yes
1203 (use-package diff-mode
1204 :commands diff-mode
1205 :mode ("COMMIT_EDITMSG$" . diff-mode)
1206 :config
1207 (use-package diff-mode-))
1208 #+END_SRC
1209 For some file endings we need to tell emacs what mode we want for them.
1210 I only list modes here where I don't have any other special
1211 configuration.
1212
1213 ** dired & co
1214 I like dired and work a lot with it, but it tends to leave lots of
1215 windows around.
1216 dired-single to the rescue.
1217 #+BEGIN_SRC emacs-lisp :tangle yes
1218 (use-package dired
1219 :defer t
1220 :init
1221 (progn
1222 (defvar mark-files-cache (make-hash-table :test #'equal))
1223
1224 (defun mark-similar-versions (name)
1225 (let ((pat name))
1226 (if (string-match "^\\(.+?\\)-[0-9._-]+$" pat)
1227 (setq pat (match-string 1 pat)))
1228 (or (gethash pat mark-files-cache)
1229 (ignore (puthash pat t mark-files-cache)))))
1230
1231 (defun dired-mark-similar-version ()
1232 (interactive)
1233 (setq mark-files-cache (make-hash-table :test #'equal))
1234 (dired-mark-sexp '(mark-similar-versions name))))
1235 :config
1236 (progn
1237 (setq dired-auto-revert-buffer (quote dired-directory-changed-p))
1238 (setq dired-dwim-target t)
1239 (setq dired-listing-switches "-alh")
1240 (setq dired-recursive-copies (quote top))
1241 (setq dired-recursive-deletes (quote top))
1242
1243 (defun dired-package-initialize ()
1244 (unless (featurep 'runner)
1245 (use-package dired-x)
1246 (use-package runner
1247 :ensure runner)
1248
1249 (use-package dired-single
1250 :ensure dired-single
1251 :init
1252 (progn
1253 (bind-key "<return>" 'dired-single-buffer dired-mode-map)
1254 (bind-key "<mouse-1>" 'dired-single-buffer-mouse dired-mode-map)
1255 (bind-key "^"
1256 (function
1257 (lambda nil (interactive) (dired-single-buffer ".."))) dired-mode-map )))
1258
1259 (use-package wdired
1260 :ensure wdired
1261 :init
1262 (progn
1263 (setq wdired-allow-to-change-permissions t)
1264 (bind-key "r" 'wdired-change-to-wdired-mode dired-mode-map)))
1265
1266 (use-package gnus-dired
1267 :init
1268 (progn
1269 (require 'gnus-dired)
1270 (add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode)
1271 (bind-key "a" 'gnus-dired-attach dired-mode-map)))
1272
1273 (bind-key "M-!" 'async-shell-command dired-mode-map)
1274 (unbind-key "M-s f" dired-mode-map)
1275
1276 (defadvice dired-omit-startup (after diminish-dired-omit activate)
1277 "Make sure to remove \"Omit\" from the modeline."
1278 (diminish 'dired-omit-mode) dired-mode-map)
1279
1280 ;; Omit files that Git would ignore
1281 (defun dired-omit-regexp ()
1282 (let ((file (expand-file-name ".git"))
1283 parent-dir)
1284 (while (and (not (file-exists-p file))
1285 (progn
1286 (setq parent-dir
1287 (file-name-directory
1288 (directory-file-name
1289 (file-name-directory file))))
1290 ;; Give up if we are already at the root dir.
1291 (not (string= (file-name-directory file)
1292 parent-dir))))
1293 ;; Move up to the parent dir and try again.
1294 (setq file (expand-file-name ".git" parent-dir)))
1295 ;; If we found a change log in a parent, use that.
1296 (if (file-exists-p file)
1297 (let ((regexp (funcall dired-omit-regexp-orig))
1298 (omitted-files
1299 (shell-command-to-string "git clean -d -x -n")))
1300 (if (= 0 (length omitted-files))
1301 regexp
1302 (concat
1303 regexp
1304 (if (> (length regexp) 0)
1305 "\\|" "")
1306 "\\("
1307 (mapconcat
1308 #'(lambda (str)
1309 (concat
1310 "^"
1311 (regexp-quote
1312 (substring str 13
1313 (if (= ?/ (aref str (1- (length str))))
1314 (1- (length str))
1315 nil)))
1316 "$"))
1317 (split-string omitted-files "\n" t)
1318 "\\|")
1319 "\\)")))
1320 (funcall dired-omit-regexp-orig))))))
1321
1322 (add-hook 'dired-mode-hook 'dired-package-initialize)
1323
1324 (defun dired-double-jump (first-dir second-dir)
1325 (interactive
1326 (list (read-directory-name "First directory: "
1327 (expand-file-name "~")
1328 nil nil "dl/")
1329 (read-directory-name "Second directory: "
1330 (expand-file-name "~")
1331 nil nil "Archives/")))
1332 (dired first-dir)
1333 (dired-other-window second-dir))
1334 (bind-key "C-c J" 'dired-double-jump)))
1335
1336 #+END_SRC
1337
1338 ** easypg
1339 EasyPG is a GnuPG interface for Emacs.
1340 #+BEGIN_SRC emacs-lisp :tangle yes
1341 (require 'epa-file)
1342 (epa-file-enable)
1343 #+END_SRC
1344
1345 I took the following from [[http://www.emacswiki.org/emacs/EasyPG][EmacsWiki: Easy PG]]
1346 #+BEGIN_SRC emacs-lisp :tangle yes
1347 (defadvice epg--start (around advice-epg-disable-agent disable)
1348 "Don't allow epg--start to use gpg-agent in plain text
1349 terminals."
1350 (if (display-graphic-p)
1351 ad-do-it
1352 (let ((agent (getenv "GPG_AGENT_INFO")))
1353 (setenv "GPG_AGENT_INFO" nil) ; give us a usable text password prompt
1354 ad-do-it
1355 (setenv "GPG_AGENT_INFO" agent))))
1356 (ad-enable-advice 'epg--start 'around 'advice-epg-disable-agent)
1357 (ad-activate 'epg--start)
1358 #+END_SRC
1359 ** ediff
1360 [2013-04-21 So 20:36]
1361 ediff - don't start another frame
1362 #+BEGIN_SRC elisp
1363 (use-package ediff
1364 :pre-init
1365 (progn
1366 (defvar ctl-period-equals-map)
1367 (define-prefix-command 'ctl-period-equals-map)
1368 (bind-key "C-. =" 'ctl-period-equals-map)
1369
1370 (bind-key "C-. = c" 'compare-windows)) ; not an ediff command, but it fits
1371
1372 :bind (("C-. = b" . ediff-buffers)
1373 ("C-. = B" . ediff-buffers3)
1374 ("C-. = =" . ediff-files)
1375 ("C-. = f" . ediff-files)
1376 ("C-. = F" . ediff-files3)
1377 ("C-. = r" . ediff-revision)
1378 ("C-. = p" . ediff-patch-file)
1379 ("C-. = P" . ediff-patch-buffer)
1380 ("C-. = l" . ediff-regions-linewise)
1381 ("C-. = w" . ediff-regions-wordwise)))
1382 #+END_SRC
1383 ** emms
1384 EMMS is the Emacs Multimedia System.
1385 #+BEGIN_SRC emacs-lisp :tangle no
1386 (require 'emms-source-file)
1387 (require 'emms-source-playlist)
1388 (require 'emms-info)
1389 (require 'emms-cache)
1390 (require 'emms-playlist-mode)
1391 (require 'emms-playing-time)
1392 (require 'emms-player-mpd)
1393 (require 'emms-playlist-sort)
1394 (require 'emms-mark)
1395 (require 'emms-browser)
1396 (require 'emms-lyrics)
1397 (require 'emms-last-played)
1398 (require 'emms-score)
1399 (require 'emms-tag-editor)
1400 (require 'emms-history)
1401 (require 'emms-i18n)
1402
1403 (setq emms-playlist-default-major-mode 'emms-playlist-mode)
1404 (add-to-list 'emms-track-initialize-functions 'emms-info-initialize-track)
1405 (emms-playing-time 1)
1406 (emms-lyrics 1)
1407 (add-hook 'emms-player-started-hook 'emms-last-played-update-current)
1408 ;(add-hook 'emms-player-started-hook 'emms-player-mpd-sync-from-emms)
1409 (emms-score 1)
1410 (when (fboundp 'emms-cache) ; work around compiler warning
1411 (emms-cache 1))
1412 (setq emms-score-default-score 3)
1413
1414 (defun emms-mpd-init ()
1415 "Connect Emms to mpd."
1416 (interactive)
1417 (emms-player-mpd-connect))
1418
1419 ;; players
1420 (require 'emms-player-mpd)
1421 (setq emms-player-mpd-server-name "localhost")
1422 (setq emms-player-mpd-server-port "6600")
1423 (add-to-list 'emms-info-functions 'emms-info-mpd)
1424 (add-to-list 'emms-player-list 'emms-player-mpd)
1425 (setq emms-volume-change-function 'emms-volume-mpd-change)
1426 (setq emms-player-mpd-sync-playlist t)
1427
1428 (setq emms-source-file-default-directory "/var/lib/mpd/music")
1429 (setq emms-player-mpd-music-directory "/var/lib/mpd/music")
1430 (setq emms-info-auto-update t)
1431 (setq emms-lyrics-scroll-p t)
1432 (setq emms-lyrics-display-on-minibuffer t)
1433 (setq emms-lyrics-display-on-modeline nil)
1434 (setq emms-lyrics-dir "~/.emacs.d/var/lyrics")
1435
1436 (setq emms-last-played-format-alist
1437 '(((emms-last-played-seconds-today) . "%H:%M")
1438 (604800 . "%a %H:%M") ; this week
1439 ((emms-last-played-seconds-month) . "%d.%m.%Y")
1440 ((emms-last-played-seconds-year) . "%d.%m.%Y")
1441 (t . "Never played")))
1442
1443 ;; Playlist format
1444 (defun my-describe (track)
1445 (let* ((empty "...")
1446 (name (emms-track-name track))
1447 (type (emms-track-type track))
1448 (short-name (file-name-nondirectory name))
1449 (play-count (or (emms-track-get track 'play-count) 0))
1450 (last-played (or (emms-track-get track 'last-played) '(0 0 0)))
1451 (artist (or (emms-track-get track 'info-artist) empty))
1452 (year (emms-track-get track 'info-year))
1453 (playing-time (or (emms-track-get track 'info-playing-time) 0))
1454 (min (/ playing-time 60))
1455 (sec (% playing-time 60))
1456 (album (or (emms-track-get track 'info-album) empty))
1457 (tracknumber (emms-track-get track 'info-tracknumber))
1458 (short-name (file-name-sans-extension
1459 (file-name-nondirectory name)))
1460 (title (or (emms-track-get track 'info-title) short-name))
1461 (rating (emms-score-get-score name))
1462 (rate-char ?☭)
1463 )
1464 (format "%12s %20s (%.4s) [%-20s] - %2s. %-30s | %2d %s"
1465 (emms-last-played-format-date last-played)
1466 artist
1467 year
1468 album
1469 (if (and tracknumber ; tracknumber
1470 (not (zerop (string-to-number tracknumber))))
1471 (format "%02d" (string-to-number tracknumber))
1472 "")
1473 title
1474 play-count
1475 (make-string rating rate-char)))
1476 )
1477
1478 (setq emms-track-description-function 'my-describe)
1479
1480 ;; (global-set-key (kbd "C-<f9> t") 'emms-play-directory-tree)
1481 ;; (global-set-key (kbd "H-<f9> e") 'emms-play-file)
1482 (global-set-key (kbd "H-<f9> <f9>") 'emms-mpd-init)
1483 (global-set-key (kbd "H-<f9> d") 'emms-play-dired)
1484 (global-set-key (kbd "H-<f9> x") 'emms-start)
1485 (global-set-key (kbd "H-<f9> v") 'emms-stop)
1486 (global-set-key (kbd "H-<f9> n") 'emms-next)
1487 (global-set-key (kbd "H-<f9> p") 'emms-previous)
1488 (global-set-key (kbd "H-<f9> o") 'emms-show)
1489 (global-set-key (kbd "H-<f9> h") 'emms-shuffle)
1490 (global-set-key (kbd "H-<f9> SPC") 'emms-pause)
1491 (global-set-key (kbd "H-<f9> a") 'emms-add-directory-tree)
1492 (global-set-key (kbd "H-<f9> b") 'emms-smart-browse)
1493 (global-set-key (kbd "H-<f9> l") 'emms-playlist-mode-go)
1494
1495 (global-set-key (kbd "H-<f9> r") 'emms-toggle-repeat-track)
1496 (global-set-key (kbd "H-<f9> R") 'emms-toggle-repeat-playlist)
1497 (global-set-key (kbd "H-<f9> m") 'emms-lyrics-toggle-display-on-minibuffer)
1498 (global-set-key (kbd "H-<f9> M") 'emms-lyrics-toggle-display-on-modeline)
1499
1500 (global-set-key (kbd "H-<f9> <left>") (lambda () (interactive) (emms-seek -10)))
1501 (global-set-key (kbd "H-<f9> <right>") (lambda () (interactive) (emms-seek +10)))
1502 (global-set-key (kbd "H-<f9> <down>") (lambda () (interactive) (emms-seek -60)))
1503 (global-set-key (kbd "H-<f9> <up>") (lambda () (interactive) (emms-seek +60)))
1504
1505 (global-set-key (kbd "H-<f9> s u") 'emms-score-up-playing)
1506 (global-set-key (kbd "H-<f9> s d") 'emms-score-down-playing)
1507 (global-set-key (kbd "H-<f9> s o") 'emms-score-show-playing)
1508 (global-set-key (kbd "H-<f9> s s") 'emms-score-set-playing)
1509
1510 (define-key emms-playlist-mode-map "u" 'emms-score-up-playing)
1511 (define-key emms-playlist-mode-map "d" 'emms-score-down-playing)
1512 (define-key emms-playlist-mode-map "o" 'emms-score-show-playing)
1513 (define-key emms-playlist-mode-map "s" 'emms-score-set-playing)
1514 (define-key emms-playlist-mode-map "r" 'emms-mpd-init)
1515 (define-key emms-playlist-mode-map "N" 'emms-playlist-new)
1516
1517 (define-key emms-playlist-mode-map "x" 'emms-start)
1518 (define-key emms-playlist-mode-map "v" 'emms-stop)
1519 (define-key emms-playlist-mode-map "n" 'emms-next)
1520 (define-key emms-playlist-mode-map "p" 'emms-previous)
1521
1522 (setq emms-playlist-buffer-name "*EMMS Playlist*"
1523 emms-playlist-mode-open-playlists t)
1524
1525 ;; Faces
1526 (if (window-system)
1527 ((lambda ()
1528 (set-face-attribute
1529 'emms-browser-artist-face nil
1530 :family "Arno Pro")
1531 )
1532 ))
1533
1534 (setq emms-player-mpd-supported-regexp
1535 (or (emms-player-mpd-get-supported-regexp)
1536 (concat "\\`http://\\|"
1537 (emms-player-simple-regexp
1538 "m3u" "ogg" "flac" "mp3" "wav" "mod" "au" "aiff"))))
1539 (emms-player-set emms-player-mpd 'regex emms-player-mpd-supported-regexp)
1540
1541 #+END_SRC
1542 ** filladapt
1543 [2013-05-02 Thu 00:04]
1544 #+BEGIN_SRC emacs-lisp :tangle yes
1545 (use-package filladapt
1546 :diminish filladapt-mode
1547 :init
1548 (setq-default filladapt-mode t))
1549 #+END_SRC
1550 ** flycheck
1551 [2013-04-28 So 22:21]
1552 Flycheck is a on-the-fly syntax checking tool, supposedly better than Flymake.
1553 As the one time I tried Flymake i wasn't happy, thats easy to
1554 understand for me.
1555 #+BEGIN_SRC emacs-lisp :tangle yes
1556 (use-package flycheck
1557 :ensure flycheck
1558 :init
1559 (add-hook 'after-init-hook #'global-flycheck-mode))
1560 #+END_SRC
1561 ** font-lock
1562 Obviously emacs can do syntax hilighting. For more things than you ever
1563 heard about.
1564 And I want to have it everywhere.
1565 #+BEGIN_SRC emacs-lisp :tangle yes
1566 (use-package font-lock
1567 :init
1568 (progn
1569 (global-font-lock-mode 1)
1570 (setq font-lock-maximum-decoration t)))
1571 #+END_SRC
1572 ** git commit mode
1573 #+BEGIN_SRC emacs-lisp :tangle yes
1574 (use-package git-commit-mode
1575 :ensure git-commit-mode
1576 :commands git-commit-mode
1577 :mode ("COMMIT_EDITMSG" . git-commit-mode))
1578 #+END_SRC
1579
1580 ** git rebase mode
1581 #+BEGIN_SRC emacs-lisp :tangle yes
1582 (use-package git-rebase-mode
1583 :ensure git-rebase-mode
1584 :commands git-rebase-mode
1585 :mode ("git-rebase-todo" . git-rebase-mode))
1586 #+END_SRC
1587 ** git-gutter+
1588 [2014-05-21 Wed 22:56]
1589 #+BEGIN_SRC emacs-lisp :tangle yes
1590 (use-package git-gutter+
1591 :ensure git-gutter+
1592 :diminish git-gutter+-mode
1593 :bind (("C-x n" . git-gutter+-next-hunk)
1594 ("C-x p" . git-gutter+-previous-hunk)
1595 ("C-x v =" . git-gutter+-show-hunk)
1596 ("C-x r" . git-gutter+-revert-hunks)
1597 ("C-x s" . git-gutter+-stage-hunks)
1598 ("C-x c" . git-gutter+-commit)
1599 )
1600 :init
1601 (progn
1602 (setq git-gutter+-disabled-modes '(org-mode)))
1603 :config
1604 (progn
1605 (use-package git-gutter-fringe+
1606 :ensure git-gutter-fringe+
1607 :config
1608 (progn
1609 (setq git-gutter-fr+-side 'right-fringe)
1610 ;(git-gutter-fr+-minimal)
1611 ))
1612 (global-git-gutter+-mode 1)))
1613
1614 #+END_SRC
1615 ** gnus
1616 Most of my gnus config is in an own file, [[file:gnus.org][gnus.org]], here I only have
1617 what I want every emacs to know.
1618 #+BEGIN_SRC emacs-lisp :tangle yes
1619 (bind-key* "\M-n" 'gnus) ; Start gnus with M-n
1620 (after 'gnus
1621 (jj-init-theme)
1622 )
1623 #+END_SRC
1624
1625 ** highlight mode
1626 [2014-05-21 Wed 23:51]
1627 #+BEGIN_SRC emacs-lisp :tangle yes
1628 (use-package hi-lock
1629 :bind (("M-o l" . highlight-lines-matching-regexp)
1630 ("M-o r" . highlight-regexp)
1631 ("M-o w" . highlight-phrase)))
1632
1633 ;;;_ , hilit-chg
1634
1635 (use-package hilit-chg
1636 :bind ("M-o C" . highlight-changes-mode))
1637
1638 #+END_SRC
1639 ** hippie-exp
1640 Crazy way of completion. It looks at the word before point and then
1641 tries to expand it in various ways.
1642 #+BEGIN_SRC emacs-lisp :tangle yes
1643 (use-package hippie-exp
1644 :defer t
1645 :bind ("M-/" . hippie-expand)
1646 :init
1647 (progn
1648 (setq hippie-expand-try-functions-list '(try-expand-dabbrev
1649 try-expand-dabbrev-all-buffers
1650 try-expand-dabbrev-from-kill
1651 try-complete-file-name-partially
1652 try-complete-file-name
1653 try-expand-all-abbrevs try-expand-list
1654 try-expand-line
1655 try-complete-lisp-symbol-partially
1656 try-complete-lisp-symbol))))
1657 #+END_SRC
1658 ** html-helper
1659 Instead of default /html-mode/ I use /html-helper-mode/.
1660 #+BEGIN_SRC emacs-lisp :tangle yes
1661 (autoload 'html-helper-mode "html-helper-mode" "Yay HTML" t)
1662 (add-auto-mode 'html-helper-mode "\\.html$")
1663 (add-auto-mode 'html-helper-mode "\\.asp$")
1664 (add-auto-mode 'html-helper-mode "\\.phtml$")
1665 (add-auto-mode 'html-helper-mode "\\.(jsp|tmpl)\\'")
1666 (defalias 'html-mode 'html-helper-mode)
1667 #+END_SRC
1668
1669 ** ibuffer
1670 [2014-05-21 Wed 23:54]
1671 #+BEGIN_SRC emacs-lisp :tangle yes
1672 (use-package ibuffer
1673 :defer t
1674 :bind (("C-h h" . ibuffer)
1675 ("C-x C-b" . ibuffer)
1676 ("<XF86WebCam>" . ibuffer)
1677 )
1678 :commands ibuffer
1679 :init
1680 (progn
1681 (defvar my-ibufffer-separator " • ")
1682 (setq ibuffer-filter-group-name-face 'variable-pitch
1683 ibuffer-use-header-line t
1684 ibuffer-old-time 12)
1685 (use-package ibuffer-vc
1686 :ensure t
1687 :commands
1688 (ibuffer-vc-set-filter-groups-by-vc-root
1689 ibuffer-vc-generate-filter-groups-by-vc-root))
1690 (use-package ibuffer-tramp
1691 :ensure t
1692 :commands (ibuffer-tramp-generate-filter-groups-by-tramp-connection
1693 ibuffer-tramp-set-filter-groups-by-tramp-connection))
1694 ;; Switching to ibuffer puts the cursor on the most recent buffer
1695 (defadvice ibuffer (around ibuffer-point-to-most-recent activate)
1696 "Open ibuffer with cursor pointed to most recent buffer name"
1697 (let ((recent-buffer-name (buffer-name)))
1698 ad-do-it
1699 (ibuffer-update nil t)
1700 (unless (string= recent-buffer-name "*Ibuffer*")
1701 (ibuffer-jump-to-buffer recent-buffer-name)))))
1702 :config
1703 (progn
1704 (unbind-key "M-o" ibuffer-mode-map)
1705 (bind-key "s" 'isearch-forward-regexp ibuffer-mode-map)
1706 (bind-key "." 'ibuffer-invert-sorting ibuffer-mode-map)
1707
1708 (defun ibuffer-magit-status ()
1709 (interactive)
1710 (--when-let (get-buffer "*Ibuffer*")
1711 (with-current-buffer it
1712 (let* ((selected-buffer (ibuffer-current-buffer))
1713 (buffer-path (with-current-buffer
1714 selected-buffer
1715 (or (buffer-file-name)
1716 list-buffers-directory
1717 default-directory)))
1718 (default-directory
1719 (if (file-regular-p buffer-path)
1720 (file-name-directory buffer-path)
1721 buffer-path)))
1722 (magit-status default-directory)))))
1723 (bind-key "i" 'ibuffer-magit-status ibuffer-mode-map)
1724 (bind-key "G" 'ibuffer-magit-status ibuffer-mode-map)
1725
1726 (setq ibuffer-directory-abbrev-alist
1727 (-uniq
1728 (-flatten
1729 (--map
1730 (list
1731 (cons (f-slash (f-expand (cdr it))) (concat (car it) my-ibufffer-separator))
1732 (cons (f-slash (f-canonical (cdr it))) (concat (car it) my-ibufffer-separator)))
1733
1734 '(
1735 ("dak" . "/develop/dak/")
1736 ("org" . "~/org/")
1737 ("config" . "~/.emacs.d/config/")
1738 ("tmp" . "~/tmp/")
1739 ("systmp" . "/tmp/")
1740 ("puppet" . "~/git/puppet")
1741 ("git" . "~/git/")
1742 )))))
1743
1744 (use-package ibuffer-git
1745 :ensure t)
1746 (use-package ibuffer-vc
1747 :ensure t)
1748
1749 (define-ibuffer-column size-h
1750 (:name "Size" :inline t)
1751 (cond
1752 ((> (buffer-size) 1000)
1753 (format "%7.1fk" (/ (buffer-size) 1000.0)))
1754 ((> (buffer-size) 1000000)
1755 (format "%7.1fM" (/ (buffer-size) 1000000.0)))
1756 (t
1757 (format "%8d" (buffer-size)))))
1758
1759 (require 'ibuf-ext)
1760 (define-ibuffer-filter filename2
1761 "Toggle current view to buffers with filename matching QUALIFIER."
1762 (:description "filename2"
1763 :reader (read-from-minibuffer "Filter by filename (regexp): "))
1764 ;; (ibuffer-awhen (buffer-local-value 'buffer-file-name buf)
1765 (ibuffer-awhen (with-current-buffer buf
1766 (or buffer-file-name
1767 default-directory))
1768 (string-match qualifier it)))
1769
1770 (defvar ibuffer-magit-filter-groups nil)
1771 (defun ibuffer-magit-define-filter-groups ()
1772 (when (and (not ibuffer-magit-filter-groups)
1773 (boundp 'magit-repo-dirs))
1774 (setq ibuffer-magit-filter-groups
1775 (--map (list
1776 (concat "git:: "
1777 (file-name-nondirectory (directory-file-name it)))
1778 `(filename2 . ,it))
1779 (mapcar 'cdr (magit-list-repos magit-repo-dirs))))))
1780
1781 (defun ibuffer-set-filter-groups-by-root ()
1782 (interactive)
1783 ;; (ibuffer-projectile-define-filter-groups)
1784 ;; (ibuffer-magit-define-filter-groups)
1785 (setq ibuffer-filter-groups
1786 (-concat
1787 ;; ibuffer-projectile-filter-groups
1788 ibuffer-magit-filter-groups
1789
1790 '(("MORE"
1791 (or (mode . magit-log-edit-mode)
1792 (name . "^\\*\\(traad-server\\|httpd\\|epc con.*\\|tramp/.*\\|Completions\\)\\*$")
1793 (name . "^\\*Pymacs\\*$")
1794 (name . "^\\*helm.*\\*")
1795 (name . "^\\*Compile-log\\*$")
1796 (name . "^\\*Ido Completions\\*$")
1797 (name . "^\\*magit-\\(process\\)\\*$")
1798 (name . "^ "))))
1799 '(("EMACS"
1800 (or
1801 (name . "^\\*scratch")
1802 (name . "^\\*Messages")
1803 (name . "^\\*Help")
1804 )))
1805 (ibuffer-vc-generate-filter-groups-by-vc-root)
1806 (ibuffer-tramp-generate-filter-groups-by-tramp-connection))))
1807
1808 (defun toggle-ibuffer-filter-groups ()
1809 "DOCSTRING"
1810 (interactive)
1811 (let ((ibuf (get-buffer "*Ibuffer*")))
1812 (when ibuf
1813 (with-current-buffer ibuf
1814 (let ((selected-buffer (ibuffer-current-buffer)))
1815 (if (not ibuffer-filter-groups)
1816 (ibuffer-set-filter-groups-by-root)
1817 (setq ibuffer-filter-groups nil))
1818 (pop-to-buffer ibuf)
1819 (ibuffer-update nil t)
1820 (ibuffer-jump-to-buffer (buffer-name selected-buffer )))))))
1821
1822 (bind-key "h" 'toggle-ibuffer-filter-groups ibuffer-mode-map)
1823
1824 (setq ibuffer-default-sorting-mode 'recency
1825 ibuffer-eliding-string "…"
1826 ibuffer-compile-formats t
1827 ibuffer-git-column-length 6
1828 ibuffer-show-empty-filter-groups nil
1829 ibuffer-default-directory "~/"
1830 )
1831 (setq ibuffer-formats '((mark vc-status-mini
1832 " "
1833 (git-status 8 8 :left)
1834 " "
1835 read-only modified
1836 " "
1837 (name 18 18 :left :elide)
1838 " "
1839 (size-h 9 -1 :right)
1840 " "
1841 (mode 16 16 :left :elide)
1842 " " filename-and-process)
1843 (mark " "
1844 (git-status 8 8 :left)
1845 " "
1846 (name 16 -1)
1847 " " filename)
1848 ))
1849
1850 (setq ibuffer-saved-filter-groups
1851 (quote (("flat")
1852 ("default"
1853 ("dired" (mode . dired-mode))
1854 ("perl" (mode . cperl-mode))
1855 ("puppet" (or
1856 (mode . puppet-mode)
1857 (mode . yaml-mode)))
1858 ("ruby" (mode . ruby-mode))
1859 ("emacs" (or
1860 (name . "^\\*scratch\\*$")
1861 (name . "^\\*Compile-log\\*$")
1862 (name . "^\\*Completions\\*$")
1863 (name . "^\\*Messages\\*$")
1864 (name . "^\\*Backtrace\\*$")
1865 (name . "^\\*Packages*\\*$")
1866 (name . "^\\*Help*\\*$")
1867 ))
1868 ("gnus" (or
1869 (mode . message-mode)
1870 (mode . bbdb-mode)
1871 (mode . mail-mode)
1872 (mode . gnus-group-mode)
1873 (mode . gnus-summary-mode)
1874 (mode . gnus-article-mode)
1875 (name . "^\\.bbdb$")
1876 (name . "^\\.newsrc-dribble")))
1877 ("org" (or
1878 (filename . ".*/org/.*")
1879 (mode . org-agenda-mode)
1880 (name . "^diary$")))
1881 ("other" (or
1882 (mode . magit-log-edit-mode)
1883 (name . "^\\*magit-\\(process\\|commit\\)\\*$"))))
1884 ("categorized"
1885 ;; -------------------------------------------------
1886 ;; programming languages #1
1887 ("code" (or
1888 (mode . emacs-lisp-mode)
1889 (mode . python-mode)
1890 (mode . ruby-mode)
1891 (mode . coffee-mode)
1892 (mode . js-mode)
1893 (mode . js2-mode)
1894 (mode . actionscript-mode)
1895 (mode . java-mode)
1896 (mode . sh-mode)
1897 (mode . haskell-mode)
1898 (mode . html-mode)
1899 (mode . web-mode)
1900 (mode . haml-mode)
1901 (mode . nxml-mode)
1902 (mode . css-mode)))
1903 ;; -------------------------------------------------
1904 ;; configuration/data files
1905 ("conf" (or
1906 (mode . json-mode)
1907 (mode . yaml-mode)
1908 (mode . conf-mode)))
1909 ;; -------------------------------------------------
1910 ;; text/notetaking/org
1911 ("org agenda" (mode . org-agenda-mode))
1912 ("org" (or
1913 (mode . org-mode)
1914 (name . "^\\*Calendar\\*$")
1915 (name . "^diary$")))
1916 ("text misc" (or
1917 (mode . text-mode)
1918 (mode . rst-mode)
1919 (mode . markdown-mode)))
1920 ;; -------------------------------------------------
1921 ;; media
1922 ("media" (or
1923 (mode . image-mode)))
1924 ;; -------------------------------------------------
1925 ;; misc
1926 ("w3m" (mode . w3m-mode))
1927 ("scm" (or
1928 (mode . magit-status-mode)
1929 (mode . magit-log-mode)
1930 (mode . vc-annotate-mode)))
1931 ("dired" (mode . dired-mode))
1932 ("help" (or
1933 (mode . Info-mode)
1934 (mode . help-mode)
1935 (mode . Man-mode)
1936 (name . "^\\*Personal Keybindings\\*$")))
1937 ;; -------------------------------------------------
1938 ;; *buffer* buffers
1939 ("MORE" (or (mode . magit-log-edit-mode)
1940 (name . "^\\*\\(traad-server\\|httpd\\|epc con.*\\|tramp/.*\\|Completions\\)\\*$")
1941 (name . "^\\*Pymacs\\*$")
1942 (name . "^\\*Compile-log\\*$")
1943 (name . "^\\*Completions\\*$")
1944 (name . "^\\*magit-\\(process\\|commit\\)\\*$")
1945 (name . "^ ")))
1946 ("*buffer*" (name . "\\*.*\\*"))))))
1947
1948 (add-hook 'ibuffer-mode-hook
1949 (lambda ()
1950 (ibuffer-auto-mode 1)
1951 (ibuffer-switch-to-saved-filter-groups "default")))
1952
1953 ;; Unless you turn this variable on you will be prompted every time
1954 ;; you want to delete a buffer, even unmodified ones, which is way
1955 ;; too cautious for most people. You’ll still be prompted for
1956 ;; confirmation when deleting modified buffers after the option has
1957 ;; been turned off.
1958 (setq ibuffer-expert t)
1959
1960 ))
1961 #+END_SRC
1962 ** icicles
1963 [[http://article.gmane.org/gmane.emacs.orgmode/4574/match%3Dicicles]["In case you never heard of it, Icicles is to ‘TAB’ completion what
1964 ‘TAB’ completion is to typing things manually every time.”]]
1965 #+BEGIN_SRC emacs-lisp :tangle yes
1966 (use-package icicles
1967 :load-path "elisp/icicle/"
1968 :init
1969 (icy-mode 1))
1970 #+END_SRC
1971 ** icomplete
1972 Incremental mini-buffer completion preview: Type in the minibuffer,
1973 list of matching commands is echoed
1974 #+BEGIN_SRC emacs-lisp :tangle yes
1975 (icomplete-mode 99)
1976 #+END_SRC
1977 ** info stuff
1978 [2014-05-20 Tue 23:35]
1979 #+BEGIN_SRC emacs-lisp :tangle yes
1980 (use-package info
1981 :bind ("C-h C-i" . info-lookup-symbol)
1982
1983 :config
1984 (progn
1985 ;; (defadvice info-setup (after load-info+ activate)
1986 ;; (use-package info+))
1987
1988 (defadvice Info-exit (after remove-info-window activate)
1989 "When info mode is quit, remove the window."
1990 (if (> (length (window-list)) 1)
1991 (delete-window)))))
1992
1993 (use-package info-look
1994 :commands info-lookup-add-help)
1995 #+END_SRC
1996 ** linum (line number)
1997 Various modes should have line numbers in front of each line.
1998
1999 But then there are some where it would just be deadly - like org-mode,
2000 gnus, so we have a list of modes where we don't want to see it.
2001 #+BEGIN_SRC emacs-lisp :tangle yes
2002 (use-package linum
2003 :diminish linum-mode
2004 :config
2005 (progn
2006 (setq linum-format "%3d ")
2007 (setq linum-mode-inhibit-modes-list '(org-mode
2008 eshell-mode
2009 shell-mode
2010 gnus-group-mode
2011 gnus-summary-mode
2012 gnus-article-mode))
2013
2014 (defadvice linum-on (around linum-on-inhibit-for-modes)
2015 "Stop the load of linum-mode for some major modes."
2016 (unless (member major-mode linum-mode-inhibit-modes-list)
2017 ad-do-it))
2018
2019 (ad-activate 'linum-on))
2020 :init
2021 (global-linum-mode 1))
2022 #+END_SRC
2023
2024 ** lisp editing stuff
2025 [2013-04-21 So 21:00]
2026 I'm not doing much of it, except for my emacs and gnus configs, but
2027 then I like it nice too...
2028 #+BEGIN_SRC emacs-lisp :tangle yes
2029 (bind-key "TAB" 'lisp-complete-symbol read-expression-map)
2030
2031 (use-package paredit
2032 :ensure paredit
2033 :diminish paredit-mode " π")
2034
2035 (setq lisp-coding-hook 'lisp-coding-defaults)
2036 (setq interactive-lisp-coding-hook 'interactive-lisp-coding-defaults)
2037
2038 (setq prelude-emacs-lisp-mode-hook 'prelude-emacs-lisp-mode-defaults)
2039 (add-hook 'emacs-lisp-mode-hook (lambda ()
2040 (run-hooks 'prelude-emacs-lisp-mode-hook)))
2041
2042 (bind-key "M-." 'find-function-at-point emacs-lisp-mode-map)
2043
2044 (after "elisp-slime-nav"
2045 '(diminish 'elisp-slime-nav-mode))
2046 (after "rainbow-mode"
2047 '(diminish 'rainbow-mode))
2048 (after "eldoc"
2049 '(diminish 'eldoc-mode))
2050 #+END_SRC
2051
2052 ** magit
2053 [2013-04-21 So 20:48]
2054 magit is a mode for interacting with git.
2055 #+BEGIN_SRC emacs-lisp :tangle yes
2056 (use-package magit
2057 :ensure magit
2058 :commands (magit-log magit-run-gitk magit-run-git-gui magit-status
2059 magit-git-repo-p magit-list-repos)
2060 :defer t
2061 :bind (("C-x g" . magit-status)
2062 ("C-x G" . magit-status-with-prefix))
2063 :init
2064 (progn
2065 (setq magit-commit-signoff t
2066 magit-repo-dirs '("~/git"
2067 "/develop/vcs/"
2068 "/develop/Debian/"
2069 )
2070 magit-repo-dirs-depth 4
2071 magit-log-auto-more t)
2072 (use-package magit-blame
2073 :commands magit-blame-mode)
2074
2075 (use-package magit-filenotify
2076 :ensure magit-filenotify)
2077
2078 (use-package magit-svn
2079 :ensure magit-svn
2080 :commands (magit-svn-mode
2081 turn-on-magit-svn))
2082
2083 (add-hook 'magit-mode-hook 'hl-line-mode)
2084 (defun magit-status-with-prefix ()
2085 (interactive)
2086 (let ((current-prefix-arg '(4)))
2087 (call-interactively 'magit-status)))
2088 )
2089 :config
2090 (progn
2091 (setenv "GIT_PAGER" "")
2092
2093 (unbind-key "M-h" magit-mode-map)
2094 (unbind-key "M-s" magit-mode-map)
2095
2096 (add-hook 'magit-log-edit-mode-hook
2097 #'(lambda ()
2098 (set-fill-column 72)
2099 (flyspell-mode)))
2100 ))
2101 #+END_SRC
2102 ** markdown-mode
2103 [2014-05-20 Tue 23:04]
2104 #+BEGIN_SRC emacs-lisp :tangle yes
2105 (use-package markdown-mode
2106 :mode (("\\.md\\'" . markdown-mode)
2107 ("\\.mdwn\\'" . markdown-mode))
2108 :defer t)
2109 #+END_SRC
2110 ** message
2111 #+BEGIN_SRC emacs-lisp :tangle yes
2112 (require 'message)
2113 (setq message-kill-buffer-on-exit t)
2114 #+END_SRC
2115 ** mingus
2116 [[https://github.com/pft/mingus][Mingus]] is a nice interface to mpd, the Music Player Daemon.
2117
2118 I want to access it from anywhere using =F6=.
2119 #+BEGIN_SRC emacs-lisp :tangle yes
2120 (use-package mingus-stays-home
2121 :bind ( "<f6>" . mingus)
2122 :defer t
2123 :config
2124 (progn
2125 (setq mingus-dired-add-keys t)
2126 (setq mingus-mode-always-modeline nil)
2127 (setq mingus-mode-line-show-elapsed-percentage nil)
2128 (setq mingus-mode-line-show-volume nil)
2129 (setq mingus-mpd-config-file "/etc/mpd.conf")
2130 (setq mingus-mpd-playlist-dir "/var/lib/mpd/playlists")
2131 (setq mingus-mpd-root "/share/music/")))
2132 #+END_SRC
2133
2134 ** miniedit
2135 Edit minibuffer in a full (text-mode) buffer by pressing *M-C-e*.
2136 #+BEGIN_SRC emacs-lisp :tangle yes
2137 (use-package miniedit
2138 :ensure miniedit
2139 :config
2140 (progn
2141 (bind-key "M-C-e" 'miniedit minibuffer-local-map)
2142 (bind-key "M-C-e" 'miniedit minibuffer-local-ns-map)
2143 (bind-key "M-C-e" 'miniedit minibuffer-local-completion-map)
2144 (bind-key "M-C-e" 'miniedit minibuffer-local-must-match-map)
2145 ))
2146 #+END_SRC
2147
2148 ** mmm-mode
2149 [2013-05-21 Tue 23:39]
2150 MMM Mode is a minor mode for Emacs that allows Multiple Major Modes to
2151 coexist in one buffer.
2152 #+BEGIN_SRC emacs-lisp :tangle yes
2153 (use-package mmm-auto
2154 :ensure mmm-mode
2155 :init
2156 (progn
2157 (setq mmm-global-mode 'buffers-with-submode-classes)
2158 (setq mmm-submode-decoration-level 2)
2159 (eval-after-load 'mmm-vars
2160 '(progn
2161 (mmm-add-group
2162 'html-css
2163 '((css-cdata
2164 :submode css-mode
2165 :face mmm-code-submode-face
2166 :front "<style[^>]*>[ \t\n]*\\(//\\)?<!\\[CDATA\\[[ \t]*\n?"
2167 :back "[ \t]*\\(//\\)?]]>[ \t\n]*</style>"
2168 :insert ((?j js-tag nil @ "<style type=\"text/css\">"
2169 @ "\n" _ "\n" @ "</script>" @)))
2170 (css
2171 :submode css-mode
2172 :face mmm-code-submode-face
2173 :front "<style[^>]*>[ \t]*\n?"
2174 :back "[ \t]*</style>"
2175 :insert ((?j js-tag nil @ "<style type=\"text/css\">"
2176 @ "\n" _ "\n" @ "</style>" @)))
2177 (css-inline
2178 :submode css-mode
2179 :face mmm-code-submode-face
2180 :front "style=\""
2181 :back "\"")))
2182 (dolist (mode (list 'html-mode 'nxml-mode))
2183 (mmm-add-mode-ext-class mode "\\.r?html\\(\\.erb\\)?\\'" 'html-css))
2184 (mmm-add-mode-ext-class 'html-mode "\\.php\\'" 'html-php)
2185 ))))
2186 #+END_SRC
2187
2188 ** mo-git-blame
2189 This is [[https://github.com/mbunkus/mo-git-blame][mo-git-blame -- An interactive, iterative 'git blame' mode for
2190 Emacs]].
2191
2192 #+BEGIN_SRC emacs-lisp :tangle yes
2193 (use-package mo-git-blame
2194 :ensure mo-git-blame
2195 :commands (mo-git-blame-current
2196 mo-git-blame-file)
2197 :config
2198 (progn
2199 (setq mo-git-blame-blame-window-width 25)))
2200 #+END_SRC
2201
2202 ** multiple cursors
2203 [2013-04-08 Mon 23:57]
2204 Use multiple cursors mode. See [[http://emacsrocks.com/e13.html][Emacs Rocks! multiple cursors]] and
2205 [[https://github.com/emacsmirror/multiple-cursors][emacsmirror/multiple-cursors · GitHub]]
2206 #+BEGIN_SRC emacs-lisp :tangle yes
2207 (use-package multiple-cursors
2208 :ensure multiple-cursors
2209 :defer t
2210 :bind (("C-S-c C-S-c" . mc/edit-lines)
2211 ("C->" . mc/mark-next-like-this)
2212 ("C-<" . mc/mark-previous-like-this)
2213 ("C-c C-<" . mc/mark-all-like-this))
2214 :config
2215 (progn
2216 (bind-key "a" 'mc/mark-all-like-this region-bindings-mode-map)
2217 (bind-key "p" 'mc/mark-previous-like-this region-bindings-mode-map)
2218 (bind-key "n" 'mc/mark-next-like-this region-bindings-mode-map)
2219 (bind-key "l" 'mc/edit-lines region-bindings-mode-map)
2220 (bind-key "m" 'mc/mark-more-like-this-extended region-bindings-mode-map)
2221 (setq mc/list-file (expand-file-name "mc-cache.el" jj-cache-dir))))
2222 #+END_SRC
2223 ** nxml
2224 [2013-05-22 Wed 22:02]
2225 nxml-mode is a major mode for editing XML.
2226 #+BEGIN_SRC emacs-lisp :tangle yes
2227 (add-auto-mode
2228 'nxml-mode
2229 (concat "\\."
2230 (regexp-opt
2231 '("xml" "xsd" "sch" "rng" "xslt" "svg" "rss"
2232 "gpx" "tcx"))
2233 "\\'"))
2234 (setq magic-mode-alist (cons '("<\\?xml " . nxml-mode) magic-mode-alist))
2235 (fset 'xml-mode 'nxml-mode)
2236 (setq nxml-slash-auto-complete-flag t)
2237
2238 ;; See: http://sinewalker.wordpress.com/2008/06/26/pretty-printing-xml-with-emacs-nxml-mode/
2239 (defun pp-xml-region (begin end)
2240 "Pretty format XML markup in region. The function inserts
2241 linebreaks to separate tags that have nothing but whitespace
2242 between them. It then indents the markup by using nxml's
2243 indentation rules."
2244 (interactive "r")
2245 (save-excursion
2246 (nxml-mode)
2247 (goto-char begin)
2248 (while (search-forward-regexp "\>[ \\t]*\<" nil t)
2249 (backward-char) (insert "\n"))
2250 (indent-region begin end)))
2251
2252 ;;----------------------------------------------------------------------------
2253 ;; Integration with tidy for html + xml
2254 ;;----------------------------------------------------------------------------
2255 ;; tidy is autoloaded
2256 (eval-after-load 'tidy
2257 '(progn
2258 (add-hook 'nxml-mode-hook (lambda () (tidy-build-menu nxml-mode-map)))
2259 (add-hook 'html-mode-hook (lambda () (tidy-build-menu html-mode-map)))
2260 ))
2261
2262 #+END_SRC
2263 ** org :FIXME:
2264 *** General settings
2265 [2013-04-28 So 17:06]
2266
2267 I use org-mode a lot and, having my config for this based on [[*Bernt%20Hansen][the config of Bernt Hansen]],
2268 it is quite extensive. Nevertheless, it starts out small, loading it.
2269 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2270 (require 'org)
2271 #+END_SRC
2272
2273 My browsers (Conkeror, Iceweasel) can store links in org-mode. For
2274 that we need org-protocol.
2275 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2276 (require 'org-protocol)
2277 #+END_SRC
2278
2279 *** Agenda
2280
2281 My current =org-agenda-files= variable only includes a set of
2282 directories.
2283 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2284 (setq org-agenda-files (quote ("~/org/"
2285 "~/org/debian"
2286 "~/org/debconf"
2287 "~/org/spi"
2288 "~/org/nsb"
2289 )))
2290 (setq org-default-notes-file "~/org/notes.org")
2291 #+END_SRC
2292 =org-mode= manages the =org-agenda-files= variable automatically using
2293 =C-c [= and =C-c ]= to add and remove files respectively. However,
2294 this replaces my directory list with a list of explicit filenames
2295 instead and is not what I want. If this occurs then adding a new org
2296 file to any of the above directories will not contribute to my agenda
2297 and I will probably miss something important.
2298
2299 I have disabled the =C-c [= and =C-c ]= keys in =org-mode-hook= to
2300 prevent messing up my list of directories in the =org-agenda-files=
2301 variable. I just add and remove directories manually here. Changing
2302 the list of directories in =org-agenda-files= happens very rarely
2303 since new files in existing directories are automatically picked up.
2304
2305 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2306 ;; Keep tasks with dates on the global todo lists
2307 (setq org-agenda-todo-ignore-with-date nil)
2308
2309 ;; Keep tasks with deadlines on the global todo lists
2310 (setq org-agenda-todo-ignore-deadlines nil)
2311
2312 ;; Keep tasks with scheduled dates on the global todo lists
2313 (setq org-agenda-todo-ignore-scheduled nil)
2314
2315 ;; Keep tasks with timestamps on the global todo lists
2316 (setq org-agenda-todo-ignore-timestamp nil)
2317
2318 ;; Remove completed deadline tasks from the agenda view
2319 (setq org-agenda-skip-deadline-if-done t)
2320
2321 ;; Remove completed scheduled tasks from the agenda view
2322 (setq org-agenda-skip-scheduled-if-done t)
2323
2324 ;; Remove completed items from search results
2325 (setq org-agenda-skip-timestamp-if-done t)
2326
2327 ;; Include agenda archive files when searching for things
2328 (setq org-agenda-text-search-extra-files (quote (agenda-archives)))
2329
2330 ;; Show all future entries for repeating tasks
2331 (setq org-agenda-repeating-timestamp-show-all t)
2332
2333 ;; Show all agenda dates - even if they are empty
2334 (setq org-agenda-show-all-dates t)
2335
2336 ;; Sorting order for tasks on the agenda
2337 (setq org-agenda-sorting-strategy
2338 (quote ((agenda habit-down time-up user-defined-up priority-down effort-up category-keep)
2339 (todo category-up priority-down effort-up)
2340 (tags category-up priority-down effort-up)
2341 (search category-up))))
2342
2343 ;; Start the weekly agenda on Monday
2344 (setq org-agenda-start-on-weekday 1)
2345
2346 ;; Enable display of the time grid so we can see the marker for the current time
2347 (setq org-agenda-time-grid (quote ((daily today remove-match)
2348 #("----------------" 0 16 (org-heading t))
2349 (0800 1000 1200 1400 1500 1700 1900 2100))))
2350
2351 ;; Display tags farther right
2352 (setq org-agenda-tags-column -102)
2353
2354 ; position the habit graph on the agenda to the right of the default
2355 (setq org-habit-graph-column 50)
2356
2357 ; turn habits back on
2358 (run-at-time "06:00" 86400 '(lambda () (setq org-habit-show-habits t)))
2359
2360 ;;
2361 ;; Agenda sorting functions
2362 ;;
2363 (setq org-agenda-cmp-user-defined 'bh/agenda-sort)
2364
2365
2366 (setq org-deadline-warning-days 30)
2367
2368 ;; Always hilight the current agenda line
2369 (add-hook 'org-agenda-mode-hook
2370 '(lambda () (hl-line-mode 1))
2371 'append)
2372 #+END_SRC
2373
2374 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2375 (setq org-agenda-persistent-filter t)
2376 (add-hook 'org-agenda-mode-hook
2377 '(lambda () (org-defkey org-agenda-mode-map "W" 'bh/widen))
2378 'append)
2379
2380 (add-hook 'org-agenda-mode-hook
2381 '(lambda () (org-defkey org-agenda-mode-map "F" 'bh/restrict-to-file-or-follow))
2382 'append)
2383
2384 (add-hook 'org-agenda-mode-hook
2385 '(lambda () (org-defkey org-agenda-mode-map "N" 'bh/narrow-to-subtree))
2386 'append)
2387
2388 (add-hook 'org-agenda-mode-hook
2389 '(lambda () (org-defkey org-agenda-mode-map "U" 'bh/narrow-up-one-level))
2390 'append)
2391
2392 (add-hook 'org-agenda-mode-hook
2393 '(lambda () (org-defkey org-agenda-mode-map "P" 'bh/narrow-to-project))
2394 'append)
2395
2396 ; Rebuild the reminders everytime the agenda is displayed
2397 (add-hook 'org-finalize-agenda-hook 'bh/org-agenda-to-appt 'append)
2398
2399 ;(if (file-exists-p "~/org/refile.org")
2400 ; (add-hook 'after-init-hook 'bh/org-agenda-to-appt))
2401
2402 ; Activate appointments so we get notifications
2403 (appt-activate t)
2404
2405 (setq org-agenda-log-mode-items (quote (closed clock state)))
2406 (if (> emacs-major-version 23)
2407 (setq org-agenda-span 3)
2408 (setq org-agenda-ndays 3))
2409
2410 (setq org-agenda-show-all-dates t)
2411 (setq org-agenda-start-on-weekday nil)
2412 (setq org-deadline-warning-days 14)
2413
2414 #+END_SRC
2415 *** Global keybindings.
2416 Start off by defining a series of keybindings.
2417
2418 Well, first we remove =C-c [= and =C-c ]=, as all agenda directories are
2419 setup manually, not by org-mode. Also turn off =C-c ;=, which
2420 comments headlines - a function never used.
2421 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2422 (add-hook 'org-mode-hook
2423 (lambda ()
2424 (org-defkey org-mode-map "\C-c[" 'undefined)
2425 (org-defkey org-mode-map "\C-c]" 'undefined)
2426 (org-defkey org-mode-map "\C-c;" 'undefined))
2427 'append)
2428 #+END_SRC
2429
2430 And now a largish set of keybindings...
2431 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2432 (bind-key "C-c l" 'org-store-link)
2433 (bind-key "C-c a" 'org-agenda)
2434 (bind-key "C-c b" 'org-iswitchb)
2435 (define-key mode-specific-map [?a] 'org-agenda)
2436
2437 (bind-key "<f12>" 'org-agenda)
2438 (bind-key "<f5>" 'bh/org-todo)
2439 (bind-key "<S-f5>" 'bh/widen)
2440 (bind-key "<f7>" 'bh/set-truncate-lines)
2441 (bind-key "<f8>" 'org-cycle-agenda-files)
2442
2443 (bind-key "<f9> <f9>" 'bh/show-org-agenda)
2444 (bind-key "<f9> b" 'bbdb)
2445 (bind-key "<f9> c" 'calendar)
2446 (bind-key "<f9> f" 'boxquote-insert-file)
2447 (bind-key "<f9> h" 'bh/hide-other)
2448 (bind-key "<f9> n" 'org-narrow-to-subtree)
2449 (bind-key "<f9> w" 'widen)
2450 (bind-key "<f9> u" 'bh/narrow-up-one-level)
2451 (bind-key "<f9> I" 'bh/punch-in)
2452 (bind-key "<f9> O" 'bh/punch-out)
2453 (bind-key "<f9> H" 'jj/punch-in-hw)
2454 (bind-key "<f9> W" 'jj/punch-out-hw)
2455 (bind-key "<f9> o" 'bh/make-org-scratch)
2456 (bind-key "<f9> p" 'bh/phone-call)
2457 (bind-key "<f9> r" 'boxquote-region)
2458 (bind-key "<f9> s" 'bh/switch-to-scratch)
2459 (bind-key "<f9> t" 'bh/insert-inactive-timestamp)
2460 (bind-key "<f9> T" 'tabify)
2461 (bind-key "<f9> U" 'untabify)
2462 (bind-key "<f9> v" 'visible-mode)
2463 (bind-key "<f9> SPC" 'bh/clock-in-last-task)
2464 (bind-key "C-<f9>" 'previous-buffer)
2465 (bind-key "C-<f10>" 'next-buffer)
2466 (bind-key "M-<f9>" 'org-toggle-inline-images)
2467 ;(bind-key "C-x n r" 'narrow-to-region)
2468 (bind-key "<f11>" 'org-clock-goto)
2469 (bind-key "C-<f11>" 'org-clock-in)
2470 (bind-key "C-M-r" 'org-capture)
2471 (bind-key "C-c r" 'org-capture)
2472 (bind-key "C-S-<f12>" 'bh/save-then-publish)
2473 (bind-key "C-k" 'jj-org-kill-line org-mode-map)
2474
2475 #+END_SRC
2476
2477 *** Tasks, States, Todo fun
2478
2479 First we define the global todo keywords.
2480 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2481 (setq org-todo-keywords
2482 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d@/!)")
2483 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "DELEGATED(g@/!)" "|" "CANCELLED(c@/!)" "PHONE"))))
2484
2485 (setq org-todo-keyword-faces
2486 (quote (("TODO" :foreground "red" :weight bold)
2487 ("NEXT" :foreground "light blue" :weight bold)
2488 ("DONE" :foreground "forest green" :weight bold)
2489 ("WAITING" :foreground "orange" :weight bold)
2490 ("HOLD" :foreground "orange" :weight bold)
2491 ("DELEGATED" :foreground "yellow" :weight bold)
2492 ("CANCELLED" :foreground "dark green" :weight bold)
2493 ("PHONE" :foreground "dark green" :weight bold))))
2494 #+END_SRC
2495
2496 **** Fast Todo Selection
2497 Fast todo selection allows changing from any task todo state to any
2498 other state directly by selecting the appropriate key from the fast
2499 todo selection key menu.
2500 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2501 (setq org-use-fast-todo-selection t)
2502 #+END_SRC
2503 Changing a task state is done with =C-c C-t KEY=
2504
2505 where =KEY= is the appropriate fast todo state selection key as defined in =org-todo-keywords=.
2506
2507 The setting
2508 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2509 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
2510 #+END_SRC
2511 allows changing todo states with S-left and S-right skipping all of
2512 the normal processing when entering or leaving a todo state. This
2513 cycles through the todo states but skips setting timestamps and
2514 entering notes which is very convenient when all you want to do is fix
2515 up the status of an entry.
2516
2517 **** Todo State Triggers
2518 I have a few triggers that automatically assign tags to tasks based on
2519 state changes. If a task moves to =CANCELLED= state then it gets a
2520 =CANCELLED= tag. Moving a =CANCELLED= task back to =TODO= removes the
2521 =CANCELLED= tag. These are used for filtering tasks in agenda views
2522 which I'll talk about later.
2523
2524 The triggers break down to the following rules:
2525
2526 - Moving a task to =CANCELLED= adds a =CANCELLED= tag
2527 - Moving a task to =WAITING= adds a =WAITING= tag
2528 - Moving a task to =HOLD= adds a =WAITING= tag
2529 - Moving a task to a done state removes a =WAITING= tag
2530 - Moving a task to =TODO= removes =WAITING= and =CANCELLED= tags
2531 - Moving a task to =NEXT= removes a =WAITING= tag
2532 - Moving a task to =DONE= removes =WAITING= and =CANCELLED= tags
2533
2534 The tags are used to filter tasks in the agenda views conveniently.
2535 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2536 (setq org-todo-state-tags-triggers
2537 (quote (("CANCELLED" ("CANCELLED" . t))
2538 ("WAITING" ("WAITING" . t))
2539 ("HOLD" ("WAITING" . t) ("HOLD" . t))
2540 (done ("WAITING") ("HOLD"))
2541 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
2542 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
2543 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
2544 #+END_SRC
2545
2546 *** Capturing new tasks
2547 Org capture replaces the old remember mode.
2548 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2549 (setq org-directory "~/org")
2550 (setq org-default-notes-file "~/org/refile.org")
2551
2552 ;; Capture templates for: TODO tasks, Notes, appointments, phone calls, and org-protocol
2553 ;; see http://orgmode.org/manual/Template-elements.html
2554 (setq org-capture-templates
2555 (quote (("t" "todo" entry (file "~/org/refile.org")
2556 "* TODO %?\nAdded: %U\n"
2557 :clock-in t :clock-resume t)
2558 ("l" "linktodo" entry (file "~/org/refile.org")
2559 "* TODO %?\nAdded: %U\n%a\n"
2560 :clock-in t :clock-resume t)
2561 ("r" "respond" entry (file "~/org/refile.org")
2562 "* TODO Respond to %:from on %:subject\nSCHEDULED: %t\nAdded: %U\n%a\n"
2563 :clock-in t :clock-resume t :immediate-finish t)
2564 ("n" "note" entry (file "~/org/refile.org")
2565 "* %? :NOTE:\nAdded: %U\n%a\n"
2566 :clock-in t :clock-resume t)
2567 ("d" "Delegated" entry (file "~/org/refile.org")
2568 "* DELEGATED %?\nAdded: %U\n%a\n"
2569 :clock-in t :clock-resume t)
2570 ("j" "Journal" entry (file+datetree "~/org/diary.org")
2571 "* %?\nAdded: %U\n"
2572 :clock-in t :clock-resume t)
2573 ("w" "org-protocol" entry (file "~/org/refile.org")
2574 "* TODO Review %c\nAdded: %U\n"
2575 :immediate-finish t)
2576 ("p" "Phone call" entry (file "~/org/refile.org")
2577 "* PHONE %? :PHONE:\nAdded: %U"
2578 :clock-in t :clock-resume t)
2579 ("x" "Bookmark link" entry (file "~/org/refile.org")
2580 "* Bookmark: %c\n%i\nAdded: %U\n"
2581 :immediate-finish t)
2582 ("h" "Habit" entry (file "~/org/refile.org")
2583 "* NEXT %?\n:PROPERTIES:\n:STYLE: habit\n:REPEAT_TO_STATE: NEXT\n:END:\nAdded: %U\nSCHEDULED: %(format-time-string \"<%Y-%m-%d %a .+1d/3d>\")\n")
2584 )))
2585 #+END_SRC
2586
2587 Capture mode now handles automatically clocking in and out of a
2588 capture task. This all works out of the box now without special hooks.
2589 When I start a capture mode task the task is clocked in as specified
2590 by =:clock-in t= and when the task is filed with =C-c C-c= the clock
2591 resumes on the original clocking task.
2592
2593 The quick clocking in and out of capture mode tasks (often it takes
2594 less than a minute to capture some new task details) can leave
2595 empty clock drawers in my tasks which aren't really useful.
2596 The following prevents this.
2597 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2598 (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
2599 #+END_SRC
2600
2601 *** Refiling
2602 All my newly captured entries end up in =refile.org= and want to be
2603 moved over to the right place. The following is the setup for it.
2604 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2605 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
2606 (setq org-refile-targets (quote ((nil :maxlevel . 9)
2607 (org-agenda-files :maxlevel . 9))))
2608
2609 ; Use full outline paths for refile targets - we file directly with IDO
2610 (setq org-refile-use-outline-path t)
2611
2612 ; Targets complete directly with IDO
2613 (setq org-outline-path-complete-in-steps nil)
2614
2615 ; Allow refile to create parent tasks with confirmation
2616 (setq org-refile-allow-creating-parent-nodes (quote confirm))
2617
2618 ; Use IDO for both buffer and file completion and ido-everywhere to t
2619 (setq org-completion-use-ido t)
2620 (setq org-completion-use-iswitchb nil)
2621 :; Use IDO for both buffer and file completion and ido-everywhere to t
2622 ;(setq ido-everywhere t)
2623 ;(setq ido-max-directory-size 100000)
2624 ;(ido-mode (quote both))
2625 ; Use the current window when visiting files and buffers with ido
2626 (setq ido-default-file-method 'selected-window)
2627 (setq ido-default-buffer-method 'selected-window)
2628
2629 ;;;; Refile settings
2630 (setq org-refile-target-verify-function 'bh/verify-refile-target)
2631 #+END_SRC
2632
2633 *** Custom agenda
2634 Agenda view is the central place for org-mode interaction...
2635 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2636 ;; Do not dim blocked tasks
2637 (setq org-agenda-dim-blocked-tasks nil)
2638 ;; Compact the block agenda view
2639 (setq org-agenda-compact-blocks t)
2640
2641 ;; Custom agenda command definitions
2642 (setq org-agenda-custom-commands
2643 (quote (("N" "Notes" tags "NOTE"
2644 ((org-agenda-overriding-header "Notes")
2645 (org-tags-match-list-sublevels t)))
2646 ("h" "Habits" tags-todo "STYLE=\"habit\""
2647 ((org-agenda-overriding-header "Habits")
2648 (org-agenda-sorting-strategy
2649 '(todo-state-down effort-up category-keep))))
2650 (" " "Agenda"
2651 ((agenda "" nil)
2652 (tags "REFILE"
2653 ((org-agenda-overriding-header "Tasks to Refile")
2654 (org-tags-match-list-sublevels nil)))
2655 (tags-todo "-HOLD-CANCELLED/!"
2656 ((org-agenda-overriding-header "Projects")
2657 (org-agenda-skip-function 'bh/skip-non-projects)
2658 (org-agenda-sorting-strategy
2659 '(category-keep))))
2660 (tags-todo "-CANCELLED/!"
2661 ((org-agenda-overriding-header "Stuck Projects")
2662 (org-agenda-skip-function 'bh/skip-non-stuck-projects)))
2663 (tags-todo "-WAITING-CANCELLED/!NEXT"
2664 ((org-agenda-overriding-header "Next Tasks")
2665 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
2666 (org-agenda-todo-ignore-scheduled t)
2667 (org-agenda-todo-ignore-deadlines t)
2668 (org-agenda-todo-ignore-with-date t)
2669 (org-tags-match-list-sublevels t)
2670 (org-agenda-sorting-strategy
2671 '(todo-state-down effort-up category-keep))))
2672 (tags-todo "-REFILE-CANCELLED/!-HOLD-WAITING"
2673 ((org-agenda-overriding-header "Tasks")
2674 (org-agenda-skip-function 'bh/skip-project-tasks-maybe)
2675 (org-agenda-todo-ignore-scheduled t)
2676 (org-agenda-todo-ignore-deadlines t)
2677 (org-agenda-todo-ignore-with-date t)
2678 (org-agenda-sorting-strategy
2679 '(category-keep))))
2680 (tags-todo "-CANCELLED+WAITING/!"
2681 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
2682 (org-agenda-skip-function 'bh/skip-stuck-projects)
2683 (org-tags-match-list-sublevels nil)
2684 (org-agenda-todo-ignore-scheduled 'future)
2685 (org-agenda-todo-ignore-deadlines 'future)))
2686 (tags "-REFILE/"
2687 ((org-agenda-overriding-header "Tasks to Archive")
2688 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
2689 (org-tags-match-list-sublevels nil))))
2690 nil)
2691 ("r" "Tasks to Refile" tags "REFILE"
2692 ((org-agenda-overriding-header "Tasks to Refile")
2693 (org-tags-match-list-sublevels nil)))
2694 ("#" "Stuck Projects" tags-todo "-CANCELLED/!"
2695 ((org-agenda-overriding-header "Stuck Projects")
2696 (org-agenda-skip-function 'bh/skip-non-stuck-projects)))
2697 ("n" "Next Tasks" tags-todo "-WAITING-CANCELLED/!NEXT"
2698 ((org-agenda-overriding-header "Next Tasks")
2699 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
2700 (org-agenda-todo-ignore-scheduled t)
2701 (org-agenda-todo-ignore-deadlines t)
2702 (org-agenda-todo-ignore-with-date t)
2703 (org-tags-match-list-sublevels t)
2704 (org-agenda-sorting-strategy
2705 '(todo-state-down effort-up category-keep))))
2706 ("R" "Tasks" tags-todo "-REFILE-CANCELLED/!-HOLD-WAITING"
2707 ((org-agenda-overriding-header "Tasks")
2708 (org-agenda-skip-function 'bh/skip-project-tasks-maybe)
2709 (org-agenda-sorting-strategy
2710 '(category-keep))))
2711 ("p" "Projects" tags-todo "-HOLD-CANCELLED/!"
2712 ((org-agenda-overriding-header "Projects")
2713 (org-agenda-skip-function 'bh/skip-non-projects)
2714 (org-agenda-sorting-strategy
2715 '(category-keep))))
2716 ("w" "Waiting Tasks" tags-todo "-CANCELLED+WAITING/!"
2717 ((org-agenda-overriding-header "Waiting and Postponed tasks"))
2718 (org-tags-match-list-sublevels nil))
2719 ("A" "Tasks to Archive" tags "-REFILE/"
2720 ((org-agenda-overriding-header "Tasks to Archive")
2721 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
2722 (org-tags-match-list-sublevels nil))))))
2723
2724 ; Overwrite the current window with the agenda
2725 (setq org-agenda-window-setup 'current-window)
2726
2727 #+END_SRC
2728
2729 *** Time
2730 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2731 ;;
2732 ;; Resume clocking task when emacs is restarted
2733 (org-clock-persistence-insinuate)
2734 ;;
2735 ;; Show lot sof clocking history so it's easy to pick items off the C-F11 list
2736 (setq org-clock-history-length 36)
2737 ;; Resume clocking task on clock-in if the clock is open
2738 (setq org-clock-in-resume t)
2739 ;; Change tasks to NEXT when clocking in
2740 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
2741 ;; Separate drawers for clocking and logs
2742 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
2743 ;; Save clock data and state changes and notes in the LOGBOOK drawer
2744 (setq org-clock-into-drawer t)
2745 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
2746 (setq org-clock-out-remove-zero-time-clocks t)
2747 ;; Clock out when moving task to a done state
2748 (setq org-clock-out-when-done (quote ("DONE" "WAITING" "DELEGATED" "CANCELLED")))
2749 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
2750 (setq org-clock-persist t)
2751 ;; Do not prompt to resume an active clock
2752 (setq org-clock-persist-query-resume nil)
2753 ;; Enable auto clock resolution for finding open clocks
2754 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
2755 ;; Include current clocking task in clock reports
2756 (setq org-clock-report-include-clocking-task t)
2757
2758 ; use discrete minute intervals (no rounding) increments
2759 (setq org-time-stamp-rounding-minutes (quote (1 1)))
2760
2761 (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
2762
2763 (setq bh/keep-clock-running nil)
2764
2765 (setq org-agenda-clock-consistency-checks
2766 (quote (:max-duration "4:00"
2767 :min-duration 0
2768 :max-gap 0
2769 :gap-ok-around ("4:00"))))
2770
2771 #+END_SRC
2772
2773 **** Setting a default clock task
2774 Per default the =** Organization= task in my tasks.org file receives
2775 misc clock time. This is the task I clock in on when I punch in at the
2776 start of my work day with =F9-I=. Punching-in anywhere clocks in this
2777 Organization task as the default task.
2778
2779 If I want to change the default clocking task I just visit the
2780 new task in any org buffer and clock it in with =C-u C-u C-c C-x
2781 C-i=. Now this new task that collects miscellaneous clock
2782 minutes when the clock would normally stop.
2783
2784 You can quickly clock in the default clocking task with =C-u C-c
2785 C-x C-i d=. Another option is to repeatedly clock out so the
2786 clock moves up the project tree until you clock out the
2787 top-level task and the clock moves to the default task.
2788
2789 **** Reporting
2790 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2791 ;; Agenda clock report parameters
2792 (setq org-agenda-clockreport-parameter-plist
2793 (quote (:link t :maxlevel 5 :fileskip0 t :compact t :narrow 80)))
2794
2795 ;; Agenda log mode items to display (closed and state changes by default)
2796 (setq org-agenda-log-mode-items (quote (closed state)))
2797 #+END_SRC
2798 **** Task estimates, column view
2799 Setup column view globally with the following headlines
2800 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2801 ; Set default column view headings: Task Effort Clock_Summary
2802 (setq org-columns-default-format "%80ITEM(Task) %10Effort(Effort){:} %10CLOCKSUM")
2803 #+END_SRC
2804 Setup the estimate for effort values.
2805 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2806 ; global Effort estimate values
2807 ; global STYLE property values for completion
2808 (setq org-global-properties (quote (("Effort_ALL" . "0:15 0:30 0:45 1:00 2:00 3:00 4:00 5:00 6:00 0:00")
2809 ("STYLE_ALL" . "habit"))))
2810 #+END_SRC
2811
2812 *** Tags
2813 Tags are mostly used for filtering inside the agenda.
2814 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2815 ; Tags with fast selection keys
2816 (setq org-tag-alist (quote ((:startgroup)
2817 ("@errand" . ?e)
2818 ("@office" . ?o)
2819 ("@home" . ?H)
2820 (:endgroup)
2821 ("PHONE" . ?p)
2822 ("WAITING" . ?w)
2823 ("HOLD" . ?h)
2824 ("PERSONAL" . ?P)
2825 ("WORK" . ?W)
2826 ("ORG" . ?O)
2827 ("PRIVATE" . ?N)
2828 ("crypt" . ?E)
2829 ("MARK" . ?M)
2830 ("NOTE" . ?n)
2831 ("CANCELLED" . ?c)
2832 ("FLAGGED" . ??))))
2833
2834 ; Allow setting single tags without the menu
2835 (setq org-fast-tag-selection-single-key (quote expert))
2836
2837 ; For tag searches ignore tasks with scheduled and deadline dates
2838 (setq org-agenda-tags-todo-honor-ignore-options t)
2839 #+END_SRC
2840
2841 *** Archiving
2842 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2843 (setq org-archive-mark-done nil)
2844 (setq org-archive-location "%s_archive::* Archived Tasks")
2845 #+END_SRC
2846
2847 *** org-babel
2848 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2849 (setq org-ditaa-jar-path "~/java/ditaa0_6b.jar")
2850 (setq org-plantuml-jar-path "~/java/plantuml.jar")
2851
2852 (add-hook 'org-babel-after-execute-hook 'bh/display-inline-images 'append)
2853
2854 ; Make babel results blocks lowercase
2855 (setq org-babel-results-keyword "results")
2856
2857 (org-babel-do-load-languages
2858 (quote org-babel-load-languages)
2859 (quote ((emacs-lisp . t)
2860 (awk . t)
2861 (css . t)
2862 (makefile . t)
2863 (perl . t)
2864 (ruby . t)
2865 (dot . t)
2866 (ditaa . t)
2867 (R . t)
2868 (python . t)
2869 (ruby . t)
2870 (gnuplot . t)
2871 (clojure . t)
2872 (sh . t)
2873 (ledger . t)
2874 (org . t)
2875 (plantuml . t)
2876 (latex . t))))
2877
2878 ; Do not prompt to confirm evaluation
2879 ; This may be dangerous - make sure you understand the consequences
2880 ; of setting this -- see the docstring for details
2881 (setq org-confirm-babel-evaluate nil)
2882
2883 ; Use fundamental mode when editing plantuml blocks with C-c '
2884 (add-to-list 'org-src-lang-modes (quote ("plantuml" . fundamental)))
2885 #+END_SRC
2886
2887 #+BEGIN_SRC emacs-lisp :tangle yes
2888 ;; Don't have images visible on startup, breaks on console
2889 (setq org-startup-with-inline-images nil)
2890 #+END_SRC
2891
2892 #+BEGIN_SRC emacs-lisp :tangle yes
2893 (add-to-list 'org-structure-template-alist
2894 '("n" "#+BEGIN_COMMENT\n?\n#+END_COMMENT"
2895 "<comment>\n?\n</comment>"))
2896 #+END_SRC
2897 **** ditaa, graphviz, etc
2898 Those are all nice tools. Look at
2899 http://doc.norang.ca/org-mode.html#playingwithditaa for a nice intro
2900 to them.
2901
2902 *** Publishing and exporting
2903
2904
2905 Org-mode can export to a variety of publishing formats including (but not limited to)
2906
2907 - ASCII
2908 (plain text - but not the original org-mode file)
2909 - HTML
2910 - LaTeX
2911 - Docbook
2912 which enables getting to lots of other formats like ODF, XML, etc
2913 - PDF
2914 via LaTeX or Docbook
2915 - iCal
2916
2917 A new exporter created by Nicolas Goaziou was introduced in org 8.0.
2918
2919 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2920 ;; Explicitly load required exporters
2921 (require 'ox-html)
2922 (require 'ox-latex)
2923 (require 'ox-ascii)
2924 ;; FIXME, check the following two
2925 ;(require 'ox-icalendar)
2926 ;(require 'ox-odt)
2927
2928 ; experimenting with docbook exports - not finished
2929 (setq org-export-docbook-xsl-fo-proc-command "fop %s %s")
2930 (setq org-export-docbook-xslt-proc-command "xsltproc --output %s /usr/share/xml/docbook/stylesheet/nwalsh/fo/docbook.xsl %s")
2931
2932 ;; define categories that should be excluded
2933 (setq org-export-exclude-category (list "google" "google"))
2934 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
2935
2936 ; define how the date strings look
2937 (setq org-export-date-timestamp-format "%Y-%m-%d")
2938 ; Inline images in HTML instead of producting links to the image
2939 (setq org-html-inline-images t)
2940 ; Do not use sub or superscripts - I currently don't need this functionality in my documents
2941 (setq org-export-with-sub-superscripts nil)
2942
2943 (setq org-html-head-extra (concat
2944 "<link rel=\"stylesheet\" href=\"http://ganneff.de/stylesheet.css\" type=\"text/css\" />\n"
2945 ))
2946 (setq org-html-head-include-default-style nil)
2947 ; Do not generate internal css formatting for HTML exports
2948 (setq org-export-htmlize-output-type (quote css))
2949 ; Export with LaTeX fragments
2950 (setq org-export-with-LaTeX-fragments t)
2951 ; Increase default number of headings to export
2952 (setq org-export-headline-levels 6)
2953
2954
2955 (setq org-publish-project-alist
2956 '(
2957 ("config-notes"
2958 :base-directory "~/.emacs.d/"
2959 :base-extension "org"
2960 :exclude "elisp"
2961 :publishing-directory "/develop/www/emacs"
2962 :recursive t
2963 :publishing-function org-html-publish-to-html
2964 :headline-levels 4 ; Just the default for this project.
2965 :auto-preamble t
2966 :auto-sitemap t
2967 :makeindex t
2968 )
2969 ("config-static"
2970 :base-directory "~/.emacs.d/"
2971 :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
2972 :publishing-directory "/develop/www/emacs"
2973 :exclude "elisp\\|elpa\\|elpa.off\\|auto-save-list\\|cache\\|eshell\\|image-dired\\|themes\\|url"
2974 :recursive t
2975 :publishing-function org-publish-attachment
2976 )
2977 ("inherit-org-info-js"
2978 :base-directory "/develop/vcs/org-info-js/"
2979 :recursive t
2980 :base-extension "js"
2981 :publishing-directory "/develop/www/"
2982 :publishing-function org-publish-attachment
2983 )
2984 ("config" :components ("inherit-org-info-js" "config-notes" "config-static")
2985 )
2986 )
2987 )
2988
2989 (setq org-export-with-timestamps nil)
2990 #+END_SRC
2991
2992 **** Latex export
2993
2994 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
2995 (setq org-latex-to-pdf-process
2996 '("xelatex -interaction nonstopmode %f"
2997 "xelatex -interaction nonstopmode %f")) ;; for multiple passes
2998 (setq org-export-latex-listings 'minted)
2999 (setq org-latex-listings t)
3000
3001 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
3002 ;; but adapted to use latexmk 4.20 or higher.
3003 (defun my-auto-tex-cmd ()
3004 "When exporting from .org with latex, automatically run latex,
3005 pdflatex, or xelatex as appropriate, using latexmk."
3006 (let ((texcmd)))
3007 ;; default command: oldstyle latex via dvi
3008 (setq texcmd "latexmk -dvi -pdfps -quiet %f")
3009 ;; pdflatex -> .pdf
3010 (if (string-match "LATEX_CMD: pdflatex" (buffer-string))
3011 (setq texcmd "latexmk -pdf -quiet %f"))
3012 ;; xelatex -> .pdf
3013 (if (string-match "LATEX_CMD: xelatex" (buffer-string))
3014 (setq texcmd "latexmk -pdflatex='xelatex -shell-escape' -pdf -quiet %f"))
3015 ;; LaTeX compilation command
3016 (setq org-latex-to-pdf-process (list texcmd)))
3017
3018 (add-hook 'org-export-latex-after-initial-vars-hook 'my-auto-tex-cmd)
3019
3020 ;; Specify default packages to be included in every tex file, whether pdflatex or xelatex
3021 (setq org-export-latex-packages-alist
3022 '(("" "graphicx" t)
3023 ("" "longtable" nil)
3024 ("" "float" nil)
3025 ("" "minted" nil)
3026 ))
3027
3028 (defun my-auto-tex-parameters ()
3029 "Automatically select the tex packages to include."
3030 ;; default packages for ordinary latex or pdflatex export
3031 (setq org-export-latex-default-packages-alist
3032 '(("AUTO" "inputenc" t)
3033 ("T1" "fontenc" t)
3034 ("" "fixltx2e" nil)
3035 ("" "wrapfig" nil)
3036 ("" "soul" t)
3037 ("" "textcomp" t)
3038 ("" "marvosym" t)
3039 ("" "wasysym" t)
3040 ("" "latexsym" t)
3041 ("" "amssymb" t)
3042 ("" "hyperref" nil)))
3043
3044 ;; Packages to include when xelatex is used
3045 (if (string-match "LATEX_CMD: xelatex" (buffer-string))
3046 (setq org-export-latex-default-packages-alist
3047 '(("" "fontspec" t)
3048 ("" "xunicode" t)
3049 ("" "url" t)
3050 ("" "rotating" t)
3051 ("german" "babel" t)
3052 ("babel" "csquotes" t)
3053 ("" "soul" t)
3054 ("xetex" "hyperref" nil)
3055 )))
3056
3057 (if (string-match "#+LATEX_CMD: xelatex" (buffer-string))
3058 (setq org-export-latex-classes
3059 (cons '("scrartcl"
3060 "\\documentclass[11pt,DIV=13,oneside]{scrartcl}"
3061 ("\\section{%s}" . "\\section*{%s}")
3062 ("\\subsection{%s}" . "\\subsection*{%s}")
3063 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
3064 ("\\paragraph{%s}" . "\\paragraph*{%s}")
3065 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
3066 org-export-latex-classes))))
3067
3068 (add-hook 'org-export-latex-after-initial-vars-hook 'my-auto-tex-parameters)
3069 #+END_SRC
3070
3071 *** Prevent editing invisible text
3072 The following setting prevents accidentally editing hidden text when
3073 the point is inside a folded region. This can happen if you are in
3074 the body of a heading and globally fold the org-file with =S-TAB=
3075
3076 I find invisible edits (and undo's) hard to deal with so now I can't
3077 edit invisible text. =C-c C-r= (org-reveal) will display where the
3078 point is if it is buried in invisible text to allow editing again.
3079
3080 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3081 (setq org-catch-invisible-edits 'error)
3082 #+END_SRC
3083
3084 *** Whatever
3085 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3086 ;; disable the default org-mode stuck projects agenda view
3087 (setq org-stuck-projects (quote ("" nil nil "")))
3088
3089 ; force showing the next headline.
3090 (setq org-show-entry-below (quote ((default))))
3091
3092 (setq org-show-following-heading t)
3093 (setq org-show-hierarchy-above t)
3094 (setq org-show-siblings (quote ((default))))
3095
3096 (setq org-special-ctrl-a/e t)
3097 (setq org-special-ctrl-k t)
3098 (setq org-yank-adjusted-subtrees t)
3099
3100 (setq org-table-export-default-format "orgtbl-to-csv")
3101
3102 #+END_SRC
3103
3104 The following setting adds alphabetical lists like
3105 ,a. item one
3106 ,b. item two
3107
3108 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3109 (if (> emacs-major-version 23)
3110 (setq org-list-allow-alphabetical t)
3111 (setq org-alphabetical-lists t))
3112 #+END_SRC
3113
3114 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3115 (setq org-remove-highlights-with-change nil)
3116
3117 (setq org-list-demote-modify-bullet (quote (("+" . "-")
3118 ("*" . "-")
3119 ("1." . "-")
3120 ("1)" . "-"))))
3121
3122
3123
3124 (add-hook 'org-insert-heading-hook 'bh/insert-heading-inactive-timestamp 'append)
3125
3126
3127 ; If we leave Emacs running overnight - reset the appointments one minute after midnight
3128 (run-at-time "24:01" nil 'bh/org-agenda-to-appt)
3129
3130 #+END_SRC
3131
3132
3133 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3134 ;; Enable abbrev-mode
3135 (add-hook 'org-mode-hook (lambda () (abbrev-mode 1)))
3136 (setq org-startup-indented t)
3137 (setq org-startup-folded t)
3138 (setq org-cycle-separator-lines 0)
3139 #+END_SRC
3140
3141 I find extra blank lines in lists and headings a bit of a nuisance.
3142 To get a body after a list you need to include a blank line between
3143 the list entry and the body -- and indent the body appropriately.
3144 Most of my lists have no body detail so I like the look of collapsed
3145 lists with no blank lines better.
3146
3147 The following setting prevents creating blank lines before headings
3148 but allows list items to adapt to existing blank lines around the items:
3149 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3150 (setq org-blank-before-new-entry (quote ((heading)
3151 (plain-list-item . auto))))
3152 #+END_SRC
3153
3154 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3155 (setq org-reverse-note-order nil)
3156 (setq org-default-notes-file "~/notes.org")
3157 #+END_SRC
3158
3159 Enforce task blocking. Tasks can't go done when there is any subtask
3160 still open. Unless they have a property of =NOBLOCKING: t=
3161 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3162 (setq org-enforce-todo-checkbox-dependencies t)
3163 (setq org-enforce-todo-dependencies t)
3164 #+END_SRC
3165
3166 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3167 (setq org-fast-tag-selection-single-key (quote expert))
3168 (setq org-footnote-auto-adjust t)
3169 (setq org-hide-block-startup t)
3170 (setq org-icalendar-alarm-time 15)
3171 (setq org-icalendar-combined-description "Ganneffs Org-mode calendar entries")
3172 (setq org-icalendar-combined-name "\"Ganneffs OrgMode\"")
3173 (setq org-icalendar-honor-noexport-tag t)
3174 (setq org-icalendar-include-bbdb-anniversaries nil)
3175 (setq org-icalendar-include-body 200)
3176 (setq org-icalendar-include-todo nil)
3177 (setq org-icalendar-store-UID t)
3178 (setq org-icalendar-timezone "Europe/Berlin")
3179 (setq org-insert-mode-line-in-empty-file t)
3180 (setq org-log-done (quote note))
3181 (setq org-log-into-drawer t)
3182 (setq org-log-state-notes-insert-after-drawers nil)
3183 (setq org-log-reschedule (quote time))
3184 (setq org-log-states-order-reversed t)
3185 (setq org-mobile-agendas (quote all))
3186 (setq org-mobile-directory "/scpx:joerg@garibaldi.ganneff.de:/srv/www2.ganneff.de/htdocs/org/")
3187 (setq org-mobile-inbox-for-pull "~/org/refile.org")
3188 (setq org-remember-store-without-prompt t)
3189 (setq org-return-follows-link t)
3190 (setq org-reverse-note-order t)
3191
3192 ; regularly save our org-mode buffers
3193 (run-at-time "00:59" 3600 'org-save-all-org-buffers)
3194
3195 (setq org-log-done t)
3196
3197 (setq org-enable-priority-commands t)
3198 (setq org-default-priority ?E)
3199 (setq org-lowest-priority ?E)
3200
3201
3202 #+END_SRC
3203
3204 Speed commands enable single-letter commands in Org-mode files when
3205 the point is at the beginning of a headline, or at the beginning of a
3206 code block.
3207
3208 See the `=org-speed-commands-default=' variable for a list of the keys
3209 and commands enabled at the beginning of headlines. All code blocks
3210 are available at the beginning of a code block, the following key
3211 sequence =C-c C-v h= (bound to `=org-babel-describe-bindings=') will
3212 display a list of the code blocks commands and their related keys.
3213
3214 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3215 (setq org-use-speed-commands t)
3216 (setq org-speed-commands-user (quote (("0" . ignore)
3217 ("1" . ignore)
3218 ("2" . ignore)
3219 ("3" . ignore)
3220 ("4" . ignore)
3221 ("5" . ignore)
3222 ("6" . ignore)
3223 ("7" . ignore)
3224 ("8" . ignore)
3225 ("9" . ignore)
3226
3227 ("a" . ignore)
3228 ("d" . ignore)
3229 ("h" . bh/hide-other)
3230 ("i" progn
3231 (forward-char 1)
3232 (call-interactively 'org-insert-heading-respect-content))
3233 ("k" . org-kill-note-or-show-branches)
3234 ("l" . ignore)
3235 ("m" . ignore)
3236 ("q" . bh/show-org-agenda)
3237 ("r" . ignore)
3238 ("s" . org-save-all-org-buffers)
3239 ("w" . org-refile)
3240 ("x" . ignore)
3241 ("y" . ignore)
3242 ("z" . org-add-note)
3243
3244 ("A" . ignore)
3245 ("B" . ignore)
3246 ("E" . ignore)
3247 ("F" . bh/restrict-to-file-or-follow)
3248 ("G" . ignore)
3249 ("H" . ignore)
3250 ("J" . org-clock-goto)
3251 ("K" . ignore)
3252 ("L" . ignore)
3253 ("M" . ignore)
3254 ("N" . bh/narrow-to-org-subtree)
3255 ("P" . bh/narrow-to-org-project)
3256 ("Q" . ignore)
3257 ("R" . ignore)
3258 ("S" . ignore)
3259 ("T" . bh/org-todo)
3260 ("U" . bh/narrow-up-one-org-level)
3261 ("V" . ignore)
3262 ("W" . bh/widen)
3263 ("X" . ignore)
3264 ("Y" . ignore)
3265 ("Z" . ignore))))
3266
3267 (add-hook 'org-agenda-mode-hook
3268 (lambda ()
3269 (define-key org-agenda-mode-map "q" 'bury-buffer))
3270 'append)
3271
3272 (defvar bh/current-view-project nil)
3273 (add-hook 'org-agenda-mode-hook
3274 '(lambda () (org-defkey org-agenda-mode-map "V" 'bh/view-next-project))
3275 'append)
3276 #+END_SRC
3277
3278 The following displays the contents of code blocks in Org-mode files
3279 using the major-mode of the code. It also changes the behavior of
3280 =TAB= to as if it were used in the appropriate major mode. This means
3281 that reading and editing code form inside of your Org-mode files is
3282 much more like reading and editing of code using its major mode.
3283
3284 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3285 (setq org-src-fontify-natively t)
3286 (setq org-src-tab-acts-natively t)
3287 #+END_SRC
3288
3289 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3290 (setq org-src-preserve-indentation nil)
3291 (setq org-edit-src-content-indentation 0)
3292 #+END_SRC
3293
3294
3295 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3296 (setq org-attach-directory "~/org/data/")
3297 #+END_SRC
3298 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3299 (setq org-agenda-sticky t)
3300 #+END_SRC
3301
3302 **** Checklist handling
3303 [2013-05-11 Sat 22:15]
3304
3305 #+BEGIN_SRC emacs-lisp :tangle yes :tangle yes
3306 (require 'org-checklist)
3307 #+END_SRC
3308
3309 ** perl / cperl
3310 I like /cperl-mode/ a bit more than the default /perl-mode/, so set it
3311 up here to be used.
3312 #+BEGIN_SRC emacs-lisp :tangle yes
3313 (use-package cperl-mode
3314 :commands cperl-mode
3315 :init
3316 (progn
3317 (defalias 'perl-mode 'cperl-mode)
3318 (add-auto-mode 'cperl-mode "\\.\\([pP][Llm]\\|al\\)\\'")
3319 (add-auto-mode 'pod-mode "\\.pod$")
3320 (add-auto-mode 'tt-mode "\\.tt$")
3321 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
3322 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
3323 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
3324 )
3325 :config
3326 (progn
3327 (setq cperl-invalid-face nil
3328 cperl-close-paren-offset -4
3329 cperl-continued-statement-offset 0
3330 cperl-indent-level 4
3331 cperl-indent-parens-as-block t
3332 cperl-hairy t
3333 cperl-electric-keywords t
3334 cperl-electric-lbrace-space t
3335 cperl-electric-parens nil
3336 cperl-highlight-variables-indiscriminately t
3337 cperl-imenu-addback t
3338 cperl-invalid-face (quote underline)
3339 cperl-lazy-help-time 5
3340 cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\|cgi\\)$"
3341 cperl-syntaxify-by-font-lock t
3342 cperl-use-syntax-table-text-property-for-tags t)
3343
3344 ;; And have cperl mode give ElDoc a useful string
3345 (defun my-cperl-eldoc-documentation-function ()
3346 "Return meaningful doc string for `eldoc-mode'."
3347 (car
3348 (let ((cperl-message-on-help-error nil))
3349 (cperl-get-help))))
3350 (add-hook 'cperl-mode-hook
3351 (lambda ()
3352 (set (make-local-variable 'eldoc-documentation-function)
3353 'my-cperl-eldoc-documentation-function)
3354 (eldoc-mode))))
3355 )
3356 #+END_SRC
3357 ** puppet
3358 [2014-05-22 Thu 00:05]
3359 #+BEGIN_SRC emacs-lisp :tangle yes
3360 (use-package puppet-mode
3361 :mode ("\\.pp\\'" . puppet-mode)
3362 :config
3363 (use-package puppet-ext
3364 :init
3365 (progn
3366 (bind-key "C-x ?" 'puppet-set-anchor puppet-mode-map)
3367 (bind-key "C-c C-r" 'puppet-create-require puppet-mode-map))))
3368 #+END_SRC
3369
3370 ** python
3371 Use elpy for the emacs python fun, but dont let it initialize all the
3372 various variables. Elpy author may like them, but I'm not him...
3373 #+BEGIN_SRC emacs-lisp :tangle yes
3374 (safe-load (concat jj-elisp-dir "/elpy/elpy-autoloads.el"))
3375 (defalias 'elpy-initialize-variables 'jj-init-elpy)
3376 (defun jj-init-elpy ()
3377 "Initialize elpy in a way i like"
3378 ;; Local variables in `python-mode'. This is not removed when Elpy
3379 ;; is disabled, which can cause some confusion.
3380 (add-hook 'python-mode-hook 'elpy-initialize-local-variables)
3381
3382 ;; `flymake-no-changes-timeout': The original value of 0.5 is too
3383 ;; short for Python code, as that will result in the current line to
3384 ;; be highlighted most of the time, and that's annoying. This value
3385 ;; might be on the long side, but at least it does not, in general,
3386 ;; interfere with normal interaction.
3387 (setq flymake-no-changes-timeout 60)
3388
3389 ;; `flymake-start-syntax-check-on-newline': This should be nil for
3390 ;; Python, as;; most lines with a colon at the end will mean the next
3391 ;; line is always highlighted as error, which is not helpful and
3392 ;; mostly annoying.
3393 (setq flymake-start-syntax-check-on-newline nil)
3394
3395 ;; `ac-auto-show-menu': Short timeout because the menu is great.
3396 (setq ac-auto-show-menu 0.4)
3397
3398 ;; `ac-quick-help-delay': I'd like to show the menu right with the
3399 ;; completions, but this value should be greater than
3400 ;; `ac-auto-show-menu' to show help for the first entry as well.
3401 (setq ac-quick-help-delay 0.5)
3402
3403 ;; `yas-trigger-key': TAB, as is the default, conflicts with the
3404 ;; autocompletion. We also need to tell yasnippet about the new
3405 ;; binding. This is a bad interface to set the trigger key. Stop
3406 ;; doing this.
3407 (let ((old (when (boundp 'yas-trigger-key)
3408 yas-trigger-key)))
3409 (setq yas-trigger-key "C-c C-i")
3410 (when (fboundp 'yas--trigger-key-reload)
3411 (yas--trigger-key-reload old)))
3412
3413 ;; yas-snippet-dirs can be a string for a single directory. Make
3414 ;; sure it's a list in that case so we can add our own entry.
3415 (when (not (listp yas-snippet-dirs))
3416 (setq yas-snippet-dirs (list yas-snippet-dirs)))
3417 (add-to-list 'yas-snippet-dirs
3418 (concat (file-name-directory (locate-library "elpy"))
3419 "snippets/")
3420 t)
3421
3422 ;; Now load yasnippets.
3423 (yas-reload-all))
3424 (elpy-enable)
3425 (elpy-use-ipython)
3426 #+END_SRC
3427
3428 Below is old setup
3429 #+BEGIN_SRC emacs-lisp :tangle no
3430 (autoload 'python-mode "python-mode" "Python Mode." t)
3431 (add-auto-mode 'python-mode "\\.py\\'")
3432 (add-auto-mode 'python-mode "\\.py$")
3433 (add-auto-mode 'python-mode "SConstruct\\'")
3434 (add-auto-mode 'python-mode "SConscript\\'")
3435 (add-to-list 'interpreter-mode-alist '("python" . python-mode))
3436
3437 (after 'python-mode
3438 (set-variable 'py-indent-offset 4)
3439 (set-variable 'py-smart-indentation nil)
3440 (set-variable 'indent-tabs-mode nil)
3441 (define-key python-mode-map "\C-m" 'newline-and-indent)
3442 (turn-on-eldoc-mode)
3443 (defun python-auto-fill-comments-only ()
3444 (auto-fill-mode 1)
3445 (set (make-local-variable 'fill-nobreak-predicate)
3446 (lambda ()
3447 (not (python-in-string/comment)))))
3448 (add-hook 'python-mode-hook
3449 (lambda ()
3450 (python-auto-fill-comments-only)))
3451 ;; pymacs
3452 (autoload 'pymacs-apply "pymacs")
3453 (autoload 'pymacs-call "pymacs")
3454 (autoload 'pymacs-eval "pymacs" nil t)
3455 (autoload 'pymacs-exec "pymacs" nil t)
3456 (autoload 'pymacs-load "pymacs" nil t))
3457 #+END_SRC
3458
3459 If an =ipython= executable is on the path, then assume that IPython is
3460 the preferred method python evaluation.
3461 #+BEGIN_SRC emacs-lisp :tangle no
3462 (when (executable-find "ipython")
3463 (require 'ipython)
3464 (setq org-babel-python-mode 'python-mode))
3465
3466 (setq python-shell-interpreter "ipython")
3467 (setq python-shell-interpreter-args "")
3468 (setq python-shell-prompt-regexp "In \\[[0-9]+\\]: ")
3469 (setq python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: ")
3470 (setq python-shell-completion-setup-code
3471 "from IPython.core.completerlib import module_completion")
3472 (setq python-shell-completion-module-string-code
3473 "';'.join(module_completion('''%s'''))\n")
3474 (setq python-shell-completion-string-code
3475 "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")
3476 #+END_SRC
3477 ** rainbow-delimiters
3478 [2013-04-09 Di 23:38]
3479 [[http://www.emacswiki.org/emacs/RainbowDelimiters][EmacsWiki: Rainbow Delimiters]] is a “rainbow parentheses”-like mode
3480 which highlights parens, brackets, and braces according to their
3481 depth. Each successive level is highlighted a different color. This
3482 makes it easy to spot matching delimiters, orient yourself in the code,
3483 and tell which statements are at the same depth.
3484 #+BEGIN_SRC emacs-lisp :tangle yes
3485 (use-package rainbow-delimiters
3486 :ensure rainbow-delimiters
3487 :init
3488 (global-rainbow-delimiters-mode))
3489 #+END_SRC
3490 ** rainbow-mode
3491 #+BEGIN_SRC emacs-lisp :tangle yes
3492 (use-package rainbow-mode
3493 :ensure rainbow-mode
3494 :diminish rainbow-mode)
3495 #+END_SRC
3496
3497 ** re-builder
3498 Saner regex syntax
3499 #+BEGIN_SRC emacs-lisp :tangle yes
3500 (use-package re-builder
3501 :command re-builder
3502 :defer t
3503 :config
3504 (setq reb-re-syntax 'string))
3505 #+END_SRC
3506 ** recentf
3507 [2014-05-19 Mo 22:56]
3508 Recentf is a minor mode that builds a list of recently opened
3509 files. This list is is automatically saved across Emacs sessions.
3510 #+BEGIN_SRC emacs-lisp :tangle yes
3511 (use-package recentf
3512 :if (not noninteractive)
3513 :bind ("C-x C-r" . recentf-open-files)
3514 :init
3515 (progn
3516 (recentf-mode 1)
3517 (setq recentf-max-menu-items 25)
3518 (setq recentf-save-file (expand-file-name ".recentf" jj-cache-dir))
3519
3520 (defun recentf-add-dired-directory ()
3521 (if (and dired-directory
3522 (file-directory-p dired-directory)
3523 (not (string= "/" dired-directory)))
3524 (let ((last-idx (1- (length dired-directory))))
3525 (recentf-add-file
3526 (if (= ?/ (aref dired-directory last-idx))
3527 (substring dired-directory 0 last-idx)
3528 dired-directory)))))
3529
3530 (add-hook 'dired-mode-hook 'recentf-add-dired-directory)))
3531 #+END_SRC
3532 ** Region bindings mode
3533 [2013-05-01 Wed 22:51]
3534 This mode allows to have keybindings that are only alive when the
3535 region is active. Helpful for things that only do any useful action
3536 then, like for example the [[*multiple%20cursors][multiple cursors]] mode I load later.
3537 #+BEGIN_SRC emacs-lisp :tangle yes
3538 (use-package region-bindings-mode
3539 :ensure region-bindings-mode
3540 :init
3541 (region-bindings-mode-enable))
3542 #+END_SRC
3543 ** ruby
3544 [2013-05-22 Wed 22:33]
3545 Programming in ruby...
3546
3547 *** Auto-modes
3548 #+BEGIN_SRC emacs-lisp :tangle yes
3549 (add-auto-mode 'ruby-mode
3550 "Rakefile\\'" "\\.rake\\'" "\.rxml\\'"
3551 "\\.rjs\\'" ".irbrc\\'" "\.builder\\'" "\\.ru\\'"
3552 "\\.gemspec\\'" "Gemfile\\'" "Kirkfile\\'")
3553 #+END_SRC
3554
3555 *** Config
3556 #+BEGIN_SRC emacs-lisp :tangle yes
3557 (use-package ruby-mode
3558 :mode ("\\.rb\\'" . ruby-mode)
3559 :interpreter ("ruby" . ruby-mode)
3560 :defer t
3561 :config
3562 (progn
3563 (use-package yari
3564 :init
3565 (progn
3566 (defvar yari-helm-source-ri-pages
3567 '((name . "RI documentation")
3568 (candidates . (lambda () (yari-ruby-obarray)))
3569 (action ("Show with Yari" . yari))
3570 (candidate-number-limit . 300)
3571 (requires-pattern . 2)
3572 "Source for completing RI documentation."))
3573
3574 (defun helm-yari (&optional rehash)
3575 (interactive (list current-prefix-arg))
3576 (when current-prefix-arg (yari-ruby-obarray rehash))
3577 (helm 'yari-helm-source-ri-pages (yari-symbol-at-point)))))
3578
3579 (defun my-ruby-smart-return ()
3580 (interactive)
3581 (when (memq (char-after) '(?\| ?\" ?\'))
3582 (forward-char))
3583 (call-interactively 'newline-and-indent))
3584
3585 (use-package ruby-hash-syntax
3586 :ensure ruby-hash-syntax)
3587
3588 (use-package inf-ruby
3589 :ensure inf-ruby
3590 :commands inf-ruby-minor-mode
3591 :init
3592 (progn
3593 (add-hook 'ruby-mode-hook 'inf-ruby-minor-mode)
3594 (bind-key "<return>" 'my-ruby-smart-return ruby-mode-map)
3595 ;(bind-key "<tab>" 'indent-for-tab-command ruby-mode-map)
3596
3597
3598 (set (make-local-variable 'yas-fallback-behavior)
3599 '(apply ruby-indent-command . nil))
3600 (bind-key "<tab>" 'yas-expand-from-trigger-key ruby-mode-map)))
3601
3602 ;; Stupidly the non-bundled ruby-mode isn't a derived mode of
3603 ;; prog-mode: we run the latter's hooks anyway in that case.
3604 (add-hook 'ruby-mode-hook
3605 (lambda ()
3606 (unless (derived-mode-p 'prog-mode)
3607 (run-hooks 'prog-mode-hook))))
3608 ))
3609 #+END_SRC
3610 ** sessions :FIXME:
3611 [2013-05-22 Wed 22:40]
3612 Save and restore the desktop
3613 #+BEGIN_SRC emacs-lisp :tangle yes
3614 (setq desktop-path (list jj-cache-dir))
3615 (desktop-save-mode 1)
3616 (defadvice desktop-read (around trace-desktop-errors activate)
3617 (let ((debug-on-error t))
3618 ad-do-it))
3619
3620 ;;----------------------------------------------------------------------------
3621 ;; Restore histories and registers after saving
3622 ;;----------------------------------------------------------------------------
3623 (use-package session
3624 :if (not noninteractive)
3625 :load-path "site-lisp/session/lisp/"
3626 :init
3627 (progn
3628 (setq session-save-file (expand-file-name "session" jj-cache-dir))
3629 (setq desktop-globals-to-save
3630 (append '((extended-command-history . 30)
3631 (file-name-history . 100)
3632 (grep-history . 30)
3633 (compile-history . 30)
3634 (minibuffer-history . 50)
3635 (query-replace-history . 60)
3636 (read-expression-history . 60)
3637 (regexp-history . 60)
3638 (regexp-search-ring . 20)
3639 (search-ring . 20)
3640 (comint-input-ring . 50)
3641 (shell-command-history . 50)
3642 kill-ring
3643 desktop-missing-file-warning
3644 tags-file-name
3645 register-alist)))
3646
3647 (session-initialize)
3648
3649 (defun remove-session-use-package-from-settings ()
3650 (when (string= (file-name-nondirectory (buffer-file-name)) "settings.el")
3651 (save-excursion
3652 (goto-char (point-min))
3653 (when (re-search-forward "^ '(session-use-package " nil t)
3654 (delete-region (line-beginning-position)
3655 (1+ (line-end-position)))))))
3656
3657 (add-hook 'before-save-hook 'remove-session-use-package-from-settings)
3658
3659 ;; expanded folded secitons as required
3660 (defun le::maybe-reveal ()
3661 (when (and (or (memq major-mode '(org-mode outline-mode))
3662 (and (boundp 'outline-minor-mode)
3663 outline-minor-mode))
3664 (outline-invisible-p))
3665 (if (eq major-mode 'org-mode)
3666 (org-reveal)
3667 (show-subtree))))
3668
3669 (add-hook 'session-after-jump-to-last-change-hook
3670 'le::maybe-reveal)
3671
3672 (defun save-information ()
3673 (with-temp-message "Saving Emacs information..."
3674 (recentf-cleanup)
3675
3676 (loop for func in kill-emacs-hook
3677 unless (memq func '(exit-gnus-on-exit server-force-stop))
3678 do (funcall func))
3679
3680 (unless (or noninteractive
3681 (eq 'listen (process-status server-process)))
3682 (server-start))))
3683
3684 (run-with-idle-timer 300 t 'save-information)
3685
3686 (if window-system
3687 (add-hook 'after-init-hook 'session-initialize t))))
3688
3689 #+END_SRC
3690 *** savehist
3691 [2013-04-21 So 20:25]
3692 Save a bit of history
3693 #+BEGIN_SRC emacs-lisp tangle no
3694 (require 'savehist)
3695 (setq savehist-additional-variables
3696 '(search ring regexp-search-ring kill-ring compile-history))
3697 ;; save every minute
3698 (setq savehist-autosave-interval 60)
3699 (setq savehist-file (expand-file-name "savehist" jj-cache-dir))
3700 (savehist-mode +1)
3701 #+END_SRC
3702
3703 *** saveplace
3704 Store at which point I have been in files.
3705 #+BEGIN_SRC emacs-lisp :tangle yes
3706 (setq-default save-place t)
3707 (require 'saveplace)
3708 (setq save-place-file (expand-file-name "saved-places" jj-cache-dir))
3709 #+END_SRC
3710
3711 ** sh
3712 Settings for shell scripts
3713 #+BEGIN_SRC emacs-lisp :tangle yes
3714 (use-package sh-script
3715 :defer t
3716 :config
3717 (progn
3718 (defvar sh-script-initialized nil)
3719 (defun initialize-sh-script ()
3720 (unless sh-script-initialized
3721 (setq sh-script-initialized t)
3722 (setq sh-indent-comment t)
3723 (info-lookup-add-help :mode 'shell-script-mode
3724 :regexp ".*"
3725 :doc-spec
3726 '(("(bash)Index")))))
3727
3728 (add-hook 'shell-mode-hook 'initialize-sh-script)))
3729 #+END_SRC
3730 ** sh-toggle
3731 #+BEGIN_SRC emacs-lisp :tangle yes
3732 (use-package sh-toggle
3733 :bind ("C-. C-z" . shell-toggle))
3734 #+END_SRC
3735 ** timestamp
3736 By default, Emacs can update the time stamp for the following two
3737 formats if one exists in the first 8 lines of the file.
3738 - Time-stamp: <>
3739 - Time-stamp: " "
3740 #+BEGIN_SRC emacs-lisp :tangle yes
3741 (use-package time-stamp
3742 :commands time-stamp
3743 :init
3744 (progn
3745 (add-hook 'write-file-hooks 'time-stamp)
3746 (setq time-stamp-active t))
3747 :config
3748 (progn
3749 (setq time-stamp-format "%02H:%02M:%02S (%z) - %02d.%02m.%:y from %u (%U) on %s")
3750 (setq time-stamp-old-format-warn nil)
3751 (setq time-stamp-time-zone nil)))
3752 #+END_SRC
3753
3754 ** tiny-tools
3755 We configure only a bit of the tiny-tools to load when I should need
3756 them. I don't need much actually, but these things are nice to have.
3757
3758 #+BEGIN_SRC emacs-lisp :tangle yes
3759 (autoload 'turn-on-tinyperl-mode "tinyperl" "" t)
3760 (add-hook 'perl-mode-hook 'turn-on-tinyperl-mode)
3761 (add-hook 'cperl-mode-hook 'turn-on-tinyperl-mode)
3762
3763 (autoload 'tinycomment-indent-for-comment "tinycomment" "" t)
3764 (autoload 'tinyeat-forward-preserve "tinyeat" "" t)
3765 (autoload 'tinyeat-backward-preserve "tinyeat" "" t)
3766 (autoload 'tinyeat-delete-paragraph "tinyeat" "" t)
3767 (autoload 'tinyeat-kill-line "tinyeat" "" t)
3768 (autoload 'tinyeat-zap-line "tinyeat" "" t)
3769 (autoload 'tinyeat-kill-line-backward "tinyeat" "" t)
3770 (autoload 'tinyeat-kill-buffer-lines-point-max "tinyeat" "" t)
3771 (autoload 'tinyeat-kill-buffer-lines-point-min "tinyeat" "" t)
3772 #+END_SRC
3773 *** Keyboard changes for tiny-tools
3774 #+BEGIN_SRC emacs-lisp :tangle yes
3775 (bind-key "\M-;" 'tinycomment-indent-for-comment)
3776 (bind-key "ESC C-k" 'tinyeat-kill-line-backward)
3777 (bind-key "ESC d" 'tinyeat-forward-preserve)
3778 (bind-key "<M-backspace>" 'tinyeat-backward-preserve)
3779 (bind-key "<S-backspace>" 'tinyeat-delete-whole-word)
3780 #+END_SRC
3781
3782 ** tramp
3783 Transparent Remote (file) Access, Multiple Protocol, remote file editing.
3784 #+BEGIN_SRC emacs-lisp :tangle yes
3785 (use-package tramp
3786 :defer t
3787 :config
3788 (progn
3789 (setq tramp-persistency-file-name (expand-file-name "tramp" jj-cache-dir))
3790 (setq shell-prompt-pattern "^[^a-zA-Z].*[#$%>] *")
3791 (add-to-list 'tramp-default-method-alist '("\\`localhost\\'" "\\`root\\'" "su")
3792 )
3793 (setq tramp-debug-buffer nil)
3794 (setq tramp-default-method "sshx")
3795 (tramp-set-completion-function "ssh"
3796 '((tramp-parse-sconfig "/etc/ssh_config")
3797 (tramp-parse-sconfig "~/.ssh/config")))
3798 (setq tramp-verbose 5)
3799 ))
3800 #+END_SRC
3801
3802 ** transient mark
3803 For some reason I prefer this mode more than the way without. I want to
3804 see the marked region.
3805 #+BEGIN_SRC emacs-lisp :tangle yes
3806 (transient-mark-mode 1)
3807 #+END_SRC
3808 ** undo-tree
3809 [2013-04-21 So 11:07]
3810 Emacs undo is pretty powerful - but can also be confusing. There are
3811 tons of modes available to change it, even downgrade it to the very
3812 crappy ways one usually knows from other systems which lose
3813 information. undo-tree is different - it helps keeping you sane while
3814 keeping the full power of emacs undo/redo.
3815 #+BEGIN_SRC emacs-lisp :tangle yes
3816 (use-package undo-tree
3817 :ensure undo-tree
3818 :init
3819 (global-undo-tree-mode)
3820 :diminish undo-tree-mode)
3821 #+END_SRC
3822
3823 Additionally I would like to keep the region active should I undo
3824 while I have one.
3825
3826 #+BEGIN_SRC emacs-lisp :tangle yes
3827 ;; Keep region when undoing in region
3828 (defadvice undo-tree-undo (around keep-region activate)
3829 (if (use-region-p)
3830 (let ((m (set-marker (make-marker) (mark)))
3831 (p (set-marker (make-marker) (point))))
3832 ad-do-it
3833 (goto-char p)
3834 (set-mark m)
3835 (set-marker p nil)
3836 (set-marker m nil))
3837 ad-do-it))
3838 #+END_SRC
3839 ** uniquify
3840 Always have unique buffernames. See [[http://www.gnu.org/software/emacs/manual/html_node/emacs/Uniquify.html][Uniquify - GNU Emacs Manual]]
3841 #+BEGIN_SRC emacs-lisp :tangle yes
3842 (use-package uniquify
3843 :init
3844 (progn
3845 (setq uniquify-buffer-name-style 'post-forward)
3846 (setq uniquify-after-kill-buffer-p t)
3847 (setq uniquify-ignore-buffers-re "^\\*")))
3848 #+END_SRC
3849
3850 ** url
3851 url contains code to parse and handle URLs - who would have thought? I
3852 set it to send Accept-language header and tell it to not send email,
3853 operating system or location info.
3854 #+BEGIN_SRC emacs-lisp :tangle yes
3855 (setq url-mime-language-string "de,en")
3856 (setq url-privacy-level (quote (email os lastloc)))
3857 #+END_SRC
3858 ** volatile highlights
3859 [2013-04-21 So 20:31]
3860 VolatileHighlights highlights changes to the buffer caused by commands
3861 such as ‘undo’, ‘yank’/’yank-pop’, etc. The highlight disappears at the
3862 next command. The highlighting gives useful visual feedback for what
3863 your operation actually changed in the buffer.
3864 #+BEGIN_SRC emacs-lisp :tangle yes
3865 (use-package volatile-highlights
3866 :ensure volatile-highlights
3867 :init
3868 (volatile-highlights-mode t)
3869 :diminish volatile-highlights-mode)
3870 #+END_SRC
3871 ** writegood
3872 This highlights some /weaselwords/, a mode to /aid in finding common
3873 writing problems/...
3874 [2013-04-27 Sa 23:29]
3875 #+BEGIN_SRC emacs-lisp :tangle yes
3876 (use-package writegood-mode
3877 :ensure writegood-mode
3878 :defer t
3879 :init
3880 (bind-key "C-c g" 'writegood-mode))
3881 #+END_SRC
3882 ** yafolding
3883 Yet another folding extension for the Emacs editor. Unlike many
3884 others, this one works by just using the existing indentation of the
3885 file, so basically works in every halfway structured file.
3886 #+BEGIN_SRC emacs-lisp :tangle yes
3887 (bind-key "C-#" 'yafolding)
3888 ;;(define-key global-map (kbd "C-c C-f") 'yafolding-toggle-all)
3889 (bind-key "C-c C-f" 'yafolding-toggle-all-by-current-level)
3890 #+END_SRC
3891 ** yaml-mode
3892 [2013-04-28 So 01:13]
3893 YAML is a nice format for data, which is both, human and machine
3894 readable/editable without getting a big headache.
3895 #+BEGIN_SRC emacs-lisp :tangle yes
3896 (use-package yaml-mode
3897 :ensure yaml-mode
3898
3899 :mode ("\\.ya?ml\\'" . yaml-mode)
3900 :config
3901 (bind-key "C-m" 'newline-and-indent yaml-mode-map ))
3902 #+END_SRC
3903
3904 ** yasnippet
3905 [2013-04-27 Sa 23:16]
3906 Yasnippet is a template system. Type an abbreviation, expand it into
3907 whatever the snippet holds.
3908 #+BEGIN_SRC emacs-lisp :tangle yes
3909 (setq yas-snippet-dirs (expand-file-name "yasnippet/snippets" jj-elisp-dir))
3910 (use-package yasnippet
3911 :ensure yasnippet
3912 :init
3913 (progn
3914 (yas-global-mode 1)
3915 ;; Integrate hippie-expand with ya-snippet
3916 (add-to-list 'hippie-expand-try-functions-list
3917 'yas-hippie-try-expand)
3918 ))
3919 #+END_SRC
3920 * Thats it
3921 And thats it for this file, control passes "back" to [[file:../initjj.org][initjj.org/el]]
3922 which then may load more files.