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