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)
62 (defmacro mdw-regexps (&rest list)
63 "Turn a LIST of strings into a single regular expression at compile-time."
66 `',(make-regexp list))
69 "This is not the key sequence you're looking for."
71 (error "wrong button"))
73 (defun mdw-emacs-version-p (major &optional minor)
74 "Return non-nil if the running Emacs is at least version MAJOR.MINOR."
75 (or (> emacs-major-version major)
76 (and (= emacs-major-version major)
77 (>= emacs-minor-version (or minor 0)))))
79 ;; Some error trapping.
81 ;; If individual bits of this file go tits-up, we don't particularly want
82 ;; the whole lot to stop right there and then, because it's bloody annoying.
84 (defmacro trap (&rest forms)
85 "Execute FORMS without allowing errors to propagate outside."
89 ,(if (cdr forms) (cons 'progn forms) (car forms))
90 (error (message "Error (trapped): %s in %s"
91 (error-message-string err)
94 ;; Configuration reading.
96 (defvar mdw-config nil)
97 (defun mdw-config (sym)
98 "Read the configuration variable named SYM."
101 (flet ((replace (what with)
102 (goto-char (point-min))
103 (while (re-search-forward what nil t)
104 (replace-match with t))))
106 (insert-file-contents "~/.mdw.conf")
107 (replace "^[ \t]*\\(#.*\\)?\n" "")
108 (replace (concat "^[ \t]*"
109 "\\([-a-zA-Z0-9_.]*\\)"
112 "[ \t]**\\(\n\\|$\\)")
114 (car (read-from-string
115 (concat "(" (buffer-string) ")")))))))
116 (cdr (assq sym mdw-config)))
118 ;; Width configuration.
120 (defcustom mdw-column-width
121 (string-to-number (or (mdw-config 'emacs-width) "77"))
122 "Width of Emacs columns."
124 (defcustom mdw-text-width mdw-column-width
125 "Expected width of text within columns."
129 ;; Local variables hacking.
131 (defun run-local-vars-mode-hook ()
132 "Run a hook for the major-mode after local variables have been processed."
133 (run-hooks (intern (concat (symbol-name major-mode)
134 "-local-variables-hook"))))
135 (add-hook 'hack-local-variables-hook 'run-local-vars-mode-hook)
137 ;; Set up the load path convincingly.
139 (dolist (dir (append (and (boundp 'debian-emacs-flavor)
140 (list (concat "/usr/share/"
141 (symbol-name debian-emacs-flavor)
143 (dolist (sub (directory-files dir t))
144 (when (and (file-accessible-directory-p sub)
145 (not (member sub load-path)))
146 (setq load-path (nconc load-path (list sub))))))
148 ;; Is an Emacs library available?
150 (defun library-exists-p (name)
151 "Return non-nil if NAME is an available library.
152 Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
153 load path. The non-nil value is the filename we found for the
155 (let ((path load-path) elt (foundp nil))
156 (while (and path (not foundp))
157 (setq elt (car path))
158 (setq path (cdr path))
159 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
160 (and (file-exists-p file) file))
161 (let ((file (concat elt "/" name ".el")))
162 (and (file-exists-p file) file)))))
165 (defun maybe-autoload (symbol file &optional docstring interactivep type)
166 "Set an autoload if the file actually exists."
167 (and (library-exists-p file)
168 (autoload symbol file docstring interactivep type)))
170 (defun mdw-kick-menu-bar (&optional frame)
171 "Regenerate FRAME's menu bar so it doesn't have empty menus."
173 (unless frame (setq frame (selected-frame)))
174 (let ((old (frame-parameter frame 'menu-bar-lines)))
175 (set-frame-parameter frame 'menu-bar-lines 0)
176 (set-frame-parameter frame 'menu-bar-lines old)))
180 (defun mdw-fixup-page-position ()
181 (unless (eq (char-before (point)) ?
\f)
184 (defadvice backward-page (after mdw-fixup compile activate)
185 (mdw-fixup-page-position))
186 (defadvice forward-page (after mdw-fixup compile activate)
187 (mdw-fixup-page-position))
189 ;; Splitting windows.
191 (unless (fboundp 'scroll-bar-columns)
192 (defun scroll-bar-columns (side)
193 (cond ((eq side 'left) 0)
196 (unless (fboundp 'fringe-columns)
197 (defun fringe-columns (side)
198 (cond ((not window-system) 0)
202 (defun mdw-horizontal-window-overhead ()
203 "Computes the horizontal window overhead.
204 This is the number of columns used by fringes, scroll bars and other such
206 (if (not window-system)
209 (dolist (what '(scroll-bar fringe))
210 (dolist (side '(left right))
211 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
215 (defun mdw-split-window-horizontally (&optional width)
216 "Split a window horizontally.
217 Without a numeric argument, split the window approximately in
218 half. With a numeric argument WIDTH, allocate WIDTH columns to
219 the left-hand window (if positive) or -WIDTH columns to the
220 right-hand window (if negative). Space for scroll bars and
221 fringes is not taken out of the allowance for WIDTH, unlike
222 \\[split-window-horizontally]."
224 (split-window-horizontally
225 (cond ((null width) nil)
226 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
227 ((< width 0) width))))
229 (defun mdw-preferred-column-width ()
230 "Return the preferred column width."
231 (if (and window-system (mdw-emacs-version-p 22)) mdw-column-width
232 (1+ mdw-column-width)))
234 (defun mdw-divvy-window (&optional width)
235 "Split a wide window into appropriate widths."
237 (setq width (if width (prefix-numeric-value width)
238 (mdw-preferred-column-width)))
239 (let* ((win (selected-window))
240 (sb-width (mdw-horizontal-window-overhead))
241 (c (/ (+ (window-width) sb-width)
242 (+ width sb-width))))
245 (split-window-horizontally (+ width sb-width))
247 (select-window win)))
249 (defun mdw-set-frame-width (columns &optional width)
250 "Set the current frame to be the correct width for COLUMNS columns.
252 If WIDTH is non-nil, then it provides the width for the new columns. (This
253 can be set interactively with a prefix argument.)"
254 (interactive "nColumns:
256 (setq width (if width (prefix-numeric-value width)
257 (mdw-preferred-column-width)))
258 (let ((sb-width (mdw-horizontal-window-overhead)))
259 (set-frame-width (selected-frame)
260 (- (* columns (+ width sb-width))
262 (mdw-divvy-window width)))
264 (defcustom mdw-frame-width-fudge
265 (cond ((<= emacs-major-version 20) 1)
266 ((= emacs-major-version 26) 3)
268 "The number of extra columns to add to the desired frame width.
270 This is sadly necessary because Emacs 26 is broken in this regard."
273 (defcustom mdw-frame-colour-alist
274 '((black . ("#000000" . "#ffffff"))
275 (red . ("#2a0000" . "#ffffff"))
276 (green . ("#002a00" . "#ffffff"))
277 (blue . ("#00002a" . "#ffffff")))
278 "Alist mapping symbol names to (FOREGROUND . BACKGROUND) colour pairs."
279 :type '(alist :key-type symbol :value-type (cons color color)))
281 (defun mdw-set-frame-colour (colour &optional frame)
282 (interactive "xColour name or (FOREGROUND . BACKGROUND) pair:
284 (when (and colour (symbolp colour))
285 (let ((entry (assq colour mdw-frame-colour-alist)))
286 (unless entry (error "Unknown colour `%s'" colour))
287 (setf colour (cdr entry))))
288 (set-frame-parameter frame 'background-color (car colour))
289 (set-frame-parameter frame 'foreground-color (cdr colour)))
291 ;; Don't raise windows unless I say so.
293 (defcustom mdw-inhibit-raise-frame nil
294 "Whether `raise-frame' should do nothing when the frame is mapped."
297 (defadvice raise-frame
298 (around mdw-inhibit (&optional frame) activate compile)
299 "Don't actually do anything if `mdw-inhibit-raise-frame' is true, and the
300 frame is actually mapped on the screen."
301 (if mdw-inhibit-raise-frame
302 (make-frame-visible frame)
305 (defmacro mdw-advise-to-inhibit-raise-frame (function)
306 "Advise the FUNCTION not to raise frames, even if it wants to."
307 `(defadvice ,function
308 (around mdw-inhibit-raise (&rest hunoz) activate compile)
309 "Don't raise the window unless you have to."
310 (let ((mdw-inhibit-raise-frame t))
313 (mdw-advise-to-inhibit-raise-frame select-frame-set-input-focus)
314 (mdw-advise-to-inhibit-raise-frame appt-disp-window)
315 (mdw-advise-to-inhibit-raise-frame mouse-select-window)
317 ;; Bug fix for markdown-mode, which breaks point positioning during
319 (defadvice markdown-check-change-for-wiki-link
320 (around mdw-save-match activate compile)
321 "Save match data around the `markdown-mode' `after-change-functions' hook."
322 (save-match-data ad-do-it))
324 ;; Bug fix for `bbdb-canonicalize-address': on Emacs 24, `run-hook-with-args'
325 ;; always returns nil, with the result that all email addresses are lost.
326 ;; Replace the function entirely.
327 (defadvice bbdb-canonicalize-address
328 (around mdw-bug-fix activate compile)
329 "Don't use `run-hook-with-args', because that doesn't work."
330 (let ((net (ad-get-arg 0)))
332 ;; Make sure this is a proper hook list.
333 (if (functionp bbdb-canonicalize-net-hook)
334 (setq bbdb-canonicalize-net-hook (list bbdb-canonicalize-net-hook)))
336 ;; Iterate over the hooks until things converge.
339 (let (next (changep nil)
340 hook (hooks bbdb-canonicalize-net-hook))
342 (setq hook (pop hooks))
343 (setq next (funcall hook net))
344 (if (not (equal next net))
347 (setq donep (not changep)))))
348 (setq ad-return-value net)))
350 ;; Transient mark mode hacks.
352 (defadvice exchange-point-and-mark
353 (around mdw-highlight (&optional arg) activate compile)
354 "Maybe don't actually exchange point and mark.
355 If `transient-mark-mode' is on and the mark is inactive, then
356 just activate it. A non-trivial prefix argument will force the
357 usual behaviour. A trivial prefix argument (i.e., just C-u) will
358 activate the mark and temporarily enable `transient-mark-mode' if
360 (cond ((or mark-active
361 (and (not transient-mark-mode) (not arg))
362 (and arg (or (not (consp arg))
363 (not (= (car arg) 4)))))
366 (or transient-mark-mode (setq transient-mark-mode 'only))
367 (set-mark (mark t)))))
369 ;; Functions for sexp diary entries.
371 (defvar mdw-diary-for-org-mode-p nil
372 "Display diary along with the agenda?")
374 (defun mdw-not-org-mode (form)
375 "As FORM, but not in Org mode agenda."
376 (and (not mdw-diary-for-org-mode-p)
379 (defun mdw-weekday (l)
380 "Return non-nil if `date' falls on one of the days of the week in L.
381 L is a list of day numbers (from 0 to 6 for Sunday through to
382 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
383 the date stored in `date' falls on a listed day, then the
384 function returns non-nil."
385 (let ((d (calendar-day-of-week date)))
387 (memq (nth d '(sunday monday tuesday wednesday
388 thursday friday saturday)) l))))
390 (defun mdw-discordian-date (date)
391 "Return the Discordian calendar date corresponding to DATE.
393 The return value is (YOLD . st-tibs-day) or (YOLD SEASON DAYNUM DOW).
395 The original is by David Pearson. I modified it to produce date components
396 as output rather than a string."
397 (let* ((days ["Sweetmorn" "Boomtime" "Pungenday"
398 "Prickle-Prickle" "Setting Orange"])
399 (months ["Chaos" "Discord" "Confusion"
400 "Bureaucracy" "Aftermath"])
401 (day-count [0 31 59 90 120 151 181 212 243 273 304 334])
402 (year (- (calendar-extract-year date) 1900))
403 (month (1- (calendar-extract-month date)))
404 (day (1- (calendar-extract-day date)))
405 (julian (+ (aref day-count month) day))
406 (dyear (+ year 3066)))
407 (if (and (= month 1) (= day 28))
408 (cons dyear 'st-tibs-day)
410 (aref months (floor (/ julian 73)))
412 (aref days (mod julian 5))))))
414 (defun mdw-diary-discordian-date ()
415 "Convert the date in `date' to a string giving the Discordian date."
416 (let* ((ddate (mdw-discordian-date date))
417 (tail (format "in the YOLD %d" (car ddate))))
418 (if (eq (cdr ddate) 'st-tibs-day)
419 (format "St Tib's Day %s" tail)
420 (let ((season (cadr ddate))
421 (daynum (caddr ddate))
422 (dayname (cadddr ddate)))
423 (format "%s, the %d%s day of %s %s"
426 (let ((ldig (mod daynum 10)))
427 (cond ((= ldig 1) "st")
434 (defun mdw-todo (&optional when)
435 "Return non-nil today, or on WHEN, whichever is later."
436 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
437 (d (calendar-absolute-from-gregorian date)))
439 (setq w (max w (calendar-absolute-from-gregorian
441 ((not european-calendar-style)
453 (defadvice org-agenda-list (around mdw-preserve-links activate)
454 (let ((mdw-diary-for-org-mode-p t))
457 (defcustom diary-time-regexp nil
458 "Regexp matching times in the diary buffer."
461 (defadvice diary-add-to-list (before mdw-trim-leading-space compile activate)
462 "Trim leading space from the diary entry string."
464 (let ((str (ad-get-arg 1))
468 (setq str (cond ((null str) nil)
469 ((string-match "\\(^\\|\n\\)[ \t]+" str)
470 (replace-match "\\1" nil nil str))
471 ((and mdw-diary-for-org-mode-p
472 (string-match (concat
474 "\\(" diary-time-regexp
475 "\\(-" diary-time-regexp "\\)?"
477 "\\(\t[ \t]*\\| [ \t]+\\)")
479 (replace-match "\\1\\2 " nil nil str))
480 ((and (not mdw-diary-for-org-mode-p)
481 (string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]"
483 (replace-match "\\1" nil nil str))
485 (if (equal str old) (setq done t)))
486 (ad-set-arg 1 str))))
488 (defadvice org-bbdb-anniversaries (after mdw-fixup-list compile activate)
489 "Return a string rather than a list."
492 (dolist (e (let ((ee ad-return-value))
493 (if (atom ee) (list ee) ee)))
495 (when anyp (insert ?\n))
498 (setq ad-return-value
499 (and anyp (buffer-string))))))
501 ;; Fighting with Org-mode's evil key maps.
503 (defcustom mdw-evil-keymap-keys
504 '(([S-up] . [?\C-c up])
505 ([S-down] . [?\C-c down])
506 ([S-left] . [?\C-c left])
507 ([S-right] . [?\C-c right])
508 (([M-up] [?\e up]) . [C-up])
509 (([M-down] [?\e down]) . [C-down])
510 (([M-left] [?\e left]) . [C-left])
511 (([M-right] [?\e right]) . [C-right]))
512 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
513 The value is an alist mapping evil keys (as a list, or singleton)
514 to good keys (in the same form)."
515 :type '(alist :key-type (choice key-sequence (repeat key-sequence))
516 :value-type key-sequence))
518 (defun mdw-clobber-evil-keymap (keymap)
519 "Replace evil key bindings in the KEYMAP.
520 Evil key bindings are defined in `mdw-evil-keymap-keys'."
521 (dolist (entry mdw-evil-keymap-keys)
523 (keys (if (listp (car entry))
526 (replacements (if (listp (cdr entry))
528 (list (cdr entry)))))
531 (setq binding (lookup-key keymap key))
533 (throw 'found nil))))
536 (define-key keymap key nil))
537 (dolist (key replacements)
538 (define-key keymap key binding))))))
540 (defcustom mdw-org-latex-defs
542 "\\documentclass{strayman}
543 \\usepackage[utf8]{inputenc}
544 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
545 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
546 ("\\section{%s}" . "\\section*{%s}")
547 ("\\subsection{%s}" . "\\subsection*{%s}")
548 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
549 ("\\paragraph{%s}" . "\\paragraph*{%s}")
550 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
551 "Additional LaTeX class definitions."
552 :type '(alist :key-type string
553 :value-type (list string
556 :value-type string))))
558 (eval-after-load "org-latex"
559 '(setq org-export-latex-classes
560 (append mdw-org-latex-defs org-export-latex-classes)))
562 (eval-after-load "ox-latex"
563 '(setq org-latex-classes (append mdw-org-latex-defs org-latex-classes)
564 org-latex-caption-above nil
565 org-latex-default-packages-alist '(("AUTO" "inputenc" t)
573 ("normalem" "ulem" t)
579 "\\tolerance=1000")))
582 (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
583 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
584 org-export-docbook-xslt-stylesheet
585 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
589 (setq glasses-separator "-"
590 glasses-separate-parentheses-p nil
591 glasses-uncapitalize-p t)
593 ;; Some hacks to do with window placement.
595 (defun mdw-clobber-other-windows-showing-buffer (buffer-or-name)
596 "Arrange that no windows on other frames are showing BUFFER-OR-NAME."
597 (interactive "bBuffer: ")
598 (let ((home-frame (selected-frame))
599 (buffer (get-buffer buffer-or-name))
600 (safe-buffer (get-buffer "*scratch*")))
601 (dolist (frame (frame-list))
602 (unless (eq frame home-frame)
603 (dolist (window (window-list frame))
604 (when (eq (window-buffer window) buffer)
605 (set-window-buffer window safe-buffer)))))))
607 (defvar mdw-inhibit-walk-windows nil
608 "If non-nil, then `walk-windows' does nothing.
609 This is used by advice on `switch-to-buffer-other-frame' to inhibit finding
610 buffers in random frames.")
612 (setq display-buffer--other-frame-action
613 '((display-buffer-reuse-window display-buffer-pop-up-frame)
614 (reusable-frames . nil)
615 (inhibit-same-window . t)))
617 (defadvice walk-windows (around mdw-inhibit activate)
618 "If `mdw-inhibit-walk-windows' is non-nil, then do nothing."
619 (and (not mdw-inhibit-walk-windows)
622 (defadvice switch-to-buffer-other-frame
623 (around mdw-always-new-frame activate)
624 "Always make a new frame.
625 Even if an existing window in some random frame looks tempting."
626 (let ((mdw-inhibit-walk-windows t)) ad-do-it))
628 (defadvice display-buffer (before mdw-inhibit-other-frames activate)
629 "Don't try to do anything fancy with other frames.
630 Pretend they don't exist. They might be on other display devices."
633 (setq even-window-sizes nil
634 even-window-heights nil)
636 ;; Rename buffers along with files.
638 (defvar mdw-inhibit-rename-buffer nil
639 "If non-nil, `rename-file' won't rename the buffer visiting the file.")
641 (defmacro mdw-advise-to-inhibit-rename-buffer (function)
642 "Advise FUNCTION to set `mdw-inhibit-rename-buffer' while it runs.
644 This will prevent `rename-file' from renaming the buffer."
645 `(defadvice ,function (around mdw-inhibit-rename-buffer compile activate)
646 "Don't rename the buffer when renaming the underlying file."
647 (let ((mdw-inhibit-rename-buffer t))
649 (mdw-advise-to-inhibit-rename-buffer recode-file-name)
650 (mdw-advise-to-inhibit-rename-buffer set-visited-file-name)
651 (mdw-advise-to-inhibit-rename-buffer backup-buffer)
653 (defadvice rename-file (after mdw-rename-buffers (from to &optional forcep)
655 "If a buffer is visiting the file, rename it to match the new name.
657 Don't do this if `mdw-inhibit-rename-buffer' is non-nil."
658 (unless mdw-inhibit-rename-buffer
659 (let ((buffer (get-file-buffer from)))
661 (let ((to (if (not (string= (file-name-nondirectory to) "")) to
662 (concat to (file-name-nondirectory from)))))
663 (with-current-buffer buffer
664 (set-visited-file-name to nil t)))))))
666 ;;;--------------------------------------------------------------------------
667 ;;; Improved compilation machinery.
669 ;; Uprated version of M-x compile.
671 (setq compile-command
672 (let ((ncpu (with-temp-buffer
673 (insert-file-contents "/proc/cpuinfo")
675 (count-matches "^processor\\s-*:"))))
676 (format "nice make -j%d -k" (* 2 ncpu))))
678 (defun mdw-compilation-buffer-name (mode)
679 (concat "*" (downcase mode) ": "
680 (abbreviate-file-name default-directory) "*"))
681 (setq compilation-buffer-name-function 'mdw-compilation-buffer-name)
683 (eval-after-load "compile"
685 (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile)))
687 (defadvice compile (around hack-environment compile activate)
688 "Hack the environment inherited by inferiors in the compilation."
689 (let ((process-environment (copy-tree process-environment)))
690 (setenv "LD_PRELOAD" nil)
693 (defun mdw-compile (command &optional directory comint)
694 "Initiate a compilation COMMAND, maybe in a different DIRECTORY.
695 The DIRECTORY may be nil to not change. If COMINT is t, then
696 start an interactive compilation.
698 Interactively, prompt for the command if the variable
699 `compilation-read-command' is non-nil, or if requested through
700 the prefix argument. Prompt for the directory, and run
701 interactively, if requested through the prefix.
703 Use a prefix of 4, 6, 12, or 14, or type C-u between one and three times, to
704 force prompting for a directory.
706 Use a prefix of 2, 6, 10, or 14, or type C-u three times, to force
707 prompting for the command.
709 Use a prefix of 8, 10, 12, or 14, or type C-u twice or three times,
710 to force interactive compilation."
712 (let* ((prefix (prefix-numeric-value current-prefix-arg))
713 (command (eval compile-command))
714 (dir (and (plusp (logand prefix #x54))
715 (read-directory-name "Compile in directory: "))))
716 (list (if (or compilation-read-command
717 (plusp (logand prefix #x42)))
718 (compilation-read-command command)
721 (plusp (logand prefix #x58)))))
722 (let ((default-directory (or directory default-directory)))
723 (compile command comint)))
727 (defun mdw-find-build-dir (build-file)
729 (let* ((src-dir (file-name-as-directory (expand-file-name ".")))
732 (when (file-exists-p (concat dir build-file))
734 (let ((sub (expand-file-name (file-relative-name src-dir dir)
735 (concat dir "build/"))))
738 (when (file-exists-p (concat sub build-file))
740 (when (string= sub dir) (throw 'give-up nil))
741 (setq sub (file-name-directory (directory-file-name sub))))))
743 (setq dir (file-name-directory
744 (directory-file-name dir))))
745 (throw 'found nil))))))
747 (defun mdw-flymake-make-init ()
748 (let ((build-dir (mdw-find-build-dir "Makefile")))
750 (let ((tmp-src (flymake-init-create-temp-buffer-copy
751 #'flymake-create-temp-inplace)))
752 (flymake-get-syntax-check-program-args
753 tmp-src build-dir t t
754 #'flymake-get-make-cmdline)))))
756 (setq flymake-allowed-file-name-masks
757 '(("\\.\\(?:[cC]\\|cc\\|cpp\\|cxx\\|c\\+\\+\\)\\'"
758 mdw-flymake-make-init)
759 ("\\.\\(?:[hH]\\|hh\\|hpp\\|hxx\\|h\\+\\+\\)\\'"
760 mdw-flymake-master-make-init)
761 ("\\.p[lm]" flymake-perl-init)))
763 (setq flymake-mode-map
764 (let ((map (if (boundp 'flymake-mode-map)
766 (make-sparse-keymap))))
767 (define-key map [?\C-c ?\C-f ?\C-p] 'flymake-goto-prev-error)
768 (define-key map [?\C-c ?\C-f ?\C-n] 'flymake-goto-next-error)
769 (define-key map [?\C-c ?\C-f ?\C-c] 'flymake-compile)
770 (define-key map [?\C-c ?\C-f ?\C-k] 'flymake-stop-all-syntax-checks)
771 (define-key map [?\C-c ?\C-f ?\C-e] 'flymake-popup-current-error-menu)
774 ;;;--------------------------------------------------------------------------
775 ;;; Mail and news hacking.
777 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
778 "Major mode for editing news and mail messages from external programs.
779 Not much right now. Just support for doing MailCrypt stuff."
782 (run-hooks 'mail-setup-hook))
784 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
786 (add-hook 'mdwail-mode-hook
788 (set-buffer-file-coding-system 'utf-8)
789 (make-local-variable 'paragraph-separate)
790 (make-local-variable 'paragraph-start)
791 (setq paragraph-start
792 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
794 (setq paragraph-separate
795 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
796 paragraph-separate))))
798 ;; How to encrypt in mdwmail.
800 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
802 (setq start (save-excursion
803 (goto-char (point-min))
804 (or (search-forward "\n\n" nil t) (point-min)))))
806 (setq end (point-max)))
807 (mc-encrypt-generic recip scm start end from sign))
809 ;; How to sign in mdwmail.
811 (defun mdwmail-mc-sign (key scm start end uclr)
813 (setq start (save-excursion
814 (goto-char (point-min))
815 (or (search-forward "\n\n" nil t) (point-min)))))
817 (setq end (point-max)))
818 (mc-sign-generic key scm start end uclr))
820 ;; Some signature mangling.
822 (defun mdwmail-mangle-signature ()
824 (goto-char (point-min))
825 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
826 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
827 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
829 ;; Insert my login name into message-ids, so I can score replies.
831 (defadvice message-unique-id (after mdw-user-name last activate compile)
832 "Ensure that the user's name appears at the end of the message-id string,
833 so that it can be used for convenient filtering."
834 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
836 ;; Tell my movemail hack where movemail is.
838 ;; This is needed to shup up warnings about LD_PRELOAD.
840 (let ((path exec-path))
842 (let ((try (expand-file-name "movemail" (car path))))
843 (if (file-executable-p try)
844 (setenv "REAL_MOVEMAIL" try))
845 (setq path (cdr path)))))
847 ;; AUTHINFO GENERIC kludge.
849 (defcustom nntp-authinfo-generic nil
850 "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'.
852 Use this to arrange for per-server settings."
853 :type '(choice (const :tag "Use `NNTPAUTH' environment variable" nil)
857 (defun nntp-open-authinfo-kludge (buffer)
858 "Open a connection to SERVER using `authinfo-kludge'."
859 (let ((proc (start-process "nntpd" buffer
860 "env" (concat "NNTPAUTH="
861 (or nntp-authinfo-generic
863 (error "NNTPAUTH unset")))
864 "authinfo-kludge" nntp-address)))
866 (nntp-wait-for-string "^\r*200")
868 (delete-region (point-min) (point))
871 (eval-after-load "erc"
872 '(load "~/.ercrc.el"))
874 ;; Heavy-duty Gnus patching.
876 (defun mdw-nnimap-transform-headers ()
877 (goto-char (point-min))
878 (let (article lines size string)
881 (while (not (looking-at "\\* [0-9]+ FETCH"))
882 (delete-region (point) (progn (forward-line 1) (point)))
885 (goto-char (match-end 0))
886 ;; Unfold quoted {number} strings.
887 (while (re-search-forward
888 "[^]][ (]{\\([0-9]+\\)}\r?\n"
890 ;; Start of the header section.
891 (or (re-search-forward "] {[0-9]+}\r?\n" nil t)
892 ;; Start of the next FETCH.
893 (re-search-forward "\\* [0-9]+ FETCH" nil t)
896 (setq size (string-to-number (match-string 1)))
897 (delete-region (+ (match-beginning 0) 2) (point))
898 (setq string (buffer-substring (point) (+ (point) size)))
899 (delete-region (point) (+ (point) size))
900 (insert (format "%S" (subst-char-in-string ?\n ?\s string)))
901 ;; [mdw] missing from upstream
905 (and (re-search-forward "UID \\([0-9]+\\)"
911 (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)"
916 (when (search-forward "BODYSTRUCTURE" (line-end-position) t)
917 (let ((structure (ignore-errors
918 (read (current-buffer)))))
919 (while (and (consp structure)
920 (not (atom (car structure))))
921 (setq structure (car structure)))
923 (stringp (car structure))
924 (equal (upcase (nth 0 structure)) "MESSAGE")
925 (equal (upcase (nth 1 structure)) "RFC822"))
927 (nth 7 structure)))))
928 (delete-region (line-beginning-position) (line-end-position))
929 (insert (format "211 %s Article retrieved." article))
932 (insert (format "Chars: %s\n" size)))
934 (insert (format "Lines: %s\n" lines)))
935 ;; Most servers have a blank line after the headers, but
937 (unless (re-search-forward "^\r$\\|^)\r?$" nil t)
938 (goto-char (point-max)))
939 (delete-region (line-beginning-position) (line-end-position))
943 (eval-after-load 'nnimap
944 '(defalias 'nnimap-transform-headers
945 (symbol-function 'mdw-nnimap-transform-headers)))
947 (defadvice gnus-other-frame (around mdw-hack-frame-width compile activate)
948 "Always arrange for mail/news frames to be 80 columns wide."
949 (let ((default-frame-alist (cons `(width . ,(+ 80 mdw-frame-width-fudge))
950 (cl-delete 'width default-frame-alist
954 ;; Preferred programs.
956 (setq mailcap-user-mime-data
957 '(((type . "application/pdf") (viewer . "mupdf %s"))))
959 ;;;--------------------------------------------------------------------------
960 ;;; Utility functions.
962 (or (fboundp 'line-number-at-pos)
963 (defun line-number-at-pos (&optional pos)
964 (let ((opoint (or pos (point))) start)
967 (goto-char (point-min))
973 (1+ (count-lines 1 (point))))))))
975 (defun mdw-uniquify-alist (&rest alists)
976 "Return the concatenation of the ALISTS with duplicate elements removed.
977 The first association with a given key prevails; others are
978 ignored. The input lists are not modified, although they'll
979 probably become garbage."
981 (let ((start-list (cons nil nil)))
982 (mdw-do-uniquify start-list
987 (defun mdw-do-uniquify (done end l rest)
988 "A helper function for mdw-uniquify-alist.
989 The DONE argument is a list whose first element is `nil'. It
990 contains the uniquified alist built so far. The leading `nil' is
991 stripped off at the end of the operation; it's only there so that
992 DONE always references a cons cell. END refers to the final cons
993 cell in the DONE list; it is modified in place each time to avoid
994 the overheads of `append'ing all the time. The L argument is the
995 alist we're currently processing; the remaining alists are given
998 ;; There are several different cases to deal with here.
1001 ;; Current list isn't empty. Add the first item to the DONE list if
1002 ;; there's not an item with the same KEY already there.
1003 (l (or (assoc (car (car l)) done)
1005 (setcdr end (cons (car l) nil))
1006 (setq end (cdr end))))
1007 (mdw-do-uniquify done end (cdr l) rest))
1009 ;; The list we were working on is empty. Shunt the next list into the
1010 ;; current list position and go round again.
1011 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
1013 ;; Everything's done. Remove the leading `nil' from the DONE list and
1014 ;; return it. Finished!
1018 "Insert the current date in a pleasing way."
1020 (insert (save-excursion
1021 (let ((buffer (get-buffer-create "*tmp*")))
1022 (unwind-protect (progn (set-buffer buffer)
1024 (shell-command "date +%Y-%m-%d" t)
1028 (kill-buffer buffer))))))
1030 (defun uuencode (file &optional name)
1031 "UUencodes a file, maybe calling it NAME, into the current buffer."
1032 (interactive "fInput file name: ")
1034 ;; If NAME isn't specified, then guess from the filename.
1038 (or (string-match "[^/]*$" file) 0))))
1039 (print (format "uuencode `%s' `%s'" file name))
1041 ;; Now actually do the thing.
1042 (call-process "uuencode" file t nil name))
1044 (defcustom np-file "~/.np"
1045 "Where the `now-playing' file is."
1049 (defun np (&optional arg)
1050 "Grabs a `now-playing' string."
1054 (goto-char (point-max))
1056 (insert-file-contents np-file)))))
1058 (defun mdw-version-< (ver-a ver-b)
1059 "Answer whether VER-A is strictly earlier than VER-B.
1060 VER-A and VER-B are version numbers, which are strings containing digit
1061 sequences separated by `.'."
1062 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
1063 (split-string ver-a "\\.")))
1064 (lb (mapcar (lambda (x) (car (read-from-string x)))
1065 (split-string ver-b "\\."))))
1068 (cond ((null la) (throw 'done lb))
1069 ((null lb) (throw 'done nil))
1070 ((< (car la) (car lb)) (throw 'done t))
1071 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))
1072 (t (throw 'done nil)))))))
1074 (defun mdw-check-autorevert ()
1075 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
1076 This takes into consideration whether it's been found using
1077 tramp, which seems to get itself into a twist."
1078 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
1080 ((and (buffer-file-name)
1081 (fboundp 'tramp-tramp-file-p)
1082 (tramp-tramp-file-p (buffer-file-name)))
1083 (unless global-auto-revert-ignore-buffer
1084 (setq global-auto-revert-ignore-buffer 'tramp)))
1085 ((eq global-auto-revert-ignore-buffer 'tramp)
1086 (setq global-auto-revert-ignore-buffer nil))))
1088 (defadvice find-file (after mdw-autorevert activate)
1089 (mdw-check-autorevert))
1090 (defadvice write-file (after mdw-autorevert activate)
1091 (mdw-check-autorevert))
1093 (defun mdw-auto-revert ()
1094 "Recheck all of the autorevertable buffers, and update VC modelines."
1096 (let ((auto-revert-check-vc-info t))
1097 (auto-revert-buffers)))
1099 ;;;--------------------------------------------------------------------------
1102 (defadvice dired-maybe-insert-subdir
1103 (around mdw-marked-insertion first activate)
1104 "The DIRNAME may be a list of directory names to insert.
1105 Interactively, if files are marked, then insert all of them.
1106 With a numeric prefix argument, select that many entries near
1107 point; with a non-numeric prefix argument, prompt for listing
1110 (list (dired-get-marked-files nil
1111 (and (integerp current-prefix-arg)
1114 (and current-prefix-arg
1115 (not (integerp current-prefix-arg))
1116 (read-string "Switches for listing: "
1117 (or dired-subdir-switches
1118 dired-actual-switches)))))
1119 (let ((dirs (ad-get-arg 0)))
1120 (dolist (dir (if (listp dirs) dirs (list dirs)))
1124 (defun mdw-dired-run (args &optional syncp)
1125 (interactive (let ((file (dired-get-filename t)))
1126 (list (read-string (format "Arguments for %s: " file))
1127 current-prefix-arg)))
1128 (funcall (if syncp 'shell-command 'async-shell-command)
1129 (concat (shell-quote-argument (dired-get-filename nil))
1132 (defadvice dired-do-flagged-delete
1133 (around mdw-delete-if-prefix-argument activate compile)
1134 (let ((delete-by-moving-to-trash (and (null current-prefix-arg)
1135 delete-by-moving-to-trash)))
1138 (eval-after-load "dired"
1139 '(define-key dired-mode-map "X" 'mdw-dired-run))
1141 ;;;--------------------------------------------------------------------------
1144 (defun mdw-w3m-browse-url (url &optional new-session-p)
1145 "Invoke w3m on the URL in its current window, or at least a different one.
1146 If NEW-SESSION-P, start a new session."
1147 (interactive "sURL: \nP")
1149 (let ((window (selected-window)))
1152 (select-window (or (and (not new-session-p)
1153 (get-buffer-window "*w3m*"))
1155 (if (one-window-p t) (split-window))
1157 (w3m-browse-url url new-session-p))
1158 (select-window window)))))
1160 (eval-after-load 'w3m
1161 '(define-key w3m-mode-map [?\e ?\r] 'w3m-view-this-url-new-session))
1163 (defcustom mdw-good-url-browsers
1164 '(browse-url-mozilla
1166 (w3m . mdw-w3m-browse-url)
1168 "List of good browsers for mdw-good-url-browsers.
1169 Each item is a browser function name, or a cons (CHECK . FUNC).
1170 A symbol FOO stands for (FOO . FOO)."
1171 :type '(repeat (choice function (cons function function))))
1173 (defun mdw-good-url-browser ()
1174 "Return a good URL browser.
1175 Trundle the list of such things, finding the first item for which
1176 CHECK is fboundp, and returning the correponding FUNC."
1177 (let ((bs mdw-good-url-browsers) b check func answer)
1178 (while (and bs (not answer))
1182 (setq check (car b) func (cdr b))
1183 (setq check b func b))
1185 (setq answer func)))
1188 (eval-after-load "w3m-search"
1192 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
1193 ("gd" "Google Directory"
1194 "http://www.google.com/search?cat=gwd/Top&q=%s")
1195 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
1196 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
1197 ("gi" "Images" "http://images.google.com/images?q=%s")
1199 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
1201 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
1202 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
1203 ("nc-wiki" "nCipher wiki"
1204 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
1205 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
1206 ("lp" "Launchpad bug by number"
1207 "https://bugs.launchpad.net/bugs/%s")
1208 ("lppkg" "Launchpad bugs by package"
1209 "https://bugs.launchpad.net/%s")
1211 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
1212 ("debbug" "Debian bug by number"
1213 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
1214 ("debbugpkg" "Debian bugs by package"
1215 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
1216 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
1217 (add-to-list 'w3m-search-engine-alist
1218 (list (cadr item) (caddr item) nil))
1219 (add-to-list 'w3m-uri-replace-alist
1220 (list (concat "\\`" (car item) ":")
1221 'w3m-search-uri-replace
1224 ;;;--------------------------------------------------------------------------
1225 ;;; Paragraph filling.
1227 ;; Useful variables.
1229 (defcustom mdw-fill-prefix nil
1230 "Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
1231 If there's no fill prefix currently set (by the `fill-prefix'
1232 variable) and there's a match from one of the regexps here, it
1233 gets used to set the fill-prefix for the current operation.
1235 The variable is a list of items of the form `PATTERN . PREFIX'; if
1236 the PATTERN matches, the PREFIX is used to set the fill prefix.
1238 A PATTERN is one of the following.
1240 * STRING -- a regular expression, expected to match at point
1241 * (eval . FORM) -- a Lisp form which must evaluate non-nil
1242 * (if COND CONSEQ-PAT ALT-PAT) -- if COND evaluates non-nil, must match
1243 CONSEQ-PAT; otherwise must match ALT-PAT
1244 * (and PATTERN ...) -- must match all of the PATTERNs
1245 * (or PATTERN ...) -- must match at least one PATTERN
1246 * (not PATTERN) -- mustn't match (probably not useful)
1248 A PREFIX is a list of the following kinds of things:
1250 * STRING -- insert a literal string
1251 * (match . N) -- insert the thing matched by bracketed subexpression N
1252 * (pad . N) -- a string of whitespace the same width as subexpression N
1253 * (expr . FORM) -- the result of evaluating FORM
1255 Information about `bracketed subexpressions' comes from the match data,
1256 as modified during matching.")
1258 (make-variable-buffer-local 'mdw-fill-prefix)
1260 (defcustom mdw-hanging-indents
1262 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
1265 "Standard regexp matching parts of a hanging indent.
1266 This is mainly useful in `auto-fill-mode'."
1269 ;; Utility functions.
1271 (defun mdw-maybe-tabify (s)
1272 "Tabify or untabify the string S, according to `indent-tabs-mode'."
1273 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
1277 (let ((start (point-min)) (end (point-max)))
1278 (funcall tabfun (point-min) (point-max))
1279 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
1281 (defun mdw-fill-prefix-match-p (pat)
1282 "Return non-nil if PAT matches at the current position."
1283 (cond ((stringp pat) (looking-at pat))
1284 ((not (consp pat)) (error "Unknown pattern item `%S'" pat))
1285 ((eq (car pat) 'eval) (eval (cdr pat)))
1287 (if (or (null (cdr pat))
1291 (error "Invalid `if' pattern `%S'" pat))
1292 (mdw-fill-prefix-match-p (if (eval (cadr pat))
1295 ((eq (car pat) 'and)
1296 (let ((pats (cdr pat))
1299 (or (mdw-fill-prefix-match-p (car pats))
1301 (setq pats (cdr pats)))
1304 (let ((pats (cdr pat))
1307 (or (not (mdw-fill-prefix-match-p (car pats)))
1308 (progn (setq ok t) nil)))
1309 (setq pats (cdr pats)))
1311 ((eq (car pat) 'not)
1312 (if (or (null (cdr pat)) (cddr pat))
1313 (error "Invalid `not' pattern `%S'" pat))
1314 (not (mdw-fill-prefix-match-p (car pats))))
1315 (t (error "Unknown pattern form `%S'" pat))))
1317 (defun mdw-maybe-car (p)
1318 "If P is a pair, return (car P), otherwise just return P."
1319 (if (consp p) (car p) p))
1321 (defun mdw-padding (s)
1322 "Return a string the same width as S but made entirely from whitespace."
1323 (let* ((l (length s)) (i 0) (n (make-string l ? )))
1325 (if (= 9 (aref s i))
1330 (defun mdw-do-prefix-match (m)
1331 "Expand a dynamic prefix match element.
1332 See `mdw-fill-prefix' for details."
1333 (cond ((not (consp m)) (format "%s" m))
1334 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
1335 ((eq (car m) 'pad) (mdw-padding (match-string
1336 (mdw-maybe-car (cdr m)))))
1337 ((eq (car m) 'eval) (eval (cdr m)))
1340 (defun mdw-examine-fill-prefixes (l)
1341 "Given a list of dynamic fill prefixes, pick one which matches
1342 context and return the static fill prefix to use. Point must be
1343 at the start of a line, and match data must be saved."
1345 (while (cond ((null l) nil)
1346 ((mdw-fill-prefix-match-p (caar l))
1350 (mapcar #'mdw-do-prefix-match
1356 (defun mdw-choose-dynamic-fill-prefix ()
1357 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
1358 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
1359 ((not mdw-fill-prefix) fill-prefix)
1363 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
1365 (defadvice do-auto-fill (around mdw-dynamic-fill-prefix () activate compile)
1366 "Handle auto-filling, working out a dynamic fill prefix in the
1367 case where there isn't a sensible static one."
1368 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1371 (defun mdw-fill-paragraph ()
1372 "Fill paragraph, getting a dynamic fill prefix."
1374 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1375 (fill-paragraph nil)))
1377 (defun mdw-point-within-string-p ()
1378 "Return non-nil if point is within a string."
1379 (let ((state (syntax-ppss)))
1382 (defun mdw-standard-fill-prefix (rx &optional mat)
1383 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
1384 This is just a short-cut for setting the thing by hand, and by
1385 design it doesn't cope with anything approximating a complicated
1387 (setq mdw-fill-prefix
1388 `(((if (mdw-point-within-string-p)
1389 ,(concat "\\(\\s-*\\)" mdw-hanging-indents)
1390 ,(concat rx mdw-hanging-indents))
1392 (pad . ,(or mat 2))))))
1394 ;;;--------------------------------------------------------------------------
1397 ;; Teach PostScript about a condensed variant of Courier. I'm using 85% of
1398 ;; the usual width, which happens to match `mdwfonts', and David Carlisle's
1399 ;; `pslatex'. (Once upon a time, I used 80%, but decided consistency with
1400 ;; `pslatex' was useful.)
1401 (setq ps-user-defined-prologue "
1402 /CourierCondensed /Courier
1403 /CourierCondensed-Bold /Courier-Bold
1404 /CourierCondensed-Oblique /Courier-Oblique
1405 /CourierCondensed-BoldOblique /Courier-BoldOblique
1406 4 { findfont [0.85 0 0 1 0 0] makefont definefont pop } repeat
1409 ;; Hack `ps-print''s settings.
1410 (eval-after-load 'ps-print
1413 ;; Notice that the comment-delimiters should be in italics too.
1414 (pushnew 'font-lock-comment-delimiter-face ps-italic-faces)
1416 ;; Select more suitable colours for the main kinds of tokens. The
1417 ;; colours set on the Emacs faces are chosen for use against a dark
1418 ;; background, and work very badly on white paper.
1419 (ps-extend-face '(font-lock-comment-face "darkgreen" nil italic))
1420 (ps-extend-face '(font-lock-comment-delimiter-face "darkgreen" nil italic))
1421 (ps-extend-face '(font-lock-string-face "RoyalBlue4" nil))
1422 (ps-extend-face '(mdw-punct-face "sienna" nil))
1423 (ps-extend-face '(mdw-number-face "OrangeRed3" nil))
1425 ;; Teach `ps-print' about my condensed varsions of Courier.
1426 (setq ps-font-info-database
1427 (append '((CourierCondensed
1428 (fonts (normal . "CourierCondensed")
1429 (bold . "CourierCondensed-Bold")
1430 (italic . "CourierCondensed-Oblique")
1431 (bold-italic . "CourierCondensed-BoldOblique"))
1433 (line-height . 10.55)
1435 (avg-char-width . 5.1)))
1436 (cl-remove 'CourierCondensed ps-font-info-database
1439 ;; Arrange to strip overlays from the buffer before we print . This will
1440 ;; prevent `flyspell' from interfering with the printout. (It would be less
1441 ;; bad if `ps-print' could merge the `flyspell' overlay face with the
1442 ;; underlying `font-lock' face, but it can't (and that seems hard). So
1443 ;; instead we have this hack.
1445 ;; The basic trick is to copy the relevant text from the buffer being printed
1446 ;; into a temporary buffer and... just print that. The text properties come
1447 ;; with the text and end up in the new buffer, and the overlays get lost
1448 ;; along the way. Only problem is that the headers identifying the file
1449 ;; being printed get confused, so remember the original buffer and reinstate
1450 ;; it when constructing the headers.
1451 (defvar mdw-printing-buffer)
1453 (defadvice ps-generate-header
1454 (around mdw-use-correct-buffer () activate compile)
1455 "Print the correct name of the buffer being printed."
1456 (with-current-buffer mdw-printing-buffer
1459 (defadvice ps-generate
1460 (around mdw-strip-overlays (buffer from to genfunc) activate compile)
1461 "Strip overlays -- in particular, from `flyspell' -- before printout."
1463 (let ((mdw-printing-buffer buffer))
1464 (insert-buffer-substring buffer from to)
1465 (ad-set-arg 0 (current-buffer))
1466 (ad-set-arg 1 (point-min))
1467 (ad-set-arg 2 (point-max))
1470 ;;;--------------------------------------------------------------------------
1471 ;;; Other common declarations.
1473 ;; Common mode settings.
1475 (defcustom mdw-auto-indent t
1476 "Whether to indent automatically after a newline."
1480 (defun mdw-whitespace-mode (&optional arg)
1481 "Turn on/off whitespace mode, but don't highlight trailing space."
1483 (when (and (boundp 'whitespace-style)
1484 (fboundp 'whitespace-mode))
1485 (let ((whitespace-style (remove 'trailing whitespace-style)))
1486 (whitespace-mode arg))
1487 (setq show-trailing-whitespace whitespace-mode)))
1489 (defvar mdw-do-misc-mode-hacking nil)
1491 (defun mdw-misc-mode-config ()
1492 (and mdw-auto-indent
1493 (cond ((eq major-mode 'lisp-mode)
1494 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
1495 ((derived-mode-p 'slime-repl-mode 'asm-mode 'comint-mode)
1498 (local-set-key "\C-m" 'newline-and-indent))))
1499 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
1500 (local-set-key [C-return] 'newline)
1501 (make-local-variable 'page-delimiter)
1502 (setq page-delimiter (concat "^" "\f"
1506 "\\(" " " ".*" " " "\\)?"
1510 (setq comment-column 40)
1512 (setq fill-column mdw-text-width)
1513 (flyspell-prog-mode)
1514 (and (fboundp 'gtags-mode)
1516 (if (fboundp 'hs-minor-mode)
1517 (trap (hs-minor-mode t))
1518 (outline-minor-mode t))
1520 (trap (turn-on-font-lock)))
1522 (defun mdw-post-local-vars-misc-mode-config ()
1523 (setq whitespace-line-column mdw-text-width)
1524 (when (and mdw-do-misc-mode-hacking
1525 (not buffer-read-only))
1526 (setq show-trailing-whitespace t)
1527 (mdw-whitespace-mode 1)))
1528 (add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
1530 (defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1531 `(progn ,@(mapcar (lambda (func)
1533 (after mdw-angry-fruit-salad activate)
1534 (when mdw-do-misc-mode-hacking
1535 (setq show-trailing-whitespace
1536 (not buffer-read-only))
1537 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1539 (mdw-advise-update-angry-fruit-salad toggle-read-only
1545 (eval-after-load 'gtags
1547 (dolist (key '([mouse-2] [mouse-3]))
1548 (define-key gtags-mode-map key nil))
1549 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1550 (define-key gtags-select-mode-map [C-S-mouse-2]
1551 'gtags-select-tag-by-event)
1552 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1553 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
1555 ;; Backup file handling.
1557 (defcustom mdw-backup-disable-regexps nil
1558 "List of regular expressions: if a file name matches any of
1559 these then the file is not backed up."
1560 :type '(repeat regexp))
1562 (defun mdw-backup-enable-predicate (name)
1563 "[mdw]'s default backup predicate.
1564 Allows a backup if the standard predicate would allow it, and it
1565 doesn't match any of the regular expressions in
1566 `mdw-backup-disable-regexps'."
1567 (and (normal-backup-enable-predicate name)
1568 (let ((answer t) (list mdw-backup-disable-regexps))
1571 (if (string-match (car list) name)
1573 (setq list (cdr list)))
1575 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
1579 (defun mdw-last-one-out-turn-off-the-lights (frame)
1580 "Disconnect from an X display if this was the last frame on that display."
1581 (let ((frame-display (frame-parameter frame 'display)))
1582 (when (and frame-display
1583 (eq window-system 'x)
1584 (not (some (lambda (fr)
1585 (and (not (eq fr frame))
1586 (string= (frame-parameter fr 'display)
1589 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1590 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1592 ;;;--------------------------------------------------------------------------
1593 ;;; Fullscreen-ness.
1595 (defcustom mdw-full-screen-parameters
1596 '((menu-bar-lines . 0)
1597 ;;(vertical-scroll-bars . nil)
1599 "Frame parameters to set when making a frame fullscreen."
1600 :type '(alist :key-type symbol))
1602 (defcustom mdw-full-screen-save
1604 "Extra frame parameters to save when setting fullscreen."
1605 :type '(repeat symbol))
1607 (defun mdw-toggle-full-screen (&optional frame)
1608 "Show the FRAME fullscreen."
1611 (cond ((frame-parameter frame 'fullscreen)
1612 (set-frame-parameter frame 'fullscreen nil)
1613 (modify-frame-parameters
1615 (or (frame-parameter frame 'mdw-full-screen-saved)
1616 (mapcar (lambda (assoc)
1617 (assq (car assoc) default-frame-alist))
1618 mdw-full-screen-parameters))))
1620 (let ((saved (mapcar (lambda (param)
1621 (cons param (frame-parameter frame param)))
1622 (append (mapcar #'car
1623 mdw-full-screen-parameters)
1624 mdw-full-screen-save))))
1625 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1626 (modify-frame-parameters frame mdw-full-screen-parameters)
1627 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1629 ;;;--------------------------------------------------------------------------
1630 ;;; General fontification.
1632 (make-face 'mdw-virgin-face)
1634 (defmacro mdw-define-face (name &rest body)
1635 "Define a face, and make sure it's actually set as the definition."
1639 (copy-face 'mdw-virgin-face ',name)
1640 (defvar ,name ',name)
1641 (put ',name 'face-defface-spec ',body)
1642 (face-spec-set ',name ',body nil)))
1644 (mdw-define-face default
1645 (((type w32)) :family "courier new" :height 85)
1646 (((type x)) :family "6x13" :foundry "trad" :height 130)
1647 (((type color)) :foreground "white" :background "black")
1649 (mdw-define-face fixed-pitch
1650 (((type w32)) :family "courier new" :height 85)
1651 (((type x)) :family "6x13" :foundry "trad" :height 130)
1652 (t :foreground "white" :background "black"))
1653 (mdw-define-face fixed-pitch-serif
1654 (((type w32)) :family "courier new" :height 85 :weight bold)
1655 (((type x)) :family "6x13" :foundry "trad" :height 130 :weight bold)
1656 (t :foreground "white" :background "black" :weight bold))
1657 (mdw-define-face variable-pitch
1658 (((type x)) :family "helvetica" :height 120))
1659 (mdw-define-face region
1660 (((min-colors 64)) :background "grey30")
1661 (((class color)) :background "blue")
1662 (t :inverse-video t))
1663 (mdw-define-face match
1664 (((class color)) :background "blue")
1665 (t :inverse-video t))
1666 (mdw-define-face mc/cursor-face
1667 (((class color)) :background "red")
1668 (t :inverse-video t))
1669 (mdw-define-face minibuffer-prompt
1671 (mdw-define-face mode-line
1672 (((class color)) :foreground "blue" :background "yellow"
1673 :box (:line-width 1 :style released-button))
1674 (t :inverse-video t))
1675 (mdw-define-face mode-line-inactive
1676 (((class color)) :foreground "yellow" :background "blue"
1677 :box (:line-width 1 :style released-button))
1678 (t :inverse-video t))
1679 (mdw-define-face nobreak-space
1681 (t :inherit escape-glyph :underline t))
1682 (mdw-define-face scroll-bar
1683 (t :foreground "black" :background "lightgrey"))
1684 (mdw-define-face fringe
1685 (t :foreground "yellow"))
1686 (mdw-define-face show-paren-match
1687 (((min-colors 64)) :background "darkgreen")
1688 (((class color)) :background "green")
1690 (mdw-define-face show-paren-mismatch
1691 (((class color)) :background "red")
1692 (t :inverse-video t))
1693 (mdw-define-face highlight
1694 (((min-colors 64)) :background "DarkSeaGreen4")
1695 (((class color)) :background "cyan")
1696 (t :inverse-video t))
1698 (mdw-define-face viper-minibuffer-emacs (t nil))
1699 (mdw-define-face viper-minibuffer-insert (t nil))
1700 (mdw-define-face viper-minibuffer-vi (t nil))
1701 (mdw-define-face viper-replace-overlay
1702 (((min-colors 64)) :background "darkred")
1703 (((class color)) :background "red")
1704 (t :inverse-video t))
1705 (mdw-define-face viper-search (t :inherit isearch))
1707 (mdw-define-face holiday-face
1708 (t :background "red"))
1709 (mdw-define-face calendar-today-face
1710 (t :foreground "yellow" :weight bold))
1712 (mdw-define-face comint-highlight-prompt
1714 (mdw-define-face comint-highlight-input
1717 (mdw-define-face Man-underline
1718 (((type tty)) :underline t)
1721 (mdw-define-face ido-subdir
1722 (t :foreground "cyan" :weight bold))
1724 (mdw-define-face dired-directory
1725 (t :foreground "cyan" :weight bold))
1726 (mdw-define-face dired-symlink
1727 (t :foreground "cyan"))
1728 (mdw-define-face dired-perm-write
1731 (mdw-define-face trailing-whitespace
1732 (((class color)) :background "red")
1733 (t :inverse-video t))
1734 (mdw-define-face whitespace-line
1735 (((class color)) :background "darkred")
1736 (t :inverse-video t))
1737 (mdw-define-face mdw-punct-face
1738 (((min-colors 64)) :foreground "burlywood2")
1739 (((class color)) :foreground "yellow"))
1740 (mdw-define-face mdw-number-face
1741 (t :foreground "yellow"))
1742 (mdw-define-face mdw-trivial-face)
1743 (mdw-define-face font-lock-function-name-face
1745 (mdw-define-face font-lock-keyword-face
1747 (mdw-define-face font-lock-constant-face
1749 (mdw-define-face font-lock-builtin-face
1751 (mdw-define-face font-lock-type-face
1752 (t :weight bold :slant italic))
1753 (mdw-define-face font-lock-reference-face
1755 (mdw-define-face font-lock-variable-name-face
1757 (mdw-define-face font-lock-comment-delimiter-face
1758 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1759 (((class color)) :foreground "green")
1761 (mdw-define-face font-lock-comment-face
1762 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1763 (((class color)) :foreground "green")
1765 (mdw-define-face font-lock-string-face
1766 (((min-colors 64)) :foreground "SkyBlue1")
1767 (((class color)) :foreground "cyan")
1770 (mdw-define-face message-separator
1771 (t :background "red" :foreground "white" :weight bold))
1772 (mdw-define-face message-cited-text
1773 (default :slant italic)
1774 (((min-colors 64)) :foreground "SkyBlue1")
1775 (((class color)) :foreground "cyan"))
1776 (mdw-define-face message-header-cc
1777 (default :slant italic)
1778 (((min-colors 64)) :foreground "SeaGreen1")
1779 (((class color)) :foreground "green"))
1780 (mdw-define-face message-header-newsgroups
1781 (default :slant italic)
1782 (((min-colors 64)) :foreground "SeaGreen1")
1783 (((class color)) :foreground "green"))
1784 (mdw-define-face message-header-subject
1785 (((min-colors 64)) :foreground "SeaGreen1")
1786 (((class color)) :foreground "green"))
1787 (mdw-define-face message-header-to
1788 (((min-colors 64)) :foreground "SeaGreen1")
1789 (((class color)) :foreground "green"))
1790 (mdw-define-face message-header-xheader
1791 (default :slant italic)
1792 (((min-colors 64)) :foreground "SeaGreen1")
1793 (((class color)) :foreground "green"))
1794 (mdw-define-face message-header-other
1795 (default :slant italic)
1796 (((min-colors 64)) :foreground "SeaGreen1")
1797 (((class color)) :foreground "green"))
1798 (mdw-define-face message-header-name
1799 (default :weight bold)
1800 (((min-colors 64)) :foreground "SeaGreen1")
1801 (((class color)) :foreground "green"))
1803 (mdw-define-face which-func
1806 (mdw-define-face gnus-header-name
1807 (default :weight bold)
1808 (((min-colors 64)) :foreground "SeaGreen1")
1809 (((class color)) :foreground "green"))
1810 (mdw-define-face gnus-header-subject
1811 (((min-colors 64)) :foreground "SeaGreen1")
1812 (((class color)) :foreground "green"))
1813 (mdw-define-face gnus-header-from
1814 (((min-colors 64)) :foreground "SeaGreen1")
1815 (((class color)) :foreground "green"))
1816 (mdw-define-face gnus-header-to
1817 (((min-colors 64)) :foreground "SeaGreen1")
1818 (((class color)) :foreground "green"))
1819 (mdw-define-face gnus-header-content
1820 (default :slant italic)
1821 (((min-colors 64)) :foreground "SeaGreen1")
1822 (((class color)) :foreground "green"))
1824 (mdw-define-face gnus-cite-1
1825 (((min-colors 64)) :foreground "SkyBlue1")
1826 (((class color)) :foreground "cyan"))
1827 (mdw-define-face gnus-cite-2
1828 (((min-colors 64)) :foreground "RoyalBlue2")
1829 (((class color)) :foreground "blue"))
1830 (mdw-define-face gnus-cite-3
1831 (((min-colors 64)) :foreground "MediumOrchid")
1832 (((class color)) :foreground "magenta"))
1833 (mdw-define-face gnus-cite-4
1834 (((min-colors 64)) :foreground "firebrick2")
1835 (((class color)) :foreground "red"))
1836 (mdw-define-face gnus-cite-5
1837 (((min-colors 64)) :foreground "burlywood2")
1838 (((class color)) :foreground "yellow"))
1839 (mdw-define-face gnus-cite-6
1840 (((min-colors 64)) :foreground "SeaGreen1")
1841 (((class color)) :foreground "green"))
1842 (mdw-define-face gnus-cite-7
1843 (((min-colors 64)) :foreground "SlateBlue1")
1844 (((class color)) :foreground "cyan"))
1845 (mdw-define-face gnus-cite-8
1846 (((min-colors 64)) :foreground "RoyalBlue2")
1847 (((class color)) :foreground "blue"))
1848 (mdw-define-face gnus-cite-9
1849 (((min-colors 64)) :foreground "purple2")
1850 (((class color)) :foreground "magenta"))
1851 (mdw-define-face gnus-cite-10
1852 (((min-colors 64)) :foreground "DarkOrange2")
1853 (((class color)) :foreground "red"))
1854 (mdw-define-face gnus-cite-11
1855 (t :foreground "grey"))
1857 (mdw-define-face gnus-emphasis-underline
1858 (((type tty)) :underline t)
1861 (mdw-define-face diff-header
1863 (mdw-define-face diff-index
1865 (mdw-define-face diff-file-header
1867 (mdw-define-face diff-hunk-header
1868 (((min-colors 64)) :foreground "SkyBlue1")
1869 (((class color)) :foreground "cyan"))
1870 (mdw-define-face diff-function
1871 (default :weight bold)
1872 (((min-colors 64)) :foreground "SkyBlue1")
1873 (((class color)) :foreground "cyan"))
1874 (mdw-define-face diff-header
1875 (((min-colors 64)) :background "grey10"))
1876 (mdw-define-face diff-added
1877 (((class color)) :foreground "green"))
1878 (mdw-define-face diff-removed
1879 (((class color)) :foreground "red"))
1880 (mdw-define-face diff-context
1882 (mdw-define-face diff-refine-change
1883 (((min-colors 64)) :background "RoyalBlue4")
1885 (mdw-define-face diff-refine-removed
1886 (((min-colors 64)) :background "#500")
1888 (mdw-define-face diff-refine-added
1889 (((min-colors 64)) :background "#050")
1892 (setq ediff-force-faces t)
1893 (mdw-define-face ediff-current-diff-A
1894 (((min-colors 64)) :background "darkred")
1895 (((class color)) :background "red")
1896 (t :inverse-video t))
1897 (mdw-define-face ediff-fine-diff-A
1898 (((min-colors 64)) :background "red3")
1899 (((class color)) :inverse-video t)
1900 (t :inverse-video nil))
1901 (mdw-define-face ediff-even-diff-A
1902 (((min-colors 64)) :background "#300"))
1903 (mdw-define-face ediff-odd-diff-A
1904 (((min-colors 64)) :background "#300"))
1905 (mdw-define-face ediff-current-diff-B
1906 (((min-colors 64)) :background "darkgreen")
1907 (((class color)) :background "magenta")
1908 (t :inverse-video t))
1909 (mdw-define-face ediff-fine-diff-B
1910 (((min-colors 64)) :background "green4")
1911 (((class color)) :inverse-video t)
1912 (t :inverse-video nil))
1913 (mdw-define-face ediff-even-diff-B
1914 (((min-colors 64)) :background "#020"))
1915 (mdw-define-face ediff-odd-diff-B
1916 (((min-colors 64)) :background "#020"))
1917 (mdw-define-face ediff-current-diff-C
1918 (((min-colors 64)) :background "darkblue")
1919 (((class color)) :background "blue")
1920 (t :inverse-video t))
1921 (mdw-define-face ediff-fine-diff-C
1922 (((min-colors 64)) :background "blue1")
1923 (((class color)) :inverse-video t)
1924 (t :inverse-video nil))
1925 (mdw-define-face ediff-even-diff-C
1926 (((min-colors 64)) :background "#004"))
1927 (mdw-define-face ediff-odd-diff-C
1928 (((min-colors 64)) :background "#004"))
1929 (mdw-define-face ediff-current-diff-Ancestor
1930 (((min-colors 64)) :background "#630")
1931 (((class color)) :background "blue")
1932 (t :inverse-video t))
1933 (mdw-define-face ediff-even-diff-Ancestor
1934 (((min-colors 64)) :background "#320"))
1935 (mdw-define-face ediff-odd-diff-Ancestor
1936 (((min-colors 64)) :background "#320"))
1938 (mdw-define-face magit-hash
1939 (((min-colors 64)) :foreground "grey40")
1940 (((class color)) :foreground "blue"))
1941 (mdw-define-face magit-diff-hunk-heading
1942 (((min-colors 64)) :foreground "grey70" :background "grey25")
1943 (((class color)) :foreground "yellow"))
1944 (mdw-define-face magit-diff-hunk-heading-highlight
1945 (((min-colors 64)) :foreground "grey70" :background "grey35")
1946 (((class color)) :foreground "yellow" :background "blue"))
1947 (mdw-define-face magit-diff-added
1948 (((min-colors 64)) :foreground "#ddffdd" :background "#335533")
1949 (((class color)) :foreground "green"))
1950 (mdw-define-face magit-diff-added-highlight
1951 (((min-colors 64)) :foreground "#cceecc" :background "#336633")
1952 (((class color)) :foreground "green" :background "blue"))
1953 (mdw-define-face magit-diff-removed
1954 (((min-colors 64)) :foreground "#ffdddd" :background "#553333")
1955 (((class color)) :foreground "red"))
1956 (mdw-define-face magit-diff-removed-highlight
1957 (((min-colors 64)) :foreground "#eecccc" :background "#663333")
1958 (((class color)) :foreground "red" :background "blue"))
1959 (mdw-define-face magit-blame-heading
1960 (((min-colors 64)) :foreground "white" :background "grey25"
1961 :weight normal :slant normal)
1962 (((class color)) :foreground "white" :background "blue"
1963 :weight normal :slant normal))
1964 (mdw-define-face magit-blame-name
1965 (t :inherit magit-blame-heading :slant italic))
1966 (mdw-define-face magit-blame-date
1967 (((min-colors 64)) :inherit magit-blame-heading :foreground "grey60")
1968 (((class color)) :inherit magit-blame-heading :foreground "cyan"))
1969 (mdw-define-face magit-blame-summary
1970 (t :inherit magit-blame-heading :weight bold))
1972 (mdw-define-face dylan-header-background
1973 (((min-colors 64)) :background "NavyBlue")
1974 (((class color)) :background "blue"))
1976 (mdw-define-face erc-input-face
1977 (t :foreground "red"))
1979 (mdw-define-face woman-bold
1981 (mdw-define-face woman-italic
1984 (eval-after-load "rst"
1986 (mdw-define-face rst-level-1-face
1987 (t :foreground "SkyBlue1" :weight bold))
1988 (mdw-define-face rst-level-2-face
1989 (t :foreground "SeaGreen1" :weight bold))
1990 (mdw-define-face rst-level-3-face
1992 (mdw-define-face rst-level-4-face
1994 (mdw-define-face rst-level-5-face
1996 (mdw-define-face rst-level-6-face
1999 (mdw-define-face p4-depot-added-face
2000 (t :foreground "green"))
2001 (mdw-define-face p4-depot-branch-op-face
2002 (t :foreground "yellow"))
2003 (mdw-define-face p4-depot-deleted-face
2004 (t :foreground "red"))
2005 (mdw-define-face p4-depot-unmapped-face
2006 (t :foreground "SkyBlue1"))
2007 (mdw-define-face p4-diff-change-face
2008 (t :foreground "yellow"))
2009 (mdw-define-face p4-diff-del-face
2010 (t :foreground "red"))
2011 (mdw-define-face p4-diff-file-face
2012 (t :foreground "SkyBlue1"))
2013 (mdw-define-face p4-diff-head-face
2014 (t :background "grey10"))
2015 (mdw-define-face p4-diff-ins-face
2016 (t :foreground "green"))
2018 (mdw-define-face w3m-anchor-face
2019 (t :foreground "SkyBlue1" :underline t))
2020 (mdw-define-face w3m-arrived-anchor-face
2021 (t :foreground "SkyBlue1" :underline t))
2023 (mdw-define-face whizzy-slice-face
2024 (t :background "grey10"))
2025 (mdw-define-face whizzy-error-face
2026 (t :background "darkred"))
2028 ;; Ellipses used to indicate hidden text (and similar).
2029 (mdw-define-face mdw-ellipsis-face
2030 (((type tty)) :foreground "blue") (t :foreground "grey60"))
2031 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
2032 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
2033 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
2034 (bar (make-glyph-code ?| mdw-ellipsis-face)))
2035 (set-display-table-slot standard-display-table 0 dollar)
2036 (set-display-table-slot standard-display-table 1 backslash)
2037 (set-display-table-slot standard-display-table 4
2038 (vector dot dot dot))
2039 (set-display-table-slot standard-display-table 5 bar))
2041 ;;;--------------------------------------------------------------------------
2044 (mdw-define-face mdw-point-overlay-face
2046 (((min-colors 64)) :background "darkblue")
2047 (((class color)) :background "blue")
2048 (((type tty) (class mono)) :inverse-video t))
2050 (defcustom mdw-point-overlay-fringe-display '(vertical-bar . vertical-bar)
2051 "Bitmaps to display in the left and right fringes in the current line."
2052 :type '(cons symbol symbol))
2054 (defun mdw-configure-point-overlay ()
2055 (let ((ov (make-overlay 0 0)))
2056 (overlay-put ov 'priority 0)
2057 (let* ((fringe (or mdw-point-overlay-fringe-display (cons nil nil)))
2058 (left (car fringe)) (right (cdr fringe))
2062 (put-text-property 0 1 'display `(left-fringe ,left) ss)
2063 (setq s (concat s ss))))
2066 (put-text-property 0 1 'display `(right-fringe ,right) ss)
2067 (setq s (concat s ss))))
2068 (when (or left right)
2069 (overlay-put ov 'before-string s)))
2070 (overlay-put ov 'face 'mdw-point-overlay-face)
2074 (defvar mdw-point-overlay (mdw-configure-point-overlay)
2075 "An overlay used for showing where point is in the selected window.")
2076 (defun mdw-reconfigure-point-overlay ()
2078 (setq mdw-point-overlay (mdw-configure-point-overlay)))
2080 (defun mdw-remove-point-overlay ()
2081 "Remove the current-point overlay."
2082 (delete-overlay mdw-point-overlay))
2084 (defun mdw-update-point-overlay ()
2085 "Mark the current point position with an overlay."
2086 (if (not mdw-point-overlay-mode)
2087 (mdw-remove-point-overlay)
2088 (overlay-put mdw-point-overlay 'window (selected-window))
2089 (move-overlay mdw-point-overlay
2090 (line-beginning-position)
2091 (+ (line-end-position) 1))))
2093 (defvar mdw-point-overlay-buffers nil
2094 "List of buffers using `mdw-point-overlay-mode'.")
2096 (define-minor-mode mdw-point-overlay-mode
2097 "Indicate current line with an overlay."
2099 (let ((buffer (current-buffer)))
2100 (setq mdw-point-overlay-buffers
2101 (mapcan (lambda (buf)
2102 (if (and (buffer-live-p buf)
2103 (not (eq buf buffer)))
2105 mdw-point-overlay-buffers))
2106 (if mdw-point-overlay-mode
2107 (setq mdw-point-overlay-buffers
2108 (cons buffer mdw-point-overlay-buffers))))
2109 (cond (mdw-point-overlay-buffers
2110 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
2111 (add-hook 'post-command-hook 'mdw-update-point-overlay))
2113 (mdw-remove-point-overlay)
2114 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
2115 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
2117 (define-globalized-minor-mode mdw-global-point-overlay-mode
2118 mdw-point-overlay-mode
2119 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
2121 (defvar mdw-terminal-title-alist nil)
2122 (defun mdw-update-terminal-title ()
2123 (when (let ((term (frame-parameter nil 'tty-type)))
2124 (and term (string-match "^xterm" term)))
2125 (let* ((tty (frame-parameter nil 'tty))
2126 (old (assoc tty mdw-terminal-title-alist))
2127 (new (format-mode-line frame-title-format)))
2128 (unless (and old (equal (cdr old) new))
2129 (if old (rplacd old new)
2130 (setq mdw-terminal-title-alist
2131 (cons (cons tty new) mdw-terminal-title-alist)))
2132 (send-string-to-terminal (concat "\e]2;" new "\e\\"))))))
2134 (add-hook 'post-command-hook 'mdw-update-terminal-title)
2136 ;;;--------------------------------------------------------------------------
2137 ;;; C programming configuration.
2139 ;; Make C indentation nice.
2141 (defun mdw-c-lineup-arglist (langelem)
2142 "Hack for DWIMmery in c-lineup-arglist."
2144 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
2146 (c-lineup-arglist langelem)))
2148 (defun mdw-c-indent-extern-mumble (langelem)
2149 "Indent `extern \"...\" {' lines."
2151 (back-to-indentation)
2153 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
2157 (defun mdw-c-indent-arglist-nested (langelem)
2158 "Indent continued argument lists.
2159 If we've nested more than one argument list, then only introduce a single
2160 indentation anyway."
2161 (let ((context c-syntactic-context)
2162 (pos (c-langelem-2nd-pos c-syntactic-element))
2163 (should-indent-p t))
2165 (eq (caar context) 'arglist-cont-nonempty))
2166 (when (and (= (caddr (pop context)) pos)
2168 (memq (caar context) '(arglist-intro
2169 arglist-cont-nonempty)))
2170 (setq should-indent-p nil)))
2171 (if should-indent-p '+ 0)))
2173 (defvar mdw-define-c-styles-hook nil
2174 "Hook run when `cc-mode' starts up to define styles.")
2176 (defun mdw-merge-style-alists (first second)
2178 (dolist (item first)
2179 (let ((key (car item)) (value (cdr item)))
2180 (if (string-suffix-p "-alist" (symbol-name key))
2182 (mdw-merge-style-alists value
2183 (cdr (assoc key second))))
2185 (push item output))))
2186 (dolist (item second)
2187 (unless (assoc (car item) first)
2188 (push item output)))
2191 (cl-defmacro mdw-define-c-style (name (&optional parent) &rest assocs)
2192 "Define a C style, called NAME (a symbol) based on PARENT, setting ASSOCs.
2193 A function, named `mdw-define-c-style/NAME', is defined to actually install
2194 the style using `c-add-style', and added to the hook
2195 `mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
2197 (declare (indent defun))
2198 (let* ((name-string (symbol-name name))
2199 (var (intern (concat "mdw-c-style/" name-string)))
2200 (func (intern (concat "mdw-define-c-style/" name-string))))
2205 (let ((parent-list (intern (concat "mdw-c-style/"
2206 (symbol-name parent)))))
2207 `(mdw-merge-style-alists ',assocs ,parent-list))))
2208 (defun ,func () (c-add-style ,name-string ,var))
2209 (and (featurep 'cc-mode) (,func))
2210 (add-hook 'mdw-define-c-styles-hook ',func)
2213 (eval-after-load "cc-mode"
2214 '(run-hooks 'mdw-define-c-styles-hook))
2216 (mdw-define-c-style mdw-c ()
2217 (c-basic-offset . 2)
2218 (comment-column . 40)
2219 (c-class-key . "class")
2220 (c-backslash-column . 72)
2221 (c-label-minimum-indentation . 0)
2222 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
2223 (defun-open . (add 0 c-indent-one-line-block))
2224 (arglist-cont-nonempty . mdw-c-lineup-arglist)
2225 (topmost-intro . mdw-c-indent-extern-mumble)
2226 (cpp-define-intro . 0)
2228 (inextern-lang . [0])
2234 (statement-cont . +)
2235 (statement-case-intro . +)))
2237 (mdw-define-c-style mdw-trustonic-c (mdw-c)
2238 (c-basic-offset . 4)
2239 (c-offsets-alist (access-label . -2)))
2241 (mdw-define-c-style mdw-trustonic-alec-c (mdw-trustonic-c)
2242 (comment-column . 0)
2243 (c-indent-comment-alist (anchored-comment . (column . 0))
2244 (end-block . (space . 1))
2245 (cpp-end-block . (space . 1))
2246 (other . (space . 1)))
2247 (c-offsets-alist (arglist-cont-nonempty . mdw-c-indent-arglist-nested)))
2249 (defun mdw-set-default-c-style (modes style)
2250 "Update the default CC Mode style for MODES to be STYLE.
2252 MODES may be a list of major mode names or a singleton. STYLE is a style
2254 (let ((modes (if (listp modes) modes (list modes)))
2255 (style (symbol-name style)))
2256 (setq c-default-style
2257 (append (mapcar (lambda (mode)
2260 (remove-if (lambda (assoc)
2261 (memq (car assoc) modes))
2262 (if (listp c-default-style)
2264 (list (cons 'other c-default-style))))))))
2265 (setq c-default-style "mdw-c")
2267 (mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
2269 (defvar mdw-c-comment-fill-prefix
2270 `((,(concat "\\([ \t]*/?\\)"
2273 "\\([A-Za-z]+:[ \t]*\\)?"
2274 mdw-hanging-indents)
2275 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
2276 "Fill prefix matching C comments (both kinds).")
2278 (defun mdw-fontify-c-and-c++ ()
2280 ;; Fiddle with some syntax codes.
2281 (modify-syntax-entry ?* ". 23")
2282 (modify-syntax-entry ?/ ". 124b")
2283 (modify-syntax-entry ?\n "> b")
2286 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2288 ;; Now define things to be fontified.
2289 (make-local-variable 'font-lock-keywords)
2291 (mdw-regexps "alignas" ;C11 macro, C++11
2293 "and" ;C++, C95 macro
2294 "and_eq" ;C++, C95 macro
2295 "asm" ;K&R, C++, GCC
2296 "atomic" ;C11 macro, C++11 template type
2298 "bitand" ;C++, C95 macro
2299 "bitor" ;C++, C95 macro
2300 "bool" ;C++, C99 macro
2305 "char16_t" ;C++11, C11 library type
2306 "char32_t" ;C++11, C11 library type
2308 "complex" ;C99 macro, C++ template type
2309 "compl" ;C++, C95 macro
2313 "continue" ;K&R, C89
2315 "defined" ;C89 preprocessor
2322 ;; "entry" ;K&R -- never used
2333 "imaginary" ;C99 macro
2334 "inline" ;C++, C99, GCC
2341 "noreturn" ;C11 macro
2342 "not" ;C++, C95 macro
2343 "not_eq" ;C++, C95 macro
2346 "or" ;C++, C95 macro
2347 "or_eq" ;C++, C95 macro
2351 "register" ;K&R, C89
2352 "reinterpret_cast" ;C++
2359 "static_assert" ;C11 macro, C++11
2366 "thread_local" ;C11 macro, C++11
2372 "unsigned" ;K&R, C89
2377 "wchar_t" ;C++, C89 library type
2379 "xor" ;C++, C95 macro
2380 "xor_eq" ;C++, C95 macro
2389 "_Pragma" ;C99 preprocessor
2390 "_Static_assert" ;C11
2391 "_Thread_local" ;C11
2394 "__attribute__" ;GCC
2397 "__extension__" ;GCC
2407 (mdw-regexps "false" ;C++, C99 macro
2409 "true" ;C++, C99 macro
2411 (preprocessor-keywords
2412 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2413 "ident" "if" "ifdef" "ifndef" "import" "include"
2414 "line" "pragma" "unassert" "undef" "warning"))
2416 (mdw-regexps "class" "defs" "encode" "end" "implementation"
2417 "interface" "private" "protected" "protocol" "public"
2420 (setq font-lock-keywords
2423 ;; Fontify include files as strings.
2424 (list (concat "^[ \t]*\\#[ \t]*"
2425 "\\(include\\|import\\)"
2426 "[ \t]*\\(<[^>]+>?\\)")
2427 '(2 font-lock-string-face))
2429 ;; Preprocessor directives are `references'?.
2430 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2431 preprocessor-keywords
2432 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2433 '(1 font-lock-keyword-face))
2435 ;; Handle the keywords defined above.
2436 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
2437 '(0 font-lock-keyword-face))
2439 (list (concat "\\<\\(" c-keywords "\\)\\>")
2440 '(0 font-lock-keyword-face))
2442 (list (concat "\\<\\(" c-builtins "\\)\\>")
2443 '(0 font-lock-variable-name-face))
2445 ;; Handle numbers too.
2447 ;; This looks strange, I know. It corresponds to the
2448 ;; preprocessor's idea of what a number looks like, rather than
2449 ;; anything sensible.
2450 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2451 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2452 '(0 mdw-number-face))
2454 ;; And anything else is punctuation.
2455 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2456 '(0 mdw-punct-face))))))
2458 (define-derived-mode sod-mode c-mode "Sod"
2459 "Major mode for editing Sod code.")
2460 (push '("\\.sod$" . sod-mode) auto-mode-alist)
2462 (dolist (hook '(c-mode-hook objc-mode-hook c++-mode-hook))
2463 (add-hook hook 'mdw-misc-mode-config t)
2464 (add-hook hook 'mdw-fontify-c-and-c++ t))
2466 ;;;--------------------------------------------------------------------------
2469 (define-derived-mode apcalc-mode c-mode "AP Calc"
2470 "Major mode for editing Calc code.")
2472 (defun mdw-fontify-apcalc ()
2474 ;; Fiddle with some syntax codes.
2475 (modify-syntax-entry ?* ". 23")
2476 (modify-syntax-entry ?/ ". 14")
2479 (setq comment-start "/* ")
2480 (setq comment-end " */")
2481 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2483 ;; Now define things to be fontified.
2484 (make-local-variable 'font-lock-keywords)
2486 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
2487 "do" "else" "exit" "for" "global" "goto" "help" "if"
2488 "local" "mat" "obj" "print" "quit" "read" "return"
2489 "show" "static" "switch" "while" "write")))
2491 (setq font-lock-keywords
2494 ;; Handle the keywords defined above.
2495 (list (concat "\\<\\(" c-keywords "\\)\\>")
2496 '(0 font-lock-keyword-face))
2498 ;; Handle numbers too.
2500 ;; This looks strange, I know. It corresponds to the
2501 ;; preprocessor's idea of what a number looks like, rather than
2502 ;; anything sensible.
2503 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2504 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2505 '(0 mdw-number-face))
2507 ;; And anything else is punctuation.
2508 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2509 '(0 mdw-punct-face))))))
2512 (add-hook 'apcalc-mode-hook 'mdw-misc-mode-config t)
2513 (add-hook 'apcalc-mode-hook 'mdw-fontify-apcalc t))
2515 ;;;--------------------------------------------------------------------------
2516 ;;; Java programming configuration.
2518 ;; Make indentation nice.
2520 (mdw-define-c-style mdw-java ()
2521 (c-basic-offset . 2)
2522 (c-backslash-column . 72)
2523 (c-offsets-alist (substatement-open . 0)
2528 (statement-case-intro . +)))
2529 (mdw-set-default-c-style 'java-mode 'mdw-java)
2531 ;; Declare Java fontification style.
2533 (defun mdw-fontify-java ()
2535 ;; Fiddle with some syntax codes.
2536 (modify-syntax-entry ?@ ".")
2537 (modify-syntax-entry ?@ "." font-lock-syntax-table)
2540 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2542 ;; Now define things to be fontified.
2543 (make-local-variable 'font-lock-keywords)
2544 (let ((java-keywords
2545 (mdw-regexps "abstract" "assert"
2546 "boolean" "break" "byte"
2547 "case" "catch" "char" "class" "const" "continue"
2548 "default" "do" "double"
2549 "else" "enum" "extends"
2550 "final" "finally" "float" "for"
2552 "if" "implements" "import" "instanceof" "int"
2556 "package" "private" "protected" "public"
2558 "short" "static" "strictfp" "switch" "synchronized"
2559 "throw" "throws" "transient" "try"
2564 (mdw-regexps "false" "null" "super" "this" "true")))
2566 (setq font-lock-keywords
2569 ;; Handle the keywords defined above.
2570 (list (concat "\\<\\(" java-keywords "\\)\\>")
2571 '(0 font-lock-keyword-face))
2573 ;; Handle the magic builtins defined above.
2574 (list (concat "\\<\\(" java-builtins "\\)\\>")
2575 '(0 font-lock-variable-name-face))
2577 ;; Handle numbers too.
2579 ;; The following isn't quite right, but it's close enough.
2580 (list (concat "\\<\\("
2581 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2582 "[0-9]+\\(\\.[0-9]*\\)?"
2583 "\\([eE][-+]?[0-9]+\\)?\\)"
2585 '(0 mdw-number-face))
2587 ;; And anything else is punctuation.
2588 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2589 '(0 mdw-punct-face))))))
2592 (add-hook 'java-mode-hook 'mdw-misc-mode-config t)
2593 (add-hook 'java-mode-hook 'mdw-fontify-java t))
2595 ;;;--------------------------------------------------------------------------
2596 ;;; Javascript programming configuration.
2598 (defun mdw-javascript-style ()
2599 (setq js-indent-level 2)
2600 (setq js-expr-indent-offset 0))
2602 (defun mdw-fontify-javascript ()
2605 (mdw-javascript-style)
2606 (setq js-auto-indent-flag t)
2608 ;; Now define things to be fontified.
2609 (make-local-variable 'font-lock-keywords)
2610 (let ((javascript-keywords
2611 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
2612 "char" "class" "const" "continue" "debugger" "default"
2613 "delete" "do" "double" "else" "enum" "export" "extends"
2614 "final" "finally" "float" "for" "function" "goto" "if"
2615 "implements" "import" "in" "instanceof" "int"
2616 "interface" "let" "long" "native" "new" "package"
2617 "private" "protected" "public" "return" "short"
2618 "static" "super" "switch" "synchronized" "throw"
2619 "throws" "transient" "try" "typeof" "var" "void"
2620 "volatile" "while" "with" "yield"))
2621 (javascript-builtins
2622 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
2623 "arguments" "this")))
2625 (setq font-lock-keywords
2628 ;; Handle the keywords defined above.
2629 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
2630 '(0 font-lock-keyword-face))
2632 ;; Handle the predefined builtins defined above.
2633 (list (concat "\\_<\\(" javascript-builtins "\\)\\_>")
2634 '(0 font-lock-variable-name-face))
2636 ;; Handle numbers too.
2638 ;; The following isn't quite right, but it's close enough.
2639 (list (concat "\\_<\\("
2640 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2641 "[0-9]+\\(\\.[0-9]*\\)?"
2642 "\\([eE][-+]?[0-9]+\\)?\\)"
2644 '(0 mdw-number-face))
2646 ;; And anything else is punctuation.
2647 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2648 '(0 mdw-punct-face))))))
2651 (add-hook 'js-mode-hook 'mdw-misc-mode-config t)
2652 (add-hook 'js-mode-hook 'mdw-fontify-javascript t))
2654 ;;;--------------------------------------------------------------------------
2655 ;;; Scala programming configuration.
2657 (defun mdw-fontify-scala ()
2660 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2662 ;; Define things to be fontified.
2663 (make-local-variable 'font-lock-keywords)
2664 (let ((scala-keywords
2665 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
2666 "extends" "final" "finally" "for" "forSome" "if"
2667 "implicit" "import" "lazy" "match" "new" "object"
2668 "override" "package" "private" "protected" "return"
2669 "sealed" "throw" "trait" "try" "type" "val"
2670 "var" "while" "with" "yield"))
2672 (mdw-regexps "false" "null" "super" "this" "true"))
2673 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
2675 (setq font-lock-keywords
2678 ;; Magical identifiers between backticks.
2679 (list (concat "`\\([^`]+\\)`")
2680 '(1 font-lock-variable-name-face))
2682 ;; Handle the keywords defined above.
2683 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
2684 '(0 font-lock-keyword-face))
2686 ;; Handle the constants defined above.
2687 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
2688 '(0 font-lock-variable-name-face))
2690 ;; Magical identifiers between backticks.
2691 (list (concat "`\\([^`]+\\)`")
2692 '(1 font-lock-variable-name-face))
2694 ;; Handle numbers too.
2696 ;; As usual, not quite right.
2697 (list (concat "\\_<\\("
2698 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2699 "[0-9]+\\(\\.[0-9]*\\)?"
2700 "\\([eE][-+]?[0-9]+\\)?\\)"
2702 '(0 mdw-number-face))
2704 ;; And everything else is punctuation.
2705 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2706 '(0 mdw-punct-face)))
2708 font-lock-syntactic-keywords
2711 ;; Single quotes around characters. But not when used to quote
2712 ;; symbol names. Ugh.
2713 (list (concat "\\('\\)"
2715 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
2716 "u+" "[0-9a-fA-F]\\{4\\}"
2717 "\\|" "\\\\" "[0-7]\\{1,3\\}"
2718 "\\|" "\\\\" "." "\\)"
2724 (add-hook 'scala-mode-hook 'mdw-misc-mode-config t)
2725 (add-hook 'scala-mode-hook 'mdw-fontify-scala t))
2727 ;;;--------------------------------------------------------------------------
2728 ;;; C# programming configuration.
2730 ;; Make indentation nice.
2732 (mdw-define-c-style mdw-csharp ()
2733 (c-basic-offset . 2)
2734 (c-backslash-column . 72)
2735 (c-offsets-alist (substatement-open . 0)
2740 (statement-case-intro . +)))
2741 (mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
2743 ;; Declare C# fontification style.
2745 (defun mdw-fontify-csharp ()
2748 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2750 ;; Now define things to be fontified.
2751 (make-local-variable 'font-lock-keywords)
2752 (let ((csharp-keywords
2753 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
2754 "char" "checked" "class" "const" "continue" "decimal"
2755 "default" "delegate" "do" "double" "else" "enum"
2756 "event" "explicit" "extern" "finally" "fixed" "float"
2757 "for" "foreach" "goto" "if" "implicit" "in" "int"
2758 "interface" "internal" "is" "lock" "long" "namespace"
2759 "new" "object" "operator" "out" "override" "params"
2760 "private" "protected" "public" "readonly" "ref"
2761 "return" "sbyte" "sealed" "short" "sizeof"
2762 "stackalloc" "static" "string" "struct" "switch"
2763 "throw" "try" "typeof" "uint" "ulong" "unchecked"
2764 "unsafe" "ushort" "using" "virtual" "void" "volatile"
2768 (mdw-regexps "base" "false" "null" "this" "true")))
2770 (setq font-lock-keywords
2773 ;; Handle the keywords defined above.
2774 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
2775 '(0 font-lock-keyword-face))
2777 ;; Handle the magic builtins defined above.
2778 (list (concat "\\<\\(" csharp-builtins "\\)\\>")
2779 '(0 font-lock-variable-name-face))
2781 ;; Handle numbers too.
2783 ;; The following isn't quite right, but it's close enough.
2784 (list (concat "\\<\\("
2785 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2786 "[0-9]+\\(\\.[0-9]*\\)?"
2787 "\\([eE][-+]?[0-9]+\\)?\\)"
2789 '(0 mdw-number-face))
2791 ;; And anything else is punctuation.
2792 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2793 '(0 mdw-punct-face))))))
2795 (define-derived-mode csharp-mode java-mode "C#"
2796 "Major mode for editing C# code.")
2798 (add-hook 'csharp-mode-hook 'mdw-fontify-csharp t)
2800 ;;;--------------------------------------------------------------------------
2801 ;;; F# programming configuration.
2803 (setq fsharp-indent-offset 2)
2805 (defun mdw-fontify-fsharp ()
2807 (let ((punct "=<>+-*/|&%!@?"))
2809 ((>= i (length punct)))
2810 (modify-syntax-entry (aref punct i) ".")))
2812 (modify-syntax-entry ?_ "_")
2813 (modify-syntax-entry ?( "(")
2814 (modify-syntax-entry ?) ")")
2816 (setq indent-tabs-mode nil)
2818 (let ((fsharp-keywords
2819 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
2821 "checked" "class" "component" "const" "constraint"
2822 "constructor" "continue"
2823 "default" "delegate" "do" "done" "downcast" "downto"
2824 "eager" "elif" "else" "end" "exception" "extern"
2825 "finally" "fixed" "for" "fori" "fun" "function"
2828 "if" "in" "include" "inherit" "inline" "interface"
2831 "match" "measure" "member" "method" "mixin" "module"
2834 "object" "of" "open" "or" "override"
2835 "parallel" "params" "private" "process" "protected"
2837 "rec" "recursive" "return"
2838 "sealed" "sig" "static" "struct"
2839 "tailcall" "then" "to" "trait" "try" "type"
2841 "val" "virtual" "void" "volatile"
2842 "when" "while" "with"
2846 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
2847 "base" "false" "null" "true"))
2850 (mdw-regexps "do" "let" "return" "use" "yield"))
2852 (preprocessor-keywords
2853 (mdw-regexps "if" "indent" "else" "endif")))
2855 (setq font-lock-keywords
2856 (list (list (concat "\\(^\\|[^\"]\\)"
2859 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
2864 '(2 font-lock-comment-face))
2866 (list (concat "'" "\\("
2869 "\\|" "[0-9][0-9][0-9]"
2870 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
2871 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
2877 "\\(" "\\\\" "\\(.\\|\n\\)"
2880 '(0 font-lock-string-face))
2882 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
2883 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
2885 "\\_<\\(" fsharp-keywords "\\)\\_>")
2886 '(0 font-lock-keyword-face))
2887 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
2888 '(0 font-lock-variable-name-face))
2890 (list (concat "\\_<"
2891 "\\(" "0[bB][01]+" "\\|"
2893 "0[xX][0-9a-fA-F]+" "\\)"
2894 "\\(" "lf\\|LF" "\\|"
2895 "[uU]?[ysnlL]?" "\\)"
2902 "\\([eE][-+]?[0-9]+\\)?"
2907 '(0 mdw-number-face))
2909 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2910 '(0 mdw-punct-face))))))
2912 (defun mdw-fontify-inferior-fsharp ()
2913 (mdw-fontify-fsharp)
2914 (setq font-lock-keywords
2915 (append (list (list "^[#-]" '(0 font-lock-comment-face))
2916 (list "^>" '(0 font-lock-keyword-face)))
2917 font-lock-keywords)))
2920 (add-hook 'fsharp-mode-hook 'mdw-misc-mode-config t)
2921 (add-hook 'fsharp-mode-hook 'mdw-fontify-fsharp t)
2922 (add-hook 'inferior-fsharp-mode-hooks 'mdw-fontify-inferior-fsharp t))
2924 ;;;--------------------------------------------------------------------------
2925 ;;; Go programming configuration.
2927 (defun mdw-fontify-go ()
2929 (make-local-variable 'font-lock-keywords)
2931 (mdw-regexps "break" "case" "chan" "const" "continue"
2932 "default" "defer" "else" "fallthrough" "for"
2933 "func" "go" "goto" "if" "import"
2934 "interface" "map" "package" "range" "return"
2935 "select" "struct" "switch" "type" "var"))
2937 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
2938 "float32" "float64" "int" "uint8" "int16" "int32"
2939 "int64" "rune" "string" "uint" "uint8" "uint16"
2940 "uint32" "uint64" "uintptr" "void"
2941 "false" "iota" "nil" "true"
2943 "append" "cap" "copy" "delete" "imag" "len" "make"
2944 "new" "panic" "real" "recover")))
2946 (setq font-lock-keywords
2949 ;; Handle the keywords defined above.
2950 (list (concat "\\<\\(" go-keywords "\\)\\>")
2951 '(0 font-lock-keyword-face))
2952 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
2953 '(0 font-lock-variable-name-face))
2955 ;; Strings and characters.
2957 "\\(" "[^\\']" "\\|"
2959 "\\(" "[abfnrtv\\'\"]" "\\|"
2960 "[0-7]\\{3\\}" "\\|"
2961 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
2962 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
2963 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
2967 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
2971 '(0 font-lock-string-face))
2973 ;; Handle numbers too.
2975 ;; The following isn't quite right, but it's close enough.
2976 (list (concat "\\<\\("
2977 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2978 "[0-9]+\\(\\.[0-9]*\\)?"
2979 "\\([eE][-+]?[0-9]+\\)?\\)")
2980 '(0 mdw-number-face))
2982 ;; And anything else is punctuation.
2983 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2984 '(0 mdw-punct-face))))))
2986 (add-hook 'go-mode-hook 'mdw-misc-mode-config t)
2987 (add-hook 'go-mode-hook 'mdw-fontify-go t))
2989 ;;;--------------------------------------------------------------------------
2990 ;;; Rust programming configuration.
2992 (setq-default rust-indent-offset 2)
2994 (defun mdw-self-insert-and-indent (count)
2996 (self-insert-command count)
2997 (indent-according-to-mode))
2999 (defun mdw-fontify-rust ()
3001 ;; Hack syntax categories.
3002 (modify-syntax-entry ?$ ".")
3003 (modify-syntax-entry ?% ".")
3004 (modify-syntax-entry ?= ".")
3006 ;; Fontify keywords and things.
3007 (make-local-variable 'font-lock-keywords)
3008 (let ((rust-keywords
3009 (mdw-regexps "abstract" "alignof" "as" "async" "await"
3010 "become" "box" "break"
3011 "const" "continue" "crate"
3013 "else" "enum" "extern"
3017 "macro" "match" "mod" "move" "mut"
3018 "offsetof" "override"
3019 "priv" "proc" "pub" "pure"
3021 "sizeof" "static" "struct" "super"
3022 "trait" "try" "type" "typeof"
3023 "union" "unsafe" "unsized" "use"
3028 (mdw-regexps "array" "pointer" "slice" "tuple"
3029 "bool" "true" "false"
3031 "i8" "i16" "i32" "i64" "isize"
3032 "u8" "u16" "u32" "u64" "usize"
3035 (setq font-lock-keywords
3038 ;; Handle the keywords defined above.
3039 (list (concat "\\_<\\(" rust-keywords "\\)\\_>")
3040 '(0 font-lock-keyword-face))
3041 (list (concat "\\_<\\(" rust-builtins "\\)\\_>")
3042 '(0 font-lock-variable-name-face))
3044 ;; Handle numbers too.
3045 (list (concat "\\_<\\("
3047 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
3051 "\\|" "\\(" "[0-9][0-9_]*"
3052 "\\|" "0x[0-9a-fA-F_]+"
3056 "\\([ui]\\(8\\|16\\|32\\|64\\|size\\)\\)?"
3058 '(0 mdw-number-face))
3060 ;; And anything else is punctuation.
3061 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3062 '(0 mdw-punct-face)))))
3064 ;; Hack key bindings.
3065 (local-set-key [?{] 'mdw-self-insert-and-indent)
3066 (local-set-key [?}] 'mdw-self-insert-and-indent))
3069 (add-hook 'rust-mode-hook 'mdw-misc-mode-config t)
3070 (add-hook 'rust-mode-hook 'mdw-fontify-rust t))
3072 ;;;--------------------------------------------------------------------------
3073 ;;; Awk programming configuration.
3075 ;; Make Awk indentation nice.
3077 (mdw-define-c-style mdw-awk ()
3078 (c-basic-offset . 2)
3079 (c-offsets-alist (substatement-open . 0)
3080 (c-backslash-column . 72)
3081 (statement-cont . 0)
3082 (statement-case-intro . +)))
3083 (mdw-set-default-c-style 'awk-mode 'mdw-awk)
3085 ;; Declare Awk fontification style.
3087 (defun mdw-fontify-awk ()
3089 ;; Miscellaneous fiddling.
3090 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3092 ;; Now define things to be fontified.
3093 (make-local-variable 'font-lock-keywords)
3095 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
3096 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
3097 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
3098 "RSTART" "RLENGTH" "RT" "SUBSEP"
3099 "atan2" "break" "close" "continue" "cos" "delete"
3100 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
3101 "function" "gensub" "getline" "gsub" "if" "in"
3102 "index" "int" "length" "log" "match" "next" "rand"
3103 "return" "print" "printf" "sin" "split" "sprintf"
3104 "sqrt" "srand" "strftime" "sub" "substr" "system"
3105 "systime" "tolower" "toupper" "while")))
3107 (setq font-lock-keywords
3110 ;; Handle the keywords defined above.
3111 (list (concat "\\<\\(" c-keywords "\\)\\>")
3112 '(0 font-lock-keyword-face))
3114 ;; Handle numbers too.
3116 ;; The following isn't quite right, but it's close enough.
3117 (list (concat "\\<\\("
3118 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
3119 "[0-9]+\\(\\.[0-9]*\\)?"
3120 "\\([eE][-+]?[0-9]+\\)?\\)"
3122 '(0 mdw-number-face))
3124 ;; And anything else is punctuation.
3125 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3126 '(0 mdw-punct-face))))))
3129 (add-hook 'awk-mode-hook 'mdw-misc-mode-config t)
3130 (add-hook 'awk-mode-hook 'mdw-fontify-awk t))
3132 ;;;--------------------------------------------------------------------------
3133 ;;; Perl programming style.
3135 ;; Perl indentation style.
3137 (setq-default perl-indent-level 2)
3139 (setq-default cperl-indent-level 2
3140 cperl-continued-statement-offset 2
3141 cperl-continued-brace-offset 0
3142 cperl-brace-offset -2
3143 cperl-brace-imaginary-offset 0
3144 cperl-label-offset 0)
3146 ;; Define perl fontification style.
3148 (defun mdw-fontify-perl ()
3150 ;; Miscellaneous fiddling.
3151 (modify-syntax-entry ?$ "\\")
3152 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
3153 (modify-syntax-entry ?: "." font-lock-syntax-table)
3154 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3156 ;; Now define fontification things.
3157 (make-local-variable 'font-lock-keywords)
3158 (let ((perl-keywords
3165 "ge" "given" "gt" "goto"
3167 "last" "le" "local" "lt"
3172 "redo" "require" "return"
3174 "undef" "unless" "until" "use"
3177 (setq font-lock-keywords
3180 ;; Set up the keywords defined above.
3181 (list (concat "\\<\\(" perl-keywords "\\)\\>")
3182 '(0 font-lock-keyword-face))
3184 ;; At least numbers are simpler than C.
3185 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3186 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
3187 "\\([eE][-+]?[0-9_]+\\)?")
3188 '(0 mdw-number-face))
3190 ;; And anything else is punctuation.
3191 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3192 '(0 mdw-punct-face))))))
3194 (defun perl-number-tests (&optional arg)
3195 "Assign consecutive numbers to lines containing `#t'. With ARG,
3196 strip numbers instead."
3199 (goto-char (point-min))
3200 (let ((i 0) (fmt (if arg "" " %4d")))
3201 (while (search-forward "#t" nil t)
3202 (delete-region (point) (line-end-position))
3204 (insert (format fmt i)))
3205 (goto-char (point-min))
3206 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
3207 (replace-match (format "\\1%d" i))))))
3209 (dolist (hook '(perl-mode-hook cperl-mode-hook))
3210 (add-hook hook 'mdw-misc-mode-config t)
3211 (add-hook hook 'mdw-fontify-perl t))
3213 ;;;--------------------------------------------------------------------------
3214 ;;; Python programming style.
3216 (setq-default py-indent-offset 2
3218 python-indent-offset 2
3219 python-fill-docstring-style 'symmetric)
3221 (defun mdw-fontify-pythonic (keywords)
3223 ;; Miscellaneous fiddling.
3224 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3225 (setq indent-tabs-mode nil)
3226 (set (make-local-variable 'forward-sexp-function) nil)
3228 ;; Now define fontification things.
3229 (make-local-variable 'font-lock-keywords)
3230 (setq font-lock-keywords
3233 ;; Set up the keywords defined above.
3234 (list (concat "\\_<\\(" keywords "\\)\\_>")
3235 '(0 font-lock-keyword-face))
3237 ;; At least numbers are simpler than C.
3238 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO]?[0-7]+\\|[bB][01]+\\)\\|"
3239 "\\_<[0-9][0-9]*\\(\\.[0-9]*\\)?"
3240 "\\([eE][-+]?[0-9]+\\|[lL]\\)?")
3241 '(0 mdw-number-face))
3243 ;; And anything else is punctuation.
3244 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3245 '(0 mdw-punct-face)))))
3247 ;; Define Python fontification styles.
3249 (defun mdw-fontify-python ()
3250 (mdw-fontify-pythonic
3251 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
3252 "del" "elif" "else" "except" "exec" "finally" "for"
3253 "from" "global" "if" "import" "in" "is" "lambda"
3254 "not" "or" "pass" "print" "raise" "return" "try"
3255 "while" "with" "yield")))
3257 (defun mdw-fontify-pyrex ()
3258 (mdw-fontify-pythonic
3259 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
3260 "ctypedef" "def" "del" "elif" "else" "enum" "except" "exec"
3261 "extern" "finally" "for" "from" "global" "if"
3262 "import" "in" "is" "lambda" "not" "or" "pass" "print"
3263 "property" "raise" "return" "struct" "try" "while" "with"
3266 (define-derived-mode pyrex-mode python-mode "Pyrex"
3267 "Major mode for editing Pyrex source code")
3268 (setq auto-mode-alist
3269 (append '(("\\.pyx$" . pyrex-mode)
3270 ("\\.pxd$" . pyrex-mode)
3271 ("\\.pxi$" . pyrex-mode))
3275 (add-hook 'python-mode-hook 'mdw-misc-mode-config t)
3276 (add-hook 'python-mode-hook 'mdw-fontify-python t)
3277 (add-hook 'pyrex-mode-hook 'mdw-fontify-pyrex t))
3279 ;;;--------------------------------------------------------------------------
3280 ;;; Lua programming style.
3282 (setq-default lua-indent-level 2)
3284 (defun mdw-fontify-lua ()
3286 ;; Miscellaneous fiddling.
3287 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3289 ;; Now define fontification things.
3290 (make-local-variable 'font-lock-keywords)
3292 (mdw-regexps "and" "break" "do" "else" "elseif" "end"
3293 "false" "for" "function" "goto" "if" "in" "local"
3294 "nil" "not" "or" "repeat" "return" "then" "true"
3296 (setq font-lock-keywords
3299 ;; Set up the keywords defined above.
3300 (list (concat "\\_<\\(" lua-keywords "\\)\\_>")
3301 '(0 font-lock-keyword-face))
3303 ;; At least numbers are simpler than C.
3304 (list (concat "\\_<\\(" "0[xX]"
3305 "\\(" "[0-9a-fA-F]+"
3306 "\\(\\.[0-9a-fA-F]*\\)?"
3307 "\\|" "\\.[0-9a-fA-F]+"
3309 "\\([pP][-+]?[0-9]+\\)?"
3310 "\\|" "\\(" "[0-9]+"
3314 "\\([eE][-+]?[0-9]+\\)?"
3316 '(0 mdw-number-face))
3318 ;; And anything else is punctuation.
3319 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3320 '(0 mdw-punct-face))))))
3323 (add-hook 'lua-mode-hook 'mdw-misc-mode-config t)
3324 (add-hook 'lua-mode-hook 'mdw-fontify-lua t))
3326 ;;;--------------------------------------------------------------------------
3327 ;;; Icon programming style.
3329 ;; Icon indentation style.
3331 (setq-default icon-brace-offset 0
3332 icon-continued-brace-offset 0
3333 icon-continued-statement-offset 2
3334 icon-indent-level 2)
3336 ;; Define Icon fontification style.
3338 (defun mdw-fontify-icon ()
3340 ;; Miscellaneous fiddling.
3341 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3343 ;; Now define fontification things.
3344 (make-local-variable 'font-lock-keywords)
3345 (let ((icon-keywords
3346 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
3347 "end" "every" "fail" "global" "if" "initial"
3348 "invocable" "link" "local" "next" "not" "of"
3349 "procedure" "record" "repeat" "return" "static"
3350 "suspend" "then" "to" "until" "while"))
3351 (preprocessor-keywords
3352 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
3353 "include" "line" "undef")))
3354 (setq font-lock-keywords
3357 ;; Set up the keywords defined above.
3358 (list (concat "\\<\\(" icon-keywords "\\)\\>")
3359 '(0 font-lock-keyword-face))
3361 ;; The things that Icon calls keywords.
3362 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
3364 ;; At least numbers are simpler than C.
3365 (list (concat "\\<[0-9]+"
3366 "\\([rR][0-9a-zA-Z]+\\|"
3367 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
3368 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
3369 '(0 mdw-number-face))
3372 (list (concat "^[ \t]*$[ \t]*\\<\\("
3373 preprocessor-keywords
3375 '(0 font-lock-keyword-face))
3377 ;; And anything else is punctuation.
3378 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3379 '(0 mdw-punct-face))))))
3382 (add-hook 'icon-mode-hook 'mdw-misc-mode-config t)
3383 (add-hook 'icon-mode-hook 'mdw-fontify-icon t))
3385 ;;;--------------------------------------------------------------------------
3388 (defun mdw-fontify-fortran-common ()
3389 (let ((fortran-keywords
3390 (mdw-regexps "access"
3408 "double\\s-*precision"
3409 "else" "elseif" "elsewhere"
3411 "endblock" "endblockdata"
3467 "select" "selectcase" "selecttype"
3478 (fortran-operators (mdw-regexps "and"
3491 (fortran-intrinsics (mdw-regexps "abs" "dabs" "iabs" "cabs"
3492 "atan" "datan" "atan2" "datan2"
3502 "int" "aint" "idint"
3503 "alog" "dlog" "clog"
3515 "sign" "isign" "dsign"
3517 "sqrt" "dsqrt" "csqrt"
3519 (preprocessor-keywords
3520 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
3521 "ident" "if" "ifdef" "ifndef" "import" "include"
3522 "line" "pragma" "unassert" "undef" "warning")))
3523 (setq font-lock-keywords-case-fold-search t
3527 ;; Fontify include files as strings.
3528 (list (concat "^[ \t]*\\#[ \t]*" "include"
3529 "[ \t]*\\(<[^>]+>?\\)")
3530 '(1 font-lock-string-face))
3532 ;; Preprocessor directives are `references'?.
3533 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
3534 preprocessor-keywords
3535 "\\)\\>\\|[0-9]+\\|$\\)\\)")
3536 '(1 font-lock-keyword-face))
3538 ;; Set up the keywords defined above.
3539 (list (concat "\\<\\(" fortran-keywords "\\)\\>")
3540 '(0 font-lock-keyword-face))
3542 ;; Set up the `.foo.' operators.
3543 (list (concat "\\.\\(" fortran-operators "\\)\\.")
3544 '(0 font-lock-keyword-face))
3546 ;; Set up the intrinsic functions.
3547 (list (concat "\\<\\(" fortran-intrinsics "\\)\\>")
3548 '(0 font-lock-variable-name-face))
3551 (list (concat "\\(" "\\<" "[0-9]+" "\\(\\.[0-9]*\\)?"
3554 "\\(" "[de]" "[+-]?" "[0-9]+" "\\)?"
3555 "\\(" "_" "\\sw+" "\\)?"
3556 "\\|" "b'[01]*'" "\\|" "'[01]*'b"
3557 "\\|" "b\"[01]*\"" "\\|" "\"[01]*\"b"
3558 "\\|" "o'[0-7]*'" "\\|" "'[0-7]*'o"
3559 "\\|" "o\"[0-7]*\"" "\\|" "\"[0-7]*\"o"
3560 "\\|" "[xz]'[0-9a-f]*'" "\\|" "'[0-9a-f]*'[xz]"
3561 "\\|" "[xz]\"[0-9a-f]*\"" "\\|" "\"[0-9a-f]*\"[xz]")
3562 '(0 mdw-number-face))
3564 ;; Any anything else is punctuation.
3565 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3566 '(0 mdw-punct-face))))
3568 (modify-syntax-entry ?/ "." font-lock-syntax-table)
3569 (modify-syntax-entry ?< ".")
3570 (modify-syntax-entry ?> ".")))
3572 (defun mdw-fontify-fortran () (mdw-fontify-fortran-common))
3573 (defun mdw-fontify-f90 () (mdw-fontify-fortran-common))
3575 (setq fortran-do-indent 2
3577 fortran-structure-indent 2
3578 fortran-comment-line-start "*"
3579 fortran-comment-indent-style 'relative
3580 fortran-continuation-string "&"
3581 fortran-continuation-indent 4)
3583 (setq f90-do-indent 2
3585 f90-program-indent 2
3586 f90-continuation-indent 4
3587 f90-smart-end-names nil
3588 f90-smart-end 'no-blink)
3591 (add-hook 'fortran-mode-hook 'mdw-misc-mode-config t)
3592 (add-hook 'fortran-mode-hook 'mdw-fontify-fortran t)
3593 (add-hook 'f90-mode-hook 'mdw-misc-mode-config t)
3594 (add-hook 'f90-mode-hook 'mdw-fontify-f90 t))
3596 ;;;--------------------------------------------------------------------------
3599 (defun mdw-fontify-asm ()
3600 (modify-syntax-entry ?' "\"")
3601 (modify-syntax-entry ?. "w")
3602 (modify-syntax-entry ?\n ">")
3603 (setf fill-prefix nil)
3604 (modify-syntax-entry ?. "_")
3605 (modify-syntax-entry ?* ". 23")
3606 (modify-syntax-entry ?/ ". 124b")
3607 (modify-syntax-entry ?\n "> b")
3608 (local-set-key ";" 'self-insert-command)
3609 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
3611 (defun mdw-asm-set-comment ()
3612 (modify-syntax-entry ?; "."
3614 (modify-syntax-entry asm-comment-char "< b")
3615 (setq comment-start (string asm-comment-char ? )))
3616 (add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
3617 (put 'asm-comment-char 'safe-local-variable 'characterp)
3620 (add-hook 'asm-mode-hook 'mdw-misc-mode-config t)
3621 (add-hook 'asm-mode-hook 'mdw-fontify-asm t))
3623 ;;;--------------------------------------------------------------------------
3624 ;;; TCL configuration.
3626 (setq-default tcl-indent-level 2)
3628 (defun mdw-fontify-tcl ()
3630 (modify-syntax-entry ch "."))
3631 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3632 (make-local-variable 'font-lock-keywords)
3633 (setq font-lock-keywords
3635 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3636 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
3637 "\\([eE][-+]?[0-9_]+\\)?")
3638 '(0 mdw-number-face))
3639 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3640 '(0 mdw-punct-face)))))
3643 (add-hook 'tcl-mode-hook 'mdw-misc-mode-config t)
3644 (add-hook 'tcl-mode-hook 'mdw-fontify-tcl t))
3646 ;;;--------------------------------------------------------------------------
3647 ;;; Dylan programming configuration.
3649 (defun mdw-fontify-dylan ()
3651 (make-local-variable 'font-lock-keywords)
3653 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
3654 ;; hook, which undoes all of our configuration.
3655 (setq major-mode 'dylan-mode)
3656 (font-lock-set-defaults)
3658 (let* ((word "[-_a-zA-Z!*@<>$%]+")
3659 (dylan-keywords (mdw-regexps
3661 "C-address" "C-callable-wrapper" "C-function"
3662 "C-mapped-subtype" "C-pointer-type" "C-struct"
3663 "C-subtype" "C-union" "C-variable"
3665 "above" "abstract" "afterwards" "all"
3666 "begin" "below" "block" "by"
3667 "case" "class" "cleanup" "constant" "create"
3669 "else" "elseif" "end" "exception" "export"
3670 "finally" "for" "from" "function"
3673 "if" "in" "instance" "interface" "iterate"
3675 "let" "library" "local"
3676 "macro" "method" "module"
3679 "select" "slot" "subclass"
3681 "unless" "until" "use"
3682 "variable" "virtual"
3684 (sharp-keywords (mdw-regexps
3685 "all-keys" "key" "next" "rest" "include"
3687 (setq font-lock-keywords
3688 (list (list (concat "\\<\\(" dylan-keywords
3689 "\\|" "with\\(out\\)?-" word
3691 '(0 font-lock-keyword-face))
3692 (list (concat "\\<" word ":" "\\|"
3693 "#\\(" sharp-keywords "\\)\\>")
3694 '(0 font-lock-variable-name-face))
3696 "\\([-+]\\|\\<\\)[0-9]+" "\\("
3697 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
3700 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
3703 "\\|" "#x[0-9a-zA-Z]+"
3705 '(0 mdw-number-face))
3707 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
3708 "\\_<[-+*/=<>:&|]+\\_>"
3710 '(0 mdw-punct-face))))))
3713 (add-hook 'dylan-mode-hook 'mdw-misc-mode-config t)
3714 (add-hook 'dylan-mode-hook 'mdw-fontify-dylan t))
3716 ;;;--------------------------------------------------------------------------
3717 ;;; Algol 68 configuration.
3719 (setq-default a68-indent-step 2)
3721 (defun mdw-fontify-algol-68 ()
3723 ;; Fix up the syntax table.
3724 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
3725 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
3726 (modify-syntax-entry ch "." a68-mode-syntax-table))
3728 (make-local-variable 'font-lock-keywords)
3731 (let ((word "COMMENT"))
3732 (do ((regexp (concat "[^" (substring word 0 1) "]+")
3733 (concat regexp "\\|"
3734 (substring word 0 i)
3735 "[^" (substring word i (1+ i)) "]"))
3737 ((>= i (length word)) regexp)))))
3738 (setq font-lock-keywords
3739 (list (list (concat "\\<COMMENT\\>"
3740 "\\(" not-comment "\\)\\{0,5\\}"
3741 "\\(\\'\\|\\<COMMENT\\>\\)")
3742 '(0 font-lock-comment-face))
3743 (list (concat "\\<CO\\>"
3744 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
3745 "\\($\\|\\<CO\\>\\)")
3746 '(0 font-lock-comment-face))
3747 (list "\\<[A-Z_]+\\>"
3748 '(0 font-lock-keyword-face))
3752 "\\([eE][-+]?[0-9]+\\)?"
3754 '(0 mdw-number-face))
3755 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
3756 '(0 mdw-punct-face))))))
3758 (dolist (hook '(a68-mode-hook a68-mode-hooks))
3759 (add-hook hook 'mdw-misc-mode-config t)
3760 (add-hook hook 'mdw-fontify-algol-68 t))
3762 ;;;--------------------------------------------------------------------------
3763 ;;; REXX configuration.
3765 (defun mdw-rexx-electric-* ()
3770 (defun mdw-rexx-indent-newline-indent ()
3773 (if abbrev-mode (expand-abbrev))
3774 (newline-and-indent))
3776 (defun mdw-fontify-rexx ()
3778 ;; Various bits of fiddling.
3779 (setq mdw-auto-indent nil)
3780 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
3781 (local-set-key [?*] 'mdw-rexx-electric-*)
3782 (dolist (ch '(?! ?? ?# ?@ ?$)) (modify-syntax-entry ch "w"))
3783 (dolist (ch '(?¬)) (modify-syntax-entry ch "."))
3784 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
3786 ;; Set up keywords and things for fontification.
3787 (make-local-variable 'font-lock-keywords-case-fold-search)
3788 (setq font-lock-keywords-case-fold-search t)
3790 (setq rexx-indent 2)
3791 (setq rexx-end-indent rexx-indent)
3792 (setq rexx-cont-indent rexx-indent)
3794 (make-local-variable 'font-lock-keywords)
3795 (let ((rexx-keywords
3796 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
3797 "else" "end" "engineering" "exit" "expose" "for"
3798 "forever" "form" "fuzz" "if" "interpret" "iterate"
3799 "leave" "linein" "name" "nop" "numeric" "off" "on"
3800 "options" "otherwise" "parse" "procedure" "pull"
3801 "push" "queue" "return" "say" "select" "signal"
3802 "scientific" "source" "then" "trace" "to" "until"
3803 "upper" "value" "var" "version" "when" "while"
3806 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
3807 "center" "center" "charin" "charout" "chars"
3808 "compare" "condition" "copies" "c2d" "c2x"
3809 "datatype" "date" "delstr" "delword" "d2c" "d2x"
3810 "errortext" "format" "fuzz" "insert" "lastpos"
3811 "left" "length" "lineout" "lines" "max" "min"
3812 "overlay" "pos" "queued" "random" "reverse" "right"
3813 "sign" "sourceline" "space" "stream" "strip"
3814 "substr" "subword" "symbol" "time" "translate"
3815 "trunc" "value" "verify" "word" "wordindex"
3816 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
3819 (setq font-lock-keywords
3822 ;; Set up the keywords defined above.
3823 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
3824 '(0 font-lock-keyword-face))
3826 ;; Fontify all symbols the same way.
3827 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
3828 "[A-Za-z0-9.!?_#@$]+\\)")
3829 '(0 font-lock-variable-name-face))
3831 ;; And everything else is punctuation.
3832 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3833 '(0 mdw-punct-face))))))
3836 (add-hook 'rexx-mode-hook 'mdw-misc-mode-config t)
3837 (add-hook 'rexx-mode-hook 'mdw-fontify-rexx t))
3839 ;;;--------------------------------------------------------------------------
3840 ;;; Standard ML programming style.
3842 (setq-default sml-nested-if-indent t
3845 sml-type-of-indent nil)
3847 (defun mdw-fontify-sml ()
3849 ;; Make underscore an honorary letter.
3850 (modify-syntax-entry ?' "w")
3853 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
3855 ;; Now define fontification things.
3856 (make-local-variable 'font-lock-keywords)
3858 (mdw-regexps "abstype" "and" "andalso" "as"
3861 "else" "end" "eqtype" "exception"
3862 "fn" "fun" "functor"
3864 "if" "in" "include" "infix" "infixr"
3867 "of" "op" "open" "orelse"
3869 "sharing" "sig" "signature" "struct" "structure"
3872 "where" "while" "with" "withtype")))
3874 (setq font-lock-keywords
3877 ;; Set up the keywords defined above.
3878 (list (concat "\\<\\(" sml-keywords "\\)\\>")
3879 '(0 font-lock-keyword-face))
3881 ;; At least numbers are simpler than C.
3882 (list (concat "\\<\\~?"
3883 "\\(0\\([wW]?[xX][0-9a-fA-F]+\\|"
3885 "\\([0-9]+\\(\\.[0-9]+\\)?"
3888 '(0 mdw-number-face))
3890 ;; And anything else is punctuation.
3891 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3892 '(0 mdw-punct-face))))))
3895 (add-hook 'sml-mode-hook 'mdw-misc-mode-config t)
3896 (add-hook 'sml-mode-hook 'mdw-fontify-sml t))
3898 ;;;--------------------------------------------------------------------------
3899 ;;; Haskell configuration.
3901 (setq-default haskell-indent-offset 2)
3903 (defun mdw-fontify-haskell ()
3905 ;; Fiddle with syntax table to get comments right.
3906 (modify-syntax-entry ?' "_")
3907 (modify-syntax-entry ?- ". 12")
3908 (modify-syntax-entry ?\n ">")
3910 ;; Make punctuation be punctuation
3911 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
3913 ((>= i (length punct)))
3914 (modify-syntax-entry (aref punct i) ".")))
3917 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
3919 ;; Fiddle with fontification.
3920 (make-local-variable 'font-lock-keywords)
3921 (let ((haskell-keywords
3923 "case" "ccall" "class"
3924 "data" "default" "deriving" "do"
3928 "if" "import" "in" "infix" "infixl" "infixr" "instance"
3941 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
3942 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
3943 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
3944 "SP" "STX" "SUB" "SYN" "US" "VT")))
3946 (setq font-lock-keywords
3948 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
3952 '(0 font-lock-comment-face))
3953 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
3954 '(0 font-lock-keyword-face))
3955 (list (concat "'\\("
3959 "\\(" "[abfnrtv\\\"']" "\\|"
3960 "^" "\\(" control-sequences "\\|"
3961 "[]A-Z@[\\^_]" "\\)" "\\|"
3968 '(0 font-lock-string-face))
3969 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
3970 '(0 font-lock-variable-name-face))
3971 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
3972 "\\_<[0-9]+\\(\\.[0-9]*\\)?"
3973 "\\([eE][-+]?[0-9]+\\)?")
3974 '(0 mdw-number-face))
3975 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3976 '(0 mdw-punct-face))))))
3979 (add-hook 'haskell-mode-hook 'mdw-misc-mode-config t)
3980 (add-hook 'haskell-mode-hook 'mdw-fontify-haskell t))
3982 ;;;--------------------------------------------------------------------------
3983 ;;; Erlang configuration.
3985 (setq-default erlang-electric-commands nil)
3987 (defun mdw-fontify-erlang ()
3990 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
3992 ;; Fiddle with fontification.
3993 (make-local-variable 'font-lock-keywords)
3994 (let ((erlang-keywords
3995 (mdw-regexps "after" "and" "andalso"
3996 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
3997 "case" "catch" "cond"
3998 "div" "end" "fun" "if" "let" "not"
4000 "query" "receive" "rem" "try" "when" "xor")))
4002 (setq font-lock-keywords
4005 '(0 font-lock-comment-face))
4006 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
4007 '(0 font-lock-keyword-face))
4008 (list (concat "^-\\sw+\\>")
4009 '(0 font-lock-keyword-face))
4010 (list "\\<[0-9]+\\(#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)?\\>"
4011 '(0 mdw-number-face))
4012 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4013 '(0 mdw-punct-face))))))
4016 (add-hook 'erlang-mode-hook 'mdw-misc-mode-config t)
4017 (add-hook 'erlang-mode-hook 'mdw-fontify-erlang t))
4019 ;;;--------------------------------------------------------------------------
4020 ;;; Texinfo configuration.
4022 (defun mdw-fontify-texinfo ()
4025 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
4027 ;; Real fontification things.
4028 (make-local-variable 'font-lock-keywords)
4029 (setq font-lock-keywords
4032 ;; Environment names are keywords.
4033 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
4034 '(2 font-lock-keyword-face))
4036 ;; Unmark escaped magic characters.
4037 (list "\\(@\\)\\([@{}]\\)"
4038 '(1 font-lock-keyword-face)
4039 '(2 font-lock-variable-name-face))
4041 ;; Make sure we get comments properly.
4042 (list "@c\\(omment\\)?\\( .*\\)?$"
4043 '(0 font-lock-comment-face))
4045 ;; Command names are keywords.
4046 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
4047 '(0 font-lock-keyword-face))
4049 ;; Fontify TeX special characters as punctuation.
4051 '(0 mdw-punct-face)))))
4053 (dolist (hook '(texinfo-mode-hook TeXinfo-mode-hook))
4054 (add-hook hook 'mdw-misc-mode-config t)
4055 (add-hook hook 'mdw-fontify-texinfo t))
4057 ;;;--------------------------------------------------------------------------
4058 ;;; TeX and LaTeX configuration.
4060 (setq-default LaTeX-table-label "tbl:"
4061 TeX-auto-untabify nil
4062 LaTeX-syntactic-comments nil
4063 LaTeX-fill-break-at-separators '(\\\[))
4065 (defun mdw-fontify-tex ()
4066 (setq ispell-parser 'tex)
4069 ;; Don't make maths into a string.
4070 (modify-syntax-entry ?$ ".")
4071 (modify-syntax-entry ?$ "." font-lock-syntax-table)
4072 (local-set-key [?$] 'self-insert-command)
4074 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
4075 (local-set-key "\C-\M-i" 'indent-relative)
4076 (setq indent-tabs-mode nil)
4079 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
4081 ;; Real fontification things.
4082 (make-local-variable 'font-lock-keywords)
4083 (setq font-lock-keywords
4086 ;; Environment names are keywords.
4087 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
4089 '(2 font-lock-keyword-face))
4091 ;; Suspended environment names are keywords too.
4092 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
4094 '(3 font-lock-keyword-face))
4096 ;; Command names are keywords.
4097 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
4098 '(0 font-lock-keyword-face))
4100 ;; Handle @/.../ for italics.
4101 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
4102 ;; '(1 font-lock-keyword-face)
4103 ;; '(3 font-lock-keyword-face))
4105 ;; Handle @*...* for boldness.
4106 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
4107 ;; '(1 font-lock-keyword-face)
4108 ;; '(3 font-lock-keyword-face))
4110 ;; Handle @`...' for literal syntax things.
4111 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
4112 ;; '(1 font-lock-keyword-face)
4113 ;; '(3 font-lock-keyword-face))
4115 ;; Handle @<...> for nonterminals.
4116 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
4117 ;; '(1 font-lock-keyword-face)
4118 ;; '(3 font-lock-keyword-face))
4120 ;; Handle other @-commands.
4121 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
4122 ;; '(0 font-lock-keyword-face))
4124 ;; Make sure we get comments properly.
4126 '(0 font-lock-comment-face))
4128 ;; Fontify TeX special characters as punctuation.
4130 '(0 mdw-punct-face)))))
4132 (setq TeX-install-font-lock 'tex-font-setup)
4134 (eval-after-load 'font-latex
4135 '(defun font-latex-jit-lock-force-redisplay (buf start end)
4136 "Compatibility for Emacsen not offering `jit-lock-force-redisplay'."
4137 ;; The following block is an expansion of `jit-lock-force-redisplay'
4138 ;; and involved macros taken from CVS Emacs on 2007-04-28.
4139 (with-current-buffer buf
4140 (let ((modified (buffer-modified-p)))
4142 (let ((buffer-undo-list t)
4143 (inhibit-read-only t)
4144 (inhibit-point-motion-hooks t)
4145 (inhibit-modification-hooks t)
4148 buffer-file-truename)
4149 (put-text-property start end 'fontified t))
4151 (restore-buffer-modified-p nil)))))))
4153 (setq TeX-output-view-style
4155 ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$")
4156 "%(o?)dvips -t landscape %d -o && xdg-open %f")
4157 ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$"
4158 "%(o?)dvips %d -o && xdg-open %f")
4160 ("^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "^landscape$")
4161 "%(o?)xdvi %dS -paper a4r -s 0 %d")
4162 ("^dvi$" "^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$"
4163 "%(o?)xdvi %dS -paper a4 %d")
4165 ("^a5\\(?:comb\\|paper\\)$" "^landscape$")
4166 "%(o?)xdvi %dS -paper a5r -s 0 %d")
4167 ("^dvi$" "^a5\\(?:comb\\|paper\\)$" "%(o?)xdvi %dS -paper a5 %d")
4168 ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
4169 ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d")
4170 ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
4171 ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
4172 ("^dvi$" "." "%(o?)xdvi %dS %d")
4173 ("^pdf$" "." "xdg-open %o")
4174 ("^html?$" "." "sensible-browser %o")))
4176 (setq TeX-view-program-list
4177 '(("mupdf" ("mupdf %o" (mode-io-correlate " %(outpage)")))))
4179 (setq TeX-view-program-selection
4180 '(((output-dvi style-pstricks) "dvips and gv")
4182 (output-pdf "mupdf")
4183 (output-html "sensible-browser")))
4185 (setq TeX-open-quote "\""
4186 TeX-close-quote "\"")
4188 (setq reftex-use-external-file-finders t
4189 reftex-auto-recenter-toc t)
4191 (setq reftex-label-alist
4192 '(("theorem" ?T "th:" "~\\ref{%s}" t ("theorems?" "th\\.") -2)
4193 ("axiom" ?A "ax:" "~\\ref{%s}" t ("axioms?" "ax\\.") -2)
4194 ("definition" ?D "def:" "~\\ref{%s}" t ("definitions?" "def\\.") -2)
4195 ("proposition" ?P "prop:" "~\\ref{%s}" t
4196 ("propositions?" "prop\\.") -2)
4197 ("lemma" ?L "lem:" "~\\ref{%s}" t ("lemmas?" "lem\\.") -2)
4198 ("example" ?X "eg:" "~\\ref{%s}" t ("examples?") -2)
4199 ("exercise" ?E "ex:" "~\\ref{%s}" t ("exercises?" "ex\\.") -2)
4200 ("enumerate" ?i "i:" "~\\ref{%s}" item ("items?"))))
4201 (setq reftex-section-prefixes
4206 (setq bibtex-field-delimiters 'double-quotes
4207 bibtex-align-at-equal-sign t
4208 bibtex-entry-format '(realign opts-or-alts required-fields
4209 numerical-fields last-comma delimiters
4210 unify-case sort-fields braces)
4211 bibtex-sort-ignore-string-entries nil
4212 bibtex-maintain-sorted-entries 'entry-class
4213 bibtex-include-OPTkey t
4214 bibtex-autokey-names-stretch 1
4215 bibtex-autokey-expand-strings t
4216 bibtex-autokey-name-separator "-"
4217 bibtex-autokey-year-length 4
4218 bibtex-autokey-titleword-separator "-"
4219 bibtex-autokey-name-year-separator "-"
4220 bibtex-autokey-year-title-separator ":")
4223 (dolist (hook '(tex-mode-hook latex-mode-hook
4224 TeX-mode-hook LaTeX-mode-hook))
4225 (add-hook hook 'mdw-misc-mode-config t)
4226 (add-hook hook 'mdw-fontify-tex t))
4227 (add-hook 'bibtex-mode-hook (lambda () (setq fill-column 76))))
4229 ;;;--------------------------------------------------------------------------
4230 ;;; HTML, CSS, and other web foolishness.
4232 (setq-default css-indent-offset 2)
4234 ;;;--------------------------------------------------------------------------
4237 (setq-default psgml-html-build-new-buffer nil)
4239 (defun mdw-sgml-mode ()
4242 (mdw-standard-fill-prefix "")
4243 (make-local-variable 'sgml-delimiters)
4244 (setq sgml-delimiters
4245 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
4246 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT"
4247 "\"" "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]"
4248 "NESTC" "{" "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">"
4249 "PIO" "<?" "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" ","
4250 "STAGO" ":" "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
4251 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE"
4253 (setq major-mode 'mdw-sgml-mode)
4254 (setq mode-name "[mdw] SGML")
4255 (run-hooks 'mdw-sgml-mode-hook))
4257 ;;;--------------------------------------------------------------------------
4258 ;;; Configuration files.
4260 (defcustom mdw-conf-quote-normal nil
4261 "Control syntax category of quote characters `\"' and `''.
4262 If this is `t', consider quote characters to be normal
4263 punctuation, as for `conf-quote-normal'. If this is `nil' then
4264 leave quote characters as quotes. If this is a list, then
4265 consider the quote characters in the list to be normal
4266 punctuation. If this is a single quote character, then consider
4267 that character only to be normal punctuation."
4268 :type '(choice boolean character (repeat character))
4269 :safe 'mdw-conf-quote-normal-acceptable-value-p)
4270 (defun mdw-conf-quote-normal-acceptable-value-p (value)
4271 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
4272 (or (booleanp value)
4273 (every (lambda (v) (memq v '(?\" ?')))
4274 (if (listp value) value (list value)))))
4276 (defun mdw-fix-up-quote ()
4277 "Apply the setting of `mdw-conf-quote-normal'."
4278 (let ((flag mdw-conf-quote-normal))
4280 (conf-quote-normal t))
4284 (let ((table (copy-syntax-table (syntax-table))))
4285 (dolist (ch (if (listp flag) flag (list flag)))
4286 (modify-syntax-entry ch "." table))
4287 (set-syntax-table table)
4288 (and font-lock-mode (font-lock-fontify-buffer)))))))
4291 (add-hook 'conf-mode-hook 'mdw-misc-mode-config t)
4292 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t))
4294 ;;;--------------------------------------------------------------------------
4297 (defun mdw-setup-sh-script-mode ()
4299 ;; Fetch the shell interpreter's name.
4300 (let ((shell-name sh-shell-file))
4302 ;; Try reading the hash-bang line.
4304 (goto-char (point-min))
4305 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
4306 (setq shell-name (match-string 1))))
4308 ;; Now try to set the shell.
4310 ;; Don't let `sh-set-shell' bugger up my script.
4311 (let ((executable-set-magic #'(lambda (s &rest r) s)))
4312 (sh-set-shell shell-name)))
4314 ;; Don't insert here-document scaffolding automatically.
4315 (local-set-key "<" 'self-insert-command)
4317 ;; Now enable my keys and the fontification.
4318 (mdw-misc-mode-config)
4320 ;; Set the indentation level correctly.
4321 (setq sh-indentation 2)
4322 (setq sh-basic-offset 2))
4324 (setq sh-shell-file "/bin/sh")
4326 ;; Awful hacking to override the shell detection for particular scripts.
4327 (defmacro define-custom-shell-mode (name shell)
4330 (set (make-local-variable 'sh-shell-file) ,shell)
4332 (define-custom-shell-mode bash-mode "/bin/bash")
4333 (define-custom-shell-mode rc-mode "/usr/bin/rc")
4334 (put 'sh-shell-file 'permanent-local t)
4336 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
4337 (eval-after-load "sh-script"
4338 '(or (assq 'rc sh-mode-syntax-table-input)
4355 (assoc (assq 'rc sh-mode-syntax-table-input)))
4358 (setq sh-mode-syntax-table-input
4359 (cons (cons 'rc frag)
4360 sh-mode-syntax-table-input))))))
4363 (add-hook 'sh-mode-hook 'mdw-misc-mode-config t)
4364 (add-hook 'sh-mode-hook 'mdw-setup-sh-script-mode t))
4366 ;;;--------------------------------------------------------------------------
4367 ;;; Emacs shell mode.
4369 (defun mdw-eshell-prompt ()
4370 (let ((left "[") (right "]"))
4371 (when (= (user-uid) 0)
4372 (setq left "«" right "»"))
4375 (replace-regexp-in-string "\\..*$" "" (system-name)))
4377 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
4378 (home (expand-file-name "~")) (nhome (length home)))
4379 (if (and (>= npwd nhome)
4381 (= (elt pwd nhome) ?/))
4382 (string= (substring pwd 0 nhome) home))
4383 (concat "~" (substring pwd (length home)))
4386 (setq-default eshell-prompt-function 'mdw-eshell-prompt)
4387 (setq-default eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
4389 (defun eshell/e (file) (find-file file) nil)
4390 (defun eshell/ee (file) (find-file-other-window file) nil)
4391 (defun eshell/w3m (url) (w3m-goto-url url) nil)
4393 (mdw-define-face eshell-prompt (t :weight bold))
4394 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
4395 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
4396 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
4397 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
4398 (mdw-define-face eshell-ls-executable (t :weight bold))
4399 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
4400 (mdw-define-face eshell-ls-readonly (t nil))
4401 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
4403 (defun mdw-eshell-hack () (setenv "LD_PRELOAD" nil))
4404 (add-hook 'eshell-mode-hook 'mdw-eshell-hack)
4406 ;;;--------------------------------------------------------------------------
4407 ;;; Messages-file mode.
4409 (defun messages-mode-guts ()
4410 (setq messages-mode-syntax-table (make-syntax-table))
4411 (set-syntax-table messages-mode-syntax-table)
4412 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
4413 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
4414 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
4415 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
4416 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
4417 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
4418 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
4419 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
4420 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
4421 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
4422 (make-local-variable 'comment-start)
4423 (make-local-variable 'comment-end)
4424 (make-local-variable 'indent-line-function)
4425 (setq indent-line-function 'indent-relative)
4426 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4427 (make-local-variable 'font-lock-defaults)
4428 (make-local-variable 'messages-mode-keywords)
4430 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
4431 "export" "enum" "fixed-octetstring" "flags"
4432 "harmless" "map" "nested" "optional"
4433 "optional-tagged" "package" "primitive"
4434 "primitive-nullfree" "relaxed[ \t]+enum"
4435 "set" "table" "tagged-optional" "union"
4436 "variadic" "vector" "version" "version-tag")))
4437 (setq messages-mode-keywords
4439 (list (concat "\\<\\(" keywords "\\)\\>:")
4440 '(0 font-lock-keyword-face))
4441 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
4442 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
4443 (0 font-lock-variable-name-face))
4444 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
4445 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4446 (0 mdw-punct-face)))))
4447 (setq font-lock-defaults
4448 '(messages-mode-keywords nil nil nil nil))
4449 (run-hooks 'messages-file-hook))
4451 (defun messages-mode ()
4454 (setq major-mode 'messages-mode)
4455 (setq mode-name "Messages")
4456 (messages-mode-guts)
4457 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
4458 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
4459 (setq comment-start "# ")
4460 (setq comment-end "")
4461 (run-hooks 'messages-mode-hook))
4463 (defun cpp-messages-mode ()
4466 (setq major-mode 'cpp-messages-mode)
4467 (setq mode-name "CPP Messages")
4468 (messages-mode-guts)
4469 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
4470 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
4471 (setq comment-start "/* ")
4472 (setq comment-end " */")
4473 (let ((preprocessor-keywords
4474 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
4475 "ident" "if" "ifdef" "ifndef" "import" "include"
4476 "line" "pragma" "unassert" "undef" "warning")))
4477 (setq messages-mode-keywords
4478 (append (list (list (concat "^[ \t]*\\#[ \t]*"
4479 "\\(include\\|import\\)"
4480 "[ \t]*\\(<[^>]+\\(>\\)?\\)")
4481 '(2 font-lock-string-face))
4482 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
4483 preprocessor-keywords
4484 "\\)\\>\\|[0-9]+\\|$\\)\\)")
4485 '(1 font-lock-keyword-face)))
4486 messages-mode-keywords)))
4487 (run-hooks 'cpp-messages-mode-hook))
4490 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
4491 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
4492 ;; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
4495 ;;;--------------------------------------------------------------------------
4496 ;;; Messages-file mode.
4498 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
4499 "Face to use for subsittution directives.")
4500 (make-face 'mallow-driver-substitution-face)
4501 (defvar mallow-driver-text-face 'mallow-driver-text-face
4502 "Face to use for body text.")
4503 (make-face 'mallow-driver-text-face)
4505 (defun mallow-driver-mode ()
4508 (setq major-mode 'mallow-driver-mode)
4509 (setq mode-name "Mallow driver")
4510 (setq mallow-driver-mode-syntax-table (make-syntax-table))
4511 (set-syntax-table mallow-driver-mode-syntax-table)
4512 (make-local-variable 'comment-start)
4513 (make-local-variable 'comment-end)
4514 (make-local-variable 'indent-line-function)
4515 (setq indent-line-function 'indent-relative)
4516 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4517 (make-local-variable 'font-lock-defaults)
4518 (make-local-variable 'mallow-driver-mode-keywords)
4520 (mdw-regexps "each" "divert" "file" "if"
4521 "perl" "set" "string" "type" "write")))
4522 (setq mallow-driver-mode-keywords
4524 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
4525 '(0 font-lock-keyword-face))
4526 (list "^%\\s *\\(#.*\\)?$"
4527 '(0 font-lock-comment-face))
4529 '(0 font-lock-keyword-face))
4530 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
4532 '(0 mallow-driver-substitution-face t)))))
4533 (setq font-lock-defaults
4534 '(mallow-driver-mode-keywords nil nil nil nil))
4535 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
4536 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
4537 (setq comment-start "%# ")
4538 (setq comment-end "")
4539 (run-hooks 'mallow-driver-mode-hook))
4542 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t))
4544 ;;;--------------------------------------------------------------------------
4547 (defun nfast-debug-mode ()
4550 (setq major-mode 'nfast-debug-mode)
4551 (setq mode-name "NFast debug")
4552 (setq messages-mode-syntax-table (make-syntax-table))
4553 (set-syntax-table messages-mode-syntax-table)
4554 (make-local-variable 'font-lock-defaults)
4555 (make-local-variable 'nfast-debug-mode-keywords)
4556 (setq truncate-lines t)
4557 (setq nfast-debug-mode-keywords
4559 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
4560 (0 font-lock-keyword-face))
4561 (list (concat "^[ \t]+\\(\\("
4562 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4563 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4565 "[0-9a-fA-F]+\\)[ \t]*$")
4566 '(0 mdw-number-face))
4567 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
4568 (1 font-lock-keyword-face))
4569 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
4570 (1 font-lock-warning-face))
4571 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
4573 (list (concat "^[ \t]+\\.cmd=[ \t]+"
4574 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
4575 '(1 font-lock-keyword-face))
4576 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
4577 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
4578 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
4579 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
4580 (setq font-lock-defaults
4581 '(nfast-debug-mode-keywords nil nil nil nil))
4582 (run-hooks 'nfast-debug-mode-hook))
4584 ;;;--------------------------------------------------------------------------
4585 ;;; Lispy languages.
4587 ;; Unpleasant bodge.
4588 (unless (boundp 'slime-repl-mode-map)
4589 (setq slime-repl-mode-map (make-sparse-keymap)))
4591 (defun mdw-indent-newline-and-indent ()
4593 (indent-for-tab-command)
4594 (newline-and-indent))
4596 (eval-after-load "cl-indent"
4598 (mapc #'(lambda (pair)
4600 'common-lisp-indent-function
4602 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
4603 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
4605 (defun mdw-common-lisp-indent ()
4606 (make-local-variable 'lisp-indent-function)
4607 (setq lisp-indent-function 'common-lisp-indent-function))
4609 (defmacro mdw-advise-hyperspec-lookup (func args)
4610 `(defadvice ,func (around mdw-browse-w3m ,args activate compile)
4612 (let ((browse-url-browser-function #'mdw-w3m-browse-url))
4615 (mdw-advise-hyperspec-lookup common-lisp-hyperspec (symbol))
4616 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-format (char))
4617 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-lookup-reader-macro (char))
4619 (defun mdw-fontify-lispy ()
4622 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
4624 ;; Not much fontification needed.
4625 (make-local-variable 'font-lock-keywords)
4626 (setq font-lock-keywords
4627 (list (list (concat "\\("
4629 "\\(" "[0-9]+/[0-9]+"
4630 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
4632 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
4637 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
4638 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
4639 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
4640 "\\|" "[0-9]+" "r" "[-+]?"
4641 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
4644 '(0 mdw-number-face))
4645 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4646 '(0 mdw-punct-face)))))
4648 ;; Special indentation.
4650 (defcustom mdw-lisp-loop-default-indent 2
4651 "Default indent for simple `loop' body."
4654 (defcustom mdw-lisp-setf-value-indent 2
4655 "Default extra indent for `setf' values."
4656 :type 'integer :safe 'integerp)
4658 (setq lisp-simple-loop-indentation 0
4659 lisp-loop-keyword-indentation 0
4660 lisp-loop-forms-indentation 2
4661 lisp-lambda-list-keyword-parameter-alignment t)
4663 (defun mdw-indent-funcall
4664 (path state &optional indent-point sexp-column normal-indent)
4665 "Indent `funcall' more usefully.
4666 Essentially, treat `funcall foo' as a function name, and align the arguments
4668 (and (or (not (consp path)) (null (cadr path)))
4670 (goto-char (cadr state))
4672 (let ((start-line (line-number-at-pos)))
4673 (and (condition-case nil (progn (forward-sexp 3) t)
4677 (and (= start-line (line-number-at-pos))
4678 (current-column))))))))
4680 (put 'funcall 'common-lisp-indent-function 'mdw-indent-funcall)
4681 (put 'funcall 'lisp-indent-function 'mdw-indent-funcall))
4683 (defun mdw-indent-setf
4684 (path state &optional indent-point sexp-column normal-indent)
4685 "Indent `setf' more usefully.
4686 If the values aren't on the same lines as their variables then indent them
4687 by `mdw-lisp-setf-value-indent' spaces."
4688 (and (or (not (consp path)) (null (cadr path)))
4689 (let ((basic-indent (save-excursion
4690 (goto-char (cadr state))
4692 (and (condition-case nil
4693 (progn (forward-sexp 2) t)
4697 (current-column)))))
4698 (offset (if (consp path) (car path)
4703 (goto-char (cadr state))
4705 (while (< (point) start)
4706 (condition-case nil (forward-sexp 1)
4707 (scan-error (throw 'done nil)))
4710 (and basic-indent offset
4711 (list (+ basic-indent
4713 mdw-lisp-setf-value-indent))
4716 (put 'setf 'common-lisp-indent-functopion 'mdw-indent-setf)
4717 (put 'psetf 'common-lisp-indent-function 'mdw-indent-setf)
4718 (put 'setq 'common-lisp-indent-function 'mdw-indent-setf)
4719 (put 'setf 'lisp-indent-function 'mdw-indent-setf)
4720 (put 'setq 'lisp-indent-function 'mdw-indent-setf)
4721 (put 'setq-local 'lisp-indent-function 'mdw-indent-setf)
4722 (put 'setq-default 'lisp-indent-function 'mdw-indent-setf))
4724 (defadvice common-lisp-loop-part-indentation
4725 (around mdw-fix-loop-indentation (indent-point state) activate compile)
4726 "Improve `loop' indentation.
4727 If the first subform is on the same line as the `loop' keyword, then
4728 align the other subforms beneath it. Otherwise, indent them
4729 `mdw-lisp-loop-default-indent' columns in from the opening parenthesis."
4731 (let* ((loop-indentation (save-excursion
4732 (goto-char (elt state 1))
4735 ;; Don't really care about this.
4736 (when (and (boundp 'lisp-indent-backquote-substitution-mode)
4737 (eq lisp-indent-backquote-substitution-mode 'corrected))
4739 (goto-char (elt state 1))
4740 (cl-incf loop-indentation
4741 (cond ((eq (char-before) ?,) -1)
4742 ((and (eq (char-before) ?@)
4743 (progn (backward-char)
4744 (eq (char-before) ?,)))
4748 ;; If the first loop item is on the same line as the `loop' itself then
4749 ;; use that as the baseline. Otherwise advance by the default indent.
4750 (goto-char (cadr state))
4752 (let ((baseline-indent
4753 (if (= (line-number-at-pos)
4754 (if (condition-case nil (progn (forward-sexp 2) t)
4756 (progn (forward-sexp -1) (line-number-at-pos))
4759 (+ loop-indentation mdw-lisp-loop-default-indent))))
4761 (goto-char indent-point)
4764 (setq ad-return-value
4766 (cond ((condition-case ()
4768 (goto-char (elt state 1))
4772 (not (looking-at "\\(:\\|\\sw\\)")))
4774 (+ baseline-indent lisp-simple-loop-indentation))
4775 ((looking-at "^\\s-*\\(:?\\sw+\\|;\\)")
4776 (+ baseline-indent lisp-loop-keyword-indentation))
4778 (+ baseline-indent lisp-loop-forms-indentation)))
4780 ;; Tell the caller that the next line needs recomputation,
4781 ;; even though it doesn't start a sexp.
4782 loop-indentation)))))
4786 (defcustom mdw-friendly-name "[mdw]"
4787 "How I want to be addressed."
4790 (defadvice slime-user-first-name
4791 (around mdw-use-friendly-name compile activate)
4792 (if mdw-friendly-name (setq ad-return-value mdw-friendly-name)
4796 (if (not mdw-fast-startup)
4798 (require 'slime-autoloads)
4799 (slime-setup '(slime-autodoc slime-c-p-c)))))
4801 (let ((stuff '((cmucl ("cmucl"))
4802 (sbcl ("sbcl") :coding-system utf-8-unix)
4803 (clisp ("clisp") :coding-system utf-8-unix))))
4804 (or (boundp 'slime-lisp-implementations)
4805 (setq slime-lisp-implementations nil))
4807 (let* ((head (car stuff))
4808 (found (assq (car head) slime-lisp-implementations)))
4809 (setq stuff (cdr stuff))
4811 (rplacd found (cdr head))
4812 (setq slime-lisp-implementations
4813 (cons head slime-lisp-implementations))))))
4814 (setq slime-default-lisp 'sbcl)
4819 (dolist (hook '(emacs-lisp-mode-hook
4822 inferior-lisp-mode-hook
4823 lisp-interaction-mode-hook
4825 slime-repl-mode-hook))
4826 (add-hook hook 'mdw-misc-mode-config t)
4827 (add-hook hook 'mdw-fontify-lispy t))
4828 (add-hook 'lisp-mode-hook 'mdw-common-lisp-indent t)
4829 (add-hook 'inferior-lisp-mode-hook
4830 #'(lambda () (local-set-key "\C-m" 'comint-send-and-indent)) t))
4832 ;;;--------------------------------------------------------------------------
4833 ;;; Other languages.
4837 (defun mdw-setup-smalltalk ()
4838 (and mdw-auto-indent
4839 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
4840 (make-local-variable 'mdw-auto-indent)
4841 (setq mdw-auto-indent nil)
4842 (local-set-key "\C-i" 'smalltalk-reindent))
4844 (defun mdw-fontify-smalltalk ()
4845 (make-local-variable 'font-lock-keywords)
4846 (setq font-lock-keywords
4848 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
4849 '(0 font-lock-keyword-face))
4850 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
4851 "[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
4852 "\\([eE][-+]?[0-9_]+\\)?")
4853 '(0 mdw-number-face))
4854 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4855 '(0 mdw-punct-face)))))
4858 (add-hook 'smalltalk-mode 'mdw-misc-mode-config t)
4859 (add-hook 'smalltalk-mode 'mdw-fontify-smalltalk t))
4863 (defun mdw-setup-m4 ()
4865 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
4866 ;; annoying: fix it.
4867 (modify-syntax-entry ?{ "(")
4868 (modify-syntax-entry ?} ")")
4871 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
4873 (dolist (hook '(m4-mode-hook autoconf-mode-hook autotest-mode-hook))
4874 (add-hook hook #'mdw-misc-mode-config t)
4875 (add-hook hook #'mdw-setup-m4 t))
4880 (add-hook 'makefile-mode-hook 'mdw-misc-mode-config t))
4882 ;;;--------------------------------------------------------------------------
4885 (defun mdw-text-mode ()
4886 (setq fill-column 72)
4888 (mdw-standard-fill-prefix
4889 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
4892 (eval-after-load "flyspell"
4893 '(define-key flyspell-mode-map "\C-\M-i" nil))
4896 (add-hook 'text-mode-hook 'mdw-text-mode t))
4898 ;;;--------------------------------------------------------------------------
4899 ;;; Outline and hide/show modes.
4901 (defun mdw-outline-collapse-all ()
4902 "Completely collapse everything in the entire buffer."
4905 (goto-char (point-min))
4906 (while (< (point) (point-max))
4910 (setq hs-hide-comments-when-hiding-all nil)
4912 (defadvice hs-hide-all (after hide-first-comment activate)
4913 (save-excursion (hs-hide-initial-comment-block)))
4915 ;;;--------------------------------------------------------------------------
4918 (defun mdw-sh-mode-setup ()
4919 (local-set-key [?\C-a] 'comint-bol)
4920 (add-hook 'comint-output-filter-functions
4921 'comint-watch-for-password-prompt))
4923 (defun mdw-term-mode-setup ()
4924 (setq term-prompt-regexp shell-prompt-pattern)
4925 (make-local-variable 'mouse-yank-at-point)
4926 (make-local-variable 'transient-mark-mode)
4927 (setq mouse-yank-at-point t)
4931 (defun comint-send-and-indent ()
4934 (and mdw-auto-indent
4935 (indent-for-tab-command)))
4937 (defadvice comint-line-beginning-position
4938 (around mdw-calculate-it-properly () activate compile)
4939 "Calculate the actual line start for multi-line input."
4940 (if (or comint-use-prompt-regexp
4941 (eq (field-at-pos (point)) 'output))
4943 (setq ad-return-value
4944 (constrain-to-field (line-beginning-position) (point)))))
4946 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
4947 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
4948 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
4949 (defun term-send-meta-meta-something ()
4951 (term-send-raw-string "\e\e")
4953 (eval-after-load 'term
4955 (define-key term-raw-map [?\e ?\e] nil)
4956 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
4957 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
4958 (define-key term-raw-map [M-right] 'term-send-meta-right)
4959 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
4960 (define-key term-raw-map [M-left] 'term-send-meta-left)
4961 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
4963 (defadvice term-exec (before program-args-list compile activate)
4964 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
4965 This allows you to pass a list of arguments through `ansi-term'."
4966 (let ((program (ad-get-arg 2)))
4969 (ad-set-arg 2 (car program))
4970 (ad-set-arg 4 (cdr program))))))
4972 (defadvice term-exec-1 (around hack-environment compile activate)
4973 "Hack the environment inherited by inferiors in the terminal."
4974 (let ((process-environment (copy-tree process-environment)))
4975 (setenv "LD_PRELOAD" nil)
4978 (defadvice shell (around hack-environment compile activate)
4979 "Hack the environment inherited by inferiors in the shell."
4980 (let ((process-environment (copy-tree process-environment)))
4981 (setenv "LD_PRELOAD" nil)
4985 "Open a terminal containing an ssh session to the HOST."
4986 (interactive "sHost: ")
4987 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
4989 (defcustom git-grep-command
4990 "env GIT_PAGER=cat git grep --no-color -nH -e "
4991 "The default command for \\[git-grep]."
4994 (defvar git-grep-history nil)
4996 (defun git-grep (command-args)
4997 "Run `git grep' with user-specified args and collect output in a buffer."
4999 (list (read-shell-command "Run git grep (like this): "
5000 git-grep-command 'git-grep-history)))
5001 (let ((grep-use-null-device nil))
5002 (grep command-args)))
5004 ;;;--------------------------------------------------------------------------
5005 ;;; Magit configuration.
5007 (setq magit-diff-refine-hunk 't
5008 magit-view-git-manual-method 'man
5009 magit-log-margin '(nil age magit-log-margin-width t 18)
5010 magit-wip-after-save-local-mode-lighter ""
5011 magit-wip-after-apply-mode-lighter ""
5012 magit-wip-before-change-mode-lighter "")
5013 (eval-after-load "magit"
5014 '(progn (global-magit-file-mode 1)
5015 (magit-wip-after-save-mode 1)
5016 (magit-wip-after-apply-mode 1)
5017 (magit-wip-before-change-mode 1)
5018 (add-to-list 'magit-no-confirm 'safe-with-wip)
5019 (add-to-list 'magit-no-confirm 'trash)
5020 (push '(:eval (if (or magit-wip-after-save-local-mode
5021 magit-wip-after-apply-mode
5022 magit-wip-before-change-mode)
5023 (format " wip:%s%s%s"
5024 (if magit-wip-after-apply-mode "A" "")
5025 (if magit-wip-before-change-mode "C" "")
5026 (if magit-wip-after-save-local-mode "S" ""))))
5028 (dolist (popup '(magit-diff-popup
5029 magit-diff-refresh-popup
5030 magit-diff-mode-refresh-popup
5031 magit-revision-mode-refresh-popup))
5032 (magit-define-popup-switch popup ?R "Reverse diff" "-R"))
5033 (magit-define-popup-switch 'magit-rebase-popup ?r
5034 "Rebase merges" "--rebase-merges")))
5036 (defadvice magit-wip-commit-buffer-file
5037 (around mdw-just-this-buffer activate compile)
5038 (let ((magit-save-repository-buffers nil)) ad-do-it))
5040 (defadvice magit-discard
5041 (around mdw-delete-if-prefix-argument activate compile)
5042 (let ((magit-delete-by-moving-to-trash
5043 (and (null current-prefix-arg)
5044 magit-delete-by-moving-to-trash)))
5047 (setq magit-repolist-columns
5048 '(("Name" 16 magit-repolist-column-ident nil)
5049 ("Version" 18 magit-repolist-column-version nil)
5050 ("St" 2 magit-repolist-column-dirty nil)
5051 ("L<U" 3 mdw-repolist-column-unpulled-from-upstream nil)
5052 ("L>U" 3 mdw-repolist-column-unpushed-to-upstream nil)
5053 ("Path" 32 magit-repolist-column-path nil)))
5055 (setq magit-repository-directories '(("~/etc/profile" . 0)
5058 (defadvice magit-list-repos (around mdw-dirname () activate compile)
5059 "Make sure the returned names are directory names.
5060 Otherwise child processes get started in the wrong directory and
5062 (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it)))
5064 (defun mdw-repolist-column-unpulled-from-upstream (_id)
5065 "Insert number of upstream commits not in the current branch."
5066 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
5068 (let ((n (cadr (magit-rev-diff-count "HEAD" upstream))))
5069 (propertize (number-to-string n) 'face
5070 (if (> n 0) 'bold 'shadow))))))
5072 (defun mdw-repolist-column-unpushed-to-upstream (_id)
5073 "Insert number of commits in the current branch but not its upstream."
5074 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
5076 (let ((n (car (magit-rev-diff-count "HEAD" upstream))))
5077 (propertize (number-to-string n) 'face
5078 (if (> n 0) 'bold 'shadow))))))
5080 (defun mdw-try-smerge ()
5082 (goto-char (point-min))
5083 (when (re-search-forward "^<<<<<<< " nil t)
5085 (add-hook 'find-file-hook 'mdw-try-smerge t)
5087 ;;;--------------------------------------------------------------------------
5088 ;;; GUD, and especially GDB.
5090 ;; Inhibit window dedication. I mean, seriously, wtf?
5091 (defadvice gdb-display-buffer (after mdw-undedicated (buf) compile activate)
5092 "Don't make windows dedicated. Seriously."
5093 (set-window-dedicated-p ad-return-value nil))
5094 (defadvice gdb-set-window-buffer
5095 (after mdw-undedicated (name &optional ignore-dedicated window)
5097 "Don't make windows dedicated. Seriously."
5098 (set-window-dedicated-p (or window (selected-window)) nil))
5100 ;;;--------------------------------------------------------------------------
5103 ;; Turn off `noip' when running `man': it interferes with `man-db''s own
5104 ;; seccomp(2)-based sandboxing, which is (in this case, at least) strictly
5106 (defadvice Man-getpage-in-background
5107 (around mdw-inhibit-noip (topic) compile activate)
5108 "Inhibit the `noip' preload hack when invoking `man'."
5109 (let* ((old-preload (getenv "LD_PRELOAD"))
5110 (preloads (and old-preload
5111 (save-match-data (split-string old-preload ":"))))
5116 (let ((item (pop preloads)))
5117 (if (string-match "\\(/\\|^\\)noip\.so\\(:\\|$\\)" item)
5119 (push item filtered)))))
5123 (setenv "LD_PRELOAD"
5125 (with-output-to-string
5126 (setq filtered (nreverse filtered))
5129 (if first (setq first nil)
5131 (write-string (pop filtered)))))))
5133 (setenv "LD_PRELOAD" old-preload))
5136 ;;;--------------------------------------------------------------------------
5137 ;;; MPC configuration.
5139 (eval-when-compile (trap (require 'mpc)))
5141 (setq mpc-browser-tags '(Artist|Composer|Performer Album|Playlist))
5143 (defun mdw-mpc-now-playing ()
5147 (set-buffer (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))))
5148 (mpc--status-callback))
5149 (let ((state (cdr (assq 'state mpc-status))))
5150 (cond ((member state '("stop"))
5151 (message "mpd stopped."))
5152 ((member state '("play" "pause"))
5153 (let* ((artist (cdr (assq 'Artist mpc-status)))
5154 (album (cdr (assq 'Album mpc-status)))
5155 (title (cdr (assq 'Title mpc-status)))
5156 (file (cdr (assq 'file mpc-status)))
5157 (duration-string (cdr (assq 'Time mpc-status)))
5158 (time-string (cdr (assq 'time mpc-status)))
5159 (time (and time-string
5161 (if (string-match ":" time-string)
5162 (substring time-string
5163 0 (match-beginning 0))
5165 (duration (and duration-string
5166 (string-to-number duration-string)))
5167 (pos (and time duration
5168 (format " [%d:%02d/%d:%02d]"
5169 (/ time 60) (mod time 60)
5170 (/ duration 60) (mod duration 60))))
5171 (fmt (cond ((and artist title)
5172 (format "`%s' by %s%s" title artist
5173 (if album (format ", from `%s'" album)
5176 (format "`%s' (no tags)" file))
5178 "(no idea what's playing!)"))))
5179 (if (string= state "play")
5180 (message "mpd playing %s%s" fmt (or pos ""))
5181 (message "mpd paused in %s%s" fmt (or pos "")))))
5183 (message "mpd in unknown state `%s'" state)))))
5185 (defmacro mdw-define-mpc-wrapper (func bvl interactive &rest body)
5187 (interactive ,@interactive)
5190 (mdw-mpc-now-playing)))
5192 (mdw-define-mpc-wrapper mdw-mpc-play-or-pause () nil
5193 (if (member (cdr (assq 'state (mpc-cmd-status))) '("play"))
5197 (mdw-define-mpc-wrapper mdw-mpc-next () nil (mpc-next))
5198 (mdw-define-mpc-wrapper mdw-mpc-prev () nil (mpc-prev))
5199 (mdw-define-mpc-wrapper mdw-mpc-stop () nil (mpc-stop))
5201 (defun mdw-mpc-louder (step)
5202 (interactive (list (if current-prefix-arg
5203 (prefix-numeric-value current-prefix-arg)
5205 (mpc-proc-cmd (format "volume %+d" step)))
5207 (defun mdw-mpc-quieter (step)
5208 (interactive (list (if current-prefix-arg
5209 (prefix-numeric-value current-prefix-arg)
5211 (mpc-proc-cmd (format "volume %+d" (- step))))
5213 (defun mdw-mpc-hack-lines (arg interactivep func)
5214 (if (and interactivep (use-region-p))
5215 (let ((from (region-beginning)) (to (region-end)))
5220 (while (< (point) to)
5223 (let ((n (prefix-numeric-value arg)))
5240 (defun mdw-mpc-select-one ()
5241 (when (and (get-char-property (point) 'mpc-file)
5242 (not (get-char-property (point) 'mpc-select)))
5243 (mpc-select-toggle)))
5245 (defun mdw-mpc-unselect-one ()
5246 (when (get-char-property (point) 'mpc-select)
5247 (mpc-select-toggle)))
5249 (defun mdw-mpc-select (&optional arg interactivep)
5250 (interactive (list current-prefix-arg t))
5251 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
5253 (defun mdw-mpc-unselect (&optional arg interactivep)
5254 (interactive (list current-prefix-arg t))
5255 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one))
5257 (defun mdw-mpc-unselect-backwards (arg)
5259 (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one))
5261 (defun mdw-mpc-unselect-all ()
5263 (setq mpc-select nil)
5264 (mpc-selection-refresh))
5266 (defun mdw-mpc-next-line (arg)
5271 (defun mdw-mpc-previous-line (arg)
5274 (forward-line (- arg)))
5276 (defun mdw-mpc-playlist-add (&optional arg interactivep)
5277 (interactive (list current-prefix-arg t))
5278 (let ((mpc-select mpc-select))
5279 (when (or arg (and interactivep (use-region-p)))
5280 (setq mpc-select nil)
5281 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
5282 (setq mpc-select (reverse mpc-select))
5283 (mpc-playlist-add)))
5285 (defun mdw-mpc-playlist-delete (&optional arg interactivep)
5286 (interactive (list current-prefix-arg t))
5287 (setq mpc-select (nreverse mpc-select))
5289 (when (or arg (and interactivep (use-region-p)))
5290 (setq mpc-select nil)
5291 (mpc-selection-refresh)
5292 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
5293 (mpc-playlist-delete)))
5295 (defun mdw-mpc-hack-tagbrowsers ()
5296 (setq-local mode-line-format
5298 mode-line-frame-identification
5299 mode-line-buffer-identification)))
5300 (add-hook 'mpc-tagbrowser-mode-hook 'mdw-mpc-hack-tagbrowsers)
5302 (defun mdw-mpc-hack-songs ()
5303 (setq-local header-line-format
5304 ;; '("MPC " mpc-volume " " mpc-current-song)
5305 (list (propertize " " 'display '(space :align-to 0))
5306 ;; 'mpc-songs-format-description
5308 (let ((deactivate-mark) (hscroll (window-hscroll)))
5310 (mpc-format mpc-songs-format 'self hscroll)
5311 ;; That would be simpler than the hscroll handling in
5312 ;; mpc-format, but currently move-to-column does not
5313 ;; recognize :space display properties.
5314 ;; (move-to-column hscroll)
5315 ;; (delete-region (point-min) (point))
5316 (buffer-string)))))))
5317 (add-hook 'mpc-songs-mode-hook 'mdw-mpc-hack-songs)
5319 (eval-after-load "mpc"
5321 (define-key mpc-mode-map "m" 'mdw-mpc-select)
5322 (define-key mpc-mode-map "u" 'mdw-mpc-unselect)
5323 (define-key mpc-mode-map "\177" 'mdw-mpc-unselect-backwards)
5324 (define-key mpc-mode-map "\e\177" 'mdw-mpc-unselect-all)
5325 (define-key mpc-mode-map "n" 'mdw-mpc-next-line)
5326 (define-key mpc-mode-map "p" 'mdw-mpc-previous-line)
5327 (define-key mpc-mode-map "/" 'mpc-songs-search)
5328 (setq mpc-songs-mode-map (make-sparse-keymap))
5329 (set-keymap-parent mpc-songs-mode-map mpc-mode-map)
5330 (define-key mpc-songs-mode-map "l" 'mpc-playlist)
5331 (define-key mpc-songs-mode-map "+" 'mdw-mpc-playlist-add)
5332 (define-key mpc-songs-mode-map "-" 'mdw-mpc-playlist-delete)
5333 (define-key mpc-songs-mode-map "\r" 'mpc-songs-jump-to)))
5335 ;;;--------------------------------------------------------------------------
5336 ;;; Inferior Emacs Lisp.
5338 (setq comint-prompt-read-only t)
5340 (eval-after-load "comint"
5342 (define-key comint-mode-map "\C-w" 'comint-kill-region)
5343 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
5345 (eval-after-load "ielm"
5347 (define-key ielm-map "\C-w" 'comint-kill-region)
5348 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
5350 ;;;----- That's all, folks --------------------------------------------------
5352 (provide 'dot-emacs)