Commit | Line | Data |
---|---|---|
f617db13 MW |
1 | ;;; -*-emacs-lisp-*- |
2 | ;;; | |
3 | ;;; $Id$ | |
4 | ;;; | |
5 | ;;; Functions and macros for .emacs | |
6 | ;;; | |
7 | ;;; (c) 2004 Mark Wooding | |
8 | ;;; | |
9 | ||
10 | ;;;----- Licensing notice --------------------------------------------------- | |
11 | ;;; | |
12 | ;;; This program is free software; you can redistribute it and/or modify | |
13 | ;;; it under the terms of the GNU General Public License as published by | |
14 | ;;; the Free Software Foundation; either version 2 of the License, or | |
15 | ;;; (at your option) any later version. | |
852cd5fb | 16 | ;;; |
f617db13 MW |
17 | ;;; This program is distributed in the hope that it will be useful, |
18 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | ;;; GNU General Public License for more details. | |
852cd5fb | 21 | ;;; |
f617db13 MW |
22 | ;;; You should have received a copy of the GNU General Public License |
23 | ;;; along with this program; if not, write to the Free Software Foundation, | |
24 | ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
25 | ||
26 | ;;;----- Some general utilities --------------------------------------------- | |
27 | ||
28 | ;; --- Some error trapping --- | |
29 | ;; | |
30 | ;; If individual bits of this file go tits-up, we don't particularly want | |
31 | ;; the whole lot to stop right there and then, because it's bloody annoying. | |
32 | ||
33 | (defmacro trap (&rest forms) | |
34 | "Execute FORMS without allowing errors to propagate outside." | |
35 | `(condition-case err | |
36 | ,(if (cdr forms) (cons 'progn forms) (car forms)) | |
37 | (error (message "Error (trapped): %s" (error-message-string err))))) | |
38 | ||
f141fe0f MW |
39 | ;; --- Configuration reading --- |
40 | ||
41 | (defvar mdw-config nil) | |
42 | (defun mdw-config (sym) | |
43 | "Read the configuration variable named SYM." | |
44 | (unless mdw-config | |
45 | (setq mdw-config (with-temp-buffer | |
46 | (insert-file-contents "~/.mdw.conf") | |
47 | (replace-regexp "^[ \t]*\\(#.*\\|\\)\n" "" | |
48 | nil (point-min) (point-max)) | |
49 | (replace-regexp (concat "^[ \t]*" | |
50 | "\\([-a-zA-Z0-9_.]*\\)" | |
51 | "[ \t]*=[ \t]*" | |
52 | "\\(.*[^ \t\n]\\|\\)" | |
53 | "[ \t]**\\(\n\\|$\\)") | |
54 | "(\\1 . \"\\2\") " | |
55 | nil (point-min) (point-max)) | |
56 | (car (read-from-string | |
57 | (concat "(" (buffer-string) ")")))))) | |
58 | (cdr (assq sym mdw-config))) | |
59 | ||
cb6e2cd1 MW |
60 | ;; --- Is an Emacs library available? --- |
61 | ||
62 | (defun library-exists-p (name) | |
63 | "Return non-nil if NAME.el (or NAME.elc) is somewhere on the Emacs load | |
64 | path. The non-nil value is the filename we found for the library." | |
65 | (let ((path load-path) elt (foundp nil)) | |
66 | (while (and path (not foundp)) | |
67 | (setq elt (car path)) | |
68 | (setq path (cdr path)) | |
69 | (setq foundp (or (let ((file (concat elt "/" name ".elc"))) | |
70 | (and (file-exists-p file) file)) | |
71 | (let ((file (concat elt "/" name ".el"))) | |
72 | (and (file-exists-p file) file))))) | |
73 | foundp)) | |
74 | ||
75 | (defun maybe-autoload (symbol file &optional docstring interactivep type) | |
76 | "Set an autoload if the file actually exists." | |
77 | (and (library-exists-p file) | |
78 | (autoload symbol file docstring interactivep type))) | |
79 | ||
f617db13 MW |
80 | ;; --- Splitting windows --- |
81 | ||
82 | (defconst mdw-scrollbar-width (if window-system 6 1) | |
83 | "Guessed width of scroll bar.") | |
84 | (defun mdw-divvy-window (&optional w) | |
85 | "Split a wide window into appropriate widths." | |
86 | (interactive) | |
87 | (or w (setq w 78)) | |
88 | (let ((win (selected-window)) | |
89 | (c (/ (+ (window-width) mdw-scrollbar-width) | |
90 | (+ w mdw-scrollbar-width)))) | |
91 | (while (> c 1) | |
92 | (setq c (1- c)) | |
93 | (split-window-horizontally (+ w mdw-scrollbar-width)) | |
94 | (other-window 1)) | |
95 | (select-window win))) | |
96 | ||
97 | ;; --- Functions for sexp diary entries --- | |
98 | ||
99 | (defun mdw-weekday (l) | |
100 | "Return non-nil if `date' falls on one of the days of the week in L. | |
101 | ||
102 | L is a list of day numbers (from 0 to 6 for Sunday through to Saturday) or | |
103 | symbols `sunday', `monday', etc. (or a mixture). If the date stored in | |
104 | `date' falls on a listed day, then the function returns non-nil." | |
105 | (let ((d (calendar-day-of-week date))) | |
106 | (or (memq d l) | |
107 | (memq (nth d '(sunday monday tuesday wednesday | |
108 | thursday friday saturday)) l)))) | |
109 | ||
110 | (defun mdw-todo (&optional when) | |
111 | "Return non-nil today, or on WHEN, whichever is later." | |
112 | (let ((w (calendar-absolute-from-gregorian (calendar-current-date))) | |
113 | (d (calendar-absolute-from-gregorian date))) | |
114 | (if when | |
115 | (setq w (max w (calendar-absolute-from-gregorian | |
116 | (cond | |
117 | ((not european-calendar-style) | |
118 | when) | |
119 | ((> (car when) 100) | |
120 | (list (nth 1 when) | |
121 | (nth 2 when) | |
122 | (nth 0 when))) | |
123 | (t | |
124 | (list (nth 1 when) | |
125 | (nth 0 when) | |
126 | (nth 2 when)))))))) | |
127 | (eq w d))) | |
128 | ||
129 | ;;;----- Utility functions -------------------------------------------------- | |
130 | ||
131 | ;; --- mdw-uniquify-alist --- | |
132 | ||
133 | (defun mdw-uniquify-alist (&rest alists) | |
134 | ||
135 | "Return the concatenation of the ALISTS with duplicate elements removed. | |
136 | ||
137 | The first association with a given key prevails; others are ignored. The | |
138 | input lists are not modified, although they'll probably become garbage." | |
139 | ||
140 | (and alists | |
141 | (let ((start-list (cons nil nil))) | |
142 | (mdw-do-uniquify start-list | |
143 | start-list | |
144 | (car alists) | |
145 | (cdr alists))))) | |
146 | ||
147 | ;; --- mdw-do-uniquify --- | |
148 | ;; | |
149 | ;; The DONE argument is a list whose first element is `nil'. It contains the | |
150 | ;; uniquified alist built so far. The leading `nil' is stripped off at the | |
151 | ;; end of the operation; it's only there so that DONE always references a | |
152 | ;; cons cell. END refers to the final cons cell in the DONE list; it is | |
153 | ;; modified in place each time to avoid the overheads of `append'ing all the | |
154 | ;; time. The L argument is the alist we're currently processing; the | |
155 | ;; remaining alists are given in REST. | |
156 | ||
157 | (defun mdw-do-uniquify (done end l rest) | |
158 | "A helper function for mdw-uniquify-alist." | |
159 | ||
160 | ;; --- There are several different cases to deal with here --- | |
161 | ||
162 | (cond | |
163 | ||
164 | ;; --- Current list isn't empty --- | |
165 | ;; | |
166 | ;; Add the first item to the DONE list if there's not an item with the | |
167 | ;; same KEY already there. | |
168 | ||
169 | (l (or (assoc (car (car l)) done) | |
170 | (progn | |
171 | (setcdr end (cons (car l) nil)) | |
172 | (setq end (cdr end)))) | |
173 | (mdw-do-uniquify done end (cdr l) rest)) | |
174 | ||
175 | ;; --- The list we were working on is empty --- | |
176 | ;; | |
177 | ;; Shunt the next list into the current list position and go round again. | |
178 | ||
179 | (rest (mdw-do-uniquify done end (car rest) (cdr rest))) | |
180 | ||
181 | ;; --- Everything's done --- | |
182 | ;; | |
183 | ;; Remove the leading `nil' from the DONE list and return it. Finished! | |
184 | ||
185 | (t (cdr done)))) | |
186 | ||
187 | ;; --- Insert a date --- | |
188 | ||
189 | (defun date () | |
190 | "Insert the current date in a pleasing way." | |
191 | (interactive) | |
192 | (insert (save-excursion | |
193 | (let ((buffer (get-buffer-create "*tmp*"))) | |
194 | (unwind-protect (progn (set-buffer buffer) | |
195 | (erase-buffer) | |
196 | (shell-command "date +%Y-%m-%d" t) | |
197 | (goto-char (mark)) | |
198 | (delete-backward-char 1) | |
199 | (buffer-string)) | |
200 | (kill-buffer buffer)))))) | |
201 | ||
202 | ;; --- UUencoding --- | |
203 | ||
204 | (defun uuencode (file &optional name) | |
205 | "UUencodes a file, maybe calling it NAME, into the current buffer." | |
206 | (interactive "fInput file name: ") | |
207 | ||
208 | ;; --- If NAME isn't specified, then guess from the filename --- | |
209 | ||
210 | (if (not name) | |
211 | (setq name | |
212 | (substring file | |
213 | (or (string-match "[^/]*$" file) 0)))) | |
214 | ||
215 | (print (format "uuencode `%s' `%s'" file name)) | |
216 | ||
217 | ;; --- Now actually do the thing --- | |
218 | ||
219 | (call-process "uuencode" file t nil name)) | |
220 | ||
221 | (defvar np-file "~/.np" | |
222 | "*Where the `now-playing' file is.") | |
223 | ||
224 | (defun np (&optional arg) | |
225 | "Grabs a `now-playing' string." | |
226 | (interactive) | |
227 | (save-excursion | |
228 | (or arg (progn | |
852cd5fb | 229 | (goto-char (point-max)) |
f617db13 | 230 | (insert "\nNP: ") |
852cd5fb | 231 | (insert-file np-file))))) |
f617db13 MW |
232 | |
233 | (trap | |
234 | (require 'tramp) | |
235 | (require 'autorevert) | |
236 | (defun mdw-check-autorevert () | |
237 | (if (and (buffer-file-name) | |
238 | (tramp-tramp-file-p (buffer-file-name))) | |
239 | (unless global-auto-revert-ignore-buffer | |
240 | (setq global-auto-revert-ignore-buffer 'tramp)) | |
241 | (if (eq global-auto-revert-ignore-buffer 'tramp) | |
242 | (setq global-auto-revert-ignore-buffer nil)))) | |
243 | (defadvice find-file (after mdw-autorevert activate) | |
244 | (mdw-check-autorevert)) | |
245 | (defadvice write-file (after mdw-autorevert activate) | |
246 | (mdw-check-autorevert))) | |
247 | ||
248 | (defun mdwmail-mode () | |
249 | "Major mode for editing news and mail messages from external programs | |
250 | Not much right now. Just support for doing MailCrypt stuff." | |
251 | (interactive) | |
252 | (kill-all-local-variables) | |
253 | (use-local-map text-mode-map) | |
254 | (setq local-abbrev-table text-mode-abbrev-table) | |
255 | (setq major-mode 'mdwmail-mode) | |
256 | (setq mode-name "[mdw] mail") | |
257 | (make-local-variable 'paragraph-separate) | |
258 | (make-local-variable 'paragraph-start) | |
259 | (setq paragraph-start (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|" | |
260 | paragraph-start)) | |
261 | (setq paragraph-separate (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|" | |
262 | paragraph-separate)) | |
263 | (run-hooks 'text-mode-hook 'mdwmail-mode-hook 'mail-setup-hook)) | |
264 | ||
265 | ;; --- How to encrypt in mdwmail --- | |
266 | ||
267 | (defun mdwmail-mc-encrypt (&optional recip scm start end from sign) | |
268 | (or start | |
269 | (setq start (save-excursion | |
270 | (goto-char (point-min)) | |
271 | (or (search-forward "\n\n" nil t) (point-min))))) | |
272 | (or end | |
273 | (setq end (point-max))) | |
274 | (mc-encrypt-generic recip scm start end from sign)) | |
275 | ||
276 | ;; --- How to sign in mdwmail --- | |
277 | ||
278 | (defun mdwmail-mc-sign (key scm start end uclr) | |
279 | (or start | |
280 | (setq start (save-excursion | |
281 | (goto-char (point-min)) | |
282 | (or (search-forward "\n\n" nil t) (point-min))))) | |
283 | (or end | |
284 | (setq end (point-max))) | |
285 | (mc-sign-generic key scm start end uclr)) | |
286 | ||
287 | ;; --- Some signature mangling --- | |
288 | ||
289 | (defun mdwmail-mangle-signature () | |
290 | (save-excursion | |
291 | (goto-char (point-min)) | |
292 | (perform-replace "\n-- \n" "\n-- " nil nil nil))) | |
293 | (add-hook 'mail-setup-hook 'mdwmail-mangle-signature) | |
294 | ||
a203fba8 MW |
295 | ;;;----- URL viewing -------------------------------------------------------- |
296 | ||
297 | (defun mdw-w3m-browse-url (url &optional new-session-p) | |
298 | "Invoke w3m on the URL in its current window, or at least a different one. | |
299 | If NEW-SESSION-P, start a new session." | |
300 | (interactive "sURL: \nP") | |
301 | (save-excursion | |
63fb20c1 MW |
302 | (let ((window (selected-window))) |
303 | (unwind-protect | |
304 | (progn | |
305 | (select-window (or (and (not new-session-p) | |
306 | (get-buffer-window "*w3m*")) | |
307 | (progn | |
308 | (if (one-window-p t) (split-window)) | |
309 | (get-lru-window)))) | |
310 | (w3m-browse-url url new-session-p)) | |
311 | (select-window window))))) | |
a203fba8 MW |
312 | |
313 | (defvar mdw-good-url-browsers | |
314 | '((w3m . mdw-w3m-browse-url) | |
315 | browse-url-w3 | |
316 | browse-url-mozilla) | |
317 | "List of good browsers for mdw-good-url-browsers; each item is a browser | |
318 | function name, or a cons (CHECK . FUNC). A symbol FOO stands for (FOO | |
319 | . FOO).") | |
320 | ||
321 | (defun mdw-good-url-browser () | |
322 | "Return a good URL browser. Trundle the list of such things, finding the | |
323 | first item for which CHECK is fboundp, and returning the correponding FUNC." | |
324 | (let ((bs mdw-good-url-browsers) b check func answer) | |
325 | (while (and bs (not answer)) | |
326 | (setq b (car bs) | |
327 | bs (cdr bs)) | |
328 | (if (consp b) | |
329 | (setq check (car b) func (cdr b)) | |
330 | (setq check b func b)) | |
331 | (if (fboundp check) | |
332 | (setq answer func))) | |
333 | answer)) | |
334 | ||
f617db13 MW |
335 | ;;;----- Paragraph filling -------------------------------------------------- |
336 | ||
337 | ;; --- Useful variables --- | |
338 | ||
339 | (defvar mdw-fill-prefix nil | |
340 | "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'. If there's | |
341 | no fill prefix currently set (by the `fill-prefix' variable) and there's | |
342 | a match from one of the regexps here, it gets used to set the fill-prefix | |
343 | for the current operation. | |
344 | ||
345 | The variable is a list of items of the form `REGEXP . PREFIX'; if the | |
346 | REGEXP matches, the PREFIX is used to set the fill prefix. It in turn is | |
347 | a list of things: | |
348 | ||
349 | STRING -- insert a literal string | |
350 | (match . N) -- insert the thing matched by bracketed subexpression N | |
351 | (pad . N) -- a string of whitespace the same width as subexpression N | |
352 | (expr . FORM) -- the result of evaluating FORM") | |
353 | ||
354 | (make-variable-buffer-local 'mdw-fill-prefix) | |
355 | ||
356 | (defvar mdw-hanging-indents | |
357 | "\\(\\(\\([*o]\\|--\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)[ \t]+\\)?\\)" | |
358 | "*Standard regular expression matching things which might be part of a | |
359 | hanging indent. This is mainly useful in `auto-fill-mode'.") | |
360 | ||
361 | ;; --- Setting things up --- | |
362 | ||
363 | (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill)) | |
364 | ||
365 | ;; --- Utility functions --- | |
366 | ||
367 | (defun mdw-tabify (s) | |
368 | "Tabify the string S. This is a horrid hack." | |
369 | (save-excursion | |
370 | (save-match-data | |
371 | (let (start end) | |
372 | (beginning-of-line) | |
373 | (setq start (point-marker)) | |
374 | (insert s "\n") | |
375 | (setq end (point-marker)) | |
376 | (tabify start end) | |
377 | (setq s (buffer-substring start (1- end))) | |
378 | (delete-region start end) | |
379 | (set-marker start nil) | |
380 | (set-marker end nil) | |
381 | s)))) | |
382 | ||
383 | (defun mdw-examine-fill-prefixes (l) | |
384 | "Given a list of dynamic fill prefixes, pick one which matches context and | |
385 | return the static fill prefix to use. Point must be at the start of a line, | |
386 | and match data must be saved." | |
387 | (cond ((not l) nil) | |
388 | ((looking-at (car (car l))) | |
389 | (mdw-tabify (apply (function concat) | |
390 | (mapcar (function mdw-do-prefix-match) | |
391 | (cdr (car l)))))) | |
392 | (t (mdw-examine-fill-prefixes (cdr l))))) | |
393 | ||
394 | (defun mdw-maybe-car (p) | |
395 | "If P is a pair, return (car P), otherwise just return P." | |
396 | (if (consp p) (car p) p)) | |
397 | ||
398 | (defun mdw-padding (s) | |
399 | "Return a string the same width as S but made entirely from whitespace." | |
400 | (let* ((l (length s)) (i 0) (n (make-string l ? ))) | |
401 | (while (< i l) | |
402 | (if (= 9 (aref s i)) | |
403 | (aset n i 9)) | |
404 | (setq i (1+ i))) | |
405 | n)) | |
406 | ||
407 | (defun mdw-do-prefix-match (m) | |
408 | "Expand a dynamic prefix match element. See `mdw-fill-prefix' for | |
409 | details." | |
410 | (cond ((not (consp m)) (format "%s" m)) | |
411 | ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m)))) | |
412 | ((eq (car m) 'pad) (mdw-padding (match-string | |
413 | (mdw-maybe-car (cdr m))))) | |
414 | ((eq (car m) 'eval) (eval (cdr m))) | |
415 | (t ""))) | |
416 | ||
417 | (defun mdw-choose-dynamic-fill-prefix () | |
418 | "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'." | |
419 | (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix) | |
420 | ((not mdw-fill-prefix) fill-prefix) | |
421 | (t (save-excursion | |
422 | (beginning-of-line) | |
423 | (save-match-data | |
424 | (mdw-examine-fill-prefixes mdw-fill-prefix)))))) | |
425 | ||
426 | (defun do-auto-fill () | |
427 | "Handle auto-filling, working out a dynamic fill prefix in the case where | |
428 | there isn't a sensible static one." | |
429 | (let ((fill-prefix (mdw-choose-dynamic-fill-prefix))) | |
430 | (mdw-do-auto-fill))) | |
431 | ||
432 | (defun mdw-fill-paragraph () | |
433 | "Fill paragraph, getting a dynamic fill prefix." | |
434 | (interactive) | |
435 | (let ((fill-prefix (mdw-choose-dynamic-fill-prefix))) | |
436 | (fill-paragraph nil))) | |
437 | ||
438 | (defun mdw-standard-fill-prefix (rx &optional mat) | |
439 | "Set the dynamic fill prefix, handling standard hanging indents and stuff. | |
440 | This is just a short-cut for setting the thing by hand, and by design it | |
441 | doesn't cope with anything approximating a complicated case." | |
442 | (setq mdw-fill-prefix | |
443 | `((,(concat rx mdw-hanging-indents) | |
444 | (match . 1) | |
445 | (pad . ,(or mat 2)))))) | |
446 | ||
447 | ;;;----- Other common declarations ------------------------------------------ | |
448 | ||
449 | (defun mdw-set-frame-transparency (&optional n) | |
450 | (interactive "P") | |
451 | (let* ((alist (frame-parameters)) | |
452 | (trans (assq 'transparency alist))) | |
453 | (if trans | |
454 | (rplacd trans (not (if n (zerop n) (cdr trans)))) | |
455 | (setq trans (cons 'transparency (not (equal 0 n))))) | |
456 | (modify-frame-parameters (selected-frame) (list trans)))) | |
457 | ||
458 | ;; --- Mouse wheel support --- | |
459 | ||
460 | (defconst mdw-wheel-scroll-amount 15) | |
461 | (defun mdw-wheel-up (click) | |
462 | (interactive "@e") | |
463 | (mdw-wheel-scroll click (function scroll-down))) | |
464 | (defun mdw-wheel-down (click) | |
465 | (interactive "@e") | |
466 | (mdw-wheel-scroll click (function scroll-up))) | |
467 | ||
468 | (defun mdw-wheel-scroll (click func) | |
469 | (let ((win (selected-window))) | |
470 | (unwind-protect | |
471 | (progn | |
472 | (select-window (posn-window (event-start click))) | |
473 | (let ((arg 2)) | |
474 | (funcall func (/ (window-height) 2)))) | |
475 | (select-window win)))) | |
476 | ||
477 | ;; --- Going backwards --- | |
478 | ||
479 | (defun other-window-backwards (arg) | |
480 | (interactive "p") | |
481 | (other-window (- arg))) | |
482 | ||
483 | ;; --- Common mode settings --- | |
484 | ||
485 | (defvar mdw-auto-indent t | |
486 | "Whether to indent automatically after a newline.") | |
487 | ||
488 | (defun mdw-misc-mode-config () | |
489 | (and mdw-auto-indent | |
490 | (cond ((eq major-mode 'lisp-mode) | |
491 | (local-set-key "\C-m" 'mdw-indent-newline-and-indent)) | |
492 | ((eq major-mode 'slime-repl-mode) nil) | |
493 | (t | |
494 | (local-set-key "\C-m" 'newline-and-indent)))) | |
495 | (local-set-key [C-return] 'newline) | |
496 | (local-set-key [?\;] 'self-insert-command) | |
497 | (local-set-key [?\#] 'self-insert-command) | |
498 | (local-set-key [?\"] 'self-insert-command) | |
499 | (setq comment-column 40) | |
500 | (auto-fill-mode 1) | |
501 | (setq fill-column 77) | |
473ff3b0 | 502 | (setq show-trailing-whitespace t) |
f617db13 MW |
503 | (mdw-set-font)) |
504 | ||
505 | ;; --- Set up all sorts of faces --- | |
506 | ||
507 | (defvar mdw-set-font nil) | |
508 | ||
509 | (defvar mdw-punct-face 'mdw-punct-face "Face to use for punctuation") | |
510 | (make-face 'mdw-punct-face) | |
511 | (defvar mdw-number-face 'mdw-number-face "Face to use for numbers") | |
512 | (make-face 'mdw-number-face) | |
513 | ||
514 | ;;;----- General fontification ---------------------------------------------- | |
515 | ||
473ff3b0 MW |
516 | (defun mdw-set-fonts (frame faces) |
517 | (while faces | |
518 | (let ((face (caar faces))) | |
519 | (or (facep face) (make-face face)) | |
520 | (set-face-attribute face frame | |
521 | :family 'unspecified | |
522 | :width 'unspecified | |
523 | :height 'unspecified | |
524 | :weight 'unspecified | |
525 | :slant 'unspecified | |
526 | :foreground 'unspecified | |
527 | :background 'unspecified | |
528 | :underline 'unspecified | |
529 | :overline 'unspecified | |
530 | :strike-through 'unspecified | |
531 | :box 'unspecified | |
532 | :inverse-video 'unspecified | |
533 | :stipple 'unspecified | |
534 | ;:font 'unspecified | |
535 | :inherit 'unspecified) | |
536 | (apply 'set-face-attribute face frame (cdar faces)) | |
537 | (setq faces (cdr faces))))) | |
f617db13 MW |
538 | |
539 | (defun mdw-do-set-font (&optional frame) | |
540 | (interactive) | |
541 | (mdw-set-fonts (and (boundp 'frame) frame) `( | |
542 | (default :foreground "white" :background "black" | |
543 | ,@(cond ((eq window-system 'w32) | |
544 | '(:family "courier new" :height 85)) | |
545 | ((eq window-system 'x) | |
546 | '(:family "misc-fixed" :width semi-condensed)))) | |
547 | (modeline :foreground "blue" :background "yellow" | |
548 | :box (:line-width 1 :style released-button)) | |
549 | (scroll-bar :foreground "black" :background "lightgrey") | |
550 | (fringe :foreground "yellow" :background "grey30") | |
551 | (show-paren-match-face :background "darkgreen") | |
552 | (show-paren-mismatch-face :background "red") | |
553 | (font-lock-warning-face :background "red" :weight bold) | |
554 | (highlight :background "DarkSeaGreen4") | |
555 | (holiday-face :background "red") | |
556 | (calendar-today-face :foreground "yellow" :weight bold) | |
557 | (comint-highlight-prompt :weight bold) | |
558 | (comint-highlight-input) | |
559 | (font-lock-builtin-face :weight bold) | |
560 | (font-lock-type-face :weight bold) | |
561 | (region :background "grey30") | |
562 | (isearch :background "palevioletred2") | |
563 | (mdw-punct-face :foreground ,(if window-system "burlywood2" "yellow")) | |
564 | (mdw-number-face :foreground "yellow") | |
565 | (font-lock-function-name-face :weight bold) | |
566 | (font-lock-variable-name-face :slant italic) | |
567 | (font-lock-comment-face | |
568 | :foreground ,(if window-system "SeaGreen1" "green") | |
569 | :slant italic) | |
570 | (font-lock-string-face :foreground ,(if window-system "SkyBlue1" "cyan")) | |
571 | (font-lock-keyword-face :weight bold) | |
572 | (font-lock-constant-face :weight bold) | |
573 | (font-lock-reference-face :weight bold) | |
574 | (woman-bold-face :weight bold) | |
575 | (woman-italic-face :slant italic) | |
576 | (diff-header-face :foreground "skyblue1") | |
577 | (diff-index-face :weight bold) | |
578 | (diff-file-header-face) | |
579 | (diff-context-face :foreground "grey70") | |
580 | (diff-added-face :foreground "white") | |
581 | (diff-removed-face :foreground "white" :slant italic) | |
582 | (whizzy-slice-face :background "grey10") | |
583 | (whizzy-error-face :background "darkred") | |
473ff3b0 | 584 | (trailing-whitespace :background "red") |
f617db13 MW |
585 | ))) |
586 | ||
587 | (defun mdw-set-font () | |
588 | (trap | |
589 | (turn-on-font-lock) | |
590 | (if (not mdw-set-font) | |
591 | (progn | |
592 | (setq mdw-set-font t) | |
593 | (mdw-do-set-font nil))))) | |
594 | ||
595 | ;;;----- C programming configuration ---------------------------------------- | |
596 | ||
597 | ;; --- Linux kernel hacking --- | |
598 | ||
599 | (defvar linux-c-mode-hook) | |
600 | ||
601 | (defun linux-c-mode () | |
602 | (interactive) | |
603 | (c-mode) | |
604 | (setq major-mode 'linux-c-mode) | |
605 | (setq mode-name "Linux C") | |
606 | (run-hooks 'linux-c-mode-hook)) | |
607 | ||
608 | ;; --- Make C indentation nice --- | |
609 | ||
610 | (defun mdw-c-style () | |
611 | (c-add-style "[mdw] C and C++ style" | |
612 | '((c-basic-offset . 2) | |
613 | (c-tab-always-indent . nil) | |
614 | (comment-column . 40) | |
615 | (c-class-key . "class") | |
616 | (c-offsets-alist (substatement-open . 0) | |
617 | (label . 0) | |
618 | (case-label . +) | |
619 | (access-label . -) | |
620 | (inclass . ++) | |
621 | (inline-open . ++) | |
622 | (statement-cont . 0) | |
623 | (statement-case-intro . +))) | |
624 | t)) | |
625 | ||
626 | (defun mdw-fontify-c-and-c++ () | |
627 | ||
628 | ;; --- Fiddle with some syntax codes --- | |
629 | ||
630 | (modify-syntax-entry ?_ "w") | |
631 | (modify-syntax-entry ?* ". 23") | |
632 | (modify-syntax-entry ?/ ". 124b") | |
633 | (modify-syntax-entry ?\n "> b") | |
634 | ||
635 | ;; --- Other stuff --- | |
636 | ||
637 | (mdw-c-style) | |
638 | (setq c-hanging-comment-ender-p nil) | |
639 | (setq c-backslash-column 72) | |
640 | (setq c-label-minimum-indentation 0) | |
641 | (setq comment-start "/* ") | |
642 | (setq comment-end " */") | |
643 | (setq mdw-fill-prefix | |
644 | `((,(concat "\\([ \t]*/?\\)" | |
645 | "\\([\*/][ \t]*\\)" | |
646 | "\\([A-Za-z]+:[ \t]*\\)?" | |
647 | mdw-hanging-indents) | |
648 | (pad . 1) (match . 2) (pad . 3) (pad . 4)))) | |
649 | ||
650 | ;; --- Now define things to be fontified --- | |
651 | ||
02109a0d | 652 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
653 | (let ((c-keywords |
654 | (make-regexp '( | |
655 | ;; "and" ;C++ | |
656 | ;; "and_eq" ;C++ | |
657 | "asm" ;K&R, GCC | |
658 | "auto" ;K&R, C89 | |
659 | ;; "bitand" ;C++ | |
660 | ;; "bitor" ;C++ | |
661 | "bool" ;C++, C9X macro | |
662 | "break" ;K&R, C89 | |
663 | "case" ;K&R, C89 | |
664 | "catch" ;C++ | |
665 | "char" ;K&R, C89 | |
666 | "class" ;C++ | |
667 | "complex" ;C9X macro, C++ template type | |
668 | ;; "compl" ;C++ | |
669 | "const" ;C89 | |
670 | "const_cast" ;C++ | |
671 | "continue" ;K&R, C89 | |
672 | "defined" ;C89 preprocessor | |
673 | "default" ;K&R, C89 | |
674 | "delete" ;C++ | |
675 | "do" ;K&R, C89 | |
676 | "double" ;K&R, C89 | |
677 | "dynamic_cast" ;C++ | |
678 | "else" ;K&R, C89 | |
679 | ;; "entry" ;K&R -- never used | |
680 | "enum" ;C89 | |
681 | "explicit" ;C++ | |
682 | ;; "export" ;C++ | |
683 | "extern" ;K&R, C89 | |
684 | "false" ;C++, C9X macro | |
685 | "float" ;K&R, C89 | |
686 | "for" ;K&R, C89 | |
687 | "fortran" ;K&R | |
688 | "friend" ;C++ | |
689 | "goto" ;K&R, C89 | |
690 | "if" ;K&R, C89 | |
691 | "imaginary" ;C9X macro | |
692 | "inline" ;C++, C9X, GCC | |
693 | "int" ;K&R, C89 | |
694 | "long" ;K&R, C89 | |
695 | "mutable" ;C++ | |
696 | "namespace" ;C++ | |
697 | "new" ;C++ | |
698 | "operator" ;C++ | |
699 | ;; "or" ;C++ | |
700 | ;; "or_eq" ;C++ | |
701 | "private" ;C++ | |
702 | "protected" ;C++ | |
703 | "public" ;C++ | |
704 | "register" ;K&R, C89 | |
705 | "reinterpret_cast" ;C++ | |
706 | "restrict" ;C9X | |
707 | "return" ;K&R, C89 | |
708 | "short" ;K&R, C89 | |
709 | "signed" ;C89 | |
710 | "sizeof" ;K&R, C89 | |
711 | "static" ;K&R, C89 | |
712 | "static_cast" ;C++ | |
713 | "struct" ;K&R, C89 | |
714 | "switch" ;K&R, C89 | |
715 | "template" ;C++ | |
716 | "this" ;C++ | |
717 | "throw" ;C++ | |
718 | "true" ;C++, C9X macro | |
719 | "try" ;C++ | |
720 | "this" ;C++ | |
721 | "typedef" ;C89 | |
722 | "typeid" ;C++ | |
723 | "typeof" ;GCC | |
724 | "typename" ;C++ | |
725 | "union" ;K&R, C89 | |
726 | "unsigned" ;K&R, C89 | |
727 | "using" ;C++ | |
728 | "virtual" ;C++ | |
729 | "void" ;C89 | |
730 | "volatile" ;C89 | |
731 | "wchar_t" ;C++, C89 library type | |
732 | "while" ;K&R, C89 | |
733 | ;; "xor" ;C++ | |
734 | ;; "xor_eq" ;C++ | |
735 | "_Bool" ;C9X | |
736 | "_Complex" ;C9X | |
737 | "_Imaginary" ;C9X | |
738 | "_Pragma" ;C9X preprocessor | |
739 | "__alignof__" ;GCC | |
740 | "__asm__" ;GCC | |
741 | "__attribute__" ;GCC | |
742 | "__complex__" ;GCC | |
743 | "__const__" ;GCC | |
744 | "__extension__" ;GCC | |
745 | "__imag__" ;GCC | |
746 | "__inline__" ;GCC | |
747 | "__label__" ;GCC | |
748 | "__real__" ;GCC | |
749 | "__signed__" ;GCC | |
750 | "__typeof__" ;GCC | |
751 | "__volatile__" ;GCC | |
752 | ))) | |
753 | (preprocessor-keywords | |
754 | (make-regexp '("assert" "define" "elif" "else" "endif" "error" | |
755 | "ident" "if" "ifdef" "ifndef" "import" "include" | |
756 | "line" "pragma" "unassert" "undef" "warning"))) | |
757 | (objc-keywords | |
758 | (make-regexp '("class" "defs" "encode" "end" "implementation" | |
759 | "interface" "private" "protected" "protocol" "public" | |
760 | "selector")))) | |
761 | ||
762 | (setq font-lock-keywords | |
763 | (list | |
764 | 't | |
765 | ||
766 | ;; --- Fontify include files as strings --- | |
767 | ||
768 | (list (concat "^[ \t]*\\#[ \t]*" | |
769 | "\\(include\\|import\\)" | |
770 | "[ \t]*\\(<[^>]+\\(>\\|\\)\\)") | |
771 | '(2 font-lock-string-face)) | |
772 | ||
773 | ;; --- Preprocessor directives are `references'? --- | |
774 | ||
775 | (list (concat "^\\([ \t]*#[ \t]*\\(\\(" | |
776 | preprocessor-keywords | |
777 | "\\)\\>\\|[0-9]+\\|$\\)\\)") | |
778 | '(1 font-lock-keyword-face)) | |
779 | ||
780 | ;; --- Handle the keywords defined above --- | |
781 | ||
782 | (list (concat "@\\<\\(" objc-keywords "\\)\\>") | |
783 | '(0 font-lock-keyword-face)) | |
784 | ||
785 | (list (concat "\\<\\(" c-keywords "\\)\\>") | |
786 | '(0 font-lock-keyword-face)) | |
787 | ||
788 | ;; --- Handle numbers too --- | |
789 | ;; | |
790 | ;; This looks strange, I know. It corresponds to the | |
791 | ;; preprocessor's idea of what a number looks like, rather than | |
792 | ;; anything sensible. | |
793 | ||
794 | (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)" | |
795 | "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*") | |
796 | '(0 mdw-number-face)) | |
797 | ||
798 | ;; --- And anything else is punctuation --- | |
799 | ||
800 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
801 | '(0 mdw-punct-face)))))) | |
802 | ||
803 | ;;;----- AP calc mode ------------------------------------------------------- | |
804 | ||
805 | (defun apcalc-mode () | |
806 | (interactive) | |
807 | (c-mode) | |
808 | (setq major-mode 'apcalc-mode) | |
809 | (setq mode-name "AP Calc") | |
810 | (run-hooks 'apcalc-mode-hook)) | |
811 | ||
812 | (defun mdw-fontify-apcalc () | |
813 | ||
814 | ;; --- Fiddle with some syntax codes --- | |
815 | ||
816 | (modify-syntax-entry ?_ "w") | |
817 | (modify-syntax-entry ?* ". 23") | |
818 | (modify-syntax-entry ?/ ". 14") | |
819 | ||
820 | ;; --- Other stuff --- | |
821 | ||
822 | (mdw-c-style) | |
823 | (setq c-hanging-comment-ender-p nil) | |
824 | (setq c-backslash-column 72) | |
825 | (setq comment-start "/* ") | |
826 | (setq comment-end " */") | |
827 | (setq mdw-fill-prefix | |
828 | `((,(concat "\\([ \t]*/?\\)" | |
829 | "\\([\*/][ \t]*\\)" | |
830 | "\\([A-Za-z]+:[ \t]*\\)?" | |
831 | mdw-hanging-indents) | |
832 | (pad . 1) (match . 2) (pad . 3) (pad . 4)))) | |
833 | ||
834 | ;; --- Now define things to be fontified --- | |
835 | ||
02109a0d | 836 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
837 | (let ((c-keywords |
838 | (make-regexp '("break" "case" "cd" "continue" "define" "default" | |
839 | "do" "else" "exit" "for" "global" "goto" "help" "if" | |
840 | "local" "mat" "obj" "print" "quit" "read" "return" | |
841 | "show" "static" "switch" "while" "write")))) | |
842 | ||
843 | (setq font-lock-keywords | |
844 | (list | |
845 | 't | |
846 | ||
847 | ;; --- Handle the keywords defined above --- | |
848 | ||
849 | (list (concat "\\<\\(" c-keywords "\\)\\>") | |
850 | '(0 font-lock-keyword-face)) | |
851 | ||
852 | ;; --- Handle numbers too --- | |
853 | ;; | |
854 | ;; This looks strange, I know. It corresponds to the | |
855 | ;; preprocessor's idea of what a number looks like, rather than | |
856 | ;; anything sensible. | |
857 | ||
858 | (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)" | |
859 | "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*") | |
860 | '(0 mdw-number-face)) | |
861 | ||
862 | ;; --- And anything else is punctuation --- | |
863 | ||
864 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
865 | '(0 mdw-punct-face)))))) | |
866 | ||
867 | ;;;----- Java programming configuration ------------------------------------- | |
868 | ||
869 | ;; --- Make indentation nice --- | |
870 | ||
871 | (defun mdw-java-style () | |
872 | (c-add-style "[mdw] Java style" | |
873 | '((c-basic-offset . 2) | |
874 | (c-tab-always-indent . nil) | |
875 | (c-offsets-alist (substatement-open . 0) | |
876 | (label . +) | |
877 | (case-label . +) | |
878 | (access-label . 0) | |
879 | (inclass . +) | |
880 | (statement-case-intro . +))) | |
881 | t)) | |
882 | ||
883 | ;; --- Declare Java fontification style --- | |
884 | ||
885 | (defun mdw-fontify-java () | |
886 | ||
887 | ;; --- Other stuff --- | |
888 | ||
889 | (mdw-java-style) | |
890 | (modify-syntax-entry ?_ "w") | |
891 | (setq c-hanging-comment-ender-p nil) | |
892 | (setq c-backslash-column 72) | |
893 | (setq comment-start "/* ") | |
894 | (setq comment-end " */") | |
895 | (setq mdw-fill-prefix | |
896 | `((,(concat "\\([ \t]*/?\\)" | |
897 | "\\([\*/][ \t]*\\)" | |
898 | "\\([A-Za-z]+:[ \t]*\\)?" | |
899 | mdw-hanging-indents) | |
900 | (pad . 1) (match . 2) (pad . 3) (pad . 4)))) | |
901 | ||
902 | ;; --- Now define things to be fontified --- | |
903 | ||
02109a0d | 904 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
905 | (let ((java-keywords |
906 | (make-regexp '("abstract" "boolean" "break" "byte" "case" "catch" | |
907 | "char" "class" "const" "continue" "default" "do" | |
908 | "double" "else" "extends" "final" "finally" "float" | |
909 | "for" "goto" "if" "implements" "import" "instanceof" | |
910 | "int" "interface" "long" "native" "new" "package" | |
911 | "private" "protected" "public" "return" "short" | |
912 | "static" "super" "switch" "synchronized" "this" | |
913 | "throw" "throws" "transient" "try" "void" "volatile" | |
914 | "while" | |
915 | ||
916 | "false" "null" "true")))) | |
917 | ||
918 | (setq font-lock-keywords | |
919 | (list | |
920 | 't | |
921 | ||
922 | ;; --- Handle the keywords defined above --- | |
923 | ||
924 | (list (concat "\\<\\(" java-keywords "\\)\\>") | |
925 | '(0 font-lock-keyword-face)) | |
926 | ||
927 | ;; --- Handle numbers too --- | |
928 | ;; | |
929 | ;; The following isn't quite right, but it's close enough. | |
930 | ||
931 | (list (concat "\\<\\(" | |
932 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
933 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
934 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
935 | "[lLfFdD]?") | |
936 | '(0 mdw-number-face)) | |
937 | ||
938 | ;; --- And anything else is punctuation --- | |
939 | ||
940 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
941 | '(0 mdw-punct-face)))))) | |
942 | ||
e808c1e5 MW |
943 | ;;;----- C# programming configuration --------------------------------------- |
944 | ||
945 | ;; --- Make indentation nice --- | |
946 | ||
947 | (defun mdw-csharp-style () | |
948 | (c-add-style "[mdw] C# style" | |
949 | '((c-basic-offset . 2) | |
950 | (c-tab-always-indent . nil) | |
951 | (c-offsets-alist (substatement-open . 0) | |
952 | (label . 0) | |
953 | (case-label . +) | |
954 | (access-label . 0) | |
955 | (inclass . +) | |
956 | (statement-case-intro . +))) | |
957 | t)) | |
958 | ||
959 | ;; --- Declare C# fontification style --- | |
960 | ||
961 | (defun mdw-fontify-csharp () | |
962 | ||
963 | ;; --- Other stuff --- | |
964 | ||
965 | (mdw-csharp-style) | |
966 | (modify-syntax-entry ?_ "w") | |
967 | (setq c-hanging-comment-ender-p nil) | |
968 | (setq c-backslash-column 72) | |
969 | (setq comment-start "/* ") | |
970 | (setq comment-end " */") | |
971 | (setq mdw-fill-prefix | |
972 | `((,(concat "\\([ \t]*/?\\)" | |
973 | "\\([\*/][ \t]*\\)" | |
974 | "\\([A-Za-z]+:[ \t]*\\)?" | |
975 | mdw-hanging-indents) | |
976 | (pad . 1) (match . 2) (pad . 3) (pad . 4)))) | |
977 | ||
978 | ;; --- Now define things to be fontified --- | |
979 | ||
980 | (make-local-variable 'font-lock-keywords) | |
981 | (let ((csharp-keywords | |
982 | (make-regexp '("abstract" "as" "base" "bool" "break" | |
983 | "byte" "case" "catch" "char" "checked" | |
984 | "class" "const" "continue" "decimal" "default" | |
985 | "delegate" "do" "double" "else" "enum" | |
986 | "event" "explicit" "extern" "false" "finally" | |
987 | "fixed" "float" "for" "foreach" "goto" | |
988 | "if" "implicit" "in" "int" "interface" | |
989 | "internal" "is" "lock" "long" "namespace" | |
990 | "new" "null" "object" "operator" "out" | |
991 | "override" "params" "private" "protected" "public" | |
992 | "readonly" "ref" "return" "sbyte" "sealed" | |
993 | "short" "sizeof" "stackalloc" "static" "string" | |
994 | "struct" "switch" "this" "throw" "true" | |
995 | "try" "typeof" "uint" "ulong" "unchecked" | |
996 | "unsafe" "ushort" "using" "virtual" "void" | |
997 | "volatile" "while" "yield")))) | |
998 | ||
999 | (setq font-lock-keywords | |
1000 | (list | |
1001 | 't | |
1002 | ||
1003 | ;; --- Handle the keywords defined above --- | |
1004 | ||
1005 | (list (concat "\\<\\(" csharp-keywords "\\)\\>") | |
1006 | '(0 font-lock-keyword-face)) | |
1007 | ||
1008 | ;; --- Handle numbers too --- | |
1009 | ;; | |
1010 | ;; The following isn't quite right, but it's close enough. | |
1011 | ||
1012 | (list (concat "\\<\\(" | |
1013 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
1014 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
1015 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
1016 | "[lLfFdD]?") | |
1017 | '(0 mdw-number-face)) | |
1018 | ||
1019 | ;; --- And anything else is punctuation --- | |
1020 | ||
1021 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1022 | '(0 mdw-punct-face)))))) | |
1023 | ||
1024 | (defun csharp-mode () | |
1025 | (interactive) | |
1026 | (java-mode) | |
1027 | (setq major-mode 'csharp-mode) | |
1028 | (setq mode-name "C#") | |
1029 | (mdw-fontify-csharp) | |
1030 | (run-hooks 'csharp-mode-hook)) | |
1031 | ||
f617db13 MW |
1032 | ;;;----- Awk programming configuration -------------------------------------- |
1033 | ||
1034 | ;; --- Make Awk indentation nice --- | |
1035 | ||
1036 | (defun mdw-awk-style () | |
1037 | (c-add-style "[mdw] Awk style" | |
1038 | '((c-basic-offset . 2) | |
1039 | (c-tab-always-indent . nil) | |
1040 | (c-offsets-alist (substatement-open . 0) | |
1041 | (statement-cont . 0) | |
1042 | (statement-case-intro . +))) | |
1043 | t)) | |
1044 | ||
1045 | ;; --- Declare Awk fontification style --- | |
1046 | ||
1047 | (defun mdw-fontify-awk () | |
1048 | ||
1049 | ;; --- Miscellaneous fiddling --- | |
1050 | ||
1051 | (modify-syntax-entry ?_ "w") | |
1052 | (mdw-awk-style) | |
1053 | (setq c-backslash-column 72) | |
1054 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
1055 | ||
1056 | ;; --- Now define things to be fontified --- | |
1057 | ||
02109a0d | 1058 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1059 | (let ((c-keywords |
1060 | (make-regexp '("BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT" | |
1061 | "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR" | |
1062 | "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS" | |
1063 | "RSTART" "RLENGTH" "RT" "SUBSEP" | |
1064 | "atan2" "break" "close" "continue" "cos" "delete" | |
1065 | "do" "else" "exit" "exp" "fflush" "file" "for" "func" | |
1066 | "function" "gensub" "getline" "gsub" "if" "in" | |
1067 | "index" "int" "length" "log" "match" "next" "rand" | |
1068 | "return" "print" "printf" "sin" "split" "sprintf" | |
1069 | "sqrt" "srand" "strftime" "sub" "substr" "system" | |
1070 | "systime" "tolower" "toupper" "while")))) | |
1071 | ||
1072 | (setq font-lock-keywords | |
1073 | (list | |
1074 | 't | |
1075 | ||
1076 | ;; --- Handle the keywords defined above --- | |
1077 | ||
1078 | (list (concat "\\<\\(" c-keywords "\\)\\>") | |
1079 | '(0 font-lock-keyword-face)) | |
1080 | ||
1081 | ;; --- Handle numbers too --- | |
1082 | ;; | |
1083 | ;; The following isn't quite right, but it's close enough. | |
1084 | ||
1085 | (list (concat "\\<\\(" | |
1086 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
1087 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
1088 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
1089 | "[uUlL]*") | |
1090 | '(0 mdw-number-face)) | |
1091 | ||
1092 | ;; --- And anything else is punctuation --- | |
1093 | ||
1094 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1095 | '(0 mdw-punct-face)))))) | |
1096 | ||
1097 | ;;;----- Perl programming style --------------------------------------------- | |
1098 | ||
1099 | ;; --- Perl indentation style --- | |
1100 | ||
1101 | (setq cperl-tab-always-indent nil) | |
1102 | ||
1103 | (setq cperl-indent-level 2) | |
1104 | (setq cperl-continued-statement-offset 2) | |
1105 | (setq cperl-continued-brace-offset 0) | |
1106 | (setq cperl-brace-offset -2) | |
1107 | (setq cperl-brace-imaginary-offset 0) | |
1108 | (setq cperl-label-offset 0) | |
1109 | ||
1110 | ;; --- Define perl fontification style --- | |
1111 | ||
1112 | (defun mdw-fontify-perl () | |
1113 | ||
1114 | ;; --- Miscellaneous fiddling --- | |
1115 | ||
1116 | (modify-syntax-entry ?_ "w") | |
1117 | (modify-syntax-entry ?$ "\\") | |
1118 | (modify-syntax-entry ?$ "\\" font-lock-syntax-table) | |
1119 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
1120 | ||
1121 | ;; --- Now define fontification things --- | |
1122 | ||
02109a0d | 1123 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1124 | (let ((perl-keywords |
1125 | (make-regexp '("and" "cmp" "continue" "do" "else" "elsif" "eq" | |
1126 | "for" "foreach" "ge" "gt" "goto" "if" | |
1127 | "last" "le" "lt" "local" "my" "ne" "next" "or" | |
1128 | "package" "redo" "require" "return" "sub" | |
1129 | "undef" "unless" "until" "use" "while")))) | |
1130 | ||
1131 | (setq font-lock-keywords | |
1132 | (list | |
1133 | 't | |
1134 | ||
1135 | ;; --- Set up the keywords defined above --- | |
1136 | ||
1137 | (list (concat "\\<\\(" perl-keywords "\\)\\>") | |
1138 | '(0 font-lock-keyword-face)) | |
1139 | ||
1140 | ;; --- At least numbers are simpler than C --- | |
1141 | ||
1142 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1143 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1144 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
1145 | '(0 mdw-number-face)) | |
1146 | ||
1147 | ;; --- And anything else is punctuation --- | |
1148 | ||
1149 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1150 | '(0 mdw-punct-face)))))) | |
1151 | ||
1152 | (defun perl-number-tests (&optional arg) | |
1153 | "Assign consecutive numbers to lines containing `#t'. With ARG, | |
1154 | strip numbers instead." | |
1155 | (interactive "P") | |
1156 | (save-excursion | |
1157 | (goto-char (point-min)) | |
1158 | (let ((i 0) (fmt (if arg "" " %4d"))) | |
1159 | (while (search-forward "#t" nil t) | |
1160 | (delete-region (point) (line-end-position)) | |
1161 | (setq i (1+ i)) | |
1162 | (insert (format fmt i))) | |
1163 | (goto-char (point-min)) | |
1164 | (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t) | |
1165 | (replace-match (format "\\1%d" i)))))) | |
1166 | ||
1167 | ;;;----- Python programming style ------------------------------------------- | |
1168 | ||
1169 | ;; --- Define Python fontification style --- | |
1170 | ||
1171 | (trap (require 'pyrex-mode)) | |
1172 | (defun mdw-fontify-python () | |
1173 | ||
1174 | ;; --- Miscellaneous fiddling --- | |
1175 | ||
1176 | (modify-syntax-entry ?_ "w") | |
1177 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
1178 | ||
1179 | ;; --- Now define fontification things --- | |
1180 | ||
02109a0d | 1181 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1182 | (let ((python-keywords |
1183 | (make-regexp '("and" "as" "assert" "break" "class" "continue" "def" | |
1184 | "del" "elif" "else" "except" "exec" "finally" "for" | |
1185 | "from" "global" "if" "import" "in" "is" "lambda" | |
1186 | "not" "or" "pass" "print" "raise" "return" "try" | |
043e413b | 1187 | "while" "yield")))) |
f617db13 MW |
1188 | (setq font-lock-keywords |
1189 | (list | |
1190 | 't | |
1191 | ||
1192 | ;; --- Set up the keywords defined above --- | |
1193 | ||
1194 | (list (concat "\\<\\(" python-keywords "\\)\\>") | |
1195 | '(0 font-lock-keyword-face)) | |
1196 | ||
1197 | ;; --- At least numbers are simpler than C --- | |
1198 | ||
1199 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1200 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1201 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)") | |
1202 | '(0 mdw-number-face)) | |
1203 | ||
1204 | ;; --- And anything else is punctuation --- | |
1205 | ||
1206 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1207 | '(0 mdw-punct-face)))))) | |
1208 | ||
1209 | ;;;----- ARM assembler programming configuration ---------------------------- | |
1210 | ||
1211 | ;; --- There doesn't appear to be an Emacs mode for this yet --- | |
1212 | ;; | |
1213 | ;; Better do something about that, I suppose. | |
1214 | ||
1215 | (defvar arm-assembler-mode-map nil) | |
1216 | (defvar arm-assembler-abbrev-table nil) | |
1217 | (defvar arm-assembler-mode-syntax-table (make-syntax-table)) | |
1218 | ||
1219 | (or arm-assembler-mode-map | |
1220 | (progn | |
1221 | (setq arm-assembler-mode-map (make-sparse-keymap)) | |
1222 | (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline) | |
1223 | (define-key arm-assembler-mode-map [C-return] 'newline) | |
1224 | (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop))) | |
1225 | ||
1226 | (defun arm-assembler-mode () | |
1227 | "Major mode for ARM assembler programs" | |
1228 | (interactive) | |
1229 | ||
1230 | ;; --- Do standard major mode things --- | |
1231 | ||
1232 | (kill-all-local-variables) | |
1233 | (use-local-map arm-assembler-mode-map) | |
1234 | (setq local-abbrev-table arm-assembler-abbrev-table) | |
1235 | (setq major-mode 'arm-assembler-mode) | |
1236 | (setq mode-name "ARM assembler") | |
1237 | ||
1238 | ;; --- Set up syntax table --- | |
1239 | ||
1240 | (set-syntax-table arm-assembler-mode-syntax-table) | |
1241 | (modify-syntax-entry ?; ; Nasty hack | |
1242 | "<" arm-assembler-mode-syntax-table) | |
1243 | (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table) | |
1244 | (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table) | |
1245 | ||
1246 | (make-local-variable 'comment-start) | |
1247 | (setq comment-start ";") | |
1248 | (make-local-variable 'comment-end) | |
1249 | (setq comment-end "") | |
1250 | (make-local-variable 'comment-column) | |
1251 | (setq comment-column 48) | |
1252 | (make-local-variable 'comment-start-skip) | |
1253 | (setq comment-start-skip ";+[ \t]*") | |
1254 | ||
1255 | ;; --- Play with indentation --- | |
1256 | ||
1257 | (make-local-variable 'indent-line-function) | |
1258 | (setq indent-line-function 'indent-relative-maybe) | |
1259 | ||
1260 | ;; --- Set fill prefix --- | |
1261 | ||
1262 | (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)") | |
1263 | ||
1264 | ;; --- Fiddle with fontification --- | |
1265 | ||
02109a0d | 1266 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1267 | (setq font-lock-keywords |
1268 | (list | |
1269 | 't | |
1270 | ||
1271 | ;; --- Handle numbers too --- | |
1272 | ;; | |
1273 | ;; The following isn't quite right, but it's close enough. | |
1274 | ||
1275 | (list (concat "\\(" | |
1276 | "&[0-9a-fA-F]+\\|" | |
1277 | "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)" | |
1278 | "\\)") | |
1279 | '(0 mdw-number-face)) | |
1280 | ||
1281 | ;; --- Do something about operators --- | |
1282 | ||
1283 | (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)" | |
1284 | '(1 font-lock-keyword-face) | |
1285 | '(2 font-lock-string-face)) | |
1286 | (list ":[a-zA-Z]+:" | |
1287 | '(0 font-lock-keyword-face)) | |
1288 | ||
1289 | ;; --- Do menemonics and directives --- | |
1290 | ||
1291 | (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)" | |
1292 | '(1 font-lock-keyword-face)) | |
1293 | ||
1294 | ;; --- And anything else is punctuation --- | |
1295 | ||
1296 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1297 | '(0 mdw-punct-face)))) | |
1298 | ||
1299 | (run-hooks 'arm-assembler-mode-hook)) | |
1300 | ||
1301 | ;;;----- TCL configuration -------------------------------------------------- | |
1302 | ||
1303 | (defun mdw-fontify-tcl () | |
1304 | (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$)) | |
1305 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
02109a0d | 1306 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1307 | (setq font-lock-keywords |
1308 | (list | |
1309 | 't | |
1310 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1311 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1312 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
1313 | '(0 mdw-number-face)) | |
1314 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1315 | '(0 mdw-punct-face))))) | |
1316 | ||
1317 | ;;;----- REXX configuration ------------------------------------------------- | |
1318 | ||
1319 | (defun mdw-rexx-electric-* () | |
1320 | (interactive) | |
1321 | (insert ?*) | |
1322 | (rexx-indent-line)) | |
1323 | ||
1324 | (defun mdw-rexx-indent-newline-indent () | |
1325 | (interactive) | |
1326 | (rexx-indent-line) | |
1327 | (if abbrev-mode (expand-abbrev)) | |
1328 | (newline-and-indent)) | |
1329 | ||
1330 | (defun mdw-fontify-rexx () | |
1331 | ||
1332 | ;; --- Various bits of fiddling --- | |
1333 | ||
1334 | (setq mdw-auto-indent nil) | |
1335 | (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent) | |
1336 | (local-set-key [?*] 'mdw-rexx-electric-*) | |
1337 | (mapcar #'(lambda (ch) (modify-syntax-entry ch "w")) | |
1338 | '(?. ?! ?? ?_ ?# ?@ ?$)) | |
1339 | (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)") | |
1340 | ||
1341 | ;; --- Set up keywords and things for fontification --- | |
1342 | ||
1343 | (make-local-variable 'font-lock-keywords-case-fold-search) | |
1344 | (setq font-lock-keywords-case-fold-search t) | |
1345 | ||
1346 | (setq rexx-indent 2) | |
1347 | (setq rexx-end-indent rexx-indent) | |
1348 | (setq rexx-tab-always-indent nil) | |
1349 | (setq rexx-cont-indent rexx-indent) | |
1350 | ||
02109a0d | 1351 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1352 | (let ((rexx-keywords |
1353 | (make-regexp '("address" "arg" "by" "call" "digits" "do" "drop" | |
1354 | "else" "end" "engineering" "exit" "expose" "for" | |
1355 | "forever" "form" "fuzz" "if" "interpret" "iterate" | |
1356 | "leave" "linein" "name" "nop" "numeric" "off" "on" | |
1357 | "options" "otherwise" "parse" "procedure" "pull" | |
1358 | "push" "queue" "return" "say" "select" "signal" | |
1359 | "scientific" "source" "then" "trace" "to" "until" | |
1360 | "upper" "value" "var" "version" "when" "while" | |
1361 | "with" | |
1362 | ||
1363 | "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x" | |
1364 | "center" "center" "charin" "charout" "chars" | |
1365 | "compare" "condition" "copies" "c2d" "c2x" | |
1366 | "datatype" "date" "delstr" "delword" "d2c" "d2x" | |
1367 | "errortext" "format" "fuzz" "insert" "lastpos" | |
1368 | "left" "length" "lineout" "lines" "max" "min" | |
1369 | "overlay" "pos" "queued" "random" "reverse" "right" | |
1370 | "sign" "sourceline" "space" "stream" "strip" | |
1371 | "substr" "subword" "symbol" "time" "translate" | |
1372 | "trunc" "value" "verify" "word" "wordindex" | |
1373 | "wordlength" "wordpos" "words" "xrange" "x2b" "x2c" | |
1374 | "x2d")))) | |
1375 | ||
1376 | (setq font-lock-keywords | |
1377 | (list | |
1378 | 't | |
1379 | ||
1380 | ;; --- Set up the keywords defined above --- | |
1381 | ||
1382 | (list (concat "\\<\\(" rexx-keywords "\\)\\>") | |
1383 | '(0 font-lock-keyword-face)) | |
1384 | ||
1385 | ;; --- Fontify all symbols the same way --- | |
1386 | ||
1387 | (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|" | |
1388 | "[A-Za-z0-9.!?_#@$]+\\)") | |
1389 | '(0 font-lock-variable-name-face)) | |
1390 | ||
1391 | ;; --- And everything else is punctuation --- | |
1392 | ||
1393 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1394 | '(0 mdw-punct-face)))))) | |
1395 | ||
1396 | ;;;----- Standard ML programming style -------------------------------------- | |
1397 | ||
1398 | (defun mdw-fontify-sml () | |
1399 | ||
1400 | ;; --- Make underscore an honorary letter --- | |
1401 | ||
1402 | (modify-syntax-entry ?_ "w") | |
1403 | (modify-syntax-entry ?' "w") | |
1404 | ||
1405 | ;; --- Set fill prefix --- | |
1406 | ||
1407 | (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)") | |
1408 | ||
1409 | ;; --- Now define fontification things --- | |
1410 | ||
02109a0d | 1411 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1412 | (let ((sml-keywords |
1413 | (make-regexp '("abstype" "and" "andalso" "as" | |
1414 | "case" | |
1415 | "datatype" "do" | |
1416 | "else" "end" "eqtype" "exception" | |
1417 | "fn" "fun" "functor" | |
1418 | "handle" | |
1419 | "if" "in" "include" "infix" "infixr" | |
1420 | "let" "local" | |
1421 | "nonfix" | |
1422 | "of" "op" "open" "orelse" | |
1423 | "raise" "rec" | |
1424 | "sharing" "sig" "signature" "struct" "structure" | |
1425 | "then" "type" | |
1426 | "val" | |
1427 | "where" "while" "with" "withtype")))) | |
1428 | ||
1429 | (setq font-lock-keywords | |
1430 | (list | |
1431 | 't | |
1432 | ||
1433 | ;; --- Set up the keywords defined above --- | |
1434 | ||
1435 | (list (concat "\\<\\(" sml-keywords "\\)\\>") | |
1436 | '(0 font-lock-keyword-face)) | |
1437 | ||
1438 | ;; --- At least numbers are simpler than C --- | |
1439 | ||
1440 | (list (concat "\\<\\(\\~\\|\\)" | |
1441 | "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|" | |
852cd5fb MW |
1442 | "[wW][0-9]+\\)\\|" |
1443 | "\\([0-9]+\\(\\.[0-9]+\\|\\)" | |
1444 | "\\([eE]\\(\\~\\|\\)" | |
1445 | "[0-9]+\\|\\)\\)\\)") | |
f617db13 MW |
1446 | '(0 mdw-number-face)) |
1447 | ||
1448 | ;; --- And anything else is punctuation --- | |
1449 | ||
1450 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1451 | '(0 mdw-punct-face)))))) | |
1452 | ||
1453 | ;;;----- Haskell configuration ---------------------------------------------- | |
1454 | ||
1455 | (defun mdw-fontify-haskell () | |
1456 | ||
1457 | ;; --- Fiddle with syntax table to get comments right --- | |
1458 | ||
1459 | (modify-syntax-entry ?_ "w") | |
1460 | (modify-syntax-entry ?' "\"") | |
1461 | (modify-syntax-entry ?- ". 123") | |
1462 | (modify-syntax-entry ?{ ". 1b") | |
1463 | (modify-syntax-entry ?} ". 4b") | |
1464 | (modify-syntax-entry ?\n ">") | |
1465 | ||
1466 | ;; --- Set fill prefix --- | |
1467 | ||
1468 | (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)") | |
1469 | ||
1470 | ;; --- Fiddle with fontification --- | |
1471 | ||
02109a0d | 1472 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1473 | (let ((haskell-keywords |
1474 | (make-regexp '("as" "case" "ccall" "class" "data" "default" | |
1475 | "deriving" "do" "else" "foreign" "hiding" "if" | |
1476 | "import" "in" "infix" "infixl" "infixr" "instance" | |
1477 | "let" "module" "newtype" "of" "qualified" "safe" | |
1478 | "stdcall" "then" "type" "unsafe" "where")))) | |
1479 | ||
1480 | (setq font-lock-keywords | |
1481 | (list | |
1482 | 't | |
1483 | (list "--.*$" | |
1484 | '(0 font-lock-comment-face)) | |
1485 | (list (concat "\\<\\(" haskell-keywords "\\)\\>") | |
1486 | '(0 font-lock-keyword-face)) | |
1487 | (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
1488 | "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)" | |
1489 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)") | |
1490 | '(0 mdw-number-face)) | |
1491 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1492 | '(0 mdw-punct-face)))))) | |
1493 | ||
1494 | ;;;----- Texinfo configuration ---------------------------------------------- | |
1495 | ||
1496 | (defun mdw-fontify-texinfo () | |
1497 | ||
1498 | ;; --- Set fill prefix --- | |
1499 | ||
1500 | (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)") | |
1501 | ||
1502 | ;; --- Real fontification things --- | |
1503 | ||
02109a0d | 1504 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1505 | (setq font-lock-keywords |
1506 | (list | |
1507 | 't | |
1508 | ||
1509 | ;; --- Environment names are keywords --- | |
1510 | ||
1511 | (list "@\\(end\\) *\\([a-zA-Z]*\\)?" | |
1512 | '(2 font-lock-keyword-face)) | |
1513 | ||
1514 | ;; --- Unmark escaped magic characters --- | |
1515 | ||
1516 | (list "\\(@\\)\\([@{}]\\)" | |
1517 | '(1 font-lock-keyword-face) | |
1518 | '(2 font-lock-variable-name-face)) | |
1519 | ||
1520 | ;; --- Make sure we get comments properly --- | |
1521 | ||
1522 | (list "@c\\(\\|omment\\)\\( .*\\)?$" | |
1523 | '(0 font-lock-comment-face)) | |
1524 | ||
1525 | ;; --- Command names are keywords --- | |
1526 | ||
1527 | (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)" | |
1528 | '(0 font-lock-keyword-face)) | |
1529 | ||
1530 | ;; --- Fontify TeX special characters as punctuation --- | |
1531 | ||
1532 | (list "[{}]+" | |
1533 | '(0 mdw-punct-face))))) | |
1534 | ||
1535 | ;;;----- TeX and LaTeX configuration ---------------------------------------- | |
1536 | ||
1537 | (defun mdw-fontify-tex () | |
1538 | (setq ispell-parser 'tex) | |
1539 | ||
1540 | ;; --- Don't make maths into a string --- | |
1541 | ||
1542 | (modify-syntax-entry ?$ ".") | |
1543 | (modify-syntax-entry ?$ "." font-lock-syntax-table) | |
1544 | (local-set-key [?$] 'self-insert-command) | |
1545 | ||
1546 | ;; --- Set fill prefix --- | |
1547 | ||
1548 | (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)") | |
1549 | ||
1550 | ;; --- Real fontification things --- | |
1551 | ||
02109a0d | 1552 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1553 | (setq font-lock-keywords |
1554 | (list | |
1555 | 't | |
1556 | ||
1557 | ;; --- Environment names are keywords --- | |
1558 | ||
1559 | (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)" | |
1560 | "{\\([^}\n]*\\)}") | |
1561 | '(2 font-lock-keyword-face)) | |
1562 | ||
1563 | ;; --- Suspended environment names are keywords too --- | |
1564 | ||
1565 | (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?" | |
1566 | "{\\([^}\n]*\\)}") | |
1567 | '(3 font-lock-keyword-face)) | |
1568 | ||
1569 | ;; --- Command names are keywords --- | |
1570 | ||
1571 | (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)" | |
1572 | '(0 font-lock-keyword-face)) | |
1573 | ||
1574 | ;; --- Handle @/.../ for italics --- | |
1575 | ||
1576 | ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)" | |
852cd5fb MW |
1577 | ;; '(1 font-lock-keyword-face) |
1578 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1579 | |
1580 | ;; --- Handle @*...* for boldness --- | |
1581 | ||
1582 | ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)" | |
852cd5fb MW |
1583 | ;; '(1 font-lock-keyword-face) |
1584 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1585 | |
1586 | ;; --- Handle @`...' for literal syntax things --- | |
1587 | ||
1588 | ;; (list "\\(@`\\)\\([^']*\\)\\('\\)" | |
852cd5fb MW |
1589 | ;; '(1 font-lock-keyword-face) |
1590 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1591 | |
1592 | ;; --- Handle @<...> for nonterminals --- | |
1593 | ||
1594 | ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)" | |
852cd5fb MW |
1595 | ;; '(1 font-lock-keyword-face) |
1596 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1597 | |
1598 | ;; --- Handle other @-commands --- | |
1599 | ||
1600 | ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)" | |
852cd5fb | 1601 | ;; '(0 font-lock-keyword-face)) |
f617db13 MW |
1602 | |
1603 | ;; --- Make sure we get comments properly --- | |
1604 | ||
1605 | (list "%.*" | |
1606 | '(0 font-lock-comment-face)) | |
1607 | ||
1608 | ;; --- Fontify TeX special characters as punctuation --- | |
1609 | ||
1610 | (list "[$^_{}#&]" | |
1611 | '(0 mdw-punct-face))))) | |
1612 | ||
1613 | ;;;----- Shell scripts ------------------------------------------------------ | |
1614 | ||
1615 | (defun mdw-setup-sh-script-mode () | |
1616 | ||
1617 | ;; --- Fetch the shell interpreter's name --- | |
1618 | ||
1619 | (let ((shell-name sh-shell-file)) | |
1620 | ||
1621 | ;; --- Try reading the hash-bang line --- | |
1622 | ||
1623 | (save-excursion | |
1624 | (goto-char (point-min)) | |
1625 | (if (looking-at "#![ \t]*\\([^ \t\n]*\\)") | |
1626 | (setq shell-name (match-string 1)))) | |
1627 | ||
1628 | ;; --- Now try to set the shell --- | |
1629 | ;; | |
1630 | ;; Don't let `sh-set-shell' bugger up my script. | |
1631 | ||
1632 | (let ((executable-set-magic #'(lambda (s &rest r) s))) | |
1633 | (sh-set-shell shell-name))) | |
1634 | ||
1635 | ;; --- Now enable my keys and the fontification --- | |
1636 | ||
1637 | (mdw-misc-mode-config) | |
1638 | ||
1639 | ;; --- Set the indentation level correctly --- | |
1640 | ||
1641 | (setq sh-indentation 2) | |
1642 | (setq sh-basic-offset 2)) | |
1643 | ||
1644 | ;;;----- Messages-file mode ------------------------------------------------- | |
1645 | ||
1646 | (defun message-mode-guts () | |
1647 | (setq messages-mode-syntax-table (make-syntax-table)) | |
1648 | (set-syntax-table messages-mode-syntax-table) | |
1649 | (modify-syntax-entry ?_ "w" messages-mode-syntax-table) | |
1650 | (modify-syntax-entry ?- "w" messages-mode-syntax-table) | |
1651 | (modify-syntax-entry ?0 "w" messages-mode-syntax-table) | |
1652 | (modify-syntax-entry ?1 "w" messages-mode-syntax-table) | |
1653 | (modify-syntax-entry ?2 "w" messages-mode-syntax-table) | |
1654 | (modify-syntax-entry ?3 "w" messages-mode-syntax-table) | |
1655 | (modify-syntax-entry ?4 "w" messages-mode-syntax-table) | |
1656 | (modify-syntax-entry ?5 "w" messages-mode-syntax-table) | |
1657 | (modify-syntax-entry ?6 "w" messages-mode-syntax-table) | |
1658 | (modify-syntax-entry ?7 "w" messages-mode-syntax-table) | |
1659 | (modify-syntax-entry ?8 "w" messages-mode-syntax-table) | |
1660 | (modify-syntax-entry ?9 "w" messages-mode-syntax-table) | |
1661 | (make-local-variable 'comment-start) | |
1662 | (make-local-variable 'comment-end) | |
1663 | (make-local-variable 'indent-line-function) | |
1664 | (setq indent-line-function 'indent-relative) | |
1665 | (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)") | |
1666 | (make-local-variable 'font-lock-defaults) | |
1667 | (make-local-variable 'message-mode-keywords) | |
1668 | (let ((keywords | |
1669 | (make-regexp '("array" "bitmap" "callback" "docs[ \t]+enum" | |
1670 | "export" "enum" "fixed-octetstring" "flags" | |
1671 | "harmless" "map" "nested" "optional" | |
1672 | "optional-tagged" "package" "primitive" | |
1673 | "primitive-nullfree" "relaxed[ \t]+enum" | |
1674 | "set" "table" "tagged-optional" "union" | |
1675 | "variadic" "vector" "version" "version-tag")))) | |
1676 | (setq message-mode-keywords | |
1677 | (list | |
1678 | (list (concat "\\<\\(" keywords "\\)\\>:") | |
1679 | '(0 font-lock-keyword-face)) | |
1680 | '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face)) | |
1681 | '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)" | |
1682 | (0 font-lock-variable-name-face)) | |
1683 | '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face)) | |
1684 | '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1685 | (0 mdw-punct-face))))) | |
1686 | (setq font-lock-defaults | |
1687 | '(message-mode-keywords nil nil nil nil)) | |
1688 | (run-hooks 'messages-file-hook)) | |
1689 | ||
1690 | (defun messages-mode () | |
1691 | (interactive) | |
1692 | (fundamental-mode) | |
1693 | (setq major-mode 'messages-mode) | |
1694 | (setq mode-name "Messages") | |
1695 | (message-mode-guts) | |
1696 | (modify-syntax-entry ?# "<" messages-mode-syntax-table) | |
1697 | (modify-syntax-entry ?\n ">" messages-mode-syntax-table) | |
1698 | (setq comment-start "# ") | |
1699 | (setq comment-end "") | |
1700 | (turn-on-font-lock-if-enabled) | |
1701 | (run-hooks 'messages-mode-hook)) | |
1702 | ||
1703 | (defun cpp-messages-mode () | |
1704 | (interactive) | |
1705 | (fundamental-mode) | |
1706 | (setq major-mode 'cpp-messages-mode) | |
1707 | (setq mode-name "CPP Messages") | |
1708 | (message-mode-guts) | |
1709 | (modify-syntax-entry ?* ". 23" messages-mode-syntax-table) | |
1710 | (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table) | |
1711 | (setq comment-start "/* ") | |
1712 | (setq comment-end " */") | |
1713 | (let ((preprocessor-keywords | |
1714 | (make-regexp '("assert" "define" "elif" "else" "endif" "error" | |
1715 | "ident" "if" "ifdef" "ifndef" "import" "include" | |
1716 | "line" "pragma" "unassert" "undef" "warning")))) | |
1717 | (setq message-mode-keywords | |
1718 | (append (list (list (concat "^[ \t]*\\#[ \t]*" | |
1719 | "\\(include\\|import\\)" | |
1720 | "[ \t]*\\(<[^>]+\\(>\\|\\)\\)") | |
1721 | '(2 font-lock-string-face)) | |
1722 | (list (concat "^\\([ \t]*#[ \t]*\\(\\(" | |
1723 | preprocessor-keywords | |
852cd5fb | 1724 | "\\)\\>\\|[0-9]+\\|$\\)\\)") |
f617db13 MW |
1725 | '(1 font-lock-keyword-face))) |
1726 | message-mode-keywords))) | |
f617db13 | 1727 | (turn-on-font-lock-if-enabled) |
297d60aa | 1728 | (run-hooks 'cpp-messages-mode-hook)) |
f617db13 | 1729 | |
297d60aa MW |
1730 | (add-hook 'messages-mode-hook 'mdw-misc-mode-config t) |
1731 | (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t) | |
f617db13 MW |
1732 | ; (add-hook 'messages-file-hook 'mdw-fontify-messages t) |
1733 | ||
1734 | ;;;----- Messages-file mode ------------------------------------------------- | |
1735 | ||
1736 | (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face | |
1737 | "Face to use for subsittution directives.") | |
1738 | (make-face 'mallow-driver-substitution-face) | |
1739 | (defvar mallow-driver-text-face 'mallow-driver-text-face | |
1740 | "Face to use for body text.") | |
1741 | (make-face 'mallow-driver-text-face) | |
1742 | ||
1743 | (defun mallow-driver-mode () | |
1744 | (interactive) | |
1745 | (fundamental-mode) | |
1746 | (setq major-mode 'mallow-driver-mode) | |
1747 | (setq mode-name "Mallow driver") | |
1748 | (setq mallow-driver-mode-syntax-table (make-syntax-table)) | |
1749 | (set-syntax-table mallow-driver-mode-syntax-table) | |
1750 | (make-local-variable 'comment-start) | |
1751 | (make-local-variable 'comment-end) | |
1752 | (make-local-variable 'indent-line-function) | |
1753 | (setq indent-line-function 'indent-relative) | |
1754 | (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)") | |
1755 | (make-local-variable 'font-lock-defaults) | |
1756 | (make-local-variable 'mallow-driver-mode-keywords) | |
1757 | (let ((keywords | |
1758 | (make-regexp '("each" "divert" "file" "if" | |
1759 | "perl" "set" "string" "type" "write")))) | |
1760 | (setq mallow-driver-mode-keywords | |
1761 | (list | |
1762 | (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$") | |
1763 | '(0 font-lock-keyword-face)) | |
1764 | (list "^%\\s *\\(#.*\\|\\)$" | |
1765 | '(0 font-lock-comment-face)) | |
1766 | (list "^%" | |
1767 | '(0 font-lock-keyword-face)) | |
1768 | (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face)) | |
1769 | (list "\\${[^}]*}" | |
1770 | '(0 mallow-driver-substitution-face t))))) | |
1771 | (setq font-lock-defaults | |
1772 | '(mallow-driver-mode-keywords nil nil nil nil)) | |
1773 | (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table) | |
1774 | (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table) | |
1775 | (setq comment-start "%# ") | |
1776 | (setq comment-end "") | |
1777 | (turn-on-font-lock-if-enabled) | |
1778 | (run-hooks 'mallow-driver-mode-hook)) | |
1779 | ||
1780 | (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t) | |
1781 | ||
1782 | ;;;----- NFast debugs ------------------------------------------------------- | |
1783 | ||
1784 | (defun nfast-debug-mode () | |
1785 | (interactive) | |
1786 | (fundamental-mode) | |
1787 | (setq major-mode 'nfast-debug-mode) | |
1788 | (setq mode-name "NFast debug") | |
1789 | (setq messages-mode-syntax-table (make-syntax-table)) | |
1790 | (set-syntax-table messages-mode-syntax-table) | |
1791 | (make-local-variable 'font-lock-defaults) | |
1792 | (make-local-variable 'nfast-debug-mode-keywords) | |
1793 | (setq truncate-lines t) | |
1794 | (setq nfast-debug-mode-keywords | |
1795 | (list | |
1796 | '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)" | |
1797 | (0 font-lock-keyword-face)) | |
1798 | (list (concat "^[ \t]+\\(\\(" | |
1799 | "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]" | |
1800 | "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]" | |
1801 | "[ \t]+\\)*" | |
1802 | "[0-9a-fA-F]+\\)[ \t]*$") | |
1803 | '(0 mdw-number-face)) | |
1804 | '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>" | |
1805 | (1 font-lock-keyword-face)) | |
1806 | '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>" | |
1807 | (1 font-lock-warning-face)) | |
1808 | '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>" | |
1809 | (1 nil)) | |
1810 | (list (concat "^[ \t]+\\.cmd=[ \t]+" | |
1811 | "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>") | |
1812 | '(1 font-lock-keyword-face)) | |
1813 | '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face)) | |
1814 | '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face)) | |
1815 | '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face)) | |
1816 | '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face)))) | |
1817 | (setq font-lock-defaults | |
1818 | '(nfast-debug-mode-keywords nil nil nil nil)) | |
1819 | (turn-on-font-lock-if-enabled) | |
1820 | (run-hooks 'nfast-debug-mode-hook)) | |
1821 | ||
1822 | ;;;----- Other languages ---------------------------------------------------- | |
1823 | ||
1824 | ;; --- Smalltalk --- | |
1825 | ||
1826 | (defun mdw-setup-smalltalk () | |
1827 | (and mdw-auto-indent | |
1828 | (local-set-key "\C-m" 'smalltalk-newline-and-indent)) | |
1829 | (make-variable-buffer-local 'mdw-auto-indent) | |
1830 | (setq mdw-auto-indent nil) | |
1831 | (local-set-key "\C-i" 'smalltalk-reindent)) | |
1832 | ||
1833 | (defun mdw-fontify-smalltalk () | |
02109a0d | 1834 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1835 | (setq font-lock-keywords |
1836 | (list | |
1837 | 't | |
1838 | (list "\\<[A-Z][a-zA-Z0-9]*\\>" | |
1839 | '(0 font-lock-keyword-face)) | |
1840 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1841 | "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1842 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
1843 | '(0 mdw-number-face)) | |
1844 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1845 | '(0 mdw-punct-face))))) | |
1846 | ||
1847 | ;; --- Lispy languages --- | |
1848 | ||
1849 | (defun mdw-indent-newline-and-indent () | |
1850 | (interactive) | |
1851 | (indent-for-tab-command) | |
1852 | (newline-and-indent)) | |
1853 | ||
1854 | (eval-after-load "cl-indent" | |
1855 | '(progn | |
1856 | (mapc #'(lambda (pair) | |
1857 | (put (car pair) | |
1858 | 'common-lisp-indent-function | |
1859 | (cdr pair))) | |
1860 | '((destructuring-bind . ((&whole 4 &rest 1) 4 &body)) | |
1861 | (multiple-value-bind . ((&whole 4 &rest 1) 4 &body)))))) | |
1862 | ||
1863 | (defun mdw-common-lisp-indent () | |
1864 | (make-variable-buffer-local 'lisp-indent-function) | |
1865 | (setq lisp-indent-function 'common-lisp-indent-function)) | |
1866 | ||
1867 | (defun mdw-fontify-lispy () | |
1868 | ||
1869 | ;; --- Set fill prefix --- | |
1870 | ||
1871 | (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)") | |
1872 | ||
1873 | ;; --- Not much fontification needed --- | |
1874 | ||
02109a0d | 1875 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1876 | (setq font-lock-keywords |
1877 | (list | |
1878 | 't | |
1879 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1880 | '(0 mdw-punct-face))))) | |
1881 | ||
1882 | (defun comint-send-and-indent () | |
1883 | (interactive) | |
1884 | (comint-send-input) | |
1885 | (and mdw-auto-indent | |
1886 | (indent-for-tab-command))) | |
1887 | ||
1888 | ;;;----- Text mode ---------------------------------------------------------- | |
1889 | ||
1890 | (defun mdw-text-mode () | |
1891 | (setq fill-column 72) | |
1892 | (flyspell-mode t) | |
1893 | (mdw-standard-fill-prefix | |
1894 | "\\([ \t]*\\([A-Za-z0-9]*[>#|:] ?\\)*[ \t]*\\)" 3) | |
1895 | (auto-fill-mode 1)) | |
1896 | ||
1897 | ;;;----- Shell mode --------------------------------------------------------- | |
1898 | ||
1899 | (defun mdw-sh-mode-setup () | |
1900 | (local-set-key [?\C-a] 'comint-bol) | |
1901 | (add-hook 'comint-output-filter-functions | |
1902 | 'comint-watch-for-password-prompt)) | |
1903 | ||
1904 | (defun mdw-term-mode-setup () | |
9a3fa88e | 1905 |