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