1 ;;; -*- mode: emacs-lisp; coding: utf-8 -*-
3 ;;; Functions and macros for .emacs
5 ;;; (c) 2004 Mark Wooding
8 ;;;----- Licensing notice ---------------------------------------------------
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.
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.
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.
24 ;;;--------------------------------------------------------------------------
25 ;;; Check command-line.
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))
32 (cond ((string= (car next) "--mdw-fast-startup")
33 (setq mdw-fast-startup t)
35 (rplacd probe (cdr next))
36 (setq command-line-args (cdr next))))
39 (setq next (cdr next))))
41 ;;;--------------------------------------------------------------------------
42 ;;; Some general utilities.
45 (unless (fboundp 'make-regexp)
49 (defmacro mdw-regexps (&rest list)
50 "Turn a LIST of strings into a single regular expression at compile-time."
53 `',(make-regexp list))
55 ;; Some error trapping.
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.
60 (defmacro trap (&rest forms)
61 "Execute FORMS without allowing errors to propagate outside."
65 ,(if (cdr forms) (cons 'progn forms) (car forms))
66 (error (message "Error (trapped): %s in %s"
67 (error-message-string err)
70 ;; Configuration reading.
72 (defvar mdw-config nil)
73 (defun mdw-config (sym)
74 "Read the configuration variable named SYM."
77 (flet ((replace (what with)
78 (goto-char (point-min))
79 (while (re-search-forward what nil t)
80 (replace-match with t))))
82 (insert-file-contents "~/.mdw.conf")
83 (replace "^[ \t]*\\(#.*\\|\\)\n" "")
84 (replace (concat "^[ \t]*"
85 "\\([-a-zA-Z0-9_.]*\\)"
88 "[ \t]**\\(\n\\|$\\)")
90 (car (read-from-string
91 (concat "(" (buffer-string) ")")))))))
92 (cdr (assq sym mdw-config)))
94 ;; Set up the load path convincingly.
96 (dolist (dir (append (and (boundp 'debian-emacs-flavor)
97 (list (concat "/usr/share/"
98 (symbol-name debian-emacs-flavor)
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))))))
105 ;; Is an Emacs library available?
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
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)))))
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)))
127 (defun mdw-kick-menu-bar (&optional frame)
128 "Regenerate FRAME's menu bar so it doesn't have empty menus."
130 (unless frame (setq frame (selected-frame)))
131 (let ((old (frame-parameter frame 'menu-bar-lines)))
132 (set-frame-parameter frame 'menu-bar-lines 0)
133 (set-frame-parameter frame 'menu-bar-lines old)))
135 ;; Splitting windows.
137 (unless (fboundp 'scroll-bar-columns)
138 (defun scroll-bar-columns (side)
139 (cond ((eq side 'left) 0)
142 (unless (fboundp 'fringe-columns)
143 (defun fringe-columns (side)
144 (cond ((not window-system) 0)
148 (defun mdw-horizontal-window-overhead ()
149 "Computes the horizontal window overhead.
150 This is the number of columns used by fringes, scroll bars and other such
152 (if (not window-system)
155 (dolist (what '(scroll-bar fringe))
156 (dolist (side '(left right))
157 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
161 (defun mdw-split-window-horizontally (&optional width)
162 "Split a window horizontally.
163 Without a numeric argument, split the window approximately in
164 half. With a numeric argument WIDTH, allocate WIDTH columns to
165 the left-hand window (if positive) or -WIDTH columns to the
166 right-hand window (if negative). Space for scroll bars and
167 fringes is not taken out of the allowance for WIDTH, unlike
168 \\[split-window-horizontally]."
170 (split-window-horizontally
171 (cond ((null width) nil)
172 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
173 ((< width 0) width))))
175 (defun mdw-divvy-window (&optional width)
176 "Split a wide window into appropriate widths."
178 (setq width (cond (width (prefix-numeric-value width))
180 (>= emacs-major-version 22))
183 (let* ((win (selected-window))
184 (sb-width (mdw-horizontal-window-overhead))
185 (c (/ (+ (window-width) sb-width)
186 (+ width sb-width))))
189 (split-window-horizontally (+ width sb-width))
191 (select-window win)))
193 ;; Transient mark mode hacks.
195 (defadvice exchange-point-and-mark
196 (around mdw-highlight (&optional arg) activate compile)
197 "Maybe don't actually exchange point and mark.
198 If `transient-mark-mode' is on and the mark is inactive, then
199 just activate it. A non-trivial prefix argument will force the
200 usual behaviour. A trivial prefix argument (i.e., just C-u) will
201 activate the mark and temporarily enable `transient-mark-mode' if
203 (cond ((or mark-active
204 (and (not transient-mark-mode) (not arg))
205 (and arg (or (not (consp arg))
206 (not (= (car arg) 4)))))
209 (or transient-mark-mode (setq transient-mark-mode 'only))
210 (set-mark (mark t)))))
212 ;; Functions for sexp diary entries.
214 (defun mdw-weekday (l)
215 "Return non-nil if `date' falls on one of the days of the week in L.
216 L is a list of day numbers (from 0 to 6 for Sunday through to
217 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
218 the date stored in `date' falls on a listed day, then the
219 function returns non-nil."
220 (let ((d (calendar-day-of-week date)))
222 (memq (nth d '(sunday monday tuesday wednesday
223 thursday friday saturday)) l))))
225 (defun mdw-todo (&optional when)
226 "Return non-nil today, or on WHEN, whichever is later."
227 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
228 (d (calendar-absolute-from-gregorian date)))
230 (setq w (max w (calendar-absolute-from-gregorian
232 ((not european-calendar-style)
244 ;; Fighting with Org-mode's evil key maps.
246 (defvar mdw-evil-keymap-keys
247 '(([S-up] . [?\C-c up])
248 ([S-down] . [?\C-c down])
249 ([S-left] . [?\C-c left])
250 ([S-right] . [?\C-c right])
251 (([M-up] [?\e up]) . [C-up])
252 (([M-down] [?\e down]) . [C-down])
253 (([M-left] [?\e left]) . [C-left])
254 (([M-right] [?\e right]) . [C-right]))
255 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
256 The value is an alist mapping evil keys (as a list, or singleton)
257 to good keys (in the same form).")
259 (defun mdw-clobber-evil-keymap (keymap)
260 "Replace evil key bindings in the KEYMAP.
261 Evil key bindings are defined in `mdw-evil-keymap-keys'."
262 (dolist (entry mdw-evil-keymap-keys)
264 (keys (if (listp (car entry))
267 (replacements (if (listp (cdr entry))
269 (list (cdr entry)))))
272 (setq binding (lookup-key keymap key))
274 (throw 'found nil))))
277 (define-key keymap key nil))
278 (dolist (key replacements)
279 (define-key keymap key binding))))))
281 (eval-after-load "org-latex"
284 "\\documentclass{strayman}
285 \\usepackage[utf8]{inputenc}
286 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
287 \\usepackage[T1]{fontenc}
288 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
289 ("\\section{%s}" . "\\section*{%s}")
290 ("\\subsection{%s}" . "\\subsection*{%s}")
291 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
292 ("\\paragraph{%s}" . "\\paragraph*{%s}")
293 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
294 org-export-latex-classes)))
296 (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
297 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
298 org-export-docbook-xslt-stylesheet
299 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
301 ;;;--------------------------------------------------------------------------
302 ;;; Mail and news hacking.
304 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
305 "Major mode for editing news and mail messages from external programs.
306 Not much right now. Just support for doing MailCrypt stuff."
309 (run-hooks 'mail-setup-hook))
311 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
313 (add-hook 'mdwail-mode-hook
315 (set-buffer-file-coding-system 'utf-8)
316 (make-local-variable 'paragraph-separate)
317 (make-local-variable 'paragraph-start)
318 (setq paragraph-start
319 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
321 (setq paragraph-separate
322 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
323 paragraph-separate))))
325 ;; How to encrypt in mdwmail.
327 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
329 (setq start (save-excursion
330 (goto-char (point-min))
331 (or (search-forward "\n\n" nil t) (point-min)))))
333 (setq end (point-max)))
334 (mc-encrypt-generic recip scm start end from sign))
336 ;; How to sign in mdwmail.
338 (defun mdwmail-mc-sign (key scm start end uclr)
340 (setq start (save-excursion
341 (goto-char (point-min))
342 (or (search-forward "\n\n" nil t) (point-min)))))
344 (setq end (point-max)))
345 (mc-sign-generic key scm start end uclr))
347 ;; Some signature mangling.
349 (defun mdwmail-mangle-signature ()
351 (goto-char (point-min))
352 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
353 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
354 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
356 ;; Insert my login name into message-ids, so I can score replies.
358 (defadvice message-unique-id (after mdw-user-name last activate compile)
359 "Ensure that the user's name appears at the end of the message-id string,
360 so that it can be used for convenient filtering."
361 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
363 ;; Tell my movemail hack where movemail is.
365 ;; This is needed to shup up warnings about LD_PRELOAD.
367 (let ((path exec-path))
369 (let ((try (expand-file-name "movemail" (car path))))
370 (if (file-executable-p try)
371 (setenv "REAL_MOVEMAIL" try))
372 (setq path (cdr path)))))
374 (eval-after-load "erc"
375 '(load "~/.ercrc.el"))
377 ;;;--------------------------------------------------------------------------
378 ;;; Utility functions.
380 (or (fboundp 'line-number-at-pos)
381 (defun line-number-at-pos (&optional pos)
382 (let ((opoint (or pos (point))) start)
385 (goto-char (point-min))
391 (1+ (count-lines 1 (point))))))))
393 (defun mdw-uniquify-alist (&rest alists)
394 "Return the concatenation of the ALISTS with duplicate elements removed.
395 The first association with a given key prevails; others are
396 ignored. The input lists are not modified, although they'll
397 probably become garbage."
399 (let ((start-list (cons nil nil)))
400 (mdw-do-uniquify start-list
405 (defun mdw-do-uniquify (done end l rest)
406 "A helper function for mdw-uniquify-alist.
407 The DONE argument is a list whose first element is `nil'. It
408 contains the uniquified alist built so far. The leading `nil' is
409 stripped off at the end of the operation; it's only there so that
410 DONE always references a cons cell. END refers to the final cons
411 cell in the DONE list; it is modified in place each time to avoid
412 the overheads of `append'ing all the time. The L argument is the
413 alist we're currently processing; the remaining alists are given
416 ;; There are several different cases to deal with here.
419 ;; Current list isn't empty. Add the first item to the DONE list if
420 ;; there's not an item with the same KEY already there.
421 (l (or (assoc (car (car l)) done)
423 (setcdr end (cons (car l) nil))
424 (setq end (cdr end))))
425 (mdw-do-uniquify done end (cdr l) rest))
427 ;; The list we were working on is empty. Shunt the next list into the
428 ;; current list position and go round again.
429 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
431 ;; Everything's done. Remove the leading `nil' from the DONE list and
432 ;; return it. Finished!
436 "Insert the current date in a pleasing way."
438 (insert (save-excursion
439 (let ((buffer (get-buffer-create "*tmp*")))
440 (unwind-protect (progn (set-buffer buffer)
442 (shell-command "date +%Y-%m-%d" t)
444 (delete-backward-char 1)
446 (kill-buffer buffer))))))
448 (defun uuencode (file &optional name)
449 "UUencodes a file, maybe calling it NAME, into the current buffer."
450 (interactive "fInput file name: ")
452 ;; If NAME isn't specified, then guess from the filename.
456 (or (string-match "[^/]*$" file) 0))))
457 (print (format "uuencode `%s' `%s'" file name))
459 ;; Now actually do the thing.
460 (call-process "uuencode" file t nil name))
462 (defvar np-file "~/.np"
463 "*Where the `now-playing' file is.")
465 (defun np (&optional arg)
466 "Grabs a `now-playing' string."
470 (goto-char (point-max))
472 (insert-file-contents np-file)))))
474 (defun mdw-version-< (ver-a ver-b)
475 "Answer whether VER-A is strictly earlier than VER-B.
476 VER-A and VER-B are version numbers, which are strings containing digit
477 sequences separated by `.'."
478 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
479 (split-string ver-a "\\.")))
480 (lb (mapcar (lambda (x) (car (read-from-string x)))
481 (split-string ver-b "\\."))))
484 (cond ((null la) (throw 'done lb))
485 ((null lb) (throw 'done nil))
486 ((< (car la) (car lb)) (throw 'done t))
487 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb))))))))
489 (defun mdw-check-autorevert ()
490 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
491 This takes into consideration whether it's been found using
492 tramp, which seems to get itself into a twist."
493 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
495 ((and (buffer-file-name)
496 (fboundp 'tramp-tramp-file-p)
497 (tramp-tramp-file-p (buffer-file-name)))
498 (unless global-auto-revert-ignore-buffer
499 (setq global-auto-revert-ignore-buffer 'tramp)))
500 ((eq global-auto-revert-ignore-buffer 'tramp)
501 (setq global-auto-revert-ignore-buffer nil))))
503 (defadvice find-file (after mdw-autorevert activate)
504 (mdw-check-autorevert))
505 (defadvice write-file (after mdw-autorevert activate)
506 (mdw-check-autorevert))
508 ;;;--------------------------------------------------------------------------
511 (defadvice dired-maybe-insert-subdir
512 (around mdw-marked-insertion first activate)
513 "The DIRNAME may be a list of directory names to insert.
514 Interactively, if files are marked, then insert all of them.
515 With a numeric prefix argument, select that many entries near
516 point; with a non-numeric prefix argument, prompt for listing
519 (list (dired-get-marked-files nil
520 (and (integerp current-prefix-arg)
523 (and current-prefix-arg
524 (not (integerp current-prefix-arg))
525 (read-string "Switches for listing: "
526 (or dired-subdir-switches
527 dired-actual-switches)))))
528 (let ((dirs (ad-get-arg 0)))
529 (dolist (dir (if (listp dirs) dirs (list dirs)))
533 ;;;--------------------------------------------------------------------------
536 (defun mdw-w3m-browse-url (url &optional new-session-p)
537 "Invoke w3m on the URL in its current window, or at least a different one.
538 If NEW-SESSION-P, start a new session."
539 (interactive "sURL: \nP")
541 (let ((window (selected-window)))
544 (select-window (or (and (not new-session-p)
545 (get-buffer-window "*w3m*"))
547 (if (one-window-p t) (split-window))
549 (w3m-browse-url url new-session-p))
550 (select-window window)))))
552 (defvar mdw-good-url-browsers
554 (w3m . mdw-w3m-browse-url)
557 "List of good browsers for mdw-good-url-browsers.
558 Each item is a browser function name, or a cons (CHECK . FUNC).
559 A symbol FOO stands for (FOO . FOO).")
561 (defun mdw-good-url-browser ()
562 "Return a good URL browser.
563 Trundle the list of such things, finding the first item for which
564 CHECK is fboundp, and returning the correponding FUNC."
565 (let ((bs mdw-good-url-browsers) b check func answer)
566 (while (and bs (not answer))
570 (setq check (car b) func (cdr b))
571 (setq check b func b))
576 (eval-after-load "w3m-search"
580 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
581 ("gd" "Google Directory"
582 "http://www.google.com/search?cat=gwd/Top&q=%s")
583 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
584 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
585 ("gi" "Images" "http://images.google.com/images?q=%s")
587 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
589 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
590 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
591 ("nc-wiki" "nCipher wiki"
592 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
593 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
594 ("lp" "Launchpad bug by number"
595 "https://bugs.launchpad.net/bugs/%s")
596 ("lppkg" "Launchpad bugs by package"
597 "https://bugs.launchpad.net/%s")
599 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
600 ("debbug" "Debian bug by number"
601 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
602 ("debbugpkg" "Debian bugs by package"
603 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
604 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
605 (add-to-list 'w3m-search-engine-alist
606 (list (cadr item) (caddr item) nil))
607 (add-to-list 'w3m-uri-replace-alist
608 (list (concat "\\`" (car item) ":")
609 'w3m-search-uri-replace
612 ;;;--------------------------------------------------------------------------
613 ;;; Paragraph filling.
617 (defvar mdw-fill-prefix nil
618 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
619 If there's no fill prefix currently set (by the `fill-prefix'
620 variable) and there's a match from one of the regexps here, it
621 gets used to set the fill-prefix for the current operation.
623 The variable is a list of items of the form `REGEXP . PREFIX'; if
624 the REGEXP matches, the PREFIX is used to set the fill prefix.
625 It in turn is a list of things:
627 STRING -- insert a literal string
628 (match . N) -- insert the thing matched by bracketed subexpression N
629 (pad . N) -- a string of whitespace the same width as subexpression N
630 (expr . FORM) -- the result of evaluating FORM")
632 (make-variable-buffer-local 'mdw-fill-prefix)
634 (defvar mdw-hanging-indents
636 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
639 "*Standard regexp matching parts of a hanging indent.
640 This is mainly useful in `auto-fill-mode'.")
642 ;; Setting things up.
644 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
646 ;; Utility functions.
648 (defun mdw-maybe-tabify (s)
649 "Tabify or untabify the string S, according to `indent-tabs-mode'."
650 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
654 (let ((start (point-min)) (end (point-max)))
655 (funcall tabfun (point-min) (point-max))
656 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
658 (defun mdw-examine-fill-prefixes (l)
659 "Given a list of dynamic fill prefixes, pick one which matches
660 context and return the static fill prefix to use. Point must be
661 at the start of a line, and match data must be saved."
663 ((looking-at (car (car l)))
664 (mdw-maybe-tabify (apply #'concat
665 (mapcar #'mdw-do-prefix-match
667 (t (mdw-examine-fill-prefixes (cdr l)))))
669 (defun mdw-maybe-car (p)
670 "If P is a pair, return (car P), otherwise just return P."
671 (if (consp p) (car p) p))
673 (defun mdw-padding (s)
674 "Return a string the same width as S but made entirely from whitespace."
675 (let* ((l (length s)) (i 0) (n (make-string l ? )))
682 (defun mdw-do-prefix-match (m)
683 "Expand a dynamic prefix match element.
684 See `mdw-fill-prefix' for details."
685 (cond ((not (consp m)) (format "%s" m))
686 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
687 ((eq (car m) 'pad) (mdw-padding (match-string
688 (mdw-maybe-car (cdr m)))))
689 ((eq (car m) 'eval) (eval (cdr m)))
692 (defun mdw-choose-dynamic-fill-prefix ()
693 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
694 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
695 ((not mdw-fill-prefix) fill-prefix)
699 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
701 (defun do-auto-fill ()
702 "Handle auto-filling, working out a dynamic fill prefix in the
703 case where there isn't a sensible static one."
704 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
707 (defun mdw-fill-paragraph ()
708 "Fill paragraph, getting a dynamic fill prefix."
710 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
711 (fill-paragraph nil)))
713 (defun mdw-standard-fill-prefix (rx &optional mat)
714 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
715 This is just a short-cut for setting the thing by hand, and by
716 design it doesn't cope with anything approximating a complicated
718 (setq mdw-fill-prefix
719 `((,(concat rx mdw-hanging-indents)
721 (pad . ,(or mat 2))))))
723 ;;;--------------------------------------------------------------------------
724 ;;; Other common declarations.
726 ;; Common mode settings.
728 (defvar mdw-auto-indent t
729 "Whether to indent automatically after a newline.")
731 (defun mdw-whitespace-mode (&optional arg)
732 "Turn on/off whitespace mode, but don't highlight trailing space."
734 (when (and (boundp 'whitespace-style)
735 (fboundp 'whitespace-mode))
736 (let ((whitespace-style (remove 'trailing whitespace-style)))
737 (whitespace-mode arg))
738 (setq show-trailing-whitespace whitespace-mode)))
740 (defun mdw-misc-mode-config ()
742 (cond ((eq major-mode 'lisp-mode)
743 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
744 ((or (eq major-mode 'slime-repl-mode)
745 (eq major-mode 'asm-mode))
748 (local-set-key "\C-m" 'newline-and-indent))))
749 (local-set-key [C-return] 'newline)
750 (make-local-variable 'page-delimiter)
751 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
752 (setq comment-column 40)
754 (setq fill-column 77)
755 (setq show-trailing-whitespace t)
756 (mdw-whitespace-mode 1)
757 (and (fboundp 'gtags-mode)
759 (if (fboundp 'hs-minor-mode)
761 (outline-minor-mode t))
763 (trap (turn-on-font-lock)))
765 (defun mdw-post-config-mode-hack ()
766 (mdw-whitespace-mode 1))
768 (eval-after-load 'gtags
770 (dolist (key '([mouse-2] [mouse-3]))
771 (define-key gtags-mode-map key nil))
772 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
773 (define-key gtags-select-mode-map [C-S-mouse-2]
774 'gtags-select-tag-by-event)
775 (dolist (map (list gtags-mode-map gtags-select-mode-map))
776 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
778 ;; Backup file handling.
780 (defvar mdw-backup-disable-regexps nil
781 "*List of regular expressions: if a file name matches any of
782 these then the file is not backed up.")
784 (defun mdw-backup-enable-predicate (name)
785 "[mdw]'s default backup predicate.
786 Allows a backup if the standard predicate would allow it, and it
787 doesn't match any of the regular expressions in
788 `mdw-backup-disable-regexps'."
789 (and (normal-backup-enable-predicate name)
790 (let ((answer t) (list mdw-backup-disable-regexps))
793 (if (string-match (car list) name)
795 (setq list (cdr list)))
797 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
801 (defun mdw-last-one-out-turn-off-the-lights (frame)
802 "Disconnect from an X display if this was the last frame on that display."
803 (let ((frame-display (frame-parameter frame 'display)))
804 (when (and frame-display
805 (eq window-system 'x)
806 (not (some (lambda (fr)
807 (and (not (eq fr frame))
808 (string= (frame-parameter fr 'display)
811 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
812 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
814 ;;;--------------------------------------------------------------------------
815 ;;; General fontification.
817 (defmacro mdw-define-face (name &rest body)
818 "Define a face, and make sure it's actually set as the definition."
823 (defvar ,name ',name)
824 (put ',name 'face-defface-spec ',body)
825 (face-spec-set ',name ',body nil)))
827 (mdw-define-face default
828 (((type w32)) :family "courier new" :height 85)
829 (((type x)) :family "6x13" :foundry "trad" :height 130)
830 (((type color)) :foreground "white" :background "black")
832 (mdw-define-face fixed-pitch
833 (((type w32)) :family "courier new" :height 85)
834 (((type x)) :family "6x13" :foundry "trad" :height 130)
835 (t :foreground "white" :background "black"))
836 (if (>= emacs-major-version 23)
837 (mdw-define-face variable-pitch
838 (((type x)) :family "sans" :height 100))
839 (mdw-define-face variable-pitch
840 (((type x)) :family "helvetica" :height 90)))
841 (mdw-define-face region
842 (((type tty) (class color)) :background "blue")
843 (((type tty) (class mono)) :inverse-video t)
844 (t :background "grey30"))
845 (mdw-define-face minibuffer-prompt
847 (mdw-define-face mode-line
848 (((class color)) :foreground "blue" :background "yellow"
849 :box (:line-width 1 :style released-button))
850 (t :inverse-video t))
851 (mdw-define-face mode-line-inactive
852 (((class color)) :foreground "yellow" :background "blue"
853 :box (:line-width 1 :style released-button))
854 (t :inverse-video t))
855 (mdw-define-face scroll-bar
856 (t :foreground "black" :background "lightgrey"))
857 (mdw-define-face fringe
858 (t :foreground "yellow"))
859 (mdw-define-face show-paren-match
860 (((class color)) :background "darkgreen")
862 (mdw-define-face show-paren-mismatch
863 (((class color)) :background "red")
864 (t :inverse-video t))
865 (mdw-define-face highlight
866 (((type x) (class color)) :background "DarkSeaGreen4")
867 (((type tty) (class color)) :background "cyan")
868 (t :inverse-video t))
870 (mdw-define-face holiday-face
871 (t :background "red"))
872 (mdw-define-face calendar-today-face
873 (t :foreground "yellow" :weight bold))
875 (mdw-define-face comint-highlight-prompt
877 (mdw-define-face comint-highlight-input
880 (mdw-define-face dired-directory
881 (t :foreground "cyan" :weight bold))
882 (mdw-define-face dired-symlink
883 (t :foreground "cyan"))
884 (mdw-define-face dired-perm-write
887 (mdw-define-face trailing-whitespace
888 (((class color)) :background "red")
889 (t :inverse-video t))
890 (mdw-define-face mdw-punct-face
891 (((type tty)) :foreground "yellow") (t :foreground "burlywood2"))
892 (mdw-define-face mdw-number-face
893 (t :foreground "yellow"))
894 (mdw-define-face font-lock-function-name-face
896 (mdw-define-face font-lock-keyword-face
898 (mdw-define-face font-lock-constant-face
900 (mdw-define-face font-lock-builtin-face
902 (mdw-define-face font-lock-type-face
903 (t :weight bold :slant italic))
904 (mdw-define-face font-lock-reference-face
906 (mdw-define-face font-lock-variable-name-face
908 (mdw-define-face font-lock-comment-delimiter-face
909 (((class mono)) :weight bold)
910 (((type tty) (class color)) :foreground "green")
911 (t :slant italic :foreground "SeaGreen1"))
912 (mdw-define-face font-lock-comment-face
913 (((class mono)) :weight bold)
914 (((type tty) (class color)) :foreground "green")
915 (t :slant italic :foreground "SeaGreen1"))
916 (mdw-define-face font-lock-string-face
917 (((class mono)) :weight bold)
918 (((class color)) :foreground "SkyBlue1"))
919 (mdw-define-face message-separator
920 (t :background "red" :foreground "white" :weight bold))
921 (mdw-define-face message-cited-text
922 (default :slant italic)
923 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
924 (mdw-define-face message-header-cc
925 (default :weight bold)
926 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
927 (mdw-define-face message-header-newsgroups
928 (default :weight bold)
929 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
930 (mdw-define-face message-header-subject
931 (default :weight bold)
932 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
933 (mdw-define-face message-header-to
934 (default :weight bold)
935 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
936 (mdw-define-face message-header-xheader
937 (default :weight bold)
938 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
939 (mdw-define-face message-header-other
940 (default :weight bold)
941 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
942 (mdw-define-face message-header-name
943 (((type tty)) :foreground "green") (t :foreground "SeaGreen1"))
944 (mdw-define-face which-func
947 (mdw-define-face diff-header
949 (mdw-define-face diff-index
951 (mdw-define-face diff-file-header
953 (mdw-define-face diff-hunk-header
954 (t :foreground "SkyBlue1"))
955 (mdw-define-face diff-function
956 (t :foreground "SkyBlue1" :weight bold))
957 (mdw-define-face diff-header
958 (t :background "grey10"))
959 (mdw-define-face diff-added
960 (t :foreground "green"))
961 (mdw-define-face diff-removed
962 (t :foreground "red"))
963 (mdw-define-face diff-context
965 (mdw-define-face diff-refine-change
966 (((class color) (type x)) :background "RoyalBlue4")
969 (mdw-define-face magit-diff-add
970 (t :foreground "green"))
971 (mdw-define-face magit-diff-del
972 (t :foreground "red"))
973 (mdw-define-face magit-diff-file-header
975 (mdw-define-face magit-diff-hunk-header
976 (t :foreground "SkyBlue1"))
978 (mdw-define-face erc-input-face
979 (t :foreground "red"))
981 (mdw-define-face woman-bold
983 (mdw-define-face woman-italic
986 (eval-after-load "rst"
988 (mdw-define-face rst-level-1-face
989 (t :foreground "SkyBlue1" :weight bold))
990 (mdw-define-face rst-level-2-face
991 (t :foreground "SeaGreen1" :weight bold))
992 (mdw-define-face rst-level-3-face
994 (mdw-define-face rst-level-4-face
996 (mdw-define-face rst-level-5-face
998 (mdw-define-face rst-level-6-face
1001 (mdw-define-face p4-depot-added-face
1002 (t :foreground "green"))
1003 (mdw-define-face p4-depot-branch-op-face
1004 (t :foreground "yellow"))
1005 (mdw-define-face p4-depot-deleted-face
1006 (t :foreground "red"))
1007 (mdw-define-face p4-depot-unmapped-face
1008 (t :foreground "SkyBlue1"))
1009 (mdw-define-face p4-diff-change-face
1010 (t :foreground "yellow"))
1011 (mdw-define-face p4-diff-del-face
1012 (t :foreground "red"))
1013 (mdw-define-face p4-diff-file-face
1014 (t :foreground "SkyBlue1"))
1015 (mdw-define-face p4-diff-head-face
1016 (t :background "grey10"))
1017 (mdw-define-face p4-diff-ins-face
1018 (t :foreground "green"))
1020 (mdw-define-face w3m-anchor-face
1021 (t :foreground "SkyBlue1" :underline t))
1022 (mdw-define-face w3m-arrived-anchor-face
1023 (t :foreground "SkyBlue1" :underline t))
1025 (mdw-define-face whizzy-slice-face
1026 (t :background "grey10"))
1027 (mdw-define-face whizzy-error-face
1028 (t :background "darkred"))
1030 ;; Ellipses used to indicate hidden text (and similar).
1031 (mdw-define-face mdw-ellipsis-face
1032 (((type tty)) :foreground "blue") (t :foreground "grey60"))
1033 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
1034 (backslash (make-glyph-code ?\ 'mdw-ellipsis-face))
1035 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
1036 (bar (make-glyph-code ?| mdw-ellipsis-face)))
1037 (set-display-table-slot standard-display-table 0 dollar)
1038 (set-display-table-slot standard-display-table 1 backslash)
1039 (set-display-table-slot standard-display-table 4
1040 (vector dot dot dot))
1041 (set-display-table-slot standard-display-table 5 bar))
1043 ;;;--------------------------------------------------------------------------
1044 ;;; C programming configuration.
1046 ;; Linux kernel hacking.
1048 (defvar linux-c-mode-hook)
1050 (defun linux-c-mode ()
1053 (setq major-mode 'linux-c-mode)
1054 (setq mode-name "Linux C")
1055 (run-hooks 'linux-c-mode-hook))
1057 ;; Make C indentation nice.
1059 (defun mdw-c-lineup-arglist (langelem)
1060 "Hack for DWIMmery in c-lineup-arglist."
1062 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1064 (c-lineup-arglist langelem)))
1066 (defun mdw-c-indent-extern-mumble (langelem)
1067 "Indent `extern \"...\" {' lines."
1069 (back-to-indentation)
1071 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1075 (defun mdw-c-style ()
1076 (c-add-style "[mdw] C and C++ style"
1077 '((c-basic-offset . 2)
1078 (comment-column . 40)
1079 (c-class-key . "class")
1080 (c-backslash-column . 72)
1082 (substatement-open . (add 0 c-indent-one-line-block))
1083 (defun-open . (add 0 c-indent-one-line-block))
1084 (arglist-cont-nonempty . mdw-c-lineup-arglist)
1085 (topmost-intro . mdw-c-indent-extern-mumble)
1086 (cpp-define-intro . 0)
1088 (inextern-lang . [0])
1094 (statement-cont . +)
1095 (statement-case-intro . +)))
1098 (defvar mdw-c-comment-fill-prefix
1099 `((,(concat "\\([ \t]*/?\\)"
1102 "\\([A-Za-z]+:[ \t]*\\)?"
1103 mdw-hanging-indents)
1104 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1105 "Fill prefix matching C comments (both kinds).")
1107 (defun mdw-fontify-c-and-c++ ()
1109 ;; Fiddle with some syntax codes.
1110 (modify-syntax-entry ?* ". 23")
1111 (modify-syntax-entry ?/ ". 124b")
1112 (modify-syntax-entry ?\n "> b")
1116 (setq c-hanging-comment-ender-p nil)
1117 (setq c-backslash-column 72)
1118 (setq c-label-minimum-indentation 0)
1119 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1121 ;; Now define things to be fontified.
1122 (make-local-variable 'font-lock-keywords)
1124 (mdw-regexps "and" ;C++
1130 "bool" ;C++, C9X macro
1136 "complex" ;C9X macro, C++ template type
1140 "continue" ;K&R, C89
1141 "defined" ;C89 preprocessor
1148 ;; "entry" ;K&R -- never used
1153 "false" ;C++, C9X macro
1160 "imaginary" ;C9X macro
1161 "inline" ;C++, C9X, GCC
1173 "register" ;K&R, C89
1174 "reinterpret_cast" ;C++
1187 "true" ;C++, C9X macro
1195 "unsigned" ;K&R, C89
1200 "wchar_t" ;C++, C89 library type
1207 "_Pragma" ;C9X preprocessor
1210 "__attribute__" ;GCC
1213 "__extension__" ;GCC
1222 (preprocessor-keywords
1223 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1224 "ident" "if" "ifdef" "ifndef" "import" "include"
1225 "line" "pragma" "unassert" "undef" "warning"))
1227 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1228 "interface" "private" "protected" "protocol" "public"
1231 (setq font-lock-keywords
1234 ;; Fontify include files as strings.
1235 (list (concat "^[ \t]*\\#[ \t]*"
1236 "\\(include\\|import\\)"
1237 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1238 '(2 font-lock-string-face))
1240 ;; Preprocessor directives are `references'?.
1241 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1242 preprocessor-keywords
1243 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1244 '(1 font-lock-keyword-face))
1246 ;; Handle the keywords defined above.
1247 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1248 '(0 font-lock-keyword-face))
1250 (list (concat "\\<\\(" c-keywords "\\)\\>")
1251 '(0 font-lock-keyword-face))
1253 ;; Handle numbers too.
1255 ;; This looks strange, I know. It corresponds to the
1256 ;; preprocessor's idea of what a number looks like, rather than
1257 ;; anything sensible.
1258 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1259 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1260 '(0 mdw-number-face))
1262 ;; And anything else is punctuation.
1263 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1264 '(0 mdw-punct-face))))
1266 (mdw-post-config-mode-hack)))
1268 ;;;--------------------------------------------------------------------------
1271 (defun apcalc-mode ()
1274 (setq major-mode 'apcalc-mode)
1275 (setq mode-name "AP Calc")
1276 (run-hooks 'apcalc-mode-hook))
1278 (defun mdw-fontify-apcalc ()
1280 ;; Fiddle with some syntax codes.
1281 (modify-syntax-entry ?* ". 23")
1282 (modify-syntax-entry ?/ ". 14")
1286 (setq c-hanging-comment-ender-p nil)
1287 (setq c-backslash-column 72)
1288 (setq comment-start "/* ")
1289 (setq comment-end " */")
1290 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1292 ;; Now define things to be fontified.
1293 (make-local-variable 'font-lock-keywords)
1295 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
1296 "do" "else" "exit" "for" "global" "goto" "help" "if"
1297 "local" "mat" "obj" "print" "quit" "read" "return"
1298 "show" "static" "switch" "while" "write")))
1300 (setq font-lock-keywords
1303 ;; Handle the keywords defined above.
1304 (list (concat "\\<\\(" c-keywords "\\)\\>")
1305 '(0 font-lock-keyword-face))
1307 ;; Handle numbers too.
1309 ;; This looks strange, I know. It corresponds to the
1310 ;; preprocessor's idea of what a number looks like, rather than
1311 ;; anything sensible.
1312 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1313 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1314 '(0 mdw-number-face))
1316 ;; And anything else is punctuation.
1317 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1318 '(0 mdw-punct-face)))))
1320 (mdw-post-config-mode-hack))
1322 ;;;--------------------------------------------------------------------------
1323 ;;; Java programming configuration.
1325 ;; Make indentation nice.
1327 (defun mdw-java-style ()
1328 (c-add-style "[mdw] Java style"
1329 '((c-basic-offset . 2)
1330 (c-offsets-alist (substatement-open . 0)
1335 (statement-case-intro . +)))
1338 ;; Declare Java fontification style.
1340 (defun mdw-fontify-java ()
1344 (setq c-hanging-comment-ender-p nil)
1345 (setq c-backslash-column 72)
1346 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1348 ;; Now define things to be fontified.
1349 (make-local-variable 'font-lock-keywords)
1350 (let ((java-keywords
1351 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1352 "char" "class" "const" "continue" "default" "do"
1353 "double" "else" "extends" "final" "finally" "float"
1354 "for" "goto" "if" "implements" "import" "instanceof"
1355 "int" "interface" "long" "native" "new" "package"
1356 "private" "protected" "public" "return" "short"
1357 "static" "super" "switch" "synchronized" "this"
1358 "throw" "throws" "transient" "try" "void" "volatile"
1361 "false" "null" "true")))
1363 (setq font-lock-keywords
1366 ;; Handle the keywords defined above.
1367 (list (concat "\\<\\(" java-keywords "\\)\\>")
1368 '(0 font-lock-keyword-face))
1370 ;; Handle numbers too.
1372 ;; The following isn't quite right, but it's close enough.
1373 (list (concat "\\<\\("
1374 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1375 "[0-9]+\\(\\.[0-9]*\\|\\)"
1376 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1378 '(0 mdw-number-face))
1380 ;; And anything else is punctuation.
1381 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1382 '(0 mdw-punct-face)))))
1384 (mdw-post-config-mode-hack))
1386 ;;;--------------------------------------------------------------------------
1387 ;;; Javascript programming configuration.
1389 (defun mdw-javascript-style ()
1390 (setq js-indent-level 2)
1391 (setq js-expr-indent-offset 0))
1393 (defun mdw-fontify-javascript ()
1396 (mdw-javascript-style)
1397 (setq js-auto-indent-flag t)
1399 ;; Now define things to be fontified.
1400 (make-local-variable 'font-lock-keywords)
1401 (let ((javascript-keywords
1402 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
1403 "char" "class" "const" "continue" "debugger" "default"
1404 "delete" "do" "double" "else" "enum" "export" "extends"
1405 "final" "finally" "float" "for" "function" "goto" "if"
1406 "implements" "import" "in" "instanceof" "int"
1407 "interface" "let" "long" "native" "new" "package"
1408 "private" "protected" "public" "return" "short"
1409 "static" "super" "switch" "synchronized" "throw"
1410 "throws" "transient" "try" "typeof" "var" "void"
1411 "volatile" "while" "with" "yield"
1413 "boolean" "byte" "char" "double" "float" "int" "long"
1415 (javascript-constants
1416 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
1417 "arguments" "this")))
1419 (setq font-lock-keywords
1422 ;; Handle the keywords defined above.
1423 (list (concat "\\<\\(" javascript-keywords "\\)\\>")
1424 '(0 font-lock-keyword-face))
1426 ;; Handle the predefined constants defined above.
1427 (list (concat "\\<\\(" javascript-constants "\\)\\>")
1428 '(0 font-lock-variable-name-face))
1430 ;; Handle numbers too.
1432 ;; The following isn't quite right, but it's close enough.
1433 (list (concat "\\<\\("
1434 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1435 "[0-9]+\\(\\.[0-9]*\\|\\)"
1436 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1438 '(0 mdw-number-face))
1440 ;; And anything else is punctuation.
1441 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1442 '(0 mdw-punct-face)))))
1444 (mdw-post-config-mode-hack))
1446 ;;;--------------------------------------------------------------------------
1447 ;;; C# programming configuration.
1449 ;; Make indentation nice.
1451 (defun mdw-csharp-style ()
1452 (c-add-style "[mdw] C# style"
1453 '((c-basic-offset . 2)
1454 (c-offsets-alist (substatement-open . 0)
1459 (statement-case-intro . +)))
1462 ;; Declare C# fontification style.
1464 (defun mdw-fontify-csharp ()
1468 (setq c-hanging-comment-ender-p nil)
1469 (setq c-backslash-column 72)
1470 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1472 ;; Now define things to be fontified.
1473 (make-local-variable 'font-lock-keywords)
1474 (let ((csharp-keywords
1475 (mdw-regexps "abstract" "as" "base" "bool" "break"
1476 "byte" "case" "catch" "char" "checked"
1477 "class" "const" "continue" "decimal" "default"
1478 "delegate" "do" "double" "else" "enum"
1479 "event" "explicit" "extern" "false" "finally"
1480 "fixed" "float" "for" "foreach" "goto"
1481 "if" "implicit" "in" "int" "interface"
1482 "internal" "is" "lock" "long" "namespace"
1483 "new" "null" "object" "operator" "out"
1484 "override" "params" "private" "protected" "public"
1485 "readonly" "ref" "return" "sbyte" "sealed"
1486 "short" "sizeof" "stackalloc" "static" "string"
1487 "struct" "switch" "this" "throw" "true"
1488 "try" "typeof" "uint" "ulong" "unchecked"
1489 "unsafe" "ushort" "using" "virtual" "void"
1490 "volatile" "while" "yield")))
1492 (setq font-lock-keywords
1495 ;; Handle the keywords defined above.
1496 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1497 '(0 font-lock-keyword-face))
1499 ;; Handle numbers too.
1501 ;; The following isn't quite right, but it's close enough.
1502 (list (concat "\\<\\("
1503 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1504 "[0-9]+\\(\\.[0-9]*\\|\\)"
1505 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1507 '(0 mdw-number-face))
1509 ;; And anything else is punctuation.
1510 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1511 '(0 mdw-punct-face)))))
1513 (mdw-post-config-mode-hack))
1515 (define-derived-mode csharp-mode java-mode "C#"
1516 "Major mode for editing C# code.")
1518 ;;;--------------------------------------------------------------------------
1519 ;;; Go programming configuration.
1521 (defun mdw-fontify-go ()
1523 (make-local-variable 'font-lock-keywords)
1525 (mdw-regexps "break" "case" "chan" "const" "continue"
1526 "default" "defer" "else" "fallthrough" "for"
1527 "func" "go" "goto" "if" "import"
1528 "interface" "map" "package" "range" "return"
1529 "select" "struct" "switch" "type" "var")))
1531 (setq font-lock-keywords
1534 ;; Handle the keywords defined above.
1535 (list (concat "\\<\\(" go-keywords "\\)\\>")
1536 '(0 font-lock-keyword-face))
1538 ;; Handle numbers too.
1540 ;; The following isn't quite right, but it's close enough.
1541 (list (concat "\\<\\("
1542 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1543 "[0-9]+\\(\\.[0-9]*\\|\\)"
1544 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
1545 '(0 mdw-number-face))
1547 ;; And anything else is punctuation.
1548 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1549 '(0 mdw-punct-face)))))
1551 (mdw-post-config-mode-hack))
1553 ;;;--------------------------------------------------------------------------
1554 ;;; Awk programming configuration.
1556 ;; Make Awk indentation nice.
1558 (defun mdw-awk-style ()
1559 (c-add-style "[mdw] Awk style"
1560 '((c-basic-offset . 2)
1561 (c-offsets-alist (substatement-open . 0)
1562 (statement-cont . 0)
1563 (statement-case-intro . +)))
1566 ;; Declare Awk fontification style.
1568 (defun mdw-fontify-awk ()
1570 ;; Miscellaneous fiddling.
1572 (setq c-backslash-column 72)
1573 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1575 ;; Now define things to be fontified.
1576 (make-local-variable 'font-lock-keywords)
1578 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1579 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1580 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1581 "RSTART" "RLENGTH" "RT" "SUBSEP"
1582 "atan2" "break" "close" "continue" "cos" "delete"
1583 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1584 "function" "gensub" "getline" "gsub" "if" "in"
1585 "index" "int" "length" "log" "match" "next" "rand"
1586 "return" "print" "printf" "sin" "split" "sprintf"
1587 "sqrt" "srand" "strftime" "sub" "substr" "system"
1588 "systime" "tolower" "toupper" "while")))
1590 (setq font-lock-keywords
1593 ;; Handle the keywords defined above.
1594 (list (concat "\\<\\(" c-keywords "\\)\\>")
1595 '(0 font-lock-keyword-face))
1597 ;; Handle numbers too.
1599 ;; The following isn't quite right, but it's close enough.
1600 (list (concat "\\<\\("
1601 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1602 "[0-9]+\\(\\.[0-9]*\\|\\)"
1603 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1605 '(0 mdw-number-face))
1607 ;; And anything else is punctuation.
1608 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1609 '(0 mdw-punct-face)))))
1611 (mdw-post-config-mode-hack))
1613 ;;;--------------------------------------------------------------------------
1614 ;;; Perl programming style.
1616 ;; Perl indentation style.
1618 (fset 'perl-mode 'cperl-mode)
1619 (setq cperl-indent-level 2)
1620 (setq cperl-continued-statement-offset 2)
1621 (setq cperl-continued-brace-offset 0)
1622 (setq cperl-brace-offset -2)
1623 (setq cperl-brace-imaginary-offset 0)
1624 (setq cperl-label-offset 0)
1626 ;; Define perl fontification style.
1628 (defun mdw-fontify-perl ()
1630 ;; Miscellaneous fiddling.
1631 (modify-syntax-entry ?$ "\\")
1632 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1633 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1635 ;; Now define fontification things.
1636 (make-local-variable 'font-lock-keywords)
1637 (let ((perl-keywords
1638 (mdw-regexps "and" "break" "cmp" "continue" "do" "else" "elsif" "eq"
1639 "for" "foreach" "ge" "given" "gt" "goto" "if"
1640 "last" "le" "lt" "local" "my" "ne" "next" "or"
1641 "our" "package" "redo" "require" "return" "sub"
1642 "undef" "unless" "until" "use" "when" "while")))
1644 (setq font-lock-keywords
1647 ;; Set up the keywords defined above.
1648 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1649 '(0 font-lock-keyword-face))
1651 ;; At least numbers are simpler than C.
1652 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1653 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1654 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1655 '(0 mdw-number-face))
1657 ;; And anything else is punctuation.
1658 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1659 '(0 mdw-punct-face)))))
1661 (mdw-post-config-mode-hack))
1663 (defun perl-number-tests (&optional arg)
1664 "Assign consecutive numbers to lines containing `#t'. With ARG,
1665 strip numbers instead."
1668 (goto-char (point-min))
1669 (let ((i 0) (fmt (if arg "" " %4d")))
1670 (while (search-forward "#t" nil t)
1671 (delete-region (point) (line-end-position))
1673 (insert (format fmt i)))
1674 (goto-char (point-min))
1675 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1676 (replace-match (format "\\1%d" i))))))
1678 ;;;--------------------------------------------------------------------------
1679 ;;; Python programming style.
1681 (defun mdw-fontify-pythonic (keywords)
1683 ;; Miscellaneous fiddling.
1684 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1685 (setq indent-tabs-mode nil)
1687 ;; Now define fontification things.
1688 (make-local-variable 'font-lock-keywords)
1689 (setq font-lock-keywords
1692 ;; Set up the keywords defined above.
1693 (list (concat "\\_<\\(" keywords "\\)\\_>")
1694 '(0 font-lock-keyword-face))
1696 ;; At least numbers are simpler than C.
1697 (list (concat "\\_<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1698 "\\_<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1699 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1700 '(0 mdw-number-face))
1702 ;; And anything else is punctuation.
1703 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1704 '(0 mdw-punct-face))))
1706 (mdw-post-config-mode-hack))
1708 ;; Define Python fontification styles.
1710 (defun mdw-fontify-python ()
1711 (mdw-fontify-pythonic
1712 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
1713 "del" "elif" "else" "except" "exec" "finally" "for"
1714 "from" "global" "if" "import" "in" "is" "lambda"
1715 "not" "or" "pass" "print" "raise" "return" "try"
1716 "while" "with" "yield")))
1718 (defun mdw-fontify-pyrex ()
1719 (mdw-fontify-pythonic
1720 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
1721 "ctypedef" "def" "del" "elif" "else" "except" "exec"
1722 "extern" "finally" "for" "from" "global" "if"
1723 "import" "in" "is" "lambda" "not" "or" "pass" "print"
1724 "raise" "return" "struct" "try" "while" "with"
1727 ;;;--------------------------------------------------------------------------
1728 ;;; Icon programming style.
1730 ;; Icon indentation style.
1732 (setq icon-brace-offset 0
1733 icon-continued-brace-offset 0
1734 icon-continued-statement-offset 2
1735 icon-indent-level 2)
1737 ;; Define Icon fontification style.
1739 (defun mdw-fontify-icon ()
1741 ;; Miscellaneous fiddling.
1742 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1744 ;; Now define fontification things.
1745 (make-local-variable 'font-lock-keywords)
1746 (let ((icon-keywords
1747 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
1748 "end" "every" "fail" "global" "if" "initial"
1749 "invocable" "link" "local" "next" "not" "of"
1750 "procedure" "record" "repeat" "return" "static"
1751 "suspend" "then" "to" "until" "while"))
1752 (preprocessor-keywords
1753 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
1754 "include" "line" "undef")))
1755 (setq font-lock-keywords
1758 ;; Set up the keywords defined above.
1759 (list (concat "\\<\\(" icon-keywords "\\)\\>")
1760 '(0 font-lock-keyword-face))
1762 ;; The things that Icon calls keywords.
1763 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
1765 ;; At least numbers are simpler than C.
1766 (list (concat "\\<[0-9]+"
1767 "\\([rR][0-9a-zA-Z]+\\|"
1768 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
1769 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
1770 '(0 mdw-number-face))
1773 (list (concat "^[ \t]*$[ \t]*\\<\\("
1774 preprocessor-keywords
1776 '(0 font-lock-keyword-face))
1778 ;; And anything else is punctuation.
1779 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1780 '(0 mdw-punct-face)))))
1782 (mdw-post-config-mode-hack))
1784 ;;;--------------------------------------------------------------------------
1785 ;;; ARM assembler programming configuration.
1787 ;; There doesn't appear to be an Emacs mode for this yet.
1789 ;; Better do something about that, I suppose.
1791 (defvar arm-assembler-mode-map nil)
1792 (defvar arm-assembler-abbrev-table nil)
1793 (defvar arm-assembler-mode-syntax-table (make-syntax-table))
1795 (or arm-assembler-mode-map
1797 (setq arm-assembler-mode-map (make-sparse-keymap))
1798 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1799 (define-key arm-assembler-mode-map [C-return] 'newline)
1800 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1802 (defun arm-assembler-mode ()
1803 "Major mode for ARM assembler programs"
1806 ;; Do standard major mode things.
1807 (kill-all-local-variables)
1808 (use-local-map arm-assembler-mode-map)
1809 (setq local-abbrev-table arm-assembler-abbrev-table)
1810 (setq major-mode 'arm-assembler-mode)
1811 (setq mode-name "ARM assembler")
1813 ;; Set up syntax table.
1814 (set-syntax-table arm-assembler-mode-syntax-table)
1815 (modify-syntax-entry ?; ; Nasty hack
1816 "<" arm-assembler-mode-syntax-table)
1817 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1818 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1819 (modify-syntax-entry ?' "\"'" arm-assembler-mode-syntax-table)
1821 (make-local-variable 'comment-start)
1822 (setq comment-start ";")
1823 (make-local-variable 'comment-end)
1824 (setq comment-end "")
1825 (make-local-variable 'comment-column)
1826 (setq comment-column 48)
1827 (make-local-variable 'comment-start-skip)
1828 (setq comment-start-skip ";+[ \t]*")
1830 ;; Play with indentation.
1831 (make-local-variable 'indent-line-function)
1832 (setq indent-line-function 'indent-relative-maybe)
1835 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1837 ;; Fiddle with fontification.
1838 (make-local-variable 'font-lock-keywords)
1839 (setq font-lock-keywords
1842 ;; Handle numbers too.
1844 ;; The following isn't quite right, but it's close enough.
1847 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1849 '(0 mdw-number-face))
1851 ;; Do something about operators.
1852 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1853 '(1 font-lock-keyword-face)
1854 '(2 font-lock-string-face))
1856 '(0 font-lock-keyword-face))
1858 ;; Do menemonics and directives.
1859 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1860 '(1 font-lock-keyword-face))
1862 ;; And anything else is punctuation.
1863 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1864 '(0 mdw-punct-face)))
1866 (mdw-post-config-mode-hack))
1867 (run-hooks 'arm-assembler-mode-hook))
1869 ;;;--------------------------------------------------------------------------
1872 (defun mdw-fontify-asm ()
1873 (modify-syntax-entry ?' "\"")
1874 (modify-syntax-entry ?. "w")
1875 (setf fill-prefix nil)
1876 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
1878 ;;;--------------------------------------------------------------------------
1879 ;;; TCL configuration.
1881 (defun mdw-fontify-tcl ()
1882 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1883 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1884 (make-local-variable 'font-lock-keywords)
1885 (setq font-lock-keywords
1887 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1888 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1889 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1890 '(0 mdw-number-face))
1891 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1892 '(0 mdw-punct-face))))
1893 (mdw-post-config-mode-hack))
1895 ;;;--------------------------------------------------------------------------
1896 ;;; REXX configuration.
1898 (defun mdw-rexx-electric-* ()
1903 (defun mdw-rexx-indent-newline-indent ()
1906 (if abbrev-mode (expand-abbrev))
1907 (newline-and-indent))
1909 (defun mdw-fontify-rexx ()
1911 ;; Various bits of fiddling.
1912 (setq mdw-auto-indent nil)
1913 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1914 (local-set-key [?*] 'mdw-rexx-electric-*)
1915 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
1917 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1919 ;; Set up keywords and things for fontification.
1920 (make-local-variable 'font-lock-keywords-case-fold-search)
1921 (setq font-lock-keywords-case-fold-search t)
1923 (setq rexx-indent 2)
1924 (setq rexx-end-indent rexx-indent)
1925 (setq rexx-cont-indent rexx-indent)
1927 (make-local-variable 'font-lock-keywords)
1928 (let ((rexx-keywords
1929 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
1930 "else" "end" "engineering" "exit" "expose" "for"
1931 "forever" "form" "fuzz" "if" "interpret" "iterate"
1932 "leave" "linein" "name" "nop" "numeric" "off" "on"
1933 "options" "otherwise" "parse" "procedure" "pull"
1934 "push" "queue" "return" "say" "select" "signal"
1935 "scientific" "source" "then" "trace" "to" "until"
1936 "upper" "value" "var" "version" "when" "while"
1939 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1940 "center" "center" "charin" "charout" "chars"
1941 "compare" "condition" "copies" "c2d" "c2x"
1942 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1943 "errortext" "format" "fuzz" "insert" "lastpos"
1944 "left" "length" "lineout" "lines" "max" "min"
1945 "overlay" "pos" "queued" "random" "reverse" "right"
1946 "sign" "sourceline" "space" "stream" "strip"
1947 "substr" "subword" "symbol" "time" "translate"
1948 "trunc" "value" "verify" "word" "wordindex"
1949 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1952 (setq font-lock-keywords
1955 ;; Set up the keywords defined above.
1956 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1957 '(0 font-lock-keyword-face))
1959 ;; Fontify all symbols the same way.
1960 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1961 "[A-Za-z0-9.!?_#@$]+\\)")
1962 '(0 font-lock-variable-name-face))
1964 ;; And everything else is punctuation.
1965 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1966 '(0 mdw-punct-face)))))
1968 (mdw-post-config-mode-hack))
1970 ;;;--------------------------------------------------------------------------
1971 ;;; Standard ML programming style.
1973 (defun mdw-fontify-sml ()
1975 ;; Make underscore an honorary letter.
1976 (modify-syntax-entry ?' "w")
1979 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1981 ;; Now define fontification things.
1982 (make-local-variable 'font-lock-keywords)
1984 (mdw-regexps "abstype" "and" "andalso" "as"
1987 "else" "end" "eqtype" "exception"
1988 "fn" "fun" "functor"
1990 "if" "in" "include" "infix" "infixr"
1993 "of" "op" "open" "orelse"
1995 "sharing" "sig" "signature" "struct" "structure"
1998 "where" "while" "with" "withtype")))
2000 (setq font-lock-keywords
2003 ;; Set up the keywords defined above.
2004 (list (concat "\\<\\(" sml-keywords "\\)\\>")
2005 '(0 font-lock-keyword-face))
2007 ;; At least numbers are simpler than C.
2008 (list (concat "\\<\\(\\~\\|\\)"
2009 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
2011 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
2012 "\\([eE]\\(\\~\\|\\)"
2013 "[0-9]+\\|\\)\\)\\)")
2014 '(0 mdw-number-face))
2016 ;; And anything else is punctuation.
2017 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2018 '(0 mdw-punct-face)))))
2020 (mdw-post-config-mode-hack))
2022 ;;;--------------------------------------------------------------------------
2023 ;;; Haskell configuration.
2025 (defun mdw-fontify-haskell ()
2027 ;; Fiddle with syntax table to get comments right.
2028 (modify-syntax-entry ?' "\"")
2029 (modify-syntax-entry ?- ". 123")
2030 (modify-syntax-entry ?{ ". 1b")
2031 (modify-syntax-entry ?} ". 4b")
2032 (modify-syntax-entry ?\n ">")
2035 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
2037 ;; Fiddle with fontification.
2038 (make-local-variable 'font-lock-keywords)
2039 (let ((haskell-keywords
2040 (mdw-regexps "as" "case" "ccall" "class" "data" "default"
2041 "deriving" "do" "else" "foreign" "hiding" "if"
2042 "import" "in" "infix" "infixl" "infixr" "instance"
2043 "let" "module" "newtype" "of" "qualified" "safe"
2044 "stdcall" "then" "type" "unsafe" "where")))
2046 (setq font-lock-keywords
2049 '(0 font-lock-comment-face))
2050 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
2051 '(0 font-lock-keyword-face))
2052 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2053 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
2054 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
2055 '(0 mdw-number-face))
2056 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2057 '(0 mdw-punct-face)))))
2059 (mdw-post-config-mode-hack))
2061 ;;;--------------------------------------------------------------------------
2062 ;;; Erlang configuration.
2064 (setq erlang-electric-commands nil)
2066 (defun mdw-fontify-erlang ()
2069 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
2071 ;; Fiddle with fontification.
2072 (make-local-variable 'font-lock-keywords)
2073 (let ((erlang-keywords
2074 (mdw-regexps "after" "and" "andalso"
2075 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
2076 "case" "catch" "cond"
2077 "div" "end" "fun" "if" "let" "not"
2079 "query" "receive" "rem" "try" "when" "xor")))
2081 (setq font-lock-keywords
2084 '(0 font-lock-comment-face))
2085 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
2086 '(0 font-lock-keyword-face))
2087 (list (concat "^-\\sw+\\>")
2088 '(0 font-lock-keyword-face))
2089 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
2090 '(0 mdw-number-face))
2091 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2092 '(0 mdw-punct-face)))))
2094 (mdw-post-config-mode-hack))
2096 ;;;--------------------------------------------------------------------------
2097 ;;; Texinfo configuration.
2099 (defun mdw-fontify-texinfo ()
2102 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
2104 ;; Real fontification things.
2105 (make-local-variable 'font-lock-keywords)
2106 (setq font-lock-keywords
2109 ;; Environment names are keywords.
2110 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
2111 '(2 font-lock-keyword-face))
2113 ;; Unmark escaped magic characters.
2114 (list "\\(@\\)\\([@{}]\\)"
2115 '(1 font-lock-keyword-face)
2116 '(2 font-lock-variable-name-face))
2118 ;; Make sure we get comments properly.
2119 (list "@c\\(\\|omment\\)\\( .*\\)?$"
2120 '(0 font-lock-comment-face))
2122 ;; Command names are keywords.
2123 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
2124 '(0 font-lock-keyword-face))
2126 ;; Fontify TeX special characters as punctuation.
2128 '(0 mdw-punct-face))))
2130 (mdw-post-config-mode-hack))
2132 ;;;--------------------------------------------------------------------------
2133 ;;; TeX and LaTeX configuration.
2135 (defun mdw-fontify-tex ()
2136 (setq ispell-parser 'tex)
2139 ;; Don't make maths into a string.
2140 (modify-syntax-entry ?$ ".")
2141 (modify-syntax-entry ?$ "." font-lock-syntax-table)
2142 (local-set-key [?$] 'self-insert-command)
2145 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
2147 ;; Real fontification things.
2148 (make-local-variable 'font-lock-keywords)
2149 (setq font-lock-keywords
2152 ;; Environment names are keywords.
2153 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
2155 '(2 font-lock-keyword-face))
2157 ;; Suspended environment names are keywords too.
2158 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
2160 '(3 font-lock-keyword-face))
2162 ;; Command names are keywords.
2163 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
2164 '(0 font-lock-keyword-face))
2166 ;; Handle @/.../ for italics.
2167 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
2168 ;; '(1 font-lock-keyword-face)
2169 ;; '(3 font-lock-keyword-face))
2171 ;; Handle @*...* for boldness.
2172 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
2173 ;; '(1 font-lock-keyword-face)
2174 ;; '(3 font-lock-keyword-face))
2176 ;; Handle @`...' for literal syntax things.
2177 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
2178 ;; '(1 font-lock-keyword-face)
2179 ;; '(3 font-lock-keyword-face))
2181 ;; Handle @<...> for nonterminals.
2182 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
2183 ;; '(1 font-lock-keyword-face)
2184 ;; '(3 font-lock-keyword-face))
2186 ;; Handle other @-commands.
2187 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
2188 ;; '(0 font-lock-keyword-face))
2190 ;; Make sure we get comments properly.
2192 '(0 font-lock-comment-face))
2194 ;; Fontify TeX special characters as punctuation.
2196 '(0 mdw-punct-face))))
2198 (mdw-post-config-mode-hack))
2200 ;;;--------------------------------------------------------------------------
2203 (defun mdw-sgml-mode ()
2206 (mdw-standard-fill-prefix "")
2207 (make-local-variable 'sgml-delimiters)
2208 (setq sgml-delimiters
2209 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
2210 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
2211 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
2212 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
2213 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
2214 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
2215 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
2217 (setq major-mode 'mdw-sgml-mode)
2218 (setq mode-name "[mdw] SGML")
2219 (run-hooks 'mdw-sgml-mode-hook))
2221 ;;;--------------------------------------------------------------------------
2222 ;;; Configuration files.
2224 (defvar mdw-conf-quote-normal nil
2225 "*Control syntax category of quote characters `\"' and `''.
2226 If this is `t', consider quote characters to be normal
2227 punctuation, as for `conf-quote-normal'. If this is `nil' then
2228 leave quote characters as quotes. If this is a list, then
2229 consider the quote characters in the list to be normal
2230 punctuation. If this is a single quote character, then consider
2231 that character only to be normal punctuation.")
2232 (defun mdw-conf-quote-normal-acceptable-value-p (value)
2233 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
2234 (or (booleanp value)
2235 (every (lambda (v) (memq v '(?\" ?')))
2236 (if (listp value) value (list value)))))
2237 (put 'mdw-conf-quote-normal 'safe-local-variable '
2238 mdw-conf-quote-normal-acceptable-value-p)
2240 (defun mdw-fix-up-quote ()
2241 "Apply the setting of `mdw-conf-quote-normal'."
2242 (let ((flag mdw-conf-quote-normal))
2244 (conf-quote-normal t))
2248 (let ((table (copy-syntax-table (syntax-table))))
2249 (mapc (lambda (ch) (modify-syntax-entry ch "." table))
2250 (if (listp flag) flag (list flag)))
2251 (set-syntax-table table)
2252 (and font-lock-mode (font-lock-fontify-buffer)))))))
2253 (defun mdw-fix-up-quote-hack ()
2254 "Unpleasant hack to call `mdw-fix-up-quote' at the right time.
2255 Annoyingly, `hack-local-variables' is done after `set-auto-mode'
2256 so we wouldn't see a local-variable setting of
2257 `mdw-conf-quote-normal' in `conf-mode-hook'. Instead, wire
2258 ourselves onto `hack-local-variables-hook' here, and check the
2259 setting once it's actually been made."
2260 (add-hook 'hack-local-variables-hook 'mdw-fix-up-quote t t))
2261 (add-hook 'conf-mode-hook 'mdw-fix-up-quote-hack t)
2263 ;;;--------------------------------------------------------------------------
2266 (defun mdw-setup-sh-script-mode ()
2268 ;; Fetch the shell interpreter's name.
2269 (let ((shell-name sh-shell-file))
2271 ;; Try reading the hash-bang line.
2273 (goto-char (point-min))
2274 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
2275 (setq shell-name (match-string 1))))
2277 ;; Now try to set the shell.
2279 ;; Don't let `sh-set-shell' bugger up my script.
2280 (let ((executable-set-magic #'(lambda (s &rest r) s)))
2281 (sh-set-shell shell-name)))
2283 ;; Now enable my keys and the fontification.
2284 (mdw-misc-mode-config)
2286 ;; Set the indentation level correctly.
2287 (setq sh-indentation 2)
2288 (setq sh-basic-offset 2))
2290 (setq sh-shell-file "/bin/sh")
2292 ;; Awful hacking to override the shell detection for particular scripts.
2293 (defmacro define-custom-shell-mode (name shell)
2296 (set (make-local-variable 'sh-shell-file) ,shell)
2298 (define-custom-shell-mode bash-mode "/bin/bash")
2299 (define-custom-shell-mode rc-mode "/usr/bin/rc")
2300 (put 'sh-shell-file 'permanent-local t)
2302 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
2303 (eval-after-load "sh-script"
2304 '(or (assq 'rc sh-mode-syntax-table-input)
2321 (assoc (assq 'rc sh-mode-syntax-table-input)))
2324 (setq sh-mode-syntax-table-input
2325 (cons (cons 'rc frag)
2326 sh-mode-syntax-table-input))))))
2328 ;;;--------------------------------------------------------------------------
2329 ;;; Emacs shell mode.
2331 (defun mdw-eshell-prompt ()
2332 (let ((left "[") (right "]"))
2333 (when (= (user-uid) 0)
2334 (setq left "«" right "»"))
2337 (replace-regexp-in-string "\\..*$" "" (system-name)))
2339 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
2340 (home (expand-file-name "~")) (nhome (length home)))
2341 (if (and (>= npwd nhome)
2343 (= (elt pwd nhome) ?/))
2344 (string= (substring pwd 0 nhome) home))
2345 (concat "~" (substring pwd (length home)))
2348 (setq eshell-prompt-function 'mdw-eshell-prompt)
2349 (setq eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
2351 (defun eshell/e (file) (find-file file) nil)
2352 (defun eshell/ee (file) (find-file-other-window file) nil)
2353 (defun eshell/w3m (url) (w3m-goto-url url) nil)
2355 (mdw-define-face eshell-prompt (t :weight bold))
2356 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
2357 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
2358 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
2359 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
2360 (mdw-define-face eshell-ls-executable (t :weight bold))
2361 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
2362 (mdw-define-face eshell-ls-readonly (t nil))
2363 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
2365 ;;;--------------------------------------------------------------------------
2366 ;;; Messages-file mode.
2368 (defun messages-mode-guts ()
2369 (setq messages-mode-syntax-table (make-syntax-table))
2370 (set-syntax-table messages-mode-syntax-table)
2371 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
2372 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
2373 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
2374 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
2375 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
2376 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
2377 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
2378 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
2379 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
2380 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
2381 (make-local-variable 'comment-start)
2382 (make-local-variable 'comment-end)
2383 (make-local-variable 'indent-line-function)
2384 (setq indent-line-function 'indent-relative)
2385 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2386 (make-local-variable 'font-lock-defaults)
2387 (make-local-variable 'messages-mode-keywords)
2389 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
2390 "export" "enum" "fixed-octetstring" "flags"
2391 "harmless" "map" "nested" "optional"
2392 "optional-tagged" "package" "primitive"
2393 "primitive-nullfree" "relaxed[ \t]+enum"
2394 "set" "table" "tagged-optional" "union"
2395 "variadic" "vector" "version" "version-tag")))
2396 (setq messages-mode-keywords
2398 (list (concat "\\<\\(" keywords "\\)\\>:")
2399 '(0 font-lock-keyword-face))
2400 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
2401 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
2402 (0 font-lock-variable-name-face))
2403 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
2404 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2405 (0 mdw-punct-face)))))
2406 (setq font-lock-defaults
2407 '(messages-mode-keywords nil nil nil nil))
2408 (run-hooks 'messages-file-hook))
2410 (defun messages-mode ()
2413 (setq major-mode 'messages-mode)
2414 (setq mode-name "Messages")
2415 (messages-mode-guts)
2416 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
2417 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
2418 (setq comment-start "# ")
2419 (setq comment-end "")
2420 (run-hooks 'messages-mode-hook))
2422 (defun cpp-messages-mode ()
2425 (setq major-mode 'cpp-messages-mode)
2426 (setq mode-name "CPP Messages")
2427 (messages-mode-guts)
2428 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
2429 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
2430 (setq comment-start "/* ")
2431 (setq comment-end " */")
2432 (let ((preprocessor-keywords
2433 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2434 "ident" "if" "ifdef" "ifndef" "import" "include"
2435 "line" "pragma" "unassert" "undef" "warning")))
2436 (setq messages-mode-keywords
2437 (append (list (list (concat "^[ \t]*\\#[ \t]*"
2438 "\\(include\\|import\\)"
2439 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2440 '(2 font-lock-string-face))
2441 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2442 preprocessor-keywords
2443 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2444 '(1 font-lock-keyword-face)))
2445 messages-mode-keywords)))
2446 (run-hooks 'cpp-messages-mode-hook))
2448 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
2449 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
2450 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
2452 ;;;--------------------------------------------------------------------------
2453 ;;; Messages-file mode.
2455 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
2456 "Face to use for subsittution directives.")
2457 (make-face 'mallow-driver-substitution-face)
2458 (defvar mallow-driver-text-face 'mallow-driver-text-face
2459 "Face to use for body text.")
2460 (make-face 'mallow-driver-text-face)
2462 (defun mallow-driver-mode ()
2465 (setq major-mode 'mallow-driver-mode)
2466 (setq mode-name "Mallow driver")
2467 (setq mallow-driver-mode-syntax-table (make-syntax-table))
2468 (set-syntax-table mallow-driver-mode-syntax-table)
2469 (make-local-variable 'comment-start)
2470 (make-local-variable 'comment-end)
2471 (make-local-variable 'indent-line-function)
2472 (setq indent-line-function 'indent-relative)
2473 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
2474 (make-local-variable 'font-lock-defaults)
2475 (make-local-variable 'mallow-driver-mode-keywords)
2477 (mdw-regexps "each" "divert" "file" "if"
2478 "perl" "set" "string" "type" "write")))
2479 (setq mallow-driver-mode-keywords
2481 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
2482 '(0 font-lock-keyword-face))
2483 (list "^%\\s *\\(#.*\\|\\)$"
2484 '(0 font-lock-comment-face))
2486 '(0 font-lock-keyword-face))
2487 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
2489 '(0 mallow-driver-substitution-face t)))))
2490 (setq font-lock-defaults
2491 '(mallow-driver-mode-keywords nil nil nil nil))
2492 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
2493 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
2494 (setq comment-start "%# ")
2495 (setq comment-end "")
2496 (run-hooks 'mallow-driver-mode-hook))
2498 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
2500 ;;;--------------------------------------------------------------------------
2503 (defun nfast-debug-mode ()
2506 (setq major-mode 'nfast-debug-mode)
2507 (setq mode-name "NFast debug")
2508 (setq messages-mode-syntax-table (make-syntax-table))
2509 (set-syntax-table messages-mode-syntax-table)
2510 (make-local-variable 'font-lock-defaults)
2511 (make-local-variable 'nfast-debug-mode-keywords)
2512 (setq truncate-lines t)
2513 (setq nfast-debug-mode-keywords
2515 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
2516 (0 font-lock-keyword-face))
2517 (list (concat "^[ \t]+\\(\\("
2518 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2519 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
2521 "[0-9a-fA-F]+\\)[ \t]*$")
2522 '(0 mdw-number-face))
2523 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
2524 (1 font-lock-keyword-face))
2525 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
2526 (1 font-lock-warning-face))
2527 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
2529 (list (concat "^[ \t]+\\.cmd=[ \t]+"
2530 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
2531 '(1 font-lock-keyword-face))
2532 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
2533 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
2534 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
2535 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
2536 (setq font-lock-defaults
2537 '(nfast-debug-mode-keywords nil nil nil nil))
2538 (run-hooks 'nfast-debug-mode-hook))
2540 ;;;--------------------------------------------------------------------------
2541 ;;; Other languages.
2545 (defun mdw-setup-smalltalk ()
2546 (and mdw-auto-indent
2547 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
2548 (make-local-variable 'mdw-auto-indent)
2549 (setq mdw-auto-indent nil)
2550 (local-set-key "\C-i" 'smalltalk-reindent))
2552 (defun mdw-fontify-smalltalk ()
2553 (make-local-variable 'font-lock-keywords)
2554 (setq font-lock-keywords
2556 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
2557 '(0 font-lock-keyword-face))
2558 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2559 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2560 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2561 '(0 mdw-number-face))
2562 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2563 '(0 mdw-punct-face))))
2564 (mdw-post-config-mode-hack))
2568 ;; Unpleasant bodge.
2569 (unless (boundp 'slime-repl-mode-map)
2570 (setq slime-repl-mode-map (make-sparse-keymap)))
2572 (defun mdw-indent-newline-and-indent ()
2574 (indent-for-tab-command)
2575 (newline-and-indent))
2577 (eval-after-load "cl-indent"
2579 (mapc #'(lambda (pair)
2581 'common-lisp-indent-function
2583 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
2584 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
2586 (defun mdw-common-lisp-indent ()
2587 (make-local-variable 'lisp-indent-function)
2588 (setq lisp-indent-function 'common-lisp-indent-function))
2590 (setq lisp-simple-loop-indentation 2
2591 lisp-loop-keyword-indentation 6
2592 lisp-loop-forms-indentation 6)
2594 (defun mdw-fontify-lispy ()
2597 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
2599 ;; Not much fontification needed.
2600 (make-local-variable 'font-lock-keywords)
2601 (setq font-lock-keywords
2603 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2604 '(0 mdw-punct-face))))
2606 (mdw-post-config-mode-hack))
2608 (defun comint-send-and-indent ()
2611 (and mdw-auto-indent
2612 (indent-for-tab-command)))
2614 (defun mdw-setup-m4 ()
2615 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
2617 ;;;--------------------------------------------------------------------------
2620 (defun mdw-text-mode ()
2621 (setq fill-column 72)
2623 (mdw-standard-fill-prefix
2624 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
2627 ;;;--------------------------------------------------------------------------
2628 ;;; Outline and hide/show modes.
2630 (defun mdw-outline-collapse-all ()
2631 "Completely collapse everything in the entire buffer."
2634 (goto-char (point-min))
2635 (while (< (point) (point-max))
2639 (setq hs-hide-comments-when-hiding-all nil)
2641 (defadvice hs-hide-all (after hide-first-comment activate)
2642 (save-excursion (hs-hide-initial-comment-block)))
2644 ;;;--------------------------------------------------------------------------
2647 (defun mdw-sh-mode-setup ()
2648 (local-set-key [?\C-a] 'comint-bol)
2649 (add-hook 'comint-output-filter-functions
2650 'comint-watch-for-password-prompt))
2652 (defun mdw-term-mode-setup ()
2653 (setq term-prompt-regexp shell-prompt-pattern)
2654 (make-local-variable 'mouse-yank-at-point)
2655 (make-local-variable 'transient-mark-mode)
2656 (setq mouse-yank-at-point t)
2660 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
2661 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
2662 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
2663 (defun term-send-meta-meta-something ()
2665 (term-send-raw-string "\e\e")
2667 (eval-after-load 'term
2669 (define-key term-raw-map [?\e ?\e] nil)
2670 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
2671 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
2672 (define-key term-raw-map [M-right] 'term-send-meta-right)
2673 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
2674 (define-key term-raw-map [M-left] 'term-send-meta-left)
2675 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
2677 (defadvice term-exec (before program-args-list compile activate)
2678 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
2679 This allows you to pass a list of arguments through `ansi-term'."
2680 (let ((program (ad-get-arg 2)))
2683 (ad-set-arg 2 (car program))
2684 (ad-set-arg 4 (cdr program))))))
2687 "Open a terminal containing an ssh session to the HOST."
2688 (interactive "sHost: ")
2689 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
2691 ;;;--------------------------------------------------------------------------
2692 ;;; Inferior Emacs Lisp.
2694 (setq comint-prompt-read-only t)
2696 (eval-after-load "comint"
2698 (define-key comint-mode-map "\C-w" 'comint-kill-region)
2699 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
2701 (eval-after-load "ielm"
2703 (define-key ielm-map "\C-w" 'comint-kill-region)
2704 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
2706 ;;;----- That's all, folks --------------------------------------------------
2708 (provide 'dot-emacs)