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