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