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))
56 "This is not the key sequence you're looking for."
58 (error "wrong button"))
60 (defun mdw-emacs-version-p (major &optional minor)
61 "Return non-nil if the running Emacs is at least version MAJOR.MINOR."
62 (or (> emacs-major-version major)
63 (and (= emacs-major-version major)
64 (>= emacs-minor-version (or minor 0)))))
66 ;; Some error trapping.
68 ;; If individual bits of this file go tits-up, we don't particularly want
69 ;; the whole lot to stop right there and then, because it's bloody annoying.
71 (defmacro trap (&rest forms)
72 "Execute FORMS without allowing errors to propagate outside."
76 ,(if (cdr forms) (cons 'progn forms) (car forms))
77 (error (message "Error (trapped): %s in %s"
78 (error-message-string err)
81 ;; Configuration reading.
83 (defvar mdw-config nil)
84 (defun mdw-config (sym)
85 "Read the configuration variable named SYM."
88 (flet ((replace (what with)
89 (goto-char (point-min))
90 (while (re-search-forward what nil t)
91 (replace-match with t))))
93 (insert-file-contents "~/.mdw.conf")
94 (replace "^[ \t]*\\(#.*\\|\\)\n" "")
95 (replace (concat "^[ \t]*"
96 "\\([-a-zA-Z0-9_.]*\\)"
99 "[ \t]**\\(\n\\|$\\)")
101 (car (read-from-string
102 (concat "(" (buffer-string) ")")))))))
103 (cdr (assq sym mdw-config)))
105 ;; Width configuration.
107 (defvar mdw-column-width
108 (string-to-number (or (mdw-config 'emacs-width) "77"))
109 "Width of Emacs columns.")
110 (defvar mdw-text-width mdw-column-width
111 "Expected width of text within columns.")
112 (put 'mdw-text-width 'safe-local-variable 'integerp)
114 ;; Local variables hacking.
116 (defun run-local-vars-mode-hook ()
117 "Run a hook for the major-mode after local variables have been processed."
118 (run-hooks (intern (concat (symbol-name major-mode)
119 "-local-variables-hook"))))
120 (add-hook 'hack-local-variables-hook 'run-local-vars-mode-hook)
122 ;; Set up the load path convincingly.
124 (dolist (dir (append (and (boundp 'debian-emacs-flavor)
125 (list (concat "/usr/share/"
126 (symbol-name debian-emacs-flavor)
128 (dolist (sub (directory-files dir t))
129 (when (and (file-accessible-directory-p sub)
130 (not (member sub load-path)))
131 (setq load-path (nconc load-path (list sub))))))
133 ;; Is an Emacs library available?
135 (defun library-exists-p (name)
136 "Return non-nil if NAME is an available library.
137 Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
138 load path. The non-nil value is the filename we found for the
140 (let ((path load-path) elt (foundp nil))
141 (while (and path (not foundp))
142 (setq elt (car path))
143 (setq path (cdr path))
144 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
145 (and (file-exists-p file) file))
146 (let ((file (concat elt "/" name ".el")))
147 (and (file-exists-p file) file)))))
150 (defun maybe-autoload (symbol file &optional docstring interactivep type)
151 "Set an autoload if the file actually exists."
152 (and (library-exists-p file)
153 (autoload symbol file docstring interactivep type)))
155 (defun mdw-kick-menu-bar (&optional frame)
156 "Regenerate FRAME's menu bar so it doesn't have empty menus."
158 (unless frame (setq frame (selected-frame)))
159 (let ((old (frame-parameter frame 'menu-bar-lines)))
160 (set-frame-parameter frame 'menu-bar-lines 0)
161 (set-frame-parameter frame 'menu-bar-lines old)))
163 ;; Splitting windows.
165 (unless (fboundp 'scroll-bar-columns)
166 (defun scroll-bar-columns (side)
167 (cond ((eq side 'left) 0)
170 (unless (fboundp 'fringe-columns)
171 (defun fringe-columns (side)
172 (cond ((not window-system) 0)
176 (defun mdw-horizontal-window-overhead ()
177 "Computes the horizontal window overhead.
178 This is the number of columns used by fringes, scroll bars and other such
180 (if (not window-system)
183 (dolist (what '(scroll-bar fringe))
184 (dolist (side '(left right))
185 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
189 (defun mdw-split-window-horizontally (&optional width)
190 "Split a window horizontally.
191 Without a numeric argument, split the window approximately in
192 half. With a numeric argument WIDTH, allocate WIDTH columns to
193 the left-hand window (if positive) or -WIDTH columns to the
194 right-hand window (if negative). Space for scroll bars and
195 fringes is not taken out of the allowance for WIDTH, unlike
196 \\[split-window-horizontally]."
198 (split-window-horizontally
199 (cond ((null width) nil)
200 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
201 ((< width 0) width))))
203 (defun mdw-preferred-column-width ()
204 "Return the preferred column width."
205 (if (and window-system (mdw-emacs-version-p 22)) mdw-column-width
206 (1+ mdw-column-width)))
208 (defun mdw-divvy-window (&optional width)
209 "Split a wide window into appropriate widths."
211 (setq width (if width (prefix-numeric-value width)
212 (mdw-preferred-column-width)))
213 (let* ((win (selected-window))
214 (sb-width (mdw-horizontal-window-overhead))
215 (c (/ (+ (window-width) sb-width)
216 (+ width sb-width))))
219 (split-window-horizontally (+ width sb-width))
221 (select-window win)))
223 (defun mdw-set-frame-width (columns &optional width)
224 (interactive "nColumns:
226 (setq width (if width (prefix-numeric-value width)
227 (mdw-preferred-column-width)))
228 (let ((sb-width (mdw-horizontal-window-overhead)))
229 (set-frame-width (selected-frame)
230 (- (* columns (+ width sb-width))
232 (mdw-divvy-window width)))
234 ;; Don't raise windows unless I say so.
236 (defvar mdw-inhibit-raise-frame nil
237 "*Whether `raise-frame' should do nothing when the frame is mapped.")
239 (defadvice raise-frame
240 (around mdw-inhibit (&optional frame) activate compile)
241 "Don't actually do anything if `mdw-inhibit-raise-frame' is true, and the
242 frame is actually mapped on the screen."
243 (if mdw-inhibit-raise-frame
244 (make-frame-visible frame)
247 (defmacro mdw-advise-to-inhibit-raise-frame (function)
248 "Advise the FUNCTION not to raise frames, even if it wants to."
249 `(defadvice ,function
250 (around mdw-inhibit-raise (&rest hunoz) activate compile)
251 "Don't raise the window unless you have to."
252 (let ((mdw-inhibit-raise-frame t))
255 (mdw-advise-to-inhibit-raise-frame select-frame-set-input-focus)
256 (mdw-advise-to-inhibit-raise-frame appt-disp-window)
257 (mdw-advise-to-inhibit-raise-frame mouse-select-window)
259 ;; Bug fix for markdown-mode, which breaks point positioning during
261 (defadvice markdown-check-change-for-wiki-link
262 (around mdw-save-match activate compile)
263 "Save match data around the `markdown-mode' `after-change-functions' hook."
264 (save-match-data ad-do-it))
266 ;; Bug fix for `bbdb-canonicalize-address': on Emacs 24, `run-hook-with-args'
267 ;; always returns nil, with the result that all email addresses are lost.
268 ;; Replace the function entirely.
269 (defadvice bbdb-canonicalize-address
270 (around mdw-bug-fix activate compile)
271 "Don't use `run-hook-with-args', because that doesn't work."
272 (let ((net (ad-get-arg 0)))
274 ;; Make sure this is a proper hook list.
275 (if (functionp bbdb-canonicalize-net-hook)
276 (setq bbdb-canonicalize-net-hook (list bbdb-canonicalize-net-hook)))
278 ;; Iterate over the hooks until things converge.
281 (let (next (changep nil)
282 hook (hooks bbdb-canonicalize-net-hook))
284 (setq hook (pop hooks))
285 (setq next (funcall hook net))
286 (if (not (equal next net))
289 (setq donep (not changep)))))
290 (setq ad-return-value net)))
292 ;; Transient mark mode hacks.
294 (defadvice exchange-point-and-mark
295 (around mdw-highlight (&optional arg) activate compile)
296 "Maybe don't actually exchange point and mark.
297 If `transient-mark-mode' is on and the mark is inactive, then
298 just activate it. A non-trivial prefix argument will force the
299 usual behaviour. A trivial prefix argument (i.e., just C-u) will
300 activate the mark and temporarily enable `transient-mark-mode' if
302 (cond ((or mark-active
303 (and (not transient-mark-mode) (not arg))
304 (and arg (or (not (consp arg))
305 (not (= (car arg) 4)))))
308 (or transient-mark-mode (setq transient-mark-mode 'only))
309 (set-mark (mark t)))))
311 ;; Functions for sexp diary entries.
313 (defun mdw-not-org-mode (form)
314 "As FORM, but not in Org mode agenda."
315 (and (not mdw-diary-for-org-mode-p)
318 (defun mdw-weekday (l)
319 "Return non-nil if `date' falls on one of the days of the week in L.
320 L is a list of day numbers (from 0 to 6 for Sunday through to
321 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
322 the date stored in `date' falls on a listed day, then the
323 function returns non-nil."
324 (let ((d (calendar-day-of-week date)))
326 (memq (nth d '(sunday monday tuesday wednesday
327 thursday friday saturday)) l))))
329 (defun mdw-discordian-date (date)
330 "Return the Discordian calendar date corresponding to DATE.
332 The return value is (YOLD . st-tibs-day) or (YOLD SEASON DAYNUM DOW).
334 The original is by David Pearson. I modified it to produce date components
335 as output rather than a string."
336 (let* ((days ["Sweetmorn" "Boomtime" "Pungenday"
337 "Prickle-Prickle" "Setting Orange"])
338 (months ["Chaos" "Discord" "Confusion"
339 "Bureaucracy" "Aftermath"])
340 (day-count [0 31 59 90 120 151 181 212 243 273 304 334])
341 (year (- (extract-calendar-year date) 1900))
342 (month (1- (extract-calendar-month date)))
343 (day (1- (extract-calendar-day date)))
344 (julian (+ (aref day-count month) day))
345 (dyear (+ year 3066)))
346 (if (and (= month 1) (= day 28))
347 (cons dyear 'st-tibs-day)
349 (aref months (floor (/ julian 73)))
351 (aref days (mod julian 5))))))
353 (defun mdw-diary-discordian-date ()
354 "Convert the date in `date' to a string giving the Discordian date."
355 (let* ((ddate (mdw-discordian-date date))
356 (tail (format "in the YOLD %d" (car ddate))))
357 (if (eq (cdr ddate) 'st-tibs-day)
358 (format "St Tib's Day %s" tail)
359 (let ((season (cadr ddate))
360 (daynum (caddr ddate))
361 (dayname (cadddr ddate)))
362 (format "%s, the %d%s day of %s %s"
365 (let ((ldig (mod daynum 10)))
366 (cond ((= ldig 1) "st")
373 (defun mdw-todo (&optional when)
374 "Return non-nil today, or on WHEN, whichever is later."
375 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
376 (d (calendar-absolute-from-gregorian date)))
378 (setq w (max w (calendar-absolute-from-gregorian
380 ((not european-calendar-style)
392 (defvar mdw-diary-for-org-mode-p nil)
394 (defadvice org-agenda-list (around mdw-preserve-links activate)
395 (let ((mdw-diary-for-org-mode-p t))
398 (defadvice diary-add-to-list (before mdw-trim-leading-space compile activate)
399 "Trim leading space from the diary entry string."
401 (let ((str (ad-get-arg 1))
405 (setq str (cond ((null str) nil)
406 ((string-match "\\(^\\|\n\\)[ \t]+" str)
407 (replace-match "\\1" nil nil str))
408 ((and mdw-diary-for-org-mode-p
409 (string-match (concat
411 "\\(" diary-time-regexp
412 "\\(-" diary-time-regexp "\\)?"
414 "\\(\t[ \t]*\\| [ \t]+\\)")
416 (replace-match "\\1\\2 " nil nil str))
417 ((and (not mdw-diary-for-org-mode-p)
418 (string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]"
420 (replace-match "\\1" nil nil str))
422 (if (equal str old) (setq done t)))
423 (ad-set-arg 1 str))))
425 (defadvice org-bbdb-anniversaries (after mdw-fixup-list compile activate)
426 "Return a string rather than a list."
429 (dolist (e (let ((ee ad-return-value))
430 (if (atom ee) (list ee) ee)))
432 (when anyp (insert ?\n))
435 (setq ad-return-value
436 (and anyp (buffer-string))))))
438 ;; Fighting with Org-mode's evil key maps.
440 (defvar mdw-evil-keymap-keys
441 '(([S-up] . [?\C-c up])
442 ([S-down] . [?\C-c down])
443 ([S-left] . [?\C-c left])
444 ([S-right] . [?\C-c right])
445 (([M-up] [?\e up]) . [C-up])
446 (([M-down] [?\e down]) . [C-down])
447 (([M-left] [?\e left]) . [C-left])
448 (([M-right] [?\e right]) . [C-right]))
449 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
450 The value is an alist mapping evil keys (as a list, or singleton)
451 to good keys (in the same form).")
453 (defun mdw-clobber-evil-keymap (keymap)
454 "Replace evil key bindings in the KEYMAP.
455 Evil key bindings are defined in `mdw-evil-keymap-keys'."
456 (dolist (entry mdw-evil-keymap-keys)
458 (keys (if (listp (car entry))
461 (replacements (if (listp (cdr entry))
463 (list (cdr entry)))))
466 (setq binding (lookup-key keymap key))
468 (throw 'found nil))))
471 (define-key keymap key nil))
472 (dolist (key replacements)
473 (define-key keymap key binding))))))
475 (defvar mdw-org-latex-defs
477 "\\documentclass{strayman}
478 \\usepackage[utf8]{inputenc}
479 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
480 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
481 ("\\section{%s}" . "\\section*{%s}")
482 ("\\subsection{%s}" . "\\subsection*{%s}")
483 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
484 ("\\paragraph{%s}" . "\\paragraph*{%s}")
485 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))
487 (eval-after-load "org-latex"
488 '(setq org-export-latex-classes
489 (append mdw-org-latex-defs org-export-latex-classes)))
491 (eval-after-load "ox-latex"
492 '(setq org-latex-classes (append mdw-org-latex-defs org-latex-classes)
493 org-latex-default-packages-alist '(("AUTO" "inputenc" t)
501 ("normalem" "ulem" t)
507 "\\tolerance=1000")))
510 (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
511 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
512 org-export-docbook-xslt-stylesheet
513 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
517 (setq glasses-separator "-"
518 glasses-separate-parentheses-p nil
519 glasses-uncapitalize-p t)
521 ;; Some hacks to do with window placement.
523 (defun mdw-clobber-other-windows-showing-buffer (buffer-or-name)
524 "Arrange that no windows on other frames are showing BUFFER-OR-NAME."
525 (interactive "bBuffer: ")
526 (let ((home-frame (selected-frame))
527 (buffer (get-buffer buffer-or-name))
528 (safe-buffer (get-buffer "*scratch*")))
529 (mapc (lambda (frame)
530 (or (eq frame home-frame)
531 (mapc (lambda (window)
532 (and (eq (window-buffer window) buffer)
533 (set-window-buffer window safe-buffer)))
534 (window-list frame))))
537 (defvar mdw-inhibit-walk-windows nil
538 "If non-nil, then `walk-windows' does nothing.
539 This is used by advice on `switch-to-buffer-other-frame' to inhibit finding
540 buffers in random frames.")
542 (defadvice walk-windows (around mdw-inhibit activate)
543 "If `mdw-inhibit-walk-windows' is non-nil, then do nothing."
544 (and (not mdw-inhibit-walk-windows)
547 (defadvice switch-to-buffer-other-frame
548 (around mdw-always-new-frame activate)
549 "Always make a new frame.
550 Even if an existing window in some random frame looks tempting."
551 (let ((mdw-inhibit-walk-windows t)) ad-do-it))
553 (defadvice display-buffer (before mdw-inhibit-other-frames activate)
554 "Don't try to do anything fancy with other frames.
555 Pretend they don't exist. They might be on other display devices."
558 ;;;--------------------------------------------------------------------------
559 ;;; Improved compilation machinery.
561 ;; Uprated version of M-x compile.
563 (setq compile-command
564 (let ((ncpu (with-temp-buffer
565 (insert-file-contents "/proc/cpuinfo")
567 (count-matches "^processor\\s-*:"))))
568 (format "make -j%d -k" (* 2 ncpu))))
570 (defun mdw-compilation-buffer-name (mode)
571 (concat "*" (downcase mode) ": "
572 (abbreviate-file-name default-directory) "*"))
573 (setq compilation-buffer-name-function 'mdw-compilation-buffer-name)
575 (eval-after-load "compile"
577 (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile)))
579 (defadvice compile (around hack-environment compile activate)
580 "Hack the environment inherited by inferiors in the compilation."
581 (let ((process-environment process-environment))
582 (setenv "LD_PRELOAD" nil)
585 (defun mdw-compile (command &optional directory comint)
586 "Initiate a compilation COMMAND, maybe in a different DIRECTORY.
587 The DIRECTORY may be nil to not change. If COMINT is t, then
588 start an interactive compilation.
590 Interactively, prompt for the command if the variable
591 `compilation-read-command' is non-nil, or if requested through
592 the prefix argument. Prompt for the directory, and run
593 interactively, if requested through the prefix.
595 Use a prefix of 4, 6, 12, or 14, or type C-u between one and three times, to
596 force prompting for a directory.
598 Use a prefix of 2, 6, 10, or 14, or type C-u three times, to force
599 prompting for the command.
601 Use a prefix of 8, 10, 12, or 14, or type C-u twice or three times,
602 to force interactive compilation."
604 (let* ((prefix (prefix-numeric-value current-prefix-arg))
605 (command (eval compile-command))
606 (dir (and (plusp (logand prefix #x54))
607 (read-directory-name "Compile in directory: "))))
608 (list (if (or compilation-read-command
609 (plusp (logand prefix #x42)))
610 (compilation-read-command command)
613 (plusp (logand prefix #x58)))))
614 (let ((default-directory (or directory default-directory)))
615 (compile command comint)))
619 (defun mdw-find-build-dir (build-file)
621 (let* ((src-dir (file-name-as-directory (expand-file-name ".")))
624 (when (file-exists-p (concat dir build-file))
626 (let ((sub (expand-file-name (file-relative-name src-dir dir)
627 (concat dir "build/"))))
630 (when (file-exists-p (concat sub build-file))
632 (when (string= sub dir) (throw 'give-up nil))
633 (setq sub (file-name-directory (directory-file-name sub))))))
635 (setq dir (file-name-directory
636 (directory-file-name dir))))
637 (throw 'found nil))))))
639 (defun mdw-flymake-make-init ()
640 (let ((build-dir (mdw-find-build-dir "Makefile")))
642 (let ((tmp-src (flymake-init-create-temp-buffer-copy
643 #'flymake-create-temp-inplace)))
644 (flymake-get-syntax-check-program-args
645 tmp-src build-dir t t
646 #'flymake-get-make-cmdline)))))
648 (setq flymake-allowed-file-name-masks
649 '(("\\.\\(?:[cC]\\|cc\\|cpp\\|cxx\\|c\\+\\+\\)\\'"
650 mdw-flymake-make-init)
651 ("\\.\\(?:[hH]\\|hh\\|hpp\\|hxx\\|h\\+\\+\\)\\'"
652 mdw-flymake-master-make-init)
653 ("\\.p[lm]" flymake-perl-init)))
655 (setq flymake-mode-map
656 (let ((map (if (boundp 'flymake-mode-map)
658 (make-sparse-keymap))))
659 (define-key map [?\C-c ?\C-f ?\C-p] 'flymake-goto-prev-error)
660 (define-key map [?\C-c ?\C-f ?\C-n] 'flymake-goto-next-error)
661 (define-key map [?\C-c ?\C-f ?\C-c] 'flymake-compile)
662 (define-key map [?\C-c ?\C-f ?\C-k] 'flymake-stop-all-syntax-checks)
663 (define-key map [?\C-c ?\C-f ?\C-e] 'flymake-popup-current-error-menu)
666 ;;;--------------------------------------------------------------------------
667 ;;; Mail and news hacking.
669 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
670 "Major mode for editing news and mail messages from external programs.
671 Not much right now. Just support for doing MailCrypt stuff."
674 (run-hooks 'mail-setup-hook))
676 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
678 (add-hook 'mdwail-mode-hook
680 (set-buffer-file-coding-system 'utf-8)
681 (make-local-variable 'paragraph-separate)
682 (make-local-variable 'paragraph-start)
683 (setq paragraph-start
684 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
686 (setq paragraph-separate
687 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
688 paragraph-separate))))
690 ;; How to encrypt in mdwmail.
692 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
694 (setq start (save-excursion
695 (goto-char (point-min))
696 (or (search-forward "\n\n" nil t) (point-min)))))
698 (setq end (point-max)))
699 (mc-encrypt-generic recip scm start end from sign))
701 ;; How to sign in mdwmail.
703 (defun mdwmail-mc-sign (key scm start end uclr)
705 (setq start (save-excursion
706 (goto-char (point-min))
707 (or (search-forward "\n\n" nil t) (point-min)))))
709 (setq end (point-max)))
710 (mc-sign-generic key scm start end uclr))
712 ;; Some signature mangling.
714 (defun mdwmail-mangle-signature ()
716 (goto-char (point-min))
717 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
718 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
719 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
721 ;; Insert my login name into message-ids, so I can score replies.
723 (defadvice message-unique-id (after mdw-user-name last activate compile)
724 "Ensure that the user's name appears at the end of the message-id string,
725 so that it can be used for convenient filtering."
726 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
728 ;; Tell my movemail hack where movemail is.
730 ;; This is needed to shup up warnings about LD_PRELOAD.
732 (let ((path exec-path))
734 (let ((try (expand-file-name "movemail" (car path))))
735 (if (file-executable-p try)
736 (setenv "REAL_MOVEMAIL" try))
737 (setq path (cdr path)))))
739 ;; AUTHINFO GENERIC kludge.
741 (defvar nntp-authinfo-generic nil
742 "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'.
744 Use this to arrange for per-server settings.")
746 (defun nntp-open-authinfo-kludge (buffer)
747 "Open a connection to SERVER using `authinfo-kludge'."
748 (let ((proc (start-process "nntpd" buffer
749 "env" (concat "NNTPAUTH="
750 (or nntp-authinfo-generic
752 (error "NNTPAUTH unset")))
753 "authinfo-kludge" nntp-address)))
755 (nntp-wait-for-string "^\r*200")
757 (delete-region (point-min) (point))
760 (eval-after-load "erc"
761 '(load "~/.ercrc.el"))
763 ;; Heavy-duty Gnus patching.
765 (defun mdw-nnimap-transform-headers ()
766 (goto-char (point-min))
767 (let (article lines size string)
770 (while (not (looking-at "\\* [0-9]+ FETCH"))
771 (delete-region (point) (progn (forward-line 1) (point)))
774 (goto-char (match-end 0))
775 ;; Unfold quoted {number} strings.
776 (while (re-search-forward
777 "[^]][ (]{\\([0-9]+\\)}\r?\n"
779 ;; Start of the header section.
780 (or (re-search-forward "] {[0-9]+}\r?\n" nil t)
781 ;; Start of the next FETCH.
782 (re-search-forward "\\* [0-9]+ FETCH" nil t)
785 (setq size (string-to-number (match-string 1)))
786 (delete-region (+ (match-beginning 0) 2) (point))
787 (setq string (buffer-substring (point) (+ (point) size)))
788 (delete-region (point) (+ (point) size))
789 (insert (format "%S" (mm-subst-char-in-string ?\n ?\s string)))
790 ;; [mdw] missing from upstream
794 (and (re-search-forward "UID \\([0-9]+\\)" (line-end-position)
799 (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)"
804 (when (search-forward "BODYSTRUCTURE" (line-end-position) t)
805 (let ((structure (ignore-errors
806 (read (current-buffer)))))
807 (while (and (consp structure)
808 (not (atom (car structure))))
809 (setq structure (car structure)))
811 (stringp (car structure))
812 (equal (upcase (nth 0 structure)) "MESSAGE")
813 (equal (upcase (nth 1 structure)) "RFC822"))
815 (nth 7 structure)))))
816 (delete-region (line-beginning-position) (line-end-position))
817 (insert (format "211 %s Article retrieved." article))
820 (insert (format "Chars: %s\n" size)))
822 (insert (format "Lines: %s\n" lines)))
823 ;; Most servers have a blank line after the headers, but
825 (unless (re-search-forward "^\r$\\|^)\r?$" nil t)
826 (goto-char (point-max)))
827 (delete-region (line-beginning-position) (line-end-position))
831 (eval-after-load 'nnimap
832 '(defalias 'nnimap-transform-headers
833 (symbol-function 'mdw-nnimap-transform-headers)))
835 ;;;--------------------------------------------------------------------------
836 ;;; Utility functions.
838 (or (fboundp 'line-number-at-pos)
839 (defun line-number-at-pos (&optional pos)
840 (let ((opoint (or pos (point))) start)
843 (goto-char (point-min))
849 (1+ (count-lines 1 (point))))))))
851 (defun mdw-uniquify-alist (&rest alists)
852 "Return the concatenation of the ALISTS with duplicate elements removed.
853 The first association with a given key prevails; others are
854 ignored. The input lists are not modified, although they'll
855 probably become garbage."
857 (let ((start-list (cons nil nil)))
858 (mdw-do-uniquify start-list
863 (defun mdw-do-uniquify (done end l rest)
864 "A helper function for mdw-uniquify-alist.
865 The DONE argument is a list whose first element is `nil'. It
866 contains the uniquified alist built so far. The leading `nil' is
867 stripped off at the end of the operation; it's only there so that
868 DONE always references a cons cell. END refers to the final cons
869 cell in the DONE list; it is modified in place each time to avoid
870 the overheads of `append'ing all the time. The L argument is the
871 alist we're currently processing; the remaining alists are given
874 ;; There are several different cases to deal with here.
877 ;; Current list isn't empty. Add the first item to the DONE list if
878 ;; there's not an item with the same KEY already there.
879 (l (or (assoc (car (car l)) done)
881 (setcdr end (cons (car l) nil))
882 (setq end (cdr end))))
883 (mdw-do-uniquify done end (cdr l) rest))
885 ;; The list we were working on is empty. Shunt the next list into the
886 ;; current list position and go round again.
887 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
889 ;; Everything's done. Remove the leading `nil' from the DONE list and
890 ;; return it. Finished!
894 "Insert the current date in a pleasing way."
896 (insert (save-excursion
897 (let ((buffer (get-buffer-create "*tmp*")))
898 (unwind-protect (progn (set-buffer buffer)
900 (shell-command "date +%Y-%m-%d" t)
902 (delete-backward-char 1)
904 (kill-buffer buffer))))))
906 (defun uuencode (file &optional name)
907 "UUencodes a file, maybe calling it NAME, into the current buffer."
908 (interactive "fInput file name: ")
910 ;; If NAME isn't specified, then guess from the filename.
914 (or (string-match "[^/]*$" file) 0))))
915 (print (format "uuencode `%s' `%s'" file name))
917 ;; Now actually do the thing.
918 (call-process "uuencode" file t nil name))
920 (defvar np-file "~/.np"
921 "*Where the `now-playing' file is.")
923 (defun np (&optional arg)
924 "Grabs a `now-playing' string."
928 (goto-char (point-max))
930 (insert-file-contents np-file)))))
932 (defun mdw-version-< (ver-a ver-b)
933 "Answer whether VER-A is strictly earlier than VER-B.
934 VER-A and VER-B are version numbers, which are strings containing digit
935 sequences separated by `.'."
936 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
937 (split-string ver-a "\\.")))
938 (lb (mapcar (lambda (x) (car (read-from-string x)))
939 (split-string ver-b "\\."))))
942 (cond ((null la) (throw 'done lb))
943 ((null lb) (throw 'done nil))
944 ((< (car la) (car lb)) (throw 'done t))
945 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))
946 (t (throw 'done nil)))))))
948 (defun mdw-check-autorevert ()
949 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
950 This takes into consideration whether it's been found using
951 tramp, which seems to get itself into a twist."
952 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
954 ((and (buffer-file-name)
955 (fboundp 'tramp-tramp-file-p)
956 (tramp-tramp-file-p (buffer-file-name)))
957 (unless global-auto-revert-ignore-buffer
958 (setq global-auto-revert-ignore-buffer 'tramp)))
959 ((eq global-auto-revert-ignore-buffer 'tramp)
960 (setq global-auto-revert-ignore-buffer nil))))
962 (defadvice find-file (after mdw-autorevert activate)
963 (mdw-check-autorevert))
964 (defadvice write-file (after mdw-autorevert activate)
965 (mdw-check-autorevert))
967 (defun mdw-auto-revert ()
968 "Recheck all of the autorevertable buffers, and update VC modelines."
970 (let ((auto-revert-check-vc-info t))
971 (auto-revert-buffers)))
973 ;;;--------------------------------------------------------------------------
976 (defadvice dired-maybe-insert-subdir
977 (around mdw-marked-insertion first activate)
978 "The DIRNAME may be a list of directory names to insert.
979 Interactively, if files are marked, then insert all of them.
980 With a numeric prefix argument, select that many entries near
981 point; with a non-numeric prefix argument, prompt for listing
984 (list (dired-get-marked-files nil
985 (and (integerp current-prefix-arg)
988 (and current-prefix-arg
989 (not (integerp current-prefix-arg))
990 (read-string "Switches for listing: "
991 (or dired-subdir-switches
992 dired-actual-switches)))))
993 (let ((dirs (ad-get-arg 0)))
994 (dolist (dir (if (listp dirs) dirs (list dirs)))
998 (defun mdw-dired-run (args &optional syncp)
999 (interactive (let ((file (dired-get-filename t)))
1000 (list (read-string (format "Arguments for %s: " file))
1001 current-prefix-arg)))
1002 (funcall (if syncp 'shell-command 'async-shell-command)
1003 (concat (shell-quote-argument (dired-get-filename nil))
1006 (defadvice dired-do-flagged-delete
1007 (around mdw-delete-if-prefix-argument activate compile)
1008 (let ((delete-by-moving-to-trash (and (null current-prefix-arg)
1009 delete-by-moving-to-trash)))
1012 (eval-after-load "dired"
1013 '(define-key dired-mode-map "X" 'mdw-dired-run))
1015 ;;;--------------------------------------------------------------------------
1018 (defun mdw-w3m-browse-url (url &optional new-session-p)
1019 "Invoke w3m on the URL in its current window, or at least a different one.
1020 If NEW-SESSION-P, start a new session."
1021 (interactive "sURL: \nP")
1023 (let ((window (selected-window)))
1026 (select-window (or (and (not new-session-p)
1027 (get-buffer-window "*w3m*"))
1029 (if (one-window-p t) (split-window))
1031 (w3m-browse-url url new-session-p))
1032 (select-window window)))))
1034 (eval-after-load 'w3m
1035 '(define-key w3m-mode-map [?\e ?\r] 'w3m-view-this-url-new-session))
1037 (defvar mdw-good-url-browsers
1038 '(browse-url-mozilla
1040 (w3m . mdw-w3m-browse-url)
1042 "List of good browsers for mdw-good-url-browsers.
1043 Each item is a browser function name, or a cons (CHECK . FUNC).
1044 A symbol FOO stands for (FOO . FOO).")
1046 (defun mdw-good-url-browser ()
1047 "Return a good URL browser.
1048 Trundle the list of such things, finding the first item for which
1049 CHECK is fboundp, and returning the correponding FUNC."
1050 (let ((bs mdw-good-url-browsers) b check func answer)
1051 (while (and bs (not answer))
1055 (setq check (car b) func (cdr b))
1056 (setq check b func b))
1058 (setq answer func)))
1061 (eval-after-load "w3m-search"
1065 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
1066 ("gd" "Google Directory"
1067 "http://www.google.com/search?cat=gwd/Top&q=%s")
1068 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
1069 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
1070 ("gi" "Images" "http://images.google.com/images?q=%s")
1072 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
1074 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
1075 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
1076 ("nc-wiki" "nCipher wiki"
1077 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
1078 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
1079 ("lp" "Launchpad bug by number"
1080 "https://bugs.launchpad.net/bugs/%s")
1081 ("lppkg" "Launchpad bugs by package"
1082 "https://bugs.launchpad.net/%s")
1084 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
1085 ("debbug" "Debian bug by number"
1086 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
1087 ("debbugpkg" "Debian bugs by package"
1088 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
1089 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
1090 (add-to-list 'w3m-search-engine-alist
1091 (list (cadr item) (caddr item) nil))
1092 (add-to-list 'w3m-uri-replace-alist
1093 (list (concat "\\`" (car item) ":")
1094 'w3m-search-uri-replace
1097 ;;;--------------------------------------------------------------------------
1098 ;;; Paragraph filling.
1100 ;; Useful variables.
1102 (defvar mdw-fill-prefix nil
1103 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
1104 If there's no fill prefix currently set (by the `fill-prefix'
1105 variable) and there's a match from one of the regexps here, it
1106 gets used to set the fill-prefix for the current operation.
1108 The variable is a list of items of the form `REGEXP . PREFIX'; if
1109 the REGEXP matches, the PREFIX is used to set the fill prefix.
1110 It in turn is a list of things:
1112 STRING -- insert a literal string
1113 (match . N) -- insert the thing matched by bracketed subexpression N
1114 (pad . N) -- a string of whitespace the same width as subexpression N
1115 (expr . FORM) -- the result of evaluating FORM")
1117 (make-variable-buffer-local 'mdw-fill-prefix)
1119 (defvar mdw-hanging-indents
1121 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
1124 "*Standard regexp matching parts of a hanging indent.
1125 This is mainly useful in `auto-fill-mode'.")
1127 ;; Utility functions.
1129 (defun mdw-maybe-tabify (s)
1130 "Tabify or untabify the string S, according to `indent-tabs-mode'."
1131 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
1135 (let ((start (point-min)) (end (point-max)))
1136 (funcall tabfun (point-min) (point-max))
1137 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
1139 (defun mdw-examine-fill-prefixes (l)
1140 "Given a list of dynamic fill prefixes, pick one which matches
1141 context and return the static fill prefix to use. Point must be
1142 at the start of a line, and match data must be saved."
1144 ((looking-at (car (car l)))
1145 (mdw-maybe-tabify (apply #'concat
1146 (mapcar #'mdw-do-prefix-match
1148 (t (mdw-examine-fill-prefixes (cdr l)))))
1150 (defun mdw-maybe-car (p)
1151 "If P is a pair, return (car P), otherwise just return P."
1152 (if (consp p) (car p) p))
1154 (defun mdw-padding (s)
1155 "Return a string the same width as S but made entirely from whitespace."
1156 (let* ((l (length s)) (i 0) (n (make-string l ? )))
1158 (if (= 9 (aref s i))
1163 (defun mdw-do-prefix-match (m)
1164 "Expand a dynamic prefix match element.
1165 See `mdw-fill-prefix' for details."
1166 (cond ((not (consp m)) (format "%s" m))
1167 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
1168 ((eq (car m) 'pad) (mdw-padding (match-string
1169 (mdw-maybe-car (cdr m)))))
1170 ((eq (car m) 'eval) (eval (cdr m)))
1173 (defun mdw-choose-dynamic-fill-prefix ()
1174 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
1175 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
1176 ((not mdw-fill-prefix) fill-prefix)
1180 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
1182 (defadvice do-auto-fill (around mdw-dynamic-fill-prefix () activate compile)
1183 "Handle auto-filling, working out a dynamic fill prefix in the
1184 case where there isn't a sensible static one."
1185 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1188 (defun mdw-fill-paragraph ()
1189 "Fill paragraph, getting a dynamic fill prefix."
1191 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1192 (fill-paragraph nil)))
1194 (defun mdw-standard-fill-prefix (rx &optional mat)
1195 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
1196 This is just a short-cut for setting the thing by hand, and by
1197 design it doesn't cope with anything approximating a complicated
1199 (setq mdw-fill-prefix
1200 `((,(concat rx mdw-hanging-indents)
1202 (pad . ,(or mat 2))))))
1204 ;;;--------------------------------------------------------------------------
1205 ;;; Other common declarations.
1207 ;; Common mode settings.
1209 (defvar mdw-auto-indent t
1210 "Whether to indent automatically after a newline.")
1212 (defun mdw-whitespace-mode (&optional arg)
1213 "Turn on/off whitespace mode, but don't highlight trailing space."
1215 (when (and (boundp 'whitespace-style)
1216 (fboundp 'whitespace-mode))
1217 (let ((whitespace-style (remove 'trailing whitespace-style)))
1218 (whitespace-mode arg))
1219 (setq show-trailing-whitespace whitespace-mode)))
1221 (defvar mdw-do-misc-mode-hacking nil)
1223 (defun mdw-misc-mode-config ()
1224 (and mdw-auto-indent
1225 (cond ((eq major-mode 'lisp-mode)
1226 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
1227 ((derived-mode-p 'slime-repl-mode 'asm-mode 'comint-mode)
1230 (local-set-key "\C-m" 'newline-and-indent))))
1231 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
1232 (local-set-key [C-return] 'newline)
1233 (make-local-variable 'page-delimiter)
1234 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
1235 (setq comment-column 40)
1237 (setq fill-column mdw-text-width)
1238 (and (fboundp 'gtags-mode)
1240 (if (fboundp 'hs-minor-mode)
1241 (trap (hs-minor-mode t))
1242 (outline-minor-mode t))
1244 (trap (turn-on-font-lock)))
1246 (defun mdw-post-local-vars-misc-mode-config ()
1247 (setq whitespace-line-column mdw-text-width)
1248 (when (and mdw-do-misc-mode-hacking
1249 (not buffer-read-only))
1250 (setq show-trailing-whitespace t)
1251 (mdw-whitespace-mode 1)))
1252 (add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
1254 (defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1255 `(progn ,@(mapcar (lambda (func)
1257 (after mdw-angry-fruit-salad activate)
1258 (when mdw-do-misc-mode-hacking
1259 (setq show-trailing-whitespace
1260 (not buffer-read-only))
1261 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1263 (mdw-advise-update-angry-fruit-salad toggle-read-only
1269 (eval-after-load 'gtags
1271 (dolist (key '([mouse-2] [mouse-3]))
1272 (define-key gtags-mode-map key nil))
1273 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1274 (define-key gtags-select-mode-map [C-S-mouse-2]
1275 'gtags-select-tag-by-event)
1276 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1277 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
1279 ;; Backup file handling.
1281 (defvar mdw-backup-disable-regexps nil
1282 "*List of regular expressions: if a file name matches any of
1283 these then the file is not backed up.")
1285 (defun mdw-backup-enable-predicate (name)
1286 "[mdw]'s default backup predicate.
1287 Allows a backup if the standard predicate would allow it, and it
1288 doesn't match any of the regular expressions in
1289 `mdw-backup-disable-regexps'."
1290 (and (normal-backup-enable-predicate name)
1291 (let ((answer t) (list mdw-backup-disable-regexps))
1294 (if (string-match (car list) name)
1296 (setq list (cdr list)))
1298 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
1302 (defun mdw-last-one-out-turn-off-the-lights (frame)
1303 "Disconnect from an X display if this was the last frame on that display."
1304 (let ((frame-display (frame-parameter frame 'display)))
1305 (when (and frame-display
1306 (eq window-system 'x)
1307 (not (some (lambda (fr)
1308 (and (not (eq fr frame))
1309 (string= (frame-parameter fr 'display)
1312 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1313 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1315 ;;;--------------------------------------------------------------------------
1316 ;;; Fullscreen-ness.
1318 (defvar mdw-full-screen-parameters
1319 '((menu-bar-lines . 0)
1320 ;(vertical-scroll-bars . nil)
1322 "Frame parameters to set when making a frame fullscreen.")
1324 (defvar mdw-full-screen-save
1326 "Extra frame parameters to save when setting fullscreen.")
1328 (defun mdw-toggle-full-screen (&optional frame)
1329 "Show the FRAME fullscreen."
1332 (cond ((frame-parameter frame 'fullscreen)
1333 (set-frame-parameter frame 'fullscreen nil)
1334 (modify-frame-parameters
1336 (or (frame-parameter frame 'mdw-full-screen-saved)
1337 (mapcar (lambda (assoc)
1338 (assq (car assoc) default-frame-alist))
1339 mdw-full-screen-parameters))))
1341 (let ((saved (mapcar (lambda (param)
1342 (cons param (frame-parameter frame param)))
1343 (append (mapcar #'car
1344 mdw-full-screen-parameters)
1345 mdw-full-screen-save))))
1346 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1347 (modify-frame-parameters frame mdw-full-screen-parameters)
1348 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1350 ;;;--------------------------------------------------------------------------
1351 ;;; General fontification.
1353 (make-face 'mdw-virgin-face)
1355 (defmacro mdw-define-face (name &rest body)
1356 "Define a face, and make sure it's actually set as the definition."
1360 (copy-face 'mdw-virgin-face ',name)
1361 (defvar ,name ',name)
1362 (put ',name 'face-defface-spec ',body)
1363 (face-spec-set ',name ',body nil)))
1365 (mdw-define-face default
1366 (((type w32)) :family "courier new" :height 85)
1367 (((type x)) :family "6x13" :foundry "trad" :height 130)
1368 (((type color)) :foreground "white" :background "black")
1370 (mdw-define-face fixed-pitch
1371 (((type w32)) :family "courier new" :height 85)
1372 (((type x)) :family "6x13" :foundry "trad" :height 130)
1373 (t :foreground "white" :background "black"))
1374 (if (mdw-emacs-version-p 23)
1375 (mdw-define-face variable-pitch
1376 (((type x)) :family "sans" :height 100))
1377 (mdw-define-face variable-pitch
1378 (((type x)) :family "helvetica" :height 90)))
1379 (mdw-define-face region
1380 (((min-colors 64)) :background "grey30")
1381 (((class color)) :background "blue")
1382 (t :inverse-video t))
1383 (mdw-define-face match
1384 (((class color)) :background "blue")
1385 (t :inverse-video t))
1386 (mdw-define-face mc/cursor-face
1387 (((class color)) :background "red")
1388 (t :inverse-video t))
1389 (mdw-define-face minibuffer-prompt
1391 (mdw-define-face mode-line
1392 (((class color)) :foreground "blue" :background "yellow"
1393 :box (:line-width 1 :style released-button))
1394 (t :inverse-video t))
1395 (mdw-define-face mode-line-inactive
1396 (((class color)) :foreground "yellow" :background "blue"
1397 :box (:line-width 1 :style released-button))
1398 (t :inverse-video t))
1399 (mdw-define-face nobreak-space
1401 (t :inherit escape-glyph :underline t))
1402 (mdw-define-face scroll-bar
1403 (t :foreground "black" :background "lightgrey"))
1404 (mdw-define-face fringe
1405 (t :foreground "yellow"))
1406 (mdw-define-face show-paren-match
1407 (((min-colors 64)) :background "darkgreen")
1408 (((class color)) :background "green")
1410 (mdw-define-face show-paren-mismatch
1411 (((class color)) :background "red")
1412 (t :inverse-video t))
1413 (mdw-define-face highlight
1414 (((min-colors 64)) :background "DarkSeaGreen4")
1415 (((class color)) :background "cyan")
1416 (t :inverse-video t))
1418 (mdw-define-face holiday-face
1419 (t :background "red"))
1420 (mdw-define-face calendar-today-face
1421 (t :foreground "yellow" :weight bold))
1423 (mdw-define-face comint-highlight-prompt
1425 (mdw-define-face comint-highlight-input
1428 (mdw-define-face ido-subdir
1429 (t :foreground "cyan" :weight bold))
1431 (mdw-define-face dired-directory
1432 (t :foreground "cyan" :weight bold))
1433 (mdw-define-face dired-symlink
1434 (t :foreground "cyan"))
1435 (mdw-define-face dired-perm-write
1438 (mdw-define-face trailing-whitespace
1439 (((class color)) :background "red")
1440 (t :inverse-video t))
1441 (mdw-define-face whitespace-line
1442 (((class color)) :background "darkred")
1443 (t :inverse-video t))
1444 (mdw-define-face mdw-punct-face
1445 (((min-colors 64)) :foreground "burlywood2")
1446 (((class color)) :foreground "yellow"))
1447 (mdw-define-face mdw-number-face
1448 (t :foreground "yellow"))
1449 (mdw-define-face mdw-trivial-face)
1450 (mdw-define-face font-lock-function-name-face
1452 (mdw-define-face font-lock-keyword-face
1454 (mdw-define-face font-lock-constant-face
1456 (mdw-define-face font-lock-builtin-face
1458 (mdw-define-face font-lock-type-face
1459 (t :weight bold :slant italic))
1460 (mdw-define-face font-lock-reference-face
1462 (mdw-define-face font-lock-variable-name-face
1464 (mdw-define-face font-lock-comment-delimiter-face
1465 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1466 (((class color)) :foreground "green")
1468 (mdw-define-face font-lock-comment-face
1469 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1470 (((class color)) :foreground "green")
1472 (mdw-define-face font-lock-string-face
1473 (((min-colors 64)) :foreground "SkyBlue1")
1474 (((class color)) :foreground "cyan")
1477 (mdw-define-face message-separator
1478 (t :background "red" :foreground "white" :weight bold))
1479 (mdw-define-face message-cited-text
1480 (default :slant italic)
1481 (((min-colors 64)) :foreground "SkyBlue1")
1482 (((class color)) :foreground "cyan"))
1483 (mdw-define-face message-header-cc
1484 (default :slant italic)
1485 (((min-colors 64)) :foreground "SeaGreen1")
1486 (((class color)) :foreground "green"))
1487 (mdw-define-face message-header-newsgroups
1488 (default :slant italic)
1489 (((min-colors 64)) :foreground "SeaGreen1")
1490 (((class color)) :foreground "green"))
1491 (mdw-define-face message-header-subject
1492 (((min-colors 64)) :foreground "SeaGreen1")
1493 (((class color)) :foreground "green"))
1494 (mdw-define-face message-header-to
1495 (((min-colors 64)) :foreground "SeaGreen1")
1496 (((class color)) :foreground "green"))
1497 (mdw-define-face message-header-xheader
1498 (default :slant italic)
1499 (((min-colors 64)) :foreground "SeaGreen1")
1500 (((class color)) :foreground "green"))
1501 (mdw-define-face message-header-other
1502 (default :slant italic)
1503 (((min-colors 64)) :foreground "SeaGreen1")
1504 (((class color)) :foreground "green"))
1505 (mdw-define-face message-header-name
1506 (default :weight bold)
1507 (((min-colors 64)) :foreground "SeaGreen1")
1508 (((class color)) :foreground "green"))
1510 (mdw-define-face which-func
1513 (mdw-define-face gnus-header-name
1514 (default :weight bold)
1515 (((min-colors 64)) :foreground "SeaGreen1")
1516 (((class color)) :foreground "green"))
1517 (mdw-define-face gnus-header-subject
1518 (((min-colors 64)) :foreground "SeaGreen1")
1519 (((class color)) :foreground "green"))
1520 (mdw-define-face gnus-header-from
1521 (((min-colors 64)) :foreground "SeaGreen1")
1522 (((class color)) :foreground "green"))
1523 (mdw-define-face gnus-header-to
1524 (((min-colors 64)) :foreground "SeaGreen1")
1525 (((class color)) :foreground "green"))
1526 (mdw-define-face gnus-header-content
1527 (default :slant italic)
1528 (((min-colors 64)) :foreground "SeaGreen1")
1529 (((class color)) :foreground "green"))
1531 (mdw-define-face gnus-cite-1
1532 (((min-colors 64)) :foreground "SkyBlue1")
1533 (((class color)) :foreground "cyan"))
1534 (mdw-define-face gnus-cite-2
1535 (((min-colors 64)) :foreground "RoyalBlue2")
1536 (((class color)) :foreground "blue"))
1537 (mdw-define-face gnus-cite-3
1538 (((min-colors 64)) :foreground "MediumOrchid")
1539 (((class color)) :foreground "magenta"))
1540 (mdw-define-face gnus-cite-4
1541 (((min-colors 64)) :foreground "firebrick2")
1542 (((class color)) :foreground "red"))
1543 (mdw-define-face gnus-cite-5
1544 (((min-colors 64)) :foreground "burlywood2")
1545 (((class color)) :foreground "yellow"))
1546 (mdw-define-face gnus-cite-6
1547 (((min-colors 64)) :foreground "SeaGreen1")
1548 (((class color)) :foreground "green"))
1549 (mdw-define-face gnus-cite-7
1550 (((min-colors 64)) :foreground "SlateBlue1")
1551 (((class color)) :foreground "cyan"))
1552 (mdw-define-face gnus-cite-8
1553 (((min-colors 64)) :foreground "RoyalBlue2")
1554 (((class color)) :foreground "blue"))
1555 (mdw-define-face gnus-cite-9
1556 (((min-colors 64)) :foreground "purple2")
1557 (((class color)) :foreground "magenta"))
1558 (mdw-define-face gnus-cite-10
1559 (((min-colors 64)) :foreground "DarkOrange2")
1560 (((class color)) :foreground "red"))
1561 (mdw-define-face gnus-cite-11
1562 (t :foreground "grey"))
1564 (mdw-define-face diff-header
1566 (mdw-define-face diff-index
1568 (mdw-define-face diff-file-header
1570 (mdw-define-face diff-hunk-header
1571 (((min-colors 64)) :foreground "SkyBlue1")
1572 (((class color)) :foreground "cyan"))
1573 (mdw-define-face diff-function
1574 (default :weight bold)
1575 (((min-colors 64)) :foreground "SkyBlue1")
1576 (((class color)) :foreground "cyan"))
1577 (mdw-define-face diff-header
1578 (((min-colors 64)) :background "grey10"))
1579 (mdw-define-face diff-added
1580 (((class color)) :foreground "green"))
1581 (mdw-define-face diff-removed
1582 (((class color)) :foreground "red"))
1583 (mdw-define-face diff-context
1585 (mdw-define-face diff-refine-change
1586 (((min-colors 64)) :background "RoyalBlue4")
1588 (mdw-define-face diff-refine-removed
1589 (((min-colors 64)) :background "#500")
1591 (mdw-define-face diff-refine-added
1592 (((min-colors 64)) :background "#050")
1595 (setq ediff-force-faces t)
1596 (mdw-define-face ediff-current-diff-A
1597 (((min-colors 64)) :background "darkred")
1598 (((class color)) :background "red")
1599 (t :inverse-video t))
1600 (mdw-define-face ediff-fine-diff-A
1601 (((min-colors 64)) :background "red3")
1602 (((class color)) :inverse-video t)
1603 (t :inverse-video nil))
1604 (mdw-define-face ediff-even-diff-A
1605 (((min-colors 64)) :background "#300"))
1606 (mdw-define-face ediff-odd-diff-A
1607 (((min-colors 64)) :background "#300"))
1608 (mdw-define-face ediff-current-diff-B
1609 (((min-colors 64)) :background "darkgreen")
1610 (((class color)) :background "magenta")
1611 (t :inverse-video t))
1612 (mdw-define-face ediff-fine-diff-B
1613 (((min-colors 64)) :background "green4")
1614 (((class color)) :inverse-video t)
1615 (t :inverse-video nil))
1616 (mdw-define-face ediff-even-diff-B
1617 (((min-colors 64)) :background "#020"))
1618 (mdw-define-face ediff-odd-diff-B
1619 (((min-colors 64)) :background "#020"))
1620 (mdw-define-face ediff-current-diff-C
1621 (((min-colors 64)) :background "darkblue")
1622 (((class color)) :background "blue")
1623 (t :inverse-video t))
1624 (mdw-define-face ediff-fine-diff-C
1625 (((min-colors 64)) :background "blue1")
1626 (((class color)) :inverse-video t)
1627 (t :inverse-video nil))
1628 (mdw-define-face ediff-even-diff-C
1629 (((min-colors 64)) :background "#004"))
1630 (mdw-define-face ediff-odd-diff-C
1631 (((min-colors 64)) :background "#004"))
1632 (mdw-define-face ediff-current-diff-Ancestor
1633 (((min-colors 64)) :background "#630")
1634 (((class color)) :background "blue")
1635 (t :inverse-video t))
1636 (mdw-define-face ediff-even-diff-Ancestor
1637 (((min-colors 64)) :background "#320"))
1638 (mdw-define-face ediff-odd-diff-Ancestor
1639 (((min-colors 64)) :background "#320"))
1641 (mdw-define-face magit-hash
1642 (((min-colors 64)) :foreground "grey40")
1643 (((class color)) :foreground "blue"))
1644 (mdw-define-face magit-diff-hunk-heading
1645 (((min-colors 64)) :foreground "grey70" :background "grey25")
1646 (((class color)) :foreground "yellow"))
1647 (mdw-define-face magit-diff-hunk-heading-highlight
1648 (((min-colors 64)) :foreground "grey70" :background "grey35")
1649 (((class color)) :foreground "yellow" :background "blue"))
1650 (mdw-define-face magit-diff-added
1651 (((min-colors 64)) :foreground "#ddffdd" :background "#335533")
1652 (((class color)) :foreground "green"))
1653 (mdw-define-face magit-diff-added-highlight
1654 (((min-colors 64)) :foreground "#cceecc" :background "#336633")
1655 (((class color)) :foreground "green" :background "blue"))
1656 (mdw-define-face magit-diff-removed
1657 (((min-colors 64)) :foreground "#ffdddd" :background "#553333")
1658 (((class color)) :foreground "red"))
1659 (mdw-define-face magit-diff-removed-highlight
1660 (((min-colors 64)) :foreground "#eecccc" :background "#663333")
1661 (((class color)) :foreground "red" :background "blue"))
1662 (mdw-define-face magit-blame-heading
1663 (((min-colors 64)) :foreground "white" :background "grey25"
1664 :weight normal :slant normal)
1665 (((class color)) :foreground "white" :background "blue"
1666 :weight normal :slant normal))
1667 (mdw-define-face magit-blame-name
1668 (t :inherit magit-blame-heading :slant italic))
1669 (mdw-define-face magit-blame-date
1670 (((min-colors 64)) :inherit magit-blame-heading :foreground "grey60")
1671 (((class color)) :inherit magit-blame-heading :foreground "cyan"))
1672 (mdw-define-face magit-blame-summary
1673 (t :inherit magit-blame-heading :weight bold))
1675 (mdw-define-face dylan-header-background
1676 (((min-colors 64)) :background "NavyBlue")
1677 (((class color)) :background "blue"))
1679 (mdw-define-face erc-input-face
1680 (t :foreground "red"))
1682 (mdw-define-face woman-bold
1684 (mdw-define-face woman-italic
1687 (eval-after-load "rst"
1689 (mdw-define-face rst-level-1-face
1690 (t :foreground "SkyBlue1" :weight bold))
1691 (mdw-define-face rst-level-2-face
1692 (t :foreground "SeaGreen1" :weight bold))
1693 (mdw-define-face rst-level-3-face
1695 (mdw-define-face rst-level-4-face
1697 (mdw-define-face rst-level-5-face
1699 (mdw-define-face rst-level-6-face
1702 (mdw-define-face p4-depot-added-face
1703 (t :foreground "green"))
1704 (mdw-define-face p4-depot-branch-op-face
1705 (t :foreground "yellow"))
1706 (mdw-define-face p4-depot-deleted-face
1707 (t :foreground "red"))
1708 (mdw-define-face p4-depot-unmapped-face
1709 (t :foreground "SkyBlue1"))
1710 (mdw-define-face p4-diff-change-face
1711 (t :foreground "yellow"))
1712 (mdw-define-face p4-diff-del-face
1713 (t :foreground "red"))
1714 (mdw-define-face p4-diff-file-face
1715 (t :foreground "SkyBlue1"))
1716 (mdw-define-face p4-diff-head-face
1717 (t :background "grey10"))
1718 (mdw-define-face p4-diff-ins-face
1719 (t :foreground "green"))
1721 (mdw-define-face w3m-anchor-face
1722 (t :foreground "SkyBlue1" :underline t))
1723 (mdw-define-face w3m-arrived-anchor-face
1724 (t :foreground "SkyBlue1" :underline t))
1726 (mdw-define-face whizzy-slice-face
1727 (t :background "grey10"))
1728 (mdw-define-face whizzy-error-face
1729 (t :background "darkred"))
1731 ;; Ellipses used to indicate hidden text (and similar).
1732 (mdw-define-face mdw-ellipsis-face
1733 (((type tty)) :foreground "blue") (t :foreground "grey60"))
1734 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
1735 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
1736 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
1737 (bar (make-glyph-code ?| mdw-ellipsis-face)))
1738 (set-display-table-slot standard-display-table 0 dollar)
1739 (set-display-table-slot standard-display-table 1 backslash)
1740 (set-display-table-slot standard-display-table 4
1741 (vector dot dot dot))
1742 (set-display-table-slot standard-display-table 5 bar))
1744 ;;;--------------------------------------------------------------------------
1747 (mdw-define-face mdw-point-overlay-face
1749 (((min-colors 64)) :background "darkblue")
1750 (((class color)) :background "blue")
1751 (((type tty) (class mono)) :inverse-video t))
1753 (defvar mdw-point-overlay-fringe-display '(vertical-bar . vertical-bar))
1755 (defun mdw-configure-point-overlay ()
1756 (let ((ov (make-overlay 0 0)))
1757 (overlay-put ov 'priority 0)
1758 (let* ((fringe (or mdw-point-overlay-fringe-display (cons nil nil)))
1759 (left (car fringe)) (right (cdr fringe))
1763 (put-text-property 0 1 'display `(left-fringe ,left) ss)
1764 (setq s (concat s ss))))
1767 (put-text-property 0 1 'display `(right-fringe ,right) ss)
1768 (setq s (concat s ss))))
1769 (when (or left right)
1770 (overlay-put ov 'before-string s)))
1771 (overlay-put ov 'face 'mdw-point-overlay-face)
1775 (defvar mdw-point-overlay (mdw-configure-point-overlay)
1776 "An overlay used for showing where point is in the selected window.")
1777 (defun mdw-reconfigure-point-overlay ()
1779 (setq mdw-point-overlay (mdw-configure-point-overlay)))
1781 (defun mdw-remove-point-overlay ()
1782 "Remove the current-point overlay."
1783 (delete-overlay mdw-point-overlay))
1785 (defun mdw-update-point-overlay ()
1786 "Mark the current point position with an overlay."
1787 (if (not mdw-point-overlay-mode)
1788 (mdw-remove-point-overlay)
1789 (overlay-put mdw-point-overlay 'window (selected-window))
1790 (move-overlay mdw-point-overlay
1791 (line-beginning-position)
1792 (+ (line-end-position) 1))))
1794 (defvar mdw-point-overlay-buffers nil
1795 "List of buffers using `mdw-point-overlay-mode'.")
1797 (define-minor-mode mdw-point-overlay-mode
1798 "Indicate current line with an overlay."
1800 (let ((buffer (current-buffer)))
1801 (setq mdw-point-overlay-buffers
1802 (mapcan (lambda (buf)
1803 (if (and (buffer-live-p buf)
1804 (not (eq buf buffer)))
1806 mdw-point-overlay-buffers))
1807 (if mdw-point-overlay-mode
1808 (setq mdw-point-overlay-buffers
1809 (cons buffer mdw-point-overlay-buffers))))
1810 (cond (mdw-point-overlay-buffers
1811 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
1812 (add-hook 'post-command-hook 'mdw-update-point-overlay))
1814 (mdw-remove-point-overlay)
1815 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
1816 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
1818 (define-globalized-minor-mode mdw-global-point-overlay-mode
1819 mdw-point-overlay-mode
1820 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
1822 ;;;--------------------------------------------------------------------------
1823 ;;; C programming configuration.
1825 ;; Make C indentation nice.
1827 (defun mdw-c-lineup-arglist (langelem)
1828 "Hack for DWIMmery in c-lineup-arglist."
1830 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1832 (c-lineup-arglist langelem)))
1834 (defun mdw-c-indent-extern-mumble (langelem)
1835 "Indent `extern \"...\" {' lines."
1837 (back-to-indentation)
1839 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1843 (defun mdw-c-indent-arglist-nested (langelem)
1844 "Indent continued argument lists.
1845 If we've nested more than one argument list, then only introduce a single
1846 indentation anyway."
1847 (let ((context c-syntactic-context)
1848 (pos (c-langelem-2nd-pos c-syntactic-element))
1849 (should-indent-p t))
1851 (eq (caar context) 'arglist-cont-nonempty))
1852 (when (and (= (caddr (pop context)) pos)
1854 (memq (caar context) '(arglist-intro
1855 arglist-cont-nonempty)))
1856 (setq should-indent-p nil)))
1857 (if should-indent-p '+ 0)))
1859 (defvar mdw-define-c-styles-hook nil
1860 "Hook run when `cc-mode' starts up to define styles.")
1862 (defmacro mdw-define-c-style (name &rest assocs)
1863 "Define a C style, called NAME (a symbol), setting ASSOCs.
1864 A function, named `mdw-define-c-style/NAME', is defined to actually install
1865 the style using `c-add-style', and added to the hook
1866 `mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
1868 (declare (indent defun))
1869 (let* ((name-string (symbol-name name))
1870 (func (intern (concat "mdw-define-c-style/" name-string))))
1872 (defun ,func () (c-add-style ,name-string ',assocs))
1873 (and (featurep 'cc-mode) (,func))
1874 (add-hook 'mdw-define-c-styles-hook ',func))))
1876 (eval-after-load "cc-mode"
1877 '(run-hooks 'mdw-define-c-styles-hook))
1879 (mdw-define-c-style mdw-trustonic-c
1880 (c-basic-offset . 4)
1881 (comment-column . 0)
1882 (c-indent-comment-alist (anchored-comment . (column . 0))
1883 (end-block . (space . 1))
1884 (cpp-end-block . (space . 1))
1885 (other . (space . 1)))
1886 (c-class-key . "class")
1887 (c-backslash-column . 0)
1888 (c-auto-align-backslashes . nil)
1889 (c-label-minimum-indentation . 0)
1890 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1891 (defun-open . (add 0 c-indent-one-line-block))
1892 (arglist-cont-nonempty . mdw-c-indent-arglist-nested)
1893 (topmost-intro . mdw-c-indent-extern-mumble)
1894 (cpp-define-intro . 0)
1896 (inextern-lang . [0])
1902 (statement-cont . +)
1903 (statement-case-intro . +)))
1905 (mdw-define-c-style mdw-c
1906 (c-basic-offset . 2)
1907 (comment-column . 40)
1908 (c-class-key . "class")
1909 (c-backslash-column . 72)
1910 (c-label-minimum-indentation . 0)
1911 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1912 (defun-open . (add 0 c-indent-one-line-block))
1913 (arglist-cont-nonempty . mdw-c-lineup-arglist)
1914 (topmost-intro . mdw-c-indent-extern-mumble)
1915 (cpp-define-intro . 0)
1917 (inextern-lang . [0])
1923 (statement-cont . +)
1924 (statement-case-intro . +)))
1926 (defun mdw-set-default-c-style (modes style)
1927 "Update the default CC Mode style for MODES to be STYLE.
1929 MODES may be a list of major mode names or a singleton. STYLE is a style
1931 (let ((modes (if (listp modes) modes (list modes)))
1932 (style (symbol-name style)))
1933 (setq c-default-style
1934 (append (mapcar (lambda (mode)
1937 (remove-if (lambda (assoc)
1938 (memq (car assoc) modes))
1939 (if (listp c-default-style)
1941 (list (cons 'other c-default-style))))))))
1942 (setq c-default-style "mdw-c")
1944 (mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
1946 (defvar mdw-c-comment-fill-prefix
1947 `((,(concat "\\([ \t]*/?\\)"
1950 "\\([A-Za-z]+:[ \t]*\\)?"
1951 mdw-hanging-indents)
1952 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1953 "Fill prefix matching C comments (both kinds).")
1955 (defun mdw-fontify-c-and-c++ ()
1957 ;; Fiddle with some syntax codes.
1958 (modify-syntax-entry ?* ". 23")
1959 (modify-syntax-entry ?/ ". 124b")
1960 (modify-syntax-entry ?\n "> b")
1963 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1965 ;; Now define things to be fontified.
1966 (make-local-variable 'font-lock-keywords)
1968 (mdw-regexps "alignas" ;C11 macro, C++11
1970 "and" ;C++, C95 macro
1971 "and_eq" ;C++, C95 macro
1972 "asm" ;K&R, C++, GCC
1973 "atomic" ;C11 macro, C++11 template type
1975 "bitand" ;C++, C95 macro
1976 "bitor" ;C++, C95 macro
1977 "bool" ;C++, C99 macro
1982 "char16_t" ;C++11, C11 library type
1983 "char32_t" ;C++11, C11 library type
1985 "complex" ;C99 macro, C++ template type
1986 "compl" ;C++, C95 macro
1990 "continue" ;K&R, C89
1992 "defined" ;C89 preprocessor
1999 ;; "entry" ;K&R -- never used
2010 "imaginary" ;C99 macro
2011 "inline" ;C++, C99, GCC
2018 "noreturn" ;C11 macro
2019 "not" ;C++, C95 macro
2020 "not_eq" ;C++, C95 macro
2023 "or" ;C++, C95 macro
2024 "or_eq" ;C++, C95 macro
2028 "register" ;K&R, C89
2029 "reinterpret_cast" ;C++
2036 "static_assert" ;C11 macro, C++11
2043 "thread_local" ;C11 macro, C++11
2049 "unsigned" ;K&R, C89
2054 "wchar_t" ;C++, C89 library type
2056 "xor" ;C++, C95 macro
2057 "xor_eq" ;C++, C95 macro
2066 "_Pragma" ;C99 preprocessor
2067 "_Static_assert" ;C11
2068 "_Thread_local" ;C11
2071 "__attribute__" ;GCC
2074 "__extension__" ;GCC
2084 (mdw-regexps "false" ;C++, C99 macro
2086 "true" ;C++, C99 macro
2088 (preprocessor-keywords
2089 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2090 "ident" "if" "ifdef" "ifndef" "import" "include"
2091 "line" "pragma" "unassert" "undef" "warning"))
2093 (mdw-regexps "class" "defs" "encode" "end" "implementation"
2094 "interface" "private" "protected" "protocol" "public"
2097 (setq font-lock-keywords
2100 ;; Fontify include files as strings.
2101 (list (concat "^[ \t]*\\#[ \t]*"
2102 "\\(include\\|import\\)"
2103 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2104 '(2 font-lock-string-face))
2106 ;; Preprocessor directives are `references'?.
2107 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2108 preprocessor-keywords
2109 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2110 '(1 font-lock-keyword-face))
2112 ;; Handle the keywords defined above.
2113 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
2114 '(0 font-lock-keyword-face))
2116 (list (concat "\\<\\(" c-keywords "\\)\\>")
2117 '(0 font-lock-keyword-face))
2119 (list (concat "\\<\\(" c-constants "\\)\\>")
2120 '(0 font-lock-variable-name-face))
2122 ;; Handle numbers too.
2124 ;; This looks strange, I know. It corresponds to the
2125 ;; preprocessor's idea of what a number looks like, rather than
2126 ;; anything sensible.
2127 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2128 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2129 '(0 mdw-number-face))
2131 ;; And anything else is punctuation.
2132 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2133 '(0 mdw-punct-face))))))
2135 (define-derived-mode sod-mode c-mode "Sod"
2136 "Major mode for editing Sod code.")
2137 (push '("\\.sod$" . sod-mode) auto-mode-alist)
2139 ;;;--------------------------------------------------------------------------
2142 (define-derived-mode apcalc-mode c-mode "AP Calc"
2143 "Major mode for editing Calc code.")
2145 (defun mdw-fontify-apcalc ()
2147 ;; Fiddle with some syntax codes.
2148 (modify-syntax-entry ?* ". 23")
2149 (modify-syntax-entry ?/ ". 14")
2152 (setq comment-start "/* ")
2153 (setq comment-end " */")
2154 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2156 ;; Now define things to be fontified.
2157 (make-local-variable 'font-lock-keywords)
2159 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
2160 "do" "else" "exit" "for" "global" "goto" "help" "if"
2161 "local" "mat" "obj" "print" "quit" "read" "return"
2162 "show" "static" "switch" "while" "write")))
2164 (setq font-lock-keywords
2167 ;; Handle the keywords defined above.
2168 (list (concat "\\<\\(" c-keywords "\\)\\>")
2169 '(0 font-lock-keyword-face))
2171 ;; Handle numbers too.
2173 ;; This looks strange, I know. It corresponds to the
2174 ;; preprocessor's idea of what a number looks like, rather than
2175 ;; anything sensible.
2176 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2177 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2178 '(0 mdw-number-face))
2180 ;; And anything else is punctuation.
2181 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2182 '(0 mdw-punct-face))))))
2184 ;;;--------------------------------------------------------------------------
2185 ;;; Java programming configuration.
2187 ;; Make indentation nice.
2189 (mdw-define-c-style mdw-java
2190 (c-basic-offset . 2)
2191 (c-backslash-column . 72)
2192 (c-offsets-alist (substatement-open . 0)
2197 (statement-case-intro . +)))
2198 (mdw-set-default-c-style 'java-mode 'mdw-java)
2200 ;; Declare Java fontification style.
2202 (defun mdw-fontify-java ()
2204 ;; Fiddle with some syntax codes.
2205 (modify-syntax-entry ?@ ".")
2206 (modify-syntax-entry ?@ "." font-lock-syntax-table)
2209 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2211 ;; Now define things to be fontified.
2212 (make-local-variable 'font-lock-keywords)
2213 (let ((java-keywords
2214 (mdw-regexps "abstract" "assert"
2215 "boolean" "break" "byte"
2216 "case" "catch" "char" "class" "const" "continue"
2217 "default" "do" "double"
2218 "else" "enum" "extends"
2219 "final" "finally" "float" "for"
2221 "if" "implements" "import" "instanceof" "int"
2225 "package" "private" "protected" "public"
2227 "short" "static" "strictfp" "switch" "synchronized"
2228 "throw" "throws" "transient" "try"
2233 (mdw-regexps "false" "null" "super" "this" "true")))
2235 (setq font-lock-keywords
2238 ;; Handle the keywords defined above.
2239 (list (concat "\\<\\(" java-keywords "\\)\\>")
2240 '(0 font-lock-keyword-face))
2242 ;; Handle the magic constants defined above.
2243 (list (concat "\\<\\(" java-constants "\\)\\>")
2244 '(0 font-lock-variable-name-face))
2246 ;; Handle numbers too.
2248 ;; The following isn't quite right, but it's close enough.
2249 (list (concat "\\<\\("
2250 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2251 "[0-9]+\\(\\.[0-9]*\\|\\)"
2252 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2254 '(0 mdw-number-face))
2256 ;; And anything else is punctuation.
2257 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2258 '(0 mdw-punct-face))))))
2260 ;;;--------------------------------------------------------------------------
2261 ;;; Javascript programming configuration.
2263 (defun mdw-javascript-style ()
2264 (setq js-indent-level 2)
2265 (setq js-expr-indent-offset 0))
2267 (defun mdw-fontify-javascript ()
2270 (mdw-javascript-style)
2271 (setq js-auto-indent-flag t)
2273 ;; Now define things to be fontified.
2274 (make-local-variable 'font-lock-keywords)
2275 (let ((javascript-keywords
2276 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
2277 "char" "class" "const" "continue" "debugger" "default"
2278 "delete" "do" "double" "else" "enum" "export" "extends"
2279 "final" "finally" "float" "for" "function" "goto" "if"
2280 "implements" "import" "in" "instanceof" "int"
2281 "interface" "let" "long" "native" "new" "package"
2282 "private" "protected" "public" "return" "short"
2283 "static" "super" "switch" "synchronized" "throw"
2284 "throws" "transient" "try" "typeof" "var" "void"
2285 "volatile" "while" "with" "yield"
2287 "boolean" "byte" "char" "double" "float" "int" "long"
2289 (javascript-constants
2290 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
2291 "arguments" "this")))
2293 (setq font-lock-keywords
2296 ;; Handle the keywords defined above.
2297 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
2298 '(0 font-lock-keyword-face))
2300 ;; Handle the predefined constants defined above.
2301 (list (concat "\\_<\\(" javascript-constants "\\)\\_>")
2302 '(0 font-lock-variable-name-face))
2304 ;; Handle numbers too.
2306 ;; The following isn't quite right, but it's close enough.
2307 (list (concat "\\_<\\("
2308 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2309 "[0-9]+\\(\\.[0-9]*\\|\\)"
2310 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2312 '(0 mdw-number-face))
2314 ;; And anything else is punctuation.
2315 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2316 '(0 mdw-punct-face))))))
2318 ;;;--------------------------------------------------------------------------
2319 ;;; Scala programming configuration.
2321 (defun mdw-fontify-scala ()
2324 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2326 ;; Define things to be fontified.
2327 (make-local-variable 'font-lock-keywords)
2328 (let ((scala-keywords
2329 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
2330 "extends" "final" "finally" "for" "forSome" "if"
2331 "implicit" "import" "lazy" "match" "new" "object"
2332 "override" "package" "private" "protected" "return"
2333 "sealed" "throw" "trait" "try" "type" "val"
2334 "var" "while" "with" "yield"))
2336 (mdw-regexps "false" "null" "super" "this" "true"))
2337 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
2339 (setq font-lock-keywords
2342 ;; Magical identifiers between backticks.
2343 (list (concat "`\\([^`]+\\)`")
2344 '(1 font-lock-variable-name-face))
2346 ;; Handle the keywords defined above.
2347 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
2348 '(0 font-lock-keyword-face))
2350 ;; Handle the constants defined above.
2351 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
2352 '(0 font-lock-variable-name-face))
2354 ;; Magical identifiers between backticks.
2355 (list (concat "`\\([^`]+\\)`")
2356 '(1 font-lock-variable-name-face))
2358 ;; Handle numbers too.
2360 ;; As usual, not quite right.
2361 (list (concat "\\_<\\("
2362 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2363 "[0-9]+\\(\\.[0-9]*\\|\\)"
2364 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2366 '(0 mdw-number-face))
2368 ;; And everything else is punctuation.
2369 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2370 '(0 mdw-punct-face)))
2372 font-lock-syntactic-keywords
2375 ;; Single quotes around characters. But not when used to quote
2376 ;; symbol names. Ugh.
2377 (list (concat "\\('\\)"
2379 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
2380 "u+" "[0-9a-fA-F]\\{4\\}"
2381 "\\|" "\\\\" "[0-7]\\{1,3\\}"
2382 "\\|" "\\\\" "." "\\)"
2387 ;;;--------------------------------------------------------------------------
2388 ;;; C# programming configuration.
2390 ;; Make indentation nice.
2392 (mdw-define-c-style mdw-csharp
2393 (c-basic-offset . 2)
2394 (c-backslash-column . 72)
2395 (c-offsets-alist (substatement-open . 0)
2400 (statement-case-intro . +)))
2401 (mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
2403 ;; Declare C# fontification style.
2405 (defun mdw-fontify-csharp ()
2408 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2410 ;; Now define things to be fontified.
2411 (make-local-variable 'font-lock-keywords)
2412 (let ((csharp-keywords
2413 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
2414 "char" "checked" "class" "const" "continue" "decimal"
2415 "default" "delegate" "do" "double" "else" "enum"
2416 "event" "explicit" "extern" "finally" "fixed" "float"
2417 "for" "foreach" "goto" "if" "implicit" "in" "int"
2418 "interface" "internal" "is" "lock" "long" "namespace"
2419 "new" "object" "operator" "out" "override" "params"
2420 "private" "protected" "public" "readonly" "ref"
2421 "return" "sbyte" "sealed" "short" "sizeof"
2422 "stackalloc" "static" "string" "struct" "switch"
2423 "throw" "try" "typeof" "uint" "ulong" "unchecked"
2424 "unsafe" "ushort" "using" "virtual" "void" "volatile"
2428 (mdw-regexps "base" "false" "null" "this" "true")))
2430 (setq font-lock-keywords
2433 ;; Handle the keywords defined above.
2434 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
2435 '(0 font-lock-keyword-face))
2437 ;; Handle the magic constants defined above.
2438 (list (concat "\\<\\(" csharp-constants "\\)\\>")
2439 '(0 font-lock-variable-name-face))
2441 ;; Handle numbers too.
2443 ;; The following isn't quite right, but it's close enough.
2444 (list (concat "\\<\\("
2445 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2446 "[0-9]+\\(\\.[0-9]*\\|\\)"
2447 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2449 '(0 mdw-number-face))
2451 ;; And anything else is punctuation.
2452 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2453 '(0 mdw-punct-face))))))
2455 (define-derived-mode csharp-mode java-mode "C#"
2456 "Major mode for editing C# code.")
2458 ;;;--------------------------------------------------------------------------
2459 ;;; F# programming configuration.
2461 (setq fsharp-indent-offset 2)
2463 (defun mdw-fontify-fsharp ()
2465 (let ((punct "=<>+-*/|&%!@?"))
2467 ((>= i (length punct)))
2468 (modify-syntax-entry (aref punct i) ".")))
2470 (modify-syntax-entry ?_ "_")
2471 (modify-syntax-entry ?( "(")
2472 (modify-syntax-entry ?) ")")
2474 (setq indent-tabs-mode nil)
2476 (let ((fsharp-keywords
2477 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
2479 "checked" "class" "component" "const" "constraint"
2480 "constructor" "continue"
2481 "default" "delegate" "do" "done" "downcast" "downto"
2482 "eager" "elif" "else" "end" "exception" "extern"
2483 "finally" "fixed" "for" "fori" "fun" "function"
2486 "if" "in" "include" "inherit" "inline" "interface"
2489 "match" "measure" "member" "method" "mixin" "module"
2492 "object" "of" "open" "or" "override"
2493 "parallel" "params" "private" "process" "protected"
2495 "rec" "recursive" "return"
2496 "sealed" "sig" "static" "struct"
2497 "tailcall" "then" "to" "trait" "try" "type"
2499 "val" "virtual" "void" "volatile"
2500 "when" "while" "with"
2504 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
2505 "base" "false" "null" "true"))
2508 (mdw-regexps "do" "let" "return" "use" "yield"))
2510 (preprocessor-keywords
2511 (mdw-regexps "if" "indent" "else" "endif")))
2513 (setq font-lock-keywords
2514 (list (list (concat "\\(^\\|[^\"]\\)"
2517 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
2522 '(2 font-lock-comment-face))
2524 (list (concat "'" "\\("
2527 "\\|" "[0-9][0-9][0-9]"
2528 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
2529 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
2535 "\\(" "\\\\" "\\(.\\|\n\\)"
2538 '(0 font-lock-string-face))
2540 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
2541 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
2543 "\\_<\\(" fsharp-keywords "\\)\\_>")
2544 '(0 font-lock-keyword-face))
2545 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
2546 '(0 font-lock-variable-name-face))
2548 (list (concat "\\_<"
2549 "\\(" "0[bB][01]+" "\\|"
2551 "0[xX][0-9a-fA-F]+" "\\)"
2552 "\\(" "lf\\|LF" "\\|"
2553 "[uU]?[ysnlL]?" "\\)"
2560 "\\([eE][-+]?[0-9]+\\)?"
2565 '(0 mdw-number-face))
2567 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2568 '(0 mdw-punct-face))))))
2570 (defun mdw-fontify-inferior-fsharp ()
2571 (mdw-fontify-fsharp)
2572 (setq font-lock-keywords
2573 (append (list (list "^[#-]" '(0 font-lock-comment-face))
2574 (list "^>" '(0 font-lock-keyword-face)))
2575 font-lock-keywords)))
2577 ;;;--------------------------------------------------------------------------
2578 ;;; Go programming configuration.
2580 (defun mdw-fontify-go ()
2582 (make-local-variable 'font-lock-keywords)
2584 (mdw-regexps "break" "case" "chan" "const" "continue"
2585 "default" "defer" "else" "fallthrough" "for"
2586 "func" "go" "goto" "if" "import"
2587 "interface" "map" "package" "range" "return"
2588 "select" "struct" "switch" "type" "var"))
2590 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
2591 "float32" "float64" "int" "uint8" "int16" "int32"
2592 "int64" "rune" "string" "uint" "uint8" "uint16"
2593 "uint32" "uint64" "uintptr" "void"
2594 "false" "iota" "nil" "true"
2596 "append" "cap" "copy" "delete" "imag" "len" "make"
2597 "new" "panic" "real" "recover")))
2599 (setq font-lock-keywords
2602 ;; Handle the keywords defined above.
2603 (list (concat "\\<\\(" go-keywords "\\)\\>")
2604 '(0 font-lock-keyword-face))
2605 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
2606 '(0 font-lock-variable-name-face))
2608 ;; Strings and characters.
2610 "\\(" "[^\\']" "\\|"
2612 "\\(" "[abfnrtv\\'\"]" "\\|"
2613 "[0-7]\\{3\\}" "\\|"
2614 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
2615 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
2616 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
2620 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
2624 '(0 font-lock-string-face))
2626 ;; Handle numbers too.
2628 ;; The following isn't quite right, but it's close enough.
2629 (list (concat "\\<\\("
2630 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2631 "[0-9]+\\(\\.[0-9]*\\|\\)"
2632 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
2633 '(0 mdw-number-face))
2635 ;; And anything else is punctuation.
2636 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2637 '(0 mdw-punct-face))))))
2639 ;;;--------------------------------------------------------------------------
2640 ;;; Rust programming configuration.
2642 (setq-default rust-indent-offset 2)
2644 (defun mdw-self-insert-and-indent (count)
2646 (self-insert-command count)
2647 (indent-according-to-mode))
2649 (defun mdw-fontify-rust ()
2651 ;; Hack syntax categories.
2652 (modify-syntax-entry ?= ".")
2654 ;; Fontify keywords and things.
2655 (make-local-variable 'font-lock-keywords)
2656 (let ((rust-keywords
2657 (mdw-regexps "abstract" "alignof" "as"
2658 "become" "box" "break"
2659 "const" "continue" "create"
2661 "else" "enum" "extern"
2665 "macro" "match" "mod" "move" "mut"
2666 "offsetof" "override"
2667 "priv" "proc" "pub" "pure"
2669 "sizeof" "static" "struct" "super"
2670 "trait" "type" "typeof"
2671 "unsafe" "unsized" "use"
2676 (mdw-regexps "array" "pointer" "slice" "tuple"
2677 "bool" "true" "false"
2679 "i8" "i16" "i32" "i64" "isize"
2680 "u8" "u16" "u32" "u64" "usize"
2683 (setq font-lock-keywords
2686 ;; Handle the keywords defined above.
2687 (list (concat "\\_<\\(" rust-keywords "\\)\\_>")
2688 '(0 font-lock-keyword-face))
2689 (list (concat "\\_<\\(" rust-builtins "\\)\\_>")
2690 '(0 font-lock-variable-name-face))
2692 ;; Handle numbers too.
2693 (list (concat "\\_<\\("
2695 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
2699 "\\|" "\\(" "[0-9][0-9_]*"
2700 "\\|" "0x[0-9a-fA-F_]+"
2704 "\\([ui]\\(8\\|16\\|32\\|64\\|s\\|size\\)\\)?"
2706 '(0 mdw-number-face))
2708 ;; And anything else is punctuation.
2709 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2710 '(0 mdw-punct-face)))))
2712 ;; Hack key bindings.
2713 (local-set-key [?{] 'mdw-self-insert-and-indent)
2714 (local-set-key [?}] 'mdw-self-insert-and-indent))
2716 ;;;--------------------------------------------------------------------------
2717 ;;; Awk programming configuration.
2719 ;; Make Awk indentation nice.
2721 (mdw-define-c-style mdw-awk
2722 (c-basic-offset . 2)
2723 (c-offsets-alist (substatement-open . 0)
2724 (c-backslash-column . 72)
2725 (statement-cont . 0)
2726 (statement-case-intro . +)))
2727 (mdw-set-default-c-style 'awk-mode 'mdw-awk)
2729 ;; Declare Awk fontification style.
2731 (defun mdw-fontify-awk ()
2733 ;; Miscellaneous fiddling.
2734 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2736 ;; Now define things to be fontified.
2737 (make-local-variable 'font-lock-keywords)
2739 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
2740 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
2741 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
2742 "RSTART" "RLENGTH" "RT" "SUBSEP"
2743 "atan2" "break" "close" "continue" "cos" "delete"
2744 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
2745 "function" "gensub" "getline" "gsub" "if" "in"
2746 "index" "int" "length" "log" "match" "next" "rand"
2747 "return" "print" "printf" "sin" "split" "sprintf"
2748 "sqrt" "srand" "strftime" "sub" "substr" "system"
2749 "systime" "tolower" "toupper" "while")))
2751 (setq font-lock-keywords
2754 ;; Handle the keywords defined above.
2755 (list (concat "\\<\\(" c-keywords "\\)\\>")
2756 '(0 font-lock-keyword-face))
2758 ;; Handle numbers too.
2760 ;; The following isn't quite right, but it's close enough.
2761 (list (concat "\\<\\("
2762 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2763 "[0-9]+\\(\\.[0-9]*\\|\\)"
2764 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2766 '(0 mdw-number-face))
2768 ;; And anything else is punctuation.
2769 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2770 '(0 mdw-punct-face))))))
2772 ;;;--------------------------------------------------------------------------
2773 ;;; Perl programming style.
2775 ;; Perl indentation style.
2777 (setq perl-indent-level 2)
2779 (setq cperl-indent-level 2)
2780 (setq cperl-continued-statement-offset 2)
2781 (setq cperl-continued-brace-offset 0)
2782 (setq cperl-brace-offset -2)
2783 (setq cperl-brace-imaginary-offset 0)
2784 (setq cperl-label-offset 0)
2786 ;; Define perl fontification style.
2788 (defun mdw-fontify-perl ()
2790 ;; Miscellaneous fiddling.
2791 (modify-syntax-entry ?$ "\\")
2792 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
2793 (modify-syntax-entry ?: "." font-lock-syntax-table)
2794 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2796 ;; Now define fontification things.
2797 (make-local-variable 'font-lock-keywords)
2798 (let ((perl-keywords
2805 "ge" "given" "gt" "goto"
2807 "last" "le" "local" "lt"
2812 "redo" "require" "return"
2814 "undef" "unless" "until" "use"
2817 (setq font-lock-keywords
2820 ;; Set up the keywords defined above.
2821 (list (concat "\\<\\(" perl-keywords "\\)\\>")
2822 '(0 font-lock-keyword-face))
2824 ;; At least numbers are simpler than C.
2825 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2826 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2827 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2828 '(0 mdw-number-face))
2830 ;; And anything else is punctuation.
2831 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2832 '(0 mdw-punct-face))))))
2834 (defun perl-number-tests (&optional arg)
2835 "Assign consecutive numbers to lines containing `#t'. With ARG,
2836 strip numbers instead."
2839 (goto-char (point-min))
2840 (let ((i 0) (fmt (if arg "" " %4d")))
2841 (while (search-forward "#t" nil t)
2842 (delete-region (point) (line-end-position))
2844 (insert (format fmt i)))
2845 (goto-char (point-min))
2846 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
2847 (replace-match (format "\\1%d" i))))))
2849 ;;;--------------------------------------------------------------------------
2850 ;;; Python programming style.
2852 (defun mdw-fontify-pythonic (keywords)
2854 ;; Miscellaneous fiddling.
2855 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2856 (setq indent-tabs-mode nil)
2858 ;; Now define fontification things.
2859 (make-local-variable 'font-lock-keywords)
2860 (setq font-lock-keywords
2863 ;; Set up the keywords defined above.
2864 (list (concat "\\_<\\(" keywords "\\)\\_>")
2865 '(0 font-lock-keyword-face))
2867 ;; At least numbers are simpler than C.
2868 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO]?[0-7]+\\|[bB][01]+\\)\\|"
2869 "\\_<[0-9][0-9]*\\(\\.[0-9]*\\|\\)"
2870 "\\([eE]\\([-+]\\|\\)[0-9]+\\|[lL]\\|\\)")
2871 '(0 mdw-number-face))
2873 ;; And anything else is punctuation.
2874 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2875 '(0 mdw-punct-face)))))
2877 ;; Define Python fontification styles.
2879 (defun mdw-fontify-python ()
2880 (mdw-fontify-pythonic
2881 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
2882 "del" "elif" "else" "except" "exec" "finally" "for"
2883 "from" "global" "if" "import" "in" "is" "lambda"
2884 "not" "or" "pass" "print" "raise" "return" "try"
2885 "while" "with" "yield")))
2887 (defun mdw-fontify-pyrex ()
2888 (mdw-fontify-pythonic
2889 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
2890 "ctypedef" "def" "del" "elif" "else" "enum" "except" "exec"
2891 "extern" "finally" "for" "from" "global" "if"
2892 "import" "in" "is" "lambda" "not" "or" "pass" "print"
2893 "property" "raise" "return" "struct" "try" "while" "with"
2896 (define-derived-mode pyrex-mode python-mode "Pyrex"
2897 "Major mode for editing Pyrex source code")
2898 (setq auto-mode-alist
2899 (append '(("\\.pyx$" . pyrex-mode)
2900 ("\\.pxd$" . pyrex-mode)
2901 ("\\.pxi$" . pyrex-mode))
2904 ;;;--------------------------------------------------------------------------
2905 ;;; Lua programming style.
2907 (setq lua-indent-level 2)
2909 (defun mdw-fontify-lua ()
2911 ;; Miscellaneous fiddling.
2912 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2914 ;; Now define fontification things.
2915 (make-local-variable 'font-lock-keywords)
2917 (mdw-regexps "and" "break" "do" "else" "elseif" "end"
2918 "false" "for" "function" "goto" "if" "in" "local"
2919 "nil" "not" "or" "repeat" "return" "then" "true"
2921 (setq font-lock-keywords
2924 ;; Set up the keywords defined above.
2925 (list (concat "\\_<\\(" lua-keywords "\\)\\_>")
2926 '(0 font-lock-keyword-face))
2928 ;; At least numbers are simpler than C.
2929 (list (concat "\\_<\\(" "0[xX]"
2930 "\\(" "[0-9a-fA-F]+"
2931 "\\(\\.[0-9a-fA-F]*\\)?"
2932 "\\|" "\\.[0-9a-fA-F]+"
2934 "\\([pP][-+]?[0-9]+\\)?"
2935 "\\|" "\\(" "[0-9]+"
2939 "\\([eE][-+]?[0-9]+\\)?"
2941 '(0 mdw-number-face))
2943 ;; And anything else is punctuation.
2944 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2945 '(0 mdw-punct-face))))))
2947 ;;;--------------------------------------------------------------------------
2948 ;;; Icon programming style.
2950 ;; Icon indentation style.
2952 (setq icon-brace-offset 0
2953 icon-continued-brace-offset 0
2954 icon-continued-statement-offset 2
2955 icon-indent-level 2)
2957 ;; Define Icon fontification style.
2959 (defun mdw-fontify-icon ()
2961 ;; Miscellaneous fiddling.
2962 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2964 ;; Now define fontification things.
2965 (make-local-variable 'font-lock-keywords)
2966 (let ((icon-keywords
2967 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
2968 "end" "every" "fail" "global" "if" "initial"
2969 "invocable" "link" "local" "next" "not" "of"
2970 "procedure" "record" "repeat" "return" "static"
2971 "suspend" "then" "to" "until" "while"))
2972 (preprocessor-keywords
2973 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
2974 "include" "line" "undef")))
2975 (setq font-lock-keywords
2978 ;; Set up the keywords defined above.
2979 (list (concat "\\<\\(" icon-keywords "\\)\\>")
2980 '(0 font-lock-keyword-face))
2982 ;; The things that Icon calls keywords.
2983 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
2985 ;; At least numbers are simpler than C.
2986 (list (concat "\\<[0-9]+"
2987 "\\([rR][0-9a-zA-Z]+\\|"
2988 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
2989 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
2990 '(0 mdw-number-face))
2993 (list (concat "^[ \t]*$[ \t]*\\<\\("
2994 preprocessor-keywords
2996 '(0 font-lock-keyword-face))
2998 ;; And anything else is punctuation.
2999 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3000 '(0 mdw-punct-face))))))
3002 ;;;--------------------------------------------------------------------------
3005 (defun mdw-fontify-asm ()
3006 (modify-syntax-entry ?' "\"")
3007 (modify-syntax-entry ?. "w")
3008 (modify-syntax-entry ?\n ">")
3009 (setf fill-prefix nil)
3010 (modify-syntax-entry ?. "_")
3011 (modify-syntax-entry ?* ". 23")
3012 (modify-syntax-entry ?/ ". 124b")
3013 (modify-syntax-entry ?\n "> b")
3014 (local-set-key ";" 'self-insert-command)
3015 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
3017 (defun mdw-asm-set-comment ()
3018 (modify-syntax-entry ?; "."
3020 (modify-syntax-entry asm-comment-char "< b")
3021 (setq comment-start (string asm-comment-char ? )))
3022 (add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
3023 (put 'asm-comment-char 'safe-local-variable 'characterp)
3025 ;;;--------------------------------------------------------------------------
3026 ;;; TCL configuration.
3028 (defun mdw-fontify-tcl ()
3029 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
3030 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3031 (make-local-variable 'font-lock-keywords)
3032 (setq font-lock-keywords
3034 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3035 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
3036 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
3037 '(0 mdw-number-face))
3038 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3039 '(0 mdw-punct-face)))))
3041 ;;;--------------------------------------------------------------------------
3042 ;;; Dylan programming configuration.
3044 (defun mdw-fontify-dylan ()
3046 (make-local-variable 'font-lock-keywords)
3048 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
3049 ;; hook, which undoes all of our configuration.
3050 (setq major-mode 'dylan-mode)
3051 (font-lock-set-defaults)
3053 (let* ((word "[-_a-zA-Z!*@<>$%]+")
3054 (dylan-keywords (mdw-regexps
3056 "C-address" "C-callable-wrapper" "C-function"
3057 "C-mapped-subtype" "C-pointer-type" "C-struct"
3058 "C-subtype" "C-union" "C-variable"
3060 "above" "abstract" "afterwards" "all"
3061 "begin" "below" "block" "by"
3062 "case" "class" "cleanup" "constant" "create"
3064 "else" "elseif" "end" "exception" "export"
3065 "finally" "for" "from" "function"
3068 "if" "in" "instance" "interface" "iterate"
3070 "let" "library" "local"
3071 "macro" "method" "module"
3074 "select" "slot" "subclass"
3076 "unless" "until" "use"
3077 "variable" "virtual"
3079 (sharp-keywords (mdw-regexps
3080 "all-keys" "key" "next" "rest" "include"
3082 (setq font-lock-keywords
3083 (list (list (concat "\\<\\(" dylan-keywords
3084 "\\|" "with\\(out\\)?-" word
3086 '(0 font-lock-keyword-face))
3087 (list (concat "\\<" word ":" "\\|"
3088 "#\\(" sharp-keywords "\\)\\>")
3089 '(0 font-lock-variable-name-face))
3091 "\\([-+]\\|\\<\\)[0-9]+" "\\("
3092 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
3095 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
3098 "\\|" "#x[0-9a-zA-Z]+"
3100 '(0 mdw-number-face))
3102 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
3103 "\\_<[-+*/=<>:&|]+\\_>"
3105 '(0 mdw-punct-face))))))
3107 ;;;--------------------------------------------------------------------------
3108 ;;; Algol 68 configuration.
3110 (setq a68-indent-step 2)
3112 (defun mdw-fontify-algol-68 ()
3114 ;; Fix up the syntax table.
3115 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
3116 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
3117 (modify-syntax-entry ch "." a68-mode-syntax-table))
3119 (make-local-variable 'font-lock-keywords)
3122 (let ((word "COMMENT"))
3123 (do ((regexp (concat "[^" (substring word 0 1) "]+")
3124 (concat regexp "\\|"
3125 (substring word 0 i)
3126 "[^" (substring word i (1+ i)) "]"))
3128 ((>= i (length word)) regexp)))))
3129 (setq font-lock-keywords
3130 (list (list (concat "\\<COMMENT\\>"
3131 "\\(" not-comment "\\)\\{0,5\\}"
3132 "\\(\\'\\|\\<COMMENT\\>\\)")
3133 '(0 font-lock-comment-face))
3134 (list (concat "\\<CO\\>"
3135 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
3136 "\\($\\|\\<CO\\>\\)")
3137 '(0 font-lock-comment-face))
3138 (list "\\<[A-Z_]+\\>"
3139 '(0 font-lock-keyword-face))
3143 "\\([eE][-+]?[0-9]+\\)?"
3145 '(0 mdw-number-face))
3146 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
3147 '(0 mdw-punct-face))))))
3149 ;;;--------------------------------------------------------------------------
3150 ;;; REXX configuration.
3152 (defun mdw-rexx-electric-* ()
3157 (defun mdw-rexx-indent-newline-indent ()
3160 (if abbrev-mode (expand-abbrev))
3161 (newline-and-indent))
3163 (defun mdw-fontify-rexx ()
3165 ;; Various bits of fiddling.
3166 (setq mdw-auto-indent nil)
3167 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
3168 (local-set-key [?*] 'mdw-rexx-electric-*)
3169 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
3171 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
3173 ;; Set up keywords and things for fontification.
3174 (make-local-variable 'font-lock-keywords-case-fold-search)
3175 (setq font-lock-keywords-case-fold-search t)
3177 (setq rexx-indent 2)
3178 (setq rexx-end-indent rexx-indent)
3179 (setq rexx-cont-indent rexx-indent)
3181 (make-local-variable 'font-lock-keywords)
3182 (let ((rexx-keywords
3183 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
3184 "else" "end" "engineering" "exit" "expose" "for"
3185 "forever" "form" "fuzz" "if" "interpret" "iterate"
3186 "leave" "linein" "name" "nop" "numeric" "off" "on"
3187 "options" "otherwise" "parse" "procedure" "pull"
3188 "push" "queue" "return" "say" "select" "signal"
3189 "scientific" "source" "then" "trace" "to" "until"
3190 "upper" "value" "var" "version" "when" "while"
3193 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
3194 "center" "center" "charin" "charout" "chars"
3195 "compare" "condition" "copies" "c2d" "c2x"
3196 "datatype" "date" "delstr" "delword" "d2c" "d2x"
3197 "errortext" "format" "fuzz" "insert" "lastpos"
3198 "left" "length" "lineout" "lines" "max" "min"
3199 "overlay" "pos" "queued" "random" "reverse" "right"
3200 "sign" "sourceline" "space" "stream" "strip"
3201 "substr" "subword" "symbol" "time" "translate"
3202 "trunc" "value" "verify" "word" "wordindex"
3203 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
3206 (setq font-lock-keywords
3209 ;; Set up the keywords defined above.
3210 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
3211 '(0 font-lock-keyword-face))
3213 ;; Fontify all symbols the same way.
3214 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
3215 "[A-Za-z0-9.!?_#@$]+\\)")
3216 '(0 font-lock-variable-name-face))
3218 ;; And everything else is punctuation.
3219 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3220 '(0 mdw-punct-face))))))
3222 ;;;--------------------------------------------------------------------------
3223 ;;; Standard ML programming style.
3225 (defun mdw-fontify-sml ()
3227 ;; Make underscore an honorary letter.
3228 (modify-syntax-entry ?' "w")
3231 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
3233 ;; Now define fontification things.
3234 (make-local-variable 'font-lock-keywords)
3236 (mdw-regexps "abstype" "and" "andalso" "as"
3239 "else" "end" "eqtype" "exception"
3240 "fn" "fun" "functor"
3242 "if" "in" "include" "infix" "infixr"
3245 "of" "op" "open" "orelse"
3247 "sharing" "sig" "signature" "struct" "structure"
3250 "where" "while" "with" "withtype")))
3252 (setq font-lock-keywords
3255 ;; Set up the keywords defined above.
3256 (list (concat "\\<\\(" sml-keywords "\\)\\>")
3257 '(0 font-lock-keyword-face))
3259 ;; At least numbers are simpler than C.
3260 (list (concat "\\<\\(\\~\\|\\)"
3261 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
3263 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
3264 "\\([eE]\\(\\~\\|\\)"
3265 "[0-9]+\\|\\)\\)\\)")
3266 '(0 mdw-number-face))
3268 ;; And anything else is punctuation.
3269 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3270 '(0 mdw-punct-face))))))
3272 ;;;--------------------------------------------------------------------------
3273 ;;; Haskell configuration.
3275 (defun mdw-fontify-haskell ()
3277 ;; Fiddle with syntax table to get comments right.
3278 (modify-syntax-entry ?' "_")
3279 (modify-syntax-entry ?- ". 12")
3280 (modify-syntax-entry ?\n ">")
3282 ;; Make punctuation be punctuation
3283 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
3285 ((>= i (length punct)))
3286 (modify-syntax-entry (aref punct i) ".")))
3289 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
3291 ;; Fiddle with fontification.
3292 (make-local-variable 'font-lock-keywords)
3293 (let ((haskell-keywords
3295 "case" "ccall" "class"
3296 "data" "default" "deriving" "do"
3300 "if" "import" "in" "infix" "infixl" "infixr" "instance"
3313 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
3314 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
3315 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
3316 "SP" "STX" "SUB" "SYN" "US" "VT")))
3318 (setq font-lock-keywords
3320 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
3324 '(0 font-lock-comment-face))
3325 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
3326 '(0 font-lock-keyword-face))
3327 (list (concat "'\\("
3331 "\\(" "[abfnrtv\\\"']" "\\|"
3332 "^" "\\(" control-sequences "\\|"
3333 "[]A-Z@[\\^_]" "\\)" "\\|"
3340 '(0 font-lock-string-face))
3341 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
3342 '(0 font-lock-variable-name-face))
3343 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
3344 "\\_<[0-9]+\\(\\.[0-9]*\\|\\)"
3345 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
3346 '(0 mdw-number-face))
3347 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3348 '(0 mdw-punct-face))))))
3350 ;;;--------------------------------------------------------------------------
3351 ;;; Erlang configuration.
3353 (setq erlang-electric-commands nil)
3355 (defun mdw-fontify-erlang ()
3358 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
3360 ;; Fiddle with fontification.
3361 (make-local-variable 'font-lock-keywords)
3362 (let ((erlang-keywords
3363 (mdw-regexps "after" "and" "andalso"
3364 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
3365 "case" "catch" "cond"
3366 "div" "end" "fun" "if" "let" "not"
3368 "query" "receive" "rem" "try" "when" "xor")))
3370 (setq font-lock-keywords
3373 '(0 font-lock-comment-face))
3374 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
3375 '(0 font-lock-keyword-face))
3376 (list (concat "^-\\sw+\\>")
3377 '(0 font-lock-keyword-face))
3378 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
3379 '(0 mdw-number-face))
3380 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3381 '(0 mdw-punct-face))))))
3383 ;;;--------------------------------------------------------------------------
3384 ;;; Texinfo configuration.
3386 (defun mdw-fontify-texinfo ()
3389 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
3391 ;; Real fontification things.
3392 (make-local-variable 'font-lock-keywords)
3393 (setq font-lock-keywords
3396 ;; Environment names are keywords.
3397 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
3398 '(2 font-lock-keyword-face))
3400 ;; Unmark escaped magic characters.
3401 (list "\\(@\\)\\([@{}]\\)"
3402 '(1 font-lock-keyword-face)
3403 '(2 font-lock-variable-name-face))
3405 ;; Make sure we get comments properly.
3406 (list "@c\\(\\|omment\\)\\( .*\\)?$"
3407 '(0 font-lock-comment-face))
3409 ;; Command names are keywords.
3410 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3411 '(0 font-lock-keyword-face))
3413 ;; Fontify TeX special characters as punctuation.
3415 '(0 mdw-punct-face)))))
3417 ;;;--------------------------------------------------------------------------
3418 ;;; TeX and LaTeX configuration.
3420 (defun mdw-fontify-tex ()
3421 (setq ispell-parser 'tex)
3424 ;; Don't make maths into a string.
3425 (modify-syntax-entry ?$ ".")
3426 (modify-syntax-entry ?$ "." font-lock-syntax-table)
3427 (local-set-key [?$] 'self-insert-command)
3429 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
3430 (local-set-key "\C-\M-i" 'indent-relative)
3431 (setq indent-tabs-mode nil)
3434 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
3436 ;; Real fontification things.
3437 (make-local-variable 'font-lock-keywords)
3438 (setq font-lock-keywords
3441 ;; Environment names are keywords.
3442 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
3444 '(2 font-lock-keyword-face))
3446 ;; Suspended environment names are keywords too.
3447 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
3449 '(3 font-lock-keyword-face))
3451 ;; Command names are keywords.
3452 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3453 '(0 font-lock-keyword-face))
3455 ;; Handle @/.../ for italics.
3456 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
3457 ;; '(1 font-lock-keyword-face)
3458 ;; '(3 font-lock-keyword-face))
3460 ;; Handle @*...* for boldness.
3461 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
3462 ;; '(1 font-lock-keyword-face)
3463 ;; '(3 font-lock-keyword-face))
3465 ;; Handle @`...' for literal syntax things.
3466 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
3467 ;; '(1 font-lock-keyword-face)
3468 ;; '(3 font-lock-keyword-face))
3470 ;; Handle @<...> for nonterminals.
3471 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
3472 ;; '(1 font-lock-keyword-face)
3473 ;; '(3 font-lock-keyword-face))
3475 ;; Handle other @-commands.
3476 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
3477 ;; '(0 font-lock-keyword-face))
3479 ;; Make sure we get comments properly.
3481 '(0 font-lock-comment-face))
3483 ;; Fontify TeX special characters as punctuation.
3485 '(0 mdw-punct-face)))))
3487 (setq TeX-install-font-lock 'tex-font-setup)
3489 (eval-after-load 'font-latex
3490 '(defun font-latex-jit-lock-force-redisplay (buf start end)
3491 "Compatibility for Emacsen not offering `jit-lock-force-redisplay'."
3492 ;; The following block is an expansion of `jit-lock-force-redisplay'
3493 ;; and involved macros taken from CVS Emacs on 2007-04-28.
3494 (with-current-buffer buf
3495 (let ((modified (buffer-modified-p)))
3497 (let ((buffer-undo-list t)
3498 (inhibit-read-only t)
3499 (inhibit-point-motion-hooks t)
3500 (inhibit-modification-hooks t)
3503 buffer-file-truename)
3504 (put-text-property start end 'fontified t))
3506 (restore-buffer-modified-p nil)))))))
3508 (setq LaTeX-syntactic-comments nil
3509 LaTeX-fill-break-at-separators '(\\\[))
3511 ;;;--------------------------------------------------------------------------
3512 ;;; HTML, CSS, and other web foolishness.
3514 (setq css-indent-offset 2)
3516 ;;;--------------------------------------------------------------------------
3519 (defun mdw-sgml-mode ()
3522 (mdw-standard-fill-prefix "")
3523 (make-local-variable 'sgml-delimiters)
3524 (setq sgml-delimiters
3525 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
3526 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
3527 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
3528 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
3529 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
3530 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
3531 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
3533 (setq major-mode 'mdw-sgml-mode)
3534 (setq mode-name "[mdw] SGML")
3535 (run-hooks 'mdw-sgml-mode-hook))
3537 ;;;--------------------------------------------------------------------------
3538 ;;; Configuration files.
3540 (defvar mdw-conf-quote-normal nil
3541 "*Control syntax category of quote characters `\"' and `''.
3542 If this is `t', consider quote characters to be normal
3543 punctuation, as for `conf-quote-normal'. If this is `nil' then
3544 leave quote characters as quotes. If this is a list, then
3545 consider the quote characters in the list to be normal
3546 punctuation. If this is a single quote character, then consider
3547 that character only to be normal punctuation.")
3548 (defun mdw-conf-quote-normal-acceptable-value-p (value)
3549 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
3550 (or (booleanp value)
3551 (every (lambda (v) (memq v '(?\" ?')))
3552 (if (listp value) value (list value)))))
3553 (put 'mdw-conf-quote-normal 'safe-local-variable
3554 'mdw-conf-quote-normal-acceptable-value-p)
3556 (defun mdw-fix-up-quote ()
3557 "Apply the setting of `mdw-conf-quote-normal'."
3558 (let ((flag mdw-conf-quote-normal))
3560 (conf-quote-normal t))
3564 (let ((table (copy-syntax-table (syntax-table))))
3565 (mapc (lambda (ch) (modify-syntax-entry ch "." table))
3566 (if (listp flag) flag (list flag)))
3567 (set-syntax-table table)
3568 (and font-lock-mode (font-lock-fontify-buffer)))))))
3569 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t)
3571 ;;;--------------------------------------------------------------------------
3574 (defun mdw-setup-sh-script-mode ()
3576 ;; Fetch the shell interpreter's name.
3577 (let ((shell-name sh-shell-file))
3579 ;; Try reading the hash-bang line.
3581 (goto-char (point-min))
3582 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
3583 (setq shell-name (match-string 1))))
3585 ;; Now try to set the shell.
3587 ;; Don't let `sh-set-shell' bugger up my script.
3588 (let ((executable-set-magic #'(lambda (s &rest r) s)))
3589 (sh-set-shell shell-name)))
3591 ;; Don't insert here-document scaffolding automatically.
3592 (local-set-key "<" 'self-insert-command)
3594 ;; Now enable my keys and the fontification.
3595 (mdw-misc-mode-config)
3597 ;; Set the indentation level correctly.
3598 (setq sh-indentation 2)
3599 (setq sh-basic-offset 2))
3601 (setq sh-shell-file "/bin/sh")
3603 ;; Awful hacking to override the shell detection for particular scripts.
3604 (defmacro define-custom-shell-mode (name shell)
3607 (set (make-local-variable 'sh-shell-file) ,shell)
3609 (define-custom-shell-mode bash-mode "/bin/bash")
3610 (define-custom-shell-mode rc-mode "/usr/bin/rc")
3611 (put 'sh-shell-file 'permanent-local t)
3613 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
3614 (eval-after-load "sh-script"
3615 '(or (assq 'rc sh-mode-syntax-table-input)
3632 (assoc (assq 'rc sh-mode-syntax-table-input)))
3635 (setq sh-mode-syntax-table-input
3636 (cons (cons 'rc frag)
3637 sh-mode-syntax-table-input))))))
3639 ;;;--------------------------------------------------------------------------
3640 ;;; Emacs shell mode.
3642 (defun mdw-eshell-prompt ()
3643 (let ((left "[") (right "]"))
3644 (when (= (user-uid) 0)
3645 (setq left "«" right "»"))
3648 (replace-regexp-in-string "\\..*$" "" (system-name)))
3650 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
3651 (home (expand-file-name "~")) (nhome (length home)))
3652 (if (and (>= npwd nhome)
3654 (= (elt pwd nhome) ?/))
3655 (string= (substring pwd 0 nhome) home))
3656 (concat "~" (substring pwd (length home)))
3659 (setq eshell-prompt-function 'mdw-eshell-prompt)
3660 (setq eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
3662 (defun eshell/e (file) (find-file file) nil)
3663 (defun eshell/ee (file) (find-file-other-window file) nil)
3664 (defun eshell/w3m (url) (w3m-goto-url url) nil)
3666 (mdw-define-face eshell-prompt (t :weight bold))
3667 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
3668 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
3669 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
3670 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
3671 (mdw-define-face eshell-ls-executable (t :weight bold))
3672 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
3673 (mdw-define-face eshell-ls-readonly (t nil))
3674 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
3676 (defun mdw-eshell-hack () (setenv "LD_PRELOAD" nil))
3677 (add-hook 'eshell-mode-hook 'mdw-eshell-hack)
3679 ;;;--------------------------------------------------------------------------
3680 ;;; Messages-file mode.
3682 (defun messages-mode-guts ()
3683 (setq messages-mode-syntax-table (make-syntax-table))
3684 (set-syntax-table messages-mode-syntax-table)
3685 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
3686 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
3687 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
3688 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
3689 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
3690 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
3691 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
3692 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
3693 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
3694 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
3695 (make-local-variable 'comment-start)
3696 (make-local-variable 'comment-end)
3697 (make-local-variable 'indent-line-function)
3698 (setq indent-line-function 'indent-relative)
3699 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3700 (make-local-variable 'font-lock-defaults)
3701 (make-local-variable 'messages-mode-keywords)
3703 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
3704 "export" "enum" "fixed-octetstring" "flags"
3705 "harmless" "map" "nested" "optional"
3706 "optional-tagged" "package" "primitive"
3707 "primitive-nullfree" "relaxed[ \t]+enum"
3708 "set" "table" "tagged-optional" "union"
3709 "variadic" "vector" "version" "version-tag")))
3710 (setq messages-mode-keywords
3712 (list (concat "\\<\\(" keywords "\\)\\>:")
3713 '(0 font-lock-keyword-face))
3714 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
3715 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
3716 (0 font-lock-variable-name-face))
3717 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
3718 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3719 (0 mdw-punct-face)))))
3720 (setq font-lock-defaults
3721 '(messages-mode-keywords nil nil nil nil))
3722 (run-hooks 'messages-file-hook))
3724 (defun messages-mode ()
3727 (setq major-mode 'messages-mode)
3728 (setq mode-name "Messages")
3729 (messages-mode-guts)
3730 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
3731 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
3732 (setq comment-start "# ")
3733 (setq comment-end "")
3734 (run-hooks 'messages-mode-hook))
3736 (defun cpp-messages-mode ()
3739 (setq major-mode 'cpp-messages-mode)
3740 (setq mode-name "CPP Messages")
3741 (messages-mode-guts)
3742 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
3743 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
3744 (setq comment-start "/* ")
3745 (setq comment-end " */")
3746 (let ((preprocessor-keywords
3747 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
3748 "ident" "if" "ifdef" "ifndef" "import" "include"
3749 "line" "pragma" "unassert" "undef" "warning")))
3750 (setq messages-mode-keywords
3751 (append (list (list (concat "^[ \t]*\\#[ \t]*"
3752 "\\(include\\|import\\)"
3753 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
3754 '(2 font-lock-string-face))
3755 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
3756 preprocessor-keywords
3757 "\\)\\>\\|[0-9]+\\|$\\)\\)")
3758 '(1 font-lock-keyword-face)))
3759 messages-mode-keywords)))
3760 (run-hooks 'cpp-messages-mode-hook))
3762 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
3763 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
3764 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
3766 ;;;--------------------------------------------------------------------------
3767 ;;; Messages-file mode.
3769 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
3770 "Face to use for subsittution directives.")
3771 (make-face 'mallow-driver-substitution-face)
3772 (defvar mallow-driver-text-face 'mallow-driver-text-face
3773 "Face to use for body text.")
3774 (make-face 'mallow-driver-text-face)
3776 (defun mallow-driver-mode ()
3779 (setq major-mode 'mallow-driver-mode)
3780 (setq mode-name "Mallow driver")
3781 (setq mallow-driver-mode-syntax-table (make-syntax-table))
3782 (set-syntax-table mallow-driver-mode-syntax-table)
3783 (make-local-variable 'comment-start)
3784 (make-local-variable 'comment-end)
3785 (make-local-variable 'indent-line-function)
3786 (setq indent-line-function 'indent-relative)
3787 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3788 (make-local-variable 'font-lock-defaults)
3789 (make-local-variable 'mallow-driver-mode-keywords)
3791 (mdw-regexps "each" "divert" "file" "if"
3792 "perl" "set" "string" "type" "write")))
3793 (setq mallow-driver-mode-keywords
3795 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
3796 '(0 font-lock-keyword-face))
3797 (list "^%\\s *\\(#.*\\|\\)$"
3798 '(0 font-lock-comment-face))
3800 '(0 font-lock-keyword-face))
3801 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
3803 '(0 mallow-driver-substitution-face t)))))
3804 (setq font-lock-defaults
3805 '(mallow-driver-mode-keywords nil nil nil nil))
3806 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
3807 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
3808 (setq comment-start "%# ")
3809 (setq comment-end "")
3810 (run-hooks 'mallow-driver-mode-hook))
3812 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
3814 ;;;--------------------------------------------------------------------------
3817 (defun nfast-debug-mode ()
3820 (setq major-mode 'nfast-debug-mode)
3821 (setq mode-name "NFast debug")
3822 (setq messages-mode-syntax-table (make-syntax-table))
3823 (set-syntax-table messages-mode-syntax-table)
3824 (make-local-variable 'font-lock-defaults)
3825 (make-local-variable 'nfast-debug-mode-keywords)
3826 (setq truncate-lines t)
3827 (setq nfast-debug-mode-keywords
3829 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
3830 (0 font-lock-keyword-face))
3831 (list (concat "^[ \t]+\\(\\("
3832 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
3833 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
3835 "[0-9a-fA-F]+\\)[ \t]*$")
3836 '(0 mdw-number-face))
3837 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
3838 (1 font-lock-keyword-face))
3839 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
3840 (1 font-lock-warning-face))
3841 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
3843 (list (concat "^[ \t]+\\.cmd=[ \t]+"
3844 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
3845 '(1 font-lock-keyword-face))
3846 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
3847 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
3848 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
3849 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
3850 (setq font-lock-defaults
3851 '(nfast-debug-mode-keywords nil nil nil nil))
3852 (run-hooks 'nfast-debug-mode-hook))
3854 ;;;--------------------------------------------------------------------------
3855 ;;; Other languages.
3859 (defun mdw-setup-smalltalk ()
3860 (and mdw-auto-indent
3861 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
3862 (make-local-variable 'mdw-auto-indent)
3863 (setq mdw-auto-indent nil)
3864 (local-set-key "\C-i" 'smalltalk-reindent))
3866 (defun mdw-fontify-smalltalk ()
3867 (make-local-variable 'font-lock-keywords)
3868 (setq font-lock-keywords
3870 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
3871 '(0 font-lock-keyword-face))
3872 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3873 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
3874 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
3875 '(0 mdw-number-face))
3876 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3877 '(0 mdw-punct-face)))))
3881 ;; Unpleasant bodge.
3882 (unless (boundp 'slime-repl-mode-map)
3883 (setq slime-repl-mode-map (make-sparse-keymap)))
3885 (defun mdw-indent-newline-and-indent ()
3887 (indent-for-tab-command)
3888 (newline-and-indent))
3890 (eval-after-load "cl-indent"
3892 (mapc #'(lambda (pair)
3894 'common-lisp-indent-function
3896 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
3897 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
3899 (defun mdw-common-lisp-indent ()
3900 (make-local-variable 'lisp-indent-function)
3901 (setq lisp-indent-function 'common-lisp-indent-function))
3903 (setq lisp-simple-loop-indentation 2
3904 lisp-loop-keyword-indentation 6
3905 lisp-loop-forms-indentation 6)
3907 (defun mdw-fontify-lispy ()
3910 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
3912 ;; Not much fontification needed.
3913 (make-local-variable 'font-lock-keywords)
3914 (setq font-lock-keywords
3915 (list (list (concat "\\("
3917 "\\(" "[0-9]+/[0-9]+"
3918 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
3920 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
3925 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
3926 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
3927 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
3928 "\\|" "[0-9]+" "r" "[-+]?"
3929 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
3932 '(0 mdw-number-face))
3933 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3934 '(0 mdw-punct-face)))))
3936 (defun comint-send-and-indent ()
3939 (and mdw-auto-indent
3940 (indent-for-tab-command)))
3942 (defadvice comint-line-beginning-position
3943 (around mdw-calculate-it-properly () activate compile)
3944 "Calculate the actual line start for multi-line input."
3945 (if (or comint-use-prompt-regexp
3946 (eq (field-at-pos (point)) 'output))
3948 (setq ad-return-value
3949 (constrain-to-field (line-beginning-position) (point)))))
3951 (defun mdw-setup-m4 ()
3953 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
3954 ;; annoying: fix it.
3955 (modify-syntax-entry ?{ "(")
3956 (modify-syntax-entry ?} ")")
3959 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
3961 ;;;--------------------------------------------------------------------------
3964 (defun mdw-text-mode ()
3965 (setq fill-column 72)
3967 (mdw-standard-fill-prefix
3968 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
3971 (eval-after-load "flyspell"
3972 '(define-key flyspell-mode-map "\C-\M-i" nil))
3974 ;;;--------------------------------------------------------------------------
3975 ;;; Outline and hide/show modes.
3977 (defun mdw-outline-collapse-all ()
3978 "Completely collapse everything in the entire buffer."
3981 (goto-char (point-min))
3982 (while (< (point) (point-max))
3986 (setq hs-hide-comments-when-hiding-all nil)
3988 (defadvice hs-hide-all (after hide-first-comment activate)
3989 (save-excursion (hs-hide-initial-comment-block)))
3991 ;;;--------------------------------------------------------------------------
3994 (defun mdw-sh-mode-setup ()
3995 (local-set-key [?\C-a] 'comint-bol)
3996 (add-hook 'comint-output-filter-functions
3997 'comint-watch-for-password-prompt))
3999 (defun mdw-term-mode-setup ()
4000 (setq term-prompt-regexp shell-prompt-pattern)
4001 (make-local-variable 'mouse-yank-at-point)
4002 (make-local-variable 'transient-mark-mode)
4003 (setq mouse-yank-at-point t)
4007 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
4008 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
4009 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
4010 (defun term-send-meta-meta-something ()
4012 (term-send-raw-string "\e\e")
4014 (eval-after-load 'term
4016 (define-key term-raw-map [?\e ?\e] nil)
4017 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
4018 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
4019 (define-key term-raw-map [M-right] 'term-send-meta-right)
4020 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
4021 (define-key term-raw-map [M-left] 'term-send-meta-left)
4022 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
4024 (defadvice term-exec (before program-args-list compile activate)
4025 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
4026 This allows you to pass a list of arguments through `ansi-term'."
4027 (let ((program (ad-get-arg 2)))
4030 (ad-set-arg 2 (car program))
4031 (ad-set-arg 4 (cdr program))))))
4033 (defadvice term-exec-1 (around hack-environment compile activate)
4034 "Hack the environment inherited by inferiors in the terminal."
4035 (let ((process-environment process-environment))
4036 (setenv "LD_PRELOAD" nil)
4039 (defadvice shell (around hack-environment compile activate)
4040 "Hack the environment inherited by inferiors in the shell."
4041 (let ((process-environment process-environment))
4042 (setenv "LD_PRELOAD" nil)
4046 "Open a terminal containing an ssh session to the HOST."
4047 (interactive "sHost: ")
4048 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
4050 (defvar git-grep-command
4051 "env GIT_PAGER=cat git grep --no-color -nH -e "
4052 "*The default command for \\[git-grep].")
4054 (defvar git-grep-history nil)
4056 (defun git-grep (command-args)
4057 "Run `git grep' with user-specified args and collect output in a buffer."
4059 (list (read-shell-command "Run git grep (like this): "
4060 git-grep-command 'git-grep-history)))
4061 (let ((grep-use-null-device nil))
4062 (grep command-args)))
4064 ;;;--------------------------------------------------------------------------
4065 ;;; Magit configuration.
4067 (setq magit-diff-refine-hunk 'all
4068 magit-view-git-manual-method 'man
4069 magit-log-margin '(nil age magit-log-margin-width t 18)
4070 magit-wip-after-save-local-mode-lighter ""
4071 magit-wip-after-apply-mode-lighter ""
4072 magit-wip-before-change-mode-lighter "")
4073 (eval-after-load "magit"
4074 '(progn (global-magit-file-mode 1)
4075 (magit-wip-after-save-mode 1)
4076 (magit-wip-after-apply-mode 1)
4077 (magit-wip-before-change-mode 1)
4078 (add-to-list 'magit-no-confirm 'safe-with-wip)
4079 (add-to-list 'magit-no-confirm 'trash)
4080 (push '(:eval (if (or magit-wip-after-save-local-mode
4081 magit-wip-after-apply-mode
4082 magit-wip-before-change-mode)
4083 (format " wip:%s%s%s"
4084 (if magit-wip-after-apply-mode "A" "")
4085 (if magit-wip-before-change-mode "C" "")
4086 (if magit-wip-after-save-local-mode "S" ""))))
4088 (dolist (popup '(magit-diff-popup
4089 magit-diff-refresh-popup
4090 magit-diff-mode-refresh-popup
4091 magit-revision-mode-refresh-popup))
4092 (magit-define-popup-switch popup ?R "Reverse diff" "-R"))))
4094 (defadvice magit-wip-commit-buffer-file
4095 (around mdw-just-this-buffer activate compile)
4096 (let ((magit-save-repository-buffers nil)) ad-do-it))
4098 (defadvice magit-discard
4099 (around mdw-delete-if-prefix-argument activate compile)
4100 (let ((magit-delete-by-moving-to-trash
4101 (and (null current-prefix-arg)
4102 magit-delete-by-moving-to-trash)))
4105 (setq magit-repolist-columns
4106 '(("Name" 16 magit-repolist-column-ident nil)
4107 ("Version" 18 magit-repolist-column-version nil)
4108 ("St" 2 magit-repolist-column-dirty nil)
4109 ("L<U" 3 mdw-repolist-column-unpulled-from-upstream nil)
4110 ("L>U" 3 mdw-repolist-column-unpushed-to-upstream nil)
4111 ("Path" 32 magit-repolist-column-path nil)))
4113 (setq magit-repository-directories '(("~/etc/profile" . 0)
4116 (defadvice magit-list-repos (around mdw-dirname () activate compile)
4117 "Make sure the returned names are directory names.
4118 Otherwise child processes get started in the wrong directory and
4120 (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it)))
4122 (defun mdw-repolist-column-unpulled-from-upstream (_id)
4123 "Insert number of upstream commits not in the current branch."
4124 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
4126 (let ((n (cadr (magit-rev-diff-count "HEAD" upstream))))
4127 (propertize (number-to-string n) 'face
4128 (if (> n 0) 'bold 'shadow))))))
4130 (defun mdw-repolist-column-unpushed-to-upstream (_id)
4131 "Insert number of commits in the current branch but not its upstream."
4132 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
4134 (let ((n (car (magit-rev-diff-count "HEAD" upstream))))
4135 (propertize (number-to-string n) 'face
4136 (if (> n 0) 'bold 'shadow))))))
4138 (defun mdw-try-smerge ()
4140 (goto-char (point-min))
4141 (when (re-search-forward "^<<<<<<< " nil t)
4143 (add-hook 'find-file-hook 'mdw-try-smerge t)
4145 ;;;--------------------------------------------------------------------------
4146 ;;; GUD, and especially GDB.
4148 ;; Inhibit window dedication. I mean, seriously, wtf?
4149 (defadvice gdb-display-buffer (after mdw-undedicated (buf) compile activate)
4150 "Don't make windows dedicated. Seriously."
4151 (set-window-dedicated-p ad-return-value nil))
4152 (defadvice gdb-set-window-buffer
4153 (after mdw-undedicated (name &optional ignore-dedicated window)
4155 "Don't make windows dedicated. Seriously."
4156 (set-window-dedicated-p (or window (selected-window)) nil))
4158 ;;;--------------------------------------------------------------------------
4159 ;;; MPC configuration.
4161 (eval-when-compile (trap (require 'mpc)))
4163 (setq mpc-browser-tags '(Artist|Composer|Performer Album|Playlist))
4165 (defun mdw-mpc-now-playing ()
4169 (set-buffer (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))))
4170 (mpc--status-callback))
4171 (let ((state (cdr (assq 'state mpc-status))))
4172 (cond ((member state '("stop"))
4173 (message "mpd stopped."))
4174 ((member state '("play" "pause"))
4175 (let* ((artist (cdr (assq 'Artist mpc-status)))
4176 (album (cdr (assq 'Album mpc-status)))
4177 (title (cdr (assq 'Title mpc-status)))
4178 (file (cdr (assq 'file mpc-status)))
4179 (duration-string (cdr (assq 'Time mpc-status)))
4180 (time-string (cdr (assq 'time mpc-status)))
4181 (time (and time-string
4183 (if (string-match ":" time-string)
4184 (substring time-string
4185 0 (match-beginning 0))
4187 (duration (and duration-string
4188 (string-to-number duration-string)))
4189 (pos (and time duration
4190 (format " [%d:%02d/%d:%02d]"
4191 (/ time 60) (mod time 60)
4192 (/ duration 60) (mod duration 60))))
4193 (fmt (cond ((and artist title)
4194 (format "`%s' by %s%s" title artist
4195 (if album (format ", from `%s'" album)
4198 (format "`%s' (no tags)" file))
4200 "(no idea what's playing!)"))))
4201 (if (string= state "play")
4202 (message "mpd playing %s%s" fmt (or pos ""))
4203 (message "mpd paused in %s%s" fmt (or pos "")))))
4205 (message "mpd in unknown state `%s'" state)))))
4207 (defmacro mdw-define-mpc-wrapper (func bvl interactive &rest body)
4209 (interactive ,@interactive)
4212 (mdw-mpc-now-playing)))
4214 (mdw-define-mpc-wrapper mdw-mpc-play-or-pause () nil
4215 (if (member (cdr (assq 'state (mpc-cmd-status))) '("play"))
4219 (mdw-define-mpc-wrapper mdw-mpc-next () nil (mpc-next))
4220 (mdw-define-mpc-wrapper mdw-mpc-prev () nil (mpc-prev))
4221 (mdw-define-mpc-wrapper mdw-mpc-stop () nil (mpc-stop))
4223 (defun mdw-mpc-louder (step)
4224 (interactive (list (if current-prefix-arg
4225 (prefix-numeric-value current-prefix-arg)
4227 (mpc-proc-cmd (format "volume %+d" step)))
4229 (defun mdw-mpc-quieter (step)
4230 (interactive (list (if current-prefix-arg
4231 (prefix-numeric-value current-prefix-arg)
4233 (mpc-proc-cmd (format "volume %+d" (- step))))
4235 (defun mdw-mpc-hack-lines (arg interactivep func)
4236 (if (and interactivep (use-region-p))
4237 (let ((from (region-beginning)) (to (region-end)))
4242 (while (< (point) to)
4245 (let ((n (prefix-numeric-value arg)))
4262 (defun mdw-mpc-select-one ()
4263 (when (and (get-char-property (point) 'mpc-file)
4264 (not (get-char-property (point) 'mpc-select)))
4265 (mpc-select-toggle)))
4267 (defun mdw-mpc-unselect-one ()
4268 (when (get-char-property (point) 'mpc-select)
4269 (mpc-select-toggle)))
4271 (defun mdw-mpc-select (&optional arg interactivep)
4272 (interactive (list current-prefix-arg t))
4273 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4275 (defun mdw-mpc-unselect (&optional arg interactivep)
4276 (interactive (list current-prefix-arg t))
4277 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one))
4279 (defun mdw-mpc-unselect-backwards (arg)
4281 (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one))
4283 (defun mdw-mpc-unselect-all ()
4285 (setq mpc-select nil)
4286 (mpc-selection-refresh))
4288 (defun mdw-mpc-next-line (arg)
4293 (defun mdw-mpc-previous-line (arg)
4296 (forward-line (- arg)))
4298 (defun mdw-mpc-playlist-add (&optional arg interactivep)
4299 (interactive (list current-prefix-arg t))
4300 (let ((mpc-select mpc-select))
4301 (when (or arg (and interactivep (use-region-p)))
4302 (setq mpc-select nil)
4303 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4304 (setq mpc-select (reverse mpc-select))
4305 (mpc-playlist-add)))
4307 (defun mdw-mpc-playlist-delete (&optional arg interactivep)
4308 (interactive (list current-prefix-arg t))
4309 (setq mpc-select (nreverse mpc-select))
4311 (when (or arg (and interactivep (use-region-p)))
4312 (setq mpc-select nil)
4313 (mpc-selection-refresh)
4314 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4315 (mpc-playlist-delete)))
4317 (defun mdw-mpc-hack-tagbrowsers ()
4318 (setq-local mode-line-format
4320 mode-line-frame-identification
4321 mode-line-buffer-identification)))
4322 (add-hook 'mpc-tagbrowser-mode-hook 'mdw-mpc-hack-tagbrowsers)
4324 (defun mdw-mpc-hack-songs ()
4325 (setq-local header-line-format
4326 ;; '("MPC " mpc-volume " " mpc-current-song)
4327 (list (propertize " " 'display '(space :align-to 0))
4328 ;; 'mpc-songs-format-description
4330 (let ((deactivate-mark) (hscroll (window-hscroll)))
4332 (mpc-format mpc-songs-format 'self hscroll)
4333 ;; That would be simpler than the hscroll handling in
4334 ;; mpc-format, but currently move-to-column does not
4335 ;; recognize :space display properties.
4336 ;; (move-to-column hscroll)
4337 ;; (delete-region (point-min) (point))
4338 (buffer-string)))))))
4339 (add-hook 'mpc-songs-mode-hook 'mdw-mpc-hack-songs)
4341 (eval-after-load "mpc"
4343 (define-key mpc-mode-map "m" 'mdw-mpc-select)
4344 (define-key mpc-mode-map "u" 'mdw-mpc-unselect)
4345 (define-key mpc-mode-map "\177" 'mdw-mpc-unselect-backwards)
4346 (define-key mpc-mode-map "\e\177" 'mdw-mpc-unselect-all)
4347 (define-key mpc-mode-map "n" 'mdw-mpc-next-line)
4348 (define-key mpc-mode-map "p" 'mdw-mpc-previous-line)
4349 (define-key mpc-mode-map "/" 'mpc-songs-search)
4350 (setq mpc-songs-mode-map (make-sparse-keymap))
4351 (set-keymap-parent mpc-songs-mode-map mpc-mode-map)
4352 (define-key mpc-songs-mode-map "l" 'mpc-playlist)
4353 (define-key mpc-songs-mode-map "+" 'mdw-mpc-playlist-add)
4354 (define-key mpc-songs-mode-map "-" 'mdw-mpc-playlist-delete)
4355 (define-key mpc-songs-mode-map "\r" 'mpc-songs-jump-to)))
4357 ;;;--------------------------------------------------------------------------
4358 ;;; Inferior Emacs Lisp.
4360 (setq comint-prompt-read-only t)
4362 (eval-after-load "comint"
4364 (define-key comint-mode-map "\C-w" 'comint-kill-region)
4365 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
4367 (eval-after-load "ielm"
4369 (define-key ielm-map "\C-w" 'comint-kill-region)
4370 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
4372 ;;;----- That's all, folks --------------------------------------------------
4374 (provide 'dot-emacs)