1 ;;; -*- mode: emacs-lisp; coding: utf-8 -*-
3 ;;; Functions and macros for .emacs
5 ;;; (c) 2004 Mark Wooding
8 ;;;----- Licensing notice ---------------------------------------------------
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 2 of the License, or
13 ;;; (at your option) any later version.
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;;; GNU General Public License for more details.
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software Foundation,
22 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 ;;;--------------------------------------------------------------------------
25 ;;; Check command-line.
27 (defun mdw-check-command-line-switch (switch)
28 (let ((probe nil) (next command-line-args) (found nil))
30 (cond ((string= (car next) switch)
32 (if probe (rplacd probe (cdr next))
33 (setq command-line-args (cdr next))))
36 (setq next (cdr next)))
39 (defvar mdw-fast-startup nil
40 "Whether .emacs should optimize for rapid startup.
41 This may be at the expense of cool features.")
42 (setq mdw-fast-startup
43 (mdw-check-command-line-switch "--mdw-fast-startup"))
45 (defvar mdw-splashy-startup nil
46 "Whether to show a splash screen and related frippery.")
47 (setq mdw-splashy-startup
48 (mdw-check-command-line-switch "--mdw-splashy-startup"))
50 ;;;--------------------------------------------------------------------------
51 ;;; Some general utilities.
54 (unless (fboundp 'make-regexp)
58 (defmacro mdw-regexps (&rest list)
59 "Turn a LIST of strings into a single regular expression at compile-time."
62 `',(make-regexp list))
65 "This is not the key sequence you're looking for."
67 (error "wrong button"))
69 (defun mdw-emacs-version-p (major &optional minor)
70 "Return non-nil if the running Emacs is at least version MAJOR.MINOR."
71 (or (> emacs-major-version major)
72 (and (= emacs-major-version major)
73 (>= emacs-minor-version (or minor 0)))))
75 ;; Some error trapping.
77 ;; If individual bits of this file go tits-up, we don't particularly want
78 ;; the whole lot to stop right there and then, because it's bloody annoying.
80 (defmacro trap (&rest forms)
81 "Execute FORMS without allowing errors to propagate outside."
85 ,(if (cdr forms) (cons 'progn forms) (car forms))
86 (error (message "Error (trapped): %s in %s"
87 (error-message-string err)
90 ;; Configuration reading.
92 (defvar mdw-config nil)
93 (defun mdw-config (sym)
94 "Read the configuration variable named SYM."
97 (flet ((replace (what with)
98 (goto-char (point-min))
99 (while (re-search-forward what nil t)
100 (replace-match with t))))
102 (insert-file-contents "~/.mdw.conf")
103 (replace "^[ \t]*\\(#.*\\)?\n" "")
104 (replace (concat "^[ \t]*"
105 "\\([-a-zA-Z0-9_.]*\\)"
108 "[ \t]**\\(\n\\|$\\)")
110 (car (read-from-string
111 (concat "(" (buffer-string) ")")))))))
112 (cdr (assq sym mdw-config)))
114 ;; Width configuration.
116 (defvar mdw-column-width
117 (string-to-number (or (mdw-config 'emacs-width) "77"))
118 "Width of Emacs columns.")
119 (defvar mdw-text-width mdw-column-width
120 "Expected width of text within columns.")
121 (put 'mdw-text-width 'safe-local-variable 'integerp)
123 ;; Local variables hacking.
125 (defun run-local-vars-mode-hook ()
126 "Run a hook for the major-mode after local variables have been processed."
127 (run-hooks (intern (concat (symbol-name major-mode)
128 "-local-variables-hook"))))
129 (add-hook 'hack-local-variables-hook 'run-local-vars-mode-hook)
131 ;; Set up the load path convincingly.
133 (dolist (dir (append (and (boundp 'debian-emacs-flavor)
134 (list (concat "/usr/share/"
135 (symbol-name debian-emacs-flavor)
137 (dolist (sub (directory-files dir t))
138 (when (and (file-accessible-directory-p sub)
139 (not (member sub load-path)))
140 (setq load-path (nconc load-path (list sub))))))
142 ;; Is an Emacs library available?
144 (defun library-exists-p (name)
145 "Return non-nil if NAME is an available library.
146 Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
147 load path. The non-nil value is the filename we found for the
149 (let ((path load-path) elt (foundp nil))
150 (while (and path (not foundp))
151 (setq elt (car path))
152 (setq path (cdr path))
153 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
154 (and (file-exists-p file) file))
155 (let ((file (concat elt "/" name ".el")))
156 (and (file-exists-p file) file)))))
159 (defun maybe-autoload (symbol file &optional docstring interactivep type)
160 "Set an autoload if the file actually exists."
161 (and (library-exists-p file)
162 (autoload symbol file docstring interactivep type)))
164 (defun mdw-kick-menu-bar (&optional frame)
165 "Regenerate FRAME's menu bar so it doesn't have empty menus."
167 (unless frame (setq frame (selected-frame)))
168 (let ((old (frame-parameter frame 'menu-bar-lines)))
169 (set-frame-parameter frame 'menu-bar-lines 0)
170 (set-frame-parameter frame 'menu-bar-lines old)))
174 (defun mdw-fixup-page-position ()
175 (unless (eq (char-before (point)) ?
\f)
178 (defadvice backward-page (after mdw-fixup compile activate)
179 (mdw-fixup-page-position))
180 (defadvice forward-page (after mdw-fixup compile activate)
181 (mdw-fixup-page-position))
183 ;; Splitting windows.
185 (unless (fboundp 'scroll-bar-columns)
186 (defun scroll-bar-columns (side)
187 (cond ((eq side 'left) 0)
190 (unless (fboundp 'fringe-columns)
191 (defun fringe-columns (side)
192 (cond ((not window-system) 0)
196 (defun mdw-horizontal-window-overhead ()
197 "Computes the horizontal window overhead.
198 This is the number of columns used by fringes, scroll bars and other such
200 (if (not window-system)
203 (dolist (what '(scroll-bar fringe))
204 (dolist (side '(left right))
205 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
209 (defun mdw-split-window-horizontally (&optional width)
210 "Split a window horizontally.
211 Without a numeric argument, split the window approximately in
212 half. With a numeric argument WIDTH, allocate WIDTH columns to
213 the left-hand window (if positive) or -WIDTH columns to the
214 right-hand window (if negative). Space for scroll bars and
215 fringes is not taken out of the allowance for WIDTH, unlike
216 \\[split-window-horizontally]."
218 (split-window-horizontally
219 (cond ((null width) nil)
220 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
221 ((< width 0) width))))
223 (defun mdw-preferred-column-width ()
224 "Return the preferred column width."
225 (if (and window-system (mdw-emacs-version-p 22)) mdw-column-width
226 (1+ mdw-column-width)))
228 (defun mdw-divvy-window (&optional width)
229 "Split a wide window into appropriate widths."
231 (setq width (if width (prefix-numeric-value width)
232 (mdw-preferred-column-width)))
233 (let* ((win (selected-window))
234 (sb-width (mdw-horizontal-window-overhead))
235 (c (/ (+ (window-width) sb-width)
236 (+ width sb-width))))
239 (split-window-horizontally (+ width sb-width))
241 (select-window win)))
243 (defun mdw-set-frame-width (columns &optional width)
244 (interactive "nColumns:
246 (setq width (if width (prefix-numeric-value width)
247 (mdw-preferred-column-width)))
248 (let ((sb-width (mdw-horizontal-window-overhead)))
249 (set-frame-width (selected-frame)
250 (- (* columns (+ width sb-width))
252 (mdw-divvy-window width)))
254 (defvar mdw-frame-width-fudge
255 (cond ((<= emacs-major-version 20) 1)
256 ((= emacs-major-version 26) 3)
258 "The number of extra columns to add to the desired frame width.
260 This is sadly necessary because Emacs 26 is broken in this regard.")
262 ;; Don't raise windows unless I say so.
264 (defvar mdw-inhibit-raise-frame nil
265 "*Whether `raise-frame' should do nothing when the frame is mapped.")
267 (defadvice raise-frame
268 (around mdw-inhibit (&optional frame) activate compile)
269 "Don't actually do anything if `mdw-inhibit-raise-frame' is true, and the
270 frame is actually mapped on the screen."
271 (if mdw-inhibit-raise-frame
272 (make-frame-visible frame)
275 (defmacro mdw-advise-to-inhibit-raise-frame (function)
276 "Advise the FUNCTION not to raise frames, even if it wants to."
277 `(defadvice ,function
278 (around mdw-inhibit-raise (&rest hunoz) activate compile)
279 "Don't raise the window unless you have to."
280 (let ((mdw-inhibit-raise-frame t))
283 (mdw-advise-to-inhibit-raise-frame select-frame-set-input-focus)
284 (mdw-advise-to-inhibit-raise-frame appt-disp-window)
285 (mdw-advise-to-inhibit-raise-frame mouse-select-window)
287 ;; Bug fix for markdown-mode, which breaks point positioning during
289 (defadvice markdown-check-change-for-wiki-link
290 (around mdw-save-match activate compile)
291 "Save match data around the `markdown-mode' `after-change-functions' hook."
292 (save-match-data ad-do-it))
294 ;; Bug fix for `bbdb-canonicalize-address': on Emacs 24, `run-hook-with-args'
295 ;; always returns nil, with the result that all email addresses are lost.
296 ;; Replace the function entirely.
297 (defadvice bbdb-canonicalize-address
298 (around mdw-bug-fix activate compile)
299 "Don't use `run-hook-with-args', because that doesn't work."
300 (let ((net (ad-get-arg 0)))
302 ;; Make sure this is a proper hook list.
303 (if (functionp bbdb-canonicalize-net-hook)
304 (setq bbdb-canonicalize-net-hook (list bbdb-canonicalize-net-hook)))
306 ;; Iterate over the hooks until things converge.
309 (let (next (changep nil)
310 hook (hooks bbdb-canonicalize-net-hook))
312 (setq hook (pop hooks))
313 (setq next (funcall hook net))
314 (if (not (equal next net))
317 (setq donep (not changep)))))
318 (setq ad-return-value net)))
320 ;; Transient mark mode hacks.
322 (defadvice exchange-point-and-mark
323 (around mdw-highlight (&optional arg) activate compile)
324 "Maybe don't actually exchange point and mark.
325 If `transient-mark-mode' is on and the mark is inactive, then
326 just activate it. A non-trivial prefix argument will force the
327 usual behaviour. A trivial prefix argument (i.e., just C-u) will
328 activate the mark and temporarily enable `transient-mark-mode' if
330 (cond ((or mark-active
331 (and (not transient-mark-mode) (not arg))
332 (and arg (or (not (consp arg))
333 (not (= (car arg) 4)))))
336 (or transient-mark-mode (setq transient-mark-mode 'only))
337 (set-mark (mark t)))))
339 ;; Functions for sexp diary entries.
341 (defun mdw-not-org-mode (form)
342 "As FORM, but not in Org mode agenda."
343 (and (not mdw-diary-for-org-mode-p)
346 (defun mdw-weekday (l)
347 "Return non-nil if `date' falls on one of the days of the week in L.
348 L is a list of day numbers (from 0 to 6 for Sunday through to
349 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
350 the date stored in `date' falls on a listed day, then the
351 function returns non-nil."
352 (let ((d (calendar-day-of-week date)))
354 (memq (nth d '(sunday monday tuesday wednesday
355 thursday friday saturday)) l))))
357 (defun mdw-discordian-date (date)
358 "Return the Discordian calendar date corresponding to DATE.
360 The return value is (YOLD . st-tibs-day) or (YOLD SEASON DAYNUM DOW).
362 The original is by David Pearson. I modified it to produce date components
363 as output rather than a string."
364 (let* ((days ["Sweetmorn" "Boomtime" "Pungenday"
365 "Prickle-Prickle" "Setting Orange"])
366 (months ["Chaos" "Discord" "Confusion"
367 "Bureaucracy" "Aftermath"])
368 (day-count [0 31 59 90 120 151 181 212 243 273 304 334])
369 (year (- (calendar-extract-year date) 1900))
370 (month (1- (calendar-extract-month date)))
371 (day (1- (calendar-extract-day date)))
372 (julian (+ (aref day-count month) day))
373 (dyear (+ year 3066)))
374 (if (and (= month 1) (= day 28))
375 (cons dyear 'st-tibs-day)
377 (aref months (floor (/ julian 73)))
379 (aref days (mod julian 5))))))
381 (defun mdw-diary-discordian-date ()
382 "Convert the date in `date' to a string giving the Discordian date."
383 (let* ((ddate (mdw-discordian-date date))
384 (tail (format "in the YOLD %d" (car ddate))))
385 (if (eq (cdr ddate) 'st-tibs-day)
386 (format "St Tib's Day %s" tail)
387 (let ((season (cadr ddate))
388 (daynum (caddr ddate))
389 (dayname (cadddr ddate)))
390 (format "%s, the %d%s day of %s %s"
393 (let ((ldig (mod daynum 10)))
394 (cond ((= ldig 1) "st")
401 (defun mdw-todo (&optional when)
402 "Return non-nil today, or on WHEN, whichever is later."
403 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
404 (d (calendar-absolute-from-gregorian date)))
406 (setq w (max w (calendar-absolute-from-gregorian
408 ((not european-calendar-style)
420 (defvar mdw-diary-for-org-mode-p nil)
422 (defadvice org-agenda-list (around mdw-preserve-links activate)
423 (let ((mdw-diary-for-org-mode-p t))
426 (defvar diary-time-regexp nil)
428 (defadvice diary-add-to-list (before mdw-trim-leading-space compile activate)
429 "Trim leading space from the diary entry string."
431 (let ((str (ad-get-arg 1))
435 (setq str (cond ((null str) nil)
436 ((string-match "\\(^\\|\n\\)[ \t]+" str)
437 (replace-match "\\1" nil nil str))
438 ((and mdw-diary-for-org-mode-p
439 (string-match (concat
441 "\\(" diary-time-regexp
442 "\\(-" diary-time-regexp "\\)?"
444 "\\(\t[ \t]*\\| [ \t]+\\)")
446 (replace-match "\\1\\2 " nil nil str))
447 ((and (not mdw-diary-for-org-mode-p)
448 (string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]"
450 (replace-match "\\1" nil nil str))
452 (if (equal str old) (setq done t)))
453 (ad-set-arg 1 str))))
455 (defadvice org-bbdb-anniversaries (after mdw-fixup-list compile activate)
456 "Return a string rather than a list."
459 (dolist (e (let ((ee ad-return-value))
460 (if (atom ee) (list ee) ee)))
462 (when anyp (insert ?\n))
465 (setq ad-return-value
466 (and anyp (buffer-string))))))
468 ;; Fighting with Org-mode's evil key maps.
470 (defvar mdw-evil-keymap-keys
471 '(([S-up] . [?\C-c up])
472 ([S-down] . [?\C-c down])
473 ([S-left] . [?\C-c left])
474 ([S-right] . [?\C-c right])
475 (([M-up] [?\e up]) . [C-up])
476 (([M-down] [?\e down]) . [C-down])
477 (([M-left] [?\e left]) . [C-left])
478 (([M-right] [?\e right]) . [C-right]))
479 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
480 The value is an alist mapping evil keys (as a list, or singleton)
481 to good keys (in the same form).")
483 (defun mdw-clobber-evil-keymap (keymap)
484 "Replace evil key bindings in the KEYMAP.
485 Evil key bindings are defined in `mdw-evil-keymap-keys'."
486 (dolist (entry mdw-evil-keymap-keys)
488 (keys (if (listp (car entry))
491 (replacements (if (listp (cdr entry))
493 (list (cdr entry)))))
496 (setq binding (lookup-key keymap key))
498 (throw 'found nil))))
501 (define-key keymap key nil))
502 (dolist (key replacements)
503 (define-key keymap key binding))))))
505 (defvar mdw-org-latex-defs
507 "\\documentclass{strayman}
508 \\usepackage[utf8]{inputenc}
509 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
510 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
511 ("\\section{%s}" . "\\section*{%s}")
512 ("\\subsection{%s}" . "\\subsection*{%s}")
513 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
514 ("\\paragraph{%s}" . "\\paragraph*{%s}")
515 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))
517 (eval-after-load "org-latex"
518 '(setq org-export-latex-classes
519 (append mdw-org-latex-defs org-export-latex-classes)))
521 (eval-after-load "ox-latex"
522 '(setq org-latex-classes (append mdw-org-latex-defs org-latex-classes)
523 org-latex-default-packages-alist '(("AUTO" "inputenc" t)
531 ("normalem" "ulem" t)
537 "\\tolerance=1000")))
540 (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
541 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
542 org-export-docbook-xslt-stylesheet
543 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
547 (setq glasses-separator "-"
548 glasses-separate-parentheses-p nil
549 glasses-uncapitalize-p t)
551 ;; Some hacks to do with window placement.
553 (defun mdw-clobber-other-windows-showing-buffer (buffer-or-name)
554 "Arrange that no windows on other frames are showing BUFFER-OR-NAME."
555 (interactive "bBuffer: ")
556 (let ((home-frame (selected-frame))
557 (buffer (get-buffer buffer-or-name))
558 (safe-buffer (get-buffer "*scratch*")))
559 (dolist (frame (frame-list))
560 (unless (eq frame home-frame)
561 (dolist (window (window-list frame))
562 (when (eq (window-buffer window) buffer)
563 (set-window-buffer window safe-buffer)))))))
565 (defvar mdw-inhibit-walk-windows nil
566 "If non-nil, then `walk-windows' does nothing.
567 This is used by advice on `switch-to-buffer-other-frame' to inhibit finding
568 buffers in random frames.")
570 (setq display-buffer--other-frame-action
571 '((display-buffer-reuse-window display-buffer-pop-up-frame)
572 (reusable-frames . nil)
573 (inhibit-same-window . t)))
575 (defadvice walk-windows (around mdw-inhibit activate)
576 "If `mdw-inhibit-walk-windows' is non-nil, then do nothing."
577 (and (not mdw-inhibit-walk-windows)
580 (defadvice switch-to-buffer-other-frame
581 (around mdw-always-new-frame activate)
582 "Always make a new frame.
583 Even if an existing window in some random frame looks tempting."
584 (let ((mdw-inhibit-walk-windows t)) ad-do-it))
586 (defadvice display-buffer (before mdw-inhibit-other-frames activate)
587 "Don't try to do anything fancy with other frames.
588 Pretend they don't exist. They might be on other display devices."
591 (setq even-window-sizes nil
592 even-window-heights nil)
594 ;; Rename buffers along with files.
596 (defvar mdw-inhibit-rename-buffer nil
597 "If non-nil, `rename-file' won't rename the buffer visiting the file.")
599 (defmacro mdw-advise-to-inhibit-rename-buffer (function)
600 "Advise FUNCTION to set `mdw-inhibit-rename-buffer' while it runs.
602 This will prevent `rename-file' from renaming the buffer."
603 `(defadvice ,function (around mdw-inhibit-rename-buffer compile activate)
604 "Don't rename the buffer when renaming the underlying file."
605 (let ((mdw-inhibit-rename-buffer t))
607 (mdw-advise-to-inhibit-rename-buffer recode-file-name)
608 (mdw-advise-to-inhibit-rename-buffer set-visited-file-name)
609 (mdw-advise-to-inhibit-rename-buffer backup-buffer)
611 (defadvice rename-file (after mdw-rename-buffers (from to &optional forcep)
613 "If a buffer is visiting the file, rename it to match the new name.
615 Don't do this if `mdw-inhibit-rename-buffer' is non-nil."
616 (unless mdw-inhibit-rename-buffer
617 (let ((buffer (get-file-buffer from)))
619 (with-current-buffer buffer
620 (set-visited-file-name to nil t))))))
622 ;;;--------------------------------------------------------------------------
623 ;;; Improved compilation machinery.
625 ;; Uprated version of M-x compile.
627 (setq compile-command
628 (let ((ncpu (with-temp-buffer
629 (insert-file-contents "/proc/cpuinfo")
631 (count-matches "^processor\\s-*:"))))
632 (format "make -j%d -k" (* 2 ncpu))))
634 (defun mdw-compilation-buffer-name (mode)
635 (concat "*" (downcase mode) ": "
636 (abbreviate-file-name default-directory) "*"))
637 (setq compilation-buffer-name-function 'mdw-compilation-buffer-name)
639 (eval-after-load "compile"
641 (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile)))
643 (defadvice compile (around hack-environment compile activate)
644 "Hack the environment inherited by inferiors in the compilation."
645 (let ((process-environment (copy-tree process-environment)))
646 (setenv "LD_PRELOAD" nil)
649 (defun mdw-compile (command &optional directory comint)
650 "Initiate a compilation COMMAND, maybe in a different DIRECTORY.
651 The DIRECTORY may be nil to not change. If COMINT is t, then
652 start an interactive compilation.
654 Interactively, prompt for the command if the variable
655 `compilation-read-command' is non-nil, or if requested through
656 the prefix argument. Prompt for the directory, and run
657 interactively, if requested through the prefix.
659 Use a prefix of 4, 6, 12, or 14, or type C-u between one and three times, to
660 force prompting for a directory.
662 Use a prefix of 2, 6, 10, or 14, or type C-u three times, to force
663 prompting for the command.
665 Use a prefix of 8, 10, 12, or 14, or type C-u twice or three times,
666 to force interactive compilation."
668 (let* ((prefix (prefix-numeric-value current-prefix-arg))
669 (command (eval compile-command))
670 (dir (and (plusp (logand prefix #x54))
671 (read-directory-name "Compile in directory: "))))
672 (list (if (or compilation-read-command
673 (plusp (logand prefix #x42)))
674 (compilation-read-command command)
677 (plusp (logand prefix #x58)))))
678 (let ((default-directory (or directory default-directory)))
679 (compile command comint)))
683 (defun mdw-find-build-dir (build-file)
685 (let* ((src-dir (file-name-as-directory (expand-file-name ".")))
688 (when (file-exists-p (concat dir build-file))
690 (let ((sub (expand-file-name (file-relative-name src-dir dir)
691 (concat dir "build/"))))
694 (when (file-exists-p (concat sub build-file))
696 (when (string= sub dir) (throw 'give-up nil))
697 (setq sub (file-name-directory (directory-file-name sub))))))
699 (setq dir (file-name-directory
700 (directory-file-name dir))))
701 (throw 'found nil))))))
703 (defun mdw-flymake-make-init ()
704 (let ((build-dir (mdw-find-build-dir "Makefile")))
706 (let ((tmp-src (flymake-init-create-temp-buffer-copy
707 #'flymake-create-temp-inplace)))
708 (flymake-get-syntax-check-program-args
709 tmp-src build-dir t t
710 #'flymake-get-make-cmdline)))))
712 (setq flymake-allowed-file-name-masks
713 '(("\\.\\(?:[cC]\\|cc\\|cpp\\|cxx\\|c\\+\\+\\)\\'"
714 mdw-flymake-make-init)
715 ("\\.\\(?:[hH]\\|hh\\|hpp\\|hxx\\|h\\+\\+\\)\\'"
716 mdw-flymake-master-make-init)
717 ("\\.p[lm]" flymake-perl-init)))
719 (setq flymake-mode-map
720 (let ((map (if (boundp 'flymake-mode-map)
722 (make-sparse-keymap))))
723 (define-key map [?\C-c ?\C-f ?\C-p] 'flymake-goto-prev-error)
724 (define-key map [?\C-c ?\C-f ?\C-n] 'flymake-goto-next-error)
725 (define-key map [?\C-c ?\C-f ?\C-c] 'flymake-compile)
726 (define-key map [?\C-c ?\C-f ?\C-k] 'flymake-stop-all-syntax-checks)
727 (define-key map [?\C-c ?\C-f ?\C-e] 'flymake-popup-current-error-menu)
730 ;;;--------------------------------------------------------------------------
731 ;;; Mail and news hacking.
733 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
734 "Major mode for editing news and mail messages from external programs.
735 Not much right now. Just support for doing MailCrypt stuff."
738 (run-hooks 'mail-setup-hook))
740 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
742 (add-hook 'mdwail-mode-hook
744 (set-buffer-file-coding-system 'utf-8)
745 (make-local-variable 'paragraph-separate)
746 (make-local-variable 'paragraph-start)
747 (setq paragraph-start
748 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
750 (setq paragraph-separate
751 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
752 paragraph-separate))))
754 ;; How to encrypt in mdwmail.
756 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
758 (setq start (save-excursion
759 (goto-char (point-min))
760 (or (search-forward "\n\n" nil t) (point-min)))))
762 (setq end (point-max)))
763 (mc-encrypt-generic recip scm start end from sign))
765 ;; How to sign in mdwmail.
767 (defun mdwmail-mc-sign (key scm start end uclr)
769 (setq start (save-excursion
770 (goto-char (point-min))
771 (or (search-forward "\n\n" nil t) (point-min)))))
773 (setq end (point-max)))
774 (mc-sign-generic key scm start end uclr))
776 ;; Some signature mangling.
778 (defun mdwmail-mangle-signature ()
780 (goto-char (point-min))
781 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
782 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
783 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
785 ;; Insert my login name into message-ids, so I can score replies.
787 (defadvice message-unique-id (after mdw-user-name last activate compile)
788 "Ensure that the user's name appears at the end of the message-id string,
789 so that it can be used for convenient filtering."
790 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
792 ;; Tell my movemail hack where movemail is.
794 ;; This is needed to shup up warnings about LD_PRELOAD.
796 (let ((path exec-path))
798 (let ((try (expand-file-name "movemail" (car path))))
799 (if (file-executable-p try)
800 (setenv "REAL_MOVEMAIL" try))
801 (setq path (cdr path)))))
803 ;; AUTHINFO GENERIC kludge.
805 (defvar nntp-authinfo-generic nil
806 "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'.
808 Use this to arrange for per-server settings.")
810 (defun nntp-open-authinfo-kludge (buffer)
811 "Open a connection to SERVER using `authinfo-kludge'."
812 (let ((proc (start-process "nntpd" buffer
813 "env" (concat "NNTPAUTH="
814 (or nntp-authinfo-generic
816 (error "NNTPAUTH unset")))
817 "authinfo-kludge" nntp-address)))
819 (nntp-wait-for-string "^\r*200")
821 (delete-region (point-min) (point))
824 (eval-after-load "erc"
825 '(load "~/.ercrc.el"))
827 ;; Heavy-duty Gnus patching.
829 (defun mdw-nnimap-transform-headers ()
830 (goto-char (point-min))
831 (let (article lines size string)
834 (while (not (looking-at "\\* [0-9]+ FETCH"))
835 (delete-region (point) (progn (forward-line 1) (point)))
838 (goto-char (match-end 0))
839 ;; Unfold quoted {number} strings.
840 (while (re-search-forward
841 "[^]][ (]{\\([0-9]+\\)}\r?\n"
843 ;; Start of the header section.
844 (or (re-search-forward "] {[0-9]+}\r?\n" nil t)
845 ;; Start of the next FETCH.
846 (re-search-forward "\\* [0-9]+ FETCH" nil t)
849 (setq size (string-to-number (match-string 1)))
850 (delete-region (+ (match-beginning 0) 2) (point))
851 (setq string (buffer-substring (point) (+ (point) size)))
852 (delete-region (point) (+ (point) size))
853 (insert (format "%S" (subst-char-in-string ?\n ?\s string)))
854 ;; [mdw] missing from upstream
858 (and (re-search-forward "UID \\([0-9]+\\)" (line-end-position)
863 (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)"
868 (when (search-forward "BODYSTRUCTURE" (line-end-position) t)
869 (let ((structure (ignore-errors
870 (read (current-buffer)))))
871 (while (and (consp structure)
872 (not (atom (car structure))))
873 (setq structure (car structure)))
875 (stringp (car structure))
876 (equal (upcase (nth 0 structure)) "MESSAGE")
877 (equal (upcase (nth 1 structure)) "RFC822"))
879 (nth 7 structure)))))
880 (delete-region (line-beginning-position) (line-end-position))
881 (insert (format "211 %s Article retrieved." article))
884 (insert (format "Chars: %s\n" size)))
886 (insert (format "Lines: %s\n" lines)))
887 ;; Most servers have a blank line after the headers, but
889 (unless (re-search-forward "^\r$\\|^)\r?$" nil t)
890 (goto-char (point-max)))
891 (delete-region (line-beginning-position) (line-end-position))
895 (eval-after-load 'nnimap
896 '(defalias 'nnimap-transform-headers
897 (symbol-function 'mdw-nnimap-transform-headers)))
899 (defadvice gnus-other-frame (around mdw-hack-frame-width compile activate)
900 "Always arrange for mail/news frames to be 80 columns wide."
901 (let ((default-frame-alist (cons `(width . ,(+ 80 mdw-frame-width-fudge))
902 (cl-delete 'width default-frame-alist
906 ;; Preferred programs.
908 (setq mailcap-user-mime-data
909 '(((type . "application/pdf") (viewer . "mupdf %s"))))
911 ;;;--------------------------------------------------------------------------
912 ;;; Utility functions.
914 (or (fboundp 'line-number-at-pos)
915 (defun line-number-at-pos (&optional pos)
916 (let ((opoint (or pos (point))) start)
919 (goto-char (point-min))
925 (1+ (count-lines 1 (point))))))))
927 (defun mdw-uniquify-alist (&rest alists)
928 "Return the concatenation of the ALISTS with duplicate elements removed.
929 The first association with a given key prevails; others are
930 ignored. The input lists are not modified, although they'll
931 probably become garbage."
933 (let ((start-list (cons nil nil)))
934 (mdw-do-uniquify start-list
939 (defun mdw-do-uniquify (done end l rest)
940 "A helper function for mdw-uniquify-alist.
941 The DONE argument is a list whose first element is `nil'. It
942 contains the uniquified alist built so far. The leading `nil' is
943 stripped off at the end of the operation; it's only there so that
944 DONE always references a cons cell. END refers to the final cons
945 cell in the DONE list; it is modified in place each time to avoid
946 the overheads of `append'ing all the time. The L argument is the
947 alist we're currently processing; the remaining alists are given
950 ;; There are several different cases to deal with here.
953 ;; Current list isn't empty. Add the first item to the DONE list if
954 ;; there's not an item with the same KEY already there.
955 (l (or (assoc (car (car l)) done)
957 (setcdr end (cons (car l) nil))
958 (setq end (cdr end))))
959 (mdw-do-uniquify done end (cdr l) rest))
961 ;; The list we were working on is empty. Shunt the next list into the
962 ;; current list position and go round again.
963 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
965 ;; Everything's done. Remove the leading `nil' from the DONE list and
966 ;; return it. Finished!
970 "Insert the current date in a pleasing way."
972 (insert (save-excursion
973 (let ((buffer (get-buffer-create "*tmp*")))
974 (unwind-protect (progn (set-buffer buffer)
976 (shell-command "date +%Y-%m-%d" t)
980 (kill-buffer buffer))))))
982 (defun uuencode (file &optional name)
983 "UUencodes a file, maybe calling it NAME, into the current buffer."
984 (interactive "fInput file name: ")
986 ;; If NAME isn't specified, then guess from the filename.
990 (or (string-match "[^/]*$" file) 0))))
991 (print (format "uuencode `%s' `%s'" file name))
993 ;; Now actually do the thing.
994 (call-process "uuencode" file t nil name))
996 (defvar np-file "~/.np"
997 "*Where the `now-playing' file is.")
999 (defun np (&optional arg)
1000 "Grabs a `now-playing' string."
1004 (goto-char (point-max))
1006 (insert-file-contents np-file)))))
1008 (defun mdw-version-< (ver-a ver-b)
1009 "Answer whether VER-A is strictly earlier than VER-B.
1010 VER-A and VER-B are version numbers, which are strings containing digit
1011 sequences separated by `.'."
1012 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
1013 (split-string ver-a "\\.")))
1014 (lb (mapcar (lambda (x) (car (read-from-string x)))
1015 (split-string ver-b "\\."))))
1018 (cond ((null la) (throw 'done lb))
1019 ((null lb) (throw 'done nil))
1020 ((< (car la) (car lb)) (throw 'done t))
1021 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))
1022 (t (throw 'done nil)))))))
1024 (defun mdw-check-autorevert ()
1025 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
1026 This takes into consideration whether it's been found using
1027 tramp, which seems to get itself into a twist."
1028 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
1030 ((and (buffer-file-name)
1031 (fboundp 'tramp-tramp-file-p)
1032 (tramp-tramp-file-p (buffer-file-name)))
1033 (unless global-auto-revert-ignore-buffer
1034 (setq global-auto-revert-ignore-buffer 'tramp)))
1035 ((eq global-auto-revert-ignore-buffer 'tramp)
1036 (setq global-auto-revert-ignore-buffer nil))))
1038 (defadvice find-file (after mdw-autorevert activate)
1039 (mdw-check-autorevert))
1040 (defadvice write-file (after mdw-autorevert activate)
1041 (mdw-check-autorevert))
1043 (defun mdw-auto-revert ()
1044 "Recheck all of the autorevertable buffers, and update VC modelines."
1046 (let ((auto-revert-check-vc-info t))
1047 (auto-revert-buffers)))
1049 (defun comint-send-and-indent ()
1052 (and mdw-auto-indent
1053 (indent-for-tab-command)))
1055 (defadvice comint-line-beginning-position
1056 (around mdw-calculate-it-properly () activate compile)
1057 "Calculate the actual line start for multi-line input."
1058 (if (or comint-use-prompt-regexp
1059 (eq (field-at-pos (point)) 'output))
1061 (setq ad-return-value
1062 (constrain-to-field (line-beginning-position) (point)))))
1064 ;;;--------------------------------------------------------------------------
1067 (defadvice dired-maybe-insert-subdir
1068 (around mdw-marked-insertion first activate)
1069 "The DIRNAME may be a list of directory names to insert.
1070 Interactively, if files are marked, then insert all of them.
1071 With a numeric prefix argument, select that many entries near
1072 point; with a non-numeric prefix argument, prompt for listing
1075 (list (dired-get-marked-files nil
1076 (and (integerp current-prefix-arg)
1079 (and current-prefix-arg
1080 (not (integerp current-prefix-arg))
1081 (read-string "Switches for listing: "
1082 (or dired-subdir-switches
1083 dired-actual-switches)))))
1084 (let ((dirs (ad-get-arg 0)))
1085 (dolist (dir (if (listp dirs) dirs (list dirs)))
1089 (defun mdw-dired-run (args &optional syncp)
1090 (interactive (let ((file (dired-get-filename t)))
1091 (list (read-string (format "Arguments for %s: " file))
1092 current-prefix-arg)))
1093 (funcall (if syncp 'shell-command 'async-shell-command)
1094 (concat (shell-quote-argument (dired-get-filename nil))
1097 (defadvice dired-do-flagged-delete
1098 (around mdw-delete-if-prefix-argument activate compile)
1099 (let ((delete-by-moving-to-trash (and (null current-prefix-arg)
1100 delete-by-moving-to-trash)))
1103 (eval-after-load "dired"
1104 '(define-key dired-mode-map "X" 'mdw-dired-run))
1106 ;;;--------------------------------------------------------------------------
1109 (defun mdw-w3m-browse-url (url &optional new-session-p)
1110 "Invoke w3m on the URL in its current window, or at least a different one.
1111 If NEW-SESSION-P, start a new session."
1112 (interactive "sURL: \nP")
1114 (let ((window (selected-window)))
1117 (select-window (or (and (not new-session-p)
1118 (get-buffer-window "*w3m*"))
1120 (if (one-window-p t) (split-window))
1122 (w3m-browse-url url new-session-p))
1123 (select-window window)))))
1125 (eval-after-load 'w3m
1126 '(define-key w3m-mode-map [?\e ?\r] 'w3m-view-this-url-new-session))
1128 (defvar mdw-good-url-browsers
1129 '(browse-url-mozilla
1131 (w3m . mdw-w3m-browse-url)
1133 "List of good browsers for mdw-good-url-browsers.
1134 Each item is a browser function name, or a cons (CHECK . FUNC).
1135 A symbol FOO stands for (FOO . FOO).")
1137 (defun mdw-good-url-browser ()
1138 "Return a good URL browser.
1139 Trundle the list of such things, finding the first item for which
1140 CHECK is fboundp, and returning the correponding FUNC."
1141 (let ((bs mdw-good-url-browsers) b check func answer)
1142 (while (and bs (not answer))
1146 (setq check (car b) func (cdr b))
1147 (setq check b func b))
1149 (setq answer func)))
1152 (eval-after-load "w3m-search"
1156 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
1157 ("gd" "Google Directory"
1158 "http://www.google.com/search?cat=gwd/Top&q=%s")
1159 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
1160 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
1161 ("gi" "Images" "http://images.google.com/images?q=%s")
1163 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
1165 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
1166 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
1167 ("nc-wiki" "nCipher wiki"
1168 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
1169 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
1170 ("lp" "Launchpad bug by number"
1171 "https://bugs.launchpad.net/bugs/%s")
1172 ("lppkg" "Launchpad bugs by package"
1173 "https://bugs.launchpad.net/%s")
1175 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
1176 ("debbug" "Debian bug by number"
1177 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
1178 ("debbugpkg" "Debian bugs by package"
1179 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
1180 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
1181 (add-to-list 'w3m-search-engine-alist
1182 (list (cadr item) (caddr item) nil))
1183 (add-to-list 'w3m-uri-replace-alist
1184 (list (concat "\\`" (car item) ":")
1185 'w3m-search-uri-replace
1188 ;;;--------------------------------------------------------------------------
1189 ;;; Paragraph filling.
1191 ;; Useful variables.
1193 (defvar mdw-fill-prefix nil
1194 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
1195 If there's no fill prefix currently set (by the `fill-prefix'
1196 variable) and there's a match from one of the regexps here, it
1197 gets used to set the fill-prefix for the current operation.
1199 The variable is a list of items of the form `REGEXP . PREFIX'; if
1200 the REGEXP matches, the PREFIX is used to set the fill prefix.
1201 It in turn is a list of things:
1203 STRING -- insert a literal string
1204 (match . N) -- insert the thing matched by bracketed subexpression N
1205 (pad . N) -- a string of whitespace the same width as subexpression N
1206 (expr . FORM) -- the result of evaluating FORM")
1208 (make-variable-buffer-local 'mdw-fill-prefix)
1210 (defvar mdw-hanging-indents
1212 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
1215 "*Standard regexp matching parts of a hanging indent.
1216 This is mainly useful in `auto-fill-mode'.")
1218 ;; Utility functions.
1220 (defun mdw-maybe-tabify (s)
1221 "Tabify or untabify the string S, according to `indent-tabs-mode'."
1222 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
1226 (let ((start (point-min)) (end (point-max)))
1227 (funcall tabfun (point-min) (point-max))
1228 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
1230 (defun mdw-maybe-car (p)
1231 "If P is a pair, return (car P), otherwise just return P."
1232 (if (consp p) (car p) p))
1234 (defun mdw-padding (s)
1235 "Return a string the same width as S but made entirely from whitespace."
1236 (let* ((l (length s)) (i 0) (n (make-string l ? )))
1238 (if (= 9 (aref s i))
1243 (defun mdw-do-prefix-match (m)
1244 "Expand a dynamic prefix match element.
1245 See `mdw-fill-prefix' for details."
1246 (cond ((not (consp m)) (format "%s" m))
1247 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
1248 ((eq (car m) 'pad) (mdw-padding (match-string
1249 (mdw-maybe-car (cdr m)))))
1250 ((eq (car m) 'eval) (eval (cdr m)))
1253 (defun mdw-examine-fill-prefixes (l)
1254 "Given a list of dynamic fill prefixes, pick one which matches
1255 context and return the static fill prefix to use. Point must be
1256 at the start of a line, and match data must be saved."
1258 (while (cond ((null l) nil)
1259 ((looking-at (caar l))
1263 (mapcar #'mdw-do-prefix-match
1269 (defun mdw-choose-dynamic-fill-prefix ()
1270 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
1271 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
1272 ((not mdw-fill-prefix) fill-prefix)
1276 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
1278 (defadvice do-auto-fill (around mdw-dynamic-fill-prefix () activate compile)
1279 "Handle auto-filling, working out a dynamic fill prefix in the
1280 case where there isn't a sensible static one."
1281 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1284 (defun mdw-fill-paragraph ()
1285 "Fill paragraph, getting a dynamic fill prefix."
1287 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1288 (fill-paragraph nil)))
1290 (defun mdw-standard-fill-prefix (rx &optional mat)
1291 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
1292 This is just a short-cut for setting the thing by hand, and by
1293 design it doesn't cope with anything approximating a complicated
1295 (setq mdw-fill-prefix
1296 `((,(concat rx mdw-hanging-indents)
1298 (pad . ,(or mat 2))))))
1300 ;;;--------------------------------------------------------------------------
1301 ;;; Other common declarations.
1303 ;; Common mode settings.
1305 (defvar mdw-auto-indent t
1306 "Whether to indent automatically after a newline.")
1308 (defun mdw-whitespace-mode (&optional arg)
1309 "Turn on/off whitespace mode, but don't highlight trailing space."
1311 (when (and (boundp 'whitespace-style)
1312 (fboundp 'whitespace-mode))
1313 (let ((whitespace-style (remove 'trailing whitespace-style)))
1314 (whitespace-mode arg))
1315 (setq show-trailing-whitespace whitespace-mode)))
1317 (defvar mdw-do-misc-mode-hacking nil)
1319 (defun mdw-misc-mode-config ()
1320 (and mdw-auto-indent
1321 (cond ((eq major-mode 'lisp-mode)
1322 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
1323 ((derived-mode-p 'slime-repl-mode 'asm-mode 'comint-mode)
1326 (local-set-key "\C-m" 'newline-and-indent))))
1327 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
1328 (local-set-key [C-return] 'newline)
1329 (make-local-variable 'page-delimiter)
1330 (setq page-delimiter (concat "^" "\f"
1334 "\\(" " " ".*" " " "\\)?"
1338 (setq comment-column 40)
1340 (setq fill-column mdw-text-width)
1341 (flyspell-prog-mode)
1342 (and (fboundp 'gtags-mode)
1344 (if (fboundp 'hs-minor-mode)
1345 (trap (hs-minor-mode t))
1346 (outline-minor-mode t))
1348 (trap (turn-on-font-lock)))
1350 (defun mdw-post-local-vars-misc-mode-config ()
1351 (setq whitespace-line-column mdw-text-width)
1352 (when (and mdw-do-misc-mode-hacking
1353 (not buffer-read-only))
1354 (setq show-trailing-whitespace t)
1355 (mdw-whitespace-mode 1)))
1356 (add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
1358 (defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1359 `(progn ,@(mapcar (lambda (func)
1361 (after mdw-angry-fruit-salad activate)
1362 (when mdw-do-misc-mode-hacking
1363 (setq show-trailing-whitespace
1364 (not buffer-read-only))
1365 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1367 (mdw-advise-update-angry-fruit-salad toggle-read-only
1373 (eval-after-load 'gtags
1375 (dolist (key '([mouse-2] [mouse-3]))
1376 (define-key gtags-mode-map key nil))
1377 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1378 (define-key gtags-select-mode-map [C-S-mouse-2]
1379 'gtags-select-tag-by-event)
1380 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1381 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
1383 ;; Backup file handling.
1385 (defvar mdw-backup-disable-regexps nil
1386 "*List of regular expressions: if a file name matches any of
1387 these then the file is not backed up.")
1389 (defun mdw-backup-enable-predicate (name)
1390 "[mdw]'s default backup predicate.
1391 Allows a backup if the standard predicate would allow it, and it
1392 doesn't match any of the regular expressions in
1393 `mdw-backup-disable-regexps'."
1394 (and (normal-backup-enable-predicate name)
1395 (let ((answer t) (list mdw-backup-disable-regexps))
1398 (if (string-match (car list) name)
1400 (setq list (cdr list)))
1402 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
1406 (defun mdw-last-one-out-turn-off-the-lights (frame)
1407 "Disconnect from an X display if this was the last frame on that display."
1408 (let ((frame-display (frame-parameter frame 'display)))
1409 (when (and frame-display
1410 (eq window-system 'x)
1411 (not (some (lambda (fr)
1412 (and (not (eq fr frame))
1413 (string= (frame-parameter fr 'display)
1416 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1417 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1419 ;;;--------------------------------------------------------------------------
1420 ;;; Fullscreen-ness.
1422 (defvar mdw-full-screen-parameters
1423 '((menu-bar-lines . 0)
1424 ;(vertical-scroll-bars . nil)
1426 "Frame parameters to set when making a frame fullscreen.")
1428 (defvar mdw-full-screen-save
1430 "Extra frame parameters to save when setting fullscreen.")
1432 (defun mdw-toggle-full-screen (&optional frame)
1433 "Show the FRAME fullscreen."
1436 (cond ((frame-parameter frame 'fullscreen)
1437 (set-frame-parameter frame 'fullscreen nil)
1438 (modify-frame-parameters
1440 (or (frame-parameter frame 'mdw-full-screen-saved)
1441 (mapcar (lambda (assoc)
1442 (assq (car assoc) default-frame-alist))
1443 mdw-full-screen-parameters))))
1445 (let ((saved (mapcar (lambda (param)
1446 (cons param (frame-parameter frame param)))
1447 (append (mapcar #'car
1448 mdw-full-screen-parameters)
1449 mdw-full-screen-save))))
1450 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1451 (modify-frame-parameters frame mdw-full-screen-parameters)
1452 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1454 ;;;--------------------------------------------------------------------------
1455 ;;; General fontification.
1457 (make-face 'mdw-virgin-face)
1459 (defmacro mdw-define-face (name &rest body)
1460 "Define a face, and make sure it's actually set as the definition."
1464 (copy-face 'mdw-virgin-face ',name)
1465 (defvar ,name ',name)
1466 (put ',name 'face-defface-spec ',body)
1467 (face-spec-set ',name ',body nil)))
1469 (mdw-define-face default
1470 (((type w32)) :family "courier new" :height 85)
1471 (((type x)) :family "6x13" :foundry "trad" :height 130)
1472 (((type color)) :foreground "white" :background "black")
1474 (mdw-define-face fixed-pitch
1475 (((type w32)) :family "courier new" :height 85)
1476 (((type x)) :family "6x13" :foundry "trad" :height 130)
1477 (t :foreground "white" :background "black"))
1478 (mdw-define-face fixed-pitch-serif
1479 (((type w32)) :family "courier new" :height 85 :weight bold)
1480 (((type x)) :family "6x13" :foundry "trad" :height 130 :weight bold)
1481 (t :foreground "white" :background "black" :weight bold))
1482 (mdw-define-face variable-pitch
1483 (((type x)) :family "helvetica" :height 120))
1484 (mdw-define-face region
1485 (((min-colors 64)) :background "grey30")
1486 (((class color)) :background "blue")
1487 (t :inverse-video t))
1488 (mdw-define-face match
1489 (((class color)) :background "blue")
1490 (t :inverse-video t))
1491 (mdw-define-face mc/cursor-face
1492 (((class color)) :background "red")
1493 (t :inverse-video t))
1494 (mdw-define-face minibuffer-prompt
1496 (mdw-define-face mode-line
1497 (((class color)) :foreground "blue" :background "yellow"
1498 :box (:line-width 1 :style released-button))
1499 (t :inverse-video t))
1500 (mdw-define-face mode-line-inactive
1501 (((class color)) :foreground "yellow" :background "blue"
1502 :box (:line-width 1 :style released-button))
1503 (t :inverse-video t))
1504 (mdw-define-face nobreak-space
1506 (t :inherit escape-glyph :underline t))
1507 (mdw-define-face scroll-bar
1508 (t :foreground "black" :background "lightgrey"))
1509 (mdw-define-face fringe
1510 (t :foreground "yellow"))
1511 (mdw-define-face show-paren-match
1512 (((min-colors 64)) :background "darkgreen")
1513 (((class color)) :background "green")
1515 (mdw-define-face show-paren-mismatch
1516 (((class color)) :background "red")
1517 (t :inverse-video t))
1518 (mdw-define-face highlight
1519 (((min-colors 64)) :background "DarkSeaGreen4")
1520 (((class color)) :background "cyan")
1521 (t :inverse-video t))
1523 (mdw-define-face holiday-face
1524 (t :background "red"))
1525 (mdw-define-face calendar-today-face
1526 (t :foreground "yellow" :weight bold))
1528 (mdw-define-face comint-highlight-prompt
1530 (mdw-define-face comint-highlight-input
1533 (mdw-define-face Man-underline
1534 (((type tty)) :underline t)
1537 (mdw-define-face ido-subdir
1538 (t :foreground "cyan" :weight bold))
1540 (mdw-define-face dired-directory
1541 (t :foreground "cyan" :weight bold))
1542 (mdw-define-face dired-symlink
1543 (t :foreground "cyan"))
1544 (mdw-define-face dired-perm-write
1547 (mdw-define-face trailing-whitespace
1548 (((class color)) :background "red")
1549 (t :inverse-video t))
1550 (mdw-define-face whitespace-line
1551 (((class color)) :background "darkred")
1552 (t :inverse-video t))
1553 (mdw-define-face mdw-punct-face
1554 (((min-colors 64)) :foreground "burlywood2")
1555 (((class color)) :foreground "yellow"))
1556 (mdw-define-face mdw-number-face
1557 (t :foreground "yellow"))
1558 (mdw-define-face mdw-trivial-face)
1559 (mdw-define-face font-lock-function-name-face
1561 (mdw-define-face font-lock-keyword-face
1563 (mdw-define-face font-lock-constant-face
1565 (mdw-define-face font-lock-builtin-face
1567 (mdw-define-face font-lock-type-face
1568 (t :weight bold :slant italic))
1569 (mdw-define-face font-lock-reference-face
1571 (mdw-define-face font-lock-variable-name-face
1573 (mdw-define-face font-lock-comment-delimiter-face
1574 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1575 (((class color)) :foreground "green")
1577 (mdw-define-face font-lock-comment-face
1578 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1579 (((class color)) :foreground "green")
1581 (mdw-define-face font-lock-string-face
1582 (((min-colors 64)) :foreground "SkyBlue1")
1583 (((class color)) :foreground "cyan")
1586 (mdw-define-face message-separator
1587 (t :background "red" :foreground "white" :weight bold))
1588 (mdw-define-face message-cited-text
1589 (default :slant italic)
1590 (((min-colors 64)) :foreground "SkyBlue1")
1591 (((class color)) :foreground "cyan"))
1592 (mdw-define-face message-header-cc
1593 (default :slant italic)
1594 (((min-colors 64)) :foreground "SeaGreen1")
1595 (((class color)) :foreground "green"))
1596 (mdw-define-face message-header-newsgroups
1597 (default :slant italic)
1598 (((min-colors 64)) :foreground "SeaGreen1")
1599 (((class color)) :foreground "green"))
1600 (mdw-define-face message-header-subject
1601 (((min-colors 64)) :foreground "SeaGreen1")
1602 (((class color)) :foreground "green"))
1603 (mdw-define-face message-header-to
1604 (((min-colors 64)) :foreground "SeaGreen1")
1605 (((class color)) :foreground "green"))
1606 (mdw-define-face message-header-xheader
1607 (default :slant italic)
1608 (((min-colors 64)) :foreground "SeaGreen1")
1609 (((class color)) :foreground "green"))
1610 (mdw-define-face message-header-other
1611 (default :slant italic)
1612 (((min-colors 64)) :foreground "SeaGreen1")
1613 (((class color)) :foreground "green"))
1614 (mdw-define-face message-header-name
1615 (default :weight bold)
1616 (((min-colors 64)) :foreground "SeaGreen1")
1617 (((class color)) :foreground "green"))
1619 (mdw-define-face which-func
1622 (mdw-define-face gnus-header-name
1623 (default :weight bold)
1624 (((min-colors 64)) :foreground "SeaGreen1")
1625 (((class color)) :foreground "green"))
1626 (mdw-define-face gnus-header-subject
1627 (((min-colors 64)) :foreground "SeaGreen1")
1628 (((class color)) :foreground "green"))
1629 (mdw-define-face gnus-header-from
1630 (((min-colors 64)) :foreground "SeaGreen1")
1631 (((class color)) :foreground "green"))
1632 (mdw-define-face gnus-header-to
1633 (((min-colors 64)) :foreground "SeaGreen1")
1634 (((class color)) :foreground "green"))
1635 (mdw-define-face gnus-header-content
1636 (default :slant italic)
1637 (((min-colors 64)) :foreground "SeaGreen1")
1638 (((class color)) :foreground "green"))
1640 (mdw-define-face gnus-cite-1
1641 (((min-colors 64)) :foreground "SkyBlue1")
1642 (((class color)) :foreground "cyan"))
1643 (mdw-define-face gnus-cite-2
1644 (((min-colors 64)) :foreground "RoyalBlue2")
1645 (((class color)) :foreground "blue"))
1646 (mdw-define-face gnus-cite-3
1647 (((min-colors 64)) :foreground "MediumOrchid")
1648 (((class color)) :foreground "magenta"))
1649 (mdw-define-face gnus-cite-4
1650 (((min-colors 64)) :foreground "firebrick2")
1651 (((class color)) :foreground "red"))
1652 (mdw-define-face gnus-cite-5
1653 (((min-colors 64)) :foreground "burlywood2")
1654 (((class color)) :foreground "yellow"))
1655 (mdw-define-face gnus-cite-6
1656 (((min-colors 64)) :foreground "SeaGreen1")
1657 (((class color)) :foreground "green"))
1658 (mdw-define-face gnus-cite-7
1659 (((min-colors 64)) :foreground "SlateBlue1")
1660 (((class color)) :foreground "cyan"))
1661 (mdw-define-face gnus-cite-8
1662 (((min-colors 64)) :foreground "RoyalBlue2")
1663 (((class color)) :foreground "blue"))
1664 (mdw-define-face gnus-cite-9
1665 (((min-colors 64)) :foreground "purple2")
1666 (((class color)) :foreground "magenta"))
1667 (mdw-define-face gnus-cite-10
1668 (((min-colors 64)) :foreground "DarkOrange2")
1669 (((class color)) :foreground "red"))
1670 (mdw-define-face gnus-cite-11
1671 (t :foreground "grey"))
1673 (mdw-define-face gnus-emphasis-underline
1674 (((type tty)) :underline t)
1677 (mdw-define-face diff-header
1679 (mdw-define-face diff-index
1681 (mdw-define-face diff-file-header
1683 (mdw-define-face diff-hunk-header
1684 (((min-colors 64)) :foreground "SkyBlue1")
1685 (((class color)) :foreground "cyan"))
1686 (mdw-define-face diff-function
1687 (default :weight bold)
1688 (((min-colors 64)) :foreground "SkyBlue1")
1689 (((class color)) :foreground "cyan"))
1690 (mdw-define-face diff-header
1691 (((min-colors 64)) :background "grey10"))
1692 (mdw-define-face diff-added
1693 (((class color)) :foreground "green"))
1694 (mdw-define-face diff-removed
1695 (((class color)) :foreground "red"))
1696 (mdw-define-face diff-context
1698 (mdw-define-face diff-refine-change
1699 (((min-colors 64)) :background "RoyalBlue4")
1701 (mdw-define-face diff-refine-removed
1702 (((min-colors 64)) :background "#500")
1704 (mdw-define-face diff-refine-added
1705 (((min-colors 64)) :background "#050")
1708 (setq ediff-force-faces t)
1709 (mdw-define-face ediff-current-diff-A
1710 (((min-colors 64)) :background "darkred")
1711 (((class color)) :background "red")
1712 (t :inverse-video t))
1713 (mdw-define-face ediff-fine-diff-A
1714 (((min-colors 64)) :background "red3")
1715 (((class color)) :inverse-video t)
1716 (t :inverse-video nil))
1717 (mdw-define-face ediff-even-diff-A
1718 (((min-colors 64)) :background "#300"))
1719 (mdw-define-face ediff-odd-diff-A
1720 (((min-colors 64)) :background "#300"))
1721 (mdw-define-face ediff-current-diff-B
1722 (((min-colors 64)) :background "darkgreen")
1723 (((class color)) :background "magenta")
1724 (t :inverse-video t))
1725 (mdw-define-face ediff-fine-diff-B
1726 (((min-colors 64)) :background "green4")
1727 (((class color)) :inverse-video t)
1728 (t :inverse-video nil))
1729 (mdw-define-face ediff-even-diff-B
1730 (((min-colors 64)) :background "#020"))
1731 (mdw-define-face ediff-odd-diff-B
1732 (((min-colors 64)) :background "#020"))
1733 (mdw-define-face ediff-current-diff-C
1734 (((min-colors 64)) :background "darkblue")
1735 (((class color)) :background "blue")
1736 (t :inverse-video t))
1737 (mdw-define-face ediff-fine-diff-C
1738 (((min-colors 64)) :background "blue1")
1739 (((class color)) :inverse-video t)
1740 (t :inverse-video nil))
1741 (mdw-define-face ediff-even-diff-C
1742 (((min-colors 64)) :background "#004"))
1743 (mdw-define-face ediff-odd-diff-C
1744 (((min-colors 64)) :background "#004"))
1745 (mdw-define-face ediff-current-diff-Ancestor
1746 (((min-colors 64)) :background "#630")
1747 (((class color)) :background "blue")
1748 (t :inverse-video t))
1749 (mdw-define-face ediff-even-diff-Ancestor
1750 (((min-colors 64)) :background "#320"))
1751 (mdw-define-face ediff-odd-diff-Ancestor
1752 (((min-colors 64)) :background "#320"))
1754 (mdw-define-face magit-hash
1755 (((min-colors 64)) :foreground "grey40")
1756 (((class color)) :foreground "blue"))
1757 (mdw-define-face magit-diff-hunk-heading
1758 (((min-colors 64)) :foreground "grey70" :background "grey25")
1759 (((class color)) :foreground "yellow"))
1760 (mdw-define-face magit-diff-hunk-heading-highlight
1761 (((min-colors 64)) :foreground "grey70" :background "grey35")
1762 (((class color)) :foreground "yellow" :background "blue"))
1763 (mdw-define-face magit-diff-added
1764 (((min-colors 64)) :foreground "#ddffdd" :background "#335533")
1765 (((class color)) :foreground "green"))
1766 (mdw-define-face magit-diff-added-highlight
1767 (((min-colors 64)) :foreground "#cceecc" :background "#336633")
1768 (((class color)) :foreground "green" :background "blue"))
1769 (mdw-define-face magit-diff-removed
1770 (((min-colors 64)) :foreground "#ffdddd" :background "#553333")
1771 (((class color)) :foreground "red"))
1772 (mdw-define-face magit-diff-removed-highlight
1773 (((min-colors 64)) :foreground "#eecccc" :background "#663333")
1774 (((class color)) :foreground "red" :background "blue"))
1775 (mdw-define-face magit-blame-heading
1776 (((min-colors 64)) :foreground "white" :background "grey25"
1777 :weight normal :slant normal)
1778 (((class color)) :foreground "white" :background "blue"
1779 :weight normal :slant normal))
1780 (mdw-define-face magit-blame-name
1781 (t :inherit magit-blame-heading :slant italic))
1782 (mdw-define-face magit-blame-date
1783 (((min-colors 64)) :inherit magit-blame-heading :foreground "grey60")
1784 (((class color)) :inherit magit-blame-heading :foreground "cyan"))
1785 (mdw-define-face magit-blame-summary
1786 (t :inherit magit-blame-heading :weight bold))
1788 (mdw-define-face dylan-header-background
1789 (((min-colors 64)) :background "NavyBlue")
1790 (((class color)) :background "blue"))
1792 (mdw-define-face erc-input-face
1793 (t :foreground "red"))
1795 (mdw-define-face woman-bold
1797 (mdw-define-face woman-italic
1800 (eval-after-load "rst"
1802 (mdw-define-face rst-level-1-face
1803 (t :foreground "SkyBlue1" :weight bold))
1804 (mdw-define-face rst-level-2-face
1805 (t :foreground "SeaGreen1" :weight bold))
1806 (mdw-define-face rst-level-3-face
1808 (mdw-define-face rst-level-4-face
1810 (mdw-define-face rst-level-5-face
1812 (mdw-define-face rst-level-6-face
1815 (mdw-define-face p4-depot-added-face
1816 (t :foreground "green"))
1817 (mdw-define-face p4-depot-branch-op-face
1818 (t :foreground "yellow"))
1819 (mdw-define-face p4-depot-deleted-face
1820 (t :foreground "red"))
1821 (mdw-define-face p4-depot-unmapped-face
1822 (t :foreground "SkyBlue1"))
1823 (mdw-define-face p4-diff-change-face
1824 (t :foreground "yellow"))
1825 (mdw-define-face p4-diff-del-face
1826 (t :foreground "red"))
1827 (mdw-define-face p4-diff-file-face
1828 (t :foreground "SkyBlue1"))
1829 (mdw-define-face p4-diff-head-face
1830 (t :background "grey10"))
1831 (mdw-define-face p4-diff-ins-face
1832 (t :foreground "green"))
1834 (mdw-define-face w3m-anchor-face
1835 (t :foreground "SkyBlue1" :underline t))
1836 (mdw-define-face w3m-arrived-anchor-face
1837 (t :foreground "SkyBlue1" :underline t))
1839 (mdw-define-face whizzy-slice-face
1840 (t :background "grey10"))
1841 (mdw-define-face whizzy-error-face
1842 (t :background "darkred"))
1844 ;; Ellipses used to indicate hidden text (and similar).
1845 (mdw-define-face mdw-ellipsis-face
1846 (((type tty)) :foreground "blue") (t :foreground "grey60"))
1847 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
1848 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
1849 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
1850 (bar (make-glyph-code ?| mdw-ellipsis-face)))
1851 (set-display-table-slot standard-display-table 0 dollar)
1852 (set-display-table-slot standard-display-table 1 backslash)
1853 (set-display-table-slot standard-display-table 4
1854 (vector dot dot dot))
1855 (set-display-table-slot standard-display-table 5 bar))
1857 ;;;--------------------------------------------------------------------------
1860 (mdw-define-face mdw-point-overlay-face
1862 (((min-colors 64)) :background "darkblue")
1863 (((class color)) :background "blue")
1864 (((type tty) (class mono)) :inverse-video t))
1866 (defvar mdw-point-overlay-fringe-display '(vertical-bar . vertical-bar))
1868 (defun mdw-configure-point-overlay ()
1869 (let ((ov (make-overlay 0 0)))
1870 (overlay-put ov 'priority 0)
1871 (let* ((fringe (or mdw-point-overlay-fringe-display (cons nil nil)))
1872 (left (car fringe)) (right (cdr fringe))
1876 (put-text-property 0 1 'display `(left-fringe ,left) ss)
1877 (setq s (concat s ss))))
1880 (put-text-property 0 1 'display `(right-fringe ,right) ss)
1881 (setq s (concat s ss))))
1882 (when (or left right)
1883 (overlay-put ov 'before-string s)))
1884 (overlay-put ov 'face 'mdw-point-overlay-face)
1888 (defvar mdw-point-overlay (mdw-configure-point-overlay)
1889 "An overlay used for showing where point is in the selected window.")
1890 (defun mdw-reconfigure-point-overlay ()
1892 (setq mdw-point-overlay (mdw-configure-point-overlay)))
1894 (defun mdw-remove-point-overlay ()
1895 "Remove the current-point overlay."
1896 (delete-overlay mdw-point-overlay))
1898 (defun mdw-update-point-overlay ()
1899 "Mark the current point position with an overlay."
1900 (if (not mdw-point-overlay-mode)
1901 (mdw-remove-point-overlay)
1902 (overlay-put mdw-point-overlay 'window (selected-window))
1903 (move-overlay mdw-point-overlay
1904 (line-beginning-position)
1905 (+ (line-end-position) 1))))
1907 (defvar mdw-point-overlay-buffers nil
1908 "List of buffers using `mdw-point-overlay-mode'.")
1910 (define-minor-mode mdw-point-overlay-mode
1911 "Indicate current line with an overlay."
1913 (let ((buffer (current-buffer)))
1914 (setq mdw-point-overlay-buffers
1915 (mapcan (lambda (buf)
1916 (if (and (buffer-live-p buf)
1917 (not (eq buf buffer)))
1919 mdw-point-overlay-buffers))
1920 (if mdw-point-overlay-mode
1921 (setq mdw-point-overlay-buffers
1922 (cons buffer mdw-point-overlay-buffers))))
1923 (cond (mdw-point-overlay-buffers
1924 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
1925 (add-hook 'post-command-hook 'mdw-update-point-overlay))
1927 (mdw-remove-point-overlay)
1928 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
1929 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
1931 (define-globalized-minor-mode mdw-global-point-overlay-mode
1932 mdw-point-overlay-mode
1933 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
1935 (defvar mdw-terminal-title-alist nil)
1936 (defun mdw-update-terminal-title ()
1937 (when (let ((term (frame-parameter nil 'tty-type)))
1938 (and term (string-match "^xterm" term)))
1939 (let* ((tty (frame-parameter nil 'tty))
1940 (old (assoc tty mdw-terminal-title-alist))
1941 (new (format-mode-line frame-title-format)))
1942 (unless (and old (equal (cdr old) new))
1943 (if old (rplacd old new)
1944 (setq mdw-terminal-title-alist
1945 (cons (cons tty new) mdw-terminal-title-alist)))
1946 (send-string-to-terminal (concat "\e]2;" new "\e\\"))))))
1948 (add-hook 'post-command-hook 'mdw-update-terminal-title)
1950 ;;;--------------------------------------------------------------------------
1951 ;;; C programming configuration.
1953 ;; Make C indentation nice.
1955 (defun mdw-c-lineup-arglist (langelem)
1956 "Hack for DWIMmery in c-lineup-arglist."
1958 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1960 (c-lineup-arglist langelem)))
1962 (defun mdw-c-indent-extern-mumble (langelem)
1963 "Indent `extern \"...\" {' lines."
1965 (back-to-indentation)
1967 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1971 (defun mdw-c-indent-arglist-nested (langelem)
1972 "Indent continued argument lists.
1973 If we've nested more than one argument list, then only introduce a single
1974 indentation anyway."
1975 (let ((context c-syntactic-context)
1976 (pos (c-langelem-2nd-pos c-syntactic-element))
1977 (should-indent-p t))
1979 (eq (caar context) 'arglist-cont-nonempty))
1980 (when (and (= (caddr (pop context)) pos)
1982 (memq (caar context) '(arglist-intro
1983 arglist-cont-nonempty)))
1984 (setq should-indent-p nil)))
1985 (if should-indent-p '+ 0)))
1987 (defvar mdw-define-c-styles-hook nil
1988 "Hook run when `cc-mode' starts up to define styles.")
1990 (defun mdw-merge-style-alists (first second)
1992 (dolist (item first)
1993 (let ((key (car item)) (value (cdr item)))
1994 (if (string-suffix-p "-alist" (symbol-name key))
1996 (mdw-merge-style-alists value
1997 (cdr (assoc key second))))
1999 (push item output))))
2000 (dolist (item second)
2001 (unless (assoc (car item) first)
2002 (push item output)))
2005 (cl-defmacro mdw-define-c-style (name (&optional parent) &rest assocs)
2006 "Define a C style, called NAME (a symbol) based on PARENT, setting ASSOCs.
2007 A function, named `mdw-define-c-style/NAME', is defined to actually install
2008 the style using `c-add-style', and added to the hook
2009 `mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
2011 (declare (indent defun))
2012 (let* ((name-string (symbol-name name))
2013 (var (intern (concat "mdw-c-style/" name-string)))
2014 (func (intern (concat "mdw-define-c-style/" name-string))))
2019 (let ((parent-list (intern (concat "mdw-c-style/"
2020 (symbol-name parent)))))
2021 `(mdw-merge-style-alists ',assocs ,parent-list))))
2022 (defun ,func () (c-add-style ,name-string ,var))
2023 (and (featurep 'cc-mode) (,func))
2024 (add-hook 'mdw-define-c-styles-hook ',func)
2027 (eval-after-load "cc-mode"
2028 '(run-hooks 'mdw-define-c-styles-hook))
2030 (mdw-define-c-style mdw-c ()
2031 (c-basic-offset . 2)
2032 (comment-column . 40)
2033 (c-class-key . "class")
2034 (c-backslash-column . 72)
2035 (c-label-minimum-indentation . 0)
2036 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
2037 (defun-open . (add 0 c-indent-one-line-block))
2038 (arglist-cont-nonempty . mdw-c-lineup-arglist)
2039 (topmost-intro . mdw-c-indent-extern-mumble)
2040 (cpp-define-intro . 0)
2042 (inextern-lang . [0])
2048 (statement-cont . +)
2049 (statement-case-intro . +)))
2051 (mdw-define-c-style mdw-trustonic-basic-c (mdw-c)
2052 (c-basic-offset . 4)
2053 (comment-column . 0)
2054 (c-indent-comment-alist (anchored-comment . (column . 0))
2055 (end-block . (space . 1))
2056 (cpp-end-block . (space . 1))
2057 (other . (space . 1)))
2058 (c-offsets-alist (access-label . -2)))
2060 (mdw-define-c-style mdw-trustonic-c (mdw-trustonic-basic-c)
2061 (c-offsets-alist (arglist-cont-nonempty . mdw-c-indent-arglist-nested)))
2063 (defun mdw-set-default-c-style (modes style)
2064 "Update the default CC Mode style for MODES to be STYLE.
2066 MODES may be a list of major mode names or a singleton. STYLE is a style
2068 (let ((modes (if (listp modes) modes (list modes)))
2069 (style (symbol-name style)))
2070 (setq c-default-style
2071 (append (mapcar (lambda (mode)
2074 (remove-if (lambda (assoc)
2075 (memq (car assoc) modes))
2076 (if (listp c-default-style)
2078 (list (cons 'other c-default-style))))))))
2079 (setq c-default-style "mdw-c")
2081 (mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
2083 (defvar mdw-c-comment-fill-prefix
2084 `((,(concat "\\([ \t]*/?\\)"
2087 "\\([A-Za-z]+:[ \t]*\\)?"
2088 mdw-hanging-indents)
2089 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
2090 "Fill prefix matching C comments (both kinds).")
2092 (defun mdw-fontify-c-and-c++ ()
2094 ;; Fiddle with some syntax codes.
2095 (modify-syntax-entry ?* ". 23")
2096 (modify-syntax-entry ?/ ". 124b")
2097 (modify-syntax-entry ?\n "> b")
2100 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2102 ;; Now define things to be fontified.
2103 (make-local-variable 'font-lock-keywords)
2105 (mdw-regexps "alignas" ;C11 macro, C++11
2107 "and" ;C++, C95 macro
2108 "and_eq" ;C++, C95 macro
2109 "asm" ;K&R, C++, GCC
2110 "atomic" ;C11 macro, C++11 template type
2112 "bitand" ;C++, C95 macro
2113 "bitor" ;C++, C95 macro
2114 "bool" ;C++, C99 macro
2119 "char16_t" ;C++11, C11 library type
2120 "char32_t" ;C++11, C11 library type
2122 "complex" ;C99 macro, C++ template type
2123 "compl" ;C++, C95 macro
2127 "continue" ;K&R, C89
2129 "defined" ;C89 preprocessor
2136 ;; "entry" ;K&R -- never used
2147 "imaginary" ;C99 macro
2148 "inline" ;C++, C99, GCC
2155 "noreturn" ;C11 macro
2156 "not" ;C++, C95 macro
2157 "not_eq" ;C++, C95 macro
2160 "or" ;C++, C95 macro
2161 "or_eq" ;C++, C95 macro
2165 "register" ;K&R, C89
2166 "reinterpret_cast" ;C++
2173 "static_assert" ;C11 macro, C++11
2180 "thread_local" ;C11 macro, C++11
2186 "unsigned" ;K&R, C89
2191 "wchar_t" ;C++, C89 library type
2193 "xor" ;C++, C95 macro
2194 "xor_eq" ;C++, C95 macro
2203 "_Pragma" ;C99 preprocessor
2204 "_Static_assert" ;C11
2205 "_Thread_local" ;C11
2208 "__attribute__" ;GCC
2211 "__extension__" ;GCC
2221 (mdw-regexps "false" ;C++, C99 macro
2223 "true" ;C++, C99 macro
2225 (preprocessor-keywords
2226 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2227 "ident" "if" "ifdef" "ifndef" "import" "include"
2228 "line" "pragma" "unassert" "undef" "warning"))
2230 (mdw-regexps "class" "defs" "encode" "end" "implementation"
2231 "interface" "private" "protected" "protocol" "public"
2234 (setq font-lock-keywords
2237 ;; Fontify include files as strings.
2238 (list (concat "^[ \t]*\\#[ \t]*"
2239 "\\(include\\|import\\)"
2240 "[ \t]*\\(<[^>]+>?\\)")
2241 '(2 font-lock-string-face))
2243 ;; Preprocessor directives are `references'?.
2244 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2245 preprocessor-keywords
2246 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2247 '(1 font-lock-keyword-face))
2249 ;; Handle the keywords defined above.
2250 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
2251 '(0 font-lock-keyword-face))
2253 (list (concat "\\<\\(" c-keywords "\\)\\>")
2254 '(0 font-lock-keyword-face))
2256 (list (concat "\\<\\(" c-builtins "\\)\\>")
2257 '(0 font-lock-variable-name-face))
2259 ;; Handle numbers too.
2261 ;; This looks strange, I know. It corresponds to the
2262 ;; preprocessor's idea of what a number looks like, rather than
2263 ;; anything sensible.
2264 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2265 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2266 '(0 mdw-number-face))
2268 ;; And anything else is punctuation.
2269 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2270 '(0 mdw-punct-face))))))
2272 (define-derived-mode sod-mode c-mode "Sod"
2273 "Major mode for editing Sod code.")
2274 (push '("\\.sod$" . sod-mode) auto-mode-alist)
2276 (dolist (hook '(c-mode-hook objc-mode-hook c++-mode-hook))
2277 (add-hook hook 'mdw-misc-mode-config t)
2278 (add-hook hook 'mdw-fontify-c-and-c++ t))
2280 ;;;--------------------------------------------------------------------------
2283 (define-derived-mode apcalc-mode c-mode "AP Calc"
2284 "Major mode for editing Calc code.")
2286 (defun mdw-fontify-apcalc ()
2288 ;; Fiddle with some syntax codes.
2289 (modify-syntax-entry ?* ". 23")
2290 (modify-syntax-entry ?/ ". 14")
2293 (setq comment-start "/* ")
2294 (setq comment-end " */")
2295 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2297 ;; Now define things to be fontified.
2298 (make-local-variable 'font-lock-keywords)
2300 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
2301 "do" "else" "exit" "for" "global" "goto" "help" "if"
2302 "local" "mat" "obj" "print" "quit" "read" "return"
2303 "show" "static" "switch" "while" "write")))
2305 (setq font-lock-keywords
2308 ;; Handle the keywords defined above.
2309 (list (concat "\\<\\(" c-keywords "\\)\\>")
2310 '(0 font-lock-keyword-face))
2312 ;; Handle numbers too.
2314 ;; This looks strange, I know. It corresponds to the
2315 ;; preprocessor's idea of what a number looks like, rather than
2316 ;; anything sensible.
2317 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2318 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2319 '(0 mdw-number-face))
2321 ;; And anything else is punctuation.
2322 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2323 '(0 mdw-punct-face))))))
2326 (add-hook 'apcalc-mode-hook 'mdw-misc-mode-config t)
2327 (add-hook 'apcalc-mode-hook 'mdw-fontify-apcalc t))
2329 ;;;--------------------------------------------------------------------------
2330 ;;; Java programming configuration.
2332 ;; Make indentation nice.
2334 (mdw-define-c-style mdw-java ()
2335 (c-basic-offset . 2)
2336 (c-backslash-column . 72)
2337 (c-offsets-alist (substatement-open . 0)
2342 (statement-case-intro . +)))
2343 (mdw-set-default-c-style 'java-mode 'mdw-java)
2345 ;; Declare Java fontification style.
2347 (defun mdw-fontify-java ()
2349 ;; Fiddle with some syntax codes.
2350 (modify-syntax-entry ?@ ".")
2351 (modify-syntax-entry ?@ "." font-lock-syntax-table)
2354 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2356 ;; Now define things to be fontified.
2357 (make-local-variable 'font-lock-keywords)
2358 (let ((java-keywords
2359 (mdw-regexps "abstract" "assert"
2360 "boolean" "break" "byte"
2361 "case" "catch" "char" "class" "const" "continue"
2362 "default" "do" "double"
2363 "else" "enum" "extends"
2364 "final" "finally" "float" "for"
2366 "if" "implements" "import" "instanceof" "int"
2370 "package" "private" "protected" "public"
2372 "short" "static" "strictfp" "switch" "synchronized"
2373 "throw" "throws" "transient" "try"
2378 (mdw-regexps "false" "null" "super" "this" "true")))
2380 (setq font-lock-keywords
2383 ;; Handle the keywords defined above.
2384 (list (concat "\\<\\(" java-keywords "\\)\\>")
2385 '(0 font-lock-keyword-face))
2387 ;; Handle the magic builtins defined above.
2388 (list (concat "\\<\\(" java-builtins "\\)\\>")
2389 '(0 font-lock-variable-name-face))
2391 ;; Handle numbers too.
2393 ;; The following isn't quite right, but it's close enough.
2394 (list (concat "\\<\\("
2395 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2396 "[0-9]+\\(\\.[0-9]*\\)?"
2397 "\\([eE][-+]?[0-9]+\\)?\\)"
2399 '(0 mdw-number-face))
2401 ;; And anything else is punctuation.
2402 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2403 '(0 mdw-punct-face))))))
2406 (add-hook 'java-mode-hook 'mdw-misc-mode-config t)
2407 (add-hook 'java-mode-hook 'mdw-fontify-java t))
2409 ;;;--------------------------------------------------------------------------
2410 ;;; Javascript programming configuration.
2412 (defun mdw-javascript-style ()
2413 (setq js-indent-level 2)
2414 (setq js-expr-indent-offset 0))
2416 (defun mdw-fontify-javascript ()
2419 (mdw-javascript-style)
2420 (setq js-auto-indent-flag t)
2422 ;; Now define things to be fontified.
2423 (make-local-variable 'font-lock-keywords)
2424 (let ((javascript-keywords
2425 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
2426 "char" "class" "const" "continue" "debugger" "default"
2427 "delete" "do" "double" "else" "enum" "export" "extends"
2428 "final" "finally" "float" "for" "function" "goto" "if"
2429 "implements" "import" "in" "instanceof" "int"
2430 "interface" "let" "long" "native" "new" "package"
2431 "private" "protected" "public" "return" "short"
2432 "static" "super" "switch" "synchronized" "throw"
2433 "throws" "transient" "try" "typeof" "var" "void"
2434 "volatile" "while" "with" "yield"))
2435 (javascript-builtins
2436 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
2437 "arguments" "this")))
2439 (setq font-lock-keywords
2442 ;; Handle the keywords defined above.
2443 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
2444 '(0 font-lock-keyword-face))
2446 ;; Handle the predefined builtins defined above.
2447 (list (concat "\\_<\\(" javascript-builtins "\\)\\_>")
2448 '(0 font-lock-variable-name-face))
2450 ;; Handle numbers too.
2452 ;; The following isn't quite right, but it's close enough.
2453 (list (concat "\\_<\\("
2454 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2455 "[0-9]+\\(\\.[0-9]*\\)?"
2456 "\\([eE][-+]?[0-9]+\\)?\\)"
2458 '(0 mdw-number-face))
2460 ;; And anything else is punctuation.
2461 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2462 '(0 mdw-punct-face))))))
2465 (add-hook 'js-mode-hook 'mdw-misc-mode-config t)
2466 (add-hook 'js-mode-hook 'mdw-fontify-javascript t))
2468 ;;;--------------------------------------------------------------------------
2469 ;;; Scala programming configuration.
2471 (defun mdw-fontify-scala ()
2474 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2476 ;; Define things to be fontified.
2477 (make-local-variable 'font-lock-keywords)
2478 (let ((scala-keywords
2479 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
2480 "extends" "final" "finally" "for" "forSome" "if"
2481 "implicit" "import" "lazy" "match" "new" "object"
2482 "override" "package" "private" "protected" "return"
2483 "sealed" "throw" "trait" "try" "type" "val"
2484 "var" "while" "with" "yield"))
2486 (mdw-regexps "false" "null" "super" "this" "true"))
2487 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
2489 (setq font-lock-keywords
2492 ;; Magical identifiers between backticks.
2493 (list (concat "`\\([^`]+\\)`")
2494 '(1 font-lock-variable-name-face))
2496 ;; Handle the keywords defined above.
2497 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
2498 '(0 font-lock-keyword-face))
2500 ;; Handle the constants defined above.
2501 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
2502 '(0 font-lock-variable-name-face))
2504 ;; Magical identifiers between backticks.
2505 (list (concat "`\\([^`]+\\)`")
2506 '(1 font-lock-variable-name-face))
2508 ;; Handle numbers too.
2510 ;; As usual, not quite right.
2511 (list (concat "\\_<\\("
2512 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2513 "[0-9]+\\(\\.[0-9]*\\)?"
2514 "\\([eE][-+]?[0-9]+\\)?\\)"
2516 '(0 mdw-number-face))
2518 ;; And everything else is punctuation.
2519 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2520 '(0 mdw-punct-face)))
2522 font-lock-syntactic-keywords
2525 ;; Single quotes around characters. But not when used to quote
2526 ;; symbol names. Ugh.
2527 (list (concat "\\('\\)"
2529 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
2530 "u+" "[0-9a-fA-F]\\{4\\}"
2531 "\\|" "\\\\" "[0-7]\\{1,3\\}"
2532 "\\|" "\\\\" "." "\\)"
2538 (add-hook 'scala-mode-hook 'mdw-misc-mode-config t)
2539 (add-hook 'scala-mode-hook 'mdw-fontify-scala t))
2541 ;;;--------------------------------------------------------------------------
2542 ;;; C# programming configuration.
2544 ;; Make indentation nice.
2546 (mdw-define-c-style mdw-csharp ()
2547 (c-basic-offset . 2)
2548 (c-backslash-column . 72)
2549 (c-offsets-alist (substatement-open . 0)
2554 (statement-case-intro . +)))
2555 (mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
2557 ;; Declare C# fontification style.
2559 (defun mdw-fontify-csharp ()
2562 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2564 ;; Now define things to be fontified.
2565 (make-local-variable 'font-lock-keywords)
2566 (let ((csharp-keywords
2567 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
2568 "char" "checked" "class" "const" "continue" "decimal"
2569 "default" "delegate" "do" "double" "else" "enum"
2570 "event" "explicit" "extern" "finally" "fixed" "float"
2571 "for" "foreach" "goto" "if" "implicit" "in" "int"
2572 "interface" "internal" "is" "lock" "long" "namespace"
2573 "new" "object" "operator" "out" "override" "params"
2574 "private" "protected" "public" "readonly" "ref"
2575 "return" "sbyte" "sealed" "short" "sizeof"
2576 "stackalloc" "static" "string" "struct" "switch"
2577 "throw" "try" "typeof" "uint" "ulong" "unchecked"
2578 "unsafe" "ushort" "using" "virtual" "void" "volatile"
2582 (mdw-regexps "base" "false" "null" "this" "true")))
2584 (setq font-lock-keywords
2587 ;; Handle the keywords defined above.
2588 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
2589 '(0 font-lock-keyword-face))
2591 ;; Handle the magic builtins defined above.
2592 (list (concat "\\<\\(" csharp-builtins "\\)\\>")
2593 '(0 font-lock-variable-name-face))
2595 ;; Handle numbers too.
2597 ;; The following isn't quite right, but it's close enough.
2598 (list (concat "\\<\\("
2599 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2600 "[0-9]+\\(\\.[0-9]*\\)?"
2601 "\\([eE][-+]?[0-9]+\\)?\\)"
2603 '(0 mdw-number-face))
2605 ;; And anything else is punctuation.
2606 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2607 '(0 mdw-punct-face))))))
2609 (define-derived-mode csharp-mode java-mode "C#"
2610 "Major mode for editing C# code.")
2612 (add-hook 'csharp-mode-hook 'mdw-fontify-csharp t)
2614 ;;;--------------------------------------------------------------------------
2615 ;;; F# programming configuration.
2617 (setq fsharp-indent-offset 2)
2619 (defun mdw-fontify-fsharp ()
2621 (let ((punct "=<>+-*/|&%!@?"))
2623 ((>= i (length punct)))
2624 (modify-syntax-entry (aref punct i) ".")))
2626 (modify-syntax-entry ?_ "_")
2627 (modify-syntax-entry ?( "(")
2628 (modify-syntax-entry ?) ")")
2630 (setq indent-tabs-mode nil)
2632 (let ((fsharp-keywords
2633 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
2635 "checked" "class" "component" "const" "constraint"
2636 "constructor" "continue"
2637 "default" "delegate" "do" "done" "downcast" "downto"
2638 "eager" "elif" "else" "end" "exception" "extern"
2639 "finally" "fixed" "for" "fori" "fun" "function"
2642 "if" "in" "include" "inherit" "inline" "interface"
2645 "match" "measure" "member" "method" "mixin" "module"
2648 "object" "of" "open" "or" "override"
2649 "parallel" "params" "private" "process" "protected"
2651 "rec" "recursive" "return"
2652 "sealed" "sig" "static" "struct"
2653 "tailcall" "then" "to" "trait" "try" "type"
2655 "val" "virtual" "void" "volatile"
2656 "when" "while" "with"
2660 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
2661 "base" "false" "null" "true"))
2664 (mdw-regexps "do" "let" "return" "use" "yield"))
2666 (preprocessor-keywords
2667 (mdw-regexps "if" "indent" "else" "endif")))
2669 (setq font-lock-keywords
2670 (list (list (concat "\\(^\\|[^\"]\\)"
2673 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
2678 '(2 font-lock-comment-face))
2680 (list (concat "'" "\\("
2683 "\\|" "[0-9][0-9][0-9]"
2684 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
2685 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
2691 "\\(" "\\\\" "\\(.\\|\n\\)"
2694 '(0 font-lock-string-face))
2696 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
2697 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
2699 "\\_<\\(" fsharp-keywords "\\)\\_>")
2700 '(0 font-lock-keyword-face))
2701 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
2702 '(0 font-lock-variable-name-face))
2704 (list (concat "\\_<"
2705 "\\(" "0[bB][01]+" "\\|"
2707 "0[xX][0-9a-fA-F]+" "\\)"
2708 "\\(" "lf\\|LF" "\\|"
2709 "[uU]?[ysnlL]?" "\\)"
2716 "\\([eE][-+]?[0-9]+\\)?"
2721 '(0 mdw-number-face))
2723 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2724 '(0 mdw-punct-face))))))
2726 (defun mdw-fontify-inferior-fsharp ()
2727 (mdw-fontify-fsharp)
2728 (setq font-lock-keywords
2729 (append (list (list "^[#-]" '(0 font-lock-comment-face))
2730 (list "^>" '(0 font-lock-keyword-face)))
2731 font-lock-keywords)))
2734 (add-hook 'fsharp-mode-hook 'mdw-misc-mode-config t)
2735 (add-hook 'fsharp-mode-hook 'mdw-fontify-fsharp t)
2736 (add-hook 'inferior-fsharp-mode-hooks 'mdw-fontify-inferior-fsharp t))
2738 ;;;--------------------------------------------------------------------------
2739 ;;; Go programming configuration.
2741 (defun mdw-fontify-go ()
2743 (make-local-variable 'font-lock-keywords)
2745 (mdw-regexps "break" "case" "chan" "const" "continue"
2746 "default" "defer" "else" "fallthrough" "for"
2747 "func" "go" "goto" "if" "import"
2748 "interface" "map" "package" "range" "return"
2749 "select" "struct" "switch" "type" "var"))
2751 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
2752 "float32" "float64" "int" "uint8" "int16" "int32"
2753 "int64" "rune" "string" "uint" "uint8" "uint16"
2754 "uint32" "uint64" "uintptr" "void"
2755 "false" "iota" "nil" "true"
2757 "append" "cap" "copy" "delete" "imag" "len" "make"
2758 "new" "panic" "real" "recover")))
2760 (setq font-lock-keywords
2763 ;; Handle the keywords defined above.
2764 (list (concat "\\<\\(" go-keywords "\\)\\>")
2765 '(0 font-lock-keyword-face))
2766 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
2767 '(0 font-lock-variable-name-face))
2769 ;; Strings and characters.
2771 "\\(" "[^\\']" "\\|"
2773 "\\(" "[abfnrtv\\'\"]" "\\|"
2774 "[0-7]\\{3\\}" "\\|"
2775 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
2776 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
2777 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
2781 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
2785 '(0 font-lock-string-face))
2787 ;; Handle numbers too.
2789 ;; The following isn't quite right, but it's close enough.
2790 (list (concat "\\<\\("
2791 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2792 "[0-9]+\\(\\.[0-9]*\\)?"
2793 "\\([eE][-+]?[0-9]+\\)?\\)")
2794 '(0 mdw-number-face))
2796 ;; And anything else is punctuation.
2797 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2798 '(0 mdw-punct-face))))))
2800 (add-hook 'go-mode-hook 'mdw-misc-mode-config t)
2801 (add-hook 'go-mode-hook 'mdw-fontify-go t))
2803 ;;;--------------------------------------------------------------------------
2804 ;;; Rust programming configuration.
2806 (setq-default rust-indent-offset 2)
2808 (defun mdw-self-insert-and-indent (count)
2810 (self-insert-command count)
2811 (indent-according-to-mode))
2813 (defun mdw-fontify-rust ()
2815 ;; Hack syntax categories.
2816 (modify-syntax-entry ?$ ".")
2817 (modify-syntax-entry ?% ".")
2818 (modify-syntax-entry ?= ".")
2820 ;; Fontify keywords and things.
2821 (make-local-variable 'font-lock-keywords)
2822 (let ((rust-keywords
2823 (mdw-regexps "abstract" "alignof" "as" "async" "await"
2824 "become" "box" "break"
2825 "const" "continue" "crate"
2827 "else" "enum" "extern"
2831 "macro" "match" "mod" "move" "mut"
2832 "offsetof" "override"
2833 "priv" "proc" "pub" "pure"
2835 "sizeof" "static" "struct" "super"
2836 "trait" "try" "type" "typeof"
2837 "union" "unsafe" "unsized" "use"
2842 (mdw-regexps "array" "pointer" "slice" "tuple"
2843 "bool" "true" "false"
2845 "i8" "i16" "i32" "i64" "isize"
2846 "u8" "u16" "u32" "u64" "usize"
2849 (setq font-lock-keywords
2852 ;; Handle the keywords defined above.
2853 (list (concat "\\_<\\(" rust-keywords "\\)\\_>")
2854 '(0 font-lock-keyword-face))
2855 (list (concat "\\_<\\(" rust-builtins "\\)\\_>")
2856 '(0 font-lock-variable-name-face))
2858 ;; Handle numbers too.
2859 (list (concat "\\_<\\("
2861 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
2865 "\\|" "\\(" "[0-9][0-9_]*"
2866 "\\|" "0x[0-9a-fA-F_]+"
2870 "\\([ui]\\(8\\|16\\|32\\|64\\|size\\)\\)?"
2872 '(0 mdw-number-face))
2874 ;; And anything else is punctuation.
2875 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2876 '(0 mdw-punct-face)))))
2878 ;; Hack key bindings.
2879 (local-set-key [?{] 'mdw-self-insert-and-indent)
2880 (local-set-key [?}] 'mdw-self-insert-and-indent))
2883 (add-hook 'rust-mode-hook 'mdw-misc-mode-config t)
2884 (add-hook 'rust-mode-hook 'mdw-fontify-rust t))
2886 ;;;--------------------------------------------------------------------------
2887 ;;; Awk programming configuration.
2889 ;; Make Awk indentation nice.
2891 (mdw-define-c-style mdw-awk ()
2892 (c-basic-offset . 2)
2893 (c-offsets-alist (substatement-open . 0)
2894 (c-backslash-column . 72)
2895 (statement-cont . 0)
2896 (statement-case-intro . +)))
2897 (mdw-set-default-c-style 'awk-mode 'mdw-awk)
2899 ;; Declare Awk fontification style.
2901 (defun mdw-fontify-awk ()
2903 ;; Miscellaneous fiddling.
2904 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2906 ;; Now define things to be fontified.
2907 (make-local-variable 'font-lock-keywords)
2909 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
2910 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
2911 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
2912 "RSTART" "RLENGTH" "RT" "SUBSEP"
2913 "atan2" "break" "close" "continue" "cos" "delete"
2914 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
2915 "function" "gensub" "getline" "gsub" "if" "in"
2916 "index" "int" "length" "log" "match" "next" "rand"
2917 "return" "print" "printf" "sin" "split" "sprintf"
2918 "sqrt" "srand" "strftime" "sub" "substr" "system"
2919 "systime" "tolower" "toupper" "while")))
2921 (setq font-lock-keywords
2924 ;; Handle the keywords defined above.
2925 (list (concat "\\<\\(" c-keywords "\\)\\>")
2926 '(0 font-lock-keyword-face))
2928 ;; Handle numbers too.
2930 ;; The following isn't quite right, but it's close enough.
2931 (list (concat "\\<\\("
2932 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2933 "[0-9]+\\(\\.[0-9]*\\)?"
2934 "\\([eE][-+]?[0-9]+\\)?\\)"
2936 '(0 mdw-number-face))
2938 ;; And anything else is punctuation.
2939 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2940 '(0 mdw-punct-face))))))
2943 (add-hook 'awk-mode-hook 'mdw-misc-mode-config t)
2944 (add-hook 'awk-mode-hook 'mdw-fontify-awk t))
2946 ;;;--------------------------------------------------------------------------
2947 ;;; Perl programming style.
2949 ;; Perl indentation style.
2951 (setq-default perl-indent-level 2)
2953 (setq-default cperl-indent-level 2
2954 cperl-continued-statement-offset 2
2955 cperl-continued-brace-offset 0
2956 cperl-brace-offset -2
2957 cperl-brace-imaginary-offset 0
2958 cperl-label-offset 0)
2960 ;; Define perl fontification style.
2962 (defun mdw-fontify-perl ()
2964 ;; Miscellaneous fiddling.
2965 (modify-syntax-entry ?$ "\\")
2966 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
2967 (modify-syntax-entry ?: "." font-lock-syntax-table)
2968 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2970 ;; Now define fontification things.
2971 (make-local-variable 'font-lock-keywords)
2972 (let ((perl-keywords
2979 "ge" "given" "gt" "goto"
2981 "last" "le" "local" "lt"
2986 "redo" "require" "return"
2988 "undef" "unless" "until" "use"
2991 (setq font-lock-keywords
2994 ;; Set up the keywords defined above.
2995 (list (concat "\\<\\(" perl-keywords "\\)\\>")
2996 '(0 font-lock-keyword-face))
2998 ;; At least numbers are simpler than C.
2999 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3000 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
3001 "\\([eE][-+]?[0-9_]+\\)?")
3002 '(0 mdw-number-face))
3004 ;; And anything else is punctuation.
3005 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3006 '(0 mdw-punct-face))))))
3008 (defun perl-number-tests (&optional arg)
3009 "Assign consecutive numbers to lines containing `#t'. With ARG,
3010 strip numbers instead."
3013 (goto-char (point-min))
3014 (let ((i 0) (fmt (if arg "" " %4d")))
3015 (while (search-forward "#t" nil t)
3016 (delete-region (point) (line-end-position))
3018 (insert (format fmt i)))
3019 (goto-char (point-min))
3020 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
3021 (replace-match (format "\\1%d" i))))))
3023 (dolist (hook '(perl-mode-hook cperl-mode-hook))
3024 (add-hook hook 'mdw-misc-mode-config t)
3025 (add-hook hook 'mdw-fontify-perl t))
3027 ;;;--------------------------------------------------------------------------
3028 ;;; Python programming style.
3030 (setq-default py-indent-offset 2
3032 python-indent-offset 2
3033 python-fill-docstring-style 'symmetric)
3035 (defun mdw-fontify-pythonic (keywords)
3037 ;; Miscellaneous fiddling.
3038 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3039 (setq indent-tabs-mode nil)
3041 ;; Now define fontification things.
3042 (make-local-variable 'font-lock-keywords)
3043 (setq font-lock-keywords
3046 ;; Set up the keywords defined above.
3047 (list (concat "\\_<\\(" keywords "\\)\\_>")
3048 '(0 font-lock-keyword-face))
3050 ;; At least numbers are simpler than C.
3051 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO]?[0-7]+\\|[bB][01]+\\)\\|"
3052 "\\_<[0-9][0-9]*\\(\\.[0-9]*\\)?"
3053 "\\([eE][-+]?[0-9]+\\|[lL]\\)?")
3054 '(0 mdw-number-face))
3056 ;; And anything else is punctuation.
3057 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3058 '(0 mdw-punct-face)))))
3060 ;; Define Python fontification styles.
3062 (defun mdw-fontify-python ()
3063 (mdw-fontify-pythonic
3064 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
3065 "del" "elif" "else" "except" "exec" "finally" "for"
3066 "from" "global" "if" "import" "in" "is" "lambda"
3067 "not" "or" "pass" "print" "raise" "return" "try"
3068 "while" "with" "yield")))
3070 (defun mdw-fontify-pyrex ()
3071 (mdw-fontify-pythonic
3072 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
3073 "ctypedef" "def" "del" "elif" "else" "enum" "except" "exec"
3074 "extern" "finally" "for" "from" "global" "if"
3075 "import" "in" "is" "lambda" "not" "or" "pass" "print"
3076 "property" "raise" "return" "struct" "try" "while" "with"
3079 (define-derived-mode pyrex-mode python-mode "Pyrex"
3080 "Major mode for editing Pyrex source code")
3081 (setq auto-mode-alist
3082 (append '(("\\.pyx$" . pyrex-mode)
3083 ("\\.pxd$" . pyrex-mode)
3084 ("\\.pxi$" . pyrex-mode))
3088 (add-hook 'python-mode-hook 'mdw-misc-mode-config t)
3089 (add-hook 'python-mode-hook 'mdw-fontify-python t)
3090 (add-hook 'pyrex-mode-hook 'mdw-fontify-pyrex t))
3092 ;;;--------------------------------------------------------------------------
3093 ;;; Lua programming style.
3095 (setq-default lua-indent-level 2)
3097 (defun mdw-fontify-lua ()
3099 ;; Miscellaneous fiddling.
3100 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3102 ;; Now define fontification things.
3103 (make-local-variable 'font-lock-keywords)
3105 (mdw-regexps "and" "break" "do" "else" "elseif" "end"
3106 "false" "for" "function" "goto" "if" "in" "local"
3107 "nil" "not" "or" "repeat" "return" "then" "true"
3109 (setq font-lock-keywords
3112 ;; Set up the keywords defined above.
3113 (list (concat "\\_<\\(" lua-keywords "\\)\\_>")
3114 '(0 font-lock-keyword-face))
3116 ;; At least numbers are simpler than C.
3117 (list (concat "\\_<\\(" "0[xX]"
3118 "\\(" "[0-9a-fA-F]+"
3119 "\\(\\.[0-9a-fA-F]*\\)?"
3120 "\\|" "\\.[0-9a-fA-F]+"
3122 "\\([pP][-+]?[0-9]+\\)?"
3123 "\\|" "\\(" "[0-9]+"
3127 "\\([eE][-+]?[0-9]+\\)?"
3129 '(0 mdw-number-face))
3131 ;; And anything else is punctuation.
3132 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3133 '(0 mdw-punct-face))))))
3136 (add-hook 'lua-mode-hook 'mdw-misc-mode-config t)
3137 (add-hook 'lua-mode-hook 'mdw-fontify-lua t))
3139 ;;;--------------------------------------------------------------------------
3140 ;;; Icon programming style.
3142 ;; Icon indentation style.
3144 (setq-default icon-brace-offset 0
3145 icon-continued-brace-offset 0
3146 icon-continued-statement-offset 2
3147 icon-indent-level 2)
3149 ;; Define Icon fontification style.
3151 (defun mdw-fontify-icon ()
3153 ;; Miscellaneous fiddling.
3154 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3156 ;; Now define fontification things.
3157 (make-local-variable 'font-lock-keywords)
3158 (let ((icon-keywords
3159 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
3160 "end" "every" "fail" "global" "if" "initial"
3161 "invocable" "link" "local" "next" "not" "of"
3162 "procedure" "record" "repeat" "return" "static"
3163 "suspend" "then" "to" "until" "while"))
3164 (preprocessor-keywords
3165 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
3166 "include" "line" "undef")))
3167 (setq font-lock-keywords
3170 ;; Set up the keywords defined above.
3171 (list (concat "\\<\\(" icon-keywords "\\)\\>")
3172 '(0 font-lock-keyword-face))
3174 ;; The things that Icon calls keywords.
3175 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
3177 ;; At least numbers are simpler than C.
3178 (list (concat "\\<[0-9]+"
3179 "\\([rR][0-9a-zA-Z]+\\|"
3180 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
3181 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
3182 '(0 mdw-number-face))
3185 (list (concat "^[ \t]*$[ \t]*\\<\\("
3186 preprocessor-keywords
3188 '(0 font-lock-keyword-face))
3190 ;; And anything else is punctuation.
3191 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3192 '(0 mdw-punct-face))))))
3195 (add-hook 'icon-mode-hook 'mdw-misc-mode-config t)
3196 (add-hook 'icon-mode-hook 'mdw-fontify-icon t))
3198 ;;;--------------------------------------------------------------------------
3201 (defun mdw-fontify-asm ()
3202 (modify-syntax-entry ?' "\"")
3203 (modify-syntax-entry ?. "w")
3204 (modify-syntax-entry ?\n ">")
3205 (setf fill-prefix nil)
3206 (modify-syntax-entry ?. "_")
3207 (modify-syntax-entry ?* ". 23")
3208 (modify-syntax-entry ?/ ". 124b")
3209 (modify-syntax-entry ?\n "> b")
3210 (local-set-key ";" 'self-insert-command)
3211 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
3213 (defun mdw-asm-set-comment ()
3214 (modify-syntax-entry ?; "."
3216 (modify-syntax-entry asm-comment-char "< b")
3217 (setq comment-start (string asm-comment-char ? )))
3218 (add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
3219 (put 'asm-comment-char 'safe-local-variable 'characterp)
3222 (add-hook 'asm-mode-hook 'mdw-misc-mode-config t)
3223 (add-hook 'asm-mode-hook 'mdw-fontify-asm t))
3225 ;;;--------------------------------------------------------------------------
3226 ;;; TCL configuration.
3228 (setq-default tcl-indent-level 2)
3230 (defun mdw-fontify-tcl ()
3232 (modify-syntax-entry ch "."))
3233 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3234 (make-local-variable 'font-lock-keywords)
3235 (setq font-lock-keywords
3237 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3238 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
3239 "\\([eE][-+]?[0-9_]+\\)?")
3240 '(0 mdw-number-face))
3241 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3242 '(0 mdw-punct-face)))))
3245 (add-hook 'tcl-mode-hook 'mdw-misc-mode-config t)
3246 (add-hook 'tcl-mode-hook 'mdw-fontify-tcl t))
3248 ;;;--------------------------------------------------------------------------
3249 ;;; Dylan programming configuration.
3251 (defun mdw-fontify-dylan ()
3253 (make-local-variable 'font-lock-keywords)
3255 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
3256 ;; hook, which undoes all of our configuration.
3257 (setq major-mode 'dylan-mode)
3258 (font-lock-set-defaults)
3260 (let* ((word "[-_a-zA-Z!*@<>$%]+")
3261 (dylan-keywords (mdw-regexps
3263 "C-address" "C-callable-wrapper" "C-function"
3264 "C-mapped-subtype" "C-pointer-type" "C-struct"
3265 "C-subtype" "C-union" "C-variable"
3267 "above" "abstract" "afterwards" "all"
3268 "begin" "below" "block" "by"
3269 "case" "class" "cleanup" "constant" "create"
3271 "else" "elseif" "end" "exception" "export"
3272 "finally" "for" "from" "function"
3275 "if" "in" "instance" "interface" "iterate"
3277 "let" "library" "local"
3278 "macro" "method" "module"
3281 "select" "slot" "subclass"
3283 "unless" "until" "use"
3284 "variable" "virtual"
3286 (sharp-keywords (mdw-regexps
3287 "all-keys" "key" "next" "rest" "include"
3289 (setq font-lock-keywords
3290 (list (list (concat "\\<\\(" dylan-keywords
3291 "\\|" "with\\(out\\)?-" word
3293 '(0 font-lock-keyword-face))
3294 (list (concat "\\<" word ":" "\\|"
3295 "#\\(" sharp-keywords "\\)\\>")
3296 '(0 font-lock-variable-name-face))
3298 "\\([-+]\\|\\<\\)[0-9]+" "\\("
3299 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
3302 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
3305 "\\|" "#x[0-9a-zA-Z]+"
3307 '(0 mdw-number-face))
3309 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
3310 "\\_<[-+*/=<>:&|]+\\_>"
3312 '(0 mdw-punct-face))))))
3315 (add-hook 'dylan-mode-hook 'mdw-misc-mode-config t)
3316 (add-hook 'dylan-mode-hook 'mdw-fontify-dylan t))
3318 ;;;--------------------------------------------------------------------------
3319 ;;; Algol 68 configuration.
3321 (setq-default a68-indent-step 2)
3323 (defun mdw-fontify-algol-68 ()
3325 ;; Fix up the syntax table.
3326 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
3327 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
3328 (modify-syntax-entry ch "." a68-mode-syntax-table))
3330 (make-local-variable 'font-lock-keywords)
3333 (let ((word "COMMENT"))
3334 (do ((regexp (concat "[^" (substring word 0 1) "]+")
3335 (concat regexp "\\|"
3336 (substring word 0 i)
3337 "[^" (substring word i (1+ i)) "]"))
3339 ((>= i (length word)) regexp)))))
3340 (setq font-lock-keywords
3341 (list (list (concat "\\<COMMENT\\>"
3342 "\\(" not-comment "\\)\\{0,5\\}"
3343 "\\(\\'\\|\\<COMMENT\\>\\)")
3344 '(0 font-lock-comment-face))
3345 (list (concat "\\<CO\\>"
3346 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
3347 "\\($\\|\\<CO\\>\\)")
3348 '(0 font-lock-comment-face))
3349 (list "\\<[A-Z_]+\\>"
3350 '(0 font-lock-keyword-face))
3354 "\\([eE][-+]?[0-9]+\\)?"
3356 '(0 mdw-number-face))
3357 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
3358 '(0 mdw-punct-face))))))
3360 (dolist (hook '(a68-mode-hook a68-mode-hooks))
3361 (add-hook hook 'mdw-misc-mode-config t)
3362 (add-hook hook 'mdw-fontify-algol-68 t))
3364 ;;;--------------------------------------------------------------------------
3365 ;;; REXX configuration.
3367 (defun mdw-rexx-electric-* ()
3372 (defun mdw-rexx-indent-newline-indent ()
3375 (if abbrev-mode (expand-abbrev))
3376 (newline-and-indent))
3378 (defun mdw-fontify-rexx ()
3380 ;; Various bits of fiddling.
3381 (setq mdw-auto-indent nil)
3382 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
3383 (local-set-key [?*] 'mdw-rexx-electric-*)
3384 (dolist (ch '(?! ?? ?# ?@ ?$)) (modify-syntax-entry ch "w"))
3385 (dolist (ch '(?¬)) (modify-syntax-entry ch "."))
3386 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
3388 ;; Set up keywords and things for fontification.
3389 (make-local-variable 'font-lock-keywords-case-fold-search)
3390 (setq font-lock-keywords-case-fold-search t)
3392 (setq rexx-indent 2)
3393 (setq rexx-end-indent rexx-indent)
3394 (setq rexx-cont-indent rexx-indent)
3396 (make-local-variable 'font-lock-keywords)
3397 (let ((rexx-keywords
3398 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
3399 "else" "end" "engineering" "exit" "expose" "for"
3400 "forever" "form" "fuzz" "if" "interpret" "iterate"
3401 "leave" "linein" "name" "nop" "numeric" "off" "on"
3402 "options" "otherwise" "parse" "procedure" "pull"
3403 "push" "queue" "return" "say" "select" "signal"
3404 "scientific" "source" "then" "trace" "to" "until"
3405 "upper" "value" "var" "version" "when" "while"
3408 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
3409 "center" "center" "charin" "charout" "chars"
3410 "compare" "condition" "copies" "c2d" "c2x"
3411 "datatype" "date" "delstr" "delword" "d2c" "d2x"
3412 "errortext" "format" "fuzz" "insert" "lastpos"
3413 "left" "length" "lineout" "lines" "max" "min"
3414 "overlay" "pos" "queued" "random" "reverse" "right"
3415 "sign" "sourceline" "space" "stream" "strip"
3416 "substr" "subword" "symbol" "time" "translate"
3417 "trunc" "value" "verify" "word" "wordindex"
3418 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
3421 (setq font-lock-keywords
3424 ;; Set up the keywords defined above.
3425 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
3426 '(0 font-lock-keyword-face))
3428 ;; Fontify all symbols the same way.
3429 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
3430 "[A-Za-z0-9.!?_#@$]+\\)")
3431 '(0 font-lock-variable-name-face))
3433 ;; And everything else is punctuation.
3434 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3435 '(0 mdw-punct-face))))))
3438 (add-hook 'rexx-mode-hook 'mdw-misc-mode-config t)
3439 (add-hook 'rexx-mode-hook 'mdw-fontify-rexx t))
3441 ;;;--------------------------------------------------------------------------
3442 ;;; Standard ML programming style.
3444 (setq-default sml-nested-if-indent t
3447 sml-type-of-indent nil)
3449 (defun mdw-fontify-sml ()
3451 ;; Make underscore an honorary letter.
3452 (modify-syntax-entry ?' "w")
3455 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
3457 ;; Now define fontification things.
3458 (make-local-variable 'font-lock-keywords)
3460 (mdw-regexps "abstype" "and" "andalso" "as"
3463 "else" "end" "eqtype" "exception"
3464 "fn" "fun" "functor"
3466 "if" "in" "include" "infix" "infixr"
3469 "of" "op" "open" "orelse"
3471 "sharing" "sig" "signature" "struct" "structure"
3474 "where" "while" "with" "withtype")))
3476 (setq font-lock-keywords
3479 ;; Set up the keywords defined above.
3480 (list (concat "\\<\\(" sml-keywords "\\)\\>")
3481 '(0 font-lock-keyword-face))
3483 ;; At least numbers are simpler than C.
3484 (list (concat "\\<\\~?"
3485 "\\(0\\([wW]?[xX][0-9a-fA-F]+\\|"
3487 "\\([0-9]+\\(\\.[0-9]+\\)?"
3490 '(0 mdw-number-face))
3492 ;; And anything else is punctuation.
3493 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3494 '(0 mdw-punct-face))))))
3497 (add-hook 'sml-mode-hook 'mdw-misc-mode-config t)
3498 (add-hook 'sml-mode-hook 'mdw-fontify-sml t))
3500 ;;;--------------------------------------------------------------------------
3501 ;;; Haskell configuration.
3503 (setq-default haskell-indent-offset 2)
3505 (defun mdw-fontify-haskell ()
3507 ;; Fiddle with syntax table to get comments right.
3508 (modify-syntax-entry ?' "_")
3509 (modify-syntax-entry ?- ". 12")
3510 (modify-syntax-entry ?\n ">")
3512 ;; Make punctuation be punctuation
3513 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
3515 ((>= i (length punct)))
3516 (modify-syntax-entry (aref punct i) ".")))
3519 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
3521 ;; Fiddle with fontification.
3522 (make-local-variable 'font-lock-keywords)
3523 (let ((haskell-keywords
3525 "case" "ccall" "class"
3526 "data" "default" "deriving" "do"
3530 "if" "import" "in" "infix" "infixl" "infixr" "instance"
3543 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
3544 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
3545 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
3546 "SP" "STX" "SUB" "SYN" "US" "VT")))
3548 (setq font-lock-keywords
3550 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
3554 '(0 font-lock-comment-face))
3555 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
3556 '(0 font-lock-keyword-face))
3557 (list (concat "'\\("
3561 "\\(" "[abfnrtv\\\"']" "\\|"
3562 "^" "\\(" control-sequences "\\|"
3563 "[]A-Z@[\\^_]" "\\)" "\\|"
3570 '(0 font-lock-string-face))
3571 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
3572 '(0 font-lock-variable-name-face))
3573 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
3574 "\\_<[0-9]+\\(\\.[0-9]*\\)?"
3575 "\\([eE][-+]?[0-9]+\\)?")
3576 '(0 mdw-number-face))
3577 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3578 '(0 mdw-punct-face))))))
3581 (add-hook 'haskell-mode-hook 'mdw-misc-mode-config t)
3582 (add-hook 'haskell-mode-hook 'mdw-fontify-haskell t))
3584 ;;;--------------------------------------------------------------------------
3585 ;;; Erlang configuration.
3587 (setq-default erlang-electric-commands nil)
3589 (defun mdw-fontify-erlang ()
3592 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
3594 ;; Fiddle with fontification.
3595 (make-local-variable 'font-lock-keywords)
3596 (let ((erlang-keywords
3597 (mdw-regexps "after" "and" "andalso"
3598 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
3599 "case" "catch" "cond"
3600 "div" "end" "fun" "if" "let" "not"
3602 "query" "receive" "rem" "try" "when" "xor")))
3604 (setq font-lock-keywords
3607 '(0 font-lock-comment-face))
3608 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
3609 '(0 font-lock-keyword-face))
3610 (list (concat "^-\\sw+\\>")
3611 '(0 font-lock-keyword-face))
3612 (list "\\<[0-9]+\\(#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)?\\>"
3613 '(0 mdw-number-face))
3614 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3615 '(0 mdw-punct-face))))))
3618 (add-hook 'erlang-mode-hook 'mdw-misc-mode-config t)
3619 (add-hook 'erlang-mode-hook 'mdw-fontify-erlang t))
3621 ;;;--------------------------------------------------------------------------
3622 ;;; Texinfo configuration.
3624 (defun mdw-fontify-texinfo ()
3627 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
3629 ;; Real fontification things.
3630 (make-local-variable 'font-lock-keywords)
3631 (setq font-lock-keywords
3634 ;; Environment names are keywords.
3635 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
3636 '(2 font-lock-keyword-face))
3638 ;; Unmark escaped magic characters.
3639 (list "\\(@\\)\\([@{}]\\)"
3640 '(1 font-lock-keyword-face)
3641 '(2 font-lock-variable-name-face))
3643 ;; Make sure we get comments properly.
3644 (list "@c\\(omment\\)?\\( .*\\)?$"
3645 '(0 font-lock-comment-face))
3647 ;; Command names are keywords.
3648 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3649 '(0 font-lock-keyword-face))
3651 ;; Fontify TeX special characters as punctuation.
3653 '(0 mdw-punct-face)))))
3655 (dolist (hook '(texinfo-mode-hook TeXinfo-mode-hook))
3656 (add-hook hook 'mdw-misc-mode-config t)
3657 (add-hook hook 'mdw-fontify-texinfo t))
3659 ;;;--------------------------------------------------------------------------
3660 ;;; TeX and LaTeX configuration.
3662 (setq-default LaTeX-table-label "tbl:"
3663 TeX-auto-untabify nil
3664 LaTeX-syntactic-comments nil
3665 LaTeX-fill-break-at-separators '(\\\[))
3667 (defun mdw-fontify-tex ()
3668 (setq ispell-parser 'tex)
3671 ;; Don't make maths into a string.
3672 (modify-syntax-entry ?$ ".")
3673 (modify-syntax-entry ?$ "." font-lock-syntax-table)
3674 (local-set-key [?$] 'self-insert-command)
3676 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
3677 (local-set-key "\C-\M-i" 'indent-relative)
3678 (setq indent-tabs-mode nil)
3681 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
3683 ;; Real fontification things.
3684 (make-local-variable 'font-lock-keywords)
3685 (setq font-lock-keywords
3688 ;; Environment names are keywords.
3689 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
3691 '(2 font-lock-keyword-face))
3693 ;; Suspended environment names are keywords too.
3694 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
3696 '(3 font-lock-keyword-face))
3698 ;; Command names are keywords.
3699 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3700 '(0 font-lock-keyword-face))
3702 ;; Handle @/.../ for italics.
3703 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
3704 ;; '(1 font-lock-keyword-face)
3705 ;; '(3 font-lock-keyword-face))
3707 ;; Handle @*...* for boldness.
3708 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
3709 ;; '(1 font-lock-keyword-face)
3710 ;; '(3 font-lock-keyword-face))
3712 ;; Handle @`...' for literal syntax things.
3713 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
3714 ;; '(1 font-lock-keyword-face)
3715 ;; '(3 font-lock-keyword-face))
3717 ;; Handle @<...> for nonterminals.
3718 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
3719 ;; '(1 font-lock-keyword-face)
3720 ;; '(3 font-lock-keyword-face))
3722 ;; Handle other @-commands.
3723 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
3724 ;; '(0 font-lock-keyword-face))
3726 ;; Make sure we get comments properly.
3728 '(0 font-lock-comment-face))
3730 ;; Fontify TeX special characters as punctuation.
3732 '(0 mdw-punct-face)))))
3734 (setq TeX-install-font-lock 'tex-font-setup)
3736 (eval-after-load 'font-latex
3737 '(defun font-latex-jit-lock-force-redisplay (buf start end)
3738 "Compatibility for Emacsen not offering `jit-lock-force-redisplay'."
3739 ;; The following block is an expansion of `jit-lock-force-redisplay'
3740 ;; and involved macros taken from CVS Emacs on 2007-04-28.
3741 (with-current-buffer buf
3742 (let ((modified (buffer-modified-p)))
3744 (let ((buffer-undo-list t)
3745 (inhibit-read-only t)
3746 (inhibit-point-motion-hooks t)
3747 (inhibit-modification-hooks t)
3750 buffer-file-truename)
3751 (put-text-property start end 'fontified t))
3753 (restore-buffer-modified-p nil)))))))
3755 (setq TeX-output-view-style
3757 ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$")
3758 "%(o?)dvips -t landscape %d -o && xdg-open %f")
3759 ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$"
3760 "%(o?)dvips %d -o && xdg-open %f")
3762 ("^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "^landscape$")
3763 "%(o?)xdvi %dS -paper a4r -s 0 %d")
3764 ("^dvi$" "^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$"
3765 "%(o?)xdvi %dS -paper a4 %d")
3767 ("^a5\\(?:comb\\|paper\\)$" "^landscape$")
3768 "%(o?)xdvi %dS -paper a5r -s 0 %d")
3769 ("^dvi$" "^a5\\(?:comb\\|paper\\)$" "%(o?)xdvi %dS -paper a5 %d")
3770 ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
3771 ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d")
3772 ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
3773 ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
3774 ("^dvi$" "." "%(o?)xdvi %dS %d")
3775 ("^pdf$" "." "xdg-open %o")
3776 ("^html?$" "." "sensible-browser %o")))
3778 (setq TeX-view-program-list
3779 '(("mupdf" ("mupdf %o" (mode-io-correlate " %(outpage)")))))
3781 (setq TeX-view-program-selection
3782 '(((output-dvi style-pstricks) "dvips and gv")
3784 (output-pdf "mupdf")
3785 (output-html "sensible-browser")))
3787 (setq TeX-open-quote "\""
3788 TeX-close-quote "\"")
3790 (setq reftex-use-external-file-finders t
3791 reftex-auto-recenter-toc t)
3793 (setq reftex-label-alist
3794 '(("theorem" ?T "th:" "~\\ref{%s}" t ("theorems?" "th\\.") -2)
3795 ("axiom" ?A "ax:" "~\\ref{%s}" t ("axioms?" "ax\\.") -2)
3796 ("definition" ?D "def:" "~\\ref{%s}" t ("definitions?" "def\\.") -2)
3797 ("proposition" ?P "prop:" "~\\ref{%s}" t
3798 ("propositions?" "prop\\.") -2)
3799 ("lemma" ?L "lem:" "~\\ref{%s}" t ("lemmas?" "lem\\.") -2)
3800 ("example" ?X "eg:" "~\\ref{%s}" t ("examples?") -2)
3801 ("exercise" ?E "ex:" "~\\ref{%s}" t ("exercises?" "ex\\.") -2)
3802 ("enumerate" ?i "i:" "~\\ref{%s}" item ("items?"))))
3803 (setq reftex-section-prefixes
3808 (setq bibtex-field-delimiters 'double-quotes
3809 bibtex-align-at-equal-sign t
3810 bibtex-entry-format '(realign opts-or-alts required-fields
3811 numerical-fields last-comma delimiters
3812 unify-case sort-fields braces)
3813 bibtex-sort-ignore-string-entries nil
3814 bibtex-maintain-sorted-entries 'entry-class
3815 bibtex-include-OPTkey t
3816 bibtex-autokey-names-stretch 1
3817 bibtex-autokey-expand-strings t
3818 bibtex-autokey-name-separator "-"
3819 bibtex-autokey-year-length 4
3820 bibtex-autokey-titleword-separator "-"
3821 bibtex-autokey-name-year-separator "-"
3822 bibtex-autokey-year-title-separator ":")
3825 (dolist (hook '(tex-mode-hook latex-mode-hook
3826 TeX-mode-hook LaTeX-mode-hook))
3827 (add-hook hook 'mdw-misc-mode-config t)
3828 (add-hook hook 'mdw-fontify-tex t))
3829 (add-hook 'bibtex-mode-hook (lambda () (setq fill-column 76))))
3831 ;;;--------------------------------------------------------------------------
3832 ;;; HTML, CSS, and other web foolishness.
3834 (setq-default css-indent-offset 2)
3836 ;;;--------------------------------------------------------------------------
3839 (setq-default psgml-html-build-new-buffer nil)
3841 (defun mdw-sgml-mode ()
3844 (mdw-standard-fill-prefix "")
3845 (make-local-variable 'sgml-delimiters)
3846 (setq sgml-delimiters
3847 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
3848 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
3849 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
3850 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
3851 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
3852 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
3853 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
3855 (setq major-mode 'mdw-sgml-mode)
3856 (setq mode-name "[mdw] SGML")
3857 (run-hooks 'mdw-sgml-mode-hook))
3859 ;;;--------------------------------------------------------------------------
3860 ;;; Configuration files.
3862 (defvar mdw-conf-quote-normal nil
3863 "*Control syntax category of quote characters `\"' and `''.
3864 If this is `t', consider quote characters to be normal
3865 punctuation, as for `conf-quote-normal'. If this is `nil' then
3866 leave quote characters as quotes. If this is a list, then
3867 consider the quote characters in the list to be normal
3868 punctuation. If this is a single quote character, then consider
3869 that character only to be normal punctuation.")
3870 (defun mdw-conf-quote-normal-acceptable-value-p (value)
3871 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
3872 (or (booleanp value)
3873 (every (lambda (v) (memq v '(?\" ?')))
3874 (if (listp value) value (list value)))))
3875 (put 'mdw-conf-quote-normal 'safe-local-variable
3876 'mdw-conf-quote-normal-acceptable-value-p)
3878 (defun mdw-fix-up-quote ()
3879 "Apply the setting of `mdw-conf-quote-normal'."
3880 (let ((flag mdw-conf-quote-normal))
3882 (conf-quote-normal t))
3886 (let ((table (copy-syntax-table (syntax-table))))
3887 (dolist (ch (if (listp flag) flag (list flag)))
3888 (modify-syntax-entry ch "." table))
3889 (set-syntax-table table)
3890 (and font-lock-mode (font-lock-fontify-buffer)))))))
3893 (add-hook 'conf-mode-hook 'mdw-misc-mode-config t)
3894 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t))
3896 ;;;--------------------------------------------------------------------------
3899 (defun mdw-setup-sh-script-mode ()
3901 ;; Fetch the shell interpreter's name.
3902 (let ((shell-name sh-shell-file))
3904 ;; Try reading the hash-bang line.
3906 (goto-char (point-min))
3907 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
3908 (setq shell-name (match-string 1))))
3910 ;; Now try to set the shell.
3912 ;; Don't let `sh-set-shell' bugger up my script.
3913 (let ((executable-set-magic #'(lambda (s &rest r) s)))
3914 (sh-set-shell shell-name)))
3916 ;; Don't insert here-document scaffolding automatically.
3917 (local-set-key "<" 'self-insert-command)
3919 ;; Now enable my keys and the fontification.
3920 (mdw-misc-mode-config)
3922 ;; Set the indentation level correctly.
3923 (setq sh-indentation 2)
3924 (setq sh-basic-offset 2))
3926 (setq sh-shell-file "/bin/sh")
3928 ;; Awful hacking to override the shell detection for particular scripts.
3929 (defmacro define-custom-shell-mode (name shell)
3932 (set (make-local-variable 'sh-shell-file) ,shell)
3934 (define-custom-shell-mode bash-mode "/bin/bash")
3935 (define-custom-shell-mode rc-mode "/usr/bin/rc")
3936 (put 'sh-shell-file 'permanent-local t)
3938 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
3939 (eval-after-load "sh-script"
3940 '(or (assq 'rc sh-mode-syntax-table-input)
3957 (assoc (assq 'rc sh-mode-syntax-table-input)))
3960 (setq sh-mode-syntax-table-input
3961 (cons (cons 'rc frag)
3962 sh-mode-syntax-table-input))))))
3965 (add-hook 'sh-mode-hook 'mdw-misc-mode-config t)
3966 (add-hook 'sh-mode-hook 'mdw-setup-sh-script-mode t))
3968 ;;;--------------------------------------------------------------------------
3969 ;;; Emacs shell mode.
3971 (defun mdw-eshell-prompt ()
3972 (let ((left "[") (right "]"))
3973 (when (= (user-uid) 0)
3974 (setq left "«" right "»"))
3977 (replace-regexp-in-string "\\..*$" "" (system-name)))
3979 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
3980 (home (expand-file-name "~")) (nhome (length home)))
3981 (if (and (>= npwd nhome)
3983 (= (elt pwd nhome) ?/))
3984 (string= (substring pwd 0 nhome) home))
3985 (concat "~" (substring pwd (length home)))
3988 (setq-default eshell-prompt-function 'mdw-eshell-prompt)
3989 (setq-default eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
3991 (defun eshell/e (file) (find-file file) nil)
3992 (defun eshell/ee (file) (find-file-other-window file) nil)
3993 (defun eshell/w3m (url) (w3m-goto-url url) nil)
3995 (mdw-define-face eshell-prompt (t :weight bold))
3996 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
3997 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
3998 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
3999 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
4000 (mdw-define-face eshell-ls-executable (t :weight bold))
4001 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
4002 (mdw-define-face eshell-ls-readonly (t nil))
4003 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
4005 (defun mdw-eshell-hack () (setenv "LD_PRELOAD" nil))
4006 (add-hook 'eshell-mode-hook 'mdw-eshell-hack)
4008 ;;;--------------------------------------------------------------------------
4009 ;;; Messages-file mode.
4011 (defun messages-mode-guts ()
4012 (setq messages-mode-syntax-table (make-syntax-table))
4013 (set-syntax-table messages-mode-syntax-table)
4014 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
4015 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
4016 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
4017 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
4018 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
4019 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
4020 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
4021 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
4022 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
4023 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
4024 (make-local-variable 'comment-start)
4025 (make-local-variable 'comment-end)
4026 (make-local-variable 'indent-line-function)
4027 (setq indent-line-function 'indent-relative)
4028 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4029 (make-local-variable 'font-lock-defaults)
4030 (make-local-variable 'messages-mode-keywords)
4032 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
4033 "export" "enum" "fixed-octetstring" "flags"
4034 "harmless" "map" "nested" "optional"
4035 "optional-tagged" "package" "primitive"
4036 "primitive-nullfree" "relaxed[ \t]+enum"
4037 "set" "table" "tagged-optional" "union"
4038 "variadic" "vector" "version" "version-tag")))
4039 (setq messages-mode-keywords
4041 (list (concat "\\<\\(" keywords "\\)\\>:")
4042 '(0 font-lock-keyword-face))
4043 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
4044 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
4045 (0 font-lock-variable-name-face))
4046 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
4047 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4048 (0 mdw-punct-face)))))
4049 (setq font-lock-defaults
4050 '(messages-mode-keywords nil nil nil nil))
4051 (run-hooks 'messages-file-hook))
4053 (defun messages-mode ()
4056 (setq major-mode 'messages-mode)
4057 (setq mode-name "Messages")
4058 (messages-mode-guts)
4059 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
4060 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
4061 (setq comment-start "# ")
4062 (setq comment-end "")
4063 (run-hooks 'messages-mode-hook))
4065 (defun cpp-messages-mode ()
4068 (setq major-mode 'cpp-messages-mode)
4069 (setq mode-name "CPP Messages")
4070 (messages-mode-guts)
4071 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
4072 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
4073 (setq comment-start "/* ")
4074 (setq comment-end " */")
4075 (let ((preprocessor-keywords
4076 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
4077 "ident" "if" "ifdef" "ifndef" "import" "include"
4078 "line" "pragma" "unassert" "undef" "warning")))
4079 (setq messages-mode-keywords
4080 (append (list (list (concat "^[ \t]*\\#[ \t]*"
4081 "\\(include\\|import\\)"
4082 "[ \t]*\\(<[^>]+\\(>\\)?\\)")
4083 '(2 font-lock-string-face))
4084 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
4085 preprocessor-keywords
4086 "\\)\\>\\|[0-9]+\\|$\\)\\)")
4087 '(1 font-lock-keyword-face)))
4088 messages-mode-keywords)))
4089 (run-hooks 'cpp-messages-mode-hook))
4092 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
4093 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
4094 ;; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
4097 ;;;--------------------------------------------------------------------------
4098 ;;; Messages-file mode.
4100 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
4101 "Face to use for subsittution directives.")
4102 (make-face 'mallow-driver-substitution-face)
4103 (defvar mallow-driver-text-face 'mallow-driver-text-face
4104 "Face to use for body text.")
4105 (make-face 'mallow-driver-text-face)
4107 (defun mallow-driver-mode ()
4110 (setq major-mode 'mallow-driver-mode)
4111 (setq mode-name "Mallow driver")
4112 (setq mallow-driver-mode-syntax-table (make-syntax-table))
4113 (set-syntax-table mallow-driver-mode-syntax-table)
4114 (make-local-variable 'comment-start)
4115 (make-local-variable 'comment-end)
4116 (make-local-variable 'indent-line-function)
4117 (setq indent-line-function 'indent-relative)
4118 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4119 (make-local-variable 'font-lock-defaults)
4120 (make-local-variable 'mallow-driver-mode-keywords)
4122 (mdw-regexps "each" "divert" "file" "if"
4123 "perl" "set" "string" "type" "write")))
4124 (setq mallow-driver-mode-keywords
4126 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
4127 '(0 font-lock-keyword-face))
4128 (list "^%\\s *\\(#.*\\)?$"
4129 '(0 font-lock-comment-face))
4131 '(0 font-lock-keyword-face))
4132 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
4134 '(0 mallow-driver-substitution-face t)))))
4135 (setq font-lock-defaults
4136 '(mallow-driver-mode-keywords nil nil nil nil))
4137 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
4138 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
4139 (setq comment-start "%# ")
4140 (setq comment-end "")
4141 (run-hooks 'mallow-driver-mode-hook))
4144 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t))
4146 ;;;--------------------------------------------------------------------------
4149 (defun nfast-debug-mode ()
4152 (setq major-mode 'nfast-debug-mode)
4153 (setq mode-name "NFast debug")
4154 (setq messages-mode-syntax-table (make-syntax-table))
4155 (set-syntax-table messages-mode-syntax-table)
4156 (make-local-variable 'font-lock-defaults)
4157 (make-local-variable 'nfast-debug-mode-keywords)
4158 (setq truncate-lines t)
4159 (setq nfast-debug-mode-keywords
4161 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
4162 (0 font-lock-keyword-face))
4163 (list (concat "^[ \t]+\\(\\("
4164 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4165 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4167 "[0-9a-fA-F]+\\)[ \t]*$")
4168 '(0 mdw-number-face))
4169 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
4170 (1 font-lock-keyword-face))
4171 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
4172 (1 font-lock-warning-face))
4173 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
4175 (list (concat "^[ \t]+\\.cmd=[ \t]+"
4176 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
4177 '(1 font-lock-keyword-face))
4178 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
4179 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
4180 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
4181 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
4182 (setq font-lock-defaults
4183 '(nfast-debug-mode-keywords nil nil nil nil))
4184 (run-hooks 'nfast-debug-mode-hook))
4186 ;;;--------------------------------------------------------------------------
4187 ;;; Lispy languages.
4189 ;; Unpleasant bodge.
4190 (unless (boundp 'slime-repl-mode-map)
4191 (setq slime-repl-mode-map (make-sparse-keymap)))
4193 (defun mdw-indent-newline-and-indent ()
4195 (indent-for-tab-command)
4196 (newline-and-indent))
4198 (eval-after-load "cl-indent"
4200 (mapc #'(lambda (pair)
4202 'common-lisp-indent-function
4204 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
4205 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
4207 (defun mdw-common-lisp-indent ()
4208 (make-local-variable 'lisp-indent-function)
4209 (setq lisp-indent-function 'common-lisp-indent-function))
4211 (setq-default lisp-simple-loop-indentation 2
4212 lisp-loop-keyword-indentation 6
4213 lisp-loop-forms-indentation 6)
4215 (defmacro mdw-advise-hyperspec-lookup (func args)
4216 `(defadvice ,func (around mdw-browse-w3m ,args activate compile)
4218 (let ((browse-url-browser-function #'mdw-w3m-browse-url))
4221 (mdw-advise-hyperspec-lookup common-lisp-hyperspec (symbol))
4222 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-format (char))
4223 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-lookup-reader-macro (char))
4225 (defun mdw-fontify-lispy ()
4228 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
4230 ;; Not much fontification needed.
4231 (make-local-variable 'font-lock-keywords)
4232 (setq font-lock-keywords
4233 (list (list (concat "\\("
4235 "\\(" "[0-9]+/[0-9]+"
4236 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
4238 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
4243 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
4244 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
4245 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
4246 "\\|" "[0-9]+" "r" "[-+]?"
4247 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
4250 '(0 mdw-number-face))
4251 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4252 '(0 mdw-punct-face)))))
4257 (if (not mdw-fast-startup)
4259 (require 'slime-autoloads)
4260 (slime-setup '(slime-autodoc slime-c-p-c)))))
4262 (let ((stuff '((cmucl ("cmucl"))
4263 (sbcl ("sbcl") :coding-system utf-8-unix)
4264 (clisp ("clisp") :coding-system utf-8-unix))))
4265 (or (boundp 'slime-lisp-implementations)
4266 (setq slime-lisp-implementations nil))
4268 (let* ((head (car stuff))
4269 (found (assq (car head) slime-lisp-implementations)))
4270 (setq stuff (cdr stuff))
4272 (rplacd found (cdr head))
4273 (setq slime-lisp-implementations
4274 (cons head slime-lisp-implementations))))))
4275 (setq slime-default-lisp 'sbcl)
4280 (dolist (hook '(emacs-lisp-mode-hook
4283 inferior-lisp-mode-hook
4284 lisp-interaction-mode-hook
4286 slime-repl-mode-hook))
4287 (add-hook hook 'mdw-misc-mode-config t)
4288 (add-hook hook 'mdw-fontify-lispy t))
4289 (add-hook 'lisp-mode-hook 'mdw-common-lisp-indent t)
4290 (add-hook 'inferior-lisp-mode-hook
4291 #'(lambda () (local-set-key "\C-m" 'comint-send-and-indent)) t))
4293 ;;;--------------------------------------------------------------------------
4294 ;;; Other languages.
4298 (defun mdw-setup-smalltalk ()
4299 (and mdw-auto-indent
4300 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
4301 (make-local-variable 'mdw-auto-indent)
4302 (setq mdw-auto-indent nil)
4303 (local-set-key "\C-i" 'smalltalk-reindent))
4305 (defun mdw-fontify-smalltalk ()
4306 (make-local-variable 'font-lock-keywords)
4307 (setq font-lock-keywords
4309 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
4310 '(0 font-lock-keyword-face))
4311 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
4312 "[0-9][0-9_]*\\(\\.[0-9_]*\\)?"
4313 "\\([eE][-+]?[0-9_]+\\)?")
4314 '(0 mdw-number-face))
4315 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4316 '(0 mdw-punct-face)))))
4319 (add-hook 'smalltalk-mode 'mdw-misc-mode-config t)
4320 (add-hook 'smalltalk-mode 'mdw-fontify-smalltalk t))
4324 (defun mdw-setup-m4 ()
4326 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
4327 ;; annoying: fix it.
4328 (modify-syntax-entry ?{ "(")
4329 (modify-syntax-entry ?} ")")
4332 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
4334 (dolist (hook '(m4-mode-hook autoconf-mode-hook autotest-mode-hook))
4335 (add-hook hook #'mdw-misc-mode-config t)
4336 (add-hook hook #'mdw-setup-m4 t))
4341 (add-hook 'makefile-mode-hook 'mdw-misc-mode-config t))
4343 ;;;--------------------------------------------------------------------------
4346 (defun mdw-text-mode ()
4347 (setq fill-column 72)
4349 (mdw-standard-fill-prefix
4350 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
4353 (eval-after-load "flyspell"
4354 '(define-key flyspell-mode-map "\C-\M-i" nil))
4357 (add-hook 'text-mode-hook 'mdw-text-mode t))
4359 ;;;--------------------------------------------------------------------------
4360 ;;; Outline and hide/show modes.
4362 (defun mdw-outline-collapse-all ()
4363 "Completely collapse everything in the entire buffer."
4366 (goto-char (point-min))
4367 (while (< (point) (point-max))
4371 (setq hs-hide-comments-when-hiding-all nil)
4373 (defadvice hs-hide-all (after hide-first-comment activate)
4374 (save-excursion (hs-hide-initial-comment-block)))
4376 ;;;--------------------------------------------------------------------------
4379 (defun mdw-sh-mode-setup ()
4380 (local-set-key [?\C-a] 'comint-bol)
4381 (add-hook 'comint-output-filter-functions
4382 'comint-watch-for-password-prompt))
4384 (defun mdw-term-mode-setup ()
4385 (setq term-prompt-regexp shell-prompt-pattern)
4386 (make-local-variable 'mouse-yank-at-point)
4387 (make-local-variable 'transient-mark-mode)
4388 (setq mouse-yank-at-point t)
4392 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
4393 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
4394 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
4395 (defun term-send-meta-meta-something ()
4397 (term-send-raw-string "\e\e")
4399 (eval-after-load 'term
4401 (define-key term-raw-map [?\e ?\e] nil)
4402 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
4403 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
4404 (define-key term-raw-map [M-right] 'term-send-meta-right)
4405 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
4406 (define-key term-raw-map [M-left] 'term-send-meta-left)
4407 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
4409 (defadvice term-exec (before program-args-list compile activate)
4410 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
4411 This allows you to pass a list of arguments through `ansi-term'."
4412 (let ((program (ad-get-arg 2)))
4415 (ad-set-arg 2 (car program))
4416 (ad-set-arg 4 (cdr program))))))
4418 (defadvice term-exec-1 (around hack-environment compile activate)
4419 "Hack the environment inherited by inferiors in the terminal."
4420 (let ((process-environment (copy-tree process-environment)))
4421 (setenv "LD_PRELOAD" nil)
4424 (defadvice shell (around hack-environment compile activate)
4425 "Hack the environment inherited by inferiors in the shell."
4426 (let ((process-environment (copy-tree process-environment)))
4427 (setenv "LD_PRELOAD" nil)
4431 "Open a terminal containing an ssh session to the HOST."
4432 (interactive "sHost: ")
4433 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
4435 (defvar git-grep-command
4436 "env GIT_PAGER=cat git grep --no-color -nH -e "
4437 "*The default command for \\[git-grep].")
4439 (defvar git-grep-history nil)
4441 (defun git-grep (command-args)
4442 "Run `git grep' with user-specified args and collect output in a buffer."
4444 (list (read-shell-command "Run git grep (like this): "
4445 git-grep-command 'git-grep-history)))
4446 (let ((grep-use-null-device nil))
4447 (grep command-args)))
4449 ;;;--------------------------------------------------------------------------
4450 ;;; Magit configuration.
4452 (setq magit-diff-refine-hunk 't
4453 magit-view-git-manual-method 'man
4454 magit-log-margin '(nil age magit-log-margin-width t 18)
4455 magit-wip-after-save-local-mode-lighter ""
4456 magit-wip-after-apply-mode-lighter ""
4457 magit-wip-before-change-mode-lighter "")
4458 (eval-after-load "magit"
4459 '(progn (global-magit-file-mode 1)
4460 (magit-wip-after-save-mode 1)
4461 (magit-wip-after-apply-mode 1)
4462 (magit-wip-before-change-mode 1)
4463 (add-to-list 'magit-no-confirm 'safe-with-wip)
4464 (add-to-list 'magit-no-confirm 'trash)
4465 (push '(:eval (if (or magit-wip-after-save-local-mode
4466 magit-wip-after-apply-mode
4467 magit-wip-before-change-mode)
4468 (format " wip:%s%s%s"
4469 (if magit-wip-after-apply-mode "A" "")
4470 (if magit-wip-before-change-mode "C" "")
4471 (if magit-wip-after-save-local-mode "S" ""))))
4473 (dolist (popup '(magit-diff-popup
4474 magit-diff-refresh-popup
4475 magit-diff-mode-refresh-popup
4476 magit-revision-mode-refresh-popup))
4477 (magit-define-popup-switch popup ?R "Reverse diff" "-R"))))
4479 (defadvice magit-wip-commit-buffer-file
4480 (around mdw-just-this-buffer activate compile)
4481 (let ((magit-save-repository-buffers nil)) ad-do-it))
4483 (defadvice magit-discard
4484 (around mdw-delete-if-prefix-argument activate compile)
4485 (let ((magit-delete-by-moving-to-trash
4486 (and (null current-prefix-arg)
4487 magit-delete-by-moving-to-trash)))
4490 (setq magit-repolist-columns
4491 '(("Name" 16 magit-repolist-column-ident nil)
4492 ("Version" 18 magit-repolist-column-version nil)
4493 ("St" 2 magit-repolist-column-dirty nil)
4494 ("L<U" 3 mdw-repolist-column-unpulled-from-upstream nil)
4495 ("L>U" 3 mdw-repolist-column-unpushed-to-upstream nil)
4496 ("Path" 32 magit-repolist-column-path nil)))
4498 (setq magit-repository-directories '(("~/etc/profile" . 0)
4501 (defadvice magit-list-repos (around mdw-dirname () activate compile)
4502 "Make sure the returned names are directory names.
4503 Otherwise child processes get started in the wrong directory and
4505 (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it)))
4507 (defun mdw-repolist-column-unpulled-from-upstream (_id)
4508 "Insert number of upstream commits not in the current branch."
4509 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
4511 (let ((n (cadr (magit-rev-diff-count "HEAD" upstream))))
4512 (propertize (number-to-string n) 'face
4513 (if (> n 0) 'bold 'shadow))))))
4515 (defun mdw-repolist-column-unpushed-to-upstream (_id)
4516 "Insert number of commits in the current branch but not its upstream."
4517 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
4519 (let ((n (car (magit-rev-diff-count "HEAD" upstream))))
4520 (propertize (number-to-string n) 'face
4521 (if (> n 0) 'bold 'shadow))))))
4523 (defun mdw-try-smerge ()
4525 (goto-char (point-min))
4526 (when (re-search-forward "^<<<<<<< " nil t)
4528 (add-hook 'find-file-hook 'mdw-try-smerge t)
4530 ;;;--------------------------------------------------------------------------
4531 ;;; GUD, and especially GDB.
4533 ;; Inhibit window dedication. I mean, seriously, wtf?
4534 (defadvice gdb-display-buffer (after mdw-undedicated (buf) compile activate)
4535 "Don't make windows dedicated. Seriously."
4536 (set-window-dedicated-p ad-return-value nil))
4537 (defadvice gdb-set-window-buffer
4538 (after mdw-undedicated (name &optional ignore-dedicated window)
4540 "Don't make windows dedicated. Seriously."
4541 (set-window-dedicated-p (or window (selected-window)) nil))
4543 ;;;--------------------------------------------------------------------------
4546 ;; Turn off `noip' when running `man': it interferes with `man-db''s own
4547 ;; seccomp(2)-based sandboxing, which is (in this case, at least) strictly
4549 (defadvice Man-getpage-in-background
4550 (around mdw-inhibit-noip (topic) compile activate)
4551 "Inhibit the `noip' preload hack when invoking `man'."
4552 (let* ((old-preload (getenv "LD_PRELOAD"))
4553 (preloads (and old-preload
4554 (save-match-data (split-string old-preload ":"))))
4559 (let ((item (pop preloads)))
4560 (if (string-match "\\(/\\|^\\)noip\.so\\(:\\|$\\)" item)
4562 (push item filtered)))))
4566 (setenv "LD_PRELOAD"
4568 (with-output-to-string
4569 (setq filtered (nreverse filtered))
4572 (if first (setq first nil)
4574 (write-string (pop filtered)))))))
4576 (setenv "LD_PRELOAD" old-preload))
4579 ;;;--------------------------------------------------------------------------
4580 ;;; MPC configuration.
4582 (eval-when-compile (trap (require 'mpc)))
4584 (setq mpc-browser-tags '(Artist|Composer|Performer Album|Playlist))
4586 (defun mdw-mpc-now-playing ()
4590 (set-buffer (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))))
4591 (mpc--status-callback))
4592 (let ((state (cdr (assq 'state mpc-status))))
4593 (cond ((member state '("stop"))
4594 (message "mpd stopped."))
4595 ((member state '("play" "pause"))
4596 (let* ((artist (cdr (assq 'Artist mpc-status)))
4597 (album (cdr (assq 'Album mpc-status)))
4598 (title (cdr (assq 'Title mpc-status)))
4599 (file (cdr (assq 'file mpc-status)))
4600 (duration-string (cdr (assq 'Time mpc-status)))
4601 (time-string (cdr (assq 'time mpc-status)))
4602 (time (and time-string
4604 (if (string-match ":" time-string)
4605 (substring time-string
4606 0 (match-beginning 0))
4608 (duration (and duration-string
4609 (string-to-number duration-string)))
4610 (pos (and time duration
4611 (format " [%d:%02d/%d:%02d]"
4612 (/ time 60) (mod time 60)
4613 (/ duration 60) (mod duration 60))))
4614 (fmt (cond ((and artist title)
4615 (format "`%s' by %s%s" title artist
4616 (if album (format ", from `%s'" album)
4619 (format "`%s' (no tags)" file))
4621 "(no idea what's playing!)"))))
4622 (if (string= state "play")
4623 (message "mpd playing %s%s" fmt (or pos ""))
4624 (message "mpd paused in %s%s" fmt (or pos "")))))
4626 (message "mpd in unknown state `%s'" state)))))
4628 (defmacro mdw-define-mpc-wrapper (func bvl interactive &rest body)
4630 (interactive ,@interactive)
4633 (mdw-mpc-now-playing)))
4635 (mdw-define-mpc-wrapper mdw-mpc-play-or-pause () nil
4636 (if (member (cdr (assq 'state (mpc-cmd-status))) '("play"))
4640 (mdw-define-mpc-wrapper mdw-mpc-next () nil (mpc-next))
4641 (mdw-define-mpc-wrapper mdw-mpc-prev () nil (mpc-prev))
4642 (mdw-define-mpc-wrapper mdw-mpc-stop () nil (mpc-stop))
4644 (defun mdw-mpc-louder (step)
4645 (interactive (list (if current-prefix-arg
4646 (prefix-numeric-value current-prefix-arg)
4648 (mpc-proc-cmd (format "volume %+d" step)))
4650 (defun mdw-mpc-quieter (step)
4651 (interactive (list (if current-prefix-arg
4652 (prefix-numeric-value current-prefix-arg)
4654 (mpc-proc-cmd (format "volume %+d" (- step))))
4656 (defun mdw-mpc-hack-lines (arg interactivep func)
4657 (if (and interactivep (use-region-p))
4658 (let ((from (region-beginning)) (to (region-end)))
4663 (while (< (point) to)
4666 (let ((n (prefix-numeric-value arg)))
4683 (defun mdw-mpc-select-one ()
4684 (when (and (get-char-property (point) 'mpc-file)
4685 (not (get-char-property (point) 'mpc-select)))
4686 (mpc-select-toggle)))
4688 (defun mdw-mpc-unselect-one ()
4689 (when (get-char-property (point) 'mpc-select)
4690 (mpc-select-toggle)))
4692 (defun mdw-mpc-select (&optional arg interactivep)
4693 (interactive (list current-prefix-arg t))
4694 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4696 (defun mdw-mpc-unselect (&optional arg interactivep)
4697 (interactive (list current-prefix-arg t))
4698 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one))
4700 (defun mdw-mpc-unselect-backwards (arg)
4702 (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one))
4704 (defun mdw-mpc-unselect-all ()
4706 (setq mpc-select nil)
4707 (mpc-selection-refresh))
4709 (defun mdw-mpc-next-line (arg)
4714 (defun mdw-mpc-previous-line (arg)
4717 (forward-line (- arg)))
4719 (defun mdw-mpc-playlist-add (&optional arg interactivep)
4720 (interactive (list current-prefix-arg t))
4721 (let ((mpc-select mpc-select))
4722 (when (or arg (and interactivep (use-region-p)))
4723 (setq mpc-select nil)
4724 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4725 (setq mpc-select (reverse mpc-select))
4726 (mpc-playlist-add)))
4728 (defun mdw-mpc-playlist-delete (&optional arg interactivep)
4729 (interactive (list current-prefix-arg t))
4730 (setq mpc-select (nreverse mpc-select))
4732 (when (or arg (and interactivep (use-region-p)))
4733 (setq mpc-select nil)
4734 (mpc-selection-refresh)
4735 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4736 (mpc-playlist-delete)))
4738 (defun mdw-mpc-hack-tagbrowsers ()
4739 (setq-local mode-line-format
4741 mode-line-frame-identification
4742 mode-line-buffer-identification)))
4743 (add-hook 'mpc-tagbrowser-mode-hook 'mdw-mpc-hack-tagbrowsers)
4745 (defun mdw-mpc-hack-songs ()
4746 (setq-local header-line-format
4747 ;; '("MPC " mpc-volume " " mpc-current-song)
4748 (list (propertize " " 'display '(space :align-to 0))
4749 ;; 'mpc-songs-format-description
4751 (let ((deactivate-mark) (hscroll (window-hscroll)))
4753 (mpc-format mpc-songs-format 'self hscroll)
4754 ;; That would be simpler than the hscroll handling in
4755 ;; mpc-format, but currently move-to-column does not
4756 ;; recognize :space display properties.
4757 ;; (move-to-column hscroll)
4758 ;; (delete-region (point-min) (point))
4759 (buffer-string)))))))
4760 (add-hook 'mpc-songs-mode-hook 'mdw-mpc-hack-songs)
4762 (eval-after-load "mpc"
4764 (define-key mpc-mode-map "m" 'mdw-mpc-select)
4765 (define-key mpc-mode-map "u" 'mdw-mpc-unselect)
4766 (define-key mpc-mode-map "\177" 'mdw-mpc-unselect-backwards)
4767 (define-key mpc-mode-map "\e\177" 'mdw-mpc-unselect-all)
4768 (define-key mpc-mode-map "n" 'mdw-mpc-next-line)
4769 (define-key mpc-mode-map "p" 'mdw-mpc-previous-line)
4770 (define-key mpc-mode-map "/" 'mpc-songs-search)
4771 (setq mpc-songs-mode-map (make-sparse-keymap))
4772 (set-keymap-parent mpc-songs-mode-map mpc-mode-map)
4773 (define-key mpc-songs-mode-map "l" 'mpc-playlist)
4774 (define-key mpc-songs-mode-map "+" 'mdw-mpc-playlist-add)
4775 (define-key mpc-songs-mode-map "-" 'mdw-mpc-playlist-delete)
4776 (define-key mpc-songs-mode-map "\r" 'mpc-songs-jump-to)))
4778 ;;;--------------------------------------------------------------------------
4779 ;;; Inferior Emacs Lisp.
4781 (setq comint-prompt-read-only t)
4783 (eval-after-load "comint"
4785 (define-key comint-mode-map "\C-w" 'comint-kill-region)
4786 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
4788 (eval-after-load "ielm"
4790 (define-key ielm-map "\C-w" 'comint-kill-region)
4791 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
4793 ;;;----- That's all, folks --------------------------------------------------
4795 (provide 'dot-emacs)