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