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 ;; Rename buffers along with files.
756 (defvar mdw-inhibit-rename-buffer nil
757 "If non-nil, `rename-file' won't rename the buffer visiting the file.")
759 (defmacro mdw-advise-to-inhibit-rename-buffer (function)
760 "Advise FUNCTION to set `mdw-inhibit-rename-buffer' while it runs.
762 This will prevent `rename-file' from renaming the buffer."
763 `(defadvice ,function (around mdw-inhibit-rename-buffer compile activate)
764 "Don't rename the buffer when renaming the underlying file."
765 (let ((mdw-inhibit-rename-buffer t))
767 (mdw-advise-to-inhibit-rename-buffer recode-file-name)
768 (mdw-advise-to-inhibit-rename-buffer set-visited-file-name)
769 (mdw-advise-to-inhibit-rename-buffer backup-buffer)
771 (defadvice rename-file (after mdw-rename-buffers (from to &optional forcep)
773 "If a buffer is visiting the file, rename it to match the new name.
775 Don't do this if `mdw-inhibit-rename-buffer' is non-nil."
776 (unless mdw-inhibit-rename-buffer
777 (let ((buffer (get-file-buffer from)))
779 (let ((to (if (not (string= (file-name-nondirectory to) "")) to
780 (concat to (file-name-nondirectory from)))))
781 (with-current-buffer buffer
782 (set-visited-file-name to nil t)))))))
784 ;;;--------------------------------------------------------------------------
785 ;;; Improved compilation machinery.
787 ;; Uprated version of M-x compile.
789 (setq compile-command
790 (let ((ncpu (with-temp-buffer
791 (insert-file-contents "/proc/cpuinfo")
793 (count-matches "^processor\\s-*:"))))
794 (format "nice make -j%d -k" (* 2 ncpu))))
796 (defun mdw-compilation-buffer-name (mode)
797 (concat "*" (downcase mode) ": "
798 (abbreviate-file-name default-directory) "*"))
799 (setq compilation-buffer-name-function 'mdw-compilation-buffer-name)
801 (eval-after-load "compile"
803 (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile)))
805 (defadvice compile (around hack-environment compile activate)
806 "Hack the environment inherited by inferiors in the compilation."
807 (let ((process-environment (copy-tree process-environment)))
808 (setenv "LD_PRELOAD" nil)
811 (defun mdw-compile (command &optional directory comint)
812 "Initiate a compilation COMMAND, maybe in a different DIRECTORY.
813 The DIRECTORY may be nil to not change. If COMINT is t, then
814 start an interactive compilation.
816 Interactively, prompt for the command if the variable
817 `compilation-read-command' is non-nil, or if requested through
818 the prefix argument. Prompt for the directory, and run
819 interactively, if requested through the prefix.
821 Use a prefix of 4, 6, 12, or 14, or type C-u between one and three times, to
822 force prompting for a directory.
824 Use a prefix of 2, 6, 10, or 14, or type C-u three times, to force
825 prompting for the command.
827 Use a prefix of 8, 10, 12, or 14, or type C-u twice or three times,
828 to force interactive compilation."
830 (let* ((prefix (prefix-numeric-value current-prefix-arg))
831 (command (eval compile-command))
832 (dir (and (plusp (logand prefix #x54))
833 (read-directory-name "Compile in directory: "))))
834 (list (if (or compilation-read-command
835 (plusp (logand prefix #x42)))
836 (compilation-read-command command)
839 (plusp (logand prefix #x58)))))
840 (let ((default-directory (or directory default-directory)))
841 (compile command comint)))
845 (defun mdw-find-build-dir (build-file)
847 (let* ((src-dir (file-name-as-directory (expand-file-name ".")))
850 (when (file-exists-p (concat dir build-file))
852 (let ((sub (expand-file-name (file-relative-name src-dir dir)
853 (concat dir "build/"))))
856 (when (file-exists-p (concat sub build-file))
858 (when (string= sub dir) (throw 'give-up nil))
859 (setq sub (file-name-directory (directory-file-name sub))))))
861 (setq dir (file-name-directory
862 (directory-file-name dir))))
863 (throw 'found nil))))))
865 (defun mdw-flymake-make-init ()
866 (let ((build-dir (mdw-find-build-dir "Makefile")))
868 (let ((tmp-src (flymake-init-create-temp-buffer-copy
869 #'flymake-create-temp-inplace)))
870 (flymake-get-syntax-check-program-args
871 tmp-src build-dir t t
872 #'flymake-get-make-cmdline)))))
874 (setq flymake-allowed-file-name-masks
875 '(("\\.\\(?:[cC]\\|cc\\|cpp\\|cxx\\|c\\+\\+\\)\\'"
876 mdw-flymake-make-init)
877 ("\\.\\(?:[hH]\\|hh\\|hpp\\|hxx\\|h\\+\\+\\)\\'"
878 mdw-flymake-master-make-init)
879 ("\\.p[lm]" flymake-perl-init)))
881 (setq flymake-mode-map
882 (let ((map (if (boundp 'flymake-mode-map)
884 (make-sparse-keymap))))
885 (define-key map [?\C-c ?\C-f ?\C-p] 'flymake-goto-prev-error)
886 (define-key map [?\C-c ?\C-f ?\C-n] 'flymake-goto-next-error)
887 (define-key map [?\C-c ?\C-f ?\C-c] 'flymake-compile)
888 (define-key map [?\C-c ?\C-f ?\C-k] 'flymake-stop-all-syntax-checks)
889 (define-key map [?\C-c ?\C-f ?\C-e] 'flymake-popup-current-error-menu)
892 ;;;--------------------------------------------------------------------------
893 ;;; Mail and news hacking.
895 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
896 "Major mode for editing news and mail messages from external programs.
897 Not much right now. Just support for doing MailCrypt stuff."
900 (run-hooks 'mail-setup-hook))
902 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
904 (add-hook 'mdwail-mode-hook
906 (set-buffer-file-coding-system 'utf-8)
907 (make-local-variable 'paragraph-separate)
908 (make-local-variable 'paragraph-start)
909 (setq paragraph-start
910 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
912 (setq paragraph-separate
913 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
914 paragraph-separate))))
916 ;; How to encrypt in mdwmail.
918 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
920 (setq start (save-excursion
921 (goto-char (point-min))
922 (or (search-forward "\n\n" nil t) (point-min)))))
924 (setq end (point-max)))
925 (mc-encrypt-generic recip scm start end from sign))
927 ;; How to sign in mdwmail.
929 (defun mdwmail-mc-sign (key scm start end uclr)
931 (setq start (save-excursion
932 (goto-char (point-min))
933 (or (search-forward "\n\n" nil t) (point-min)))))
935 (setq end (point-max)))
936 (mc-sign-generic key scm start end uclr))
938 ;; Some signature mangling.
940 (defun mdwmail-mangle-signature ()
942 (goto-char (point-min))
943 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
944 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
945 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
947 ;; Insert my login name into message-ids, so I can score replies.
949 (defadvice message-unique-id (after mdw-user-name last activate compile)
950 "Ensure that the user's name appears at the end of the message-id string,
951 so that it can be used for convenient filtering."
952 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
954 ;; Tell my movemail hack where movemail is.
956 ;; This is needed to shup up warnings about LD_PRELOAD.
958 (let ((path exec-path))
960 (let ((try (expand-file-name "movemail" (car path))))
961 (if (file-executable-p try)
962 (setenv "REAL_MOVEMAIL" try))
963 (setq path (cdr path)))))
965 ;; AUTHINFO GENERIC kludge.
967 (defcustom nntp-authinfo-generic nil
968 "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'.
970 Use this to arrange for per-server settings."
971 :type '(choice (const :tag "Use `NNTPAUTH' environment variable" nil)
975 (defun nntp-open-authinfo-kludge (buffer)
976 "Open a connection to SERVER using `authinfo-kludge'."
977 (let ((proc (start-process "nntpd" buffer
978 "env" (concat "NNTPAUTH="
979 (or nntp-authinfo-generic
981 (error "NNTPAUTH unset")))
982 "authinfo-kludge" nntp-address)))
984 (nntp-wait-for-string "^\r*200")
986 (delete-region (point-min) (point))
989 (eval-after-load "erc"
990 '(load "~/.ercrc.el"))
992 ;; Heavy-duty Gnus patching.
994 (defun mdw-nnimap-transform-headers ()
995 (goto-char (point-min))
996 (let (article lines size string)
999 (while (not (looking-at "\\* [0-9]+ FETCH"))
1000 (delete-region (point) (progn (forward-line 1) (point)))
1003 (goto-char (match-end 0))
1004 ;; Unfold quoted {number} strings.
1005 (while (re-search-forward
1006 "[^]][ (]{\\([0-9]+\\)}\r?\n"
1008 ;; Start of the header section.
1009 (or (re-search-forward "] {[0-9]+}\r?\n" nil t)
1010 ;; Start of the next FETCH.
1011 (re-search-forward "\\* [0-9]+ FETCH" nil t)
1014 (setq size (string-to-number (match-string 1)))
1015 (delete-region (+ (match-beginning 0) 2) (point))
1016 (setq string (buffer-substring (point) (+ (point) size)))
1017 (delete-region (point) (+ (point) size))
1018 (insert (format "%S" (subst-char-in-string ?\n ?\s string)))
1019 ;; [mdw] missing from upstream
1023 (and (re-search-forward "UID \\([0-9]+\\)"
1029 (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)"
1034 (when (search-forward "BODYSTRUCTURE" (line-end-position) t)
1035 (let ((structure (ignore-errors
1036 (read (current-buffer)))))
1037 (while (and (consp structure)
1038 (not (atom (car structure))))
1039 (setq structure (car structure)))
1040 (setq lines (if (and
1041 (stringp (car structure))
1042 (equal (upcase (nth 0 structure)) "MESSAGE")
1043 (equal (upcase (nth 1 structure)) "RFC822"))
1045 (nth 7 structure)))))
1046 (delete-region (line-beginning-position) (line-end-position))
1047 (insert (format "211 %s Article retrieved." article))
1050 (insert (format "Chars: %s\n" size)))
1052 (insert (format "Lines: %s\n" lines)))
1053 ;; Most servers have a blank line after the headers, but
1055 (unless (re-search-forward "^\r$\\|^)\r?$" nil t)
1056 (goto-char (point-max)))
1057 (delete-region (line-beginning-position) (line-end-position))
1059 (forward-line 1)))))
1061 (eval-after-load 'nnimap
1062 '(defalias 'nnimap-transform-headers
1063 (symbol-function 'mdw-nnimap-transform-headers)))
1065 (defadvice gnus-other-frame (around mdw-hack-frame-width compile activate)
1066 "Always arrange for mail/news frames to be 80 columns wide."
1067 (let ((default-frame-alist (cons `(width . ,(+ 80 mdw-frame-width-fudge))
1068 (delete* 'width default-frame-alist
1072 ;; Preferred programs.
1074 (setq mailcap-user-mime-data
1075 '(((type . "application/pdf") (viewer . "mupdf %s"))))
1077 ;;;--------------------------------------------------------------------------
1078 ;;; Utility functions.
1080 (or (fboundp 'line-number-at-pos)
1081 (defun line-number-at-pos (&optional pos)
1082 (let ((opoint (or pos (point))) start)
1085 (goto-char (point-min))
1088 (setq start (point))
1091 (1+ (count-lines 1 (point))))))))
1093 (defun mdw-uniquify-alist (&rest alists)
1094 "Return the concatenation of the ALISTS with duplicate elements removed.
1095 The first association with a given key prevails; others are
1096 ignored. The input lists are not modified, although they'll
1097 probably become garbage."
1099 (let ((start-list (cons nil nil)))
1100 (mdw-do-uniquify start-list
1105 (defun mdw-do-uniquify (done end l rest)
1106 "A helper function for mdw-uniquify-alist.
1107 The DONE argument is a list whose first element is `nil'. It
1108 contains the uniquified alist built so far. The leading `nil' is
1109 stripped off at the end of the operation; it's only there so that
1110 DONE always references a cons cell. END refers to the final cons
1111 cell in the DONE list; it is modified in place each time to avoid
1112 the overheads of `append'ing all the time. The L argument is the
1113 alist we're currently processing; the remaining alists are given
1116 ;; There are several different cases to deal with here.
1119 ;; Current list isn't empty. Add the first item to the DONE list if
1120 ;; there's not an item with the same KEY already there.
1121 (l (or (assoc (car (car l)) done)
1123 (setcdr end (cons (car l) nil))
1124 (setq end (cdr end))))
1125 (mdw-do-uniquify done end (cdr l) rest))
1127 ;; The list we were working on is empty. Shunt the next list into the
1128 ;; current list position and go round again.
1129 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
1131 ;; Everything's done. Remove the leading `nil' from the DONE list and
1132 ;; return it. Finished!
1136 "Insert the current date in a pleasing way."
1138 (insert (save-excursion
1139 (let ((buffer (get-buffer-create "*tmp*")))
1140 (unwind-protect (progn (set-buffer buffer)
1142 (shell-command "date +%Y-%m-%d" t)
1146 (kill-buffer buffer))))))
1148 (defun uuencode (file &optional name)
1149 "UUencodes a file, maybe calling it NAME, into the current buffer."
1150 (interactive "fInput file name: ")
1152 ;; If NAME isn't specified, then guess from the filename.
1156 (or (string-match "[^/]*$" file) 0))))
1157 (print (format "uuencode `%s' `%s'" file name))
1159 ;; Now actually do the thing.
1160 (call-process "uuencode" file t nil name))
1162 (defcustom np-file "~/.np"
1163 "Where the `now-playing' file is."
1167 (defun np (&optional arg)
1168 "Grabs a `now-playing' string."
1172 (goto-char (point-max))
1174 (insert-file-contents np-file)))))
1176 (defun mdw-version-< (ver-a ver-b)
1177 "Answer whether VER-A is strictly earlier than VER-B.
1178 VER-A and VER-B are version numbers, which are strings containing digit
1179 sequences separated by `.'."
1180 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
1181 (split-string ver-a "\\.")))
1182 (lb (mapcar (lambda (x) (car (read-from-string x)))
1183 (split-string ver-b "\\."))))
1186 (cond ((null la) (throw 'done lb))
1187 ((null lb) (throw 'done nil))
1188 ((< (car la) (car lb)) (throw 'done t))
1189 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))
1190 (t (throw 'done nil)))))))
1192 (defun mdw-check-autorevert ()
1193 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
1194 This takes into consideration whether it's been found using
1195 tramp, which seems to get itself into a twist."
1196 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
1198 ((and (buffer-file-name)
1199 (fboundp 'tramp-tramp-file-p)
1200 (tramp-tramp-file-p (buffer-file-name)))
1201 (unless global-auto-revert-ignore-buffer
1202 (setq global-auto-revert-ignore-buffer 'tramp)))
1203 ((eq global-auto-revert-ignore-buffer 'tramp)
1204 (setq global-auto-revert-ignore-buffer nil))))
1206 (defadvice find-file (after mdw-autorevert activate)
1207 (mdw-check-autorevert))
1208 (defadvice write-file (after mdw-autorevert activate)
1209 (mdw-check-autorevert))
1211 (defun mdw-auto-revert ()
1212 "Recheck all of the autorevertable buffers, and update VC modelines."
1214 (let ((auto-revert-check-vc-info t))
1215 (auto-revert-buffers)))
1217 ;;;--------------------------------------------------------------------------
1220 (defadvice dired-maybe-insert-subdir
1221 (around mdw-marked-insertion first activate)
1222 "The DIRNAME may be a list of directory names to insert.
1223 Interactively, if files are marked, then insert all of them.
1224 With a numeric prefix argument, select that many entries near
1225 point; with a non-numeric prefix argument, prompt for listing
1228 (list (dired-get-marked-files nil
1229 (and (integerp current-prefix-arg)
1232 (and current-prefix-arg
1233 (not (integerp current-prefix-arg))
1234 (read-string "Switches for listing: "
1235 (or dired-subdir-switches
1236 dired-actual-switches)))))
1237 (let ((dirs (ad-get-arg 0)))
1238 (dolist (dir (if (listp dirs) dirs (list dirs)))
1242 (defun mdw-dired-run (args &optional syncp)
1243 (interactive (let ((file (dired-get-filename t)))
1244 (list (read-string (format "Arguments for %s: " file))
1245 current-prefix-arg)))
1246 (funcall (if syncp 'shell-command 'async-shell-command)
1247 (concat (shell-quote-argument (dired-get-filename nil))
1250 (defadvice dired-do-flagged-delete
1251 (around mdw-delete-if-prefix-argument activate compile)
1252 (let ((delete-by-moving-to-trash (and (null current-prefix-arg)
1253 delete-by-moving-to-trash)))
1256 (eval-after-load "dired"
1257 '(define-key dired-mode-map "X" 'mdw-dired-run))
1259 ;;;--------------------------------------------------------------------------
1262 (defun mdw-w3m-browse-url (url &optional new-session-p)
1263 "Invoke w3m on the URL in its current window, or at least a different one.
1264 If NEW-SESSION-P, start a new session."
1265 (interactive "sURL: \nP")
1267 (let ((window (selected-window)))
1270 (select-window (or (and (not new-session-p)
1271 (get-buffer-window "*w3m*"))
1273 (if (one-window-p t) (split-window))
1275 (w3m-browse-url url new-session-p))
1276 (select-window window)))))
1278 (eval-after-load 'w3m
1279 '(define-key w3m-mode-map [?\e ?\r] 'w3m-view-this-url-new-session))
1281 (defcustom mdw-good-url-browsers
1282 '(browse-url-mozilla
1284 (w3m . mdw-w3m-browse-url)
1286 "List of good browsers for mdw-good-url-browsers.
1287 Each item is a browser function name, or a cons (CHECK . FUNC).
1288 A symbol FOO stands for (FOO . FOO)."
1289 :type '(repeat (choice function (cons function function))))
1291 (defun mdw-good-url-browser ()
1292 "Return a good URL browser.
1293 Trundle the list of such things, finding the first item for which
1294 CHECK is fboundp, and returning the correponding FUNC."
1295 (let ((bs mdw-good-url-browsers) b check func answer)
1296 (while (and bs (not answer))
1300 (setq check (car b) func (cdr b))
1301 (setq check b func b))
1303 (setq answer func)))
1306 (eval-after-load "w3m-search"
1310 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
1311 ("gd" "Google Directory"
1312 "http://www.google.com/search?cat=gwd/Top&q=%s")
1313 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
1314 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
1315 ("gi" "Images" "http://images.google.com/images?q=%s")
1317 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
1319 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
1320 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
1321 ("nc-wiki" "nCipher wiki"
1322 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
1323 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
1324 ("lp" "Launchpad bug by number"
1325 "https://bugs.launchpad.net/bugs/%s")
1326 ("lppkg" "Launchpad bugs by package"
1327 "https://bugs.launchpad.net/%s")
1329 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
1330 ("debbug" "Debian bug by number"
1331 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
1332 ("debbugpkg" "Debian bugs by package"
1333 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
1334 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
1335 (add-to-list 'w3m-search-engine-alist
1336 (list (cadr item) (caddr item) nil))
1337 (add-to-list 'w3m-uri-replace-alist
1338 (list (concat "\\`" (car item) ":")
1339 'w3m-search-uri-replace
1342 ;;;--------------------------------------------------------------------------
1343 ;;; Paragraph filling.
1345 ;; Useful variables.
1347 (defcustom mdw-fill-prefix nil
1348 "Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
1349 If there's no fill prefix currently set (by the `fill-prefix'
1350 variable) and there's a match from one of the regexps here, it
1351 gets used to set the fill-prefix for the current operation.
1353 The variable is a list of items of the form `PATTERN . PREFIX'; if
1354 the PATTERN matches, the PREFIX is used to set the fill prefix.
1356 A PATTERN is one of the following.
1358 * STRING -- a regular expression, expected to match at point
1359 * (eval . FORM) -- a Lisp form which must evaluate non-nil
1360 * (if COND CONSEQ-PAT ALT-PAT) -- if COND evaluates non-nil, must match
1361 CONSEQ-PAT; otherwise must match ALT-PAT
1362 * (and PATTERN ...) -- must match all of the PATTERNs
1363 * (or PATTERN ...) -- must match at least one PATTERN
1364 * (not PATTERN) -- mustn't match (probably not useful)
1366 A PREFIX is a list of the following kinds of things:
1368 * STRING -- insert a literal string
1369 * (match . N) -- insert the thing matched by bracketed subexpression N
1370 * (pad . N) -- a string of whitespace the same width as subexpression N
1371 * (expr . FORM) -- the result of evaluating FORM
1373 Information about `bracketed subexpressions' comes from the match data,
1374 as modified during matching.")
1376 (make-variable-buffer-local 'mdw-fill-prefix)
1378 (defcustom mdw-hanging-indents
1380 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
1383 "Standard regexp matching parts of a hanging indent.
1384 This is mainly useful in `auto-fill-mode'."
1387 ;; Utility functions.
1389 (defun mdw-maybe-tabify (s)
1390 "Tabify or untabify the string S, according to `indent-tabs-mode'."
1391 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
1395 (let ((start (point-min)) (end (point-max)))
1396 (funcall tabfun (point-min) (point-max))
1397 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
1399 (defun mdw-fill-prefix-match-p (pat)
1400 "Return non-nil if PAT matches at the current position."
1401 (cond ((stringp pat) (looking-at pat))
1402 ((not (consp pat)) (error "Unknown pattern item `%S'" pat))
1403 ((eq (car pat) 'eval) (eval (cdr pat)))
1405 (if (or (null (cdr pat))
1409 (error "Invalid `if' pattern `%S'" pat))
1410 (mdw-fill-prefix-match-p (if (eval (cadr pat))
1413 ((eq (car pat) 'and)
1414 (let ((pats (cdr pat))
1417 (or (mdw-fill-prefix-match-p (car pats))
1419 (setq pats (cdr pats)))
1422 (let ((pats (cdr pat))
1425 (or (not (mdw-fill-prefix-match-p (car pats)))
1426 (progn (setq ok t) nil)))
1427 (setq pats (cdr pats)))
1429 ((eq (car pat) 'not)
1430 (if (or (null (cdr pat)) (cddr pat))
1431 (error "Invalid `not' pattern `%S'" pat))
1432 (not (mdw-fill-prefix-match-p (car pats))))
1433 (t (error "Unknown pattern form `%S'" pat))))
1435 (defun mdw-maybe-car (p)
1436 "If P is a pair, return (car P), otherwise just return P."
1437 (if (consp p) (car p) p))
1439 (defun mdw-padding (s)
1440 "Return a string the same width as S but made entirely from whitespace."
1441 (let* ((l (length s)) (i 0) (n (make-string l ? )))
1443 (if (= 9 (aref s i))
1448 (defun mdw-do-prefix-match (m)
1449 "Expand a dynamic prefix match element.
1450 See `mdw-fill-prefix' for details."
1451 (cond ((not (consp m)) (format "%s" m))
1452 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
1453 ((eq (car m) 'pad) (mdw-padding (match-string
1454 (mdw-maybe-car (cdr m)))))
1455 ((eq (car m) 'eval) (eval (cdr m)))
1458 (defun mdw-examine-fill-prefixes (l)
1459 "Given a list of dynamic fill prefixes, pick one which matches
1460 context and return the static fill prefix to use. Point must be
1461 at the start of a line, and match data must be saved."
1463 (while (cond ((null l) nil)
1464 ((mdw-fill-prefix-match-p (caar l))
1468 (mapcar #'mdw-do-prefix-match
1474 (defun mdw-choose-dynamic-fill-prefix ()
1475 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
1476 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
1477 ((not mdw-fill-prefix) fill-prefix)
1481 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
1483 (defadvice do-auto-fill (around mdw-dynamic-fill-prefix () activate compile)
1484 "Handle auto-filling, working out a dynamic fill prefix in the
1485 case where there isn't a sensible static one."
1486 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1489 (defun mdw-fill-paragraph ()
1490 "Fill paragraph, getting a dynamic fill prefix."
1492 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1493 (fill-paragraph nil)))
1495 (defun mdw-point-within-string-p ()
1496 "Return non-nil if point is within a string."
1497 (let ((state (syntax-ppss)))
1500 (defun mdw-standard-fill-prefix (rx &optional mat)
1501 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
1502 This is just a short-cut for setting the thing by hand, and by
1503 design it doesn't cope with anything approximating a complicated
1505 (setq mdw-fill-prefix
1506 `(((if (mdw-point-within-string-p)
1507 ,(concat "\\(\\s-*\\)" mdw-hanging-indents)
1508 ,(concat rx mdw-hanging-indents))
1510 (pad . ,(or mat 2))))))
1512 ;;;--------------------------------------------------------------------------
1515 ;; Teach PostScript about a condensed variant of Courier. I'm using 85% of
1516 ;; the usual width, which happens to match `mdwfonts', and David Carlisle's
1517 ;; `pslatex'. (Once upon a time, I used 80%, but decided consistency with
1518 ;; `pslatex' was useful.)
1519 (setq ps-user-defined-prologue "
1520 /CourierCondensed /Courier
1521 /CourierCondensed-Bold /Courier-Bold
1522 /CourierCondensed-Oblique /Courier-Oblique
1523 /CourierCondensed-BoldOblique /Courier-BoldOblique
1524 4 { findfont [0.85 0 0 1 0 0] makefont definefont pop } repeat
1527 ;; Hack `ps-print''s settings.
1528 (eval-after-load 'ps-print
1531 ;; Notice that the comment-delimiters should be in italics too.
1532 (pushnew 'font-lock-comment-delimiter-face ps-italic-faces)
1534 ;; Select more suitable colours for the main kinds of tokens. The
1535 ;; colours set on the Emacs faces are chosen for use against a dark
1536 ;; background, and work very badly on white paper.
1537 (ps-extend-face '(font-lock-comment-face "darkgreen" nil italic))
1538 (ps-extend-face '(font-lock-comment-delimiter-face "darkgreen" nil italic))
1539 (ps-extend-face '(font-lock-string-face "RoyalBlue4" nil))
1540 (ps-extend-face '(mdw-punct-face "sienna" nil))
1541 (ps-extend-face '(mdw-number-face "OrangeRed3" nil))
1543 ;; Teach `ps-print' about my condensed varsions of Courier.
1544 (setq ps-font-info-database
1545 (append '((CourierCondensed
1546 (fonts (normal . "CourierCondensed")
1547 (bold . "CourierCondensed-Bold")
1548 (italic . "CourierCondensed-Oblique")
1549 (bold-italic . "CourierCondensed-BoldOblique"))
1551 (line-height . 10.55)
1553 (avg-char-width . 5.1)))
1554 (remove* 'CourierCondensed ps-font-info-database
1557 ;; Arrange to strip overlays from the buffer before we print . This will
1558 ;; prevent `flyspell' from interfering with the printout. (It would be less
1559 ;; bad if `ps-print' could merge the `flyspell' overlay face with the
1560 ;; underlying `font-lock' face, but it can't (and that seems hard). So
1561 ;; instead we have this hack.
1563 ;; The basic trick is to copy the relevant text from the buffer being printed
1564 ;; into a temporary buffer and... just print that. The text properties come
1565 ;; with the text and end up in the new buffer, and the overlays get lost
1566 ;; along the way. Only problem is that the headers identifying the file
1567 ;; being printed get confused, so remember the original buffer and reinstate
1568 ;; it when constructing the headers.
1569 (defvar mdw-printing-buffer)
1571 (defadvice ps-generate-header
1572 (around mdw-use-correct-buffer () activate compile)
1573 "Print the correct name of the buffer being printed."
1574 (with-current-buffer mdw-printing-buffer
1577 (defadvice ps-generate
1578 (around mdw-strip-overlays (buffer from to genfunc) activate compile)
1579 "Strip overlays -- in particular, from `flyspell' -- before printout."
1581 (let ((mdw-printing-buffer buffer))
1582 (insert-buffer-substring buffer from to)
1583 (ad-set-arg 0 (current-buffer))
1584 (ad-set-arg 1 (point-min))
1585 (ad-set-arg 2 (point-max))
1588 ;;;--------------------------------------------------------------------------
1589 ;;; Other common declarations.
1591 ;; Common mode settings.
1593 (defcustom mdw-auto-indent t
1594 "Whether to indent automatically after a newline."
1598 (defun mdw-whitespace-mode (&optional arg)
1599 "Turn on/off whitespace mode, but don't highlight trailing space."
1601 (when (and (boundp 'whitespace-style)
1602 (fboundp 'whitespace-mode))
1603 (let ((whitespace-style (remove 'trailing whitespace-style)))
1604 (whitespace-mode arg))
1605 (setq show-trailing-whitespace whitespace-mode)))
1607 (defvar mdw-do-misc-mode-hacking nil)
1609 (defun mdw-misc-mode-config ()
1610 (and mdw-auto-indent
1611 (cond ((eq major-mode 'lisp-mode)
1612 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
1613 ((derived-mode-p 'slime-repl-mode 'asm-mode 'comint-mode)
1616 (local-set-key "\C-m" 'newline-and-indent))))
1617 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
1618 (local-set-key [C-return] 'newline)
1619 (make-local-variable 'page-delimiter)
1620 (setq page-delimiter (concat "^" "\f"
1624 "\\(" " " ".*" " " "\\)?"
1628 (setq comment-column 40)
1630 (setq fill-column mdw-text-width)
1631 (flyspell-prog-mode)
1632 (and (fboundp 'gtags-mode)
1634 (if (fboundp 'hs-minor-mode)
1635 (trap (hs-minor-mode t))
1636 (outline-minor-mode t))
1638 (trap (turn-on-font-lock)))
1640 (defun mdw-post-local-vars-misc-mode-config ()
1641 (setq whitespace-line-column mdw-text-width)
1642 (when (and mdw-do-misc-mode-hacking
1643 (not buffer-read-only))
1644 (setq show-trailing-whitespace t)
1645 (mdw-whitespace-mode 1)))
1646 (add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
1648 (defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1649 `(progn ,@(mapcar (lambda (func)
1651 (after mdw-angry-fruit-salad activate)
1652 (when mdw-do-misc-mode-hacking
1653 (setq show-trailing-whitespace
1654 (not buffer-read-only))
1655 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1657 (mdw-advise-update-angry-fruit-salad toggle-read-only
1663 (eval-after-load 'gtags
1665 (dolist (key '([mouse-2] [mouse-3]))
1666 (define-key gtags-mode-map key nil))
1667 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1668 (define-key gtags-select-mode-map [C-S-mouse-2]
1669 'gtags-select-tag-by-event)
1670 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1671 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
1673 ;; Backup file handling.
1675 (defcustom mdw-backup-disable-regexps nil
1676 "List of regular expressions: if a file name matches any of
1677 these then the file is not backed up."
1678 :type '(repeat regexp))
1680 (defun mdw-backup-enable-predicate (name)
1681 "[mdw]'s default backup predicate.
1682 Allows a backup if the standard predicate would allow it, and it
1683 doesn't match any of the regular expressions in
1684 `mdw-backup-disable-regexps'."
1685 (and (normal-backup-enable-predicate name)
1686 (let ((answer t) (list mdw-backup-disable-regexps))
1689 (if (string-match (car list) name)
1691 (setq list (cdr list)))
1693 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
1697 (defun mdw-last-one-out-turn-off-the-lights (frame)
1698 "Disconnect from an X display if this was the last frame on that display."
1699 (let ((frame-display (frame-parameter frame 'display)))
1700 (when (and frame-display
1701 (eq window-system 'x)
1702 (not (some (lambda (fr)
1703 (and (not (eq fr frame))
1704 (string= (frame-parameter fr 'display)
1707 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1708 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1710 ;;;--------------------------------------------------------------------------
1711 ;;; Fullscreen-ness.
1713 (defcustom mdw-full-screen-parameters
1714 '((menu-bar-lines . 0)
1715 ;;(vertical-scroll-bars . nil)
1717 "Frame parameters to set when making a frame fullscreen."
1718 :type '(alist :key-type symbol))
1720 (defcustom mdw-full-screen-save
1722 "Extra frame parameters to save when setting fullscreen."
1723 :type '(repeat symbol))
1725 (defun mdw-toggle-full-screen (&optional frame)
1726 "Show the FRAME fullscreen."
1729 (cond ((frame-parameter frame 'fullscreen)
1730 (set-frame-parameter frame 'fullscreen nil)
1731 (modify-frame-parameters
1733 (or (frame-parameter frame 'mdw-full-screen-saved)
1734 (mapcar (lambda (assoc)
1735 (assq (car assoc) default-frame-alist))
1736 mdw-full-screen-parameters))))
1738 (let ((saved (mapcar (lambda (param)
1739 (cons param (frame-parameter frame param)))
1740 (append (mapcar #'car
1741 mdw-full-screen-parameters)
1742 mdw-full-screen-save))))
1743 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1744 (modify-frame-parameters frame mdw-full-screen-parameters)
1745 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1747 ;;;--------------------------------------------------------------------------
1748 ;;; General fontification.
1750 (make-face 'mdw-virgin-face)
1752 (defmacro mdw-define-face (name &rest body)
1753 "Define a face, and make sure it's actually set as the definition."
1757 (copy-face 'mdw-virgin-face ',name)
1758 (defvar ,name ',name)
1759 (put ',name 'face-defface-spec ',body)
1760 (face-spec-set ',name ',body nil)))
1762 (mdw-define-face default
1763 (((type w32)) :family "courier new" :height 85)
1764 (((type x)) :family "6x13" :foundry "trad" :height 130)
1765 (((type color)) :foreground "white" :background "black")
1767 (mdw-define-face fixed-pitch
1768 (((type w32)) :family "courier new" :height 85)
1769 (((type x)) :family "6x13" :foundry "trad" :height 130)
1770 (t :foreground "white" :background "black"))
1771 (mdw-define-face fixed-pitch-serif
1772 (((type w32)) :family "courier new" :height 85 :weight bold)
1773 (((type x)) :family "6x13" :foundry "trad" :height 130 :weight bold)
1774 (t :foreground "white" :background "black" :weight bold))
1775 (mdw-define-face variable-pitch
1776 (((type x)) :family "helvetica" :height 120))
1777 (mdw-define-face region
1778 (((min-colors 64)) :background "grey30")
1779 (((class color)) :background "blue")
1780 (t :inverse-video t))
1781 (mdw-define-face match
1782 (((class color)) :background "blue")
1783 (t :inverse-video t))
1784 (mdw-define-face mc/cursor-face
1785 (((class color)) :background "red")
1786 (t :inverse-video t))
1787 (mdw-define-face minibuffer-prompt
1789 (mdw-define-face mode-line
1790 (((class color)) :foreground "blue" :background "yellow"
1791 :box (:line-width 1 :style released-button))
1792 (t :inverse-video t))
1793 (mdw-define-face mode-line-inactive
1794 (((class color)) :foreground "yellow" :background "blue"
1795 :box (:line-width 1 :style released-button))
1796 (t :inverse-video t))
1797 (mdw-define-face nobreak-space
1799 (t :inherit escape-glyph :underline t))
1800 (mdw-define-face scroll-bar
1801 (t :foreground "black" :background "lightgrey"))
1802 (mdw-define-face fringe
1803 (t :foreground "yellow"))
1804 (mdw-define-face show-paren-match
1805 (((min-colors 64)) :background "darkgreen")
1806 (((class color)) :background "green")
1808 (mdw-define-face show-paren-mismatch
1809 (((class color)) :background "red")
1810 (t :inverse-video t))
1811 (mdw-define-face highlight
1812 (((min-colors 64)) :background "DarkSeaGreen4")
1813 (((class color)) :background "cyan")
1814 (t :inverse-video t))
1816 (mdw-define-face viper-minibuffer-emacs (t nil))
1817 (mdw-define-face viper-minibuffer-insert (t nil))
1818 (mdw-define-face viper-minibuffer-vi (t nil))
1819 (mdw-define-face viper-replace-overlay
1820 (((min-colors 64)) :background "darkred")
1821 (((class color)) :background "red")
1822 (t :inverse-video t))
1823 (mdw-define-face viper-search (t :inherit isearch))
1825 (mdw-define-face compilation-error
1826 (((class color)) :foreground "red" :weight bold)
1828 (mdw-define-face compilation-warning
1829 (((class color)) :foreground "orange" :weight bold)
1831 (mdw-define-face compilation-info
1832 (((class color)) :foreground "green" :weight bold)
1834 (mdw-define-face compilation-line-number
1836 (mdw-define-face compilation-column-number
1837 (((min-colors 64)) :foreground "lightgrey"))
1838 (setq compilation-message-face 'mdw-virgin-face)
1839 (setq compilation-enter-directory-face 'font-lock-comment-face)
1840 (setq compilation-leave-directory-face 'font-lock-comment-face)
1842 (mdw-define-face holiday-face
1843 (t :background "red"))
1844 (mdw-define-face calendar-today-face
1845 (t :foreground "yellow" :weight bold))
1847 (mdw-define-face comint-highlight-prompt
1849 (mdw-define-face comint-highlight-input
1852 (mdw-define-face Man-underline
1853 (((type tty)) :underline t)
1856 (mdw-define-face ido-subdir
1857 (t :foreground "cyan" :weight bold))
1859 (mdw-define-face dired-directory
1860 (t :foreground "cyan" :weight bold))
1861 (mdw-define-face dired-symlink
1862 (t :foreground "cyan"))
1863 (mdw-define-face dired-perm-write
1866 (mdw-define-face trailing-whitespace
1867 (((class color)) :background "red")
1868 (t :inverse-video t))
1869 (mdw-define-face whitespace-line
1870 (((class color)) :background "darkred")
1871 (t :inverse-video t))
1872 (mdw-define-face mdw-punct-face
1873 (((min-colors 64)) :foreground "burlywood2")
1874 (((class color)) :foreground "yellow"))
1875 (mdw-define-face mdw-number-face
1876 (t :foreground "yellow"))
1877 (mdw-define-face mdw-trivial-face)
1878 (mdw-define-face font-lock-function-name-face
1880 (mdw-define-face font-lock-keyword-face
1882 (mdw-define-face font-lock-constant-face
1884 (mdw-define-face font-lock-builtin-face
1886 (mdw-define-face font-lock-type-face
1887 (t :weight bold :slant italic))
1888 (mdw-define-face font-lock-reference-face
1890 (mdw-define-face font-lock-variable-name-face
1892 (mdw-define-face font-lock-comment-face
1893 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1894 (((class color)) :foreground "green")
1896 (mdw-define-face font-lock-comment-delimiter-face
1897 (t :inherit font-lock-comment-face))
1898 (mdw-define-face font-lock-string-face
1899 (((min-colors 64)) :foreground "SkyBlue1")
1900 (((class color)) :foreground "cyan")
1902 (mdw-define-face font-lock-doc-face
1903 (t :inherit font-lock-string-face))
1905 (mdw-define-face message-separator
1906 (t :background "red" :foreground "white" :weight bold))
1907 (mdw-define-face message-cited-text
1908 (default :slant italic)
1909 (((min-colors 64)) :foreground "SkyBlue1")
1910 (((class color)) :foreground "cyan"))
1911 (mdw-define-face message-header-cc
1912 (default :slant italic)
1913 (((min-colors 64)) :foreground "SeaGreen1")
1914 (((class color)) :foreground "green"))
1915 (mdw-define-face message-header-newsgroups
1916 (default :slant italic)
1917 (((min-colors 64)) :foreground "SeaGreen1")
1918 (((class color)) :foreground "green"))
1919 (mdw-define-face message-header-subject
1920 (((min-colors 64)) :foreground "SeaGreen1")
1921 (((class color)) :foreground "green"))
1922 (mdw-define-face message-header-to
1923 (((min-colors 64)) :foreground "SeaGreen1")
1924 (((class color)) :foreground "green"))
1925 (mdw-define-face message-header-xheader
1926 (default :slant italic)
1927 (((min-colors 64)) :foreground "SeaGreen1")
1928 (((class color)) :foreground "green"))
1929 (mdw-define-face message-header-other
1930 (default :slant italic)
1931 (((min-colors 64)) :foreground "SeaGreen1")
1932 (((class color)) :foreground "green"))
1933 (mdw-define-face message-header-name
1934 (default :weight bold)
1935 (((min-colors 64)) :foreground "SeaGreen1")
1936 (((class color)) :foreground "green"))
1938 (mdw-define-face which-func
1941 (mdw-define-face gnus-header-name
1942 (default :weight bold)
1943 (((min-colors 64)) :foreground "SeaGreen1")
1944 (((class color)) :foreground "green"))
1945 (mdw-define-face gnus-header-subject
1946 (((min-colors 64)) :foreground "SeaGreen1")
1947 (((class color)) :foreground "green"))
1948 (mdw-define-face gnus-header-from
1949 (((min-colors 64)) :foreground "SeaGreen1")
1950 (((class color)) :foreground "green"))
1951 (mdw-define-face gnus-header-to
1952 (((min-colors 64)) :foreground "SeaGreen1")
1953 (((class color)) :foreground "green"))
1954 (mdw-define-face gnus-header-content
1955 (default :slant italic)
1956 (((min-colors 64)) :foreground "SeaGreen1")
1957 (((class color)) :foreground "green"))
1959 (mdw-define-face gnus-cite-1
1960 (((min-colors 64)) :foreground "SkyBlue1")
1961 (((class color)) :foreground "cyan"))
1962 (mdw-define-face gnus-cite-2
1963 (((min-colors 64)) :foreground "RoyalBlue2")
1964 (((class color)) :foreground "blue"))
1965 (mdw-define-face gnus-cite-3
1966 (((min-colors 64)) :foreground "MediumOrchid")
1967 (((class color)) :foreground "magenta"))
1968 (mdw-define-face gnus-cite-4
1969 (((min-colors 64)) :foreground "firebrick2")
1970 (((class color)) :foreground "red"))
1971 (mdw-define-face gnus-cite-5
1972 (((min-colors 64)) :foreground "burlywood2")
1973 (((class color)) :foreground "yellow"))
1974 (mdw-define-face gnus-cite-6
1975 (((min-colors 64)) :foreground "SeaGreen1")
1976 (((class color)) :foreground "green"))
1977 (mdw-define-face gnus-cite-7
1978 (((min-colors 64)) :foreground "SlateBlue1")
1979 (((class color)) :foreground "cyan"))
1980 (mdw-define-face gnus-cite-8
1981 (((min-colors 64)) :foreground "RoyalBlue2")
1982 (((class color)) :foreground "blue"))
1983 (mdw-define-face gnus-cite-9
1984 (((min-colors 64)) :foreground "purple2")
1985 (((class color)) :foreground "magenta"))
1986 (mdw-define-face gnus-cite-10
1987 (((min-colors 64)) :foreground "DarkOrange2")
1988 (((class color)) :foreground "red"))
1989 (mdw-define-face gnus-cite-11
1990 (t :foreground "grey"))
1992 (mdw-define-face gnus-emphasis-underline
1993 (((type tty)) :underline t)
1996 (mdw-define-face diff-header
1998 (mdw-define-face diff-index
2000 (mdw-define-face diff-file-header
2002 (mdw-define-face diff-hunk-header
2003 (((min-colors 64)) :foreground "SkyBlue1")
2004 (((class color)) :foreground "cyan"))
2005 (mdw-define-face diff-function
2006 (default :weight bold)
2007 (((min-colors 64)) :foreground "SkyBlue1")
2008 (((class color)) :foreground "cyan"))
2009 (mdw-define-face diff-header
2010 (((min-colors 64)) :background "grey10"))
2011 (mdw-define-face diff-added
2012 (((class color)) :foreground "green"))
2013 (mdw-define-face diff-removed
2014 (((class color)) :foreground "red"))
2015 (mdw-define-face diff-context
2017 (mdw-define-face diff-refine-change
2018 (((min-colors 64)) :background "RoyalBlue4")
2020 (mdw-define-face diff-refine-removed
2021 (((min-colors 64)) :background "#500")
2023 (mdw-define-face diff-refine-added
2024 (((min-colors 64)) :background "#050")
2027 (setq ediff-force-faces t)
2028 (mdw-define-face ediff-current-diff-A
2029 (((min-colors 64)) :background "darkred")
2030 (((class color)) :background "red")
2031 (t :inverse-video t))
2032 (mdw-define-face ediff-fine-diff-A
2033 (((min-colors 64)) :background "red3")
2034 (((class color)) :inverse-video t)
2035 (t :inverse-video nil))
2036 (mdw-define-face ediff-even-diff-A
2037 (((min-colors 64)) :background "#300"))
2038 (mdw-define-face ediff-odd-diff-A
2039 (((min-colors 64)) :background "#300"))
2040 (mdw-define-face ediff-current-diff-B
2041 (((min-colors 64)) :background "darkgreen")
2042 (((class color)) :background "magenta")
2043 (t :inverse-video t))
2044 (mdw-define-face ediff-fine-diff-B
2045 (((min-colors 64)) :background "green4")
2046 (((class color)) :inverse-video t)
2047 (t :inverse-video nil))
2048 (mdw-define-face ediff-even-diff-B
2049 (((min-colors 64)) :background "#020"))
2050 (mdw-define-face ediff-odd-diff-B
2051 (((min-colors 64)) :background "#020"))
2052 (mdw-define-face ediff-current-diff-C
2053 (((min-colors 64)) :background "darkblue")
2054 (((class color)) :background "blue")
2055 (t :inverse-video t))
2056 (mdw-define-face ediff-fine-diff-C
2057 (((min-colors 64)) :background "blue1")
2058 (((class color)) :inverse-video t)
2059 (t :inverse-video nil))
2060 (mdw-define-face ediff-even-diff-C
2061 (((min-colors 64)) :background "#004"))
2062 (mdw-define-face ediff-odd-diff-C
2063 (((min-colors 64)) :background "#004"))
2064 (mdw-define-face ediff-current-diff-Ancestor
2065 (((min-colors 64)) :background "#630")
2066 (((class color)) :background "blue")
2067 (t :inverse-video t))
2068 (mdw-define-face ediff-even-diff-Ancestor
2069 (((min-colors 64)) :background "#320"))
2070 (mdw-define-face ediff-odd-diff-Ancestor
2071 (((min-colors 64)) :background "#320"))
2073 (mdw-define-face magit-hash
2074 (((min-colors 64)) :foreground "grey40")
2075 (((class color)) :foreground "blue"))
2076 (mdw-define-face magit-diff-hunk-heading
2077 (((min-colors 64)) :foreground "grey70" :background "grey25")
2078 (((class color)) :foreground "yellow"))
2079 (mdw-define-face magit-diff-hunk-heading-highlight
2080 (((min-colors 64)) :foreground "grey70" :background "grey35")
2081 (((class color)) :foreground "yellow" :background "blue"))
2082 (mdw-define-face magit-diff-added
2083 (((min-colors 64)) :foreground "#ddffdd" :background "#335533")
2084 (((class color)) :foreground "green"))
2085 (mdw-define-face magit-diff-added-highlight
2086 (((min-colors 64)) :foreground "#cceecc" :background "#336633")
2087 (((class color)) :foreground "green" :background "blue"))
2088 (mdw-define-face magit-diff-removed
2089 (((min-colors 64)) :foreground "#ffdddd" :background "#553333")
2090 (((class color)) :foreground "red"))
2091 (mdw-define-face magit-diff-removed-highlight
2092 (((min-colors 64)) :foreground "#eecccc" :background "#663333")
2093 (((class color)) :foreground "red" :background "blue"))
2094 (mdw-define-face magit-blame-heading
2095 (((min-colors 64)) :foreground "white" :background "grey25"
2096 :weight normal :slant normal)
2097 (((class color)) :foreground "white" :background "blue"
2098 :weight normal :slant normal))
2099 (mdw-define-face magit-blame-name
2100 (t :inherit magit-blame-heading :slant italic))
2101 (mdw-define-face magit-blame-date
2102 (((min-colors 64)) :inherit magit-blame-heading :foreground "grey60")
2103 (((class color)) :inherit magit-blame-heading :foreground "cyan"))
2104 (mdw-define-face magit-blame-summary
2105 (t :inherit magit-blame-heading :weight bold))
2107 (mdw-define-face dylan-header-background
2108 (((min-colors 64)) :background "NavyBlue")
2109 (((class color)) :background "blue"))
2111 (mdw-define-face erc-input-face
2112 (t :foreground "red"))
2114 (mdw-define-face woman-bold
2116 (mdw-define-face woman-italic
2119 (eval-after-load "rst"
2121 (mdw-define-face rst-level-1-face
2122 (t :foreground "SkyBlue1" :weight bold))
2123 (mdw-define-face rst-level-2-face
2124 (t :foreground "SeaGreen1" :weight bold))
2125 (mdw-define-face rst-level-3-face
2127 (mdw-define-face rst-level-4-face
2129 (mdw-define-face rst-level-5-face
2131 (mdw-define-face rst-level-6-face
2134 (mdw-define-face p4-depot-added-face
2135 (t :foreground "green"))
2136 (mdw-define-face p4-depot-branch-op-face
2137 (t :foreground "yellow"))
2138 (mdw-define-face p4-depot-deleted-face
2139 (t :foreground "red"))
2140 (mdw-define-face p4-depot-unmapped-face
2141 (t :foreground "SkyBlue1"))
2142 (mdw-define-face p4-diff-change-face
2143 (t :foreground "yellow"))
2144 (mdw-define-face p4-diff-del-face
2145 (t :foreground "red"))
2146 (mdw-define-face p4-diff-file-face
2147 (t :foreground "SkyBlue1"))
2148 (mdw-define-face p4-diff-head-face
2149 (t :background "grey10"))
2150 (mdw-define-face p4-diff-ins-face
2151 (t :foreground "green"))
2153 (mdw-define-face w3m-anchor-face
2154 (t :foreground "SkyBlue1" :underline t))
2155 (mdw-define-face w3m-arrived-anchor-face
2156 (t :foreground "SkyBlue1" :underline t))
2158 (mdw-define-face whizzy-slice-face
2159 (t :background "grey10"))
2160 (mdw-define-face whizzy-error-face
2161 (t :background "darkred"))
2163 ;; Ellipses used to indicate hidden text (and similar).
2164 (mdw-define-face mdw-ellipsis-face
2165 (((type tty)) :foreground "blue") (t :foreground "grey60"))
2166 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
2167 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
2168 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
2169 (bar (make-glyph-code ?| mdw-ellipsis-face)))
2170 (set-display-table-slot standard-display-table 0 dollar)
2171 (set-display-table-slot standard-display-table 1 backslash)
2172 (set-display-table-slot standard-display-table 4
2173 (vector dot dot dot))
2174 (set-display-table-slot standard-display-table 5 bar))
2176 ;;;--------------------------------------------------------------------------
2179 (mdw-define-face mdw-point-overlay-face
2181 (((min-colors 64)) :background "darkblue")
2182 (((class color)) :background "blue")
2183 (((type tty) (class mono)) :inverse-video t))
2185 (defcustom mdw-point-overlay-fringe-display '(vertical-bar . vertical-bar)
2186 "Bitmaps to display in the left and right fringes in the current line."
2187 :type '(cons symbol symbol))
2189 (defun mdw-configure-point-overlay ()
2190 (let ((ov (make-overlay 0 0)))
2191 (overlay-put ov 'priority 0)
2192 (let* ((fringe (or mdw-point-overlay-fringe-display (cons nil nil)))
2193 (left (car fringe)) (right (cdr fringe))
2197 (put-text-property 0 1 'display `(left-fringe ,left) ss)
2198 (setq s (concat s ss))))
2201 (put-text-property 0 1 'display `(right-fringe ,right) ss)
2202 (setq s (concat s ss))))
2203 (when (or left right)
2204 (overlay-put ov 'before-string s)))
2205 (overlay-put ov 'face 'mdw-point-overlay-face)
2209 (defvar mdw-point-overlay (mdw-configure-point-overlay)
2210 "An overlay used for showing where point is in the selected window.")
2211 (defun mdw-reconfigure-point-overlay ()
2213 (setq mdw-point-overlay (mdw-configure-point-overlay)))
2215 (defun mdw-remove-point-overlay ()
2216 "Remove the current-point overlay."
2217 (delete-overlay mdw-point-overlay))
2219 (defun mdw-update-point-overlay ()
2220 "Mark the current point position with an overlay."
2221 (if (not mdw-point-overlay-mode)
2222 (mdw-remove-point-overlay)
2223 (overlay-put mdw-point-overlay 'window (selected-window))
2224 (move-overlay mdw-point-overlay
2225 (line-beginning-position)
2226 (+ (line-end-position) 1))))
2228 (defvar mdw-point-overlay-buffers nil
2229 "List of buffers using `mdw-point-overlay-mode'.")
2231 (define-minor-mode mdw-point-overlay-mode
2232 "Indicate current line with an overlay."
2234 (let ((buffer (current-buffer)))
2235 (setq mdw-point-overlay-buffers
2236 (mapcan (lambda (buf)
2237 (if (and (buffer-live-p buf)
2238 (not (eq buf buffer)))
2240 mdw-point-overlay-buffers))
2241 (if mdw-point-overlay-mode
2242 (setq mdw-point-overlay-buffers
2243 (cons buffer mdw-point-overlay-buffers))))
2244 (cond (mdw-point-overlay-buffers
2245 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
2246 (add-hook 'post-command-hook 'mdw-update-point-overlay))
2248 (mdw-remove-point-overlay)
2249 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
2250 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
2252 (define-globalized-minor-mode mdw-global-point-overlay-mode
2253 mdw-point-overlay-mode
2254 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
2256 (defvar mdw-terminal-title-alist nil)
2257 (defun mdw-update-terminal-title ()
2258 (when (let ((term (frame-parameter nil 'tty-type)))
2259 (and term (string-match "^xterm" term)))
2260 (let* ((tty (frame-parameter nil 'tty))
2261 (old (assoc tty mdw-terminal-title-alist))
2262 (new (format-mode-line frame-title-format)))
2263 (unless (and old (equal (cdr old) new))
2264 (if old (rplacd old new)
2265 (setq mdw-terminal-title-alist
2266 (cons (cons tty new) mdw-terminal-title-alist)))
2267 (send-string-to-terminal (concat "\e]2;" new "\e\\"))))))
2269 (add-hook 'post-command-hook 'mdw-update-terminal-title)
2271 ;;;--------------------------------------------------------------------------
2274 (defvar mdw-ediff-previous-windows)
2275 (defun mdw-ediff-setup ()
2276 (setq mdw-ediff-previous-windows (current-window-configuration)))
2277 (defun mdw-ediff-suspend-or-quit ()
2278 (set-window-configuration mdw-ediff-previous-windows))
2279 (add-hook 'ediff-before-setup-hook 'mdw-ediff-setup)
2280 (add-hook 'ediff-quit-hook 'mdw-ediff-suspend-or-quit t)
2281 (add-hook 'ediff-suspend-hook 'mdw-ediff-suspend-or-quit t)
2283 ;;;--------------------------------------------------------------------------
2284 ;;; C programming configuration.
2286 ;; Make C indentation nice.
2288 (defun mdw-c-lineup-arglist (langelem)
2289 "Hack for DWIMmery in c-lineup-arglist."
2291 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
2293 (c-lineup-arglist langelem)))
2295 (defun mdw-c-indent-extern-mumble (langelem)
2296 "Indent `extern \"...\" {' lines."
2298 (back-to-indentation)
2300 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
2304 (defun mdw-c-indent-arglist-nested (langelem)
2305 "Indent continued argument lists.
2306 If we've nested more than one argument list, then only introduce a single
2307 indentation anyway."
2308 (let ((context c-syntactic-context)
2309 (pos (c-langelem-2nd-pos c-syntactic-element))
2310 (should-indent-p t))
2312 (eq (caar context) 'arglist-cont-nonempty))
2313 (when (and (= (caddr (pop context)) pos)
2315 (memq (caar context) '(arglist-intro
2316 arglist-cont-nonempty)))
2317 (setq should-indent-p nil)))
2318 (if should-indent-p '+ 0)))
2320 (defvar mdw-define-c-styles-hook nil
2321 "Hook run when `cc-mode' starts up to define styles.")
2323 (defun mdw-merge-style-alists (first second)
2325 (dolist (item first)
2326 (let ((key (car item)) (value (cdr item)))
2327 (if (let* ((key-name (symbol-name key))
2328 (key-len (length key-name)))
2330 (string= (subseq key-name (- key-len 5)) "-alist")))
2332 (mdw-merge-style-alists value
2333 (cdr (assoc key second))))
2335 (push item output))))
2336 (dolist (item second)
2337 (unless (assoc (car item) first)
2338 (push item output)))
2341 (defmacro* mdw-define-c-style (name (&optional parent) &rest assocs)
2342 "Define a C style, called NAME (a symbol) based on PARENT, setting ASSOCs.
2343 A function, named `mdw-define-c-style/NAME', is defined to actually install
2344 the style using `c-add-style', and added to the hook
2345 `mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
2347 (declare (indent defun))
2348 (let* ((name-string (symbol-name name))
2349 (var (intern (concat "mdw-c-style/" name-string)))
2350 (func (intern (concat "mdw-define-c-style/" name-string))))
2355 (let ((parent-list (intern (concat "mdw-c-style/"
2356 (symbol-name parent)))))
2357 `(mdw-merge-style-alists ',assocs ,parent-list))))
2358 (defun ,func () (c-add-style ,name-string ,var))
2359 (and (featurep 'cc-mode) (,func))
2360 (add-hook 'mdw-define-c-styles-hook ',func)
2363 (eval-after-load "cc-mode"
2364 '(run-hooks 'mdw-define-c-styles-hook))
2366 (mdw-define-c-style mdw-c ()
2367 (c-basic-offset . 2)
2368 (comment-column . 40)
2369 (c-class-key . "class")
2370 (c-backslash-column . 72)
2371 (c-label-minimum-indentation . 0)
2372 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
2373 (defun-open . (add 0 c-indent-one-line-block))
2374 (arglist-cont-nonempty . mdw-c-lineup-arglist)
2375 (topmost-intro . mdw-c-indent-extern-mumble)
2376 (cpp-define-intro . 0)
2378 (inextern-lang . [0])
2384 (statement-cont . +)
2385 (statement-case-intro . +)))
2387 (mdw-define-c-style mdw-trustonic-c (mdw-c)
2388 (c-basic-offset . 4)
2389 (c-offsets-alist (access-label . -2)))
2391 (mdw-define-c-style mdw-trustonic-alec-c (mdw-trustonic-c)
2392 (comment-column . 0)
2393 (c-indent-comment-alist (anchored-comment . (column . 0))
2394 (end-block . (space . 1))
2395 (cpp-end-block . (space . 1))
2396 (other . (space . 1)))
2397 (c-offsets-alist (arglist-cont-nonempty . mdw-c-indent-arglist-nested)))
2399 (defun mdw-set-default-c-style (modes style)
2400 "Update the default CC Mode style for MODES to be STYLE.
2402 MODES may be a list of major mode names or a singleton. STYLE is a style
2404 (let ((modes (if (listp modes) modes (list modes)))
2405 (style (symbol-name style)))
2406 (setq c-default-style
2407 (append (mapcar (lambda (mode)
2410 (remove-if (lambda (assoc)
2411 (memq (car assoc) modes))
2412 (if (listp c-default-style)
2414 (list (cons 'other c-default-style))))))))
2415 (setq c-default-style "mdw-c")
2417 (mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
2419 (defvar mdw-c-comment-fill-prefix
2420 `((,(concat "\\([ \t]*/?\\)"
2423 "\\([A-Za-z]+:[ \t]*\\)?"
2424 mdw-hanging-indents)
2425 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
2426 "Fill prefix matching C comments (both kinds).")
2428 (defun mdw-fontify-c-and-c++ ()
2430 ;; Fiddle with some syntax codes.
2431 (modify-syntax-entry ?* ". 23")
2432 (modify-syntax-entry ?/ ". 124b")
2433 (modify-syntax-entry ?\n "> b")
2436 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2438 ;; Now define things to be fontified.
2439 (make-local-variable 'font-lock-keywords)
2441 (mdw-regexps "alignas" ;C11 macro, C++11
2443 "and" ;C++, C95 macro
2444 "and_eq" ;C++, C95 macro
2445 "asm" ;K&R, C++, GCC
2446 "atomic" ;C11 macro, C++11 template type
2448 "bitand" ;C++, C95 macro
2449 "bitor" ;C++, C95 macro
2450 "bool" ;C++, C99 macro
2455 "char16_t" ;C++11, C11 library type
2456 "char32_t" ;C++11, C11 library type
2458 "complex" ;C99 macro, C++ template type
2459 "compl" ;C++, C95 macro
2463 "continue" ;K&R, C89
2465 "defined" ;C89 preprocessor
2472 ;; "entry" ;K&R -- never used
2483 "imaginary" ;C99 macro
2484 "inline" ;C++, C99, GCC
2491 "noreturn" ;C11 macro
2492 "not" ;C++, C95 macro
2493 "not_eq" ;C++, C95 macro
2496 "or" ;C++, C95 macro
2497 "or_eq" ;C++, C95 macro
2501 "register" ;K&R, C89
2502 "reinterpret_cast" ;C++
2509 "static_assert" ;C11 macro, C++11
2516 "thread_local" ;C11 macro, C++11
2522 "unsigned" ;K&R, C89
2527 "wchar_t" ;C++, C89 library type
2529 "xor" ;C++, C95 macro
2530 "xor_eq" ;C++, C95 macro
2539 "_Pragma" ;C99 preprocessor
2540 "_Static_assert" ;C11
2541 "_Thread_local" ;C11
2544 "__attribute__" ;GCC
2547 "__extension__" ;GCC
2557 (mdw-regexps "false" ;C++, C99 macro
2559 "true" ;C++, C99 macro
2561 (preprocessor-keywords
2562 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2563 "ident" "if" "ifdef" "ifndef" "import" "include"
2564 "line" "pragma" "unassert" "undef" "warning"))
2566 (mdw-regexps "class" "defs" "encode" "end" "implementation"
2567 "interface" "private" "protected" "protocol" "public"
2570 (setq font-lock-keywords
2573 ;; Fontify include files as strings.
2574 (list (concat "^[ \t]*\\#[ \t]*"
2575 "\\(include\\|import\\)"
2576 "[ \t]*\\(<[^>]+>?\\)")
2577 '(2 font-lock-string-face))
2579 ;; Preprocessor directives are `references'?.
2580 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2581 preprocessor-keywords
2582 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2583 '(1 font-lock-keyword-face))
2585 ;; Handle the keywords defined above.
2586 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
2587 '(0 font-lock-keyword-face))
2589 (list (concat "\\<\\(" c-keywords "\\)\\>")
2590 '(0 font-lock-keyword-face))
2592 (list (concat "\\<\\(" c-builtins "\\)\\>")
2593 '(0 font-lock-variable-name-face))
2595 ;; Handle numbers too.
2597 ;; This looks strange, I know. It corresponds to the
2598 ;; preprocessor's idea of what a number looks like, rather than
2599 ;; anything sensible.
2600 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2601 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2602 '(0 mdw-number-face))
2604 ;; And anything else is punctuation.
2605 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2606 '(0 mdw-punct-face))))))
2608 (define-derived-mode sod-mode c-mode "Sod"
2609 "Major mode for editing Sod code.")
2610 (push '("\\.sod$" . sod-mode) auto-mode-alist)
2612 (dolist (hook '(c-mode-hook objc-mode-hook c++-mode-hook))
2613 (add-hook hook 'mdw-misc-mode-config t)
2614 (add-hook hook 'mdw-fontify-c-and-c++ t))
2616 ;;;--------------------------------------------------------------------------
2619 (define-derived-mode apcalc-mode c-mode "AP Calc"
2620 "Major mode for editing Calc code.")
2622 (defun mdw-fontify-apcalc ()
2624 ;; Fiddle with some syntax codes.
2625 (modify-syntax-entry ?* ". 23")
2626 (modify-syntax-entry ?/ ". 14")
2629 (setq comment-start "/* ")
2630 (setq comment-end " */")
2631 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2633 ;; Now define things to be fontified.
2634 (make-local-variable 'font-lock-keywords)
2636 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
2637 "do" "else" "exit" "for" "global" "goto" "help" "if"
2638 "local" "mat" "obj" "print" "quit" "read" "return"
2639 "show" "static" "switch" "while" "write")))
2641 (setq font-lock-keywords
2644 ;; Handle the keywords defined above.
2645 (list (concat "\\<\\(" c-keywords "\\)\\>")
2646 '(0 font-lock-keyword-face))
2648 ;; Handle numbers too.
2650 ;; This looks strange, I know. It corresponds to the
2651 ;; preprocessor's idea of what a number looks like, rather than
2652 ;; anything sensible.
2653 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2654 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2655 '(0 mdw-number-face))
2657 ;; And anything else is punctuation.
2658 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2659 '(0 mdw-punct-face))))))
2662 (add-hook 'apcalc-mode-hook 'mdw-misc-mode-config t)
2663 (add-hook 'apcalc-mode-hook 'mdw-fontify-apcalc t))
2665 ;;;--------------------------------------------------------------------------
2666 ;;; Java programming configuration.
2668 ;; Make indentation nice.
2670 (mdw-define-c-style mdw-java ()
2671 (c-basic-offset . 2)
2672 (c-backslash-column . 72)
2673 (c-offsets-alist (substatement-open . 0)
2678 (statement-case-intro . +)))
2679 (mdw-set-default-c-style 'java-mode 'mdw-java)
2681 ;; Declare Java fontification style.
2683 (defun mdw-fontify-java ()
2685 ;; Fiddle with some syntax codes.
2686 (modify-syntax-entry ?@ ".")
2687 (modify-syntax-entry ?@ "." font-lock-syntax-table)
2690 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2692 ;; Now define things to be fontified.
2693 (make-local-variable 'font-lock-keywords)
2694 (let ((java-keywords
2695 (mdw-regexps "abstract" "assert"
2696 "boolean" "break" "byte"
2697 "case" "catch" "char" "class" "const" "continue"
2698 "default" "do" "double"
2699 "else" "enum" "extends"
2700 "final" "finally" "float" "for"
2702 "if" "implements" "import" "instanceof" "int"
2706 "package" "private" "protected" "public"
2708 "short" "static" "strictfp" "switch" "synchronized"
2709 "throw" "throws" "transient" "try"
2714 (mdw-regexps "false" "null" "super" "this" "true")))
2716 (setq font-lock-keywords
2719 ;; Handle the keywords defined above.
2720 (list (concat "\\<\\(" java-keywords "\\)\\>")
2721 '(0 font-lock-keyword-face))
2723 ;; Handle the magic builtins defined above.
2724 (list (concat "\\<\\(" java-builtins "\\)\\>")
2725 '(0 font-lock-variable-name-face))
2727 ;; Handle numbers too.
2729 ;; The following isn't quite right, but it's close enough.
2730 (list (concat "\\<\\("
2731 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2732 "[0-9]+\\(\\.[0-9]*\\)?"
2733 "\\([eE][-+]?[0-9]+\\)?\\)"
2735 '(0 mdw-number-face))
2737 ;; And anything else is punctuation.
2738 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2739 '(0 mdw-punct-face))))))
2742 (add-hook 'java-mode-hook 'mdw-misc-mode-config t)
2743 (add-hook 'java-mode-hook 'mdw-fontify-java t))
2745 ;;;--------------------------------------------------------------------------
2746 ;;; Javascript programming configuration.
2748 (defun mdw-javascript-style ()
2749 (setq js-indent-level 2)
2750 (setq js-expr-indent-offset 0))
2752 (defun mdw-fontify-javascript ()
2755 (mdw-javascript-style)
2756 (setq js-auto-indent-flag t)
2758 ;; Now define things to be fontified.
2759 (make-local-variable 'font-lock-keywords)
2760 (let ((javascript-keywords
2761 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
2762 "char" "class" "const" "continue" "debugger" "default"
2763 "delete" "do" "double" "else" "enum" "export" "extends"
2764 "final" "finally" "float" "for" "function" "goto" "if"
2765 "implements" "import" "in" "instanceof" "int"
2766 "interface" "let" "long" "native" "new" "package"
2767 "private" "protected" "public" "return" "short"
2768 "static" "super" "switch" "synchronized" "throw"
2769 "throws" "transient" "try" "typeof" "var" "void"
2770 "volatile" "while" "with" "yield"))
2771 (javascript-builtins
2772 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
2773 "arguments" "this")))
2775 (setq font-lock-keywords
2778 ;; Handle the keywords defined above.
2779 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
2780 '(0 font-lock-keyword-face))
2782 ;; Handle the predefined builtins defined above.
2783 (list (concat "\\_<\\(" javascript-builtins "\\)\\_>")
2784 '(0 font-lock-variable-name-face))
2786 ;; Handle numbers too.
2788 ;; The following isn't quite right, but it's close enough.
2789 (list (concat "\\_<\\("
2790 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2791 "[0-9]+\\(\\.[0-9]*\\)?"
2792 "\\([eE][-+]?[0-9]+\\)?\\)"
2794 '(0 mdw-number-face))
2796 ;; And anything else is punctuation.
2797 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2798 '(0 mdw-punct-face))))))
2801 (add-hook 'js-mode-hook 'mdw-misc-mode-config t)
2802 (add-hook 'js-mode-hook 'mdw-fontify-javascript t))
2804 ;;;--------------------------------------------------------------------------
2805 ;;; Scala programming configuration.
2807 (defun mdw-fontify-scala ()
2810 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2812 ;; Define things to be fontified.
2813 (make-local-variable 'font-lock-keywords)
2814 (let ((scala-keywords
2815 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
2816 "extends" "final" "finally" "for" "forSome" "if"
2817 "implicit" "import" "lazy" "match" "new" "object"
2818 "override" "package" "private" "protected" "return"
2819 "sealed" "throw" "trait" "try" "type" "val"
2820 "var" "while" "with" "yield"))
2822 (mdw-regexps "false" "null" "super" "this" "true"))
2823 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
2825 (setq font-lock-keywords
2828 ;; Magical identifiers between backticks.
2829 (list (concat "`\\([^`]+\\)`")
2830 '(1 font-lock-variable-name-face))
2832 ;; Handle the keywords defined above.
2833 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
2834 '(0 font-lock-keyword-face))
2836 ;; Handle the constants defined above.
2837 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
2838 '(0 font-lock-variable-name-face))
2840 ;; Magical identifiers between backticks.
2841 (list (concat "`\\([^`]+\\)`")
2842 '(1 font-lock-variable-name-face))
2844 ;; Handle numbers too.
2846 ;; As usual, not quite right.
2847 (list (concat "\\_<\\("
2848 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2849 "[0-9]+\\(\\.[0-9]*\\)?"
2850 "\\([eE][-+]?[0-9]+\\)?\\)"
2852 '(0 mdw-number-face))
2854 ;; And everything else is punctuation.
2855 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2856 '(0 mdw-punct-face)))
2858 font-lock-syntactic-keywords
2861 ;; Single quotes around characters. But not when used to quote
2862 ;; symbol names. Ugh.
2863 (list (concat "\\('\\)"
2865 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
2866 "u+" "[0-9a-fA-F]\\{4\\}"
2867 "\\|" "\\\\" "[0-7]\\{1,3\\}"
2868 "\\|" "\\\\" "." "\\)"
2874 (add-hook 'scala-mode-hook 'mdw-misc-mode-config t)
2875 (add-hook 'scala-mode-hook 'mdw-fontify-scala t))
2877 ;;;--------------------------------------------------------------------------
2878 ;;; C# programming configuration.
2880 ;; Make indentation nice.
2882 (mdw-define-c-style mdw-csharp ()
2883 (c-basic-offset . 2)
2884 (c-backslash-column . 72)
2885 (c-offsets-alist (substatement-open . 0)
2890 (statement-case-intro . +)))
2891 (mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
2893 ;; Declare C# fontification style.
2895 (defun mdw-fontify-csharp ()
2898 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2900 ;; Now define things to be fontified.
2901 (make-local-variable 'font-lock-keywords)
2902 (let ((csharp-keywords
2903 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
2904 "char" "checked" "class" "const" "continue" "decimal"
2905 "default" "delegate" "do" "double" "else" "enum"
2906 "event" "explicit" "extern" "finally" "fixed" "float"
2907 "for" "foreach" "goto" "if" "implicit" "in" "int"
2908 "interface" "internal" "is" "lock" "long" "namespace"
2909 "new" "object" "operator" "out" "override" "params"
2910 "private" "protected" "public" "readonly" "ref"
2911 "return" "sbyte" "sealed" "short" "sizeof"
2912 "stackalloc" "static" "string" "struct" "switch"
2913 "throw" "try" "typeof" "uint" "ulong" "unchecked"
2914 "unsafe" "ushort" "using" "virtual" "void" "volatile"
2918 (mdw-regexps "base" "false" "null" "this" "true")))
2920 (setq font-lock-keywords
2923 ;; Handle the keywords defined above.
2924 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
2925 '(0 font-lock-keyword-face))
2927 ;; Handle the magic builtins defined above.
2928 (list (concat "\\<\\(" csharp-builtins "\\)\\>")
2929 '(0 font-lock-variable-name-face))
2931 ;; Handle numbers too.
2933 ;; The following isn't quite right, but it's close enough.
2934 (list (concat "\\<\\("
2935 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2936 "[0-9]+\\(\\.[0-9]*\\)?"
2937 "\\([eE][-+]?[0-9]+\\)?\\)"
2939 '(0 mdw-number-face))
2941 ;; And anything else is punctuation.
2942 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2943 '(0 mdw-punct-face))))))
2945 (define-derived-mode csharp-mode java-mode "C#"
2946 "Major mode for editing C# code.")
2948 (add-hook 'csharp-mode-hook 'mdw-fontify-csharp t)
2950 ;;;--------------------------------------------------------------------------
2951 ;;; F# programming configuration.
2953 (setq fsharp-indent-offset 2)
2955 (defun mdw-fontify-fsharp ()
2957 (let ((punct "=<>+-*/|&%!@?"))
2959 ((>= i (length punct)))
2960 (modify-syntax-entry (aref punct i) ".")))
2962 (modify-syntax-entry ?_ "_")
2963 (modify-syntax-entry ?( "(")
2964 (modify-syntax-entry ?) ")")
2966 (setq indent-tabs-mode nil)
2968 (let ((fsharp-keywords
2969 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
2971 "checked" "class" "component" "const" "constraint"
2972 "constructor" "continue"
2973 "default" "delegate" "do" "done" "downcast" "downto"
2974 "eager" "elif" "else" "end" "exception" "extern"
2975 "finally" "fixed" "for" "fori" "fun" "function"
2978 "if" "in" "include" "inherit" "inline" "interface"
2981 "match" "measure" "member" "method" "mixin" "module"
2984 "object" "of" "open" "or" "override"
2985 "parallel" "params" "private" "process" "protected"
2987 "rec" "recursive" "return"
2988 "sealed" "sig" "static" "struct"
2989 "tailcall" "then" "to" "trait" "try" "type"
2991 "val" "virtual" "void" "volatile"
2992 "when" "while" "with"
2996 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
2997 "base" "false" "null" "true"))
3000 (mdw-regexps "do" "let" "return" "use" "yield"))
3002 (preprocessor-keywords
3003 (mdw-regexps "if" "indent" "else" "endif")))
3005 (setq font-lock-keywords
3006 (list (list (concat "\\(^\\|[^\"]\\)"
3009 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
3014 '(2 font-lock-comment-face))
3016 (list (concat "'" "\\("
3019 "\\|" "[0-9][0-9][0-9]"
3020 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
3021 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
3027 "\\(" "\\\\" "\\(.\\|\n\\)"
3030 '(0 font-lock-string-face))
3032 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
3033 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
3035 "\\_<\\(" fsharp-keywords "\\)\\_>")
3036 '(0 font-lock-keyword-face))
3037 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
3038 '(0 font-lock-variable-name-face))
3040 (list (concat "\\_<"
3041 "\\(" "0[bB][01]+" "\\|"
3043 "0[xX][0-9a-fA-F]+" "\\)"
3044 "\\(" "lf\\|LF" "\\|"
3045 "[uU]?[ysnlL]?" "\\)"
3052 "\\([eE][-+]?[0-9]+\\)?"
3057 '(0 mdw-number-face))
3059 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3060 '(0 mdw-punct-face))))))
3062 (defun mdw-fontify-inferior-fsharp ()
3063 (mdw-fontify-fsharp)
3064 (setq font-lock-keywords
3065 (append (list (list "^[#-]" '(0 font-lock-comment-face))
3066 (list "^>" '(0 font-lock-keyword-face)))
3067 font-lock-keywords)))
3070 (add-hook 'fsharp-mode-hook 'mdw-misc-mode-config t)
3071 (add-hook 'fsharp-mode-hook 'mdw-fontify-fsharp t)
3072 (add-hook 'inferior-fsharp-mode-hooks 'mdw-fontify-inferior-fsharp t))
3074 ;;;--------------------------------------------------------------------------
3075 ;;; Go programming configuration.
3077 (defun mdw-fontify-go ()
3079 (make-local-variable 'font-lock-keywords)
3081 (mdw-regexps "break" "case" "chan" "const" "continue"
3082 "default" "defer" "else" "fallthrough" "for"
3083 "func" "go" "goto" "if" "import"
3084 "interface" "map" "package" "range" "return"
3085 "select" "struct" "switch" "type" "var"))
3087 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
3088 "float32" "float64" "int" "uint8" "int16" "int32"
3089 "int64" "rune" "string" "uint" "uint8" "uint16"
3090 "uint32" "uint64" "uintptr" "void"
3091 "false" "iota" "nil" "true"
3093 "append" "cap" "copy" "delete" "imag" "len" "make"
3094 "new" "panic" "real" "recover")))
3096 (setq font-lock-keywords
3099 ;; Handle the keywords defined above.
3100 (list (concat "\\<\\(" go-keywords "\\)\\>")
3101 '(0 font-lock-keyword-face))
3102 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
3103 '(0 font-lock-variable-name-face))
3105 ;; Strings and characters.
3107 "\\(" "[^\\']" "\\|"
3109 "\\(" "[abfnrtv\\'\"]" "\\|"
3110 "[0-7]\\{3\\}" "\\|"
3111 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
3112 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
3113 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
3117 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
3121 '(0 font-lock-string-face))
3123 ;; Handle numbers too.
3125 ;; The following isn't quite right, but it's close enough.
3126 (list (concat "\\<\\("
3127 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
3128 "[0-9]+\\(\\.[0-9]*\\)?"
3129 "\\([eE][-+]?[0-9]+\\)?\\)")
3130 '(0 mdw-number-face))
3132 ;; And anything else is punctuation.
3133 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3134 '(0 mdw-punct-face))))))
3136 (add-hook 'go-mode-hook 'mdw-misc-mode-config t)
3137 (add-hook 'go-mode-hook 'mdw-fontify-go t))
3139 ;;;--------------------------------------------------------------------------
3140 ;;; Rust programming configuration.
3142 (setq-default rust-indent-offset 2)
3144 (defun mdw-self-insert-and-indent (count)
3146 (self-insert-command count)
3147 (indent-according-to-mode))
3149 (defun mdw-fontify-rust ()
3151 ;; Hack syntax categories.
3152 (modify-syntax-entry ?$ ".")
3153 (modify-syntax-entry ?% ".")
3154 (modify-syntax-entry ?= ".")
3156 ;; Fontify keywords and things.
3157 (make-local-variable 'font-lock-keywords)
3158 (let ((rust-keywords
3159 (mdw-regexps "abstract" "alignof" "as" "async" "await"
3160 "become" "box" "break"
3161 "const" "continue" "crate"
3163 "else" "enum" "extern"
3167 "macro" "match" "mod" "move" "mut"
3168 "offsetof" "override"
3169 "priv" "proc" "pub" "pure"
3171 "sizeof" "static" "struct" "super"
3172 "trait" "try" "type" "typeof"
3173 "union" "unsafe" "unsized" "use"
3178 (mdw-regexps "array" "pointer" "slice" "tuple"
3179 "bool" "true" "false"
3181 "i8" "i16" "i32" "i64" "isize"
3182 "u8" "u16" "u32" "u64" "usize"
3185 (setq font-lock-keywords
3188 ;; Handle the keywords defined above.
3189 (list (concat "\\_<\\(" rust-keywords "\\)\\_>")
3190 '(0 font-lock-keyword-face))
3191 (list (concat "\\_<\\(" rust-builtins "\\)\\_>")
3192 '(0 font-lock-variable-name-face))
3194 ;; Handle numbers too.
3195 (list (concat "\\_<\\("
3197 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
3201 "\\|" "\\(" "[0-9][0-9_]*"
3202 "\\|" "0x[0-9a-fA-F_]+"
3206 "\\([ui]\\(8\\|16\\|32\\|64\\|size\\)\\)?"
3208 '(0 mdw-number-face))
3210 ;; And anything else is punctuation.
3211 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3212 '(0 mdw-punct-face)))
3213 font-lock-syntactic-face-function . nil))
3215 ;; Hack key bindings.
3216 (local-set-key [?{] 'mdw-self-insert-and-indent)
3217 (local-set-key [?}] 'mdw-self-insert-and-indent))
3220 (add-hook 'rust-mode-hook 'mdw-misc-mode-config t)
3221 (add-hook 'rust-mode-hook 'mdw-fontify-rust t))
3223 ;;;--------------------------------------------------------------------------
3224 ;;; Awk programming configuration.
3226 ;; Make Awk indentation nice.
3228 (mdw-define-c-style mdw-awk ()
3229 (c-basic-offset . 2)
3230 (c-offsets-alist (substatement-open . 0)
3231 (c-backslash-column . 72)
3232 (statement-cont . 0)
3233 (statement-case-intro . +)))
3234 (mdw-set-default-c-style 'awk-mode 'mdw-awk)
3236 ;; Declare Awk fontification style.
3238 (defun mdw-fontify-awk ()
3240 ;; Miscellaneous fiddling.
3241 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3243 ;; Now define things to be fontified.
3244 (make-local-variable 'font-lock-keywords)
3246 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
3247 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
3248 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
3249 "RSTART" "RLENGTH" "RT" "SUBSEP"
3250 "atan2" "break" "close" "continue" "cos" "delete"
3251 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
3252 "function" "gensub" "getline" "gsub" "if" "in"
3253 "index" "int" "length" "log" "match" "next" "rand"
3254 "return" "print" "printf" "sin" "split" "sprintf"
3255 "sqrt" "srand" "strftime" "sub" "substr" "system"
3256 "systime" "tolower" "toupper" "while")))
3258 (setq font-lock-keywords
3261 ;; Handle the keywords defined above.
3262 (list (concat "\\<\\(" c-keywords "\\)\\>")
3263 '(0 font-lock-keyword-face))
3265 ;; Handle numbers too.
3267 ;; The following isn't quite right, but it's close enough.
3268 (list (concat "\\<\\("
3269 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
3270 "[0-9]+\\(\\.[0-9]*\\)?"
3271 "\\([eE][-+]?[0-9]+\\)?\\)"
3273 '(0 mdw-number-face))
3275 ;; And anything else is punctuation.
3276 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3277 '(0 mdw-punct-face))))))
3280 (add-hook 'awk-mode-hook 'mdw-misc-mode-config t)
3281 (add-hook 'awk-mode-hook 'mdw-fontify-awk t))
3283 ;;;--------------------------------------------------------------------------
3284 ;;; Perl programming style.
3286 ;; Perl indentation style.
3288 (setq-default perl-indent-level 2)
3290 (setq-default cperl-indent-level 2
3291 cperl-continued-statement-offset 2
3292 cperl-indent-region-fix-constructs nil
3293 cperl-continued-brace-offset 0
3294 cperl-brace-offset -2
3295 cperl-brace-imaginary-offset 0
3296 cperl-label-offset 0)
3298 ;; Define perl fontification style.
3300 (defun mdw-fontify-perl ()
3302 ;; Miscellaneous fiddling.
3303 (modify-syntax-entry ?$ "\\")
3304 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
3305 (modify-syntax-entry ?: "." font-lock-syntax-table)
3306 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3308 ;; Now define fontification things.
3309 (make-local-variable 'font-lock-keywords)
3310 (let ((perl-keywords
3317 "ge" "given" "gt" "goto"
3319 "last" "le" "local" "lt"
3324 "redo" "require" "return"
3326 "undef" "unless" "until" "use"
3329 (setq font-lock-keywords
3332 ;; Set up the keywords defined above.
3333 (list (concat "\\<\\(" perl-keywords "\\)\\>")
3334 '(0 font-lock-keyword-face))
3336 ;; At least numbers are simpler than C.
3337 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3338 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
3339 "\\([eE][-+]?[0-9_]+\\)?")
3340 '(0 mdw-number-face))
3342 ;; And anything else is punctuation.
3343 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3344 '(0 mdw-punct-face))))))
3346 (defun perl-number-tests (&optional arg)
3347 "Assign consecutive numbers to lines containing `#t'. With ARG,
3348 strip numbers instead."
3351 (goto-char (point-min))
3352 (let ((i 0) (fmt (if arg "" " %4d")))
3353 (while (search-forward "#t" nil t)
3354 (delete-region (point) (line-end-position))
3356 (insert (format fmt i)))
3357 (goto-char (point-min))
3358 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
3359 (replace-match (format "\\1%d" i))))))
3361 (dolist (hook '(perl-mode-hook cperl-mode-hook))
3362 (add-hook hook 'mdw-misc-mode-config t)
3363 (add-hook hook 'mdw-fontify-perl t))
3365 ;;;--------------------------------------------------------------------------
3366 ;;; Python programming style.
3368 (setq-default py-indent-offset 2
3370 python-indent-offset 2
3371 python-fill-docstring-style 'symmetric)
3373 (defun mdw-fontify-pythonic (keywords)
3375 ;; Miscellaneous fiddling.
3376 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3377 (setq indent-tabs-mode nil)
3378 (set (make-local-variable 'forward-sexp-function) nil)
3380 ;; Now define fontification things.
3381 (make-local-variable 'font-lock-keywords)
3382 (setq font-lock-keywords
3385 ;; Set up the keywords defined above.
3386 (list (concat "\\_<\\(" keywords "\\)\\_>")
3387 '(0 font-lock-keyword-face))
3389 ;; At least numbers are simpler than C.
3390 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO]?[0-7]+\\|[bB][01]+\\)\\|"
3391 "\\_<[0-9][0-9]*\\(\\.[0-9]*\\)?"
3392 "\\([eE][-+]?[0-9]+\\|[lL]\\)?")
3393 '(0 mdw-number-face))
3395 ;; And anything else is punctuation.
3396 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3397 '(0 mdw-punct-face)))))
3399 ;; Define Python fontification styles.
3401 (defun mdw-fontify-python ()
3402 (mdw-fontify-pythonic
3403 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
3404 "del" "elif" "else" "except" "exec" "finally" "for"
3405 "from" "global" "if" "import" "in" "is" "lambda"
3406 "not" "or" "pass" "print" "raise" "return" "try"
3407 "while" "with" "yield")))
3409 (defun mdw-fontify-pyrex ()
3410 (mdw-fontify-pythonic
3411 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
3412 "ctypedef" "def" "del" "elif" "else" "enum" "except" "exec"
3413 "extern" "finally" "for" "from" "global" "if"
3414 "import" "in" "is" "lambda" "not" "or" "pass" "print"
3415 "property" "raise" "return" "struct" "try" "while" "with"
3418 (define-derived-mode pyrex-mode python-mode "Pyrex"
3419 "Major mode for editing Pyrex source code")
3420 (setq auto-mode-alist
3421 (append '(("\\.pyx$" . pyrex-mode)
3422 ("\\.pxd$" . pyrex-mode)
3423 ("\\.pxi$" . pyrex-mode))
3427 (add-hook 'python-mode-hook 'mdw-misc-mode-config t)
3428 (add-hook 'python-mode-hook 'mdw-fontify-python t)
3429 (add-hook 'pyrex-mode-hook 'mdw-fontify-pyrex t))
3431 ;;;--------------------------------------------------------------------------
3432 ;;; Lua programming style.
3434 (setq-default lua-indent-level 2)
3436 (defun mdw-fontify-lua ()
3438 ;; Miscellaneous fiddling.
3439 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3441 ;; Now define fontification things.
3442 (make-local-variable 'font-lock-keywords)
3444 (mdw-regexps "and" "break" "do" "else" "elseif" "end"
3445 "false" "for" "function" "goto" "if" "in" "local"
3446 "nil" "not" "or" "repeat" "return" "then" "true"
3448 (setq font-lock-keywords
3451 ;; Set up the keywords defined above.
3452 (list (concat "\\_<\\(" lua-keywords "\\)\\_>")
3453 '(0 font-lock-keyword-face))
3455 ;; At least numbers are simpler than C.
3456 (list (concat "\\_<\\(" "0[xX]"
3457 "\\(" "[0-9a-fA-F]+"
3458 "\\(\\.[0-9a-fA-F]*\\)?"
3459 "\\|" "\\.[0-9a-fA-F]+"
3461 "\\([pP][-+]?[0-9]+\\)?"
3462 "\\|" "\\(" "[0-9]+"
3466 "\\([eE][-+]?[0-9]+\\)?"
3468 '(0 mdw-number-face))
3470 ;; And anything else is punctuation.
3471 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3472 '(0 mdw-punct-face))))))
3475 (add-hook 'lua-mode-hook 'mdw-misc-mode-config t)
3476 (add-hook 'lua-mode-hook 'mdw-fontify-lua t))
3478 ;;;--------------------------------------------------------------------------
3479 ;;; Icon programming style.
3481 ;; Icon indentation style.
3483 (setq-default icon-brace-offset 0
3484 icon-continued-brace-offset 0
3485 icon-continued-statement-offset 2
3486 icon-indent-level 2)
3488 ;; Define Icon fontification style.
3490 (defun mdw-fontify-icon ()
3492 ;; Miscellaneous fiddling.
3493 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3495 ;; Now define fontification things.
3496 (make-local-variable 'font-lock-keywords)
3497 (let ((icon-keywords
3498 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
3499 "end" "every" "fail" "global" "if" "initial"
3500 "invocable" "link" "local" "next" "not" "of"
3501 "procedure" "record" "repeat" "return" "static"
3502 "suspend" "then" "to" "until" "while"))
3503 (preprocessor-keywords
3504 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
3505 "include" "line" "undef")))
3506 (setq font-lock-keywords
3509 ;; Set up the keywords defined above.
3510 (list (concat "\\<\\(" icon-keywords "\\)\\>")
3511 '(0 font-lock-keyword-face))
3513 ;; The things that Icon calls keywords.
3514 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
3516 ;; At least numbers are simpler than C.
3517 (list (concat "\\<[0-9]+"
3518 "\\([rR][0-9a-zA-Z]+\\|"
3519 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
3520 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
3521 '(0 mdw-number-face))
3524 (list (concat "^[ \t]*$[ \t]*\\<\\("
3525 preprocessor-keywords
3527 '(0 font-lock-keyword-face))
3529 ;; And anything else is punctuation.
3530 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3531 '(0 mdw-punct-face))))))
3534 (add-hook 'icon-mode-hook 'mdw-misc-mode-config t)
3535 (add-hook 'icon-mode-hook 'mdw-fontify-icon t))
3537 ;;;--------------------------------------------------------------------------
3540 (defun mdw-fontify-fortran-common ()
3541 (let ((fortran-keywords
3542 (mdw-regexps "access"
3560 "double\\s-*precision"
3561 "else" "elseif" "elsewhere"
3563 "endblock" "endblockdata"
3619 "select" "selectcase" "selecttype"
3630 (fortran-operators (mdw-regexps "and"
3643 (fortran-intrinsics (mdw-regexps "abs" "dabs" "iabs" "cabs"
3644 "atan" "datan" "atan2" "datan2"
3654 "int" "aint" "idint"
3655 "alog" "dlog" "clog"
3667 "sign" "isign" "dsign"
3669 "sqrt" "dsqrt" "csqrt"
3671 (preprocessor-keywords
3672 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
3673 "ident" "if" "ifdef" "ifndef" "import" "include"
3674 "line" "pragma" "unassert" "undef" "warning")))
3675 (setq font-lock-keywords-case-fold-search t
3679 ;; Fontify include files as strings.
3680 (list (concat "^[ \t]*\\#[ \t]*" "include"
3681 "[ \t]*\\(<[^>]+>?\\)")
3682 '(1 font-lock-string-face))
3684 ;; Preprocessor directives are `references'?.
3685 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
3686 preprocessor-keywords
3687 "\\)\\>\\|[0-9]+\\|$\\)\\)")
3688 '(1 font-lock-keyword-face))
3690 ;; Set up the keywords defined above.
3691 (list (concat "\\<\\(" fortran-keywords "\\)\\>")
3692 '(0 font-lock-keyword-face))
3694 ;; Set up the `.foo.' operators.
3695 (list (concat "\\.\\(" fortran-operators "\\)\\.")
3696 '(0 font-lock-keyword-face))
3698 ;; Set up the intrinsic functions.
3699 (list (concat "\\<\\(" fortran-intrinsics "\\)\\>")
3700 '(0 font-lock-variable-name-face))
3703 (list (concat "\\(" "\\<" "[0-9]+" "\\(\\.[0-9]*\\)?"
3706 "\\(" "[de]" "[+-]?" "[0-9]+" "\\)?"
3707 "\\(" "_" "\\sw+" "\\)?"
3708 "\\|" "b'[01]*'" "\\|" "'[01]*'b"
3709 "\\|" "b\"[01]*\"" "\\|" "\"[01]*\"b"
3710 "\\|" "o'[0-7]*'" "\\|" "'[0-7]*'o"
3711 "\\|" "o\"[0-7]*\"" "\\|" "\"[0-7]*\"o"
3712 "\\|" "[xz]'[0-9a-f]*'" "\\|" "'[0-9a-f]*'[xz]"
3713 "\\|" "[xz]\"[0-9a-f]*\"" "\\|" "\"[0-9a-f]*\"[xz]")
3714 '(0 mdw-number-face))
3716 ;; Any anything else is punctuation.
3717 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3718 '(0 mdw-punct-face))))
3720 (modify-syntax-entry ?/ "." font-lock-syntax-table)
3721 (modify-syntax-entry ?< ".")
3722 (modify-syntax-entry ?> ".")))
3724 (defun mdw-fontify-fortran () (mdw-fontify-fortran-common))
3725 (defun mdw-fontify-f90 () (mdw-fontify-fortran-common))
3727 (setq fortran-do-indent 2
3729 fortran-structure-indent 2
3730 fortran-comment-line-start "*"
3731 fortran-comment-indent-style 'relative
3732 fortran-continuation-string "&"
3733 fortran-continuation-indent 4)
3735 (setq f90-do-indent 2
3737 f90-program-indent 2
3738 f90-continuation-indent 4
3739 f90-smart-end-names nil
3740 f90-smart-end 'no-blink)
3743 (add-hook 'fortran-mode-hook 'mdw-misc-mode-config t)
3744 (add-hook 'fortran-mode-hook 'mdw-fontify-fortran t)
3745 (add-hook 'f90-mode-hook 'mdw-misc-mode-config t)
3746 (add-hook 'f90-mode-hook 'mdw-fontify-f90 t))
3748 ;;;--------------------------------------------------------------------------
3751 (defun mdw-fontify-asm ()
3752 (modify-syntax-entry ?' "\"")
3753 (modify-syntax-entry ?. "w")
3754 (modify-syntax-entry ?\n ">")
3755 (setf fill-prefix nil)
3756 (modify-syntax-entry ?. "_")
3757 (modify-syntax-entry ?* ". 23")
3758 (modify-syntax-entry ?/ ". 124b")
3759 (modify-syntax-entry ?\n "> b")
3760 (local-set-key ";" 'self-insert-command)
3761 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
3763 (defun mdw-asm-set-comment ()
3764 (modify-syntax-entry ?; "."
3766 (modify-syntax-entry asm-comment-char "< b")
3767 (setq comment-start (string asm-comment-char ? )))
3768 (add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
3769 (put 'asm-comment-char 'safe-local-variable 'characterp)
3772 (add-hook 'asm-mode-hook 'mdw-misc-mode-config t)
3773 (add-hook 'asm-mode-hook 'mdw-fontify-asm t))
3775 ;;;--------------------------------------------------------------------------
3776 ;;; TCL configuration.
3778 (setq-default tcl-indent-level 2)
3780 (defun mdw-fontify-tcl ()
3782 (modify-syntax-entry ch "."))
3783 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3784 (make-local-variable 'font-lock-keywords)
3785 (setq font-lock-keywords
3787 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3788 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
3789 "\\([eE][-+]?[0-9_]+\\)?")
3790 '(0 mdw-number-face))
3791 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3792 '(0 mdw-punct-face)))))
3795 (add-hook 'tcl-mode-hook 'mdw-misc-mode-config t)
3796 (add-hook 'tcl-mode-hook 'mdw-fontify-tcl t))
3798 ;;;--------------------------------------------------------------------------
3799 ;;; Dylan programming configuration.
3801 (defun mdw-fontify-dylan ()
3803 (make-local-variable 'font-lock-keywords)
3805 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
3806 ;; hook, which undoes all of our configuration.
3807 (setq major-mode 'dylan-mode)
3808 (font-lock-set-defaults)
3810 (let* ((word "[-_a-zA-Z!*@<>$%]+")
3811 (dylan-keywords (mdw-regexps
3813 "C-address" "C-callable-wrapper" "C-function"
3814 "C-mapped-subtype" "C-pointer-type" "C-struct"
3815 "C-subtype" "C-union" "C-variable"
3817 "above" "abstract" "afterwards" "all"
3818 "begin" "below" "block" "by"
3819 "case" "class" "cleanup" "constant" "create"
3821 "else" "elseif" "end" "exception" "export"
3822 "finally" "for" "from" "function"
3825 "if" "in" "instance" "interface" "iterate"
3827 "let" "library" "local"
3828 "macro" "method" "module"
3831 "select" "slot" "subclass"
3833 "unless" "until" "use"
3834 "variable" "virtual"
3836 (sharp-keywords (mdw-regexps
3837 "all-keys" "key" "next" "rest" "include"
3839 (setq font-lock-keywords
3840 (list (list (concat "\\<\\(" dylan-keywords
3841 "\\|" "with\\(out\\)?-" word
3843 '(0 font-lock-keyword-face))
3844 (list (concat "\\<" word ":" "\\|"
3845 "#\\(" sharp-keywords "\\)\\>")
3846 '(0 font-lock-variable-name-face))
3848 "\\([-+]\\|\\<\\)[0-9]+" "\\("
3849 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
3852 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
3855 "\\|" "#x[0-9a-zA-Z]+"
3857 '(0 mdw-number-face))
3859 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
3860 "\\_<[-+*/=<>:&|]+\\_>"
3862 '(0 mdw-punct-face))))))
3865 (add-hook 'dylan-mode-hook 'mdw-misc-mode-config t)
3866 (add-hook 'dylan-mode-hook 'mdw-fontify-dylan t))
3868 ;;;--------------------------------------------------------------------------
3869 ;;; Algol 68 configuration.
3871 (setq-default a68-indent-step 2)
3873 (defun mdw-fontify-algol-68 ()
3875 ;; Fix up the syntax table.
3876 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
3877 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
3878 (modify-syntax-entry ch "." a68-mode-syntax-table))
3880 (make-local-variable 'font-lock-keywords)
3883 (let ((word "COMMENT"))
3884 (do ((regexp (concat "[^" (substring word 0 1) "]+")
3885 (concat regexp "\\|"
3886 (substring word 0 i)
3887 "[^" (substring word i (1+ i)) "]"))
3889 ((>= i (length word)) regexp)))))
3890 (setq font-lock-keywords
3891 (list (list (concat "\\<COMMENT\\>"
3892 "\\(" not-comment "\\)\\{0,5\\}"
3893 "\\(\\'\\|\\<COMMENT\\>\\)")
3894 '(0 font-lock-comment-face))
3895 (list (concat "\\<CO\\>"
3896 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
3897 "\\($\\|\\<CO\\>\\)")
3898 '(0 font-lock-comment-face))
3899 (list "\\<[A-Z_]+\\>"
3900 '(0 font-lock-keyword-face))
3904 "\\([eE][-+]?[0-9]+\\)?"
3906 '(0 mdw-number-face))
3907 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
3908 '(0 mdw-punct-face))))))
3910 (dolist (hook '(a68-mode-hook a68-mode-hooks))
3911 (add-hook hook 'mdw-misc-mode-config t)
3912 (add-hook hook 'mdw-fontify-algol-68 t))
3914 ;;;--------------------------------------------------------------------------
3915 ;;; REXX configuration.
3917 (defun mdw-rexx-electric-* ()
3922 (defun mdw-rexx-indent-newline-indent ()
3925 (if abbrev-mode (expand-abbrev))
3926 (newline-and-indent))
3928 (defun mdw-fontify-rexx ()
3930 ;; Various bits of fiddling.
3931 (setq mdw-auto-indent nil)
3932 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
3933 (local-set-key [?*] 'mdw-rexx-electric-*)
3934 (dolist (ch '(?! ?? ?# ?@ ?$)) (modify-syntax-entry ch "w"))
3935 (dolist (ch '(?¬)) (modify-syntax-entry ch "."))
3936 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
3938 ;; Set up keywords and things for fontification.
3939 (make-local-variable 'font-lock-keywords-case-fold-search)
3940 (setq font-lock-keywords-case-fold-search t)
3942 (setq rexx-indent 2)
3943 (setq rexx-end-indent rexx-indent)
3944 (setq rexx-cont-indent rexx-indent)
3946 (make-local-variable 'font-lock-keywords)
3947 (let ((rexx-keywords
3948 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
3949 "else" "end" "engineering" "exit" "expose" "for"
3950 "forever" "form" "fuzz" "if" "interpret" "iterate"
3951 "leave" "linein" "name" "nop" "numeric" "off" "on"
3952 "options" "otherwise" "parse" "procedure" "pull"
3953 "push" "queue" "return" "say" "select" "signal"
3954 "scientific" "source" "then" "trace" "to" "until"
3955 "upper" "value" "var" "version" "when" "while"
3958 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
3959 "center" "center" "charin" "charout" "chars"
3960 "compare" "condition" "copies" "c2d" "c2x"
3961 "datatype" "date" "delstr" "delword" "d2c" "d2x"
3962 "errortext" "format" "fuzz" "insert" "lastpos"
3963 "left" "length" "lineout" "lines" "max" "min"
3964 "overlay" "pos" "queued" "random" "reverse" "right"
3965 "sign" "sourceline" "space" "stream" "strip"
3966 "substr" "subword" "symbol" "time" "translate"
3967 "trunc" "value" "verify" "word" "wordindex"
3968 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
3971 (setq font-lock-keywords
3974 ;; Set up the keywords defined above.
3975 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
3976 '(0 font-lock-keyword-face))
3978 ;; Fontify all symbols the same way.
3979 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
3980 "[A-Za-z0-9.!?_#@$]+\\)")
3981 '(0 font-lock-variable-name-face))
3983 ;; And everything else is punctuation.
3984 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3985 '(0 mdw-punct-face))))))
3988 (add-hook 'rexx-mode-hook 'mdw-misc-mode-config t)
3989 (add-hook 'rexx-mode-hook 'mdw-fontify-rexx t))
3991 ;;;--------------------------------------------------------------------------
3992 ;;; Standard ML programming style.
3994 (setq-default sml-nested-if-indent t
3997 sml-type-of-indent nil)
3999 (defun mdw-fontify-sml ()
4001 ;; Make underscore an honorary letter.
4002 (modify-syntax-entry ?' "w")
4005 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
4007 ;; Now define fontification things.
4008 (make-local-variable 'font-lock-keywords)
4010 (mdw-regexps "abstype" "and" "andalso" "as"
4013 "else" "end" "eqtype" "exception"
4014 "fn" "fun" "functor"
4016 "if" "in" "include" "infix" "infixr"
4019 "of" "op" "open" "orelse"
4021 "sharing" "sig" "signature" "struct" "structure"
4024 "where" "while" "with" "withtype")))
4026 (setq font-lock-keywords
4029 ;; Set up the keywords defined above.
4030 (list (concat "\\<\\(" sml-keywords "\\)\\>")
4031 '(0 font-lock-keyword-face))
4033 ;; At least numbers are simpler than C.
4034 (list (concat "\\<\\~?"
4035 "\\(0\\([wW]?[xX][0-9a-fA-F]+\\|"
4037 "\\([0-9]+\\(\\.[0-9]+\\)?"
4040 '(0 mdw-number-face))
4042 ;; And anything else is punctuation.
4043 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4044 '(0 mdw-punct-face))))))
4047 (add-hook 'sml-mode-hook 'mdw-misc-mode-config t)
4048 (add-hook 'sml-mode-hook 'mdw-fontify-sml t))
4050 ;;;--------------------------------------------------------------------------
4051 ;;; Haskell configuration.
4053 (setq-default haskell-indent-offset 2)
4055 (defun mdw-fontify-haskell ()
4057 ;; Fiddle with syntax table to get comments right.
4058 (modify-syntax-entry ?' "_")
4059 (modify-syntax-entry ?- ". 12")
4060 (modify-syntax-entry ?\n ">")
4062 ;; Make punctuation be punctuation
4063 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
4065 ((>= i (length punct)))
4066 (modify-syntax-entry (aref punct i) ".")))
4069 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
4071 ;; Fiddle with fontification.
4072 (make-local-variable 'font-lock-keywords)
4073 (let ((haskell-keywords
4075 "case" "ccall" "class"
4076 "data" "default" "deriving" "do"
4080 "if" "import" "in" "infix" "infixl" "infixr" "instance"
4093 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
4094 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
4095 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
4096 "SP" "STX" "SUB" "SYN" "US" "VT")))
4098 (setq font-lock-keywords
4100 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
4104 '(0 font-lock-comment-face))
4105 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
4106 '(0 font-lock-keyword-face))
4107 (list (concat "'\\("
4111 "\\(" "[abfnrtv\\\"']" "\\|"
4112 "^" "\\(" control-sequences "\\|"
4113 "[]A-Z@[\\^_]" "\\)" "\\|"
4120 '(0 font-lock-string-face))
4121 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
4122 '(0 font-lock-variable-name-face))
4123 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
4124 "\\_<[0-9]+\\(\\.[0-9]*\\)?"
4125 "\\([eE][-+]?[0-9]+\\)?")
4126 '(0 mdw-number-face))
4127 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4128 '(0 mdw-punct-face))))))
4131 (add-hook 'haskell-mode-hook 'mdw-misc-mode-config t)
4132 (add-hook 'haskell-mode-hook 'mdw-fontify-haskell t))
4134 ;;;--------------------------------------------------------------------------
4135 ;;; Erlang configuration.
4137 (setq-default erlang-electric-commands nil)
4139 (defun mdw-fontify-erlang ()
4142 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
4144 ;; Fiddle with fontification.
4145 (make-local-variable 'font-lock-keywords)
4146 (let ((erlang-keywords
4147 (mdw-regexps "after" "and" "andalso"
4148 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
4149 "case" "catch" "cond"
4150 "div" "end" "fun" "if" "let" "not"
4152 "query" "receive" "rem" "try" "when" "xor")))
4154 (setq font-lock-keywords
4157 '(0 font-lock-comment-face))
4158 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
4159 '(0 font-lock-keyword-face))
4160 (list (concat "^-\\sw+\\>")
4161 '(0 font-lock-keyword-face))
4162 (list "\\<[0-9]+\\(#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)?\\>"
4163 '(0 mdw-number-face))
4164 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4165 '(0 mdw-punct-face))))))
4168 (add-hook 'erlang-mode-hook 'mdw-misc-mode-config t)
4169 (add-hook 'erlang-mode-hook 'mdw-fontify-erlang t))
4171 ;;;--------------------------------------------------------------------------
4172 ;;; Texinfo configuration.
4174 (defun mdw-fontify-texinfo ()
4177 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
4179 ;; Real fontification things.
4180 (make-local-variable 'font-lock-keywords)
4181 (setq font-lock-keywords
4184 ;; Environment names are keywords.
4185 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
4186 '(2 font-lock-keyword-face))
4188 ;; Unmark escaped magic characters.
4189 (list "\\(@\\)\\([@{}]\\)"
4190 '(1 font-lock-keyword-face)
4191 '(2 font-lock-variable-name-face))
4193 ;; Make sure we get comments properly.
4194 (list "@c\\(omment\\)?\\( .*\\)?$"
4195 '(0 font-lock-comment-face))
4197 ;; Command names are keywords.
4198 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
4199 '(0 font-lock-keyword-face))
4201 ;; Fontify TeX special characters as punctuation.
4203 '(0 mdw-punct-face)))))
4205 (dolist (hook '(texinfo-mode-hook TeXinfo-mode-hook))
4206 (add-hook hook 'mdw-misc-mode-config t)
4207 (add-hook hook 'mdw-fontify-texinfo t))
4209 ;;;--------------------------------------------------------------------------
4210 ;;; TeX and LaTeX configuration.
4212 (setq-default LaTeX-table-label "tbl:"
4213 TeX-auto-untabify nil
4214 LaTeX-syntactic-comments nil
4215 LaTeX-fill-break-at-separators '(\\\[))
4217 (defun mdw-fontify-tex ()
4218 (setq ispell-parser 'tex)
4221 ;; Don't make maths into a string.
4222 (modify-syntax-entry ?$ ".")
4223 (modify-syntax-entry ?$ "." font-lock-syntax-table)
4224 (local-set-key [?$] 'self-insert-command)
4226 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
4227 (local-set-key "\C-\M-i" 'indent-relative)
4228 (setq indent-tabs-mode nil)
4231 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
4233 ;; Real fontification things.
4234 (make-local-variable 'font-lock-keywords)
4235 (setq font-lock-keywords
4238 ;; Environment names are keywords.
4239 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
4241 '(2 font-lock-keyword-face))
4243 ;; Suspended environment names are keywords too.
4244 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
4246 '(3 font-lock-keyword-face))
4248 ;; Command names are keywords.
4249 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
4250 '(0 font-lock-keyword-face))
4252 ;; Handle @/.../ for italics.
4253 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
4254 ;; '(1 font-lock-keyword-face)
4255 ;; '(3 font-lock-keyword-face))
4257 ;; Handle @*...* for boldness.
4258 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
4259 ;; '(1 font-lock-keyword-face)
4260 ;; '(3 font-lock-keyword-face))
4262 ;; Handle @`...' for literal syntax things.
4263 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
4264 ;; '(1 font-lock-keyword-face)
4265 ;; '(3 font-lock-keyword-face))
4267 ;; Handle @<...> for nonterminals.
4268 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
4269 ;; '(1 font-lock-keyword-face)
4270 ;; '(3 font-lock-keyword-face))
4272 ;; Handle other @-commands.
4273 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
4274 ;; '(0 font-lock-keyword-face))
4276 ;; Make sure we get comments properly.
4278 '(0 font-lock-comment-face))
4280 ;; Fontify TeX special characters as punctuation.
4282 '(0 mdw-punct-face)))))
4284 (setq TeX-install-font-lock 'tex-font-setup)
4286 (eval-after-load 'font-latex
4287 '(defun font-latex-jit-lock-force-redisplay (buf start end)
4288 "Compatibility for Emacsen not offering `jit-lock-force-redisplay'."
4289 ;; The following block is an expansion of `jit-lock-force-redisplay'
4290 ;; and involved macros taken from CVS Emacs on 2007-04-28.
4291 (with-current-buffer buf
4292 (let ((modified (buffer-modified-p)))
4294 (let ((buffer-undo-list t)
4295 (inhibit-read-only t)
4296 (inhibit-point-motion-hooks t)
4297 (inhibit-modification-hooks t)
4300 buffer-file-truename)
4301 (put-text-property start end 'fontified t))
4303 (restore-buffer-modified-p nil)))))))
4305 (setq TeX-output-view-style
4307 ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$")
4308 "%(o?)dvips -t landscape %d -o && xdg-open %f")
4309 ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$"
4310 "%(o?)dvips %d -o && xdg-open %f")
4312 ("^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "^landscape$")
4313 "%(o?)xdvi %dS -paper a4r -s 0 %d")
4314 ("^dvi$" "^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$"
4315 "%(o?)xdvi %dS -paper a4 %d")
4317 ("^a5\\(?:comb\\|paper\\)$" "^landscape$")
4318 "%(o?)xdvi %dS -paper a5r -s 0 %d")
4319 ("^dvi$" "^a5\\(?:comb\\|paper\\)$" "%(o?)xdvi %dS -paper a5 %d")
4320 ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
4321 ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d")
4322 ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
4323 ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
4324 ("^dvi$" "." "%(o?)xdvi %dS %d")
4325 ("^pdf$" "." "xdg-open %o")
4326 ("^html?$" "." "sensible-browser %o")))
4328 (setq TeX-view-program-list
4329 '(("mupdf" ("mupdf %o" (mode-io-correlate " %(outpage)")))))
4331 (setq TeX-view-program-selection
4332 '(((output-dvi style-pstricks) "dvips and gv")
4334 (output-pdf "mupdf")
4335 (output-html "sensible-browser")))
4337 (setq TeX-open-quote "\""
4338 TeX-close-quote "\"")
4340 (setq reftex-use-external-file-finders t
4341 reftex-auto-recenter-toc t)
4343 (setq reftex-label-alist
4344 '(("theorem" ?T "th:" "~\\ref{%s}" t ("theorems?" "th\\.") -2)
4345 ("axiom" ?A "ax:" "~\\ref{%s}" t ("axioms?" "ax\\.") -2)
4346 ("definition" ?D "def:" "~\\ref{%s}" t ("definitions?" "def\\.") -2)
4347 ("proposition" ?P "prop:" "~\\ref{%s}" t
4348 ("propositions?" "prop\\.") -2)
4349 ("lemma" ?L "lem:" "~\\ref{%s}" t ("lemmas?" "lem\\.") -2)
4350 ("example" ?X "eg:" "~\\ref{%s}" t ("examples?") -2)
4351 ("exercise" ?E "ex:" "~\\ref{%s}" t ("exercises?" "ex\\.") -2)
4352 ("enumerate" ?i "i:" "~\\ref{%s}" item ("items?"))))
4353 (setq reftex-section-prefixes
4358 (setq bibtex-field-delimiters 'double-quotes
4359 bibtex-align-at-equal-sign t
4360 bibtex-entry-format '(realign opts-or-alts required-fields
4361 numerical-fields last-comma delimiters
4362 unify-case sort-fields braces)
4363 bibtex-sort-ignore-string-entries nil
4364 bibtex-maintain-sorted-entries 'entry-class
4365 bibtex-include-OPTkey t
4366 bibtex-autokey-names-stretch 1
4367 bibtex-autokey-expand-strings t
4368 bibtex-autokey-name-separator "-"
4369 bibtex-autokey-year-length 4
4370 bibtex-autokey-titleword-separator "-"
4371 bibtex-autokey-name-year-separator "-"
4372 bibtex-autokey-year-title-separator ":")
4375 (dolist (hook '(tex-mode-hook latex-mode-hook
4376 TeX-mode-hook LaTeX-mode-hook))
4377 (add-hook hook 'mdw-misc-mode-config t)
4378 (add-hook hook 'mdw-fontify-tex t))
4379 (add-hook 'bibtex-mode-hook (lambda () (setq fill-column 76))))
4381 ;;;--------------------------------------------------------------------------
4382 ;;; HTML, CSS, and other web foolishness.
4384 (setq-default css-indent-offset 8)
4386 ;;;--------------------------------------------------------------------------
4389 (setq-default psgml-html-build-new-buffer nil)
4391 (defun mdw-sgml-mode ()
4394 (mdw-standard-fill-prefix "")
4395 (make-local-variable 'sgml-delimiters)
4396 (setq sgml-delimiters
4397 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
4398 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT"
4399 "\"" "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]"
4400 "NESTC" "{" "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">"
4401 "PIO" "<?" "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" ","
4402 "STAGO" ":" "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
4403 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE"
4405 (setq major-mode 'mdw-sgml-mode)
4406 (setq mode-name "[mdw] SGML")
4407 (run-hooks 'mdw-sgml-mode-hook))
4409 ;;;--------------------------------------------------------------------------
4410 ;;; Configuration files.
4412 (defcustom mdw-conf-quote-normal nil
4413 "Control syntax category of quote characters `\"' and `''.
4414 If this is `t', consider quote characters to be normal
4415 punctuation, as for `conf-quote-normal'. If this is `nil' then
4416 leave quote characters as quotes. If this is a list, then
4417 consider the quote characters in the list to be normal
4418 punctuation. If this is a single quote character, then consider
4419 that character only to be normal punctuation."
4420 :type '(choice boolean character (repeat character))
4421 :safe 'mdw-conf-quote-normal-acceptable-value-p)
4422 (defun mdw-conf-quote-normal-acceptable-value-p (value)
4423 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
4424 (or (booleanp value)
4425 (every (lambda (v) (memq v '(?\" ?')))
4426 (if (listp value) value (list value)))))
4428 (defun mdw-fix-up-quote ()
4429 "Apply the setting of `mdw-conf-quote-normal'."
4430 (let ((flag mdw-conf-quote-normal))
4432 (conf-quote-normal t))
4436 (let ((table (copy-syntax-table (syntax-table))))
4437 (dolist (ch (if (listp flag) flag (list flag)))
4438 (modify-syntax-entry ch "." table))
4439 (set-syntax-table table)
4440 (and font-lock-mode (font-lock-fontify-buffer)))))))
4443 (add-hook 'conf-mode-hook 'mdw-misc-mode-config t)
4444 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t))
4446 ;;;--------------------------------------------------------------------------
4449 (defun mdw-setup-sh-script-mode ()
4451 ;; Fetch the shell interpreter's name.
4452 (let ((shell-name sh-shell-file))
4454 ;; Try reading the hash-bang line.
4456 (goto-char (point-min))
4457 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
4458 (setq shell-name (match-string 1))))
4460 ;; Now try to set the shell.
4462 ;; Don't let `sh-set-shell' bugger up my script.
4463 (let ((executable-set-magic #'(lambda (s &rest r) s)))
4464 (sh-set-shell shell-name)))
4466 ;; Don't insert here-document scaffolding automatically.
4467 (local-set-key "<" 'self-insert-command)
4469 ;; Now enable my keys and the fontification.
4470 (mdw-misc-mode-config)
4472 ;; Set the indentation level correctly.
4473 (setq sh-indentation 2)
4474 (setq sh-basic-offset 2))
4476 (setq sh-shell-file "/bin/sh")
4478 ;; Awful hacking to override the shell detection for particular scripts.
4479 (defmacro define-custom-shell-mode (name shell)
4482 (set (make-local-variable 'sh-shell-file) ,shell)
4484 (define-custom-shell-mode bash-mode "/bin/bash")
4485 (define-custom-shell-mode rc-mode "/usr/bin/rc")
4486 (put 'sh-shell-file 'permanent-local t)
4488 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
4489 (eval-after-load "sh-script"
4490 '(or (assq 'rc sh-mode-syntax-table-input)
4507 (assoc (assq 'rc sh-mode-syntax-table-input)))
4510 (setq sh-mode-syntax-table-input
4511 (cons (cons 'rc frag)
4512 sh-mode-syntax-table-input))))))
4515 (add-hook 'sh-mode-hook 'mdw-misc-mode-config t)
4516 (add-hook 'sh-mode-hook 'mdw-setup-sh-script-mode t))
4518 ;;;--------------------------------------------------------------------------
4519 ;;; Emacs shell mode.
4521 (defun mdw-eshell-prompt ()
4522 (let ((left "[") (right "]"))
4523 (when (= (user-uid) 0)
4524 (setq left "«" right "»"))
4527 (replace-regexp-in-string "\\..*$" "" (system-name)))
4529 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
4530 (home (expand-file-name "~")) (nhome (length home)))
4531 (if (and (>= npwd nhome)
4533 (= (elt pwd nhome) ?/))
4534 (string= (substring pwd 0 nhome) home))
4535 (concat "~" (substring pwd (length home)))
4538 (setq-default eshell-prompt-function 'mdw-eshell-prompt)
4539 (setq-default eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
4541 (defun eshell/e (file) (find-file file) nil)
4542 (defun eshell/ee (file) (find-file-other-window file) nil)
4543 (defun eshell/w3m (url) (w3m-goto-url url) nil)
4545 (mdw-define-face eshell-prompt (t :weight bold))
4546 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
4547 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
4548 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
4549 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
4550 (mdw-define-face eshell-ls-executable (t :weight bold))
4551 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
4552 (mdw-define-face eshell-ls-readonly (t nil))
4553 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
4555 (defun mdw-eshell-hack () (setenv "LD_PRELOAD" nil))
4556 (add-hook 'eshell-mode-hook 'mdw-eshell-hack)
4558 ;;;--------------------------------------------------------------------------
4559 ;;; Messages-file mode.
4561 (defun messages-mode-guts ()
4562 (setq messages-mode-syntax-table (make-syntax-table))
4563 (set-syntax-table messages-mode-syntax-table)
4564 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
4565 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
4566 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
4567 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
4568 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
4569 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
4570 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
4571 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
4572 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
4573 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
4574 (make-local-variable 'comment-start)
4575 (make-local-variable 'comment-end)
4576 (make-local-variable 'indent-line-function)
4577 (setq indent-line-function 'indent-relative)
4578 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4579 (make-local-variable 'font-lock-defaults)
4580 (make-local-variable 'messages-mode-keywords)
4582 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
4583 "export" "enum" "fixed-octetstring" "flags"
4584 "harmless" "map" "nested" "optional"
4585 "optional-tagged" "package" "primitive"
4586 "primitive-nullfree" "relaxed[ \t]+enum"
4587 "set" "table" "tagged-optional" "union"
4588 "variadic" "vector" "version" "version-tag")))
4589 (setq messages-mode-keywords
4591 (list (concat "\\<\\(" keywords "\\)\\>:")
4592 '(0 font-lock-keyword-face))
4593 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
4594 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
4595 (0 font-lock-variable-name-face))
4596 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
4597 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4598 (0 mdw-punct-face)))))
4599 (setq font-lock-defaults
4600 '(messages-mode-keywords nil nil nil nil))
4601 (run-hooks 'messages-file-hook))
4603 (defun messages-mode ()
4606 (setq major-mode 'messages-mode)
4607 (setq mode-name "Messages")
4608 (messages-mode-guts)
4609 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
4610 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
4611 (setq comment-start "# ")
4612 (setq comment-end "")
4613 (run-hooks 'messages-mode-hook))
4615 (defun cpp-messages-mode ()
4618 (setq major-mode 'cpp-messages-mode)
4619 (setq mode-name "CPP Messages")
4620 (messages-mode-guts)
4621 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
4622 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
4623 (setq comment-start "/* ")
4624 (setq comment-end " */")
4625 (let ((preprocessor-keywords
4626 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
4627 "ident" "if" "ifdef" "ifndef" "import" "include"
4628 "line" "pragma" "unassert" "undef" "warning")))
4629 (setq messages-mode-keywords
4630 (append (list (list (concat "^[ \t]*\\#[ \t]*"
4631 "\\(include\\|import\\)"
4632 "[ \t]*\\(<[^>]+\\(>\\)?\\)")
4633 '(2 font-lock-string-face))
4634 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
4635 preprocessor-keywords
4636 "\\)\\>\\|[0-9]+\\|$\\)\\)")
4637 '(1 font-lock-keyword-face)))
4638 messages-mode-keywords)))
4639 (run-hooks 'cpp-messages-mode-hook))
4642 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
4643 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
4644 ;; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
4647 ;;;--------------------------------------------------------------------------
4648 ;;; Messages-file mode.
4650 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
4651 "Face to use for subsittution directives.")
4652 (make-face 'mallow-driver-substitution-face)
4653 (defvar mallow-driver-text-face 'mallow-driver-text-face
4654 "Face to use for body text.")
4655 (make-face 'mallow-driver-text-face)
4657 (defun mallow-driver-mode ()
4660 (setq major-mode 'mallow-driver-mode)
4661 (setq mode-name "Mallow driver")
4662 (setq mallow-driver-mode-syntax-table (make-syntax-table))
4663 (set-syntax-table mallow-driver-mode-syntax-table)
4664 (make-local-variable 'comment-start)
4665 (make-local-variable 'comment-end)
4666 (make-local-variable 'indent-line-function)
4667 (setq indent-line-function 'indent-relative)
4668 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4669 (make-local-variable 'font-lock-defaults)
4670 (make-local-variable 'mallow-driver-mode-keywords)
4672 (mdw-regexps "each" "divert" "file" "if"
4673 "perl" "set" "string" "type" "write")))
4674 (setq mallow-driver-mode-keywords
4676 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
4677 '(0 font-lock-keyword-face))
4678 (list "^%\\s *\\(#.*\\)?$"
4679 '(0 font-lock-comment-face))
4681 '(0 font-lock-keyword-face))
4682 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
4684 '(0 mallow-driver-substitution-face t)))))
4685 (setq font-lock-defaults
4686 '(mallow-driver-mode-keywords nil nil nil nil))
4687 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
4688 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
4689 (setq comment-start "%# ")
4690 (setq comment-end "")
4691 (run-hooks 'mallow-driver-mode-hook))
4694 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t))
4696 ;;;--------------------------------------------------------------------------
4699 (defun nfast-debug-mode ()
4702 (setq major-mode 'nfast-debug-mode)
4703 (setq mode-name "NFast debug")
4704 (setq messages-mode-syntax-table (make-syntax-table))
4705 (set-syntax-table messages-mode-syntax-table)
4706 (make-local-variable 'font-lock-defaults)
4707 (make-local-variable 'nfast-debug-mode-keywords)
4708 (setq truncate-lines t)
4709 (setq nfast-debug-mode-keywords
4711 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
4712 (0 font-lock-keyword-face))
4713 (list (concat "^[ \t]+\\(\\("
4714 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4715 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4717 "[0-9a-fA-F]+\\)[ \t]*$")
4718 '(0 mdw-number-face))
4719 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
4720 (1 font-lock-keyword-face))
4721 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
4722 (1 font-lock-warning-face))
4723 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
4725 (list (concat "^[ \t]+\\.cmd=[ \t]+"
4726 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
4727 '(1 font-lock-keyword-face))
4728 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
4729 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
4730 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
4731 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
4732 (setq font-lock-defaults
4733 '(nfast-debug-mode-keywords nil nil nil nil))
4734 (run-hooks 'nfast-debug-mode-hook))
4736 ;;;--------------------------------------------------------------------------
4737 ;;; Lispy languages.
4739 ;; Unpleasant bodge.
4740 (unless (boundp 'slime-repl-mode-map)
4741 (setq slime-repl-mode-map (make-sparse-keymap)))
4743 (defun mdw-indent-newline-and-indent ()
4745 (indent-for-tab-command)
4746 (newline-and-indent))
4748 (eval-after-load "cl-indent"
4750 (mapc #'(lambda (pair)
4752 'common-lisp-indent-function
4754 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
4755 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
4757 (defun mdw-common-lisp-indent ()
4758 (make-local-variable 'lisp-indent-function)
4759 (setq lisp-indent-function 'common-lisp-indent-function))
4761 (defmacro mdw-advise-hyperspec-lookup (func args)
4762 `(defadvice ,func (around mdw-browse-w3m ,args activate compile)
4764 (let ((browse-url-browser-function #'mdw-w3m-browse-url))
4767 (mdw-advise-hyperspec-lookup common-lisp-hyperspec (symbol))
4768 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-format (char))
4769 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-lookup-reader-macro (char))
4771 (defun mdw-fontify-lispy ()
4774 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
4776 ;; Not much fontification needed.
4777 (make-local-variable 'font-lock-keywords)
4778 (setq font-lock-keywords
4779 (list (list (concat "\\("
4781 "\\(" "[0-9]+/[0-9]+"
4782 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
4784 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
4789 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
4790 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
4791 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
4792 "\\|" "[0-9]+" "r" "[-+]?"
4793 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
4796 '(0 mdw-number-face))
4797 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4798 '(0 mdw-punct-face)))))
4800 ;; Special indentation.
4802 (defcustom mdw-lisp-loop-default-indent 2
4803 "Default indent for simple `loop' body."
4806 (defcustom mdw-lisp-setf-value-indent 2
4807 "Default extra indent for `setf' values."
4808 :type 'integer :safe 'integerp)
4810 (setq lisp-simple-loop-indentation 0
4811 lisp-loop-keyword-indentation 0
4812 lisp-loop-forms-indentation 2
4813 lisp-lambda-list-keyword-parameter-alignment t)
4815 (defun mdw-indent-funcall
4816 (path state &optional indent-point sexp-column normal-indent)
4817 "Indent `funcall' more usefully.
4818 Essentially, treat `funcall foo' as a function name, and align the arguments
4820 (and (or (not (consp path)) (null (cadr path)))
4822 (goto-char (cadr state))
4824 (let ((start-line (line-number-at-pos)))
4825 (and (condition-case nil (progn (forward-sexp 3) t)
4829 (and (= start-line (line-number-at-pos))
4830 (current-column))))))))
4832 (put 'funcall 'common-lisp-indent-function 'mdw-indent-funcall)
4833 (put 'funcall 'lisp-indent-function 'mdw-indent-funcall))
4835 (defun mdw-indent-setf
4836 (path state &optional indent-point sexp-column normal-indent)
4837 "Indent `setf' more usefully.
4838 If the values aren't on the same lines as their variables then indent them
4839 by `mdw-lisp-setf-value-indent' spaces."
4840 (and (or (not (consp path)) (null (cadr path)))
4841 (let ((basic-indent (save-excursion
4842 (goto-char (cadr state))
4844 (and (condition-case nil
4845 (progn (forward-sexp 2) t)
4849 (current-column)))))
4850 (offset (if (consp path) (car path)
4855 (goto-char (cadr state))
4857 (while (< (point) start)
4858 (condition-case nil (forward-sexp 1)
4859 (scan-error (throw 'done nil)))
4862 (and basic-indent offset
4863 (list (+ basic-indent
4865 mdw-lisp-setf-value-indent))
4868 (put 'setf 'common-lisp-indent-functopion 'mdw-indent-setf)
4869 (put 'psetf 'common-lisp-indent-function 'mdw-indent-setf)
4870 (put 'setq 'common-lisp-indent-function 'mdw-indent-setf)
4871 (put 'setf 'lisp-indent-function 'mdw-indent-setf)
4872 (put 'setq 'lisp-indent-function 'mdw-indent-setf)
4873 (put 'setq-local 'lisp-indent-function 'mdw-indent-setf)
4874 (put 'setq-default 'lisp-indent-function 'mdw-indent-setf))
4876 (defadvice common-lisp-loop-part-indentation
4877 (around mdw-fix-loop-indentation (indent-point state) activate compile)
4878 "Improve `loop' indentation.
4879 If the first subform is on the same line as the `loop' keyword, then
4880 align the other subforms beneath it. Otherwise, indent them
4881 `mdw-lisp-loop-default-indent' columns in from the opening parenthesis."
4883 (let* ((loop-indentation (save-excursion
4884 (goto-char (elt state 1))
4887 ;; Don't really care about this.
4888 (when (and (boundp 'lisp-indent-backquote-substitution-mode)
4889 (eq lisp-indent-backquote-substitution-mode 'corrected))
4891 (goto-char (elt state 1))
4892 (incf loop-indentation
4893 (cond ((eq (char-before) ?,) -1)
4894 ((and (eq (char-before) ?@)
4895 (progn (backward-char)
4896 (eq (char-before) ?,)))
4900 ;; If the first loop item is on the same line as the `loop' itself then
4901 ;; use that as the baseline. Otherwise advance by the default indent.
4902 (goto-char (cadr state))
4904 (let ((baseline-indent
4905 (if (= (line-number-at-pos)
4906 (if (condition-case nil (progn (forward-sexp 2) t)
4908 (progn (forward-sexp -1) (line-number-at-pos))
4911 (+ loop-indentation mdw-lisp-loop-default-indent))))
4913 (goto-char indent-point)
4916 (setq ad-return-value
4918 (cond ((condition-case ()
4920 (goto-char (elt state 1))
4924 (not (looking-at "\\(:\\|\\sw\\)")))
4926 (+ baseline-indent lisp-simple-loop-indentation))
4927 ((looking-at "^\\s-*\\(:?\\sw+\\|;\\)")
4928 (+ baseline-indent lisp-loop-keyword-indentation))
4930 (+ baseline-indent lisp-loop-forms-indentation)))
4932 ;; Tell the caller that the next line needs recomputation,
4933 ;; even though it doesn't start a sexp.
4934 loop-indentation)))))
4938 (defcustom mdw-friendly-name "[mdw]"
4939 "How I want to be addressed."
4942 (defadvice slime-user-first-name
4943 (around mdw-use-friendly-name compile activate)
4944 (if mdw-friendly-name (setq ad-return-value mdw-friendly-name)
4949 (if (not mdw-fast-startup)
4951 (require 'slime-autoloads)
4952 (slime-setup '(slime-autodoc slime-c-p-c))))))
4954 (let ((stuff '((cmucl ("cmucl"))
4955 (sbcl ("sbcl") :coding-system utf-8-unix)
4956 (clisp ("clisp") :coding-system utf-8-unix))))
4957 (or (boundp 'slime-lisp-implementations)
4958 (setq slime-lisp-implementations nil))
4960 (let* ((head (car stuff))
4961 (found (assq (car head) slime-lisp-implementations)))
4962 (setq stuff (cdr stuff))
4964 (rplacd found (cdr head))
4965 (setq slime-lisp-implementations
4966 (cons head slime-lisp-implementations))))))
4967 (setq slime-default-lisp 'sbcl)
4972 (dolist (hook '(emacs-lisp-mode-hook
4975 inferior-lisp-mode-hook
4976 lisp-interaction-mode-hook
4978 slime-repl-mode-hook))
4979 (add-hook hook 'mdw-misc-mode-config t)
4980 (add-hook hook 'mdw-fontify-lispy t))
4981 (add-hook 'lisp-mode-hook 'mdw-common-lisp-indent t)
4982 (add-hook 'inferior-lisp-mode-hook
4983 #'(lambda () (local-set-key "\C-m" 'comint-send-and-indent)) t))
4985 ;;;--------------------------------------------------------------------------
4986 ;;; Other languages.
4990 (defun mdw-setup-smalltalk ()
4991 (and mdw-auto-indent
4992 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
4993 (make-local-variable 'mdw-auto-indent)
4994 (setq mdw-auto-indent nil)
4995 (local-set-key "\C-i" 'smalltalk-reindent))
4997 (defun mdw-fontify-smalltalk ()
4998 (make-local-variable 'font-lock-keywords)
4999 (setq font-lock-keywords
5001 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
5002 '(0 font-lock-keyword-face))
5003 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
5004 "[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
5005 "\\([eE][-+]?[0-9_]+\\)?")
5006 '(0 mdw-number-face))
5007 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
5008 '(0 mdw-punct-face)))))
5011 (add-hook 'smalltalk-mode 'mdw-misc-mode-config t)
5012 (add-hook 'smalltalk-mode 'mdw-fontify-smalltalk t))
5016 (defun mdw-setup-m4 ()
5018 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
5019 ;; annoying: fix it.
5020 (modify-syntax-entry ?{ "(")
5021 (modify-syntax-entry ?} ")")
5024 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
5026 (dolist (hook '(m4-mode-hook autoconf-mode-hook autotest-mode-hook))
5027 (add-hook hook #'mdw-misc-mode-config t)
5028 (add-hook hook #'mdw-setup-m4 t))
5033 (add-hook 'makefile-mode-hook 'mdw-misc-mode-config t))
5035 ;;;--------------------------------------------------------------------------
5038 (defun mdw-text-mode ()
5039 (setq fill-column 72)
5041 (mdw-standard-fill-prefix
5042 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
5045 (eval-after-load "flyspell"
5046 '(define-key flyspell-mode-map "\C-\M-i" nil))
5049 (add-hook 'text-mode-hook 'mdw-text-mode t))
5051 ;;;--------------------------------------------------------------------------
5052 ;;; Outline and hide/show modes.
5054 (defun mdw-outline-collapse-all ()
5055 "Completely collapse everything in the entire buffer."
5058 (goto-char (point-min))
5059 (while (< (point) (point-max))
5063 (setq hs-hide-comments-when-hiding-all nil)
5065 (defadvice hs-hide-all (after hide-first-comment activate)
5066 (save-excursion (hs-hide-initial-comment-block)))
5068 ;;;--------------------------------------------------------------------------
5071 (defun mdw-sh-mode-setup ()
5072 (local-set-key [?\C-a] 'comint-bol)
5073 (add-hook 'comint-output-filter-functions
5074 'comint-watch-for-password-prompt))
5076 (defun mdw-term-mode-setup ()
5077 (setq term-prompt-regexp shell-prompt-pattern)
5078 (make-local-variable 'mouse-yank-at-point)
5079 (make-local-variable 'transient-mark-mode)
5080 (setq mouse-yank-at-point t)
5084 (defun comint-send-and-indent ()
5087 (and mdw-auto-indent
5088 (indent-for-tab-command)))
5090 (defadvice comint-line-beginning-position
5091 (around mdw-calculate-it-properly () activate compile)
5092 "Calculate the actual line start for multi-line input."
5093 (if (or comint-use-prompt-regexp
5094 (eq (field-at-pos (point)) 'output))
5096 (setq ad-return-value
5097 (constrain-to-field (line-beginning-position) (point)))))
5099 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
5100 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
5101 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
5102 (defun term-send-meta-meta-something ()
5104 (term-send-raw-string "\e\e")
5106 (eval-after-load 'term
5108 (define-key term-raw-map [?\e ?\e] nil)
5109 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
5110 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
5111 (define-key term-raw-map [M-right] 'term-send-meta-right)
5112 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
5113 (define-key term-raw-map [M-left] 'term-send-meta-left)
5114 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
5116 (defadvice term-exec (before program-args-list compile activate)
5117 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
5118 This allows you to pass a list of arguments through `ansi-term'."
5119 (let ((program (ad-get-arg 2)))
5122 (ad-set-arg 2 (car program))
5123 (ad-set-arg 4 (cdr program))))))
5125 (defadvice term-exec-1 (around hack-environment compile activate)
5126 "Hack the environment inherited by inferiors in the terminal."
5127 (let ((process-environment (copy-tree process-environment)))
5128 (setenv "LD_PRELOAD" nil)
5131 (defadvice shell (around hack-environment compile activate)
5132 "Hack the environment inherited by inferiors in the shell."
5133 (let ((process-environment (copy-tree process-environment)))
5134 (setenv "LD_PRELOAD" nil)
5138 "Open a terminal containing an ssh session to the HOST."
5139 (interactive "sHost: ")
5140 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
5142 (defcustom git-grep-command
5143 "env GIT_PAGER=cat git grep --no-color -nH -e "
5144 "The default command for \\[git-grep]."
5147 (defvar git-grep-history nil)
5149 (defun git-grep (command-args)
5150 "Run `git grep' with user-specified args and collect output in a buffer."
5152 (list (read-shell-command "Run git grep (like this): "
5153 git-grep-command 'git-grep-history)))
5154 (let ((grep-use-null-device nil))
5155 (grep command-args)))
5157 ;;;--------------------------------------------------------------------------
5158 ;;; Magit configuration.
5160 (setq magit-diff-refine-hunk 't
5161 magit-view-git-manual-method 'man
5162 magit-log-margin '(nil age magit-log-margin-width t 18)
5163 magit-wip-after-save-local-mode-lighter ""
5164 magit-wip-after-apply-mode-lighter ""
5165 magit-wip-before-change-mode-lighter "")
5166 (eval-after-load "magit"
5167 '(progn (global-magit-file-mode 1)
5168 (magit-wip-after-save-mode 1)
5169 (magit-wip-after-apply-mode 1)
5170 (magit-wip-before-change-mode 1)
5171 (add-to-list 'magit-no-confirm 'safe-with-wip)
5172 (add-to-list 'magit-no-confirm 'trash)
5173 (push '(:eval (if (or magit-wip-after-save-local-mode
5174 magit-wip-after-apply-mode
5175 magit-wip-before-change-mode)
5176 (format " wip:%s%s%s"
5177 (if magit-wip-after-apply-mode "A" "")
5178 (if magit-wip-before-change-mode "C" "")
5179 (if magit-wip-after-save-local-mode "S" ""))))
5181 (dolist (popup '(magit-diff-popup
5182 magit-diff-refresh-popup
5183 magit-diff-mode-refresh-popup
5184 magit-revision-mode-refresh-popup))
5185 (magit-define-popup-switch popup ?R "Reverse diff" "-R"))
5186 (magit-define-popup-switch 'magit-rebase-popup ?r
5187 "Rebase merges" "--rebase-merges")))
5189 (defadvice magit-wip-commit-buffer-file
5190 (around mdw-just-this-buffer activate compile)
5191 (let ((magit-save-repository-buffers nil)) ad-do-it))
5193 (defadvice magit-discard
5194 (around mdw-delete-if-prefix-argument activate compile)
5195 (let ((magit-delete-by-moving-to-trash
5196 (and (null current-prefix-arg)
5197 magit-delete-by-moving-to-trash)))
5200 (setq magit-repolist-columns
5201 '(("Name" 16 magit-repolist-column-ident nil)
5202 ("Version" 18 magit-repolist-column-version nil)
5203 ("St" 2 magit-repolist-column-dirty nil)
5204 ("L<U" 3 mdw-repolist-column-unpulled-from-upstream nil)
5205 ("L>U" 3 mdw-repolist-column-unpushed-to-upstream nil)
5206 ("Path" 32 magit-repolist-column-path nil)))
5208 (setq magit-repository-directories '(("~/etc/profile" . 0)
5211 (defadvice magit-list-repos (around mdw-dirname () activate compile)
5212 "Make sure the returned names are directory names.
5213 Otherwise child processes get started in the wrong directory and
5215 (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it)))
5217 (defun mdw-repolist-column-unpulled-from-upstream (_id)
5218 "Insert number of upstream commits not in the current branch."
5219 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
5221 (let ((n (cadr (magit-rev-diff-count "HEAD" upstream))))
5222 (propertize (number-to-string n) 'face
5223 (if (> n 0) 'bold 'shadow))))))
5225 (defun mdw-repolist-column-unpushed-to-upstream (_id)
5226 "Insert number of commits in the current branch but not its upstream."
5227 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
5229 (let ((n (car (magit-rev-diff-count "HEAD" upstream))))
5230 (propertize (number-to-string n) 'face
5231 (if (> n 0) 'bold 'shadow))))))
5233 (defun mdw-try-smerge ()
5235 (goto-char (point-min))
5236 (when (re-search-forward "^<<<<<<< " nil t)
5238 (add-hook 'find-file-hook 'mdw-try-smerge t)
5240 (defcustom mdw-magit-new-window-modes
5247 "Magit modes which should cause a new window to be used."
5248 :type '(repeat symbol))
5250 (defun mdw-display-magit-buffer (buffer)
5251 "Like `magit-display-buffer-traditional'.
5252 But uses `mdw-magit-new-window-modes' for its list of modes
5253 rather than baking the list into the function."
5254 (display-buffer buffer
5255 (let ((mode (with-current-buffer buffer major-mode)))
5256 (if (and (not mdw-designated-window)
5257 (derived-mode-p 'magit-mode)
5258 (mdw-submode-p mode 'magit-mode)
5259 (not (memq mode mdw-magit-new-window-modes)))
5260 '(display-buffer-same-window . nil)
5262 (setq magit-display-buffer-function 'mdw-display-magit-buffer)
5264 (defun mdw-display-magit-file-buffer (buffer)
5265 "Show a file buffer from a diff."
5266 (select-window (display-buffer buffer)))
5267 (setq magit-display-file-buffer-function 'mdw-display-magit-file-buffer)
5269 ;;;--------------------------------------------------------------------------
5270 ;;; GUD, and especially GDB.
5272 ;; Inhibit window dedication. I mean, seriously, wtf?
5273 (defadvice gdb-display-buffer (after mdw-undedicated (buf) compile activate)
5274 "Don't make windows dedicated. Seriously."
5275 (set-window-dedicated-p ad-return-value nil))
5276 (defadvice gdb-set-window-buffer
5277 (after mdw-undedicated (name &optional ignore-dedicated window)
5279 "Don't make windows dedicated. Seriously."
5280 (set-window-dedicated-p (or window (selected-window)) nil))
5282 ;;;--------------------------------------------------------------------------
5285 (setq sql-postgres-options '("-n" "-P" "pager=off")
5286 sql-postgres-login-params
5287 '((user :default "mdw")
5288 (database :default "mdw")
5289 (server :default "db.distorted.org.uk")))
5291 ;;;--------------------------------------------------------------------------
5294 ;; Turn off `noip' when running `man': it interferes with `man-db''s own
5295 ;; seccomp(2)-based sandboxing, which is (in this case, at least) strictly
5297 (defadvice Man-getpage-in-background
5298 (around mdw-inhibit-noip (topic) compile activate)
5299 "Inhibit the `noip' preload hack when invoking `man'."
5300 (let* ((old-preload (getenv "LD_PRELOAD"))
5301 (preloads (and old-preload
5302 (save-match-data (split-string old-preload ":"))))
5307 (let ((item (pop preloads)))
5308 (if (string-match "\\(/\\|^\\)noip\.so\\(:\\|$\\)" item)
5310 (push item filtered)))))
5314 (setenv "LD_PRELOAD"
5316 (with-output-to-string
5317 (setq filtered (nreverse filtered))
5320 (if first (setq first nil)
5322 (write-string (pop filtered)))))))
5324 (setenv "LD_PRELOAD" old-preload))
5327 ;;;--------------------------------------------------------------------------
5328 ;;; MPC configuration.
5330 (eval-when-compile (trap (require 'mpc)))
5332 (setq mpc-browser-tags '(Artist|Composer|Performer Album|Playlist))
5334 (defun mdw-mpc-now-playing ()
5338 (set-buffer (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))))
5339 (mpc--status-callback))
5340 (let ((state (cdr (assq 'state mpc-status))))
5341 (cond ((member state '("stop"))
5342 (message "mpd stopped."))
5343 ((member state '("play" "pause"))
5344 (let* ((artist (cdr (assq 'Artist mpc-status)))
5345 (album (cdr (assq 'Album mpc-status)))
5346 (title (cdr (assq 'Title mpc-status)))
5347 (file (cdr (assq 'file mpc-status)))
5348 (duration-string (cdr (assq 'Time mpc-status)))
5349 (time-string (cdr (assq 'time mpc-status)))
5350 (time (and time-string
5352 (if (string-match ":" time-string)
5353 (substring time-string
5354 0 (match-beginning 0))
5356 (duration (and duration-string
5357 (string-to-number duration-string)))
5358 (pos (and time duration
5359 (format " [%d:%02d/%d:%02d]"
5360 (/ time 60) (mod time 60)
5361 (/ duration 60) (mod duration 60))))
5362 (fmt (cond ((and artist title)
5363 (format "`%s' by %s%s" title artist
5364 (if album (format ", from `%s'" album)
5367 (format "`%s' (no tags)" file))
5369 "(no idea what's playing!)"))))
5370 (if (string= state "play")
5371 (message "mpd playing %s%s" fmt (or pos ""))
5372 (message "mpd paused in %s%s" fmt (or pos "")))))
5374 (message "mpd in unknown state `%s'" state)))))
5376 (defmacro mdw-define-mpc-wrapper (func bvl interactive &rest body)
5378 (interactive ,@interactive)
5381 (mdw-mpc-now-playing)))
5383 (mdw-define-mpc-wrapper mdw-mpc-play-or-pause () nil
5384 (if (member (cdr (assq 'state (mpc-cmd-status))) '("play"))
5388 (mdw-define-mpc-wrapper mdw-mpc-next () nil (mpc-next))
5389 (mdw-define-mpc-wrapper mdw-mpc-prev () nil (mpc-prev))
5390 (mdw-define-mpc-wrapper mdw-mpc-stop () nil (mpc-stop))
5392 (defun mdw-mpc-louder (step)
5393 (interactive (list (if current-prefix-arg
5394 (prefix-numeric-value current-prefix-arg)
5396 (mpc-proc-cmd (format "volume %+d" step)))
5398 (defun mdw-mpc-quieter (step)
5399 (interactive (list (if current-prefix-arg
5400 (prefix-numeric-value current-prefix-arg)
5402 (mpc-proc-cmd (format "volume %+d" (- step))))
5404 (defun mdw-mpc-hack-lines (arg interactivep func)
5405 (if (and interactivep (use-region-p))
5406 (let ((from (region-beginning)) (to (region-end)))
5411 (while (< (point) to)
5414 (let ((n (prefix-numeric-value arg)))
5431 (defun mdw-mpc-select-one ()
5432 (when (and (get-char-property (point) 'mpc-file)
5433 (not (get-char-property (point) 'mpc-select)))
5434 (mpc-select-toggle)))
5436 (defun mdw-mpc-unselect-one ()
5437 (when (get-char-property (point) 'mpc-select)
5438 (mpc-select-toggle)))
5440 (defun mdw-mpc-select (&optional arg interactivep)
5441 (interactive (list current-prefix-arg t))
5442 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
5444 (defun mdw-mpc-unselect (&optional arg interactivep)
5445 (interactive (list current-prefix-arg t))
5446 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one))
5448 (defun mdw-mpc-unselect-backwards (arg)
5450 (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one))
5452 (defun mdw-mpc-unselect-all ()
5454 (setq mpc-select nil)
5455 (mpc-selection-refresh))
5457 (defun mdw-mpc-next-line (arg)
5462 (defun mdw-mpc-previous-line (arg)
5465 (forward-line (- arg)))
5467 (defun mdw-mpc-playlist-add (&optional arg interactivep)
5468 (interactive (list current-prefix-arg t))
5469 (let ((mpc-select mpc-select))
5470 (when (or arg (and interactivep (use-region-p)))
5471 (setq mpc-select nil)
5472 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
5473 (setq mpc-select (reverse mpc-select))
5474 (mpc-playlist-add)))
5476 (defun mdw-mpc-playlist-delete (&optional arg interactivep)
5477 (interactive (list current-prefix-arg t))
5478 (setq mpc-select (nreverse mpc-select))
5480 (when (or arg (and interactivep (use-region-p)))
5481 (setq mpc-select nil)
5482 (mpc-selection-refresh)
5483 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
5484 (mpc-playlist-delete)))
5486 (defun mdw-mpc-hack-tagbrowsers ()
5487 (setq-local mode-line-format
5489 mode-line-frame-identification
5490 mode-line-buffer-identification)))
5491 (add-hook 'mpc-tagbrowser-mode-hook 'mdw-mpc-hack-tagbrowsers)
5493 (defun mdw-mpc-hack-songs ()
5494 (setq-local header-line-format
5495 ;; '("MPC " mpc-volume " " mpc-current-song)
5496 (list (propertize " " 'display '(space :align-to 0))
5497 ;; 'mpc-songs-format-description
5499 (let ((deactivate-mark) (hscroll (window-hscroll)))
5501 (mpc-format mpc-songs-format 'self hscroll)
5502 ;; That would be simpler than the hscroll handling in
5503 ;; mpc-format, but currently move-to-column does not
5504 ;; recognize :space display properties.
5505 ;; (move-to-column hscroll)
5506 ;; (delete-region (point-min) (point))
5507 (buffer-string)))))))
5508 (add-hook 'mpc-songs-mode-hook 'mdw-mpc-hack-songs)
5510 (eval-after-load "mpc"
5512 (define-key mpc-mode-map "m" 'mdw-mpc-select)
5513 (define-key mpc-mode-map "u" 'mdw-mpc-unselect)
5514 (define-key mpc-mode-map "\177" 'mdw-mpc-unselect-backwards)
5515 (define-key mpc-mode-map "\e\177" 'mdw-mpc-unselect-all)
5516 (define-key mpc-mode-map "n" 'mdw-mpc-next-line)
5517 (define-key mpc-mode-map "p" 'mdw-mpc-previous-line)
5518 (define-key mpc-mode-map "/" 'mpc-songs-search)
5519 (setq mpc-songs-mode-map (make-sparse-keymap))
5520 (set-keymap-parent mpc-songs-mode-map mpc-mode-map)
5521 (define-key mpc-songs-mode-map "l" 'mpc-playlist)
5522 (define-key mpc-songs-mode-map "+" 'mdw-mpc-playlist-add)
5523 (define-key mpc-songs-mode-map "-" 'mdw-mpc-playlist-delete)
5524 (define-key mpc-songs-mode-map "\r" 'mpc-songs-jump-to)))
5526 ;;;--------------------------------------------------------------------------
5527 ;;; Inferior Emacs Lisp.
5529 (setq comint-prompt-read-only t)
5531 (eval-after-load "comint"
5533 (define-key comint-mode-map "\C-w" 'comint-kill-region)
5534 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
5536 (eval-after-load "ielm"
5538 (define-key ielm-map "\C-w" 'comint-kill-region)
5539 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
5541 ;;;----- That's all, folks --------------------------------------------------
5543 (provide 'dot-emacs)