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