]> git.donarmstrong.com Git - lib.git/blob - emacs_el/configuration/don-configuration.org
add atomic-chrome support
[lib.git] / emacs_el / configuration / don-configuration.org
1 #+PROPERTY: header-args:emacs-lisp :tangle don-configuration.el
2 * Load debugger
3
4 # if for some reason, things get pear-shaped, we want to be able to
5 # enter the debugger by sending -USR2 to emacs
6
7 #+BEGIN_SRC emacs-lisp
8 (setq debug-on-event 'siguser2)
9 #+END_SRC
10 * Add library paths
11
12 #+BEGIN_SRC emacs-lisp
13   (add-to-list 'load-path '"~/lib/emacs_el/")
14   (add-to-list 'load-path '"~/lib/emacs_el/helm")
15   (add-to-list 'load-path '"~/lib/emacs_el/tiny-tools/lisp/tiny")
16   (add-to-list 'load-path '"~/lib/emacs_el/tiny-tools/lisp/other")
17   (add-to-list 'load-path '"~/lib/emacs_el/auctex/lisp")
18   (add-to-list 'load-path '"~/lib/emacs_el/auctex")
19   (add-to-list 'load-path '"~/lib/emacs_el/ESS/lisp")
20   (add-to-list 'load-path '"~/lib/emacs_el/org-mode/lisp")
21   (add-to-list 'load-path '"~/lib/emacs_el/auctex-beamer")
22   (add-to-list 'load-path '"~/lib/emacs_el/magit-annex")
23   (add-to-list 'load-path '"~/lib/emacs_el/polymode")
24 #+END_SRC
25
26 * Package management
27 ** package repositories and package manager
28 #+BEGIN_SRC emacs-lisp
29   (require 'package)
30   (setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
31                            ("melpa" . "https://melpa.org/packages/")
32                            ("org" . "http://orgmode.org/elpa/") ))
33 #+END_SRC
34 ** [[https://github.com/jwiegley/use-package/][use-package]]
35 #+BEGIN_SRC emacs-lisp
36   (require 'use-package)
37   (package-initialize)
38 #+END_SRC
39 ** Paradox
40 #+BEGIN_SRC emacs-lisp
41   (package-initialize)
42   (use-package paradox
43     :ensure paradox
44   )
45 #+END_SRC
46 * Misc functions
47 ** with-library
48 #+BEGIN_SRC emacs-lisp
49 ;; From http://www.emacswiki.org/emacs/LoadingLispFiles
50 ;; execute conditional code when loading libraries
51 (defmacro with-library (symbol &rest body)
52   `(when (require ,symbol nil t)
53      ,@body))
54 (put 'with-library 'lisp-indent-function 1)
55 #+END_SRC
56
57
58 * Memory
59 #+BEGIN_SRC emacs-lisp
60   (setq global-mark-ring-max 128
61         mark-ring-max 128
62         kill-ring-max 128)
63
64   (defun don/minibuffer-setup-hook ()
65     (setq gc-cons-threshold most-positive-fixnum))
66
67   (defun don/minibuffer-exit-hook ()
68     (setq gc-cons-threshold 1048576))
69
70   (add-hook 'minibuffer-setup-hook #'don/minibuffer-setup-hook)
71   (add-hook 'minibuffer-exit-hook #'don/minibuffer-exit-hook)
72 #+END_SRC
73 * Modules
74 ** Flyspell 🐝 
75 #+BEGIN_SRC emacs-lisp
76   (use-package flyspell
77     :ensure t
78     :diminish flyspell-mode 🐝
79     :config
80     (add-hook 'message-mode-hook 'turn-on-flyspell)
81     (add-hook 'text-mode-hook 'turn-on-flyspell)
82     (add-hook 'c-mode-common-hook 'flyspell-prog-mode)
83     (add-hook 'cperl-mode-hook 'flyspell-prog-mode)
84     (add-hook 'tcl-mode-hook 'flyspell-prog-mode)
85     :init
86     (setq ispell-program-name "ispell")
87     )
88
89 #+END_SRC
90 ** Winnermode
91 #+BEGIN_SRC emacs-lisp
92   (winner-mode 1)
93 #+END_SRC
94 ** Eyebrowse
95
96 #+BEGIN_SRC emacs-lisp
97   ;; (use-package eyebrowse
98   ;;   :ensure t
99   ;;   :diminish eyebrowse-mode
100   ;;   :init (setq eyebrowse-keymap-prefix (kbd "C-c C-\\"))
101   ;;   :config (progn
102   ;;             (setq eyebrowse-wrap-around t)
103   ;;             (eyebrowse-mode t)
104   ;; 
105   ;;             (defun my/eyebrowse-new-window-config ()
106   ;;               (interactive)
107   ;;               (let ((done nil))
108   ;;                 (dotimes (i 10)
109   ;;                   ;; start at 1 run till 0
110   ;;                   (let ((j (mod (+ i 1) 10)))
111   ;;                     (when (and (not done)
112   ;;                                (not (eyebrowse--window-config-present-p j)))
113   ;;                       (eyebrowse-switch-to-window-config j)
114   ;;                       (call-interactively 'eyebrowse-rename-window-config2 j)
115   ;;                       (setq done t)
116   ;;                       ))
117   ;;                   )))
118   ;; 
119   ;;             ;; I don't use latex-preview-pane
120   ;;             ;; (require 'latex-preview-pane)
121   ;;             ;; (defun my/close-latex-preview-pane-before-eyebrowse-switch ()
122   ;;             ;;   ;; latex-preview-pane uses window-parameters which are
123   ;;             ;;   ;; not preserved by eyebrowse, so we close the preview
124   ;;             ;;   ;; pane before switching, it will be regenerated when we
125   ;;             ;;   ;; edit the TeX file.
126   ;;             ;;   (when (lpp/window-containing-preview)
127   ;;             ;;     (delete-window (lpp/window-containing-preview))))
128   ;; 
129   ;;             ;; (add-to-list 'eyebrowse-pre-window-switch-hook
130   ;;             ;;              #'my/close-latex-preview-pane-before-eyebrowse-switch)
131   ;; 
132   ;;             ;; (my/set-menu-key "["  #'my/eyebrowse-new-window-config)
133   ;;             ;; (my/set-menu-key ";"  #'eyebrowse-prev-window-config)
134   ;;             ;; (my/set-menu-key "'"  #'eyebrowse-next-window-config)
135   ;;             ;; (my/set-menu-key "]"  #'eyebrowse-close-window-config)
136   ;;             ;; (my/set-menu-key "\\" #'eyebrowse-rename-window-config)
137   ;;             )
138   ;;   )
139 #+END_SRC
140
141 ** Window handling
142
143 *** Splitting
144 #+BEGIN_SRC emacs-lisp
145   (defun my/vsplit-last-buffer ()
146     "Split the window vertically and display the previous buffer."
147     (interactive)
148     (split-window-vertically)
149     (other-window 1 nil)
150     (switch-to-next-buffer))
151
152   (defun my/hsplit-last-buffer ()
153     "Split the window horizontally and display the previous buffer."
154     (interactive)
155     (split-window-horizontally)
156     (other-window 1 nil)
157     (switch-to-next-buffer))
158
159   (bind-key "C-x 2" 'my/vsplit-last-buffer)
160   (bind-key "C-x 3" 'my/hsplit-last-buffer)
161
162   (setq split-width-threshold  100)
163   (setq split-height-threshold 60)
164
165   (defun my/split-window-prefer-vertically (window)
166     "If there's only one window (excluding any possibly active
167            minibuffer), then split the current window horizontally."
168     (if (and (one-window-p t)
169              (not (active-minibuffer-window))
170              ( < (frame-width) (frame-height))
171              )
172         (let ((split-width-threshold nil))
173           (split-window-sensibly window))
174       (split-window-sensibly window)))
175
176   (setq split-window-preferred-function #'my/split-window-prefer-vertically)
177   (setq window-combination-resize t)
178 #+END_SRC
179
180 *** Compilation window
181
182 If there is no compilation window, open one at the bottom, spanning
183 the complete width of the frame. Otherwise, reuse existing window. In
184 the former case, if there was no error the window closes
185 automatically.
186
187 #+BEGIN_SRC emacs-lisp
188   (add-to-list 'display-buffer-alist
189                `(,(rx bos "*compilation*" eos)
190                  (display-buffer-reuse-window
191                   display-buffer-in-side-window)
192                  (reusable-frames . visible)
193                  (side            . bottom)
194                  (window-height   . 0.4)))
195 #+END_SRC
196
197 #+BEGIN_SRC emacs-lisp
198   (defun my/compilation-exit-autoclose (status code msg)
199     ;; If M-x compile exists with a 0
200     (when (and (eq status 'exit) (zerop code))
201       ;; and delete the *compilation* window
202       (let ((compilation-window (get-buffer-window (get-buffer "*compilation*"))))
203         (when (and (not (window-at-side-p compilation-window 'top))
204                    (window-at-side-p compilation-window 'left)
205                    (window-at-side-p compilation-window 'right))
206           (delete-window compilation-window))))
207     ;; Always return the anticipated result of compilation-exit-message-function
208     (cons msg code))
209
210   ;; Specify my function (maybe I should have done a lambda function)
211   (setq compilation-exit-message-function #'my/compilation-exit-autoclose)
212 #+END_SRC
213
214 If you change the variable ~compilation-scroll-output~ to a ~non-nil~
215 value, the compilation buffer scrolls automatically to follow the
216 output. If the value is ~first-error~, scrolling stops when the first
217 error appears, leaving point at that error. For any other non-nil
218 value, scrolling continues until there is no more output.
219
220 #+BEGIN_SRC emacs-lisp
221   (setq compilation-scroll-output 'first-error)
222 #+END_SRC
223
224 ** Mode line cleaning
225 *** Diminish
226 #+BEGIN_SRC emacs-lisp
227   (use-package diminish
228     :ensure t)
229 #+END_SRC
230
231 *** Delight 
232 #+BEGIN_SRC emacs-lisp
233   (use-package delight
234     :ensure t)
235 #+END_SRC
236
237 ** Jumping
238 *** Avy
239 #+BEGIN_SRC emacs-lisp
240 (use-package avy
241   :ensure t
242   :bind ("C-c C-SPC" . avy-goto-word-1)
243   :config (progn
244             (setq avy-background t)
245             (key-chord-define-global "jj"  #'avy-goto-word-1)))
246 #+END_SRC
247
248 ** Snippets
249
250 *** Yasnippet
251 #+BEGIN_SRC emacs-lisp
252   (use-package yasnippet
253     :ensure t
254     :diminish yas-minor-mode
255     :config (progn
256               (yas-global-mode)
257               (setq yas-verbosity 1)
258               (define-key yas-minor-mode-map (kbd "<tab>") nil)
259               (define-key yas-minor-mode-map (kbd "TAB") nil)
260               (define-key yas-minor-mode-map (kbd "<backtab>") 'yas-expand)
261               ))
262 #+END_SRC
263
264 ** Helm Flx
265
266 [[https://github.com/PythonNut/helm-flx][helm-flx]] implements intelligent helm fuzzy sorting, provided by [[https://github.com/lewang/flx][flx]].
267
268 #+BEGIN_SRC emacs-lisp
269 (use-package helm-flx
270   :ensure t
271   :config (progn
272             ;; these are helm configs, but they kind of fit here nicely
273             (setq helm-M-x-fuzzy-match                  t
274                   helm-bookmark-show-location           t
275                   helm-buffers-fuzzy-matching           t
276                   helm-completion-in-region-fuzzy-match t
277                   helm-file-cache-fuzzy-match           t
278                   helm-imenu-fuzzy-match                t
279                   helm-mode-fuzzy-match                 t
280                   helm-locate-fuzzy-match               nil
281                   helm-quick-update                     t
282                   helm-recentf-fuzzy-match              nil
283                   helm-semantic-fuzzy-match             t)
284             (helm-flx-mode +1)))
285 #+END_SRC
286
287
288 ** Tinyprocmail
289
290 #+BEGIN_SRC emacs-lisp
291   ;; load tinyprocmail
292   (use-package tinyprocmail
293     :ensure f
294     :config (with-library 'tinyprocmail
295               ;; (setq tinyprocmail--procmail-version "v3.22")
296               (add-hook 'tinyprocmail--load-hook 'tinyprocmail-install))
297   )
298 #+END_SRC
299
300 ** Magit
301 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
302   (use-package magit
303     :ensure t
304     :bind (("C-x g" . magit-status)
305            ("C-x C-g" . magit-status))
306     :config
307     ;; don't verify where we are pushing
308     (setq magit-push-always-verify nil)
309     ;; refine diffs always (hilight words)
310     (setq magit-diff-refine-hunk nil)
311     ;; load magit-annex
312     (setq load-path
313           (append '("~/lib/emacs_el/magit-annex")
314                   load-path))
315     ;; load magit-vcsh
316     (setq load-path
317           (append '("~/lib/emacs_el/magit-vcsh")
318                   load-path))
319     )
320   (use-package magit-annex
321     :ensure t
322   )
323   (use-package magit-vcsh
324     :ensure f ; currently not in melpa, so don't try to install
325   )
326 #+END_SRC
327
328 ** Perl
329 #+BEGIN_SRC emacs-lisp
330   (require 'cperl-mode)
331   ;; Use c-mode for perl .xs files
332   (add-to-list 'auto-mode-alist '("\\.xs\\'" . c-mode))
333   (add-to-list 'auto-mode-alist '("\\.\\([pP][Llm]\\|al\\)\\'" . cperl-mode))
334   (add-to-list 'interpreter-mode-alist '("perl" . cperl-mode))
335   (add-to-list 'interpreter-mode-alist '("perl5" . cperl-mode))
336   (add-to-list 'interpreter-mode-alist '("miniperl" . cperl-mode))
337   (setq cperl-hairy t
338         cperl-indent-level 4
339         cperl-auto-newline nil
340         cperl-auto-newline-after-colon nil
341         cperl-continued-statement-offset 4
342         cperl-brace-offset -1
343         cperl-continued-brace-offset 0
344         cperl-label-offset -4
345         cperl-highlight-variables-indiscriminately t
346         cperl-electric-lbrace-space nil
347         cperl-indent-parens-as-block nil
348         cperl-close-paren-offset -1
349         cperl-tab-always-indent t)
350   ;(add-hook 'cperl-mode-hook (lambda () (cperl-set-style "PerlStyle")))
351 #+END_SRC
352
353 ** Helm
354 #+BEGIN_SRC emacs-lisp
355   (use-package helm
356     :ensure t
357     :config
358     (helm-mode 1)
359     (define-key global-map [remap find-file] 'helm-find-files)
360     (define-key global-map [remap occur] 'helm-occur)
361     (define-key global-map [remap list-buffers] 'helm-buffers-list)
362     (define-key global-map [remap dabbrev-expand] 'helm-dabbrev)
363     (global-set-key (kbd "M-x") 'helm-M-x)
364     (unless (boundp 'completion-in-region-function)
365       (define-key lisp-interaction-mode-map [remap completion-at-point] 'helm-lisp-completion-at-point)
366       (define-key emacs-lisp-mode-map       [remap completion-at-point] 'helm-lisp-completion-at-point))
367     (add-hook 'kill-emacs-hook #'(lambda () (and (file-exists-p "$TMP") (delete-file "$TMP"))))
368   )
369 #+END_SRC
370 ** Hydra
371 #+BEGIN_SRC emacs-lisp :tangle don-configuration.el
372 (require 'don-hydra)
373 #+END_SRC
374
375 ** Tramp
376 #+BEGIN_SRC emacs-lisp
377   (add-to-list 'tramp-methods '("vcsh"
378                                 (tramp-login-program "vcsh")
379                                 (tramp-login-args
380                                  (("enter")
381                                   ("%h")))
382                                 (tramp-remote-shell "/bin/sh")
383                                 (tramp-remote-shell-args
384                                  ("-c"))))
385 #+END_SRC
386 ** Reftex
387 #+BEGIN_SRC emacs-lisp
388   (use-package reftex
389     :ensure t
390     :config
391     (setq-default reftex-default-bibliography
392                     '("~/projects/research/references.bib")))
393 #+END_SRC
394 ** LaTeX
395 #+BEGIN_SRC emacs-lisp
396   (use-package tex
397     :defer t
398     :ensure auctex
399     :config
400     ; (add-to-list 'TeX-style-path '"/home/don/lib/emacs_el/auctex/style")
401     ;; REFTEX (much enhanced management of cross-ref, labels, etc)
402     ;; http://www.strw.leidenuniv.nl/~dominik/Tools/reftex/
403     ; (autoload 'reftex-mode     "reftex" "RefTeX Minor Mode" t)
404     ; (autoload 'turn-on-reftex  "reftex" "RefTeX Minor Mode" nil)
405     ; (autoload 'reftex-citation "reftex-cite" "Make citation" nil)
406     ; (autoload 'reftex-index-phrase-mode "reftex-index" "Phrase mode" t)
407     (add-hook 'LaTeX-mode-hook 'turn-on-reftex)   ; with AUCTeX LaTeX mode
408     (add-hook 'latex-mode-hook 'turn-on-reftex)   ; with Emacs latex mode
409     (add-hook 'LaTeX-mode-hook 'outline-minor-mode)   ; with AUCTeX LaTeX mode
410     (add-hook 'latex-mode-hook 'outline-minor-mode)   ; with Emacs latex mode
411
412     (setq-default reftex-plug-into-AUCTeX t)
413     ;; support fake section headers
414     (setq TeX-outline-extra
415           '(("%chapter" 1)
416             ("%section" 2)
417             ("%subsection" 3)
418             ("%subsubsection" 4)
419             ("%paragraph" 5)))
420     ;; add font locking to the headers
421     (font-lock-add-keywords
422      'latex-mode
423      '(("^%\\(chapter\\|\\(sub\\|subsub\\)?section\\|paragraph\\)"
424         0 'font-lock-keyword-face t)
425        ("^%chapter{\\(.*\\)}"       1 'font-latex-sectioning-1-face t)
426        ("^%section{\\(.*\\)}"       1 'font-latex-sectioning-2-face t)
427        ("^%subsection{\\(.*\\)}"    1 'font-latex-sectioning-3-face t)
428        ("^%subsubsection{\\(.*\\)}" 1 'font-latex-sectioning-4-face t)
429        ("^%paragraph{\\(.*\\)}"     1 'font-latex-sectioning-5-face t)))
430
431     ;; use smart quotes by default instead of `` and ''
432     ;; taken from http://kieranhealy.org/esk/kjhealy.html
433     (setq TeX-open-quote "“")
434     (setq TeX-close-quote "”")
435
436     ;; (TeX-add-style-hook
437     ;;  "latex"
438     ;;  (lambda ()
439     ;;    (TeX-add-symbols
440     ;;     '("DLA" 1))))
441     ;; (custom-set-variables
442     ;;  '(font-latex-user-keyword-classes 
443     ;;    '(("fixme" 
444     ;;       ("DLA" "RZ")
445     ;;       font-lock-function-name-face 2 (command 1 t))))
446     ;; ) 
447     (setq-default TeX-parse-self t)
448     (setq-default TeX-auto-save t)
449     (setq-default TeX-master nil)
450     (eval-after-load
451         "latex"
452       '(TeX-add-style-hook
453         "cleveref"
454         (lambda ()
455           (if (boundp 'reftex-ref-style-alist)
456               (add-to-list
457                'reftex-ref-style-alist
458                '("Cleveref" "cleveref"
459                  (("\\cref" ?c) ("\\Cref" ?C) ("\\cpageref" ?d) ("\\Cpageref" ?D)))))
460           (reftex-ref-style-activate "Cleveref")
461           (TeX-add-symbols
462            '("cref" TeX-arg-ref)
463            '("Cref" TeX-arg-ref)
464            '("cpageref" TeX-arg-ref)
465            '("Cpageref" TeX-arg-ref)))))
466     (eval-after-load
467         "latex"
468       '(add-to-list 'LaTeX-fill-excluded-macros
469                     '("Sexpr")))
470
471     (use-package font-latex
472       :config
473       (setq font-latex-match-reference-keywords
474             '(
475               ("fref" "{")
476               ("Fref" "{")
477               ("citep" "{")
478               ("citet" "{")
479               ("acs" "{")
480               ("acsp" "{")
481               ("ac" "{")
482               ("acp" "{")
483               ("acl" "{")
484               ("aclp" "{")
485               ("acsu" "{")
486               ("aclu" "{")
487               ("acused" "{")
488               ("DLA" "{")
489               ("RZ" "{")
490               ("OM" "{")
491               ("DL" "{")
492               ("fixme" "{"))
493             )
494       )
495   )
496
497 #+END_SRC
498 ** Org
499 #+BEGIN_SRC emacs-lisp
500   (require 'org-mode-configuration)
501 #+END_SRC
502 *** Org-Gcal
503 #+BEGIN_SRC emacs-lisp
504   (use-package calfw
505     :ensure f
506     )
507   (use-package calfw-org
508     :ensure f
509     )
510   (use-package org-gcal
511     :ensure f
512     :config '((if (file-readable-p "~/.hide/org_gcal.el")
513                   (load-file "~/.hide/org_gcal.el"))
514               )
515     )
516 #+END_SRC
517 ** ESS
518 #+BEGIN_SRC emacs-lisp
519   (use-package ess
520     :ensure t
521     :config (require 'ess_configuration))
522 #+END_SRC
523
524 ** Rainbowmode
525 From http://julien.danjou.info/projects/emacs-packages#rainbow-mode, this colorizes color strings
526
527 #+BEGIN_SRC emacs-lisp
528   (use-package rainbow-mode
529     ;; add ess to the x major mode
530     :config (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[S])
531     (add-to-list 'rainbow-x-colors-major-mode-list 'ESS[R])
532   )
533 #+END_SRC
534
535 ** Polymode
536 #+BEGIN_SRC emacs-lisp
537   (use-package polymode
538     :config
539     (use-package poly-R)
540     (use-package poly-noweb)
541     (use-package poly-markdown)
542     :mode ("\\.Snw" . poly-noweb+r-mode)
543     :mode ("\\.Rnw" . poly-noweb+r-mode)
544     :mode ("\\.Rmd" . poly-markdown+r-mode)
545     )
546 #+END_SRC
547
548 ** Outlining
549 *** Outline magic
550 #+BEGIN_SRC emacs-lisp
551   (use-package outline-magic)
552 #+END_SRC
553 ** Writeroom Mode
554 #+BEGIN_SRC emacs-lisp
555   (use-package writeroom-mode
556     :config (add-hook 'writeroom-mode-hook 'auto-fill-mode)
557     )
558 #+END_SRC
559 ** GhostText/Atomic Chrome
560 #+BEGIN_SRC emacs-lisp
561   (use-package atomic-chrome
562     :config (atomic-chrome-start-server)
563     )
564 #+END_SRC
565 * Keybindings
566 ** Override other things
567 #+BEGIN_SRC emacs-lisp
568   ; apparently things like to step on C-;, so we'll use a hack from
569   ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
570
571   (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
572
573   ; use iedit everywhere
574   (define-key my-keys-minor-mode-map (kbd "C-;") 'iedit-mode)
575   ;; use outline mode keybindings everywhere
576   ;; (define-key my-keys-minor-mode-map (kbd "C-;") 'my/mydra-outline/body)
577
578   (define-minor-mode my-keys-minor-mode
579     "A minor mode so that my key settings override annoying major modes."
580     t " my-keys" 'my-keys-minor-mode-map)
581
582   (my-keys-minor-mode 1)
583   (defun my-minibuffer-setup-hook ()
584     (my-keys-minor-mode 0))
585
586   (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
587   (defadvice load (after give-my-keybindings-priority)
588     "Try to ensure that my keybindings always have priority."
589     (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
590         (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
591           (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
592           (add-to-list 'minor-mode-map-alist mykeys))))
593   (ad-activate 'load)
594 #+END_SRC
595
596 * Misc (uncharacterized)
597 #+BEGIN_SRC emacs-lisp
598   (setq bibtex-user-optional-fields (quote (("annote" "Personal annotation (ignored)") ("abstract" "") ("pmid" "") ("doi" ""))))
599   (setq calendar-latitude 40.11)
600   (setq calendar-longitude -88.24)
601   (setq case-fold-search t)
602   (setq confirm-kill-emacs (quote y-or-n-p))
603   (setq cperl-lazy-help-time nil)
604   (setq debian-changelog-mailing-address "don@debian.org")
605   (display-time)
606   (setq display-time-24hr-format t)
607   (setq display-time-day-and-date t)
608   (display-time-mode 1)
609   (setq font-latex-fontify-script nil)
610   (setq font-latex-fontify-sectioning (quote color))
611   (setq font-latex-script-display (quote (nil)))
612   (global-auto-revert-mode 1)
613   (global-font-lock-mode 1)
614   (icomplete-mode 1)
615   (setq log-edit-keep-buffer t)
616   (setq mail-user-agent (quote sendmail-user-agent))
617   (setq markdown-enable-math t)
618   (setq markdown-follow-wiki-link-on-enter nil)
619   (setq mutt-alias-file-list (quote ("~/.mutt/aliases" "~/.mail_aliases")))
620   (setq post-email-address "don@donarmstrong.com")
621   (setq post-kill-quoted-sig nil)
622   (setq post-mail-message "mutt\\(ng\\|\\)-[a-z0-9]+-[0-9]+-.*")
623   (setq post-uses-fill-mode nil)
624   (setq ps-footer-font-size (quote (8 . 10)))
625   (setq ps-header-font-size (quote (8 . 10)))
626   (setq ps-header-title-font-size (quote (10 . 10)))
627   (setq ps-line-number-color "blue")
628   (setq ps-print-footer t)
629   (setq ps-print-footer-frame nil)
630   (setq ps-print-only-one-header t)
631   (setq safe-local-variable-values (quote ((auto-save-default) (make-backup-files))))
632   (setq sentence-end "[.?!][]\"')]*\\($\\|   \\| \\)[    
633   ]*")
634   (setq sentence-end-double-space nil)
635   ; enable matching parenthesis
636   (show-paren-mode 1)
637   (tool-bar-mode -1)
638   (setq user-mail-address "don@donarmstrong.com")
639   (setq vc-delete-logbuf-window nil)
640   (setq vc-follow-symlinks t)
641
642   ;; use git before SVN; use CVS earlier, because I have CVS
643   ;; repositories inside of git directories
644   (setq vc-handled-backends (quote (CVS Git RCS SVN SCCS Bzr Hg Mtn Arch)))
645
646   ;; switch back to the old primary selection method
647   (setq x-select-enable-clipboard nil)
648   (setq x-select-enable-primary t)
649   ; (setq mouse-drag-copy-region t)
650
651   (fset 'perl-mode 'cperl-mode)
652   ;;(load-file "cperl-mode.el")
653
654   (require 'vcl-mode)
655
656   (require 'tex-site)
657   ;;(require 'psvn)
658   ;;(require 'ecasound)
659   ;;(require 'emacs-wiki)
660   (require 'bibtex)
661   (require 'post)
662   ;;(require 'fixme)
663   ; (require 'google-weather)
664   ; (require 'org-google-weather)
665   ; (setq-default org-google-weather-format "%i %c, [%l,%h] %s %C")
666   
667   (global-set-key "\C-xp" 'server-edit)
668
669   (setq-default auto-mode-alist (cons '("\.wml$" . 
670                     (lambda () (html-mode) (auto-fill-mode)))
671                   auto-mode-alist))
672
673
674   ; use markdown mode for mdwn files
675   (add-to-list 'auto-mode-alist '("\\.mdwn$" . markdown-mode))
676   (add-to-list 'auto-mode-alist '("\\.md$" . markdown-mode))
677
678
679   ;; tramp configuration
680   (setq tramp-use-ssh-controlmaster-options nil)
681
682   ; mail configuration
683   (add-to-list 'auto-mode-alist '("muttng-[a-z0-9]+-[0-9]+-" . message-mode))
684   (add-to-list 'auto-mode-alist '("muttngrc" . muttrc-mode))
685
686   (add-to-list 'auto-mode-alist '("mutt-[a-z0-9]+-[0-9]+-" . message-mode))
687   (add-to-list 'auto-mode-alist '("muttrc" . muttrc-mode))
688   (defun my-message-mode-settings ()
689     (font-lock-add-keywords nil
690                             '(("^[ \t]*>[ \t]*>[ \t]*>.*$"
691                                (0 'message-multiply-quoted-text-face))
692                               ("^[ \t]*>[ \t]*>.*$"
693                                (0 'message-double-quoted-text-face))))
694     (local-set-key (kbd "C-c C-a") 'my-post-attach-file)
695     )
696   (add-hook 'message-mode-hook 'my-message-mode-settings)
697
698   (defun my-post-attach-file ()
699     "Prompt for an attachment."
700     (interactive)
701     (let ((file (read-file-name "Attach file: " nil nil t nil))
702           (description (string-read "Description: ")))
703       (my-header-attach-file file description)))
704
705   (symbol-function 'my-post-attach-file)
706
707   (defun my-header-attach-file (file description)
708     "Attach a FILE to the current message (works with Mutt).
709   Argument DESCRIPTION MIME description."
710     (interactive "fAttach file: \nsDescription: ")
711     (when (> (length file) 0)
712       (save-excursion
713         (save-match-data
714           (save-restriction
715             (widen)
716             (goto-char (point-min))
717             (search-forward-regexp "^$")
718             (insert (concat "Attach: " (replace-regexp-in-string "\\([[:space:]\\]\\)" "\\\\\\1" (file-truename file)) " "
719                             description "\n"))
720             (message (concat "Attached '" file "'."))
721             (setq post-has-attachment t))))))
722
723
724
725   (setq mail-yank-prefix "> ")
726
727   (global-unset-key "\M-g")
728   (global-set-key "\M-g" 'goto-line)
729
730   ;; self-insert-command hack.
731   ;;   Without this, "if<SP>" expands to
732   ;;   if ( -!-) {
733   ;;   }
734   ;;   which really should be,
735   ;;   if (-!-) {
736   ;;   }
737
738
739
740   ;(load-library "php-mode")
741
742   (setq-default c-indent-level 4)
743   (setq-default c-brace-imaginary-offset 0)
744   (setq-default c-brace-offset -4)
745   (setq-default c-argdecl-indent 4)
746   (setq-default c-label-offset -4)
747   (setq-default c-continued-statement-offset 4)
748   ; tabs are annoying
749   (setq-default indent-tabs-mode nil)
750   (setq-default tab-width 4)
751
752
753   ;; (autoload 'php-mode "php-mode" "PHP editing mode" t)
754   ;; (add-to-list 'auto-mode-alist '("\\.php3?\\'" . php-mode))
755   ;; (add-to-list 'auto-mode-alist '("\\.phtml?\\'" . php-mode))
756   ;; (add-to-list 'auto-mode-alist '("\\.php?\\'" . php-mode))
757   ;; (add-to-list 'auto-mode-alist '("\\.php4?\\'" . php-mode))
758
759
760   (defun insert-date ()
761     "Insert date at point."
762     (interactive)
763     (insert (format-time-string "%A, %B %e, %Y %k:%M:%S %Z")))
764   (global-set-key "\C-[d" 'insert-date)
765
766   (defun unfill-paragraph (arg)
767     "Pull this whole paragraph up onto one line."
768     (interactive "*p")
769     (let ((fill-column 10000))
770       (fill-paragraph arg))
771     )
772
773   (column-number-mode t)
774
775   (server-start)
776
777   ; (require 'mode-compile)
778
779   (defadvice server-process-filter (after post-mode-message first activate)
780     "If the buffer is in post mode, overwrite the server-edit
781       message with a post-save-current-buffer-and-exit message."
782     (if (eq major-mode 'post-mode)
783         (message
784          (substitute-command-keys "Type \\[describe-mode] for help composing; \\[post-save-current-buffer-and-exit] when done."))))
785                       ; This is also needed to see the magic message.  Set to a higher
786                       ; number if you have a faster computer or read slower than me.
787   '(font-lock-verbose 1000)
788   ;(setq-default server-temp-file-regexp "mutt\(-\|ng-\)")
789   ; (add-hook 'server-switch-hook 
790   ;     (function (lambda()
791   ;             (cond ((string-match "Post" mode-name)
792   ;                (post-goto-body)))
793   ;             set-buffer-file-coding-system 'utf-8
794   ;             )))
795   ; 
796
797   (add-hook 'post-mode-hook
798         (auto-fill-mode nil)
799         )
800   ; abbrev mode settings
801   ; load abbreviations from 
802   (setq abbrev-file-name       
803         "~/.emacs_abbrev_def")
804
805   ; read the abbrev file if it exists
806   (if (file-exists-p abbrev-file-name)
807       (quietly-read-abbrev-file))
808
809   ; for now, use abbrev mode everywhere
810   (setq default-abbrev-mode t)
811
812
813   (defun insert-function-documentation ()
814     "Insert function documentation"
815     (interactive)
816     (insert-file-contents "/home/don/lib/templates/perl_function_documentation" nil))
817   (global-set-key "\M-f" 'insert-function-documentation)
818
819   (eval-after-load "lilypond-mode" 
820     '(progn
821        (load-library "lyqi-mode")
822        (define-key LilyPond-mode-map "\C-cq" 'lyqi-mode)))
823
824   (autoload 'spamassassin-mode "spamassassin-mode" nil t)
825
826   (desktop-load-default)
827   (desktop-read)
828   '(icomplete-mode on)
829   (custom-set-faces
830    ;; custom-set-faces was added by Custom.
831    ;; If you edit it by hand, you could mess it up, so be careful.
832    ;; Your init file should contain only one such instance.
833    ;; If there is more than one, they won't work right.
834    '(menu ((((type x-toolkit)) (:background "black" :foreground "grey90")))))
835
836
837   (put 'upcase-region 'disabled nil)
838   (put 'downcase-region 'disabled nil)
839   (put 'narrow-to-region 'disabled nil)
840
841   ; (defun turn-on-flyspell ()
842   ;    "Force flyspell-mode on using a positive arg.  For use in hooks."
843   ;    (interactive)
844   ;    (flyspell-mode 1))
845
846
847    ; Outline-minor-mode key map
848    (define-prefix-command 'cm-map nil "Outline-")
849    ; HIDE
850    (define-key cm-map "q" 'hide-sublevels)    ; Hide everything but the top-level headings
851    (define-key cm-map "t" 'hide-body)         ; Hide everything but headings (all body lines)
852    (define-key cm-map "o" 'hide-other)        ; Hide other branches
853    (define-key cm-map "c" 'hide-entry)        ; Hide this entry's body
854    (define-key cm-map "l" 'hide-leaves)       ; Hide body lines in this entry and sub-entries
855    (define-key cm-map "d" 'hide-subtree)      ; Hide everything in this entry and sub-entries
856    ; SHOW
857    (define-key cm-map "a" 'show-all)          ; Show (expand) everything
858    (define-key cm-map "e" 'show-entry)        ; Show this heading's body
859    (define-key cm-map "i" 'show-children)     ; Show this heading's immediate child sub-headings
860    (define-key cm-map "k" 'show-branches)     ; Show all sub-headings under this heading
861    (define-key cm-map "s" 'show-subtree)      ; Show (expand) everything in this heading & below
862    ; MOVE
863    (define-key cm-map "u" 'outline-up-heading)                ; Up
864    (define-key cm-map "n" 'outline-next-visible-heading)      ; Next
865    (define-key cm-map "p" 'outline-previous-visible-heading)  ; Previous
866    (define-key cm-map "f" 'outline-forward-same-level)        ; Forward - same level
867    (define-key cm-map "b" 'outline-backward-same-level)       ; Backward - same level
868    (global-set-key "\M-o" cm-map)
869
870
871   ; debian stuff
872   (setq-default debian-changelog-mailing-address "don@debian.org")
873   (setq-default debian-changelog-full-name "Don Armstrong")
874
875   ; ediff configuration
876   ; don't use the multi-window configuration
877   (setq ediff-window-setup-function 'ediff-setup-windows-plain)
878
879   ; use iedit
880   (require 'iedit)
881   (define-key global-map (kbd "C-;") 'iedit-mode)
882   (global-set-key  (kbd "C-;") 'iedit-mode)
883
884   ; fix up css mode to not be silly
885   ; from http://www.stokebloke.com/wordpress/2008/03/21/css-mode-indent-buffer-fix/
886   (setq cssm-indent-level 4)
887   (setq cssm-newline-before-closing-bracket t)
888   (setq cssm-indent-function #'cssm-c-style-indenter)
889   (setq cssm-mirror-mode nil)
890
891   (require 'multi-web-mode)
892   (setq mweb-default-major-mode 'html-mode)
893   (setq mweb-tags '((php-mode "<\\?php\\|<\\? \\|<\\?=" "\\?>")
894                     (js-mode "<script +\\(type=\"text/javascript\"\\|language=\"javascript\"\\)[^>]*>" "</script>")
895                     (css-mode "<style +type=\"text/css\"[^>]*>" "</style>")))
896   (setq mweb-filename-extensions '("php" "htm" "html" "ctp" "phtml" "php4" "php5"))
897   (multi-web-global-mode 1)
898
899   ;;; alias the new `flymake-report-status-slim' to
900   ;;; `flymake-report-status'
901   (defalias 'flymake-report-status 'flymake-report-status-slim)
902   (defun flymake-report-status-slim (e-w &optional status)
903     "Show \"slim\" flymake status in mode line."
904     (when e-w
905       (setq flymake-mode-line-e-w e-w))
906     (when status
907       (setq flymake-mode-line-status status))
908     (let* ((mode-line " Φ"))
909       (when (> (length flymake-mode-line-e-w) 0)
910         (setq mode-line (concat mode-line ":" flymake-mode-line-e-w)))
911       (setq mode-line (concat mode-line flymake-mode-line-status))
912       (setq flymake-mode-line mode-line)
913       (force-mode-line-update)))
914
915   ; load sql-indent when sql is loaded
916   (eval-after-load "sql"
917     '(load-library "sql-indent"))
918
919   ; fix up tmux xterm keys
920   ; stolen from http://unix.stackexchange.com/questions/24414/shift-arrow-not-working-in-emacs-within-tmux
921   (defun fix-up-tmux-keys ()
922       "Fix up tmux xterm keys"
923       (if (getenv "TMUX")
924           (progn
925             (let ((x 2) (tkey ""))
926               (while (<= x 8)
927                 ;; shift
928                 (if (= x 2)
929                     (setq tkey "S-"))
930                 ;; alt
931                 (if (= x 3)
932                     (setq tkey "M-"))
933                 ;; alt + shift
934                 (if (= x 4)
935                     (setq tkey "M-S-"))
936                 ;; ctrl
937                 (if (= x 5)
938                     (setq tkey "C-"))
939                 ;; ctrl + shift
940                 (if (= x 6)
941                     (setq tkey "C-S-"))
942                 ;; ctrl + alt
943                 (if (= x 7)
944                     (setq tkey "C-M-"))
945                 ;; ctrl + alt + shift
946                 (if (= x 8)
947                     (setq tkey "C-M-S-"))
948
949                 ;; arrows
950                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d A" x)) (kbd (format "%s<up>" tkey)))
951                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d B" x)) (kbd (format "%s<down>" tkey)))
952                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d C" x)) (kbd (format "%s<right>" tkey)))
953                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d D" x)) (kbd (format "%s<left>" tkey)))
954                 ;; home
955                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d H" x)) (kbd (format "%s<home>" tkey)))
956                 ;; end
957                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d F" x)) (kbd (format "%s<end>" tkey)))
958                 ;; page up
959                 (define-key key-translation-map (kbd (format "M-[ 5 ; %d ~" x)) (kbd (format "%s<prior>" tkey)))
960                 ;; page down
961                 (define-key key-translation-map (kbd (format "M-[ 6 ; %d ~" x)) (kbd (format "%s<next>" tkey)))
962                 ;; insert
963                 (define-key key-translation-map (kbd (format "M-[ 2 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
964                 ;; delete
965                 (define-key key-translation-map (kbd (format "M-[ 3 ; %d ~" x)) (kbd (format "%s<delete>" tkey)))
966                 ;; f1
967                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d P" x)) (kbd (format "%s<f1>" tkey)))
968                 ;; f2
969                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d Q" x)) (kbd (format "%s<f2>" tkey)))
970                 ;; f3
971                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d R" x)) (kbd (format "%s<f3>" tkey)))
972                 ;; f4
973                 (define-key key-translation-map (kbd (format "M-[ 1 ; %d S" x)) (kbd (format "%s<f4>" tkey)))
974                 ;; f5
975                 (define-key key-translation-map (kbd (format "M-[ 15 ; %d ~" x)) (kbd (format "%s<f5>" tkey)))
976                 ;; f6
977                 (define-key key-translation-map (kbd (format "M-[ 17 ; %d ~" x)) (kbd (format "%s<f6>" tkey)))
978                 ;; f7
979                 (define-key key-translation-map (kbd (format "M-[ 18 ; %d ~" x)) (kbd (format "%s<f7>" tkey)))
980                 ;; f8
981                 (define-key key-translation-map (kbd (format "M-[ 19 ; %d ~" x)) (kbd (format "%s<f8>" tkey)))
982                 ;; f9
983                 (define-key key-translation-map (kbd (format "M-[ 20 ; %d ~" x)) (kbd (format "%s<f9>" tkey)))
984                 ;; f10
985                 (define-key key-translation-map (kbd (format "M-[ 21 ; %d ~" x)) (kbd (format "%s<f10>" tkey)))
986                 ;; f11
987                 (define-key key-translation-map (kbd (format "M-[ 23 ; %d ~" x)) (kbd (format "%s<f11>" tkey)))
988                 ;; f12
989                 (define-key key-translation-map (kbd (format "M-[ 24 ; %d ~" x)) (kbd (format "%s<f12>" tkey)))
990                 ;; f13
991                 (define-key key-translation-map (kbd (format "M-[ 25 ; %d ~" x)) (kbd (format "%s<f13>" tkey)))
992                 ;; f14
993                 (define-key key-translation-map (kbd (format "M-[ 26 ; %d ~" x)) (kbd (format "%s<f14>" tkey)))
994                 ;; f15
995                 (define-key key-translation-map (kbd (format "M-[ 28 ; %d ~" x)) (kbd (format "%s<f15>" tkey)))
996                 ;; f16
997                 (define-key key-translation-map (kbd (format "M-[ 29 ; %d ~" x)) (kbd (format "%s<f16>" tkey)))
998                 ;; f17
999                 (define-key key-translation-map (kbd (format "M-[ 31 ; %d ~" x)) (kbd (format "%s<f17>" tkey)))
1000                 ;; f18
1001                 (define-key key-translation-map (kbd (format "M-[ 32 ; %d ~" x)) (kbd (format "%s<f18>" tkey)))
1002                 ;; f19
1003                 (define-key key-translation-map (kbd (format "M-[ 33 ; %d ~" x)) (kbd (format "%s<f19>" tkey)))
1004                 ;; f20
1005                 (define-key key-translation-map (kbd (format "M-[ 34 ; %d ~" x)) (kbd (format "%s<f20>" tkey)))
1006
1007                 (setq x (+ x 1))
1008                 ))
1009             )
1010         )
1011       )
1012   ; (add-hook 'tty-setup-hook 'fix-up-tmux-keys)
1013
1014   ; procmailmode configuration
1015   (load "procmail_mode")
1016
1017   (load "mode-line-cleaner")
1018
1019   (defadvice ask-user-about-supersession-threat (around ask-user-about-supersession-threat-if-necessary)
1020     "Call ask-user-about-supersession-threat only if the buffer is actually obsolete."
1021     (if (or (buffer-modified-p)
1022             (verify-visited-file-modtime)
1023             (< (* 8 1024 1024) (buffer-size))
1024             (/= 0 (call-process-region 1 (+ 1 (buffer-size)) "diff" nil nil nil "-q" (buffer-file-name) "-")))
1025         ad-do-it
1026       (clear-visited-file-modtime)
1027       (not-modified)))
1028   (ad-activate 'ask-user-about-supersession-threat)
1029
1030   ; apparently things like to step on C-;, so we'll use a hack from
1031   ; http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 to fix this
1032
1033   (defvar my-keys-minor-mode-map (make-keymap) "my-keys-minor-mode keymap.")
1034
1035   ; use iedit everywhere
1036   (define-key my-keys-minor-mode-map (kbd "C-;") 'iedit-mode)
1037
1038   (define-minor-mode my-keys-minor-mode
1039     "A minor mode so that my key settings override annoying major modes."
1040     t " my-keys" 'my-keys-minor-mode-map)
1041
1042   (my-keys-minor-mode 1)
1043   (defun my-minibuffer-setup-hook ()
1044     (my-keys-minor-mode 0))
1045
1046   (add-hook 'minibuffer-setup-hook 'my-minibuffer-setup-hook)
1047   (defadvice load (after give-my-keybindings-priority)
1048     "Try to ensure that my keybindings always have priority."
1049     (if (not (eq (car (car minor-mode-map-alist)) 'my-keys-minor-mode))
1050         (let ((mykeys (assq 'my-keys-minor-mode minor-mode-map-alist)))
1051           (assq-delete-all 'my-keys-minor-mode minor-mode-map-alist)
1052           (add-to-list 'minor-mode-map-alist mykeys))))
1053   (ad-activate 'load)
1054   (global-set-key "\M- " 'hippie-expand)
1055
1056 #+END_SRC
1057
1058 * END
1059 #+BEGIN_SRC emacs-lisp
1060   (provide 'don-configuration)
1061 #+END_SRC