dot/e16-bindings: New bindings for fiddling with window opacity.
[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
6132bc01 55;; Some error trapping.
f617db13
MW
56;;
57;; If individual bits of this file go tits-up, we don't particularly want
58;; the whole lot to stop right there and then, because it's bloody annoying.
59
60(defmacro trap (&rest forms)
61 "Execute FORMS without allowing errors to propagate outside."
9e789ed5
MW
62 (declare (indent 0)
63 (debug t))
f617db13
MW
64 `(condition-case err
65 ,(if (cdr forms) (cons 'progn forms) (car forms))
8df912e4
MW
66 (error (message "Error (trapped): %s in %s"
67 (error-message-string err)
68 ',forms))))
f617db13 69
6132bc01 70;; Configuration reading.
f141fe0f
MW
71
72(defvar mdw-config nil)
73(defun mdw-config (sym)
74 "Read the configuration variable named SYM."
75 (unless mdw-config
daff679f
MW
76 (setq mdw-config
77 (flet ((replace (what with)
78 (goto-char (point-min))
79 (while (re-search-forward what nil t)
80 (replace-match with t))))
81 (with-temp-buffer
82 (insert-file-contents "~/.mdw.conf")
83 (replace "^[ \t]*\\(#.*\\|\\)\n" "")
84 (replace (concat "^[ \t]*"
85 "\\([-a-zA-Z0-9_.]*\\)"
86 "[ \t]*=[ \t]*"
87 "\\(.*[^ \t\n]\\|\\)"
88 "[ \t]**\\(\n\\|$\\)")
89 "(\\1 . \"\\2\")\n")
90 (car (read-from-string
91 (concat "(" (buffer-string) ")")))))))
f141fe0f
MW
92 (cdr (assq sym mdw-config)))
93
6132bc01 94;; Set up the load path convincingly.
eac7b622
MW
95
96(dolist (dir (append (and (boundp 'debian-emacs-flavor)
97 (list (concat "/usr/share/"
98 (symbol-name debian-emacs-flavor)
99 "/site-lisp")))))
100 (dolist (sub (directory-files dir t))
101 (when (and (file-accessible-directory-p sub)
102 (not (member sub load-path)))
103 (setq load-path (nconc load-path (list sub))))))
104
6132bc01 105;; Is an Emacs library available?
cb6e2cd1
MW
106
107(defun library-exists-p (name)
6132bc01
MW
108 "Return non-nil if NAME is an available library.
109Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
110load path. The non-nil value is the filename we found for the
111library."
cb6e2cd1
MW
112 (let ((path load-path) elt (foundp nil))
113 (while (and path (not foundp))
114 (setq elt (car path))
115 (setq path (cdr path))
116 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
117 (and (file-exists-p file) file))
118 (let ((file (concat elt "/" name ".el")))
119 (and (file-exists-p file) file)))))
120 foundp))
121
122(defun maybe-autoload (symbol file &optional docstring interactivep type)
123 "Set an autoload if the file actually exists."
124 (and (library-exists-p file)
125 (autoload symbol file docstring interactivep type)))
126
6132bc01 127;; Splitting windows.
f617db13 128
8c2b05d5
MW
129(unless (fboundp 'scroll-bar-columns)
130 (defun scroll-bar-columns (side)
131 (cond ((eq side 'left) 0)
132 (window-system 3)
133 (t 1))))
134(unless (fboundp 'fringe-columns)
135 (defun fringe-columns (side)
136 (cond ((not window-system) 0)
137 ((eq side 'left) 1)
138 (t 2))))
139
3ba0b777
MW
140(defun mdw-horizontal-window-overhead ()
141 "Computes the horizontal window overhead.
142This is the number of columns used by fringes, scroll bars and other such
143cruft."
144 (if (not window-system)
145 1
146 (let ((tot 0))
147 (dolist (what '(scroll-bar fringe))
148 (dolist (side '(left right))
149 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
150 side))))
151 tot)))
152
153(defun mdw-split-window-horizontally (&optional width)
154 "Split a window horizontally.
155Without a numeric argument, split the window approximately in
156half. With a numeric argument WIDTH, allocate WIDTH columns to
157the left-hand window (if positive) or -WIDTH columns to the
158right-hand window (if negative). Space for scroll bars and
159fringes is not taken out of the allowance for WIDTH, unlike
160\\[split-window-horizontally]."
161 (interactive "P")
162 (split-window-horizontally
163 (cond ((null width) nil)
164 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
165 ((< width 0) width))))
166
8c2b05d5 167(defun mdw-divvy-window (&optional width)
f617db13 168 "Split a wide window into appropriate widths."
8c2b05d5
MW
169 (interactive "P")
170 (setq width (cond (width (prefix-numeric-value width))
171 ((and window-system
172 (>= emacs-major-version 22))
173 77)
174 (t 78)))
b5d724dd 175 (let* ((win (selected-window))
3ba0b777 176 (sb-width (mdw-horizontal-window-overhead))
b5d724dd 177 (c (/ (+ (window-width) sb-width)
8c2b05d5 178 (+ width sb-width))))
f617db13
MW
179 (while (> c 1)
180 (setq c (1- c))
8c2b05d5 181 (split-window-horizontally (+ width sb-width))
f617db13
MW
182 (other-window 1))
183 (select-window win)))
184
c4b18360
MW
185;; Transient mark mode hacks.
186
187(defadvice exchange-point-and-mark
188 (around mdw-highlight (&optional arg) activate compile)
189 "Maybe don't actually exchange point and mark.
190If `transient-mark-mode' is on and the mark is inactive, then
191just activate it. A non-trivial prefix argument will force the
192usual behaviour. A trivial prefix argument (i.e., just C-u) will
193activate the mark and temporarily enable `transient-mark-mode' if
194it's currently off."
195 (cond ((or mark-active
196 (and (not transient-mark-mode) (not arg))
197 (and arg (or (not (consp arg))
198 (not (= (car arg) 4)))))
199 ad-do-it)
200 (t
201 (or transient-mark-mode (setq transient-mark-mode 'only))
202 (set-mark (mark t)))))
203
6132bc01 204;; Functions for sexp diary entries.
f617db13
MW
205
206(defun mdw-weekday (l)
207 "Return non-nil if `date' falls on one of the days of the week in L.
6132bc01
MW
208L is a list of day numbers (from 0 to 6 for Sunday through to
209Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
210the date stored in `date' falls on a listed day, then the
211function returns non-nil."
f617db13
MW
212 (let ((d (calendar-day-of-week date)))
213 (or (memq d l)
214 (memq (nth d '(sunday monday tuesday wednesday
215 thursday friday saturday)) l))))
216
217(defun mdw-todo (&optional when)
218 "Return non-nil today, or on WHEN, whichever is later."
219 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
220 (d (calendar-absolute-from-gregorian date)))
221 (if when
222 (setq w (max w (calendar-absolute-from-gregorian
223 (cond
224 ((not european-calendar-style)
225 when)
226 ((> (car when) 100)
227 (list (nth 1 when)
228 (nth 2 when)
229 (nth 0 when)))
230 (t
231 (list (nth 1 when)
232 (nth 0 when)
233 (nth 2 when))))))))
234 (eq w d)))
235
6132bc01 236;; Fighting with Org-mode's evil key maps.
16fe7c41
MW
237
238(defvar mdw-evil-keymap-keys
239 '(([S-up] . [?\C-c up])
240 ([S-down] . [?\C-c down])
241 ([S-left] . [?\C-c left])
242 ([S-right] . [?\C-c right])
243 (([M-up] [?\e up]) . [C-up])
244 (([M-down] [?\e down]) . [C-down])
245 (([M-left] [?\e left]) . [C-left])
246 (([M-right] [?\e right]) . [C-right]))
247 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
248The value is an alist mapping evil keys (as a list, or singleton)
249to good keys (in the same form).")
250
251(defun mdw-clobber-evil-keymap (keymap)
252 "Replace evil key bindings in the KEYMAP.
253Evil key bindings are defined in `mdw-evil-keymap-keys'."
254 (dolist (entry mdw-evil-keymap-keys)
255 (let ((binding nil)
256 (keys (if (listp (car entry))
257 (car entry)
258 (list (car entry))))
259 (replacements (if (listp (cdr entry))
260 (cdr entry)
261 (list (cdr entry)))))
262 (catch 'found
263 (dolist (key keys)
264 (setq binding (lookup-key keymap key))
265 (when binding
266 (throw 'found nil))))
267 (when binding
268 (dolist (key keys)
269 (define-key keymap key nil))
270 (dolist (key replacements)
271 (define-key keymap key binding))))))
272
0f6be0b1 273(eval-after-load "org-latex"
f0dbee84
MW
274 '(progn
275 (push '("strayman"
276 "\\documentclass{strayman}
277\\usepackage[utf8]{inputenc}
278\\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
279\\usepackage[T1]{fontenc}
280\\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
281 ("\\section{%s}" . "\\section*{%s}")
282 ("\\subsection{%s}" . "\\subsection*{%s}")
283 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
284 ("\\paragraph{%s}" . "\\paragraph*{%s}")
285 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
286 org-export-latex-classes)))
287
6132bc01
MW
288;;;--------------------------------------------------------------------------
289;;; Mail and news hacking.
a3bdb4d9
MW
290
291(define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
6132bc01 292 "Major mode for editing news and mail messages from external programs.
a3bdb4d9
MW
293Not much right now. Just support for doing MailCrypt stuff."
294 :syntax-table nil
295 :abbrev-table nil
296 (run-hooks 'mail-setup-hook))
297
298(define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
299
300(add-hook 'mdwail-mode-hook
301 (lambda ()
302 (set-buffer-file-coding-system 'utf-8)
303 (make-local-variable 'paragraph-separate)
304 (make-local-variable 'paragraph-start)
305 (setq paragraph-start
306 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
307 paragraph-start))
308 (setq paragraph-separate
309 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
310 paragraph-separate))))
311
6132bc01 312;; How to encrypt in mdwmail.
a3bdb4d9
MW
313
314(defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
315 (or start
316 (setq start (save-excursion
317 (goto-char (point-min))
318 (or (search-forward "\n\n" nil t) (point-min)))))
319 (or end
320 (setq end (point-max)))
321 (mc-encrypt-generic recip scm start end from sign))
322
6132bc01 323;; How to sign in mdwmail.
a3bdb4d9
MW
324
325(defun mdwmail-mc-sign (key scm start end uclr)
326 (or start
327 (setq start (save-excursion
328 (goto-char (point-min))
329 (or (search-forward "\n\n" nil t) (point-min)))))
330 (or end
331 (setq end (point-max)))
332 (mc-sign-generic key scm start end uclr))
333
6132bc01 334;; Some signature mangling.
a3bdb4d9
MW
335
336(defun mdwmail-mangle-signature ()
337 (save-excursion
338 (goto-char (point-min))
339 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
340(add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
341(add-hook 'message-setup-hook 'mdwmail-mangle-signature)
342
6132bc01 343;; Insert my login name into message-ids, so I can score replies.
a3bdb4d9
MW
344
345(defadvice message-unique-id (after mdw-user-name last activate compile)
346 "Ensure that the user's name appears at the end of the message-id string,
347so that it can be used for convenient filtering."
348 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
349
6132bc01 350;; Tell my movemail hack where movemail is.
a3bdb4d9
MW
351;;
352;; This is needed to shup up warnings about LD_PRELOAD.
353
354(let ((path exec-path))
355 (while path
356 (let ((try (expand-file-name "movemail" (car path))))
357 (if (file-executable-p try)
358 (setenv "REAL_MOVEMAIL" try))
359 (setq path (cdr path)))))
360
d17c6756
MW
361(eval-after-load "erc"
362 '(load "~/.ercrc.el"))
363
6132bc01
MW
364;;;--------------------------------------------------------------------------
365;;; Utility functions.
f617db13 366
b5d724dd
MW
367(or (fboundp 'line-number-at-pos)
368 (defun line-number-at-pos (&optional pos)
369 (let ((opoint (or pos (point))) start)
370 (save-excursion
371 (save-restriction
372 (goto-char (point-min))
373 (widen)
374 (forward-line 0)
375 (setq start (point))
376 (goto-char opoint)
377 (forward-line 0)
378 (1+ (count-lines 1 (point))))))))
459c9fb2 379
f617db13 380(defun mdw-uniquify-alist (&rest alists)
f617db13 381 "Return the concatenation of the ALISTS with duplicate elements removed.
6132bc01
MW
382The first association with a given key prevails; others are
383ignored. The input lists are not modified, although they'll
384probably become garbage."
f617db13
MW
385 (and alists
386 (let ((start-list (cons nil nil)))
387 (mdw-do-uniquify start-list
388 start-list
389 (car alists)
390 (cdr alists)))))
391
f617db13 392(defun mdw-do-uniquify (done end l rest)
6132bc01
MW
393 "A helper function for mdw-uniquify-alist.
394The DONE argument is a list whose first element is `nil'. It
395contains the uniquified alist built so far. The leading `nil' is
396stripped off at the end of the operation; it's only there so that
397DONE always references a cons cell. END refers to the final cons
398cell in the DONE list; it is modified in place each time to avoid
399the overheads of `append'ing all the time. The L argument is the
400alist we're currently processing; the remaining alists are given
401in REST."
402
403 ;; There are several different cases to deal with here.
f617db13
MW
404 (cond
405
6132bc01
MW
406 ;; Current list isn't empty. Add the first item to the DONE list if
407 ;; there's not an item with the same KEY already there.
f617db13
MW
408 (l (or (assoc (car (car l)) done)
409 (progn
410 (setcdr end (cons (car l) nil))
411 (setq end (cdr end))))
412 (mdw-do-uniquify done end (cdr l) rest))
413
6132bc01
MW
414 ;; The list we were working on is empty. Shunt the next list into the
415 ;; current list position and go round again.
f617db13
MW
416 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
417
6132bc01
MW
418 ;; Everything's done. Remove the leading `nil' from the DONE list and
419 ;; return it. Finished!
f617db13
MW
420 (t (cdr done))))
421
f617db13
MW
422(defun date ()
423 "Insert the current date in a pleasing way."
424 (interactive)
425 (insert (save-excursion
426 (let ((buffer (get-buffer-create "*tmp*")))
427 (unwind-protect (progn (set-buffer buffer)
428 (erase-buffer)
429 (shell-command "date +%Y-%m-%d" t)
430 (goto-char (mark))
431 (delete-backward-char 1)
432 (buffer-string))
433 (kill-buffer buffer))))))
434
f617db13
MW
435(defun uuencode (file &optional name)
436 "UUencodes a file, maybe calling it NAME, into the current buffer."
437 (interactive "fInput file name: ")
438
6132bc01 439 ;; If NAME isn't specified, then guess from the filename.
f617db13
MW
440 (if (not name)
441 (setq name
442 (substring file
443 (or (string-match "[^/]*$" file) 0))))
f617db13
MW
444 (print (format "uuencode `%s' `%s'" file name))
445
6132bc01 446 ;; Now actually do the thing.
f617db13
MW
447 (call-process "uuencode" file t nil name))
448
449(defvar np-file "~/.np"
450 "*Where the `now-playing' file is.")
451
452(defun np (&optional arg)
453 "Grabs a `now-playing' string."
454 (interactive)
455 (save-excursion
456 (or arg (progn
852cd5fb 457 (goto-char (point-max))
f617db13 458 (insert "\nNP: ")
daff679f 459 (insert-file-contents np-file)))))
f617db13 460
ae7460d4
MW
461(defun mdw-version-< (ver-a ver-b)
462 "Answer whether VER-A is strictly earlier than VER-B.
463VER-A and VER-B are version numbers, which are strings containing digit
464sequences separated by `.'."
465 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
466 (split-string ver-a "\\.")))
467 (lb (mapcar (lambda (x) (car (read-from-string x)))
468 (split-string ver-b "\\."))))
469 (catch 'done
470 (while t
471 (cond ((null la) (throw 'done lb))
472 ((null lb) (throw 'done nil))
473 ((< (car la) (car lb)) (throw 'done t))
474 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb))))))))
475
c7a8da49 476(defun mdw-check-autorevert ()
6132bc01
MW
477 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
478This takes into consideration whether it's been found using
479tramp, which seems to get itself into a twist."
46e69f55
MW
480 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
481 nil)
482 ((and (buffer-file-name)
483 (fboundp 'tramp-tramp-file-p)
c7a8da49
MW
484 (tramp-tramp-file-p (buffer-file-name)))
485 (unless global-auto-revert-ignore-buffer
486 (setq global-auto-revert-ignore-buffer 'tramp)))
487 ((eq global-auto-revert-ignore-buffer 'tramp)
488 (setq global-auto-revert-ignore-buffer nil))))
489
490(defadvice find-file (after mdw-autorevert activate)
491 (mdw-check-autorevert))
492(defadvice write-file (after mdw-autorevert activate)
4d9f2d65 493 (mdw-check-autorevert))
eae0aa6d 494
6132bc01
MW
495;;;--------------------------------------------------------------------------
496;;; Dired hacking.
5195cbc3
MW
497
498(defadvice dired-maybe-insert-subdir
499 (around mdw-marked-insertion first activate)
6132bc01
MW
500 "The DIRNAME may be a list of directory names to insert.
501Interactively, if files are marked, then insert all of them.
502With a numeric prefix argument, select that many entries near
503point; with a non-numeric prefix argument, prompt for listing
504options."
5195cbc3
MW
505 (interactive
506 (list (dired-get-marked-files nil
507 (and (integerp current-prefix-arg)
508 current-prefix-arg)
509 #'file-directory-p)
510 (and current-prefix-arg
511 (not (integerp current-prefix-arg))
512 (read-string "Switches for listing: "
513 (or dired-subdir-switches
514 dired-actual-switches)))))
515 (let ((dirs (ad-get-arg 0)))
516 (dolist (dir (if (listp dirs) dirs (list dirs)))
517 (ad-set-arg 0 dir)
518 ad-do-it)))
519
6132bc01
MW
520;;;--------------------------------------------------------------------------
521;;; URL viewing.
a203fba8
MW
522
523(defun mdw-w3m-browse-url (url &optional new-session-p)
524 "Invoke w3m on the URL in its current window, or at least a different one.
525If NEW-SESSION-P, start a new session."
526 (interactive "sURL: \nP")
527 (save-excursion
63fb20c1
MW
528 (let ((window (selected-window)))
529 (unwind-protect
530 (progn
531 (select-window (or (and (not new-session-p)
532 (get-buffer-window "*w3m*"))
533 (progn
534 (if (one-window-p t) (split-window))
535 (get-lru-window))))
536 (w3m-browse-url url new-session-p))
537 (select-window window)))))
a203fba8
MW
538
539(defvar mdw-good-url-browsers
ed5e20a5
MW
540 '(browse-url-generic
541 (w3m . mdw-w3m-browse-url)
a203fba8
MW
542 browse-url-w3
543 browse-url-mozilla)
6132bc01
MW
544 "List of good browsers for mdw-good-url-browsers.
545Each item is a browser function name, or a cons (CHECK . FUNC).
546A symbol FOO stands for (FOO . FOO).")
a203fba8
MW
547
548(defun mdw-good-url-browser ()
6132bc01
MW
549 "Return a good URL browser.
550Trundle the list of such things, finding the first item for which
551CHECK is fboundp, and returning the correponding FUNC."
a203fba8
MW
552 (let ((bs mdw-good-url-browsers) b check func answer)
553 (while (and bs (not answer))
554 (setq b (car bs)
555 bs (cdr bs))
556 (if (consp b)
557 (setq check (car b) func (cdr b))
558 (setq check b func b))
559 (if (fboundp check)
560 (setq answer func)))
561 answer))
562
f36cdb77
MW
563(eval-after-load "w3m-search"
564 '(progn
565 (dolist
566 (item
567 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
568 ("gd" "Google Directory"
569 "http://www.google.com/search?cat=gwd/Top&q=%s")
570 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
571 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
572 ("gi" "Images" "http://images.google.com/images?q=%s")
573 ("rfc" "RFC"
574 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
575 ("wp" "Wikipedia"
576 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
577 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
578 ("nc-wiki" "nCipher wiki"
579 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
580 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
581 ("lp" "Launchpad bug by number"
582 "https://bugs.launchpad.net/bugs/%s")
583 ("lppkg" "Launchpad bugs by package"
584 "https://bugs.launchpad.net/%s")
585 ("msdn" "MSDN"
586 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
587 ("debbug" "Debian bug by number"
588 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
589 ("debbugpkg" "Debian bugs by package"
590 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
591 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
592 (add-to-list 'w3m-search-engine-alist
593 (list (cadr item) (caddr item) nil))
594 (add-to-list 'w3m-uri-replace-alist
595 (list (concat "\\`" (car item) ":")
596 'w3m-search-uri-replace
597 (cadr item))))))
598
6132bc01
MW
599;;;--------------------------------------------------------------------------
600;;; Paragraph filling.
f617db13 601
6132bc01 602;; Useful variables.
f617db13
MW
603
604(defvar mdw-fill-prefix nil
6132bc01
MW
605 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
606If there's no fill prefix currently set (by the `fill-prefix'
607variable) and there's a match from one of the regexps here, it
608gets used to set the fill-prefix for the current operation.
f617db13 609
6132bc01
MW
610The variable is a list of items of the form `REGEXP . PREFIX'; if
611the REGEXP matches, the PREFIX is used to set the fill prefix.
612It in turn is a list of things:
f617db13
MW
613
614 STRING -- insert a literal string
615 (match . N) -- insert the thing matched by bracketed subexpression N
616 (pad . N) -- a string of whitespace the same width as subexpression N
617 (expr . FORM) -- the result of evaluating FORM")
618
619(make-variable-buffer-local 'mdw-fill-prefix)
620
621(defvar mdw-hanging-indents
10fa2414 622 (concat "\\(\\("
f8bfe560 623 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
10fa2414
MW
624 "[ \t]+"
625 "\\)?\\)")
6132bc01
MW
626 "*Standard regexp matching parts of a hanging indent.
627This is mainly useful in `auto-fill-mode'.")
f617db13 628
6132bc01 629;; Setting things up.
f617db13
MW
630
631(fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
632
6132bc01 633;; Utility functions.
f617db13
MW
634
635(defun mdw-tabify (s)
636 "Tabify the string S. This is a horrid hack."
637 (save-excursion
638 (save-match-data
639 (let (start end)
640 (beginning-of-line)
641 (setq start (point-marker))
642 (insert s "\n")
643 (setq end (point-marker))
644 (tabify start end)
645 (setq s (buffer-substring start (1- end)))
646 (delete-region start end)
647 (set-marker start nil)
648 (set-marker end nil)
649 s))))
650
651(defun mdw-examine-fill-prefixes (l)
6132bc01
MW
652 "Given a list of dynamic fill prefixes, pick one which matches
653context and return the static fill prefix to use. Point must be
654at the start of a line, and match data must be saved."
f617db13
MW
655 (cond ((not l) nil)
656 ((looking-at (car (car l)))
657 (mdw-tabify (apply (function concat)
658 (mapcar (function mdw-do-prefix-match)
659 (cdr (car l))))))
660 (t (mdw-examine-fill-prefixes (cdr l)))))
661
662(defun mdw-maybe-car (p)
663 "If P is a pair, return (car P), otherwise just return P."
664 (if (consp p) (car p) p))
665
666(defun mdw-padding (s)
667 "Return a string the same width as S but made entirely from whitespace."
668 (let* ((l (length s)) (i 0) (n (make-string l ? )))
669 (while (< i l)
670 (if (= 9 (aref s i))
671 (aset n i 9))
672 (setq i (1+ i)))
673 n))
674
675(defun mdw-do-prefix-match (m)
6132bc01
MW
676 "Expand a dynamic prefix match element.
677See `mdw-fill-prefix' for details."
f617db13
MW
678 (cond ((not (consp m)) (format "%s" m))
679 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
680 ((eq (car m) 'pad) (mdw-padding (match-string
681 (mdw-maybe-car (cdr m)))))
682 ((eq (car m) 'eval) (eval (cdr m)))
683 (t "")))
684
685(defun mdw-choose-dynamic-fill-prefix ()
686 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
687 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
688 ((not mdw-fill-prefix) fill-prefix)
689 (t (save-excursion
690 (beginning-of-line)
691 (save-match-data
692 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
693
694(defun do-auto-fill ()
6132bc01
MW
695 "Handle auto-filling, working out a dynamic fill prefix in the
696case where there isn't a sensible static one."
f617db13
MW
697 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
698 (mdw-do-auto-fill)))
699
700(defun mdw-fill-paragraph ()
701 "Fill paragraph, getting a dynamic fill prefix."
702 (interactive)
703 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
704 (fill-paragraph nil)))
705
706(defun mdw-standard-fill-prefix (rx &optional mat)
707 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
6132bc01
MW
708This is just a short-cut for setting the thing by hand, and by
709design it doesn't cope with anything approximating a complicated
710case."
f617db13
MW
711 (setq mdw-fill-prefix
712 `((,(concat rx mdw-hanging-indents)
713 (match . 1)
714 (pad . ,(or mat 2))))))
715
6132bc01
MW
716;;;--------------------------------------------------------------------------
717;;; Other common declarations.
f617db13 718
6132bc01 719;; Common mode settings.
f617db13
MW
720
721(defvar mdw-auto-indent t
722 "Whether to indent automatically after a newline.")
723
0e58a7c2
MW
724(defun mdw-whitespace-mode (&optional arg)
725 "Turn on/off whitespace mode, but don't highlight trailing space."
726 (interactive "P")
727 (when (and (boundp 'whitespace-style)
728 (fboundp 'whitespace-mode))
729 (let ((whitespace-style (remove 'trailing whitespace-style)))
558fc014
MW
730 (whitespace-mode arg))
731 (setq show-trailing-whitespace whitespace-mode)))
0e58a7c2 732
f617db13
MW
733(defun mdw-misc-mode-config ()
734 (and mdw-auto-indent
735 (cond ((eq major-mode 'lisp-mode)
736 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
30c8a8fb
MW
737 ((or (eq major-mode 'slime-repl-mode)
738 (eq major-mode 'asm-mode))
739 nil)
f617db13
MW
740 (t
741 (local-set-key "\C-m" 'newline-and-indent))))
742 (local-set-key [C-return] 'newline)
8a425bd7 743 (make-local-variable 'page-delimiter)
8cb7626b 744 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
f617db13
MW
745 (setq comment-column 40)
746 (auto-fill-mode 1)
747 (setq fill-column 77)
473ff3b0 748 (setq show-trailing-whitespace t)
0e58a7c2 749 (mdw-whitespace-mode 1)
253f61b4
MW
750 (and (fboundp 'gtags-mode)
751 (gtags-mode))
ddf6e116
MW
752 (if (fboundp 'hs-minor-mode)
753 (hs-minor-mode t)
754 (outline-minor-mode t))
49b2646e 755 (reveal-mode t)
1e7a9479 756 (trap (turn-on-font-lock)))
f617db13 757
ed7b46b9 758(defun mdw-post-config-mode-hack ()
0e58a7c2 759 (mdw-whitespace-mode 1))
ed7b46b9 760
253f61b4 761(eval-after-load 'gtags
506bada9
MW
762 '(progn
763 (dolist (key '([mouse-2] [mouse-3]))
764 (define-key gtags-mode-map key nil))
765 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
766 (define-key gtags-select-mode-map [C-S-mouse-2]
767 'gtags-select-tag-by-event)
768 (dolist (map (list gtags-mode-map gtags-select-mode-map))
769 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
253f61b4 770
6132bc01 771;; Backup file handling.
2ae647c4
MW
772
773(defvar mdw-backup-disable-regexps nil
6132bc01
MW
774 "*List of regular expressions: if a file name matches any of
775these then the file is not backed up.")
2ae647c4
MW
776
777(defun mdw-backup-enable-predicate (name)
6132bc01
MW
778 "[mdw]'s default backup predicate.
779Allows a backup if the standard predicate would allow it, and it
780doesn't match any of the regular expressions in
781`mdw-backup-disable-regexps'."
2ae647c4
MW
782 (and (normal-backup-enable-predicate name)
783 (let ((answer t) (list mdw-backup-disable-regexps))
784 (save-match-data
785 (while list
786 (if (string-match (car list) name)
787 (setq answer nil))
788 (setq list (cdr list)))
789 answer))))
790(setq backup-enable-predicate 'mdw-backup-enable-predicate)
791
7bb78c67
MW
792;; Frame cleanup.
793
794(defun mdw-last-one-out-turn-off-the-lights (frame)
795 "Disconnect from an X display if this was the last frame on that display."
796 (let ((frame-display (frame-parameter frame 'display)))
797 (when (and frame-display
798 (eq window-system 'x)
799 (not (some (lambda (fr)
7bb78c67 800 (and (not (eq fr frame))
a04d8f3d 801 (string= (frame-parameter fr 'display)
d70716b5 802 frame-display)))
7bb78c67 803 (frame-list))))
7bb78c67
MW
804 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
805(add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
806
6132bc01
MW
807;;;--------------------------------------------------------------------------
808;;; General fontification.
f617db13 809
1e7a9479
MW
810(defmacro mdw-define-face (name &rest body)
811 "Define a face, and make sure it's actually set as the definition."
812 (declare (indent 1)
813 (debug 0))
814 `(progn
815 (make-face ',name)
816 (defvar ,name ',name)
817 (put ',name 'face-defface-spec ',body)
88cb9c2b 818 (face-spec-set ',name ',body nil)))
1e7a9479
MW
819
820(mdw-define-face default
821 (((type w32)) :family "courier new" :height 85)
822 (((type x)) :family "6x13" :height 130)
db10ce0a
MW
823 (((type color)) :foreground "white" :background "black")
824 (t nil))
1e7a9479
MW
825(mdw-define-face fixed-pitch
826 (((type w32)) :family "courier new" :height 85)
827 (((type x)) :family "6x13" :height 130)
828 (t :foreground "white" :background "black"))
c383eb8a
MW
829(if (>= emacs-major-version 23)
830 (mdw-define-face variable-pitch
831 (((type x)) :family "sans" :height 100))
832 (mdw-define-face variable-pitch
3f001ff6 833 (((type x)) :family "helvetica" :height 90)))
1e7a9479 834(mdw-define-face region
db10ce0a
MW
835 (((type tty) (class color)) :background "blue")
836 (((type tty) (class mono)) :inverse-video t)
837 (t :background "grey30"))
1e7a9479
MW
838(mdw-define-face minibuffer-prompt
839 (t :weight bold))
840(mdw-define-face mode-line
db10ce0a
MW
841 (((class color)) :foreground "blue" :background "yellow"
842 :box (:line-width 1 :style released-button))
843 (t :inverse-video t))
1e7a9479 844(mdw-define-face mode-line-inactive
db10ce0a
MW
845 (((class color)) :foreground "yellow" :background "blue"
846 :box (:line-width 1 :style released-button))
847 (t :inverse-video t))
1e7a9479
MW
848(mdw-define-face scroll-bar
849 (t :foreground "black" :background "lightgrey"))
850(mdw-define-face fringe
851 (t :foreground "yellow"))
c383eb8a 852(mdw-define-face show-paren-match
db10ce0a
MW
853 (((class color)) :background "darkgreen")
854 (t :underline t))
c383eb8a 855(mdw-define-face show-paren-mismatch
db10ce0a
MW
856 (((class color)) :background "red")
857 (t :inverse-video t))
1e7a9479 858(mdw-define-face highlight
db10ce0a
MW
859 (((class color)) :background "DarkSeaGreen4")
860 (t :inverse-video t))
1e7a9479
MW
861
862(mdw-define-face holiday-face
863 (t :background "red"))
864(mdw-define-face calendar-today-face
865 (t :foreground "yellow" :weight bold))
866
867(mdw-define-face comint-highlight-prompt
868 (t :weight bold))
5fd055c2
MW
869(mdw-define-face comint-highlight-input
870 (t nil))
1e7a9479 871
e0e2aca3
MW
872(mdw-define-face dired-directory
873 (t :foreground "cyan" :weight bold))
874(mdw-define-face dired-symlink
875 (t :foreground "cyan"))
876(mdw-define-face dired-perm-write
877 (t nil))
878
1e7a9479 879(mdw-define-face trailing-whitespace
db10ce0a
MW
880 (((class color)) :background "red")
881 (t :inverse-video t))
1e7a9479
MW
882(mdw-define-face mdw-punct-face
883 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
884(mdw-define-face mdw-number-face
885 (t :foreground "yellow"))
886(mdw-define-face font-lock-function-name-face
c383eb8a 887 (t :slant italic))
1e7a9479
MW
888(mdw-define-face font-lock-keyword-face
889 (t :weight bold))
890(mdw-define-face font-lock-constant-face
891 (t :slant italic))
892(mdw-define-face font-lock-builtin-face
893 (t :weight bold))
07965a39
MW
894(mdw-define-face font-lock-type-face
895 (t :weight bold :slant italic))
1e7a9479
MW
896(mdw-define-face font-lock-reference-face
897 (t :weight bold))
898(mdw-define-face font-lock-variable-name-face
899 (t :slant italic))
900(mdw-define-face font-lock-comment-delimiter-face
db10ce0a
MW
901 (((class mono)) :weight bold)
902 (((type tty) (class color)) :foreground "green")
903 (t :slant italic :foreground "SeaGreen1"))
1e7a9479 904(mdw-define-face font-lock-comment-face
db10ce0a
MW
905 (((class mono)) :weight bold)
906 (((type tty) (class color)) :foreground "green")
907 (t :slant italic :foreground "SeaGreen1"))
1e7a9479 908(mdw-define-face font-lock-string-face
db10ce0a
MW
909 (((class mono)) :weight bold)
910 (((class color)) :foreground "SkyBlue1"))
1e7a9479
MW
911(mdw-define-face message-separator
912 (t :background "red" :foreground "white" :weight bold))
913(mdw-define-face message-cited-text
914 (default :slant italic)
915 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
916(mdw-define-face message-header-cc
917 (default :weight bold)
918 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
919(mdw-define-face message-header-newsgroups
920 (default :weight bold)
921 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
922(mdw-define-face message-header-subject
923 (default :weight bold)
924 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
925(mdw-define-face message-header-to
926 (default :weight bold)
927 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
928(mdw-define-face message-header-xheader
929 (default :weight bold)
930 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
931(mdw-define-face message-header-other
932 (default :weight bold)
933 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
934(mdw-define-face message-header-name
935 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
69498691
MW
936(mdw-define-face which-func
937 (t nil))
1e7a9479
MW
938
939(mdw-define-face diff-index
940 (t :weight bold))
941(mdw-define-face diff-file-header
942 (t :weight bold))
943(mdw-define-face diff-hunk-header
944 (t :foreground "SkyBlue1"))
945(mdw-define-face diff-function
946 (t :foreground "SkyBlue1" :weight bold))
947(mdw-define-face diff-header
948 (t :background "grey10"))
949(mdw-define-face diff-added
950 (t :foreground "green"))
951(mdw-define-face diff-removed
952 (t :foreground "red"))
5fd055c2
MW
953(mdw-define-face diff-context
954 (t nil))
1e7a9479 955
e1b8de18
MW
956(mdw-define-face erc-input-face
957 (t :foreground "red"))
958
1e7a9479
MW
959(mdw-define-face woman-bold
960 (t :weight bold))
961(mdw-define-face woman-italic
962 (t :slant italic))
963
964(mdw-define-face p4-depot-added-face
965 (t :foreground "green"))
966(mdw-define-face p4-depot-branch-op-face
967 (t :foreground "yellow"))
968(mdw-define-face p4-depot-deleted-face
969 (t :foreground "red"))
970(mdw-define-face p4-depot-unmapped-face
971 (t :foreground "SkyBlue1"))
972(mdw-define-face p4-diff-change-face
973 (t :foreground "yellow"))
974(mdw-define-face p4-diff-del-face
975 (t :foreground "red"))
976(mdw-define-face p4-diff-file-face
977 (t :foreground "SkyBlue1"))
978(mdw-define-face p4-diff-head-face
979 (t :background "grey10"))
980(mdw-define-face p4-diff-ins-face
981 (t :foreground "green"))
982
983(mdw-define-face whizzy-slice-face
984 (t :background "grey10"))
985(mdw-define-face whizzy-error-face
986 (t :background "darkred"))
f617db13 987
5fedb342
MW
988;; Ellipses used to indicate hidden text (and similar).
989(mdw-define-face mdw-ellipsis-face
990 (((type tty)) :foreground "blue") (t :foreground "grey60"))
991(let ((dot (make-glyph-code ?. 'mdw-ellipsis-face)))
992 (set-display-table-slot standard-display-table 4
993 (vector dot dot dot)))
994
6132bc01
MW
995;;;--------------------------------------------------------------------------
996;;; C programming configuration.
f617db13 997
6132bc01 998;; Linux kernel hacking.
f617db13
MW
999
1000(defvar linux-c-mode-hook)
1001
1002(defun linux-c-mode ()
1003 (interactive)
1004 (c-mode)
1005 (setq major-mode 'linux-c-mode)
1006 (setq mode-name "Linux C")
1007 (run-hooks 'linux-c-mode-hook))
1008
6132bc01 1009;; Make C indentation nice.
f617db13 1010
f50c1bed
MW
1011(defun mdw-c-lineup-arglist (langelem)
1012 "Hack for DWIMmery in c-lineup-arglist."
1013 (if (save-excursion
1014 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1015 0
1016 (c-lineup-arglist langelem)))
1017
1018(defun mdw-c-indent-extern-mumble (langelem)
1019 "Indent `extern \"...\" {' lines."
1020 (save-excursion
1021 (back-to-indentation)
1022 (if (looking-at
1023 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1024 c-basic-offset
1025 nil)))
1026
f617db13
MW
1027(defun mdw-c-style ()
1028 (c-add-style "[mdw] C and C++ style"
1029 '((c-basic-offset . 2)
f617db13
MW
1030 (comment-column . 40)
1031 (c-class-key . "class")
f50c1bed
MW
1032 (c-backslash-column . 72)
1033 (c-offsets-alist
1034 (substatement-open . (add 0 c-indent-one-line-block))
1035 (defun-open . (add 0 c-indent-one-line-block))
1036 (arglist-cont-nonempty . mdw-c-lineup-arglist)
1037 (topmost-intro . mdw-c-indent-extern-mumble)
1038 (cpp-define-intro . 0)
10598d75 1039 (knr-argdecl . 0)
f50c1bed
MW
1040 (inextern-lang . [0])
1041 (label . 0)
1042 (case-label . +)
1043 (access-label . -)
1044 (inclass . +)
1045 (inline-open . ++)
10598d75 1046 (statement-cont . +)
f50c1bed 1047 (statement-case-intro . +)))
f617db13
MW
1048 t))
1049
0e7d960b
MW
1050(defvar mdw-c-comment-fill-prefix
1051 `((,(concat "\\([ \t]*/?\\)"
1052 "\\(\*\\|//]\\)"
1053 "\\([ \t]*\\)"
1054 "\\([A-Za-z]+:[ \t]*\\)?"
1055 mdw-hanging-indents)
1056 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1057 "Fill prefix matching C comments (both kinds).")
1058
f617db13
MW
1059(defun mdw-fontify-c-and-c++ ()
1060
6132bc01 1061 ;; Fiddle with some syntax codes.
f617db13
MW
1062 (modify-syntax-entry ?* ". 23")
1063 (modify-syntax-entry ?/ ". 124b")
1064 (modify-syntax-entry ?\n "> b")
1065
6132bc01 1066 ;; Other stuff.
f617db13
MW
1067 (mdw-c-style)
1068 (setq c-hanging-comment-ender-p nil)
1069 (setq c-backslash-column 72)
1070 (setq c-label-minimum-indentation 0)
0e7d960b 1071 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
f617db13 1072
6132bc01 1073 ;; Now define things to be fontified.
02109a0d 1074 (make-local-variable 'font-lock-keywords)
f617db13 1075 (let ((c-keywords
8d6d55b9
MW
1076 (mdw-regexps "and" ;C++
1077 "and_eq" ;C++
1078 "asm" ;K&R, GCC
1079 "auto" ;K&R, C89
1080 "bitand" ;C++
1081 "bitor" ;C++
1082 "bool" ;C++, C9X macro
1083 "break" ;K&R, C89
1084 "case" ;K&R, C89
1085 "catch" ;C++
1086 "char" ;K&R, C89
1087 "class" ;C++
1088 "complex" ;C9X macro, C++ template type
1089 "compl" ;C++
1090 "const" ;C89
1091 "const_cast" ;C++
1092 "continue" ;K&R, C89
1093 "defined" ;C89 preprocessor
1094 "default" ;K&R, C89
1095 "delete" ;C++
1096 "do" ;K&R, C89
1097 "double" ;K&R, C89
1098 "dynamic_cast" ;C++
1099 "else" ;K&R, C89
1100 ;; "entry" ;K&R -- never used
1101 "enum" ;C89
1102 "explicit" ;C++
1103 "export" ;C++
1104 "extern" ;K&R, C89
1105 "false" ;C++, C9X macro
1106 "float" ;K&R, C89
1107 "for" ;K&R, C89
1108 ;; "fortran" ;K&R
1109 "friend" ;C++
1110 "goto" ;K&R, C89
1111 "if" ;K&R, C89
1112 "imaginary" ;C9X macro
1113 "inline" ;C++, C9X, GCC
1114 "int" ;K&R, C89
1115 "long" ;K&R, C89
1116 "mutable" ;C++
1117 "namespace" ;C++
1118 "new" ;C++
1119 "operator" ;C++
1120 "or" ;C++
1121 "or_eq" ;C++
1122 "private" ;C++
1123 "protected" ;C++
1124 "public" ;C++
1125 "register" ;K&R, C89
1126 "reinterpret_cast" ;C++
1127 "restrict" ;C9X
1128 "return" ;K&R, C89
1129 "short" ;K&R, C89
1130 "signed" ;C89
1131 "sizeof" ;K&R, C89
1132 "static" ;K&R, C89
1133 "static_cast" ;C++
1134 "struct" ;K&R, C89
1135 "switch" ;K&R, C89
1136 "template" ;C++
1137 "this" ;C++
1138 "throw" ;C++
1139 "true" ;C++, C9X macro
1140 "try" ;C++
1141 "this" ;C++
1142 "typedef" ;C89
1143 "typeid" ;C++
1144 "typeof" ;GCC
1145 "typename" ;C++
1146 "union" ;K&R, C89
1147 "unsigned" ;K&R, C89
1148 "using" ;C++
1149 "virtual" ;C++
1150 "void" ;C89
1151 "volatile" ;C89
1152 "wchar_t" ;C++, C89 library type
1153 "while" ;K&R, C89
1154 "xor" ;C++
1155 "xor_eq" ;C++
1156 "_Bool" ;C9X
1157 "_Complex" ;C9X
1158 "_Imaginary" ;C9X
1159 "_Pragma" ;C9X preprocessor
1160 "__alignof__" ;GCC
1161 "__asm__" ;GCC
1162 "__attribute__" ;GCC
1163 "__complex__" ;GCC
1164 "__const__" ;GCC
1165 "__extension__" ;GCC
1166 "__imag__" ;GCC
1167 "__inline__" ;GCC
1168 "__label__" ;GCC
1169 "__real__" ;GCC
1170 "__signed__" ;GCC
1171 "__typeof__" ;GCC
1172 "__volatile__" ;GCC
1173 ))
f617db13 1174 (preprocessor-keywords
8d6d55b9
MW
1175 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1176 "ident" "if" "ifdef" "ifndef" "import" "include"
1177 "line" "pragma" "unassert" "undef" "warning"))
f617db13 1178 (objc-keywords
8d6d55b9
MW
1179 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1180 "interface" "private" "protected" "protocol" "public"
1181 "selector")))
f617db13
MW
1182
1183 (setq font-lock-keywords
1184 (list
f617db13 1185
6132bc01 1186 ;; Fontify include files as strings.
f617db13
MW
1187 (list (concat "^[ \t]*\\#[ \t]*"
1188 "\\(include\\|import\\)"
1189 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1190 '(2 font-lock-string-face))
1191
6132bc01 1192 ;; Preprocessor directives are `references'?.
f617db13
MW
1193 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1194 preprocessor-keywords
1195 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1196 '(1 font-lock-keyword-face))
1197
6132bc01 1198 ;; Handle the keywords defined above.
f617db13
MW
1199 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1200 '(0 font-lock-keyword-face))
1201
1202 (list (concat "\\<\\(" c-keywords "\\)\\>")
1203 '(0 font-lock-keyword-face))
1204
6132bc01 1205 ;; Handle numbers too.
f617db13
MW
1206 ;;
1207 ;; This looks strange, I know. It corresponds to the
1208 ;; preprocessor's idea of what a number looks like, rather than
1209 ;; anything sensible.
f617db13
MW
1210 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1211 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1212 '(0 mdw-number-face))
1213
6132bc01 1214 ;; And anything else is punctuation.
f617db13 1215 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1216 '(0 mdw-punct-face))))
1217
1218 (mdw-post-config-mode-hack)))
f617db13 1219
6132bc01
MW
1220;;;--------------------------------------------------------------------------
1221;;; AP calc mode.
f617db13
MW
1222
1223(defun apcalc-mode ()
1224 (interactive)
1225 (c-mode)
1226 (setq major-mode 'apcalc-mode)
1227 (setq mode-name "AP Calc")
1228 (run-hooks 'apcalc-mode-hook))
1229
1230(defun mdw-fontify-apcalc ()
1231
6132bc01 1232 ;; Fiddle with some syntax codes.
f617db13
MW
1233 (modify-syntax-entry ?* ". 23")
1234 (modify-syntax-entry ?/ ". 14")
1235
6132bc01 1236 ;; Other stuff.
f617db13
MW
1237 (mdw-c-style)
1238 (setq c-hanging-comment-ender-p nil)
1239 (setq c-backslash-column 72)
1240 (setq comment-start "/* ")
1241 (setq comment-end " */")
0e7d960b 1242 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
f617db13 1243
6132bc01 1244 ;; Now define things to be fontified.
02109a0d 1245 (make-local-variable 'font-lock-keywords)
f617db13 1246 (let ((c-keywords
8d6d55b9
MW
1247 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1248 "do" "else" "exit" "for" "global" "goto" "help" "if"
1249 "local" "mat" "obj" "print" "quit" "read" "return"
1250 "show" "static" "switch" "while" "write")))
f617db13
MW
1251
1252 (setq font-lock-keywords
1253 (list
f617db13 1254
6132bc01 1255 ;; Handle the keywords defined above.
f617db13
MW
1256 (list (concat "\\<\\(" c-keywords "\\)\\>")
1257 '(0 font-lock-keyword-face))
1258
6132bc01 1259 ;; Handle numbers too.
f617db13
MW
1260 ;;
1261 ;; This looks strange, I know. It corresponds to the
1262 ;; preprocessor's idea of what a number looks like, rather than
1263 ;; anything sensible.
f617db13
MW
1264 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1265 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1266 '(0 mdw-number-face))
1267
6132bc01 1268 ;; And anything else is punctuation.
f617db13 1269 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1270 '(0 mdw-punct-face)))))
1271
1272 (mdw-post-config-mode-hack))
f617db13 1273
6132bc01
MW
1274;;;--------------------------------------------------------------------------
1275;;; Java programming configuration.
f617db13 1276
6132bc01 1277;; Make indentation nice.
f617db13
MW
1278
1279(defun mdw-java-style ()
1280 (c-add-style "[mdw] Java style"
1281 '((c-basic-offset . 2)
f617db13
MW
1282 (c-offsets-alist (substatement-open . 0)
1283 (label . +)
1284 (case-label . +)
1285 (access-label . 0)
1286 (inclass . +)
1287 (statement-case-intro . +)))
1288 t))
1289
6132bc01 1290;; Declare Java fontification style.
f617db13
MW
1291
1292(defun mdw-fontify-java ()
1293
6132bc01 1294 ;; Other stuff.
f617db13 1295 (mdw-java-style)
f617db13
MW
1296 (setq c-hanging-comment-ender-p nil)
1297 (setq c-backslash-column 72)
0e7d960b 1298 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
f617db13 1299
6132bc01 1300 ;; Now define things to be fontified.
02109a0d 1301 (make-local-variable 'font-lock-keywords)
f617db13 1302 (let ((java-keywords
8d6d55b9
MW
1303 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1304 "char" "class" "const" "continue" "default" "do"
1305 "double" "else" "extends" "final" "finally" "float"
1306 "for" "goto" "if" "implements" "import" "instanceof"
1307 "int" "interface" "long" "native" "new" "package"
1308 "private" "protected" "public" "return" "short"
1309 "static" "super" "switch" "synchronized" "this"
1310 "throw" "throws" "transient" "try" "void" "volatile"
1311 "while"
1312
1313 "false" "null" "true")))
f617db13
MW
1314
1315 (setq font-lock-keywords
1316 (list
f617db13 1317
6132bc01 1318 ;; Handle the keywords defined above.
f617db13
MW
1319 (list (concat "\\<\\(" java-keywords "\\)\\>")
1320 '(0 font-lock-keyword-face))
1321
6132bc01 1322 ;; Handle numbers too.
f617db13
MW
1323 ;;
1324 ;; The following isn't quite right, but it's close enough.
f617db13
MW
1325 (list (concat "\\<\\("
1326 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1327 "[0-9]+\\(\\.[0-9]*\\|\\)"
1328 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1329 "[lLfFdD]?")
1330 '(0 mdw-number-face))
1331
6132bc01 1332 ;; And anything else is punctuation.
f617db13 1333 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1334 '(0 mdw-punct-face)))))
1335
1336 (mdw-post-config-mode-hack))
f617db13 1337
6132bc01
MW
1338;;;--------------------------------------------------------------------------
1339;;; C# programming configuration.
e808c1e5 1340
6132bc01 1341;; Make indentation nice.
e808c1e5
MW
1342
1343(defun mdw-csharp-style ()
1344 (c-add-style "[mdw] C# style"
1345 '((c-basic-offset . 2)
e808c1e5
MW
1346 (c-offsets-alist (substatement-open . 0)
1347 (label . 0)
1348 (case-label . +)
1349 (access-label . 0)
1350 (inclass . +)
1351 (statement-case-intro . +)))
1352 t))
1353
6132bc01 1354;; Declare C# fontification style.
e808c1e5
MW
1355
1356(defun mdw-fontify-csharp ()
1357
6132bc01 1358 ;; Other stuff.
e808c1e5 1359 (mdw-csharp-style)
e808c1e5
MW
1360 (setq c-hanging-comment-ender-p nil)
1361 (setq c-backslash-column 72)
0e7d960b 1362 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
e808c1e5 1363
6132bc01 1364 ;; Now define things to be fontified.
e808c1e5
MW
1365 (make-local-variable 'font-lock-keywords)
1366 (let ((csharp-keywords
8d6d55b9
MW
1367 (mdw-regexps "abstract" "as" "base" "bool" "break"
1368 "byte" "case" "catch" "char" "checked"
1369 "class" "const" "continue" "decimal" "default"
1370 "delegate" "do" "double" "else" "enum"
1371 "event" "explicit" "extern" "false" "finally"
1372 "fixed" "float" "for" "foreach" "goto"
1373 "if" "implicit" "in" "int" "interface"
1374 "internal" "is" "lock" "long" "namespace"
1375 "new" "null" "object" "operator" "out"
1376 "override" "params" "private" "protected" "public"
1377 "readonly" "ref" "return" "sbyte" "sealed"
1378 "short" "sizeof" "stackalloc" "static" "string"
1379 "struct" "switch" "this" "throw" "true"
1380 "try" "typeof" "uint" "ulong" "unchecked"
1381 "unsafe" "ushort" "using" "virtual" "void"
1382 "volatile" "while" "yield")))
e808c1e5
MW
1383
1384 (setq font-lock-keywords
1385 (list
e808c1e5 1386
6132bc01 1387 ;; Handle the keywords defined above.
e808c1e5
MW
1388 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1389 '(0 font-lock-keyword-face))
1390
6132bc01 1391 ;; Handle numbers too.
e808c1e5
MW
1392 ;;
1393 ;; The following isn't quite right, but it's close enough.
e808c1e5
MW
1394 (list (concat "\\<\\("
1395 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1396 "[0-9]+\\(\\.[0-9]*\\|\\)"
1397 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1398 "[lLfFdD]?")
1399 '(0 mdw-number-face))
1400
6132bc01 1401 ;; And anything else is punctuation.
e808c1e5 1402 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1403 '(0 mdw-punct-face)))))
1404
1405 (mdw-post-config-mode-hack))
e808c1e5 1406
103c5923
MW
1407(define-derived-mode csharp-mode java-mode "C#"
1408 "Major mode for editing C# code.")
e808c1e5 1409
6132bc01 1410;;;--------------------------------------------------------------------------
07965a39
MW
1411;;; Go programming configuration.
1412
1413(defun mdw-fontify-go ()
1414
1415 (make-local-variable 'font-lock-keywords)
1416 (let ((go-keywords
1417 (mdw-regexps "break" "case" "chan" "const" "continue"
1418 "default" "defer" "else" "fallthrough" "for"
1419 "func" "go" "goto" "if" "import"
1420 "interface" "map" "package" "range" "return"
1421 "select" "struct" "switch" "type" "var")))
1422
1423 (setq font-lock-keywords
1424 (list
1425
1426 ;; Handle the keywords defined above.
1427 (list (concat "\\<\\(" go-keywords "\\)\\>")
1428 '(0 font-lock-keyword-face))
1429
1430 ;; Handle numbers too.
1431 ;;
1432 ;; The following isn't quite right, but it's close enough.
1433 (list (concat "\\<\\("
1434 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1435 "[0-9]+\\(\\.[0-9]*\\|\\)"
1436 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
1437 '(0 mdw-number-face))
1438
1439 ;; And anything else is punctuation.
1440 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1441 '(0 mdw-punct-face)))))
1442
1443 (mdw-post-config-mode-hack))
07965a39
MW
1444
1445;;;--------------------------------------------------------------------------
6132bc01 1446;;; Awk programming configuration.
f617db13 1447
6132bc01 1448;; Make Awk indentation nice.
f617db13
MW
1449
1450(defun mdw-awk-style ()
1451 (c-add-style "[mdw] Awk style"
1452 '((c-basic-offset . 2)
f617db13
MW
1453 (c-offsets-alist (substatement-open . 0)
1454 (statement-cont . 0)
1455 (statement-case-intro . +)))
1456 t))
1457
6132bc01 1458;; Declare Awk fontification style.
f617db13
MW
1459
1460(defun mdw-fontify-awk ()
1461
6132bc01 1462 ;; Miscellaneous fiddling.
f617db13
MW
1463 (mdw-awk-style)
1464 (setq c-backslash-column 72)
1465 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1466
6132bc01 1467 ;; Now define things to be fontified.
02109a0d 1468 (make-local-variable 'font-lock-keywords)
f617db13 1469 (let ((c-keywords
8d6d55b9
MW
1470 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1471 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1472 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1473 "RSTART" "RLENGTH" "RT" "SUBSEP"
1474 "atan2" "break" "close" "continue" "cos" "delete"
1475 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1476 "function" "gensub" "getline" "gsub" "if" "in"
1477 "index" "int" "length" "log" "match" "next" "rand"
1478 "return" "print" "printf" "sin" "split" "sprintf"
1479 "sqrt" "srand" "strftime" "sub" "substr" "system"
1480 "systime" "tolower" "toupper" "while")))
f617db13
MW
1481
1482 (setq font-lock-keywords
1483 (list
f617db13 1484
6132bc01 1485 ;; Handle the keywords defined above.
f617db13
MW
1486 (list (concat "\\<\\(" c-keywords "\\)\\>")
1487 '(0 font-lock-keyword-face))
1488
6132bc01 1489 ;; Handle numbers too.
f617db13
MW
1490 ;;
1491 ;; The following isn't quite right, but it's close enough.
f617db13
MW
1492 (list (concat "\\<\\("
1493 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1494 "[0-9]+\\(\\.[0-9]*\\|\\)"
1495 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1496 "[uUlL]*")
1497 '(0 mdw-number-face))
1498
6132bc01 1499 ;; And anything else is punctuation.
f617db13 1500 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1501 '(0 mdw-punct-face)))))
1502
1503 (mdw-post-config-mode-hack))
f617db13 1504
6132bc01
MW
1505;;;--------------------------------------------------------------------------
1506;;; Perl programming style.
f617db13 1507
6132bc01 1508;; Perl indentation style.
f617db13 1509
f617db13
MW
1510(setq cperl-indent-level 2)
1511(setq cperl-continued-statement-offset 2)
1512(setq cperl-continued-brace-offset 0)
1513(setq cperl-brace-offset -2)
1514(setq cperl-brace-imaginary-offset 0)
1515(setq cperl-label-offset 0)
1516
6132bc01 1517;; Define perl fontification style.
f617db13
MW
1518
1519(defun mdw-fontify-perl ()
1520
6132bc01 1521 ;; Miscellaneous fiddling.
f617db13
MW
1522 (modify-syntax-entry ?$ "\\")
1523 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1524 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1525
6132bc01 1526 ;; Now define fontification things.
02109a0d 1527 (make-local-variable 'font-lock-keywords)
f617db13 1528 (let ((perl-keywords
8d6d55b9
MW
1529 (mdw-regexps "and" "cmp" "continue" "do" "else" "elsif" "eq"
1530 "for" "foreach" "ge" "gt" "goto" "if"
1531 "last" "le" "lt" "local" "my" "ne" "next" "or"
1532 "package" "redo" "require" "return" "sub"
1533 "undef" "unless" "until" "use" "while")))
f617db13
MW
1534
1535 (setq font-lock-keywords
1536 (list
f617db13 1537
6132bc01 1538 ;; Set up the keywords defined above.
f617db13
MW
1539 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1540 '(0 font-lock-keyword-face))
1541
6132bc01 1542 ;; At least numbers are simpler than C.
f617db13
MW
1543 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1544 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1545 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1546 '(0 mdw-number-face))
1547
6132bc01 1548 ;; And anything else is punctuation.
f617db13 1549 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1550 '(0 mdw-punct-face)))))
1551
1552 (mdw-post-config-mode-hack))
f617db13
MW
1553
1554(defun perl-number-tests (&optional arg)
1555 "Assign consecutive numbers to lines containing `#t'. With ARG,
1556strip numbers instead."
1557 (interactive "P")
1558 (save-excursion
1559 (goto-char (point-min))
1560 (let ((i 0) (fmt (if arg "" " %4d")))
1561 (while (search-forward "#t" nil t)
1562 (delete-region (point) (line-end-position))
1563 (setq i (1+ i))
1564 (insert (format fmt i)))
1565 (goto-char (point-min))
1566 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1567 (replace-match (format "\\1%d" i))))))
1568
6132bc01
MW
1569;;;--------------------------------------------------------------------------
1570;;; Python programming style.
f617db13 1571
99fe6ef5 1572(defun mdw-fontify-pythonic (keywords)
f617db13 1573
6132bc01 1574 ;; Miscellaneous fiddling.
f617db13 1575 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
7c0fcfde 1576 (setq indent-tabs-mode nil)
f617db13 1577
6132bc01 1578 ;; Now define fontification things.
02109a0d 1579 (make-local-variable 'font-lock-keywords)
99fe6ef5
MW
1580 (setq font-lock-keywords
1581 (list
f617db13 1582
be2cc788 1583 ;; Set up the keywords defined above.
29826b11 1584 (list (concat "\\<\\(" keywords "\\)\\>")
99fe6ef5 1585 '(0 font-lock-keyword-face))
f617db13 1586
be2cc788 1587 ;; At least numbers are simpler than C.
99fe6ef5
MW
1588 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1589 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1590 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1591 '(0 mdw-number-face))
f617db13 1592
be2cc788 1593 ;; And anything else is punctuation.
99fe6ef5 1594 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1595 '(0 mdw-punct-face))))
1596
1597 (mdw-post-config-mode-hack))
99fe6ef5 1598
be2cc788 1599;; Define Python fontification styles.
99fe6ef5
MW
1600
1601(defun mdw-fontify-python ()
1602 (mdw-fontify-pythonic
1603 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
1604 "del" "elif" "else" "except" "exec" "finally" "for"
1605 "from" "global" "if" "import" "in" "is" "lambda"
1606 "not" "or" "pass" "print" "raise" "return" "try"
1607 "while" "with" "yield")))
1608
1609(defun mdw-fontify-pyrex ()
1610 (mdw-fontify-pythonic
1611 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
1612 "ctypedef" "def" "del" "elif" "else" "except" "exec"
1613 "extern" "finally" "for" "from" "global" "if"
1614 "import" "in" "is" "lambda" "not" "or" "pass" "print"
1615 "raise" "return" "struct" "try" "while" "with"
1616 "yield")))
f617db13 1617
6132bc01
MW
1618;;;--------------------------------------------------------------------------
1619;;; Icon programming style.
cc1980e1 1620
6132bc01 1621;; Icon indentation style.
cc1980e1
MW
1622
1623(setq icon-brace-offset 0
1624 icon-continued-brace-offset 0
1625 icon-continued-statement-offset 2
1626 icon-indent-level 2)
1627
6132bc01 1628;; Define Icon fontification style.
cc1980e1
MW
1629
1630(defun mdw-fontify-icon ()
1631
6132bc01 1632 ;; Miscellaneous fiddling.
cc1980e1
MW
1633 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1634
6132bc01 1635 ;; Now define fontification things.
cc1980e1
MW
1636 (make-local-variable 'font-lock-keywords)
1637 (let ((icon-keywords
1638 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
1639 "end" "every" "fail" "global" "if" "initial"
1640 "invocable" "link" "local" "next" "not" "of"
1641 "procedure" "record" "repeat" "return" "static"
1642 "suspend" "then" "to" "until" "while"))
1643 (preprocessor-keywords
1644 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
1645 "include" "line" "undef")))
1646 (setq font-lock-keywords
1647 (list
1648
6132bc01 1649 ;; Set up the keywords defined above.
cc1980e1
MW
1650 (list (concat "\\<\\(" icon-keywords "\\)\\>")
1651 '(0 font-lock-keyword-face))
1652
6132bc01 1653 ;; The things that Icon calls keywords.
cc1980e1
MW
1654 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
1655
6132bc01 1656 ;; At least numbers are simpler than C.
cc1980e1
MW
1657 (list (concat "\\<[0-9]+"
1658 "\\([rR][0-9a-zA-Z]+\\|"
1659 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
1660 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
1661 '(0 mdw-number-face))
1662
6132bc01 1663 ;; Preprocessor.
cc1980e1
MW
1664 (list (concat "^[ \t]*$[ \t]*\\<\\("
1665 preprocessor-keywords
1666 "\\)\\>")
1667 '(0 font-lock-keyword-face))
1668
6132bc01 1669 ;; And anything else is punctuation.
cc1980e1 1670 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1671 '(0 mdw-punct-face)))))
1672
1673 (mdw-post-config-mode-hack))
cc1980e1 1674
6132bc01
MW
1675;;;--------------------------------------------------------------------------
1676;;; ARM assembler programming configuration.
f617db13 1677
6132bc01 1678;; There doesn't appear to be an Emacs mode for this yet.
f617db13
MW
1679;;
1680;; Better do something about that, I suppose.
1681
1682(defvar arm-assembler-mode-map nil)
1683(defvar arm-assembler-abbrev-table nil)
1684(defvar arm-assembler-mode-syntax-table (make-syntax-table))
1685
1686(or arm-assembler-mode-map
1687 (progn
1688 (setq arm-assembler-mode-map (make-sparse-keymap))
1689 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1690 (define-key arm-assembler-mode-map [C-return] 'newline)
1691 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1692
1693(defun arm-assembler-mode ()
1694 "Major mode for ARM assembler programs"
1695 (interactive)
1696
6132bc01 1697 ;; Do standard major mode things.
f617db13
MW
1698 (kill-all-local-variables)
1699 (use-local-map arm-assembler-mode-map)
1700 (setq local-abbrev-table arm-assembler-abbrev-table)
1701 (setq major-mode 'arm-assembler-mode)
1702 (setq mode-name "ARM assembler")
1703
6132bc01 1704 ;; Set up syntax table.
f617db13
MW
1705 (set-syntax-table arm-assembler-mode-syntax-table)
1706 (modify-syntax-entry ?; ; Nasty hack
1707 "<" arm-assembler-mode-syntax-table)
1708 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1709 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1710
1711 (make-local-variable 'comment-start)
1712 (setq comment-start ";")
1713 (make-local-variable 'comment-end)
1714 (setq comment-end "")
1715 (make-local-variable 'comment-column)
1716 (setq comment-column 48)
1717 (make-local-variable 'comment-start-skip)
1718 (setq comment-start-skip ";+[ \t]*")
1719
6132bc01 1720 ;; Play with indentation.
f617db13
MW
1721 (make-local-variable 'indent-line-function)
1722 (setq indent-line-function 'indent-relative-maybe)
1723
6132bc01 1724 ;; Set fill prefix.
f617db13
MW
1725 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1726
6132bc01 1727 ;; Fiddle with fontification.
02109a0d 1728 (make-local-variable 'font-lock-keywords)
f617db13
MW
1729 (setq font-lock-keywords
1730 (list
f617db13 1731
6132bc01 1732 ;; Handle numbers too.
f617db13
MW
1733 ;;
1734 ;; The following isn't quite right, but it's close enough.
f617db13
MW
1735 (list (concat "\\("
1736 "&[0-9a-fA-F]+\\|"
1737 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1738 "\\)")
1739 '(0 mdw-number-face))
1740
6132bc01 1741 ;; Do something about operators.
f617db13
MW
1742 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1743 '(1 font-lock-keyword-face)
1744 '(2 font-lock-string-face))
1745 (list ":[a-zA-Z]+:"
1746 '(0 font-lock-keyword-face))
1747
6132bc01 1748 ;; Do menemonics and directives.
f617db13
MW
1749 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1750 '(1 font-lock-keyword-face))
1751
6132bc01 1752 ;; And anything else is punctuation.
f617db13 1753 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9 1754 '(0 mdw-punct-face)))
f617db13 1755
ed7b46b9 1756 (mdw-post-config-mode-hack))
f617db13
MW
1757 (run-hooks 'arm-assembler-mode-hook))
1758
6132bc01
MW
1759;;;--------------------------------------------------------------------------
1760;;; Assembler mode.
30c8a8fb
MW
1761
1762(defun mdw-fontify-asm ()
1763 (modify-syntax-entry ?' "\"")
1764 (modify-syntax-entry ?. "w")
1765 (setf fill-prefix nil)
1766 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
1767
6132bc01
MW
1768;;;--------------------------------------------------------------------------
1769;;; TCL configuration.
f617db13
MW
1770
1771(defun mdw-fontify-tcl ()
1772 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1773 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
02109a0d 1774 (make-local-variable 'font-lock-keywords)
f617db13
MW
1775 (setq font-lock-keywords
1776 (list
f617db13
MW
1777 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1778 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1779 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1780 '(0 mdw-number-face))
1781 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1782 '(0 mdw-punct-face))))
1783 (mdw-post-config-mode-hack))
f617db13 1784
6132bc01
MW
1785;;;--------------------------------------------------------------------------
1786;;; REXX configuration.
f617db13
MW
1787
1788(defun mdw-rexx-electric-* ()
1789 (interactive)
1790 (insert ?*)
1791 (rexx-indent-line))
1792
1793(defun mdw-rexx-indent-newline-indent ()
1794 (interactive)
1795 (rexx-indent-line)
1796 (if abbrev-mode (expand-abbrev))
1797 (newline-and-indent))
1798
1799(defun mdw-fontify-rexx ()
1800
6132bc01 1801 ;; Various bits of fiddling.
f617db13
MW
1802 (setq mdw-auto-indent nil)
1803 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1804 (local-set-key [?*] 'mdw-rexx-electric-*)
1805 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
e443a4cd 1806 '(?! ?? ?# ?@ ?$))
f617db13
MW
1807 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1808
6132bc01 1809 ;; Set up keywords and things for fontification.
f617db13
MW
1810 (make-local-variable 'font-lock-keywords-case-fold-search)
1811 (setq font-lock-keywords-case-fold-search t)
1812
1813 (setq rexx-indent 2)
1814 (setq rexx-end-indent rexx-indent)
f617db13
MW
1815 (setq rexx-cont-indent rexx-indent)
1816
02109a0d 1817 (make-local-variable 'font-lock-keywords)
f617db13 1818 (let ((rexx-keywords
8d6d55b9
MW
1819 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
1820 "else" "end" "engineering" "exit" "expose" "for"
1821 "forever" "form" "fuzz" "if" "interpret" "iterate"
1822 "leave" "linein" "name" "nop" "numeric" "off" "on"
1823 "options" "otherwise" "parse" "procedure" "pull"
1824 "push" "queue" "return" "say" "select" "signal"
1825 "scientific" "source" "then" "trace" "to" "until"
1826 "upper" "value" "var" "version" "when" "while"
1827 "with"
1828
1829 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1830 "center" "center" "charin" "charout" "chars"
1831 "compare" "condition" "copies" "c2d" "c2x"
1832 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1833 "errortext" "format" "fuzz" "insert" "lastpos"
1834 "left" "length" "lineout" "lines" "max" "min"
1835 "overlay" "pos" "queued" "random" "reverse" "right"
1836 "sign" "sourceline" "space" "stream" "strip"
1837 "substr" "subword" "symbol" "time" "translate"
1838 "trunc" "value" "verify" "word" "wordindex"
1839 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1840 "x2d")))
f617db13
MW
1841
1842 (setq font-lock-keywords
1843 (list
f617db13 1844
6132bc01 1845 ;; Set up the keywords defined above.
f617db13
MW
1846 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1847 '(0 font-lock-keyword-face))
1848
6132bc01 1849 ;; Fontify all symbols the same way.
f617db13
MW
1850 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1851 "[A-Za-z0-9.!?_#@$]+\\)")
1852 '(0 font-lock-variable-name-face))
1853
6132bc01 1854 ;; And everything else is punctuation.
f617db13 1855 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1856 '(0 mdw-punct-face)))))
1857
1858 (mdw-post-config-mode-hack))
f617db13 1859
6132bc01
MW
1860;;;--------------------------------------------------------------------------
1861;;; Standard ML programming style.
f617db13
MW
1862
1863(defun mdw-fontify-sml ()
1864
6132bc01 1865 ;; Make underscore an honorary letter.
f617db13
MW
1866 (modify-syntax-entry ?' "w")
1867
6132bc01 1868 ;; Set fill prefix.
f617db13
MW
1869 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1870
6132bc01 1871 ;; Now define fontification things.
02109a0d 1872 (make-local-variable 'font-lock-keywords)
f617db13 1873 (let ((sml-keywords
8d6d55b9
MW
1874 (mdw-regexps "abstype" "and" "andalso" "as"
1875 "case"
1876 "datatype" "do"
1877 "else" "end" "eqtype" "exception"
1878 "fn" "fun" "functor"
1879 "handle"
1880 "if" "in" "include" "infix" "infixr"
1881 "let" "local"
1882 "nonfix"
1883 "of" "op" "open" "orelse"
1884 "raise" "rec"
1885 "sharing" "sig" "signature" "struct" "structure"
1886 "then" "type"
1887 "val"
1888 "where" "while" "with" "withtype")))
f617db13
MW
1889
1890 (setq font-lock-keywords
1891 (list
f617db13 1892
6132bc01 1893 ;; Set up the keywords defined above.
f617db13
MW
1894 (list (concat "\\<\\(" sml-keywords "\\)\\>")
1895 '(0 font-lock-keyword-face))
1896
6132bc01 1897 ;; At least numbers are simpler than C.
f617db13
MW
1898 (list (concat "\\<\\(\\~\\|\\)"
1899 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
852cd5fb
MW
1900 "[wW][0-9]+\\)\\|"
1901 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
1902 "\\([eE]\\(\\~\\|\\)"
1903 "[0-9]+\\|\\)\\)\\)")
f617db13
MW
1904 '(0 mdw-number-face))
1905
6132bc01 1906 ;; And anything else is punctuation.
f617db13 1907 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1908 '(0 mdw-punct-face)))))
1909
1910 (mdw-post-config-mode-hack))
f617db13 1911
6132bc01
MW
1912;;;--------------------------------------------------------------------------
1913;;; Haskell configuration.
f617db13
MW
1914
1915(defun mdw-fontify-haskell ()
1916
6132bc01 1917 ;; Fiddle with syntax table to get comments right.
f617db13
MW
1918 (modify-syntax-entry ?' "\"")
1919 (modify-syntax-entry ?- ". 123")
1920 (modify-syntax-entry ?{ ". 1b")
1921 (modify-syntax-entry ?} ". 4b")
1922 (modify-syntax-entry ?\n ">")
1923
6132bc01 1924 ;; Set fill prefix.
f617db13
MW
1925 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
1926
6132bc01 1927 ;; Fiddle with fontification.
02109a0d 1928 (make-local-variable 'font-lock-keywords)
f617db13 1929 (let ((haskell-keywords
8d6d55b9
MW
1930 (mdw-regexps "as" "case" "ccall" "class" "data" "default"
1931 "deriving" "do" "else" "foreign" "hiding" "if"
1932 "import" "in" "infix" "infixl" "infixr" "instance"
1933 "let" "module" "newtype" "of" "qualified" "safe"
1934 "stdcall" "then" "type" "unsafe" "where")))
f617db13
MW
1935
1936 (setq font-lock-keywords
1937 (list
f617db13
MW
1938 (list "--.*$"
1939 '(0 font-lock-comment-face))
1940 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
1941 '(0 font-lock-keyword-face))
1942 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1943 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
1944 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
1945 '(0 mdw-number-face))
1946 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1947 '(0 mdw-punct-face)))))
1948
1949 (mdw-post-config-mode-hack))
f617db13 1950
6132bc01
MW
1951;;;--------------------------------------------------------------------------
1952;;; Erlang configuration.
2ded9493 1953
52941dec 1954(setq erlang-electric-commands nil)
2ded9493
MW
1955
1956(defun mdw-fontify-erlang ()
1957
6132bc01 1958 ;; Set fill prefix.
2ded9493
MW
1959 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
1960
6132bc01 1961 ;; Fiddle with fontification.
2ded9493
MW
1962 (make-local-variable 'font-lock-keywords)
1963 (let ((erlang-keywords
1964 (mdw-regexps "after" "and" "andalso"
1965 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
1966 "case" "catch" "cond"
1967 "div" "end" "fun" "if" "let" "not"
1968 "of" "or" "orelse"
1969 "query" "receive" "rem" "try" "when" "xor")))
1970
1971 (setq font-lock-keywords
1972 (list
1973 (list "%.*$"
1974 '(0 font-lock-comment-face))
1975 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
1976 '(0 font-lock-keyword-face))
1977 (list (concat "^-\\sw+\\>")
1978 '(0 font-lock-keyword-face))
1979 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
1980 '(0 mdw-number-face))
1981 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
1982 '(0 mdw-punct-face)))))
1983
1984 (mdw-post-config-mode-hack))
2ded9493 1985
6132bc01
MW
1986;;;--------------------------------------------------------------------------
1987;;; Texinfo configuration.
f617db13
MW
1988
1989(defun mdw-fontify-texinfo ()
1990
6132bc01 1991 ;; Set fill prefix.
f617db13
MW
1992 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
1993
6132bc01 1994 ;; Real fontification things.
02109a0d 1995 (make-local-variable 'font-lock-keywords)
f617db13
MW
1996 (setq font-lock-keywords
1997 (list
f617db13 1998
6132bc01 1999 ;; Environment names are keywords.
f617db13
MW
2000 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
2001 '(2 font-lock-keyword-face))
2002
6132bc01 2003 ;; Unmark escaped magic characters.
f617db13
MW
2004 (list "\\(@\\)\\([@{}]\\)"
2005 '(1 font-lock-keyword-face)
2006 '(2 font-lock-variable-name-face))
2007
6132bc01 2008 ;; Make sure we get comments properly.
f617db13
MW
2009 (list "@c\\(\\|omment\\)\\( .*\\)?$"
2010 '(0 font-lock-comment-face))
2011
6132bc01 2012 ;; Command names are keywords.
f617db13
MW
2013 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
2014 '(0 font-lock-keyword-face))
2015
6132bc01 2016 ;; Fontify TeX special characters as punctuation.
f617db13 2017 (list "[{}]+"
ed7b46b9
MW
2018 '(0 mdw-punct-face))))
2019
2020 (mdw-post-config-mode-hack))
f617db13 2021
6132bc01
MW
2022;;;--------------------------------------------------------------------------
2023;;; TeX and LaTeX configuration.
f617db13
MW
2024
2025(defun mdw-fontify-tex ()
2026 (setq ispell-parser 'tex)
55f80fae 2027 (turn-on-reftex)
f617db13 2028
6132bc01 2029 ;; Don't make maths into a string.
f617db13
MW
2030 (modify-syntax-entry ?$ ".")
2031 (modify-syntax-entry ?$ "." font-lock-syntax-table)
2032 (local-set-key [?$] 'self-insert-command)
2033
6132bc01 2034 ;; Set fill prefix.
f617db13
MW
2035 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
2036
6132bc01 2037 ;; Real fontification things.
02109a0d 2038 (make-local-variable 'font-lock-keywords)
f617db13
MW
2039 (setq font-lock-keywords
2040 (list
f617db13 2041
6132bc01 2042 ;; Environment names are keywords.
f617db13
MW
2043 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
2044 "{\\([^}\n]*\\)}")
2045 '(2 font-lock-keyword-face))
2046
6132bc01 2047 ;; Suspended environment names are keywords too.
f617db13
MW
2048 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
2049 "{\\([^}\n]*\\)}")
2050 '(3 font-lock-keyword-face))
2051
6132bc01 2052 ;; Command names are keywords.
f617db13
MW
2053 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
2054 '(0 font-lock-keyword-face))
2055
6132bc01 2056 ;; Handle @/.../ for italics.
f617db13 2057 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
852cd5fb
MW
2058 ;; '(1 font-lock-keyword-face)
2059 ;; '(3 font-lock-keyword-face))
f617db13 2060
6132bc01 2061 ;; Handle @*...* for boldness.
f617db13 2062 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
852cd5fb
MW
2063 ;; '(1 font-lock-keyword-face)
2064 ;; '(3 font-lock-keyword-face))
f617db13 2065
6132bc01 2066 ;; Handle @`...' for literal syntax things.
f617db13 2067 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
852cd5fb
MW
2068 ;; '(1 font-lock-keyword-face)
2069 ;; '(3 font-lock-keyword-face))
f617db13 2070
6132bc01 2071 ;; Handle @<...> for nonterminals.
f617db13 2072 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
852cd5fb
MW
2073 ;; '(1 font-lock-keyword-face)
2074 ;; '(3 font-lock-keyword-face))
f617db13 2075
6132bc01 2076 ;; Handle other @-commands.
f617db13 2077 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
852cd5fb 2078 ;; '(0 font-lock-keyword-face))
f617db13 2079
6132bc01 2080 ;; Make sure we get comments properly.
f617db13
MW
2081 (list "%.*"
2082 '(0 font-lock-comment-face))
2083
6132bc01 2084 ;; Fontify TeX special characters as punctuation.
f617db13 2085 (list "[$^_{}#&]"
ed7b46b9
MW
2086 '(0 mdw-punct-face))))
2087
2088 (mdw-post-config-mode-hack))
f617db13 2089
6132bc01
MW
2090;;;--------------------------------------------------------------------------
2091;;; SGML hacking.
f25cf300
MW
2092
2093(defun mdw-sgml-mode ()
2094 (interactive)
2095 (sgml-mode)
2096 (mdw-standard-fill-prefix "")
8a425bd7 2097 (make-local-variable 'sgml-delimiters)
f25cf300
MW
2098 (setq sgml-delimiters
2099 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
2100 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
2101 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
2102 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
2103 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
2104 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
2105 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
2106 "NULL" ""))
2107 (setq major-mode 'mdw-sgml-mode)
2108 (setq mode-name "[mdw] SGML")
2109 (run-hooks 'mdw-sgml-mode-hook))
2110
6132bc01
MW
2111;;;--------------------------------------------------------------------------
2112;;; Shell scripts.
f617db13
MW
2113
2114(defun mdw-setup-sh-script-mode ()
2115
6132bc01 2116 ;; Fetch the shell interpreter's name.
f617db13
MW
2117 (let ((shell-name sh-shell-file))
2118
6132bc01 2119 ;; Try reading the hash-bang line.
f617db13
MW
2120 (save-excursion
2121 (goto-char (point-min))
2122 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
2123 (setq shell-name (match-string 1))))
2124
6132bc01 2125 ;; Now try to set the shell.
f617db13
MW
2126 ;;
2127 ;; Don't let `sh-set-shell' bugger up my script.
f617db13
MW
2128 (let ((executable-set-magic #'(lambda (s &rest r) s)))
2129 (sh-set-shell shell-name)))
2130
6132bc01 2131 ;; Now enable my keys and the fontification.
f617db13
MW
2132 (mdw-misc-mode-config)
2133
6132bc01 2134 ;; Set the indentation level correctly.
f617db13
MW
2135 (setq sh-indentation 2)
2136 (setq sh-basic-offset 2))
2137
6132bc01 2138;;;--------------------------------------------------------------------------
092f0a38
MW
2139;;; Emacs shell mode.
2140
2141(defun mdw-eshell-prompt ()
2142 (let ((left "[") (right "]"))
2143 (when (= (user-uid) 0)
2144 (setq left "«" right "»"))
2145 (concat left
2146 (save-match-data
2147 (replace-regexp-in-string "\\..*$" "" (system-name)))
2148 " "
2d8b2924
MW
2149 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
2150 (home (expand-file-name "~")) (nhome (length home)))
2151 (if (and (>= npwd nhome)
2152 (or (= nhome npwd)
5801e199
MW
2153 (= (elt pwd nhome) ?/))
2154 (string= (substring pwd 0 nhome) home))
2d8b2924
MW
2155 (concat "~" (substring pwd (length home)))
2156 pwd))
092f0a38
MW
2157 right)))
2158(setq eshell-prompt-function 'mdw-eshell-prompt)
ac4ae7cd 2159(setq eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
092f0a38 2160
2d8b2924
MW
2161(defun eshell/e (file) (find-file file) nil)
2162(defun eshell/ee (file) (find-file-other-window file) nil)
2163(defun eshell/w3m (url) (w3m-goto-url url) nil)
415a23dd 2164
092f0a38
MW
2165(mdw-define-face eshell-prompt (t :weight bold))
2166(mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
2167(mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
2168(mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
2169(mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
2170(mdw-define-face eshell-ls-executable (t :weight bold))
2171(mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
2172(mdw-define-face eshell-ls-readonly (t nil))
2173(mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
2174
2175;;;--------------------------------------------------------------------------
6132bc01 2176;;; Messages-file mode.
f617db13 2177
4bb22eea 2178(defun messages-mode-guts ()
f617db13
MW
2179 (setq messages-mode-syntax-table (make-syntax-table))
2180 (set-syntax-table messages-mode-syntax-table)
f617db13
MW
2181 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
2182 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
2183 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
2184 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
2185 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
2186 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
2187 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
2188 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
2189 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
2190 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
2191 (make-local-variable 'comment-start)
2192 (make-local-variable 'comment-end)
2193 (make-local-variable 'indent-line-function)
2194 (setq indent-line-function 'indent-relative)
2195 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2196 (make-local-variable 'font-lock-defaults)
4bb22eea 2197 (make-local-variable 'messages-mode-keywords)
f617db13 2198 (let ((keywords
8d6d55b9
MW
2199 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
2200 "export" "enum" "fixed-octetstring" "flags"
2201 "harmless" "map" "nested" "optional"
2202 "optional-tagged" "package" "primitive"
2203 "primitive-nullfree" "relaxed[ \t]+enum"
2204 "set" "table" "tagged-optional" "union"
2205 "variadic" "vector" "version" "version-tag")))
4bb22eea 2206 (setq messages-mode-keywords
f617db13
MW
2207 (list
2208 (list (concat "\\<\\(" keywords "\\)\\>:")
2209 '(0 font-lock-keyword-face))
2210 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
2211 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
2212 (0 font-lock-variable-name-face))
2213 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
2214 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2215 (0 mdw-punct-face)))))
2216 (setq font-lock-defaults
4bb22eea 2217 '(messages-mode-keywords nil nil nil nil))
f617db13
MW
2218 (run-hooks 'messages-file-hook))
2219
2220(defun messages-mode ()
2221 (interactive)
2222 (fundamental-mode)
2223 (setq major-mode 'messages-mode)
2224 (setq mode-name "Messages")
4bb22eea 2225 (messages-mode-guts)
f617db13
MW
2226 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
2227 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
2228 (setq comment-start "# ")
2229 (setq comment-end "")
f617db13
MW
2230 (run-hooks 'messages-mode-hook))
2231
2232(defun cpp-messages-mode ()
2233 (interactive)
2234 (fundamental-mode)
2235 (setq major-mode 'cpp-messages-mode)
2236 (setq mode-name "CPP Messages")
4bb22eea 2237 (messages-mode-guts)
f617db13
MW
2238 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
2239 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
2240 (setq comment-start "/* ")
2241 (setq comment-end " */")
2242 (let ((preprocessor-keywords
8d6d55b9
MW
2243 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2244 "ident" "if" "ifdef" "ifndef" "import" "include"
2245 "line" "pragma" "unassert" "undef" "warning")))
4bb22eea 2246 (setq messages-mode-keywords
f617db13
MW
2247 (append (list (list (concat "^[ \t]*\\#[ \t]*"
2248 "\\(include\\|import\\)"
2249 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2250 '(2 font-lock-string-face))
2251 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2252 preprocessor-keywords
852cd5fb 2253 "\\)\\>\\|[0-9]+\\|$\\)\\)")
f617db13 2254 '(1 font-lock-keyword-face)))
4bb22eea 2255 messages-mode-keywords)))
297d60aa 2256 (run-hooks 'cpp-messages-mode-hook))
f617db13 2257
297d60aa
MW
2258(add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
2259(add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
f617db13
MW
2260; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
2261
6132bc01
MW
2262;;;--------------------------------------------------------------------------
2263;;; Messages-file mode.
f617db13
MW
2264
2265(defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
2266 "Face to use for subsittution directives.")
2267(make-face 'mallow-driver-substitution-face)
2268(defvar mallow-driver-text-face 'mallow-driver-text-face
2269 "Face to use for body text.")
2270(make-face 'mallow-driver-text-face)
2271
2272(defun mallow-driver-mode ()
2273 (interactive)
2274 (fundamental-mode)
2275 (setq major-mode 'mallow-driver-mode)
2276 (setq mode-name "Mallow driver")
2277 (setq mallow-driver-mode-syntax-table (make-syntax-table))
2278 (set-syntax-table mallow-driver-mode-syntax-table)
2279 (make-local-variable 'comment-start)
2280 (make-local-variable 'comment-end)
2281 (make-local-variable 'indent-line-function)
2282 (setq indent-line-function 'indent-relative)
2283 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2284 (make-local-variable 'font-lock-defaults)
2285 (make-local-variable 'mallow-driver-mode-keywords)
2286 (let ((keywords
8d6d55b9
MW
2287 (mdw-regexps "each" "divert" "file" "if"
2288 "perl" "set" "string" "type" "write")))
f617db13
MW
2289 (setq mallow-driver-mode-keywords
2290 (list
2291 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
2292 '(0 font-lock-keyword-face))
2293 (list "^%\\s *\\(#.*\\|\\)$"
2294 '(0 font-lock-comment-face))
2295 (list "^%"
2296 '(0 font-lock-keyword-face))
2297 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
2298 (list "\\${[^}]*}"
2299 '(0 mallow-driver-substitution-face t)))))
2300 (setq font-lock-defaults
2301 '(mallow-driver-mode-keywords nil nil nil nil))
2302 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
2303 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
2304 (setq comment-start "%# ")
2305 (setq comment-end "")
f617db13
MW
2306 (run-hooks 'mallow-driver-mode-hook))
2307
2308(add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
2309
6132bc01
MW
2310;;;--------------------------------------------------------------------------
2311;;; NFast debugs.
f617db13
MW
2312
2313(defun nfast-debug-mode ()
2314 (interactive)
2315 (fundamental-mode)
2316 (setq major-mode 'nfast-debug-mode)
2317 (setq mode-name "NFast debug")
2318 (setq messages-mode-syntax-table (make-syntax-table))
2319 (set-syntax-table messages-mode-syntax-table)
2320 (make-local-variable 'font-lock-defaults)
2321 (make-local-variable 'nfast-debug-mode-keywords)
2322 (setq truncate-lines t)
2323 (setq nfast-debug-mode-keywords
2324 (list
2325 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
2326 (0 font-lock-keyword-face))
2327 (list (concat "^[ \t]+\\(\\("
2328 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2329 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2330 "[ \t]+\\)*"
2331 "[0-9a-fA-F]+\\)[ \t]*$")
2332 '(0 mdw-number-face))
2333 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
2334 (1 font-lock-keyword-face))
2335 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
2336 (1 font-lock-warning-face))
2337 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
2338 (1 nil))
2339 (list (concat "^[ \t]+\\.cmd=[ \t]+"
2340 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
2341 '(1 font-lock-keyword-face))
2342 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
2343 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
2344 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
2345 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
2346 (setq font-lock-defaults
2347 '(nfast-debug-mode-keywords nil nil nil nil))
f617db13
MW
2348 (run-hooks 'nfast-debug-mode-hook))
2349
6132bc01
MW
2350;;;--------------------------------------------------------------------------
2351;;; Other languages.
f617db13 2352
6132bc01 2353;; Smalltalk.
f617db13
MW
2354
2355(defun mdw-setup-smalltalk ()
2356 (and mdw-auto-indent
2357 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
8a425bd7 2358 (make-local-variable 'mdw-auto-indent)
f617db13
MW
2359 (setq mdw-auto-indent nil)
2360 (local-set-key "\C-i" 'smalltalk-reindent))
2361
2362(defun mdw-fontify-smalltalk ()
02109a0d 2363 (make-local-variable 'font-lock-keywords)
f617db13
MW
2364 (setq font-lock-keywords
2365 (list
f617db13
MW
2366 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
2367 '(0 font-lock-keyword-face))
2368 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2369 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2370 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2371 '(0 mdw-number-face))
2372 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
2373 '(0 mdw-punct-face))))
2374 (mdw-post-config-mode-hack))
f617db13 2375
6132bc01 2376;; Lispy languages.
f617db13 2377
873d87df
MW
2378;; Unpleasant bodge.
2379(unless (boundp 'slime-repl-mode-map)
2380 (setq slime-repl-mode-map (make-sparse-keymap)))
2381
f617db13
MW
2382(defun mdw-indent-newline-and-indent ()
2383 (interactive)
2384 (indent-for-tab-command)
2385 (newline-and-indent))
2386
2387(eval-after-load "cl-indent"
2388 '(progn
2389 (mapc #'(lambda (pair)
2390 (put (car pair)
2391 'common-lisp-indent-function
2392 (cdr pair)))
2393 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
2394 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
2395
2396(defun mdw-common-lisp-indent ()
8a425bd7 2397 (make-local-variable 'lisp-indent-function)
f617db13
MW
2398 (setq lisp-indent-function 'common-lisp-indent-function))
2399
037be6de 2400(setq lisp-simple-loop-indentation 2
95575d1f
MW
2401 lisp-loop-keyword-indentation 6
2402 lisp-loop-forms-indentation 6)
2403
f617db13
MW
2404(defun mdw-fontify-lispy ()
2405
6132bc01 2406 ;; Set fill prefix.
f617db13
MW
2407 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
2408
6132bc01 2409 ;; Not much fontification needed.
02109a0d 2410 (make-local-variable 'font-lock-keywords)
f617db13
MW
2411 (setq font-lock-keywords
2412 (list
f617db13 2413 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
ed7b46b9
MW
2414 '(0 mdw-punct-face))))
2415
2416 (mdw-post-config-mode-hack))
f617db13
MW
2417
2418(defun comint-send-and-indent ()
2419 (interactive)
2420 (comint-send-input)
2421 (and mdw-auto-indent
2422 (indent-for-tab-command)))
2423
ec007bea
MW
2424(defun mdw-setup-m4 ()
2425 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
2426
6132bc01
MW
2427;;;--------------------------------------------------------------------------
2428;;; Text mode.
f617db13
MW
2429
2430(defun mdw-text-mode ()
2431 (setq fill-column 72)
2432 (flyspell-mode t)
2433 (mdw-standard-fill-prefix
c7a8da49 2434 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
f617db13
MW
2435 (auto-fill-mode 1))
2436
6132bc01 2437;;;--------------------------------------------------------------------------
faf2cef7 2438;;; Outline and hide/show modes.
5de5db48
MW
2439
2440(defun mdw-outline-collapse-all ()
2441 "Completely collapse everything in the entire buffer."
2442 (interactive)
2443 (save-excursion
2444 (goto-char (point-min))
2445 (while (< (point) (point-max))
2446 (hide-subtree)
2447 (forward-line))))
2448
faf2cef7
MW
2449(setq hs-hide-comments-when-hiding-all nil)
2450
b200af26 2451(defadvice hs-hide-all (after hide-first-comment activate)
941c29ba 2452 (save-excursion (hs-hide-initial-comment-block)))
b200af26 2453
6132bc01
MW
2454;;;--------------------------------------------------------------------------
2455;;; Shell mode.
f617db13
MW
2456
2457(defun mdw-sh-mode-setup ()
2458 (local-set-key [?\C-a] 'comint-bol)
2459 (add-hook 'comint-output-filter-functions
2460 'comint-watch-for-password-prompt))
2461
2462(defun mdw-term-mode-setup ()
3d9147ea 2463 (setq term-prompt-regexp shell-prompt-pattern)
f617db13
MW
2464 (make-local-variable 'mouse-yank-at-point)
2465 (make-local-variable 'transient-mark-mode)
2466 (setq mouse-yank-at-point t)
f617db13
MW
2467 (auto-fill-mode -1)
2468 (setq tab-width 8))
2469
3d9147ea
MW
2470(defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
2471(defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
2472(defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
2473(defun term-send-meta-meta-something ()
2474 (interactive)
2475 (term-send-raw-string "\e\e")
2476 (term-send-raw))
2477(eval-after-load 'term
2478 '(progn
2479 (define-key term-raw-map [?\e ?\e] nil)
2480 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
2481 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
2482 (define-key term-raw-map [M-right] 'term-send-meta-right)
2483 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
2484 (define-key term-raw-map [M-left] 'term-send-meta-left)
2485 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
2486
c4434c20
MW
2487(defadvice term-exec (before program-args-list compile activate)
2488 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
2489This allows you to pass a list of arguments through `ansi-term'."
2490 (let ((program (ad-get-arg 2)))
2491 (if (listp program)
2492 (progn
2493 (ad-set-arg 2 (car program))
2494 (ad-set-arg 4 (cdr program))))))
2495
2496(defun ssh (host)
2497 "Open a terminal containing an ssh session to the HOST."
2498 (interactive "sHost: ")
2499 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
2500
e07e3320
MW
2501;;;--------------------------------------------------------------------------
2502;;; Inferior Emacs Lisp.
2503
2504(setq comint-prompt-read-only t)
2505
2506(eval-after-load "comint"
2507 '(progn
2508 (define-key comint-mode-map "\C-w" 'comint-kill-region)
2509 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
2510
2511(eval-after-load "ielm"
2512 '(progn
2513 (define-key ielm-map "\C-w" 'comint-kill-region)
2514 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
2515
f617db13
MW
2516;;;----- That's all, folks --------------------------------------------------
2517
2518(provide 'dot-emacs)