dot/gnus.el, dot/gnus-local.el.distorted: Gnus Cloud silliness.
[profile] / el / dot-emacs.el
... / ...
CommitLineData
1;;; -*- mode: emacs-lisp; coding: utf-8 -*-
2;;;
3;;; Functions and macros for .emacs
4;;;
5;;; (c) 2004 Mark Wooding
6;;;
7
8;;;----- Licensing notice ---------------------------------------------------
9;;;
10;;; This program is free software; you can redistribute it and/or modify
11;;; it under the terms of the GNU General Public License as published by
12;;; the Free Software Foundation; either version 2 of the License, or
13;;; (at your option) any later version.
14;;;
15;;; This program is distributed in the hope that it will be useful,
16;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;;; GNU General Public License for more details.
19;;;
20;;; You should have received a copy of the GNU General Public License
21;;; along with this program; if not, write to the Free Software Foundation,
22;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24;;;--------------------------------------------------------------------------
25;;; Check command-line.
26
27(defgroup mdw nil
28 "Customization for mdw's Emacs configuration."
29 :prefix "mdw-")
30
31(defun mdw-check-command-line-switch (switch)
32 (let ((probe nil) (next command-line-args) (found nil))
33 (while next
34 (cond ((string= (car next) switch)
35 (setq found t)
36 (if probe (rplacd probe (cdr next))
37 (setq command-line-args (cdr next))))
38 (t
39 (setq probe next)))
40 (setq next (cdr next)))
41 found))
42
43(defvar mdw-fast-startup nil
44 "Whether .emacs should optimize for rapid startup.
45This may be at the expense of cool features.")
46(setq mdw-fast-startup
47 (mdw-check-command-line-switch "--mdw-fast-startup"))
48
49(defvar mdw-splashy-startup nil
50 "Whether to show a splash screen and related frippery.")
51(setq mdw-splashy-startup
52 (mdw-check-command-line-switch "--mdw-splashy-startup"))
53
54;;;--------------------------------------------------------------------------
55;;; Some general utilities.
56
57(eval-when-compile
58 (unless (fboundp 'make-regexp) (load "make-regexp"))
59 (require 'cl-lib))
60
61(defmacro mdw-regexps (&rest list)
62 "Turn a LIST of strings into a single regular expression at compile-time."
63 (declare (indent nil)
64 (debug 0))
65 `',(make-regexp (sort (cl-copy-list list) #'string<)))
66
67(defun mdw-wrong ()
68 "This is not the key sequence you're looking for."
69 (interactive)
70 (error "wrong button"))
71
72(defun mdw-emacs-version-p (major &optional minor)
73 "Return non-nil if the running Emacs is at least version MAJOR.MINOR."
74 (or (> emacs-major-version major)
75 (and (= emacs-major-version major)
76 (>= emacs-minor-version (or minor 0)))))
77
78(defun mdw-submode-p (mode parent)
79 "Return non-nil if MODE is indirectly derived from PARENT."
80 (let ((answer nil))
81 (while (cond ((eq mode parent) (setq answer t) nil)
82 (t (setq mode (get mode 'derived-mode-parent)))))
83 answer))
84
85;; Some error trapping.
86;;
87;; If individual bits of this file go tits-up, we don't particularly want
88;; the whole lot to stop right there and then, because it's bloody annoying.
89
90(eval-and-compile
91 (defmacro trap (&rest forms)
92 "Execute FORMS without allowing errors to propagate outside."
93 (declare (indent 0)
94 (debug t))
95 `(condition-case err
96 ,(if (cdr forms) (cons 'progn forms) (car forms))
97 (error (message "Error (trapped): %s in %s"
98 (error-message-string err)
99 ',forms)))))
100
101;; Configuration reading.
102
103(defvar mdw-config nil)
104(defun mdw-config (sym)
105 "Read the configuration variable named SYM."
106 (unless mdw-config
107 (setq mdw-config
108 (cl-flet ((replace (what with)
109 (goto-char (point-min))
110 (while (re-search-forward what nil t)
111 (replace-match with t))))
112 (with-temp-buffer
113 (insert-file-contents "~/.mdw.conf")
114 (replace "^[ \t]*\\(#.*\\)?\n" "")
115 (replace (concat "^[ \t]*"
116 "\\([-a-zA-Z0-9_.]*\\)"
117 "[ \t]*=[ \t]*"
118 "\\(.*[^ \t\n]\\)?"
119 "[ \t]**\\(\n\\|$\\)")
120 "(\\1 . \"\\2\")\n")
121 (car (read-from-string
122 (concat "(" (buffer-string) ")")))))))
123 (cdr (assq sym mdw-config)))
124
125;; Width configuration.
126
127(defcustom mdw-column-width
128 (string-to-number (or (mdw-config 'emacs-width) "77"))
129 "Width of Emacs columns."
130 :type 'integer)
131(defcustom mdw-text-width mdw-column-width
132 "Expected width of text within columns."
133 :type 'integer
134 :safe 'integerp)
135
136;; Local variables hacking.
137
138(defun run-local-vars-mode-hook ()
139 "Run a hook for the major-mode after local variables have been processed."
140 (run-hooks (intern (concat (symbol-name major-mode)
141 "-local-variables-hook"))))
142(add-hook 'hack-local-variables-hook 'run-local-vars-mode-hook)
143
144;; Set up the load path convincingly.
145
146(dolist (dir (append (and (boundp 'debian-emacs-flavor)
147 (list (concat "/usr/share/"
148 (symbol-name debian-emacs-flavor)
149 "/site-lisp")))))
150 (dolist (sub (directory-files dir t))
151 (when (and (file-accessible-directory-p sub)
152 (not (member sub load-path)))
153 (setq load-path (nconc load-path (list sub))))))
154
155;; Is an Emacs library available?
156
157(defun library-exists-p (name)
158 "Return non-nil if NAME is an available library.
159Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
160load path. The non-nil value is the filename we found for the
161library."
162 (let ((path load-path) elt (foundp nil))
163 (while (and path (not foundp))
164 (setq elt (car path))
165 (setq path (cdr path))
166 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
167 (and (file-exists-p file) file))
168 (let ((file (concat elt "/" name ".el")))
169 (and (file-exists-p file) file)))))
170 foundp))
171
172(defun maybe-autoload (symbol file &optional docstring interactivep type)
173 "Set an autoload if the file actually exists."
174 (and (library-exists-p file)
175 (autoload symbol file docstring interactivep type)))
176
177(defun mdw-kick-menu-bar (&optional frame)
178 "Regenerate FRAME's menu bar so it doesn't have empty menus."
179 (interactive)
180 (unless frame (setq frame (selected-frame)))
181 (let ((old (frame-parameter frame 'menu-bar-lines)))
182 (set-frame-parameter frame 'menu-bar-lines 0)
183 (set-frame-parameter frame 'menu-bar-lines old)))
184
185;; Page motion.
186
187(defun mdw-fixup-page-position ()
188 (unless (eq (char-before (point)) ?\f)
189 (forward-line 0)))
190
191(defadvice backward-page (after mdw-fixup compile activate)
192 (mdw-fixup-page-position))
193(defadvice forward-page (after mdw-fixup compile activate)
194 (mdw-fixup-page-position))
195
196;; Splitting windows.
197
198(unless (fboundp 'scroll-bar-columns)
199 (defun scroll-bar-columns (side)
200 (cond ((eq side 'left) 0)
201 (window-system 3)
202 (t 1))))
203(unless (fboundp 'fringe-columns)
204 (defun fringe-columns (side)
205 (cond ((not window-system) 0)
206 ((eq side 'left) 1)
207 (t 2))))
208
209(defun mdw-horizontal-window-overhead ()
210 "Computes the horizontal window overhead.
211This is the number of columns used by fringes, scroll bars and other such
212cruft."
213 (if (not window-system)
214 1
215 (let ((tot 0))
216 (dolist (what '(scroll-bar fringe))
217 (dolist (side '(left right))
218 (cl-incf tot
219 (funcall (intern (concat (symbol-name what) "-columns"))
220 side))))
221 tot)))
222
223(defun mdw-split-window-horizontally (&optional width)
224 "Split a window horizontally.
225Without a numeric argument, split the window approximately in
226half. With a numeric argument WIDTH, allocate WIDTH columns to
227the left-hand window (if positive) or -WIDTH columns to the
228right-hand window (if negative). Space for scroll bars and
229fringes is not taken out of the allowance for WIDTH, unlike
230\\[split-window-horizontally]."
231 (interactive "P")
232 (split-window-horizontally
233 (cond ((null width) nil)
234 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
235 ((< width 0) width))))
236
237(defun mdw-preferred-column-width ()
238 "Return the preferred column width."
239 (if (and window-system (mdw-emacs-version-p 22)) mdw-column-width
240 (1+ mdw-column-width)))
241
242(defun mdw-divvy-window (&optional width)
243 "Split a wide window into appropriate widths."
244 (interactive "P")
245 (setq width (if width (prefix-numeric-value width)
246 (mdw-preferred-column-width)))
247 (let* ((win (selected-window))
248 (sb-width (mdw-horizontal-window-overhead))
249 (c (/ (+ (window-width) sb-width)
250 (+ width sb-width))))
251 (while (> c 1)
252 (setq c (1- c))
253 (split-window-horizontally (+ width sb-width))
254 (other-window 1))
255 (select-window win)))
256
257(defun mdw-frame-width-quantized-p (frame-width column-width)
258 "Return whether the FRAME-WIDTH was chosen specifically for COLUMN-WIDTH."
259 (let ((sb-width (mdw-horizontal-window-overhead)))
260 (zerop (mod (+ frame-width sb-width)
261 (+ column-width sb-width)))))
262
263(defun mdw-frame-width-for-columns (columns width)
264 "Return the preferred width for a frame with so many COLUMNS of WIDTH."
265 (let ((sb-width (mdw-horizontal-window-overhead)))
266 (- (* columns (+ width sb-width))
267 sb-width)))
268
269(defun mdw-set-frame-width (columns &optional width)
270 "Set the current frame to be the correct width for COLUMNS columns.
271
272If WIDTH is non-nil, then it provides the width for the new columns. (This
273can be set interactively with a prefix argument.)"
274 (interactive "nColumns:
275P")
276 (setq width (if width (prefix-numeric-value width)
277 (mdw-preferred-column-width)))
278 (set-frame-width (selected-frame)
279 (mdw-frame-width-for-columns columns width))
280 (mdw-divvy-window width))
281
282(defcustom mdw-frame-width-fudge
283 (cond ((<= emacs-major-version 20) 1)
284 ((= emacs-major-version 26) 3)
285 (t 0))
286 "The number of extra columns to add to the desired frame width.
287
288This is sadly necessary because Emacs 26 is broken in this regard."
289 :type 'integer)
290
291(defcustom mdw-frame-colour-alist
292 '((black . ("#000000" . "#ffffff"))
293 (red . ("#2a0000" . "#ffffff"))
294 (green . ("#002a00" . "#ffffff"))
295 (blue . ("#00002a" . "#ffffff")))
296 "Alist mapping symbol names to (FOREGROUND . BACKGROUND) colour pairs."
297 :type '(alist :key-type symbol :value-type (cons color color)))
298
299(defun mdw-set-frame-colour (colour &optional frame)
300 (interactive "xColour name or (FOREGROUND . BACKGROUND) pair:
301")
302 (when (and colour (symbolp colour))
303 (let ((entry (assq colour mdw-frame-colour-alist)))
304 (unless entry (error "Unknown colour `%s'" colour))
305 (setf colour (cdr entry))))
306 (set-frame-parameter frame 'background-color (car colour))
307 (set-frame-parameter frame 'foreground-color (cdr colour)))
308
309;; Window configuration switching.
310
311(defvar mdw-current-window-configuration nil
312 "The current window configuration register name, or `nil'.")
313
314(defun mdw-switch-window-configuration (register &optional no-save)
315 "Switch make REGISTER be the new current window configuration.
316If a current window configuration register is established, and
317NO-SAVE is nil, then save the current window configuration to
318that register first.
319
320Signal an error if the new register contains something other than
321a window configuration. If the register is unset then save the
322current window configuration to it immediately.
323
324With one or three C-u, or an odd numeric prefix argument, set
325NO-SAVE, so the previous window configuration register is left
326unchanged.
327
328With two or three C-u, or a prefix argument which is an odd
329multiple of 2, just clear the record of the current window
330configuration register, so that the next switch doesn't save the
331prevailing configuration."
332 (interactive
333 (let ((arg current-prefix-arg))
334 (list (if (or (and (consp arg) (= (car arg) 16) (= (car arg) 64))
335 (and (integerp arg) (not (zerop (logand arg 2)))))
336 nil
337 (register-read-with-preview "Switch to window configuration: "))
338 (or (and (consp arg) (= (car arg) 4) (= (car arg) 64))
339 (and (integerp arg) (not (zerop (logand arg 1))))))))
340
341 (let ((previous mdw-current-window-configuration)
342 (current-windows (list (current-window-configuration)
343 (point-marker)))
344 (register-value (and register (get-register register))))
345 (when (and mdw-current-window-configuration (not no-save))
346 (set-register mdw-current-window-configuration current-windows))
347 (cond ((null register)
348 (setq mdw-current-window-configuration nil)
349 (if previous
350 (message "Left window configuration `%c'." previous)
351 (message "Nothing to do!")))
352 ((not (or (null register-value)
353 (and (consp register-value)
354 (window-configuration-p (car register-value))
355 (integer-or-marker-p (cadr register-value))
356 (null (cl-caddr register-value)))))
357 (error "Register `%c' is not a window configuration" register))
358 (t
359 (cond ((null register-value)
360 (set-register register current-windows)
361 (message "Started new window configuration `%c'."
362 register))
363 (t
364 (set-window-configuration (car register-value))
365 (goto-char (cadr register-value))
366 (message "Switched to window configuration `%c'."
367 register)))
368 (setq mdw-current-window-configuration register)))))
369
370;; Don't raise windows unless I say so.
371
372(defcustom mdw-inhibit-raise-frame nil
373 "Whether `raise-frame' should do nothing when the frame is mapped."
374 :type 'boolean)
375
376(defadvice raise-frame
377 (around mdw-inhibit (&optional frame) activate compile)
378 "Don't actually do anything if `mdw-inhibit-raise-frame' is true, and the
379frame is actually mapped on the screen."
380 (if mdw-inhibit-raise-frame
381 (make-frame-visible frame)
382 ad-do-it))
383
384(defmacro mdw-advise-to-inhibit-raise-frame (function)
385 "Advise the FUNCTION not to raise frames, even if it wants to."
386 `(defadvice ,function
387 (around mdw-inhibit-raise (&rest hunoz) activate compile)
388 "Don't raise the window unless you have to."
389 (let ((mdw-inhibit-raise-frame t))
390 ad-do-it)))
391
392(mdw-advise-to-inhibit-raise-frame select-frame-set-input-focus)
393(mdw-advise-to-inhibit-raise-frame appt-disp-window)
394(mdw-advise-to-inhibit-raise-frame mouse-select-window)
395
396;; Bug fix for markdown-mode, which breaks point positioning during
397;; `query-replace'.
398(defadvice markdown-check-change-for-wiki-link
399 (around mdw-save-match activate compile)
400 "Save match data around the `markdown-mode' `after-change-functions' hook."
401 (save-match-data ad-do-it))
402
403;; Bug fix for `bbdb-canonicalize-address': on Emacs 24, `run-hook-with-args'
404;; always returns nil, with the result that all email addresses are lost.
405;; Replace the function entirely.
406(defadvice bbdb-canonicalize-address
407 (around mdw-bug-fix activate compile)
408 "Don't use `run-hook-with-args', because that doesn't work."
409 (let ((net (ad-get-arg 0)))
410
411 ;; Make sure this is a proper hook list.
412 (if (functionp bbdb-canonicalize-net-hook)
413 (setq bbdb-canonicalize-net-hook (list bbdb-canonicalize-net-hook)))
414
415 ;; Iterate over the hooks until things converge.
416 (let ((donep nil))
417 (while (not donep)
418 (let (next (changep nil)
419 hook (hooks bbdb-canonicalize-net-hook))
420 (while hooks
421 (setq hook (pop hooks))
422 (setq next (funcall hook net))
423 (if (not (equal next net))
424 (setq changep t
425 net next)))
426 (setq donep (not changep)))))
427 (setq ad-return-value net)))
428
429;; Transient mark mode hacks.
430
431(defadvice exchange-point-and-mark
432 (around mdw-highlight (&optional arg) activate compile)
433 "Maybe don't actually exchange point and mark.
434If `transient-mark-mode' is on and the mark is inactive, then
435just activate it. A non-trivial prefix argument will force the
436usual behaviour. A trivial prefix argument (i.e., just C-u) will
437activate the mark and temporarily enable `transient-mark-mode' if
438it's currently off."
439 (cond ((or mark-active
440 (and (not transient-mark-mode) (not arg))
441 (and arg (or (not (consp arg))
442 (not (= (car arg) 4)))))
443 ad-do-it)
444 (t
445 (or transient-mark-mode (setq transient-mark-mode 'only))
446 (set-mark (mark t)))))
447
448;; Functions for sexp diary entries.
449
450(defvar mdw-diary-for-org-mode-p nil
451 "Display diary along with the agenda?")
452
453(defun mdw-not-org-mode (form)
454 "As FORM, but not in Org mode agenda."
455 (and (not mdw-diary-for-org-mode-p)
456 (eval form)))
457
458(defun mdw-weekday (l)
459 "Return non-nil if `date' falls on one of the days of the week in L.
460L is a list of day numbers (from 0 to 6 for Sunday through to
461Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
462the date stored in `date' falls on a listed day, then the
463function returns non-nil."
464 (let ((d (calendar-day-of-week date)))
465 (or (memq d l)
466 (memq (nth d '(sunday monday tuesday wednesday
467 thursday friday saturday)) l))))
468
469(defun mdw-discordian-date (date)
470 "Return the Discordian calendar date corresponding to DATE.
471
472The return value is (YOLD . st-tibs-day) or (YOLD SEASON DAYNUM DOW).
473
474The original is by David Pearson. I modified it to produce date components
475as output rather than a string."
476 (let* ((days ["Sweetmorn" "Boomtime" "Pungenday"
477 "Prickle-Prickle" "Setting Orange"])
478 (months ["Chaos" "Discord" "Confusion"
479 "Bureaucracy" "Aftermath"])
480 (day-count [0 31 59 90 120 151 181 212 243 273 304 334])
481 (year (- (calendar-extract-year date) 1900))
482 (month (1- (calendar-extract-month date)))
483 (day (1- (calendar-extract-day date)))
484 (julian (+ (aref day-count month) day))
485 (dyear (+ year 3066)))
486 (if (and (= month 1) (= day 28))
487 (cons dyear 'st-tibs-day)
488 (list dyear
489 (aref months (floor (/ julian 73)))
490 (1+ (mod julian 73))
491 (aref days (mod julian 5))))))
492
493(defun mdw-diary-discordian-date ()
494 "Convert the date in `date' to a string giving the Discordian date."
495 (let* ((ddate (mdw-discordian-date date))
496 (tail (format "in the YOLD %d" (car ddate))))
497 (if (eq (cdr ddate) 'st-tibs-day)
498 (format "St Tib's Day %s" tail)
499 (let ((season (cadr ddate))
500 (daynum (cl-caddr ddate))
501 (dayname (cl-cadddr ddate)))
502 (format "%s, the %d%s day of %s %s"
503 dayname
504 daynum
505 (let ((ldig (mod daynum 10)))
506 (cond ((= ldig 1) "st")
507 ((= ldig 2) "nd")
508 ((= ldig 3) "rd")
509 (t "th")))
510 season
511 tail)))))
512
513(defun mdw-todo (&optional when)
514 "Return non-nil today, or on WHEN, whichever is later."
515 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
516 (d (calendar-absolute-from-gregorian date)))
517 (if when
518 (setq w (max w (calendar-absolute-from-gregorian
519 (cond
520 ((not european-calendar-style)
521 when)
522 ((> (car when) 100)
523 (list (nth 1 when)
524 (nth 2 when)
525 (nth 0 when)))
526 (t
527 (list (nth 1 when)
528 (nth 0 when)
529 (nth 2 when))))))))
530 (eq w d)))
531
532(defadvice org-agenda-list (around mdw-preserve-links activate)
533 (let ((mdw-diary-for-org-mode-p t))
534 ad-do-it))
535
536(defcustom diary-time-regexp nil
537 "Regexp matching times in the diary buffer."
538 :type 'regexp)
539
540(defadvice diary-add-to-list (before mdw-trim-leading-space compile activate)
541 "Trim leading space from the diary entry string."
542 (save-match-data
543 (let ((str (ad-get-arg 1))
544 (done nil) old)
545 (while (not done)
546 (setq old str)
547 (setq str (cond ((null str) nil)
548 ((string-match "\\(^\\|\n\\)[ \t]+" str)
549 (replace-match "\\1" nil nil str))
550 ((and mdw-diary-for-org-mode-p
551 (string-match (concat
552 "\\(^\\|\n\\)"
553 "\\(" diary-time-regexp
554 "\\(-" diary-time-regexp "\\)?"
555 "\\)"
556 "\\(\t[ \t]*\\| [ \t]+\\)")
557 str))
558 (replace-match "\\1\\2 " nil nil str))
559 ((and (not mdw-diary-for-org-mode-p)
560 (string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]"
561 str))
562 (replace-match "\\1" nil nil str))
563 (t str)))
564 (if (equal str old) (setq done t)))
565 (ad-set-arg 1 str))))
566
567(defadvice org-bbdb-anniversaries (after mdw-fixup-list compile activate)
568 "Return a string rather than a list."
569 (with-temp-buffer
570 (let ((anyp nil))
571 (dolist (e (let ((ee ad-return-value))
572 (if (atom ee) (list ee) ee)))
573 (when e
574 (when anyp (insert ?\n))
575 (insert e)
576 (setq anyp t)))
577 (setq ad-return-value
578 (and anyp (buffer-string))))))
579
580;; Fighting with Org-mode's evil key maps.
581
582(defcustom mdw-evil-keymap-keys
583 '(([S-up] . [?\C-c up])
584 ([S-down] . [?\C-c down])
585 ([S-left] . [?\C-c left])
586 ([S-right] . [?\C-c right])
587 (([M-up] [?\e up]) . [C-up])
588 (([M-down] [?\e down]) . [C-down])
589 (([M-left] [?\e left]) . [C-left])
590 (([M-right] [?\e right]) . [C-right]))
591 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
592The value is an alist mapping evil keys (as a list, or singleton)
593to good keys (in the same form)."
594 :type '(alist :key-type (choice key-sequence (repeat key-sequence))
595 :value-type key-sequence))
596
597(defun mdw-clobber-evil-keymap (keymap)
598 "Replace evil key bindings in the KEYMAP.
599Evil key bindings are defined in `mdw-evil-keymap-keys'."
600 (dolist (entry mdw-evil-keymap-keys)
601 (let ((binding nil)
602 (keys (if (listp (car entry))
603 (car entry)
604 (list (car entry))))
605 (replacements (if (listp (cdr entry))
606 (cdr entry)
607 (list (cdr entry)))))
608 (catch 'found
609 (dolist (key keys)
610 (setq binding (lookup-key keymap key))
611 (when binding
612 (throw 'found nil))))
613 (when binding
614 (dolist (key keys)
615 (define-key keymap key nil))
616 (dolist (key replacements)
617 (define-key keymap key binding))))))
618
619(defcustom mdw-org-latex-defs
620 '(("strayman"
621 "\\documentclass{strayman}
622\\usepackage[utf8]{inputenc}
623\\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
624\\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
625 ("\\section{%s}" . "\\section*{%s}")
626 ("\\subsection{%s}" . "\\subsection*{%s}")
627 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
628 ("\\paragraph{%s}" . "\\paragraph*{%s}")
629 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
630 "Additional LaTeX class definitions."
631 :type '(alist :key-type string
632 :value-type (list string
633 (alist :inline t
634 :key-type string
635 :value-type string))))
636
637(setq org-emphasis-regexp-components
638 '("- \t('\"{}" ; prematch
639 "- \t.,:!?;'\")}\\[" ; postmatch
640 " \t\r\n" ; /forbidden/ as border
641 "." ; body regexp
642 1)) ; maximum newlines
643
644(setq org-entities-user
645 ;; NAME LATEX MATHP HTML ASCII LATIN1 UTF8
646 '(("relax" "" nil "" "" "" "")))
647
648(eval-after-load "org-latex"
649 '(setq org-export-latex-classes
650 (append mdw-org-latex-defs org-export-latex-classes)))
651
652(eval-after-load "ox-latex"
653 '(setq org-latex-classes (append mdw-org-latex-defs org-latex-classes)
654 org-latex-caption-above nil
655 org-latex-default-packages-alist '(("AUTO" "inputenc" t)
656 ("T1" "fontenc" t)
657 ("" "fixltx2e" nil)
658 ("" "graphicx" t)
659 ("" "longtable" nil)
660 ("" "float" nil)
661 ("" "wrapfig" nil)
662 ("" "rotating" nil)
663 ("normalem" "ulem" t)
664 ("" "textcomp" t)
665 ("" "marvosym" t)
666 ("" "wasysym" t)
667 ("" "amssymb" t)
668 ("" "hyperref" nil)
669 "\\tolerance=1000")))
670
671(setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
672 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
673 org-export-docbook-xslt-stylesheet
674 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
675
676;; Glasses.
677
678(setq glasses-separator "-"
679 glasses-separate-parentheses-p nil
680 glasses-uncapitalize-p t)
681
682;; Some hacks to do with window placement.
683
684(defvar mdw-designated-window nil
685 "The window chosen by `mdw-designate-window', or nil.")
686
687(defun mdw-designated-window-display-buffer-function (buffer not-this-window)
688 "Display buffer function to use the designated window."
689 (unless mdw-designated-window (error "No designated window!"))
690 (prog1 mdw-designated-window
691 (with-selected-window mdw-designated-window (switch-to-buffer buffer))
692 (setq mdw-designated-window nil
693 display-buffer-function nil)))
694
695(defun mdw-display-buffer-in-designated-window (buffer alist)
696 "Display function to use the designated window."
697 (prog1 mdw-designated-window
698 (when mdw-designated-window
699 (with-selected-window mdw-designated-window
700 (switch-to-buffer buffer nil t)))
701 (setq mdw-designated-window nil)))
702
703(defun mdw-designate-window (cancel)
704 "Use the selected window for the next pop-up buffer.
705With a prefix argument, clear the designated window."
706 (interactive "P")
707 (let ((window (selected-window)))
708 (cond (cancel
709 (cond (mdw-designated-window
710 (setq mdw-designated-window nil)
711 (unless (mdw-emacs-version-p 24)
712 (setq display-buffer-function nil))
713 (message "Window designation cleared."))
714 (t
715 (message "No designated window active."))))
716 ((window-dedicated-p window)
717 (error "Window is dedicated to its buffer."))
718 (t
719 (setq mdw-designated-window window)
720 (unless (mdw-emacs-version-p 24)
721 (setq display-buffer-function
722 #'mdw-designated-window-display-buffer-function))
723 (message "Window designated.")))))
724
725(when (mdw-emacs-version-p 24)
726 (setq display-buffer-base-action
727 (let* ((action display-buffer-base-action)
728 (funcs (car action))
729 (alist (cdr action)))
730 (cons (cons 'mdw-display-buffer-in-designated-window funcs)
731 alist))))
732
733(defun mdw-clobber-other-windows-showing-buffer (buffer-or-name)
734 "Arrange that no windows on other frames are showing BUFFER-OR-NAME."
735 (interactive "bBuffer: ")
736 (let ((home-frame (selected-frame))
737 (buffer (get-buffer buffer-or-name))
738 (safe-buffer (get-buffer "*scratch*")))
739 (dolist (frame (frame-list))
740 (unless (eq frame home-frame)
741 (dolist (window (window-list frame))
742 (when (eq (window-buffer window) buffer)
743 (set-window-buffer window safe-buffer)))))))
744
745(defvar mdw-inhibit-walk-windows nil
746 "If non-nil, then `walk-windows' does nothing.
747This is used by advice on `switch-to-buffer-other-frame' to inhibit finding
748buffers in random frames.")
749
750(setq display-buffer--other-frame-action
751 '((display-buffer-reuse-window display-buffer-pop-up-frame)
752 (reusable-frames . nil)
753 (inhibit-same-window . t)))
754
755(defadvice walk-windows (around mdw-inhibit activate)
756 "If `mdw-inhibit-walk-windows' is non-nil, then do nothing."
757 (and (not mdw-inhibit-walk-windows)
758 ad-do-it))
759
760(defadvice switch-to-buffer-other-frame
761 (around mdw-always-new-frame activate)
762 "Always make a new frame.
763Even if an existing window in some random frame looks tempting."
764 (let ((mdw-inhibit-walk-windows t)) ad-do-it))
765
766(defadvice display-buffer (before mdw-inhibit-other-frames activate)
767 "Don't try to do anything fancy with other frames.
768Pretend they don't exist. They might be on other display devices."
769 (ad-set-arg 2 nil))
770
771(setq even-window-sizes nil
772 even-window-heights nil
773 display-buffer-reuse-frames nil)
774
775(defvar mdw-fallback-window-alist nil
776 "Alist mapping frames to fallback windows.")
777
778(defun mdw-cleanup-fallback-window-alist ()
779 "Remove entries for dead frames and windows from the fallback alist."
780 (let ((prev nil)
781 (cursor mdw-fallback-window-alist))
782 (while cursor
783 (let* ((assoc (car cursor))
784 (tail (cdr cursor)))
785 (cond ((and (frame-live-p (car assoc))
786 (window-live-p (cdr assoc)))
787 (setq prev cursor))
788 ((null prev)
789 (setq mdw-fallback-window-alist tail))
790 (t
791 (setcdr prev tail)))
792 (setq cursor tail)))))
793
794(defun mdw-set-fallback-window (cancel)
795 "Prefer the selected window for pop-up buffers in this frame.
796With a prefix argument, clear the fallback window."
797 (interactive "P")
798 (let* ((frame (selected-frame)) (window (selected-window))
799 (assoc (assq (selected-frame) mdw-fallback-window-alist)))
800 (cond (cancel
801 (cond (assoc
802 (setcdr assoc nil)
803 (message "Fallback window cleared."))
804 (t
805 (message "No fallback window active in this frame."))))
806 ((window-dedicated-p window)
807 (error "Window is dedicated to its buffer."))
808 (t
809 (if assoc (setcdr assoc window)
810 (push (cons frame window) mdw-fallback-window-alist))
811 (message "Fallback window set.")))
812 (mdw-cleanup-fallback-window-alist)))
813
814(defun mdw-last-window-in-frame-p (window)
815 "Return whether WINDOW is the last in its frame."
816 (catch 'done
817 (while window
818 (let ((next (window-next-sibling window)))
819 (while (and next (window-minibuffer-p next))
820 (setq next (window-next-sibling next)))
821 (if next (throw 'done nil)))
822 (setq window (window-parent window)))
823 t))
824
825(defun mdw-display-buffer-in-tolerable-window (buffer alist)
826 "Try finding a tolerable window in which to display BUFFER.
827Begone, foul DWIMmerlaik!
828
829This is all totally subject to arbitrary change in the future, but the
830emphasis is on predictability rather than crazy DWIMmery."
831 (let* ((selected (selected-window)) chosen
832 (fallback (assq (selected-frame) mdw-fallback-window-alist))
833 (full-height-p (window-full-height-p selected))
834 (full-width-p (window-full-width-p selected)))
835 (cond
836
837 ((and fallback (window-live-p (cdr fallback)))
838 ;; There's a fallback window set for this frame. Use it.
839
840 (setq chosen (cdr fallback)
841 selected nil)
842 (display-buffer-record-window 'window chosen buffer))
843
844 ((and full-height-p full-width-p)
845 ;; We're basically the only window in the frame. If we want to get
846 ;; anywhere, we'll have to split the window.
847
848 (let ((width (window-width selected))
849 (preferred-width (mdw-preferred-column-width)))
850 (if (and (>= width (mdw-frame-width-for-columns 2 preferred-width))
851 (mdw-frame-width-quantized-p width preferred-width))
852 (setq chosen (split-window-right preferred-width))
853 (setq chosen (split-window-below)))
854 (display-buffer-record-window 'window chosen buffer)))
855
856 ((mdw-last-window-in-frame-p selected)
857 ;; This is the last window in the frame. I don't think I want to
858 ;; clobber the first window, so rebound and clobber the previous one
859 ;; instead. (This obviously has the same effect if there are only two
860 ;; windows, but seems more useful if there are three.)
861
862 (setq chosen (previous-window selected 'never nil))
863 (display-buffer-record-window 'reuse chosen buffer))
864
865 (t
866 ;; There's another window in front of us. Let's use that one.
867 (setq chosen (next-window selected 'never nil)))
868 (display-buffer-record-window 'reuse chosen buffer))
869
870 (if (eq chosen selected)
871 (error "Failed to select a different window!"))
872
873 (when chosen
874 (with-selected-window chosen (switch-to-buffer buffer)))
875 chosen))
876
877;; Hack the display actions so that they do something sensible.
878(setq display-buffer-fallback-action
879 '((display-buffer--maybe-same-window
880 display-buffer-reuse-window
881 display-buffer-pop-up-window
882 mdw-display-buffer-in-tolerable-window)))
883
884;; Rename buffers along with files.
885
886(defvar mdw-inhibit-rename-buffer nil
887 "If non-nil, `rename-file' won't rename the buffer visiting the file.")
888
889(defmacro mdw-advise-to-inhibit-rename-buffer (function)
890 "Advise FUNCTION to set `mdw-inhibit-rename-buffer' while it runs.
891
892This will prevent `rename-file' from renaming the buffer."
893 `(defadvice ,function (around mdw-inhibit-rename-buffer compile activate)
894 "Don't rename the buffer when renaming the underlying file."
895 (let ((mdw-inhibit-rename-buffer t))
896 ad-do-it)))
897(mdw-advise-to-inhibit-rename-buffer recode-file-name)
898(mdw-advise-to-inhibit-rename-buffer set-visited-file-name)
899(mdw-advise-to-inhibit-rename-buffer backup-buffer)
900
901(defadvice rename-file (after mdw-rename-buffers (from to &optional forcep)
902 compile activate)
903 "If a buffer is visiting the file, rename it to match the new name.
904
905Don't do this if `mdw-inhibit-rename-buffer' is non-nil."
906 (unless mdw-inhibit-rename-buffer
907 (let ((buffer (get-file-buffer from)))
908 (when buffer
909 (let ((to (if (not (string= (file-name-nondirectory to) "")) to
910 (concat to (file-name-nondirectory from)))))
911 (with-current-buffer buffer
912 (set-visited-file-name to nil t)))))))
913
914;;;--------------------------------------------------------------------------
915;;; Improved compilation machinery.
916
917;; Uprated version of M-x compile.
918
919(setq compile-command
920 (let ((ncpu (with-temp-buffer
921 (insert-file-contents "/proc/cpuinfo")
922 (buffer-string)
923 (count-matches "^processor\\s-*:"))))
924 (format "nice make -j%d -k" (* 2 ncpu))))
925
926(defun mdw-compilation-buffer-name (mode)
927 (concat "*" (downcase mode) ": "
928 (abbreviate-file-name default-directory) "*"))
929(setq compilation-buffer-name-function 'mdw-compilation-buffer-name)
930
931(eval-after-load "compile"
932 '(progn
933 (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile)))
934
935(defadvice compile (around hack-environment compile activate)
936 "Hack the environment inherited by inferiors in the compilation."
937 (let ((process-environment (copy-tree process-environment)))
938 (setenv "LD_PRELOAD" nil)
939 ad-do-it))
940
941(defun mdw-compile (command &optional directory comint)
942 "Initiate a compilation COMMAND, maybe in a different DIRECTORY.
943The DIRECTORY may be nil to not change. If COMINT is t, then
944start an interactive compilation.
945
946Interactively, prompt for the command if the variable
947`compilation-read-command' is non-nil, or if requested through
948the prefix argument. Prompt for the directory, and run
949interactively, if requested through the prefix.
950
951Use a prefix of 4, 6, 12, or 14, or type C-u between one and three times, to
952force prompting for a directory.
953
954Use a prefix of 2, 6, 10, or 14, or type C-u three times, to force
955prompting for the command.
956
957Use a prefix of 8, 10, 12, or 14, or type C-u twice or three times,
958to force interactive compilation."
959 (interactive
960 (let* ((prefix (prefix-numeric-value current-prefix-arg))
961 (command (eval compile-command))
962 (dir (and (cl-plusp (logand prefix #x54))
963 (read-directory-name "Compile in directory: "))))
964 (list (if (or compilation-read-command
965 (cl-plusp (logand prefix #x42)))
966 (compilation-read-command command)
967 command)
968 dir
969 (cl-plusp (logand prefix #x58)))))
970 (let ((default-directory (or directory default-directory)))
971 (compile command comint)))
972
973;; Flymake support.
974
975(defun mdw-find-build-dir (build-file)
976 (catch 'found
977 (let* ((src-dir (file-name-as-directory (expand-file-name ".")))
978 (dir src-dir))
979 (cl-loop
980 (when (file-exists-p (concat dir build-file))
981 (throw 'found dir))
982 (let ((sub (expand-file-name (file-relative-name src-dir dir)
983 (concat dir "build/"))))
984 (catch 'give-up
985 (cl-loop
986 (when (file-exists-p (concat sub build-file))
987 (throw 'found sub))
988 (when (string= sub dir) (throw 'give-up nil))
989 (setq sub (file-name-directory (directory-file-name sub))))))
990 (when (string= dir
991 (setq dir (file-name-directory
992 (directory-file-name dir))))
993 (throw 'found nil))))))
994
995(defun mdw-flymake-make-init ()
996 (let ((build-dir (mdw-find-build-dir "Makefile")))
997 (and build-dir
998 (let ((tmp-src (flymake-init-create-temp-buffer-copy
999 #'flymake-create-temp-inplace)))
1000 (flymake-get-syntax-check-program-args
1001 tmp-src build-dir t t
1002 #'flymake-get-make-cmdline)))))
1003
1004(setq flymake-allowed-file-name-masks
1005 '(("\\.\\(?:[cC]\\|cc\\|cpp\\|cxx\\|c\\+\\+\\)\\'"
1006 mdw-flymake-make-init)
1007 ("\\.\\(?:[hH]\\|hh\\|hpp\\|hxx\\|h\\+\\+\\)\\'"
1008 mdw-flymake-master-make-init)
1009 ("\\.p[lm]" flymake-perl-init)))
1010
1011(setq flymake-mode-map
1012 (let ((map (if (boundp 'flymake-mode-map)
1013 flymake-mode-map
1014 (make-sparse-keymap))))
1015 (define-key map [?\C-c ?\C-f ?\C-p] 'flymake-goto-prev-error)
1016 (define-key map [?\C-c ?\C-f ?\C-n] 'flymake-goto-next-error)
1017 (define-key map [?\C-c ?\C-f ?\C-c] 'flymake-compile)
1018 (define-key map [?\C-c ?\C-f ?\C-k] 'flymake-stop-all-syntax-checks)
1019 (define-key map [?\C-c ?\C-f ?\C-e] 'flymake-popup-current-error-menu)
1020 map))
1021
1022;;;--------------------------------------------------------------------------
1023;;; Mail and news hacking.
1024
1025(define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
1026 "Major mode for editing news and mail messages from external programs.
1027Not much right now. Just support for doing MailCrypt stuff."
1028 :syntax-table nil
1029 :abbrev-table nil
1030 (run-hooks 'mail-setup-hook))
1031
1032(define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
1033
1034(add-hook 'mdwail-mode-hook
1035 (lambda ()
1036 (set-buffer-file-coding-system 'utf-8)
1037 (make-local-variable 'paragraph-separate)
1038 (make-local-variable 'paragraph-start)
1039 (setq paragraph-start
1040 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
1041 paragraph-start))
1042 (setq paragraph-separate
1043 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
1044 paragraph-separate))))
1045
1046;; How to encrypt in mdwmail.
1047
1048(defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
1049 (or start
1050 (setq start (save-excursion
1051 (goto-char (point-min))
1052 (or (search-forward "\n\n" nil t) (point-min)))))
1053 (or end
1054 (setq end (point-max)))
1055 (mc-encrypt-generic recip scm start end from sign))
1056
1057;; How to sign in mdwmail.
1058
1059(defun mdwmail-mc-sign (key scm start end uclr)
1060 (or start
1061 (setq start (save-excursion
1062 (goto-char (point-min))
1063 (or (search-forward "\n\n" nil t) (point-min)))))
1064 (or end
1065 (setq end (point-max)))
1066 (mc-sign-generic key scm start end uclr))
1067
1068;; Some signature mangling.
1069
1070(defun mdwmail-mangle-signature ()
1071 (save-excursion
1072 (goto-char (point-min))
1073 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
1074(add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
1075(add-hook 'message-setup-hook 'mdwmail-mangle-signature)
1076
1077;; Insert my login name into message-ids, so I can score replies.
1078
1079(defadvice message-unique-id (after mdw-user-name last activate compile)
1080 "Ensure that the user's name appears at the end of the message-id string,
1081so that it can be used for convenient filtering."
1082 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
1083
1084;; Tell my movemail hack where movemail is.
1085;;
1086;; This is needed to shup up warnings about LD_PRELOAD.
1087
1088(let ((path exec-path))
1089 (while path
1090 (let ((try (expand-file-name "movemail" (car path))))
1091 (if (file-executable-p try)
1092 (setenv "REAL_MOVEMAIL" try))
1093 (setq path (cdr path)))))
1094
1095;; AUTHINFO GENERIC kludge.
1096
1097(defcustom nntp-authinfo-generic nil
1098 "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'.
1099
1100Use this to arrange for per-server settings."
1101 :type '(choice (const :tag "Use `NNTPAUTH' environment variable" nil)
1102 string)
1103 :safe 'stringp)
1104
1105(defun nntp-open-authinfo-kludge (buffer)
1106 "Open a connection to SERVER using `authinfo-kludge'."
1107 (let ((proc (start-process "nntpd" buffer
1108 "env" (concat "NNTPAUTH="
1109 (or nntp-authinfo-generic
1110 (getenv "NNTPAUTH")
1111 (error "NNTPAUTH unset")))
1112 "authinfo-kludge" nntp-address)))
1113 (set-buffer buffer)
1114 (nntp-wait-for-string "^\r*200")
1115 (beginning-of-line)
1116 (delete-region (point-min) (point))
1117 proc))
1118
1119(eval-after-load "erc"
1120 '(load "~/.ercrc.el"))
1121
1122;; Heavy-duty Gnus patching.
1123
1124(defun mdw-nnimap-transform-headers ()
1125 (goto-char (point-min))
1126 (let (article lines size string)
1127 (cl-block nil
1128 (while (not (eobp))
1129 (while (not (looking-at "\\* [0-9]+ FETCH"))
1130 (delete-region (point) (progn (forward-line 1) (point)))
1131 (when (eobp)
1132 (cl-return)))
1133 (goto-char (match-end 0))
1134 ;; Unfold quoted {number} strings.
1135 (while (re-search-forward
1136 "[^]][ (]{\\([0-9]+\\)}\r?\n"
1137 (save-excursion
1138 ;; Start of the header section.
1139 (or (re-search-forward "] {[0-9]+}\r?\n" nil t)
1140 ;; Start of the next FETCH.
1141 (re-search-forward "\\* [0-9]+ FETCH" nil t)
1142 (point-max)))
1143 t)
1144 (setq size (string-to-number (match-string 1)))
1145 (delete-region (+ (match-beginning 0) 2) (point))
1146 (setq string (buffer-substring (point) (+ (point) size)))
1147 (delete-region (point) (+ (point) size))
1148 (insert (format "%S" (subst-char-in-string ?\n ?\s string)))
1149 ;; [mdw] missing from upstream
1150 (backward-char 1))
1151 (beginning-of-line)
1152 (setq article
1153 (and (re-search-forward "UID \\([0-9]+\\)"
1154 (line-end-position)
1155 t)
1156 (match-string 1)))
1157 (setq lines nil)
1158 (setq size
1159 (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)"
1160 (line-end-position)
1161 t)
1162 (match-string 1)))
1163 (beginning-of-line)
1164 (when (search-forward "BODYSTRUCTURE" (line-end-position) t)
1165 (let ((structure (ignore-errors
1166 (read (current-buffer)))))
1167 (while (and (consp structure)
1168 (not (atom (car structure))))
1169 (setq structure (car structure)))
1170 (setq lines (if (and
1171 (stringp (car structure))
1172 (equal (upcase (nth 0 structure)) "MESSAGE")
1173 (equal (upcase (nth 1 structure)) "RFC822"))
1174 (nth 9 structure)
1175 (nth 7 structure)))))
1176 (delete-region (line-beginning-position) (line-end-position))
1177 (insert (format "211 %s Article retrieved." article))
1178 (forward-line 1)
1179 (when size
1180 (insert (format "Chars: %s\n" size)))
1181 (when lines
1182 (insert (format "Lines: %s\n" lines)))
1183 ;; Most servers have a blank line after the headers, but
1184 ;; Davmail doesn't.
1185 (unless (re-search-forward "^\r$\\|^)\r?$" nil t)
1186 (goto-char (point-max)))
1187 (delete-region (line-beginning-position) (line-end-position))
1188 (insert ".")
1189 (forward-line 1)))))
1190
1191(eval-after-load 'nnimap
1192 '(defalias 'nnimap-transform-headers
1193 (symbol-function 'mdw-nnimap-transform-headers)))
1194
1195(defadvice gnus-other-frame (around mdw-hack-frame-width compile activate)
1196 "Always arrange for mail/news frames to be 80 columns wide."
1197 (let ((default-frame-alist (cons `(width . ,(+ 80 mdw-frame-width-fudge))
1198 (delete* 'width default-frame-alist
1199 :key #'car))))
1200 ad-do-it))
1201
1202;; Preferred programs.
1203
1204(setq mailcap-user-mime-data
1205 '(((type . "application/pdf") (viewer . "mupdf %s"))))
1206
1207;;;--------------------------------------------------------------------------
1208;;; Utility functions.
1209
1210(or (fboundp 'line-number-at-pos)
1211 (defun line-number-at-pos (&optional pos)
1212 (let ((opoint (or pos (point))) start)
1213 (save-excursion
1214 (save-restriction
1215 (goto-char (point-min))
1216 (widen)
1217 (forward-line 0)
1218 (setq start (point))
1219 (goto-char opoint)
1220 (forward-line 0)
1221 (1+ (count-lines 1 (point))))))))
1222
1223(defun mdw-uniquify-alist (&rest alists)
1224 "Return the concatenation of the ALISTS with duplicate elements removed.
1225The first association with a given key prevails; others are
1226ignored. The input lists are not modified, although they'll
1227probably become garbage."
1228 (and alists
1229 (let ((start-list (cons nil nil)))
1230 (mdw-do-uniquify start-list
1231 start-list
1232 (car alists)
1233 (cdr alists)))))
1234
1235(defun mdw-do-uniquify (done end l rest)
1236 "A helper function for mdw-uniquify-alist.
1237The DONE argument is a list whose first element is `nil'. It
1238contains the uniquified alist built so far. The leading `nil' is
1239stripped off at the end of the operation; it's only there so that
1240DONE always references a cons cell. END refers to the final cons
1241cell in the DONE list; it is modified in place each time to avoid
1242the overheads of `append'ing all the time. The L argument is the
1243alist we're currently processing; the remaining alists are given
1244in REST."
1245
1246 ;; There are several different cases to deal with here.
1247 (cond
1248
1249 ;; Current list isn't empty. Add the first item to the DONE list if
1250 ;; there's not an item with the same KEY already there.
1251 (l (or (assoc (car (car l)) done)
1252 (progn
1253 (setcdr end (cons (car l) nil))
1254 (setq end (cdr end))))
1255 (mdw-do-uniquify done end (cdr l) rest))
1256
1257 ;; The list we were working on is empty. Shunt the next list into the
1258 ;; current list position and go round again.
1259 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
1260
1261 ;; Everything's done. Remove the leading `nil' from the DONE list and
1262 ;; return it. Finished!
1263 (t (cdr done))))
1264
1265(defun date ()
1266 "Insert the current date in a pleasing way."
1267 (interactive)
1268 (insert (save-excursion
1269 (let ((buffer (get-buffer-create "*tmp*")))
1270 (unwind-protect (progn (set-buffer buffer)
1271 (erase-buffer)
1272 (shell-command "date +%Y-%m-%d" t)
1273 (goto-char (mark))
1274 (delete-char -1)
1275 (buffer-string))
1276 (kill-buffer buffer))))))
1277
1278(defun uuencode (file &optional name)
1279 "UUencodes a file, maybe calling it NAME, into the current buffer."
1280 (interactive "fInput file name: ")
1281
1282 ;; If NAME isn't specified, then guess from the filename.
1283 (if (not name)
1284 (setq name
1285 (substring file
1286 (or (string-match "[^/]*$" file) 0))))
1287 (print (format "uuencode `%s' `%s'" file name))
1288
1289 ;; Now actually do the thing.
1290 (call-process "uuencode" file t nil name))
1291
1292(defcustom np-file "~/.np"
1293 "Where the `now-playing' file is."
1294 :type 'file
1295 :safe 'stringp)
1296
1297(defun np (&optional arg)
1298 "Grabs a `now-playing' string."
1299 (interactive)
1300 (save-excursion
1301 (or arg (progn
1302 (goto-char (point-max))
1303 (insert "\nNP: ")
1304 (insert-file-contents np-file)))))
1305
1306(defun mdw-version-< (ver-a ver-b)
1307 "Answer whether VER-A is strictly earlier than VER-B.
1308VER-A and VER-B are version numbers, which are strings containing digit
1309sequences separated by `.'."
1310 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
1311 (split-string ver-a "\\.")))
1312 (lb (mapcar (lambda (x) (car (read-from-string x)))
1313 (split-string ver-b "\\."))))
1314 (catch 'done
1315 (while t
1316 (cond ((null la) (throw 'done lb))
1317 ((null lb) (throw 'done nil))
1318 ((< (car la) (car lb)) (throw 'done t))
1319 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))
1320 (t (throw 'done nil)))))))
1321
1322(defun mdw-check-autorevert ()
1323 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
1324This takes into consideration whether it's been found using
1325tramp, which seems to get itself into a twist."
1326 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
1327 nil)
1328 ((and (buffer-file-name)
1329 (fboundp 'tramp-tramp-file-p)
1330 (tramp-tramp-file-p (buffer-file-name)))
1331 (unless global-auto-revert-ignore-buffer
1332 (setq global-auto-revert-ignore-buffer 'tramp)))
1333 ((eq global-auto-revert-ignore-buffer 'tramp)
1334 (setq global-auto-revert-ignore-buffer nil))))
1335
1336(defadvice find-file (after mdw-autorevert activate)
1337 (mdw-check-autorevert))
1338(defadvice write-file (after mdw-autorevert activate)
1339 (mdw-check-autorevert))
1340
1341(defun mdw-auto-revert ()
1342 "Recheck all of the autorevertable buffers, and update VC modelines."
1343 (interactive)
1344 (let ((auto-revert-check-vc-info t))
1345 (auto-revert-buffers)))
1346
1347;;;--------------------------------------------------------------------------
1348;;; Dired hacking.
1349
1350(defadvice dired-maybe-insert-subdir
1351 (around mdw-marked-insertion first activate)
1352 "The DIRNAME may be a list of directory names to insert.
1353Interactively, if files are marked, then insert all of them.
1354With a numeric prefix argument, select that many entries near
1355point; with a non-numeric prefix argument, prompt for listing
1356options."
1357 (interactive
1358 (list (dired-get-marked-files nil
1359 (and (integerp current-prefix-arg)
1360 current-prefix-arg)
1361 #'file-directory-p)
1362 (and current-prefix-arg
1363 (not (integerp current-prefix-arg))
1364 (read-string "Switches for listing: "
1365 (or dired-subdir-switches
1366 dired-actual-switches)))))
1367 (let ((dirs (ad-get-arg 0)))
1368 (dolist (dir (if (listp dirs) dirs (list dirs)))
1369 (ad-set-arg 0 dir)
1370 ad-do-it)))
1371
1372(defun mdw-dired-run (args &optional syncp)
1373 (interactive (let ((file (dired-get-filename t)))
1374 (list (read-string (format "Arguments for %s: " file))
1375 current-prefix-arg)))
1376 (funcall (if syncp 'shell-command 'async-shell-command)
1377 (concat (shell-quote-argument (dired-get-filename nil))
1378 " " args)))
1379
1380(defadvice dired-do-flagged-delete
1381 (around mdw-delete-if-prefix-argument activate compile)
1382 (let ((delete-by-moving-to-trash (and (null current-prefix-arg)
1383 delete-by-moving-to-trash)))
1384 ad-do-it))
1385
1386(eval-after-load "dired"
1387 '(define-key dired-mode-map "X" 'mdw-dired-run))
1388
1389;;;--------------------------------------------------------------------------
1390;;; URL viewing.
1391
1392(defun mdw-w3m-browse-url (url &optional new-session-p)
1393 "Invoke w3m on the URL in its current window, or at least a different one.
1394If NEW-SESSION-P, start a new session."
1395 (interactive "sURL: \nP")
1396 (save-excursion
1397 (let ((window (selected-window)))
1398 (unwind-protect
1399 (progn
1400 (select-window (or (and (not new-session-p)
1401 (get-buffer-window "*w3m*"))
1402 (progn
1403 (if (one-window-p t) (split-window))
1404 (get-lru-window))))
1405 (w3m-browse-url url new-session-p))
1406 (select-window window)))))
1407
1408(eval-after-load 'w3m
1409 '(define-key w3m-mode-map [?\e ?\r] 'w3m-view-this-url-new-session))
1410
1411(defcustom mdw-good-url-browsers
1412 '(browse-url-firefox
1413 browse-url-mozilla
1414 browse-url-generic
1415 (w3m . mdw-w3m-browse-url)
1416 browse-url-w3)
1417 "List of good browsers for mdw-good-url-browsers.
1418Each item is a browser function name, or a cons (CHECK . FUNC).
1419A symbol FOO stands for (FOO . FOO)."
1420 :type '(repeat (choice function (cons function function))))
1421
1422(defun mdw-good-url-browser ()
1423 "Return a good URL browser.
1424Trundle the list of such things, finding the first item for which
1425CHECK is fboundp, and returning the correponding FUNC."
1426 (let ((bs mdw-good-url-browsers) b check func answer)
1427 (while (and bs (not answer))
1428 (setq b (car bs)
1429 bs (cdr bs))
1430 (if (consp b)
1431 (setq check (car b) func (cdr b))
1432 (setq check b func b))
1433 (if (fboundp check)
1434 (setq answer func)))
1435 answer))
1436
1437(eval-after-load "w3m-search"
1438 '(progn
1439 (dolist
1440 (item
1441 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
1442 ("gd" "Google Directory"
1443 "http://www.google.com/search?cat=gwd/Top&q=%s")
1444 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
1445 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
1446 ("gi" "Images" "http://images.google.com/images?q=%s")
1447 ("rfc" "RFC"
1448 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
1449 ("wp" "Wikipedia"
1450 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
1451 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
1452 ("nc-wiki" "nCipher wiki"
1453 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
1454 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
1455 ("lp" "Launchpad bug by number"
1456 "https://bugs.launchpad.net/bugs/%s")
1457 ("lppkg" "Launchpad bugs by package"
1458 "https://bugs.launchpad.net/%s")
1459 ("msdn" "MSDN"
1460 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
1461 ("debbug" "Debian bug by number"
1462 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
1463 ("debbugpkg" "Debian bugs by package"
1464 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
1465 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
1466 (add-to-list 'w3m-search-engine-alist
1467 (list (cadr item) (cl-caddr item) nil))
1468 (add-to-list 'w3m-uri-replace-alist
1469 (list (concat "\\`" (car item) ":")
1470 'w3m-search-uri-replace
1471 (cadr item))))))
1472
1473;;;--------------------------------------------------------------------------
1474;;; Paragraph filling.
1475
1476;; Useful variables.
1477
1478(defcustom mdw-fill-prefix nil
1479 "Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
1480If there's no fill prefix currently set (by the `fill-prefix'
1481variable) and there's a match from one of the regexps here, it
1482gets used to set the fill-prefix for the current operation.
1483
1484The variable is a list of items of the form `PATTERN . PREFIX'; if
1485the PATTERN matches, the PREFIX is used to set the fill prefix.
1486
1487A PATTERN is one of the following.
1488
1489 * STRING -- a regular expression, expected to match at point
1490 * (eval . FORM) -- a Lisp form which must evaluate non-nil
1491 * (if COND CONSEQ-PAT ALT-PAT) -- if COND evaluates non-nil, must match
1492 CONSEQ-PAT; otherwise must match ALT-PAT
1493 * (and PATTERN ...) -- must match all of the PATTERNs
1494 * (or PATTERN ...) -- must match at least one PATTERN
1495 * (not PATTERN) -- mustn't match (probably not useful)
1496
1497A PREFIX is a list of the following kinds of things:
1498
1499 * STRING -- insert a literal string
1500 * (match . N) -- insert the thing matched by bracketed subexpression N
1501 * (pad . N) -- a string of whitespace the same width as subexpression N
1502 * (expr . FORM) -- the result of evaluating FORM
1503
1504Information about `bracketed subexpressions' comes from the match data,
1505as modified during matching.")
1506
1507(make-variable-buffer-local 'mdw-fill-prefix)
1508
1509(defcustom mdw-hanging-indents
1510 (concat "\\(\\("
1511 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
1512 "[ \t]+"
1513 "\\)?\\)")
1514 "Standard regexp matching parts of a hanging indent.
1515This is mainly useful in `auto-fill-mode'."
1516 :type 'regexp)
1517
1518;; Utility functions.
1519
1520(defun mdw-maybe-tabify (s)
1521 "Tabify or untabify the string S, according to `indent-tabs-mode'."
1522 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
1523 (with-temp-buffer
1524 (save-match-data
1525 (insert s "\n")
1526 (let ((start (point-min)) (end (point-max)))
1527 (funcall tabfun (point-min) (point-max))
1528 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
1529
1530(defun mdw-fill-prefix-match-p (pat)
1531 "Return non-nil if PAT matches at the current position."
1532 (cond ((stringp pat) (looking-at pat))
1533 ((not (consp pat)) (error "Unknown pattern item `%S'" pat))
1534 ((eq (car pat) 'eval) (eval (cdr pat)))
1535 ((eq (car pat) 'if)
1536 (if (or (null (cdr pat))
1537 (null (cddr pat))
1538 (null (cl-cdddr pat))
1539 (cl-cddddr pat))
1540 (error "Invalid `if' pattern `%S'" pat))
1541 (mdw-fill-prefix-match-p (if (eval (cadr pat))
1542 (cl-caddr pat)
1543 (cl-cadddr pat))))
1544 ((eq (car pat) 'and)
1545 (let ((pats (cdr pat))
1546 (ok t))
1547 (while (and pats
1548 (or (mdw-fill-prefix-match-p (car pats))
1549 (setq ok nil)))
1550 (setq pats (cdr pats)))
1551 ok))
1552 ((eq (car pat) 'or)
1553 (let ((pats (cdr pat))
1554 (ok nil))
1555 (while (and pats
1556 (or (not (mdw-fill-prefix-match-p (car pats)))
1557 (progn (setq ok t) nil)))
1558 (setq pats (cdr pats)))
1559 ok))
1560 ((eq (car pat) 'not)
1561 (if (or (null (cdr pat)) (cddr pat))
1562 (error "Invalid `not' pattern `%S'" pat))
1563 (not (mdw-fill-prefix-match-p (car pats))))
1564 (t (error "Unknown pattern form `%S'" pat))))
1565
1566(defun mdw-maybe-car (p)
1567 "If P is a pair, return (car P), otherwise just return P."
1568 (if (consp p) (car p) p))
1569
1570(defun mdw-padding (s)
1571 "Return a string the same width as S but made entirely from whitespace."
1572 (let* ((l (length s)) (i 0) (n (make-string l ? )))
1573 (while (< i l)
1574 (if (= 9 (aref s i))
1575 (aset n i 9))
1576 (setq i (1+ i)))
1577 n))
1578
1579(defun mdw-do-prefix-match (m)
1580 "Expand a dynamic prefix match element.
1581See `mdw-fill-prefix' for details."
1582 (cond ((not (consp m)) (format "%s" m))
1583 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
1584 ((eq (car m) 'pad) (mdw-padding (match-string
1585 (mdw-maybe-car (cdr m)))))
1586 ((eq (car m) 'eval) (eval (cdr m)))
1587 (t "")))
1588
1589(defun mdw-examine-fill-prefixes (l)
1590 "Given a list of dynamic fill prefixes, pick one which matches
1591context and return the static fill prefix to use. Point must be
1592at the start of a line, and match data must be saved."
1593 (let ((prefix nil))
1594 (while (cond ((null l) nil)
1595 ((mdw-fill-prefix-match-p (caar l))
1596 (setq prefix
1597 (mdw-maybe-tabify
1598 (apply #'concat
1599 (mapcar #'mdw-do-prefix-match
1600 (cdr (car l))))))
1601 nil))
1602 (setq l (cdr l)))
1603 prefix))
1604
1605(defun mdw-choose-dynamic-fill-prefix ()
1606 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
1607 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
1608 ((not mdw-fill-prefix) fill-prefix)
1609 (t (save-excursion
1610 (beginning-of-line)
1611 (save-match-data
1612 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
1613
1614(defadvice do-auto-fill (around mdw-dynamic-fill-prefix () activate compile)
1615 "Handle auto-filling, working out a dynamic fill prefix in the
1616case where there isn't a sensible static one."
1617 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1618 ad-do-it))
1619
1620(defun mdw-fill-paragraph ()
1621 "Fill paragraph, getting a dynamic fill prefix."
1622 (interactive)
1623 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1624 (fill-paragraph nil)))
1625
1626(defun mdw-point-within-string-p ()
1627 "Return non-nil if point is within a string."
1628 (let ((state (syntax-ppss)))
1629 (elt state 3)))
1630
1631(defun mdw-standard-fill-prefix (rx &optional mat)
1632 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
1633This is just a short-cut for setting the thing by hand, and by
1634design it doesn't cope with anything approximating a complicated
1635case."
1636 (setq mdw-fill-prefix
1637 `(((if (mdw-point-within-string-p)
1638 ,(concat "\\(\\s-*\\)" mdw-hanging-indents)
1639 ,(concat rx mdw-hanging-indents))
1640 (match . 1)
1641 (pad . ,(or mat 2))))))
1642
1643;;;--------------------------------------------------------------------------
1644;;; Printing.
1645
1646;; Teach PostScript about a condensed variant of Courier. I'm using 85% of
1647;; the usual width, which happens to match `mdwfonts', and David Carlisle's
1648;; `pslatex'. (Once upon a time, I used 80%, but decided consistency with
1649;; `pslatex' was useful.)
1650(setq ps-user-defined-prologue "
1651/CourierCondensed /Courier
1652/CourierCondensed-Bold /Courier-Bold
1653/CourierCondensed-Oblique /Courier-Oblique
1654/CourierCondensed-BoldOblique /Courier-BoldOblique
1655 4 { findfont [0.85 0 0 1 0 0] makefont definefont pop } repeat
1656")
1657
1658;; Hack `ps-print''s settings.
1659(eval-after-load 'ps-print
1660 '(progn
1661
1662 ;; Notice that the comment-delimiters should be in italics too.
1663 (cl-pushnew 'font-lock-comment-delimiter-face ps-italic-faces)
1664
1665 ;; Select more suitable colours for the main kinds of tokens. The
1666 ;; colours set on the Emacs faces are chosen for use against a dark
1667 ;; background, and work very badly on white paper.
1668 (ps-extend-face '(font-lock-comment-face "darkgreen" nil italic))
1669 (ps-extend-face '(font-lock-comment-delimiter-face "darkgreen" nil italic))
1670 (ps-extend-face '(font-lock-string-face "RoyalBlue4" nil))
1671 (ps-extend-face '(mdw-punct-face "sienna" nil))
1672 (ps-extend-face '(mdw-number-face "OrangeRed3" nil))
1673
1674 ;; Teach `ps-print' about my condensed varsions of Courier.
1675 (setq ps-font-info-database
1676 (append '((CourierCondensed
1677 (fonts (normal . "CourierCondensed")
1678 (bold . "CourierCondensed-Bold")
1679 (italic . "CourierCondensed-Oblique")
1680 (bold-italic . "CourierCondensed-BoldOblique"))
1681 (size . 10.0)
1682 (line-height . 10.55)
1683 (space-width . 5.1)
1684 (avg-char-width . 5.1)))
1685 (cl-remove 'CourierCondensed ps-font-info-database
1686 :key #'car)))))
1687
1688;; Arrange to strip overlays from the buffer before we print . This will
1689;; prevent `flyspell' from interfering with the printout. (It would be less
1690;; bad if `ps-print' could merge the `flyspell' overlay face with the
1691;; underlying `font-lock' face, but it can't (and that seems hard). So
1692;; instead we have this hack.
1693;;
1694;; The basic trick is to copy the relevant text from the buffer being printed
1695;; into a temporary buffer and... just print that. The text properties come
1696;; with the text and end up in the new buffer, and the overlays get lost
1697;; along the way. Only problem is that the headers identifying the file
1698;; being printed get confused, so remember the original buffer and reinstate
1699;; it when constructing the headers.
1700(defvar mdw-printing-buffer)
1701
1702(defadvice ps-generate-header
1703 (around mdw-use-correct-buffer () activate compile)
1704 "Print the correct name of the buffer being printed."
1705 (with-current-buffer mdw-printing-buffer
1706 ad-do-it))
1707
1708(defadvice ps-generate
1709 (around mdw-strip-overlays (buffer from to genfunc) activate compile)
1710 "Strip overlays -- in particular, from `flyspell' -- before printout."
1711 (with-temp-buffer
1712 (let ((mdw-printing-buffer buffer))
1713 (insert-buffer-substring buffer from to)
1714 (ad-set-arg 0 (current-buffer))
1715 (ad-set-arg 1 (point-min))
1716 (ad-set-arg 2 (point-max))
1717 ad-do-it)))
1718
1719;;;--------------------------------------------------------------------------
1720;;; Other common declarations.
1721
1722;; Common mode settings.
1723
1724(defcustom mdw-auto-indent t
1725 "Whether to indent automatically after a newline."
1726 :type 'boolean
1727 :safe 'booleanp)
1728
1729(defun mdw-whitespace-mode (&optional arg)
1730 "Turn on/off whitespace mode, but don't highlight trailing space."
1731 (interactive "P")
1732 (when (and (boundp 'whitespace-style)
1733 (fboundp 'whitespace-mode))
1734 (let ((whitespace-style (remove 'trailing whitespace-style)))
1735 (whitespace-mode arg))
1736 (setq show-trailing-whitespace whitespace-mode)))
1737
1738(defvar mdw-do-misc-mode-hacking nil)
1739
1740(defun mdw-misc-mode-config ()
1741 (and mdw-auto-indent
1742 (cond ((eq major-mode 'lisp-mode)
1743 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
1744 ((derived-mode-p 'slime-repl-mode 'asm-mode 'comint-mode)
1745 nil)
1746 (t
1747 (local-set-key "\C-m" 'newline-and-indent))))
1748 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
1749 (local-set-key [C-return] 'newline)
1750 (make-local-variable 'page-delimiter)
1751 (setq page-delimiter (concat "^" "\f"
1752 "\\|" "^"
1753 ".\\{0,4\\}"
1754 "-\\{5\\}"
1755 "\\(" " " ".*" " " "\\)?"
1756 "-+"
1757 ".\\{0,2\\}"
1758 "$"))
1759 (setq comment-column 40)
1760 (auto-fill-mode 1)
1761 (setq fill-column mdw-text-width)
1762 (flyspell-prog-mode)
1763 (and (fboundp 'gtags-mode)
1764 (gtags-mode))
1765 (if (fboundp 'hs-minor-mode)
1766 (trap (hs-minor-mode t))
1767 (outline-minor-mode t))
1768 (reveal-mode t)
1769 (trap (turn-on-font-lock)))
1770
1771(defun mdw-post-local-vars-misc-mode-config ()
1772 (setq whitespace-line-column mdw-text-width)
1773 (when (and mdw-do-misc-mode-hacking
1774 (not buffer-read-only))
1775 (setq show-trailing-whitespace t)
1776 (mdw-whitespace-mode 1)))
1777(add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
1778
1779(defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1780 `(progn ,@(mapcar (lambda (func)
1781 `(defadvice ,func
1782 (after mdw-angry-fruit-salad activate)
1783 (when mdw-do-misc-mode-hacking
1784 (setq show-trailing-whitespace
1785 (not buffer-read-only))
1786 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1787 funcs)))
1788(mdw-advise-update-angry-fruit-salad toggle-read-only
1789 read-only-mode
1790 view-mode
1791 view-mode-enable
1792 view-mode-disable)
1793
1794(eval-after-load 'gtags
1795 '(progn
1796 (dolist (key '([mouse-2] [mouse-3]))
1797 (define-key gtags-mode-map key nil))
1798 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1799 (define-key gtags-select-mode-map [C-S-mouse-2]
1800 'gtags-select-tag-by-event)
1801 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1802 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
1803
1804;; Backup file handling.
1805
1806(defcustom mdw-backup-disable-regexps nil
1807 "List of regular expressions: if a file name matches any of
1808these then the file is not backed up."
1809 :type '(repeat regexp))
1810
1811(defun mdw-backup-enable-predicate (name)
1812 "[mdw]'s default backup predicate.
1813Allows a backup if the standard predicate would allow it, and it
1814doesn't match any of the regular expressions in
1815`mdw-backup-disable-regexps'."
1816 (and (normal-backup-enable-predicate name)
1817 (let ((answer t) (list mdw-backup-disable-regexps))
1818 (save-match-data
1819 (while list
1820 (if (string-match (car list) name)
1821 (setq answer nil))
1822 (setq list (cdr list)))
1823 answer))))
1824(setq backup-enable-predicate 'mdw-backup-enable-predicate)
1825
1826;; Frame cleanup.
1827
1828(defun mdw-last-one-out-turn-off-the-lights (frame)
1829 "Disconnect from an X display if this was the last frame on that display."
1830 (let ((frame-display (frame-parameter frame 'display)))
1831 (when (and frame-display
1832 (eq window-system 'x)
1833 (not (cl-some (lambda (fr)
1834 (and (not (eq fr frame))
1835 (string= (frame-parameter fr 'display)
1836 frame-display)))
1837 (frame-list))))
1838 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1839(add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1840
1841;;;--------------------------------------------------------------------------
1842;;; Fullscreen-ness.
1843
1844(defcustom mdw-full-screen-parameters
1845 '((menu-bar-lines . 0)
1846 ;;(vertical-scroll-bars . nil)
1847 )
1848 "Frame parameters to set when making a frame fullscreen."
1849 :type '(alist :key-type symbol))
1850
1851(defcustom mdw-full-screen-save
1852 '(width height)
1853 "Extra frame parameters to save when setting fullscreen."
1854 :type '(repeat symbol))
1855
1856(defun mdw-toggle-full-screen (&optional frame)
1857 "Show the FRAME fullscreen."
1858 (interactive)
1859 (when window-system
1860 (cond ((frame-parameter frame 'fullscreen)
1861 (set-frame-parameter frame 'fullscreen nil)
1862 (modify-frame-parameters
1863 nil
1864 (or (frame-parameter frame 'mdw-full-screen-saved)
1865 (mapcar (lambda (assoc)
1866 (assq (car assoc) default-frame-alist))
1867 mdw-full-screen-parameters))))
1868 (t
1869 (let ((saved (mapcar (lambda (param)
1870 (cons param (frame-parameter frame param)))
1871 (append (mapcar #'car
1872 mdw-full-screen-parameters)
1873 mdw-full-screen-save))))
1874 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1875 (modify-frame-parameters frame mdw-full-screen-parameters)
1876 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1877
1878;;;--------------------------------------------------------------------------
1879;;; General fontification.
1880
1881(make-face 'mdw-virgin-face)
1882
1883(defmacro mdw-define-face (name &rest body)
1884 "Define a face, and make sure it's actually set as the definition."
1885 (declare (indent 1)
1886 (debug 0))
1887 `(progn
1888 (copy-face 'mdw-virgin-face ',name)
1889 (defvar ,name ',name)
1890 (put ',name 'face-defface-spec ',body)
1891 (face-spec-set ',name ',body nil)))
1892
1893(mdw-define-face default
1894 (((type w32)) :family "courier new" :height 85)
1895 (((type x)) :family "6x13" :foundry "trad" :height 130)
1896 (((type color)) :foreground "white" :background "black")
1897 (t nil))
1898(mdw-define-face fixed-pitch
1899 (((type w32)) :family "courier new" :height 85)
1900 (((type x)) :family "6x13" :foundry "trad" :height 130)
1901 (t :foreground "white" :background "black"))
1902(mdw-define-face fixed-pitch-serif
1903 (((type w32)) :family "courier new" :height 85 :weight bold)
1904 (((type x)) :family "6x13" :foundry "trad" :height 130 :weight bold)
1905 (t :foreground "white" :background "black" :weight bold))
1906(mdw-define-face variable-pitch
1907 (((type x)) :family "helvetica" :height 120))
1908(mdw-define-face region
1909 (((min-colors 64)) :background "grey30")
1910 (((class color)) :background "blue")
1911 (t :inverse-video t))
1912(mdw-define-face error
1913 (((class color)) :background "red")
1914 (t :inverse-video t))
1915(mdw-define-face match
1916 (((class color)) :background "blue")
1917 (t :inverse-video t))
1918(mdw-define-face mc/cursor-face
1919 (((class color)) :background "red")
1920 (t :inverse-video t))
1921(mdw-define-face minibuffer-prompt
1922 (t :weight bold))
1923(mdw-define-face mode-line
1924 (((class color)) :foreground "blue" :background "yellow"
1925 :box (:line-width 1 :style released-button))
1926 (t :inverse-video t))
1927(mdw-define-face mode-line-inactive
1928 (((class color)) :foreground "yellow" :background "blue"
1929 :box (:line-width 1 :style released-button))
1930 (t :inverse-video t))
1931(mdw-define-face nobreak-space
1932 (((type tty)))
1933 (t :inherit escape-glyph :underline t))
1934(mdw-define-face scroll-bar
1935 (t :foreground "black" :background "lightgrey"))
1936(mdw-define-face fringe
1937 (t :foreground "yellow"))
1938(mdw-define-face show-paren-match
1939 (((min-colors 64)) :background "darkgreen")
1940 (((class color)) :background "green")
1941 (t :underline t))
1942(mdw-define-face show-paren-mismatch
1943 (((class color)) :background "red")
1944 (t :inverse-video t))
1945(mdw-define-face highlight
1946 (((min-colors 64)) :background "DarkSeaGreen4")
1947 (((class color)) :background "cyan")
1948 (t :inverse-video t))
1949
1950(mdw-define-face viper-minibuffer-emacs (t nil))
1951(mdw-define-face viper-minibuffer-insert (t nil))
1952(mdw-define-face viper-minibuffer-vi (t nil))
1953(mdw-define-face viper-replace-overlay
1954 (((min-colors 64)) :background "darkred")
1955 (((class color)) :background "red")
1956 (t :inverse-video t))
1957(mdw-define-face viper-search (t :inherit isearch))
1958
1959(mdw-define-face compilation-error
1960 (((class color)) :foreground "red" :weight bold)
1961 (t :weight bold))
1962(mdw-define-face compilation-warning
1963 (((class color)) :foreground "orange" :weight bold)
1964 (t :weight bold))
1965(mdw-define-face compilation-info
1966 (((class color)) :foreground "green" :weight bold)
1967 (t :weight bold))
1968(mdw-define-face compilation-line-number
1969 (t :weight bold))
1970(mdw-define-face compilation-column-number
1971 (((min-colors 64)) :foreground "lightgrey"))
1972(setq compilation-message-face 'mdw-virgin-face)
1973(setq compilation-enter-directory-face 'font-lock-comment-face)
1974(setq compilation-leave-directory-face 'font-lock-comment-face)
1975
1976(mdw-define-face holiday-face
1977 (t :background "red"))
1978(mdw-define-face calendar-today-face
1979 (t :foreground "yellow" :weight bold))
1980
1981(mdw-define-face flyspell-incorrect
1982 (((type x)) :underline (:color "red" :style wave))
1983 (((class color)) :foreground "red" :underline t)
1984 (t :underline t))
1985(mdw-define-face flyspell-duplicate
1986 (((type x)) :underline (:color "orange" :style wave))
1987 (((class color)) :foreground "orange" :underline t)
1988 (t :underline t))
1989
1990(mdw-define-face comint-highlight-prompt
1991 (t :weight bold))
1992(mdw-define-face comint-highlight-input
1993 (t nil))
1994
1995(mdw-define-face Man-underline
1996 (((type tty)) :underline t)
1997 (t :slant italic))
1998
1999(mdw-define-face ido-subdir
2000 (t :foreground "cyan" :weight bold))
2001
2002(mdw-define-face dired-directory
2003 (t :foreground "cyan" :weight bold))
2004(mdw-define-face dired-symlink
2005 (t :foreground "cyan"))
2006(mdw-define-face dired-perm-write
2007 (t nil))
2008
2009(mdw-define-face trailing-whitespace
2010 (((class color)) :background "red")
2011 (t :inverse-video t))
2012(mdw-define-face whitespace-line
2013 (((class color)) :background "darkred")
2014 (t :inverse-video t))
2015(mdw-define-face mdw-punct-face
2016 (((min-colors 64)) :foreground "burlywood2")
2017 (((class color)) :foreground "yellow"))
2018(mdw-define-face mdw-number-face
2019 (t :foreground "yellow"))
2020(mdw-define-face mdw-trivial-face)
2021(mdw-define-face font-lock-function-name-face
2022 (t :slant italic))
2023(mdw-define-face font-lock-keyword-face
2024 (t :weight bold))
2025(mdw-define-face font-lock-constant-face
2026 (t :slant italic))
2027(mdw-define-face font-lock-builtin-face
2028 (t :weight bold))
2029(mdw-define-face font-lock-type-face
2030 (t :weight bold :slant italic))
2031(mdw-define-face font-lock-reference-face
2032 (t :weight bold))
2033(mdw-define-face font-lock-variable-name-face
2034 (t :slant italic))
2035(mdw-define-face font-lock-comment-face
2036 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
2037 (((class color)) :foreground "green")
2038 (t :weight bold))
2039(mdw-define-face font-lock-comment-delimiter-face
2040 (t :inherit font-lock-comment-face))
2041(mdw-define-face font-lock-string-face
2042 (((min-colors 64)) :foreground "SkyBlue1")
2043 (((class color)) :foreground "cyan")
2044 (t :weight bold))
2045(mdw-define-face font-lock-doc-face
2046 (t :inherit font-lock-string-face))
2047
2048(mdw-define-face message-separator
2049 (t :background "red" :foreground "white" :weight bold))
2050(mdw-define-face message-cited-text
2051 (default :slant italic)
2052 (((min-colors 64)) :foreground "SkyBlue1")
2053 (((class color)) :foreground "cyan"))
2054(mdw-define-face message-header-cc
2055 (default :slant italic)
2056 (((min-colors 64)) :foreground "SeaGreen1")
2057 (((class color)) :foreground "green"))
2058(mdw-define-face message-header-newsgroups
2059 (default :slant italic)
2060 (((min-colors 64)) :foreground "SeaGreen1")
2061 (((class color)) :foreground "green"))
2062(mdw-define-face message-header-subject
2063 (((min-colors 64)) :foreground "SeaGreen1")
2064 (((class color)) :foreground "green"))
2065(mdw-define-face message-header-to
2066 (((min-colors 64)) :foreground "SeaGreen1")
2067 (((class color)) :foreground "green"))
2068(mdw-define-face message-header-xheader
2069 (default :slant italic)
2070 (((min-colors 64)) :foreground "SeaGreen1")
2071 (((class color)) :foreground "green"))
2072(mdw-define-face message-header-other
2073 (default :slant italic)
2074 (((min-colors 64)) :foreground "SeaGreen1")
2075 (((class color)) :foreground "green"))
2076(mdw-define-face message-header-name
2077 (default :weight bold)
2078 (((min-colors 64)) :foreground "SeaGreen1")
2079 (((class color)) :foreground "green"))
2080
2081(mdw-define-face which-func
2082 (t nil))
2083
2084(mdw-define-face gnus-header-name
2085 (default :weight bold)
2086 (((min-colors 64)) :foreground "SeaGreen1")
2087 (((class color)) :foreground "green"))
2088(mdw-define-face gnus-header-subject
2089 (((min-colors 64)) :foreground "SeaGreen1")
2090 (((class color)) :foreground "green"))
2091(mdw-define-face gnus-header-from
2092 (((min-colors 64)) :foreground "SeaGreen1")
2093 (((class color)) :foreground "green"))
2094(mdw-define-face gnus-header-to
2095 (((min-colors 64)) :foreground "SeaGreen1")
2096 (((class color)) :foreground "green"))
2097(mdw-define-face gnus-header-content
2098 (default :slant italic)
2099 (((min-colors 64)) :foreground "SeaGreen1")
2100 (((class color)) :foreground "green"))
2101
2102(mdw-define-face gnus-cite-1
2103 (((min-colors 64)) :foreground "SkyBlue1")
2104 (((class color)) :foreground "cyan"))
2105(mdw-define-face gnus-cite-2
2106 (((min-colors 64)) :foreground "RoyalBlue2")
2107 (((class color)) :foreground "blue"))
2108(mdw-define-face gnus-cite-3
2109 (((min-colors 64)) :foreground "MediumOrchid")
2110 (((class color)) :foreground "magenta"))
2111(mdw-define-face gnus-cite-4
2112 (((min-colors 64)) :foreground "firebrick2")
2113 (((class color)) :foreground "red"))
2114(mdw-define-face gnus-cite-5
2115 (((min-colors 64)) :foreground "burlywood2")
2116 (((class color)) :foreground "yellow"))
2117(mdw-define-face gnus-cite-6
2118 (((min-colors 64)) :foreground "SeaGreen1")
2119 (((class color)) :foreground "green"))
2120(mdw-define-face gnus-cite-7
2121 (((min-colors 64)) :foreground "SlateBlue1")
2122 (((class color)) :foreground "cyan"))
2123(mdw-define-face gnus-cite-8
2124 (((min-colors 64)) :foreground "RoyalBlue2")
2125 (((class color)) :foreground "blue"))
2126(mdw-define-face gnus-cite-9
2127 (((min-colors 64)) :foreground "purple2")
2128 (((class color)) :foreground "magenta"))
2129(mdw-define-face gnus-cite-10
2130 (((min-colors 64)) :foreground "DarkOrange2")
2131 (((class color)) :foreground "red"))
2132(mdw-define-face gnus-cite-11
2133 (t :foreground "grey"))
2134
2135(mdw-define-face gnus-emphasis-underline
2136 (((type tty)) :underline t)
2137 (t :slant italic))
2138
2139(mdw-define-face diff-header
2140 (t nil))
2141(mdw-define-face diff-index
2142 (t :weight bold))
2143(mdw-define-face diff-file-header
2144 (t :weight bold))
2145(mdw-define-face diff-hunk-header
2146 (((min-colors 64)) :foreground "SkyBlue1")
2147 (((class color)) :foreground "cyan"))
2148(mdw-define-face diff-function
2149 (default :weight bold)
2150 (((min-colors 64)) :foreground "SkyBlue1")
2151 (((class color)) :foreground "cyan"))
2152(mdw-define-face diff-header
2153 (((min-colors 64)) :background "grey10"))
2154(mdw-define-face diff-added
2155 (((class color)) :foreground "green"))
2156(mdw-define-face diff-removed
2157 (((class color)) :foreground "red"))
2158(mdw-define-face diff-context
2159 (t nil))
2160(mdw-define-face diff-refine-change
2161 (((min-colors 64)) :background "RoyalBlue4")
2162 (t :underline t))
2163(mdw-define-face diff-refine-removed
2164 (((min-colors 64)) :background "#500")
2165 (t :underline t))
2166(mdw-define-face diff-refine-added
2167 (((min-colors 64)) :background "#050")
2168 (t :underline t))
2169
2170(setq ediff-force-faces t)
2171(mdw-define-face ediff-current-diff-A
2172 (((min-colors 64)) :background "darkred")
2173 (((class color)) :background "red")
2174 (t :inverse-video t))
2175(mdw-define-face ediff-fine-diff-A
2176 (((min-colors 64)) :background "red3")
2177 (((class color)) :inverse-video t)
2178 (t :inverse-video nil))
2179(mdw-define-face ediff-even-diff-A
2180 (((min-colors 64)) :background "#300"))
2181(mdw-define-face ediff-odd-diff-A
2182 (((min-colors 64)) :background "#300"))
2183(mdw-define-face ediff-current-diff-B
2184 (((min-colors 64)) :background "darkgreen")
2185 (((class color)) :background "magenta")
2186 (t :inverse-video t))
2187(mdw-define-face ediff-fine-diff-B
2188 (((min-colors 64)) :background "green4")
2189 (((class color)) :inverse-video t)
2190 (t :inverse-video nil))
2191(mdw-define-face ediff-even-diff-B
2192 (((min-colors 64)) :background "#020"))
2193(mdw-define-face ediff-odd-diff-B
2194 (((min-colors 64)) :background "#020"))
2195(mdw-define-face ediff-current-diff-C
2196 (((min-colors 64)) :background "darkblue")
2197 (((class color)) :background "blue")
2198 (t :inverse-video t))
2199(mdw-define-face ediff-fine-diff-C
2200 (((min-colors 64)) :background "blue1")
2201 (((class color)) :inverse-video t)
2202 (t :inverse-video nil))
2203(mdw-define-face ediff-even-diff-C
2204 (((min-colors 64)) :background "#004"))
2205(mdw-define-face ediff-odd-diff-C
2206 (((min-colors 64)) :background "#004"))
2207(mdw-define-face ediff-current-diff-Ancestor
2208 (((min-colors 64)) :background "#630")
2209 (((class color)) :background "blue")
2210 (t :inverse-video t))
2211(mdw-define-face ediff-even-diff-Ancestor
2212 (((min-colors 64)) :background "#320"))
2213(mdw-define-face ediff-odd-diff-Ancestor
2214 (((min-colors 64)) :background "#320"))
2215
2216(mdw-define-face magit-hash
2217 (((min-colors 64)) :foreground "grey40")
2218 (((class color)) :foreground "blue"))
2219(mdw-define-face magit-popup-argument
2220 (((min-colors 64)) :foreground "SeaGreen1")
2221 (((class color)) :foreground "green")
2222 (t :weight bold))
2223(mdw-define-face magit-diff-hunk-heading
2224 (((min-colors 64)) :foreground "grey70" :background "grey25")
2225 (((class color)) :foreground "yellow"))
2226(mdw-define-face magit-diff-hunk-heading-highlight
2227 (((min-colors 64)) :foreground "grey70" :background "grey35")
2228 (((class color)) :foreground "yellow" :background "blue"))
2229(mdw-define-face magit-diff-added
2230 (((min-colors 64)) :foreground "#ddffdd" :background "#335533")
2231 (((class color)) :foreground "green"))
2232(mdw-define-face magit-diff-added-highlight
2233 (((min-colors 64)) :foreground "#cceecc" :background "#336633")
2234 (((class color)) :foreground "green" :background "blue"))
2235(mdw-define-face magit-diff-removed
2236 (((min-colors 64)) :foreground "#ffdddd" :background "#553333")
2237 (((class color)) :foreground "red"))
2238(mdw-define-face magit-diff-removed-highlight
2239 (((min-colors 64)) :foreground "#eecccc" :background "#663333")
2240 (((class color)) :foreground "red" :background "blue"))
2241(mdw-define-face magit-blame-heading
2242 (((min-colors 64)) :foreground "white" :background "grey25"
2243 :weight normal :slant normal)
2244 (((class color)) :foreground "white" :background "blue"
2245 :weight normal :slant normal))
2246(mdw-define-face magit-blame-name
2247 (t :inherit magit-blame-heading :slant italic))
2248(mdw-define-face magit-blame-date
2249 (((min-colors 64)) :inherit magit-blame-heading :foreground "grey60")
2250 (((class color)) :inherit magit-blame-heading :foreground "cyan"))
2251(mdw-define-face magit-blame-summary
2252 (t :inherit magit-blame-heading :weight bold))
2253
2254(mdw-define-face dylan-header-background
2255 (((min-colors 64)) :background "NavyBlue")
2256 (((class color)) :background "blue"))
2257
2258(mdw-define-face erc-my-nick-face
2259 (t :foreground "yellow" :weight bold))
2260(mdw-define-face erc-current-nick-face
2261 (t :foreground "yellow" :weight bold))
2262(mdw-define-face erc-input-face
2263 (t :foreground "yellow"))
2264(mdw-define-face erc-action-face
2265 ())
2266(mdw-define-face erc-button
2267 (t :foreground "cyan" :underline t :weight semi-bold))
2268
2269(mdw-define-face woman-bold
2270 (t :weight bold))
2271(mdw-define-face woman-italic
2272 (t :slant italic))
2273
2274(eval-after-load "rst"
2275 '(progn
2276 (mdw-define-face rst-level-1-face
2277 (t :foreground "SkyBlue1" :weight bold))
2278 (mdw-define-face rst-level-2-face
2279 (t :foreground "SeaGreen1" :weight bold))
2280 (mdw-define-face rst-level-3-face
2281 (t :weight bold))
2282 (mdw-define-face rst-level-4-face
2283 (t :slant italic))
2284 (mdw-define-face rst-level-5-face
2285 (t :underline t))
2286 (mdw-define-face rst-level-6-face
2287 ())))
2288
2289(mdw-define-face p4-depot-added-face
2290 (t :foreground "green"))
2291(mdw-define-face p4-depot-branch-op-face
2292 (t :foreground "yellow"))
2293(mdw-define-face p4-depot-deleted-face
2294 (t :foreground "red"))
2295(mdw-define-face p4-depot-unmapped-face
2296 (t :foreground "SkyBlue1"))
2297(mdw-define-face p4-diff-change-face
2298 (t :foreground "yellow"))
2299(mdw-define-face p4-diff-del-face
2300 (t :foreground "red"))
2301(mdw-define-face p4-diff-file-face
2302 (t :foreground "SkyBlue1"))
2303(mdw-define-face p4-diff-head-face
2304 (t :background "grey10"))
2305(mdw-define-face p4-diff-ins-face
2306 (t :foreground "green"))
2307
2308(mdw-define-face w3m-anchor-face
2309 (t :foreground "SkyBlue1" :underline t))
2310(mdw-define-face w3m-arrived-anchor-face
2311 (t :foreground "SkyBlue1" :underline t))
2312
2313(mdw-define-face whizzy-slice-face
2314 (t :background "grey10"))
2315(mdw-define-face whizzy-error-face
2316 (t :background "darkred"))
2317
2318;; Ellipses used to indicate hidden text (and similar).
2319(mdw-define-face mdw-ellipsis-face
2320 (((type tty)) :foreground "blue") (t :foreground "grey60"))
2321(let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
2322 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
2323 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
2324 (bar (make-glyph-code ?| mdw-ellipsis-face)))
2325 (set-display-table-slot standard-display-table 0 dollar)
2326 (set-display-table-slot standard-display-table 1 backslash)
2327 (set-display-table-slot standard-display-table 4
2328 (vector dot dot dot))
2329 (set-display-table-slot standard-display-table 5 bar))
2330
2331;;;--------------------------------------------------------------------------
2332;;; Where is point?
2333
2334(mdw-define-face mdw-point-overlay-face
2335 (((type graphic)))
2336 (((min-colors 64)) :background "darkblue")
2337 (((class color)) :background "blue")
2338 (((type tty) (class mono)) :inverse-video t))
2339
2340(defcustom mdw-point-overlay-fringe-display '(vertical-bar . vertical-bar)
2341 "Bitmaps to display in the left and right fringes in the current line."
2342 :type '(cons symbol symbol))
2343
2344(defun mdw-configure-point-overlay ()
2345 (let ((ov (make-overlay 0 0)))
2346 (overlay-put ov 'priority 0)
2347 (let* ((fringe (or mdw-point-overlay-fringe-display (cons nil nil)))
2348 (left (car fringe)) (right (cdr fringe))
2349 (s ""))
2350 (when left
2351 (let ((ss "."))
2352 (put-text-property 0 1 'display `(left-fringe ,left) ss)
2353 (setq s (concat s ss))))
2354 (when right
2355 (let ((ss "."))
2356 (put-text-property 0 1 'display `(right-fringe ,right) ss)
2357 (setq s (concat s ss))))
2358 (when (or left right)
2359 (overlay-put ov 'before-string s)))
2360 (overlay-put ov 'face 'mdw-point-overlay-face)
2361 (delete-overlay ov)
2362 ov))
2363
2364(defvar mdw-point-overlay (mdw-configure-point-overlay)
2365 "An overlay used for showing where point is in the selected window.")
2366(defun mdw-reconfigure-point-overlay ()
2367 (interactive)
2368 (setq mdw-point-overlay (mdw-configure-point-overlay)))
2369
2370(defun mdw-remove-point-overlay ()
2371 "Remove the current-point overlay."
2372 (delete-overlay mdw-point-overlay))
2373
2374(defun mdw-update-point-overlay ()
2375 "Mark the current point position with an overlay."
2376 (if (not mdw-point-overlay-mode)
2377 (mdw-remove-point-overlay)
2378 (overlay-put mdw-point-overlay 'window (selected-window))
2379 (move-overlay mdw-point-overlay
2380 (line-beginning-position)
2381 (+ (line-end-position) 1))))
2382
2383(defvar mdw-point-overlay-buffers nil
2384 "List of buffers using `mdw-point-overlay-mode'.")
2385
2386(define-minor-mode mdw-point-overlay-mode
2387 "Indicate current line with an overlay."
2388 :global nil
2389 (let ((buffer (current-buffer)))
2390 (setq mdw-point-overlay-buffers
2391 (cl-mapcan (lambda (buf)
2392 (if (and (buffer-live-p buf)
2393 (not (eq buf buffer)))
2394 (list buf)))
2395 mdw-point-overlay-buffers))
2396 (if mdw-point-overlay-mode
2397 (setq mdw-point-overlay-buffers
2398 (cons buffer mdw-point-overlay-buffers))))
2399 (cond (mdw-point-overlay-buffers
2400 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
2401 (add-hook 'post-command-hook 'mdw-update-point-overlay))
2402 (t
2403 (mdw-remove-point-overlay)
2404 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
2405 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
2406
2407(define-globalized-minor-mode mdw-global-point-overlay-mode
2408 mdw-point-overlay-mode
2409 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
2410
2411(defvar mdw-terminal-title-alist nil)
2412(defun mdw-update-terminal-title ()
2413 (when (let ((term (frame-parameter nil 'tty-type)))
2414 (and term (string-match "^xterm" term)))
2415 (let* ((tty (frame-parameter nil 'tty))
2416 (old (assoc tty mdw-terminal-title-alist))
2417 (new (format-mode-line frame-title-format)))
2418 (unless (and old (equal (cdr old) new))
2419 (if old (rplacd old new)
2420 (setq mdw-terminal-title-alist
2421 (cons (cons tty new) mdw-terminal-title-alist)))
2422 (send-string-to-terminal (concat "\e]2;" new "\e\\"))))))
2423
2424(add-hook 'post-command-hook 'mdw-update-terminal-title)
2425
2426;;;--------------------------------------------------------------------------
2427;;; Ediff hacking.
2428
2429(defvar mdw-ediff-previous-windows)
2430(defun mdw-ediff-setup ()
2431 (setq mdw-ediff-previous-windows (current-window-configuration)))
2432(defun mdw-ediff-suspend-or-quit ()
2433 (set-window-configuration mdw-ediff-previous-windows))
2434(add-hook 'ediff-before-setup-hook 'mdw-ediff-setup)
2435(add-hook 'ediff-quit-hook 'mdw-ediff-suspend-or-quit t)
2436(add-hook 'ediff-suspend-hook 'mdw-ediff-suspend-or-quit t)
2437
2438;;;--------------------------------------------------------------------------
2439;;; C programming configuration.
2440
2441;; Make C indentation nice.
2442
2443(defun mdw-c-lineup-arglist (langelem)
2444 "Hack for DWIMmery in c-lineup-arglist."
2445 (if (save-excursion
2446 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
2447 0
2448 (c-lineup-arglist langelem)))
2449
2450(defun mdw-c-indent-extern-mumble (langelem)
2451 "Indent `extern \"...\" {' lines."
2452 (save-excursion
2453 (back-to-indentation)
2454 (if (looking-at
2455 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
2456 c-basic-offset
2457 nil)))
2458
2459(defun mdw-c-indent-arglist-nested (langelem)
2460 "Indent continued argument lists.
2461If we've nested more than one argument list, then only introduce a single
2462indentation anyway."
2463 (let ((context c-syntactic-context)
2464 (pos (c-langelem-2nd-pos c-syntactic-element))
2465 (should-indent-p t))
2466 (while (and context
2467 (eq (caar context) 'arglist-cont-nonempty))
2468 (when (and (= (cl-caddr (pop context)) pos)
2469 context
2470 (memq (caar context) '(arglist-intro
2471 arglist-cont-nonempty)))
2472 (setq should-indent-p nil)))
2473 (if should-indent-p '+ 0)))
2474
2475(defvar mdw-define-c-styles-hook nil
2476 "Hook run when `cc-mode' starts up to define styles.")
2477
2478(defun mdw-merge-style-alists (first second)
2479 (let ((output nil))
2480 (dolist (item first)
2481 (let ((key (car item)) (value (cdr item)))
2482 (if (let* ((key-name (symbol-name key))
2483 (key-len (length key-name)))
2484 (and (>= key-len 6)
2485 (string= (substring key-name (- key-len 6)) "-alist")))
2486 (push (cons key
2487 (mdw-merge-style-alists value
2488 (cdr (assoc key second))))
2489 output)
2490 (push item output))))
2491 (dolist (item second)
2492 (unless (assoc (car item) first)
2493 (push item output)))
2494 (nreverse output)))
2495
2496(cl-defmacro mdw-define-c-style (name (&optional parent) &rest assocs)
2497 "Define a C style, called NAME (a symbol) based on PARENT, setting ASSOCs.
2498A function, named `mdw-define-c-style/NAME', is defined to actually install
2499the style using `c-add-style', and added to the hook
2500`mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
2501set."
2502 (declare (indent defun))
2503 (let* ((name-string (symbol-name name))
2504 (var (intern (concat "mdw-c-style/" name-string)))
2505 (func (intern (concat "mdw-define-c-style/" name-string))))
2506 `(progn
2507 (setq ,var
2508 ,(if (null parent)
2509 `',assocs
2510 (let ((parent-list (intern (concat "mdw-c-style/"
2511 (symbol-name parent)))))
2512 `(mdw-merge-style-alists ',assocs ,parent-list))))
2513 (defun ,func () (c-add-style ,name-string ,var))
2514 (and (featurep 'cc-mode) (,func))
2515 (add-hook 'mdw-define-c-styles-hook ',func)
2516 ',name)))
2517
2518(eval-after-load "cc-mode"
2519 '(run-hooks 'mdw-define-c-styles-hook))
2520
2521(mdw-define-c-style mdw-c ()
2522 (c-basic-offset . 2)
2523 (comment-column . 40)
2524 (c-class-key . "class")
2525 (c-backslash-column . 72)
2526 (c-label-minimum-indentation . 0)
2527 (c-indent-comments-syntactically-p t)
2528 (c-indent-comment-alist (end-block . (column . nil))
2529 (cpp-end-block . (column . nil))
2530 (other . (column . nil)))
2531 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
2532 (defun-open . (add 0 c-indent-one-line-block))
2533 (arglist-cont-nonempty . mdw-c-lineup-arglist)
2534 (topmost-intro . mdw-c-indent-extern-mumble)
2535 (cpp-define-intro . 0)
2536 (knr-argdecl . 0)
2537 (inextern-lang . [0])
2538 (label . 0)
2539 (case-label . +)
2540 (access-label . -)
2541 (inclass . +)
2542 (inline-open . ++)
2543 (statement-cont . +)
2544 (statement-case-intro . +)))
2545
2546(mdw-define-c-style mdw-trustonic-c (mdw-c)
2547 (c-basic-offset . 4)
2548 (c-offsets-alist (access-label . -2)))
2549
2550(mdw-define-c-style mdw-trustonic-alec-c (mdw-trustonic-c)
2551 (comment-column . 0)
2552 (c-indent-comment-alist (anchored-comment . (column . 0))
2553 (end-block . (space . 1))
2554 (cpp-end-block . (space . 1))
2555 (other . (space . 1)))
2556 (c-offsets-alist (arglist-cont-nonempty . mdw-c-indent-arglist-nested)))
2557
2558(defun mdw-set-default-c-style (modes style)
2559 "Update the default CC Mode style for MODES to be STYLE.
2560
2561MODES may be a list of major mode names or a singleton. STYLE is a style
2562name, as a symbol."
2563 (let ((modes (if (listp modes) modes (list modes)))
2564 (style (symbol-name style)))
2565 (setq c-default-style
2566 (append (mapcar (lambda (mode)
2567 (cons mode style))
2568 modes)
2569 (cl-remove-if (lambda (assoc)
2570 (memq (car assoc) modes))
2571 (if (listp c-default-style)
2572 c-default-style
2573 (list (cons 'other
2574 c-default-style))))))))
2575(setq c-default-style "mdw-c")
2576
2577(mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
2578
2579(defvar mdw-c-comment-fill-prefix
2580 `((,(concat "\\([ \t]*/?\\)"
2581 "\\(\\*\\|//\\)"
2582 "\\([ \t]*\\)"
2583 "\\([A-Za-z]+:[ \t]*\\)?"
2584 mdw-hanging-indents)
2585 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
2586 "Fill prefix matching C comments (both kinds).")
2587
2588(defun mdw-fontify-c-and-c++ ()
2589
2590 ;; Fiddle with some syntax codes.
2591 (modify-syntax-entry ?* ". 23")
2592 (modify-syntax-entry ?/ ". 124b")
2593 (modify-syntax-entry ?\n "> b")
2594
2595 ;; Other stuff.
2596 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2597
2598 ;; Now define things to be fontified.
2599 (make-local-variable 'font-lock-keywords)
2600 (let ((c-keywords
2601 (mdw-regexps "alignas" ;C11 macro, C++11
2602 "alignof" ;C++11
2603 "and" ;C++, C95 macro
2604 "and_eq" ;C++, C95 macro
2605 "asm" ;K&R, C++, GCC
2606 "atomic" ;C11 macro, C++11 template type
2607 "auto" ;K&R, C89
2608 "bitand" ;C++, C95 macro
2609 "bitor" ;C++, C95 macro
2610 "bool" ;C++, C99 macro
2611 "break" ;K&R, C89
2612 "case" ;K&R, C89
2613 "catch" ;C++
2614 "char" ;K&R, C89
2615 "char16_t" ;C++11, C11 library type
2616 "char32_t" ;C++11, C11 library type
2617 "class" ;C++
2618 "complex" ;C99 macro, C++ template type
2619 "compl" ;C++, C95 macro
2620 "const" ;C89
2621 "constexpr" ;C++11
2622 "const_cast" ;C++
2623 "continue" ;K&R, C89
2624 "decltype" ;C++11
2625 "defined" ;C89 preprocessor
2626 "default" ;K&R, C89
2627 "delete" ;C++
2628 "do" ;K&R, C89
2629 "double" ;K&R, C89
2630 "dynamic_cast" ;C++
2631 "else" ;K&R, C89
2632 ;; "entry" ;K&R -- never used
2633 "enum" ;C89
2634 "explicit" ;C++
2635 "export" ;C++
2636 "extern" ;K&R, C89
2637 "float" ;K&R, C89
2638 "for" ;K&R, C89
2639 ;; "fortran" ;K&R
2640 "friend" ;C++
2641 "goto" ;K&R, C89
2642 "if" ;K&R, C89
2643 "imaginary" ;C99 macro
2644 "inline" ;C++, C99, GCC
2645 "int" ;K&R, C89
2646 "long" ;K&R, C89
2647 "mutable" ;C++
2648 "namespace" ;C++
2649 "new" ;C++
2650 "noexcept" ;C++11
2651 "noreturn" ;C11 macro
2652 "not" ;C++, C95 macro
2653 "not_eq" ;C++, C95 macro
2654 "nullptr" ;C++11
2655 "operator" ;C++
2656 "or" ;C++, C95 macro
2657 "or_eq" ;C++, C95 macro
2658 "private" ;C++
2659 "protected" ;C++
2660 "public" ;C++
2661 "register" ;K&R, C89
2662 "reinterpret_cast" ;C++
2663 "restrict" ;C99
2664 "return" ;K&R, C89
2665 "short" ;K&R, C89
2666 "signed" ;C89
2667 "sizeof" ;K&R, C89
2668 "static" ;K&R, C89
2669 "static_assert" ;C11 macro, C++11
2670 "static_cast" ;C++
2671 "struct" ;K&R, C89
2672 "switch" ;K&R, C89
2673 "template" ;C++
2674 "throw" ;C++
2675 "try" ;C++
2676 "thread_local" ;C11 macro, C++11
2677 "typedef" ;C89
2678 "typeid" ;C++
2679 "typeof" ;GCC
2680 "typename" ;C++
2681 "union" ;K&R, C89
2682 "unsigned" ;K&R, C89
2683 "using" ;C++
2684 "virtual" ;C++
2685 "void" ;C89
2686 "volatile" ;C89
2687 "wchar_t" ;C++, C89 library type
2688 "while" ;K&R, C89
2689 "xor" ;C++, C95 macro
2690 "xor_eq" ;C++, C95 macro
2691 "_Alignas" ;C11
2692 "_Alignof" ;C11
2693 "_Atomic" ;C11
2694 "_Bool" ;C99
2695 "_Complex" ;C99
2696 "_Generic" ;C11
2697 "_Imaginary" ;C99
2698 "_Noreturn" ;C11
2699 "_Pragma" ;C99 preprocessor
2700 "_Static_assert" ;C11
2701 "_Thread_local" ;C11
2702 "__alignof__" ;GCC
2703 "__asm__" ;GCC
2704 "__attribute__" ;GCC
2705 "__complex__" ;GCC
2706 "__const__" ;GCC
2707 "__extension__" ;GCC
2708 "__imag__" ;GCC
2709 "__inline__" ;GCC
2710 "__label__" ;GCC
2711 "__real__" ;GCC
2712 "__signed__" ;GCC
2713 "__typeof__" ;GCC
2714 "__volatile__" ;GCC
2715 ))
2716 (c-builtins
2717 (mdw-regexps "false" ;C++, C99 macro
2718 "this" ;C++
2719 "true" ;C++, C99 macro
2720 ))
2721 (preprocessor-keywords
2722 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2723 "ident" "if" "ifdef" "ifndef" "import" "include"
2724 "line" "pragma" "unassert" "undef" "warning"))
2725 (objc-keywords
2726 (mdw-regexps "class" "defs" "encode" "end" "implementation"
2727 "interface" "private" "protected" "protocol" "public"
2728 "selector")))
2729
2730 (setq font-lock-keywords
2731 (list
2732
2733 ;; Fontify include files as strings.
2734 (list (concat "^[ \t]*\\#[ \t]*"
2735 "\\(include\\|import\\)"
2736 "[ \t]*\\(<[^>]+>?\\)")
2737 '(2 font-lock-string-face))
2738
2739 ;; Preprocessor directives are `references'?.
2740 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2741 preprocessor-keywords
2742 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2743 '(1 font-lock-keyword-face))
2744
2745 ;; Handle the keywords defined above.
2746 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
2747 '(0 font-lock-keyword-face))
2748
2749 (list (concat "\\<\\(" c-keywords "\\)\\>")
2750 '(0 font-lock-keyword-face))
2751
2752 (list (concat "\\<\\(" c-builtins "\\)\\>")
2753 '(0 font-lock-variable-name-face))
2754
2755 ;; Handle numbers too.
2756 ;;
2757 ;; This looks strange, I know. It corresponds to the
2758 ;; preprocessor's idea of what a number looks like, rather than
2759 ;; anything sensible.
2760 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2761 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2762 '(0 mdw-number-face))
2763
2764 ;; And anything else is punctuation.
2765 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2766 '(0 mdw-punct-face))))))
2767
2768(define-derived-mode sod-mode c-mode "Sod"
2769 "Major mode for editing Sod code.")
2770(push '("\\.sod$" . sod-mode) auto-mode-alist)
2771
2772(dolist (hook '(c-mode-hook objc-mode-hook c++-mode-hook))
2773 (add-hook hook 'mdw-misc-mode-config t)
2774 (add-hook hook 'mdw-fontify-c-and-c++ t))
2775
2776;;;--------------------------------------------------------------------------
2777;;; AP calc mode.
2778
2779(define-derived-mode apcalc-mode c-mode "AP Calc"
2780 "Major mode for editing Calc code.")
2781
2782(defun mdw-fontify-apcalc ()
2783
2784 ;; Fiddle with some syntax codes.
2785 (modify-syntax-entry ?* ". 23")
2786 (modify-syntax-entry ?/ ". 14")
2787
2788 ;; Other stuff.
2789 (setq comment-start "/* ")
2790 (setq comment-end " */")
2791 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2792
2793 ;; Now define things to be fontified.
2794 (make-local-variable 'font-lock-keywords)
2795 (let ((c-keywords
2796 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
2797 "do" "else" "exit" "for" "global" "goto" "help" "if"
2798 "local" "mat" "obj" "print" "quit" "read" "return"
2799 "show" "static" "switch" "while" "write")))
2800
2801 (setq font-lock-keywords
2802 (list
2803
2804 ;; Handle the keywords defined above.
2805 (list (concat "\\<\\(" c-keywords "\\)\\>")
2806 '(0 font-lock-keyword-face))
2807
2808 ;; Handle numbers too.
2809 ;;
2810 ;; This looks strange, I know. It corresponds to the
2811 ;; preprocessor's idea of what a number looks like, rather than
2812 ;; anything sensible.
2813 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2814 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2815 '(0 mdw-number-face))
2816
2817 ;; And anything else is punctuation.
2818 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2819 '(0 mdw-punct-face))))))
2820
2821(progn
2822 (add-hook 'apcalc-mode-hook 'mdw-misc-mode-config t)
2823 (add-hook 'apcalc-mode-hook 'mdw-fontify-apcalc t))
2824
2825;;;--------------------------------------------------------------------------
2826;;; Java programming configuration.
2827
2828;; Make indentation nice.
2829
2830(mdw-define-c-style mdw-java ()
2831 (c-basic-offset . 2)
2832 (c-backslash-column . 72)
2833 (c-offsets-alist (substatement-open . 0)
2834 (label . +)
2835 (case-label . +)
2836 (access-label . 0)
2837 (inclass . +)
2838 (statement-case-intro . +)))
2839(mdw-set-default-c-style 'java-mode 'mdw-java)
2840
2841;; Declare Java fontification style.
2842
2843(defun mdw-fontify-java ()
2844
2845 ;; Fiddle with some syntax codes.
2846 (modify-syntax-entry ?@ ".")
2847 (modify-syntax-entry ?@ "." font-lock-syntax-table)
2848
2849 ;; Other stuff.
2850 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2851
2852 ;; Now define things to be fontified.
2853 (make-local-variable 'font-lock-keywords)
2854 (let ((java-keywords
2855 (mdw-regexps "abstract" "assert"
2856 "boolean" "break" "byte"
2857 "case" "catch" "char" "class" "const" "continue"
2858 "default" "do" "double"
2859 "else" "enum" "extends"
2860 "final" "finally" "float" "for"
2861 "goto"
2862 "if" "implements" "import" "instanceof" "int"
2863 "interface"
2864 "long"
2865 "native" "new"
2866 "package" "private" "protected" "public"
2867 "return"
2868 "short" "static" "strictfp" "switch" "synchronized"
2869 "throw" "throws" "transient" "try"
2870 "void" "volatile"
2871 "while"))
2872
2873 (java-builtins
2874 (mdw-regexps "false" "null" "super" "this" "true")))
2875
2876 (setq font-lock-keywords
2877 (list
2878
2879 ;; Handle the keywords defined above.
2880 (list (concat "\\<\\(" java-keywords "\\)\\>")
2881 '(0 font-lock-keyword-face))
2882
2883 ;; Handle the magic builtins defined above.
2884 (list (concat "\\<\\(" java-builtins "\\)\\>")
2885 '(0 font-lock-variable-name-face))
2886
2887 ;; Handle numbers too.
2888 ;;
2889 ;; The following isn't quite right, but it's close enough.
2890 (list (concat "\\<\\("
2891 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2892 "[0-9]+\\(\\.[0-9]*\\)?"
2893 "\\([eE][-+]?[0-9]+\\)?\\)"
2894 "[lLfFdD]?")
2895 '(0 mdw-number-face))
2896
2897 ;; And anything else is punctuation.
2898 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2899 '(0 mdw-punct-face))))))
2900
2901(progn
2902 (add-hook 'java-mode-hook 'mdw-misc-mode-config t)
2903 (add-hook 'java-mode-hook 'mdw-fontify-java t))
2904
2905;;;--------------------------------------------------------------------------
2906;;; Javascript programming configuration.
2907
2908(defun mdw-javascript-style ()
2909 (setq js-indent-level 2)
2910 (setq js-expr-indent-offset 0))
2911
2912(defun mdw-fontify-javascript ()
2913
2914 ;; Other stuff.
2915 (mdw-javascript-style)
2916 (setq js-auto-indent-flag t)
2917
2918 ;; Now define things to be fontified.
2919 (make-local-variable 'font-lock-keywords)
2920 (let ((javascript-keywords
2921 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
2922 "char" "class" "const" "continue" "debugger" "default"
2923 "delete" "do" "double" "else" "enum" "export" "extends"
2924 "final" "finally" "float" "for" "function" "goto" "if"
2925 "implements" "import" "in" "instanceof" "int"
2926 "interface" "let" "long" "native" "new" "package"
2927 "private" "protected" "public" "return" "short"
2928 "static" "super" "switch" "synchronized" "throw"
2929 "throws" "transient" "try" "typeof" "var" "void"
2930 "volatile" "while" "with" "yield"))
2931 (javascript-builtins
2932 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
2933 "arguments" "this")))
2934
2935 (setq font-lock-keywords
2936 (list
2937
2938 ;; Handle the keywords defined above.
2939 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
2940 '(0 font-lock-keyword-face))
2941
2942 ;; Handle the predefined builtins defined above.
2943 (list (concat "\\_<\\(" javascript-builtins "\\)\\_>")
2944 '(0 font-lock-variable-name-face))
2945
2946 ;; Handle numbers too.
2947 ;;
2948 ;; The following isn't quite right, but it's close enough.
2949 (list (concat "\\_<\\("
2950 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2951 "[0-9]+\\(\\.[0-9]*\\)?"
2952 "\\([eE][-+]?[0-9]+\\)?\\)"
2953 "[lLfFdD]?")
2954 '(0 mdw-number-face))
2955
2956 ;; And anything else is punctuation.
2957 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2958 '(0 mdw-punct-face))))))
2959
2960(progn
2961 (add-hook 'js-mode-hook 'mdw-misc-mode-config t)
2962 (add-hook 'js-mode-hook 'mdw-fontify-javascript t))
2963
2964;;;--------------------------------------------------------------------------
2965;;; Scala programming configuration.
2966
2967(defun mdw-fontify-scala ()
2968
2969 ;; Comment filling.
2970 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2971
2972 ;; Define things to be fontified.
2973 (make-local-variable 'font-lock-keywords)
2974 (let ((scala-keywords
2975 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
2976 "extends" "final" "finally" "for" "forSome" "if"
2977 "implicit" "import" "lazy" "match" "new" "object"
2978 "override" "package" "private" "protected" "return"
2979 "sealed" "throw" "trait" "try" "type" "val"
2980 "var" "while" "with" "yield"))
2981 (scala-constants
2982 (mdw-regexps "false" "null" "super" "this" "true"))
2983 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
2984
2985 (setq font-lock-keywords
2986 (list
2987
2988 ;; Magical identifiers between backticks.
2989 (list (concat "`\\([^`]+\\)`")
2990 '(1 font-lock-variable-name-face))
2991
2992 ;; Handle the keywords defined above.
2993 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
2994 '(0 font-lock-keyword-face))
2995
2996 ;; Handle the constants defined above.
2997 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
2998 '(0 font-lock-variable-name-face))
2999
3000 ;; Magical identifiers between backticks.
3001 (list (concat "`\\([^`]+\\)`")
3002 '(1 font-lock-variable-name-face))
3003
3004 ;; Handle numbers too.
3005 ;;
3006 ;; As usual, not quite right.
3007 (list (concat "\\_<\\("
3008 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
3009 "[0-9]+\\(\\.[0-9]*\\)?"
3010 "\\([eE][-+]?[0-9]+\\)?\\)"
3011 "[lLfFdD]?")
3012 '(0 mdw-number-face))
3013
3014 ;; And everything else is punctuation.
3015 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3016 '(0 mdw-punct-face)))
3017
3018 font-lock-syntactic-keywords
3019 (list
3020
3021 ;; Single quotes around characters. But not when used to quote
3022 ;; symbol names. Ugh.
3023 (list (concat "\\('\\)"
3024 "\\(" "."
3025 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
3026 "u+" "[0-9a-fA-F]\\{4\\}"
3027 "\\|" "\\\\" "[0-7]\\{1,3\\}"
3028 "\\|" "\\\\" "." "\\)"
3029 "\\('\\)")
3030 '(1 "\"")
3031 '(4 "\""))))))
3032
3033(progn
3034 (add-hook 'scala-mode-hook 'mdw-misc-mode-config t)
3035 (add-hook 'scala-mode-hook 'mdw-fontify-scala t))
3036
3037;;;--------------------------------------------------------------------------
3038;;; C# programming configuration.
3039
3040;; Make indentation nice.
3041
3042(mdw-define-c-style mdw-csharp ()
3043 (c-basic-offset . 2)
3044 (c-backslash-column . 72)
3045 (c-offsets-alist (substatement-open . 0)
3046 (label . 0)
3047 (case-label . +)
3048 (access-label . 0)
3049 (inclass . +)
3050 (statement-case-intro . +)))
3051(mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
3052
3053;; Declare C# fontification style.
3054
3055(defun mdw-fontify-csharp ()
3056
3057 ;; Other stuff.
3058 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
3059
3060 ;; Now define things to be fontified.
3061 (make-local-variable 'font-lock-keywords)
3062 (let ((csharp-keywords
3063 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
3064 "char" "checked" "class" "const" "continue" "decimal"
3065 "default" "delegate" "do" "double" "else" "enum"
3066 "event" "explicit" "extern" "finally" "fixed" "float"
3067 "for" "foreach" "goto" "if" "implicit" "in" "int"
3068 "interface" "internal" "is" "lock" "long" "namespace"
3069 "new" "object" "operator" "out" "override" "params"
3070 "private" "protected" "public" "readonly" "ref"
3071 "return" "sbyte" "sealed" "short" "sizeof"
3072 "stackalloc" "static" "string" "struct" "switch"
3073 "throw" "try" "typeof" "uint" "ulong" "unchecked"
3074 "unsafe" "ushort" "using" "virtual" "void" "volatile"
3075 "while" "yield"))
3076
3077 (csharp-builtins
3078 (mdw-regexps "base" "false" "null" "this" "true")))
3079
3080 (setq font-lock-keywords
3081 (list
3082
3083 ;; Handle the keywords defined above.
3084 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
3085 '(0 font-lock-keyword-face))
3086
3087 ;; Handle the magic builtins defined above.
3088 (list (concat "\\<\\(" csharp-builtins "\\)\\>")
3089 '(0 font-lock-variable-name-face))
3090
3091 ;; Handle numbers too.
3092 ;;
3093 ;; The following isn't quite right, but it's close enough.
3094 (list (concat "\\<\\("
3095 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
3096 "[0-9]+\\(\\.[0-9]*\\)?"
3097 "\\([eE][-+]?[0-9]+\\)?\\)"
3098 "[lLfFdD]?")
3099 '(0 mdw-number-face))
3100
3101 ;; And anything else is punctuation.
3102 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3103 '(0 mdw-punct-face))))))
3104
3105(define-derived-mode csharp-mode java-mode "C#"
3106 "Major mode for editing C# code.")
3107
3108(add-hook 'csharp-mode-hook 'mdw-fontify-csharp t)
3109
3110;;;--------------------------------------------------------------------------
3111;;; F# programming configuration.
3112
3113(setq fsharp-indent-offset 2)
3114
3115(defun mdw-fontify-fsharp ()
3116
3117 (let ((punct "=<>+-*/|&%!@?"))
3118 (cl-do ((i 0 (1+ i)))
3119 ((>= i (length punct)))
3120 (modify-syntax-entry (aref punct i) ".")))
3121
3122 (modify-syntax-entry ?_ "_")
3123 (modify-syntax-entry ?( "(")
3124 (modify-syntax-entry ?) ")")
3125
3126 (setq indent-tabs-mode nil)
3127
3128 (let ((fsharp-keywords
3129 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
3130 "begin" "break"
3131 "checked" "class" "component" "const" "constraint"
3132 "constructor" "continue"
3133 "default" "delegate" "do" "done" "downcast" "downto"
3134 "eager" "elif" "else" "end" "exception" "extern"
3135 "finally" "fixed" "for" "fori" "fun" "function"
3136 "functor"
3137 "global"
3138 "if" "in" "include" "inherit" "inline" "interface"
3139 "internal"
3140 "lazy" "let"
3141 "match" "measure" "member" "method" "mixin" "module"
3142 "mutable"
3143 "namespace" "new"
3144 "object" "of" "open" "or" "override"
3145 "parallel" "params" "private" "process" "protected"
3146 "public" "pure"
3147 "rec" "recursive" "return"
3148 "sealed" "sig" "static" "struct"
3149 "tailcall" "then" "to" "trait" "try" "type"
3150 "upcast" "use"
3151 "val" "virtual" "void" "volatile"
3152 "when" "while" "with"
3153 "yield"))
3154
3155 (fsharp-builtins
3156 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
3157 "base" "false" "null" "true"))
3158
3159 (bang-keywords
3160 (mdw-regexps "do" "let" "return" "use" "yield"))
3161
3162 (preprocessor-keywords
3163 (mdw-regexps "if" "indent" "else" "endif")))
3164
3165 (setq font-lock-keywords
3166 (list (list (concat "\\(^\\|[^\"]\\)"
3167 "\\(" "(\\*"
3168 "[^*]*\\*+"
3169 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
3170 ")"
3171 "\\|"
3172 "//.*"
3173 "\\)")
3174 '(2 font-lock-comment-face))
3175
3176 (list (concat "'" "\\("
3177 "\\\\"
3178 "\\(" "[ntbr'\\]"
3179 "\\|" "[0-9][0-9][0-9]"
3180 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
3181 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
3182 "\\)"
3183 "\\|"
3184 "." "\\)" "'"
3185 "\\|"
3186 "\"" "[^\"\\]*"
3187 "\\(" "\\\\" "\\(.\\|\n\\)"
3188 "[^\"\\]*" "\\)*"
3189 "\\(\"\\|\\'\\)")
3190 '(0 font-lock-string-face))
3191
3192 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
3193 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
3194 "\\|"
3195 "\\_<\\(" fsharp-keywords "\\)\\_>")
3196 '(0 font-lock-keyword-face))
3197 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
3198 '(0 font-lock-variable-name-face))
3199
3200 (list (concat "\\_<"
3201 "\\(" "0[bB][01]+" "\\|"
3202 "0[oO][0-7]+" "\\|"
3203 "0[xX][0-9a-fA-F]+" "\\)"
3204 "\\(" "lf\\|LF" "\\|"
3205 "[uU]?[ysnlL]?" "\\)"
3206 "\\|"
3207 "\\_<"
3208 "[0-9]+" "\\("
3209 "[mMQRZING]"
3210 "\\|"
3211 "\\(\\.[0-9]*\\)?"
3212 "\\([eE][-+]?[0-9]+\\)?"
3213 "[fFmM]?"
3214 "\\|"
3215 "[uU]?[ysnlL]?"
3216 "\\)")
3217 '(0 mdw-number-face))
3218
3219 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3220 '(0 mdw-punct-face))))))
3221
3222(defun mdw-fontify-inferior-fsharp ()
3223 (mdw-fontify-fsharp)
3224 (setq font-lock-keywords
3225 (append (list (list "^[#-]" '(0 font-lock-comment-face))
3226 (list "^>" '(0 font-lock-keyword-face)))
3227 font-lock-keywords)))
3228
3229(progn
3230 (add-hook 'fsharp-mode-hook 'mdw-misc-mode-config t)
3231 (add-hook 'fsharp-mode-hook 'mdw-fontify-fsharp t)
3232 (add-hook 'inferior-fsharp-mode-hooks 'mdw-fontify-inferior-fsharp t))
3233
3234;;;--------------------------------------------------------------------------
3235;;; Go programming configuration.
3236
3237(defun mdw-fontify-go ()
3238
3239 (make-local-variable 'font-lock-keywords)
3240 (let ((go-keywords
3241 (mdw-regexps "break" "case" "chan" "const" "continue"
3242 "default" "defer" "else" "fallthrough" "for"
3243 "func" "go" "goto" "if" "import"
3244 "interface" "map" "package" "range" "return"
3245 "select" "struct" "switch" "type" "var"))
3246 (go-intrinsics
3247 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
3248 "float32" "float64" "int" "uint8" "int16" "int32"
3249 "int64" "rune" "string" "uint" "uint8" "uint16"
3250 "uint32" "uint64" "uintptr" "void"
3251 "false" "iota" "nil" "true"
3252 "init" "main"
3253 "append" "cap" "copy" "delete" "imag" "len" "make"
3254 "new" "panic" "real" "recover")))
3255
3256 (setq font-lock-keywords
3257 (list
3258
3259 ;; Handle the keywords defined above.
3260 (list (concat "\\<\\(" go-keywords "\\)\\>")
3261 '(0 font-lock-keyword-face))
3262 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
3263 '(0 font-lock-variable-name-face))
3264
3265 ;; Strings and characters.
3266 (list (concat "'"
3267 "\\(" "[^\\']" "\\|"
3268 "\\\\"
3269 "\\(" "[abfnrtv\\'\"]" "\\|"
3270 "[0-7]\\{3\\}" "\\|"
3271 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
3272 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
3273 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
3274 "'"
3275 "\\|"
3276 "\""
3277 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
3278 "\\(\"\\|$\\)"
3279 "\\|"
3280 "`" "[^`]+" "`")
3281 '(0 font-lock-string-face))
3282
3283 ;; Handle numbers too.
3284 ;;
3285 ;; The following isn't quite right, but it's close enough.
3286 (list (concat "\\<\\("
3287 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
3288 "[0-9]+\\(\\.[0-9]*\\)?"
3289 "\\([eE][-+]?[0-9]+\\)?\\)")
3290 '(0 mdw-number-face))
3291
3292 ;; And anything else is punctuation.
3293 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3294 '(0 mdw-punct-face))))))
3295(progn
3296 (add-hook 'go-mode-hook 'mdw-misc-mode-config t)
3297 (add-hook 'go-mode-hook 'mdw-fontify-go t))
3298
3299;;;--------------------------------------------------------------------------
3300;;; Rust programming configuration.
3301
3302(setq-default rust-indent-offset 2)
3303
3304(defun mdw-self-insert-and-indent (count)
3305 (interactive "p")
3306 (self-insert-command count)
3307 (indent-according-to-mode))
3308
3309(defun mdw-fontify-rust ()
3310
3311 ;; Hack syntax categories.
3312 (modify-syntax-entry ?$ ".")
3313 (modify-syntax-entry ?% ".")
3314 (modify-syntax-entry ?= ".")
3315
3316 ;; Fontify keywords and things.
3317 (make-local-variable 'font-lock-keywords)
3318 (let ((rust-keywords
3319 (mdw-regexps "abstract" "alignof" "as" "async" "await"
3320 "become" "box" "break"
3321 "const" "continue" "crate"
3322 "do" "dyn"
3323 "else" "enum" "extern"
3324 "final" "fn" "for"
3325 "if" "impl" "in"
3326 "let" "loop"
3327 "macro" "match" "mod" "move" "mut"
3328 "offsetof" "override"
3329 "priv" "proc" "pub" "pure"
3330 "ref" "return"
3331 "sizeof" "static" "struct" "super"
3332 "trait" "try" "type" "typeof"
3333 "union" "unsafe" "unsized" "use"
3334 "virtual"
3335 "where" "while"
3336 "yield"))
3337 (rust-builtins
3338 (mdw-regexps "array" "pointer" "slice" "tuple"
3339 "bool" "true" "false"
3340 "f32" "f64"
3341 "i8" "i16" "i32" "i64" "isize"
3342 "u8" "u16" "u32" "u64" "usize"
3343 "char" "str"
3344 "self" "Self")))
3345 (setq font-lock-keywords
3346 (list
3347
3348 ;; Handle the keywords defined above.
3349 (list (concat "\\_<\\(" rust-keywords "\\)\\_>")
3350 '(0 font-lock-keyword-face))
3351 (list (concat "\\_<\\(" rust-builtins "\\)\\_>")
3352 '(0 font-lock-variable-name-face))
3353
3354 ;; Handle numbers too.
3355 (list (concat "\\_<\\("
3356 "[0-9][0-9_]*"
3357 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
3358 "\\|" "\\.[0-9_]+"
3359 "\\)"
3360 "\\(f32\\|f64\\)?"
3361 "\\|" "\\(" "[0-9][0-9_]*"
3362 "\\|" "0x[0-9a-fA-F_]+"
3363 "\\|" "0o[0-7_]+"
3364 "\\|" "0b[01_]+"
3365 "\\)"
3366 "\\([ui]\\(8\\|16\\|32\\|64\\|size\\)\\)?"
3367 "\\)\\_>")
3368 '(0 mdw-number-face))
3369
3370 ;; And anything else is punctuation.
3371 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3372 '(0 mdw-punct-face)))
3373 font-lock-syntactic-face-function nil))
3374
3375 ;; Hack key bindings.
3376 (local-set-key [?{] 'mdw-self-insert-and-indent)
3377 (local-set-key [?}] 'mdw-self-insert-and-indent))
3378
3379(progn
3380 (add-hook 'rust-mode-hook 'mdw-misc-mode-config t)
3381 (add-hook 'rust-mode-hook 'mdw-fontify-rust t))
3382
3383;;;--------------------------------------------------------------------------
3384;;; Awk programming configuration.
3385
3386;; Make Awk indentation nice.
3387
3388(mdw-define-c-style mdw-awk ()
3389 (c-basic-offset . 2)
3390 (c-offsets-alist (substatement-open . 0)
3391 (c-backslash-column . 72)
3392 (statement-cont . 0)
3393 (statement-case-intro . +)))
3394(mdw-set-default-c-style 'awk-mode 'mdw-awk)
3395
3396;; Declare Awk fontification style.
3397
3398(defun mdw-fontify-awk ()
3399
3400 ;; Miscellaneous fiddling.
3401 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3402
3403 ;; Now define things to be fontified.
3404 (make-local-variable 'font-lock-keywords)
3405 (let ((c-keywords
3406 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
3407 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
3408 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
3409 "RSTART" "RLENGTH" "RT" "SUBSEP"
3410 "atan2" "break" "close" "continue" "cos" "delete"
3411 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
3412 "function" "gensub" "getline" "gsub" "if" "in"
3413 "index" "int" "length" "log" "match" "next" "rand"
3414 "return" "print" "printf" "sin" "split" "sprintf"
3415 "sqrt" "srand" "strftime" "sub" "substr" "system"
3416 "systime" "tolower" "toupper" "while")))
3417
3418 (setq font-lock-keywords
3419 (list
3420
3421 ;; Handle the keywords defined above.
3422 (list (concat "\\<\\(" c-keywords "\\)\\>")
3423 '(0 font-lock-keyword-face))
3424
3425 ;; Handle numbers too.
3426 ;;
3427 ;; The following isn't quite right, but it's close enough.
3428 (list (concat "\\<\\("
3429 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
3430 "[0-9]+\\(\\.[0-9]*\\)?"
3431 "\\([eE][-+]?[0-9]+\\)?\\)"
3432 "[uUlL]*")
3433 '(0 mdw-number-face))
3434
3435 ;; And anything else is punctuation.
3436 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3437 '(0 mdw-punct-face))))))
3438
3439(progn
3440 (add-hook 'awk-mode-hook 'mdw-misc-mode-config t)
3441 (add-hook 'awk-mode-hook 'mdw-fontify-awk t))
3442
3443;;;--------------------------------------------------------------------------
3444;;; Perl programming style.
3445
3446;; Perl indentation style.
3447
3448(setq-default perl-indent-level 2)
3449
3450(setq-default cperl-indent-level 2
3451 cperl-continued-statement-offset 2
3452 cperl-indent-region-fix-constructs nil
3453 cperl-continued-brace-offset 0
3454 cperl-brace-offset -2
3455 cperl-brace-imaginary-offset 0
3456 cperl-label-offset 0)
3457
3458;; Define perl fontification style.
3459
3460(defun mdw-fontify-perl ()
3461
3462 ;; Miscellaneous fiddling.
3463 (modify-syntax-entry ?$ "\\")
3464 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
3465 (modify-syntax-entry ?: "." font-lock-syntax-table)
3466 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3467 (setq auto-fill-function #'do-auto-fill)
3468
3469 ;; Now define fontification things.
3470 (make-local-variable 'font-lock-keywords)
3471 (let ((perl-keywords
3472 (mdw-regexps "and"
3473 "break"
3474 "cmp" "continue"
3475 "default" "do"
3476 "else" "elsif" "eq"
3477 "for" "foreach"
3478 "ge" "given" "gt" "goto"
3479 "if"
3480 "last" "le" "local" "lt"
3481 "my"
3482 "ne" "next"
3483 "or" "our"
3484 "package"
3485 "redo" "require" "return"
3486 "sub"
3487 "undef" "unless" "until" "use"
3488 "when" "while")))
3489
3490 (setq font-lock-keywords
3491 (list
3492
3493 ;; Set up the keywords defined above.
3494 (list (concat "\\<\\(" perl-keywords "\\)\\>")
3495 '(0 font-lock-keyword-face))
3496
3497 ;; At least numbers are simpler than C.
3498 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3499 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
3500 "\\([eE][-+]?[0-9_]+\\)?")
3501 '(0 mdw-number-face))
3502
3503 ;; And anything else is punctuation.
3504 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3505 '(0 mdw-punct-face))))))
3506
3507(defun perl-number-tests (&optional arg)
3508 "Assign consecutive numbers to lines containing `#t'. With ARG,
3509strip numbers instead."
3510 (interactive "P")
3511 (save-excursion
3512 (goto-char (point-min))
3513 (let ((i 0) (fmt (if arg "" " %4d")))
3514 (while (search-forward "#t" nil t)
3515 (delete-region (point) (line-end-position))
3516 (setq i (1+ i))
3517 (insert (format fmt i)))
3518 (goto-char (point-min))
3519 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
3520 (replace-match (format "\\1%d" i))))))
3521
3522(dolist (hook '(perl-mode-hook cperl-mode-hook))
3523 (add-hook hook 'mdw-misc-mode-config t)
3524 (add-hook hook 'mdw-fontify-perl t))
3525
3526;;;--------------------------------------------------------------------------
3527;;; Python programming style.
3528
3529(setq-default py-indent-offset 2
3530 python-indent 2
3531 python-indent-offset 2
3532 python-fill-docstring-style 'symmetric)
3533
3534(defun mdw-fontify-pythonic (keywords soft-keywords builtins)
3535
3536 ;; Miscellaneous fiddling.
3537 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3538 (setq indent-tabs-mode nil)
3539 (set (make-local-variable 'forward-sexp-function) nil)
3540
3541 ;; Now define fontification things.
3542 (make-local-variable 'font-lock-keywords)
3543 (setq font-lock-keywords
3544 (list
3545
3546 ;; Set up the keywords defined above.
3547 (list (concat "\\_<\\(" keywords "\\)\\_>")
3548 '(0 font-lock-keyword-face))
3549 (list (concat "\\(^\\|[^.]\\)\\_<\\(" soft-keywords "\\)\\_>")
3550 '(2 font-lock-keyword-face))
3551 (list (concat "\\(^\\|[^.]\\)\\_<\\(" builtins "\\)\\_>")
3552 '(2 font-lock-variable-name-face))
3553 (list (concat "\\_<\\(__\\(\\sw+\\|\\s_+\\)+__\\)\\_>")
3554 '(0 font-lock-variable-name-face))
3555
3556 ;; At least numbers are simpler than C.
3557 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO]?[0-7]+\\|[bB][01]+\\)\\|"
3558 "\\_<[0-9][0-9]*\\(\\.[0-9]*\\)?"
3559 "\\([eE][-+]?[0-9]+\\|[lL]\\)?")
3560 '(0 mdw-number-face))
3561
3562 ;; And anything else is punctuation.
3563 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3564 '(0 mdw-punct-face)))))
3565
3566;; Define Python fontification styles.
3567
3568(defun mdw-fontify-python ()
3569 (mdw-fontify-pythonic
3570 (mdw-regexps "and" "as" "assert" "async" "await"
3571 "break"
3572 "class" "continue"
3573 "def" "del"
3574 "elif" "else" "except" ;"exec"
3575 "finally" "for" "from"
3576 "global"
3577 "if" "import" "in" "is"
3578 "lambda"
3579 "nonlocal"
3580 "not"
3581 "or"
3582 "pass" ;"print"
3583 "raise" "return"
3584 "try" ;"type"
3585 "while" "with"
3586 "yield")
3587
3588 (mdw-regexps "case"
3589 "match")
3590
3591 (mdw-regexps "Ellipsis"
3592 "False"
3593 "None" "NotImplemented"
3594 "True"
3595 "__debug__"
3596
3597 "BaseException"
3598 "BaseExceptionGroup"
3599 "Exception"
3600 "StandardError"
3601 "ArithmeticError"
3602 "FloatingPointError"
3603 "OverflowError"
3604 "ZeroDivisionError"
3605 "AssertionError"
3606 "AttributeError"
3607 "BufferError"
3608 "EnvironmentError"
3609 "IOError"
3610 "OSError"
3611 "BlockingIOError"
3612 "ChildProcessError"
3613 "ConnectionError"
3614 "BrokenPipeError"
3615 "ConnectionAbortedError"
3616 "ConnectionRefusedError"
3617 "ConnectionResetError"
3618 "FileExistsError"
3619 "FileNotFoundError"
3620 "InterruptedError"
3621 "IsADirectoryError"
3622 "NotADirectoryError"
3623 "PermissionError"
3624 "TimeoutError"
3625 "EOFError"
3626 "ExceptionGroup"
3627 "ImportError"
3628 "ModuleNotFoundError"
3629 "LookupError"
3630 "IndexError"
3631 "KeyError"
3632 "MemoryError"
3633 "NameError"
3634 "UnboundLocalError"
3635 "ReferenceError"
3636 "RuntimeError"
3637 "NotImplementedError"
3638 "RecursionError"
3639 "SyntaxError"
3640 "IndentationError"
3641 "TabError"
3642 "SystemError"
3643 "TypeError"
3644 "ValueError"
3645 "UnicodeError"
3646 "UnicodeDecodeError"
3647 "UnicodeEncodeError"
3648 "UnicodeTranslateError"
3649 "StopIteration"
3650 "Warning"
3651 "BytesWarning"
3652 "DeprecationWarning"
3653 "EncodingWarning"
3654 "FutureWarning"
3655 "ImportWarning"
3656 "PendingDeprecationWarning"
3657 "ResourceWarning"
3658 "RuntimeWarning"
3659 "SyntaxWarning"
3660 "UnicodeWarning"
3661 "UserWarning"
3662 "GeneratorExit"
3663 "KeyboardInterrupt"
3664 "SystemExit"
3665
3666 "abs" "absolute_import" "aiter"
3667 "all" "anext" "any" "apply" "ascii"
3668 "basestring" "bin" "bool" "breakpoint"
3669 "buffer" "bytearray" "bytes"
3670 "callable" "coerce" "chr" "classmethod"
3671 "cmp" "compile" "complex"
3672 "delattr" "dict" "dir" "divmod"
3673 "enumerate" "eval" "exec" "execfile"
3674 "file" "filter" "float" "format" "frozenset"
3675 "getattr" "globals"
3676 "hasattr" "hash" "help" "hex"
3677 "id" "input" "int" "intern"
3678 "isinstance" "issubclass" "iter"
3679 "len" "list" "locals" "long"
3680 "map" "max" "memoryview" "min"
3681 "next"
3682 "object" "oct" "open" "ord"
3683 "pow" "print" "property"
3684 "range" "raw_input" "reduce" "reload"
3685 "repr" "reversed" "round"
3686 "set" "setattr" "slice" "sorted"
3687 "staticmethod" "str" "sum" "super"
3688 "tuple" "type"
3689 "unichr" "unicode"
3690 "vars"
3691 "xrange"
3692 "zip"
3693 "__import__")))
3694
3695(defun mdw-fontify-pyrex ()
3696 (mdw-fontify-pythonic
3697 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
3698 "ctypedef" "def" "del" "elif" "else" "enum" "except" "exec"
3699 "extern" "finally" "for" "from" "global" "if"
3700 "import" "in" "is" "lambda" "not" "or" "pass" "print"
3701 "property" "raise" "return" "struct" "try" "while" "with"
3702 "yield")
3703 ""
3704 ""))
3705
3706(define-derived-mode pyrex-mode python-mode "Pyrex"
3707 "Major mode for editing Pyrex source code")
3708(setq auto-mode-alist
3709 (append '(("\\.pyx$" . pyrex-mode)
3710 ("\\.pxd$" . pyrex-mode)
3711 ("\\.pxi$" . pyrex-mode))
3712 auto-mode-alist))
3713
3714(progn
3715 (add-hook 'python-mode-hook 'mdw-misc-mode-config t)
3716 (add-hook 'python-mode-hook 'mdw-fontify-python t)
3717 (add-hook 'pyrex-mode-hook 'mdw-fontify-pyrex t))
3718
3719;;;--------------------------------------------------------------------------
3720;;; Lua programming style.
3721
3722(setq-default lua-indent-level 2)
3723
3724(defun mdw-fontify-lua ()
3725
3726 ;; Miscellaneous fiddling.
3727 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3728
3729 ;; Now define fontification things.
3730 (make-local-variable 'font-lock-keywords)
3731 (let ((lua-keywords
3732 (mdw-regexps "and" "break" "do" "else" "elseif" "end"
3733 "false" "for" "function" "goto" "if" "in" "local"
3734 "nil" "not" "or" "repeat" "return" "then" "true"
3735 "until" "while")))
3736 (setq font-lock-keywords
3737 (list
3738
3739 ;; Set up the keywords defined above.
3740 (list (concat "\\_<\\(" lua-keywords "\\)\\_>")
3741 '(0 font-lock-keyword-face))
3742
3743 ;; At least numbers are simpler than C.
3744 (list (concat "\\_<\\(" "0[xX]"
3745 "\\(" "[0-9a-fA-F]+"
3746 "\\(\\.[0-9a-fA-F]*\\)?"
3747 "\\|" "\\.[0-9a-fA-F]+"
3748 "\\)"
3749 "\\([pP][-+]?[0-9]+\\)?"
3750 "\\|" "\\(" "[0-9]+"
3751 "\\(\\.[0-9]*\\)?"
3752 "\\|" "\\.[0-9]+"
3753 "\\)"
3754 "\\([eE][-+]?[0-9]+\\)?"
3755 "\\)")
3756 '(0 mdw-number-face))
3757
3758 ;; And anything else is punctuation.
3759 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3760 '(0 mdw-punct-face))))))
3761
3762(progn
3763 (add-hook 'lua-mode-hook 'mdw-misc-mode-config t)
3764 (add-hook 'lua-mode-hook 'mdw-fontify-lua t))
3765
3766;;;--------------------------------------------------------------------------
3767;;; Icon programming style.
3768
3769;; Icon indentation style.
3770
3771(setq-default icon-brace-offset 0
3772 icon-continued-brace-offset 0
3773 icon-continued-statement-offset 2
3774 icon-indent-level 2)
3775
3776;; Define Icon fontification style.
3777
3778(defun mdw-fontify-icon ()
3779
3780 ;; Miscellaneous fiddling.
3781 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3782
3783 ;; Now define fontification things.
3784 (make-local-variable 'font-lock-keywords)
3785 (let ((icon-keywords
3786 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
3787 "end" "every" "fail" "global" "if" "initial"
3788 "invocable" "link" "local" "next" "not" "of"
3789 "procedure" "record" "repeat" "return" "static"
3790 "suspend" "then" "to" "until" "while"))
3791 (preprocessor-keywords
3792 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
3793 "include" "line" "undef")))
3794 (setq font-lock-keywords
3795 (list
3796
3797 ;; Set up the keywords defined above.
3798 (list (concat "\\<\\(" icon-keywords "\\)\\>")
3799 '(0 font-lock-keyword-face))
3800
3801 ;; The things that Icon calls keywords.
3802 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
3803
3804 ;; At least numbers are simpler than C.
3805 (list (concat "\\<[0-9]+"
3806 "\\([rR][0-9a-zA-Z]+\\|"
3807 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
3808 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
3809 '(0 mdw-number-face))
3810
3811 ;; Preprocessor.
3812 (list (concat "^[ \t]*$[ \t]*\\<\\("
3813 preprocessor-keywords
3814 "\\)\\>")
3815 '(0 font-lock-keyword-face))
3816
3817 ;; And anything else is punctuation.
3818 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3819 '(0 mdw-punct-face))))))
3820
3821(progn
3822 (add-hook 'icon-mode-hook 'mdw-misc-mode-config t)
3823 (add-hook 'icon-mode-hook 'mdw-fontify-icon t))
3824
3825;;;--------------------------------------------------------------------------
3826;;; Fortran mode.
3827
3828(defun mdw-fontify-fortran-common ()
3829 (let ((fortran-keywords
3830 (mdw-regexps "access"
3831 "assign"
3832 "associate"
3833 "backspace"
3834 "blank"
3835 "block\\s-*data"
3836 "call"
3837 "case"
3838 "character"
3839 "class"
3840 "close"
3841 "common"
3842 "complex"
3843 "continue"
3844 "critical"
3845 "data"
3846 "dimension"
3847 "do"
3848 "double\\s-*precision"
3849 "else" "elseif" "elsewhere"
3850 "end"
3851 "endblock" "endblockdata"
3852 "endcritical"
3853 "enddo"
3854 "endinterface"
3855 "endmodule"
3856 "endprocedure"
3857 "endprogram"
3858 "endselect"
3859 "endsubmodule"
3860 "endsubroutine"
3861 "endtype"
3862 "endwhere"
3863 "endenum"
3864 "end\\s-*file"
3865 "endforall"
3866 "endfunction"
3867 "endif"
3868 "entry"
3869 "enum"
3870 "equivalence"
3871 "err"
3872 "external"
3873 "file"
3874 "fmt"
3875 "forall"
3876 "form"
3877 "format"
3878 "function"
3879 "go\\s-*to"
3880 "if"
3881 "implicit"
3882 "in" "inout"
3883 "inquire"
3884 "include"
3885 "integer"
3886 "interface"
3887 "intrinsic"
3888 "iostat"
3889 "len"
3890 "logical"
3891 "module"
3892 "open"
3893 "out"
3894 "parameter"
3895 "pause"
3896 "procedure"
3897 "program"
3898 "precision"
3899 "program"
3900 "read"
3901 "real"
3902 "rec"
3903 "recl"
3904 "return"
3905 "rewind"
3906 "save"
3907 "select" "selectcase" "selecttype"
3908 "status"
3909 "stop"
3910 "submodule"
3911 "subroutine"
3912 "then"
3913 "to"
3914 "type"
3915 "unit"
3916 "where"
3917 "write"))
3918 (fortran-operators (mdw-regexps "and"
3919 "eq"
3920 "eqv"
3921 "false"
3922 "ge"
3923 "gt"
3924 "le"
3925 "lt"
3926 "ne"
3927 "neqv"
3928 "not"
3929 "or"
3930 "true"))
3931 (fortran-intrinsics (mdw-regexps "abs" "dabs" "iabs" "cabs"
3932 "atan" "datan" "atan2" "datan2"
3933 "cmplx"
3934 "conjg"
3935 "cos" "dcos" "ccos"
3936 "dble"
3937 "dim" "idim"
3938 "exp" "dexp" "cexp"
3939 "float"
3940 "ifix"
3941 "aimag"
3942 "int" "aint" "idint"
3943 "alog" "dlog" "clog"
3944 "alog10" "dlog10"
3945 "max"
3946 "amax0" "amax1"
3947 "max0" "max1"
3948 "dmax1"
3949 "min"
3950 "amin0" "amin1"
3951 "min0" "min1"
3952 "dmin1"
3953 "mod" "amod" "dmod"
3954 "sin" "dsin" "csin"
3955 "sign" "isign" "dsign"
3956 "sngl"
3957 "sqrt" "dsqrt" "csqrt"
3958 "tanh"))
3959 (preprocessor-keywords
3960 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
3961 "ident" "if" "ifdef" "ifndef" "import" "include"
3962 "line" "pragma" "unassert" "undef" "warning")))
3963 (setq font-lock-keywords-case-fold-search t
3964 font-lock-keywords
3965 (list
3966
3967 ;; Fontify include files as strings.
3968 (list (concat "^[ \t]*\\#[ \t]*" "include"
3969 "[ \t]*\\(<[^>]+>?\\)")
3970 '(1 font-lock-string-face))
3971
3972 ;; Preprocessor directives are `references'?.
3973 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
3974 preprocessor-keywords
3975 "\\)\\>\\|[0-9]+\\|$\\)\\)")
3976 '(1 font-lock-keyword-face))
3977
3978 ;; Set up the keywords defined above.
3979 (list (concat "\\<\\(" fortran-keywords "\\)\\>")
3980 '(0 font-lock-keyword-face))
3981
3982 ;; Set up the `.foo.' operators.
3983 (list (concat "\\.\\(" fortran-operators "\\)\\.")
3984 '(0 font-lock-keyword-face))
3985
3986 ;; Set up the intrinsic functions.
3987 (list (concat "\\<\\(" fortran-intrinsics "\\)\\>")
3988 '(0 font-lock-variable-name-face))
3989
3990 ;; Numbers.
3991 (list (concat "\\(" "\\<" "[0-9]+" "\\(\\.[0-9]*\\)?"
3992 "\\|" "\\.[0-9]+"
3993 "\\)"
3994 "\\(" "[de]" "[+-]?" "[0-9]+" "\\)?"
3995 "\\(" "_" "\\sw+" "\\)?"
3996 "\\|" "b'[01]*'" "\\|" "'[01]*'b"
3997 "\\|" "b\"[01]*\"" "\\|" "\"[01]*\"b"
3998 "\\|" "o'[0-7]*'" "\\|" "'[0-7]*'o"
3999 "\\|" "o\"[0-7]*\"" "\\|" "\"[0-7]*\"o"
4000 "\\|" "[xz]'[0-9a-f]*'" "\\|" "'[0-9a-f]*'[xz]"
4001 "\\|" "[xz]\"[0-9a-f]*\"" "\\|" "\"[0-9a-f]*\"[xz]")
4002 '(0 mdw-number-face))
4003
4004 ;; Any anything else is punctuation.
4005 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4006 '(0 mdw-punct-face))))
4007
4008 (modify-syntax-entry ?/ "." font-lock-syntax-table)
4009 (modify-syntax-entry ?< ".")
4010 (modify-syntax-entry ?> ".")))
4011
4012(defun mdw-fontify-fortran () (mdw-fontify-fortran-common))
4013(defun mdw-fontify-f90 () (mdw-fontify-fortran-common))
4014
4015(setq fortran-do-indent 2
4016 fortran-if-indent 2
4017 fortran-structure-indent 2
4018 fortran-comment-line-start "*"
4019 fortran-comment-indent-style 'relative
4020 fortran-continuation-string "&"
4021 fortran-continuation-indent 4)
4022
4023(setq f90-do-indent 2
4024 f90-if-indent 2
4025 f90-program-indent 2
4026 f90-continuation-indent 4
4027 f90-smart-end-names nil
4028 f90-smart-end 'no-blink)
4029
4030(progn
4031 (add-hook 'fortran-mode-hook 'mdw-misc-mode-config t)
4032 (add-hook 'fortran-mode-hook 'mdw-fontify-fortran t)
4033 (add-hook 'f90-mode-hook 'mdw-misc-mode-config t)
4034 (add-hook 'f90-mode-hook 'mdw-fontify-f90 t))
4035
4036;;;--------------------------------------------------------------------------
4037;;; Assembler mode.
4038
4039(defun mdw-fontify-asm ()
4040 (modify-syntax-entry ?' "\"")
4041 (modify-syntax-entry ?. "w")
4042 (modify-syntax-entry ?\n ">")
4043 (setf fill-prefix nil)
4044 (modify-syntax-entry ?. "_")
4045 (modify-syntax-entry ?* ". 23")
4046 (modify-syntax-entry ?/ ". 124b")
4047 (modify-syntax-entry ?\n "> b")
4048 (local-set-key ";" 'self-insert-command)
4049 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
4050
4051(defun mdw-asm-set-comment ()
4052 (modify-syntax-entry ?; "."
4053 )
4054 (modify-syntax-entry asm-comment-char "< b")
4055 (setq comment-start (string asm-comment-char ? )))
4056(add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
4057(put 'asm-comment-char 'safe-local-variable 'characterp)
4058
4059(progn
4060 (add-hook 'asm-mode-hook 'mdw-misc-mode-config t)
4061 (add-hook 'asm-mode-hook 'mdw-fontify-asm t))
4062
4063;;;--------------------------------------------------------------------------
4064;;; TCL configuration.
4065
4066(setq-default tcl-indent-level 2)
4067
4068(defun mdw-fontify-tcl ()
4069 (dolist (ch '(?$))
4070 (modify-syntax-entry ch "."))
4071 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
4072 (make-local-variable 'font-lock-keywords)
4073 (setq font-lock-keywords
4074 (list
4075 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
4076 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
4077 "\\([eE][-+]?[0-9_]+\\)?")
4078 '(0 mdw-number-face))
4079 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4080 '(0 mdw-punct-face)))))
4081
4082(progn
4083 (add-hook 'tcl-mode-hook 'mdw-misc-mode-config t)
4084 (add-hook 'tcl-mode-hook 'mdw-fontify-tcl t))
4085
4086;;;--------------------------------------------------------------------------
4087;;; Dylan programming configuration.
4088
4089(defun mdw-fontify-dylan ()
4090
4091 (make-local-variable 'font-lock-keywords)
4092
4093 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
4094 ;; hook, which undoes all of our configuration.
4095 (setq major-mode 'dylan-mode)
4096 (font-lock-set-defaults)
4097
4098 (let* ((word "[-_a-zA-Z!*@<>$%]+")
4099 (dylan-keywords (mdw-regexps
4100
4101 "C-address" "C-callable-wrapper" "C-function"
4102 "C-mapped-subtype" "C-pointer-type" "C-struct"
4103 "C-subtype" "C-union" "C-variable"
4104
4105 "above" "abstract" "afterwards" "all"
4106 "begin" "below" "block" "by"
4107 "case" "class" "cleanup" "constant" "create"
4108 "define" "domain"
4109 "else" "elseif" "end" "exception" "export"
4110 "finally" "for" "from" "function"
4111 "generic"
4112 "handler"
4113 "if" "in" "instance" "interface" "iterate"
4114 "keyed-by"
4115 "let" "library" "local"
4116 "macro" "method" "module"
4117 "otherwise"
4118 "profiling"
4119 "select" "slot" "subclass"
4120 "table" "then" "to"
4121 "unless" "until" "use"
4122 "variable" "virtual"
4123 "when" "while"))
4124 (sharp-keywords (mdw-regexps
4125 "all-keys" "key" "next" "rest" "include"
4126 "t" "f")))
4127 (setq font-lock-keywords
4128 (list (list (concat "\\<\\(" dylan-keywords
4129 "\\|" "with\\(out\\)?-" word
4130 "\\)\\>")
4131 '(0 font-lock-keyword-face))
4132 (list (concat "\\<" word ":" "\\|"
4133 "#\\(" sharp-keywords "\\)\\>")
4134 '(0 font-lock-variable-name-face))
4135 (list (concat "\\("
4136 "\\([-+]\\|\\<\\)[0-9]+" "\\("
4137 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
4138 "\\|" "/[0-9]+"
4139 "\\)"
4140 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
4141 "\\|" "#b[01]+"
4142 "\\|" "#o[0-7]+"
4143 "\\|" "#x[0-9a-zA-Z]+"
4144 "\\)\\>")
4145 '(0 mdw-number-face))
4146 (list (concat "\\("
4147 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
4148 "\\_<[-+*/=<>:&|]+\\_>"
4149 "\\)")
4150 '(0 mdw-punct-face))))))
4151
4152(progn
4153 (add-hook 'dylan-mode-hook 'mdw-misc-mode-config t)
4154 (add-hook 'dylan-mode-hook 'mdw-fontify-dylan t))
4155
4156;;;--------------------------------------------------------------------------
4157;;; Algol 68 configuration.
4158
4159(setq-default a68-indent-step 2)
4160
4161(defun mdw-fontify-algol-68 ()
4162
4163 ;; Fix up the syntax table.
4164 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
4165 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
4166 (modify-syntax-entry ch "." a68-mode-syntax-table))
4167
4168 (make-local-variable 'font-lock-keywords)
4169
4170 (let ((not-comment
4171 (let ((word "COMMENT"))
4172 (cl-do ((regexp (concat "[^" (substring word 0 1) "]+")
4173 (concat regexp "\\|"
4174 (substring word 0 i)
4175 "[^" (substring word i (1+ i)) "]"))
4176 (i 1 (1+ i)))
4177 ((>= i (length word)) regexp)))))
4178 (setq font-lock-keywords
4179 (list (list (concat "\\<COMMENT\\>"
4180 "\\(" not-comment "\\)\\{0,5\\}"
4181 "\\(\\'\\|\\<COMMENT\\>\\)")
4182 '(0 font-lock-comment-face))
4183 (list (concat "\\<CO\\>"
4184 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
4185 "\\($\\|\\<CO\\>\\)")
4186 '(0 font-lock-comment-face))
4187 (list "\\<[A-Z_]+\\>"
4188 '(0 font-lock-keyword-face))
4189 (list (concat "\\<"
4190 "[0-9]+"
4191 "\\(\\.[0-9]+\\)?"
4192 "\\([eE][-+]?[0-9]+\\)?"
4193 "\\>")
4194 '(0 mdw-number-face))
4195 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
4196 '(0 mdw-punct-face))))))
4197
4198(dolist (hook '(a68-mode-hook a68-mode-hooks))
4199 (add-hook hook 'mdw-misc-mode-config t)
4200 (add-hook hook 'mdw-fontify-algol-68 t))
4201
4202;;;--------------------------------------------------------------------------
4203;;; REXX configuration.
4204
4205(defun mdw-rexx-electric-* ()
4206 (interactive)
4207 (insert ?*)
4208 (rexx-indent-line))
4209
4210(defun mdw-rexx-indent-newline-indent ()
4211 (interactive)
4212 (rexx-indent-line)
4213 (if abbrev-mode (expand-abbrev))
4214 (newline-and-indent))
4215
4216(defun mdw-fontify-rexx ()
4217
4218 ;; Various bits of fiddling.
4219 (setq mdw-auto-indent nil)
4220 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
4221 (local-set-key [?*] 'mdw-rexx-electric-*)
4222 (dolist (ch '(?! ?? ?# ?@ ?$)) (modify-syntax-entry ch "w"))
4223 (dolist (ch '(?¬)) (modify-syntax-entry ch "."))
4224 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
4225
4226 ;; Set up keywords and things for fontification.
4227 (make-local-variable 'font-lock-keywords-case-fold-search)
4228 (setq font-lock-keywords-case-fold-search t)
4229
4230 (setq rexx-indent 2)
4231 (setq rexx-end-indent rexx-indent)
4232 (setq rexx-cont-indent rexx-indent)
4233
4234 (make-local-variable 'font-lock-keywords)
4235 (let ((rexx-keywords
4236 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
4237 "else" "end" "engineering" "exit" "expose" "for"
4238 "forever" "form" "fuzz" "if" "interpret" "iterate"
4239 "leave" "linein" "name" "nop" "numeric" "off" "on"
4240 "options" "otherwise" "parse" "procedure" "pull"
4241 "push" "queue" "return" "say" "select" "signal"
4242 "scientific" "source" "then" "trace" "to" "until"
4243 "upper" "value" "var" "version" "when" "while"
4244 "with"
4245
4246 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
4247 "center" "center" "charin" "charout" "chars"
4248 "compare" "condition" "copies" "c2d" "c2x"
4249 "datatype" "date" "delstr" "delword" "d2c" "d2x"
4250 "errortext" "format" "fuzz" "insert" "lastpos"
4251 "left" "length" "lineout" "lines" "max" "min"
4252 "overlay" "pos" "queued" "random" "reverse" "right"
4253 "sign" "sourceline" "space" "stream" "strip"
4254 "substr" "subword" "symbol" "time" "translate"
4255 "trunc" "value" "verify" "word" "wordindex"
4256 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
4257 "x2d")))
4258
4259 (setq font-lock-keywords
4260 (list
4261
4262 ;; Set up the keywords defined above.
4263 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
4264 '(0 font-lock-keyword-face))
4265
4266 ;; Fontify all symbols the same way.
4267 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
4268 "[A-Za-z0-9.!?_#@$]+\\)")
4269 '(0 font-lock-variable-name-face))
4270
4271 ;; And everything else is punctuation.
4272 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4273 '(0 mdw-punct-face))))))
4274
4275(progn
4276 (add-hook 'rexx-mode-hook 'mdw-misc-mode-config t)
4277 (add-hook 'rexx-mode-hook 'mdw-fontify-rexx t))
4278
4279;;;--------------------------------------------------------------------------
4280;;; Standard ML programming style.
4281
4282(setq-default sml-nested-if-indent t
4283 sml-case-indent nil
4284 sml-indent-level 4
4285 sml-type-of-indent nil)
4286
4287(defun mdw-fontify-sml ()
4288
4289 ;; Make underscore an honorary letter.
4290 (modify-syntax-entry ?' "w")
4291
4292 ;; Set fill prefix.
4293 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
4294
4295 ;; Now define fontification things.
4296 (make-local-variable 'font-lock-keywords)
4297 (let ((sml-keywords
4298 (mdw-regexps "abstype" "and" "andalso" "as"
4299 "case"
4300 "datatype" "do"
4301 "else" "end" "eqtype" "exception"
4302 "fn" "fun" "functor"
4303 "handle"
4304 "if" "in" "include" "infix" "infixr"
4305 "let" "local"
4306 "nonfix"
4307 "of" "op" "open" "orelse"
4308 "raise" "rec"
4309 "sharing" "sig" "signature" "struct" "structure"
4310 "then" "type"
4311 "val"
4312 "where" "while" "with" "withtype")))
4313
4314 (setq font-lock-keywords
4315 (list
4316
4317 ;; Set up the keywords defined above.
4318 (list (concat "\\<\\(" sml-keywords "\\)\\>")
4319 '(0 font-lock-keyword-face))
4320
4321 ;; At least numbers are simpler than C.
4322 (list (concat "\\<\\~?"
4323 "\\(0\\([wW]?[xX][0-9a-fA-F]+\\|"
4324 "[wW][0-9]+\\)\\|"
4325 "\\([0-9]+\\(\\.[0-9]+\\)?"
4326 "\\([eE]\\~?"
4327 "[0-9]+\\)?\\)\\)")
4328 '(0 mdw-number-face))
4329
4330 ;; And anything else is punctuation.
4331 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4332 '(0 mdw-punct-face))))))
4333
4334(progn
4335 (add-hook 'sml-mode-hook 'mdw-misc-mode-config t)
4336 (add-hook 'sml-mode-hook 'mdw-fontify-sml t))
4337
4338;;;--------------------------------------------------------------------------
4339;;; Haskell configuration.
4340
4341(setq-default haskell-indent-offset 2)
4342(setq haskell-doc-prettify-types nil
4343 haskell-interactive-popup-errors nil)
4344
4345(defun mdw-fontify-haskell ()
4346
4347 ;; Fiddle with syntax table to get comments right.
4348 (modify-syntax-entry ?' "_")
4349 (modify-syntax-entry ?- ". 12")
4350 (modify-syntax-entry ?\n ">")
4351
4352 ;; Make punctuation be punctuation
4353 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
4354 (cl-do ((i 0 (1+ i)))
4355 ((>= i (length punct)))
4356 (modify-syntax-entry (aref punct i) ".")))
4357
4358 ;; Set fill prefix.
4359 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
4360
4361 ;; Fiddle with fontification.
4362 (make-local-variable 'font-lock-keywords)
4363 (let ((haskell-keywords
4364 (mdw-regexps "as"
4365 "case" "ccall" "class"
4366 "data" "default" "deriving" "do"
4367 "else" "exists"
4368 "forall" "foreign"
4369 "hiding"
4370 "if" "import" "in" "infix" "infixl" "infixr" "instance"
4371 "let"
4372 "mdo" "module"
4373 "newtype"
4374 "of"
4375 "proc"
4376 "qualified"
4377 "rec"
4378 "safe" "stdcall"
4379 "then" "type"
4380 "unsafe"
4381 "where"))
4382 (control-sequences
4383 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
4384 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
4385 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
4386 "SP" "STX" "SUB" "SYN" "US" "VT")))
4387
4388 (setq font-lock-keywords
4389 (list
4390 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
4391 "\\(-+}\\|-*\\'\\)"
4392 "\\|"
4393 "--.*$")
4394 '(0 font-lock-comment-face))
4395 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
4396 '(0 font-lock-keyword-face))
4397 (list (concat "'\\("
4398 "[^\\]"
4399 "\\|"
4400 "\\\\"
4401 "\\(" "[abfnrtv\\\"']" "\\|"
4402 "^" "\\(" control-sequences "\\|"
4403 "[]A-Z@[\\^_]" "\\)" "\\|"
4404 "\\|"
4405 "[0-9]+" "\\|"
4406 "[oO][0-7]+" "\\|"
4407 "[xX][0-9A-Fa-f]+"
4408 "\\)"
4409 "\\)'")
4410 '(0 font-lock-string-face))
4411 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
4412 '(0 font-lock-variable-name-face))
4413 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
4414 "\\_<[0-9]+\\(\\.[0-9]*\\)?"
4415 "\\([eE][-+]?[0-9]+\\)?")
4416 '(0 mdw-number-face))
4417 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4418 '(0 mdw-punct-face))))))
4419
4420(progn
4421 (add-hook 'haskell-mode-hook 'mdw-misc-mode-config t)
4422 (add-hook 'haskell-mode-hook 'mdw-fontify-haskell t))
4423
4424;;;--------------------------------------------------------------------------
4425;;; Erlang configuration.
4426
4427(setq-default erlang-electric-commands nil)
4428
4429(defun mdw-fontify-erlang ()
4430
4431 ;; Set fill prefix.
4432 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
4433
4434 ;; Fiddle with fontification.
4435 (make-local-variable 'font-lock-keywords)
4436 (let ((erlang-keywords
4437 (mdw-regexps "after" "and" "andalso"
4438 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
4439 "case" "catch" "cond"
4440 "div" "end" "fun" "if" "let" "not"
4441 "of" "or" "orelse"
4442 "query" "receive" "rem" "try" "when" "xor")))
4443
4444 (setq font-lock-keywords
4445 (list
4446 (list "%.*$"
4447 '(0 font-lock-comment-face))
4448 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
4449 '(0 font-lock-keyword-face))
4450 (list (concat "^-\\sw+\\>")
4451 '(0 font-lock-keyword-face))
4452 (list "\\<[0-9]+\\(#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)?\\>"
4453 '(0 mdw-number-face))
4454 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4455 '(0 mdw-punct-face))))))
4456
4457(progn
4458 (add-hook 'erlang-mode-hook 'mdw-misc-mode-config t)
4459 (add-hook 'erlang-mode-hook 'mdw-fontify-erlang t))
4460
4461;;;--------------------------------------------------------------------------
4462;;; Texinfo configuration.
4463
4464(defun mdw-fontify-texinfo ()
4465
4466 ;; Set fill prefix.
4467 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
4468
4469 ;; Real fontification things.
4470 (make-local-variable 'font-lock-keywords)
4471 (setq font-lock-keywords
4472 (list
4473
4474 ;; Environment names are keywords.
4475 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
4476 '(2 font-lock-keyword-face))
4477
4478 ;; Unmark escaped magic characters.
4479 (list "\\(@\\)\\([@{}]\\)"
4480 '(1 font-lock-keyword-face)
4481 '(2 font-lock-variable-name-face))
4482
4483 ;; Make sure we get comments properly.
4484 (list "@c\\(omment\\)?\\( .*\\)?$"
4485 '(0 font-lock-comment-face))
4486
4487 ;; Command names are keywords.
4488 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
4489 '(0 font-lock-keyword-face))
4490
4491 ;; Fontify TeX special characters as punctuation.
4492 (list "[{}]+"
4493 '(0 mdw-punct-face)))))
4494
4495(dolist (hook '(texinfo-mode-hook TeXinfo-mode-hook))
4496 (add-hook hook 'mdw-misc-mode-config t)
4497 (add-hook hook 'mdw-fontify-texinfo t))
4498
4499;;;--------------------------------------------------------------------------
4500;;; TeX and LaTeX configuration.
4501
4502(setq-default LaTeX-table-label "tbl:"
4503 TeX-auto-untabify nil
4504 LaTeX-syntactic-comments nil
4505 LaTeX-fill-break-at-separators '(\\\[))
4506
4507(defun mdw-fontify-tex ()
4508 (setq ispell-parser 'tex)
4509 (turn-on-reftex)
4510
4511 ;; Don't make maths into a string.
4512 (modify-syntax-entry ?$ ".")
4513 (modify-syntax-entry ?$ "." font-lock-syntax-table)
4514 (local-set-key [?$] 'self-insert-command)
4515
4516 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
4517 (local-set-key "\C-\M-i" 'indent-relative)
4518 (setq indent-tabs-mode nil)
4519
4520 ;; Set fill prefix.
4521 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
4522
4523 ;; Real fontification things.
4524 (make-local-variable 'font-lock-keywords)
4525 (setq font-lock-keywords
4526 (list
4527
4528 ;; Environment names are keywords.
4529 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
4530 "{\\([^}\n]*\\)}")
4531 '(2 font-lock-keyword-face))
4532
4533 ;; Suspended environment names are keywords too.
4534 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
4535 "{\\([^}\n]*\\)}")
4536 '(3 font-lock-keyword-face))
4537
4538 ;; Command names are keywords.
4539 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
4540 '(0 font-lock-keyword-face))
4541
4542 ;; Handle @/.../ for italics.
4543 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
4544 ;; '(1 font-lock-keyword-face)
4545 ;; '(3 font-lock-keyword-face))
4546
4547 ;; Handle @*...* for boldness.
4548 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
4549 ;; '(1 font-lock-keyword-face)
4550 ;; '(3 font-lock-keyword-face))
4551
4552 ;; Handle @`...' for literal syntax things.
4553 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
4554 ;; '(1 font-lock-keyword-face)
4555 ;; '(3 font-lock-keyword-face))
4556
4557 ;; Handle @<...> for nonterminals.
4558 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
4559 ;; '(1 font-lock-keyword-face)
4560 ;; '(3 font-lock-keyword-face))
4561
4562 ;; Handle other @-commands.
4563 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
4564 ;; '(0 font-lock-keyword-face))
4565
4566 ;; Make sure we get comments properly.
4567 (list "%.*"
4568 '(0 font-lock-comment-face))
4569
4570 ;; Fontify TeX special characters as punctuation.
4571 (list "[$^_{}#&]"
4572 '(0 mdw-punct-face)))))
4573
4574(setq TeX-install-font-lock 'tex-font-setup)
4575
4576(eval-after-load 'font-latex
4577 '(defun font-latex-jit-lock-force-redisplay (buf start end)
4578 "Compatibility for Emacsen not offering `jit-lock-force-redisplay'."
4579 ;; The following block is an expansion of `jit-lock-force-redisplay'
4580 ;; and involved macros taken from CVS Emacs on 2007-04-28.
4581 (with-current-buffer buf
4582 (let ((modified (buffer-modified-p)))
4583 (unwind-protect
4584 (let ((buffer-undo-list t)
4585 (inhibit-read-only t)
4586 (inhibit-point-motion-hooks t)
4587 (inhibit-modification-hooks t)
4588 deactivate-mark
4589 buffer-file-name
4590 buffer-file-truename)
4591 (put-text-property start end 'fontified t))
4592 (unless modified
4593 (restore-buffer-modified-p nil)))))))
4594
4595(setq TeX-output-view-style
4596 '(("^dvi$"
4597 ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$")
4598 "%(o?)dvips -t landscape %d -o && xdg-open %f")
4599 ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$"
4600 "%(o?)dvips %d -o && xdg-open %f")
4601 ("^dvi$"
4602 ("^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "^landscape$")
4603 "%(o?)xdvi %dS -paper a4r -s 0 %d")
4604 ("^dvi$" "^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$"
4605 "%(o?)xdvi %dS -paper a4 %d")
4606 ("^dvi$"
4607 ("^a5\\(?:comb\\|paper\\)$" "^landscape$")
4608 "%(o?)xdvi %dS -paper a5r -s 0 %d")
4609 ("^dvi$" "^a5\\(?:comb\\|paper\\)$" "%(o?)xdvi %dS -paper a5 %d")
4610 ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
4611 ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d")
4612 ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
4613 ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
4614 ("^dvi$" "." "%(o?)xdvi %dS %d")
4615 ("^pdf$" "." "xdg-open %o")
4616 ("^html?$" "." "sensible-browser %o")))
4617
4618(setq TeX-view-program-list
4619 '(("mupdf" ("mupdf %o" (mode-io-correlate " %(outpage)")))))
4620
4621(setq TeX-view-program-selection
4622 '(((output-dvi style-pstricks) "dvips and gv")
4623 (output-dvi "xdvi")
4624 (output-pdf "mupdf")
4625 (output-html "sensible-browser")))
4626
4627(setq TeX-open-quote "\""
4628 TeX-close-quote "\"")
4629
4630(setq reftex-use-external-file-finders t
4631 reftex-auto-recenter-toc t)
4632
4633(setq reftex-label-alist
4634 '(("theorem" ?T "th:" "~\\ref{%s}" t ("theorems?" "th\\.") -2)
4635 ("axiom" ?A "ax:" "~\\ref{%s}" t ("axioms?" "ax\\.") -2)
4636 ("definition" ?D "def:" "~\\ref{%s}" t ("definitions?" "def\\.") -2)
4637 ("proposition" ?P "prop:" "~\\ref{%s}" t
4638 ("propositions?" "prop\\.") -2)
4639 ("lemma" ?L "lem:" "~\\ref{%s}" t ("lemmas?" "lem\\.") -2)
4640 ("example" ?X "eg:" "~\\ref{%s}" t ("examples?") -2)
4641 ("exercise" ?E "ex:" "~\\ref{%s}" t ("exercises?" "ex\\.") -2)
4642 ("enumerate" ?i "i:" "~\\ref{%s}" item ("items?"))))
4643(setq reftex-section-prefixes
4644 '((0 . "part:")
4645 (1 . "ch:")
4646 (t . "sec:")))
4647
4648(setq bibtex-field-delimiters 'double-quotes
4649 bibtex-align-at-equal-sign t
4650 bibtex-entry-format '(realign opts-or-alts required-fields
4651 numerical-fields last-comma delimiters
4652 unify-case sort-fields braces)
4653 bibtex-sort-ignore-string-entries nil
4654 bibtex-maintain-sorted-entries 'entry-class
4655 bibtex-include-OPTkey t
4656 bibtex-autokey-names-stretch 1
4657 bibtex-autokey-expand-strings t
4658 bibtex-autokey-name-separator "-"
4659 bibtex-autokey-year-length 4
4660 bibtex-autokey-titleword-separator "-"
4661 bibtex-autokey-name-year-separator "-"
4662 bibtex-autokey-year-title-separator ":")
4663
4664(progn
4665 (dolist (hook '(tex-mode-hook latex-mode-hook
4666 TeX-mode-hook LaTeX-mode-hook))
4667 (add-hook hook 'mdw-misc-mode-config t)
4668 (add-hook hook 'mdw-fontify-tex t))
4669 (add-hook 'bibtex-mode-hook (lambda () (setq fill-column 76))))
4670
4671;;;--------------------------------------------------------------------------
4672;;; HTML, CSS, and other web foolishness.
4673
4674(setq-default css-indent-offset 8)
4675
4676;;;--------------------------------------------------------------------------
4677;;; SGML hacking.
4678
4679(setq-default psgml-html-build-new-buffer nil)
4680
4681(defun mdw-sgml-mode ()
4682 (interactive)
4683 (sgml-mode)
4684 (mdw-standard-fill-prefix "")
4685 (make-local-variable 'sgml-delimiters)
4686 (setq sgml-delimiters
4687 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
4688 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT"
4689 "\"" "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]"
4690 "NESTC" "{" "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">"
4691 "PIO" "<?" "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" ","
4692 "STAGO" ":" "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
4693 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE"
4694 "/>" "NULL" ""))
4695 (setq major-mode 'mdw-sgml-mode)
4696 (setq mode-name "[mdw] SGML")
4697 (run-hooks 'mdw-sgml-mode-hook))
4698
4699;;;--------------------------------------------------------------------------
4700;;; Configuration files.
4701
4702(defcustom mdw-conf-quote-normal nil
4703 "Control syntax category of quote characters `\"' and `''.
4704If this is `t', consider quote characters to be normal
4705punctuation, as for `conf-quote-normal'. If this is `nil' then
4706leave quote characters as quotes. If this is a list, then
4707consider the quote characters in the list to be normal
4708punctuation. If this is a single quote character, then consider
4709that character only to be normal punctuation."
4710 :type '(choice boolean character (repeat character))
4711 :safe 'mdw-conf-quote-normal-acceptable-value-p)
4712(defun mdw-conf-quote-normal-acceptable-value-p (value)
4713 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
4714 (or (booleanp value)
4715 (cl-every (lambda (v) (memq v '(?\" ?')))
4716 (if (listp value) value (list value)))))
4717
4718(defun mdw-fix-up-quote ()
4719 "Apply the setting of `mdw-conf-quote-normal'."
4720 (let ((flag mdw-conf-quote-normal))
4721 (cond ((eq flag t)
4722 (conf-quote-normal t))
4723 ((not flag)
4724 nil)
4725 (t
4726 (let ((table (copy-syntax-table (syntax-table))))
4727 (dolist (ch (if (listp flag) flag (list flag)))
4728 (modify-syntax-entry ch "." table))
4729 (set-syntax-table table)
4730 (and font-lock-mode (font-lock-fontify-buffer)))))))
4731
4732(progn
4733 (add-hook 'conf-mode-hook 'mdw-misc-mode-config t)
4734 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t))
4735
4736;;;--------------------------------------------------------------------------
4737;;; Shell scripts.
4738
4739(defun mdw-setup-sh-script-mode ()
4740
4741 ;; Fetch the shell interpreter's name.
4742 (let ((shell-name sh-shell-file))
4743
4744 ;; Try reading the hash-bang line.
4745 (save-excursion
4746 (goto-char (point-min))
4747 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
4748 (setq shell-name (match-string 1))))
4749
4750 ;; Now try to set the shell.
4751 ;;
4752 ;; Don't let `sh-set-shell' bugger up my script.
4753 (let ((executable-set-magic #'(lambda (s &rest r) s)))
4754 (sh-set-shell shell-name)))
4755
4756 ;; Don't insert here-document scaffolding automatically.
4757 (local-set-key "<" 'self-insert-command)
4758
4759 ;; Now enable my keys and the fontification.
4760 (mdw-misc-mode-config)
4761
4762 ;; Set the indentation level correctly.
4763 (setq sh-indentation 2)
4764 (setq sh-basic-offset 2))
4765
4766(setq sh-shell-file "/bin/sh")
4767
4768;; Awful hacking to override the shell detection for particular scripts.
4769(defmacro define-custom-shell-mode (name shell)
4770 `(defun ,name ()
4771 (interactive)
4772 (set (make-local-variable 'sh-shell-file) ,shell)
4773 (sh-mode)))
4774(define-custom-shell-mode bash-mode "/bin/bash")
4775(define-custom-shell-mode rc-mode "/usr/bin/rc")
4776(put 'sh-shell-file 'permanent-local t)
4777
4778;; Hack the rc syntax table. Backquotes aren't paired in rc.
4779(eval-after-load "sh-script"
4780 '(or (assq 'rc sh-mode-syntax-table-input)
4781 (let ((frag '(nil
4782 ?# "<"
4783 ?\n ">#"
4784 ?\" "\"\""
4785 ?\' "\"\'"
4786 ?$ "'"
4787 ?\` "."
4788 ?! "_"
4789 ?% "_"
4790 ?. "_"
4791 ?^ "_"
4792 ?~ "_"
4793 ?, "_"
4794 ?= "."
4795 ?< "."
4796 ?> "."))
4797 (assoc (assq 'rc sh-mode-syntax-table-input)))
4798 (if assoc
4799 (rplacd assoc frag)
4800 (setq sh-mode-syntax-table-input
4801 (cons (cons 'rc frag)
4802 sh-mode-syntax-table-input))))))
4803
4804(progn
4805 (add-hook 'sh-mode-hook 'mdw-misc-mode-config t)
4806 (add-hook 'sh-mode-hook 'mdw-setup-sh-script-mode t))
4807
4808;;;--------------------------------------------------------------------------
4809;;; Emacs shell mode.
4810
4811(defun mdw-eshell-prompt ()
4812 (let ((left "[") (right "]"))
4813 (when (= (user-uid) 0)
4814 (setq left "«" right "»"))
4815 (concat left
4816 (save-match-data
4817 (replace-regexp-in-string "\\..*$" "" (system-name)))
4818 " "
4819 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
4820 (home (expand-file-name "~")) (nhome (length home)))
4821 (if (and (>= npwd nhome)
4822 (or (= nhome npwd)
4823 (= (elt pwd nhome) ?/))
4824 (string= (substring pwd 0 nhome) home))
4825 (concat "~" (substring pwd (length home)))
4826 pwd))
4827 right)))
4828(setq-default eshell-prompt-function 'mdw-eshell-prompt)
4829(setq-default eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
4830
4831(defun eshell/e (file) (find-file file) nil)
4832(defun eshell/ee (file) (find-file-other-window file) nil)
4833(defun eshell/w3m (url) (w3m-goto-url url) nil)
4834
4835(mdw-define-face eshell-prompt (t :weight bold))
4836(mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
4837(mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
4838(mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
4839(mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
4840(mdw-define-face eshell-ls-executable (t :weight bold))
4841(mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
4842(mdw-define-face eshell-ls-readonly (t nil))
4843(mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
4844
4845(defun mdw-eshell-hack () (setenv "LD_PRELOAD" nil))
4846(add-hook 'eshell-mode-hook 'mdw-eshell-hack)
4847
4848;;;--------------------------------------------------------------------------
4849;;; Messages-file mode.
4850
4851(defun messages-mode-guts ()
4852 (setq messages-mode-syntax-table (make-syntax-table))
4853 (set-syntax-table messages-mode-syntax-table)
4854 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
4855 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
4856 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
4857 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
4858 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
4859 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
4860 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
4861 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
4862 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
4863 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
4864 (make-local-variable 'comment-start)
4865 (make-local-variable 'comment-end)
4866 (make-local-variable 'indent-line-function)
4867 (setq indent-line-function 'indent-relative)
4868 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4869 (make-local-variable 'font-lock-defaults)
4870 (make-local-variable 'messages-mode-keywords)
4871 (let ((keywords
4872 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
4873 "export" "enum" "fixed-octetstring" "flags"
4874 "harmless" "map" "nested" "optional"
4875 "optional-tagged" "package" "primitive"
4876 "primitive-nullfree" "relaxed[ \t]+enum"
4877 "set" "table" "tagged-optional" "union"
4878 "variadic" "vector" "version" "version-tag")))
4879 (setq messages-mode-keywords
4880 (list
4881 (list (concat "\\<\\(" keywords "\\)\\>:")
4882 '(0 font-lock-keyword-face))
4883 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
4884 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
4885 (0 font-lock-variable-name-face))
4886 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
4887 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4888 (0 mdw-punct-face)))))
4889 (setq font-lock-defaults
4890 '(messages-mode-keywords nil nil nil nil))
4891 (run-hooks 'messages-file-hook))
4892
4893(defun messages-mode ()
4894 (interactive)
4895 (fundamental-mode)
4896 (setq major-mode 'messages-mode)
4897 (setq mode-name "Messages")
4898 (messages-mode-guts)
4899 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
4900 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
4901 (setq comment-start "# ")
4902 (setq comment-end "")
4903 (run-hooks 'messages-mode-hook))
4904
4905(defun cpp-messages-mode ()
4906 (interactive)
4907 (fundamental-mode)
4908 (setq major-mode 'cpp-messages-mode)
4909 (setq mode-name "CPP Messages")
4910 (messages-mode-guts)
4911 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
4912 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
4913 (setq comment-start "/* ")
4914 (setq comment-end " */")
4915 (let ((preprocessor-keywords
4916 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
4917 "ident" "if" "ifdef" "ifndef" "import" "include"
4918 "line" "pragma" "unassert" "undef" "warning")))
4919 (setq messages-mode-keywords
4920 (append (list (list (concat "^[ \t]*\\#[ \t]*"
4921 "\\(include\\|import\\)"
4922 "[ \t]*\\(<[^>]+\\(>\\)?\\)")
4923 '(2 font-lock-string-face))
4924 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
4925 preprocessor-keywords
4926 "\\)\\>\\|[0-9]+\\|$\\)\\)")
4927 '(1 font-lock-keyword-face)))
4928 messages-mode-keywords)))
4929 (run-hooks 'cpp-messages-mode-hook))
4930
4931(progn
4932 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
4933 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
4934 ;; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
4935 )
4936
4937;;;--------------------------------------------------------------------------
4938;;; Messages-file mode.
4939
4940(defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
4941 "Face to use for subsittution directives.")
4942(make-face 'mallow-driver-substitution-face)
4943(defvar mallow-driver-text-face 'mallow-driver-text-face
4944 "Face to use for body text.")
4945(make-face 'mallow-driver-text-face)
4946
4947(defun mallow-driver-mode ()
4948 (interactive)
4949 (fundamental-mode)
4950 (setq major-mode 'mallow-driver-mode)
4951 (setq mode-name "Mallow driver")
4952 (setq mallow-driver-mode-syntax-table (make-syntax-table))
4953 (set-syntax-table mallow-driver-mode-syntax-table)
4954 (make-local-variable 'comment-start)
4955 (make-local-variable 'comment-end)
4956 (make-local-variable 'indent-line-function)
4957 (setq indent-line-function 'indent-relative)
4958 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4959 (make-local-variable 'font-lock-defaults)
4960 (make-local-variable 'mallow-driver-mode-keywords)
4961 (let ((keywords
4962 (mdw-regexps "each" "divert" "file" "if"
4963 "perl" "set" "string" "type" "write")))
4964 (setq mallow-driver-mode-keywords
4965 (list
4966 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
4967 '(0 font-lock-keyword-face))
4968 (list "^%\\s *\\(#.*\\)?$"
4969 '(0 font-lock-comment-face))
4970 (list "^%"
4971 '(0 font-lock-keyword-face))
4972 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
4973 (list "\\${[^}]*}"
4974 '(0 mallow-driver-substitution-face t)))))
4975 (setq font-lock-defaults
4976 '(mallow-driver-mode-keywords nil nil nil nil))
4977 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
4978 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
4979 (setq comment-start "%# ")
4980 (setq comment-end "")
4981 (run-hooks 'mallow-driver-mode-hook))
4982
4983(progn
4984 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t))
4985
4986;;;--------------------------------------------------------------------------
4987;;; NFast debugs.
4988
4989(defun nfast-debug-mode ()
4990 (interactive)
4991 (fundamental-mode)
4992 (setq major-mode 'nfast-debug-mode)
4993 (setq mode-name "NFast debug")
4994 (setq messages-mode-syntax-table (make-syntax-table))
4995 (set-syntax-table messages-mode-syntax-table)
4996 (make-local-variable 'font-lock-defaults)
4997 (make-local-variable 'nfast-debug-mode-keywords)
4998 (setq truncate-lines t)
4999 (setq nfast-debug-mode-keywords
5000 (list
5001 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
5002 (0 font-lock-keyword-face))
5003 (list (concat "^[ \t]+\\(\\("
5004 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
5005 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
5006 "[ \t]+\\)*"
5007 "[0-9a-fA-F]+\\)[ \t]*$")
5008 '(0 mdw-number-face))
5009 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
5010 (1 font-lock-keyword-face))
5011 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
5012 (1 font-lock-warning-face))
5013 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
5014 (1 nil))
5015 (list (concat "^[ \t]+\\.cmd=[ \t]+"
5016 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
5017 '(1 font-lock-keyword-face))
5018 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
5019 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
5020 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
5021 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
5022 (setq font-lock-defaults
5023 '(nfast-debug-mode-keywords nil nil nil nil))
5024 (run-hooks 'nfast-debug-mode-hook))
5025
5026;;;--------------------------------------------------------------------------
5027;;; Lispy languages.
5028
5029;; Unpleasant bodge.
5030(unless (boundp 'slime-repl-mode-map)
5031 (setq slime-repl-mode-map (make-sparse-keymap)))
5032
5033(defun mdw-indent-newline-and-indent ()
5034 (interactive)
5035 (indent-for-tab-command)
5036 (newline-and-indent))
5037
5038(eval-after-load "cl-indent"
5039 '(progn
5040 (mapc #'(lambda (pair)
5041 (put (car pair)
5042 'common-lisp-indent-function
5043 (cdr pair)))
5044 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
5045 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
5046
5047(defun mdw-common-lisp-indent ()
5048 (make-local-variable 'lisp-indent-function)
5049 (setq lisp-indent-function 'common-lisp-indent-function))
5050
5051(defmacro mdw-advise-hyperspec-lookup (func args)
5052 `(defadvice ,func (around mdw-browse-w3m ,args activate compile)
5053 (if (fboundp 'w3m)
5054 (let ((browse-url-browser-function #'mdw-w3m-browse-url))
5055 ad-do-it)
5056 ad-do-it)))
5057(mdw-advise-hyperspec-lookup common-lisp-hyperspec (symbol))
5058(mdw-advise-hyperspec-lookup common-lisp-hyperspec-format (char))
5059(mdw-advise-hyperspec-lookup common-lisp-hyperspec-lookup-reader-macro (char))
5060
5061(defun mdw-fontify-lispy ()
5062
5063 ;; Set fill prefix.
5064 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
5065
5066 ;; Not much fontification needed.
5067 (make-local-variable 'font-lock-keywords)
5068 (setq font-lock-keywords
5069 (list (list (concat "\\("
5070 "\\_<[-+]?"
5071 "\\(" "[0-9]+/[0-9]+"
5072 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
5073 "\\.[0-9]+" "\\)"
5074 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
5075 "\\)"
5076 "\\|"
5077 "#"
5078 "\\(" "x" "[-+]?"
5079 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
5080 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
5081 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
5082 "\\|" "[0-9]+" "r" "[-+]?"
5083 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
5084 "\\)"
5085 "\\)\\_>")
5086 '(0 mdw-number-face))
5087 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
5088 '(0 mdw-punct-face)))))
5089
5090;; Special indentation.
5091
5092(defcustom mdw-lisp-loop-default-indent 2
5093 "Default indent for simple `loop' body."
5094 :type 'integer
5095 :safe 'integerp)
5096(defcustom mdw-lisp-setf-value-indent 2
5097 "Default extra indent for `setf' values."
5098 :type 'integer :safe 'integerp)
5099
5100(setq lisp-simple-loop-indentation 0
5101 lisp-loop-keyword-indentation 0
5102 lisp-loop-forms-indentation 2
5103 lisp-lambda-list-keyword-parameter-alignment t)
5104
5105(defun mdw-indent-funcall
5106 (path state &optional indent-point sexp-column normal-indent)
5107 "Indent `funcall' more usefully.
5108Essentially, treat `funcall foo' as a function name, and align the arguments
5109to `foo'."
5110 (and (or (not (consp path)) (null (cadr path)))
5111 (save-excursion
5112 (goto-char (cadr state))
5113 (forward-char 1)
5114 (let ((start-line (line-number-at-pos)))
5115 (and (condition-case nil (progn (forward-sexp 3) t)
5116 (scan-error nil))
5117 (progn
5118 (forward-sexp -1)
5119 (and (= start-line (line-number-at-pos))
5120 (current-column))))))))
5121(progn
5122 (put 'funcall 'common-lisp-indent-function 'mdw-indent-funcall)
5123 (put 'funcall 'lisp-indent-function 'mdw-indent-funcall))
5124
5125(defun mdw-indent-setf
5126 (path state &optional indent-point sexp-column normal-indent)
5127 "Indent `setf' more usefully.
5128If the values aren't on the same lines as their variables then indent them
5129by `mdw-lisp-setf-value-indent' spaces."
5130 (and (or (not (consp path)) (null (cadr path)))
5131 (let ((basic-indent (save-excursion
5132 (goto-char (cadr state))
5133 (forward-char 1)
5134 (and (condition-case nil
5135 (progn (forward-sexp 2) t)
5136 (scan-error nil))
5137 (progn
5138 (forward-sexp -1)
5139 (current-column)))))
5140 (offset (if (consp path) (car path)
5141 (catch 'done
5142 (save-excursion
5143 (let ((start path)
5144 (count 0))
5145 (goto-char (cadr state))
5146 (forward-char 1)
5147 (while (< (point) start)
5148 (condition-case nil (forward-sexp 1)
5149 (scan-error (throw 'done nil)))
5150 (cl-incf count))
5151 (1- count)))))))
5152 (and basic-indent offset
5153 (list (+ basic-indent
5154 (if (cl-oddp offset) 0
5155 mdw-lisp-setf-value-indent))
5156 basic-indent)))))
5157(progn
5158 (put 'setf 'common-lisp-indent-functopion 'mdw-indent-setf)
5159 (put 'psetf 'common-lisp-indent-function 'mdw-indent-setf)
5160 (put 'setq 'common-lisp-indent-function 'mdw-indent-setf)
5161 (put 'setf 'lisp-indent-function 'mdw-indent-setf)
5162 (put 'setq 'lisp-indent-function 'mdw-indent-setf)
5163 (put 'setq-local 'lisp-indent-function 'mdw-indent-setf)
5164 (put 'setq-default 'lisp-indent-function 'mdw-indent-setf))
5165
5166(defadvice common-lisp-loop-part-indentation
5167 (around mdw-fix-loop-indentation (indent-point state) activate compile)
5168 "Improve `loop' indentation.
5169If the first subform is on the same line as the `loop' keyword, then
5170align the other subforms beneath it. Otherwise, indent them
5171`mdw-lisp-loop-default-indent' columns in from the opening parenthesis."
5172
5173 (let* ((loop-indentation (save-excursion
5174 (goto-char (elt state 1))
5175 (current-column))))
5176
5177 ;; Don't really care about this.
5178 (when (and (boundp 'lisp-indent-backquote-substitution-mode)
5179 (eq lisp-indent-backquote-substitution-mode 'corrected))
5180 (save-excursion
5181 (goto-char (elt state 1))
5182 (cl-incf loop-indentation
5183 (cond ((eq (char-before) ?,) -1)
5184 ((and (eq (char-before) ?@)
5185 (progn (backward-char)
5186 (eq (char-before) ?,)))
5187 -2)
5188 (t 0)))))
5189
5190 ;; If the first loop item is on the same line as the `loop' itself then
5191 ;; use that as the baseline. Otherwise advance by the default indent.
5192 (goto-char (cadr state))
5193 (forward-char 1)
5194 (let ((baseline-indent
5195 (if (= (line-number-at-pos)
5196 (if (condition-case nil (progn (forward-sexp 2) t)
5197 (scan-error nil))
5198 (progn (forward-sexp -1) (line-number-at-pos))
5199 -1))
5200 (current-column)
5201 (+ loop-indentation mdw-lisp-loop-default-indent))))
5202
5203 (goto-char indent-point)
5204 (beginning-of-line)
5205
5206 (setq ad-return-value
5207 (list
5208 (cond ((condition-case ()
5209 (save-excursion
5210 (goto-char (elt state 1))
5211 (forward-char 1)
5212 (forward-sexp 2)
5213 (backward-sexp 1)
5214 (not (looking-at "\\(:\\|\\sw\\)")))
5215 (error nil))
5216 (+ baseline-indent lisp-simple-loop-indentation))
5217 ((looking-at "^\\s-*\\(:?\\sw+\\|;\\)")
5218 (+ baseline-indent lisp-loop-keyword-indentation))
5219 (t
5220 (+ baseline-indent lisp-loop-forms-indentation)))
5221
5222 ;; Tell the caller that the next line needs recomputation,
5223 ;; even though it doesn't start a sexp.
5224 loop-indentation)))))
5225
5226;; SLIME setup.
5227
5228(defcustom mdw-friendly-name "[mdw]"
5229 "How I want to be addressed."
5230 :type 'string
5231 :safe 'stringp)
5232(defadvice slime-user-first-name
5233 (around mdw-use-friendly-name compile activate)
5234 (if mdw-friendly-name (setq ad-return-value mdw-friendly-name)
5235 ad-do-it))
5236
5237(eval-and-compile
5238 (trap
5239 (if (not mdw-fast-startup)
5240 (progn
5241 (require 'slime-autoloads)
5242 (slime-setup '(slime-autodoc slime-c-p-c))))))
5243
5244(let ((stuff '((cmucl ("cmucl"))
5245 (sbcl ("sbcl") :coding-system utf-8-unix)
5246 (clisp ("clisp") :coding-system utf-8-unix))))
5247 (or (boundp 'slime-lisp-implementations)
5248 (setq slime-lisp-implementations nil))
5249 (while stuff
5250 (let* ((head (car stuff))
5251 (found (assq (car head) slime-lisp-implementations)))
5252 (setq stuff (cdr stuff))
5253 (if found
5254 (rplacd found (cdr head))
5255 (setq slime-lisp-implementations
5256 (cons head slime-lisp-implementations))))))
5257(setq slime-default-lisp 'sbcl)
5258
5259;; Hooks.
5260
5261(progn
5262 (dolist (hook '(emacs-lisp-mode-hook
5263 scheme-mode-hook
5264 lisp-mode-hook
5265 inferior-lisp-mode-hook
5266 lisp-interaction-mode-hook
5267 ielm-mode-hook
5268 slime-repl-mode-hook))
5269 (add-hook hook 'mdw-misc-mode-config t)
5270 (add-hook hook 'mdw-fontify-lispy t))
5271 (add-hook 'lisp-mode-hook 'mdw-common-lisp-indent t)
5272 (add-hook 'inferior-lisp-mode-hook
5273 #'(lambda () (local-set-key "\C-m" 'comint-send-and-indent)) t))
5274
5275;;;--------------------------------------------------------------------------
5276;;; Other languages.
5277
5278;; Smalltalk.
5279
5280(defun mdw-setup-smalltalk ()
5281 (and mdw-auto-indent
5282 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
5283 (make-local-variable 'mdw-auto-indent)
5284 (setq mdw-auto-indent nil)
5285 (local-set-key "\C-i" 'smalltalk-reindent))
5286
5287(defun mdw-fontify-smalltalk ()
5288 (make-local-variable 'font-lock-keywords)
5289 (setq font-lock-keywords
5290 (list
5291 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
5292 '(0 font-lock-keyword-face))
5293 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
5294 "[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
5295 "\\([eE][-+]?[0-9_]+\\)?")
5296 '(0 mdw-number-face))
5297 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
5298 '(0 mdw-punct-face)))))
5299
5300(progn
5301 (add-hook 'smalltalk-mode 'mdw-misc-mode-config t)
5302 (add-hook 'smalltalk-mode 'mdw-fontify-smalltalk t))
5303
5304;; m4.
5305
5306(defun mdw-setup-m4 ()
5307
5308 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
5309 ;; annoying: fix it.
5310 (modify-syntax-entry ?{ "(")
5311 (modify-syntax-entry ?} ")")
5312
5313 ;; Fill prefix.
5314 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
5315
5316(dolist (hook '(m4-mode-hook autoconf-mode-hook autotest-mode-hook))
5317 (add-hook hook #'mdw-misc-mode-config t)
5318 (add-hook hook #'mdw-setup-m4 t))
5319
5320;; Make.
5321
5322(progn
5323 (add-hook 'makefile-mode-hook 'mdw-misc-mode-config t))
5324
5325;; nroff/troff.
5326
5327(progn
5328 (add-hook 'nroff-mode-hook 'mdw-misc-mode-config t))
5329
5330;;;--------------------------------------------------------------------------
5331;;; Text mode.
5332
5333(defun mdw-text-mode ()
5334 (setq fill-column 72)
5335 (flyspell-mode t)
5336 (mdw-standard-fill-prefix
5337 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
5338 (auto-fill-mode 1))
5339
5340(eval-after-load "flyspell"
5341 '(define-key flyspell-mode-map "\C-\M-i" nil))
5342
5343(progn
5344 (add-hook 'text-mode-hook 'mdw-text-mode t))
5345
5346;;;--------------------------------------------------------------------------
5347;;; Outline and hide/show modes.
5348
5349(defun mdw-outline-collapse-all ()
5350 "Completely collapse everything in the entire buffer."
5351 (interactive)
5352 (save-excursion
5353 (goto-char (point-min))
5354 (while (< (point) (point-max))
5355 (hide-subtree)
5356 (forward-line))))
5357
5358(setq hs-hide-comments-when-hiding-all nil)
5359
5360(defadvice hs-hide-all (after hide-first-comment activate)
5361 (save-excursion (hs-hide-initial-comment-block)))
5362
5363;;;--------------------------------------------------------------------------
5364;;; Shell mode.
5365
5366(defun mdw-sh-mode-setup ()
5367 (local-set-key [?\C-a] 'comint-bol)
5368 (add-hook 'comint-output-filter-functions
5369 'comint-watch-for-password-prompt))
5370
5371(defun mdw-term-mode-setup ()
5372 (setq term-prompt-regexp shell-prompt-pattern)
5373 (make-local-variable 'mouse-yank-at-point)
5374 (make-local-variable 'transient-mark-mode)
5375 (setq mouse-yank-at-point t)
5376 (auto-fill-mode -1)
5377 (setq tab-width 8))
5378
5379(defun comint-send-and-indent ()
5380 (interactive)
5381 (comint-send-input)
5382 (and mdw-auto-indent
5383 (indent-for-tab-command)))
5384
5385(defadvice comint-line-beginning-position
5386 (around mdw-calculate-it-properly () activate compile)
5387 "Calculate the actual line start for multi-line input."
5388 (if (or comint-use-prompt-regexp
5389 (eq (field-at-pos (point)) 'output))
5390 ad-do-it
5391 (setq ad-return-value
5392 (constrain-to-field (line-beginning-position) (point)))))
5393
5394(defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
5395(defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
5396(defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
5397(defun term-send-meta-meta-something ()
5398 (interactive)
5399 (term-send-raw-string "\e\e")
5400 (term-send-raw))
5401(eval-after-load 'term
5402 '(progn
5403 (define-key term-raw-map [?\e ?\e] nil)
5404 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
5405 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
5406 (define-key term-raw-map [M-right] 'term-send-meta-right)
5407 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
5408 (define-key term-raw-map [M-left] 'term-send-meta-left)
5409 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
5410
5411(defadvice term-exec (before program-args-list compile activate)
5412 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
5413This allows you to pass a list of arguments through `ansi-term'."
5414 (let ((program (ad-get-arg 2)))
5415 (if (listp program)
5416 (progn
5417 (ad-set-arg 2 (car program))
5418 (ad-set-arg 4 (cdr program))))))
5419
5420(defadvice term-exec-1 (around hack-environment compile activate)
5421 "Hack the environment inherited by inferiors in the terminal."
5422 (let ((process-environment (copy-tree process-environment)))
5423 (setenv "LD_PRELOAD" nil)
5424 ad-do-it))
5425
5426(defadvice shell (around hack-environment compile activate)
5427 "Hack the environment inherited by inferiors in the shell."
5428 (let ((process-environment (copy-tree process-environment)))
5429 (setenv "LD_PRELOAD" nil)
5430 ad-do-it))
5431
5432(defun ssh (host)
5433 "Open a terminal containing an ssh session to the HOST."
5434 (interactive "sHost: ")
5435 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
5436
5437(defcustom git-grep-command
5438 "env GIT_PAGER=cat git grep --no-color -nH -e "
5439 "The default command for \\[git-grep]."
5440 :type 'string)
5441
5442(defvar git-grep-history nil)
5443
5444(defun git-grep (command-args)
5445 "Run `git grep' with user-specified args and collect output in a buffer."
5446 (interactive
5447 (list (read-shell-command "Run git grep (like this): "
5448 git-grep-command 'git-grep-history)))
5449 (let ((grep-use-null-device nil))
5450 (grep command-args)))
5451
5452;;;--------------------------------------------------------------------------
5453;;; Magit configuration.
5454
5455(setq magit-diff-refine-hunk 't
5456 magit-view-git-manual-method 'man
5457 magit-log-margin '(nil age magit-log-margin-width t 18)
5458 magit-wip-after-save-local-mode-lighter ""
5459 magit-wip-after-apply-mode-lighter ""
5460 magit-wip-before-change-mode-lighter "")
5461(eval-after-load "magit"
5462 '(progn (global-magit-file-mode 1)
5463 (magit-wip-after-save-mode 1)
5464 (magit-wip-after-apply-mode 1)
5465 (magit-wip-before-change-mode 1)
5466 (add-to-list 'magit-no-confirm 'safe-with-wip)
5467 (add-to-list 'magit-no-confirm 'trash)
5468 (push '(:eval (if (or magit-wip-after-save-local-mode
5469 magit-wip-after-apply-mode
5470 magit-wip-before-change-mode)
5471 (format " wip:%s%s%s"
5472 (if magit-wip-after-apply-mode "A" "")
5473 (if magit-wip-before-change-mode "C" "")
5474 (if magit-wip-after-save-local-mode "S" ""))))
5475 minor-mode-alist)
5476 (dolist (popup '(magit-diff-popup
5477 magit-diff-refresh-popup
5478 magit-diff-mode-refresh-popup
5479 magit-revision-mode-refresh-popup))
5480 (magit-define-popup-switch popup ?R "Reverse diff" "-R"))
5481 (magit-define-popup-switch 'magit-rebase-popup ?r
5482 "Rebase merges" "--rebase-merges")))
5483
5484(defadvice magit-wip-commit-buffer-file
5485 (around mdw-just-this-buffer activate compile)
5486 (let ((magit-save-repository-buffers nil)) ad-do-it))
5487
5488(defadvice magit-discard
5489 (around mdw-delete-if-prefix-argument activate compile)
5490 (let ((magit-delete-by-moving-to-trash
5491 (and (null current-prefix-arg)
5492 magit-delete-by-moving-to-trash)))
5493 ad-do-it))
5494
5495(setq magit-repolist-columns
5496 '(("Name" 16 magit-repolist-column-ident nil)
5497 ("Version" 18 magit-repolist-column-version nil)
5498 ("St" 2 magit-repolist-column-dirty nil)
5499 ("L<U" 3 mdw-repolist-column-unpulled-from-upstream nil)
5500 ("L>U" 3 mdw-repolist-column-unpushed-to-upstream nil)
5501 ("Path" 32 magit-repolist-column-path nil)))
5502
5503(setq magit-repository-directories '(("~/etc/profile" . 0)
5504 ("~/src/" . 1)))
5505
5506(defadvice magit-list-repos (around mdw-dirname () activate compile)
5507 "Make sure the returned names are directory names.
5508Otherwise child processes get started in the wrong directory and
5509there is sadness."
5510 (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it)))
5511
5512(defun mdw-repolist-column-unpulled-from-upstream (_id)
5513 "Insert number of upstream commits not in the current branch."
5514 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
5515 (and upstream
5516 (let ((n (cadr (magit-rev-diff-count "HEAD" upstream))))
5517 (propertize (number-to-string n) 'face
5518 (if (> n 0) 'bold 'shadow))))))
5519
5520(defun mdw-repolist-column-unpushed-to-upstream (_id)
5521 "Insert number of commits in the current branch but not its upstream."
5522 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
5523 (and upstream
5524 (let ((n (car (magit-rev-diff-count "HEAD" upstream))))
5525 (propertize (number-to-string n) 'face
5526 (if (> n 0) 'bold 'shadow))))))
5527
5528(defun mdw-try-smerge ()
5529 (save-excursion
5530 (goto-char (point-min))
5531 (when (re-search-forward "^<<<<<<< " nil t)
5532 (smerge-mode 1))))
5533(add-hook 'find-file-hook 'mdw-try-smerge t)
5534
5535(defcustom mdw-magit-new-window-modes
5536 '(magit-diff-mode
5537 magit-log-mode
5538 magit-process-mode
5539 magit-revision-mode
5540 magit-stash-mode
5541 magit-status-mode)
5542 "Magit modes which should cause a new window to be used."
5543 :type '(repeat symbol))
5544
5545(defun mdw-display-magit-buffer (buffer)
5546 "Like `magit-display-buffer-traditional'.
5547But uses `mdw-magit-new-window-modes' for its list of modes
5548rather than baking the list into the function."
5549 (display-buffer buffer
5550 (let ((mode (with-current-buffer buffer major-mode)))
5551 (if (and (not mdw-designated-window)
5552 (derived-mode-p 'magit-mode)
5553 (mdw-submode-p mode 'magit-mode)
5554 (not (memq mode mdw-magit-new-window-modes)))
5555 '(display-buffer-same-window . nil)
5556 nil))))
5557(setq magit-display-buffer-function 'mdw-display-magit-buffer)
5558
5559(defun mdw-display-magit-file-buffer (buffer)
5560 "Show a file buffer from a diff."
5561 (select-window (display-buffer buffer)))
5562(setq magit-display-file-buffer-function 'mdw-display-magit-file-buffer)
5563
5564;;;--------------------------------------------------------------------------
5565;;; GUD, and especially GDB.
5566
5567;; Inhibit window dedication. I mean, seriously, wtf?
5568(defadvice gdb-display-buffer (after mdw-undedicated (buf) compile activate)
5569 "Don't make windows dedicated. Seriously."
5570 (set-window-dedicated-p ad-return-value nil))
5571(defadvice gdb-set-window-buffer
5572 (after mdw-undedicated (name &optional ignore-dedicated window)
5573 compile activate)
5574 "Don't make windows dedicated. Seriously."
5575 (set-window-dedicated-p (or window (selected-window)) nil))
5576
5577(defadvice gud-find-expr
5578 (around mdw-inhibit-read-only (&rest args) compile activate)
5579 "Inhibit errors caused by my setting of `comint-prompt-read-only'."
5580 (let ((inhibit-read-only t)) ad-do-it))
5581
5582;;;--------------------------------------------------------------------------
5583;;; SQL stuff.
5584
5585(setq sql-postgres-options '("-n" "-P" "pager=off")
5586 sql-postgres-login-params
5587 '((user :default "mdw")
5588 (database :default "mdw")
5589 (server :default "db.distorted.org.uk")))
5590
5591;;;--------------------------------------------------------------------------
5592;;; Man pages.
5593
5594;; Turn off `noip' when running `man': it interferes with `man-db''s own
5595;; seccomp(2)-based sandboxing, which is (in this case, at least) strictly
5596;; better.
5597(defadvice Man-getpage-in-background
5598 (around mdw-inhibit-noip (topic) compile activate)
5599 "Inhibit the `noip' preload hack when invoking `man'."
5600 (let* ((old-preload (getenv "LD_PRELOAD"))
5601 (preloads (and old-preload
5602 (save-match-data (split-string old-preload ":"))))
5603 (any nil)
5604 (filtered nil))
5605 (save-match-data
5606 (while preloads
5607 (let ((item (pop preloads)))
5608 (if (string-match "\\(/\\|^\\)noip\.so\\(:\\|$\\)" item)
5609 (setq any t)
5610 (push item filtered)))))
5611 (if any
5612 (unwind-protect
5613 (progn
5614 (setenv "LD_PRELOAD"
5615 (and filtered
5616 (with-output-to-string
5617 (setq filtered (nreverse filtered))
5618 (let ((first t))
5619 (while filtered
5620 (if first (setq first nil)
5621 (write-char ?:))
5622 (write-string (pop filtered)))))))
5623 ad-do-it)
5624 (setenv "LD_PRELOAD" old-preload))
5625 ad-do-it)))
5626
5627;;;--------------------------------------------------------------------------
5628;;; MPC configuration.
5629
5630(eval-when-compile (trap (require 'mpc)))
5631
5632(setq mpc-browser-tags '(Artist|Composer|Performer Album|Playlist))
5633
5634(defun mdw-mpc-now-playing ()
5635 (interactive)
5636 (require 'mpc)
5637 (save-excursion
5638 (set-buffer (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))))
5639 (mpc--status-callback))
5640 (let ((state (cdr (assq 'state mpc-status))))
5641 (cond ((member state '("stop"))
5642 (message "mpd stopped."))
5643 ((member state '("play" "pause"))
5644 (let* ((artist (cdr (assq 'Artist mpc-status)))
5645 (album (cdr (assq 'Album mpc-status)))
5646 (title (cdr (assq 'Title mpc-status)))
5647 (file (cdr (assq 'file mpc-status)))
5648 (duration-string (cdr (assq 'Time mpc-status)))
5649 (time-string (cdr (assq 'time mpc-status)))
5650 (time (and time-string
5651 (string-to-number
5652 (if (string-match ":" time-string)
5653 (substring time-string
5654 0 (match-beginning 0))
5655 (time-string)))))
5656 (duration (and duration-string
5657 (string-to-number duration-string)))
5658 (pos (and time duration
5659 (format " [%d:%02d/%d:%02d]"
5660 (/ time 60) (mod time 60)
5661 (/ duration 60) (mod duration 60))))
5662 (fmt (cond ((and artist title)
5663 (format "`%s' by %s%s" title artist
5664 (if album (format ", from `%s'" album)
5665 "")))
5666 (file
5667 (format "`%s' (no tags)" file))
5668 (t
5669 "(no idea what's playing!)"))))
5670 (if (string= state "play")
5671 (message "mpd playing %s%s" fmt (or pos ""))
5672 (message "mpd paused in %s%s" fmt (or pos "")))))
5673 (t
5674 (message "mpd in unknown state `%s'" state)))))
5675
5676(defmacro mdw-define-mpc-wrapper (func bvl interactive &rest body)
5677 `(defun ,func ,bvl
5678 (interactive ,@interactive)
5679 (require 'mpc)
5680 ,@body
5681 (mdw-mpc-now-playing)))
5682
5683(mdw-define-mpc-wrapper mdw-mpc-play-or-pause () nil
5684 (if (member (cdr (assq 'state (mpc-cmd-status))) '("play"))
5685 (mpc-pause)
5686 (mpc-play)))
5687
5688(mdw-define-mpc-wrapper mdw-mpc-next () nil (mpc-next))
5689(mdw-define-mpc-wrapper mdw-mpc-prev () nil (mpc-prev))
5690(mdw-define-mpc-wrapper mdw-mpc-stop () nil (mpc-stop))
5691
5692(defun mdw-mpc-louder (step)
5693 (interactive (list (if current-prefix-arg
5694 (prefix-numeric-value current-prefix-arg)
5695 +10)))
5696 (mpc-proc-cmd (format "volume %+d" step)))
5697
5698(defun mdw-mpc-quieter (step)
5699 (interactive (list (if current-prefix-arg
5700 (prefix-numeric-value current-prefix-arg)
5701 +10)))
5702 (mpc-proc-cmd (format "volume %+d" (- step))))
5703
5704(defun mdw-mpc-hack-lines (arg interactivep func)
5705 (if (and interactivep (use-region-p))
5706 (let ((from (region-beginning)) (to (region-end)))
5707 (goto-char from)
5708 (beginning-of-line)
5709 (funcall func)
5710 (forward-line)
5711 (while (< (point) to)
5712 (funcall func)
5713 (forward-line)))
5714 (let ((n (prefix-numeric-value arg)))
5715 (cond ((cl-minusp n)
5716 (unless (bolp)
5717 (beginning-of-line)
5718 (funcall func)
5719 (cl-incf n))
5720 (while (cl-minusp n)
5721 (forward-line -1)
5722 (funcall func)
5723 (cl-incf n)))
5724 (t
5725 (beginning-of-line)
5726 (while (cl-plusp n)
5727 (funcall func)
5728 (forward-line)
5729 (cl-decf n)))))))
5730
5731(defun mdw-mpc-select-one ()
5732 (when (and (get-char-property (point) 'mpc-file)
5733 (not (get-char-property (point) 'mpc-select)))
5734 (mpc-select-toggle)))
5735
5736(defun mdw-mpc-unselect-one ()
5737 (when (get-char-property (point) 'mpc-select)
5738 (mpc-select-toggle)))
5739
5740(defun mdw-mpc-select (&optional arg interactivep)
5741 (interactive (list current-prefix-arg t))
5742 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
5743
5744(defun mdw-mpc-unselect (&optional arg interactivep)
5745 (interactive (list current-prefix-arg t))
5746 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one))
5747
5748(defun mdw-mpc-unselect-backwards (arg)
5749 (interactive "p")
5750 (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one))
5751
5752(defun mdw-mpc-unselect-all ()
5753 (interactive)
5754 (setq mpc-select nil)
5755 (mpc-selection-refresh))
5756
5757(defun mdw-mpc-next-line (arg)
5758 (interactive "p")
5759 (beginning-of-line)
5760 (forward-line arg))
5761
5762(defun mdw-mpc-previous-line (arg)
5763 (interactive "p")
5764 (beginning-of-line)
5765 (forward-line (- arg)))
5766
5767(defun mdw-mpc-playlist-add (&optional arg interactivep)
5768 (interactive (list current-prefix-arg t))
5769 (let ((mpc-select mpc-select))
5770 (when (or arg (and interactivep (use-region-p)))
5771 (setq mpc-select nil)
5772 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
5773 (setq mpc-select (reverse mpc-select))
5774 (mpc-playlist-add)))
5775
5776(defun mdw-mpc-playlist-delete (&optional arg interactivep)
5777 (interactive (list current-prefix-arg t))
5778 (setq mpc-select (nreverse mpc-select))
5779 (mpc-select-save
5780 (when (or arg (and interactivep (use-region-p)))
5781 (setq mpc-select nil)
5782 (mpc-selection-refresh)
5783 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
5784 (mpc-playlist-delete)))
5785
5786(defun mdw-mpc-hack-tagbrowsers ()
5787 (setq-local mode-line-format
5788 '("%e"
5789 mode-line-frame-identification
5790 mode-line-buffer-identification)))
5791(add-hook 'mpc-tagbrowser-mode-hook 'mdw-mpc-hack-tagbrowsers)
5792
5793(defun mdw-mpc-hack-songs ()
5794 (setq-local header-line-format
5795 ;; '("MPC " mpc-volume " " mpc-current-song)
5796 (list (propertize " " 'display '(space :align-to 0))
5797 ;; 'mpc-songs-format-description
5798 '(:eval
5799 (let ((deactivate-mark) (hscroll (window-hscroll)))
5800 (with-temp-buffer
5801 (mpc-format mpc-songs-format 'self hscroll)
5802 ;; That would be simpler than the hscroll handling in
5803 ;; mpc-format, but currently move-to-column does not
5804 ;; recognize :space display properties.
5805 ;; (move-to-column hscroll)
5806 ;; (delete-region (point-min) (point))
5807 (buffer-string)))))))
5808(add-hook 'mpc-songs-mode-hook 'mdw-mpc-hack-songs)
5809
5810(eval-after-load "mpc"
5811 '(progn
5812 (define-key mpc-mode-map "m" 'mdw-mpc-select)
5813 (define-key mpc-mode-map "u" 'mdw-mpc-unselect)
5814 (define-key mpc-mode-map "\177" 'mdw-mpc-unselect-backwards)
5815 (define-key mpc-mode-map "\e\177" 'mdw-mpc-unselect-all)
5816 (define-key mpc-mode-map "n" 'mdw-mpc-next-line)
5817 (define-key mpc-mode-map "p" 'mdw-mpc-previous-line)
5818 (define-key mpc-mode-map "/" 'mpc-songs-search)
5819 (setq mpc-songs-mode-map (make-sparse-keymap))
5820 (set-keymap-parent mpc-songs-mode-map mpc-mode-map)
5821 (define-key mpc-songs-mode-map "l" 'mpc-playlist)
5822 (define-key mpc-songs-mode-map "+" 'mdw-mpc-playlist-add)
5823 (define-key mpc-songs-mode-map "-" 'mdw-mpc-playlist-delete)
5824 (define-key mpc-songs-mode-map "\r" 'mpc-songs-jump-to)))
5825
5826;;;--------------------------------------------------------------------------
5827;;; Inferior Emacs Lisp.
5828
5829(setq comint-prompt-read-only t)
5830
5831(eval-after-load "comint"
5832 '(progn
5833 (define-key comint-mode-map "\C-w" 'comint-kill-region)
5834 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
5835
5836(eval-after-load "ielm"
5837 '(progn
5838 (define-key ielm-map "\C-w" 'comint-kill-region)
5839 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
5840
5841;;;----- That's all, folks --------------------------------------------------
5842
5843(provide 'dot-emacs)