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