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