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