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