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