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