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