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