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