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