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