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