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