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 | ||
943 | ;;;----- Awk programming configuration -------------------------------------- | |
944 | ||
945 | ;; --- Make Awk indentation nice --- | |
946 | ||
947 | (defun mdw-awk-style () | |
948 | (c-add-style "[mdw] Awk style" | |
949 | '((c-basic-offset . 2) | |
950 | (c-tab-always-indent . nil) | |
951 | (c-offsets-alist (substatement-open . 0) | |
952 | (statement-cont . 0) | |
953 | (statement-case-intro . +))) | |
954 | t)) | |
955 | ||
956 | ;; --- Declare Awk fontification style --- | |
957 | ||
958 | (defun mdw-fontify-awk () | |
959 | ||
960 | ;; --- Miscellaneous fiddling --- | |
961 | ||
962 | (modify-syntax-entry ?_ "w") | |
963 | (mdw-awk-style) | |
964 | (setq c-backslash-column 72) | |
965 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
966 | ||
967 | ;; --- Now define things to be fontified --- | |
968 | ||
02109a0d | 969 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
970 | (let ((c-keywords |
971 | (make-regexp '("BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT" | |
972 | "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR" | |
973 | "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS" | |
974 | "RSTART" "RLENGTH" "RT" "SUBSEP" | |
975 | "atan2" "break" "close" "continue" "cos" "delete" | |
976 | "do" "else" "exit" "exp" "fflush" "file" "for" "func" | |
977 | "function" "gensub" "getline" "gsub" "if" "in" | |
978 | "index" "int" "length" "log" "match" "next" "rand" | |
979 | "return" "print" "printf" "sin" "split" "sprintf" | |
980 | "sqrt" "srand" "strftime" "sub" "substr" "system" | |
981 | "systime" "tolower" "toupper" "while")))) | |
982 | ||
983 | (setq font-lock-keywords | |
984 | (list | |
985 | 't | |
986 | ||
987 | ;; --- Handle the keywords defined above --- | |
988 | ||
989 | (list (concat "\\<\\(" c-keywords "\\)\\>") | |
990 | '(0 font-lock-keyword-face)) | |
991 | ||
992 | ;; --- Handle numbers too --- | |
993 | ;; | |
994 | ;; The following isn't quite right, but it's close enough. | |
995 | ||
996 | (list (concat "\\<\\(" | |
997 | "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
998 | "[0-9]+\\(\\.[0-9]*\\|\\)" | |
999 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" | |
1000 | "[uUlL]*") | |
1001 | '(0 mdw-number-face)) | |
1002 | ||
1003 | ;; --- And anything else is punctuation --- | |
1004 | ||
1005 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1006 | '(0 mdw-punct-face)))))) | |
1007 | ||
1008 | ;;;----- Perl programming style --------------------------------------------- | |
1009 | ||
1010 | ;; --- Perl indentation style --- | |
1011 | ||
1012 | (setq cperl-tab-always-indent nil) | |
1013 | ||
1014 | (setq cperl-indent-level 2) | |
1015 | (setq cperl-continued-statement-offset 2) | |
1016 | (setq cperl-continued-brace-offset 0) | |
1017 | (setq cperl-brace-offset -2) | |
1018 | (setq cperl-brace-imaginary-offset 0) | |
1019 | (setq cperl-label-offset 0) | |
1020 | ||
1021 | ;; --- Define perl fontification style --- | |
1022 | ||
1023 | (defun mdw-fontify-perl () | |
1024 | ||
1025 | ;; --- Miscellaneous fiddling --- | |
1026 | ||
1027 | (modify-syntax-entry ?_ "w") | |
1028 | (modify-syntax-entry ?$ "\\") | |
1029 | (modify-syntax-entry ?$ "\\" font-lock-syntax-table) | |
1030 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
1031 | ||
1032 | ;; --- Now define fontification things --- | |
1033 | ||
02109a0d | 1034 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1035 | (let ((perl-keywords |
1036 | (make-regexp '("and" "cmp" "continue" "do" "else" "elsif" "eq" | |
1037 | "for" "foreach" "ge" "gt" "goto" "if" | |
1038 | "last" "le" "lt" "local" "my" "ne" "next" "or" | |
1039 | "package" "redo" "require" "return" "sub" | |
1040 | "undef" "unless" "until" "use" "while")))) | |
1041 | ||
1042 | (setq font-lock-keywords | |
1043 | (list | |
1044 | 't | |
1045 | ||
1046 | ;; --- Set up the keywords defined above --- | |
1047 | ||
1048 | (list (concat "\\<\\(" perl-keywords "\\)\\>") | |
1049 | '(0 font-lock-keyword-face)) | |
1050 | ||
1051 | ;; --- At least numbers are simpler than C --- | |
1052 | ||
1053 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1054 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1055 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
1056 | '(0 mdw-number-face)) | |
1057 | ||
1058 | ;; --- And anything else is punctuation --- | |
1059 | ||
1060 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1061 | '(0 mdw-punct-face)))))) | |
1062 | ||
1063 | (defun perl-number-tests (&optional arg) | |
1064 | "Assign consecutive numbers to lines containing `#t'. With ARG, | |
1065 | strip numbers instead." | |
1066 | (interactive "P") | |
1067 | (save-excursion | |
1068 | (goto-char (point-min)) | |
1069 | (let ((i 0) (fmt (if arg "" " %4d"))) | |
1070 | (while (search-forward "#t" nil t) | |
1071 | (delete-region (point) (line-end-position)) | |
1072 | (setq i (1+ i)) | |
1073 | (insert (format fmt i))) | |
1074 | (goto-char (point-min)) | |
1075 | (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t) | |
1076 | (replace-match (format "\\1%d" i)))))) | |
1077 | ||
1078 | ;;;----- Python programming style ------------------------------------------- | |
1079 | ||
1080 | ;; --- Define Python fontification style --- | |
1081 | ||
1082 | (trap (require 'pyrex-mode)) | |
1083 | (defun mdw-fontify-python () | |
1084 | ||
1085 | ;; --- Miscellaneous fiddling --- | |
1086 | ||
1087 | (modify-syntax-entry ?_ "w") | |
1088 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
1089 | ||
1090 | ;; --- Now define fontification things --- | |
1091 | ||
02109a0d | 1092 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1093 | (let ((python-keywords |
1094 | (make-regexp '("and" "as" "assert" "break" "class" "continue" "def" | |
1095 | "del" "elif" "else" "except" "exec" "finally" "for" | |
1096 | "from" "global" "if" "import" "in" "is" "lambda" | |
1097 | "not" "or" "pass" "print" "raise" "return" "try" | |
043e413b | 1098 | "while" "yield")))) |
f617db13 MW |
1099 | (setq font-lock-keywords |
1100 | (list | |
1101 | 't | |
1102 | ||
1103 | ;; --- Set up the keywords defined above --- | |
1104 | ||
1105 | (list (concat "\\<\\(" python-keywords "\\)\\>") | |
1106 | '(0 font-lock-keyword-face)) | |
1107 | ||
1108 | ;; --- At least numbers are simpler than C --- | |
1109 | ||
1110 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1111 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1112 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)") | |
1113 | '(0 mdw-number-face)) | |
1114 | ||
1115 | ;; --- And anything else is punctuation --- | |
1116 | ||
1117 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1118 | '(0 mdw-punct-face)))))) | |
1119 | ||
1120 | ;;;----- ARM assembler programming configuration ---------------------------- | |
1121 | ||
1122 | ;; --- There doesn't appear to be an Emacs mode for this yet --- | |
1123 | ;; | |
1124 | ;; Better do something about that, I suppose. | |
1125 | ||
1126 | (defvar arm-assembler-mode-map nil) | |
1127 | (defvar arm-assembler-abbrev-table nil) | |
1128 | (defvar arm-assembler-mode-syntax-table (make-syntax-table)) | |
1129 | ||
1130 | (or arm-assembler-mode-map | |
1131 | (progn | |
1132 | (setq arm-assembler-mode-map (make-sparse-keymap)) | |
1133 | (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline) | |
1134 | (define-key arm-assembler-mode-map [C-return] 'newline) | |
1135 | (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop))) | |
1136 | ||
1137 | (defun arm-assembler-mode () | |
1138 | "Major mode for ARM assembler programs" | |
1139 | (interactive) | |
1140 | ||
1141 | ;; --- Do standard major mode things --- | |
1142 | ||
1143 | (kill-all-local-variables) | |
1144 | (use-local-map arm-assembler-mode-map) | |
1145 | (setq local-abbrev-table arm-assembler-abbrev-table) | |
1146 | (setq major-mode 'arm-assembler-mode) | |
1147 | (setq mode-name "ARM assembler") | |
1148 | ||
1149 | ;; --- Set up syntax table --- | |
1150 | ||
1151 | (set-syntax-table arm-assembler-mode-syntax-table) | |
1152 | (modify-syntax-entry ?; ; Nasty hack | |
1153 | "<" arm-assembler-mode-syntax-table) | |
1154 | (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table) | |
1155 | (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table) | |
1156 | ||
1157 | (make-local-variable 'comment-start) | |
1158 | (setq comment-start ";") | |
1159 | (make-local-variable 'comment-end) | |
1160 | (setq comment-end "") | |
1161 | (make-local-variable 'comment-column) | |
1162 | (setq comment-column 48) | |
1163 | (make-local-variable 'comment-start-skip) | |
1164 | (setq comment-start-skip ";+[ \t]*") | |
1165 | ||
1166 | ;; --- Play with indentation --- | |
1167 | ||
1168 | (make-local-variable 'indent-line-function) | |
1169 | (setq indent-line-function 'indent-relative-maybe) | |
1170 | ||
1171 | ;; --- Set fill prefix --- | |
1172 | ||
1173 | (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)") | |
1174 | ||
1175 | ;; --- Fiddle with fontification --- | |
1176 | ||
02109a0d | 1177 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1178 | (setq font-lock-keywords |
1179 | (list | |
1180 | 't | |
1181 | ||
1182 | ;; --- Handle numbers too --- | |
1183 | ;; | |
1184 | ;; The following isn't quite right, but it's close enough. | |
1185 | ||
1186 | (list (concat "\\(" | |
1187 | "&[0-9a-fA-F]+\\|" | |
1188 | "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)" | |
1189 | "\\)") | |
1190 | '(0 mdw-number-face)) | |
1191 | ||
1192 | ;; --- Do something about operators --- | |
1193 | ||
1194 | (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)" | |
1195 | '(1 font-lock-keyword-face) | |
1196 | '(2 font-lock-string-face)) | |
1197 | (list ":[a-zA-Z]+:" | |
1198 | '(0 font-lock-keyword-face)) | |
1199 | ||
1200 | ;; --- Do menemonics and directives --- | |
1201 | ||
1202 | (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)" | |
1203 | '(1 font-lock-keyword-face)) | |
1204 | ||
1205 | ;; --- And anything else is punctuation --- | |
1206 | ||
1207 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1208 | '(0 mdw-punct-face)))) | |
1209 | ||
1210 | (run-hooks 'arm-assembler-mode-hook)) | |
1211 | ||
1212 | ;;;----- TCL configuration -------------------------------------------------- | |
1213 | ||
1214 | (defun mdw-fontify-tcl () | |
1215 | (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$)) | |
1216 | (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") | |
02109a0d | 1217 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1218 | (setq font-lock-keywords |
1219 | (list | |
1220 | 't | |
1221 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1222 | "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1223 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
1224 | '(0 mdw-number-face)) | |
1225 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1226 | '(0 mdw-punct-face))))) | |
1227 | ||
1228 | ;;;----- REXX configuration ------------------------------------------------- | |
1229 | ||
1230 | (defun mdw-rexx-electric-* () | |
1231 | (interactive) | |
1232 | (insert ?*) | |
1233 | (rexx-indent-line)) | |
1234 | ||
1235 | (defun mdw-rexx-indent-newline-indent () | |
1236 | (interactive) | |
1237 | (rexx-indent-line) | |
1238 | (if abbrev-mode (expand-abbrev)) | |
1239 | (newline-and-indent)) | |
1240 | ||
1241 | (defun mdw-fontify-rexx () | |
1242 | ||
1243 | ;; --- Various bits of fiddling --- | |
1244 | ||
1245 | (setq mdw-auto-indent nil) | |
1246 | (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent) | |
1247 | (local-set-key [?*] 'mdw-rexx-electric-*) | |
1248 | (mapcar #'(lambda (ch) (modify-syntax-entry ch "w")) | |
1249 | '(?. ?! ?? ?_ ?# ?@ ?$)) | |
1250 | (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)") | |
1251 | ||
1252 | ;; --- Set up keywords and things for fontification --- | |
1253 | ||
1254 | (make-local-variable 'font-lock-keywords-case-fold-search) | |
1255 | (setq font-lock-keywords-case-fold-search t) | |
1256 | ||
1257 | (setq rexx-indent 2) | |
1258 | (setq rexx-end-indent rexx-indent) | |
1259 | (setq rexx-tab-always-indent nil) | |
1260 | (setq rexx-cont-indent rexx-indent) | |
1261 | ||
02109a0d | 1262 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1263 | (let ((rexx-keywords |
1264 | (make-regexp '("address" "arg" "by" "call" "digits" "do" "drop" | |
1265 | "else" "end" "engineering" "exit" "expose" "for" | |
1266 | "forever" "form" "fuzz" "if" "interpret" "iterate" | |
1267 | "leave" "linein" "name" "nop" "numeric" "off" "on" | |
1268 | "options" "otherwise" "parse" "procedure" "pull" | |
1269 | "push" "queue" "return" "say" "select" "signal" | |
1270 | "scientific" "source" "then" "trace" "to" "until" | |
1271 | "upper" "value" "var" "version" "when" "while" | |
1272 | "with" | |
1273 | ||
1274 | "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x" | |
1275 | "center" "center" "charin" "charout" "chars" | |
1276 | "compare" "condition" "copies" "c2d" "c2x" | |
1277 | "datatype" "date" "delstr" "delword" "d2c" "d2x" | |
1278 | "errortext" "format" "fuzz" "insert" "lastpos" | |
1279 | "left" "length" "lineout" "lines" "max" "min" | |
1280 | "overlay" "pos" "queued" "random" "reverse" "right" | |
1281 | "sign" "sourceline" "space" "stream" "strip" | |
1282 | "substr" "subword" "symbol" "time" "translate" | |
1283 | "trunc" "value" "verify" "word" "wordindex" | |
1284 | "wordlength" "wordpos" "words" "xrange" "x2b" "x2c" | |
1285 | "x2d")))) | |
1286 | ||
1287 | (setq font-lock-keywords | |
1288 | (list | |
1289 | 't | |
1290 | ||
1291 | ;; --- Set up the keywords defined above --- | |
1292 | ||
1293 | (list (concat "\\<\\(" rexx-keywords "\\)\\>") | |
1294 | '(0 font-lock-keyword-face)) | |
1295 | ||
1296 | ;; --- Fontify all symbols the same way --- | |
1297 | ||
1298 | (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|" | |
1299 | "[A-Za-z0-9.!?_#@$]+\\)") | |
1300 | '(0 font-lock-variable-name-face)) | |
1301 | ||
1302 | ;; --- And everything else is punctuation --- | |
1303 | ||
1304 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1305 | '(0 mdw-punct-face)))))) | |
1306 | ||
1307 | ;;;----- Standard ML programming style -------------------------------------- | |
1308 | ||
1309 | (defun mdw-fontify-sml () | |
1310 | ||
1311 | ;; --- Make underscore an honorary letter --- | |
1312 | ||
1313 | (modify-syntax-entry ?_ "w") | |
1314 | (modify-syntax-entry ?' "w") | |
1315 | ||
1316 | ;; --- Set fill prefix --- | |
1317 | ||
1318 | (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)") | |
1319 | ||
1320 | ;; --- Now define fontification things --- | |
1321 | ||
02109a0d | 1322 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1323 | (let ((sml-keywords |
1324 | (make-regexp '("abstype" "and" "andalso" "as" | |
1325 | "case" | |
1326 | "datatype" "do" | |
1327 | "else" "end" "eqtype" "exception" | |
1328 | "fn" "fun" "functor" | |
1329 | "handle" | |
1330 | "if" "in" "include" "infix" "infixr" | |
1331 | "let" "local" | |
1332 | "nonfix" | |
1333 | "of" "op" "open" "orelse" | |
1334 | "raise" "rec" | |
1335 | "sharing" "sig" "signature" "struct" "structure" | |
1336 | "then" "type" | |
1337 | "val" | |
1338 | "where" "while" "with" "withtype")))) | |
1339 | ||
1340 | (setq font-lock-keywords | |
1341 | (list | |
1342 | 't | |
1343 | ||
1344 | ;; --- Set up the keywords defined above --- | |
1345 | ||
1346 | (list (concat "\\<\\(" sml-keywords "\\)\\>") | |
1347 | '(0 font-lock-keyword-face)) | |
1348 | ||
1349 | ;; --- At least numbers are simpler than C --- | |
1350 | ||
1351 | (list (concat "\\<\\(\\~\\|\\)" | |
1352 | "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|" | |
852cd5fb MW |
1353 | "[wW][0-9]+\\)\\|" |
1354 | "\\([0-9]+\\(\\.[0-9]+\\|\\)" | |
1355 | "\\([eE]\\(\\~\\|\\)" | |
1356 | "[0-9]+\\|\\)\\)\\)") | |
f617db13 MW |
1357 | '(0 mdw-number-face)) |
1358 | ||
1359 | ;; --- And anything else is punctuation --- | |
1360 | ||
1361 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1362 | '(0 mdw-punct-face)))))) | |
1363 | ||
1364 | ;;;----- Haskell configuration ---------------------------------------------- | |
1365 | ||
1366 | (defun mdw-fontify-haskell () | |
1367 | ||
1368 | ;; --- Fiddle with syntax table to get comments right --- | |
1369 | ||
1370 | (modify-syntax-entry ?_ "w") | |
1371 | (modify-syntax-entry ?' "\"") | |
1372 | (modify-syntax-entry ?- ". 123") | |
1373 | (modify-syntax-entry ?{ ". 1b") | |
1374 | (modify-syntax-entry ?} ". 4b") | |
1375 | (modify-syntax-entry ?\n ">") | |
1376 | ||
1377 | ;; --- Set fill prefix --- | |
1378 | ||
1379 | (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)") | |
1380 | ||
1381 | ;; --- Fiddle with fontification --- | |
1382 | ||
02109a0d | 1383 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1384 | (let ((haskell-keywords |
1385 | (make-regexp '("as" "case" "ccall" "class" "data" "default" | |
1386 | "deriving" "do" "else" "foreign" "hiding" "if" | |
1387 | "import" "in" "infix" "infixl" "infixr" "instance" | |
1388 | "let" "module" "newtype" "of" "qualified" "safe" | |
1389 | "stdcall" "then" "type" "unsafe" "where")))) | |
1390 | ||
1391 | (setq font-lock-keywords | |
1392 | (list | |
1393 | 't | |
1394 | (list "--.*$" | |
1395 | '(0 font-lock-comment-face)) | |
1396 | (list (concat "\\<\\(" haskell-keywords "\\)\\>") | |
1397 | '(0 font-lock-keyword-face)) | |
1398 | (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" | |
1399 | "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)" | |
1400 | "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)") | |
1401 | '(0 mdw-number-face)) | |
1402 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1403 | '(0 mdw-punct-face)))))) | |
1404 | ||
1405 | ;;;----- Texinfo configuration ---------------------------------------------- | |
1406 | ||
1407 | (defun mdw-fontify-texinfo () | |
1408 | ||
1409 | ;; --- Set fill prefix --- | |
1410 | ||
1411 | (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)") | |
1412 | ||
1413 | ;; --- Real fontification things --- | |
1414 | ||
02109a0d | 1415 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1416 | (setq font-lock-keywords |
1417 | (list | |
1418 | 't | |
1419 | ||
1420 | ;; --- Environment names are keywords --- | |
1421 | ||
1422 | (list "@\\(end\\) *\\([a-zA-Z]*\\)?" | |
1423 | '(2 font-lock-keyword-face)) | |
1424 | ||
1425 | ;; --- Unmark escaped magic characters --- | |
1426 | ||
1427 | (list "\\(@\\)\\([@{}]\\)" | |
1428 | '(1 font-lock-keyword-face) | |
1429 | '(2 font-lock-variable-name-face)) | |
1430 | ||
1431 | ;; --- Make sure we get comments properly --- | |
1432 | ||
1433 | (list "@c\\(\\|omment\\)\\( .*\\)?$" | |
1434 | '(0 font-lock-comment-face)) | |
1435 | ||
1436 | ;; --- Command names are keywords --- | |
1437 | ||
1438 | (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)" | |
1439 | '(0 font-lock-keyword-face)) | |
1440 | ||
1441 | ;; --- Fontify TeX special characters as punctuation --- | |
1442 | ||
1443 | (list "[{}]+" | |
1444 | '(0 mdw-punct-face))))) | |
1445 | ||
1446 | ;;;----- TeX and LaTeX configuration ---------------------------------------- | |
1447 | ||
1448 | (defun mdw-fontify-tex () | |
1449 | (setq ispell-parser 'tex) | |
1450 | ||
1451 | ;; --- Don't make maths into a string --- | |
1452 | ||
1453 | (modify-syntax-entry ?$ ".") | |
1454 | (modify-syntax-entry ?$ "." font-lock-syntax-table) | |
1455 | (local-set-key [?$] 'self-insert-command) | |
1456 | ||
1457 | ;; --- Set fill prefix --- | |
1458 | ||
1459 | (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)") | |
1460 | ||
1461 | ;; --- Real fontification things --- | |
1462 | ||
02109a0d | 1463 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1464 | (setq font-lock-keywords |
1465 | (list | |
1466 | 't | |
1467 | ||
1468 | ;; --- Environment names are keywords --- | |
1469 | ||
1470 | (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)" | |
1471 | "{\\([^}\n]*\\)}") | |
1472 | '(2 font-lock-keyword-face)) | |
1473 | ||
1474 | ;; --- Suspended environment names are keywords too --- | |
1475 | ||
1476 | (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?" | |
1477 | "{\\([^}\n]*\\)}") | |
1478 | '(3 font-lock-keyword-face)) | |
1479 | ||
1480 | ;; --- Command names are keywords --- | |
1481 | ||
1482 | (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)" | |
1483 | '(0 font-lock-keyword-face)) | |
1484 | ||
1485 | ;; --- Handle @/.../ for italics --- | |
1486 | ||
1487 | ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)" | |
852cd5fb MW |
1488 | ;; '(1 font-lock-keyword-face) |
1489 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1490 | |
1491 | ;; --- Handle @*...* for boldness --- | |
1492 | ||
1493 | ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)" | |
852cd5fb MW |
1494 | ;; '(1 font-lock-keyword-face) |
1495 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1496 | |
1497 | ;; --- Handle @`...' for literal syntax things --- | |
1498 | ||
1499 | ;; (list "\\(@`\\)\\([^']*\\)\\('\\)" | |
852cd5fb MW |
1500 | ;; '(1 font-lock-keyword-face) |
1501 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1502 | |
1503 | ;; --- Handle @<...> for nonterminals --- | |
1504 | ||
1505 | ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)" | |
852cd5fb MW |
1506 | ;; '(1 font-lock-keyword-face) |
1507 | ;; '(3 font-lock-keyword-face)) | |
f617db13 MW |
1508 | |
1509 | ;; --- Handle other @-commands --- | |
1510 | ||
1511 | ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)" | |
852cd5fb | 1512 | ;; '(0 font-lock-keyword-face)) |
f617db13 MW |
1513 | |
1514 | ;; --- Make sure we get comments properly --- | |
1515 | ||
1516 | (list "%.*" | |
1517 | '(0 font-lock-comment-face)) | |
1518 | ||
1519 | ;; --- Fontify TeX special characters as punctuation --- | |
1520 | ||
1521 | (list "[$^_{}#&]" | |
1522 | '(0 mdw-punct-face))))) | |
1523 | ||
1524 | ;;;----- Shell scripts ------------------------------------------------------ | |
1525 | ||
1526 | (defun mdw-setup-sh-script-mode () | |
1527 | ||
1528 | ;; --- Fetch the shell interpreter's name --- | |
1529 | ||
1530 | (let ((shell-name sh-shell-file)) | |
1531 | ||
1532 | ;; --- Try reading the hash-bang line --- | |
1533 | ||
1534 | (save-excursion | |
1535 | (goto-char (point-min)) | |
1536 | (if (looking-at "#![ \t]*\\([^ \t\n]*\\)") | |
1537 | (setq shell-name (match-string 1)))) | |
1538 | ||
1539 | ;; --- Now try to set the shell --- | |
1540 | ;; | |
1541 | ;; Don't let `sh-set-shell' bugger up my script. | |
1542 | ||
1543 | (let ((executable-set-magic #'(lambda (s &rest r) s))) | |
1544 | (sh-set-shell shell-name))) | |
1545 | ||
1546 | ;; --- Now enable my keys and the fontification --- | |
1547 | ||
1548 | (mdw-misc-mode-config) | |
1549 | ||
1550 | ;; --- Set the indentation level correctly --- | |
1551 | ||
1552 | (setq sh-indentation 2) | |
1553 | (setq sh-basic-offset 2)) | |
1554 | ||
1555 | ;;;----- Messages-file mode ------------------------------------------------- | |
1556 | ||
1557 | (defun message-mode-guts () | |
1558 | (setq messages-mode-syntax-table (make-syntax-table)) | |
1559 | (set-syntax-table messages-mode-syntax-table) | |
1560 | (modify-syntax-entry ?_ "w" messages-mode-syntax-table) | |
1561 | (modify-syntax-entry ?- "w" messages-mode-syntax-table) | |
1562 | (modify-syntax-entry ?0 "w" messages-mode-syntax-table) | |
1563 | (modify-syntax-entry ?1 "w" messages-mode-syntax-table) | |
1564 | (modify-syntax-entry ?2 "w" messages-mode-syntax-table) | |
1565 | (modify-syntax-entry ?3 "w" messages-mode-syntax-table) | |
1566 | (modify-syntax-entry ?4 "w" messages-mode-syntax-table) | |
1567 | (modify-syntax-entry ?5 "w" messages-mode-syntax-table) | |
1568 | (modify-syntax-entry ?6 "w" messages-mode-syntax-table) | |
1569 | (modify-syntax-entry ?7 "w" messages-mode-syntax-table) | |
1570 | (modify-syntax-entry ?8 "w" messages-mode-syntax-table) | |
1571 | (modify-syntax-entry ?9 "w" messages-mode-syntax-table) | |
1572 | (make-local-variable 'comment-start) | |
1573 | (make-local-variable 'comment-end) | |
1574 | (make-local-variable 'indent-line-function) | |
1575 | (setq indent-line-function 'indent-relative) | |
1576 | (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)") | |
1577 | (make-local-variable 'font-lock-defaults) | |
1578 | (make-local-variable 'message-mode-keywords) | |
1579 | (let ((keywords | |
1580 | (make-regexp '("array" "bitmap" "callback" "docs[ \t]+enum" | |
1581 | "export" "enum" "fixed-octetstring" "flags" | |
1582 | "harmless" "map" "nested" "optional" | |
1583 | "optional-tagged" "package" "primitive" | |
1584 | "primitive-nullfree" "relaxed[ \t]+enum" | |
1585 | "set" "table" "tagged-optional" "union" | |
1586 | "variadic" "vector" "version" "version-tag")))) | |
1587 | (setq message-mode-keywords | |
1588 | (list | |
1589 | (list (concat "\\<\\(" keywords "\\)\\>:") | |
1590 | '(0 font-lock-keyword-face)) | |
1591 | '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face)) | |
1592 | '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)" | |
1593 | (0 font-lock-variable-name-face)) | |
1594 | '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face)) | |
1595 | '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1596 | (0 mdw-punct-face))))) | |
1597 | (setq font-lock-defaults | |
1598 | '(message-mode-keywords nil nil nil nil)) | |
1599 | (run-hooks 'messages-file-hook)) | |
1600 | ||
1601 | (defun messages-mode () | |
1602 | (interactive) | |
1603 | (fundamental-mode) | |
1604 | (setq major-mode 'messages-mode) | |
1605 | (setq mode-name "Messages") | |
1606 | (message-mode-guts) | |
1607 | (modify-syntax-entry ?# "<" messages-mode-syntax-table) | |
1608 | (modify-syntax-entry ?\n ">" messages-mode-syntax-table) | |
1609 | (setq comment-start "# ") | |
1610 | (setq comment-end "") | |
1611 | (turn-on-font-lock-if-enabled) | |
1612 | (run-hooks 'messages-mode-hook)) | |
1613 | ||
1614 | (defun cpp-messages-mode () | |
1615 | (interactive) | |
1616 | (fundamental-mode) | |
1617 | (setq major-mode 'cpp-messages-mode) | |
1618 | (setq mode-name "CPP Messages") | |
1619 | (message-mode-guts) | |
1620 | (modify-syntax-entry ?* ". 23" messages-mode-syntax-table) | |
1621 | (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table) | |
1622 | (setq comment-start "/* ") | |
1623 | (setq comment-end " */") | |
1624 | (let ((preprocessor-keywords | |
1625 | (make-regexp '("assert" "define" "elif" "else" "endif" "error" | |
1626 | "ident" "if" "ifdef" "ifndef" "import" "include" | |
1627 | "line" "pragma" "unassert" "undef" "warning")))) | |
1628 | (setq message-mode-keywords | |
1629 | (append (list (list (concat "^[ \t]*\\#[ \t]*" | |
1630 | "\\(include\\|import\\)" | |
1631 | "[ \t]*\\(<[^>]+\\(>\\|\\)\\)") | |
1632 | '(2 font-lock-string-face)) | |
1633 | (list (concat "^\\([ \t]*#[ \t]*\\(\\(" | |
1634 | preprocessor-keywords | |
852cd5fb | 1635 | "\\)\\>\\|[0-9]+\\|$\\)\\)") |
f617db13 MW |
1636 | '(1 font-lock-keyword-face))) |
1637 | message-mode-keywords))) | |
f617db13 | 1638 | (turn-on-font-lock-if-enabled) |
297d60aa | 1639 | (run-hooks 'cpp-messages-mode-hook)) |
f617db13 | 1640 | |
297d60aa MW |
1641 | (add-hook 'messages-mode-hook 'mdw-misc-mode-config t) |
1642 | (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t) | |
f617db13 MW |
1643 | ; (add-hook 'messages-file-hook 'mdw-fontify-messages t) |
1644 | ||
1645 | ;;;----- Messages-file mode ------------------------------------------------- | |
1646 | ||
1647 | (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face | |
1648 | "Face to use for subsittution directives.") | |
1649 | (make-face 'mallow-driver-substitution-face) | |
1650 | (defvar mallow-driver-text-face 'mallow-driver-text-face | |
1651 | "Face to use for body text.") | |
1652 | (make-face 'mallow-driver-text-face) | |
1653 | ||
1654 | (defun mallow-driver-mode () | |
1655 | (interactive) | |
1656 | (fundamental-mode) | |
1657 | (setq major-mode 'mallow-driver-mode) | |
1658 | (setq mode-name "Mallow driver") | |
1659 | (setq mallow-driver-mode-syntax-table (make-syntax-table)) | |
1660 | (set-syntax-table mallow-driver-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 'mallow-driver-mode-keywords) | |
1668 | (let ((keywords | |
1669 | (make-regexp '("each" "divert" "file" "if" | |
1670 | "perl" "set" "string" "type" "write")))) | |
1671 | (setq mallow-driver-mode-keywords | |
1672 | (list | |
1673 | (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$") | |
1674 | '(0 font-lock-keyword-face)) | |
1675 | (list "^%\\s *\\(#.*\\|\\)$" | |
1676 | '(0 font-lock-comment-face)) | |
1677 | (list "^%" | |
1678 | '(0 font-lock-keyword-face)) | |
1679 | (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face)) | |
1680 | (list "\\${[^}]*}" | |
1681 | '(0 mallow-driver-substitution-face t))))) | |
1682 | (setq font-lock-defaults | |
1683 | '(mallow-driver-mode-keywords nil nil nil nil)) | |
1684 | (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table) | |
1685 | (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table) | |
1686 | (setq comment-start "%# ") | |
1687 | (setq comment-end "") | |
1688 | (turn-on-font-lock-if-enabled) | |
1689 | (run-hooks 'mallow-driver-mode-hook)) | |
1690 | ||
1691 | (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t) | |
1692 | ||
1693 | ;;;----- NFast debugs ------------------------------------------------------- | |
1694 | ||
1695 | (defun nfast-debug-mode () | |
1696 | (interactive) | |
1697 | (fundamental-mode) | |
1698 | (setq major-mode 'nfast-debug-mode) | |
1699 | (setq mode-name "NFast debug") | |
1700 | (setq messages-mode-syntax-table (make-syntax-table)) | |
1701 | (set-syntax-table messages-mode-syntax-table) | |
1702 | (make-local-variable 'font-lock-defaults) | |
1703 | (make-local-variable 'nfast-debug-mode-keywords) | |
1704 | (setq truncate-lines t) | |
1705 | (setq nfast-debug-mode-keywords | |
1706 | (list | |
1707 | '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)" | |
1708 | (0 font-lock-keyword-face)) | |
1709 | (list (concat "^[ \t]+\\(\\(" | |
1710 | "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]" | |
1711 | "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]" | |
1712 | "[ \t]+\\)*" | |
1713 | "[0-9a-fA-F]+\\)[ \t]*$") | |
1714 | '(0 mdw-number-face)) | |
1715 | '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>" | |
1716 | (1 font-lock-keyword-face)) | |
1717 | '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>" | |
1718 | (1 font-lock-warning-face)) | |
1719 | '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>" | |
1720 | (1 nil)) | |
1721 | (list (concat "^[ \t]+\\.cmd=[ \t]+" | |
1722 | "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>") | |
1723 | '(1 font-lock-keyword-face)) | |
1724 | '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face)) | |
1725 | '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face)) | |
1726 | '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face)) | |
1727 | '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face)))) | |
1728 | (setq font-lock-defaults | |
1729 | '(nfast-debug-mode-keywords nil nil nil nil)) | |
1730 | (turn-on-font-lock-if-enabled) | |
1731 | (run-hooks 'nfast-debug-mode-hook)) | |
1732 | ||
1733 | ;;;----- Other languages ---------------------------------------------------- | |
1734 | ||
1735 | ;; --- Smalltalk --- | |
1736 | ||
1737 | (defun mdw-setup-smalltalk () | |
1738 | (and mdw-auto-indent | |
1739 | (local-set-key "\C-m" 'smalltalk-newline-and-indent)) | |
1740 | (make-variable-buffer-local 'mdw-auto-indent) | |
1741 | (setq mdw-auto-indent nil) | |
1742 | (local-set-key "\C-i" 'smalltalk-reindent)) | |
1743 | ||
1744 | (defun mdw-fontify-smalltalk () | |
02109a0d | 1745 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1746 | (setq font-lock-keywords |
1747 | (list | |
1748 | 't | |
1749 | (list "\\<[A-Z][a-zA-Z0-9]*\\>" | |
1750 | '(0 font-lock-keyword-face)) | |
1751 | (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" | |
1752 | "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" | |
1753 | "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") | |
1754 | '(0 mdw-number-face)) | |
1755 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1756 | '(0 mdw-punct-face))))) | |
1757 | ||
1758 | ;; --- Lispy languages --- | |
1759 | ||
1760 | (defun mdw-indent-newline-and-indent () | |
1761 | (interactive) | |
1762 | (indent-for-tab-command) | |
1763 | (newline-and-indent)) | |
1764 | ||
1765 | (eval-after-load "cl-indent" | |
1766 | '(progn | |
1767 | (mapc #'(lambda (pair) | |
1768 | (put (car pair) | |
1769 | 'common-lisp-indent-function | |
1770 | (cdr pair))) | |
1771 | '((destructuring-bind . ((&whole 4 &rest 1) 4 &body)) | |
1772 | (multiple-value-bind . ((&whole 4 &rest 1) 4 &body)))))) | |
1773 | ||
1774 | (defun mdw-common-lisp-indent () | |
1775 | (make-variable-buffer-local 'lisp-indent-function) | |
1776 | (setq lisp-indent-function 'common-lisp-indent-function)) | |
1777 | ||
1778 | (defun mdw-fontify-lispy () | |
1779 | ||
1780 | ;; --- Set fill prefix --- | |
1781 | ||
1782 | (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)") | |
1783 | ||
1784 | ;; --- Not much fontification needed --- | |
1785 | ||
02109a0d | 1786 | (make-local-variable 'font-lock-keywords) |
f617db13 MW |
1787 | (setq font-lock-keywords |
1788 | (list | |
1789 | 't | |
1790 | (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" | |
1791 | '(0 mdw-punct-face))))) | |
1792 | ||
1793 | (defun comint-send-and-indent () | |
1794 | (interactive) | |
1795 | (comint-send-input) | |
1796 | (and mdw-auto-indent | |
1797 | (indent-for-tab-command))) | |
1798 | ||
1799 | ;;;----- Text mode ---------------------------------------------------------- | |
1800 | ||
1801 | (defun mdw-text-mode () | |
1802 | (setq fill-column 72) | |
1803 | (flyspell-mode t) | |
1804 | (mdw-standard-fill-prefix | |
1805 | "\\([ \t]*\\([A-Za-z0-9]*[>#|:] ?\\)*[ \t]*\\)" 3) | |
1806 | (auto-fill-mode 1)) | |
1807 | ||
1808 | ;;;----- Shell mode --------------------------------------------------------- | |
1809 | ||
1810 | (defun mdw-sh-mode-setup () | |
1811 | (local-set-key [?\C-a] 'comint-bol) | |
1812 | (add-hook 'comint-output-filter-functions | |
1813 | 'comint-watch-for-password-prompt)) | |
1814 | ||
1815 | (defun mdw-term-mode-setup () | |
9a3fa88e | 1816 |