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.
28 "Customization for mdw's Emacs configuration."
31 (defun mdw-check-command-line-switch (switch)
32 (let ((probe nil) (next command-line-args) (found nil))
34 (cond ((string= (car next) switch)
36 (if probe (rplacd probe (cdr next))
37 (setq command-line-args (cdr next))))
40 (setq next (cdr next)))
43 (defvar mdw-fast-startup nil
44 "Whether .emacs should optimize for rapid startup.
45 This may be at the expense of cool features.")
46 (setq mdw-fast-startup
47 (mdw-check-command-line-switch "--mdw-fast-startup"))
49 (defvar mdw-splashy-startup nil
50 "Whether to show a splash screen and related frippery.")
51 (setq mdw-splashy-startup
52 (mdw-check-command-line-switch "--mdw-splashy-startup"))
54 ;;;--------------------------------------------------------------------------
55 ;;; Some general utilities.
58 (unless (fboundp 'make-regexp) (load "make-regexp"))
61 (defmacro mdw-regexps (&rest list)
62 "Turn a LIST of strings into a single regular expression at compile-time."
65 `',(make-regexp list))
68 "This is not the key sequence you're looking for."
70 (error "wrong button"))
72 (defun mdw-emacs-version-p (major &optional minor)
73 "Return non-nil if the running Emacs is at least version MAJOR.MINOR."
74 (or (> emacs-major-version major)
75 (and (= emacs-major-version major)
76 (>= emacs-minor-version (or minor 0)))))
78 (defun mdw-submode-p (mode parent)
79 "Return non-nil if MODE is indirectly derived from PARENT."
81 (while (cond ((eq mode parent) (setq answer t) nil)
82 (t (setq mode (get mode 'derived-mode-parent)))))
85 ;; Some error trapping.
87 ;; If individual bits of this file go tits-up, we don't particularly want
88 ;; the whole lot to stop right there and then, because it's bloody annoying.
91 (defmacro trap (&rest forms)
92 "Execute FORMS without allowing errors to propagate outside."
96 ,(if (cdr forms) (cons 'progn forms) (car forms))
97 (error (message "Error (trapped): %s in %s"
98 (error-message-string err)
101 ;; Configuration reading.
103 (defvar mdw-config nil)
104 (defun mdw-config (sym)
105 "Read the configuration variable named SYM."
108 (flet ((replace (what with)
109 (goto-char (point-min))
110 (while (re-search-forward what nil t)
111 (replace-match with t))))
113 (insert-file-contents "~/.mdw.conf")
114 (replace "^[ \t]*\\(#.*\\)?\n" "")
115 (replace (concat "^[ \t]*"
116 "\\([-a-zA-Z0-9_.]*\\)"
119 "[ \t]**\\(\n\\|$\\)")
121 (car (read-from-string
122 (concat "(" (buffer-string) ")")))))))
123 (cdr (assq sym mdw-config)))
125 ;; Width configuration.
127 (defcustom mdw-column-width
128 (string-to-number (or (mdw-config 'emacs-width) "77"))
129 "Width of Emacs columns."
131 (defcustom mdw-text-width mdw-column-width
132 "Expected width of text within columns."
136 ;; Local variables hacking.
138 (defun run-local-vars-mode-hook ()
139 "Run a hook for the major-mode after local variables have been processed."
140 (run-hooks (intern (concat (symbol-name major-mode)
141 "-local-variables-hook"))))
142 (add-hook 'hack-local-variables-hook 'run-local-vars-mode-hook)
144 ;; Set up the load path convincingly.
146 (dolist (dir (append (and (boundp 'debian-emacs-flavor)
147 (list (concat "/usr/share/"
148 (symbol-name debian-emacs-flavor)
150 (dolist (sub (directory-files dir t))
151 (when (and (file-accessible-directory-p sub)
152 (not (member sub load-path)))
153 (setq load-path (nconc load-path (list sub))))))
155 ;; Is an Emacs library available?
157 (defun library-exists-p (name)
158 "Return non-nil if NAME is an available library.
159 Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
160 load path. The non-nil value is the filename we found for the
162 (let ((path load-path) elt (foundp nil))
163 (while (and path (not foundp))
164 (setq elt (car path))
165 (setq path (cdr path))
166 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
167 (and (file-exists-p file) file))
168 (let ((file (concat elt "/" name ".el")))
169 (and (file-exists-p file) file)))))
172 (defun maybe-autoload (symbol file &optional docstring interactivep type)
173 "Set an autoload if the file actually exists."
174 (and (library-exists-p file)
175 (autoload symbol file docstring interactivep type)))
177 (defun mdw-kick-menu-bar (&optional frame)
178 "Regenerate FRAME's menu bar so it doesn't have empty menus."
180 (unless frame (setq frame (selected-frame)))
181 (let ((old (frame-parameter frame 'menu-bar-lines)))
182 (set-frame-parameter frame 'menu-bar-lines 0)
183 (set-frame-parameter frame 'menu-bar-lines old)))
187 (defun mdw-fixup-page-position ()
188 (unless (eq (char-before (point)) ?
\f)
191 (defadvice backward-page (after mdw-fixup compile activate)
192 (mdw-fixup-page-position))
193 (defadvice forward-page (after mdw-fixup compile activate)
194 (mdw-fixup-page-position))
196 ;; Splitting windows.
198 (unless (fboundp 'scroll-bar-columns)
199 (defun scroll-bar-columns (side)
200 (cond ((eq side 'left) 0)
203 (unless (fboundp 'fringe-columns)
204 (defun fringe-columns (side)
205 (cond ((not window-system) 0)
209 (defun mdw-horizontal-window-overhead ()
210 "Computes the horizontal window overhead.
211 This is the number of columns used by fringes, scroll bars and other such
213 (if (not window-system)
216 (dolist (what '(scroll-bar fringe))
217 (dolist (side '(left right))
218 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
222 (defun mdw-split-window-horizontally (&optional width)
223 "Split a window horizontally.
224 Without a numeric argument, split the window approximately in
225 half. With a numeric argument WIDTH, allocate WIDTH columns to
226 the left-hand window (if positive) or -WIDTH columns to the
227 right-hand window (if negative). Space for scroll bars and
228 fringes is not taken out of the allowance for WIDTH, unlike
229 \\[split-window-horizontally]."
231 (split-window-horizontally
232 (cond ((null width) nil)
233 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
234 ((< width 0) width))))
236 (defun mdw-preferred-column-width ()
237 "Return the preferred column width."
238 (if (and window-system (mdw-emacs-version-p 22)) mdw-column-width
239 (1+ mdw-column-width)))
241 (defun mdw-divvy-window (&optional width)
242 "Split a wide window into appropriate widths."
244 (setq width (if width (prefix-numeric-value width)
245 (mdw-preferred-column-width)))
246 (let* ((win (selected-window))
247 (sb-width (mdw-horizontal-window-overhead))
248 (c (/ (+ (window-width) sb-width)
249 (+ width sb-width))))
252 (split-window-horizontally (+ width sb-width))
254 (select-window win)))
256 (defun mdw-frame-width-for-columns (columns width)
257 "Return the preferred width for a frame with so many COLUMNS of WIDTH."
258 (let ((sb-width (mdw-horizontal-window-overhead)))
259 (- (* columns (+ width sb-width))
262 (defun mdw-set-frame-width (columns &optional width)
263 "Set the current frame to be the correct width for COLUMNS columns.
265 If WIDTH is non-nil, then it provides the width for the new columns. (This
266 can be set interactively with a prefix argument.)"
267 (interactive "nColumns:
269 (setq width (if width (prefix-numeric-value width)
270 (mdw-preferred-column-width)))
271 (set-frame-width (selected-frame)
272 (mdw-frame-width-for-columns columns width))
273 (mdw-divvy-window width))
275 (defcustom mdw-frame-width-fudge
276 (cond ((<= emacs-major-version 20) 1)
277 ((= emacs-major-version 26) 3)
279 "The number of extra columns to add to the desired frame width.
281 This is sadly necessary because Emacs 26 is broken in this regard."
284 (defcustom mdw-frame-colour-alist
285 '((black . ("#000000" . "#ffffff"))
286 (red . ("#2a0000" . "#ffffff"))
287 (green . ("#002a00" . "#ffffff"))
288 (blue . ("#00002a" . "#ffffff")))
289 "Alist mapping symbol names to (FOREGROUND . BACKGROUND) colour pairs."
290 :type '(alist :key-type symbol :value-type (cons color color)))
292 (defun mdw-set-frame-colour (colour &optional frame)
293 (interactive "xColour name or (FOREGROUND . BACKGROUND) pair:
295 (when (and colour (symbolp colour))
296 (let ((entry (assq colour mdw-frame-colour-alist)))
297 (unless entry (error "Unknown colour `%s'" colour))
298 (setf colour (cdr entry))))
299 (set-frame-parameter frame 'background-color (car colour))
300 (set-frame-parameter frame 'foreground-color (cdr colour)))
302 ;; Window configuration switching.
304 (defvar mdw-current-window-configuration nil
305 "The current window configuration register name, or `nil'.")
307 (defun mdw-switch-window-configuration (register &optional no-save)
308 "Switch make REGISTER be the new current window configuration.
309 If a current window configuration register is established, and
310 NO-SAVE is nil, then save the current window configuration to
313 Signal an error if the new register contains something other than
314 a window configuration. If the register is unset then save the
315 current window configuration to it immediately.
317 With one or three C-u, or an odd numeric prefix argument, set
318 NO-SAVE, so the previous window configuration register is left
321 With two or three C-u, or a prefix argument which is an odd
322 multiple of 2, just clear the record of the current window
323 configuration register, so that the next switch doesn't save the
324 prevailing configuration."
326 (let ((arg current-prefix-arg))
327 (list (if (or (and (consp arg) (= (car arg) 16) (= (car arg) 64))
328 (and (integerp arg) (not (zerop (logand arg 2)))))
330 (register-read-with-preview "Switch to window configuration: "))
331 (or (and (consp arg) (= (car arg) 4) (= (car arg) 64))
332 (and (integerp arg) (not (zerop (logand arg 1))))))))
334 (let ((previous mdw-current-window-configuration)
335 (current-windows (list (current-window-configuration)
337 (register-value (and register (get-register register))))
338 (when (and mdw-current-window-configuration (not no-save))
339 (set-register mdw-current-window-configuration current-windows))
340 (cond ((null register)
341 (setq mdw-current-window-configuration nil)
343 (message "Left window configuration `%c'." previous)
344 (message "Nothing to do!")))
345 ((not (or (null register-value)
346 (and (consp register-value)
347 (window-configuration-p (car register-value))
348 (integer-or-marker-p (cadr register-value))
349 (null (caddr register-value)))))
350 (error "Register `%c' is not a window configuration" register))
352 (cond ((null register-value)
353 (set-register register current-windows)
354 (message "Started new window configuration `%c'."
357 (set-window-configuration (car register-value))
358 (goto-char (cadr register-value))
359 (message "Switched to window configuration `%c'."
361 (setq mdw-current-window-configuration register)))))
363 ;; Don't raise windows unless I say so.
365 (defcustom mdw-inhibit-raise-frame nil
366 "Whether `raise-frame' should do nothing when the frame is mapped."
369 (defadvice raise-frame
370 (around mdw-inhibit (&optional frame) activate compile)
371 "Don't actually do anything if `mdw-inhibit-raise-frame' is true, and the
372 frame is actually mapped on the screen."
373 (if mdw-inhibit-raise-frame
374 (make-frame-visible frame)
377 (defmacro mdw-advise-to-inhibit-raise-frame (function)
378 "Advise the FUNCTION not to raise frames, even if it wants to."
379 `(defadvice ,function
380 (around mdw-inhibit-raise (&rest hunoz) activate compile)
381 "Don't raise the window unless you have to."
382 (let ((mdw-inhibit-raise-frame t))
385 (mdw-advise-to-inhibit-raise-frame select-frame-set-input-focus)
386 (mdw-advise-to-inhibit-raise-frame appt-disp-window)
387 (mdw-advise-to-inhibit-raise-frame mouse-select-window)
389 ;; Bug fix for markdown-mode, which breaks point positioning during
391 (defadvice markdown-check-change-for-wiki-link
392 (around mdw-save-match activate compile)
393 "Save match data around the `markdown-mode' `after-change-functions' hook."
394 (save-match-data ad-do-it))
396 ;; Bug fix for `bbdb-canonicalize-address': on Emacs 24, `run-hook-with-args'
397 ;; always returns nil, with the result that all email addresses are lost.
398 ;; Replace the function entirely.
399 (defadvice bbdb-canonicalize-address
400 (around mdw-bug-fix activate compile)
401 "Don't use `run-hook-with-args', because that doesn't work."
402 (let ((net (ad-get-arg 0)))
404 ;; Make sure this is a proper hook list.
405 (if (functionp bbdb-canonicalize-net-hook)
406 (setq bbdb-canonicalize-net-hook (list bbdb-canonicalize-net-hook)))
408 ;; Iterate over the hooks until things converge.
411 (let (next (changep nil)
412 hook (hooks bbdb-canonicalize-net-hook))
414 (setq hook (pop hooks))
415 (setq next (funcall hook net))
416 (if (not (equal next net))
419 (setq donep (not changep)))))
420 (setq ad-return-value net)))
422 ;; Transient mark mode hacks.
424 (defadvice exchange-point-and-mark
425 (around mdw-highlight (&optional arg) activate compile)
426 "Maybe don't actually exchange point and mark.
427 If `transient-mark-mode' is on and the mark is inactive, then
428 just activate it. A non-trivial prefix argument will force the
429 usual behaviour. A trivial prefix argument (i.e., just C-u) will
430 activate the mark and temporarily enable `transient-mark-mode' if
432 (cond ((or mark-active
433 (and (not transient-mark-mode) (not arg))
434 (and arg (or (not (consp arg))
435 (not (= (car arg) 4)))))
438 (or transient-mark-mode (setq transient-mark-mode 'only))
439 (set-mark (mark t)))))
441 ;; Functions for sexp diary entries.
443 (defvar mdw-diary-for-org-mode-p nil
444 "Display diary along with the agenda?")
446 (defun mdw-not-org-mode (form)
447 "As FORM, but not in Org mode agenda."
448 (and (not mdw-diary-for-org-mode-p)
451 (defun mdw-weekday (l)
452 "Return non-nil if `date' falls on one of the days of the week in L.
453 L is a list of day numbers (from 0 to 6 for Sunday through to
454 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
455 the date stored in `date' falls on a listed day, then the
456 function returns non-nil."
457 (let ((d (calendar-day-of-week date)))
459 (memq (nth d '(sunday monday tuesday wednesday
460 thursday friday saturday)) l))))
462 (defun mdw-discordian-date (date)
463 "Return the Discordian calendar date corresponding to DATE.
465 The return value is (YOLD . st-tibs-day) or (YOLD SEASON DAYNUM DOW).
467 The original is by David Pearson. I modified it to produce date components
468 as output rather than a string."
469 (let* ((days ["Sweetmorn" "Boomtime" "Pungenday"
470 "Prickle-Prickle" "Setting Orange"])
471 (months ["Chaos" "Discord" "Confusion"
472 "Bureaucracy" "Aftermath"])
473 (day-count [0 31 59 90 120 151 181 212 243 273 304 334])
474 (year (- (calendar-extract-year date) 1900))
475 (month (1- (calendar-extract-month date)))
476 (day (1- (calendar-extract-day date)))
477 (julian (+ (aref day-count month) day))
478 (dyear (+ year 3066)))
479 (if (and (= month 1) (= day 28))
480 (cons dyear 'st-tibs-day)
482 (aref months (floor (/ julian 73)))
484 (aref days (mod julian 5))))))
486 (defun mdw-diary-discordian-date ()
487 "Convert the date in `date' to a string giving the Discordian date."
488 (let* ((ddate (mdw-discordian-date date))
489 (tail (format "in the YOLD %d" (car ddate))))
490 (if (eq (cdr ddate) 'st-tibs-day)
491 (format "St Tib's Day %s" tail)
492 (let ((season (cadr ddate))
493 (daynum (caddr ddate))
494 (dayname (cadddr ddate)))
495 (format "%s, the %d%s day of %s %s"
498 (let ((ldig (mod daynum 10)))
499 (cond ((= ldig 1) "st")
506 (defun mdw-todo (&optional when)
507 "Return non-nil today, or on WHEN, whichever is later."
508 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
509 (d (calendar-absolute-from-gregorian date)))
511 (setq w (max w (calendar-absolute-from-gregorian
513 ((not european-calendar-style)
525 (defadvice org-agenda-list (around mdw-preserve-links activate)
526 (let ((mdw-diary-for-org-mode-p t))
529 (defcustom diary-time-regexp nil
530 "Regexp matching times in the diary buffer."
533 (defadvice diary-add-to-list (before mdw-trim-leading-space compile activate)
534 "Trim leading space from the diary entry string."
536 (let ((str (ad-get-arg 1))
540 (setq str (cond ((null str) nil)
541 ((string-match "\\(^\\|\n\\)[ \t]+" str)
542 (replace-match "\\1" nil nil str))
543 ((and mdw-diary-for-org-mode-p
544 (string-match (concat
546 "\\(" diary-time-regexp
547 "\\(-" diary-time-regexp "\\)?"
549 "\\(\t[ \t]*\\| [ \t]+\\)")
551 (replace-match "\\1\\2 " nil nil str))
552 ((and (not mdw-diary-for-org-mode-p)
553 (string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]"
555 (replace-match "\\1" nil nil str))
557 (if (equal str old) (setq done t)))
558 (ad-set-arg 1 str))))
560 (defadvice org-bbdb-anniversaries (after mdw-fixup-list compile activate)
561 "Return a string rather than a list."
564 (dolist (e (let ((ee ad-return-value))
565 (if (atom ee) (list ee) ee)))
567 (when anyp (insert ?\n))
570 (setq ad-return-value
571 (and anyp (buffer-string))))))
573 ;; Fighting with Org-mode's evil key maps.
575 (defcustom mdw-evil-keymap-keys
576 '(([S-up] . [?\C-c up])
577 ([S-down] . [?\C-c down])
578 ([S-left] . [?\C-c left])
579 ([S-right] . [?\C-c right])
580 (([M-up] [?\e up]) . [C-up])
581 (([M-down] [?\e down]) . [C-down])
582 (([M-left] [?\e left]) . [C-left])
583 (([M-right] [?\e right]) . [C-right]))
584 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
585 The value is an alist mapping evil keys (as a list, or singleton)
586 to good keys (in the same form)."
587 :type '(alist :key-type (choice key-sequence (repeat key-sequence))
588 :value-type key-sequence))
590 (defun mdw-clobber-evil-keymap (keymap)
591 "Replace evil key bindings in the KEYMAP.
592 Evil key bindings are defined in `mdw-evil-keymap-keys'."
593 (dolist (entry mdw-evil-keymap-keys)
595 (keys (if (listp (car entry))
598 (replacements (if (listp (cdr entry))
600 (list (cdr entry)))))
603 (setq binding (lookup-key keymap key))
605 (throw 'found nil))))
608 (define-key keymap key nil))
609 (dolist (key replacements)
610 (define-key keymap key binding))))))
612 (defcustom mdw-org-latex-defs
614 "\\documentclass{strayman}
615 \\usepackage[utf8]{inputenc}
616 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
617 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
618 ("\\section{%s}" . "\\section*{%s}")
619 ("\\subsection{%s}" . "\\subsection*{%s}")
620 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
621 ("\\paragraph{%s}" . "\\paragraph*{%s}")
622 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
623 "Additional LaTeX class definitions."
624 :type '(alist :key-type string
625 :value-type (list string
628 :value-type string))))
630 (eval-after-load "org-latex"
631 '(setq org-export-latex-classes
632 (append mdw-org-latex-defs org-export-latex-classes)))
634 (eval-after-load "ox-latex"
635 '(setq org-latex-classes (append mdw-org-latex-defs org-latex-classes)
636 org-latex-caption-above nil
637 org-latex-default-packages-alist '(("AUTO" "inputenc" t)
645 ("normalem" "ulem" t)
651 "\\tolerance=1000")))
654 (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
655 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
656 org-export-docbook-xslt-stylesheet
657 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
661 (setq glasses-separator "-"
662 glasses-separate-parentheses-p nil
663 glasses-uncapitalize-p t)
665 ;; Some hacks to do with window placement.
667 (defvar mdw-designated-window nil
668 "The window chosen by `mdw-designate-window', or nil.")
670 (defun mdw-designated-window-display-buffer-function (buffer not-this-window)
671 "Display buffer function to use the designated window."
672 (unless mdw-designated-window (error "No designated window!"))
673 (prog1 mdw-designated-window
674 (with-selected-window mdw-designated-window (switch-to-buffer buffer))
675 (setq mdw-designated-window nil
676 display-buffer-function nil)))
678 (defun mdw-display-buffer-in-designated-window (buffer alist)
679 "Display function to use the designated window."
680 (prog1 mdw-designated-window
681 (when mdw-designated-window
682 (with-selected-window mdw-designated-window
683 (switch-to-buffer buffer nil t)))
684 (setq mdw-designated-window nil)))
686 (defun mdw-designate-window (cancel)
687 "Use the selected window for the next pop-up buffer.
688 With a prefix argument, clear the designated window."
690 (let ((window (selected-window)))
692 (setq mdw-designated-window nil)
693 (unless (mdw-emacs-version-p 24)
694 (setq display-buffer-function nil))
695 (message "Window designation cleared."))
696 ((window-dedicated-p window)
697 (error "Window is dedicated to its buffer."))
699 (setq mdw-designated-window window)
700 (unless (mdw-emacs-version-p 24)
701 (setq display-buffer-function
702 #'mdw-designated-window-display-buffer-function))
703 (message "Window designated.")))))
705 (when (mdw-emacs-version-p 24)
706 (setq display-buffer-base-action
707 (let* ((action display-buffer-base-action)
709 (alist (cdr action)))
710 (cons (cons 'mdw-display-buffer-in-designated-window funcs)
713 (defun mdw-clobber-other-windows-showing-buffer (buffer-or-name)
714 "Arrange that no windows on other frames are showing BUFFER-OR-NAME."
715 (interactive "bBuffer: ")
716 (let ((home-frame (selected-frame))
717 (buffer (get-buffer buffer-or-name))
718 (safe-buffer (get-buffer "*scratch*")))
719 (dolist (frame (frame-list))
720 (unless (eq frame home-frame)
721 (dolist (window (window-list frame))
722 (when (eq (window-buffer window) buffer)
723 (set-window-buffer window safe-buffer)))))))
725 (defvar mdw-inhibit-walk-windows nil
726 "If non-nil, then `walk-windows' does nothing.
727 This is used by advice on `switch-to-buffer-other-frame' to inhibit finding
728 buffers in random frames.")
730 (setq display-buffer--other-frame-action
731 '((display-buffer-reuse-window display-buffer-pop-up-frame)
732 (reusable-frames . nil)
733 (inhibit-same-window . t)))
735 (defadvice walk-windows (around mdw-inhibit activate)
736 "If `mdw-inhibit-walk-windows' is non-nil, then do nothing."
737 (and (not mdw-inhibit-walk-windows)
740 (defadvice switch-to-buffer-other-frame
741 (around mdw-always-new-frame activate)
742 "Always make a new frame.
743 Even if an existing window in some random frame looks tempting."
744 (let ((mdw-inhibit-walk-windows t)) ad-do-it))
746 (defadvice display-buffer (before mdw-inhibit-other-frames activate)
747 "Don't try to do anything fancy with other frames.
748 Pretend they don't exist. They might be on other display devices."
751 (setq even-window-sizes nil
752 even-window-heights nil)
754 (setq display-buffer-reuse-frames nil)
756 ;; Rename buffers along with files.
758 (defvar mdw-inhibit-rename-buffer nil
759 "If non-nil, `rename-file' won't rename the buffer visiting the file.")
761 (defmacro mdw-advise-to-inhibit-rename-buffer (function)
762 "Advise FUNCTION to set `mdw-inhibit-rename-buffer' while it runs.
764 This will prevent `rename-file' from renaming the buffer."
765 `(defadvice ,function (around mdw-inhibit-rename-buffer compile activate)
766 "Don't rename the buffer when renaming the underlying file."
767 (let ((mdw-inhibit-rename-buffer t))
769 (mdw-advise-to-inhibit-rename-buffer recode-file-name)
770 (mdw-advise-to-inhibit-rename-buffer set-visited-file-name)
771 (mdw-advise-to-inhibit-rename-buffer backup-buffer)
773 (defadvice rename-file (after mdw-rename-buffers (from to &optional forcep)
775 "If a buffer is visiting the file, rename it to match the new name.
777 Don't do this if `mdw-inhibit-rename-buffer' is non-nil."
778 (unless mdw-inhibit-rename-buffer
779 (let ((buffer (get-file-buffer from)))
781 (let ((to (if (not (string= (file-name-nondirectory to) "")) to
782 (concat to (file-name-nondirectory from)))))
783 (with-current-buffer buffer
784 (set-visited-file-name to nil t)))))))
786 ;;;--------------------------------------------------------------------------
787 ;;; Improved compilation machinery.
789 ;; Uprated version of M-x compile.
791 (setq compile-command
792 (let ((ncpu (with-temp-buffer
793 (insert-file-contents "/proc/cpuinfo")
795 (count-matches "^processor\\s-*:"))))
796 (format "nice make -j%d -k" (* 2 ncpu))))
798 (defun mdw-compilation-buffer-name (mode)
799 (concat "*" (downcase mode) ": "
800 (abbreviate-file-name default-directory) "*"))
801 (setq compilation-buffer-name-function 'mdw-compilation-buffer-name)
803 (eval-after-load "compile"
805 (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile)))
807 (defadvice compile (around hack-environment compile activate)
808 "Hack the environment inherited by inferiors in the compilation."
809 (let ((process-environment (copy-tree process-environment)))
810 (setenv "LD_PRELOAD" nil)
813 (defun mdw-compile (command &optional directory comint)
814 "Initiate a compilation COMMAND, maybe in a different DIRECTORY.
815 The DIRECTORY may be nil to not change. If COMINT is t, then
816 start an interactive compilation.
818 Interactively, prompt for the command if the variable
819 `compilation-read-command' is non-nil, or if requested through
820 the prefix argument. Prompt for the directory, and run
821 interactively, if requested through the prefix.
823 Use a prefix of 4, 6, 12, or 14, or type C-u between one and three times, to
824 force prompting for a directory.
826 Use a prefix of 2, 6, 10, or 14, or type C-u three times, to force
827 prompting for the command.
829 Use a prefix of 8, 10, 12, or 14, or type C-u twice or three times,
830 to force interactive compilation."
832 (let* ((prefix (prefix-numeric-value current-prefix-arg))
833 (command (eval compile-command))
834 (dir (and (plusp (logand prefix #x54))
835 (read-directory-name "Compile in directory: "))))
836 (list (if (or compilation-read-command
837 (plusp (logand prefix #x42)))
838 (compilation-read-command command)
841 (plusp (logand prefix #x58)))))
842 (let ((default-directory (or directory default-directory)))
843 (compile command comint)))
847 (defun mdw-find-build-dir (build-file)
849 (let* ((src-dir (file-name-as-directory (expand-file-name ".")))
852 (when (file-exists-p (concat dir build-file))
854 (let ((sub (expand-file-name (file-relative-name src-dir dir)
855 (concat dir "build/"))))
858 (when (file-exists-p (concat sub build-file))
860 (when (string= sub dir) (throw 'give-up nil))
861 (setq sub (file-name-directory (directory-file-name sub))))))
863 (setq dir (file-name-directory
864 (directory-file-name dir))))
865 (throw 'found nil))))))
867 (defun mdw-flymake-make-init ()
868 (let ((build-dir (mdw-find-build-dir "Makefile")))
870 (let ((tmp-src (flymake-init-create-temp-buffer-copy
871 #'flymake-create-temp-inplace)))
872 (flymake-get-syntax-check-program-args
873 tmp-src build-dir t t
874 #'flymake-get-make-cmdline)))))
876 (setq flymake-allowed-file-name-masks
877 '(("\\.\\(?:[cC]\\|cc\\|cpp\\|cxx\\|c\\+\\+\\)\\'"
878 mdw-flymake-make-init)
879 ("\\.\\(?:[hH]\\|hh\\|hpp\\|hxx\\|h\\+\\+\\)\\'"
880 mdw-flymake-master-make-init)
881 ("\\.p[lm]" flymake-perl-init)))
883 (setq flymake-mode-map
884 (let ((map (if (boundp 'flymake-mode-map)
886 (make-sparse-keymap))))
887 (define-key map [?\C-c ?\C-f ?\C-p] 'flymake-goto-prev-error)
888 (define-key map [?\C-c ?\C-f ?\C-n] 'flymake-goto-next-error)
889 (define-key map [?\C-c ?\C-f ?\C-c] 'flymake-compile)
890 (define-key map [?\C-c ?\C-f ?\C-k] 'flymake-stop-all-syntax-checks)
891 (define-key map [?\C-c ?\C-f ?\C-e] 'flymake-popup-current-error-menu)
894 ;;;--------------------------------------------------------------------------
895 ;;; Mail and news hacking.
897 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
898 "Major mode for editing news and mail messages from external programs.
899 Not much right now. Just support for doing MailCrypt stuff."
902 (run-hooks 'mail-setup-hook))
904 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
906 (add-hook 'mdwail-mode-hook
908 (set-buffer-file-coding-system 'utf-8)
909 (make-local-variable 'paragraph-separate)
910 (make-local-variable 'paragraph-start)
911 (setq paragraph-start
912 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
914 (setq paragraph-separate
915 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
916 paragraph-separate))))
918 ;; How to encrypt in mdwmail.
920 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
922 (setq start (save-excursion
923 (goto-char (point-min))
924 (or (search-forward "\n\n" nil t) (point-min)))))
926 (setq end (point-max)))
927 (mc-encrypt-generic recip scm start end from sign))
929 ;; How to sign in mdwmail.
931 (defun mdwmail-mc-sign (key scm start end uclr)
933 (setq start (save-excursion
934 (goto-char (point-min))
935 (or (search-forward "\n\n" nil t) (point-min)))))
937 (setq end (point-max)))
938 (mc-sign-generic key scm start end uclr))
940 ;; Some signature mangling.
942 (defun mdwmail-mangle-signature ()
944 (goto-char (point-min))
945 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
946 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
947 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
949 ;; Insert my login name into message-ids, so I can score replies.
951 (defadvice message-unique-id (after mdw-user-name last activate compile)
952 "Ensure that the user's name appears at the end of the message-id string,
953 so that it can be used for convenient filtering."
954 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
956 ;; Tell my movemail hack where movemail is.
958 ;; This is needed to shup up warnings about LD_PRELOAD.
960 (let ((path exec-path))
962 (let ((try (expand-file-name "movemail" (car path))))
963 (if (file-executable-p try)
964 (setenv "REAL_MOVEMAIL" try))
965 (setq path (cdr path)))))
967 ;; AUTHINFO GENERIC kludge.
969 (defcustom nntp-authinfo-generic nil
970 "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'.
972 Use this to arrange for per-server settings."
973 :type '(choice (const :tag "Use `NNTPAUTH' environment variable" nil)
977 (defun nntp-open-authinfo-kludge (buffer)
978 "Open a connection to SERVER using `authinfo-kludge'."
979 (let ((proc (start-process "nntpd" buffer
980 "env" (concat "NNTPAUTH="
981 (or nntp-authinfo-generic
983 (error "NNTPAUTH unset")))
984 "authinfo-kludge" nntp-address)))
986 (nntp-wait-for-string "^\r*200")
988 (delete-region (point-min) (point))
991 (eval-after-load "erc"
992 '(load "~/.ercrc.el"))
994 ;; Heavy-duty Gnus patching.
996 (defun mdw-nnimap-transform-headers ()
997 (goto-char (point-min))
998 (let (article lines size string)
1001 (while (not (looking-at "\\* [0-9]+ FETCH"))
1002 (delete-region (point) (progn (forward-line 1) (point)))
1005 (goto-char (match-end 0))
1006 ;; Unfold quoted {number} strings.
1007 (while (re-search-forward
1008 "[^]][ (]{\\([0-9]+\\)}\r?\n"
1010 ;; Start of the header section.
1011 (or (re-search-forward "] {[0-9]+}\r?\n" nil t)
1012 ;; Start of the next FETCH.
1013 (re-search-forward "\\* [0-9]+ FETCH" nil t)
1016 (setq size (string-to-number (match-string 1)))
1017 (delete-region (+ (match-beginning 0) 2) (point))
1018 (setq string (buffer-substring (point) (+ (point) size)))
1019 (delete-region (point) (+ (point) size))
1020 (insert (format "%S" (subst-char-in-string ?\n ?\s string)))
1021 ;; [mdw] missing from upstream
1025 (and (re-search-forward "UID \\([0-9]+\\)"
1031 (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)"
1036 (when (search-forward "BODYSTRUCTURE" (line-end-position) t)
1037 (let ((structure (ignore-errors
1038 (read (current-buffer)))))
1039 (while (and (consp structure)
1040 (not (atom (car structure))))
1041 (setq structure (car structure)))
1042 (setq lines (if (and
1043 (stringp (car structure))
1044 (equal (upcase (nth 0 structure)) "MESSAGE")
1045 (equal (upcase (nth 1 structure)) "RFC822"))
1047 (nth 7 structure)))))
1048 (delete-region (line-beginning-position) (line-end-position))
1049 (insert (format "211 %s Article retrieved." article))
1052 (insert (format "Chars: %s\n" size)))
1054 (insert (format "Lines: %s\n" lines)))
1055 ;; Most servers have a blank line after the headers, but
1057 (unless (re-search-forward "^\r$\\|^)\r?$" nil t)
1058 (goto-char (point-max)))
1059 (delete-region (line-beginning-position) (line-end-position))
1061 (forward-line 1)))))
1063 (eval-after-load 'nnimap
1064 '(defalias 'nnimap-transform-headers
1065 (symbol-function 'mdw-nnimap-transform-headers)))
1067 (defadvice gnus-other-frame (around mdw-hack-frame-width compile activate)
1068 "Always arrange for mail/news frames to be 80 columns wide."
1069 (let ((default-frame-alist (cons `(width . ,(+ 80 mdw-frame-width-fudge))
1070 (delete* 'width default-frame-alist
1074 ;; Preferred programs.
1076 (setq mailcap-user-mime-data
1077 '(((type . "application/pdf") (viewer . "mupdf %s"))))
1079 ;;;--------------------------------------------------------------------------
1080 ;;; Utility functions.
1082 (or (fboundp 'line-number-at-pos)
1083 (defun line-number-at-pos (&optional pos)
1084 (let ((opoint (or pos (point))) start)
1087 (goto-char (point-min))
1090 (setq start (point))
1093 (1+ (count-lines 1 (point))))))))
1095 (defun mdw-uniquify-alist (&rest alists)
1096 "Return the concatenation of the ALISTS with duplicate elements removed.
1097 The first association with a given key prevails; others are
1098 ignored. The input lists are not modified, although they'll
1099 probably become garbage."
1101 (let ((start-list (cons nil nil)))
1102 (mdw-do-uniquify start-list
1107 (defun mdw-do-uniquify (done end l rest)
1108 "A helper function for mdw-uniquify-alist.
1109 The DONE argument is a list whose first element is `nil'. It
1110 contains the uniquified alist built so far. The leading `nil' is
1111 stripped off at the end of the operation; it's only there so that
1112 DONE always references a cons cell. END refers to the final cons
1113 cell in the DONE list; it is modified in place each time to avoid
1114 the overheads of `append'ing all the time. The L argument is the
1115 alist we're currently processing; the remaining alists are given
1118 ;; There are several different cases to deal with here.
1121 ;; Current list isn't empty. Add the first item to the DONE list if
1122 ;; there's not an item with the same KEY already there.
1123 (l (or (assoc (car (car l)) done)
1125 (setcdr end (cons (car l) nil))
1126 (setq end (cdr end))))
1127 (mdw-do-uniquify done end (cdr l) rest))
1129 ;; The list we were working on is empty. Shunt the next list into the
1130 ;; current list position and go round again.
1131 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
1133 ;; Everything's done. Remove the leading `nil' from the DONE list and
1134 ;; return it. Finished!
1138 "Insert the current date in a pleasing way."
1140 (insert (save-excursion
1141 (let ((buffer (get-buffer-create "*tmp*")))
1142 (unwind-protect (progn (set-buffer buffer)
1144 (shell-command "date +%Y-%m-%d" t)
1148 (kill-buffer buffer))))))
1150 (defun uuencode (file &optional name)
1151 "UUencodes a file, maybe calling it NAME, into the current buffer."
1152 (interactive "fInput file name: ")
1154 ;; If NAME isn't specified, then guess from the filename.
1158 (or (string-match "[^/]*$" file) 0))))
1159 (print (format "uuencode `%s' `%s'" file name))
1161 ;; Now actually do the thing.
1162 (call-process "uuencode" file t nil name))
1164 (defcustom np-file "~/.np"
1165 "Where the `now-playing' file is."
1169 (defun np (&optional arg)
1170 "Grabs a `now-playing' string."
1174 (goto-char (point-max))
1176 (insert-file-contents np-file)))))
1178 (defun mdw-version-< (ver-a ver-b)
1179 "Answer whether VER-A is strictly earlier than VER-B.
1180 VER-A and VER-B are version numbers, which are strings containing digit
1181 sequences separated by `.'."
1182 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
1183 (split-string ver-a "\\.")))
1184 (lb (mapcar (lambda (x) (car (read-from-string x)))
1185 (split-string ver-b "\\."))))
1188 (cond ((null la) (throw 'done lb))
1189 ((null lb) (throw 'done nil))
1190 ((< (car la) (car lb)) (throw 'done t))
1191 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))
1192 (t (throw 'done nil)))))))
1194 (defun mdw-check-autorevert ()
1195 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
1196 This takes into consideration whether it's been found using
1197 tramp, which seems to get itself into a twist."
1198 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
1200 ((and (buffer-file-name)
1201 (fboundp 'tramp-tramp-file-p)
1202 (tramp-tramp-file-p (buffer-file-name)))
1203 (unless global-auto-revert-ignore-buffer
1204 (setq global-auto-revert-ignore-buffer 'tramp)))
1205 ((eq global-auto-revert-ignore-buffer 'tramp)
1206 (setq global-auto-revert-ignore-buffer nil))))
1208 (defadvice find-file (after mdw-autorevert activate)
1209 (mdw-check-autorevert))
1210 (defadvice write-file (after mdw-autorevert activate)
1211 (mdw-check-autorevert))
1213 (defun mdw-auto-revert ()
1214 "Recheck all of the autorevertable buffers, and update VC modelines."
1216 (let ((auto-revert-check-vc-info t))
1217 (auto-revert-buffers)))
1219 ;;;--------------------------------------------------------------------------
1222 (defadvice dired-maybe-insert-subdir
1223 (around mdw-marked-insertion first activate)
1224 "The DIRNAME may be a list of directory names to insert.
1225 Interactively, if files are marked, then insert all of them.
1226 With a numeric prefix argument, select that many entries near
1227 point; with a non-numeric prefix argument, prompt for listing
1230 (list (dired-get-marked-files nil
1231 (and (integerp current-prefix-arg)
1234 (and current-prefix-arg
1235 (not (integerp current-prefix-arg))
1236 (read-string "Switches for listing: "
1237 (or dired-subdir-switches
1238 dired-actual-switches)))))
1239 (let ((dirs (ad-get-arg 0)))
1240 (dolist (dir (if (listp dirs) dirs (list dirs)))
1244 (defun mdw-dired-run (args &optional syncp)
1245 (interactive (let ((file (dired-get-filename t)))
1246 (list (read-string (format "Arguments for %s: " file))
1247 current-prefix-arg)))
1248 (funcall (if syncp 'shell-command 'async-shell-command)
1249 (concat (shell-quote-argument (dired-get-filename nil))
1252 (defadvice dired-do-flagged-delete
1253 (around mdw-delete-if-prefix-argument activate compile)
1254 (let ((delete-by-moving-to-trash (and (null current-prefix-arg)
1255 delete-by-moving-to-trash)))
1258 (eval-after-load "dired"
1259 '(define-key dired-mode-map "X" 'mdw-dired-run))
1261 ;;;--------------------------------------------------------------------------
1264 (defun mdw-w3m-browse-url (url &optional new-session-p)
1265 "Invoke w3m on the URL in its current window, or at least a different one.
1266 If NEW-SESSION-P, start a new session."
1267 (interactive "sURL: \nP")
1269 (let ((window (selected-window)))
1272 (select-window (or (and (not new-session-p)
1273 (get-buffer-window "*w3m*"))
1275 (if (one-window-p t) (split-window))
1277 (w3m-browse-url url new-session-p))
1278 (select-window window)))))
1280 (eval-after-load 'w3m
1281 '(define-key w3m-mode-map [?\e ?\r] 'w3m-view-this-url-new-session))
1283 (defcustom mdw-good-url-browsers
1284 '(browse-url-mozilla
1286 (w3m . mdw-w3m-browse-url)
1288 "List of good browsers for mdw-good-url-browsers.
1289 Each item is a browser function name, or a cons (CHECK . FUNC).
1290 A symbol FOO stands for (FOO . FOO)."
1291 :type '(repeat (choice function (cons function function))))
1293 (defun mdw-good-url-browser ()
1294 "Return a good URL browser.
1295 Trundle the list of such things, finding the first item for which
1296 CHECK is fboundp, and returning the correponding FUNC."
1297 (let ((bs mdw-good-url-browsers) b check func answer)
1298 (while (and bs (not answer))
1302 (setq check (car b) func (cdr b))
1303 (setq check b func b))
1305 (setq answer func)))
1308 (eval-after-load "w3m-search"
1312 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
1313 ("gd" "Google Directory"
1314 "http://www.google.com/search?cat=gwd/Top&q=%s")
1315 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
1316 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
1317 ("gi" "Images" "http://images.google.com/images?q=%s")
1319 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
1321 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
1322 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
1323 ("nc-wiki" "nCipher wiki"
1324 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
1325 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
1326 ("lp" "Launchpad bug by number"
1327 "https://bugs.launchpad.net/bugs/%s")
1328 ("lppkg" "Launchpad bugs by package"
1329 "https://bugs.launchpad.net/%s")
1331 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
1332 ("debbug" "Debian bug by number"
1333 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
1334 ("debbugpkg" "Debian bugs by package"
1335 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
1336 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
1337 (add-to-list 'w3m-search-engine-alist
1338 (list (cadr item) (caddr item) nil))
1339 (add-to-list 'w3m-uri-replace-alist
1340 (list (concat "\\`" (car item) ":")
1341 'w3m-search-uri-replace
1344 ;;;--------------------------------------------------------------------------
1345 ;;; Paragraph filling.
1347 ;; Useful variables.
1349 (defcustom mdw-fill-prefix nil
1350 "Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
1351 If there's no fill prefix currently set (by the `fill-prefix'
1352 variable) and there's a match from one of the regexps here, it
1353 gets used to set the fill-prefix for the current operation.
1355 The variable is a list of items of the form `PATTERN . PREFIX'; if
1356 the PATTERN matches, the PREFIX is used to set the fill prefix.
1358 A PATTERN is one of the following.
1360 * STRING -- a regular expression, expected to match at point
1361 * (eval . FORM) -- a Lisp form which must evaluate non-nil
1362 * (if COND CONSEQ-PAT ALT-PAT) -- if COND evaluates non-nil, must match
1363 CONSEQ-PAT; otherwise must match ALT-PAT
1364 * (and PATTERN ...) -- must match all of the PATTERNs
1365 * (or PATTERN ...) -- must match at least one PATTERN
1366 * (not PATTERN) -- mustn't match (probably not useful)
1368 A PREFIX is a list of the following kinds of things:
1370 * STRING -- insert a literal string
1371 * (match . N) -- insert the thing matched by bracketed subexpression N
1372 * (pad . N) -- a string of whitespace the same width as subexpression N
1373 * (expr . FORM) -- the result of evaluating FORM
1375 Information about `bracketed subexpressions' comes from the match data,
1376 as modified during matching.")
1378 (make-variable-buffer-local 'mdw-fill-prefix)
1380 (defcustom mdw-hanging-indents
1382 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
1385 "Standard regexp matching parts of a hanging indent.
1386 This is mainly useful in `auto-fill-mode'."
1389 ;; Utility functions.
1391 (defun mdw-maybe-tabify (s)
1392 "Tabify or untabify the string S, according to `indent-tabs-mode'."
1393 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
1397 (let ((start (point-min)) (end (point-max)))
1398 (funcall tabfun (point-min) (point-max))
1399 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
1401 (defun mdw-fill-prefix-match-p (pat)
1402 "Return non-nil if PAT matches at the current position."
1403 (cond ((stringp pat) (looking-at pat))
1404 ((not (consp pat)) (error "Unknown pattern item `%S'" pat))
1405 ((eq (car pat) 'eval) (eval (cdr pat)))
1407 (if (or (null (cdr pat))
1411 (error "Invalid `if' pattern `%S'" pat))
1412 (mdw-fill-prefix-match-p (if (eval (cadr pat))
1415 ((eq (car pat) 'and)
1416 (let ((pats (cdr pat))
1419 (or (mdw-fill-prefix-match-p (car pats))
1421 (setq pats (cdr pats)))
1424 (let ((pats (cdr pat))
1427 (or (not (mdw-fill-prefix-match-p (car pats)))
1428 (progn (setq ok t) nil)))
1429 (setq pats (cdr pats)))
1431 ((eq (car pat) 'not)
1432 (if (or (null (cdr pat)) (cddr pat))
1433 (error "Invalid `not' pattern `%S'" pat))
1434 (not (mdw-fill-prefix-match-p (car pats))))
1435 (t (error "Unknown pattern form `%S'" pat))))
1437 (defun mdw-maybe-car (p)
1438 "If P is a pair, return (car P), otherwise just return P."
1439 (if (consp p) (car p) p))
1441 (defun mdw-padding (s)
1442 "Return a string the same width as S but made entirely from whitespace."
1443 (let* ((l (length s)) (i 0) (n (make-string l ? )))
1445 (if (= 9 (aref s i))
1450 (defun mdw-do-prefix-match (m)
1451 "Expand a dynamic prefix match element.
1452 See `mdw-fill-prefix' for details."
1453 (cond ((not (consp m)) (format "%s" m))
1454 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
1455 ((eq (car m) 'pad) (mdw-padding (match-string
1456 (mdw-maybe-car (cdr m)))))
1457 ((eq (car m) 'eval) (eval (cdr m)))
1460 (defun mdw-examine-fill-prefixes (l)
1461 "Given a list of dynamic fill prefixes, pick one which matches
1462 context and return the static fill prefix to use. Point must be
1463 at the start of a line, and match data must be saved."
1465 (while (cond ((null l) nil)
1466 ((mdw-fill-prefix-match-p (caar l))
1470 (mapcar #'mdw-do-prefix-match
1476 (defun mdw-choose-dynamic-fill-prefix ()
1477 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
1478 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
1479 ((not mdw-fill-prefix) fill-prefix)
1483 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
1485 (defadvice do-auto-fill (around mdw-dynamic-fill-prefix () activate compile)
1486 "Handle auto-filling, working out a dynamic fill prefix in the
1487 case where there isn't a sensible static one."
1488 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1491 (defun mdw-fill-paragraph ()
1492 "Fill paragraph, getting a dynamic fill prefix."
1494 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1495 (fill-paragraph nil)))
1497 (defun mdw-point-within-string-p ()
1498 "Return non-nil if point is within a string."
1499 (let ((state (syntax-ppss)))
1502 (defun mdw-standard-fill-prefix (rx &optional mat)
1503 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
1504 This is just a short-cut for setting the thing by hand, and by
1505 design it doesn't cope with anything approximating a complicated
1507 (setq mdw-fill-prefix
1508 `(((if (mdw-point-within-string-p)
1509 ,(concat "\\(\\s-*\\)" mdw-hanging-indents)
1510 ,(concat rx mdw-hanging-indents))
1512 (pad . ,(or mat 2))))))
1514 ;;;--------------------------------------------------------------------------
1517 ;; Teach PostScript about a condensed variant of Courier. I'm using 85% of
1518 ;; the usual width, which happens to match `mdwfonts', and David Carlisle's
1519 ;; `pslatex'. (Once upon a time, I used 80%, but decided consistency with
1520 ;; `pslatex' was useful.)
1521 (setq ps-user-defined-prologue "
1522 /CourierCondensed /Courier
1523 /CourierCondensed-Bold /Courier-Bold
1524 /CourierCondensed-Oblique /Courier-Oblique
1525 /CourierCondensed-BoldOblique /Courier-BoldOblique
1526 4 { findfont [0.85 0 0 1 0 0] makefont definefont pop } repeat
1529 ;; Hack `ps-print''s settings.
1530 (eval-after-load 'ps-print
1533 ;; Notice that the comment-delimiters should be in italics too.
1534 (pushnew 'font-lock-comment-delimiter-face ps-italic-faces)
1536 ;; Select more suitable colours for the main kinds of tokens. The
1537 ;; colours set on the Emacs faces are chosen for use against a dark
1538 ;; background, and work very badly on white paper.
1539 (ps-extend-face '(font-lock-comment-face "darkgreen" nil italic))
1540 (ps-extend-face '(font-lock-comment-delimiter-face "darkgreen" nil italic))
1541 (ps-extend-face '(font-lock-string-face "RoyalBlue4" nil))
1542 (ps-extend-face '(mdw-punct-face "sienna" nil))
1543 (ps-extend-face '(mdw-number-face "OrangeRed3" nil))
1545 ;; Teach `ps-print' about my condensed varsions of Courier.
1546 (setq ps-font-info-database
1547 (append '((CourierCondensed
1548 (fonts (normal . "CourierCondensed")
1549 (bold . "CourierCondensed-Bold")
1550 (italic . "CourierCondensed-Oblique")
1551 (bold-italic . "CourierCondensed-BoldOblique"))
1553 (line-height . 10.55)
1555 (avg-char-width . 5.1)))
1556 (remove* 'CourierCondensed ps-font-info-database
1559 ;; Arrange to strip overlays from the buffer before we print . This will
1560 ;; prevent `flyspell' from interfering with the printout. (It would be less
1561 ;; bad if `ps-print' could merge the `flyspell' overlay face with the
1562 ;; underlying `font-lock' face, but it can't (and that seems hard). So
1563 ;; instead we have this hack.
1565 ;; The basic trick is to copy the relevant text from the buffer being printed
1566 ;; into a temporary buffer and... just print that. The text properties come
1567 ;; with the text and end up in the new buffer, and the overlays get lost
1568 ;; along the way. Only problem is that the headers identifying the file
1569 ;; being printed get confused, so remember the original buffer and reinstate
1570 ;; it when constructing the headers.
1571 (defvar mdw-printing-buffer)
1573 (defadvice ps-generate-header
1574 (around mdw-use-correct-buffer () activate compile)
1575 "Print the correct name of the buffer being printed."
1576 (with-current-buffer mdw-printing-buffer
1579 (defadvice ps-generate
1580 (around mdw-strip-overlays (buffer from to genfunc) activate compile)
1581 "Strip overlays -- in particular, from `flyspell' -- before printout."
1583 (let ((mdw-printing-buffer buffer))
1584 (insert-buffer-substring buffer from to)
1585 (ad-set-arg 0 (current-buffer))
1586 (ad-set-arg 1 (point-min))
1587 (ad-set-arg 2 (point-max))
1590 ;;;--------------------------------------------------------------------------
1591 ;;; Other common declarations.
1593 ;; Common mode settings.
1595 (defcustom mdw-auto-indent t
1596 "Whether to indent automatically after a newline."
1600 (defun mdw-whitespace-mode (&optional arg)
1601 "Turn on/off whitespace mode, but don't highlight trailing space."
1603 (when (and (boundp 'whitespace-style)
1604 (fboundp 'whitespace-mode))
1605 (let ((whitespace-style (remove 'trailing whitespace-style)))
1606 (whitespace-mode arg))
1607 (setq show-trailing-whitespace whitespace-mode)))
1609 (defvar mdw-do-misc-mode-hacking nil)
1611 (defun mdw-misc-mode-config ()
1612 (and mdw-auto-indent
1613 (cond ((eq major-mode 'lisp-mode)
1614 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
1615 ((derived-mode-p 'slime-repl-mode 'asm-mode 'comint-mode)
1618 (local-set-key "\C-m" 'newline-and-indent))))
1619 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
1620 (local-set-key [C-return] 'newline)
1621 (make-local-variable 'page-delimiter)
1622 (setq page-delimiter (concat "^" "\f"
1626 "\\(" " " ".*" " " "\\)?"
1630 (setq comment-column 40)
1632 (setq fill-column mdw-text-width)
1633 (flyspell-prog-mode)
1634 (and (fboundp 'gtags-mode)
1636 (if (fboundp 'hs-minor-mode)
1637 (trap (hs-minor-mode t))
1638 (outline-minor-mode t))
1640 (trap (turn-on-font-lock)))
1642 (defun mdw-post-local-vars-misc-mode-config ()
1643 (setq whitespace-line-column mdw-text-width)
1644 (when (and mdw-do-misc-mode-hacking
1645 (not buffer-read-only))
1646 (setq show-trailing-whitespace t)
1647 (mdw-whitespace-mode 1)))
1648 (add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
1650 (defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1651 `(progn ,@(mapcar (lambda (func)
1653 (after mdw-angry-fruit-salad activate)
1654 (when mdw-do-misc-mode-hacking
1655 (setq show-trailing-whitespace
1656 (not buffer-read-only))
1657 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1659 (mdw-advise-update-angry-fruit-salad toggle-read-only
1665 (eval-after-load 'gtags
1667 (dolist (key '([mouse-2] [mouse-3]))
1668 (define-key gtags-mode-map key nil))
1669 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1670 (define-key gtags-select-mode-map [C-S-mouse-2]
1671 'gtags-select-tag-by-event)
1672 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1673 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
1675 ;; Backup file handling.
1677 (defcustom mdw-backup-disable-regexps nil
1678 "List of regular expressions: if a file name matches any of
1679 these then the file is not backed up."
1680 :type '(repeat regexp))
1682 (defun mdw-backup-enable-predicate (name)
1683 "[mdw]'s default backup predicate.
1684 Allows a backup if the standard predicate would allow it, and it
1685 doesn't match any of the regular expressions in
1686 `mdw-backup-disable-regexps'."
1687 (and (normal-backup-enable-predicate name)
1688 (let ((answer t) (list mdw-backup-disable-regexps))
1691 (if (string-match (car list) name)
1693 (setq list (cdr list)))
1695 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
1699 (defun mdw-last-one-out-turn-off-the-lights (frame)
1700 "Disconnect from an X display if this was the last frame on that display."
1701 (let ((frame-display (frame-parameter frame 'display)))
1702 (when (and frame-display
1703 (eq window-system 'x)
1704 (not (some (lambda (fr)
1705 (and (not (eq fr frame))
1706 (string= (frame-parameter fr 'display)
1709 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1710 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1712 ;;;--------------------------------------------------------------------------
1713 ;;; Fullscreen-ness.
1715 (defcustom mdw-full-screen-parameters
1716 '((menu-bar-lines . 0)
1717 ;;(vertical-scroll-bars . nil)
1719 "Frame parameters to set when making a frame fullscreen."
1720 :type '(alist :key-type symbol))
1722 (defcustom mdw-full-screen-save
1724 "Extra frame parameters to save when setting fullscreen."
1725 :type '(repeat symbol))
1727 (defun mdw-toggle-full-screen (&optional frame)
1728 "Show the FRAME fullscreen."
1731 (cond ((frame-parameter frame 'fullscreen)
1732 (set-frame-parameter frame 'fullscreen nil)
1733 (modify-frame-parameters
1735 (or (frame-parameter frame 'mdw-full-screen-saved)
1736 (mapcar (lambda (assoc)
1737 (assq (car assoc) default-frame-alist))
1738 mdw-full-screen-parameters))))
1740 (let ((saved (mapcar (lambda (param)
1741 (cons param (frame-parameter frame param)))
1742 (append (mapcar #'car
1743 mdw-full-screen-parameters)
1744 mdw-full-screen-save))))
1745 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1746 (modify-frame-parameters frame mdw-full-screen-parameters)
1747 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1749 ;;;--------------------------------------------------------------------------
1750 ;;; General fontification.
1752 (make-face 'mdw-virgin-face)
1754 (defmacro mdw-define-face (name &rest body)
1755 "Define a face, and make sure it's actually set as the definition."
1759 (copy-face 'mdw-virgin-face ',name)
1760 (defvar ,name ',name)
1761 (put ',name 'face-defface-spec ',body)
1762 (face-spec-set ',name ',body nil)))
1764 (mdw-define-face default
1765 (((type w32)) :family "courier new" :height 85)
1766 (((type x)) :family "6x13" :foundry "trad" :height 130)
1767 (((type color)) :foreground "white" :background "black")
1769 (mdw-define-face fixed-pitch
1770 (((type w32)) :family "courier new" :height 85)
1771 (((type x)) :family "6x13" :foundry "trad" :height 130)
1772 (t :foreground "white" :background "black"))
1773 (mdw-define-face fixed-pitch-serif
1774 (((type w32)) :family "courier new" :height 85 :weight bold)
1775 (((type x)) :family "6x13" :foundry "trad" :height 130 :weight bold)
1776 (t :foreground "white" :background "black" :weight bold))
1777 (mdw-define-face variable-pitch
1778 (((type x)) :family "helvetica" :height 120))
1779 (mdw-define-face region
1780 (((min-colors 64)) :background "grey30")
1781 (((class color)) :background "blue")
1782 (t :inverse-video t))
1783 (mdw-define-face match
1784 (((class color)) :background "blue")
1785 (t :inverse-video t))
1786 (mdw-define-face mc/cursor-face
1787 (((class color)) :background "red")
1788 (t :inverse-video t))
1789 (mdw-define-face minibuffer-prompt
1791 (mdw-define-face mode-line
1792 (((class color)) :foreground "blue" :background "yellow"
1793 :box (:line-width 1 :style released-button))
1794 (t :inverse-video t))
1795 (mdw-define-face mode-line-inactive
1796 (((class color)) :foreground "yellow" :background "blue"
1797 :box (:line-width 1 :style released-button))
1798 (t :inverse-video t))
1799 (mdw-define-face nobreak-space
1801 (t :inherit escape-glyph :underline t))
1802 (mdw-define-face scroll-bar
1803 (t :foreground "black" :background "lightgrey"))
1804 (mdw-define-face fringe
1805 (t :foreground "yellow"))
1806 (mdw-define-face show-paren-match
1807 (((min-colors 64)) :background "darkgreen")
1808 (((class color)) :background "green")
1810 (mdw-define-face show-paren-mismatch
1811 (((class color)) :background "red")
1812 (t :inverse-video t))
1813 (mdw-define-face highlight
1814 (((min-colors 64)) :background "DarkSeaGreen4")
1815 (((class color)) :background "cyan")
1816 (t :inverse-video t))
1818 (mdw-define-face viper-minibuffer-emacs (t nil))
1819 (mdw-define-face viper-minibuffer-insert (t nil))
1820 (mdw-define-face viper-minibuffer-vi (t nil))
1821 (mdw-define-face viper-replace-overlay
1822 (((min-colors 64)) :background "darkred")
1823 (((class color)) :background "red")
1824 (t :inverse-video t))
1825 (mdw-define-face viper-search (t :inherit isearch))
1827 (mdw-define-face compilation-error
1828 (((class color)) :foreground "red" :weight bold)
1830 (mdw-define-face compilation-warning
1831 (((class color)) :foreground "orange" :weight bold)
1833 (mdw-define-face compilation-info
1834 (((class color)) :foreground "green" :weight bold)
1836 (mdw-define-face compilation-line-number
1838 (mdw-define-face compilation-column-number
1839 (((min-colors 64)) :foreground "lightgrey"))
1840 (setq compilation-message-face 'mdw-virgin-face)
1841 (setq compilation-enter-directory-face 'font-lock-comment-face)
1842 (setq compilation-leave-directory-face 'font-lock-comment-face)
1844 (mdw-define-face holiday-face
1845 (t :background "red"))
1846 (mdw-define-face calendar-today-face
1847 (t :foreground "yellow" :weight bold))
1849 (mdw-define-face comint-highlight-prompt
1851 (mdw-define-face comint-highlight-input
1854 (mdw-define-face Man-underline
1855 (((type tty)) :underline t)
1858 (mdw-define-face ido-subdir
1859 (t :foreground "cyan" :weight bold))
1861 (mdw-define-face dired-directory
1862 (t :foreground "cyan" :weight bold))
1863 (mdw-define-face dired-symlink
1864 (t :foreground "cyan"))
1865 (mdw-define-face dired-perm-write
1868 (mdw-define-face trailing-whitespace
1869 (((class color)) :background "red")
1870 (t :inverse-video t))
1871 (mdw-define-face whitespace-line
1872 (((class color)) :background "darkred")
1873 (t :inverse-video t))
1874 (mdw-define-face mdw-punct-face
1875 (((min-colors 64)) :foreground "burlywood2")
1876 (((class color)) :foreground "yellow"))
1877 (mdw-define-face mdw-number-face
1878 (t :foreground "yellow"))
1879 (mdw-define-face mdw-trivial-face)
1880 (mdw-define-face font-lock-function-name-face
1882 (mdw-define-face font-lock-keyword-face
1884 (mdw-define-face font-lock-constant-face
1886 (mdw-define-face font-lock-builtin-face
1888 (mdw-define-face font-lock-type-face
1889 (t :weight bold :slant italic))
1890 (mdw-define-face font-lock-reference-face
1892 (mdw-define-face font-lock-variable-name-face
1894 (mdw-define-face font-lock-comment-face
1895 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1896 (((class color)) :foreground "green")
1898 (mdw-define-face font-lock-comment-delimiter-face
1899 (t :inherit font-lock-comment-face))
1900 (mdw-define-face font-lock-string-face
1901 (((min-colors 64)) :foreground "SkyBlue1")
1902 (((class color)) :foreground "cyan")
1904 (mdw-define-face font-lock-doc-face
1905 (t :inherit font-lock-string-face))
1907 (mdw-define-face message-separator
1908 (t :background "red" :foreground "white" :weight bold))
1909 (mdw-define-face message-cited-text
1910 (default :slant italic)
1911 (((min-colors 64)) :foreground "SkyBlue1")
1912 (((class color)) :foreground "cyan"))
1913 (mdw-define-face message-header-cc
1914 (default :slant italic)
1915 (((min-colors 64)) :foreground "SeaGreen1")
1916 (((class color)) :foreground "green"))
1917 (mdw-define-face message-header-newsgroups
1918 (default :slant italic)
1919 (((min-colors 64)) :foreground "SeaGreen1")
1920 (((class color)) :foreground "green"))
1921 (mdw-define-face message-header-subject
1922 (((min-colors 64)) :foreground "SeaGreen1")
1923 (((class color)) :foreground "green"))
1924 (mdw-define-face message-header-to
1925 (((min-colors 64)) :foreground "SeaGreen1")
1926 (((class color)) :foreground "green"))
1927 (mdw-define-face message-header-xheader
1928 (default :slant italic)
1929 (((min-colors 64)) :foreground "SeaGreen1")
1930 (((class color)) :foreground "green"))
1931 (mdw-define-face message-header-other
1932 (default :slant italic)
1933 (((min-colors 64)) :foreground "SeaGreen1")
1934 (((class color)) :foreground "green"))
1935 (mdw-define-face message-header-name
1936 (default :weight bold)
1937 (((min-colors 64)) :foreground "SeaGreen1")
1938 (((class color)) :foreground "green"))
1940 (mdw-define-face which-func
1943 (mdw-define-face gnus-header-name
1944 (default :weight bold)
1945 (((min-colors 64)) :foreground "SeaGreen1")
1946 (((class color)) :foreground "green"))
1947 (mdw-define-face gnus-header-subject
1948 (((min-colors 64)) :foreground "SeaGreen1")
1949 (((class color)) :foreground "green"))
1950 (mdw-define-face gnus-header-from
1951 (((min-colors 64)) :foreground "SeaGreen1")
1952 (((class color)) :foreground "green"))
1953 (mdw-define-face gnus-header-to
1954 (((min-colors 64)) :foreground "SeaGreen1")
1955 (((class color)) :foreground "green"))
1956 (mdw-define-face gnus-header-content
1957 (default :slant italic)
1958 (((min-colors 64)) :foreground "SeaGreen1")
1959 (((class color)) :foreground "green"))
1961 (mdw-define-face gnus-cite-1
1962 (((min-colors 64)) :foreground "SkyBlue1")
1963 (((class color)) :foreground "cyan"))
1964 (mdw-define-face gnus-cite-2
1965 (((min-colors 64)) :foreground "RoyalBlue2")
1966 (((class color)) :foreground "blue"))
1967 (mdw-define-face gnus-cite-3
1968 (((min-colors 64)) :foreground "MediumOrchid")
1969 (((class color)) :foreground "magenta"))
1970 (mdw-define-face gnus-cite-4
1971 (((min-colors 64)) :foreground "firebrick2")
1972 (((class color)) :foreground "red"))
1973 (mdw-define-face gnus-cite-5
1974 (((min-colors 64)) :foreground "burlywood2")
1975 (((class color)) :foreground "yellow"))
1976 (mdw-define-face gnus-cite-6
1977 (((min-colors 64)) :foreground "SeaGreen1")
1978 (((class color)) :foreground "green"))
1979 (mdw-define-face gnus-cite-7
1980 (((min-colors 64)) :foreground "SlateBlue1")
1981 (((class color)) :foreground "cyan"))
1982 (mdw-define-face gnus-cite-8
1983 (((min-colors 64)) :foreground "RoyalBlue2")
1984 (((class color)) :foreground "blue"))
1985 (mdw-define-face gnus-cite-9
1986 (((min-colors 64)) :foreground "purple2")
1987 (((class color)) :foreground "magenta"))
1988 (mdw-define-face gnus-cite-10
1989 (((min-colors 64)) :foreground "DarkOrange2")
1990 (((class color)) :foreground "red"))
1991 (mdw-define-face gnus-cite-11
1992 (t :foreground "grey"))
1994 (mdw-define-face gnus-emphasis-underline
1995 (((type tty)) :underline t)
1998 (mdw-define-face diff-header
2000 (mdw-define-face diff-index
2002 (mdw-define-face diff-file-header
2004 (mdw-define-face diff-hunk-header
2005 (((min-colors 64)) :foreground "SkyBlue1")
2006 (((class color)) :foreground "cyan"))
2007 (mdw-define-face diff-function
2008 (default :weight bold)
2009 (((min-colors 64)) :foreground "SkyBlue1")
2010 (((class color)) :foreground "cyan"))
2011 (mdw-define-face diff-header
2012 (((min-colors 64)) :background "grey10"))
2013 (mdw-define-face diff-added
2014 (((class color)) :foreground "green"))
2015 (mdw-define-face diff-removed
2016 (((class color)) :foreground "red"))
2017 (mdw-define-face diff-context
2019 (mdw-define-face diff-refine-change
2020 (((min-colors 64)) :background "RoyalBlue4")
2022 (mdw-define-face diff-refine-removed
2023 (((min-colors 64)) :background "#500")
2025 (mdw-define-face diff-refine-added
2026 (((min-colors 64)) :background "#050")
2029 (setq ediff-force-faces t)
2030 (mdw-define-face ediff-current-diff-A
2031 (((min-colors 64)) :background "darkred")
2032 (((class color)) :background "red")
2033 (t :inverse-video t))
2034 (mdw-define-face ediff-fine-diff-A
2035 (((min-colors 64)) :background "red3")
2036 (((class color)) :inverse-video t)
2037 (t :inverse-video nil))
2038 (mdw-define-face ediff-even-diff-A
2039 (((min-colors 64)) :background "#300"))
2040 (mdw-define-face ediff-odd-diff-A
2041 (((min-colors 64)) :background "#300"))
2042 (mdw-define-face ediff-current-diff-B
2043 (((min-colors 64)) :background "darkgreen")
2044 (((class color)) :background "magenta")
2045 (t :inverse-video t))
2046 (mdw-define-face ediff-fine-diff-B
2047 (((min-colors 64)) :background "green4")
2048 (((class color)) :inverse-video t)
2049 (t :inverse-video nil))
2050 (mdw-define-face ediff-even-diff-B
2051 (((min-colors 64)) :background "#020"))
2052 (mdw-define-face ediff-odd-diff-B
2053 (((min-colors 64)) :background "#020"))
2054 (mdw-define-face ediff-current-diff-C
2055 (((min-colors 64)) :background "darkblue")
2056 (((class color)) :background "blue")
2057 (t :inverse-video t))
2058 (mdw-define-face ediff-fine-diff-C
2059 (((min-colors 64)) :background "blue1")
2060 (((class color)) :inverse-video t)
2061 (t :inverse-video nil))
2062 (mdw-define-face ediff-even-diff-C
2063 (((min-colors 64)) :background "#004"))
2064 (mdw-define-face ediff-odd-diff-C
2065 (((min-colors 64)) :background "#004"))
2066 (mdw-define-face ediff-current-diff-Ancestor
2067 (((min-colors 64)) :background "#630")
2068 (((class color)) :background "blue")
2069 (t :inverse-video t))
2070 (mdw-define-face ediff-even-diff-Ancestor
2071 (((min-colors 64)) :background "#320"))
2072 (mdw-define-face ediff-odd-diff-Ancestor
2073 (((min-colors 64)) :background "#320"))
2075 (mdw-define-face magit-hash
2076 (((min-colors 64)) :foreground "grey40")
2077 (((class color)) :foreground "blue"))
2078 (mdw-define-face magit-diff-hunk-heading
2079 (((min-colors 64)) :foreground "grey70" :background "grey25")
2080 (((class color)) :foreground "yellow"))
2081 (mdw-define-face magit-diff-hunk-heading-highlight
2082 (((min-colors 64)) :foreground "grey70" :background "grey35")
2083 (((class color)) :foreground "yellow" :background "blue"))
2084 (mdw-define-face magit-diff-added
2085 (((min-colors 64)) :foreground "#ddffdd" :background "#335533")
2086 (((class color)) :foreground "green"))
2087 (mdw-define-face magit-diff-added-highlight
2088 (((min-colors 64)) :foreground "#cceecc" :background "#336633")
2089 (((class color)) :foreground "green" :background "blue"))
2090 (mdw-define-face magit-diff-removed
2091 (((min-colors 64)) :foreground "#ffdddd" :background "#553333")
2092 (((class color)) :foreground "red"))
2093 (mdw-define-face magit-diff-removed-highlight
2094 (((min-colors 64)) :foreground "#eecccc" :background "#663333")
2095 (((class color)) :foreground "red" :background "blue"))
2096 (mdw-define-face magit-blame-heading
2097 (((min-colors 64)) :foreground "white" :background "grey25"
2098 :weight normal :slant normal)
2099 (((class color)) :foreground "white" :background "blue"
2100 :weight normal :slant normal))
2101 (mdw-define-face magit-blame-name
2102 (t :inherit magit-blame-heading :slant italic))
2103 (mdw-define-face magit-blame-date
2104 (((min-colors 64)) :inherit magit-blame-heading :foreground "grey60")
2105 (((class color)) :inherit magit-blame-heading :foreground "cyan"))
2106 (mdw-define-face magit-blame-summary
2107 (t :inherit magit-blame-heading :weight bold))
2109 (mdw-define-face dylan-header-background
2110 (((min-colors 64)) :background "NavyBlue")
2111 (((class color)) :background "blue"))
2113 (mdw-define-face erc-input-face
2114 (t :foreground "red"))
2116 (mdw-define-face woman-bold
2118 (mdw-define-face woman-italic
2121 (eval-after-load "rst"
2123 (mdw-define-face rst-level-1-face
2124 (t :foreground "SkyBlue1" :weight bold))
2125 (mdw-define-face rst-level-2-face
2126 (t :foreground "SeaGreen1" :weight bold))
2127 (mdw-define-face rst-level-3-face
2129 (mdw-define-face rst-level-4-face
2131 (mdw-define-face rst-level-5-face
2133 (mdw-define-face rst-level-6-face
2136 (mdw-define-face p4-depot-added-face
2137 (t :foreground "green"))
2138 (mdw-define-face p4-depot-branch-op-face
2139 (t :foreground "yellow"))
2140 (mdw-define-face p4-depot-deleted-face
2141 (t :foreground "red"))
2142 (mdw-define-face p4-depot-unmapped-face
2143 (t :foreground "SkyBlue1"))
2144 (mdw-define-face p4-diff-change-face
2145 (t :foreground "yellow"))
2146 (mdw-define-face p4-diff-del-face
2147 (t :foreground "red"))
2148 (mdw-define-face p4-diff-file-face
2149 (t :foreground "SkyBlue1"))
2150 (mdw-define-face p4-diff-head-face
2151 (t :background "grey10"))
2152 (mdw-define-face p4-diff-ins-face
2153 (t :foreground "green"))
2155 (mdw-define-face w3m-anchor-face
2156 (t :foreground "SkyBlue1" :underline t))
2157 (mdw-define-face w3m-arrived-anchor-face
2158 (t :foreground "SkyBlue1" :underline t))
2160 (mdw-define-face whizzy-slice-face
2161 (t :background "grey10"))
2162 (mdw-define-face whizzy-error-face
2163 (t :background "darkred"))
2165 ;; Ellipses used to indicate hidden text (and similar).
2166 (mdw-define-face mdw-ellipsis-face
2167 (((type tty)) :foreground "blue") (t :foreground "grey60"))
2168 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
2169 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
2170 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
2171 (bar (make-glyph-code ?| mdw-ellipsis-face)))
2172 (set-display-table-slot standard-display-table 0 dollar)
2173 (set-display-table-slot standard-display-table 1 backslash)
2174 (set-display-table-slot standard-display-table 4
2175 (vector dot dot dot))
2176 (set-display-table-slot standard-display-table 5 bar))
2178 ;;;--------------------------------------------------------------------------
2181 (mdw-define-face mdw-point-overlay-face
2183 (((min-colors 64)) :background "darkblue")
2184 (((class color)) :background "blue")
2185 (((type tty) (class mono)) :inverse-video t))
2187 (defcustom mdw-point-overlay-fringe-display '(vertical-bar . vertical-bar)
2188 "Bitmaps to display in the left and right fringes in the current line."
2189 :type '(cons symbol symbol))
2191 (defun mdw-configure-point-overlay ()
2192 (let ((ov (make-overlay 0 0)))
2193 (overlay-put ov 'priority 0)
2194 (let* ((fringe (or mdw-point-overlay-fringe-display (cons nil nil)))
2195 (left (car fringe)) (right (cdr fringe))
2199 (put-text-property 0 1 'display `(left-fringe ,left) ss)
2200 (setq s (concat s ss))))
2203 (put-text-property 0 1 'display `(right-fringe ,right) ss)
2204 (setq s (concat s ss))))
2205 (when (or left right)
2206 (overlay-put ov 'before-string s)))
2207 (overlay-put ov 'face 'mdw-point-overlay-face)
2211 (defvar mdw-point-overlay (mdw-configure-point-overlay)
2212 "An overlay used for showing where point is in the selected window.")
2213 (defun mdw-reconfigure-point-overlay ()
2215 (setq mdw-point-overlay (mdw-configure-point-overlay)))
2217 (defun mdw-remove-point-overlay ()
2218 "Remove the current-point overlay."
2219 (delete-overlay mdw-point-overlay))
2221 (defun mdw-update-point-overlay ()
2222 "Mark the current point position with an overlay."
2223 (if (not mdw-point-overlay-mode)
2224 (mdw-remove-point-overlay)
2225 (overlay-put mdw-point-overlay 'window (selected-window))
2226 (move-overlay mdw-point-overlay
2227 (line-beginning-position)
2228 (+ (line-end-position) 1))))
2230 (defvar mdw-point-overlay-buffers nil
2231 "List of buffers using `mdw-point-overlay-mode'.")
2233 (define-minor-mode mdw-point-overlay-mode
2234 "Indicate current line with an overlay."
2236 (let ((buffer (current-buffer)))
2237 (setq mdw-point-overlay-buffers
2238 (mapcan (lambda (buf)
2239 (if (and (buffer-live-p buf)
2240 (not (eq buf buffer)))
2242 mdw-point-overlay-buffers))
2243 (if mdw-point-overlay-mode
2244 (setq mdw-point-overlay-buffers
2245 (cons buffer mdw-point-overlay-buffers))))
2246 (cond (mdw-point-overlay-buffers
2247 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
2248 (add-hook 'post-command-hook 'mdw-update-point-overlay))
2250 (mdw-remove-point-overlay)
2251 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
2252 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
2254 (define-globalized-minor-mode mdw-global-point-overlay-mode
2255 mdw-point-overlay-mode
2256 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
2258 (defvar mdw-terminal-title-alist nil)
2259 (defun mdw-update-terminal-title ()
2260 (when (let ((term (frame-parameter nil 'tty-type)))
2261 (and term (string-match "^xterm" term)))
2262 (let* ((tty (frame-parameter nil 'tty))
2263 (old (assoc tty mdw-terminal-title-alist))
2264 (new (format-mode-line frame-title-format)))
2265 (unless (and old (equal (cdr old) new))
2266 (if old (rplacd old new)
2267 (setq mdw-terminal-title-alist
2268 (cons (cons tty new) mdw-terminal-title-alist)))
2269 (send-string-to-terminal (concat "\e]2;" new "\e\\"))))))
2271 (add-hook 'post-command-hook 'mdw-update-terminal-title)
2273 ;;;--------------------------------------------------------------------------
2276 (defvar mdw-ediff-previous-windows)
2277 (defun mdw-ediff-setup ()
2278 (setq mdw-ediff-previous-windows (current-window-configuration)))
2279 (defun mdw-ediff-suspend-or-quit ()
2280 (set-window-configuration mdw-ediff-previous-windows))
2281 (add-hook 'ediff-before-setup-hook 'mdw-ediff-setup)
2282 (add-hook 'ediff-quit-hook 'mdw-ediff-suspend-or-quit t)
2283 (add-hook 'ediff-suspend-hook 'mdw-ediff-suspend-or-quit t)
2285 ;;;--------------------------------------------------------------------------
2286 ;;; C programming configuration.
2288 ;; Make C indentation nice.
2290 (defun mdw-c-lineup-arglist (langelem)
2291 "Hack for DWIMmery in c-lineup-arglist."
2293 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
2295 (c-lineup-arglist langelem)))
2297 (defun mdw-c-indent-extern-mumble (langelem)
2298 "Indent `extern \"...\" {' lines."
2300 (back-to-indentation)
2302 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
2306 (defun mdw-c-indent-arglist-nested (langelem)
2307 "Indent continued argument lists.
2308 If we've nested more than one argument list, then only introduce a single
2309 indentation anyway."
2310 (let ((context c-syntactic-context)
2311 (pos (c-langelem-2nd-pos c-syntactic-element))
2312 (should-indent-p t))
2314 (eq (caar context) 'arglist-cont-nonempty))
2315 (when (and (= (caddr (pop context)) pos)
2317 (memq (caar context) '(arglist-intro
2318 arglist-cont-nonempty)))
2319 (setq should-indent-p nil)))
2320 (if should-indent-p '+ 0)))
2322 (defvar mdw-define-c-styles-hook nil
2323 "Hook run when `cc-mode' starts up to define styles.")
2325 (defun mdw-merge-style-alists (first second)
2327 (dolist (item first)
2328 (let ((key (car item)) (value (cdr item)))
2329 (if (let* ((key-name (symbol-name key))
2330 (key-len (length key-name)))
2332 (string= (subseq key-name (- key-len 5)) "-alist")))
2334 (mdw-merge-style-alists value
2335 (cdr (assoc key second))))
2337 (push item output))))
2338 (dolist (item second)
2339 (unless (assoc (car item) first)
2340 (push item output)))
2343 (defmacro* mdw-define-c-style (name (&optional parent) &rest assocs)
2344 "Define a C style, called NAME (a symbol) based on PARENT, setting ASSOCs.
2345 A function, named `mdw-define-c-style/NAME', is defined to actually install
2346 the style using `c-add-style', and added to the hook
2347 `mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
2349 (declare (indent defun))
2350 (let* ((name-string (symbol-name name))
2351 (var (intern (concat "mdw-c-style/" name-string)))
2352 (func (intern (concat "mdw-define-c-style/" name-string))))
2357 (let ((parent-list (intern (concat "mdw-c-style/"
2358 (symbol-name parent)))))
2359 `(mdw-merge-style-alists ',assocs ,parent-list))))
2360 (defun ,func () (c-add-style ,name-string ,var))
2361 (and (featurep 'cc-mode) (,func))
2362 (add-hook 'mdw-define-c-styles-hook ',func)
2365 (eval-after-load "cc-mode"
2366 '(run-hooks 'mdw-define-c-styles-hook))
2368 (mdw-define-c-style mdw-c ()
2369 (c-basic-offset . 2)
2370 (comment-column . 40)
2371 (c-class-key . "class")
2372 (c-backslash-column . 72)
2373 (c-label-minimum-indentation . 0)
2374 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
2375 (defun-open . (add 0 c-indent-one-line-block))
2376 (arglist-cont-nonempty . mdw-c-lineup-arglist)
2377 (topmost-intro . mdw-c-indent-extern-mumble)
2378 (cpp-define-intro . 0)
2380 (inextern-lang . [0])
2386 (statement-cont . +)
2387 (statement-case-intro . +)))
2389 (mdw-define-c-style mdw-trustonic-c (mdw-c)
2390 (c-basic-offset . 4)
2391 (c-offsets-alist (access-label . -2)))
2393 (mdw-define-c-style mdw-trustonic-alec-c (mdw-trustonic-c)
2394 (comment-column . 0)
2395 (c-indent-comment-alist (anchored-comment . (column . 0))
2396 (end-block . (space . 1))
2397 (cpp-end-block . (space . 1))
2398 (other . (space . 1)))
2399 (c-offsets-alist (arglist-cont-nonempty . mdw-c-indent-arglist-nested)))
2401 (defun mdw-set-default-c-style (modes style)
2402 "Update the default CC Mode style for MODES to be STYLE.
2404 MODES may be a list of major mode names or a singleton. STYLE is a style
2406 (let ((modes (if (listp modes) modes (list modes)))
2407 (style (symbol-name style)))
2408 (setq c-default-style
2409 (append (mapcar (lambda (mode)
2412 (remove-if (lambda (assoc)
2413 (memq (car assoc) modes))
2414 (if (listp c-default-style)
2416 (list (cons 'other c-default-style))))))))
2417 (setq c-default-style "mdw-c")
2419 (mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
2421 (defvar mdw-c-comment-fill-prefix
2422 `((,(concat "\\([ \t]*/?\\)"
2425 "\\([A-Za-z]+:[ \t]*\\)?"
2426 mdw-hanging-indents)
2427 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
2428 "Fill prefix matching C comments (both kinds).")
2430 (defun mdw-fontify-c-and-c++ ()
2432 ;; Fiddle with some syntax codes.
2433 (modify-syntax-entry ?* ". 23")
2434 (modify-syntax-entry ?/ ". 124b")
2435 (modify-syntax-entry ?\n "> b")
2438 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2440 ;; Now define things to be fontified.
2441 (make-local-variable 'font-lock-keywords)
2443 (mdw-regexps "alignas" ;C11 macro, C++11
2445 "and" ;C++, C95 macro
2446 "and_eq" ;C++, C95 macro
2447 "asm" ;K&R, C++, GCC
2448 "atomic" ;C11 macro, C++11 template type
2450 "bitand" ;C++, C95 macro
2451 "bitor" ;C++, C95 macro
2452 "bool" ;C++, C99 macro
2457 "char16_t" ;C++11, C11 library type
2458 "char32_t" ;C++11, C11 library type
2460 "complex" ;C99 macro, C++ template type
2461 "compl" ;C++, C95 macro
2465 "continue" ;K&R, C89
2467 "defined" ;C89 preprocessor
2474 ;; "entry" ;K&R -- never used
2485 "imaginary" ;C99 macro
2486 "inline" ;C++, C99, GCC
2493 "noreturn" ;C11 macro
2494 "not" ;C++, C95 macro
2495 "not_eq" ;C++, C95 macro
2498 "or" ;C++, C95 macro
2499 "or_eq" ;C++, C95 macro
2503 "register" ;K&R, C89
2504 "reinterpret_cast" ;C++
2511 "static_assert" ;C11 macro, C++11
2518 "thread_local" ;C11 macro, C++11
2524 "unsigned" ;K&R, C89
2529 "wchar_t" ;C++, C89 library type
2531 "xor" ;C++, C95 macro
2532 "xor_eq" ;C++, C95 macro
2541 "_Pragma" ;C99 preprocessor
2542 "_Static_assert" ;C11
2543 "_Thread_local" ;C11
2546 "__attribute__" ;GCC
2549 "__extension__" ;GCC
2559 (mdw-regexps "false" ;C++, C99 macro
2561 "true" ;C++, C99 macro
2563 (preprocessor-keywords
2564 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2565 "ident" "if" "ifdef" "ifndef" "import" "include"
2566 "line" "pragma" "unassert" "undef" "warning"))
2568 (mdw-regexps "class" "defs" "encode" "end" "implementation"
2569 "interface" "private" "protected" "protocol" "public"
2572 (setq font-lock-keywords
2575 ;; Fontify include files as strings.
2576 (list (concat "^[ \t]*\\#[ \t]*"
2577 "\\(include\\|import\\)"
2578 "[ \t]*\\(<[^>]+>?\\)")
2579 '(2 font-lock-string-face))
2581 ;; Preprocessor directives are `references'?.
2582 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2583 preprocessor-keywords
2584 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2585 '(1 font-lock-keyword-face))
2587 ;; Handle the keywords defined above.
2588 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
2589 '(0 font-lock-keyword-face))
2591 (list (concat "\\<\\(" c-keywords "\\)\\>")
2592 '(0 font-lock-keyword-face))
2594 (list (concat "\\<\\(" c-builtins "\\)\\>")
2595 '(0 font-lock-variable-name-face))
2597 ;; Handle numbers too.
2599 ;; This looks strange, I know. It corresponds to the
2600 ;; preprocessor's idea of what a number looks like, rather than
2601 ;; anything sensible.
2602 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2603 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2604 '(0 mdw-number-face))
2606 ;; And anything else is punctuation.
2607 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2608 '(0 mdw-punct-face))))))
2610 (define-derived-mode sod-mode c-mode "Sod"
2611 "Major mode for editing Sod code.")
2612 (push '("\\.sod$" . sod-mode) auto-mode-alist)
2614 (dolist (hook '(c-mode-hook objc-mode-hook c++-mode-hook))
2615 (add-hook hook 'mdw-misc-mode-config t)
2616 (add-hook hook 'mdw-fontify-c-and-c++ t))
2618 ;;;--------------------------------------------------------------------------
2621 (define-derived-mode apcalc-mode c-mode "AP Calc"
2622 "Major mode for editing Calc code.")
2624 (defun mdw-fontify-apcalc ()
2626 ;; Fiddle with some syntax codes.
2627 (modify-syntax-entry ?* ". 23")
2628 (modify-syntax-entry ?/ ". 14")
2631 (setq comment-start "/* ")
2632 (setq comment-end " */")
2633 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2635 ;; Now define things to be fontified.
2636 (make-local-variable 'font-lock-keywords)
2638 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
2639 "do" "else" "exit" "for" "global" "goto" "help" "if"
2640 "local" "mat" "obj" "print" "quit" "read" "return"
2641 "show" "static" "switch" "while" "write")))
2643 (setq font-lock-keywords
2646 ;; Handle the keywords defined above.
2647 (list (concat "\\<\\(" c-keywords "\\)\\>")
2648 '(0 font-lock-keyword-face))
2650 ;; Handle numbers too.
2652 ;; This looks strange, I know. It corresponds to the
2653 ;; preprocessor's idea of what a number looks like, rather than
2654 ;; anything sensible.
2655 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2656 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2657 '(0 mdw-number-face))
2659 ;; And anything else is punctuation.
2660 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2661 '(0 mdw-punct-face))))))
2664 (add-hook 'apcalc-mode-hook 'mdw-misc-mode-config t)
2665 (add-hook 'apcalc-mode-hook 'mdw-fontify-apcalc t))
2667 ;;;--------------------------------------------------------------------------
2668 ;;; Java programming configuration.
2670 ;; Make indentation nice.
2672 (mdw-define-c-style mdw-java ()
2673 (c-basic-offset . 2)
2674 (c-backslash-column . 72)
2675 (c-offsets-alist (substatement-open . 0)
2680 (statement-case-intro . +)))
2681 (mdw-set-default-c-style 'java-mode 'mdw-java)
2683 ;; Declare Java fontification style.
2685 (defun mdw-fontify-java ()
2687 ;; Fiddle with some syntax codes.
2688 (modify-syntax-entry ?@ ".")
2689 (modify-syntax-entry ?@ "." font-lock-syntax-table)
2692 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2694 ;; Now define things to be fontified.
2695 (make-local-variable 'font-lock-keywords)
2696 (let ((java-keywords
2697 (mdw-regexps "abstract" "assert"
2698 "boolean" "break" "byte"
2699 "case" "catch" "char" "class" "const" "continue"
2700 "default" "do" "double"
2701 "else" "enum" "extends"
2702 "final" "finally" "float" "for"
2704 "if" "implements" "import" "instanceof" "int"
2708 "package" "private" "protected" "public"
2710 "short" "static" "strictfp" "switch" "synchronized"
2711 "throw" "throws" "transient" "try"
2716 (mdw-regexps "false" "null" "super" "this" "true")))
2718 (setq font-lock-keywords
2721 ;; Handle the keywords defined above.
2722 (list (concat "\\<\\(" java-keywords "\\)\\>")
2723 '(0 font-lock-keyword-face))
2725 ;; Handle the magic builtins defined above.
2726 (list (concat "\\<\\(" java-builtins "\\)\\>")
2727 '(0 font-lock-variable-name-face))
2729 ;; Handle numbers too.
2731 ;; The following isn't quite right, but it's close enough.
2732 (list (concat "\\<\\("
2733 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2734 "[0-9]+\\(\\.[0-9]*\\)?"
2735 "\\([eE][-+]?[0-9]+\\)?\\)"
2737 '(0 mdw-number-face))
2739 ;; And anything else is punctuation.
2740 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2741 '(0 mdw-punct-face))))))
2744 (add-hook 'java-mode-hook 'mdw-misc-mode-config t)
2745 (add-hook 'java-mode-hook 'mdw-fontify-java t))
2747 ;;;--------------------------------------------------------------------------
2748 ;;; Javascript programming configuration.
2750 (defun mdw-javascript-style ()
2751 (setq js-indent-level 2)
2752 (setq js-expr-indent-offset 0))
2754 (defun mdw-fontify-javascript ()
2757 (mdw-javascript-style)
2758 (setq js-auto-indent-flag t)
2760 ;; Now define things to be fontified.
2761 (make-local-variable 'font-lock-keywords)
2762 (let ((javascript-keywords
2763 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
2764 "char" "class" "const" "continue" "debugger" "default"
2765 "delete" "do" "double" "else" "enum" "export" "extends"
2766 "final" "finally" "float" "for" "function" "goto" "if"
2767 "implements" "import" "in" "instanceof" "int"
2768 "interface" "let" "long" "native" "new" "package"
2769 "private" "protected" "public" "return" "short"
2770 "static" "super" "switch" "synchronized" "throw"
2771 "throws" "transient" "try" "typeof" "var" "void"
2772 "volatile" "while" "with" "yield"))
2773 (javascript-builtins
2774 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
2775 "arguments" "this")))
2777 (setq font-lock-keywords
2780 ;; Handle the keywords defined above.
2781 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
2782 '(0 font-lock-keyword-face))
2784 ;; Handle the predefined builtins defined above.
2785 (list (concat "\\_<\\(" javascript-builtins "\\)\\_>")
2786 '(0 font-lock-variable-name-face))
2788 ;; Handle numbers too.
2790 ;; The following isn't quite right, but it's close enough.
2791 (list (concat "\\_<\\("
2792 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2793 "[0-9]+\\(\\.[0-9]*\\)?"
2794 "\\([eE][-+]?[0-9]+\\)?\\)"
2796 '(0 mdw-number-face))
2798 ;; And anything else is punctuation.
2799 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2800 '(0 mdw-punct-face))))))
2803 (add-hook 'js-mode-hook 'mdw-misc-mode-config t)
2804 (add-hook 'js-mode-hook 'mdw-fontify-javascript t))
2806 ;;;--------------------------------------------------------------------------
2807 ;;; Scala programming configuration.
2809 (defun mdw-fontify-scala ()
2812 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2814 ;; Define things to be fontified.
2815 (make-local-variable 'font-lock-keywords)
2816 (let ((scala-keywords
2817 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
2818 "extends" "final" "finally" "for" "forSome" "if"
2819 "implicit" "import" "lazy" "match" "new" "object"
2820 "override" "package" "private" "protected" "return"
2821 "sealed" "throw" "trait" "try" "type" "val"
2822 "var" "while" "with" "yield"))
2824 (mdw-regexps "false" "null" "super" "this" "true"))
2825 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
2827 (setq font-lock-keywords
2830 ;; Magical identifiers between backticks.
2831 (list (concat "`\\([^`]+\\)`")
2832 '(1 font-lock-variable-name-face))
2834 ;; Handle the keywords defined above.
2835 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
2836 '(0 font-lock-keyword-face))
2838 ;; Handle the constants defined above.
2839 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
2840 '(0 font-lock-variable-name-face))
2842 ;; Magical identifiers between backticks.
2843 (list (concat "`\\([^`]+\\)`")
2844 '(1 font-lock-variable-name-face))
2846 ;; Handle numbers too.
2848 ;; As usual, not quite right.
2849 (list (concat "\\_<\\("
2850 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2851 "[0-9]+\\(\\.[0-9]*\\)?"
2852 "\\([eE][-+]?[0-9]+\\)?\\)"
2854 '(0 mdw-number-face))
2856 ;; And everything else is punctuation.
2857 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2858 '(0 mdw-punct-face)))
2860 font-lock-syntactic-keywords
2863 ;; Single quotes around characters. But not when used to quote
2864 ;; symbol names. Ugh.
2865 (list (concat "\\('\\)"
2867 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
2868 "u+" "[0-9a-fA-F]\\{4\\}"
2869 "\\|" "\\\\" "[0-7]\\{1,3\\}"
2870 "\\|" "\\\\" "." "\\)"
2876 (add-hook 'scala-mode-hook 'mdw-misc-mode-config t)
2877 (add-hook 'scala-mode-hook 'mdw-fontify-scala t))
2879 ;;;--------------------------------------------------------------------------
2880 ;;; C# programming configuration.
2882 ;; Make indentation nice.
2884 (mdw-define-c-style mdw-csharp ()
2885 (c-basic-offset . 2)
2886 (c-backslash-column . 72)
2887 (c-offsets-alist (substatement-open . 0)
2892 (statement-case-intro . +)))
2893 (mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
2895 ;; Declare C# fontification style.
2897 (defun mdw-fontify-csharp ()
2900 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2902 ;; Now define things to be fontified.
2903 (make-local-variable 'font-lock-keywords)
2904 (let ((csharp-keywords
2905 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
2906 "char" "checked" "class" "const" "continue" "decimal"
2907 "default" "delegate" "do" "double" "else" "enum"
2908 "event" "explicit" "extern" "finally" "fixed" "float"
2909 "for" "foreach" "goto" "if" "implicit" "in" "int"
2910 "interface" "internal" "is" "lock" "long" "namespace"
2911 "new" "object" "operator" "out" "override" "params"
2912 "private" "protected" "public" "readonly" "ref"
2913 "return" "sbyte" "sealed" "short" "sizeof"
2914 "stackalloc" "static" "string" "struct" "switch"
2915 "throw" "try" "typeof" "uint" "ulong" "unchecked"
2916 "unsafe" "ushort" "using" "virtual" "void" "volatile"
2920 (mdw-regexps "base" "false" "null" "this" "true")))
2922 (setq font-lock-keywords
2925 ;; Handle the keywords defined above.
2926 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
2927 '(0 font-lock-keyword-face))
2929 ;; Handle the magic builtins defined above.
2930 (list (concat "\\<\\(" csharp-builtins "\\)\\>")
2931 '(0 font-lock-variable-name-face))
2933 ;; Handle numbers too.
2935 ;; The following isn't quite right, but it's close enough.
2936 (list (concat "\\<\\("
2937 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2938 "[0-9]+\\(\\.[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 (define-derived-mode csharp-mode java-mode "C#"
2948 "Major mode for editing C# code.")
2950 (add-hook 'csharp-mode-hook 'mdw-fontify-csharp t)
2952 ;;;--------------------------------------------------------------------------
2953 ;;; F# programming configuration.
2955 (setq fsharp-indent-offset 2)
2957 (defun mdw-fontify-fsharp ()
2959 (let ((punct "=<>+-*/|&%!@?"))
2961 ((>= i (length punct)))
2962 (modify-syntax-entry (aref punct i) ".")))
2964 (modify-syntax-entry ?_ "_")
2965 (modify-syntax-entry ?( "(")
2966 (modify-syntax-entry ?) ")")
2968 (setq indent-tabs-mode nil)
2970 (let ((fsharp-keywords
2971 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
2973 "checked" "class" "component" "const" "constraint"
2974 "constructor" "continue"
2975 "default" "delegate" "do" "done" "downcast" "downto"
2976 "eager" "elif" "else" "end" "exception" "extern"
2977 "finally" "fixed" "for" "fori" "fun" "function"
2980 "if" "in" "include" "inherit" "inline" "interface"
2983 "match" "measure" "member" "method" "mixin" "module"
2986 "object" "of" "open" "or" "override"
2987 "parallel" "params" "private" "process" "protected"
2989 "rec" "recursive" "return"
2990 "sealed" "sig" "static" "struct"
2991 "tailcall" "then" "to" "trait" "try" "type"
2993 "val" "virtual" "void" "volatile"
2994 "when" "while" "with"
2998 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
2999 "base" "false" "null" "true"))
3002 (mdw-regexps "do" "let" "return" "use" "yield"))
3004 (preprocessor-keywords
3005 (mdw-regexps "if" "indent" "else" "endif")))
3007 (setq font-lock-keywords
3008 (list (list (concat "\\(^\\|[^\"]\\)"
3011 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
3016 '(2 font-lock-comment-face))
3018 (list (concat "'" "\\("
3021 "\\|" "[0-9][0-9][0-9]"
3022 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
3023 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
3029 "\\(" "\\\\" "\\(.\\|\n\\)"
3032 '(0 font-lock-string-face))
3034 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
3035 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
3037 "\\_<\\(" fsharp-keywords "\\)\\_>")
3038 '(0 font-lock-keyword-face))
3039 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
3040 '(0 font-lock-variable-name-face))
3042 (list (concat "\\_<"
3043 "\\(" "0[bB][01]+" "\\|"
3045 "0[xX][0-9a-fA-F]+" "\\)"
3046 "\\(" "lf\\|LF" "\\|"
3047 "[uU]?[ysnlL]?" "\\)"
3054 "\\([eE][-+]?[0-9]+\\)?"
3059 '(0 mdw-number-face))
3061 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3062 '(0 mdw-punct-face))))))
3064 (defun mdw-fontify-inferior-fsharp ()
3065 (mdw-fontify-fsharp)
3066 (setq font-lock-keywords
3067 (append (list (list "^[#-]" '(0 font-lock-comment-face))
3068 (list "^>" '(0 font-lock-keyword-face)))
3069 font-lock-keywords)))
3072 (add-hook 'fsharp-mode-hook 'mdw-misc-mode-config t)
3073 (add-hook 'fsharp-mode-hook 'mdw-fontify-fsharp t)
3074 (add-hook 'inferior-fsharp-mode-hooks 'mdw-fontify-inferior-fsharp t))
3076 ;;;--------------------------------------------------------------------------
3077 ;;; Go programming configuration.
3079 (defun mdw-fontify-go ()
3081 (make-local-variable 'font-lock-keywords)
3083 (mdw-regexps "break" "case" "chan" "const" "continue"
3084 "default" "defer" "else" "fallthrough" "for"
3085 "func" "go" "goto" "if" "import"
3086 "interface" "map" "package" "range" "return"
3087 "select" "struct" "switch" "type" "var"))
3089 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
3090 "float32" "float64" "int" "uint8" "int16" "int32"
3091 "int64" "rune" "string" "uint" "uint8" "uint16"
3092 "uint32" "uint64" "uintptr" "void"
3093 "false" "iota" "nil" "true"
3095 "append" "cap" "copy" "delete" "imag" "len" "make"
3096 "new" "panic" "real" "recover")))
3098 (setq font-lock-keywords
3101 ;; Handle the keywords defined above.
3102 (list (concat "\\<\\(" go-keywords "\\)\\>")
3103 '(0 font-lock-keyword-face))
3104 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
3105 '(0 font-lock-variable-name-face))
3107 ;; Strings and characters.
3109 "\\(" "[^\\']" "\\|"
3111 "\\(" "[abfnrtv\\'\"]" "\\|"
3112 "[0-7]\\{3\\}" "\\|"
3113 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
3114 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
3115 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
3119 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
3123 '(0 font-lock-string-face))
3125 ;; Handle numbers too.
3127 ;; The following isn't quite right, but it's close enough.
3128 (list (concat "\\<\\("
3129 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
3130 "[0-9]+\\(\\.[0-9]*\\)?"
3131 "\\([eE][-+]?[0-9]+\\)?\\)")
3132 '(0 mdw-number-face))
3134 ;; And anything else is punctuation.
3135 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3136 '(0 mdw-punct-face))))))
3138 (add-hook 'go-mode-hook 'mdw-misc-mode-config t)
3139 (add-hook 'go-mode-hook 'mdw-fontify-go t))
3141 ;;;--------------------------------------------------------------------------
3142 ;;; Rust programming configuration.
3144 (setq-default rust-indent-offset 2)
3146 (defun mdw-self-insert-and-indent (count)
3148 (self-insert-command count)
3149 (indent-according-to-mode))
3151 (defun mdw-fontify-rust ()
3153 ;; Hack syntax categories.
3154 (modify-syntax-entry ?$ ".")
3155 (modify-syntax-entry ?% ".")
3156 (modify-syntax-entry ?= ".")
3158 ;; Fontify keywords and things.
3159 (make-local-variable 'font-lock-keywords)
3160 (let ((rust-keywords
3161 (mdw-regexps "abstract" "alignof" "as" "async" "await"
3162 "become" "box" "break"
3163 "const" "continue" "crate"
3165 "else" "enum" "extern"
3169 "macro" "match" "mod" "move" "mut"
3170 "offsetof" "override"
3171 "priv" "proc" "pub" "pure"
3173 "sizeof" "static" "struct" "super"
3174 "trait" "try" "type" "typeof"
3175 "union" "unsafe" "unsized" "use"
3180 (mdw-regexps "array" "pointer" "slice" "tuple"
3181 "bool" "true" "false"
3183 "i8" "i16" "i32" "i64" "isize"
3184 "u8" "u16" "u32" "u64" "usize"
3187 (setq font-lock-keywords
3190 ;; Handle the keywords defined above.
3191 (list (concat "\\_<\\(" rust-keywords "\\)\\_>")
3192 '(0 font-lock-keyword-face))
3193 (list (concat "\\_<\\(" rust-builtins "\\)\\_>")
3194 '(0 font-lock-variable-name-face))
3196 ;; Handle numbers too.
3197 (list (concat "\\_<\\("
3199 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
3203 "\\|" "\\(" "[0-9][0-9_]*"
3204 "\\|" "0x[0-9a-fA-F_]+"
3208 "\\([ui]\\(8\\|16\\|32\\|64\\|size\\)\\)?"
3210 '(0 mdw-number-face))
3212 ;; And anything else is punctuation.
3213 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3214 '(0 mdw-punct-face)))
3215 font-lock-syntactic-face-function . nil))
3217 ;; Hack key bindings.
3218 (local-set-key [?{] 'mdw-self-insert-and-indent)
3219 (local-set-key [?}] 'mdw-self-insert-and-indent))
3222 (add-hook 'rust-mode-hook 'mdw-misc-mode-config t)
3223 (add-hook 'rust-mode-hook 'mdw-fontify-rust t))
3225 ;;;--------------------------------------------------------------------------
3226 ;;; Awk programming configuration.
3228 ;; Make Awk indentation nice.
3230 (mdw-define-c-style mdw-awk ()
3231 (c-basic-offset . 2)
3232 (c-offsets-alist (substatement-open . 0)
3233 (c-backslash-column . 72)
3234 (statement-cont . 0)
3235 (statement-case-intro . +)))
3236 (mdw-set-default-c-style 'awk-mode 'mdw-awk)
3238 ;; Declare Awk fontification style.
3240 (defun mdw-fontify-awk ()
3242 ;; Miscellaneous fiddling.
3243 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3245 ;; Now define things to be fontified.
3246 (make-local-variable 'font-lock-keywords)
3248 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
3249 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
3250 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
3251 "RSTART" "RLENGTH" "RT" "SUBSEP"
3252 "atan2" "break" "close" "continue" "cos" "delete"
3253 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
3254 "function" "gensub" "getline" "gsub" "if" "in"
3255 "index" "int" "length" "log" "match" "next" "rand"
3256 "return" "print" "printf" "sin" "split" "sprintf"
3257 "sqrt" "srand" "strftime" "sub" "substr" "system"
3258 "systime" "tolower" "toupper" "while")))
3260 (setq font-lock-keywords
3263 ;; Handle the keywords defined above.
3264 (list (concat "\\<\\(" c-keywords "\\)\\>")
3265 '(0 font-lock-keyword-face))
3267 ;; Handle numbers too.
3269 ;; The following isn't quite right, but it's close enough.
3270 (list (concat "\\<\\("
3271 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
3272 "[0-9]+\\(\\.[0-9]*\\)?"
3273 "\\([eE][-+]?[0-9]+\\)?\\)"
3275 '(0 mdw-number-face))
3277 ;; And anything else is punctuation.
3278 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3279 '(0 mdw-punct-face))))))
3282 (add-hook 'awk-mode-hook 'mdw-misc-mode-config t)
3283 (add-hook 'awk-mode-hook 'mdw-fontify-awk t))
3285 ;;;--------------------------------------------------------------------------
3286 ;;; Perl programming style.
3288 ;; Perl indentation style.
3290 (setq-default perl-indent-level 2)
3292 (setq-default cperl-indent-level 2
3293 cperl-continued-statement-offset 2
3294 cperl-indent-region-fix-constructs nil
3295 cperl-continued-brace-offset 0
3296 cperl-brace-offset -2
3297 cperl-brace-imaginary-offset 0
3298 cperl-label-offset 0)
3300 ;; Define perl fontification style.
3302 (defun mdw-fontify-perl ()
3304 ;; Miscellaneous fiddling.
3305 (modify-syntax-entry ?$ "\\")
3306 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
3307 (modify-syntax-entry ?: "." font-lock-syntax-table)
3308 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3310 ;; Now define fontification things.
3311 (make-local-variable 'font-lock-keywords)
3312 (let ((perl-keywords
3319 "ge" "given" "gt" "goto"
3321 "last" "le" "local" "lt"
3326 "redo" "require" "return"
3328 "undef" "unless" "until" "use"
3331 (setq font-lock-keywords
3334 ;; Set up the keywords defined above.
3335 (list (concat "\\<\\(" perl-keywords "\\)\\>")
3336 '(0 font-lock-keyword-face))
3338 ;; At least numbers are simpler than C.
3339 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3340 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
3341 "\\([eE][-+]?[0-9_]+\\)?")
3342 '(0 mdw-number-face))
3344 ;; And anything else is punctuation.
3345 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3346 '(0 mdw-punct-face))))))
3348 (defun perl-number-tests (&optional arg)
3349 "Assign consecutive numbers to lines containing `#t'. With ARG,
3350 strip numbers instead."
3353 (goto-char (point-min))
3354 (let ((i 0) (fmt (if arg "" " %4d")))
3355 (while (search-forward "#t" nil t)
3356 (delete-region (point) (line-end-position))
3358 (insert (format fmt i)))
3359 (goto-char (point-min))
3360 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
3361 (replace-match (format "\\1%d" i))))))
3363 (dolist (hook '(perl-mode-hook cperl-mode-hook))
3364 (add-hook hook 'mdw-misc-mode-config t)
3365 (add-hook hook 'mdw-fontify-perl t))
3367 ;;;--------------------------------------------------------------------------
3368 ;;; Python programming style.
3370 (setq-default py-indent-offset 2
3372 python-indent-offset 2
3373 python-fill-docstring-style 'symmetric)
3375 (defun mdw-fontify-pythonic (keywords)
3377 ;; Miscellaneous fiddling.
3378 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3379 (setq indent-tabs-mode nil)
3380 (set (make-local-variable 'forward-sexp-function) nil)
3382 ;; Now define fontification things.
3383 (make-local-variable 'font-lock-keywords)
3384 (setq font-lock-keywords
3387 ;; Set up the keywords defined above.
3388 (list (concat "\\_<\\(" keywords "\\)\\_>")
3389 '(0 font-lock-keyword-face))
3391 ;; At least numbers are simpler than C.
3392 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO]?[0-7]+\\|[bB][01]+\\)\\|"
3393 "\\_<[0-9][0-9]*\\(\\.[0-9]*\\)?"
3394 "\\([eE][-+]?[0-9]+\\|[lL]\\)?")
3395 '(0 mdw-number-face))
3397 ;; And anything else is punctuation.
3398 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3399 '(0 mdw-punct-face)))))
3401 ;; Define Python fontification styles.
3403 (defun mdw-fontify-python ()
3404 (mdw-fontify-pythonic
3405 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
3406 "del" "elif" "else" "except" "exec" "finally" "for"
3407 "from" "global" "if" "import" "in" "is" "lambda"
3408 "not" "or" "pass" "print" "raise" "return" "try"
3409 "while" "with" "yield")))
3411 (defun mdw-fontify-pyrex ()
3412 (mdw-fontify-pythonic
3413 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
3414 "ctypedef" "def" "del" "elif" "else" "enum" "except" "exec"
3415 "extern" "finally" "for" "from" "global" "if"
3416 "import" "in" "is" "lambda" "not" "or" "pass" "print"
3417 "property" "raise" "return" "struct" "try" "while" "with"
3420 (define-derived-mode pyrex-mode python-mode "Pyrex"
3421 "Major mode for editing Pyrex source code")
3422 (setq auto-mode-alist
3423 (append '(("\\.pyx$" . pyrex-mode)
3424 ("\\.pxd$" . pyrex-mode)
3425 ("\\.pxi$" . pyrex-mode))
3429 (add-hook 'python-mode-hook 'mdw-misc-mode-config t)
3430 (add-hook 'python-mode-hook 'mdw-fontify-python t)
3431 (add-hook 'pyrex-mode-hook 'mdw-fontify-pyrex t))
3433 ;;;--------------------------------------------------------------------------
3434 ;;; Lua programming style.
3436 (setq-default lua-indent-level 2)
3438 (defun mdw-fontify-lua ()
3440 ;; Miscellaneous fiddling.
3441 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3443 ;; Now define fontification things.
3444 (make-local-variable 'font-lock-keywords)
3446 (mdw-regexps "and" "break" "do" "else" "elseif" "end"
3447 "false" "for" "function" "goto" "if" "in" "local"
3448 "nil" "not" "or" "repeat" "return" "then" "true"
3450 (setq font-lock-keywords
3453 ;; Set up the keywords defined above.
3454 (list (concat "\\_<\\(" lua-keywords "\\)\\_>")
3455 '(0 font-lock-keyword-face))
3457 ;; At least numbers are simpler than C.
3458 (list (concat "\\_<\\(" "0[xX]"
3459 "\\(" "[0-9a-fA-F]+"
3460 "\\(\\.[0-9a-fA-F]*\\)?"
3461 "\\|" "\\.[0-9a-fA-F]+"
3463 "\\([pP][-+]?[0-9]+\\)?"
3464 "\\|" "\\(" "[0-9]+"
3468 "\\([eE][-+]?[0-9]+\\)?"
3470 '(0 mdw-number-face))
3472 ;; And anything else is punctuation.
3473 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3474 '(0 mdw-punct-face))))))
3477 (add-hook 'lua-mode-hook 'mdw-misc-mode-config t)
3478 (add-hook 'lua-mode-hook 'mdw-fontify-lua t))
3480 ;;;--------------------------------------------------------------------------
3481 ;;; Icon programming style.
3483 ;; Icon indentation style.
3485 (setq-default icon-brace-offset 0
3486 icon-continued-brace-offset 0
3487 icon-continued-statement-offset 2
3488 icon-indent-level 2)
3490 ;; Define Icon fontification style.
3492 (defun mdw-fontify-icon ()
3494 ;; Miscellaneous fiddling.
3495 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3497 ;; Now define fontification things.
3498 (make-local-variable 'font-lock-keywords)
3499 (let ((icon-keywords
3500 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
3501 "end" "every" "fail" "global" "if" "initial"
3502 "invocable" "link" "local" "next" "not" "of"
3503 "procedure" "record" "repeat" "return" "static"
3504 "suspend" "then" "to" "until" "while"))
3505 (preprocessor-keywords
3506 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
3507 "include" "line" "undef")))
3508 (setq font-lock-keywords
3511 ;; Set up the keywords defined above.
3512 (list (concat "\\<\\(" icon-keywords "\\)\\>")
3513 '(0 font-lock-keyword-face))
3515 ;; The things that Icon calls keywords.
3516 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
3518 ;; At least numbers are simpler than C.
3519 (list (concat "\\<[0-9]+"
3520 "\\([rR][0-9a-zA-Z]+\\|"
3521 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
3522 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
3523 '(0 mdw-number-face))
3526 (list (concat "^[ \t]*$[ \t]*\\<\\("
3527 preprocessor-keywords
3529 '(0 font-lock-keyword-face))
3531 ;; And anything else is punctuation.
3532 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3533 '(0 mdw-punct-face))))))
3536 (add-hook 'icon-mode-hook 'mdw-misc-mode-config t)
3537 (add-hook 'icon-mode-hook 'mdw-fontify-icon t))
3539 ;;;--------------------------------------------------------------------------
3542 (defun mdw-fontify-fortran-common ()
3543 (let ((fortran-keywords
3544 (mdw-regexps "access"
3562 "double\\s-*precision"
3563 "else" "elseif" "elsewhere"
3565 "endblock" "endblockdata"
3621 "select" "selectcase" "selecttype"
3632 (fortran-operators (mdw-regexps "and"
3645 (fortran-intrinsics (mdw-regexps "abs" "dabs" "iabs" "cabs"
3646 "atan" "datan" "atan2" "datan2"
3656 "int" "aint" "idint"
3657 "alog" "dlog" "clog"
3669 "sign" "isign" "dsign"
3671 "sqrt" "dsqrt" "csqrt"
3673 (preprocessor-keywords
3674 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
3675 "ident" "if" "ifdef" "ifndef" "import" "include"
3676 "line" "pragma" "unassert" "undef" "warning")))
3677 (setq font-lock-keywords-case-fold-search t
3681 ;; Fontify include files as strings.
3682 (list (concat "^[ \t]*\\#[ \t]*" "include"
3683 "[ \t]*\\(<[^>]+>?\\)")
3684 '(1 font-lock-string-face))
3686 ;; Preprocessor directives are `references'?.
3687 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
3688 preprocessor-keywords
3689 "\\)\\>\\|[0-9]+\\|$\\)\\)")
3690 '(1 font-lock-keyword-face))
3692 ;; Set up the keywords defined above.
3693 (list (concat "\\<\\(" fortran-keywords "\\)\\>")
3694 '(0 font-lock-keyword-face))
3696 ;; Set up the `.foo.' operators.
3697 (list (concat "\\.\\(" fortran-operators "\\)\\.")
3698 '(0 font-lock-keyword-face))
3700 ;; Set up the intrinsic functions.
3701 (list (concat "\\<\\(" fortran-intrinsics "\\)\\>")
3702 '(0 font-lock-variable-name-face))
3705 (list (concat "\\(" "\\<" "[0-9]+" "\\(\\.[0-9]*\\)?"
3708 "\\(" "[de]" "[+-]?" "[0-9]+" "\\)?"
3709 "\\(" "_" "\\sw+" "\\)?"
3710 "\\|" "b'[01]*'" "\\|" "'[01]*'b"
3711 "\\|" "b\"[01]*\"" "\\|" "\"[01]*\"b"
3712 "\\|" "o'[0-7]*'" "\\|" "'[0-7]*'o"
3713 "\\|" "o\"[0-7]*\"" "\\|" "\"[0-7]*\"o"
3714 "\\|" "[xz]'[0-9a-f]*'" "\\|" "'[0-9a-f]*'[xz]"
3715 "\\|" "[xz]\"[0-9a-f]*\"" "\\|" "\"[0-9a-f]*\"[xz]")
3716 '(0 mdw-number-face))
3718 ;; Any anything else is punctuation.
3719 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3720 '(0 mdw-punct-face))))
3722 (modify-syntax-entry ?/ "." font-lock-syntax-table)
3723 (modify-syntax-entry ?< ".")
3724 (modify-syntax-entry ?> ".")))
3726 (defun mdw-fontify-fortran () (mdw-fontify-fortran-common))
3727 (defun mdw-fontify-f90 () (mdw-fontify-fortran-common))
3729 (setq fortran-do-indent 2
3731 fortran-structure-indent 2
3732 fortran-comment-line-start "*"
3733 fortran-comment-indent-style 'relative
3734 fortran-continuation-string "&"
3735 fortran-continuation-indent 4)
3737 (setq f90-do-indent 2
3739 f90-program-indent 2
3740 f90-continuation-indent 4
3741 f90-smart-end-names nil
3742 f90-smart-end 'no-blink)
3745 (add-hook 'fortran-mode-hook 'mdw-misc-mode-config t)
3746 (add-hook 'fortran-mode-hook 'mdw-fontify-fortran t)
3747 (add-hook 'f90-mode-hook 'mdw-misc-mode-config t)
3748 (add-hook 'f90-mode-hook 'mdw-fontify-f90 t))
3750 ;;;--------------------------------------------------------------------------
3753 (defun mdw-fontify-asm ()
3754 (modify-syntax-entry ?' "\"")
3755 (modify-syntax-entry ?. "w")
3756 (modify-syntax-entry ?\n ">")
3757 (setf fill-prefix nil)
3758 (modify-syntax-entry ?. "_")
3759 (modify-syntax-entry ?* ". 23")
3760 (modify-syntax-entry ?/ ". 124b")
3761 (modify-syntax-entry ?\n "> b")
3762 (local-set-key ";" 'self-insert-command)
3763 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
3765 (defun mdw-asm-set-comment ()
3766 (modify-syntax-entry ?; "."
3768 (modify-syntax-entry asm-comment-char "< b")
3769 (setq comment-start (string asm-comment-char ? )))
3770 (add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
3771 (put 'asm-comment-char 'safe-local-variable 'characterp)
3774 (add-hook 'asm-mode-hook 'mdw-misc-mode-config t)
3775 (add-hook 'asm-mode-hook 'mdw-fontify-asm t))
3777 ;;;--------------------------------------------------------------------------
3778 ;;; TCL configuration.
3780 (setq-default tcl-indent-level 2)
3782 (defun mdw-fontify-tcl ()
3784 (modify-syntax-entry ch "."))
3785 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3786 (make-local-variable 'font-lock-keywords)
3787 (setq font-lock-keywords
3789 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3790 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
3791 "\\([eE][-+]?[0-9_]+\\)?")
3792 '(0 mdw-number-face))
3793 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3794 '(0 mdw-punct-face)))))
3797 (add-hook 'tcl-mode-hook 'mdw-misc-mode-config t)
3798 (add-hook 'tcl-mode-hook 'mdw-fontify-tcl t))
3800 ;;;--------------------------------------------------------------------------
3801 ;;; Dylan programming configuration.
3803 (defun mdw-fontify-dylan ()
3805 (make-local-variable 'font-lock-keywords)
3807 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
3808 ;; hook, which undoes all of our configuration.
3809 (setq major-mode 'dylan-mode)
3810 (font-lock-set-defaults)
3812 (let* ((word "[-_a-zA-Z!*@<>$%]+")
3813 (dylan-keywords (mdw-regexps
3815 "C-address" "C-callable-wrapper" "C-function"
3816 "C-mapped-subtype" "C-pointer-type" "C-struct"
3817 "C-subtype" "C-union" "C-variable"
3819 "above" "abstract" "afterwards" "all"
3820 "begin" "below" "block" "by"
3821 "case" "class" "cleanup" "constant" "create"
3823 "else" "elseif" "end" "exception" "export"
3824 "finally" "for" "from" "function"
3827 "if" "in" "instance" "interface" "iterate"
3829 "let" "library" "local"
3830 "macro" "method" "module"
3833 "select" "slot" "subclass"
3835 "unless" "until" "use"
3836 "variable" "virtual"
3838 (sharp-keywords (mdw-regexps
3839 "all-keys" "key" "next" "rest" "include"
3841 (setq font-lock-keywords
3842 (list (list (concat "\\<\\(" dylan-keywords
3843 "\\|" "with\\(out\\)?-" word
3845 '(0 font-lock-keyword-face))
3846 (list (concat "\\<" word ":" "\\|"
3847 "#\\(" sharp-keywords "\\)\\>")
3848 '(0 font-lock-variable-name-face))
3850 "\\([-+]\\|\\<\\)[0-9]+" "\\("
3851 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
3854 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
3857 "\\|" "#x[0-9a-zA-Z]+"
3859 '(0 mdw-number-face))
3861 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
3862 "\\_<[-+*/=<>:&|]+\\_>"
3864 '(0 mdw-punct-face))))))
3867 (add-hook 'dylan-mode-hook 'mdw-misc-mode-config t)
3868 (add-hook 'dylan-mode-hook 'mdw-fontify-dylan t))
3870 ;;;--------------------------------------------------------------------------
3871 ;;; Algol 68 configuration.
3873 (setq-default a68-indent-step 2)
3875 (defun mdw-fontify-algol-68 ()
3877 ;; Fix up the syntax table.
3878 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
3879 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
3880 (modify-syntax-entry ch "." a68-mode-syntax-table))
3882 (make-local-variable 'font-lock-keywords)
3885 (let ((word "COMMENT"))
3886 (do ((regexp (concat "[^" (substring word 0 1) "]+")
3887 (concat regexp "\\|"
3888 (substring word 0 i)
3889 "[^" (substring word i (1+ i)) "]"))
3891 ((>= i (length word)) regexp)))))
3892 (setq font-lock-keywords
3893 (list (list (concat "\\<COMMENT\\>"
3894 "\\(" not-comment "\\)\\{0,5\\}"
3895 "\\(\\'\\|\\<COMMENT\\>\\)")
3896 '(0 font-lock-comment-face))
3897 (list (concat "\\<CO\\>"
3898 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
3899 "\\($\\|\\<CO\\>\\)")
3900 '(0 font-lock-comment-face))
3901 (list "\\<[A-Z_]+\\>"
3902 '(0 font-lock-keyword-face))
3906 "\\([eE][-+]?[0-9]+\\)?"
3908 '(0 mdw-number-face))
3909 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
3910 '(0 mdw-punct-face))))))
3912 (dolist (hook '(a68-mode-hook a68-mode-hooks))
3913 (add-hook hook 'mdw-misc-mode-config t)
3914 (add-hook hook 'mdw-fontify-algol-68 t))
3916 ;;;--------------------------------------------------------------------------
3917 ;;; REXX configuration.
3919 (defun mdw-rexx-electric-* ()
3924 (defun mdw-rexx-indent-newline-indent ()
3927 (if abbrev-mode (expand-abbrev))
3928 (newline-and-indent))
3930 (defun mdw-fontify-rexx ()
3932 ;; Various bits of fiddling.
3933 (setq mdw-auto-indent nil)
3934 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
3935 (local-set-key [?*] 'mdw-rexx-electric-*)
3936 (dolist (ch '(?! ?? ?# ?@ ?$)) (modify-syntax-entry ch "w"))
3937 (dolist (ch '(?¬)) (modify-syntax-entry ch "."))
3938 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
3940 ;; Set up keywords and things for fontification.
3941 (make-local-variable 'font-lock-keywords-case-fold-search)
3942 (setq font-lock-keywords-case-fold-search t)
3944 (setq rexx-indent 2)
3945 (setq rexx-end-indent rexx-indent)
3946 (setq rexx-cont-indent rexx-indent)
3948 (make-local-variable 'font-lock-keywords)
3949 (let ((rexx-keywords
3950 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
3951 "else" "end" "engineering" "exit" "expose" "for"
3952 "forever" "form" "fuzz" "if" "interpret" "iterate"
3953 "leave" "linein" "name" "nop" "numeric" "off" "on"
3954 "options" "otherwise" "parse" "procedure" "pull"
3955 "push" "queue" "return" "say" "select" "signal"
3956 "scientific" "source" "then" "trace" "to" "until"
3957 "upper" "value" "var" "version" "when" "while"
3960 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
3961 "center" "center" "charin" "charout" "chars"
3962 "compare" "condition" "copies" "c2d" "c2x"
3963 "datatype" "date" "delstr" "delword" "d2c" "d2x"
3964 "errortext" "format" "fuzz" "insert" "lastpos"
3965 "left" "length" "lineout" "lines" "max" "min"
3966 "overlay" "pos" "queued" "random" "reverse" "right"
3967 "sign" "sourceline" "space" "stream" "strip"
3968 "substr" "subword" "symbol" "time" "translate"
3969 "trunc" "value" "verify" "word" "wordindex"
3970 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
3973 (setq font-lock-keywords
3976 ;; Set up the keywords defined above.
3977 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
3978 '(0 font-lock-keyword-face))
3980 ;; Fontify all symbols the same way.
3981 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
3982 "[A-Za-z0-9.!?_#@$]+\\)")
3983 '(0 font-lock-variable-name-face))
3985 ;; And everything else is punctuation.
3986 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3987 '(0 mdw-punct-face))))))
3990 (add-hook 'rexx-mode-hook 'mdw-misc-mode-config t)
3991 (add-hook 'rexx-mode-hook 'mdw-fontify-rexx t))
3993 ;;;--------------------------------------------------------------------------
3994 ;;; Standard ML programming style.
3996 (setq-default sml-nested-if-indent t
3999 sml-type-of-indent nil)
4001 (defun mdw-fontify-sml ()
4003 ;; Make underscore an honorary letter.
4004 (modify-syntax-entry ?' "w")
4007 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
4009 ;; Now define fontification things.
4010 (make-local-variable 'font-lock-keywords)
4012 (mdw-regexps "abstype" "and" "andalso" "as"
4015 "else" "end" "eqtype" "exception"
4016 "fn" "fun" "functor"
4018 "if" "in" "include" "infix" "infixr"
4021 "of" "op" "open" "orelse"
4023 "sharing" "sig" "signature" "struct" "structure"
4026 "where" "while" "with" "withtype")))
4028 (setq font-lock-keywords
4031 ;; Set up the keywords defined above.
4032 (list (concat "\\<\\(" sml-keywords "\\)\\>")
4033 '(0 font-lock-keyword-face))
4035 ;; At least numbers are simpler than C.
4036 (list (concat "\\<\\~?"
4037 "\\(0\\([wW]?[xX][0-9a-fA-F]+\\|"
4039 "\\([0-9]+\\(\\.[0-9]+\\)?"
4042 '(0 mdw-number-face))
4044 ;; And anything else is punctuation.
4045 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4046 '(0 mdw-punct-face))))))
4049 (add-hook 'sml-mode-hook 'mdw-misc-mode-config t)
4050 (add-hook 'sml-mode-hook 'mdw-fontify-sml t))
4052 ;;;--------------------------------------------------------------------------
4053 ;;; Haskell configuration.
4055 (setq-default haskell-indent-offset 2)
4057 (defun mdw-fontify-haskell ()
4059 ;; Fiddle with syntax table to get comments right.
4060 (modify-syntax-entry ?' "_")
4061 (modify-syntax-entry ?- ". 12")
4062 (modify-syntax-entry ?\n ">")
4064 ;; Make punctuation be punctuation
4065 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
4067 ((>= i (length punct)))
4068 (modify-syntax-entry (aref punct i) ".")))
4071 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
4073 ;; Fiddle with fontification.
4074 (make-local-variable 'font-lock-keywords)
4075 (let ((haskell-keywords
4077 "case" "ccall" "class"
4078 "data" "default" "deriving" "do"
4082 "if" "import" "in" "infix" "infixl" "infixr" "instance"
4095 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
4096 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
4097 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
4098 "SP" "STX" "SUB" "SYN" "US" "VT")))
4100 (setq font-lock-keywords
4102 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
4106 '(0 font-lock-comment-face))
4107 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
4108 '(0 font-lock-keyword-face))
4109 (list (concat "'\\("
4113 "\\(" "[abfnrtv\\\"']" "\\|"
4114 "^" "\\(" control-sequences "\\|"
4115 "[]A-Z@[\\^_]" "\\)" "\\|"
4122 '(0 font-lock-string-face))
4123 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
4124 '(0 font-lock-variable-name-face))
4125 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
4126 "\\_<[0-9]+\\(\\.[0-9]*\\)?"
4127 "\\([eE][-+]?[0-9]+\\)?")
4128 '(0 mdw-number-face))
4129 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4130 '(0 mdw-punct-face))))))
4133 (add-hook 'haskell-mode-hook 'mdw-misc-mode-config t)
4134 (add-hook 'haskell-mode-hook 'mdw-fontify-haskell t))
4136 ;;;--------------------------------------------------------------------------
4137 ;;; Erlang configuration.
4139 (setq-default erlang-electric-commands nil)
4141 (defun mdw-fontify-erlang ()
4144 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
4146 ;; Fiddle with fontification.
4147 (make-local-variable 'font-lock-keywords)
4148 (let ((erlang-keywords
4149 (mdw-regexps "after" "and" "andalso"
4150 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
4151 "case" "catch" "cond"
4152 "div" "end" "fun" "if" "let" "not"
4154 "query" "receive" "rem" "try" "when" "xor")))
4156 (setq font-lock-keywords
4159 '(0 font-lock-comment-face))
4160 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
4161 '(0 font-lock-keyword-face))
4162 (list (concat "^-\\sw+\\>")
4163 '(0 font-lock-keyword-face))
4164 (list "\\<[0-9]+\\(#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)?\\>"
4165 '(0 mdw-number-face))
4166 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4167 '(0 mdw-punct-face))))))
4170 (add-hook 'erlang-mode-hook 'mdw-misc-mode-config t)
4171 (add-hook 'erlang-mode-hook 'mdw-fontify-erlang t))
4173 ;;;--------------------------------------------------------------------------
4174 ;;; Texinfo configuration.
4176 (defun mdw-fontify-texinfo ()
4179 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
4181 ;; Real fontification things.
4182 (make-local-variable 'font-lock-keywords)
4183 (setq font-lock-keywords
4186 ;; Environment names are keywords.
4187 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
4188 '(2 font-lock-keyword-face))
4190 ;; Unmark escaped magic characters.
4191 (list "\\(@\\)\\([@{}]\\)"
4192 '(1 font-lock-keyword-face)
4193 '(2 font-lock-variable-name-face))
4195 ;; Make sure we get comments properly.
4196 (list "@c\\(omment\\)?\\( .*\\)?$"
4197 '(0 font-lock-comment-face))
4199 ;; Command names are keywords.
4200 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
4201 '(0 font-lock-keyword-face))
4203 ;; Fontify TeX special characters as punctuation.
4205 '(0 mdw-punct-face)))))
4207 (dolist (hook '(texinfo-mode-hook TeXinfo-mode-hook))
4208 (add-hook hook 'mdw-misc-mode-config t)
4209 (add-hook hook 'mdw-fontify-texinfo t))
4211 ;;;--------------------------------------------------------------------------
4212 ;;; TeX and LaTeX configuration.
4214 (setq-default LaTeX-table-label "tbl:"
4215 TeX-auto-untabify nil
4216 LaTeX-syntactic-comments nil
4217 LaTeX-fill-break-at-separators '(\\\[))
4219 (defun mdw-fontify-tex ()
4220 (setq ispell-parser 'tex)
4223 ;; Don't make maths into a string.
4224 (modify-syntax-entry ?$ ".")
4225 (modify-syntax-entry ?$ "." font-lock-syntax-table)
4226 (local-set-key [?$] 'self-insert-command)
4228 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
4229 (local-set-key "\C-\M-i" 'indent-relative)
4230 (setq indent-tabs-mode nil)
4233 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
4235 ;; Real fontification things.
4236 (make-local-variable 'font-lock-keywords)
4237 (setq font-lock-keywords
4240 ;; Environment names are keywords.
4241 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
4243 '(2 font-lock-keyword-face))
4245 ;; Suspended environment names are keywords too.
4246 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
4248 '(3 font-lock-keyword-face))
4250 ;; Command names are keywords.
4251 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
4252 '(0 font-lock-keyword-face))
4254 ;; Handle @/.../ for italics.
4255 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
4256 ;; '(1 font-lock-keyword-face)
4257 ;; '(3 font-lock-keyword-face))
4259 ;; Handle @*...* for boldness.
4260 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
4261 ;; '(1 font-lock-keyword-face)
4262 ;; '(3 font-lock-keyword-face))
4264 ;; Handle @`...' for literal syntax things.
4265 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
4266 ;; '(1 font-lock-keyword-face)
4267 ;; '(3 font-lock-keyword-face))
4269 ;; Handle @<...> for nonterminals.
4270 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
4271 ;; '(1 font-lock-keyword-face)
4272 ;; '(3 font-lock-keyword-face))
4274 ;; Handle other @-commands.
4275 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
4276 ;; '(0 font-lock-keyword-face))
4278 ;; Make sure we get comments properly.
4280 '(0 font-lock-comment-face))
4282 ;; Fontify TeX special characters as punctuation.
4284 '(0 mdw-punct-face)))))
4286 (setq TeX-install-font-lock 'tex-font-setup)
4288 (eval-after-load 'font-latex
4289 '(defun font-latex-jit-lock-force-redisplay (buf start end)
4290 "Compatibility for Emacsen not offering `jit-lock-force-redisplay'."
4291 ;; The following block is an expansion of `jit-lock-force-redisplay'
4292 ;; and involved macros taken from CVS Emacs on 2007-04-28.
4293 (with-current-buffer buf
4294 (let ((modified (buffer-modified-p)))
4296 (let ((buffer-undo-list t)
4297 (inhibit-read-only t)
4298 (inhibit-point-motion-hooks t)
4299 (inhibit-modification-hooks t)
4302 buffer-file-truename)
4303 (put-text-property start end 'fontified t))
4305 (restore-buffer-modified-p nil)))))))
4307 (setq TeX-output-view-style
4309 ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$")
4310 "%(o?)dvips -t landscape %d -o && xdg-open %f")
4311 ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$"
4312 "%(o?)dvips %d -o && xdg-open %f")
4314 ("^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "^landscape$")
4315 "%(o?)xdvi %dS -paper a4r -s 0 %d")
4316 ("^dvi$" "^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$"
4317 "%(o?)xdvi %dS -paper a4 %d")
4319 ("^a5\\(?:comb\\|paper\\)$" "^landscape$")
4320 "%(o?)xdvi %dS -paper a5r -s 0 %d")
4321 ("^dvi$" "^a5\\(?:comb\\|paper\\)$" "%(o?)xdvi %dS -paper a5 %d")
4322 ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
4323 ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d")
4324 ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
4325 ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
4326 ("^dvi$" "." "%(o?)xdvi %dS %d")
4327 ("^pdf$" "." "xdg-open %o")
4328 ("^html?$" "." "sensible-browser %o")))
4330 (setq TeX-view-program-list
4331 '(("mupdf" ("mupdf %o" (mode-io-correlate " %(outpage)")))))
4333 (setq TeX-view-program-selection
4334 '(((output-dvi style-pstricks) "dvips and gv")
4336 (output-pdf "mupdf")
4337 (output-html "sensible-browser")))
4339 (setq TeX-open-quote "\""
4340 TeX-close-quote "\"")
4342 (setq reftex-use-external-file-finders t
4343 reftex-auto-recenter-toc t)
4345 (setq reftex-label-alist
4346 '(("theorem" ?T "th:" "~\\ref{%s}" t ("theorems?" "th\\.") -2)
4347 ("axiom" ?A "ax:" "~\\ref{%s}" t ("axioms?" "ax\\.") -2)
4348 ("definition" ?D "def:" "~\\ref{%s}" t ("definitions?" "def\\.") -2)
4349 ("proposition" ?P "prop:" "~\\ref{%s}" t
4350 ("propositions?" "prop\\.") -2)
4351 ("lemma" ?L "lem:" "~\\ref{%s}" t ("lemmas?" "lem\\.") -2)
4352 ("example" ?X "eg:" "~\\ref{%s}" t ("examples?") -2)
4353 ("exercise" ?E "ex:" "~\\ref{%s}" t ("exercises?" "ex\\.") -2)
4354 ("enumerate" ?i "i:" "~\\ref{%s}" item ("items?"))))
4355 (setq reftex-section-prefixes
4360 (setq bibtex-field-delimiters 'double-quotes
4361 bibtex-align-at-equal-sign t
4362 bibtex-entry-format '(realign opts-or-alts required-fields
4363 numerical-fields last-comma delimiters
4364 unify-case sort-fields braces)
4365 bibtex-sort-ignore-string-entries nil
4366 bibtex-maintain-sorted-entries 'entry-class
4367 bibtex-include-OPTkey t
4368 bibtex-autokey-names-stretch 1
4369 bibtex-autokey-expand-strings t
4370 bibtex-autokey-name-separator "-"
4371 bibtex-autokey-year-length 4
4372 bibtex-autokey-titleword-separator "-"
4373 bibtex-autokey-name-year-separator "-"
4374 bibtex-autokey-year-title-separator ":")
4377 (dolist (hook '(tex-mode-hook latex-mode-hook
4378 TeX-mode-hook LaTeX-mode-hook))
4379 (add-hook hook 'mdw-misc-mode-config t)
4380 (add-hook hook 'mdw-fontify-tex t))
4381 (add-hook 'bibtex-mode-hook (lambda () (setq fill-column 76))))
4383 ;;;--------------------------------------------------------------------------
4384 ;;; HTML, CSS, and other web foolishness.
4386 (setq-default css-indent-offset 8)
4388 ;;;--------------------------------------------------------------------------
4391 (setq-default psgml-html-build-new-buffer nil)
4393 (defun mdw-sgml-mode ()
4396 (mdw-standard-fill-prefix "")
4397 (make-local-variable 'sgml-delimiters)
4398 (setq sgml-delimiters
4399 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
4400 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT"
4401 "\"" "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]"
4402 "NESTC" "{" "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">"
4403 "PIO" "<?" "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" ","
4404 "STAGO" ":" "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
4405 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE"
4407 (setq major-mode 'mdw-sgml-mode)
4408 (setq mode-name "[mdw] SGML")
4409 (run-hooks 'mdw-sgml-mode-hook))
4411 ;;;--------------------------------------------------------------------------
4412 ;;; Configuration files.
4414 (defcustom mdw-conf-quote-normal nil
4415 "Control syntax category of quote characters `\"' and `''.
4416 If this is `t', consider quote characters to be normal
4417 punctuation, as for `conf-quote-normal'. If this is `nil' then
4418 leave quote characters as quotes. If this is a list, then
4419 consider the quote characters in the list to be normal
4420 punctuation. If this is a single quote character, then consider
4421 that character only to be normal punctuation."
4422 :type '(choice boolean character (repeat character))
4423 :safe 'mdw-conf-quote-normal-acceptable-value-p)
4424 (defun mdw-conf-quote-normal-acceptable-value-p (value)
4425 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
4426 (or (booleanp value)
4427 (every (lambda (v) (memq v '(?\" ?')))
4428 (if (listp value) value (list value)))))
4430 (defun mdw-fix-up-quote ()
4431 "Apply the setting of `mdw-conf-quote-normal'."
4432 (let ((flag mdw-conf-quote-normal))
4434 (conf-quote-normal t))
4438 (let ((table (copy-syntax-table (syntax-table))))
4439 (dolist (ch (if (listp flag) flag (list flag)))
4440 (modify-syntax-entry ch "." table))
4441 (set-syntax-table table)
4442 (and font-lock-mode (font-lock-fontify-buffer)))))))
4445 (add-hook 'conf-mode-hook 'mdw-misc-mode-config t)
4446 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t))
4448 ;;;--------------------------------------------------------------------------
4451 (defun mdw-setup-sh-script-mode ()
4453 ;; Fetch the shell interpreter's name.
4454 (let ((shell-name sh-shell-file))
4456 ;; Try reading the hash-bang line.
4458 (goto-char (point-min))
4459 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
4460 (setq shell-name (match-string 1))))
4462 ;; Now try to set the shell.
4464 ;; Don't let `sh-set-shell' bugger up my script.
4465 (let ((executable-set-magic #'(lambda (s &rest r) s)))
4466 (sh-set-shell shell-name)))
4468 ;; Don't insert here-document scaffolding automatically.
4469 (local-set-key "<" 'self-insert-command)
4471 ;; Now enable my keys and the fontification.
4472 (mdw-misc-mode-config)
4474 ;; Set the indentation level correctly.
4475 (setq sh-indentation 2)
4476 (setq sh-basic-offset 2))
4478 (setq sh-shell-file "/bin/sh")
4480 ;; Awful hacking to override the shell detection for particular scripts.
4481 (defmacro define-custom-shell-mode (name shell)
4484 (set (make-local-variable 'sh-shell-file) ,shell)
4486 (define-custom-shell-mode bash-mode "/bin/bash")
4487 (define-custom-shell-mode rc-mode "/usr/bin/rc")
4488 (put 'sh-shell-file 'permanent-local t)
4490 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
4491 (eval-after-load "sh-script"
4492 '(or (assq 'rc sh-mode-syntax-table-input)
4509 (assoc (assq 'rc sh-mode-syntax-table-input)))
4512 (setq sh-mode-syntax-table-input
4513 (cons (cons 'rc frag)
4514 sh-mode-syntax-table-input))))))
4517 (add-hook 'sh-mode-hook 'mdw-misc-mode-config t)
4518 (add-hook 'sh-mode-hook 'mdw-setup-sh-script-mode t))
4520 ;;;--------------------------------------------------------------------------
4521 ;;; Emacs shell mode.
4523 (defun mdw-eshell-prompt ()
4524 (let ((left "[") (right "]"))
4525 (when (= (user-uid) 0)
4526 (setq left "«" right "»"))
4529 (replace-regexp-in-string "\\..*$" "" (system-name)))
4531 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
4532 (home (expand-file-name "~")) (nhome (length home)))
4533 (if (and (>= npwd nhome)
4535 (= (elt pwd nhome) ?/))
4536 (string= (substring pwd 0 nhome) home))
4537 (concat "~" (substring pwd (length home)))
4540 (setq-default eshell-prompt-function 'mdw-eshell-prompt)
4541 (setq-default eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
4543 (defun eshell/e (file) (find-file file) nil)
4544 (defun eshell/ee (file) (find-file-other-window file) nil)
4545 (defun eshell/w3m (url) (w3m-goto-url url) nil)
4547 (mdw-define-face eshell-prompt (t :weight bold))
4548 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
4549 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
4550 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
4551 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
4552 (mdw-define-face eshell-ls-executable (t :weight bold))
4553 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
4554 (mdw-define-face eshell-ls-readonly (t nil))
4555 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
4557 (defun mdw-eshell-hack () (setenv "LD_PRELOAD" nil))
4558 (add-hook 'eshell-mode-hook 'mdw-eshell-hack)
4560 ;;;--------------------------------------------------------------------------
4561 ;;; Messages-file mode.
4563 (defun messages-mode-guts ()
4564 (setq messages-mode-syntax-table (make-syntax-table))
4565 (set-syntax-table messages-mode-syntax-table)
4566 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
4567 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
4568 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
4569 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
4570 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
4571 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
4572 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
4573 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
4574 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
4575 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
4576 (make-local-variable 'comment-start)
4577 (make-local-variable 'comment-end)
4578 (make-local-variable 'indent-line-function)
4579 (setq indent-line-function 'indent-relative)
4580 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4581 (make-local-variable 'font-lock-defaults)
4582 (make-local-variable 'messages-mode-keywords)
4584 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
4585 "export" "enum" "fixed-octetstring" "flags"
4586 "harmless" "map" "nested" "optional"
4587 "optional-tagged" "package" "primitive"
4588 "primitive-nullfree" "relaxed[ \t]+enum"
4589 "set" "table" "tagged-optional" "union"
4590 "variadic" "vector" "version" "version-tag")))
4591 (setq messages-mode-keywords
4593 (list (concat "\\<\\(" keywords "\\)\\>:")
4594 '(0 font-lock-keyword-face))
4595 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
4596 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
4597 (0 font-lock-variable-name-face))
4598 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
4599 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4600 (0 mdw-punct-face)))))
4601 (setq font-lock-defaults
4602 '(messages-mode-keywords nil nil nil nil))
4603 (run-hooks 'messages-file-hook))
4605 (defun messages-mode ()
4608 (setq major-mode 'messages-mode)
4609 (setq mode-name "Messages")
4610 (messages-mode-guts)
4611 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
4612 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
4613 (setq comment-start "# ")
4614 (setq comment-end "")
4615 (run-hooks 'messages-mode-hook))
4617 (defun cpp-messages-mode ()
4620 (setq major-mode 'cpp-messages-mode)
4621 (setq mode-name "CPP Messages")
4622 (messages-mode-guts)
4623 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
4624 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
4625 (setq comment-start "/* ")
4626 (setq comment-end " */")
4627 (let ((preprocessor-keywords
4628 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
4629 "ident" "if" "ifdef" "ifndef" "import" "include"
4630 "line" "pragma" "unassert" "undef" "warning")))
4631 (setq messages-mode-keywords
4632 (append (list (list (concat "^[ \t]*\\#[ \t]*"
4633 "\\(include\\|import\\)"
4634 "[ \t]*\\(<[^>]+\\(>\\)?\\)")
4635 '(2 font-lock-string-face))
4636 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
4637 preprocessor-keywords
4638 "\\)\\>\\|[0-9]+\\|$\\)\\)")
4639 '(1 font-lock-keyword-face)))
4640 messages-mode-keywords)))
4641 (run-hooks 'cpp-messages-mode-hook))
4644 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
4645 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
4646 ;; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
4649 ;;;--------------------------------------------------------------------------
4650 ;;; Messages-file mode.
4652 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
4653 "Face to use for subsittution directives.")
4654 (make-face 'mallow-driver-substitution-face)
4655 (defvar mallow-driver-text-face 'mallow-driver-text-face
4656 "Face to use for body text.")
4657 (make-face 'mallow-driver-text-face)
4659 (defun mallow-driver-mode ()
4662 (setq major-mode 'mallow-driver-mode)
4663 (setq mode-name "Mallow driver")
4664 (setq mallow-driver-mode-syntax-table (make-syntax-table))
4665 (set-syntax-table mallow-driver-mode-syntax-table)
4666 (make-local-variable 'comment-start)
4667 (make-local-variable 'comment-end)
4668 (make-local-variable 'indent-line-function)
4669 (setq indent-line-function 'indent-relative)
4670 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4671 (make-local-variable 'font-lock-defaults)
4672 (make-local-variable 'mallow-driver-mode-keywords)
4674 (mdw-regexps "each" "divert" "file" "if"
4675 "perl" "set" "string" "type" "write")))
4676 (setq mallow-driver-mode-keywords
4678 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
4679 '(0 font-lock-keyword-face))
4680 (list "^%\\s *\\(#.*\\)?$"
4681 '(0 font-lock-comment-face))
4683 '(0 font-lock-keyword-face))
4684 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
4686 '(0 mallow-driver-substitution-face t)))))
4687 (setq font-lock-defaults
4688 '(mallow-driver-mode-keywords nil nil nil nil))
4689 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
4690 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
4691 (setq comment-start "%# ")
4692 (setq comment-end "")
4693 (run-hooks 'mallow-driver-mode-hook))
4696 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t))
4698 ;;;--------------------------------------------------------------------------
4701 (defun nfast-debug-mode ()
4704 (setq major-mode 'nfast-debug-mode)
4705 (setq mode-name "NFast debug")
4706 (setq messages-mode-syntax-table (make-syntax-table))
4707 (set-syntax-table messages-mode-syntax-table)
4708 (make-local-variable 'font-lock-defaults)
4709 (make-local-variable 'nfast-debug-mode-keywords)
4710 (setq truncate-lines t)
4711 (setq nfast-debug-mode-keywords
4713 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
4714 (0 font-lock-keyword-face))
4715 (list (concat "^[ \t]+\\(\\("
4716 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4717 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4719 "[0-9a-fA-F]+\\)[ \t]*$")
4720 '(0 mdw-number-face))
4721 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
4722 (1 font-lock-keyword-face))
4723 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
4724 (1 font-lock-warning-face))
4725 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
4727 (list (concat "^[ \t]+\\.cmd=[ \t]+"
4728 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
4729 '(1 font-lock-keyword-face))
4730 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
4731 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
4732 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
4733 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
4734 (setq font-lock-defaults
4735 '(nfast-debug-mode-keywords nil nil nil nil))
4736 (run-hooks 'nfast-debug-mode-hook))
4738 ;;;--------------------------------------------------------------------------
4739 ;;; Lispy languages.
4741 ;; Unpleasant bodge.
4742 (unless (boundp 'slime-repl-mode-map)
4743 (setq slime-repl-mode-map (make-sparse-keymap)))
4745 (defun mdw-indent-newline-and-indent ()
4747 (indent-for-tab-command)
4748 (newline-and-indent))
4750 (eval-after-load "cl-indent"
4752 (mapc #'(lambda (pair)
4754 'common-lisp-indent-function
4756 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
4757 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
4759 (defun mdw-common-lisp-indent ()
4760 (make-local-variable 'lisp-indent-function)
4761 (setq lisp-indent-function 'common-lisp-indent-function))
4763 (defmacro mdw-advise-hyperspec-lookup (func args)
4764 `(defadvice ,func (around mdw-browse-w3m ,args activate compile)
4766 (let ((browse-url-browser-function #'mdw-w3m-browse-url))
4769 (mdw-advise-hyperspec-lookup common-lisp-hyperspec (symbol))
4770 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-format (char))
4771 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-lookup-reader-macro (char))
4773 (defun mdw-fontify-lispy ()
4776 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
4778 ;; Not much fontification needed.
4779 (make-local-variable 'font-lock-keywords)
4780 (setq font-lock-keywords
4781 (list (list (concat "\\("
4783 "\\(" "[0-9]+/[0-9]+"
4784 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
4786 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
4791 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
4792 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
4793 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
4794 "\\|" "[0-9]+" "r" "[-+]?"
4795 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
4798 '(0 mdw-number-face))
4799 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4800 '(0 mdw-punct-face)))))
4802 ;; Special indentation.
4804 (defcustom mdw-lisp-loop-default-indent 2
4805 "Default indent for simple `loop' body."
4808 (defcustom mdw-lisp-setf-value-indent 2
4809 "Default extra indent for `setf' values."
4810 :type 'integer :safe 'integerp)
4812 (setq lisp-simple-loop-indentation 0
4813 lisp-loop-keyword-indentation 0
4814 lisp-loop-forms-indentation 2
4815 lisp-lambda-list-keyword-parameter-alignment t)
4817 (defun mdw-indent-funcall
4818 (path state &optional indent-point sexp-column normal-indent)
4819 "Indent `funcall' more usefully.
4820 Essentially, treat `funcall foo' as a function name, and align the arguments
4822 (and (or (not (consp path)) (null (cadr path)))
4824 (goto-char (cadr state))
4826 (let ((start-line (line-number-at-pos)))
4827 (and (condition-case nil (progn (forward-sexp 3) t)
4831 (and (= start-line (line-number-at-pos))
4832 (current-column))))))))
4834 (put 'funcall 'common-lisp-indent-function 'mdw-indent-funcall)
4835 (put 'funcall 'lisp-indent-function 'mdw-indent-funcall))
4837 (defun mdw-indent-setf
4838 (path state &optional indent-point sexp-column normal-indent)
4839 "Indent `setf' more usefully.
4840 If the values aren't on the same lines as their variables then indent them
4841 by `mdw-lisp-setf-value-indent' spaces."
4842 (and (or (not (consp path)) (null (cadr path)))
4843 (let ((basic-indent (save-excursion
4844 (goto-char (cadr state))
4846 (and (condition-case nil
4847 (progn (forward-sexp 2) t)
4851 (current-column)))))
4852 (offset (if (consp path) (car path)
4857 (goto-char (cadr state))
4859 (while (< (point) start)
4860 (condition-case nil (forward-sexp 1)
4861 (scan-error (throw 'done nil)))
4864 (and basic-indent offset
4865 (list (+ basic-indent
4867 mdw-lisp-setf-value-indent))
4870 (put 'setf 'common-lisp-indent-functopion 'mdw-indent-setf)
4871 (put 'psetf 'common-lisp-indent-function 'mdw-indent-setf)
4872 (put 'setq 'common-lisp-indent-function 'mdw-indent-setf)
4873 (put 'setf 'lisp-indent-function 'mdw-indent-setf)
4874 (put 'setq 'lisp-indent-function 'mdw-indent-setf)
4875 (put 'setq-local 'lisp-indent-function 'mdw-indent-setf)
4876 (put 'setq-default 'lisp-indent-function 'mdw-indent-setf))
4878 (defadvice common-lisp-loop-part-indentation
4879 (around mdw-fix-loop-indentation (indent-point state) activate compile)
4880 "Improve `loop' indentation.
4881 If the first subform is on the same line as the `loop' keyword, then
4882 align the other subforms beneath it. Otherwise, indent them
4883 `mdw-lisp-loop-default-indent' columns in from the opening parenthesis."
4885 (let* ((loop-indentation (save-excursion
4886 (goto-char (elt state 1))
4889 ;; Don't really care about this.
4890 (when (and (boundp 'lisp-indent-backquote-substitution-mode)
4891 (eq lisp-indent-backquote-substitution-mode 'corrected))
4893 (goto-char (elt state 1))
4894 (incf loop-indentation
4895 (cond ((eq (char-before) ?,) -1)
4896 ((and (eq (char-before) ?@)
4897 (progn (backward-char)
4898 (eq (char-before) ?,)))
4902 ;; If the first loop item is on the same line as the `loop' itself then
4903 ;; use that as the baseline. Otherwise advance by the default indent.
4904 (goto-char (cadr state))
4906 (let ((baseline-indent
4907 (if (= (line-number-at-pos)
4908 (if (condition-case nil (progn (forward-sexp 2) t)
4910 (progn (forward-sexp -1) (line-number-at-pos))
4913 (+ loop-indentation mdw-lisp-loop-default-indent))))
4915 (goto-char indent-point)
4918 (setq ad-return-value
4920 (cond ((condition-case ()
4922 (goto-char (elt state 1))
4926 (not (looking-at "\\(:\\|\\sw\\)")))
4928 (+ baseline-indent lisp-simple-loop-indentation))
4929 ((looking-at "^\\s-*\\(:?\\sw+\\|;\\)")
4930 (+ baseline-indent lisp-loop-keyword-indentation))
4932 (+ baseline-indent lisp-loop-forms-indentation)))
4934 ;; Tell the caller that the next line needs recomputation,
4935 ;; even though it doesn't start a sexp.
4936 loop-indentation)))))
4940 (defcustom mdw-friendly-name "[mdw]"
4941 "How I want to be addressed."
4944 (defadvice slime-user-first-name
4945 (around mdw-use-friendly-name compile activate)
4946 (if mdw-friendly-name (setq ad-return-value mdw-friendly-name)
4951 (if (not mdw-fast-startup)
4953 (require 'slime-autoloads)
4954 (slime-setup '(slime-autodoc slime-c-p-c))))))
4956 (let ((stuff '((cmucl ("cmucl"))
4957 (sbcl ("sbcl") :coding-system utf-8-unix)
4958 (clisp ("clisp") :coding-system utf-8-unix))))
4959 (or (boundp 'slime-lisp-implementations)
4960 (setq slime-lisp-implementations nil))
4962 (let* ((head (car stuff))
4963 (found (assq (car head) slime-lisp-implementations)))
4964 (setq stuff (cdr stuff))
4966 (rplacd found (cdr head))
4967 (setq slime-lisp-implementations
4968 (cons head slime-lisp-implementations))))))
4969 (setq slime-default-lisp 'sbcl)
4974 (dolist (hook '(emacs-lisp-mode-hook
4977 inferior-lisp-mode-hook
4978 lisp-interaction-mode-hook
4980 slime-repl-mode-hook))
4981 (add-hook hook 'mdw-misc-mode-config t)
4982 (add-hook hook 'mdw-fontify-lispy t))
4983 (add-hook 'lisp-mode-hook 'mdw-common-lisp-indent t)
4984 (add-hook 'inferior-lisp-mode-hook
4985 #'(lambda () (local-set-key "\C-m" 'comint-send-and-indent)) t))
4987 ;;;--------------------------------------------------------------------------
4988 ;;; Other languages.
4992 (defun mdw-setup-smalltalk ()
4993 (and mdw-auto-indent
4994 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
4995 (make-local-variable 'mdw-auto-indent)
4996 (setq mdw-auto-indent nil)
4997 (local-set-key "\C-i" 'smalltalk-reindent))
4999 (defun mdw-fontify-smalltalk ()
5000 (make-local-variable 'font-lock-keywords)
5001 (setq font-lock-keywords
5003 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
5004 '(0 font-lock-keyword-face))
5005 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
5006 "[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
5007 "\\([eE][-+]?[0-9_]+\\)?")
5008 '(0 mdw-number-face))
5009 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
5010 '(0 mdw-punct-face)))))
5013 (add-hook 'smalltalk-mode 'mdw-misc-mode-config t)
5014 (add-hook 'smalltalk-mode 'mdw-fontify-smalltalk t))
5018 (defun mdw-setup-m4 ()
5020 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
5021 ;; annoying: fix it.
5022 (modify-syntax-entry ?{ "(")
5023 (modify-syntax-entry ?} ")")
5026 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
5028 (dolist (hook '(m4-mode-hook autoconf-mode-hook autotest-mode-hook))
5029 (add-hook hook #'mdw-misc-mode-config t)
5030 (add-hook hook #'mdw-setup-m4 t))
5035 (add-hook 'makefile-mode-hook 'mdw-misc-mode-config t))
5037 ;;;--------------------------------------------------------------------------
5040 (defun mdw-text-mode ()
5041 (setq fill-column 72)
5043 (mdw-standard-fill-prefix
5044 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
5047 (eval-after-load "flyspell"
5048 '(define-key flyspell-mode-map "\C-\M-i" nil))
5051 (add-hook 'text-mode-hook 'mdw-text-mode t))
5053 ;;;--------------------------------------------------------------------------
5054 ;;; Outline and hide/show modes.
5056 (defun mdw-outline-collapse-all ()
5057 "Completely collapse everything in the entire buffer."
5060 (goto-char (point-min))
5061 (while (< (point) (point-max))
5065 (setq hs-hide-comments-when-hiding-all nil)
5067 (defadvice hs-hide-all (after hide-first-comment activate)
5068 (save-excursion (hs-hide-initial-comment-block)))
5070 ;;;--------------------------------------------------------------------------
5073 (defun mdw-sh-mode-setup ()
5074 (local-set-key [?\C-a] 'comint-bol)
5075 (add-hook 'comint-output-filter-functions
5076 'comint-watch-for-password-prompt))
5078 (defun mdw-term-mode-setup ()
5079 (setq term-prompt-regexp shell-prompt-pattern)
5080 (make-local-variable 'mouse-yank-at-point)
5081 (make-local-variable 'transient-mark-mode)
5082 (setq mouse-yank-at-point t)
5086 (defun comint-send-and-indent ()
5089 (and mdw-auto-indent
5090 (indent-for-tab-command)))
5092 (defadvice comint-line-beginning-position
5093 (around mdw-calculate-it-properly () activate compile)
5094 "Calculate the actual line start for multi-line input."
5095 (if (or comint-use-prompt-regexp
5096 (eq (field-at-pos (point)) 'output))
5098 (setq ad-return-value
5099 (constrain-to-field (line-beginning-position) (point)))))
5101 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
5102 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
5103 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
5104 (defun term-send-meta-meta-something ()
5106 (term-send-raw-string "\e\e")
5108 (eval-after-load 'term
5110 (define-key term-raw-map [?\e ?\e] nil)
5111 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
5112 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
5113 (define-key term-raw-map [M-right] 'term-send-meta-right)
5114 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
5115 (define-key term-raw-map [M-left] 'term-send-meta-left)
5116 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
5118 (defadvice term-exec (before program-args-list compile activate)
5119 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
5120 This allows you to pass a list of arguments through `ansi-term'."
5121 (let ((program (ad-get-arg 2)))
5124 (ad-set-arg 2 (car program))
5125 (ad-set-arg 4 (cdr program))))))
5127 (defadvice term-exec-1 (around hack-environment compile activate)
5128 "Hack the environment inherited by inferiors in the terminal."
5129 (let ((process-environment (copy-tree process-environment)))
5130 (setenv "LD_PRELOAD" nil)
5133 (defadvice shell (around hack-environment compile activate)
5134 "Hack the environment inherited by inferiors in the shell."
5135 (let ((process-environment (copy-tree process-environment)))
5136 (setenv "LD_PRELOAD" nil)
5140 "Open a terminal containing an ssh session to the HOST."
5141 (interactive "sHost: ")
5142 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
5144 (defcustom git-grep-command
5145 "env GIT_PAGER=cat git grep --no-color -nH -e "
5146 "The default command for \\[git-grep]."
5149 (defvar git-grep-history nil)
5151 (defun git-grep (command-args)
5152 "Run `git grep' with user-specified args and collect output in a buffer."
5154 (list (read-shell-command "Run git grep (like this): "
5155 git-grep-command 'git-grep-history)))
5156 (let ((grep-use-null-device nil))
5157 (grep command-args)))
5159 ;;;--------------------------------------------------------------------------
5160 ;;; Magit configuration.
5162 (setq magit-diff-refine-hunk 't
5163 magit-view-git-manual-method 'man
5164 magit-log-margin '(nil age magit-log-margin-width t 18)
5165 magit-wip-after-save-local-mode-lighter ""
5166 magit-wip-after-apply-mode-lighter ""
5167 magit-wip-before-change-mode-lighter "")
5168 (eval-after-load "magit"
5169 '(progn (global-magit-file-mode 1)
5170 (magit-wip-after-save-mode 1)
5171 (magit-wip-after-apply-mode 1)
5172 (magit-wip-before-change-mode 1)
5173 (add-to-list 'magit-no-confirm 'safe-with-wip)
5174 (add-to-list 'magit-no-confirm 'trash)
5175 (push '(:eval (if (or magit-wip-after-save-local-mode
5176 magit-wip-after-apply-mode
5177 magit-wip-before-change-mode)
5178 (format " wip:%s%s%s"
5179 (if magit-wip-after-apply-mode "A" "")
5180 (if magit-wip-before-change-mode "C" "")
5181 (if magit-wip-after-save-local-mode "S" ""))))
5183 (dolist (popup '(magit-diff-popup
5184 magit-diff-refresh-popup
5185 magit-diff-mode-refresh-popup
5186 magit-revision-mode-refresh-popup))
5187 (magit-define-popup-switch popup ?R "Reverse diff" "-R"))
5188 (magit-define-popup-switch 'magit-rebase-popup ?r
5189 "Rebase merges" "--rebase-merges")))
5191 (defadvice magit-wip-commit-buffer-file
5192 (around mdw-just-this-buffer activate compile)
5193 (let ((magit-save-repository-buffers nil)) ad-do-it))
5195 (defadvice magit-discard
5196 (around mdw-delete-if-prefix-argument activate compile)
5197 (let ((magit-delete-by-moving-to-trash
5198 (and (null current-prefix-arg)
5199 magit-delete-by-moving-to-trash)))
5202 (setq magit-repolist-columns
5203 '(("Name" 16 magit-repolist-column-ident nil)
5204 ("Version" 18 magit-repolist-column-version nil)
5205 ("St" 2 magit-repolist-column-dirty nil)
5206 ("L<U" 3 mdw-repolist-column-unpulled-from-upstream nil)
5207 ("L>U" 3 mdw-repolist-column-unpushed-to-upstream nil)
5208 ("Path" 32 magit-repolist-column-path nil)))
5210 (setq magit-repository-directories '(("~/etc/profile" . 0)
5213 (defadvice magit-list-repos (around mdw-dirname () activate compile)
5214 "Make sure the returned names are directory names.
5215 Otherwise child processes get started in the wrong directory and
5217 (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it)))
5219 (defun mdw-repolist-column-unpulled-from-upstream (_id)
5220 "Insert number of upstream commits not in the current branch."
5221 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
5223 (let ((n (cadr (magit-rev-diff-count "HEAD" upstream))))
5224 (propertize (number-to-string n) 'face
5225 (if (> n 0) 'bold 'shadow))))))
5227 (defun mdw-repolist-column-unpushed-to-upstream (_id)
5228 "Insert number of commits in the current branch but not its upstream."
5229 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
5231 (let ((n (car (magit-rev-diff-count "HEAD" upstream))))
5232 (propertize (number-to-string n) 'face
5233 (if (> n 0) 'bold 'shadow))))))
5235 (defun mdw-try-smerge ()
5237 (goto-char (point-min))
5238 (when (re-search-forward "^<<<<<<< " nil t)
5240 (add-hook 'find-file-hook 'mdw-try-smerge t)
5242 (defcustom mdw-magit-new-window-modes
5249 "Magit modes which should cause a new window to be used."
5250 :type '(repeat symbol))
5252 (defun mdw-display-magit-buffer (buffer)
5253 "Like `magit-display-buffer-traditional'.
5254 But uses `mdw-magit-new-window-modes' for its list of modes
5255 rather than baking the list into the function."
5256 (display-buffer buffer
5257 (let ((mode (with-current-buffer buffer major-mode)))
5258 (if (and (not mdw-designated-window)
5259 (derived-mode-p 'magit-mode)
5260 (mdw-submode-p mode 'magit-mode)
5261 (not (memq mode mdw-magit-new-window-modes)))
5262 '(display-buffer-same-window . nil)
5264 (setq magit-display-buffer-function 'mdw-display-magit-buffer)
5266 (defun mdw-display-magit-file-buffer (buffer)
5267 "Show a file buffer from a diff."
5268 (select-window (display-buffer buffer)))
5269 (setq magit-display-file-buffer-function 'mdw-display-magit-file-buffer)
5271 ;;;--------------------------------------------------------------------------
5272 ;;; GUD, and especially GDB.
5274 ;; Inhibit window dedication. I mean, seriously, wtf?
5275 (defadvice gdb-display-buffer (after mdw-undedicated (buf) compile activate)
5276 "Don't make windows dedicated. Seriously."
5277 (set-window-dedicated-p ad-return-value nil))
5278 (defadvice gdb-set-window-buffer
5279 (after mdw-undedicated (name &optional ignore-dedicated window)
5281 "Don't make windows dedicated. Seriously."
5282 (set-window-dedicated-p (or window (selected-window)) nil))
5284 ;;;--------------------------------------------------------------------------
5287 (setq sql-postgres-options '("-n" "-P" "pager=off")
5288 sql-postgres-login-params
5289 '((user :default "mdw")
5290 (database :default "mdw")
5291 (server :default "db.distorted.org.uk")))
5293 ;;;--------------------------------------------------------------------------
5296 ;; Turn off `noip' when running `man': it interferes with `man-db''s own
5297 ;; seccomp(2)-based sandboxing, which is (in this case, at least) strictly
5299 (defadvice Man-getpage-in-background
5300 (around mdw-inhibit-noip (topic) compile activate)
5301 "Inhibit the `noip' preload hack when invoking `man'."
5302 (let* ((old-preload (getenv "LD_PRELOAD"))
5303 (preloads (and old-preload
5304 (save-match-data (split-string old-preload ":"))))
5309 (let ((item (pop preloads)))
5310 (if (string-match "\\(/\\|^\\)noip\.so\\(:\\|$\\)" item)
5312 (push item filtered)))))
5316 (setenv "LD_PRELOAD"
5318 (with-output-to-string
5319 (setq filtered (nreverse filtered))
5322 (if first (setq first nil)
5324 (write-string (pop filtered)))))))
5326 (setenv "LD_PRELOAD" old-preload))
5329 ;;;--------------------------------------------------------------------------
5330 ;;; MPC configuration.
5332 (eval-when-compile (trap (require 'mpc)))
5334 (setq mpc-browser-tags '(Artist|Composer|Performer Album|Playlist))
5336 (defun mdw-mpc-now-playing ()
5340 (set-buffer (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))))
5341 (mpc--status-callback))
5342 (let ((state (cdr (assq 'state mpc-status))))
5343 (cond ((member state '("stop"))
5344 (message "mpd stopped."))
5345 ((member state '("play" "pause"))
5346 (let* ((artist (cdr (assq 'Artist mpc-status)))
5347 (album (cdr (assq 'Album mpc-status)))
5348 (title (cdr (assq 'Title mpc-status)))
5349 (file (cdr (assq 'file mpc-status)))
5350 (duration-string (cdr (assq 'Time mpc-status)))
5351 (time-string (cdr (assq 'time mpc-status)))
5352 (time (and time-string
5354 (if (string-match ":" time-string)
5355 (substring time-string
5356 0 (match-beginning 0))
5358 (duration (and duration-string
5359 (string-to-number duration-string)))
5360 (pos (and time duration
5361 (format " [%d:%02d/%d:%02d]"
5362 (/ time 60) (mod time 60)
5363 (/ duration 60) (mod duration 60))))
5364 (fmt (cond ((and artist title)
5365 (format "`%s' by %s%s" title artist
5366 (if album (format ", from `%s'" album)
5369 (format "`%s' (no tags)" file))
5371 "(no idea what's playing!)"))))
5372 (if (string= state "play")
5373 (message "mpd playing %s%s" fmt (or pos ""))
5374 (message "mpd paused in %s%s" fmt (or pos "")))))
5376 (message "mpd in unknown state `%s'" state)))))
5378 (defmacro mdw-define-mpc-wrapper (func bvl interactive &rest body)
5380 (interactive ,@interactive)
5383 (mdw-mpc-now-playing)))
5385 (mdw-define-mpc-wrapper mdw-mpc-play-or-pause () nil
5386 (if (member (cdr (assq 'state (mpc-cmd-status))) '("play"))
5390 (mdw-define-mpc-wrapper mdw-mpc-next () nil (mpc-next))
5391 (mdw-define-mpc-wrapper mdw-mpc-prev () nil (mpc-prev))
5392 (mdw-define-mpc-wrapper mdw-mpc-stop () nil (mpc-stop))
5394 (defun mdw-mpc-louder (step)
5395 (interactive (list (if current-prefix-arg
5396 (prefix-numeric-value current-prefix-arg)
5398 (mpc-proc-cmd (format "volume %+d" step)))
5400 (defun mdw-mpc-quieter (step)
5401 (interactive (list (if current-prefix-arg
5402 (prefix-numeric-value current-prefix-arg)
5404 (mpc-proc-cmd (format "volume %+d" (- step))))
5406 (defun mdw-mpc-hack-lines (arg interactivep func)
5407 (if (and interactivep (use-region-p))
5408 (let ((from (region-beginning)) (to (region-end)))
5413 (while (< (point) to)
5416 (let ((n (prefix-numeric-value arg)))
5433 (defun mdw-mpc-select-one ()
5434 (when (and (get-char-property (point) 'mpc-file)
5435 (not (get-char-property (point) 'mpc-select)))
5436 (mpc-select-toggle)))
5438 (defun mdw-mpc-unselect-one ()
5439 (when (get-char-property (point) 'mpc-select)
5440 (mpc-select-toggle)))
5442 (defun mdw-mpc-select (&optional arg interactivep)
5443 (interactive (list current-prefix-arg t))
5444 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
5446 (defun mdw-mpc-unselect (&optional arg interactivep)
5447 (interactive (list current-prefix-arg t))
5448 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one))
5450 (defun mdw-mpc-unselect-backwards (arg)
5452 (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one))
5454 (defun mdw-mpc-unselect-all ()
5456 (setq mpc-select nil)
5457 (mpc-selection-refresh))
5459 (defun mdw-mpc-next-line (arg)
5464 (defun mdw-mpc-previous-line (arg)
5467 (forward-line (- arg)))
5469 (defun mdw-mpc-playlist-add (&optional arg interactivep)
5470 (interactive (list current-prefix-arg t))
5471 (let ((mpc-select mpc-select))
5472 (when (or arg (and interactivep (use-region-p)))
5473 (setq mpc-select nil)
5474 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
5475 (setq mpc-select (reverse mpc-select))
5476 (mpc-playlist-add)))
5478 (defun mdw-mpc-playlist-delete (&optional arg interactivep)
5479 (interactive (list current-prefix-arg t))
5480 (setq mpc-select (nreverse mpc-select))
5482 (when (or arg (and interactivep (use-region-p)))
5483 (setq mpc-select nil)
5484 (mpc-selection-refresh)
5485 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
5486 (mpc-playlist-delete)))
5488 (defun mdw-mpc-hack-tagbrowsers ()
5489 (setq-local mode-line-format
5491 mode-line-frame-identification
5492 mode-line-buffer-identification)))
5493 (add-hook 'mpc-tagbrowser-mode-hook 'mdw-mpc-hack-tagbrowsers)
5495 (defun mdw-mpc-hack-songs ()
5496 (setq-local header-line-format
5497 ;; '("MPC " mpc-volume " " mpc-current-song)
5498 (list (propertize " " 'display '(space :align-to 0))
5499 ;; 'mpc-songs-format-description
5501 (let ((deactivate-mark) (hscroll (window-hscroll)))
5503 (mpc-format mpc-songs-format 'self hscroll)
5504 ;; That would be simpler than the hscroll handling in
5505 ;; mpc-format, but currently move-to-column does not
5506 ;; recognize :space display properties.
5507 ;; (move-to-column hscroll)
5508 ;; (delete-region (point-min) (point))
5509 (buffer-string)))))))
5510 (add-hook 'mpc-songs-mode-hook 'mdw-mpc-hack-songs)
5512 (eval-after-load "mpc"
5514 (define-key mpc-mode-map "m" 'mdw-mpc-select)
5515 (define-key mpc-mode-map "u" 'mdw-mpc-unselect)
5516 (define-key mpc-mode-map "\177" 'mdw-mpc-unselect-backwards)
5517 (define-key mpc-mode-map "\e\177" 'mdw-mpc-unselect-all)
5518 (define-key mpc-mode-map "n" 'mdw-mpc-next-line)
5519 (define-key mpc-mode-map "p" 'mdw-mpc-previous-line)
5520 (define-key mpc-mode-map "/" 'mpc-songs-search)
5521 (setq mpc-songs-mode-map (make-sparse-keymap))
5522 (set-keymap-parent mpc-songs-mode-map mpc-mode-map)
5523 (define-key mpc-songs-mode-map "l" 'mpc-playlist)
5524 (define-key mpc-songs-mode-map "+" 'mdw-mpc-playlist-add)
5525 (define-key mpc-songs-mode-map "-" 'mdw-mpc-playlist-delete)
5526 (define-key mpc-songs-mode-map "\r" 'mpc-songs-jump-to)))
5528 ;;;--------------------------------------------------------------------------
5529 ;;; Inferior Emacs Lisp.
5531 (setq comint-prompt-read-only t)
5533 (eval-after-load "comint"
5535 (define-key comint-mode-map "\C-w" 'comint-kill-region)
5536 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
5538 (eval-after-load "ielm"
5540 (define-key ielm-map "\C-w" 'comint-kill-region)
5541 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
5543 ;;;----- That's all, folks --------------------------------------------------
5545 (provide 'dot-emacs)