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)) | |
30c8a8fb MW |
492 | ((or (eq major-mode 'slime-repl-mode) |
493 | (eq major-mode 'asm-mode)) | |
494 | nil) | |
f617db13 MW |
495 | (t |
496 | (local-set-key "\C-m" 'newline-and-indent)))) | |
497 | (local-set-key [C-return] 'newline) | |
30c8a8fb MW |
498 | (or (eq major-mode 'asm-mode) |
499 | (local-set-key [?\;] 'self-insert-command)) | |
f617db13 MW |
500 | (local-set-key [?\#] 'self-insert-command) |
501 | (local-set-key [?\"] 'self-insert-command) | |
502 | (setq comment-column 40) | |
503 | (auto-fill-mode 1) | |
504 | (setq fill-column 77) | |
473ff3b0 | 505 | (setq show-trailing-whitespace t) |
f617db13 MW |
506 | (mdw-set-font)) |
507 | ||
508 | ;; --- Set up all sorts of faces --- | |
509 | ||
510 | (defvar mdw-set-font nil) | |
511 | ||
512 | (defvar mdw-punct-face 'mdw-punct-face "Face to use for punctuation") | |
513 | (make-face 'mdw-punct-face) | |
514 | (defvar mdw-number-face 'mdw-number-face "Face to use for numbers") | |
515 | (make-face 'mdw-number-face) | |
516 | ||
517 | ;;;----- General fontification ---------------------------------------------- | |
518 | ||
473ff3b0 MW |
519 | (defun mdw-set-fonts (frame faces) |
520 | (while faces | |
521 | (let ((face (caar faces))) | |
522 | (or (facep face) (make-face face)) | |
523 | (set-face-attribute face frame | |
524 | :family 'unspecified | |
525 | :width 'unspecified | |
526 | :height 'unspecified | |
527 | :weight 'unspecified | |
528 | :slant 'unspecified | |
529 | :foreground 'unspecified | |
530 | :background 'unspecified | |
531 | :underline 'unspecified | |
532 | :overline 'unspecified | |
533 | :strike-through 'unspecified | |
534 | :box 'unspecified | |
535 | :inverse-video 'unspecified | |
536 | :stipple 'unspecified | |
537 | ;:font 'unspecified | |
538 | :inherit 'unspecified) | |
539 | (apply 'set-face-attribute face frame (cdar faces)) | |
540 | (setq faces (cdr faces))))) | |
f617db13 MW |
541 | |
542 | (defun mdw-do-set-font (&optional frame) | |
543 | (interactive) | |
544 | (mdw-set-fonts (and (boundp 'frame) frame) `( | |
545 | (default :foreground "white" :background "black" | |
546 | ,@(cond ((eq window-system 'w32) | |
547 | '(:family "courier new" :height 85)) | |
548 | ((eq window-system 'x) | |
549 | '(:family "misc-fixed" :width semi-condensed)))) | |
550 | (modeline :foreground "blue" :background "yellow" | |
551 | :box (:line-width 1 :style released-button)) | |
552 | (scroll-bar :foreground "black" :background "lightgrey") | |
553 | (fringe :foreground "yellow" :background "grey30") | |
554 | (show-paren-match-face :background "darkgreen") | |
555 | (show-paren-mismatch-face :background "red") | |
556 | (font-lock-warning-face :background "red" :weight bold) | |
557 | (highlight :background "DarkSeaGreen4") | |
558 | (holiday-face :background "red") | |
559 | (calendar-today-face :foreground "yellow" :weight bold) | |
560 | (comint-highlight-prompt :weight bold) | |
561 | (comint-highlight-input) | |
562 | (font-lock-builtin-face :weight bold) | |
563 | (font-lock-type-face :weight bold) | |
564 | (region :background "grey30") | |
565 | (isearch :background "palevioletred2") | |
566 | (mdw-punct-face :foreground ,(if window-system "burlywood2" "yellow")) | |
567 | (mdw-number-face :foreground "yellow") | |
568 | (font-lock-function-name-face :weight bold) | |
569 | (font-lock-variable-name-face :slant italic) | |
570 | (font-lock-comment-face | |
571 | :foreground ,(if window-system "SeaGreen1" "green") | |
572 | :slant italic) | |
573 | (font-lock-string-face :foreground ,(if window-system "SkyBlue1" "cyan")) | |
574 | (font-lock-keyword-face :weight bold) | |
575 | (font-lock-constant-face :weight bold) | |
576 | (font-lock-reference-face :weight bold) | |
577 | (woman-bold-face :weight bold) | |
578 | (woman-italic-face :slant italic) | |
579 | (diff-header-face :foreground "skyblue1") | |
580 | (diff-index-face :weight bold) | |
581 | (diff-file-header-face) | |
582 | (diff-context-face :foreground "grey70") | |
583 | (diff-added-face :foreground "white") | |
584 | (diff-removed-face :foreground "white" :slant italic) | |
585 | (whizzy-slice-face :background "grey10") | |
586 | (whizzy-error-face :background "darkred") | |
473ff3b0 | 587 | (trailing-whitespace :background "red") |
f617db13 MW |
588 | ))) |
589 | ||
590 | (defun mdw-set-font () | |
591 | (trap | |
592 | (turn-on-font-lock) | |
593 | (if (not mdw-set-font) | |
594 | (progn | |
595 | (setq mdw-set-font t) | |
596 | (mdw-do-set-font nil))))) | |
597 | ||
598 | ;;;----- C programming configuration ---------------------------------------- | |
599 | ||
600 | ;; --- Linux kernel hacking --- | |
601 | ||
602 | (defvar linux-c-mode-hook) | |
603 | ||
604 | (defun linux-c-mode () | |
605 | (interactive) | |
606 | (c-mode) | |
607 | (setq major-mode 'linux-c-mode) | |
608 | (setq mode-name "Linux C") | |
609 | (run-hooks 'linux-c-mode-hook)) | |
610 | ||
611 | ;; --- Make C indentation nice --- | |
612 | ||
613 | (defun mdw-c-style () | |
614 | (c-add-style "[mdw] C and C++ style" | |
615 | '((c-basic-offset . 2) | |
616 | (c-tab-always-indent . nil) | |
617 | (comment-column . 40) | |
618 | (c-class-key . "class") | |
619 | (c-offsets-alist (substatement-open . 0) | |
620 | (label . 0) | |
621 | (case-label . +) | |
622 | (access-label . -) | |
623 | (inclass . ++) | |
624 | (inline-open . ++) | |
625 | (statement-cont . 0) | |
626 | (statement-case-intro . +))) | |
627 | t)) | |
628 | ||
629 | (defun mdw-fontify-c-and-c++ () | |
630 | ||
631 | ;; --- Fiddle with some syntax codes --- | |
632 | ||
633 | (modify-syntax-entry ?_ "w") | |
634 | (modify-syntax-entry ?* ". 23") | |
635 | (modify-syntax-entry ?/ ". 124b") | |
636 | (modify-syntax-entry ?\n "> b") | |
637 | ||
638 | ;; --- Other stuff --- | |
639 | ||
640 | (mdw-c-style) | |
641 | (setq c-hanging-comment-ender-p nil) | |
642 | (setq c-backslash-column 72) | |
643 | (setq c-label-minimum-indentation 0) | |
f617db13 MW |
644 | (setq mdw-fill-prefix |
645 | `((,(concat "\\([ \t]*/?\\)" | |
646 | "\\([\*/][ \t]*\\)" | |
647 | "\\([A-Za-z]+:[ \t]*\\)?" | |
648 | mdw-hanging-indents) | |
649 | (pad . 1) (match . 2) (pad . 3) (pad . 4)))) | |
650 | ||
651 | ;; --- Now define things to be fontified --- | |
652 | ||
02109a0d | 653 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
654 | (let ((c-keywords |
655 | (make-regexp '( | |
4459800e MW |
656 | "and" ;C++ |
657 | "and_eq" ;C++ | |
f617db13 MW |
658 | "asm" ;K&R, GCC |
659 | "auto" ;K&R, C89 | |
4459800e MW |
660 | "bitand" ;C++ |
661 | "bitor" ;C++ | |
f617db13 MW |
662 | "bool" ;C++, C9X macro |
663 | "break" ;K&R, C89 | |
664 | "case" ;K&R, C89 | |
665 | "catch" ;C++ | |
666 | "char" ;K&R, C89 | |
667 | "class" ;C++ | |
668 | "complex" ;C9X macro, C++ template type | |
4459800e | 669 | "compl" ;C++ |
f617db13 MW |
670 | "const" ;C89 |
671 | "const_cast" ;C++ | |
672 | "continue" ;K&R, C89 | |
673 | "defined" ;C89 preprocessor | |
674 | "default" ;K&R, C89 | |
675 | "delete" ;C++ | |
676 | "do" ;K&R, C89 | |
677 | "double" ;K&R, C89 | |
678 | "dynamic_cast" ;C++ | |
679 | "else" ;K&R, C89 | |
680 | ;; "entry" ;K&R -- never used | |
681 | "enum" ;C89 | |
682 | "explicit" ;C++ | |
4459800e | 683 | "export" ;C++ |
f617db13 MW |
684 | "extern" ;K&R, C89 |
685 | "false" ;C++, C9X macro | |
686 | "float" ;K&R, C89 | |
687 | "for" ;K&R, C89 | |
4459800e | 688 | ;; "fortran" ;K&R |
f617db13 MW |
689 | "friend" ;C++ |
690 | "goto" ;K&R, C89 | |
691 | "if" ;K&R, C89 | |
692 | "imaginary" ;C9X macro | |
693 | "inline" ;C++, C9X, GCC | |
694 | "int" ;K&R, C89 | |
695 | "long" ;K&R, C89 | |
696 | "mutable" ;C++ | |
697 | "namespace" ;C++ | |
698 | "new" ;C++ | |
699 | "operator" ;C++ | |
4459800e MW |
700 | "or" ;C++ |
701 | "or_eq" ;C++ | |
f617db13 MW |
702 | "private" ;C++ |
703 | "protected" ;C++ | |
704 | "public" ;C++ | |
705 | "register" ;K&R, C89 | |
706 | "reinterpret_cast" ;C++ | |
707 | "restrict" ;C9X | |
708 | "return" ;K&R, C89 | |
709 | "short" ;K&R, C89 | |
710 | "signed" ;C89 | |
711 | "sizeof" ;K&R, C89 | |
712 | "static" ;K&R, C89 | |
713 | "static_cast" ;C++ | |
714 | "struct" ;K&R, C89 | |
715 | "switch" ;K&R, C89 | |
716 | "template" ;C++ | |
717 | "this" ;C++ | |
718 | "throw" ;C++ | |
719 | "true" ;C++, C9X macro | |
720 | "try" ;C++ | |
721 | "this" ;C++ | |
722 | "typedef" ;C89 | |
723 | "typeid" ;C++ | |
724 | "typeof" ;GCC | |
725 | "typename" ;C++ | |
726 | "union" ;K&R, C89 | |
727 | "unsigned" ;K&R, C89 | |
728 | "using" ;C++ | |
729 | "virtual" ;C++ | |
730 | "void" ;C89 | |
731 | "volatile" ;C89 | |
732 | "wchar_t" ;C++, C89 library type | |
733 | "while" ;K&R, C89 | |
4459800e MW |
734 | "xor" ;C++ |
735 | "xor_eq" ;C++ | |
f617db13 MW |
736 | "_Bool" ;C9X |
737 | "_Complex" ;C9X | |
738 | "_Imaginary" ;C9X | |
739 | "_Pragma" ;C9X preprocessor | |
740 | "__alignof__" ;GCC | |
741 | "__asm__" ;GCC | |
742 | "__attribute__" ;GCC | |
743 | "__complex__" ;GCC | |
744 | "__const__" ;GCC | |
745 | "__extension__" ;GCC | |
746 | "__imag__" ;GCC | |
747 | "__inline__" ;GCC | |
748 | "__label__" ;GCC | |
749 | "__real__" ;GCC | |
750 | "__signed__" ;GCC | |
751 | "__typeof__" ;GCC | |
752 | "__volatile__" ;GCC | |
753 | ))) | |
754 | (preprocessor-keywords | |
755 | (make-regexp '("assert" "define" "elif" "else" "endif" "error" | |
756 | "ident" "if" "ifdef" "ifndef" "import" "include" | |
757 | "line" "pragma" "unassert" "undef" "warning"))) | |
758 | (objc-keywords | |
759 | (make-regexp '("class" "defs" "encode" "end" "implementation" | |
760 | "interface" "private" "protected" "protocol" "public" | |
761 | "selector")))) | |
762 | ||
763 | (setq font-lock-keywords | |
764 | (list | |
765 | 't | |
766 | ||
767 | ;; --- Fontify include files as strings --- | |
768 | ||
769 | (list (concat "^[ \t]*\\#[ \t]*" | |
770 | "\\(include\\|import\\)" | |
771 | "[ \t]*\\(<[^>]+\\(>\\|\\)\\)") | |
772 | '(2 font-lock-string-face)) | |
773 | ||
774 | ;; --- Preprocessor directives are `references'? --- | |
775 | ||
776 | (list (concat "^\\([ \t]*#[ \t]*\\(\\(" | |
777 | preprocessor-keywords | |
778 | "\\)\\>\\|[0-9]+\\|$\\)\\)") | |
779 | '(1 font-lock-keyword-face)) | |
780 | ||
781 | ;; --- Handle the keywords defined above --- | |
782 | ||
783 | (list (concat "@\\<\\(" objc-keywords "\\)\\>") | |
784 | '(0 font-lock-keyword-face)) | |
785 | ||
786 | (list (concat "\\<\\(" c-keywords "\\)\\>") | |
787 | '(0 font-lock-keyword-face)) | |
788 | ||
789 | ;; --- Handle numbers too --- | |
790 | ;; | |
791 | ;; This looks strange, I know. It corresponds to the | |
792 | ;; preprocessor's idea of what a number looks like, rather than | |
793 | ;; anything sensible. | |
794 | ||
795 | (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)" | |
796 | "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*") | |
797 | '(0 mdw-number-face)) | |
798 | ||
799 | ;; --- And anything else is punctuation --- | |
800 | ||
801 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
802 | '(0 mdw-punct-face)))))) | |
803 | ||
804 | ;;;----- AP calc mode ------------------------------------------------------- | |
805 | ||
806 | (defun apcalc-mode () | |
807 | (interactive) | |
808 | (c-mode) | |
809 | (setq major-mode 'apcalc-mode) | |
810 | (setq mode-name "AP Calc") | |
811 | (run-hooks 'apcalc-mode-hook)) | |
812 | ||
813 | (defun mdw-fontify-apcalc () | |
814 | ||
815 | ;; --- Fiddle with some syntax codes --- | |
816 | ||
817 | (modify-syntax-entry ?_ "w") | |
818 | (modify-syntax-entry ?* ". 23") | |
819 | (modify-syntax-entry ?/ ". 14") | |
820 | ||
821 | ;; --- Other stuff --- | |
822 | ||
823 | (mdw-c-style) | |
824 | (setq c-hanging-comment-ender-p nil) | |
825 | (setq c-backslash-column 72) | |
826 | (setq comment-start "/* ") | |
827 | (setq comment-end " */") | |
828 | (setq mdw-fill-prefix | |
829 | `((,(concat "\\([ \t]*/?\\)" | |
830 | "\\([\*/][ \t]*\\)" | |
831 | "\\([A-Za-z]+:[ \t]*\\)?" | |
832 | mdw-hanging-indents) | |
833 | (pad . 1) (match . 2) (pad . 3) (pad . 4)))) | |
834 | ||
835 | ;; --- Now define things to be fontified --- | |
836 | ||
02109a0d | 837 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
838 | (let ((c-keywords |
839 | (make-regexp '("break" "case" "cd" "continue" "define" "default" | |
840 | "do" "else" "exit" "for" "global" "goto" "help" "if" | |
841 | "local" "mat" "obj" "print" "quit" "read" "return" | |
842 | "show" "static" "switch" "while" "write")))) | |
843 | ||
844 | (setq font-lock-keywords | |
845 | (list | |
846 | 't | |
847 | ||
848 | ;; --- Handle the keywords defined above --- | |
849 | ||
850 | (list (concat "\\<\\(" c-keywords "\\)\\>") | |
851 | '(0 font-lock-keyword-face)) | |
852 | ||
853 | ;; --- Handle numbers too --- | |
854 | ;; | |
855 | ;; This looks strange, I know. It corresponds to the | |
856 | ;; preprocessor's idea of what a number looks like, rather than | |
857 | ;; anything sensible. | |
858 | ||
859 | (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)" | |
860 | "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*") | |
861 | '(0 mdw-number-face)) | |
862 | ||
863 | ;; --- And anything else is punctuation --- | |
864 | ||
865 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
866 | '(0 mdw-punct-face)))))) | |
867 | ||
868 | ;;;----- Java programming configuration ------------------------------------- | |
869 | ||
870 | ;; --- Make indentation nice --- | |
871 | ||
872 | (defun mdw-java-style () | |
873 | (c-add-style "[mdw] Java style" | |
874 | '((c-basic-offset . 2) | |
875 | (c-tab-always-indent . nil) | |
876 | (c-offsets-alist (substatement-open . 0) | |
877 | (label . +) | |
878 | (case-label . +) | |
879 | (access-label . 0) | |
880 | (inclass . +) | |
881 | (statement-case-intro . +))) | |
882 | t)) | |
883 | ||
884 | ;; --- Declare Java fontification style --- | |
885 | ||
886 | (defun mdw-fontify-java () | |
887 | ||
888 | ;; --- Other stuff --- | |
889 | ||
890 | (mdw-java-style) | |
891 | (modify-syntax-entry ?_ "w") | |
892 | (setq c-hanging-comment-ender-p nil) | |
893 | (setq c-backslash-column 72) | |
894 | (setq comment-start "/* ") | |
895 | (setq comment-end " */") | |
896 | (setq mdw-fill-prefix | |
897 | `((,(concat "\\([ \t]*/?\\)" | |
898 | "\\([\*/][ \t]*\\)" | |
899 | "\\([A-Za-z]+:[ \t]*\\)?" | |
900 | mdw-hanging-indents) | |
901 | (pad . 1) (match . 2) (pad . 3) (pad . 4)))) | |
902 | ||
903 | ;; --- Now define things to be fontified --- | |
904 | ||
02109a0d | 905 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
906 | (let ((java-keywords |
907 | (make-regexp '("abstract" "boolean" "break" "byte" "case" "catch" | |
908 | "char" "class" "const" "continue" "default" "do" | |
909 | "double" "else" "extends" "final" "finally" "float" | |
910 | "for" "goto" "if" "implements" "import" "instanceof" | |
911 | "int" "interface" "long" "native" "new" "package" | |
912 | "private" "protected" "public" "return" "short" | |
913 | "static" "super" "switch" "synchronized" "this" | |
914 | "throw" "throws" "transient" "try" "void" "volatile" | |
915 | "while" | |
916 | ||
917 | "false" "null" "true")))) | |
918 | ||
919 | (setq font-lock-keywords | |
920 | (list | |
921 | 't | |
922 | ||
923 | ;; --- Handle the keywords defined above --- | |
924 | ||
925 | (list (concat "\\<\\(" java-keywords "\\)\\>") | |
926 | '(0 font-lock-keyword-face)) | |
927 | ||
928 | ;; --- Handle numbers too --- | |
929 | ;; | |
930 | ;; The following isn't quite right, but it's close enough. | |
931 | ||
932 | (list (concat "\\<\\(" | |
933 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
934 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
935 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
936 | "[lLfFdD]?") | |
937 | '(0 mdw-number-face)) | |
938 | ||
939 | ;; --- And anything else is punctuation --- | |
940 | ||
941 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
942 | '(0 mdw-punct-face)))))) | |
943 | ||
e808c1e5 MW |
944 | ;;;----- C# programming configuration --------------------------------------- |
945 | ||
946 | ;; --- Make indentation nice --- | |
947 | ||
948 | (defun mdw-csharp-style () | |
949 | (c-add-style "[mdw] C# style" | |
950 | '((c-basic-offset . 2) | |
951 | (c-tab-always-indent . nil) | |
952 | (c-offsets-alist (substatement-open . 0) | |
953 | (label . 0) | |
954 | (case-label . +) | |
955 | (access-label . 0) | |
956 | (inclass . +) | |
957 | (statement-case-intro . +))) | |
958 | t)) | |
959 | ||
960 | ;; --- Declare C# fontification style --- | |
961 | ||
962 | (defun mdw-fontify-csharp () | |
963 | ||
964 | ;; --- Other stuff --- | |
965 | ||
966 | (mdw-csharp-style) | |
967 | (modify-syntax-entry ?_ "w") | |
968 | (setq c-hanging-comment-ender-p nil) | |
969 | (setq c-backslash-column 72) | |
970 | (setq comment-start "/* ") | |
971 | (setq comment-end " */") | |
972 | (setq mdw-fill-prefix | |
973 | `((,(concat "\\([ \t]*/?\\)" | |
974 | "\\([\*/][ \t]*\\)" | |
975 | "\\([A-Za-z]+:[ \t]*\\)?" | |
976 | mdw-hanging-indents) | |
977 | (pad . 1) (match . 2) (pad . 3) (pad . 4)))) | |
978 | ||
979 | ;; --- Now define things to be fontified --- | |
980 | ||
981 | (make-local-variable 'font-lock-keywords) | |
982 | (let ((csharp-keywords | |
983 | (make-regexp '("abstract" "as" "base" "bool" "break" | |
984 | "byte" "case" "catch" "char" "checked" | |
985 | "class" "const" "continue" "decimal" "default" | |
986 | "delegate" "do" "double" "else" "enum" | |
987 | "event" "explicit" "extern" "false" "finally" | |
988 | "fixed" "float" "for" "foreach" "goto" | |
989 | "if" "implicit" "in" "int" "interface" | |
990 | "internal" "is" "lock" "long" "namespace" | |
991 | "new" "null" "object" "operator" "out" | |
992 | "override" "params" "private" "protected" "public" | |
993 | "readonly" "ref" "return" "sbyte" "sealed" | |
994 | "short" "sizeof" "stackalloc" "static" "string" | |
995 | "struct" "switch" "this" "throw" "true" | |
996 | "try" "typeof" "uint" "ulong" "unchecked" | |
997 | "unsafe" "ushort" "using" "virtual" "void" | |
998 | "volatile" "while" "yield")))) | |
999 | ||
1000 | (setq font-lock-keywords | |
1001 | (list | |
1002 | 't | |
1003 | ||
1004 | ;; --- Handle the keywords defined above --- | |
1005 | ||
1006 | (list (concat "\\<\\(" csharp-keywords "\\)\\>") | |
1007 | '(0 font-lock-keyword-face)) | |
1008 | ||
1009 | ;; --- Handle numbers too --- | |
1010 | ;; | |
1011 | ;; The following isn't quite right, but it's close enough. | |
1012 | ||
1013 | (list (concat "\\<\\(" | |
1014 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
1015 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
1016 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
1017 | "[lLfFdD]?") | |
1018 | '(0 mdw-number-face)) | |
1019 | ||
1020 | ;; --- And anything else is punctuation --- | |
1021 | ||
1022 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1023 | '(0 mdw-punct-face)))))) | |
1024 | ||
1025 | (defun csharp-mode () | |
1026 | (interactive) | |
1027 | (java-mode) | |
1028 | (setq major-mode 'csharp-mode) | |
1029 | (setq mode-name "C#") | |
1030 | (mdw-fontify-csharp) | |
1031 | (run-hooks 'csharp-mode-hook)) | |
1032 | ||
f617db13 MW |
1033 | ;;;----- Awk programming configuration -------------------------------------- |
1034 | ||
1035 | ;; --- Make Awk indentation nice --- | |
1036 | ||
1037 | (defun mdw-awk-style () | |
1038 | (c-add-style "[mdw] Awk style" | |
1039 | '((c-basic-offset . 2) | |
1040 | (c-tab-always-indent . nil) | |
1041 | (c-offsets-alist (substatement-open . 0) | |
1042 | (statement-cont . 0) | |
1043 | (statement-case-intro . +))) | |
1044 | t)) | |
1045 | ||
1046 | ;; --- Declare Awk fontification style --- | |
1047 | ||
1048 | (defun mdw-fontify-awk () | |
1049 | ||
1050 | ;; --- Miscellaneous fiddling --- | |
1051 | ||
1052 | (modify-syntax-entry ?_ "w") | |
1053 | (mdw-awk-style) | |
1054 | (setq c-backslash-column 72) | |
1055 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
1056 | ||
1057 | ;; --- Now define things to be fontified --- | |
1058 | ||
02109a0d | 1059 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1060 | (let ((c-keywords |
1061 | (make-regexp '("BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT" | |
1062 | "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR" | |
1063 | "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS" | |
1064 | "RSTART" "RLENGTH" "RT" "SUBSEP" | |
1065 | "atan2" "break" "close" "continue" "cos" "delete" | |
1066 | "do" "else" "exit" "exp" "fflush" "file" "for" "func" | |
1067 | "function" "gensub" "getline" "gsub" "if" "in" | |
1068 | "index" "int" "length" "log" "match" "next" "rand" | |
1069 | "return" "print" "printf" "sin" "split" "sprintf" | |
1070 | "sqrt" "srand" "strftime" "sub" "substr" "system" | |
1071 | "systime" "tolower" "toupper" "while")))) | |
1072 | ||
1073 | (setq font-lock-keywords | |
1074 | (list | |
1075 | 't | |
1076 | ||
1077 | ;; --- Handle the keywords defined above --- | |
1078 | ||
1079 | (list (concat "\\<\\(" c-keywords "\\)\\>") | |
1080 | '(0 font-lock-keyword-face)) | |
1081 | ||
1082 | ;; --- Handle numbers too --- | |
1083 | ;; | |
1084 | ;; The following isn't quite right, but it's close enough. | |
1085 | ||
1086 | (list (concat "\\<\\(" | |
1087 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
1088 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
1089 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
1090 | "[uUlL]*") | |
1091 | '(0 mdw-number-face)) | |
1092 | ||
1093 | ;; --- And anything else is punctuation --- | |
1094 | ||
1095 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1096 | '(0 mdw-punct-face)))))) | |
1097 | ||
1098 | ;;;----- Perl programming style --------------------------------------------- | |
1099 | ||
1100 | ;; --- Perl indentation style --- | |
1101 | ||
1102 | (setq cperl-tab-always-indent nil) | |
1103 | ||
1104 | (setq cperl-indent-level 2) | |
1105 | (setq cperl-continued-statement-offset 2) | |
1106 | (setq cperl-continued-brace-offset 0) | |
1107 | (setq cperl-brace-offset -2) | |
1108 | (setq cperl-brace-imaginary-offset 0) | |
1109 | (setq cperl-label-offset 0) | |
1110 | ||
1111 | ;; --- Define perl fontification style --- | |
1112 | ||
1113 | (defun mdw-fontify-perl () | |
1114 | ||
1115 | ;; --- Miscellaneous fiddling --- | |
1116 | ||
1117 | (modify-syntax-entry ?_ "w") | |
1118 | (modify-syntax-entry ?$ "\\") | |
1119 | (modify-syntax-entry ?$ "\\" font-lock-syntax-table) | |
1120 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
1121 | ||
1122 | ;; --- Now define fontification things --- | |
1123 | ||
02109a0d | 1124 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1125 | (let ((perl-keywords |
1126 | (make-regexp '("and" "cmp" "continue" "do" "else" "elsif" "eq" | |
1127 | "for" "foreach" "ge" "gt" "goto" "if" | |
1128 | "last" "le" "lt" "local" "my" "ne" "next" "or" | |
1129 | "package" "redo" "require" "return" "sub" | |
1130 | "undef" "unless" "until" "use" "while")))) | |
1131 | ||
1132 | (setq font-lock-keywords | |
1133 | (list | |
1134 | 't | |
1135 | ||
1136 | ;; --- Set up the keywords defined above --- | |
1137 | ||
1138 | (list (concat "\\<\\(" perl-keywords "\\)\\>") | |
1139 | '(0 font-lock-keyword-face)) | |
1140 | ||
1141 | ;; --- At least numbers are simpler than C --- | |
1142 | ||
1143 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1144 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1145 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
1146 | '(0 mdw-number-face)) | |
1147 | ||
1148 | ;; --- And anything else is punctuation --- | |
1149 | ||
1150 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1151 | '(0 mdw-punct-face)))))) | |
1152 | ||
1153 | (defun perl-number-tests (&optional arg) | |
1154 | "Assign consecutive numbers to lines containing `#t'. With ARG, | |
1155 | strip numbers instead." | |
1156 | (interactive "P") | |
1157 | (save-excursion | |
1158 | (goto-char (point-min)) | |
1159 | (let ((i 0) (fmt (if arg "" " %4d"))) | |
1160 | (while (search-forward "#t" nil t) | |
1161 | (delete-region (point) (line-end-position)) | |
1162 | (setq i (1+ i)) | |
1163 | (insert (format fmt i))) | |
1164 | (goto-char (point-min)) | |
1165 | (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t) | |
1166 | (replace-match (format "\\1%d" i)))))) | |
1167 | ||
1168 | ;;;----- Python programming style ------------------------------------------- | |
1169 | ||
1170 | ;; --- Define Python fontification style --- | |
1171 | ||
1172 | (trap (require 'pyrex-mode)) | |
1173 | (defun mdw-fontify-python () | |
1174 | ||
1175 | ;; --- Miscellaneous fiddling --- | |
1176 | ||
1177 | (modify-syntax-entry ?_ "w") | |
1178 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
1179 | ||
1180 | ;; --- Now define fontification things --- | |
1181 | ||
02109a0d | 1182 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1183 | (let ((python-keywords |
1184 | (make-regexp '("and" "as" "assert" "break" "class" "continue" "def" | |
1185 | "del" "elif" "else" "except" "exec" "finally" "for" | |
1186 | "from" "global" "if" "import" "in" "is" "lambda" | |
1187 | "not" "or" "pass" "print" "raise" "return" "try" | |
043e413b | 1188 | "while" "yield")))) |
f617db13 MW |
1189 | (setq font-lock-keywords |
1190 | (list | |
1191 | 't | |
1192 | ||
1193 | ;; --- Set up the keywords defined above --- | |
1194 | ||
1195 | (list (concat "\\<\\(" python-keywords "\\)\\>") | |
1196 | '(0 font-lock-keyword-face)) | |
1197 | ||
1198 | ;; --- At least numbers are simpler than C --- | |
1199 | ||
1200 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1201 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1202 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)") | |
1203 | '(0 mdw-number-face)) | |
1204 | ||
1205 | ;; --- And anything else is punctuation --- | |
1206 | ||
1207 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1208 | '(0 mdw-punct-face)))))) | |
1209 | ||
1210 | ;;;----- ARM assembler programming configuration ---------------------------- | |
1211 | ||
1212 | ;; --- There doesn't appear to be an Emacs mode for this yet --- | |
1213 | ;; | |
1214 | ;; Better do something about that, I suppose. | |
1215 | ||
1216 | (defvar arm-assembler-mode-map nil) | |
1217 | (defvar arm-assembler-abbrev-table nil) | |
1218 | (defvar arm-assembler-mode-syntax-table (make-syntax-table)) | |
1219 | ||
1220 | (or arm-assembler-mode-map | |
1221 | (progn | |
1222 | (setq arm-assembler-mode-map (make-sparse-keymap)) | |
1223 | (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline) | |
1224 | (define-key arm-assembler-mode-map [C-return] 'newline) | |
1225 | (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop))) | |
1226 | ||
1227 | (defun arm-assembler-mode () | |
1228 | "Major mode for ARM assembler programs" | |
1229 | (interactive) | |
1230 | ||
1231 | ;; --- Do standard major mode things --- | |
1232 | ||
1233 | (kill-all-local-variables) | |
1234 | (use-local-map arm-assembler-mode-map) | |
1235 | (setq local-abbrev-table arm-assembler-abbrev-table) | |
1236 | (setq major-mode 'arm-assembler-mode) | |
1237 | (setq mode-name "ARM assembler") | |
1238 | ||
1239 | ;; --- Set up syntax table --- | |
1240 | ||
1241 | (set-syntax-table arm-assembler-mode-syntax-table) | |
1242 | (modify-syntax-entry ?; ; Nasty hack | |
1243 | "<" arm-assembler-mode-syntax-table) | |
1244 | (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table) | |
1245 | (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table) | |
1246 | ||
1247 | (make-local-variable 'comment-start) | |
1248 | (setq comment-start ";") | |
1249 | (make-local-variable 'comment-end) | |
1250 | (setq comment-end "") | |
1251 | (make-local-variable 'comment-column) | |
1252 | (setq comment-column 48) | |
1253 | (make-local-variable 'comment-start-skip) | |
1254 | (setq comment-start-skip ";+[ \t]*") | |
1255 | ||
1256 | ;; --- Play with indentation --- | |
1257 | ||
1258 | (make-local-variable 'indent-line-function) | |
1259 | (setq indent-line-function 'indent-relative-maybe) | |
1260 | ||
1261 | ;; --- Set fill prefix --- | |
1262 | ||
1263 | (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)") | |
1264 | ||
1265 | ;; --- Fiddle with fontification --- | |
1266 | ||
02109a0d | 1267 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1268 | (setq font-lock-keywords |
1269 | (list | |
1270 | 't | |
1271 | ||
1272 | ;; --- Handle numbers too --- | |
1273 | ;; | |
1274 | ;; The following isn't quite right, but it's close enough. | |
1275 | ||
1276 | (list (concat "\\(" | |
1277 | "&[0-9a-fA-F]+\\|" | |
1278 | "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)" | |
1279 | "\\)") | |
1280 | '(0 mdw-number-face)) | |
1281 | ||
1282 | ;; --- Do something about operators --- | |
1283 | ||
1284 | (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)" | |
1285 | '(1 font-lock-keyword-face) | |
1286 | '(2 font-lock-string-face)) | |
1287 | (list ":[a-zA-Z]+:" | |
1288 | '(0 font-lock-keyword-face)) | |
1289 | ||
1290 | ;; --- Do menemonics and directives --- | |
1291 | ||
1292 | (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)" | |
1293 | '(1 font-lock-keyword-face)) | |
1294 | ||
1295 | ;; --- And anything else is punctuation --- | |
1296 | ||
1297 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1298 | '(0 mdw-punct-face)))) | |
1299 | ||
1300 | (run-hooks 'arm-assembler-mode-hook)) | |
1301 | ||
30c8a8fb MW |
1302 | ;;;----- Assembler mode ----------------------------------------------------- |
1303 | ||
1304 | (defun mdw-fontify-asm () | |
1305 | (modify-syntax-entry ?' "\"") | |
1306 | (modify-syntax-entry ?. "w") | |
1307 | (setf fill-prefix nil) | |
1308 | (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")) | |
1309 | ||
f617db13 MW |
1310 | ;;;----- TCL configuration -------------------------------------------------- |
1311 | ||
1312 | (defun mdw-fontify-tcl () | |
1313 | (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$)) | |
1314 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
02109a0d | 1315 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1316 | (setq font-lock-keywords |
1317 | (list | |
1318 | 't | |
1319 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1320 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1321 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
1322 | '(0 mdw-number-face)) | |
1323 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1324 | '(0 mdw-punct-face))))) | |
1325 | ||
1326 | ;;;----- REXX configuration ------------------------------------------------- | |
1327 | ||
1328 | (defun mdw-rexx-electric-* () | |
1329 | (interactive) | |
1330 | (insert ?*) | |
1331 | (rexx-indent-line)) | |
1332 | ||
1333 | (defun mdw-rexx-indent-newline-indent () | |
1334 | (interactive) | |
1335 | (rexx-indent-line) | |
1336 | (if abbrev-mode (expand-abbrev)) | |
1337 | (newline-and-indent)) | |
1338 | ||
1339 | (defun mdw-fontify-rexx () | |
1340 | ||
1341 | ;; --- Various bits of fiddling --- | |
1342 | ||
1343 | (setq mdw-auto-indent nil) | |
1344 | (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent) | |
1345 | (local-set-key [?*] 'mdw-rexx-electric-*) | |
1346 | (mapcar #'(lambda (ch) (modify-syntax-entry ch "w")) | |
1347 | '(?. ?! ?? ?_ ?# ?@ ?$)) | |
1348 | (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)") | |
1349 | ||
1350 | ;; --- Set up keywords and things for fontification --- | |
1351 | ||
1352 | (make-local-variable 'font-lock-keywords-case-fold-search) | |
1353 | (setq font-lock-keywords-case-fold-search t) | |
1354 | ||
1355 | (setq rexx-indent 2) | |
1356 | (setq rexx-end-indent rexx-indent) | |
1357 | (setq rexx-tab-always-indent nil) | |
1358 | (setq rexx-cont-indent rexx-indent) | |
1359 | ||
02109a0d | 1360 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1361 | (let ((rexx-keywords |
1362 | (make-regexp '("address" "arg" "by" "call" "digits" "do" "drop" | |
1363 | "else" "end" "engineering" "exit" "expose" "for" | |
1364 | "forever" "form" "fuzz" "if" "interpret" "iterate" | |
1365 | "leave" "linein" "name" "nop" "numeric" "off" "on" | |
1366 | "options" "otherwise" "parse" "procedure" "pull" | |
1367 | "push" "queue" "return" "say" "select" "signal" | |
1368 | "scientific" "source" "then" "trace" "to" "until" | |
1369 | "upper" "value" "var" "version" "when" "while" | |
1370 | "with" | |
1371 | ||
1372 | "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x" | |
1373 | "center" "center" "charin" "charout" "chars" | |
1374 | "compare" "condition" "copies" "c2d" "c2x" | |
1375 | "datatype" "date" "delstr" "delword" "d2c" "d2x" | |
1376 | "errortext" "format" "fuzz" "insert" "lastpos" | |
1377 | "left" "length" "lineout" "lines" "max" "min" | |
1378 | "overlay" "pos" "queued" "random" "reverse" "right" | |
1379 | "sign" "sourceline" "space" "stream" "strip" | |
1380 | "substr" "subword" "symbol" "time" "translate" | |
1381 | "trunc" "value" "verify" "word" "wordindex" | |
1382 | "wordlength" "wordpos" "words" "xrange" "x2b" "x2c" | |
1383 | "x2d")))) | |
1384 | ||
1385 | (setq font-lock-keywords | |
1386 | (list | |
1387 | 't | |
1388 | ||
1389 | ;; --- Set up the keywords defined above --- | |
1390 | ||
1391 | (list (concat "\\<\\(" rexx-keywords "\\)\\>") | |
1392 | '(0 font-lock-keyword-face)) | |
1393 | ||
1394 | ;; --- Fontify all symbols the same way --- | |
1395 | ||
1396 | (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|" | |
1397 | "[A-Za-z0-9.!?_#@$]+\\)") | |
1398 | '(0 font-lock-variable-name-face)) | |
1399 | ||
1400 | ;; --- And everything else is punctuation --- | |
1401 | ||
1402 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1403 | '(0 mdw-punct-face)))))) | |
1404 | ||
1405 | ;;;----- Standard ML programming style -------------------------------------- | |
1406 | ||
1407 | (defun mdw-fontify-sml () | |
1408 | ||
1409 | ;; --- Make underscore an honorary letter --- | |
1410 | ||
1411 | (modify-syntax-entry ?_ "w") | |
1412 | (modify-syntax-entry ?' "w") | |
1413 | ||
1414 | ;; --- Set fill prefix --- | |
1415 | ||
1416 | (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)") | |
1417 | ||
1418 | ;; --- Now define fontification things --- | |
1419 | ||
02109a0d | 1420 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1421 | (let ((sml-keywords |
1422 | (make-regexp '("abstype" "and" "andalso" "as" | |
1423 | "case" | |
1424 | "datatype" "do" | |
1425 | "else" "end" "eqtype" "exception" | |
1426 | "fn" "fun" "functor" | |
1427 | "handle" | |
1428 | "if" "in" "include" "infix" "infixr" | |
1429 | "let" "local" | |
1430 | "nonfix" | |
1431 | "of" "op" "open" "orelse" | |
1432 | "raise" "rec" | |
1433 | "sharing" "sig" "signature" "struct" "structure" | |
1434 | "then" "type" | |
1435 | "val" | |
1436 | "where" "while" "with" "withtype")))) | |
1437 | ||
1438 | (setq font-lock-keywords | |
1439 | (list | |
1440 | 't | |
1441 | ||
1442 | ;; --- Set up the keywords defined above --- | |
1443 | ||
1444 | (list (concat "\\<\\(" sml-keywords "\\)\\>") | |
1445 | '(0 font-lock-keyword-face)) | |
1446 | ||
1447 | ;; --- At least numbers are simpler than C --- | |
1448 | ||
1449 | (list (concat "\\<\\(\\~\\|\\)" | |
1450 | "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|" | |
852cd5fb MW |
1451 | "[wW][0-9]+\\)\\|" |
1452 | "\\([0-9]+\\(\\.[0-9]+\\|\\)" | |
1453 | "\\([eE]\\(\\~\\|\\)" | |
1454 | "[0-9]+\\|\\)\\)\\)") | |
f617db13 MW |
1455 | '(0 mdw-number-face)) |
1456 | ||
1457 | ;; --- And anything else is punctuation --- | |
1458 | ||
1459 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1460 | '(0 mdw-punct-face)))))) | |
1461 | ||
1462 | ;;;----- Haskell configuration ---------------------------------------------- | |
1463 | ||
1464 | (defun mdw-fontify-haskell () | |
1465 | ||
1466 | ;; --- Fiddle with syntax table to get comments right --- | |
1467 | ||
1468 | (modify-syntax-entry ?_ "w") | |
1469 | (modify-syntax-entry ?' "\"") | |
1470 | (modify-syntax-entry ?- ". 123") | |
1471 | (modify-syntax-entry ?{ ". 1b") | |
1472 | (modify-syntax-entry ?} ". 4b") | |
1473 | (modify-syntax-entry ?\n ">") | |
1474 | ||
1475 | ;; --- Set fill prefix --- | |
1476 | ||
1477 | (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)") | |
1478 | ||
1479 | ;; --- Fiddle with fontification --- | |
1480 | ||
02109a0d | 1481 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1482 | (let ((haskell-keywords |
1483 | (make-regexp '("as" "case" "ccall" "class" "data" "default" | |
1484 | "deriving" "do" "else" "foreign" "hiding" "if" | |
1485 | "import" "in" "infix" "infixl" "infixr" "instance" | |
1486 | "let" "module" "newtype" "of" "qualified" "safe" | |
1487 | "stdcall" "then" "type" "unsafe" "where")))) | |
1488 | ||
1489 | (setq font-lock-keywords | |
1490 | (list | |
1491 | 't | |
1492 | (list "--.*$" | |
1493 | '(0 font-lock-comment-face)) | |
1494 | (list (concat "\\<\\(" haskell-keywords "\\)\\>") | |
1495 | '(0 font-lock-keyword-face)) | |
1496 | (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
1497 | "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)" | |
1498 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)") | |
1499 | '(0 mdw-number-face)) | |
1500 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1501 | '(0 mdw-punct-face)))))) | |
1502 | ||
1503 | ;;;----- Texinfo configuration ---------------------------------------------- | |
1504 | ||
1505 | (defun mdw-fontify-texinfo () | |
1506 | ||
1507 | ;; --- Set fill prefix --- | |
1508 | ||
1509 | (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)") | |
1510 | ||
1511 | ;; --- Real fontification things --- | |
1512 | ||
02109a0d | 1513 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1514 | (setq font-lock-keywords |
1515 | (list | |
1516 | 't | |
1517 | ||
1518 | ;; --- Environment names are keywords --- | |
1519 | ||
1520 | (list "@\\(end\\) *\\([a-zA-Z]*\\)?" | |
1521 | '(2 font-lock-keyword-face)) | |
1522 | ||
1523 | ;; --- Unmark escaped magic characters --- | |
1524 | ||
1525 | (list "\\(@\\)\\([@{}]\\)" | |
1526 | '(1 font-lock-keyword-face) | |
1527 | '(2 font-lock-variable-name-face)) | |
1528 | ||
1529 | ;; --- Make sure we get comments properly --- | |
1530 | ||
1531 | (list "@c\\(\\|omment\\)\\( .*\\)?$" | |
1532 | '(0 font-lock-comment-face)) | |
1533 | ||
1534 | ;; --- Command names are keywords --- | |
1535 | ||
1536 | (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)" | |
1537 | '(0 font-lock-keyword-face)) | |
1538 | ||
1539 | ;; --- Fontify TeX special characters as punctuation --- | |
1540 | ||
1541 | (list "[{}]+" | |
1542 | '(0 mdw-punct-face))))) | |
1543 | ||
1544 | ;;;----- TeX and LaTeX configuration ---------------------------------------- | |
1545 | ||
1546 | (defun mdw-fontify-tex () | |
1547 | (setq ispell-parser 'tex) | |
1548 | ||
1549 | ;; --- Don't make maths into a string --- | |
1550 | ||
1551 | (modify-syntax-entry ?$ ".") | |
1552 | (modify-syntax-entry ?$ "." font-lock-syntax-table) | |
1553 | (local-set-key [?$] 'self-insert-command) | |
1554 | ||
1555 | ;; --- Set fill prefix --- | |
1556 | ||
1557 | (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)") | |
1558 | ||
1559 | ;; --- Real fontification things --- | |
1560 | ||
02109a0d | 1561 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1562 | (setq font-lock-keywords |
1563 | (list | |
1564 | 't | |
1565 | ||
1566 | ;; --- Environment names are keywords --- | |
1567 | ||
1568 | (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)" | |
1569 | "{\\([^}\n]*\\)}") | |
1570 | '(2 font-lock-keyword-face)) | |
1571 | ||
1572 | ;; --- Suspended environment names are keywords too --- | |
1573 | ||
1574 | (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?" | |
1575 | "{\\([^}\n]*\\)}") | |
1576 | '(3 font-lock-keyword-face)) | |
1577 | ||
1578 | ;; --- Command names are keywords --- | |
1579 | ||
1580 | (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)" | |
1581 | '(0 font-lock-keyword-face)) | |
1582 | ||
1583 | ;; --- Handle @/.../ for italics --- | |
1584 | ||
1585 | ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)" | |
852cd5fb MW |
1586 | ;; '(1 font-lock-keyword-face) |
1587 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1588 | |
1589 | ;; --- Handle @*...* for boldness --- | |
1590 | ||
1591 | ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)" | |
852cd5fb MW |
1592 | ;; '(1 font-lock-keyword-face) |
1593 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1594 | |
1595 | ;; --- Handle @`...' for literal syntax things --- | |
1596 | ||
1597 | ;; (list "\\(@`\\)\\([^']*\\)\\('\\)" | |
852cd5fb MW |
1598 | ;; '(1 font-lock-keyword-face) |
1599 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1600 | |
1601 | ;; --- Handle @<...> for nonterminals --- | |
1602 | ||
1603 | ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)" | |
852cd5fb MW |
1604 | ;; '(1 font-lock-keyword-face) |
1605 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1606 | |
1607 | ;; --- Handle other @-commands --- | |
1608 | ||
1609 | ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)" | |
852cd5fb | 1610 | ;; '(0 font-lock-keyword-face)) |
f617db13 MW |
1611 | |
1612 | ;; --- Make sure we get comments properly --- | |
1613 | ||
1614 | (list "%.*" | |
1615 | '(0 font-lock-comment-face)) | |
1616 | ||
1617 | ;; --- Fontify TeX special characters as punctuation --- | |
1618 | ||
1619 | (list "[$^_{}#&]" | |
1620 | '(0 mdw-punct-face))))) | |
1621 | ||
1622 | ;;;----- Shell scripts ------------------------------------------------------ | |
1623 | ||
1624 | (defun mdw-setup-sh-script-mode () | |
1625 | ||
1626 | ;; --- Fetch the shell interpreter's name --- | |
1627 | ||
1628 | (let ((shell-name sh-shell-file)) | |
1629 | ||
1630 | ;; --- Try reading the hash-bang line --- | |
1631 | ||
1632 | (save-excursion | |
1633 | (goto-char (point-min)) | |
1634 | (if (looking-at "#![ \t]*\\([^ \t\n]*\\)") | |
1635 | (setq shell-name (match-string 1)))) | |
1636 | ||
1637 | ;; --- Now try to set the shell --- | |
1638 | ;; | |
1639 | ;; Don't let `sh-set-shell' bugger up my script. | |
1640 | ||
1641 | (let ((executable-set-magic #'(lambda (s &rest r) s))) | |
1642 | (sh-set-shell shell-name))) | |
1643 | ||
1644 | ;; --- Now enable my keys and the fontification --- | |
1645 | ||
1646 | (mdw-misc-mode-config) | |
1647 | ||
1648 | ;; --- Set the indentation level correctly --- | |
1649 | ||
1650 | (setq sh-indentation 2) | |
1651 | (setq sh-basic-offset 2)) | |
1652 | ||
1653 | ;;;----- Messages-file mode ------------------------------------------------- | |
1654 | ||
1655 | (defun message-mode-guts () | |
1656 | (setq messages-mode-syntax-table (make-syntax-table)) | |
1657 | (set-syntax-table messages-mode-syntax-table) | |
1658 | (modify-syntax-entry ?_ "w" messages-mode-syntax-table) | |
1659 | (modify-syntax-entry ?- "w" messages-mode-syntax-table) | |
1660 | (modify-syntax-entry ?0 "w" messages-mode-syntax-table) | |
1661 | (modify-syntax-entry ?1 "w" messages-mode-syntax-table) | |
1662 | (modify-syntax-entry ?2 "w" messages-mode-syntax-table) | |
1663 | (modify-syntax-entry ?3 "w" messages-mode-syntax-table) | |
1664 | (modify-syntax-entry ?4 "w" messages-mode-syntax-table) | |
1665 | (modify-syntax-entry ?5 "w" messages-mode-syntax-table) | |
1666 | (modify-syntax-entry ?6 "w" messages-mode-syntax-table) | |
1667 | (modify-syntax-entry ?7 "w" messages-mode-syntax-table) | |
1668 | (modify-syntax-entry ?8 "w" messages-mode-syntax-table) | |
1669 | (modify-syntax-entry ?9 "w" messages-mode-syntax-table) | |
1670 | (make-local-variable 'comment-start) | |
1671 | (make-local-variable 'comment-end) | |
1672 | (make-local-variable 'indent-line-function) | |
1673 | (setq indent-line-function 'indent-relative) | |
1674 | (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)") | |
1675 | (make-local-variable 'font-lock-defaults) | |
1676 | (make-local-variable 'message-mode-keywords) | |
1677 | (let ((keywords | |
1678 | (make-regexp '("array" "bitmap" "callback" "docs[ \t]+enum" | |
1679 | "export" "enum" "fixed-octetstring" "flags" | |
1680 | "harmless" "map" "nested" "optional" | |
1681 | "optional-tagged" "package" "primitive" | |
1682 | "primitive-nullfree" "relaxed[ \t]+enum" | |
1683 | "set" "table" "tagged-optional" "union" | |
1684 | "variadic" "vector" "version" "version-tag")))) | |
1685 | (setq message-mode-keywords | |
1686 | (list | |
1687 | (list (concat "\\<\\(" keywords "\\)\\>:") | |
1688 | '(0 font-lock-keyword-face)) | |
1689 | '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face)) | |
1690 | '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)" | |
1691 | (0 font-lock-variable-name-face)) | |
1692 | '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face)) | |
1693 | '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1694 | (0 mdw-punct-face))))) | |
1695 | (setq font-lock-defaults | |
1696 | '(message-mode-keywords nil nil nil nil)) | |
1697 | (run-hooks 'messages-file-hook)) | |
1698 | ||
1699 | (defun messages-mode () | |
1700 | (interactive) | |
1701 | (fundamental-mode) | |
1702 | (setq major-mode 'messages-mode) | |
1703 | (setq mode-name "Messages") | |
1704 | (message-mode-guts) | |
1705 | (modify-syntax-entry ?# "<" messages-mode-syntax-table) | |
1706 | (modify-syntax-entry ?\n ">" messages-mode-syntax-table) | |
1707 | (setq comment-start "# ") | |
1708 | (setq comment-end "") | |
1709 | (turn-on-font-lock-if-enabled) | |
1710 | (run-hooks 'messages-mode-hook)) | |
1711 | ||
1712 | (defun cpp-messages-mode () | |
1713 | (interactive) | |
1714 | (fundamental-mode) | |
1715 | (setq major-mode 'cpp-messages-mode) | |
1716 | (setq mode-name "CPP Messages") | |
1717 | (message-mode-guts) | |
1718 | (modify-syntax-entry ?* ". 23" messages-mode-syntax-table) | |
1719 | (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table) | |
1720 | (setq comment-start "/* ") | |
1721 | (setq comment-end " */") | |
1722 | (let ((preprocessor-keywords | |
1723 | (make-regexp '("assert" "define" "elif" "else" "endif" "error" | |
1724 | "ident" "if" "ifdef" "ifndef" "import" "include" | |
1725 | "line" "pragma" "unassert" "undef" "warning")))) | |
1726 | (setq message-mode-keywords | |
1727 | (append (list (list (concat "^[ \t]*\\#[ \t]*" | |
1728 | "\\(include\\|import\\)" | |
1729 | "[ \t]*\\(<[^>]+\\(>\\|\\)\\)") | |
1730 | '(2 font-lock-string-face)) | |
1731 | (list (concat "^\\([ \t]*#[ \t]*\\(\\(" | |
1732 | preprocessor-keywords | |
852cd5fb | 1733 | "\\)\\>\\|[0-9]+\\|$\\)\\)") |
f617db13 MW |
1734 | '(1 font-lock-keyword-face))) |
1735 | message-mode-keywords))) | |
f617db13 | 1736 | (turn-on-font-lock-if-enabled) |
297d60aa | 1737 | (run-hooks 'cpp-messages-mode-hook)) |
f617db13 | 1738 | |
297d60aa MW |
1739 | (add-hook 'messages-mode-hook 'mdw-misc-mode-config t) |
1740 | (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t) | |
f617db13 MW |
1741 | ; (add-hook 'messages-file-hook 'mdw-fontify-messages t) |
1742 | ||
1743 | ;;;----- Messages-file mode ------------------------------------------------- | |
1744 | ||
1745 | (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face | |
1746 | "Face to use for subsittution directives.") | |
1747 | (make-face 'mallow-driver-substitution-face) | |
1748 | (defvar mallow-driver-text-face 'mallow-driver-text-face | |
1749 | "Face to use for body text.") | |
1750 | (make-face 'mallow-driver-text-face) | |
1751 | ||
1752 | (defun mallow-driver-mode () | |
1753 | (interactive) | |
1754 | (fundamental-mode) | |
1755 | (setq major-mode 'mallow-driver-mode) | |
1756 | (setq mode-name "Mallow driver") | |
1757 | (setq mallow-driver-mode-syntax-table (make-syntax-table)) | |
1758 | (set-syntax-table mallow-driver-mode-syntax-table) | |
1759 | (make-local-variable 'comment-start) | |
1760 | (make-local-variable 'comment-end) | |
1761 | (make-local-variable 'indent-line-function) | |
1762 | (setq indent-line-function 'indent-relative) | |
1763 | (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)") | |
1764 | (make-local-variable 'font-lock-defaults) | |
1765 | (make-local-variable 'mallow-driver-mode-keywords) | |
1766 | (let ((keywords | |
1767 | (make-regexp '("each" "divert" "file" "if" | |
1768 | "perl" "set" "string" "type" "write")))) | |
1769 | (setq mallow-driver-mode-keywords | |
1770 | (list | |
1771 | (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$") | |
1772 | '(0 font-lock-keyword-face)) | |
1773 | (list "^%\\s *\\(#.*\\|\\)$" | |
1774 | '(0 font-lock-comment-face)) | |
1775 | (list "^%" | |
1776 | '(0 font-lock-keyword-face)) | |
1777 | (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face)) | |
1778 | (list "\\${[^}]*}" | |
1779 | '(0 mallow-driver-substitution-face t))))) | |
1780 | (setq font-lock-defaults | |
1781 | '(mallow-driver-mode-keywords nil nil nil nil)) | |
1782 | (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table) | |
1783 | (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table) | |
1784 | (setq comment-start "%# ") | |
1785 | (setq comment-end "") | |
1786 | (turn-on-font-lock-if-enabled) | |
1787 | (run-hooks 'mallow-driver-mode-hook)) | |
1788 | ||
1789 | (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t) | |
1790 | ||
1791 | ;;;----- NFast debugs ------------------------------------------------------- | |
1792 | ||
1793 | (defun nfast-debug-mode () | |
1794 | (interactive) | |
1795 | (fundamental-mode) | |
1796 | (setq major-mode 'nfast-debug-mode) | |
1797 | (setq mode-name "NFast debug") | |
1798 | (setq messages-mode-syntax-table (make-syntax-table)) | |
1799 | (set-syntax-table messages-mode-syntax-table) | |
1800 | (make-local-variable 'font-lock-defaults) | |
1801 | (make-local-variable 'nfast-debug-mode-keywords) | |
1802 | (setq truncate-lines t) | |
1803 | (setq nfast-debug-mode-keywords | |
1804 | (list | |
1805 | '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)" | |
1806 | (0 font-lock-keyword-face)) | |
1807 | (list (concat "^[ \t]+\\(\\(" | |
1808 | "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]" | |
1809 | "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]" | |
1810 | "[ \t]+\\)*" | |
1811 | "[0-9a-fA-F]+\\)[ \t]*$") | |
1812 | '(0 mdw-number-face)) | |
1813 | '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>" | |
1814 | (1 font-lock-keyword-face)) | |
1815 | '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>" | |
1816 | (1 font-lock-warning-face)) | |
1817 | '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>" | |
1818 | (1 nil)) | |
1819 | (list (concat "^[ \t]+\\.cmd=[ \t]+" | |
1820 | "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>") | |
1821 | '(1 font-lock-keyword-face)) | |
1822 | '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face)) | |
1823 | '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face)) | |
1824 | '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face)) | |
1825 | '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face)))) | |
1826 | (setq font-lock-defaults | |
1827 | '(nfast-debug-mode-keywords nil nil nil nil)) | |
1828 | (turn-on-font-lock-if-enabled) | |
1829 | (run-hooks 'nfast-debug-mode-hook)) | |
1830 | ||
1831 | ;;;----- Other languages ---------------------------------------------------- | |
1832 | ||
1833 | ;; --- Smalltalk --- | |
1834 | ||
1835 | (defun mdw-setup-smalltalk () | |
1836 | (and mdw-auto-indent | |
1837 | (local-set-key "\C-m" 'smalltalk-newline-and-indent)) | |
1838 | (make-variable-buffer-local 'mdw-auto-indent) | |
1839 | (setq mdw-auto-indent nil) | |
1840 | (local-set-key "\C-i" 'smalltalk-reindent)) | |
1841 | ||
1842 | (defun mdw-fontify-smalltalk () | |
02109a0d | 1843 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1844 | (setq font-lock-keywords |
1845 | (list | |
1846 | 't | |
1847 | (list "\\<[A-Z][a-zA-Z0-9]*\\>" | |
1848 | '(0 font-lock-keyword-face)) | |
1849 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1850 | "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1851 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
1852 | '(0 mdw-number-face)) | |
1853 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1854 | '(0 mdw-punct-face))))) | |
1855 | ||
1856 | ;; --- Lispy languages --- | |
1857 | ||
1858 | (defun mdw-indent-newline-and-indent () | |
1859 | (interactive) | |
1860 | (indent-for-tab-command) | |
1861 | (newline-and-indent)) | |
1862 | ||
1863 | (eval-after-load "cl-indent" | |
1864 | '(progn | |
1865 | (mapc #'(lambda (pair) | |
1866 | (put (car pair) | |
1867 | 'common-lisp-indent-function | |
1868 | (cdr pair))) | |
1869 | '((destructuring-bind . ((&whole 4 &rest 1) 4 &body)) | |
1870 | (multiple-value-bind . ((&whole 4 &rest 1) 4 &body)))))) | |
1871 | ||
1872 | (defun mdw-common-lisp-indent () | |
1873 | (make-variable-buffer-local 'lisp-indent-function) | |
1874 | (setq lisp-indent-function 'common-lisp-indent-function)) | |
1875 | ||
1876 | (defun mdw-fontify-lispy () | |
1877 | ||
1878 | ;; --- Set fill prefix --- | |
1879 | ||
1880 | (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)") | |
1881 | ||
1882 | ;; --- Not much fontification needed --- | |
1883 | ||
02109a0d | 1884 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1885 | (setq font-lock-keywords |
1886 | (list | |
1887 | 't | |
1888 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1889 | '(0 mdw-punct-face))))) | |
1890 | ||
1891 | (defun comint-send-and-indent () | |
1892 | (interactive) | |
1893 | (comint-send-input) | |
1894 | (and mdw-auto-indent | |
1895 | (indent-for-tab-command))) | |
1896 | ||
1897 | ;;;----- Text mode ---------------------------------------------------------- | |
1898 | ||
1899 | (defun mdw-text-mode () | |
1900 | (setq fill-column 72) | |
1901 | (flyspell-mode t) | |
1902 | (mdw-standard-fill-prefix | |
1903 | "\\([ \t]*\\([A-Za-z0-9]*[>#|:] ?\\)*[ \t]*\\)" 3) | |
1904 | (auto-fill-mode 1)) | |
1905 | ||
1906 | ;;;----- Shell mode --------------------------------------------------------- | |
1907 | ||
1908 | (defun mdw-sh-mode-setup () | |
1909 | (local-set-key [?\C-a] 'comint-bol) | |
1910 | (add-hook 'comint-output-filter-functions | |
1911 | 'comint-watch-for-password-prompt)) | |
1912 | ||
1913 | (defun mdw-term-mode-setup () | |
9a3fa88e | 1914 |