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