dot/profile: Inhibit angry-fruit-salad errors from things.
[profile] / el / dot-emacs.el
CommitLineData
502f4699 1;;; -*- mode: emacs-lisp; coding: utf-8 -*-
f617db13 2;;;
f617db13
MW
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.
852cd5fb 14;;;
f617db13
MW
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.
852cd5fb 19;;;
f617db13
MW
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
6132bc01
MW
24;;;--------------------------------------------------------------------------
25;;; Check command-line.
c7a8da49 26
61aab372
MW
27(defun mdw-check-command-line-switch (switch)
28 (let ((probe nil) (next command-line-args) (found nil))
29 (while next
30 (cond ((string= (car next) switch)
31 (setq found t)
32 (if probe (rplacd probe (cdr next))
33 (setq command-line-args (cdr next))))
34 (t
35 (setq probe next)))
36 (setq next (cdr next)))
37 found))
38
c7a8da49
MW
39(defvar mdw-fast-startup nil
40 "Whether .emacs should optimize for rapid startup.
41This may be at the expense of cool features.")
61aab372
MW
42(setq mdw-fast-startup
43 (mdw-check-command-line-switch "--mdw-fast-startup"))
c7a8da49 44
3a87e7ef
MW
45(defvar mdw-splashy-startup nil
46 "Whether to show a splash screen and related frippery.")
47(setq mdw-splashy-startup
48 (mdw-check-command-line-switch "--mdw-splashy-startup"))
49
6132bc01
MW
50;;;--------------------------------------------------------------------------
51;;; Some general utilities.
f617db13 52
417dcddd
MW
53(eval-when-compile
54 (unless (fboundp 'make-regexp)
55 (load "make-regexp"))
56 (require 'cl))
c7a8da49
MW
57
58(defmacro mdw-regexps (&rest list)
59 "Turn a LIST of strings into a single regular expression at compile-time."
9e789ed5
MW
60 (declare (indent nil)
61 (debug 0))
417dcddd 62 `',(make-regexp list))
c7a8da49 63
a1b01eb3
MW
64(defun mdw-wrong ()
65 "This is not the key sequence you're looking for."
66 (interactive)
67 (error "wrong button"))
68
e8ea88ba
MW
69(defun mdw-emacs-version-p (major &optional minor)
70 "Return non-nil if the running Emacs is at least version MAJOR.MINOR."
71 (or (> emacs-major-version major)
72 (and (= emacs-major-version major)
73 (>= emacs-minor-version (or minor 0)))))
74
6132bc01 75;; Some error trapping.
f617db13
MW
76;;
77;; If individual bits of this file go tits-up, we don't particularly want
78;; the whole lot to stop right there and then, because it's bloody annoying.
79
80(defmacro trap (&rest forms)
81 "Execute FORMS without allowing errors to propagate outside."
9e789ed5
MW
82 (declare (indent 0)
83 (debug t))
f617db13
MW
84 `(condition-case err
85 ,(if (cdr forms) (cons 'progn forms) (car forms))
8df912e4
MW
86 (error (message "Error (trapped): %s in %s"
87 (error-message-string err)
88 ',forms))))
f617db13 89
6132bc01 90;; Configuration reading.
f141fe0f
MW
91
92(defvar mdw-config nil)
93(defun mdw-config (sym)
94 "Read the configuration variable named SYM."
95 (unless mdw-config
daff679f
MW
96 (setq mdw-config
97 (flet ((replace (what with)
98 (goto-char (point-min))
99 (while (re-search-forward what nil t)
100 (replace-match with t))))
101 (with-temp-buffer
102 (insert-file-contents "~/.mdw.conf")
103 (replace "^[ \t]*\\(#.*\\|\\)\n" "")
104 (replace (concat "^[ \t]*"
105 "\\([-a-zA-Z0-9_.]*\\)"
106 "[ \t]*=[ \t]*"
107 "\\(.*[^ \t\n]\\|\\)"
108 "[ \t]**\\(\n\\|$\\)")
109 "(\\1 . \"\\2\")\n")
110 (car (read-from-string
111 (concat "(" (buffer-string) ")")))))))
f141fe0f
MW
112 (cdr (assq sym mdw-config)))
113
c7203018
MW
114;; Width configuration.
115
116(defvar mdw-column-width
117 (string-to-number (or (mdw-config 'emacs-width) "77"))
118 "Width of Emacs columns.")
119(defvar mdw-text-width mdw-column-width
120 "Expected width of text within columns.")
121(put 'mdw-text-width 'safe-local-variable 'integerp)
122
18bb0f77
MW
123;; Local variables hacking.
124
125(defun run-local-vars-mode-hook ()
126 "Run a hook for the major-mode after local variables have been processed."
127 (run-hooks (intern (concat (symbol-name major-mode)
128 "-local-variables-hook"))))
129(add-hook 'hack-local-variables-hook 'run-local-vars-mode-hook)
130
6132bc01 131;; Set up the load path convincingly.
eac7b622
MW
132
133(dolist (dir (append (and (boundp 'debian-emacs-flavor)
134 (list (concat "/usr/share/"
135 (symbol-name debian-emacs-flavor)
136 "/site-lisp")))))
137 (dolist (sub (directory-files dir t))
138 (when (and (file-accessible-directory-p sub)
139 (not (member sub load-path)))
140 (setq load-path (nconc load-path (list sub))))))
141
6132bc01 142;; Is an Emacs library available?
cb6e2cd1
MW
143
144(defun library-exists-p (name)
6132bc01
MW
145 "Return non-nil if NAME is an available library.
146Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
147load path. The non-nil value is the filename we found for the
148library."
cb6e2cd1
MW
149 (let ((path load-path) elt (foundp nil))
150 (while (and path (not foundp))
151 (setq elt (car path))
152 (setq path (cdr path))
153 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
154 (and (file-exists-p file) file))
155 (let ((file (concat elt "/" name ".el")))
156 (and (file-exists-p file) file)))))
157 foundp))
158
159(defun maybe-autoload (symbol file &optional docstring interactivep type)
160 "Set an autoload if the file actually exists."
161 (and (library-exists-p file)
162 (autoload symbol file docstring interactivep type)))
163
8183de08
MW
164(defun mdw-kick-menu-bar (&optional frame)
165 "Regenerate FRAME's menu bar so it doesn't have empty menus."
166 (interactive)
167 (unless frame (setq frame (selected-frame)))
168 (let ((old (frame-parameter frame 'menu-bar-lines)))
169 (set-frame-parameter frame 'menu-bar-lines 0)
170 (set-frame-parameter frame 'menu-bar-lines old)))
171
6132bc01 172;; Splitting windows.
f617db13 173
8c2b05d5
MW
174(unless (fboundp 'scroll-bar-columns)
175 (defun scroll-bar-columns (side)
176 (cond ((eq side 'left) 0)
177 (window-system 3)
178 (t 1))))
179(unless (fboundp 'fringe-columns)
180 (defun fringe-columns (side)
181 (cond ((not window-system) 0)
182 ((eq side 'left) 1)
183 (t 2))))
184
3ba0b777
MW
185(defun mdw-horizontal-window-overhead ()
186 "Computes the horizontal window overhead.
187This is the number of columns used by fringes, scroll bars and other such
188cruft."
189 (if (not window-system)
190 1
191 (let ((tot 0))
192 (dolist (what '(scroll-bar fringe))
193 (dolist (side '(left right))
194 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
195 side))))
196 tot)))
197
198(defun mdw-split-window-horizontally (&optional width)
199 "Split a window horizontally.
200Without a numeric argument, split the window approximately in
201half. With a numeric argument WIDTH, allocate WIDTH columns to
202the left-hand window (if positive) or -WIDTH columns to the
203right-hand window (if negative). Space for scroll bars and
204fringes is not taken out of the allowance for WIDTH, unlike
205\\[split-window-horizontally]."
206 (interactive "P")
207 (split-window-horizontally
208 (cond ((null width) nil)
209 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
210 ((< width 0) width))))
211
22e1b8c3
MW
212(defun mdw-preferred-column-width ()
213 "Return the preferred column width."
214 (if (and window-system (mdw-emacs-version-p 22)) mdw-column-width
215 (1+ mdw-column-width)))
216
8c2b05d5 217(defun mdw-divvy-window (&optional width)
f617db13 218 "Split a wide window into appropriate widths."
8c2b05d5 219 (interactive "P")
22e1b8c3
MW
220 (setq width (if width (prefix-numeric-value width)
221 (mdw-preferred-column-width)))
b5d724dd 222 (let* ((win (selected-window))
3ba0b777 223 (sb-width (mdw-horizontal-window-overhead))
b5d724dd 224 (c (/ (+ (window-width) sb-width)
8c2b05d5 225 (+ width sb-width))))
f617db13
MW
226 (while (> c 1)
227 (setq c (1- c))
8c2b05d5 228 (split-window-horizontally (+ width sb-width))
f617db13
MW
229 (other-window 1))
230 (select-window win)))
231
cc8708fc
MW
232(defun mdw-set-frame-width (columns &optional width)
233 (interactive "nColumns:
234P")
22e1b8c3
MW
235 (setq width (if width (prefix-numeric-value width)
236 (mdw-preferred-column-width)))
cc8708fc
MW
237 (let ((sb-width (mdw-horizontal-window-overhead)))
238 (set-frame-width (selected-frame)
239 (- (* columns (+ width sb-width))
240 sb-width))
241 (mdw-divvy-window width)))
242
cc2be23e
MW
243;; Don't raise windows unless I say so.
244
245(defvar mdw-inhibit-raise-frame nil
246 "*Whether `raise-frame' should do nothing when the frame is mapped.")
247
248(defadvice raise-frame
249 (around mdw-inhibit (&optional frame) activate compile)
250 "Don't actually do anything if `mdw-inhibit-raise-frame' is true, and the
251frame is actually mapped on the screen."
252 (if mdw-inhibit-raise-frame
253 (make-frame-visible frame)
254 ad-do-it))
255
256(defmacro mdw-advise-to-inhibit-raise-frame (function)
257 "Advise the FUNCTION not to raise frames, even if it wants to."
258 `(defadvice ,function
259 (around mdw-inhibit-raise (&rest hunoz) activate compile)
260 "Don't raise the window unless you have to."
261 (let ((mdw-inhibit-raise-frame t))
262 ad-do-it)))
263
264(mdw-advise-to-inhibit-raise-frame select-frame-set-input-focus)
b8e4b4a9 265(mdw-advise-to-inhibit-raise-frame appt-disp-window)
a3289165 266(mdw-advise-to-inhibit-raise-frame mouse-select-window)
cc2be23e 267
a1e4004c
MW
268;; Bug fix for markdown-mode, which breaks point positioning during
269;; `query-replace'.
270(defadvice markdown-check-change-for-wiki-link
271 (around mdw-save-match activate compile)
272 "Save match data around the `markdown-mode' `after-change-functions' hook."
273 (save-match-data ad-do-it))
274
d54a4cf3
MW
275;; Bug fix for `bbdb-canonicalize-address': on Emacs 24, `run-hook-with-args'
276;; always returns nil, with the result that all email addresses are lost.
277;; Replace the function entirely.
278(defadvice bbdb-canonicalize-address
279 (around mdw-bug-fix activate compile)
280 "Don't use `run-hook-with-args', because that doesn't work."
281 (let ((net (ad-get-arg 0)))
282
283 ;; Make sure this is a proper hook list.
284 (if (functionp bbdb-canonicalize-net-hook)
285 (setq bbdb-canonicalize-net-hook (list bbdb-canonicalize-net-hook)))
286
287 ;; Iterate over the hooks until things converge.
288 (let ((donep nil))
289 (while (not donep)
290 (let (next (changep nil)
291 hook (hooks bbdb-canonicalize-net-hook))
292 (while hooks
293 (setq hook (pop hooks))
294 (setq next (funcall hook net))
295 (if (not (equal next net))
296 (setq changep t
297 net next)))
298 (setq donep (not changep)))))
299 (setq ad-return-value net)))
300
c4b18360
MW
301;; Transient mark mode hacks.
302
303(defadvice exchange-point-and-mark
304 (around mdw-highlight (&optional arg) activate compile)
305 "Maybe don't actually exchange point and mark.
306If `transient-mark-mode' is on and the mark is inactive, then
307just activate it. A non-trivial prefix argument will force the
308usual behaviour. A trivial prefix argument (i.e., just C-u) will
309activate the mark and temporarily enable `transient-mark-mode' if
310it's currently off."
311 (cond ((or mark-active
312 (and (not transient-mark-mode) (not arg))
313 (and arg (or (not (consp arg))
314 (not (= (car arg) 4)))))
315 ad-do-it)
316 (t
317 (or transient-mark-mode (setq transient-mark-mode 'only))
318 (set-mark (mark t)))))
319
6132bc01 320;; Functions for sexp diary entries.
f617db13 321
aede9fd7
MW
322(defun mdw-not-org-mode (form)
323 "As FORM, but not in Org mode agenda."
324 (and (not mdw-diary-for-org-mode-p)
325 (eval form)))
326
f617db13
MW
327(defun mdw-weekday (l)
328 "Return non-nil if `date' falls on one of the days of the week in L.
6132bc01
MW
329L is a list of day numbers (from 0 to 6 for Sunday through to
330Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
331the date stored in `date' falls on a listed day, then the
332function returns non-nil."
f617db13
MW
333 (let ((d (calendar-day-of-week date)))
334 (or (memq d l)
335 (memq (nth d '(sunday monday tuesday wednesday
336 thursday friday saturday)) l))))
337
d401f71b
MW
338(defun mdw-discordian-date (date)
339 "Return the Discordian calendar date corresponding to DATE.
340
341The return value is (YOLD . st-tibs-day) or (YOLD SEASON DAYNUM DOW).
342
343The original is by David Pearson. I modified it to produce date components
344as output rather than a string."
345 (let* ((days ["Sweetmorn" "Boomtime" "Pungenday"
346 "Prickle-Prickle" "Setting Orange"])
347 (months ["Chaos" "Discord" "Confusion"
348 "Bureaucracy" "Aftermath"])
349 (day-count [0 31 59 90 120 151 181 212 243 273 304 334])
350 (year (- (extract-calendar-year date) 1900))
351 (month (1- (extract-calendar-month date)))
352 (day (1- (extract-calendar-day date)))
353 (julian (+ (aref day-count month) day))
354 (dyear (+ year 3066)))
355 (if (and (= month 1) (= day 28))
356 (cons dyear 'st-tibs-day)
357 (list dyear
358 (aref months (floor (/ julian 73)))
359 (1+ (mod julian 73))
360 (aref days (mod julian 5))))))
361
362(defun mdw-diary-discordian-date ()
363 "Convert the date in `date' to a string giving the Discordian date."
364 (let* ((ddate (mdw-discordian-date date))
365 (tail (format "in the YOLD %d" (car ddate))))
366 (if (eq (cdr ddate) 'st-tibs-day)
367 (format "St Tib's Day %s" tail)
368 (let ((season (cadr ddate))
369 (daynum (caddr ddate))
370 (dayname (cadddr ddate)))
371 (format "%s, the %d%s day of %s %s"
372 dayname
373 daynum
374 (let ((ldig (mod daynum 10)))
375 (cond ((= ldig 1) "st")
376 ((= ldig 2) "nd")
377 ((= ldig 3) "rd")
378 (t "th")))
379 season
380 tail)))))
381
f617db13
MW
382(defun mdw-todo (&optional when)
383 "Return non-nil today, or on WHEN, whichever is later."
384 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
385 (d (calendar-absolute-from-gregorian date)))
386 (if when
387 (setq w (max w (calendar-absolute-from-gregorian
388 (cond
389 ((not european-calendar-style)
390 when)
391 ((> (car when) 100)
392 (list (nth 1 when)
393 (nth 2 when)
394 (nth 0 when)))
395 (t
396 (list (nth 1 when)
397 (nth 0 when)
398 (nth 2 when))))))))
399 (eq w d)))
400
aede9fd7
MW
401(defvar mdw-diary-for-org-mode-p nil)
402
403(defadvice org-agenda-list (around mdw-preserve-links activate)
404 (let ((mdw-diary-for-org-mode-p t))
405 ad-do-it))
406
1d342abe 407(defadvice diary-add-to-list (before mdw-trim-leading-space compile activate)
9f58a8d2
MW
408 "Trim leading space from the diary entry string."
409 (save-match-data
2745469d
MW
410 (let ((str (ad-get-arg 1))
411 (done nil) old)
412 (while (not done)
413 (setq old str)
414 (setq str (cond ((null str) nil)
415 ((string-match "\\(^\\|\n\\)[ \t]+" str)
416 (replace-match "\\1" nil nil str))
aede9fd7
MW
417 ((and mdw-diary-for-org-mode-p
418 (string-match (concat
2745469d 419 "\\(^\\|\n\\)"
aede9fd7
MW
420 "\\(" diary-time-regexp
421 "\\(-" diary-time-regexp "\\)?"
2745469d
MW
422 "\\)"
423 "\\(\t[ \t]*\\| [ \t]+\\)")
aede9fd7 424 str))
2745469d 425 (replace-match "\\1\\2 " nil nil str))
aede9fd7
MW
426 ((and (not mdw-diary-for-org-mode-p)
427 (string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]"
428 str))
429 (replace-match "\\1" nil nil str))
2745469d
MW
430 (t str)))
431 (if (equal str old) (setq done t)))
432 (ad-set-arg 1 str))))
9f58a8d2 433
319736bd
MW
434(defadvice org-bbdb-anniversaries (after mdw-fixup-list compile activate)
435 "Return a string rather than a list."
436 (with-temp-buffer
437 (let ((anyp nil))
438 (dolist (e (let ((ee ad-return-value))
439 (if (atom ee) (list ee) ee)))
440 (when e
441 (when anyp (insert ?\n))
442 (insert e)
443 (setq anyp t)))
444 (setq ad-return-value
445 (and anyp (buffer-string))))))
446
6132bc01 447;; Fighting with Org-mode's evil key maps.
16fe7c41
MW
448
449(defvar mdw-evil-keymap-keys
450 '(([S-up] . [?\C-c up])
451 ([S-down] . [?\C-c down])
452 ([S-left] . [?\C-c left])
453 ([S-right] . [?\C-c right])
454 (([M-up] [?\e up]) . [C-up])
455 (([M-down] [?\e down]) . [C-down])
456 (([M-left] [?\e left]) . [C-left])
457 (([M-right] [?\e right]) . [C-right]))
458 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
459The value is an alist mapping evil keys (as a list, or singleton)
460to good keys (in the same form).")
461
462(defun mdw-clobber-evil-keymap (keymap)
463 "Replace evil key bindings in the KEYMAP.
464Evil key bindings are defined in `mdw-evil-keymap-keys'."
465 (dolist (entry mdw-evil-keymap-keys)
466 (let ((binding nil)
467 (keys (if (listp (car entry))
468 (car entry)
469 (list (car entry))))
470 (replacements (if (listp (cdr entry))
471 (cdr entry)
472 (list (cdr entry)))))
473 (catch 'found
474 (dolist (key keys)
475 (setq binding (lookup-key keymap key))
476 (when binding
477 (throw 'found nil))))
478 (when binding
479 (dolist (key keys)
480 (define-key keymap key nil))
481 (dolist (key replacements)
482 (define-key keymap key binding))))))
483
1656a861
MW
484(defvar mdw-org-latex-defs
485 '(("strayman"
486 "\\documentclass{strayman}
f0dbee84
MW
487\\usepackage[utf8]{inputenc}
488\\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
f0dbee84 489\\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
1656a861
MW
490 ("\\section{%s}" . "\\section*{%s}")
491 ("\\subsection{%s}" . "\\subsection*{%s}")
492 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
493 ("\\paragraph{%s}" . "\\paragraph*{%s}")
494 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))
495
496(eval-after-load "org-latex"
497 '(setq org-export-latex-classes
498 (append mdw-org-latex-defs org-export-latex-classes)))
f0dbee84 499
fbc946b7
MW
500(eval-after-load "ox-latex"
501 '(setq org-latex-classes (append mdw-org-latex-defs org-latex-classes)
502 org-latex-default-packages-alist '(("AUTO" "inputenc" t)
503 ("T1" "fontenc" t)
504 ("" "fixltx2e" nil)
505 ("" "graphicx" t)
506 ("" "longtable" nil)
507 ("" "float" nil)
508 ("" "wrapfig" nil)
509 ("" "rotating" nil)
510 ("normalem" "ulem" t)
511 ("" "textcomp" t)
512 ("" "marvosym" t)
513 ("" "wasysym" t)
514 ("" "amssymb" t)
515 ("" "hyperref" nil)
516 "\\tolerance=1000")))
517
518
8ba985cb
MW
519(setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
520 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
521 org-export-docbook-xslt-stylesheet
522 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
523
5a0925a4
MW
524;; Glasses.
525
526(setq glasses-separator "-"
527 glasses-separate-parentheses-p nil
528 glasses-uncapitalize-p t)
529
5dccbe61
MW
530;; Some hacks to do with window placement.
531
532(defun mdw-clobber-other-windows-showing-buffer (buffer-or-name)
533 "Arrange that no windows on other frames are showing BUFFER-OR-NAME."
534 (interactive "bBuffer: ")
535 (let ((home-frame (selected-frame))
536 (buffer (get-buffer buffer-or-name))
537 (safe-buffer (get-buffer "*scratch*")))
6c4bd06b
MW
538 (dolist (frame (frame-list))
539 (unless (eq frame home-frame)
540 (dolist (window (window-list frame))
541 (when (eq (window-buffer window) buffer)
542 (set-window-buffer window safe-buffer)))))))
5dccbe61
MW
543
544(defvar mdw-inhibit-walk-windows nil
545 "If non-nil, then `walk-windows' does nothing.
546This is used by advice on `switch-to-buffer-other-frame' to inhibit finding
547buffers in random frames.")
548
549(defadvice walk-windows (around mdw-inhibit activate)
550 "If `mdw-inhibit-walk-windows' is non-nil, then do nothing."
551 (and (not mdw-inhibit-walk-windows)
552 ad-do-it))
553
554(defadvice switch-to-buffer-other-frame
555 (around mdw-always-new-frame activate)
556 "Always make a new frame.
557Even if an existing window in some random frame looks tempting."
558 (let ((mdw-inhibit-walk-windows t)) ad-do-it))
559
560(defadvice display-buffer (before mdw-inhibit-other-frames activate)
561 "Don't try to do anything fancy with other frames.
562Pretend they don't exist. They might be on other display devices."
563 (ad-set-arg 2 nil))
564
6132bc01 565;;;--------------------------------------------------------------------------
b7fc31ec
MW
566;;; Improved compilation machinery.
567
568;; Uprated version of M-x compile.
569
570(setq compile-command
571 (let ((ncpu (with-temp-buffer
572 (insert-file-contents "/proc/cpuinfo")
573 (buffer-string)
574 (count-matches "^processor\\s-*:"))))
575 (format "make -j%d -k" (* 2 ncpu))))
576
577(defun mdw-compilation-buffer-name (mode)
578 (concat "*" (downcase mode) ": "
579 (abbreviate-file-name default-directory) "*"))
580(setq compilation-buffer-name-function 'mdw-compilation-buffer-name)
581
582(eval-after-load "compile"
583 '(progn
584 (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile)))
585
8845865d
MW
586(defadvice compile (around hack-environment compile activate)
587 "Hack the environment inherited by inferiors in the compilation."
f8592fee 588 (let ((process-environment (copy-tree process-environment)))
8845865d
MW
589 (setenv "LD_PRELOAD" nil)
590 ad-do-it))
591
b7fc31ec
MW
592(defun mdw-compile (command &optional directory comint)
593 "Initiate a compilation COMMAND, maybe in a different DIRECTORY.
594The DIRECTORY may be nil to not change. If COMINT is t, then
595start an interactive compilation.
596
597Interactively, prompt for the command if the variable
598`compilation-read-command' is non-nil, or if requested through
599the prefix argument. Prompt for the directory, and run
600interactively, if requested through the prefix.
601
602Use a prefix of 4, 6, 12, or 14, or type C-u between one and three times, to
603force prompting for a directory.
604
605Use a prefix of 2, 6, 10, or 14, or type C-u three times, to force
606prompting for the command.
607
608Use a prefix of 8, 10, 12, or 14, or type C-u twice or three times,
609to force interactive compilation."
610 (interactive
611 (let* ((prefix (prefix-numeric-value current-prefix-arg))
612 (command (eval compile-command))
613 (dir (and (plusp (logand prefix #x54))
614 (read-directory-name "Compile in directory: "))))
615 (list (if (or compilation-read-command
616 (plusp (logand prefix #x42)))
617 (compilation-read-command command)
618 command)
619 dir
620 (plusp (logand prefix #x58)))))
621 (let ((default-directory (or directory default-directory)))
622 (compile command comint)))
623
50d3dd03
MW
624;; Flymake support.
625
626(defun mdw-find-build-dir (build-file)
627 (catch 'found
628 (let* ((src-dir (file-name-as-directory (expand-file-name ".")))
629 (dir src-dir))
630 (loop
631 (when (file-exists-p (concat dir build-file))
632 (throw 'found dir))
633 (let ((sub (expand-file-name (file-relative-name src-dir dir)
634 (concat dir "build/"))))
635 (catch 'give-up
636 (loop
637 (when (file-exists-p (concat sub build-file))
638 (throw 'found sub))
639 (when (string= sub dir) (throw 'give-up nil))
640 (setq sub (file-name-directory (directory-file-name sub))))))
641 (when (string= dir
642 (setq dir (file-name-directory
643 (directory-file-name dir))))
644 (throw 'found nil))))))
645
646(defun mdw-flymake-make-init ()
647 (let ((build-dir (mdw-find-build-dir "Makefile")))
648 (and build-dir
649 (let ((tmp-src (flymake-init-create-temp-buffer-copy
650 #'flymake-create-temp-inplace)))
651 (flymake-get-syntax-check-program-args
652 tmp-src build-dir t t
653 #'flymake-get-make-cmdline)))))
654
655(setq flymake-allowed-file-name-masks
f1150017 656 '(("\\.\\(?:[cC]\\|cc\\|cpp\\|cxx\\|c\\+\\+\\)\\'"
50d3dd03 657 mdw-flymake-make-init)
f1150017 658 ("\\.\\(?:[hH]\\|hh\\|hpp\\|hxx\\|h\\+\\+\\)\\'"
50d3dd03
MW
659 mdw-flymake-master-make-init)
660 ("\\.p[lm]" flymake-perl-init)))
661
662(setq flymake-mode-map
663 (let ((map (if (boundp 'flymake-mode-map)
664 flymake-mode-map
665 (make-sparse-keymap))))
666 (define-key map [?\C-c ?\C-f ?\C-p] 'flymake-goto-prev-error)
667 (define-key map [?\C-c ?\C-f ?\C-n] 'flymake-goto-next-error)
668 (define-key map [?\C-c ?\C-f ?\C-c] 'flymake-compile)
669 (define-key map [?\C-c ?\C-f ?\C-k] 'flymake-stop-all-syntax-checks)
670 (define-key map [?\C-c ?\C-f ?\C-e] 'flymake-popup-current-error-menu)
671 map))
672
b7fc31ec 673;;;--------------------------------------------------------------------------
6132bc01 674;;; Mail and news hacking.
a3bdb4d9
MW
675
676(define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
6132bc01 677 "Major mode for editing news and mail messages from external programs.
a3bdb4d9
MW
678Not much right now. Just support for doing MailCrypt stuff."
679 :syntax-table nil
680 :abbrev-table nil
681 (run-hooks 'mail-setup-hook))
682
683(define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
684
685(add-hook 'mdwail-mode-hook
686 (lambda ()
687 (set-buffer-file-coding-system 'utf-8)
688 (make-local-variable 'paragraph-separate)
689 (make-local-variable 'paragraph-start)
690 (setq paragraph-start
691 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
692 paragraph-start))
693 (setq paragraph-separate
694 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
695 paragraph-separate))))
696
6132bc01 697;; How to encrypt in mdwmail.
a3bdb4d9
MW
698
699(defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
700 (or start
701 (setq start (save-excursion
702 (goto-char (point-min))
703 (or (search-forward "\n\n" nil t) (point-min)))))
704 (or end
705 (setq end (point-max)))
706 (mc-encrypt-generic recip scm start end from sign))
707
6132bc01 708;; How to sign in mdwmail.
a3bdb4d9
MW
709
710(defun mdwmail-mc-sign (key scm start end uclr)
711 (or start
712 (setq start (save-excursion
713 (goto-char (point-min))
714 (or (search-forward "\n\n" nil t) (point-min)))))
715 (or end
716 (setq end (point-max)))
717 (mc-sign-generic key scm start end uclr))
718
6132bc01 719;; Some signature mangling.
a3bdb4d9
MW
720
721(defun mdwmail-mangle-signature ()
722 (save-excursion
723 (goto-char (point-min))
724 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
725(add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
726(add-hook 'message-setup-hook 'mdwmail-mangle-signature)
727
6132bc01 728;; Insert my login name into message-ids, so I can score replies.
a3bdb4d9
MW
729
730(defadvice message-unique-id (after mdw-user-name last activate compile)
731 "Ensure that the user's name appears at the end of the message-id string,
732so that it can be used for convenient filtering."
733 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
734
6132bc01 735;; Tell my movemail hack where movemail is.
a3bdb4d9
MW
736;;
737;; This is needed to shup up warnings about LD_PRELOAD.
738
739(let ((path exec-path))
740 (while path
741 (let ((try (expand-file-name "movemail" (car path))))
742 (if (file-executable-p try)
743 (setenv "REAL_MOVEMAIL" try))
744 (setq path (cdr path)))))
745
4d5799eb
MW
746;; AUTHINFO GENERIC kludge.
747
748(defvar nntp-authinfo-generic nil
749 "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'.
750
751Use this to arrange for per-server settings.")
752
753(defun nntp-open-authinfo-kludge (buffer)
754 "Open a connection to SERVER using `authinfo-kludge'."
755 (let ((proc (start-process "nntpd" buffer
756 "env" (concat "NNTPAUTH="
757 (or nntp-authinfo-generic
758 (getenv "NNTPAUTH")
759 (error "NNTPAUTH unset")))
760 "authinfo-kludge" nntp-address)))
761 (set-buffer buffer)
762 (nntp-wait-for-string "^\r*200")
763 (beginning-of-line)
764 (delete-region (point-min) (point))
765 proc))
766
d17c6756 767(eval-after-load "erc"
3db66f7b 768 '(load "~/.ercrc.el"))
d17c6756 769
d2d1d5dc
MW
770;; Heavy-duty Gnus patching.
771
772(defun mdw-nnimap-transform-headers ()
773 (goto-char (point-min))
774 (let (article lines size string)
775 (block nil
776 (while (not (eobp))
777 (while (not (looking-at "\\* [0-9]+ FETCH"))
778 (delete-region (point) (progn (forward-line 1) (point)))
779 (when (eobp)
780 (return)))
781 (goto-char (match-end 0))
782 ;; Unfold quoted {number} strings.
783 (while (re-search-forward
784 "[^]][ (]{\\([0-9]+\\)}\r?\n"
785 (save-excursion
786 ;; Start of the header section.
787 (or (re-search-forward "] {[0-9]+}\r?\n" nil t)
788 ;; Start of the next FETCH.
789 (re-search-forward "\\* [0-9]+ FETCH" nil t)
790 (point-max)))
791 t)
792 (setq size (string-to-number (match-string 1)))
793 (delete-region (+ (match-beginning 0) 2) (point))
794 (setq string (buffer-substring (point) (+ (point) size)))
795 (delete-region (point) (+ (point) size))
796 (insert (format "%S" (mm-subst-char-in-string ?\n ?\s string)))
797 ;; [mdw] missing from upstream
798 (backward-char 1))
799 (beginning-of-line)
800 (setq article
801 (and (re-search-forward "UID \\([0-9]+\\)" (line-end-position)
802 t)
803 (match-string 1)))
804 (setq lines nil)
805 (setq size
806 (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)"
807 (line-end-position)
808 t)
809 (match-string 1)))
810 (beginning-of-line)
811 (when (search-forward "BODYSTRUCTURE" (line-end-position) t)
812 (let ((structure (ignore-errors
813 (read (current-buffer)))))
814 (while (and (consp structure)
815 (not (atom (car structure))))
816 (setq structure (car structure)))
817 (setq lines (if (and
818 (stringp (car structure))
819 (equal (upcase (nth 0 structure)) "MESSAGE")
820 (equal (upcase (nth 1 structure)) "RFC822"))
821 (nth 9 structure)
822 (nth 7 structure)))))
823 (delete-region (line-beginning-position) (line-end-position))
824 (insert (format "211 %s Article retrieved." article))
825 (forward-line 1)
826 (when size
827 (insert (format "Chars: %s\n" size)))
828 (when lines
829 (insert (format "Lines: %s\n" lines)))
830 ;; Most servers have a blank line after the headers, but
831 ;; Davmail doesn't.
832 (unless (re-search-forward "^\r$\\|^)\r?$" nil t)
833 (goto-char (point-max)))
834 (delete-region (line-beginning-position) (line-end-position))
835 (insert ".")
836 (forward-line 1)))))
837
838(eval-after-load 'nnimap
839 '(defalias 'nnimap-transform-headers
840 (symbol-function 'mdw-nnimap-transform-headers)))
841
6132bc01
MW
842;;;--------------------------------------------------------------------------
843;;; Utility functions.
f617db13 844
b5d724dd
MW
845(or (fboundp 'line-number-at-pos)
846 (defun line-number-at-pos (&optional pos)
847 (let ((opoint (or pos (point))) start)
848 (save-excursion
849 (save-restriction
850 (goto-char (point-min))
851 (widen)
852 (forward-line 0)
853 (setq start (point))
854 (goto-char opoint)
855 (forward-line 0)
856 (1+ (count-lines 1 (point))))))))
459c9fb2 857
f617db13 858(defun mdw-uniquify-alist (&rest alists)
f617db13 859 "Return the concatenation of the ALISTS with duplicate elements removed.
6132bc01
MW
860The first association with a given key prevails; others are
861ignored. The input lists are not modified, although they'll
862probably become garbage."
f617db13
MW
863 (and alists
864 (let ((start-list (cons nil nil)))
865 (mdw-do-uniquify start-list
866 start-list
867 (car alists)
868 (cdr alists)))))
869
f617db13 870(defun mdw-do-uniquify (done end l rest)
6132bc01
MW
871 "A helper function for mdw-uniquify-alist.
872The DONE argument is a list whose first element is `nil'. It
873contains the uniquified alist built so far. The leading `nil' is
874stripped off at the end of the operation; it's only there so that
875DONE always references a cons cell. END refers to the final cons
876cell in the DONE list; it is modified in place each time to avoid
877the overheads of `append'ing all the time. The L argument is the
878alist we're currently processing; the remaining alists are given
879in REST."
880
881 ;; There are several different cases to deal with here.
f617db13
MW
882 (cond
883
6132bc01
MW
884 ;; Current list isn't empty. Add the first item to the DONE list if
885 ;; there's not an item with the same KEY already there.
f617db13
MW
886 (l (or (assoc (car (car l)) done)
887 (progn
888 (setcdr end (cons (car l) nil))
889 (setq end (cdr end))))
890 (mdw-do-uniquify done end (cdr l) rest))
891
6132bc01
MW
892 ;; The list we were working on is empty. Shunt the next list into the
893 ;; current list position and go round again.
f617db13
MW
894 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
895
6132bc01
MW
896 ;; Everything's done. Remove the leading `nil' from the DONE list and
897 ;; return it. Finished!
f617db13
MW
898 (t (cdr done))))
899
f617db13
MW
900(defun date ()
901 "Insert the current date in a pleasing way."
902 (interactive)
903 (insert (save-excursion
904 (let ((buffer (get-buffer-create "*tmp*")))
905 (unwind-protect (progn (set-buffer buffer)
906 (erase-buffer)
907 (shell-command "date +%Y-%m-%d" t)
908 (goto-char (mark))
fbf8b18e 909 (delete-char -1)
f617db13
MW
910 (buffer-string))
911 (kill-buffer buffer))))))
912
f617db13
MW
913(defun uuencode (file &optional name)
914 "UUencodes a file, maybe calling it NAME, into the current buffer."
915 (interactive "fInput file name: ")
916
6132bc01 917 ;; If NAME isn't specified, then guess from the filename.
f617db13
MW
918 (if (not name)
919 (setq name
920 (substring file
921 (or (string-match "[^/]*$" file) 0))))
f617db13
MW
922 (print (format "uuencode `%s' `%s'" file name))
923
6132bc01 924 ;; Now actually do the thing.
f617db13
MW
925 (call-process "uuencode" file t nil name))
926
927(defvar np-file "~/.np"
928 "*Where the `now-playing' file is.")
929
930(defun np (&optional arg)
931 "Grabs a `now-playing' string."
932 (interactive)
933 (save-excursion
934 (or arg (progn
852cd5fb 935 (goto-char (point-max))
f617db13 936 (insert "\nNP: ")
daff679f 937 (insert-file-contents np-file)))))
f617db13 938
ae7460d4
MW
939(defun mdw-version-< (ver-a ver-b)
940 "Answer whether VER-A is strictly earlier than VER-B.
941VER-A and VER-B are version numbers, which are strings containing digit
942sequences separated by `.'."
943 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
944 (split-string ver-a "\\.")))
945 (lb (mapcar (lambda (x) (car (read-from-string x)))
946 (split-string ver-b "\\."))))
947 (catch 'done
948 (while t
949 (cond ((null la) (throw 'done lb))
950 ((null lb) (throw 'done nil))
951 ((< (car la) (car lb)) (throw 'done t))
f64c5a1a
MW
952 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))
953 (t (throw 'done nil)))))))
ae7460d4 954
c7a8da49 955(defun mdw-check-autorevert ()
6132bc01
MW
956 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
957This takes into consideration whether it's been found using
958tramp, which seems to get itself into a twist."
46e69f55
MW
959 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
960 nil)
961 ((and (buffer-file-name)
962 (fboundp 'tramp-tramp-file-p)
c7a8da49
MW
963 (tramp-tramp-file-p (buffer-file-name)))
964 (unless global-auto-revert-ignore-buffer
965 (setq global-auto-revert-ignore-buffer 'tramp)))
966 ((eq global-auto-revert-ignore-buffer 'tramp)
967 (setq global-auto-revert-ignore-buffer nil))))
968
969(defadvice find-file (after mdw-autorevert activate)
970 (mdw-check-autorevert))
971(defadvice write-file (after mdw-autorevert activate)
4d9f2d65 972 (mdw-check-autorevert))
eae0aa6d 973
a58a4227
MW
974(defun mdw-auto-revert ()
975 "Recheck all of the autorevertable buffers, and update VC modelines."
976 (interactive)
977 (let ((auto-revert-check-vc-info t))
978 (auto-revert-buffers)))
979
41a1f4fa
MW
980(defun comint-send-and-indent ()
981 (interactive)
982 (comint-send-input)
983 (and mdw-auto-indent
984 (indent-for-tab-command)))
985
986(defadvice comint-line-beginning-position
987 (around mdw-calculate-it-properly () activate compile)
988 "Calculate the actual line start for multi-line input."
989 (if (or comint-use-prompt-regexp
990 (eq (field-at-pos (point)) 'output))
991 ad-do-it
992 (setq ad-return-value
993 (constrain-to-field (line-beginning-position) (point)))))
994
6132bc01
MW
995;;;--------------------------------------------------------------------------
996;;; Dired hacking.
5195cbc3
MW
997
998(defadvice dired-maybe-insert-subdir
999 (around mdw-marked-insertion first activate)
6132bc01
MW
1000 "The DIRNAME may be a list of directory names to insert.
1001Interactively, if files are marked, then insert all of them.
1002With a numeric prefix argument, select that many entries near
1003point; with a non-numeric prefix argument, prompt for listing
1004options."
5195cbc3
MW
1005 (interactive
1006 (list (dired-get-marked-files nil
1007 (and (integerp current-prefix-arg)
1008 current-prefix-arg)
1009 #'file-directory-p)
1010 (and current-prefix-arg
1011 (not (integerp current-prefix-arg))
1012 (read-string "Switches for listing: "
1013 (or dired-subdir-switches
1014 dired-actual-switches)))))
1015 (let ((dirs (ad-get-arg 0)))
1016 (dolist (dir (if (listp dirs) dirs (list dirs)))
1017 (ad-set-arg 0 dir)
1018 ad-do-it)))
1019
d40903f4
MW
1020(defun mdw-dired-run (args &optional syncp)
1021 (interactive (let ((file (dired-get-filename t)))
1022 (list (read-string (format "Arguments for %s: " file))
1023 current-prefix-arg)))
1024 (funcall (if syncp 'shell-command 'async-shell-command)
1025 (concat (shell-quote-argument (dired-get-filename nil))
1026 " " args)))
1027
2a67803a
MW
1028(defadvice dired-do-flagged-delete
1029 (around mdw-delete-if-prefix-argument activate compile)
1030 (let ((delete-by-moving-to-trash (and (null current-prefix-arg)
1031 delete-by-moving-to-trash)))
1032 ad-do-it))
1033
d40903f4
MW
1034(eval-after-load "dired"
1035 '(define-key dired-mode-map "X" 'mdw-dired-run))
1036
6132bc01
MW
1037;;;--------------------------------------------------------------------------
1038;;; URL viewing.
a203fba8
MW
1039
1040(defun mdw-w3m-browse-url (url &optional new-session-p)
1041 "Invoke w3m on the URL in its current window, or at least a different one.
1042If NEW-SESSION-P, start a new session."
1043 (interactive "sURL: \nP")
1044 (save-excursion
63fb20c1
MW
1045 (let ((window (selected-window)))
1046 (unwind-protect
1047 (progn
1048 (select-window (or (and (not new-session-p)
1049 (get-buffer-window "*w3m*"))
1050 (progn
1051 (if (one-window-p t) (split-window))
1052 (get-lru-window))))
1053 (w3m-browse-url url new-session-p))
1054 (select-window window)))))
a203fba8 1055
2ae8f8e3
MW
1056(eval-after-load 'w3m
1057 '(define-key w3m-mode-map [?\e ?\r] 'w3m-view-this-url-new-session))
1058
a203fba8 1059(defvar mdw-good-url-browsers
94526c3f 1060 '(browse-url-mozilla
a0d16e44 1061 browse-url-generic
ed5e20a5 1062 (w3m . mdw-w3m-browse-url)
a0d16e44 1063 browse-url-w3)
6132bc01
MW
1064 "List of good browsers for mdw-good-url-browsers.
1065Each item is a browser function name, or a cons (CHECK . FUNC).
1066A symbol FOO stands for (FOO . FOO).")
a203fba8
MW
1067
1068(defun mdw-good-url-browser ()
6132bc01
MW
1069 "Return a good URL browser.
1070Trundle the list of such things, finding the first item for which
1071CHECK is fboundp, and returning the correponding FUNC."
a203fba8
MW
1072 (let ((bs mdw-good-url-browsers) b check func answer)
1073 (while (and bs (not answer))
1074 (setq b (car bs)
1075 bs (cdr bs))
1076 (if (consp b)
1077 (setq check (car b) func (cdr b))
1078 (setq check b func b))
1079 (if (fboundp check)
1080 (setq answer func)))
1081 answer))
1082
f36cdb77
MW
1083(eval-after-load "w3m-search"
1084 '(progn
1085 (dolist
1086 (item
1087 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
1088 ("gd" "Google Directory"
1089 "http://www.google.com/search?cat=gwd/Top&q=%s")
1090 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
1091 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
1092 ("gi" "Images" "http://images.google.com/images?q=%s")
1093 ("rfc" "RFC"
1094 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
1095 ("wp" "Wikipedia"
1096 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
1097 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
1098 ("nc-wiki" "nCipher wiki"
1099 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
1100 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
1101 ("lp" "Launchpad bug by number"
1102 "https://bugs.launchpad.net/bugs/%s")
1103 ("lppkg" "Launchpad bugs by package"
1104 "https://bugs.launchpad.net/%s")
1105 ("msdn" "MSDN"
1106 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
1107 ("debbug" "Debian bug by number"
1108 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
1109 ("debbugpkg" "Debian bugs by package"
1110 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
1111 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
1112 (add-to-list 'w3m-search-engine-alist
1113 (list (cadr item) (caddr item) nil))
1114 (add-to-list 'w3m-uri-replace-alist
1115 (list (concat "\\`" (car item) ":")
1116 'w3m-search-uri-replace
1117 (cadr item))))))
1118
6132bc01
MW
1119;;;--------------------------------------------------------------------------
1120;;; Paragraph filling.
f617db13 1121
6132bc01 1122;; Useful variables.
f617db13
MW
1123
1124(defvar mdw-fill-prefix nil
6132bc01
MW
1125 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
1126If there's no fill prefix currently set (by the `fill-prefix'
1127variable) and there's a match from one of the regexps here, it
1128gets used to set the fill-prefix for the current operation.
f617db13 1129
6132bc01
MW
1130The variable is a list of items of the form `REGEXP . PREFIX'; if
1131the REGEXP matches, the PREFIX is used to set the fill prefix.
1132It in turn is a list of things:
f617db13
MW
1133
1134 STRING -- insert a literal string
1135 (match . N) -- insert the thing matched by bracketed subexpression N
1136 (pad . N) -- a string of whitespace the same width as subexpression N
1137 (expr . FORM) -- the result of evaluating FORM")
1138
1139(make-variable-buffer-local 'mdw-fill-prefix)
1140
1141(defvar mdw-hanging-indents
10fa2414 1142 (concat "\\(\\("
f8bfe560 1143 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
10fa2414
MW
1144 "[ \t]+"
1145 "\\)?\\)")
6132bc01
MW
1146 "*Standard regexp matching parts of a hanging indent.
1147This is mainly useful in `auto-fill-mode'.")
f617db13 1148
6132bc01 1149;; Utility functions.
f617db13 1150
cd07f97f
MW
1151(defun mdw-maybe-tabify (s)
1152 "Tabify or untabify the string S, according to `indent-tabs-mode'."
c736b08b
MW
1153 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
1154 (with-temp-buffer
1155 (save-match-data
f617db13 1156 (insert s "\n")
cd07f97f 1157 (let ((start (point-min)) (end (point-max)))
c736b08b
MW
1158 (funcall tabfun (point-min) (point-max))
1159 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
f617db13
MW
1160
1161(defun mdw-examine-fill-prefixes (l)
6132bc01
MW
1162 "Given a list of dynamic fill prefixes, pick one which matches
1163context and return the static fill prefix to use. Point must be
1164at the start of a line, and match data must be saved."
f617db13 1165 (cond ((not l) nil)
6ed1b26a
MW
1166 ((looking-at (car (car l)))
1167 (mdw-maybe-tabify (apply #'concat
1168 (mapcar #'mdw-do-prefix-match
1169 (cdr (car l))))))
1170 (t (mdw-examine-fill-prefixes (cdr l)))))
f617db13
MW
1171
1172(defun mdw-maybe-car (p)
1173 "If P is a pair, return (car P), otherwise just return P."
1174 (if (consp p) (car p) p))
1175
1176(defun mdw-padding (s)
1177 "Return a string the same width as S but made entirely from whitespace."
1178 (let* ((l (length s)) (i 0) (n (make-string l ? )))
1179 (while (< i l)
1180 (if (= 9 (aref s i))
1181 (aset n i 9))
1182 (setq i (1+ i)))
1183 n))
1184
1185(defun mdw-do-prefix-match (m)
6132bc01
MW
1186 "Expand a dynamic prefix match element.
1187See `mdw-fill-prefix' for details."
f617db13 1188 (cond ((not (consp m)) (format "%s" m))
6ed1b26a
MW
1189 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
1190 ((eq (car m) 'pad) (mdw-padding (match-string
1191 (mdw-maybe-car (cdr m)))))
1192 ((eq (car m) 'eval) (eval (cdr m)))
1193 (t "")))
f617db13
MW
1194
1195(defun mdw-choose-dynamic-fill-prefix ()
1196 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
1197 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
6ed1b26a
MW
1198 ((not mdw-fill-prefix) fill-prefix)
1199 (t (save-excursion
1200 (beginning-of-line)
1201 (save-match-data
1202 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
f617db13 1203
b8c659bb 1204(defadvice do-auto-fill (around mdw-dynamic-fill-prefix () activate compile)
6132bc01
MW
1205 "Handle auto-filling, working out a dynamic fill prefix in the
1206case where there isn't a sensible static one."
f617db13 1207 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
b8c659bb 1208 ad-do-it))
f617db13
MW
1209
1210(defun mdw-fill-paragraph ()
1211 "Fill paragraph, getting a dynamic fill prefix."
1212 (interactive)
1213 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1214 (fill-paragraph nil)))
1215
1216(defun mdw-standard-fill-prefix (rx &optional mat)
1217 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
6132bc01
MW
1218This is just a short-cut for setting the thing by hand, and by
1219design it doesn't cope with anything approximating a complicated
1220case."
f617db13 1221 (setq mdw-fill-prefix
6ed1b26a
MW
1222 `((,(concat rx mdw-hanging-indents)
1223 (match . 1)
1224 (pad . ,(or mat 2))))))
f617db13 1225
6132bc01
MW
1226;;;--------------------------------------------------------------------------
1227;;; Other common declarations.
f617db13 1228
6132bc01 1229;; Common mode settings.
f617db13
MW
1230
1231(defvar mdw-auto-indent t
1232 "Whether to indent automatically after a newline.")
1233
0e58a7c2
MW
1234(defun mdw-whitespace-mode (&optional arg)
1235 "Turn on/off whitespace mode, but don't highlight trailing space."
1236 (interactive "P")
1237 (when (and (boundp 'whitespace-style)
1238 (fboundp 'whitespace-mode))
1239 (let ((whitespace-style (remove 'trailing whitespace-style)))
558fc014
MW
1240 (whitespace-mode arg))
1241 (setq show-trailing-whitespace whitespace-mode)))
0e58a7c2 1242
21beda17
MW
1243(defvar mdw-do-misc-mode-hacking nil)
1244
f617db13
MW
1245(defun mdw-misc-mode-config ()
1246 (and mdw-auto-indent
1247 (cond ((eq major-mode 'lisp-mode)
1248 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
4a7ce1ee 1249 ((derived-mode-p 'slime-repl-mode 'asm-mode 'comint-mode)
30c8a8fb 1250 nil)
f617db13
MW
1251 (t
1252 (local-set-key "\C-m" 'newline-and-indent))))
2e7c6a86 1253 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
f617db13 1254 (local-set-key [C-return] 'newline)
8a425bd7 1255 (make-local-variable 'page-delimiter)
8cb7626b 1256 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
f617db13
MW
1257 (setq comment-column 40)
1258 (auto-fill-mode 1)
c7203018 1259 (setq fill-column mdw-text-width)
253f61b4
MW
1260 (and (fboundp 'gtags-mode)
1261 (gtags-mode))
ddf6e116 1262 (if (fboundp 'hs-minor-mode)
612717ec 1263 (trap (hs-minor-mode t))
ddf6e116 1264 (outline-minor-mode t))
49b2646e 1265 (reveal-mode t)
1e7a9479 1266 (trap (turn-on-font-lock)))
f617db13 1267
2e7c6a86 1268(defun mdw-post-local-vars-misc-mode-config ()
c7203018 1269 (setq whitespace-line-column mdw-text-width)
2717a191
MW
1270 (when (and mdw-do-misc-mode-hacking
1271 (not buffer-read-only))
2e7c6a86
MW
1272 (setq show-trailing-whitespace t)
1273 (mdw-whitespace-mode 1)))
1274(add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
ed7b46b9 1275
2c1ccbb9
MW
1276(defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1277 `(progn ,@(mapcar (lambda (func)
1278 `(defadvice ,func
1279 (after mdw-angry-fruit-salad activate)
1280 (when mdw-do-misc-mode-hacking
1281 (setq show-trailing-whitespace
1282 (not buffer-read-only))
1283 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1284 funcs)))
1285(mdw-advise-update-angry-fruit-salad toggle-read-only
1286 read-only-mode
1287 view-mode
1288 view-mode-enable
1289 view-mode-disable)
2717a191 1290
253f61b4 1291(eval-after-load 'gtags
506bada9
MW
1292 '(progn
1293 (dolist (key '([mouse-2] [mouse-3]))
1294 (define-key gtags-mode-map key nil))
1295 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1296 (define-key gtags-select-mode-map [C-S-mouse-2]
1297 'gtags-select-tag-by-event)
1298 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1299 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
253f61b4 1300
6132bc01 1301;; Backup file handling.
2ae647c4
MW
1302
1303(defvar mdw-backup-disable-regexps nil
6132bc01
MW
1304 "*List of regular expressions: if a file name matches any of
1305these then the file is not backed up.")
2ae647c4
MW
1306
1307(defun mdw-backup-enable-predicate (name)
6132bc01
MW
1308 "[mdw]'s default backup predicate.
1309Allows a backup if the standard predicate would allow it, and it
1310doesn't match any of the regular expressions in
1311`mdw-backup-disable-regexps'."
2ae647c4
MW
1312 (and (normal-backup-enable-predicate name)
1313 (let ((answer t) (list mdw-backup-disable-regexps))
1314 (save-match-data
1315 (while list
1316 (if (string-match (car list) name)
1317 (setq answer nil))
1318 (setq list (cdr list)))
1319 answer))))
1320(setq backup-enable-predicate 'mdw-backup-enable-predicate)
1321
7bb78c67
MW
1322;; Frame cleanup.
1323
1324(defun mdw-last-one-out-turn-off-the-lights (frame)
1325 "Disconnect from an X display if this was the last frame on that display."
1326 (let ((frame-display (frame-parameter frame 'display)))
1327 (when (and frame-display
1328 (eq window-system 'x)
1329 (not (some (lambda (fr)
7bb78c67 1330 (and (not (eq fr frame))
a04d8f3d 1331 (string= (frame-parameter fr 'display)
d70716b5 1332 frame-display)))
7bb78c67 1333 (frame-list))))
7bb78c67
MW
1334 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1335(add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1336
6132bc01 1337;;;--------------------------------------------------------------------------
f3674a83
MW
1338;;; Fullscreen-ness.
1339
1340(defvar mdw-full-screen-parameters
1341 '((menu-bar-lines . 0)
1342 ;(vertical-scroll-bars . nil)
1343 )
1344 "Frame parameters to set when making a frame fullscreen.")
1345
1346(defvar mdw-full-screen-save
1347 '(width height)
1348 "Extra frame parameters to save when setting fullscreen.")
1349
1350(defun mdw-toggle-full-screen (&optional frame)
1351 "Show the FRAME fullscreen."
1352 (interactive)
1353 (when window-system
1354 (cond ((frame-parameter frame 'fullscreen)
1355 (set-frame-parameter frame 'fullscreen nil)
1356 (modify-frame-parameters
1357 nil
1358 (or (frame-parameter frame 'mdw-full-screen-saved)
1359 (mapcar (lambda (assoc)
1360 (assq (car assoc) default-frame-alist))
1361 mdw-full-screen-parameters))))
1362 (t
1363 (let ((saved (mapcar (lambda (param)
1364 (cons param (frame-parameter frame param)))
1365 (append (mapcar #'car
1366 mdw-full-screen-parameters)
1367 mdw-full-screen-save))))
1368 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1369 (modify-frame-parameters frame mdw-full-screen-parameters)
1370 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1371
1372;;;--------------------------------------------------------------------------
6132bc01 1373;;; General fontification.
f617db13 1374
bc149706
MW
1375(make-face 'mdw-virgin-face)
1376
1e7a9479
MW
1377(defmacro mdw-define-face (name &rest body)
1378 "Define a face, and make sure it's actually set as the definition."
1379 (declare (indent 1)
1380 (debug 0))
1381 `(progn
bc149706 1382 (copy-face 'mdw-virgin-face ',name)
1e7a9479
MW
1383 (defvar ,name ',name)
1384 (put ',name 'face-defface-spec ',body)
88cb9c2b 1385 (face-spec-set ',name ',body nil)))
1e7a9479
MW
1386
1387(mdw-define-face default
1388 (((type w32)) :family "courier new" :height 85)
caa63513 1389 (((type x)) :family "6x13" :foundry "trad" :height 130)
db10ce0a
MW
1390 (((type color)) :foreground "white" :background "black")
1391 (t nil))
1e7a9479
MW
1392(mdw-define-face fixed-pitch
1393 (((type w32)) :family "courier new" :height 85)
caa63513 1394 (((type x)) :family "6x13" :foundry "trad" :height 130)
1e7a9479 1395 (t :foreground "white" :background "black"))
e8ea88ba 1396(if (mdw-emacs-version-p 23)
c383eb8a
MW
1397 (mdw-define-face variable-pitch
1398 (((type x)) :family "sans" :height 100))
1399 (mdw-define-face variable-pitch
3f001ff6 1400 (((type x)) :family "helvetica" :height 90)))
1e7a9479 1401(mdw-define-face region
fefae026
MW
1402 (((min-colors 64)) :background "grey30")
1403 (((class color)) :background "blue")
4833e35c 1404 (t :inverse-video t))
fa156643 1405(mdw-define-face match
fefae026
MW
1406 (((class color)) :background "blue")
1407 (t :inverse-video t))
c6fe19d5 1408(mdw-define-face mc/cursor-face
fefae026
MW
1409 (((class color)) :background "red")
1410 (t :inverse-video t))
1e7a9479
MW
1411(mdw-define-face minibuffer-prompt
1412 (t :weight bold))
1413(mdw-define-face mode-line
db10ce0a
MW
1414 (((class color)) :foreground "blue" :background "yellow"
1415 :box (:line-width 1 :style released-button))
1416 (t :inverse-video t))
1e7a9479 1417(mdw-define-face mode-line-inactive
db10ce0a
MW
1418 (((class color)) :foreground "yellow" :background "blue"
1419 :box (:line-width 1 :style released-button))
1420 (t :inverse-video t))
ae0a853f
MW
1421(mdw-define-face nobreak-space
1422 (((type tty)))
1423 (t :inherit escape-glyph :underline t))
1e7a9479
MW
1424(mdw-define-face scroll-bar
1425 (t :foreground "black" :background "lightgrey"))
1426(mdw-define-face fringe
1427 (t :foreground "yellow"))
c383eb8a 1428(mdw-define-face show-paren-match
9cf75a93
MW
1429 (((min-colors 64)) :background "darkgreen")
1430 (((class color)) :background "green")
db10ce0a 1431 (t :underline t))
c383eb8a 1432(mdw-define-face show-paren-mismatch
db10ce0a
MW
1433 (((class color)) :background "red")
1434 (t :inverse-video t))
1e7a9479 1435(mdw-define-face highlight
fefae026
MW
1436 (((min-colors 64)) :background "DarkSeaGreen4")
1437 (((class color)) :background "cyan")
db10ce0a 1438 (t :inverse-video t))
1e7a9479
MW
1439
1440(mdw-define-face holiday-face
1441 (t :background "red"))
1442(mdw-define-face calendar-today-face
1443 (t :foreground "yellow" :weight bold))
1444
1445(mdw-define-face comint-highlight-prompt
1446 (t :weight bold))
5fd055c2
MW
1447(mdw-define-face comint-highlight-input
1448 (t nil))
1e7a9479 1449
2e97e639
MW
1450(mdw-define-face ido-subdir
1451 (t :foreground "cyan" :weight bold))
1452
e0e2aca3
MW
1453(mdw-define-face dired-directory
1454 (t :foreground "cyan" :weight bold))
1455(mdw-define-face dired-symlink
1456 (t :foreground "cyan"))
1457(mdw-define-face dired-perm-write
1458 (t nil))
1459
1e7a9479 1460(mdw-define-face trailing-whitespace
db10ce0a
MW
1461 (((class color)) :background "red")
1462 (t :inverse-video t))
33aa287b
MW
1463(mdw-define-face whitespace-line
1464 (((class color)) :background "darkred")
a52bc3ca 1465 (t :inverse-video t))
1e7a9479 1466(mdw-define-face mdw-punct-face
fefae026
MW
1467 (((min-colors 64)) :foreground "burlywood2")
1468 (((class color)) :foreground "yellow"))
1e7a9479
MW
1469(mdw-define-face mdw-number-face
1470 (t :foreground "yellow"))
52bcde59 1471(mdw-define-face mdw-trivial-face)
1e7a9479 1472(mdw-define-face font-lock-function-name-face
c383eb8a 1473 (t :slant italic))
1e7a9479
MW
1474(mdw-define-face font-lock-keyword-face
1475 (t :weight bold))
1476(mdw-define-face font-lock-constant-face
1477 (t :slant italic))
1478(mdw-define-face font-lock-builtin-face
1479 (t :weight bold))
07965a39
MW
1480(mdw-define-face font-lock-type-face
1481 (t :weight bold :slant italic))
1e7a9479
MW
1482(mdw-define-face font-lock-reference-face
1483 (t :weight bold))
1484(mdw-define-face font-lock-variable-name-face
1485 (t :slant italic))
1486(mdw-define-face font-lock-comment-delimiter-face
fefae026
MW
1487 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1488 (((class color)) :foreground "green")
1489 (t :weight bold))
1e7a9479 1490(mdw-define-face font-lock-comment-face
fefae026
MW
1491 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1492 (((class color)) :foreground "green")
1493 (t :weight bold))
1e7a9479 1494(mdw-define-face font-lock-string-face
fefae026
MW
1495 (((min-colors 64)) :foreground "SkyBlue1")
1496 (((class color)) :foreground "cyan")
1497 (t :weight bold))
898c7efb 1498
1e7a9479
MW
1499(mdw-define-face message-separator
1500 (t :background "red" :foreground "white" :weight bold))
1501(mdw-define-face message-cited-text
1502 (default :slant italic)
fefae026
MW
1503 (((min-colors 64)) :foreground "SkyBlue1")
1504 (((class color)) :foreground "cyan"))
1e7a9479 1505(mdw-define-face message-header-cc
4790fcb7 1506 (default :slant italic)
fefae026
MW
1507 (((min-colors 64)) :foreground "SeaGreen1")
1508 (((class color)) :foreground "green"))
1e7a9479 1509(mdw-define-face message-header-newsgroups
4790fcb7 1510 (default :slant italic)
fefae026
MW
1511 (((min-colors 64)) :foreground "SeaGreen1")
1512 (((class color)) :foreground "green"))
1e7a9479 1513(mdw-define-face message-header-subject
fefae026
MW
1514 (((min-colors 64)) :foreground "SeaGreen1")
1515 (((class color)) :foreground "green"))
1e7a9479 1516(mdw-define-face message-header-to
fefae026
MW
1517 (((min-colors 64)) :foreground "SeaGreen1")
1518 (((class color)) :foreground "green"))
1e7a9479 1519(mdw-define-face message-header-xheader
4790fcb7 1520 (default :slant italic)
fefae026
MW
1521 (((min-colors 64)) :foreground "SeaGreen1")
1522 (((class color)) :foreground "green"))
1e7a9479 1523(mdw-define-face message-header-other
4790fcb7 1524 (default :slant italic)
fefae026
MW
1525 (((min-colors 64)) :foreground "SeaGreen1")
1526 (((class color)) :foreground "green"))
1e7a9479 1527(mdw-define-face message-header-name
4790fcb7 1528 (default :weight bold)
fefae026
MW
1529 (((min-colors 64)) :foreground "SeaGreen1")
1530 (((class color)) :foreground "green"))
4790fcb7 1531
69498691
MW
1532(mdw-define-face which-func
1533 (t nil))
1e7a9479 1534
4790fcb7
MW
1535(mdw-define-face gnus-header-name
1536 (default :weight bold)
fefae026
MW
1537 (((min-colors 64)) :foreground "SeaGreen1")
1538 (((class color)) :foreground "green"))
4790fcb7 1539(mdw-define-face gnus-header-subject
fefae026
MW
1540 (((min-colors 64)) :foreground "SeaGreen1")
1541 (((class color)) :foreground "green"))
4790fcb7 1542(mdw-define-face gnus-header-from
fefae026
MW
1543 (((min-colors 64)) :foreground "SeaGreen1")
1544 (((class color)) :foreground "green"))
4790fcb7 1545(mdw-define-face gnus-header-to
fefae026
MW
1546 (((min-colors 64)) :foreground "SeaGreen1")
1547 (((class color)) :foreground "green"))
4790fcb7
MW
1548(mdw-define-face gnus-header-content
1549 (default :slant italic)
fefae026
MW
1550 (((min-colors 64)) :foreground "SeaGreen1")
1551 (((class color)) :foreground "green"))
4790fcb7
MW
1552
1553(mdw-define-face gnus-cite-1
fefae026
MW
1554 (((min-colors 64)) :foreground "SkyBlue1")
1555 (((class color)) :foreground "cyan"))
4790fcb7 1556(mdw-define-face gnus-cite-2
fefae026
MW
1557 (((min-colors 64)) :foreground "RoyalBlue2")
1558 (((class color)) :foreground "blue"))
4790fcb7 1559(mdw-define-face gnus-cite-3
fefae026
MW
1560 (((min-colors 64)) :foreground "MediumOrchid")
1561 (((class color)) :foreground "magenta"))
4790fcb7 1562(mdw-define-face gnus-cite-4
fefae026
MW
1563 (((min-colors 64)) :foreground "firebrick2")
1564 (((class color)) :foreground "red"))
4790fcb7 1565(mdw-define-face gnus-cite-5
fefae026
MW
1566 (((min-colors 64)) :foreground "burlywood2")
1567 (((class color)) :foreground "yellow"))
4790fcb7 1568(mdw-define-face gnus-cite-6
fefae026
MW
1569 (((min-colors 64)) :foreground "SeaGreen1")
1570 (((class color)) :foreground "green"))
4790fcb7 1571(mdw-define-face gnus-cite-7
fefae026
MW
1572 (((min-colors 64)) :foreground "SlateBlue1")
1573 (((class color)) :foreground "cyan"))
4790fcb7 1574(mdw-define-face gnus-cite-8
fefae026
MW
1575 (((min-colors 64)) :foreground "RoyalBlue2")
1576 (((class color)) :foreground "blue"))
4790fcb7 1577(mdw-define-face gnus-cite-9
fefae026
MW
1578 (((min-colors 64)) :foreground "purple2")
1579 (((class color)) :foreground "magenta"))
4790fcb7 1580(mdw-define-face gnus-cite-10
fefae026
MW
1581 (((min-colors 64)) :foreground "DarkOrange2")
1582 (((class color)) :foreground "red"))
4790fcb7
MW
1583(mdw-define-face gnus-cite-11
1584 (t :foreground "grey"))
1585
2f238de8
MW
1586(mdw-define-face diff-header
1587 (t nil))
1e7a9479
MW
1588(mdw-define-face diff-index
1589 (t :weight bold))
1590(mdw-define-face diff-file-header
1591 (t :weight bold))
1592(mdw-define-face diff-hunk-header
fefae026
MW
1593 (((min-colors 64)) :foreground "SkyBlue1")
1594 (((class color)) :foreground "cyan"))
1e7a9479 1595(mdw-define-face diff-function
fefae026
MW
1596 (default :weight bold)
1597 (((min-colors 64)) :foreground "SkyBlue1")
1598 (((class color)) :foreground "cyan"))
1e7a9479 1599(mdw-define-face diff-header
fefae026 1600 (((min-colors 64)) :background "grey10"))
1e7a9479 1601(mdw-define-face diff-added
fefae026 1602 (((class color)) :foreground "green"))
1e7a9479 1603(mdw-define-face diff-removed
fefae026 1604 (((class color)) :foreground "red"))
5fd055c2
MW
1605(mdw-define-face diff-context
1606 (t nil))
2f238de8 1607(mdw-define-face diff-refine-change
fefae026 1608 (((min-colors 64)) :background "RoyalBlue4")
b31f422b 1609 (t :underline t))
5f454d3e 1610(mdw-define-face diff-refine-removed
fefae026 1611 (((min-colors 64)) :background "#500")
5f454d3e
MW
1612 (t :underline t))
1613(mdw-define-face diff-refine-added
fefae026 1614 (((min-colors 64)) :background "#050")
5f454d3e 1615 (t :underline t))
1e7a9479 1616
a62d0541
MW
1617(setq ediff-force-faces t)
1618(mdw-define-face ediff-current-diff-A
fefae026
MW
1619 (((min-colors 64)) :background "darkred")
1620 (((class color)) :background "red")
a62d0541
MW
1621 (t :inverse-video t))
1622(mdw-define-face ediff-fine-diff-A
fefae026
MW
1623 (((min-colors 64)) :background "red3")
1624 (((class color)) :inverse-video t)
a62d0541
MW
1625 (t :inverse-video nil))
1626(mdw-define-face ediff-even-diff-A
fefae026 1627 (((min-colors 64)) :background "#300"))
a62d0541 1628(mdw-define-face ediff-odd-diff-A
fefae026 1629 (((min-colors 64)) :background "#300"))
a62d0541 1630(mdw-define-face ediff-current-diff-B
fefae026
MW
1631 (((min-colors 64)) :background "darkgreen")
1632 (((class color)) :background "magenta")
a62d0541
MW
1633 (t :inverse-video t))
1634(mdw-define-face ediff-fine-diff-B
fefae026
MW
1635 (((min-colors 64)) :background "green4")
1636 (((class color)) :inverse-video t)
a62d0541
MW
1637 (t :inverse-video nil))
1638(mdw-define-face ediff-even-diff-B
fefae026 1639 (((min-colors 64)) :background "#020"))
a62d0541 1640(mdw-define-face ediff-odd-diff-B
fefae026 1641 (((min-colors 64)) :background "#020"))
a62d0541 1642(mdw-define-face ediff-current-diff-C
fefae026
MW
1643 (((min-colors 64)) :background "darkblue")
1644 (((class color)) :background "blue")
a62d0541
MW
1645 (t :inverse-video t))
1646(mdw-define-face ediff-fine-diff-C
fefae026
MW
1647 (((min-colors 64)) :background "blue1")
1648 (((class color)) :inverse-video t)
a62d0541
MW
1649 (t :inverse-video nil))
1650(mdw-define-face ediff-even-diff-C
fefae026 1651 (((min-colors 64)) :background "#004"))
a62d0541 1652(mdw-define-face ediff-odd-diff-C
fefae026 1653 (((min-colors 64)) :background "#004"))
a62d0541 1654(mdw-define-face ediff-current-diff-Ancestor
fefae026
MW
1655 (((min-colors 64)) :background "#630")
1656 (((class color)) :background "blue")
a62d0541
MW
1657 (t :inverse-video t))
1658(mdw-define-face ediff-even-diff-Ancestor
fefae026 1659 (((min-colors 64)) :background "#320"))
a62d0541 1660(mdw-define-face ediff-odd-diff-Ancestor
fefae026 1661 (((min-colors 64)) :background "#320"))
a62d0541 1662
53f93f0d 1663(mdw-define-face magit-hash
fefae026
MW
1664 (((min-colors 64)) :foreground "grey40")
1665 (((class color)) :foreground "blue"))
53f93f0d 1666(mdw-define-face magit-diff-hunk-heading
fefae026
MW
1667 (((min-colors 64)) :foreground "grey70" :background "grey25")
1668 (((class color)) :foreground "yellow"))
53f93f0d 1669(mdw-define-face magit-diff-hunk-heading-highlight
fefae026
MW
1670 (((min-colors 64)) :foreground "grey70" :background "grey35")
1671 (((class color)) :foreground "yellow" :background "blue"))
53f93f0d 1672(mdw-define-face magit-diff-added
fefae026
MW
1673 (((min-colors 64)) :foreground "#ddffdd" :background "#335533")
1674 (((class color)) :foreground "green"))
53f93f0d 1675(mdw-define-face magit-diff-added-highlight
fefae026
MW
1676 (((min-colors 64)) :foreground "#cceecc" :background "#336633")
1677 (((class color)) :foreground "green" :background "blue"))
53f93f0d 1678(mdw-define-face magit-diff-removed
fefae026
MW
1679 (((min-colors 64)) :foreground "#ffdddd" :background "#553333")
1680 (((class color)) :foreground "red"))
53f93f0d 1681(mdw-define-face magit-diff-removed-highlight
fefae026
MW
1682 (((min-colors 64)) :foreground "#eecccc" :background "#663333")
1683 (((class color)) :foreground "red" :background "blue"))
857045c6
MW
1684(mdw-define-face magit-blame-heading
1685 (((min-colors 64)) :foreground "white" :background "grey25"
1686 :weight normal :slant normal)
1687 (((class color)) :foreground "white" :background "blue"
1688 :weight normal :slant normal))
1689(mdw-define-face magit-blame-name
1690 (t :inherit magit-blame-heading :slant italic))
1691(mdw-define-face magit-blame-date
1692 (((min-colors 64)) :inherit magit-blame-heading :foreground "grey60")
1693 (((class color)) :inherit magit-blame-heading :foreground "cyan"))
1694(mdw-define-face magit-blame-summary
1695 (t :inherit magit-blame-heading :weight bold))
53f93f0d 1696
ad305d7e 1697(mdw-define-face dylan-header-background
fefae026
MW
1698 (((min-colors 64)) :background "NavyBlue")
1699 (((class color)) :background "blue"))
ad305d7e 1700
e1b8de18
MW
1701(mdw-define-face erc-input-face
1702 (t :foreground "red"))
1703
1e7a9479
MW
1704(mdw-define-face woman-bold
1705 (t :weight bold))
1706(mdw-define-face woman-italic
1707 (t :slant italic))
1708
5a83259f
MW
1709(eval-after-load "rst"
1710 '(progn
1711 (mdw-define-face rst-level-1-face
1712 (t :foreground "SkyBlue1" :weight bold))
1713 (mdw-define-face rst-level-2-face
1714 (t :foreground "SeaGreen1" :weight bold))
1715 (mdw-define-face rst-level-3-face
1716 (t :weight bold))
1717 (mdw-define-face rst-level-4-face
1718 (t :slant italic))
1719 (mdw-define-face rst-level-5-face
1720 (t :underline t))
1721 (mdw-define-face rst-level-6-face
1722 ())))
4f251391 1723
1e7a9479
MW
1724(mdw-define-face p4-depot-added-face
1725 (t :foreground "green"))
1726(mdw-define-face p4-depot-branch-op-face
1727 (t :foreground "yellow"))
1728(mdw-define-face p4-depot-deleted-face
1729 (t :foreground "red"))
1730(mdw-define-face p4-depot-unmapped-face
1731 (t :foreground "SkyBlue1"))
1732(mdw-define-face p4-diff-change-face
1733 (t :foreground "yellow"))
1734(mdw-define-face p4-diff-del-face
1735 (t :foreground "red"))
1736(mdw-define-face p4-diff-file-face
1737 (t :foreground "SkyBlue1"))
1738(mdw-define-face p4-diff-head-face
1739 (t :background "grey10"))
1740(mdw-define-face p4-diff-ins-face
1741 (t :foreground "green"))
1742
4c39e530
MW
1743(mdw-define-face w3m-anchor-face
1744 (t :foreground "SkyBlue1" :underline t))
1745(mdw-define-face w3m-arrived-anchor-face
1746 (t :foreground "SkyBlue1" :underline t))
1747
1e7a9479
MW
1748(mdw-define-face whizzy-slice-face
1749 (t :background "grey10"))
1750(mdw-define-face whizzy-error-face
1751 (t :background "darkred"))
f617db13 1752
5fedb342
MW
1753;; Ellipses used to indicate hidden text (and similar).
1754(mdw-define-face mdw-ellipsis-face
1755 (((type tty)) :foreground "blue") (t :foreground "grey60"))
c11ac343 1756(let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
a8a7976a 1757 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
c11ac343
MW
1758 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
1759 (bar (make-glyph-code ?| mdw-ellipsis-face)))
1760 (set-display-table-slot standard-display-table 0 dollar)
1761 (set-display-table-slot standard-display-table 1 backslash)
5fedb342 1762 (set-display-table-slot standard-display-table 4
c11ac343
MW
1763 (vector dot dot dot))
1764 (set-display-table-slot standard-display-table 5 bar))
5fedb342 1765
6132bc01 1766;;;--------------------------------------------------------------------------
c70e3179
MW
1767;;; Where is point?
1768
6a2d05ae 1769(mdw-define-face mdw-point-overlay-face
3f32879e 1770 (((type graphic)))
c70e3179
MW
1771 (((min-colors 64)) :background "darkblue")
1772 (((class color)) :background "blue")
1773 (((type tty) (class mono)) :inverse-video t))
1774
1775(defvar mdw-point-overlay-fringe-display '(vertical-bar . vertical-bar))
1776
1777(defun mdw-configure-point-overlay ()
1778 (let ((ov (make-overlay 0 0)))
1779 (overlay-put ov 'priority 0)
1780 (let* ((fringe (or mdw-point-overlay-fringe-display (cons nil nil)))
1781 (left (car fringe)) (right (cdr fringe))
1782 (s ""))
1783 (when left
1784 (let ((ss "."))
1785 (put-text-property 0 1 'display `(left-fringe ,left) ss)
1786 (setq s (concat s ss))))
1787 (when right
1788 (let ((ss "."))
1789 (put-text-property 0 1 'display `(right-fringe ,right) ss)
1790 (setq s (concat s ss))))
1791 (when (or left right)
1792 (overlay-put ov 'before-string s)))
6a2d05ae 1793 (overlay-put ov 'face 'mdw-point-overlay-face)
c70e3179
MW
1794 (delete-overlay ov)
1795 ov))
1796
1797(defvar mdw-point-overlay (mdw-configure-point-overlay)
1798 "An overlay used for showing where point is in the selected window.")
1799(defun mdw-reconfigure-point-overlay ()
1800 (interactive)
1801 (setq mdw-point-overlay (mdw-configure-point-overlay)))
1802
1803(defun mdw-remove-point-overlay ()
1804 "Remove the current-point overlay."
1805 (delete-overlay mdw-point-overlay))
1806
1807(defun mdw-update-point-overlay ()
1808 "Mark the current point position with an overlay."
1809 (if (not mdw-point-overlay-mode)
1810 (mdw-remove-point-overlay)
1811 (overlay-put mdw-point-overlay 'window (selected-window))
1812 (move-overlay mdw-point-overlay
1813 (line-beginning-position)
1814 (+ (line-end-position) 1))))
1815
1816(defvar mdw-point-overlay-buffers nil
1817 "List of buffers using `mdw-point-overlay-mode'.")
1818
1819(define-minor-mode mdw-point-overlay-mode
1820 "Indicate current line with an overlay."
1821 :global nil
1822 (let ((buffer (current-buffer)))
1823 (setq mdw-point-overlay-buffers
1824 (mapcan (lambda (buf)
1825 (if (and (buffer-live-p buf)
1826 (not (eq buf buffer)))
1827 (list buf)))
1828 mdw-point-overlay-buffers))
1829 (if mdw-point-overlay-mode
1830 (setq mdw-point-overlay-buffers
1831 (cons buffer mdw-point-overlay-buffers))))
1832 (cond (mdw-point-overlay-buffers
1833 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
1834 (add-hook 'post-command-hook 'mdw-update-point-overlay))
1835 (t
1836 (mdw-remove-point-overlay)
1837 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
1838 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
1839
1840(define-globalized-minor-mode mdw-global-point-overlay-mode
1841 mdw-point-overlay-mode
1842 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
1843
1844;;;--------------------------------------------------------------------------
6132bc01 1845;;; C programming configuration.
f617db13 1846
6132bc01 1847;; Make C indentation nice.
f617db13 1848
f50c1bed
MW
1849(defun mdw-c-lineup-arglist (langelem)
1850 "Hack for DWIMmery in c-lineup-arglist."
1851 (if (save-excursion
1852 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1853 0
1854 (c-lineup-arglist langelem)))
1855
1856(defun mdw-c-indent-extern-mumble (langelem)
1857 "Indent `extern \"...\" {' lines."
1858 (save-excursion
1859 (back-to-indentation)
1860 (if (looking-at
1861 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1862 c-basic-offset
1863 nil)))
1864
b521d36a
MW
1865(defun mdw-c-indent-arglist-nested (langelem)
1866 "Indent continued argument lists.
1867If we've nested more than one argument list, then only introduce a single
1868indentation anyway."
1869 (let ((context c-syntactic-context)
1870 (pos (c-langelem-2nd-pos c-syntactic-element))
1871 (should-indent-p t))
1872 (while (and context
1873 (eq (caar context) 'arglist-cont-nonempty))
1874 (when (and (= (caddr (pop context)) pos)
1875 context
1876 (memq (caar context) '(arglist-intro
1877 arglist-cont-nonempty)))
1878 (setq should-indent-p nil)))
1879 (if should-indent-p '+ 0)))
1880
c56296d0
MW
1881(defvar mdw-define-c-styles-hook nil
1882 "Hook run when `cc-mode' starts up to define styles.")
1883
1884(defmacro mdw-define-c-style (name &rest assocs)
1885 "Define a C style, called NAME (a symbol), setting ASSOCs.
1886A function, named `mdw-define-c-style/NAME', is defined to actually install
1887the style using `c-add-style', and added to the hook
1888`mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
1889set."
1890 (declare (indent defun))
1891 (let* ((name-string (symbol-name name))
1892 (func (intern (concat "mdw-define-c-style/" name-string))))
1893 `(progn
1894 (defun ,func () (c-add-style ,name-string ',assocs))
1895 (and (featurep 'cc-mode) (,func))
1896 (add-hook 'mdw-define-c-styles-hook ',func))))
1897
1898(eval-after-load "cc-mode"
1899 '(run-hooks 'mdw-define-c-styles-hook))
1900
b521d36a
MW
1901(mdw-define-c-style mdw-trustonic-c
1902 (c-basic-offset . 4)
1903 (comment-column . 0)
1904 (c-indent-comment-alist (anchored-comment . (column . 0))
1905 (end-block . (space . 1))
1906 (cpp-end-block . (space . 1))
1907 (other . (space . 1)))
1908 (c-class-key . "class")
1909 (c-backslash-column . 0)
1910 (c-auto-align-backslashes . nil)
1911 (c-label-minimum-indentation . 0)
1912 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1913 (defun-open . (add 0 c-indent-one-line-block))
1914 (arglist-cont-nonempty . mdw-c-indent-arglist-nested)
1915 (topmost-intro . mdw-c-indent-extern-mumble)
1916 (cpp-define-intro . 0)
1917 (knr-argdecl . 0)
1918 (inextern-lang . [0])
1919 (label . 0)
1920 (case-label . +)
b07634df 1921 (access-label . -2)
b521d36a
MW
1922 (inclass . +)
1923 (inline-open . ++)
1924 (statement-cont . +)
1925 (statement-case-intro . +)))
1926
c56296d0
MW
1927(mdw-define-c-style mdw-c
1928 (c-basic-offset . 2)
1929 (comment-column . 40)
1930 (c-class-key . "class")
1931 (c-backslash-column . 72)
1932 (c-label-minimum-indentation . 0)
1933 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1934 (defun-open . (add 0 c-indent-one-line-block))
1935 (arglist-cont-nonempty . mdw-c-lineup-arglist)
1936 (topmost-intro . mdw-c-indent-extern-mumble)
1937 (cpp-define-intro . 0)
1938 (knr-argdecl . 0)
1939 (inextern-lang . [0])
1940 (label . 0)
1941 (case-label . +)
1942 (access-label . -)
1943 (inclass . +)
1944 (inline-open . ++)
1945 (statement-cont . +)
1946 (statement-case-intro . +)))
1947
1948(defun mdw-set-default-c-style (modes style)
1949 "Update the default CC Mode style for MODES to be STYLE.
1950
1951MODES may be a list of major mode names or a singleton. STYLE is a style
1952name, as a symbol."
1953 (let ((modes (if (listp modes) modes (list modes)))
1954 (style (symbol-name style)))
1955 (setq c-default-style
1956 (append (mapcar (lambda (mode)
1957 (cons mode style))
1958 modes)
1959 (remove-if (lambda (assoc)
1960 (memq (car assoc) modes))
1961 (if (listp c-default-style)
1962 c-default-style
1963 (list (cons 'other c-default-style))))))))
1964(setq c-default-style "mdw-c")
1965
1966(mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
f617db13 1967
0e7d960b
MW
1968(defvar mdw-c-comment-fill-prefix
1969 `((,(concat "\\([ \t]*/?\\)"
a7474429 1970 "\\(\\*\\|//\\)"
0e7d960b
MW
1971 "\\([ \t]*\\)"
1972 "\\([A-Za-z]+:[ \t]*\\)?"
1973 mdw-hanging-indents)
1974 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1975 "Fill prefix matching C comments (both kinds).")
1976
f617db13
MW
1977(defun mdw-fontify-c-and-c++ ()
1978
6132bc01 1979 ;; Fiddle with some syntax codes.
f617db13
MW
1980 (modify-syntax-entry ?* ". 23")
1981 (modify-syntax-entry ?/ ". 124b")
1982 (modify-syntax-entry ?\n "> b")
1983
6132bc01 1984 ;; Other stuff.
c56296d0 1985 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
f617db13 1986
6132bc01 1987 ;; Now define things to be fontified.
02109a0d 1988 (make-local-variable 'font-lock-keywords)
f617db13 1989 (let ((c-keywords
fe307a8c
MW
1990 (mdw-regexps "alignas" ;C11 macro, C++11
1991 "alignof" ;C++11
1992 "and" ;C++, C95 macro
0681f29e 1993 "and_eq" ;C++, C95 macro
7b84c078 1994 "asm" ;K&R, C++, GCC
fe307a8c 1995 "atomic" ;C11 macro, C++11 template type
26f18bd1 1996 "auto" ;K&R, C89
0681f29e
MW
1997 "bitand" ;C++, C95 macro
1998 "bitor" ;C++, C95 macro
d4783d9c 1999 "bool" ;C++, C99 macro
26f18bd1
MW
2000 "break" ;K&R, C89
2001 "case" ;K&R, C89
2002 "catch" ;C++
2003 "char" ;K&R, C89
fe307a8c
MW
2004 "char16_t" ;C++11, C11 library type
2005 "char32_t" ;C++11, C11 library type
26f18bd1 2006 "class" ;C++
d4783d9c 2007 "complex" ;C99 macro, C++ template type
0681f29e 2008 "compl" ;C++, C95 macro
26f18bd1 2009 "const" ;C89
fe307a8c 2010 "constexpr" ;C++11
26f18bd1
MW
2011 "const_cast" ;C++
2012 "continue" ;K&R, C89
fe307a8c 2013 "decltype" ;C++11
26f18bd1
MW
2014 "defined" ;C89 preprocessor
2015 "default" ;K&R, C89
2016 "delete" ;C++
2017 "do" ;K&R, C89
2018 "double" ;K&R, C89
2019 "dynamic_cast" ;C++
2020 "else" ;K&R, C89
2021 ;; "entry" ;K&R -- never used
2022 "enum" ;C89
2023 "explicit" ;C++
2024 "export" ;C++
2025 "extern" ;K&R, C89
2026 "float" ;K&R, C89
2027 "for" ;K&R, C89
2028 ;; "fortran" ;K&R
2029 "friend" ;C++
2030 "goto" ;K&R, C89
2031 "if" ;K&R, C89
d4783d9c
MW
2032 "imaginary" ;C99 macro
2033 "inline" ;C++, C99, GCC
26f18bd1
MW
2034 "int" ;K&R, C89
2035 "long" ;K&R, C89
2036 "mutable" ;C++
2037 "namespace" ;C++
2038 "new" ;C++
fe307a8c
MW
2039 "noexcept" ;C++11
2040 "noreturn" ;C11 macro
0681f29e
MW
2041 "not" ;C++, C95 macro
2042 "not_eq" ;C++, C95 macro
fe307a8c 2043 "nullptr" ;C++11
26f18bd1 2044 "operator" ;C++
0681f29e
MW
2045 "or" ;C++, C95 macro
2046 "or_eq" ;C++, C95 macro
26f18bd1
MW
2047 "private" ;C++
2048 "protected" ;C++
2049 "public" ;C++
2050 "register" ;K&R, C89
8d6d55b9 2051 "reinterpret_cast" ;C++
d4783d9c 2052 "restrict" ;C99
8d6d55b9
MW
2053 "return" ;K&R, C89
2054 "short" ;K&R, C89
2055 "signed" ;C89
2056 "sizeof" ;K&R, C89
2057 "static" ;K&R, C89
fe307a8c 2058 "static_assert" ;C11 macro, C++11
8d6d55b9
MW
2059 "static_cast" ;C++
2060 "struct" ;K&R, C89
2061 "switch" ;K&R, C89
2062 "template" ;C++
8d6d55b9 2063 "throw" ;C++
8d6d55b9 2064 "try" ;C++
fe307a8c 2065 "thread_local" ;C11 macro, C++11
8d6d55b9
MW
2066 "typedef" ;C89
2067 "typeid" ;C++
2068 "typeof" ;GCC
2069 "typename" ;C++
2070 "union" ;K&R, C89
2071 "unsigned" ;K&R, C89
2072 "using" ;C++
2073 "virtual" ;C++
2074 "void" ;C89
2075 "volatile" ;C89
2076 "wchar_t" ;C++, C89 library type
2077 "while" ;K&R, C89
0681f29e
MW
2078 "xor" ;C++, C95 macro
2079 "xor_eq" ;C++, C95 macro
fe307a8c
MW
2080 "_Alignas" ;C11
2081 "_Alignof" ;C11
2082 "_Atomic" ;C11
d4783d9c
MW
2083 "_Bool" ;C99
2084 "_Complex" ;C99
fe307a8c 2085 "_Generic" ;C11
d4783d9c 2086 "_Imaginary" ;C99
fe307a8c 2087 "_Noreturn" ;C11
d4783d9c 2088 "_Pragma" ;C99 preprocessor
fe307a8c
MW
2089 "_Static_assert" ;C11
2090 "_Thread_local" ;C11
8d6d55b9
MW
2091 "__alignof__" ;GCC
2092 "__asm__" ;GCC
2093 "__attribute__" ;GCC
2094 "__complex__" ;GCC
2095 "__const__" ;GCC
2096 "__extension__" ;GCC
2097 "__imag__" ;GCC
2098 "__inline__" ;GCC
2099 "__label__" ;GCC
2100 "__real__" ;GCC
2101 "__signed__" ;GCC
2102 "__typeof__" ;GCC
2103 "__volatile__" ;GCC
2104 ))
300f8827 2105 (c-builtins
26f18bd1 2106 (mdw-regexps "false" ;C++, C99 macro
165cecf8 2107 "this" ;C++
26f18bd1 2108 "true" ;C++, C99 macro
165cecf8 2109 ))
f617db13 2110 (preprocessor-keywords
8d6d55b9
MW
2111 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2112 "ident" "if" "ifdef" "ifndef" "import" "include"
2113 "line" "pragma" "unassert" "undef" "warning"))
f617db13 2114 (objc-keywords
8d6d55b9
MW
2115 (mdw-regexps "class" "defs" "encode" "end" "implementation"
2116 "interface" "private" "protected" "protocol" "public"
2117 "selector")))
f617db13
MW
2118
2119 (setq font-lock-keywords
2120 (list
f617db13 2121
6132bc01 2122 ;; Fontify include files as strings.
f617db13
MW
2123 (list (concat "^[ \t]*\\#[ \t]*"
2124 "\\(include\\|import\\)"
2125 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2126 '(2 font-lock-string-face))
2127
6132bc01 2128 ;; Preprocessor directives are `references'?.
f617db13
MW
2129 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2130 preprocessor-keywords
2131 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2132 '(1 font-lock-keyword-face))
2133
6132bc01 2134 ;; Handle the keywords defined above.
f617db13
MW
2135 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
2136 '(0 font-lock-keyword-face))
2137
2138 (list (concat "\\<\\(" c-keywords "\\)\\>")
2139 '(0 font-lock-keyword-face))
2140
300f8827 2141 (list (concat "\\<\\(" c-builtins "\\)\\>")
165cecf8
MW
2142 '(0 font-lock-variable-name-face))
2143
6132bc01 2144 ;; Handle numbers too.
f617db13
MW
2145 ;;
2146 ;; This looks strange, I know. It corresponds to the
2147 ;; preprocessor's idea of what a number looks like, rather than
2148 ;; anything sensible.
f617db13
MW
2149 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2150 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2151 '(0 mdw-number-face))
2152
6132bc01 2153 ;; And anything else is punctuation.
f617db13 2154 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 2155 '(0 mdw-punct-face))))))
f617db13 2156
fb16ed85
MW
2157(define-derived-mode sod-mode c-mode "Sod"
2158 "Major mode for editing Sod code.")
2159(push '("\\.sod$" . sod-mode) auto-mode-alist)
2160
b50c6712
MW
2161(dolist (hook '(c-mode-hook objc-mode-hook c++-mode-hook))
2162 (add-hook hook 'mdw-misc-mode-config t)
2163 (add-hook hook 'mdw-fontify-c-and-c++ t))
2164
6132bc01
MW
2165;;;--------------------------------------------------------------------------
2166;;; AP calc mode.
f617db13 2167
e7186cbe
MW
2168(define-derived-mode apcalc-mode c-mode "AP Calc"
2169 "Major mode for editing Calc code.")
f617db13
MW
2170
2171(defun mdw-fontify-apcalc ()
2172
6132bc01 2173 ;; Fiddle with some syntax codes.
f617db13
MW
2174 (modify-syntax-entry ?* ". 23")
2175 (modify-syntax-entry ?/ ". 14")
2176
6132bc01 2177 ;; Other stuff.
f617db13
MW
2178 (setq comment-start "/* ")
2179 (setq comment-end " */")
0e7d960b 2180 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
f617db13 2181
6132bc01 2182 ;; Now define things to be fontified.
02109a0d 2183 (make-local-variable 'font-lock-keywords)
f617db13 2184 (let ((c-keywords
8d6d55b9
MW
2185 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
2186 "do" "else" "exit" "for" "global" "goto" "help" "if"
2187 "local" "mat" "obj" "print" "quit" "read" "return"
2188 "show" "static" "switch" "while" "write")))
f617db13
MW
2189
2190 (setq font-lock-keywords
2191 (list
f617db13 2192
6132bc01 2193 ;; Handle the keywords defined above.
f617db13
MW
2194 (list (concat "\\<\\(" c-keywords "\\)\\>")
2195 '(0 font-lock-keyword-face))
2196
6132bc01 2197 ;; Handle numbers too.
f617db13
MW
2198 ;;
2199 ;; This looks strange, I know. It corresponds to the
2200 ;; preprocessor's idea of what a number looks like, rather than
2201 ;; anything sensible.
f617db13
MW
2202 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2203 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2204 '(0 mdw-number-face))
2205
6132bc01 2206 ;; And anything else is punctuation.
f617db13 2207 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 2208 '(0 mdw-punct-face))))))
f617db13 2209
b50c6712
MW
2210(progn
2211 (add-hook 'apcalc-mode-hook 'mdw-misc-mode-config t)
2212 (add-hook 'apcalc-mode-hook 'mdw-fontify-apcalc t))
2213
6132bc01
MW
2214;;;--------------------------------------------------------------------------
2215;;; Java programming configuration.
f617db13 2216
6132bc01 2217;; Make indentation nice.
f617db13 2218
c56296d0
MW
2219(mdw-define-c-style mdw-java
2220 (c-basic-offset . 2)
2221 (c-backslash-column . 72)
2222 (c-offsets-alist (substatement-open . 0)
2223 (label . +)
2224 (case-label . +)
2225 (access-label . 0)
2226 (inclass . +)
2227 (statement-case-intro . +)))
2228(mdw-set-default-c-style 'java-mode 'mdw-java)
f617db13 2229
6132bc01 2230;; Declare Java fontification style.
f617db13
MW
2231
2232(defun mdw-fontify-java ()
2233
36eabf61
MW
2234 ;; Fiddle with some syntax codes.
2235 (modify-syntax-entry ?@ ".")
2236 (modify-syntax-entry ?@ "." font-lock-syntax-table)
2237
6132bc01 2238 ;; Other stuff.
0e7d960b 2239 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
f617db13 2240
6132bc01 2241 ;; Now define things to be fontified.
02109a0d 2242 (make-local-variable 'font-lock-keywords)
f617db13 2243 (let ((java-keywords
853d8555
MW
2244 (mdw-regexps "abstract" "assert"
2245 "boolean" "break" "byte"
2246 "case" "catch" "char" "class" "const" "continue"
2247 "default" "do" "double"
2248 "else" "enum" "extends"
2249 "final" "finally" "float" "for"
2250 "goto"
2251 "if" "implements" "import" "instanceof" "int"
2252 "interface"
2253 "long"
2254 "native" "new"
2255 "package" "private" "protected" "public"
2256 "return"
2257 "short" "static" "strictfp" "switch" "synchronized"
2258 "throw" "throws" "transient" "try"
2259 "void" "volatile"
2260 "while"))
8d6d55b9 2261
300f8827 2262 (java-builtins
165cecf8 2263 (mdw-regexps "false" "null" "super" "this" "true")))
f617db13
MW
2264
2265 (setq font-lock-keywords
2266 (list
f617db13 2267
6132bc01 2268 ;; Handle the keywords defined above.
f617db13
MW
2269 (list (concat "\\<\\(" java-keywords "\\)\\>")
2270 '(0 font-lock-keyword-face))
2271
300f8827
MW
2272 ;; Handle the magic builtins defined above.
2273 (list (concat "\\<\\(" java-builtins "\\)\\>")
165cecf8
MW
2274 '(0 font-lock-variable-name-face))
2275
6132bc01 2276 ;; Handle numbers too.
f617db13
MW
2277 ;;
2278 ;; The following isn't quite right, but it's close enough.
f617db13
MW
2279 (list (concat "\\<\\("
2280 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2281 "[0-9]+\\(\\.[0-9]*\\|\\)"
2282 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2283 "[lLfFdD]?")
2284 '(0 mdw-number-face))
2285
6132bc01 2286 ;; And anything else is punctuation.
f617db13 2287 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 2288 '(0 mdw-punct-face))))))
f617db13 2289
b50c6712
MW
2290(progn
2291 (add-hook 'java-mode-hook 'mdw-misc-mode-config t)
2292 (add-hook 'java-mode-hook 'mdw-fontify-java t))
2293
6132bc01 2294;;;--------------------------------------------------------------------------
61d63206
MW
2295;;; Javascript programming configuration.
2296
2297(defun mdw-javascript-style ()
2298 (setq js-indent-level 2)
2299 (setq js-expr-indent-offset 0))
2300
2301(defun mdw-fontify-javascript ()
2302
2303 ;; Other stuff.
2304 (mdw-javascript-style)
2305 (setq js-auto-indent-flag t)
2306
2307 ;; Now define things to be fontified.
2308 (make-local-variable 'font-lock-keywords)
2309 (let ((javascript-keywords
2310 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
2311 "char" "class" "const" "continue" "debugger" "default"
2312 "delete" "do" "double" "else" "enum" "export" "extends"
2313 "final" "finally" "float" "for" "function" "goto" "if"
2314 "implements" "import" "in" "instanceof" "int"
2315 "interface" "let" "long" "native" "new" "package"
2316 "private" "protected" "public" "return" "short"
2317 "static" "super" "switch" "synchronized" "throw"
2318 "throws" "transient" "try" "typeof" "var" "void"
4e23ea53 2319 "volatile" "while" "with" "yield"))
300f8827 2320 (javascript-builtins
61d63206
MW
2321 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
2322 "arguments" "this")))
2323
2324 (setq font-lock-keywords
2325 (list
2326
2327 ;; Handle the keywords defined above.
f7856acd 2328 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
61d63206
MW
2329 '(0 font-lock-keyword-face))
2330
300f8827
MW
2331 ;; Handle the predefined builtins defined above.
2332 (list (concat "\\_<\\(" javascript-builtins "\\)\\_>")
61d63206
MW
2333 '(0 font-lock-variable-name-face))
2334
2335 ;; Handle numbers too.
2336 ;;
2337 ;; The following isn't quite right, but it's close enough.
f7856acd 2338 (list (concat "\\_<\\("
61d63206
MW
2339 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2340 "[0-9]+\\(\\.[0-9]*\\|\\)"
2341 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2342 "[lLfFdD]?")
2343 '(0 mdw-number-face))
2344
2345 ;; And anything else is punctuation.
2346 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 2347 '(0 mdw-punct-face))))))
61d63206 2348
b50c6712
MW
2349(progn
2350 (add-hook 'js-mode-hook 'mdw-misc-mode-config t)
2351 (add-hook 'js-mode-hook 'mdw-fontify-javascript t))
2352
61d63206 2353;;;--------------------------------------------------------------------------
ee7c3dea
MW
2354;;; Scala programming configuration.
2355
2356(defun mdw-fontify-scala ()
2357
7b5903d8
MW
2358 ;; Comment filling.
2359 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2360
ee7c3dea
MW
2361 ;; Define things to be fontified.
2362 (make-local-variable 'font-lock-keywords)
2363 (let ((scala-keywords
2364 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
2365 "extends" "final" "finally" "for" "forSome" "if"
2366 "implicit" "import" "lazy" "match" "new" "object"
3f017188
MW
2367 "override" "package" "private" "protected" "return"
2368 "sealed" "throw" "trait" "try" "type" "val"
ee7c3dea
MW
2369 "var" "while" "with" "yield"))
2370 (scala-constants
3f017188 2371 (mdw-regexps "false" "null" "super" "this" "true"))
7b5903d8 2372 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
ee7c3dea
MW
2373
2374 (setq font-lock-keywords
2375 (list
2376
2377 ;; Magical identifiers between backticks.
2378 (list (concat "`\\([^`]+\\)`")
2379 '(1 font-lock-variable-name-face))
2380
2381 ;; Handle the keywords defined above.
2382 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
2383 '(0 font-lock-keyword-face))
2384
2385 ;; Handle the constants defined above.
2386 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
2387 '(0 font-lock-variable-name-face))
2388
2389 ;; Magical identifiers between backticks.
2390 (list (concat "`\\([^`]+\\)`")
2391 '(1 font-lock-variable-name-face))
2392
2393 ;; Handle numbers too.
2394 ;;
2395 ;; As usual, not quite right.
2396 (list (concat "\\_<\\("
2397 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2398 "[0-9]+\\(\\.[0-9]*\\|\\)"
2399 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2400 "[lLfFdD]?")
2401 '(0 mdw-number-face))
2402
ee7c3dea
MW
2403 ;; And everything else is punctuation.
2404 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2405 '(0 mdw-punct-face)))
2406
2407 font-lock-syntactic-keywords
2408 (list
2409
2410 ;; Single quotes around characters. But not when used to quote
2411 ;; symbol names. Ugh.
2412 (list (concat "\\('\\)"
2413 "\\(" "."
2414 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
2415 "u+" "[0-9a-fA-F]\\{4\\}"
2416 "\\|" "\\\\" "[0-7]\\{1,3\\}"
2417 "\\|" "\\\\" "." "\\)"
2418 "\\('\\)")
2419 '(1 "\"")
2e7c6a86 2420 '(4 "\""))))))
ee7c3dea 2421
b50c6712
MW
2422(progn
2423 (add-hook 'scala-mode-hook 'mdw-misc-mode-config t)
2424 (add-hook 'scala-mode-hook 'mdw-fontify-scala t))
2425
ee7c3dea 2426;;;--------------------------------------------------------------------------
6132bc01 2427;;; C# programming configuration.
e808c1e5 2428
6132bc01 2429;; Make indentation nice.
e808c1e5 2430
c56296d0
MW
2431(mdw-define-c-style mdw-csharp
2432 (c-basic-offset . 2)
2433 (c-backslash-column . 72)
2434 (c-offsets-alist (substatement-open . 0)
2435 (label . 0)
2436 (case-label . +)
2437 (access-label . 0)
2438 (inclass . +)
2439 (statement-case-intro . +)))
2440(mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
e808c1e5 2441
6132bc01 2442;; Declare C# fontification style.
e808c1e5
MW
2443
2444(defun mdw-fontify-csharp ()
2445
6132bc01 2446 ;; Other stuff.
0e7d960b 2447 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
e808c1e5 2448
6132bc01 2449 ;; Now define things to be fontified.
e808c1e5
MW
2450 (make-local-variable 'font-lock-keywords)
2451 (let ((csharp-keywords
165cecf8
MW
2452 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
2453 "char" "checked" "class" "const" "continue" "decimal"
2454 "default" "delegate" "do" "double" "else" "enum"
2455 "event" "explicit" "extern" "finally" "fixed" "float"
2456 "for" "foreach" "goto" "if" "implicit" "in" "int"
2457 "interface" "internal" "is" "lock" "long" "namespace"
2458 "new" "object" "operator" "out" "override" "params"
2459 "private" "protected" "public" "readonly" "ref"
2460 "return" "sbyte" "sealed" "short" "sizeof"
2461 "stackalloc" "static" "string" "struct" "switch"
2462 "throw" "try" "typeof" "uint" "ulong" "unchecked"
2463 "unsafe" "ushort" "using" "virtual" "void" "volatile"
2464 "while" "yield"))
2465
300f8827 2466 (csharp-builtins
165cecf8 2467 (mdw-regexps "base" "false" "null" "this" "true")))
e808c1e5
MW
2468
2469 (setq font-lock-keywords
2470 (list
e808c1e5 2471
6132bc01 2472 ;; Handle the keywords defined above.
e808c1e5
MW
2473 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
2474 '(0 font-lock-keyword-face))
2475
300f8827
MW
2476 ;; Handle the magic builtins defined above.
2477 (list (concat "\\<\\(" csharp-builtins "\\)\\>")
165cecf8
MW
2478 '(0 font-lock-variable-name-face))
2479
6132bc01 2480 ;; Handle numbers too.
e808c1e5
MW
2481 ;;
2482 ;; The following isn't quite right, but it's close enough.
e808c1e5
MW
2483 (list (concat "\\<\\("
2484 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2485 "[0-9]+\\(\\.[0-9]*\\|\\)"
2486 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2487 "[lLfFdD]?")
2488 '(0 mdw-number-face))
2489
6132bc01 2490 ;; And anything else is punctuation.
e808c1e5 2491 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 2492 '(0 mdw-punct-face))))))
e808c1e5 2493
103c5923
MW
2494(define-derived-mode csharp-mode java-mode "C#"
2495 "Major mode for editing C# code.")
e808c1e5 2496
b50c6712
MW
2497(add-hook 'csharp-mode-hook 'mdw-fontify-csharp t)
2498
6132bc01 2499;;;--------------------------------------------------------------------------
81fb08fc
MW
2500;;; F# programming configuration.
2501
2502(setq fsharp-indent-offset 2)
2503
2504(defun mdw-fontify-fsharp ()
2505
2506 (let ((punct "=<>+-*/|&%!@?"))
2507 (do ((i 0 (1+ i)))
2508 ((>= i (length punct)))
2509 (modify-syntax-entry (aref punct i) ".")))
2510
2511 (modify-syntax-entry ?_ "_")
2512 (modify-syntax-entry ?( "(")
2513 (modify-syntax-entry ?) ")")
2514
2515 (setq indent-tabs-mode nil)
2516
2517 (let ((fsharp-keywords
2518 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
165cecf8 2519 "begin" "break"
81fb08fc
MW
2520 "checked" "class" "component" "const" "constraint"
2521 "constructor" "continue"
2522 "default" "delegate" "do" "done" "downcast" "downto"
2523 "eager" "elif" "else" "end" "exception" "extern"
165cecf8 2524 "finally" "fixed" "for" "fori" "fun" "function"
81fb08fc
MW
2525 "functor"
2526 "global"
2527 "if" "in" "include" "inherit" "inline" "interface"
2528 "internal"
2529 "lazy" "let"
2530 "match" "measure" "member" "method" "mixin" "module"
2531 "mutable"
165cecf8
MW
2532 "namespace" "new"
2533 "object" "of" "open" "or" "override"
81fb08fc
MW
2534 "parallel" "params" "private" "process" "protected"
2535 "public" "pure"
2536 "rec" "recursive" "return"
2537 "sealed" "sig" "static" "struct"
165cecf8 2538 "tailcall" "then" "to" "trait" "try" "type"
81fb08fc
MW
2539 "upcast" "use"
2540 "val" "virtual" "void" "volatile"
2541 "when" "while" "with"
2542 "yield"))
2543
2544 (fsharp-builtins
165cecf8
MW
2545 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
2546 "base" "false" "null" "true"))
81fb08fc
MW
2547
2548 (bang-keywords
2549 (mdw-regexps "do" "let" "return" "use" "yield"))
2550
2551 (preprocessor-keywords
2552 (mdw-regexps "if" "indent" "else" "endif")))
2553
2554 (setq font-lock-keywords
2555 (list (list (concat "\\(^\\|[^\"]\\)"
2556 "\\(" "(\\*"
2557 "[^*]*\\*+"
2558 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
2559 ")"
2560 "\\|"
2561 "//.*"
2562 "\\)")
2563 '(2 font-lock-comment-face))
2564
2565 (list (concat "'" "\\("
2566 "\\\\"
2567 "\\(" "[ntbr'\\]"
2568 "\\|" "[0-9][0-9][0-9]"
2569 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
2570 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
2571 "\\)"
2572 "\\|"
2573 "." "\\)" "'"
2574 "\\|"
2575 "\"" "[^\"\\]*"
2576 "\\(" "\\\\" "\\(.\\|\n\\)"
2577 "[^\"\\]*" "\\)*"
2578 "\\(\"\\|\\'\\)")
2579 '(0 font-lock-string-face))
2580
2581 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
2582 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
2583 "\\|"
2584 "\\_<\\(" fsharp-keywords "\\)\\_>")
2585 '(0 font-lock-keyword-face))
2586 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
2587 '(0 font-lock-variable-name-face))
2588
2589 (list (concat "\\_<"
2590 "\\(" "0[bB][01]+" "\\|"
2591 "0[oO][0-7]+" "\\|"
2592 "0[xX][0-9a-fA-F]+" "\\)"
2593 "\\(" "lf\\|LF" "\\|"
2594 "[uU]?[ysnlL]?" "\\)"
2595 "\\|"
2596 "\\_<"
2597 "[0-9]+" "\\("
2598 "[mMQRZING]"
2599 "\\|"
2600 "\\(\\.[0-9]*\\)?"
2601 "\\([eE][-+]?[0-9]+\\)?"
2602 "[fFmM]?"
2603 "\\|"
2604 "[uU]?[ysnlL]?"
2605 "\\)")
2606 '(0 mdw-number-face))
2607
2608 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 2609 '(0 mdw-punct-face))))))
81fb08fc
MW
2610
2611(defun mdw-fontify-inferior-fsharp ()
2612 (mdw-fontify-fsharp)
2613 (setq font-lock-keywords
2614 (append (list (list "^[#-]" '(0 font-lock-comment-face))
2615 (list "^>" '(0 font-lock-keyword-face)))
2616 font-lock-keywords)))
2617
b50c6712
MW
2618(progn
2619 (add-hook 'fsharp-mode-hook 'mdw-misc-mode-config t)
2620 (add-hook 'fsharp-mode-hook 'mdw-fontify-fsharp t)
2621 (add-hook 'inferior-fsharp-mode-hooks 'mdw-fontify-inferior-fsharp t))
2622
81fb08fc 2623;;;--------------------------------------------------------------------------
07965a39
MW
2624;;; Go programming configuration.
2625
2626(defun mdw-fontify-go ()
2627
2628 (make-local-variable 'font-lock-keywords)
2629 (let ((go-keywords
2630 (mdw-regexps "break" "case" "chan" "const" "continue"
2631 "default" "defer" "else" "fallthrough" "for"
2632 "func" "go" "goto" "if" "import"
2633 "interface" "map" "package" "range" "return"
fc79ff88
MW
2634 "select" "struct" "switch" "type" "var"))
2635 (go-intrinsics
2636 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
2637 "float32" "float64" "int" "uint8" "int16" "int32"
2638 "int64" "rune" "string" "uint" "uint8" "uint16"
2639 "uint32" "uint64" "uintptr" "void"
2640 "false" "iota" "nil" "true"
2641 "init" "main"
2642 "append" "cap" "copy" "delete" "imag" "len" "make"
2643 "new" "panic" "real" "recover")))
07965a39
MW
2644
2645 (setq font-lock-keywords
2646 (list
2647
2648 ;; Handle the keywords defined above.
2649 (list (concat "\\<\\(" go-keywords "\\)\\>")
2650 '(0 font-lock-keyword-face))
fc79ff88
MW
2651 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
2652 '(0 font-lock-variable-name-face))
07965a39 2653
cbbea94e
MW
2654 ;; Strings and characters.
2655 (list (concat "'"
2656 "\\(" "[^\\']" "\\|"
2657 "\\\\"
2658 "\\(" "[abfnrtv\\'\"]" "\\|"
2659 "[0-7]\\{3\\}" "\\|"
2660 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
2661 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
2662 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
2663 "'"
2664 "\\|"
2665 "\""
2666 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
2667 "\\(\"\\|$\\)"
2668 "\\|"
2669 "`" "[^`]+" "`")
2670 '(0 font-lock-string-face))
2671
07965a39
MW
2672 ;; Handle numbers too.
2673 ;;
2674 ;; The following isn't quite right, but it's close enough.
2675 (list (concat "\\<\\("
2676 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2677 "[0-9]+\\(\\.[0-9]*\\|\\)"
2678 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
2679 '(0 mdw-number-face))
2680
2681 ;; And anything else is punctuation.
2682 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 2683 '(0 mdw-punct-face))))))
b50c6712
MW
2684(progn
2685 (add-hook 'go-mode-hook 'mdw-misc-mode-config t)
2686 (add-hook 'go-mode-hook 'mdw-fontify-go t))
07965a39
MW
2687
2688;;;--------------------------------------------------------------------------
36db1ea7
MW
2689;;; Rust programming configuration.
2690
2691(setq-default rust-indent-offset 2)
2692
2693(defun mdw-self-insert-and-indent (count)
2694 (interactive "p")
2695 (self-insert-command count)
2696 (indent-according-to-mode))
2697
2698(defun mdw-fontify-rust ()
2699
2700 ;; Hack syntax categories.
cbd69b16 2701 (modify-syntax-entry ?$ ".")
8e234929 2702 (modify-syntax-entry ?% ".")
36db1ea7
MW
2703 (modify-syntax-entry ?= ".")
2704
2705 ;; Fontify keywords and things.
2706 (make-local-variable 'font-lock-keywords)
2707 (let ((rust-keywords
87def30c 2708 (mdw-regexps "abstract" "alignof" "as" "async" "await"
36db1ea7 2709 "become" "box" "break"
260564a3 2710 "const" "continue" "crate"
87def30c 2711 "do" "dyn"
36db1ea7 2712 "else" "enum" "extern"
b6f44b18 2713 "final" "fn" "for"
36db1ea7
MW
2714 "if" "impl" "in"
2715 "let" "loop"
2716 "macro" "match" "mod" "move" "mut"
2717 "offsetof" "override"
b6f44b18 2718 "priv" "proc" "pub" "pure"
36db1ea7 2719 "ref" "return"
b6f44b18 2720 "sizeof" "static" "struct" "super"
87def30c
MW
2721 "trait" "try" "type" "typeof"
2722 "union" "unsafe" "unsized" "use"
36db1ea7
MW
2723 "virtual"
2724 "where" "while"
2725 "yield"))
2726 (rust-builtins
2727 (mdw-regexps "array" "pointer" "slice" "tuple"
2728 "bool" "true" "false"
2729 "f32" "f64"
2730 "i8" "i16" "i32" "i64" "isize"
2731 "u8" "u16" "u32" "u64" "usize"
b6f44b18
MW
2732 "char" "str"
2733 "self" "Self")))
36db1ea7
MW
2734 (setq font-lock-keywords
2735 (list
2736
2737 ;; Handle the keywords defined above.
d71a646d 2738 (list (concat "\\_<\\(" rust-keywords "\\)\\_>")
36db1ea7 2739 '(0 font-lock-keyword-face))
d71a646d 2740 (list (concat "\\_<\\(" rust-builtins "\\)\\_>")
36db1ea7
MW
2741 '(0 font-lock-variable-name-face))
2742
2743 ;; Handle numbers too.
d71a646d 2744 (list (concat "\\_<\\("
36db1ea7
MW
2745 "[0-9][0-9_]*"
2746 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
2747 "\\|" "\\.[0-9_]+"
2748 "\\)"
2749 "\\(f32\\|f64\\)?"
2750 "\\|" "\\(" "[0-9][0-9_]*"
2751 "\\|" "0x[0-9a-fA-F_]+"
2752 "\\|" "0o[0-7_]+"
2753 "\\|" "0b[01_]+"
2754 "\\)"
63b40831 2755 "\\([ui]\\(8\\|16\\|32\\|64\\|size\\)\\)?"
d71a646d 2756 "\\)\\_>")
36db1ea7
MW
2757 '(0 mdw-number-face))
2758
2759 ;; And anything else is punctuation.
2760 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2761 '(0 mdw-punct-face)))))
2762
2763 ;; Hack key bindings.
d2f85967 2764 (local-set-key [?{] 'mdw-self-insert-and-indent)
2e7c6a86 2765 (local-set-key [?}] 'mdw-self-insert-and-indent))
36db1ea7 2766
b50c6712
MW
2767(progn
2768 (add-hook 'rust-mode-hook 'mdw-misc-mode-config t)
2769 (add-hook 'rust-mode-hook 'mdw-fontify-rust t))
2770
36db1ea7 2771;;;--------------------------------------------------------------------------
6132bc01 2772;;; Awk programming configuration.
f617db13 2773
6132bc01 2774;; Make Awk indentation nice.
f617db13 2775
c56296d0
MW
2776(mdw-define-c-style mdw-awk
2777 (c-basic-offset . 2)
2778 (c-offsets-alist (substatement-open . 0)
2779 (c-backslash-column . 72)
2780 (statement-cont . 0)
2781 (statement-case-intro . +)))
2782(mdw-set-default-c-style 'awk-mode 'mdw-awk)
f617db13 2783
6132bc01 2784;; Declare Awk fontification style.
f617db13
MW
2785
2786(defun mdw-fontify-awk ()
2787
6132bc01 2788 ;; Miscellaneous fiddling.
f617db13
MW
2789 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2790
6132bc01 2791 ;; Now define things to be fontified.
02109a0d 2792 (make-local-variable 'font-lock-keywords)
f617db13 2793 (let ((c-keywords
8d6d55b9
MW
2794 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
2795 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
2796 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
2797 "RSTART" "RLENGTH" "RT" "SUBSEP"
2798 "atan2" "break" "close" "continue" "cos" "delete"
2799 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
2800 "function" "gensub" "getline" "gsub" "if" "in"
2801 "index" "int" "length" "log" "match" "next" "rand"
2802 "return" "print" "printf" "sin" "split" "sprintf"
2803 "sqrt" "srand" "strftime" "sub" "substr" "system"
2804 "systime" "tolower" "toupper" "while")))
f617db13
MW
2805
2806 (setq font-lock-keywords
2807 (list
f617db13 2808
6132bc01 2809 ;; Handle the keywords defined above.
f617db13
MW
2810 (list (concat "\\<\\(" c-keywords "\\)\\>")
2811 '(0 font-lock-keyword-face))
2812
6132bc01 2813 ;; Handle numbers too.
f617db13
MW
2814 ;;
2815 ;; The following isn't quite right, but it's close enough.
f617db13
MW
2816 (list (concat "\\<\\("
2817 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2818 "[0-9]+\\(\\.[0-9]*\\|\\)"
2819 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2820 "[uUlL]*")
2821 '(0 mdw-number-face))
2822
6132bc01 2823 ;; And anything else is punctuation.
f617db13 2824 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 2825 '(0 mdw-punct-face))))))
f617db13 2826
b50c6712
MW
2827(progn
2828 (add-hook 'awk-mode-hook 'mdw-misc-mode-config t)
2829 (add-hook 'awk-mode-hook 'mdw-fontify-awk t))
2830
6132bc01
MW
2831;;;--------------------------------------------------------------------------
2832;;; Perl programming style.
f617db13 2833
6132bc01 2834;; Perl indentation style.
f617db13 2835
08b1b191 2836(setq-default perl-indent-level 2)
88158daf 2837
08b1b191
MW
2838(setq-default cperl-indent-level 2
2839 cperl-continued-statement-offset 2
2840 cperl-continued-brace-offset 0
2841 cperl-brace-offset -2
2842 cperl-brace-imaginary-offset 0
2843 cperl-label-offset 0)
f617db13 2844
6132bc01 2845;; Define perl fontification style.
f617db13
MW
2846
2847(defun mdw-fontify-perl ()
2848
6132bc01 2849 ;; Miscellaneous fiddling.
f617db13
MW
2850 (modify-syntax-entry ?$ "\\")
2851 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
a3b8176f 2852 (modify-syntax-entry ?: "." font-lock-syntax-table)
f617db13
MW
2853 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2854
6132bc01 2855 ;; Now define fontification things.
02109a0d 2856 (make-local-variable 'font-lock-keywords)
f617db13 2857 (let ((perl-keywords
821c4945
MW
2858 (mdw-regexps "and"
2859 "break"
2860 "cmp" "continue"
2861 "default" "do"
2862 "else" "elsif" "eq"
2863 "for" "foreach"
2864 "ge" "given" "gt" "goto"
2865 "if"
2866 "last" "le" "local" "lt"
2867 "my"
2868 "ne" "next"
2869 "or" "our"
2870 "package"
2871 "redo" "require" "return"
2872 "sub"
2873 "undef" "unless" "until" "use"
2874 "when" "while")))
f617db13
MW
2875
2876 (setq font-lock-keywords
2877 (list
f617db13 2878
6132bc01 2879 ;; Set up the keywords defined above.
f617db13
MW
2880 (list (concat "\\<\\(" perl-keywords "\\)\\>")
2881 '(0 font-lock-keyword-face))
2882
6132bc01 2883 ;; At least numbers are simpler than C.
f617db13
MW
2884 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2885 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2886 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2887 '(0 mdw-number-face))
2888
6132bc01 2889 ;; And anything else is punctuation.
f617db13 2890 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 2891 '(0 mdw-punct-face))))))
f617db13
MW
2892
2893(defun perl-number-tests (&optional arg)
2894 "Assign consecutive numbers to lines containing `#t'. With ARG,
2895strip numbers instead."
2896 (interactive "P")
2897 (save-excursion
2898 (goto-char (point-min))
2899 (let ((i 0) (fmt (if arg "" " %4d")))
2900 (while (search-forward "#t" nil t)
2901 (delete-region (point) (line-end-position))
2902 (setq i (1+ i))
2903 (insert (format fmt i)))
2904 (goto-char (point-min))
2905 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
2906 (replace-match (format "\\1%d" i))))))
2907
b50c6712
MW
2908(dolist (hook '(perl-mode-hook cperl-mode-hook))
2909 (add-hook hook 'mdw-misc-mode-config t)
2910 (add-hook hook 'mdw-fontify-perl t))
2911
6132bc01
MW
2912;;;--------------------------------------------------------------------------
2913;;; Python programming style.
f617db13 2914
b50c6712
MW
2915(setq-default py-indent-offset 2
2916 python-indent 2
2917 python-indent-offset 2
2918 python-fill-docstring-style 'symmetric)
2919
99fe6ef5 2920(defun mdw-fontify-pythonic (keywords)
f617db13 2921
6132bc01 2922 ;; Miscellaneous fiddling.
f617db13 2923 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
7c0fcfde 2924 (setq indent-tabs-mode nil)
f617db13 2925
6132bc01 2926 ;; Now define fontification things.
02109a0d 2927 (make-local-variable 'font-lock-keywords)
99fe6ef5
MW
2928 (setq font-lock-keywords
2929 (list
f617db13 2930
be2cc788 2931 ;; Set up the keywords defined above.
4b037109 2932 (list (concat "\\_<\\(" keywords "\\)\\_>")
99fe6ef5 2933 '(0 font-lock-keyword-face))
f617db13 2934
be2cc788 2935 ;; At least numbers are simpler than C.
b257436d 2936 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO]?[0-7]+\\|[bB][01]+\\)\\|"
b834ced3
MW
2937 "\\_<[0-9][0-9]*\\(\\.[0-9]*\\|\\)"
2938 "\\([eE]\\([-+]\\|\\)[0-9]+\\|[lL]\\|\\)")
99fe6ef5 2939 '(0 mdw-number-face))
f617db13 2940
be2cc788 2941 ;; And anything else is punctuation.
99fe6ef5 2942 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 2943 '(0 mdw-punct-face)))))
99fe6ef5 2944
be2cc788 2945;; Define Python fontification styles.
99fe6ef5
MW
2946
2947(defun mdw-fontify-python ()
2948 (mdw-fontify-pythonic
2949 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
2950 "del" "elif" "else" "except" "exec" "finally" "for"
2951 "from" "global" "if" "import" "in" "is" "lambda"
2952 "not" "or" "pass" "print" "raise" "return" "try"
2953 "while" "with" "yield")))
2954
2955(defun mdw-fontify-pyrex ()
2956 (mdw-fontify-pythonic
2957 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
a63efb67 2958 "ctypedef" "def" "del" "elif" "else" "enum" "except" "exec"
99fe6ef5
MW
2959 "extern" "finally" "for" "from" "global" "if"
2960 "import" "in" "is" "lambda" "not" "or" "pass" "print"
a63efb67 2961 "property" "raise" "return" "struct" "try" "while" "with"
99fe6ef5 2962 "yield")))
f617db13 2963
b5263ae5
MW
2964(define-derived-mode pyrex-mode python-mode "Pyrex"
2965 "Major mode for editing Pyrex source code")
2966(setq auto-mode-alist
2967 (append '(("\\.pyx$" . pyrex-mode)
2968 ("\\.pxd$" . pyrex-mode)
2969 ("\\.pxi$" . pyrex-mode))
2970 auto-mode-alist))
2971
b50c6712
MW
2972(progn
2973 (add-hook 'python-mode-hook 'mdw-misc-mode-config t)
2974 (add-hook 'python-mode-hook 'mdw-fontify-python t)
2975 (add-hook 'pyrex-mode-hook 'mdw-fontify-pyrex t))
2976
6132bc01 2977;;;--------------------------------------------------------------------------
772a7a3b
MW
2978;;; Lua programming style.
2979
08b1b191 2980(setq-default lua-indent-level 2)
772a7a3b
MW
2981
2982(defun mdw-fontify-lua ()
2983
2984 ;; Miscellaneous fiddling.
2985 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2986
2987 ;; Now define fontification things.
2988 (make-local-variable 'font-lock-keywords)
2989 (let ((lua-keywords
2990 (mdw-regexps "and" "break" "do" "else" "elseif" "end"
2991 "false" "for" "function" "goto" "if" "in" "local"
2992 "nil" "not" "or" "repeat" "return" "then" "true"
2993 "until" "while")))
2994 (setq font-lock-keywords
2995 (list
2996
2997 ;; Set up the keywords defined above.
2998 (list (concat "\\_<\\(" lua-keywords "\\)\\_>")
2999 '(0 font-lock-keyword-face))
3000
3001 ;; At least numbers are simpler than C.
3002 (list (concat "\\_<\\(" "0[xX]"
3003 "\\(" "[0-9a-fA-F]+"
3004 "\\(\\.[0-9a-fA-F]*\\)?"
3005 "\\|" "\\.[0-9a-fA-F]+"
3006 "\\)"
3007 "\\([pP][-+]?[0-9]+\\)?"
3008 "\\|" "\\(" "[0-9]+"
3009 "\\(\\.[0-9]*\\)?"
3010 "\\|" "\\.[0-9]+"
3011 "\\)"
3012 "\\([eE][-+]?[0-9]+\\)?"
3013 "\\)")
3014 '(0 mdw-number-face))
3015
3016 ;; And anything else is punctuation.
3017 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3018 '(0 mdw-punct-face))))))
3019
b50c6712
MW
3020(progn
3021 (add-hook 'lua-mode-hook 'mdw-misc-mode-config t)
3022 (add-hook 'lua-mode-hook 'mdw-fontify-lua t))
3023
772a7a3b 3024;;;--------------------------------------------------------------------------
6132bc01 3025;;; Icon programming style.
cc1980e1 3026
6132bc01 3027;; Icon indentation style.
cc1980e1 3028
08b1b191
MW
3029(setq-default icon-brace-offset 0
3030 icon-continued-brace-offset 0
3031 icon-continued-statement-offset 2
3032 icon-indent-level 2)
cc1980e1 3033
6132bc01 3034;; Define Icon fontification style.
cc1980e1
MW
3035
3036(defun mdw-fontify-icon ()
3037
6132bc01 3038 ;; Miscellaneous fiddling.
cc1980e1
MW
3039 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3040
6132bc01 3041 ;; Now define fontification things.
cc1980e1
MW
3042 (make-local-variable 'font-lock-keywords)
3043 (let ((icon-keywords
3044 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
3045 "end" "every" "fail" "global" "if" "initial"
3046 "invocable" "link" "local" "next" "not" "of"
3047 "procedure" "record" "repeat" "return" "static"
3048 "suspend" "then" "to" "until" "while"))
3049 (preprocessor-keywords
3050 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
3051 "include" "line" "undef")))
3052 (setq font-lock-keywords
3053 (list
3054
6132bc01 3055 ;; Set up the keywords defined above.
cc1980e1
MW
3056 (list (concat "\\<\\(" icon-keywords "\\)\\>")
3057 '(0 font-lock-keyword-face))
3058
6132bc01 3059 ;; The things that Icon calls keywords.
cc1980e1
MW
3060 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
3061
6132bc01 3062 ;; At least numbers are simpler than C.
cc1980e1
MW
3063 (list (concat "\\<[0-9]+"
3064 "\\([rR][0-9a-zA-Z]+\\|"
3065 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
3066 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
3067 '(0 mdw-number-face))
3068
6132bc01 3069 ;; Preprocessor.
cc1980e1
MW
3070 (list (concat "^[ \t]*$[ \t]*\\<\\("
3071 preprocessor-keywords
3072 "\\)\\>")
3073 '(0 font-lock-keyword-face))
3074
6132bc01 3075 ;; And anything else is punctuation.
cc1980e1 3076 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 3077 '(0 mdw-punct-face))))))
cc1980e1 3078
b50c6712
MW
3079(progn
3080 (add-hook 'icon-mode-hook 'mdw-misc-mode-config t)
3081 (add-hook 'icon-mode-hook 'mdw-fontify-icon t))
3082
6132bc01 3083;;;--------------------------------------------------------------------------
6132bc01 3084;;; Assembler mode.
30c8a8fb
MW
3085
3086(defun mdw-fontify-asm ()
3087 (modify-syntax-entry ?' "\"")
3088 (modify-syntax-entry ?. "w")
9032280b 3089 (modify-syntax-entry ?\n ">")
30c8a8fb 3090 (setf fill-prefix nil)
5edd6d49
MW
3091 (modify-syntax-entry ?. "_")
3092 (modify-syntax-entry ?* ". 23")
3093 (modify-syntax-entry ?/ ". 124b")
3094 (modify-syntax-entry ?\n "> b")
b90c2a2c 3095 (local-set-key ";" 'self-insert-command)
30c8a8fb
MW
3096 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
3097
227b2b2b
MW
3098(defun mdw-asm-set-comment ()
3099 (modify-syntax-entry ?; "."
3100 )
5edd6d49 3101 (modify-syntax-entry asm-comment-char "< b")
227b2b2b
MW
3102 (setq comment-start (string asm-comment-char ? )))
3103(add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
3104(put 'asm-comment-char 'safe-local-variable 'characterp)
9032280b 3105
b50c6712
MW
3106(progn
3107 (add-hook 'asm-mode-hook 'mdw-misc-mode-config t)
3108 (add-hook 'asm-mode-hook 'mdw-fontify-asm t))
3109
6132bc01
MW
3110;;;--------------------------------------------------------------------------
3111;;; TCL configuration.
f617db13 3112
b50c6712
MW
3113(setq-default tcl-indent-level 2)
3114
f617db13 3115(defun mdw-fontify-tcl ()
6c4bd06b
MW
3116 (dolist (ch '(?$))
3117 (modify-syntax-entry ch "."))
f617db13 3118 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
02109a0d 3119 (make-local-variable 'font-lock-keywords)
f617db13
MW
3120 (setq font-lock-keywords
3121 (list
f617db13
MW
3122 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3123 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
3124 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
3125 '(0 mdw-number-face))
3126 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 3127 '(0 mdw-punct-face)))))
f617db13 3128
b50c6712
MW
3129(progn
3130 (add-hook 'tcl-mode-hook 'mdw-misc-mode-config t)
3131 (add-hook 'tcl-mode-hook 'mdw-fontify-tcl t))
3132
6132bc01 3133;;;--------------------------------------------------------------------------
ad305d7e
MW
3134;;; Dylan programming configuration.
3135
3136(defun mdw-fontify-dylan ()
3137
3138 (make-local-variable 'font-lock-keywords)
3139
3140 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
3141 ;; hook, which undoes all of our configuration.
3142 (setq major-mode 'dylan-mode)
3143 (font-lock-set-defaults)
3144
3145 (let* ((word "[-_a-zA-Z!*@<>$%]+")
3146 (dylan-keywords (mdw-regexps
3147
3148 "C-address" "C-callable-wrapper" "C-function"
3149 "C-mapped-subtype" "C-pointer-type" "C-struct"
3150 "C-subtype" "C-union" "C-variable"
3151
3152 "above" "abstract" "afterwards" "all"
3153 "begin" "below" "block" "by"
3154 "case" "class" "cleanup" "constant" "create"
3155 "define" "domain"
3156 "else" "elseif" "end" "exception" "export"
3157 "finally" "for" "from" "function"
3158 "generic"
3159 "handler"
3160 "if" "in" "instance" "interface" "iterate"
3161 "keyed-by"
3162 "let" "library" "local"
3163 "macro" "method" "module"
3164 "otherwise"
3165 "profiling"
3166 "select" "slot" "subclass"
3167 "table" "then" "to"
3168 "unless" "until" "use"
3169 "variable" "virtual"
3170 "when" "while"))
3171 (sharp-keywords (mdw-regexps
3172 "all-keys" "key" "next" "rest" "include"
3173 "t" "f")))
3174 (setq font-lock-keywords
3175 (list (list (concat "\\<\\(" dylan-keywords
ce29694e 3176 "\\|" "with\\(out\\)?-" word
ad305d7e
MW
3177 "\\)\\>")
3178 '(0 font-lock-keyword-face))
ce29694e
MW
3179 (list (concat "\\<" word ":" "\\|"
3180 "#\\(" sharp-keywords "\\)\\>")
ad305d7e
MW
3181 '(0 font-lock-variable-name-face))
3182 (list (concat "\\("
3183 "\\([-+]\\|\\<\\)[0-9]+" "\\("
3184 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
3185 "\\|" "/[0-9]+"
3186 "\\)"
3187 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
3188 "\\|" "#b[01]+"
3189 "\\|" "#o[0-7]+"
3190 "\\|" "#x[0-9a-zA-Z]+"
3191 "\\)\\>")
3192 '(0 mdw-number-face))
3193 (list (concat "\\("
3194 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
3195 "\\_<[-+*/=<>:&|]+\\_>"
3196 "\\)")
2e7c6a86 3197 '(0 mdw-punct-face))))))
ad305d7e 3198
b50c6712
MW
3199(progn
3200 (add-hook 'dylan-mode-hook 'mdw-misc-mode-config t)
3201 (add-hook 'dylan-mode-hook 'mdw-fontify-dylan t))
3202
ad305d7e 3203;;;--------------------------------------------------------------------------
7fce54c3
MW
3204;;; Algol 68 configuration.
3205
08b1b191 3206(setq-default a68-indent-step 2)
7fce54c3
MW
3207
3208(defun mdw-fontify-algol-68 ()
3209
3210 ;; Fix up the syntax table.
3211 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
3212 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
3213 (modify-syntax-entry ch "." a68-mode-syntax-table))
3214
3215 (make-local-variable 'font-lock-keywords)
3216
3217 (let ((not-comment
3218 (let ((word "COMMENT"))
3219 (do ((regexp (concat "[^" (substring word 0 1) "]+")
3220 (concat regexp "\\|"
3221 (substring word 0 i)
3222 "[^" (substring word i (1+ i)) "]"))
3223 (i 1 (1+ i)))
3224 ((>= i (length word)) regexp)))))
3225 (setq font-lock-keywords
3226 (list (list (concat "\\<COMMENT\\>"
3227 "\\(" not-comment "\\)\\{0,5\\}"
3228 "\\(\\'\\|\\<COMMENT\\>\\)")
3229 '(0 font-lock-comment-face))
3230 (list (concat "\\<CO\\>"
3231 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
3232 "\\($\\|\\<CO\\>\\)")
3233 '(0 font-lock-comment-face))
3234 (list "\\<[A-Z_]+\\>"
3235 '(0 font-lock-keyword-face))
3236 (list (concat "\\<"
3237 "[0-9]+"
3238 "\\(\\.[0-9]+\\)?"
3239 "\\([eE][-+]?[0-9]+\\)?"
3240 "\\>")
3241 '(0 mdw-number-face))
3242 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
2e7c6a86 3243 '(0 mdw-punct-face))))))
7fce54c3 3244
b50c6712
MW
3245(dolist (hook '(a68-mode-hook a68-mode-hooks))
3246 (add-hook hook 'mdw-misc-mode-config t)
3247 (add-hook hook 'mdw-fontify-algol-68 t))
3248
7fce54c3 3249;;;--------------------------------------------------------------------------
6132bc01 3250;;; REXX configuration.
f617db13
MW
3251
3252(defun mdw-rexx-electric-* ()
3253 (interactive)
3254 (insert ?*)
3255 (rexx-indent-line))
3256
3257(defun mdw-rexx-indent-newline-indent ()
3258 (interactive)
3259 (rexx-indent-line)
3260 (if abbrev-mode (expand-abbrev))
3261 (newline-and-indent))
3262
3263(defun mdw-fontify-rexx ()
3264
6132bc01 3265 ;; Various bits of fiddling.
f617db13
MW
3266 (setq mdw-auto-indent nil)
3267 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
3268 (local-set-key [?*] 'mdw-rexx-electric-*)
6c4bd06b
MW
3269 (dolist (ch '(?! ?? ?# ?@ ?$)) (modify-syntax-entry ch "w"))
3270 (dolist (ch '(?¬)) (modify-syntax-entry ch "."))
f617db13
MW
3271 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
3272
6132bc01 3273 ;; Set up keywords and things for fontification.
f617db13
MW
3274 (make-local-variable 'font-lock-keywords-case-fold-search)
3275 (setq font-lock-keywords-case-fold-search t)
3276
3277 (setq rexx-indent 2)
3278 (setq rexx-end-indent rexx-indent)
f617db13
MW
3279 (setq rexx-cont-indent rexx-indent)
3280
02109a0d 3281 (make-local-variable 'font-lock-keywords)
f617db13 3282 (let ((rexx-keywords
8d6d55b9
MW
3283 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
3284 "else" "end" "engineering" "exit" "expose" "for"
3285 "forever" "form" "fuzz" "if" "interpret" "iterate"
3286 "leave" "linein" "name" "nop" "numeric" "off" "on"
3287 "options" "otherwise" "parse" "procedure" "pull"
3288 "push" "queue" "return" "say" "select" "signal"
3289 "scientific" "source" "then" "trace" "to" "until"
3290 "upper" "value" "var" "version" "when" "while"
3291 "with"
3292
3293 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
3294 "center" "center" "charin" "charout" "chars"
3295 "compare" "condition" "copies" "c2d" "c2x"
3296 "datatype" "date" "delstr" "delword" "d2c" "d2x"
3297 "errortext" "format" "fuzz" "insert" "lastpos"
3298 "left" "length" "lineout" "lines" "max" "min"
3299 "overlay" "pos" "queued" "random" "reverse" "right"
3300 "sign" "sourceline" "space" "stream" "strip"
3301 "substr" "subword" "symbol" "time" "translate"
3302 "trunc" "value" "verify" "word" "wordindex"
3303 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
3304 "x2d")))
f617db13
MW
3305
3306 (setq font-lock-keywords
3307 (list
f617db13 3308
6132bc01 3309 ;; Set up the keywords defined above.
f617db13
MW
3310 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
3311 '(0 font-lock-keyword-face))
3312
6132bc01 3313 ;; Fontify all symbols the same way.
f617db13
MW
3314 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
3315 "[A-Za-z0-9.!?_#@$]+\\)")
3316 '(0 font-lock-variable-name-face))
3317
6132bc01 3318 ;; And everything else is punctuation.
f617db13 3319 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 3320 '(0 mdw-punct-face))))))
f617db13 3321
b50c6712
MW
3322(progn
3323 (add-hook 'rexx-mode-hook 'mdw-misc-mode-config t)
3324 (add-hook 'rexx-mode-hook 'mdw-fontify-rexx t))
3325
6132bc01
MW
3326;;;--------------------------------------------------------------------------
3327;;; Standard ML programming style.
f617db13 3328
b50c6712
MW
3329(setq-default sml-nested-if-indent t
3330 sml-case-indent nil
3331 sml-indent-level 4
3332 sml-type-of-indent nil)
3333
f617db13
MW
3334(defun mdw-fontify-sml ()
3335
6132bc01 3336 ;; Make underscore an honorary letter.
f617db13
MW
3337 (modify-syntax-entry ?' "w")
3338
6132bc01 3339 ;; Set fill prefix.
f617db13
MW
3340 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
3341
6132bc01 3342 ;; Now define fontification things.
02109a0d 3343 (make-local-variable 'font-lock-keywords)
f617db13 3344 (let ((sml-keywords
8d6d55b9
MW
3345 (mdw-regexps "abstype" "and" "andalso" "as"
3346 "case"
3347 "datatype" "do"
3348 "else" "end" "eqtype" "exception"
3349 "fn" "fun" "functor"
3350 "handle"
3351 "if" "in" "include" "infix" "infixr"
3352 "let" "local"
3353 "nonfix"
3354 "of" "op" "open" "orelse"
3355 "raise" "rec"
3356 "sharing" "sig" "signature" "struct" "structure"
3357 "then" "type"
3358 "val"
3359 "where" "while" "with" "withtype")))
f617db13
MW
3360
3361 (setq font-lock-keywords
3362 (list
f617db13 3363
6132bc01 3364 ;; Set up the keywords defined above.
f617db13
MW
3365 (list (concat "\\<\\(" sml-keywords "\\)\\>")
3366 '(0 font-lock-keyword-face))
3367
6132bc01 3368 ;; At least numbers are simpler than C.
f617db13
MW
3369 (list (concat "\\<\\(\\~\\|\\)"
3370 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
852cd5fb
MW
3371 "[wW][0-9]+\\)\\|"
3372 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
3373 "\\([eE]\\(\\~\\|\\)"
3374 "[0-9]+\\|\\)\\)\\)")
f617db13
MW
3375 '(0 mdw-number-face))
3376
6132bc01 3377 ;; And anything else is punctuation.
f617db13 3378 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 3379 '(0 mdw-punct-face))))))
f617db13 3380
b50c6712
MW
3381(progn
3382 (add-hook 'sml-mode-hook 'mdw-misc-mode-config t)
3383 (add-hook 'sml-mode-hook 'mdw-fontify-sml t))
3384
6132bc01
MW
3385;;;--------------------------------------------------------------------------
3386;;; Haskell configuration.
f617db13 3387
b50c6712
MW
3388(setq-default haskell-indent-offset 2)
3389
f617db13
MW
3390(defun mdw-fontify-haskell ()
3391
6132bc01 3392 ;; Fiddle with syntax table to get comments right.
5952a020
MW
3393 (modify-syntax-entry ?' "_")
3394 (modify-syntax-entry ?- ". 12")
f617db13
MW
3395 (modify-syntax-entry ?\n ">")
3396
4d90cf3d
MW
3397 ;; Make punctuation be punctuation
3398 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
3399 (do ((i 0 (1+ i)))
3400 ((>= i (length punct)))
3401 (modify-syntax-entry (aref punct i) ".")))
3402
6132bc01 3403 ;; Set fill prefix.
f617db13
MW
3404 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
3405
6132bc01 3406 ;; Fiddle with fontification.
02109a0d 3407 (make-local-variable 'font-lock-keywords)
f617db13 3408 (let ((haskell-keywords
5952a020
MW
3409 (mdw-regexps "as"
3410 "case" "ccall" "class"
3411 "data" "default" "deriving" "do"
3412 "else" "exists"
3413 "forall" "foreign"
3414 "hiding"
3415 "if" "import" "in" "infix" "infixl" "infixr" "instance"
3416 "let"
3417 "mdo" "module"
3418 "newtype"
3419 "of"
3420 "proc"
3421 "qualified"
3422 "rec"
3423 "safe" "stdcall"
3424 "then" "type"
3425 "unsafe"
3426 "where"))
3427 (control-sequences
3428 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
3429 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
3430 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
3431 "SP" "STX" "SUB" "SYN" "US" "VT")))
f617db13
MW
3432
3433 (setq font-lock-keywords
3434 (list
5952a020
MW
3435 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
3436 "\\(-+}\\|-*\\'\\)"
3437 "\\|"
3438 "--.*$")
f617db13 3439 '(0 font-lock-comment-face))
5952a020 3440 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
f617db13 3441 '(0 font-lock-keyword-face))
5952a020
MW
3442 (list (concat "'\\("
3443 "[^\\]"
3444 "\\|"
3445 "\\\\"
3446 "\\(" "[abfnrtv\\\"']" "\\|"
3447 "^" "\\(" control-sequences "\\|"
3448 "[]A-Z@[\\^_]" "\\)" "\\|"
3449 "\\|"
3450 "[0-9]+" "\\|"
3451 "[oO][0-7]+" "\\|"
3452 "[xX][0-9A-Fa-f]+"
3453 "\\)"
3454 "\\)'")
3455 '(0 font-lock-string-face))
3456 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
3457 '(0 font-lock-variable-name-face))
3458 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
3459 "\\_<[0-9]+\\(\\.[0-9]*\\|\\)"
f617db13
MW
3460 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
3461 '(0 mdw-number-face))
3462 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 3463 '(0 mdw-punct-face))))))
f617db13 3464
b50c6712
MW
3465(progn
3466 (add-hook 'haskell-mode-hook 'mdw-misc-mode-config t)
3467 (add-hook 'haskell-mode-hook 'mdw-fontify-haskell t))
3468
6132bc01
MW
3469;;;--------------------------------------------------------------------------
3470;;; Erlang configuration.
2ded9493 3471
08b1b191 3472(setq-default erlang-electric-commands nil)
2ded9493
MW
3473
3474(defun mdw-fontify-erlang ()
3475
6132bc01 3476 ;; Set fill prefix.
2ded9493
MW
3477 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
3478
6132bc01 3479 ;; Fiddle with fontification.
2ded9493
MW
3480 (make-local-variable 'font-lock-keywords)
3481 (let ((erlang-keywords
3482 (mdw-regexps "after" "and" "andalso"
3483 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
3484 "case" "catch" "cond"
3485 "div" "end" "fun" "if" "let" "not"
3486 "of" "or" "orelse"
3487 "query" "receive" "rem" "try" "when" "xor")))
3488
3489 (setq font-lock-keywords
3490 (list
3491 (list "%.*$"
3492 '(0 font-lock-comment-face))
3493 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
3494 '(0 font-lock-keyword-face))
3495 (list (concat "^-\\sw+\\>")
3496 '(0 font-lock-keyword-face))
3497 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
3498 '(0 mdw-number-face))
3499 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 3500 '(0 mdw-punct-face))))))
2ded9493 3501
b50c6712
MW
3502(progn
3503 (add-hook 'erlang-mode-hook 'mdw-misc-mode-config t)
3504 (add-hook 'erlang-mode-hook 'mdw-fontify-erlang t))
3505
6132bc01
MW
3506;;;--------------------------------------------------------------------------
3507;;; Texinfo configuration.
f617db13
MW
3508
3509(defun mdw-fontify-texinfo ()
3510
6132bc01 3511 ;; Set fill prefix.
f617db13
MW
3512 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
3513
6132bc01 3514 ;; Real fontification things.
02109a0d 3515 (make-local-variable 'font-lock-keywords)
f617db13
MW
3516 (setq font-lock-keywords
3517 (list
f617db13 3518
6132bc01 3519 ;; Environment names are keywords.
f617db13
MW
3520 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
3521 '(2 font-lock-keyword-face))
3522
6132bc01 3523 ;; Unmark escaped magic characters.
f617db13
MW
3524 (list "\\(@\\)\\([@{}]\\)"
3525 '(1 font-lock-keyword-face)
3526 '(2 font-lock-variable-name-face))
3527
6132bc01 3528 ;; Make sure we get comments properly.
f617db13
MW
3529 (list "@c\\(\\|omment\\)\\( .*\\)?$"
3530 '(0 font-lock-comment-face))
3531
6132bc01 3532 ;; Command names are keywords.
f617db13
MW
3533 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3534 '(0 font-lock-keyword-face))
3535
6132bc01 3536 ;; Fontify TeX special characters as punctuation.
f617db13 3537 (list "[{}]+"
2e7c6a86 3538 '(0 mdw-punct-face)))))
f617db13 3539
b50c6712
MW
3540(dolist (hook '(texinfo-mode-hook TeXinfo-mode-hook))
3541 (add-hook hook 'mdw-misc-mode-config t)
3542 (add-hook hook 'mdw-fontify-texinfo t))
3543
6132bc01
MW
3544;;;--------------------------------------------------------------------------
3545;;; TeX and LaTeX configuration.
f617db13 3546
b50c6712
MW
3547(setq-default LaTeX-table-label "tbl:"
3548 TeX-auto-untabify nil
3549 LaTeX-syntactic-comments nil
3550 LaTeX-fill-break-at-separators '(\\\[))
3551
f617db13
MW
3552(defun mdw-fontify-tex ()
3553 (setq ispell-parser 'tex)
55f80fae 3554 (turn-on-reftex)
f617db13 3555
6132bc01 3556 ;; Don't make maths into a string.
f617db13
MW
3557 (modify-syntax-entry ?$ ".")
3558 (modify-syntax-entry ?$ "." font-lock-syntax-table)
3559 (local-set-key [?$] 'self-insert-command)
3560
df200ecd 3561 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
060c23ce 3562 (local-set-key "\C-\M-i" 'indent-relative)
df200ecd
MW
3563 (setq indent-tabs-mode nil)
3564
6132bc01 3565 ;; Set fill prefix.
f617db13
MW
3566 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
3567
6132bc01 3568 ;; Real fontification things.
02109a0d 3569 (make-local-variable 'font-lock-keywords)
f617db13
MW
3570 (setq font-lock-keywords
3571 (list
f617db13 3572
6132bc01 3573 ;; Environment names are keywords.
f617db13
MW
3574 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
3575 "{\\([^}\n]*\\)}")
3576 '(2 font-lock-keyword-face))
3577
6132bc01 3578 ;; Suspended environment names are keywords too.
f617db13
MW
3579 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
3580 "{\\([^}\n]*\\)}")
3581 '(3 font-lock-keyword-face))
3582
6132bc01 3583 ;; Command names are keywords.
f617db13
MW
3584 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3585 '(0 font-lock-keyword-face))
3586
6132bc01 3587 ;; Handle @/.../ for italics.
f617db13 3588 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
852cd5fb
MW
3589 ;; '(1 font-lock-keyword-face)
3590 ;; '(3 font-lock-keyword-face))
f617db13 3591
6132bc01 3592 ;; Handle @*...* for boldness.
f617db13 3593 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
852cd5fb
MW
3594 ;; '(1 font-lock-keyword-face)
3595 ;; '(3 font-lock-keyword-face))
f617db13 3596
6132bc01 3597 ;; Handle @`...' for literal syntax things.
f617db13 3598 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
852cd5fb
MW
3599 ;; '(1 font-lock-keyword-face)
3600 ;; '(3 font-lock-keyword-face))
f617db13 3601
6132bc01 3602 ;; Handle @<...> for nonterminals.
f617db13 3603 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
852cd5fb
MW
3604 ;; '(1 font-lock-keyword-face)
3605 ;; '(3 font-lock-keyword-face))
f617db13 3606
6132bc01 3607 ;; Handle other @-commands.
f617db13 3608 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
852cd5fb 3609 ;; '(0 font-lock-keyword-face))
f617db13 3610
6132bc01 3611 ;; Make sure we get comments properly.
f617db13
MW
3612 (list "%.*"
3613 '(0 font-lock-comment-face))
3614
6132bc01 3615 ;; Fontify TeX special characters as punctuation.
f617db13 3616 (list "[$^_{}#&]"
2e7c6a86 3617 '(0 mdw-punct-face)))))
f617db13 3618
d9bba20d
MW
3619(setq TeX-install-font-lock 'tex-font-setup)
3620
8638f2f3
MW
3621(eval-after-load 'font-latex
3622 '(defun font-latex-jit-lock-force-redisplay (buf start end)
3623 "Compatibility for Emacsen not offering `jit-lock-force-redisplay'."
3624 ;; The following block is an expansion of `jit-lock-force-redisplay'
3625 ;; and involved macros taken from CVS Emacs on 2007-04-28.
3626 (with-current-buffer buf
3627 (let ((modified (buffer-modified-p)))
3628 (unwind-protect
3629 (let ((buffer-undo-list t)
3630 (inhibit-read-only t)
3631 (inhibit-point-motion-hooks t)
3632 (inhibit-modification-hooks t)
3633 deactivate-mark
3634 buffer-file-name
3635 buffer-file-truename)
3636 (put-text-property start end 'fontified t))
3637 (unless modified
3638 (restore-buffer-modified-p nil)))))))
3639
b50c6712
MW
3640(setq TeX-output-view-style
3641 '(("^dvi$"
3642 ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$")
3643 "%(o?)dvips -t landscape %d -o && xdg-open %f")
3644 ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$"
3645 "%(o?)dvips %d -o && xdg-open %f")
3646 ("^dvi$"
3647 ("^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "^landscape$")
3648 "%(o?)xdvi %dS -paper a4r -s 0 %d")
3649 ("^dvi$" "^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$"
3650 "%(o?)xdvi %dS -paper a4 %d")
3651 ("^dvi$"
3652 ("^a5\\(?:comb\\|paper\\)$" "^landscape$")
3653 "%(o?)xdvi %dS -paper a5r -s 0 %d")
3654 ("^dvi$" "^a5\\(?:comb\\|paper\\)$" "%(o?)xdvi %dS -paper a5 %d")
3655 ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
3656 ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d")
3657 ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
3658 ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
3659 ("^dvi$" "." "%(o?)xdvi %dS %d")
3660 ("^pdf$" "." "xdg-open %o")
3661 ("^html?$" "." "sensible-browser %o")))
3662
3663(setq TeX-view-program-list
3664 '(("mupdf" ("mupdf %o" (mode-io-correlate " %(outpage)")))))
3665
3666(setq TeX-view-program-selection
3667 '(((output-dvi style-pstricks) "dvips and gv")
3668 (output-dvi "xdvi")
3669 (output-pdf "mupdf")
3670 (output-html "sensible-browser")))
3671
3672(setq TeX-open-quote "\""
3673 TeX-close-quote "\"")
3674
3675(setq reftex-use-external-file-finders t
3676 reftex-auto-recenter-toc t)
3677
3678(setq reftex-label-alist
3679 '(("theorem" ?T "th:" "~\\ref{%s}" t ("theorems?" "th\\.") -2)
3680 ("axiom" ?A "ax:" "~\\ref{%s}" t ("axioms?" "ax\\.") -2)
3681 ("definition" ?D "def:" "~\\ref{%s}" t ("definitions?" "def\\.") -2)
3682 ("proposition" ?P "prop:" "~\\ref{%s}" t
3683 ("propositions?" "prop\\.") -2)
3684 ("lemma" ?L "lem:" "~\\ref{%s}" t ("lemmas?" "lem\\.") -2)
3685 ("example" ?X "eg:" "~\\ref{%s}" t ("examples?") -2)
3686 ("exercise" ?E "ex:" "~\\ref{%s}" t ("exercises?" "ex\\.") -2)
3687 ("enumerate" ?i "i:" "~\\ref{%s}" item ("items?"))))
3688(setq reftex-section-prefixes
3689 '((0 . "part:")
3690 (1 . "ch:")
3691 (t . "sec:")))
3692
3693(setq bibtex-field-delimiters 'double-quotes
3694 bibtex-align-at-equal-sign t
3695 bibtex-entry-format '(realign opts-or-alts required-fields
3696 numerical-fields last-comma delimiters
3697 unify-case sort-fields braces)
3698 bibtex-sort-ignore-string-entries nil
3699 bibtex-maintain-sorted-entries 'entry-class
3700 bibtex-include-OPTkey t
3701 bibtex-autokey-names-stretch 1
3702 bibtex-autokey-expand-strings t
3703 bibtex-autokey-name-separator "-"
3704 bibtex-autokey-year-length 4
3705 bibtex-autokey-titleword-separator "-"
3706 bibtex-autokey-name-year-separator "-"
3707 bibtex-autokey-year-title-separator ":")
3708
3709(progn
3710 (dolist (hook '(tex-mode-hook latex-mode-hook
3711 TeX-mode-hook LaTeX-mode-hook))
3712 (add-hook hook 'mdw-misc-mode-config t)
3713 (add-hook hook 'mdw-fontify-tex t))
3714 (add-hook 'bibtex-mode-hook (lambda () (setq fill-column 76))))
ad14c2fe 3715
6132bc01 3716;;;--------------------------------------------------------------------------
445ddb61
MW
3717;;; HTML, CSS, and other web foolishness.
3718
08b1b191 3719(setq-default css-indent-offset 2)
445ddb61
MW
3720
3721;;;--------------------------------------------------------------------------
6132bc01 3722;;; SGML hacking.
f25cf300 3723
b50c6712
MW
3724(setq-default psgml-html-build-new-buffer nil)
3725
f25cf300
MW
3726(defun mdw-sgml-mode ()
3727 (interactive)
3728 (sgml-mode)
3729 (mdw-standard-fill-prefix "")
8a425bd7 3730 (make-local-variable 'sgml-delimiters)
f25cf300
MW
3731 (setq sgml-delimiters
3732 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
3733 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
3734 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
3735 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
3736 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
3737 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
3738 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
3739 "NULL" ""))
3740 (setq major-mode 'mdw-sgml-mode)
3741 (setq mode-name "[mdw] SGML")
3742 (run-hooks 'mdw-sgml-mode-hook))
6cb52f8b
MW
3743
3744;;;--------------------------------------------------------------------------
3745;;; Configuration files.
3746
3747(defvar mdw-conf-quote-normal nil
3748 "*Control syntax category of quote characters `\"' and `''.
3749If this is `t', consider quote characters to be normal
3750punctuation, as for `conf-quote-normal'. If this is `nil' then
3751leave quote characters as quotes. If this is a list, then
3752consider the quote characters in the list to be normal
3753punctuation. If this is a single quote character, then consider
3754that character only to be normal punctuation.")
3755(defun mdw-conf-quote-normal-acceptable-value-p (value)
3756 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
3757 (or (booleanp value)
3758 (every (lambda (v) (memq v '(?\" ?')))
3759 (if (listp value) value (list value)))))
18bb0f77
MW
3760(put 'mdw-conf-quote-normal 'safe-local-variable
3761 'mdw-conf-quote-normal-acceptable-value-p)
6cb52f8b
MW
3762
3763(defun mdw-fix-up-quote ()
3764 "Apply the setting of `mdw-conf-quote-normal'."
3765 (let ((flag mdw-conf-quote-normal))
3766 (cond ((eq flag t)
3767 (conf-quote-normal t))
3768 ((not flag)
3769 nil)
3770 (t
3771 (let ((table (copy-syntax-table (syntax-table))))
6c4bd06b
MW
3772 (dolist (ch (if (listp flag) flag (list flag)))
3773 (modify-syntax-entry ch "." table))
6cb52f8b
MW
3774 (set-syntax-table table)
3775 (and font-lock-mode (font-lock-fontify-buffer)))))))
b50c6712
MW
3776
3777(progn
3778 (add-hook 'conf-mode-hook 'mdw-misc-mode-config t)
3779 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t))
f25cf300 3780
6132bc01
MW
3781;;;--------------------------------------------------------------------------
3782;;; Shell scripts.
f617db13
MW
3783
3784(defun mdw-setup-sh-script-mode ()
3785
6132bc01 3786 ;; Fetch the shell interpreter's name.
f617db13
MW
3787 (let ((shell-name sh-shell-file))
3788
6132bc01 3789 ;; Try reading the hash-bang line.
f617db13
MW
3790 (save-excursion
3791 (goto-char (point-min))
3792 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
3793 (setq shell-name (match-string 1))))
3794
6132bc01 3795 ;; Now try to set the shell.
f617db13
MW
3796 ;;
3797 ;; Don't let `sh-set-shell' bugger up my script.
f617db13
MW
3798 (let ((executable-set-magic #'(lambda (s &rest r) s)))
3799 (sh-set-shell shell-name)))
3800
10c51541
MW
3801 ;; Don't insert here-document scaffolding automatically.
3802 (local-set-key "<" 'self-insert-command)
3803
6132bc01 3804 ;; Now enable my keys and the fontification.
f617db13
MW
3805 (mdw-misc-mode-config)
3806
6132bc01 3807 ;; Set the indentation level correctly.
f617db13
MW
3808 (setq sh-indentation 2)
3809 (setq sh-basic-offset 2))
3810
070c1dca
MW
3811(setq sh-shell-file "/bin/sh")
3812
6d6e095a
MW
3813;; Awful hacking to override the shell detection for particular scripts.
3814(defmacro define-custom-shell-mode (name shell)
3815 `(defun ,name ()
3816 (interactive)
3817 (set (make-local-variable 'sh-shell-file) ,shell)
3818 (sh-mode)))
3819(define-custom-shell-mode bash-mode "/bin/bash")
3820(define-custom-shell-mode rc-mode "/usr/bin/rc")
3821(put 'sh-shell-file 'permanent-local t)
3822
3823;; Hack the rc syntax table. Backquotes aren't paired in rc.
3824(eval-after-load "sh-script"
3825 '(or (assq 'rc sh-mode-syntax-table-input)
3826 (let ((frag '(nil
3827 ?# "<"
3828 ?\n ">#"
3829 ?\" "\"\""
3830 ?\' "\"\'"
3831 ?$ "'"
3832 ?\` "."
3833 ?! "_"
3834 ?% "_"
3835 ?. "_"
3836 ?^ "_"
3837 ?~ "_"
3838 ?, "_"
3839 ?= "."
3840 ?< "."
3841 ?> "."))
3842 (assoc (assq 'rc sh-mode-syntax-table-input)))
3843 (if assoc
3844 (rplacd assoc frag)
3845 (setq sh-mode-syntax-table-input
3846 (cons (cons 'rc frag)
3847 sh-mode-syntax-table-input))))))
3848
b50c6712
MW
3849(progn
3850 (add-hook 'sh-mode-hook 'mdw-misc-mode-config t)
3851 (add-hook 'sh-mode-hook 'mdw-setup-sh-script-mode t))
3852
6132bc01 3853;;;--------------------------------------------------------------------------
092f0a38
MW
3854;;; Emacs shell mode.
3855
3856(defun mdw-eshell-prompt ()
3857 (let ((left "[") (right "]"))
3858 (when (= (user-uid) 0)
3859 (setq left "«" right "»"))
3860 (concat left
3861 (save-match-data
3862 (replace-regexp-in-string "\\..*$" "" (system-name)))
3863 " "
2d8b2924
MW
3864 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
3865 (home (expand-file-name "~")) (nhome (length home)))
3866 (if (and (>= npwd nhome)
3867 (or (= nhome npwd)
5801e199
MW
3868 (= (elt pwd nhome) ?/))
3869 (string= (substring pwd 0 nhome) home))
2d8b2924
MW
3870 (concat "~" (substring pwd (length home)))
3871 pwd))
092f0a38 3872 right)))
08b1b191
MW
3873(setq-default eshell-prompt-function 'mdw-eshell-prompt)
3874(setq-default eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
092f0a38 3875
2d8b2924
MW
3876(defun eshell/e (file) (find-file file) nil)
3877(defun eshell/ee (file) (find-file-other-window file) nil)
3878(defun eshell/w3m (url) (w3m-goto-url url) nil)
415a23dd 3879
092f0a38
MW
3880(mdw-define-face eshell-prompt (t :weight bold))
3881(mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
3882(mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
3883(mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
3884(mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
3885(mdw-define-face eshell-ls-executable (t :weight bold))
3886(mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
3887(mdw-define-face eshell-ls-readonly (t nil))
3888(mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
3889
b1a598dc 3890(defun mdw-eshell-hack () (setenv "LD_PRELOAD" nil))
8845865d
MW
3891(add-hook 'eshell-mode-hook 'mdw-eshell-hack)
3892
092f0a38 3893;;;--------------------------------------------------------------------------
6132bc01 3894;;; Messages-file mode.
f617db13 3895
4bb22eea 3896(defun messages-mode-guts ()
f617db13
MW
3897 (setq messages-mode-syntax-table (make-syntax-table))
3898 (set-syntax-table messages-mode-syntax-table)
f617db13
MW
3899 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
3900 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
3901 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
3902 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
3903 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
3904 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
3905 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
3906 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
3907 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
3908 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
3909 (make-local-variable 'comment-start)
3910 (make-local-variable 'comment-end)
3911 (make-local-variable 'indent-line-function)
3912 (setq indent-line-function 'indent-relative)
3913 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3914 (make-local-variable 'font-lock-defaults)
4bb22eea 3915 (make-local-variable 'messages-mode-keywords)
f617db13 3916 (let ((keywords
8d6d55b9
MW
3917 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
3918 "export" "enum" "fixed-octetstring" "flags"
3919 "harmless" "map" "nested" "optional"
3920 "optional-tagged" "package" "primitive"
3921 "primitive-nullfree" "relaxed[ \t]+enum"
3922 "set" "table" "tagged-optional" "union"
3923 "variadic" "vector" "version" "version-tag")))
4bb22eea 3924 (setq messages-mode-keywords
f617db13
MW
3925 (list
3926 (list (concat "\\<\\(" keywords "\\)\\>:")
3927 '(0 font-lock-keyword-face))
3928 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
3929 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
3930 (0 font-lock-variable-name-face))
3931 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
3932 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3933 (0 mdw-punct-face)))))
3934 (setq font-lock-defaults
4bb22eea 3935 '(messages-mode-keywords nil nil nil nil))
f617db13
MW
3936 (run-hooks 'messages-file-hook))
3937
3938(defun messages-mode ()
3939 (interactive)
3940 (fundamental-mode)
3941 (setq major-mode 'messages-mode)
3942 (setq mode-name "Messages")
4bb22eea 3943 (messages-mode-guts)
f617db13
MW
3944 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
3945 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
3946 (setq comment-start "# ")
3947 (setq comment-end "")
f617db13
MW
3948 (run-hooks 'messages-mode-hook))
3949
3950(defun cpp-messages-mode ()
3951 (interactive)
3952 (fundamental-mode)
3953 (setq major-mode 'cpp-messages-mode)
3954 (setq mode-name "CPP Messages")
4bb22eea 3955 (messages-mode-guts)
f617db13
MW
3956 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
3957 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
3958 (setq comment-start "/* ")
3959 (setq comment-end " */")
3960 (let ((preprocessor-keywords
8d6d55b9
MW
3961 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
3962 "ident" "if" "ifdef" "ifndef" "import" "include"
3963 "line" "pragma" "unassert" "undef" "warning")))
4bb22eea 3964 (setq messages-mode-keywords
f617db13
MW
3965 (append (list (list (concat "^[ \t]*\\#[ \t]*"
3966 "\\(include\\|import\\)"
3967 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
3968 '(2 font-lock-string-face))
3969 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
3970 preprocessor-keywords
852cd5fb 3971 "\\)\\>\\|[0-9]+\\|$\\)\\)")
f617db13 3972 '(1 font-lock-keyword-face)))
4bb22eea 3973 messages-mode-keywords)))
297d60aa 3974 (run-hooks 'cpp-messages-mode-hook))
f617db13 3975
b50c6712
MW
3976(progn
3977 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
3978 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
3979 ;; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
3980 )
f617db13 3981
6132bc01
MW
3982;;;--------------------------------------------------------------------------
3983;;; Messages-file mode.
f617db13
MW
3984
3985(defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
3986 "Face to use for subsittution directives.")
3987(make-face 'mallow-driver-substitution-face)
3988(defvar mallow-driver-text-face 'mallow-driver-text-face
3989 "Face to use for body text.")
3990(make-face 'mallow-driver-text-face)
3991
3992(defun mallow-driver-mode ()
3993 (interactive)
3994 (fundamental-mode)
3995 (setq major-mode 'mallow-driver-mode)
3996 (setq mode-name "Mallow driver")
3997 (setq mallow-driver-mode-syntax-table (make-syntax-table))
3998 (set-syntax-table mallow-driver-mode-syntax-table)
3999 (make-local-variable 'comment-start)
4000 (make-local-variable 'comment-end)
4001 (make-local-variable 'indent-line-function)
4002 (setq indent-line-function 'indent-relative)
4003 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4004 (make-local-variable 'font-lock-defaults)
4005 (make-local-variable 'mallow-driver-mode-keywords)
4006 (let ((keywords
8d6d55b9
MW
4007 (mdw-regexps "each" "divert" "file" "if"
4008 "perl" "set" "string" "type" "write")))
f617db13
MW
4009 (setq mallow-driver-mode-keywords
4010 (list
4011 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
4012 '(0 font-lock-keyword-face))
4013 (list "^%\\s *\\(#.*\\|\\)$"
4014 '(0 font-lock-comment-face))
4015 (list "^%"
4016 '(0 font-lock-keyword-face))
4017 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
4018 (list "\\${[^}]*}"
4019 '(0 mallow-driver-substitution-face t)))))
4020 (setq font-lock-defaults
4021 '(mallow-driver-mode-keywords nil nil nil nil))
4022 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
4023 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
4024 (setq comment-start "%# ")
4025 (setq comment-end "")
f617db13
MW
4026 (run-hooks 'mallow-driver-mode-hook))
4027
b50c6712
MW
4028(progn
4029 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t))
f617db13 4030
6132bc01
MW
4031;;;--------------------------------------------------------------------------
4032;;; NFast debugs.
f617db13
MW
4033
4034(defun nfast-debug-mode ()
4035 (interactive)
4036 (fundamental-mode)
4037 (setq major-mode 'nfast-debug-mode)
4038 (setq mode-name "NFast debug")
4039 (setq messages-mode-syntax-table (make-syntax-table))
4040 (set-syntax-table messages-mode-syntax-table)
4041 (make-local-variable 'font-lock-defaults)
4042 (make-local-variable 'nfast-debug-mode-keywords)
4043 (setq truncate-lines t)
4044 (setq nfast-debug-mode-keywords
4045 (list
4046 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
4047 (0 font-lock-keyword-face))
4048 (list (concat "^[ \t]+\\(\\("
4049 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4050 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4051 "[ \t]+\\)*"
4052 "[0-9a-fA-F]+\\)[ \t]*$")
4053 '(0 mdw-number-face))
4054 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
4055 (1 font-lock-keyword-face))
4056 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
4057 (1 font-lock-warning-face))
4058 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
4059 (1 nil))
4060 (list (concat "^[ \t]+\\.cmd=[ \t]+"
4061 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
4062 '(1 font-lock-keyword-face))
4063 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
4064 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
4065 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
4066 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
4067 (setq font-lock-defaults
4068 '(nfast-debug-mode-keywords nil nil nil nil))
f617db13
MW
4069 (run-hooks 'nfast-debug-mode-hook))
4070
6132bc01 4071;;;--------------------------------------------------------------------------
658bc848 4072;;; Lispy languages.
f617db13 4073
873d87df
MW
4074;; Unpleasant bodge.
4075(unless (boundp 'slime-repl-mode-map)
4076 (setq slime-repl-mode-map (make-sparse-keymap)))
4077
f617db13
MW
4078(defun mdw-indent-newline-and-indent ()
4079 (interactive)
4080 (indent-for-tab-command)
4081 (newline-and-indent))
4082
4083(eval-after-load "cl-indent"
4084 '(progn
4085 (mapc #'(lambda (pair)
4086 (put (car pair)
4087 'common-lisp-indent-function
4088 (cdr pair)))
4089 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
4090 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
4091
4092(defun mdw-common-lisp-indent ()
8a425bd7 4093 (make-local-variable 'lisp-indent-function)
f617db13
MW
4094 (setq lisp-indent-function 'common-lisp-indent-function))
4095
08b1b191
MW
4096(setq-default lisp-simple-loop-indentation 2
4097 lisp-loop-keyword-indentation 6
4098 lisp-loop-forms-indentation 6)
95575d1f 4099
36cd5c10
MW
4100(defmacro mdw-advise-hyperspec-lookup (func args)
4101 `(defadvice ,func (around mdw-browse-w3m ,args activate compile)
4102 (if (fboundp 'w3m)
4103 (let ((browse-url-browser-function #'mdw-w3m-browse-url))
4104 ad-do-it)
4105 ad-do-it)))
0c3e50d5
MW
4106(mdw-advise-hyperspec-lookup common-lisp-hyperspec (symbol))
4107(mdw-advise-hyperspec-lookup common-lisp-hyperspec-format (char))
4108(mdw-advise-hyperspec-lookup common-lisp-hyperspec-lookup-reader-macro (char))
36cd5c10 4109
f617db13
MW
4110(defun mdw-fontify-lispy ()
4111
6132bc01 4112 ;; Set fill prefix.
f617db13
MW
4113 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
4114
6132bc01 4115 ;; Not much fontification needed.
02109a0d 4116 (make-local-variable 'font-lock-keywords)
f617db13 4117 (setq font-lock-keywords
2287504f
MW
4118 (list (list (concat "\\("
4119 "\\_<[-+]?"
4120 "\\(" "[0-9]+/[0-9]+"
4121 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
4122 "\\.[0-9]+" "\\)"
4123 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
4124 "\\)"
4125 "\\|"
4126 "#"
4127 "\\(" "x" "[-+]?"
4128 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
4129 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
4130 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
4131 "\\|" "[0-9]+" "r" "[-+]?"
4132 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
4133 "\\)"
4134 "\\)\\_>")
4135 '(0 mdw-number-face))
4136 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2e7c6a86 4137 '(0 mdw-punct-face)))))
f617db13 4138
b50c6712
MW
4139;; SLIME setup.
4140
4141(trap
4142 (if (not mdw-fast-startup)
4143 (progn
4144 (require 'slime-autoloads)
4145 (slime-setup '(slime-autodoc slime-c-p-c)))))
4146
4147(let ((stuff '((cmucl ("cmucl"))
4148 (sbcl ("sbcl") :coding-system utf-8-unix)
4149 (clisp ("clisp") :coding-system utf-8-unix))))
4150 (or (boundp 'slime-lisp-implementations)
4151 (setq slime-lisp-implementations nil))
4152 (while stuff
4153 (let* ((head (car stuff))
4154 (found (assq (car head) slime-lisp-implementations)))
4155 (setq stuff (cdr stuff))
4156 (if found
4157 (rplacd found (cdr head))
4158 (setq slime-lisp-implementations
4159 (cons head slime-lisp-implementations))))))
4160(setq slime-default-lisp 'sbcl)
4161
4162;; Hooks.
4163
4164(progn
4165 (dolist (hook '(emacs-lisp-mode-hook
4166 scheme-mode-hook
4167 lisp-mode-hook
4168 inferior-lisp-mode-hook
4169 lisp-interaction-mode-hook
4170 ielm-mode-hook
4171 slime-repl-mode-hook))
4172 (add-hook hook 'mdw-misc-mode-config t)
4173 (add-hook hook 'mdw-fontify-lispy t))
4174 (add-hook 'lisp-mode-hook 'mdw-common-lisp-indent t)
4175 (add-hook 'inferior-lisp-mode-hook
4176 #'(lambda () (local-set-key "\C-m" 'comint-send-and-indent)) t))
4177
658bc848
MW
4178;;;--------------------------------------------------------------------------
4179;;; Other languages.
4180
4181;; Smalltalk.
4182
4183(defun mdw-setup-smalltalk ()
4184 (and mdw-auto-indent
4185 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
4186 (make-local-variable 'mdw-auto-indent)
4187 (setq mdw-auto-indent nil)
4188 (local-set-key "\C-i" 'smalltalk-reindent))
4189
4190(defun mdw-fontify-smalltalk ()
4191 (make-local-variable 'font-lock-keywords)
4192 (setq font-lock-keywords
4193 (list
4194 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
4195 '(0 font-lock-keyword-face))
4196 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
4197 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
4198 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
4199 '(0 mdw-number-face))
4200 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4201 '(0 mdw-punct-face)))))
4202
b50c6712
MW
4203(progn
4204 (add-hook 'smalltalk-mode 'mdw-misc-mode-config t)
4205 (add-hook 'smalltalk-mode 'mdw-fontify-smalltalk t))
4206
df77a575
MW
4207;; m4.
4208
ec007bea 4209(defun mdw-setup-m4 ()
ed5d93a4
MW
4210
4211 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
4212 ;; annoying: fix it.
4213 (modify-syntax-entry ?{ "(")
4214 (modify-syntax-entry ?} ")")
4215
4216 ;; Fill prefix.
ec007bea
MW
4217 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
4218
b50c6712
MW
4219(dolist (hook '(m4-mode-hook autoconf-mode-hook autotest-mode-hook))
4220 (add-hook hook #'mdw-misc-mode-config t)
4221 (add-hook hook #'mdw-setup-m4 t))
4222
4223;; Make.
4224
4225(progn
4226 (add-hook 'makefile-mode-hook 'mdw-misc-mode-config t))
4227
6132bc01
MW
4228;;;--------------------------------------------------------------------------
4229;;; Text mode.
f617db13
MW
4230
4231(defun mdw-text-mode ()
4232 (setq fill-column 72)
4233 (flyspell-mode t)
4234 (mdw-standard-fill-prefix
c7a8da49 4235 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
f617db13
MW
4236 (auto-fill-mode 1))
4237
060c23ce
MW
4238(eval-after-load "flyspell"
4239 '(define-key flyspell-mode-map "\C-\M-i" nil))
4240
b50c6712
MW
4241(progn
4242 (add-hook 'text-mode-hook 'mdw-text-mode t))
4243
6132bc01 4244;;;--------------------------------------------------------------------------
faf2cef7 4245;;; Outline and hide/show modes.
5de5db48
MW
4246
4247(defun mdw-outline-collapse-all ()
4248 "Completely collapse everything in the entire buffer."
4249 (interactive)
4250 (save-excursion
4251 (goto-char (point-min))
4252 (while (< (point) (point-max))
4253 (hide-subtree)
4254 (forward-line))))
4255
faf2cef7
MW
4256(setq hs-hide-comments-when-hiding-all nil)
4257
b200af26 4258(defadvice hs-hide-all (after hide-first-comment activate)
941c29ba 4259 (save-excursion (hs-hide-initial-comment-block)))
b200af26 4260
6132bc01
MW
4261;;;--------------------------------------------------------------------------
4262;;; Shell mode.
f617db13
MW
4263
4264(defun mdw-sh-mode-setup ()
4265 (local-set-key [?\C-a] 'comint-bol)
4266 (add-hook 'comint-output-filter-functions
4267 'comint-watch-for-password-prompt))
4268
4269(defun mdw-term-mode-setup ()
3d9147ea 4270 (setq term-prompt-regexp shell-prompt-pattern)
f617db13
MW
4271 (make-local-variable 'mouse-yank-at-point)
4272 (make-local-variable 'transient-mark-mode)
4273 (setq mouse-yank-at-point t)
f617db13
MW
4274 (auto-fill-mode -1)
4275 (setq tab-width 8))
4276
3d9147ea
MW
4277(defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
4278(defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
4279(defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
4280(defun term-send-meta-meta-something ()
4281 (interactive)
4282 (term-send-raw-string "\e\e")
4283 (term-send-raw))
4284(eval-after-load 'term
4285 '(progn
4286 (define-key term-raw-map [?\e ?\e] nil)
4287 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
4288 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
4289 (define-key term-raw-map [M-right] 'term-send-meta-right)
4290 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
4291 (define-key term-raw-map [M-left] 'term-send-meta-left)
4292 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
4293
c4434c20
MW
4294(defadvice term-exec (before program-args-list compile activate)
4295 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
4296This allows you to pass a list of arguments through `ansi-term'."
4297 (let ((program (ad-get-arg 2)))
4298 (if (listp program)
4299 (progn
4300 (ad-set-arg 2 (car program))
4301 (ad-set-arg 4 (cdr program))))))
4302
8845865d
MW
4303(defadvice term-exec-1 (around hack-environment compile activate)
4304 "Hack the environment inherited by inferiors in the terminal."
f8592fee 4305 (let ((process-environment (copy-tree process-environment)))
8845865d
MW
4306 (setenv "LD_PRELOAD" nil)
4307 ad-do-it))
4308
4309(defadvice shell (around hack-environment compile activate)
4310 "Hack the environment inherited by inferiors in the shell."
f8592fee 4311 (let ((process-environment (copy-tree process-environment)))
8845865d
MW
4312 (setenv "LD_PRELOAD" nil)
4313 ad-do-it))
4314
c4434c20
MW
4315(defun ssh (host)
4316 "Open a terminal containing an ssh session to the HOST."
4317 (interactive "sHost: ")
4318 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
4319
5aa1b95f 4320(defvar git-grep-command
20b6cd68 4321 "env GIT_PAGER=cat git grep --no-color -nH -e "
5aa1b95f
MW
4322 "*The default command for \\[git-grep].")
4323
4324(defvar git-grep-history nil)
4325
4326(defun git-grep (command-args)
4327 "Run `git grep' with user-specified args and collect output in a buffer."
4328 (interactive
4329 (list (read-shell-command "Run git grep (like this): "
4330 git-grep-command 'git-grep-history)))
6a0a9a51
MW
4331 (let ((grep-use-null-device nil))
4332 (grep command-args)))
5aa1b95f 4333
c63bce81
MW
4334;;;--------------------------------------------------------------------------
4335;;; Magit configuration.
4336
c14a5ec3
MW
4337(setq magit-diff-refine-hunk 'all
4338 magit-view-git-manual-method 'man
83d2acdd 4339 magit-log-margin '(nil age magit-log-margin-width t 18)
c14a5ec3
MW
4340 magit-wip-after-save-local-mode-lighter ""
4341 magit-wip-after-apply-mode-lighter ""
4342 magit-wip-before-change-mode-lighter "")
4343(eval-after-load "magit"
4344 '(progn (global-magit-file-mode 1)
4345 (magit-wip-after-save-mode 1)
4346 (magit-wip-after-apply-mode 1)
4347 (magit-wip-before-change-mode 1)
60c22e1b 4348 (add-to-list 'magit-no-confirm 'safe-with-wip)
2a67803a 4349 (add-to-list 'magit-no-confirm 'trash)
87746eb7
MW
4350 (push '(:eval (if (or magit-wip-after-save-local-mode
4351 magit-wip-after-apply-mode
4352 magit-wip-before-change-mode)
4353 (format " wip:%s%s%s"
4354 (if magit-wip-after-apply-mode "A" "")
4355 (if magit-wip-before-change-mode "C" "")
4356 (if magit-wip-after-save-local-mode "S" ""))))
4357 minor-mode-alist)
60c22e1b
MW
4358 (dolist (popup '(magit-diff-popup
4359 magit-diff-refresh-popup
4360 magit-diff-mode-refresh-popup
4361 magit-revision-mode-refresh-popup))
4362 (magit-define-popup-switch popup ?R "Reverse diff" "-R"))))
c14a5ec3 4363
28509f06
MW
4364(defadvice magit-wip-commit-buffer-file
4365 (around mdw-just-this-buffer activate compile)
4366 (let ((magit-save-repository-buffers nil)) ad-do-it))
4367
2a67803a
MW
4368(defadvice magit-discard
4369 (around mdw-delete-if-prefix-argument activate compile)
4370 (let ((magit-delete-by-moving-to-trash
4371 (and (null current-prefix-arg)
4372 magit-delete-by-moving-to-trash)))
4373 ad-do-it))
4374
ff6a7bee
MW
4375(setq magit-repolist-columns
4376 '(("Name" 16 magit-repolist-column-ident nil)
4377 ("Version" 18 magit-repolist-column-version nil)
4378 ("St" 2 magit-repolist-column-dirty nil)
4379 ("L<U" 3 mdw-repolist-column-unpulled-from-upstream nil)
4380 ("L>U" 3 mdw-repolist-column-unpushed-to-upstream nil)
4381 ("Path" 32 magit-repolist-column-path nil)))
4382
4383(setq magit-repository-directories '(("~/etc/profile" . 0)
4384 ("~/src/" . 1)))
4385
4386(defadvice magit-list-repos (around mdw-dirname () activate compile)
4387 "Make sure the returned names are directory names.
4388Otherwise child processes get started in the wrong directory and
4389there is sadness."
4390 (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it)))
4391
4392(defun mdw-repolist-column-unpulled-from-upstream (_id)
4393 "Insert number of upstream commits not in the current branch."
4394 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
4395 (and upstream
4396 (let ((n (cadr (magit-rev-diff-count "HEAD" upstream))))
4397 (propertize (number-to-string n) 'face
4398 (if (> n 0) 'bold 'shadow))))))
4399
4400(defun mdw-repolist-column-unpushed-to-upstream (_id)
4401 "Insert number of commits in the current branch but not its upstream."
4402 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
4403 (and upstream
4404 (let ((n (car (magit-rev-diff-count "HEAD" upstream))))
4405 (propertize (number-to-string n) 'face
4406 (if (> n 0) 'bold 'shadow))))))
4407
5d824e2f
MW
4408(defun mdw-try-smerge ()
4409 (save-excursion
4410 (goto-char (point-min))
4411 (when (re-search-forward "^<<<<<<< " nil t)
4412 (smerge-mode 1))))
4413(add-hook 'find-file-hook 'mdw-try-smerge t)
4414
e07e3320 4415;;;--------------------------------------------------------------------------
e48c2e5b
MW
4416;;; GUD, and especially GDB.
4417
4418;; Inhibit window dedication. I mean, seriously, wtf?
4419(defadvice gdb-display-buffer (after mdw-undedicated (buf) compile activate)
4420 "Don't make windows dedicated. Seriously."
4421 (set-window-dedicated-p ad-return-value nil))
4422(defadvice gdb-set-window-buffer
4423 (after mdw-undedicated (name &optional ignore-dedicated window)
4424 compile activate)
4425 "Don't make windows dedicated. Seriously."
4426 (set-window-dedicated-p (or window (selected-window)) nil))
4427
4428;;;--------------------------------------------------------------------------
0f81a131
MW
4429;;; MPC configuration.
4430
50a77b30
MW
4431(eval-when-compile (trap (require 'mpc)))
4432
0f81a131
MW
4433(setq mpc-browser-tags '(Artist|Composer|Performer Album|Playlist))
4434
4435(defun mdw-mpc-now-playing ()
4436 (interactive)
4437 (require 'mpc)
4438 (save-excursion
4439 (set-buffer (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))))
4440 (mpc--status-callback))
4441 (let ((state (cdr (assq 'state mpc-status))))
4442 (cond ((member state '("stop"))
4443 (message "mpd stopped."))
4444 ((member state '("play" "pause"))
4445 (let* ((artist (cdr (assq 'Artist mpc-status)))
4446 (album (cdr (assq 'Album mpc-status)))
4447 (title (cdr (assq 'Title mpc-status)))
4448 (file (cdr (assq 'file mpc-status)))
4449 (duration-string (cdr (assq 'Time mpc-status)))
4450 (time-string (cdr (assq 'time mpc-status)))
4451 (time (and time-string
355d1336 4452 (string-to-number
0f81a131
MW
4453 (if (string-match ":" time-string)
4454 (substring time-string
4455 0 (match-beginning 0))
4456 (time-string)))))
4457 (duration (and duration-string
355d1336 4458 (string-to-number duration-string)))
0f81a131
MW
4459 (pos (and time duration
4460 (format " [%d:%02d/%d:%02d]"
4461 (/ time 60) (mod time 60)
4462 (/ duration 60) (mod duration 60))))
4463 (fmt (cond ((and artist title)
4464 (format "`%s' by %s%s" title artist
4465 (if album (format ", from `%s'" album)
4466 "")))
4467 (file
4468 (format "`%s' (no tags)" file))
4469 (t
4470 "(no idea what's playing!)"))))
4471 (if (string= state "play")
4472 (message "mpd playing %s%s" fmt (or pos ""))
4473 (message "mpd paused in %s%s" fmt (or pos "")))))
4474 (t
4475 (message "mpd in unknown state `%s'" state)))))
4476
4aba12fa
MW
4477(defmacro mdw-define-mpc-wrapper (func bvl interactive &rest body)
4478 `(defun ,func ,bvl
4479 (interactive ,@interactive)
4480 (require 'mpc)
4481 ,@body
4482 (mdw-mpc-now-playing)))
4483
4484(mdw-define-mpc-wrapper mdw-mpc-play-or-pause () nil
4485 (if (member (cdr (assq 'state (mpc-cmd-status))) '("play"))
4486 (mpc-pause)
4487 (mpc-play)))
4488
4489(mdw-define-mpc-wrapper mdw-mpc-next () nil (mpc-next))
4490(mdw-define-mpc-wrapper mdw-mpc-prev () nil (mpc-prev))
4491(mdw-define-mpc-wrapper mdw-mpc-stop () nil (mpc-stop))
0f81a131 4492
5147578f
MW
4493(defun mdw-mpc-louder (step)
4494 (interactive (list (if current-prefix-arg
4495 (prefix-numeric-value current-prefix-arg)
4496 +10)))
4497 (mpc-proc-cmd (format "volume %+d" step)))
4498
4499(defun mdw-mpc-quieter (step)
4500 (interactive (list (if current-prefix-arg
4501 (prefix-numeric-value current-prefix-arg)
4502 +10)))
4503 (mpc-proc-cmd (format "volume %+d" (- step))))
4504
6dbdfe26
MW
4505(defun mdw-mpc-hack-lines (arg interactivep func)
4506 (if (and interactivep (use-region-p))
4507 (let ((from (region-beginning)) (to (region-end)))
4508 (goto-char from)
4509 (beginning-of-line)
4510 (funcall func)
4511 (forward-line)
4512 (while (< (point) to)
4513 (funcall func)
4514 (forward-line)))
4515 (let ((n (prefix-numeric-value arg)))
4516 (cond ((minusp n)
4517 (unless (bolp)
4518 (beginning-of-line)
4519 (funcall func)
4520 (incf n))
4521 (while (minusp n)
4522 (forward-line -1)
4523 (funcall func)
4524 (incf n)))
4525 (t
4526 (beginning-of-line)
4527 (while (plusp n)
4528 (funcall func)
4529 (forward-line)
4530 (decf n)))))))
4531
4532(defun mdw-mpc-select-one ()
4466dfac
MW
4533 (when (and (get-char-property (point) 'mpc-file)
4534 (not (get-char-property (point) 'mpc-select)))
6dbdfe26
MW
4535 (mpc-select-toggle)))
4536
4537(defun mdw-mpc-unselect-one ()
4538 (when (get-char-property (point) 'mpc-select)
4539 (mpc-select-toggle)))
4540
4541(defun mdw-mpc-select (&optional arg interactivep)
4542 (interactive (list current-prefix-arg t))
a30d0e33 4543 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
6dbdfe26
MW
4544
4545(defun mdw-mpc-unselect (&optional arg interactivep)
4546 (interactive (list current-prefix-arg t))
a30d0e33 4547 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one))
6dbdfe26
MW
4548
4549(defun mdw-mpc-unselect-backwards (arg)
4550 (interactive "p")
a30d0e33 4551 (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one))
6dbdfe26
MW
4552
4553(defun mdw-mpc-unselect-all ()
4554 (interactive)
4555 (setq mpc-select nil)
4556 (mpc-selection-refresh))
4557
4558(defun mdw-mpc-next-line (arg)
4559 (interactive "p")
4560 (beginning-of-line)
4561 (forward-line arg))
4562
4563(defun mdw-mpc-previous-line (arg)
4564 (interactive "p")
4565 (beginning-of-line)
4566 (forward-line (- arg)))
4567
6d6f2b51
MW
4568(defun mdw-mpc-playlist-add (&optional arg interactivep)
4569 (interactive (list current-prefix-arg t))
4570 (let ((mpc-select mpc-select))
4571 (when (or arg (and interactivep (use-region-p)))
4572 (setq mpc-select nil)
4573 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4574 (setq mpc-select (reverse mpc-select))
4575 (mpc-playlist-add)))
4576
4577(defun mdw-mpc-playlist-delete (&optional arg interactivep)
4578 (interactive (list current-prefix-arg t))
4579 (setq mpc-select (nreverse mpc-select))
4580 (mpc-select-save
4581 (when (or arg (and interactivep (use-region-p)))
4582 (setq mpc-select nil)
4583 (mpc-selection-refresh)
4584 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4585 (mpc-playlist-delete)))
4586
75019c66
MW
4587(defun mdw-mpc-hack-tagbrowsers ()
4588 (setq-local mode-line-format
4589 '("%e"
4590 mode-line-frame-identification
4591 mode-line-buffer-identification)))
4592(add-hook 'mpc-tagbrowser-mode-hook 'mdw-mpc-hack-tagbrowsers)
4593
65f6a37a
MW
4594(defun mdw-mpc-hack-songs ()
4595 (setq-local header-line-format
4596 ;; '("MPC " mpc-volume " " mpc-current-song)
4597 (list (propertize " " 'display '(space :align-to 0))
4598 ;; 'mpc-songs-format-description
4599 '(:eval
4600 (let ((deactivate-mark) (hscroll (window-hscroll)))
4601 (with-temp-buffer
4602 (mpc-format mpc-songs-format 'self hscroll)
4603 ;; That would be simpler than the hscroll handling in
4604 ;; mpc-format, but currently move-to-column does not
4605 ;; recognize :space display properties.
4606 ;; (move-to-column hscroll)
4607 ;; (delete-region (point-min) (point))
4608 (buffer-string)))))))
4609(add-hook 'mpc-songs-mode-hook 'mdw-mpc-hack-songs)
4610
6dbdfe26
MW
4611(eval-after-load "mpc"
4612 '(progn
4613 (define-key mpc-mode-map "m" 'mdw-mpc-select)
4614 (define-key mpc-mode-map "u" 'mdw-mpc-unselect)
4615 (define-key mpc-mode-map "\177" 'mdw-mpc-unselect-backwards)
4616 (define-key mpc-mode-map "\e\177" 'mdw-mpc-unselect-all)
4617 (define-key mpc-mode-map "n" 'mdw-mpc-next-line)
4618 (define-key mpc-mode-map "p" 'mdw-mpc-previous-line)
56ba17be 4619 (define-key mpc-mode-map "/" 'mpc-songs-search)
6dbdfe26
MW
4620 (setq mpc-songs-mode-map (make-sparse-keymap))
4621 (set-keymap-parent mpc-songs-mode-map mpc-mode-map)
4622 (define-key mpc-songs-mode-map "l" 'mpc-playlist)
6d6f2b51
MW
4623 (define-key mpc-songs-mode-map "+" 'mdw-mpc-playlist-add)
4624 (define-key mpc-songs-mode-map "-" 'mdw-mpc-playlist-delete)
56ba17be 4625 (define-key mpc-songs-mode-map "\r" 'mpc-songs-jump-to)))
6dbdfe26 4626
0f81a131 4627;;;--------------------------------------------------------------------------
e07e3320
MW
4628;;; Inferior Emacs Lisp.
4629
4630(setq comint-prompt-read-only t)
4631
4632(eval-after-load "comint"
4633 '(progn
4634 (define-key comint-mode-map "\C-w" 'comint-kill-region)
4635 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
4636
4637(eval-after-load "ielm"
4638 '(progn
4639 (define-key ielm-map "\C-w" 'comint-kill-region)
4640 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
4641
f617db13
MW
4642;;;----- That's all, folks --------------------------------------------------
4643
4644(provide 'dot-emacs)