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