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