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