advice swiper to recenter
[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 ;;advise swiper to recenter on exit
2610 (defun bjm-swiper-recenter (&rest args)
2611 "recenter display after swiper"
2612 (recenter)
2613 )
2614 (advice-add 'swiper :after #'bjm-swiper-recenter)
2615 ))
2616 #+END_SRC
2617 ** icicles
2618 [[http://article.gmane.org/gmane.emacs.orgmode/4574/match%3Dicicles]["In case you never heard of it, Icicles is to ‘TAB’ completion what
2619 ‘TAB’ completion is to typing things manually every time.”]]
2620 #+BEGIN_SRC emacs-lisp
2621 (use-package icicles
2622 :load-path "elisp/icicle/"
2623 :init
2624 (icy-mode 1))
2625 #+END_SRC
2626 ** icomplete
2627 Incremental mini-buffer completion preview: Type in the minibuffer,
2628 list of matching commands is echoed
2629 #+BEGIN_SRC emacs-lisp
2630 (icomplete-mode 99)
2631 #+END_SRC
2632 ** iedit
2633 [2014-05-26 Mon 22:49]
2634 #+BEGIN_SRC emacs-lisp
2635 (use-package iedit
2636 :ensure iedit
2637 :commands (iedit-mode)
2638 :defer t
2639 :bind (("C-;" . iedit-mode)
2640 ("C-," . iedit-mode-toggle-on-function))
2641 )
2642
2643 #+END_SRC
2644 ** info stuff
2645 [2014-05-20 Tue 23:35]
2646 #+BEGIN_SRC emacs-lisp
2647 (use-package info
2648 :bind ("C-h C-i" . info-lookup-symbol)
2649 :commands info-lookup-symbol
2650 :config
2651 (progn
2652 ;; (defadvice info-setup (after load-info+ activate)
2653 ;; (use-package info+))
2654
2655 (defadvice Info-exit (after remove-info-window activate)
2656 "When info mode is quit, remove the window."
2657 (if (> (length (window-list)) 1)
2658 (delete-window)))))
2659
2660 (use-package info-look
2661 :commands info-lookup-add-help)
2662 #+END_SRC
2663 ** linum (line number)
2664 Various modes should have line numbers in front of each line.
2665
2666 But then there are some where it would just be deadly - like org-mode,
2667 gnus, so we have a list of modes where we don't want to see it.
2668 #+BEGIN_SRC emacs-lisp
2669 (use-package linum
2670 :diminish linum-mode
2671 :config
2672 (progn
2673 (setq linum-format "%3d ")
2674 (setq linum-mode-inhibit-modes-list '(org-mode
2675 eshell-mode
2676 shell-mode
2677 gnus-group-mode
2678 gnus-summary-mode
2679 gnus-article-mode))
2680
2681 (defadvice linum-on (around linum-on-inhibit-for-modes)
2682 "Stop the load of linum-mode for some major modes."
2683 (unless (member major-mode linum-mode-inhibit-modes-list)
2684 ad-do-it))
2685
2686 (ad-activate 'linum-on)
2687
2688 (use-package linum-relative
2689 :ensure linum-relative
2690 :init
2691 (progn
2692 (setq linum-format 'dynamic)
2693 )))
2694 :init
2695 (global-linum-mode 1))
2696 #+END_SRC
2697
2698 ** lisp editing stuff
2699
2700 [2013-04-21 So 21:00]
2701 I'm not doing much of it, except for my emacs and gnus configs, but
2702 then I like it nice too...
2703 #+BEGIN_SRC emacs-lisp
2704 (bind-key "TAB" 'lisp-complete-symbol read-expression-map)
2705
2706 (defun remove-elc-on-save ()
2707 "If you're saving an elisp file, likely the .elc is no longer valid."
2708 (make-local-variable 'after-save-hook)
2709 (add-hook 'after-save-hook
2710 (lambda ()
2711 (if (file-exists-p (concat buffer-file-name "c"))
2712 (delete-file (concat buffer-file-name "c"))))))
2713
2714 (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
2715 (add-hook 'emacs-lisp-mode-hook 'remove-elc-on-save)
2716
2717 (use-package paredit
2718 :ensure paredit
2719 :diminish paredit-mode " π")
2720
2721 (setq lisp-coding-hook 'lisp-coding-defaults)
2722 (setq interactive-lisp-coding-hook 'interactive-lisp-coding-defaults)
2723
2724 (setq prelude-emacs-lisp-mode-hook 'prelude-emacs-lisp-mode-defaults)
2725 (add-hook 'emacs-lisp-mode-hook (lambda ()
2726 (run-hooks 'prelude-emacs-lisp-mode-hook)))
2727
2728 (bind-key "M-." 'find-function-at-point emacs-lisp-mode-map)
2729
2730 (after "elisp-slime-nav"
2731 '(diminish 'elisp-slime-nav-mode))
2732 (after "rainbow-mode"
2733 '(diminish 'rainbow-mode))
2734 (after "eldoc"
2735 '(diminish 'eldoc-mode))
2736 #+END_SRC
2737 ** magit
2738 [2013-04-21 So 20:48]
2739 magit is a mode for interacting with git.
2740 #+BEGIN_SRC emacs-lisp
2741 (use-package magit
2742 :ensure magit
2743 :commands (magit-log magit-run-gitk magit-run-git-gui magit-status
2744 magit-git-repo-p magit-list-repos)
2745 :defer t
2746 :bind (("C-x g" . magit-status)
2747 ("C-x G" . magit-status-with-prefix))
2748 :init
2749 (progn
2750 (setq magit-commit-signoff t
2751 magit-repo-dirs '("~/git"
2752 "/develop/vcs/"
2753 "/develop/Debian/"
2754 )
2755 magit-repo-dirs-depth 4
2756 magit-log-auto-more t)
2757
2758 (use-package magit-blame
2759 :commands magit-blame-mode
2760 :defer t)
2761
2762 ; (use-package magit-svn
2763 ; :ensure magit-svn
2764 ; :commands (magit-svn-mode
2765 ; turn-on-magit-svn)
2766 ; :defer t)
2767
2768 (add-hook 'magit-mode-hook 'hl-line-mode)
2769 (defun magit-status-with-prefix ()
2770 (interactive)
2771 (let ((current-prefix-arg '(4)))
2772 (call-interactively 'magit-status)))
2773 )
2774 :config
2775 (progn
2776 (setenv "GIT_PAGER" "")
2777
2778 (unbind-key "M-h" magit-mode-map)
2779 (unbind-key "M-s" magit-mode-map)
2780 (add-to-list 'magit-no-confirm 'stage-all-changes)
2781 (setq magit-push-always-verify nil)
2782 (setq magit-last-seen-setup-instructions "2.1.0")
2783 ; (use-package magit-find-file
2784 ; :ensure magit-find-file
2785 ; :commands (magit-find-file-completing-read)
2786 ; :defer t
2787 ; :init
2788 ; (progn
2789 ; (bind-key "C-x C-f" 'magit-find-file-completing-read magit-mode-map)))
2790
2791 (add-hook 'magit-log-edit-mode-hook
2792 #'(lambda ()
2793 (set-fill-column 72)
2794 (flyspell-mode)))
2795
2796 (add-hook 'git-rebase-mode-hook
2797 #'(lambda ()
2798 (smartscan-mode 0))
2799 )
2800 (defadvice magit-status (around magit-fullscreen activate)
2801 (window-configuration-to-register :magit-fullscreen)
2802 ad-do-it
2803 (delete-other-windows))
2804
2805 (defun magit-quit-session ()
2806 "Restores the previous window configuration and kills the magit buffer"
2807 (interactive)
2808 (kill-buffer)
2809 (jump-to-register :magit-fullscreen))
2810
2811 (bind-key "q" 'magit-quit-session magit-status-mode-map)
2812
2813 (defun magit-rebase-unpushed (commit &optional args)
2814 "Start an interactive rebase sequence over all unpushed commits."
2815 (interactive (list (magit-get-tracked-branch)
2816 (magit-rebase-arguments)))
2817 (if (setq commit (magit-rebase-interactive-assert commit))
2818 (magit-run-git-sequencer "rebase" "-i" commit args)
2819 (magit-log-select
2820 `(lambda (commit)
2821 (magit-rebase-interactive (concat commit "^") (list ,@args))))))
2822
2823 (magit-define-popup-action 'magit-rebase-popup ?l "Rebase unpushed" 'magit-rebase-unpushed)
2824 ))
2825 #+END_SRC
2826 ** markdown-mode
2827 [2014-05-20 Tue 23:04]
2828 #+BEGIN_SRC emacs-lisp
2829 (use-package markdown-mode
2830 :mode (("\\.md\\'" . markdown-mode)
2831 ("\\.mdwn\\'" . markdown-mode))
2832 :defer t)
2833 #+END_SRC
2834 ** message
2835 #+BEGIN_SRC emacs-lisp
2836 (use-package message
2837 :idle
2838 (progn
2839 (setq message-kill-buffer-on-exit t)))
2840 #+END_SRC
2841 ** mingus
2842 [[https://github.com/pft/mingus][Mingus]] is a nice interface to mpd, the Music Player Daemon.
2843
2844 I want to access it from anywhere using =F6=.
2845 #+BEGIN_SRC emacs-lisp
2846 (use-package mingus-stays-home
2847 :bind ( "<f6>" . mingus)
2848 :defer t
2849 :config
2850 (progn
2851 (setq mingus-dired-add-keys t)
2852 (setq mingus-mode-always-modeline nil)
2853 (setq mingus-mode-line-show-elapsed-percentage nil)
2854 (setq mingus-mode-line-show-volume nil)
2855 (setq mingus-mpd-config-file "/etc/mpd.conf")
2856 (setq mingus-mpd-playlist-dir "/var/lib/mpd/playlists")
2857 (setq mingus-mpd-root "/share/music/")))
2858 #+END_SRC
2859
2860 ** miniedit
2861 Edit minibuffer in a full (text-mode) buffer by pressing *M-C-e*.
2862 #+BEGIN_SRC emacs-lisp
2863 (use-package miniedit
2864 :ensure miniedit
2865 :commands miniedit
2866 :config
2867 (progn
2868 (bind-key "M-C-e" 'miniedit minibuffer-local-map)
2869 (bind-key "M-C-e" 'miniedit minibuffer-local-ns-map)
2870 (bind-key "M-C-e" 'miniedit minibuffer-local-completion-map)
2871 (bind-key "M-C-e" 'miniedit minibuffer-local-must-match-map)
2872 ))
2873 #+END_SRC
2874
2875 ** mmm-mode
2876 [2013-05-21 Tue 23:39]
2877 MMM Mode is a minor mode for Emacs that allows Multiple Major Modes to
2878 coexist in one buffer.
2879 #+BEGIN_SRC emacs-lisp :tangle no
2880 (use-package mmm-auto
2881 :ensure mmm-mode
2882 :init
2883 (progn
2884 (setq mmm-global-mode 'buffers-with-submode-classes)
2885 (setq mmm-submode-decoration-level 2)
2886 (eval-after-load 'mmm-vars
2887 '(progn
2888 (mmm-add-group
2889 'html-css
2890 '((css-cdata
2891 :submode css-mode
2892 :face mmm-code-submode-face
2893 :front "<style[^>]*>[ \t\n]*\\(//\\)?<!\\[CDATA\\[[ \t]*\n?"
2894 :back "[ \t]*\\(//\\)?]]>[ \t\n]*</style>"
2895 :insert ((?j js-tag nil @ "<style type=\"text/css\">"
2896 @ "\n" _ "\n" @ "</script>" @)))
2897 (css
2898 :submode css-mode
2899 :face mmm-code-submode-face
2900 :front "<style[^>]*>[ \t]*\n?"
2901 :back "[ \t]*</style>"
2902 :insert ((?j js-tag nil @ "<style type=\"text/css\">"
2903 @ "\n" _ "\n" @ "</style>" @)))
2904 (css-inline
2905 :submode css-mode
2906 :face mmm-code-submode-face
2907 :front "style=\""
2908 :back "\"")))
2909 (dolist (mode (list 'html-mode 'nxml-mode))
2910 (mmm-add-mode-ext-class mode "\\.r?html\\(\\.erb\\)?\\'" 'html-css))
2911 (mmm-add-mode-ext-class 'html-mode "\\.php\\'" 'html-php)
2912 ))))
2913 #+END_SRC
2914
2915 ** mo-git-blame
2916 This is [[https://github.com/mbunkus/mo-git-blame][mo-git-blame -- An interactive, iterative 'git blame' mode for
2917 Emacs]].
2918 #+BEGIN_SRC emacs-lisp
2919 (use-package mo-git-blame
2920 :ensure mo-git-blame
2921 :commands (mo-git-blame-current
2922 mo-git-blame-file)
2923 :config
2924 (progn
2925 (setq mo-git-blame-blame-window-width 25)))
2926 #+END_SRC
2927
2928 ** multiple cursors
2929 [2013-04-08 Mon 23:57]
2930 Use multiple cursors mode. See [[http://emacsrocks.com/e13.html][Emacs Rocks! multiple cursors]] and
2931 [[https://github.com/emacsmirror/multiple-cursors][emacsmirror/multiple-cursors · GitHub]]
2932 #+BEGIN_SRC emacs-lisp
2933 (use-package multiple-cursors
2934 :ensure multiple-cursors
2935 :defer t
2936 :commands (mc/remove-fake-cursors
2937 mc/create-fake-cursor-at-point
2938 mc/pop-state-from-overlay
2939 mc/maybe-multiple-cursors-mode)
2940 :defines (multiple-cursors-mode
2941 mc--read-char
2942 mc--read-quoted-char
2943 rectangular-region-mode)
2944 :bind (("C-S-c C-S-c" . mc/edit-lines)
2945 ("C->" . mc/mark-next-like-this)
2946 ("C-<" . mc/mark-previous-like-this)
2947 ("C-c C-<" . mc/mark-all-like-this)
2948 ("C-c i" . mc/insert-numbers))
2949 :config
2950 (progn
2951 (bind-key "a" 'mc/mark-all-like-this region-bindings-mode-map)
2952 (bind-key "p" 'mc/mark-previous-like-this region-bindings-mode-map)
2953 (bind-key "n" 'mc/mark-next-like-this region-bindings-mode-map)
2954 (bind-key "l" 'mc/edit-lines region-bindings-mode-map)
2955 (bind-key "m" 'mc/mark-more-like-this-extended region-bindings-mode-map)
2956 (setq mc/list-file (expand-file-name "mc-cache.el" jj-cache-dir))))
2957 #+END_SRC
2958 ** neotree
2959 [2014-08-27 Wed 17:15]
2960 A emacs tree plugin
2961 #+BEGIN_SRC emacs-lisp
2962 (use-package neotree
2963 :ensure neotree
2964 :defer t
2965 :bind (("<f8>" . neotree-toggle))
2966 :commands (neotree-find
2967 neotree-toggle
2968 neotree)
2969 :idle
2970 (progn
2971 (setq neo-smart-open t))
2972 :config
2973 (progn
2974 (bind-key "^" 'neotree-select-up-node neotree-mode-map)))
2975 #+END_SRC
2976 ** nxml
2977 [2013-05-22 Wed 22:02]
2978 nxml-mode is a major mode for editing XML.
2979 #+BEGIN_SRC emacs-lisp
2980 (add-auto-mode
2981 'nxml-mode
2982 (concat "\\."
2983 (regexp-opt
2984 '("xml" "xsd" "sch" "rng" "xslt" "svg" "rss"
2985 "gpx" "tcx"))
2986 "\\'"))
2987 (setq magic-mode-alist (cons '("<\\?xml " . nxml-mode) magic-mode-alist))
2988 (fset 'xml-mode 'nxml-mode)
2989 (setq nxml-slash-auto-complete-flag t)
2990
2991 ;; See: http://sinewalker.wordpress.com/2008/06/26/pretty-printing-xml-with-emacs-nxml-mode/
2992 (defun pp-xml-region (begin end)
2993 "Pretty format XML markup in region. The function inserts
2994 linebreaks to separate tags that have nothing but whitespace
2995 between them. It then indents the markup by using nxml's
2996 indentation rules."
2997 (interactive "r")
2998 (save-excursion
2999 (nxml-mode)
3000 (goto-char begin)
3001 (while (search-forward-regexp "\>[ \\t]*\<" nil t)
3002 (backward-char) (insert "\n"))
3003 (indent-region begin end)))
3004
3005 ;;----------------------------------------------------------------------------
3006 ;; Integration with tidy for html + xml
3007 ;;----------------------------------------------------------------------------
3008 ;; tidy is autoloaded
3009 (eval-after-load 'tidy
3010 '(progn
3011 (add-hook 'nxml-mode-hook (lambda () (tidy-build-menu nxml-mode-map)))
3012 (add-hook 'html-mode-hook (lambda () (tidy-build-menu html-mode-map)))
3013 ))
3014
3015 #+END_SRC
3016 ** org :FIXME:
3017 *** General settings
3018 [2013-04-28 So 17:06]
3019
3020 I use org-mode a lot and, having my config for this based on [[*Bernt%20Hansen][the config of Bernt Hansen]],
3021 it is quite extensive. Nevertheless, it starts out small, loading it.
3022 #+BEGIN_SRC emacs-lisp
3023 (require 'org)
3024 #+END_SRC
3025
3026 My browsers (Conkeror, Iceweasel) can store links in org-mode. For
3027 that we need org-protocol.
3028 #+BEGIN_SRC emacs-lisp
3029 (require 'org-protocol)
3030 #+END_SRC
3031
3032 *** Agenda
3033
3034 My current =org-agenda-files= variable only includes a set of
3035 directories.
3036 #+BEGIN_SRC emacs-lisp
3037 (setq org-agenda-files (quote ("~/org/"
3038 "~/org/debian"
3039 "~/org/debconf"
3040 "~/org/spi"
3041 "~/org/nsb"
3042 )))
3043 (setq org-default-notes-file "~/org/notes.org")
3044 #+END_SRC
3045 =org-mode= manages the =org-agenda-files= variable automatically using
3046 =C-c [= and =C-c ]= to add and remove files respectively. However,
3047 this replaces my directory list with a list of explicit filenames
3048 instead and is not what I want. If this occurs then adding a new org
3049 file to any of the above directories will not contribute to my agenda
3050 and I will probably miss something important.
3051
3052 I have disabled the =C-c [= and =C-c ]= keys in =org-mode-hook= to
3053 prevent messing up my list of directories in the =org-agenda-files=
3054 variable. I just add and remove directories manually here. Changing
3055 the list of directories in =org-agenda-files= happens very rarely
3056 since new files in existing directories are automatically picked up.
3057
3058 #+BEGIN_SRC emacs-lisp
3059 ;; Keep tasks with dates on the global todo lists
3060 (setq org-agenda-todo-ignore-with-date nil)
3061
3062 ;; Keep tasks with deadlines on the global todo lists
3063 (setq org-agenda-todo-ignore-deadlines nil)
3064
3065 ;; Keep tasks with scheduled dates on the global todo lists
3066 (setq org-agenda-todo-ignore-scheduled nil)
3067
3068 ;; Keep tasks with timestamps on the global todo lists
3069 (setq org-agenda-todo-ignore-timestamp nil)
3070
3071 ;; Remove completed deadline tasks from the agenda view
3072 (setq org-agenda-skip-deadline-if-done t)
3073
3074 ;; Remove completed scheduled tasks from the agenda view
3075 (setq org-agenda-skip-scheduled-if-done t)
3076
3077 ;; Remove completed items from search results
3078 (setq org-agenda-skip-timestamp-if-done t)
3079
3080 ;; Include agenda archive files when searching for things
3081 (setq org-agenda-text-search-extra-files (quote (agenda-archives)))
3082
3083 ;; Show all future entries for repeating tasks
3084 (setq org-agenda-repeating-timestamp-show-all t)
3085
3086 ;; Show all agenda dates - even if they are empty
3087 (setq org-agenda-show-all-dates t)
3088
3089 ;; Sorting order for tasks on the agenda
3090 (setq org-agenda-sorting-strategy
3091 (quote ((agenda habit-down time-up user-defined-up priority-down effort-up category-keep)
3092 (todo category-up priority-down effort-up)
3093 (tags category-up priority-down effort-up)
3094 (search category-up))))
3095
3096 ;; Start the weekly agenda on Monday
3097 (setq org-agenda-start-on-weekday 1)
3098
3099 ;; Enable display of the time grid so we can see the marker for the current time
3100 (setq org-agenda-time-grid (quote ((daily today remove-match)
3101 #("----------------" 0 16 (org-heading t))
3102 (0800 1000 1200 1400 1500 1700 1900 2100))))
3103
3104 ;; Display tags farther right
3105 (setq org-agenda-tags-column -102)
3106
3107 ; position the habit graph on the agenda to the right of the default
3108 (setq org-habit-graph-column 50)
3109
3110 ; turn habits back on
3111 (run-at-time "06:00" 86400 '(lambda () (setq org-habit-show-habits t)))
3112
3113 ;;
3114 ;; Agenda sorting functions
3115 ;;
3116 (setq org-agenda-cmp-user-defined 'bh/agenda-sort)
3117
3118
3119 (setq org-deadline-warning-days 30)
3120
3121 ;; Always hilight the current agenda line
3122 (add-hook 'org-agenda-mode-hook
3123 '(lambda () (hl-line-mode 1))
3124 'append)
3125 #+END_SRC
3126
3127 #+BEGIN_SRC emacs-lisp
3128 (setq org-agenda-persistent-filter t)
3129 (add-hook 'org-agenda-mode-hook
3130 '(lambda () (org-defkey org-agenda-mode-map "W" 'bh/widen))
3131 'append)
3132
3133 (add-hook 'org-agenda-mode-hook
3134 '(lambda () (org-defkey org-agenda-mode-map "F" 'bh/restrict-to-file-or-follow))
3135 'append)
3136
3137 (add-hook 'org-agenda-mode-hook
3138 '(lambda () (org-defkey org-agenda-mode-map "N" 'bh/narrow-to-subtree))
3139 'append)
3140
3141 (add-hook 'org-agenda-mode-hook
3142 '(lambda () (org-defkey org-agenda-mode-map "U" 'bh/narrow-up-one-level))
3143 'append)
3144
3145 (add-hook 'org-agenda-mode-hook
3146 '(lambda () (org-defkey org-agenda-mode-map "P" 'bh/narrow-to-project))
3147 'append)
3148
3149 ; Rebuild the reminders everytime the agenda is displayed
3150 (add-hook 'org-finalize-agenda-hook 'bh/org-agenda-to-appt 'append)
3151
3152 ;(if (file-exists-p "~/org/refile.org")
3153 ; (add-hook 'after-init-hook 'bh/org-agenda-to-appt))
3154
3155 ; Activate appointments so we get notifications
3156 (appt-activate t)
3157
3158 (setq org-agenda-log-mode-items (quote (closed clock state)))
3159 (if (> emacs-major-version 23)
3160 (setq org-agenda-span 3)
3161 (setq org-agenda-ndays 3))
3162
3163 (setq org-agenda-show-all-dates t)
3164 (setq org-agenda-start-on-weekday nil)
3165 (setq org-deadline-warning-days 14)
3166
3167 #+END_SRC
3168 *** Global keybindings.
3169 Start off by defining a series of keybindings.
3170
3171 Well, first we remove =C-c [= and =C-c ]=, as all agenda directories are
3172 setup manually, not by org-mode. Also turn off =C-c ;=, which
3173 comments headlines - a function never used.
3174 #+BEGIN_SRC emacs-lisp
3175 (add-hook 'org-mode-hook
3176 (lambda ()
3177 (org-defkey org-mode-map "\C-c[" 'undefined)
3178 (org-defkey org-mode-map "\C-c]" 'undefined)
3179 (org-defkey org-mode-map "\C-c;" 'undefined))
3180 'append)
3181 #+END_SRC
3182
3183 And now a largish set of keybindings...
3184 #+BEGIN_SRC emacs-lisp
3185 (bind-key "C-c l" 'org-store-link)
3186 (bind-key "C-c a" 'org-agenda)
3187 ;(bind-key "C-c b" 'org-iswitchb)
3188 (define-key mode-specific-map [?a] 'org-agenda)
3189
3190 (bind-key "<f12>" 'org-agenda)
3191 (bind-key "<f5>" 'bh/org-todo)
3192 (bind-key "<S-f5>" 'bh/widen)
3193 ;(bind-key "<f7>" 'bh/set-truncate-lines)
3194 ;(bind-key "<f8>" 'org-cycle-agenda-files)
3195
3196 (bind-key "<f9> <f9>" 'bh/show-org-agenda)
3197 (bind-key "<f9> b" 'bbdb)
3198 (bind-key "<f9> c" 'calendar)
3199 (bind-key "<f9> f" 'boxquote-insert-file)
3200 (bind-key "<f9> h" 'bh/hide-other)
3201 (bind-key "<f9> n" 'org-narrow-to-subtree)
3202 (bind-key "<f9> w" 'widen)
3203 (bind-key "<f9> u" 'bh/narrow-up-one-level)
3204 (bind-key "<f9> I" 'bh/punch-in)
3205 (bind-key "<f9> O" 'bh/punch-out)
3206 (bind-key "<f9> H" 'jj/punch-in-hw)
3207 (bind-key "<f9> W" 'jj/punch-out-hw)
3208 (bind-key "<f9> o" 'bh/make-org-scratch)
3209 (bind-key "<f9> p" 'bh/phone-call)
3210 (bind-key "<f9> r" 'boxquote-region)
3211 (bind-key "<f9> s" 'bh/switch-to-scratch)
3212 (bind-key "<f9> t" 'bh/insert-inactive-timestamp)
3213 (bind-key "<f9> T" 'tabify)
3214 (bind-key "<f9> U" 'untabify)
3215 (bind-key "<f9> v" 'visible-mode)
3216 (bind-key "<f9> SPC" 'bh/clock-in-last-task)
3217 (bind-key "C-<f9>" 'previous-buffer)
3218 (bind-key "C-<f10>" 'next-buffer)
3219 (bind-key "M-<f9>" 'org-toggle-inline-images)
3220 ;(bind-key "C-x n r" 'narrow-to-region)
3221 (bind-key "<f11>" 'org-clock-goto)
3222 (bind-key "C-<f11>" 'org-clock-in)
3223 (bind-key "C-M-r" 'org-capture)
3224 (bind-key "C-c r" 'org-capture)
3225 (bind-key "C-S-<f12>" 'bh/save-then-publish)
3226 ;(bind-key "C-k" 'jj-org-kill-line org-mode-map)
3227
3228 #+END_SRC
3229
3230 *** Tasks, States, Todo fun
3231
3232 First we define the global todo keywords.
3233 #+BEGIN_SRC emacs-lisp
3234 (setq org-todo-keywords
3235 (quote ((sequence "TODO(t)" "NEXT(n)" "|" "DONE(d@/!)")
3236 (sequence "WAITING(w@/!)" "HOLD(h@/!)" "DELEGATED(g@/!)" "|" "CANCELLED(c@/!)" "PHONE"))))
3237
3238 (setq org-todo-keyword-faces
3239 (quote (("TODO" :foreground "red" :weight bold)
3240 ("NEXT" :foreground "light blue" :weight bold)
3241 ("DONE" :foreground "forest green" :weight bold)
3242 ("WAITING" :foreground "orange" :weight bold)
3243 ("HOLD" :foreground "orange" :weight bold)
3244 ("DELEGATED" :foreground "yellow" :weight bold)
3245 ("CANCELLED" :foreground "dark green" :weight bold)
3246 ("PHONE" :foreground "dark green" :weight bold))))
3247 #+END_SRC
3248
3249 **** Fast Todo Selection
3250 Fast todo selection allows changing from any task todo state to any
3251 other state directly by selecting the appropriate key from the fast
3252 todo selection key menu.
3253 #+BEGIN_SRC emacs-lisp
3254 (setq org-use-fast-todo-selection t)
3255 #+END_SRC
3256 Changing a task state is done with =C-c C-t KEY=
3257
3258 where =KEY= is the appropriate fast todo state selection key as defined in =org-todo-keywords=.
3259
3260 The setting
3261 #+BEGIN_SRC emacs-lisp
3262 (setq org-treat-S-cursor-todo-selection-as-state-change nil)
3263 #+END_SRC
3264 allows changing todo states with S-left and S-right skipping all of
3265 the normal processing when entering or leaving a todo state. This
3266 cycles through the todo states but skips setting timestamps and
3267 entering notes which is very convenient when all you want to do is fix
3268 up the status of an entry.
3269
3270 **** Todo State Triggers
3271 I have a few triggers that automatically assign tags to tasks based on
3272 state changes. If a task moves to =CANCELLED= state then it gets a
3273 =CANCELLED= tag. Moving a =CANCELLED= task back to =TODO= removes the
3274 =CANCELLED= tag. These are used for filtering tasks in agenda views
3275 which I'll talk about later.
3276
3277 The triggers break down to the following rules:
3278
3279 - Moving a task to =CANCELLED= adds a =CANCELLED= tag
3280 - Moving a task to =WAITING= adds a =WAITING= tag
3281 - Moving a task to =HOLD= adds a =WAITING= tag
3282 - Moving a task to a done state removes a =WAITING= tag
3283 - Moving a task to =TODO= removes =WAITING= and =CANCELLED= tags
3284 - Moving a task to =NEXT= removes a =WAITING= tag
3285 - Moving a task to =DONE= removes =WAITING= and =CANCELLED= tags
3286
3287 The tags are used to filter tasks in the agenda views conveniently.
3288 #+BEGIN_SRC emacs-lisp
3289 (setq org-todo-state-tags-triggers
3290 (quote (("CANCELLED" ("CANCELLED" . t))
3291 ("WAITING" ("WAITING" . t))
3292 ("HOLD" ("WAITING" . t) ("HOLD" . t))
3293 (done ("WAITING") ("HOLD"))
3294 ("TODO" ("WAITING") ("CANCELLED") ("HOLD"))
3295 ("NEXT" ("WAITING") ("CANCELLED") ("HOLD"))
3296 ("DONE" ("WAITING") ("CANCELLED") ("HOLD")))))
3297 #+END_SRC
3298
3299 *** Capturing new tasks
3300 Org capture replaces the old remember mode.
3301 #+BEGIN_SRC emacs-lisp
3302 (setq org-directory "~/org")
3303 (setq org-default-notes-file "~/org/refile.org")
3304
3305 ;; Capture templates for: TODO tasks, Notes, appointments, phone calls, and org-protocol
3306 ;; see http://orgmode.org/manual/Template-elements.html
3307 (setq org-capture-templates
3308 (quote (("t" "todo" entry (file "~/org/refile.org")
3309 "* TODO %?\nAdded: %U\n"
3310 :clock-in t :clock-resume t)
3311 ("l" "linktodo" entry (file "~/org/refile.org")
3312 "* TODO %?\nAdded: %U\n%a\n"
3313 :clock-in t :clock-resume t)
3314 ("r" "respond" entry (file "~/org/refile.org")
3315 "* TODO Respond to %:from on %:subject\nSCHEDULED: %t\nAdded: %U\n%a\n"
3316 :clock-in t :clock-resume t :immediate-finish t)
3317 ("n" "note" entry (file "~/org/refile.org")
3318 "* %? :NOTE:\nAdded: %U\n%a\n"
3319 :clock-in t :clock-resume t)
3320 ("d" "Delegated" entry (file "~/org/refile.org")
3321 "* DELEGATED %?\nAdded: %U\n%a\n"
3322 :clock-in t :clock-resume t)
3323 ("j" "Journal" entry (file+datetree "~/org/diary.org")
3324 "* %?\nAdded: %U\n"
3325 :clock-in t :clock-resume t)
3326 ("w" "org-protocol" entry (file "~/org/refile.org")
3327 "* TODO Review %c\nAdded: %U\n"
3328 :immediate-finish t)
3329 ("p" "Phone call" entry (file "~/org/refile.org")
3330 "* PHONE %? :PHONE:\nAdded: %U"
3331 :clock-in t :clock-resume t)
3332 ("x" "Bookmark link" entry (file "~/org/refile.org")
3333 "* Bookmark: %c\n%i\nAdded: %U\n"
3334 :immediate-finish t)
3335 ("h" "Habit" entry (file "~/org/refile.org")
3336 "* 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")
3337 )))
3338 #+END_SRC
3339
3340 Capture mode now handles automatically clocking in and out of a
3341 capture task. This all works out of the box now without special hooks.
3342 When I start a capture mode task the task is clocked in as specified
3343 by =:clock-in t= and when the task is filed with =C-c C-c= the clock
3344 resumes on the original clocking task.
3345
3346 The quick clocking in and out of capture mode tasks (often it takes
3347 less than a minute to capture some new task details) can leave
3348 empty clock drawers in my tasks which aren't really useful.
3349 The following prevents this.
3350 #+BEGIN_SRC emacs-lisp
3351 (add-hook 'org-clock-out-hook 'bh/remove-empty-drawer-on-clock-out 'append)
3352 #+END_SRC
3353
3354 *** Refiling
3355 All my newly captured entries end up in =refile.org= and want to be
3356 moved over to the right place. The following is the setup for it.
3357 #+BEGIN_SRC emacs-lisp
3358 ; Targets include this file and any file contributing to the agenda - up to 9 levels deep
3359 (setq org-refile-targets (quote ((nil :maxlevel . 9)
3360 (org-agenda-files :maxlevel . 9))))
3361
3362 ; Use full outline paths for refile targets - we file directly with IDO
3363 (setq org-refile-use-outline-path t)
3364
3365 ; Targets complete directly with IDO
3366 (setq org-outline-path-complete-in-steps nil)
3367
3368 ; Allow refile to create parent tasks with confirmation
3369 (setq org-refile-allow-creating-parent-nodes (quote confirm))
3370
3371 ; Use IDO for both buffer and file completion and ido-everywhere to t
3372 (setq org-completion-use-ido t)
3373 (setq org-completion-use-iswitchb nil)
3374 :; Use IDO for both buffer and file completion and ido-everywhere to t
3375 ;(setq ido-everywhere t)
3376 ;(setq ido-max-directory-size 100000)
3377 ;(ido-mode (quote both))
3378 ; Use the current window when visiting files and buffers with ido
3379 (setq ido-default-file-method 'selected-window)
3380 (setq ido-default-buffer-method 'selected-window)
3381
3382 ;;;; Refile settings
3383 (setq org-refile-target-verify-function 'bh/verify-refile-target)
3384 #+END_SRC
3385
3386 *** Custom agenda
3387 Agenda view is the central place for org-mode interaction...
3388 #+BEGIN_SRC emacs-lisp
3389 ;; Do not dim blocked tasks
3390 (setq org-agenda-dim-blocked-tasks nil)
3391 ;; Compact the block agenda view
3392 (setq org-agenda-compact-blocks t)
3393
3394 ;; Custom agenda command definitions
3395 (setq org-agenda-custom-commands
3396 (quote (("N" "Notes" tags "NOTE"
3397 ((org-agenda-overriding-header "Notes")
3398 (org-tags-match-list-sublevels t)))
3399 ("h" "Habits" tags-todo "STYLE=\"habit\""
3400 ((org-agenda-overriding-header "Habits")
3401 (org-agenda-sorting-strategy
3402 '(todo-state-down effort-up category-keep))))
3403 (" " "Agenda"
3404 ((agenda "" nil)
3405 (tags "REFILE"
3406 ((org-agenda-overriding-header "Tasks to Refile")
3407 (org-tags-match-list-sublevels nil)))
3408 (tags-todo "-HOLD-CANCELLED/!"
3409 ((org-agenda-overriding-header "Projects")
3410 (org-agenda-skip-function 'bh/skip-non-projects)
3411 (org-agenda-sorting-strategy
3412 '(category-keep))))
3413 (tags-todo "-CANCELLED/!"
3414 ((org-agenda-overriding-header "Stuck Projects")
3415 (org-agenda-skip-function 'bh/skip-non-stuck-projects)))
3416 (tags-todo "-WAITING-CANCELLED/!NEXT"
3417 ((org-agenda-overriding-header "Next Tasks")
3418 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
3419 (org-agenda-todo-ignore-scheduled t)
3420 (org-agenda-todo-ignore-deadlines t)
3421 (org-agenda-todo-ignore-with-date t)
3422 (org-tags-match-list-sublevels t)
3423 (org-agenda-sorting-strategy
3424 '(todo-state-down effort-up category-keep))))
3425 (tags-todo "-REFILE-CANCELLED/!-HOLD-WAITING"
3426 ((org-agenda-overriding-header "Tasks")
3427 (org-agenda-skip-function 'bh/skip-project-tasks-maybe)
3428 (org-agenda-todo-ignore-scheduled t)
3429 (org-agenda-todo-ignore-deadlines t)
3430 (org-agenda-todo-ignore-with-date t)
3431 (org-agenda-sorting-strategy
3432 '(category-keep))))
3433 (tags-todo "-CANCELLED+WAITING/!"
3434 ((org-agenda-overriding-header "Waiting and Postponed Tasks")
3435 (org-agenda-skip-function 'bh/skip-stuck-projects)
3436 (org-tags-match-list-sublevels nil)
3437 (org-agenda-todo-ignore-scheduled 'future)
3438 (org-agenda-todo-ignore-deadlines 'future)))
3439 (tags "-REFILE/"
3440 ((org-agenda-overriding-header "Tasks to Archive")
3441 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
3442 (org-tags-match-list-sublevels nil))))
3443 nil)
3444 ("r" "Tasks to Refile" tags "REFILE"
3445 ((org-agenda-overriding-header "Tasks to Refile")
3446 (org-tags-match-list-sublevels nil)))
3447 ("#" "Stuck Projects" tags-todo "-CANCELLED/!"
3448 ((org-agenda-overriding-header "Stuck Projects")
3449 (org-agenda-skip-function 'bh/skip-non-stuck-projects)))
3450 ("n" "Next Tasks" tags-todo "-WAITING-CANCELLED/!NEXT"
3451 ((org-agenda-overriding-header "Next Tasks")
3452 (org-agenda-skip-function 'bh/skip-projects-and-habits-and-single-tasks)
3453 (org-agenda-todo-ignore-scheduled t)
3454 (org-agenda-todo-ignore-deadlines t)
3455 (org-agenda-todo-ignore-with-date t)
3456 (org-tags-match-list-sublevels t)
3457 (org-agenda-sorting-strategy
3458 '(todo-state-down effort-up category-keep))))
3459 ("R" "Tasks" tags-todo "-REFILE-CANCELLED/!-HOLD-WAITING"
3460 ((org-agenda-overriding-header "Tasks")
3461 (org-agenda-skip-function 'bh/skip-project-tasks-maybe)
3462 (org-agenda-sorting-strategy
3463 '(category-keep))))
3464 ("p" "Projects" tags-todo "-HOLD-CANCELLED/!"
3465 ((org-agenda-overriding-header "Projects")
3466 (org-agenda-skip-function 'bh/skip-non-projects)
3467 (org-agenda-sorting-strategy
3468 '(category-keep))))
3469 ("w" "Waiting Tasks" tags-todo "-CANCELLED+WAITING/!"
3470 ((org-agenda-overriding-header "Waiting and Postponed tasks"))
3471 (org-tags-match-list-sublevels nil))
3472 ("A" "Tasks to Archive" tags "-REFILE/"
3473 ((org-agenda-overriding-header "Tasks to Archive")
3474 (org-agenda-skip-function 'bh/skip-non-archivable-tasks)
3475 (org-tags-match-list-sublevels nil))))))
3476
3477 ; Overwrite the current window with the agenda
3478 (setq org-agenda-window-setup 'current-window)
3479
3480 #+END_SRC
3481
3482 *** Time
3483 #+BEGIN_SRC emacs-lisp
3484 ;;
3485 ;; Resume clocking task when emacs is restarted
3486 (org-clock-persistence-insinuate)
3487 ;;
3488 ;; Show lot sof clocking history so it's easy to pick items off the C-F11 list
3489 (setq org-clock-history-length 36)
3490 ;; Resume clocking task on clock-in if the clock is open
3491 (setq org-clock-in-resume t)
3492 ;; Change tasks to NEXT when clocking in
3493 (setq org-clock-in-switch-to-state 'bh/clock-in-to-next)
3494 ;; Separate drawers for clocking and logs
3495 (setq org-drawers (quote ("PROPERTIES" "LOGBOOK")))
3496 ;; Save clock data and state changes and notes in the LOGBOOK drawer
3497 (setq org-clock-into-drawer t)
3498 ;; Sometimes I change tasks I'm clocking quickly - this removes clocked tasks with 0:00 duration
3499 (setq org-clock-out-remove-zero-time-clocks t)
3500 ;; Clock out when moving task to a done state
3501 (setq org-clock-out-when-done (quote ("DONE" "WAITING" "DELEGATED" "CANCELLED")))
3502 ;; Save the running clock and all clock history when exiting Emacs, load it on startup
3503 (setq org-clock-persist t)
3504 ;; Do not prompt to resume an active clock
3505 (setq org-clock-persist-query-resume nil)
3506 ;; Enable auto clock resolution for finding open clocks
3507 (setq org-clock-auto-clock-resolution (quote when-no-clock-is-running))
3508 ;; Include current clocking task in clock reports
3509 (setq org-clock-report-include-clocking-task t)
3510
3511 ; use discrete minute intervals (no rounding) increments
3512 (setq org-time-stamp-rounding-minutes (quote (1 1)))
3513
3514 (add-hook 'org-clock-out-hook 'bh/clock-out-maybe 'append)
3515
3516 (setq bh/keep-clock-running nil)
3517
3518 (setq org-agenda-clock-consistency-checks
3519 (quote (:max-duration "4:00"
3520 :min-duration 0
3521 :max-gap 0
3522 :gap-ok-around ("4:00"))))
3523
3524 #+END_SRC
3525
3526 **** Setting a default clock task
3527 Per default the =** Organization= task in my tasks.org file receives
3528 misc clock time. This is the task I clock in on when I punch in at the
3529 start of my work day with =F9-I=. Punching-in anywhere clocks in this
3530 Organization task as the default task.
3531
3532 If I want to change the default clocking task I just visit the
3533 new task in any org buffer and clock it in with =C-u C-u C-c C-x
3534 C-i=. Now this new task that collects miscellaneous clock
3535 minutes when the clock would normally stop.
3536
3537 You can quickly clock in the default clocking task with =C-u C-c
3538 C-x C-i d=. Another option is to repeatedly clock out so the
3539 clock moves up the project tree until you clock out the
3540 top-level task and the clock moves to the default task.
3541
3542 **** Reporting
3543 #+BEGIN_SRC emacs-lisp
3544 ;; Agenda clock report parameters
3545 (setq org-agenda-clockreport-parameter-plist
3546 (quote (:link t :maxlevel 5 :fileskip0 t :compact t :narrow 80)))
3547
3548 ;; Agenda log mode items to display (closed and state changes by default)
3549 (setq org-agenda-log-mode-items (quote (closed state)))
3550 #+END_SRC
3551 **** Task estimates, column view
3552 Setup column view globally with the following headlines
3553 #+BEGIN_SRC emacs-lisp
3554 ; Set default column view headings: Task Effort Clock_Summary
3555 (setq org-columns-default-format "%80ITEM(Task) %10Effort(Effort){:} %10CLOCKSUM")
3556 #+END_SRC
3557 Setup the estimate for effort values.
3558 #+BEGIN_SRC emacs-lisp
3559 ; global Effort estimate values
3560 ; global STYLE property values for completion
3561 (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")
3562 ("STYLE_ALL" . "habit"))))
3563 #+END_SRC
3564
3565 *** Tags
3566 Tags are mostly used for filtering inside the agenda.
3567 #+BEGIN_SRC emacs-lisp
3568 ; Tags with fast selection keys
3569 (setq org-tag-alist (quote ((:startgroup)
3570 ("@errand" . ?e)
3571 ("@office" . ?o)
3572 ("@home" . ?H)
3573 (:endgroup)
3574 ("PHONE" . ?p)
3575 ("WAITING" . ?w)
3576 ("HOLD" . ?h)
3577 ("PERSONAL" . ?P)
3578 ("WORK" . ?W)
3579 ("ORG" . ?O)
3580 ("PRIVATE" . ?N)
3581 ("crypt" . ?E)
3582 ("MARK" . ?M)
3583 ("NOTE" . ?n)
3584 ("CANCELLED" . ?c)
3585 ("FLAGGED" . ??))))
3586
3587 ; Allow setting single tags without the menu
3588 (setq org-fast-tag-selection-single-key (quote expert))
3589
3590 ; For tag searches ignore tasks with scheduled and deadline dates
3591 (setq org-agenda-tags-todo-honor-ignore-options t)
3592 #+END_SRC
3593
3594 *** Archiving
3595 #+BEGIN_SRC emacs-lisp
3596 (setq org-archive-mark-done nil)
3597 (setq org-archive-location "%s_archive::* Archived Tasks")
3598 #+END_SRC
3599
3600 *** org-babel
3601 #+BEGIN_SRC emacs-lisp
3602 (setq org-ditaa-jar-path "~/java/ditaa0_6b.jar")
3603 (setq org-plantuml-jar-path "~/java/plantuml.jar")
3604
3605 (add-hook 'org-babel-after-execute-hook 'bh/display-inline-images 'append)
3606
3607 ; Make babel results blocks lowercase
3608 (setq org-babel-results-keyword "results")
3609
3610 (org-babel-do-load-languages
3611 (quote org-babel-load-languages)
3612 (quote ((emacs-lisp . t)
3613 (awk . t)
3614 (css . t)
3615 (makefile . t)
3616 (perl . t)
3617 (ruby . t)
3618 (dot . t)
3619 (ditaa . t)
3620 (R . t)
3621 (python . t)
3622 (ruby . t)
3623 (gnuplot . t)
3624 (clojure . t)
3625 (sh . t)
3626 (ledger . t)
3627 (org . t)
3628 (plantuml . t)
3629 (latex . t))))
3630
3631 ; Do not prompt to confirm evaluation
3632 ; This may be dangerous - make sure you understand the consequences
3633 ; of setting this -- see the docstring for details
3634 (setq org-confirm-babel-evaluate nil)
3635
3636 ; Use fundamental mode when editing plantuml blocks with C-c '
3637 (add-to-list 'org-src-lang-modes (quote ("plantuml" . fundamental)))
3638 #+END_SRC
3639
3640 #+BEGIN_SRC emacs-lisp
3641 ;; Don't have images visible on startup, breaks on console
3642 (setq org-startup-with-inline-images nil)
3643 #+END_SRC
3644
3645 #+BEGIN_SRC emacs-lisp
3646 (add-to-list 'org-structure-template-alist
3647 '("n" "#+BEGIN_COMMENT\n?\n#+END_COMMENT"
3648 "<comment>\n?\n</comment>"))
3649 #+END_SRC
3650 **** ditaa, graphviz, etc
3651 Those are all nice tools. Look at
3652 http://doc.norang.ca/org-mode.html#playingwithditaa for a nice intro
3653 to them.
3654
3655 *** Publishing and exporting
3656
3657
3658 Org-mode can export to a variety of publishing formats including (but not limited to)
3659
3660 - ASCII
3661 (plain text - but not the original org-mode file)
3662 - HTML
3663 - LaTeX
3664 - Docbook
3665 which enables getting to lots of other formats like ODF, XML, etc
3666 - PDF
3667 via LaTeX or Docbook
3668 - iCal
3669
3670 A new exporter created by Nicolas Goaziou was introduced in org 8.0.
3671
3672 #+BEGIN_SRC emacs-lisp
3673 ;; Explicitly load required exporters
3674 (require 'ox-html)
3675 (require 'ox-latex)
3676 (require 'ox-ascii)
3677 (require 'ox-reveal)
3678 ;; FIXME, check the following two
3679 ;(require 'ox-icalendar)
3680 ;(require 'ox-odt)
3681
3682 ; experimenting with docbook exports - not finished
3683 (setq org-export-docbook-xsl-fo-proc-command "fop %s %s")
3684 (setq org-export-docbook-xslt-proc-command "xsltproc --output %s /usr/share/xml/docbook/stylesheet/nwalsh/fo/docbook.xsl %s")
3685
3686 (setq org-reveal-root "file:///home/joerg/devel/ganeticon2015/reveal.js/reveal.js")
3687
3688 ;; define categories that should be excluded
3689 (setq org-export-exclude-category (list "google" "google"))
3690 (setq org-icalendar-use-scheduled '(todo-start event-if-todo))
3691
3692 ; define how the date strings look
3693 (setq org-export-date-timestamp-format "%Y-%m-%d")
3694 ; Inline images in HTML instead of producting links to the image
3695 (setq org-html-inline-images t)
3696 ; Do not use sub or superscripts - I currently don't need this functionality in my documents
3697 (setq org-export-with-sub-superscripts nil)
3698
3699 (setq org-html-head-extra (concat
3700 "<link rel=\"stylesheet\" href=\"https://ganneff.de/stylesheet.css\" type=\"text/css\" />\n"
3701 ))
3702 (setq org-html-head-include-default-style nil)
3703 ; Do not generate internal css formatting for HTML exports
3704 (setq org-export-htmlize-output-type (quote css))
3705 ; Export with LaTeX fragments
3706 (setq org-export-with-LaTeX-fragments t)
3707 ; Increase default number of headings to export
3708 (setq org-export-headline-levels 6)
3709
3710
3711 (setq org-publish-project-alist
3712 '(
3713 ("config-notes"
3714 :base-directory "~/.emacs.d/"
3715 :base-extension "org"
3716 :exclude "elisp"
3717 :publishing-directory "/develop/www/emacs"
3718 :recursive t
3719 :publishing-function org-html-publish-to-html
3720 :headline-levels 4 ; Just the default for this project.
3721 :auto-preamble t
3722 :auto-sitemap t
3723 :makeindex t
3724 )
3725 ("config-static"
3726 :base-directory "~/.emacs.d/"
3727 :base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
3728 :publishing-directory "/develop/www/emacs"
3729 :exclude "elisp\\|elpa\\|elpa.off\\|auto-save-list\\|cache\\|eshell\\|image-dired\\|themes\\|url"
3730 :recursive t
3731 :publishing-function org-publish-attachment
3732 )
3733 ("inherit-org-info-js"
3734 :base-directory "/develop/vcs/org-info-js/"
3735 :recursive t
3736 :base-extension "js"
3737 :publishing-directory "/develop/www/"
3738 :publishing-function org-publish-attachment
3739 )
3740 ("config" :components ("inherit-org-info-js" "config-notes" "config-static")
3741 )
3742 )
3743 )
3744
3745 (setq org-export-with-timestamps nil)
3746 #+END_SRC
3747
3748 **** Latex export
3749
3750 #+BEGIN_SRC emacs-lisp
3751 (setq org-latex-to-pdf-process
3752 '("xelatex -interaction nonstopmode %f"
3753 "xelatex -interaction nonstopmode %f")) ;; for multiple passes
3754 (setq org-export-latex-listings 'minted)
3755 (setq org-latex-listings t)
3756
3757 ;; Originally taken from Bruno Tavernier: http://thread.gmane.org/gmane.emacs.orgmode/31150/focus=31432
3758 ;; but adapted to use latexmk 4.20 or higher.
3759 (defun my-auto-tex-cmd ()
3760 "When exporting from .org with latex, automatically run latex,
3761 pdflatex, or xelatex as appropriate, using latexmk."
3762 (let ((texcmd)))
3763 ;; default command: oldstyle latex via dvi
3764 (setq texcmd "latexmk -dvi -pdfps -quiet %f")
3765 ;; pdflatex -> .pdf
3766 (if (string-match "LATEX_CMD: pdflatex" (buffer-string))
3767 (setq texcmd "latexmk -pdf -quiet %f"))
3768 ;; xelatex -> .pdf
3769 (if (string-match "LATEX_CMD: xelatex" (buffer-string))
3770 (setq texcmd "latexmk -pdflatex='xelatex -shell-escape' -pdf -quiet %f"))
3771 ;; LaTeX compilation command
3772 (setq org-latex-to-pdf-process (list texcmd)))
3773
3774 (add-hook 'org-export-latex-after-initial-vars-hook 'my-auto-tex-cmd)
3775
3776 ;; Specify default packages to be included in every tex file, whether pdflatex or xelatex
3777 (setq org-export-latex-packages-alist
3778 '(("" "graphicx" t)
3779 ("" "longtable" nil)
3780 ("" "float" nil)
3781 ("" "minted" nil)
3782 ))
3783
3784 (defun my-auto-tex-parameters ()
3785 "Automatically select the tex packages to include."
3786 ;; default packages for ordinary latex or pdflatex export
3787 (setq org-export-latex-default-packages-alist
3788 '(("AUTO" "inputenc" t)
3789 ("T1" "fontenc" t)
3790 ("" "fixltx2e" nil)
3791 ("" "wrapfig" nil)
3792 ("" "soul" t)
3793 ("" "textcomp" t)
3794 ("" "marvosym" t)
3795 ("" "wasysym" t)
3796 ("" "latexsym" t)
3797 ("" "amssymb" t)
3798 ("" "hyperref" nil)))
3799
3800 ;; Packages to include when xelatex is used
3801 (if (string-match "LATEX_CMD: xelatex" (buffer-string))
3802 (setq org-export-latex-default-packages-alist
3803 '(("" "fontspec" t)
3804 ("" "xunicode" t)
3805 ("" "url" t)
3806 ("" "rotating" t)
3807 ("german" "babel" t)
3808 ("babel" "csquotes" t)
3809 ("" "soul" t)
3810 ("xetex" "hyperref" nil)
3811 )))
3812
3813 (if (string-match "#+LATEX_CMD: xelatex" (buffer-string))
3814 (setq org-export-latex-classes
3815 (cons '("scrartcl"
3816 "\\documentclass[11pt,DIV=13,oneside]{scrartcl}"
3817 ("\\section{%s}" . "\\section*{%s}")
3818 ("\\subsection{%s}" . "\\subsection*{%s}")
3819 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
3820 ("\\paragraph{%s}" . "\\paragraph*{%s}")
3821 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
3822 org-export-latex-classes))))
3823
3824 (add-hook 'org-export-latex-after-initial-vars-hook 'my-auto-tex-parameters)
3825 #+END_SRC
3826
3827 *** Prevent editing invisible text
3828 The following setting prevents accidentally editing hidden text when
3829 the point is inside a folded region. This can happen if you are in
3830 the body of a heading and globally fold the org-file with =S-TAB=
3831
3832 I find invisible edits (and undo's) hard to deal with so now I can't
3833 edit invisible text. =C-c C-r= (org-reveal) will display where the
3834 point is if it is buried in invisible text to allow editing again.
3835
3836 #+BEGIN_SRC emacs-lisp
3837 (setq org-catch-invisible-edits 'error)
3838 #+END_SRC
3839
3840 *** Whatever
3841 #+BEGIN_SRC emacs-lisp
3842 ;; disable the default org-mode stuck projects agenda view
3843 (setq org-stuck-projects (quote ("" nil nil "")))
3844
3845 ; force showing the next headline.
3846 (setq org-show-entry-below (quote ((default))))
3847
3848 (setq org-show-following-heading t)
3849 (setq org-show-hierarchy-above t)
3850 (setq org-show-siblings (quote ((default))))
3851
3852 (setq org-special-ctrl-a/e t)
3853 (setq org-special-ctrl-k t)
3854 (setq org-yank-adjusted-subtrees t)
3855
3856 (setq org-table-export-default-format "orgtbl-to-csv")
3857
3858 #+END_SRC
3859
3860 The following setting adds alphabetical lists like
3861 ,a. item one
3862 ,b. item two
3863
3864 #+BEGIN_SRC emacs-lisp
3865 (if (> emacs-major-version 23)
3866 (setq org-list-allow-alphabetical t)
3867 (setq org-alphabetical-lists t))
3868 #+END_SRC
3869
3870 #+BEGIN_SRC emacs-lisp
3871 (setq org-remove-highlights-with-change nil)
3872
3873 (setq org-list-demote-modify-bullet (quote (("+" . "-")
3874 ("*" . "-")
3875 ("1." . "-")
3876 ("1)" . "-"))))
3877
3878
3879
3880 (add-hook 'org-insert-heading-hook 'bh/insert-heading-inactive-timestamp 'append)
3881
3882
3883 ; If we leave Emacs running overnight - reset the appointments one minute after midnight
3884 (run-at-time "24:01" nil 'bh/org-agenda-to-appt)
3885
3886 #+END_SRC
3887
3888
3889 #+BEGIN_SRC emacs-lisp
3890 ;; Enable abbrev-mode
3891 (add-hook 'org-mode-hook (lambda () (abbrev-mode 1)))
3892 (setq org-startup-indented t)
3893 (setq org-startup-folded t)
3894 (setq org-cycle-separator-lines 0)
3895 #+END_SRC
3896
3897 I find extra blank lines in lists and headings a bit of a nuisance.
3898 To get a body after a list you need to include a blank line between
3899 the list entry and the body -- and indent the body appropriately.
3900 Most of my lists have no body detail so I like the look of collapsed
3901 lists with no blank lines better.
3902
3903 The following setting prevents creating blank lines before headings
3904 but allows list items to adapt to existing blank lines around the items:
3905 #+BEGIN_SRC emacs-lisp
3906 (setq org-blank-before-new-entry (quote ((heading)
3907 (plain-list-item . auto))))
3908 #+END_SRC
3909
3910 #+BEGIN_SRC emacs-lisp
3911 (setq org-reverse-note-order nil)
3912 (setq org-default-notes-file "~/notes.org")
3913 #+END_SRC
3914
3915 Enforce task blocking. Tasks can't go done when there is any subtask
3916 still open. Unless they have a property of =NOBLOCKING: t=
3917 #+BEGIN_SRC emacs-lisp
3918 (setq org-enforce-todo-checkbox-dependencies t)
3919 (setq org-enforce-todo-dependencies t)
3920 #+END_SRC
3921
3922 #+BEGIN_SRC emacs-lisp
3923 (setq org-fast-tag-selection-single-key (quote expert))
3924 (setq org-footnote-auto-adjust t)
3925 (setq org-hide-block-startup t)
3926 (setq org-icalendar-alarm-time 15)
3927 (setq org-icalendar-combined-description "Ganneffs Org-mode calendar entries")
3928 (setq org-icalendar-combined-name "\"Ganneffs OrgMode\"")
3929 (setq org-icalendar-honor-noexport-tag t)
3930 (setq org-icalendar-include-bbdb-anniversaries nil)
3931 (setq org-icalendar-include-body 200)
3932 (setq org-icalendar-include-todo nil)
3933 (setq org-icalendar-store-UID t)
3934 (setq org-icalendar-timezone "Europe/Berlin")
3935 (setq org-insert-mode-line-in-empty-file t)
3936 (setq org-log-done (quote note))
3937 (setq org-log-into-drawer t)
3938 (setq org-log-state-notes-insert-after-drawers nil)
3939 (setq org-log-reschedule (quote time))
3940 (setq org-log-states-order-reversed t)
3941 (setq org-mobile-agendas (quote all))
3942 (setq org-mobile-directory "/scpx:joerg@garibaldi.ganneff.de:/srv/www2.ganneff.de/htdocs/org/")
3943 (setq org-mobile-inbox-for-pull "~/org/refile.org")
3944 (setq org-remember-store-without-prompt t)
3945 (setq org-return-follows-link t)
3946 (setq org-reverse-note-order t)
3947
3948 ; regularly save our org-mode buffers
3949 (run-at-time "00:59" 3600 'org-save-all-org-buffers)
3950
3951 (setq org-log-done t)
3952
3953 (setq org-enable-priority-commands t)
3954 (setq org-default-priority ?E)
3955 (setq org-lowest-priority ?E)
3956
3957
3958 #+END_SRC
3959
3960 Speed commands enable single-letter commands in Org-mode files when
3961 the point is at the beginning of a headline, or at the beginning of a
3962 code block.
3963
3964 See the `=org-speed-commands-default=' variable for a list of the keys
3965 and commands enabled at the beginning of headlines. All code blocks
3966 are available at the beginning of a code block, the following key
3967 sequence =C-c C-v h= (bound to `=org-babel-describe-bindings=') will
3968 display a list of the code blocks commands and their related keys.
3969
3970 #+BEGIN_SRC emacs-lisp
3971 (setq org-use-speed-commands nil)
3972 (setq org-speed-commands-user (quote (("0" . ignore)
3973 ("1" . ignore)
3974 ("2" . ignore)
3975 ("3" . ignore)
3976 ("4" . ignore)
3977 ("5" . ignore)
3978 ("6" . ignore)
3979 ("7" . ignore)
3980 ("8" . ignore)
3981 ("9" . ignore)
3982
3983 ("a" . ignore)
3984 ("d" . ignore)
3985 ("h" . bh/hide-other)
3986 ("i" progn
3987 (forward-char 1)
3988 (call-interactively 'org-insert-heading-respect-content))
3989 ("k" . org-kill-note-or-show-branches)
3990 ("l" . ignore)
3991 ("m" . ignore)
3992 ("q" . bh/show-org-agenda)
3993 ("r" . ignore)
3994 ("s" . org-save-all-org-buffers)
3995 ("w" . org-refile)
3996 ("x" . ignore)
3997 ("y" . ignore)
3998 ("z" . org-add-note)
3999
4000 ("A" . ignore)
4001 ("B" . ignore)
4002 ("E" . ignore)
4003 ("F" . bh/restrict-to-file-or-follow)
4004 ("G" . ignore)
4005 ("H" . ignore)
4006 ("J" . org-clock-goto)
4007 ("K" . ignore)
4008 ("L" . ignore)
4009 ("M" . ignore)
4010 ("N" . bh/narrow-to-org-subtree)
4011 ("P" . bh/narrow-to-org-project)
4012 ("Q" . ignore)
4013 ("R" . ignore)
4014 ("S" . ignore)
4015 ("T" . bh/org-todo)
4016 ("U" . bh/narrow-up-one-org-level)
4017 ("V" . ignore)
4018 ("W" . bh/widen)
4019 ("X" . ignore)
4020 ("Y" . ignore)
4021 ("Z" . ignore))))
4022
4023 (add-hook 'org-agenda-mode-hook
4024 (lambda ()
4025 (define-key org-agenda-mode-map "q" 'bury-buffer))
4026 'append)
4027
4028 (defvar bh/current-view-project nil)
4029 (add-hook 'org-agenda-mode-hook
4030 '(lambda () (org-defkey org-agenda-mode-map "V" 'bh/view-next-project))
4031 'append)
4032 #+END_SRC
4033
4034
4035 The following displays the contents of code blocks in Org-mode files
4036 using the major-mode of the code. It also changes the behavior of
4037 =TAB= to as if it were used in the appropriate major mode. This means
4038 that reading and editing code form inside of your Org-mode files is
4039 much more like reading and editing of code using its major mode.
4040
4041 #+BEGIN_SRC emacs-lisp
4042 (setq org-src-fontify-natively t)
4043 (setq org-src-tab-acts-natively t)
4044 #+END_SRC
4045
4046 #+BEGIN_SRC emacs-lisp
4047 (setq org-src-preserve-indentation nil)
4048 (setq org-edit-src-content-indentation 0)
4049 #+END_SRC
4050
4051
4052 #+BEGIN_SRC emacs-lisp
4053 (setq org-attach-directory "~/org/data/")
4054 #+END_SRC
4055 #+BEGIN_SRC emacs-lisp
4056 (setq org-agenda-sticky t)
4057 #+END_SRC
4058
4059 **** Checklist handling
4060 [2013-05-11 Sat 22:15]
4061
4062 #+BEGIN_SRC emacs-lisp
4063 ;(require 'org-checklist)
4064 #+END_SRC
4065 ** perl / cperl
4066 I like /cperl-mode/ a bit more than the default /perl-mode/, so set it
4067 up here to be used.
4068 #+BEGIN_SRC emacs-lisp
4069 (use-package cperl-mode
4070 :commands cperl-mode
4071 :idle
4072 (progn
4073 (defalias 'perl-mode 'cperl-mode)
4074 (add-auto-mode 'cperl-mode "\\.\\([pP][Llm]\\|al\\)\\'")
4075 (add-auto-mode 'pod-mode "\\.pod$")
4076 (add-auto-mode 'tt-mode "\\.tt$")
4077 (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
4078 (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
4079 (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
4080 )
4081 :config
4082 (progn
4083 (setq cperl-invalid-face nil
4084 cperl-close-paren-offset -4
4085 cperl-continued-statement-offset 0
4086 cperl-indent-level 4
4087 cperl-indent-parens-as-block t
4088 cperl-hairy t
4089 cperl-electric-keywords t
4090 cperl-electric-lbrace-space t
4091 cperl-electric-parens nil
4092 cperl-highlight-variables-indiscriminately t
4093 cperl-imenu-addback t
4094 cperl-invalid-face (quote underline)
4095 cperl-lazy-help-time 5
4096 cperl-scan-files-regexp "\\.\\([pP][Llm]\\|xs\\|cgi\\)$"
4097 cperl-syntaxify-by-font-lock t
4098 cperl-use-syntax-table-text-property-for-tags t)
4099
4100 ;; And have cperl mode give ElDoc a useful string
4101 (defun my-cperl-eldoc-documentation-function ()
4102 "Return meaningful doc string for `eldoc-mode'."
4103 (car
4104 (let ((cperl-message-on-help-error nil))
4105 (cperl-get-help))))
4106 (add-hook 'cperl-mode-hook
4107 (lambda ()
4108 (set (make-local-variable 'eldoc-documentation-function)
4109 'my-cperl-eldoc-documentation-function)
4110 (eldoc-mode))))
4111 )
4112 #+END_SRC
4113 ** puppet
4114 [2014-05-22 Thu 00:05]
4115 #+BEGIN_SRC emacs-lisp
4116 (use-package puppet-mode
4117 :mode ("\\.pp\\'" . puppet-mode)
4118 :commands puppet-mode
4119 :idle
4120 (progn
4121 (defun my-puppet-mode-hook ()
4122 (setq require-final-newline nil))
4123 (add-hook 'puppet-mode-hook 'my-puppet-mode-hook))
4124 :config
4125 (progn
4126 (use-package puppet-ext
4127 :init
4128 (progn
4129 (bind-key "C-x ?" 'puppet-set-anchor puppet-mode-map)
4130 (bind-key "C-c C-r" 'puppet-create-require puppet-mode-map)))))
4131 #+END_SRC
4132
4133 ** python
4134 Use elpy for the emacs python fun, but dont let it initialize all the
4135 various variables. Elpy author may like them, but I'm not him...
4136 #+BEGIN_SRC emacs-lisp
4137 (use-package elpy
4138 :defer t
4139 :mode ("\.py" . python-mode)
4140 :init
4141 (progn
4142 (safe-load (concat jj-elisp-dir "/elpy/elpy-autoloads.el"))
4143 )
4144 :config
4145 (progn
4146
4147 (use-package nose
4148 :ensure nose
4149 :commands (nosetests-all nosetests-module nosetests-one
4150 nosetests-failed nosetests-pdb-all
4151 nosetests-pdb-module nosetests-pdb-one)
4152 )
4153
4154 (use-package pyvenv
4155 :ensure pyvenv
4156 :commands (pyvenv-activate pyvenv-deactivate pyvenv-mode pyvenv-restart-python)
4157 )
4158
4159 (use-package idomenu
4160 :ensure idomenu
4161 :commands (idomenu)
4162 :defer t)
4163
4164 (use-package highlight-indentation
4165 :ensure t
4166 :commands (highlight-indentation-mode))
4167
4168 (use-package find-file-in-project
4169 :ensure t
4170 :commands (find-file-in-project ffip-project-files ffip ))
4171
4172 (use-package fuzzy
4173 :ensure t)
4174
4175 ;; Local variables in `python-mode'. This is not removed when Elpy
4176 ;; is disabled, which can cause some confusion.
4177 (add-hook 'python-mode-hook 'elpy-initialize-local-variables)
4178
4179 (defun my-python-mode-hook ()
4180 (setq require-final-newline nil)
4181 (setq mode-require-final-newline))
4182 (add-hook 'python-mode-hook 'my-python-mode-hook)
4183
4184 ;; Flymake support using flake8, including warning faces.
4185 (when (and (executable-find "flake8")
4186 (not (executable-find python-check-command)))
4187 (setq python-check-command "flake8"))
4188
4189 ;; `flymake-no-changes-timeout': The original value of 0.5 is too
4190 ;; short for Python code, as that will result in the current line to
4191 ;; be highlighted most of the time, and that's annoying. This value
4192 ;; might be on the long side, but at least it does not, in general,
4193 ;; interfere with normal interaction.
4194 (setq flymake-no-changes-timeout 60)
4195
4196 ;; `flymake-start-syntax-check-on-newline': This should be nil for
4197 ;; Python, as;; most lines with a colon at the end will mean the next
4198 ;; line is always highlighted as error, which is not helpful and
4199 ;; mostly annoying.
4200 (setq flymake-start-syntax-check-on-newline nil)
4201
4202 ;; `ac-auto-show-menu': Short timeout because the menu is great.