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