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