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