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