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