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