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