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