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