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