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