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