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