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_.]*\\)"
107 "\\(.*[^ \t\n]\\|\\)"
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 ;; Rename buffers along with files.
593 (defadvice rename-file (after mdw-rename-buffers (from to &optional forcep)
595 "If a buffer is visiting the file, rename it to match the new name."
596 (let ((buffer (get-file-buffer from)))
598 (with-current-buffer buffer
599 (set-visited-file-name to nil t)))))
601 ;;;--------------------------------------------------------------------------
602 ;;; Improved compilation machinery.
604 ;; Uprated version of M-x compile.
606 (setq compile-command
607 (let ((ncpu (with-temp-buffer
608 (insert-file-contents "/proc/cpuinfo")
610 (count-matches "^processor\\s-*:"))))
611 (format "make -j%d -k" (* 2 ncpu))))
613 (defun mdw-compilation-buffer-name (mode)
614 (concat "*" (downcase mode) ": "
615 (abbreviate-file-name default-directory) "*"))
616 (setq compilation-buffer-name-function 'mdw-compilation-buffer-name)
618 (eval-after-load "compile"
620 (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile)))
622 (defadvice compile (around hack-environment compile activate)
623 "Hack the environment inherited by inferiors in the compilation."
624 (let ((process-environment (copy-tree process-environment)))
625 (setenv "LD_PRELOAD" nil)
628 (defun mdw-compile (command &optional directory comint)
629 "Initiate a compilation COMMAND, maybe in a different DIRECTORY.
630 The DIRECTORY may be nil to not change. If COMINT is t, then
631 start an interactive compilation.
633 Interactively, prompt for the command if the variable
634 `compilation-read-command' is non-nil, or if requested through
635 the prefix argument. Prompt for the directory, and run
636 interactively, if requested through the prefix.
638 Use a prefix of 4, 6, 12, or 14, or type C-u between one and three times, to
639 force prompting for a directory.
641 Use a prefix of 2, 6, 10, or 14, or type C-u three times, to force
642 prompting for the command.
644 Use a prefix of 8, 10, 12, or 14, or type C-u twice or three times,
645 to force interactive compilation."
647 (let* ((prefix (prefix-numeric-value current-prefix-arg))
648 (command (eval compile-command))
649 (dir (and (plusp (logand prefix #x54))
650 (read-directory-name "Compile in directory: "))))
651 (list (if (or compilation-read-command
652 (plusp (logand prefix #x42)))
653 (compilation-read-command command)
656 (plusp (logand prefix #x58)))))
657 (let ((default-directory (or directory default-directory)))
658 (compile command comint)))
662 (defun mdw-find-build-dir (build-file)
664 (let* ((src-dir (file-name-as-directory (expand-file-name ".")))
667 (when (file-exists-p (concat dir build-file))
669 (let ((sub (expand-file-name (file-relative-name src-dir dir)
670 (concat dir "build/"))))
673 (when (file-exists-p (concat sub build-file))
675 (when (string= sub dir) (throw 'give-up nil))
676 (setq sub (file-name-directory (directory-file-name sub))))))
678 (setq dir (file-name-directory
679 (directory-file-name dir))))
680 (throw 'found nil))))))
682 (defun mdw-flymake-make-init ()
683 (let ((build-dir (mdw-find-build-dir "Makefile")))
685 (let ((tmp-src (flymake-init-create-temp-buffer-copy
686 #'flymake-create-temp-inplace)))
687 (flymake-get-syntax-check-program-args
688 tmp-src build-dir t t
689 #'flymake-get-make-cmdline)))))
691 (setq flymake-allowed-file-name-masks
692 '(("\\.\\(?:[cC]\\|cc\\|cpp\\|cxx\\|c\\+\\+\\)\\'"
693 mdw-flymake-make-init)
694 ("\\.\\(?:[hH]\\|hh\\|hpp\\|hxx\\|h\\+\\+\\)\\'"
695 mdw-flymake-master-make-init)
696 ("\\.p[lm]" flymake-perl-init)))
698 (setq flymake-mode-map
699 (let ((map (if (boundp 'flymake-mode-map)
701 (make-sparse-keymap))))
702 (define-key map [?\C-c ?\C-f ?\C-p] 'flymake-goto-prev-error)
703 (define-key map [?\C-c ?\C-f ?\C-n] 'flymake-goto-next-error)
704 (define-key map [?\C-c ?\C-f ?\C-c] 'flymake-compile)
705 (define-key map [?\C-c ?\C-f ?\C-k] 'flymake-stop-all-syntax-checks)
706 (define-key map [?\C-c ?\C-f ?\C-e] 'flymake-popup-current-error-menu)
709 ;;;--------------------------------------------------------------------------
710 ;;; Mail and news hacking.
712 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
713 "Major mode for editing news and mail messages from external programs.
714 Not much right now. Just support for doing MailCrypt stuff."
717 (run-hooks 'mail-setup-hook))
719 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
721 (add-hook 'mdwail-mode-hook
723 (set-buffer-file-coding-system 'utf-8)
724 (make-local-variable 'paragraph-separate)
725 (make-local-variable 'paragraph-start)
726 (setq paragraph-start
727 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
729 (setq paragraph-separate
730 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
731 paragraph-separate))))
733 ;; How to encrypt in mdwmail.
735 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
737 (setq start (save-excursion
738 (goto-char (point-min))
739 (or (search-forward "\n\n" nil t) (point-min)))))
741 (setq end (point-max)))
742 (mc-encrypt-generic recip scm start end from sign))
744 ;; How to sign in mdwmail.
746 (defun mdwmail-mc-sign (key scm start end uclr)
748 (setq start (save-excursion
749 (goto-char (point-min))
750 (or (search-forward "\n\n" nil t) (point-min)))))
752 (setq end (point-max)))
753 (mc-sign-generic key scm start end uclr))
755 ;; Some signature mangling.
757 (defun mdwmail-mangle-signature ()
759 (goto-char (point-min))
760 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
761 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
762 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
764 ;; Insert my login name into message-ids, so I can score replies.
766 (defadvice message-unique-id (after mdw-user-name last activate compile)
767 "Ensure that the user's name appears at the end of the message-id string,
768 so that it can be used for convenient filtering."
769 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
771 ;; Tell my movemail hack where movemail is.
773 ;; This is needed to shup up warnings about LD_PRELOAD.
775 (let ((path exec-path))
777 (let ((try (expand-file-name "movemail" (car path))))
778 (if (file-executable-p try)
779 (setenv "REAL_MOVEMAIL" try))
780 (setq path (cdr path)))))
782 ;; AUTHINFO GENERIC kludge.
784 (defvar nntp-authinfo-generic nil
785 "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'.
787 Use this to arrange for per-server settings.")
789 (defun nntp-open-authinfo-kludge (buffer)
790 "Open a connection to SERVER using `authinfo-kludge'."
791 (let ((proc (start-process "nntpd" buffer
792 "env" (concat "NNTPAUTH="
793 (or nntp-authinfo-generic
795 (error "NNTPAUTH unset")))
796 "authinfo-kludge" nntp-address)))
798 (nntp-wait-for-string "^\r*200")
800 (delete-region (point-min) (point))
803 (eval-after-load "erc"
804 '(load "~/.ercrc.el"))
806 ;; Heavy-duty Gnus patching.
808 (defun mdw-nnimap-transform-headers ()
809 (goto-char (point-min))
810 (let (article lines size string)
813 (while (not (looking-at "\\* [0-9]+ FETCH"))
814 (delete-region (point) (progn (forward-line 1) (point)))
817 (goto-char (match-end 0))
818 ;; Unfold quoted {number} strings.
819 (while (re-search-forward
820 "[^]][ (]{\\([0-9]+\\)}\r?\n"
822 ;; Start of the header section.
823 (or (re-search-forward "] {[0-9]+}\r?\n" nil t)
824 ;; Start of the next FETCH.
825 (re-search-forward "\\* [0-9]+ FETCH" nil t)
828 (setq size (string-to-number (match-string 1)))
829 (delete-region (+ (match-beginning 0) 2) (point))
830 (setq string (buffer-substring (point) (+ (point) size)))
831 (delete-region (point) (+ (point) size))
832 (insert (format "%S" (subst-char-in-string ?\n ?\s string)))
833 ;; [mdw] missing from upstream
837 (and (re-search-forward "UID \\([0-9]+\\)" (line-end-position)
842 (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)"
847 (when (search-forward "BODYSTRUCTURE" (line-end-position) t)
848 (let ((structure (ignore-errors
849 (read (current-buffer)))))
850 (while (and (consp structure)
851 (not (atom (car structure))))
852 (setq structure (car structure)))
854 (stringp (car structure))
855 (equal (upcase (nth 0 structure)) "MESSAGE")
856 (equal (upcase (nth 1 structure)) "RFC822"))
858 (nth 7 structure)))))
859 (delete-region (line-beginning-position) (line-end-position))
860 (insert (format "211 %s Article retrieved." article))
863 (insert (format "Chars: %s\n" size)))
865 (insert (format "Lines: %s\n" lines)))
866 ;; Most servers have a blank line after the headers, but
868 (unless (re-search-forward "^\r$\\|^)\r?$" nil t)
869 (goto-char (point-max)))
870 (delete-region (line-beginning-position) (line-end-position))
874 (eval-after-load 'nnimap
875 '(defalias 'nnimap-transform-headers
876 (symbol-function 'mdw-nnimap-transform-headers)))
878 (defadvice gnus-other-frame (around mdw-hack-frame-width compile activate)
879 "Always arrange for mail/news frames to be 80 columns wide."
880 (let ((default-frame-alist (cons `(width . ,(+ 80 mdw-frame-width-fudge))
881 (cl-delete 'width default-frame-alist
885 ;; Preferred programs.
887 (setq mailcap-user-mime-data
888 '(((type . "application/pdf") (viewer . "mupdf %s"))))
890 ;;;--------------------------------------------------------------------------
891 ;;; Utility functions.
893 (or (fboundp 'line-number-at-pos)
894 (defun line-number-at-pos (&optional pos)
895 (let ((opoint (or pos (point))) start)
898 (goto-char (point-min))
904 (1+ (count-lines 1 (point))))))))
906 (defun mdw-uniquify-alist (&rest alists)
907 "Return the concatenation of the ALISTS with duplicate elements removed.
908 The first association with a given key prevails; others are
909 ignored. The input lists are not modified, although they'll
910 probably become garbage."
912 (let ((start-list (cons nil nil)))
913 (mdw-do-uniquify start-list
918 (defun mdw-do-uniquify (done end l rest)
919 "A helper function for mdw-uniquify-alist.
920 The DONE argument is a list whose first element is `nil'. It
921 contains the uniquified alist built so far. The leading `nil' is
922 stripped off at the end of the operation; it's only there so that
923 DONE always references a cons cell. END refers to the final cons
924 cell in the DONE list; it is modified in place each time to avoid
925 the overheads of `append'ing all the time. The L argument is the
926 alist we're currently processing; the remaining alists are given
929 ;; There are several different cases to deal with here.
932 ;; Current list isn't empty. Add the first item to the DONE list if
933 ;; there's not an item with the same KEY already there.
934 (l (or (assoc (car (car l)) done)
936 (setcdr end (cons (car l) nil))
937 (setq end (cdr end))))
938 (mdw-do-uniquify done end (cdr l) rest))
940 ;; The list we were working on is empty. Shunt the next list into the
941 ;; current list position and go round again.
942 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
944 ;; Everything's done. Remove the leading `nil' from the DONE list and
945 ;; return it. Finished!
949 "Insert the current date in a pleasing way."
951 (insert (save-excursion
952 (let ((buffer (get-buffer-create "*tmp*")))
953 (unwind-protect (progn (set-buffer buffer)
955 (shell-command "date +%Y-%m-%d" t)
959 (kill-buffer buffer))))))
961 (defun uuencode (file &optional name)
962 "UUencodes a file, maybe calling it NAME, into the current buffer."
963 (interactive "fInput file name: ")
965 ;; If NAME isn't specified, then guess from the filename.
969 (or (string-match "[^/]*$" file) 0))))
970 (print (format "uuencode `%s' `%s'" file name))
972 ;; Now actually do the thing.
973 (call-process "uuencode" file t nil name))
975 (defvar np-file "~/.np"
976 "*Where the `now-playing' file is.")
978 (defun np (&optional arg)
979 "Grabs a `now-playing' string."
983 (goto-char (point-max))
985 (insert-file-contents np-file)))))
987 (defun mdw-version-< (ver-a ver-b)
988 "Answer whether VER-A is strictly earlier than VER-B.
989 VER-A and VER-B are version numbers, which are strings containing digit
990 sequences separated by `.'."
991 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
992 (split-string ver-a "\\.")))
993 (lb (mapcar (lambda (x) (car (read-from-string x)))
994 (split-string ver-b "\\."))))
997 (cond ((null la) (throw 'done lb))
998 ((null lb) (throw 'done nil))
999 ((< (car la) (car lb)) (throw 'done t))
1000 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))
1001 (t (throw 'done nil)))))))
1003 (defun mdw-check-autorevert ()
1004 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
1005 This takes into consideration whether it's been found using
1006 tramp, which seems to get itself into a twist."
1007 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
1009 ((and (buffer-file-name)
1010 (fboundp 'tramp-tramp-file-p)
1011 (tramp-tramp-file-p (buffer-file-name)))
1012 (unless global-auto-revert-ignore-buffer
1013 (setq global-auto-revert-ignore-buffer 'tramp)))
1014 ((eq global-auto-revert-ignore-buffer 'tramp)
1015 (setq global-auto-revert-ignore-buffer nil))))
1017 (defadvice find-file (after mdw-autorevert activate)
1018 (mdw-check-autorevert))
1019 (defadvice write-file (after mdw-autorevert activate)
1020 (mdw-check-autorevert))
1022 (defun mdw-auto-revert ()
1023 "Recheck all of the autorevertable buffers, and update VC modelines."
1025 (let ((auto-revert-check-vc-info t))
1026 (auto-revert-buffers)))
1028 (defun comint-send-and-indent ()
1031 (and mdw-auto-indent
1032 (indent-for-tab-command)))
1034 (defadvice comint-line-beginning-position
1035 (around mdw-calculate-it-properly () activate compile)
1036 "Calculate the actual line start for multi-line input."
1037 (if (or comint-use-prompt-regexp
1038 (eq (field-at-pos (point)) 'output))
1040 (setq ad-return-value
1041 (constrain-to-field (line-beginning-position) (point)))))
1043 ;;;--------------------------------------------------------------------------
1046 (defadvice dired-maybe-insert-subdir
1047 (around mdw-marked-insertion first activate)
1048 "The DIRNAME may be a list of directory names to insert.
1049 Interactively, if files are marked, then insert all of them.
1050 With a numeric prefix argument, select that many entries near
1051 point; with a non-numeric prefix argument, prompt for listing
1054 (list (dired-get-marked-files nil
1055 (and (integerp current-prefix-arg)
1058 (and current-prefix-arg
1059 (not (integerp current-prefix-arg))
1060 (read-string "Switches for listing: "
1061 (or dired-subdir-switches
1062 dired-actual-switches)))))
1063 (let ((dirs (ad-get-arg 0)))
1064 (dolist (dir (if (listp dirs) dirs (list dirs)))
1068 (defun mdw-dired-run (args &optional syncp)
1069 (interactive (let ((file (dired-get-filename t)))
1070 (list (read-string (format "Arguments for %s: " file))
1071 current-prefix-arg)))
1072 (funcall (if syncp 'shell-command 'async-shell-command)
1073 (concat (shell-quote-argument (dired-get-filename nil))
1076 (defadvice dired-do-flagged-delete
1077 (around mdw-delete-if-prefix-argument activate compile)
1078 (let ((delete-by-moving-to-trash (and (null current-prefix-arg)
1079 delete-by-moving-to-trash)))
1082 (eval-after-load "dired"
1083 '(define-key dired-mode-map "X" 'mdw-dired-run))
1085 ;;;--------------------------------------------------------------------------
1088 (defun mdw-w3m-browse-url (url &optional new-session-p)
1089 "Invoke w3m on the URL in its current window, or at least a different one.
1090 If NEW-SESSION-P, start a new session."
1091 (interactive "sURL: \nP")
1093 (let ((window (selected-window)))
1096 (select-window (or (and (not new-session-p)
1097 (get-buffer-window "*w3m*"))
1099 (if (one-window-p t) (split-window))
1101 (w3m-browse-url url new-session-p))
1102 (select-window window)))))
1104 (eval-after-load 'w3m
1105 '(define-key w3m-mode-map [?\e ?\r] 'w3m-view-this-url-new-session))
1107 (defvar mdw-good-url-browsers
1108 '(browse-url-mozilla
1110 (w3m . mdw-w3m-browse-url)
1112 "List of good browsers for mdw-good-url-browsers.
1113 Each item is a browser function name, or a cons (CHECK . FUNC).
1114 A symbol FOO stands for (FOO . FOO).")
1116 (defun mdw-good-url-browser ()
1117 "Return a good URL browser.
1118 Trundle the list of such things, finding the first item for which
1119 CHECK is fboundp, and returning the correponding FUNC."
1120 (let ((bs mdw-good-url-browsers) b check func answer)
1121 (while (and bs (not answer))
1125 (setq check (car b) func (cdr b))
1126 (setq check b func b))
1128 (setq answer func)))
1131 (eval-after-load "w3m-search"
1135 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
1136 ("gd" "Google Directory"
1137 "http://www.google.com/search?cat=gwd/Top&q=%s")
1138 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
1139 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
1140 ("gi" "Images" "http://images.google.com/images?q=%s")
1142 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
1144 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
1145 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
1146 ("nc-wiki" "nCipher wiki"
1147 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
1148 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
1149 ("lp" "Launchpad bug by number"
1150 "https://bugs.launchpad.net/bugs/%s")
1151 ("lppkg" "Launchpad bugs by package"
1152 "https://bugs.launchpad.net/%s")
1154 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
1155 ("debbug" "Debian bug by number"
1156 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
1157 ("debbugpkg" "Debian bugs by package"
1158 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
1159 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
1160 (add-to-list 'w3m-search-engine-alist
1161 (list (cadr item) (caddr item) nil))
1162 (add-to-list 'w3m-uri-replace-alist
1163 (list (concat "\\`" (car item) ":")
1164 'w3m-search-uri-replace
1167 ;;;--------------------------------------------------------------------------
1168 ;;; Paragraph filling.
1170 ;; Useful variables.
1172 (defvar mdw-fill-prefix nil
1173 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
1174 If there's no fill prefix currently set (by the `fill-prefix'
1175 variable) and there's a match from one of the regexps here, it
1176 gets used to set the fill-prefix for the current operation.
1178 The variable is a list of items of the form `REGEXP . PREFIX'; if
1179 the REGEXP matches, the PREFIX is used to set the fill prefix.
1180 It in turn is a list of things:
1182 STRING -- insert a literal string
1183 (match . N) -- insert the thing matched by bracketed subexpression N
1184 (pad . N) -- a string of whitespace the same width as subexpression N
1185 (expr . FORM) -- the result of evaluating FORM")
1187 (make-variable-buffer-local 'mdw-fill-prefix)
1189 (defvar mdw-hanging-indents
1191 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
1194 "*Standard regexp matching parts of a hanging indent.
1195 This is mainly useful in `auto-fill-mode'.")
1197 ;; Utility functions.
1199 (defun mdw-maybe-tabify (s)
1200 "Tabify or untabify the string S, according to `indent-tabs-mode'."
1201 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
1205 (let ((start (point-min)) (end (point-max)))
1206 (funcall tabfun (point-min) (point-max))
1207 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
1209 (defun mdw-examine-fill-prefixes (l)
1210 "Given a list of dynamic fill prefixes, pick one which matches
1211 context and return the static fill prefix to use. Point must be
1212 at the start of a line, and match data must be saved."
1214 ((looking-at (car (car l)))
1215 (mdw-maybe-tabify (apply #'concat
1216 (mapcar #'mdw-do-prefix-match
1218 (t (mdw-examine-fill-prefixes (cdr l)))))
1220 (defun mdw-maybe-car (p)
1221 "If P is a pair, return (car P), otherwise just return P."
1222 (if (consp p) (car p) p))
1224 (defun mdw-padding (s)
1225 "Return a string the same width as S but made entirely from whitespace."
1226 (let* ((l (length s)) (i 0) (n (make-string l ? )))
1228 (if (= 9 (aref s i))
1233 (defun mdw-do-prefix-match (m)
1234 "Expand a dynamic prefix match element.
1235 See `mdw-fill-prefix' for details."
1236 (cond ((not (consp m)) (format "%s" m))
1237 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
1238 ((eq (car m) 'pad) (mdw-padding (match-string
1239 (mdw-maybe-car (cdr m)))))
1240 ((eq (car m) 'eval) (eval (cdr m)))
1243 (defun mdw-choose-dynamic-fill-prefix ()
1244 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
1245 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
1246 ((not mdw-fill-prefix) fill-prefix)
1250 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
1252 (defadvice do-auto-fill (around mdw-dynamic-fill-prefix () activate compile)
1253 "Handle auto-filling, working out a dynamic fill prefix in the
1254 case where there isn't a sensible static one."
1255 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1258 (defun mdw-fill-paragraph ()
1259 "Fill paragraph, getting a dynamic fill prefix."
1261 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1262 (fill-paragraph nil)))
1264 (defun mdw-standard-fill-prefix (rx &optional mat)
1265 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
1266 This is just a short-cut for setting the thing by hand, and by
1267 design it doesn't cope with anything approximating a complicated
1269 (setq mdw-fill-prefix
1270 `((,(concat rx mdw-hanging-indents)
1272 (pad . ,(or mat 2))))))
1274 ;;;--------------------------------------------------------------------------
1275 ;;; Other common declarations.
1277 ;; Common mode settings.
1279 (defvar mdw-auto-indent t
1280 "Whether to indent automatically after a newline.")
1282 (defun mdw-whitespace-mode (&optional arg)
1283 "Turn on/off whitespace mode, but don't highlight trailing space."
1285 (when (and (boundp 'whitespace-style)
1286 (fboundp 'whitespace-mode))
1287 (let ((whitespace-style (remove 'trailing whitespace-style)))
1288 (whitespace-mode arg))
1289 (setq show-trailing-whitespace whitespace-mode)))
1291 (defvar mdw-do-misc-mode-hacking nil)
1293 (defun mdw-misc-mode-config ()
1294 (and mdw-auto-indent
1295 (cond ((eq major-mode 'lisp-mode)
1296 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
1297 ((derived-mode-p 'slime-repl-mode 'asm-mode 'comint-mode)
1300 (local-set-key "\C-m" 'newline-and-indent))))
1301 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
1302 (local-set-key [C-return] 'newline)
1303 (make-local-variable 'page-delimiter)
1304 (setq page-delimiter (concat "^" "\f"
1308 "\\(" " " ".*" " " "\\)?"
1312 (setq comment-column 40)
1314 (setq fill-column mdw-text-width)
1315 (and (fboundp 'gtags-mode)
1317 (if (fboundp 'hs-minor-mode)
1318 (trap (hs-minor-mode t))
1319 (outline-minor-mode t))
1321 (trap (turn-on-font-lock)))
1323 (defun mdw-post-local-vars-misc-mode-config ()
1324 (setq whitespace-line-column mdw-text-width)
1325 (when (and mdw-do-misc-mode-hacking
1326 (not buffer-read-only))
1327 (setq show-trailing-whitespace t)
1328 (mdw-whitespace-mode 1)))
1329 (add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
1331 (defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1332 `(progn ,@(mapcar (lambda (func)
1334 (after mdw-angry-fruit-salad activate)
1335 (when mdw-do-misc-mode-hacking
1336 (setq show-trailing-whitespace
1337 (not buffer-read-only))
1338 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1340 (mdw-advise-update-angry-fruit-salad toggle-read-only
1346 (eval-after-load 'gtags
1348 (dolist (key '([mouse-2] [mouse-3]))
1349 (define-key gtags-mode-map key nil))
1350 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1351 (define-key gtags-select-mode-map [C-S-mouse-2]
1352 'gtags-select-tag-by-event)
1353 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1354 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
1356 ;; Backup file handling.
1358 (defvar mdw-backup-disable-regexps nil
1359 "*List of regular expressions: if a file name matches any of
1360 these then the file is not backed up.")
1362 (defun mdw-backup-enable-predicate (name)
1363 "[mdw]'s default backup predicate.
1364 Allows a backup if the standard predicate would allow it, and it
1365 doesn't match any of the regular expressions in
1366 `mdw-backup-disable-regexps'."
1367 (and (normal-backup-enable-predicate name)
1368 (let ((answer t) (list mdw-backup-disable-regexps))
1371 (if (string-match (car list) name)
1373 (setq list (cdr list)))
1375 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
1379 (defun mdw-last-one-out-turn-off-the-lights (frame)
1380 "Disconnect from an X display if this was the last frame on that display."
1381 (let ((frame-display (frame-parameter frame 'display)))
1382 (when (and frame-display
1383 (eq window-system 'x)
1384 (not (some (lambda (fr)
1385 (and (not (eq fr frame))
1386 (string= (frame-parameter fr 'display)
1389 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1390 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1392 ;;;--------------------------------------------------------------------------
1393 ;;; Fullscreen-ness.
1395 (defvar mdw-full-screen-parameters
1396 '((menu-bar-lines . 0)
1397 ;(vertical-scroll-bars . nil)
1399 "Frame parameters to set when making a frame fullscreen.")
1401 (defvar mdw-full-screen-save
1403 "Extra frame parameters to save when setting fullscreen.")
1405 (defun mdw-toggle-full-screen (&optional frame)
1406 "Show the FRAME fullscreen."
1409 (cond ((frame-parameter frame 'fullscreen)
1410 (set-frame-parameter frame 'fullscreen nil)
1411 (modify-frame-parameters
1413 (or (frame-parameter frame 'mdw-full-screen-saved)
1414 (mapcar (lambda (assoc)
1415 (assq (car assoc) default-frame-alist))
1416 mdw-full-screen-parameters))))
1418 (let ((saved (mapcar (lambda (param)
1419 (cons param (frame-parameter frame param)))
1420 (append (mapcar #'car
1421 mdw-full-screen-parameters)
1422 mdw-full-screen-save))))
1423 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1424 (modify-frame-parameters frame mdw-full-screen-parameters)
1425 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1427 ;;;--------------------------------------------------------------------------
1428 ;;; General fontification.
1430 (make-face 'mdw-virgin-face)
1432 (defmacro mdw-define-face (name &rest body)
1433 "Define a face, and make sure it's actually set as the definition."
1437 (copy-face 'mdw-virgin-face ',name)
1438 (defvar ,name ',name)
1439 (put ',name 'face-defface-spec ',body)
1440 (face-spec-set ',name ',body nil)))
1442 (mdw-define-face default
1443 (((type w32)) :family "courier new" :height 85)
1444 (((type x)) :family "6x13" :foundry "trad" :height 130)
1445 (((type color)) :foreground "white" :background "black")
1447 (mdw-define-face fixed-pitch
1448 (((type w32)) :family "courier new" :height 85)
1449 (((type x)) :family "6x13" :foundry "trad" :height 130)
1450 (t :foreground "white" :background "black"))
1451 (mdw-define-face fixed-pitch-serif
1452 (((type w32)) :family "courier new" :height 85 :weight bold)
1453 (((type x)) :family "6x13" :foundry "trad" :height 130 :weight bold)
1454 (t :foreground "white" :background "black" :weight bold))
1455 (mdw-define-face variable-pitch
1456 (((type x)) :family "helvetica" :height 120))
1457 (mdw-define-face region
1458 (((min-colors 64)) :background "grey30")
1459 (((class color)) :background "blue")
1460 (t :inverse-video t))
1461 (mdw-define-face match
1462 (((class color)) :background "blue")
1463 (t :inverse-video t))
1464 (mdw-define-face mc/cursor-face
1465 (((class color)) :background "red")
1466 (t :inverse-video t))
1467 (mdw-define-face minibuffer-prompt
1469 (mdw-define-face mode-line
1470 (((class color)) :foreground "blue" :background "yellow"
1471 :box (:line-width 1 :style released-button))
1472 (t :inverse-video t))
1473 (mdw-define-face mode-line-inactive
1474 (((class color)) :foreground "yellow" :background "blue"
1475 :box (:line-width 1 :style released-button))
1476 (t :inverse-video t))
1477 (mdw-define-face nobreak-space
1479 (t :inherit escape-glyph :underline t))
1480 (mdw-define-face scroll-bar
1481 (t :foreground "black" :background "lightgrey"))
1482 (mdw-define-face fringe
1483 (t :foreground "yellow"))
1484 (mdw-define-face show-paren-match
1485 (((min-colors 64)) :background "darkgreen")
1486 (((class color)) :background "green")
1488 (mdw-define-face show-paren-mismatch
1489 (((class color)) :background "red")
1490 (t :inverse-video t))
1491 (mdw-define-face highlight
1492 (((min-colors 64)) :background "DarkSeaGreen4")
1493 (((class color)) :background "cyan")
1494 (t :inverse-video t))
1496 (mdw-define-face holiday-face
1497 (t :background "red"))
1498 (mdw-define-face calendar-today-face
1499 (t :foreground "yellow" :weight bold))
1501 (mdw-define-face comint-highlight-prompt
1503 (mdw-define-face comint-highlight-input
1506 (mdw-define-face Man-underline
1507 (((type tty)) :underline t)
1510 (mdw-define-face ido-subdir
1511 (t :foreground "cyan" :weight bold))
1513 (mdw-define-face dired-directory
1514 (t :foreground "cyan" :weight bold))
1515 (mdw-define-face dired-symlink
1516 (t :foreground "cyan"))
1517 (mdw-define-face dired-perm-write
1520 (mdw-define-face trailing-whitespace
1521 (((class color)) :background "red")
1522 (t :inverse-video t))
1523 (mdw-define-face whitespace-line
1524 (((class color)) :background "darkred")
1525 (t :inverse-video t))
1526 (mdw-define-face mdw-punct-face
1527 (((min-colors 64)) :foreground "burlywood2")
1528 (((class color)) :foreground "yellow"))
1529 (mdw-define-face mdw-number-face
1530 (t :foreground "yellow"))
1531 (mdw-define-face mdw-trivial-face)
1532 (mdw-define-face font-lock-function-name-face
1534 (mdw-define-face font-lock-keyword-face
1536 (mdw-define-face font-lock-constant-face
1538 (mdw-define-face font-lock-builtin-face
1540 (mdw-define-face font-lock-type-face
1541 (t :weight bold :slant italic))
1542 (mdw-define-face font-lock-reference-face
1544 (mdw-define-face font-lock-variable-name-face
1546 (mdw-define-face font-lock-comment-delimiter-face
1547 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1548 (((class color)) :foreground "green")
1550 (mdw-define-face font-lock-comment-face
1551 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1552 (((class color)) :foreground "green")
1554 (mdw-define-face font-lock-string-face
1555 (((min-colors 64)) :foreground "SkyBlue1")
1556 (((class color)) :foreground "cyan")
1559 (mdw-define-face message-separator
1560 (t :background "red" :foreground "white" :weight bold))
1561 (mdw-define-face message-cited-text
1562 (default :slant italic)
1563 (((min-colors 64)) :foreground "SkyBlue1")
1564 (((class color)) :foreground "cyan"))
1565 (mdw-define-face message-header-cc
1566 (default :slant italic)
1567 (((min-colors 64)) :foreground "SeaGreen1")
1568 (((class color)) :foreground "green"))
1569 (mdw-define-face message-header-newsgroups
1570 (default :slant italic)
1571 (((min-colors 64)) :foreground "SeaGreen1")
1572 (((class color)) :foreground "green"))
1573 (mdw-define-face message-header-subject
1574 (((min-colors 64)) :foreground "SeaGreen1")
1575 (((class color)) :foreground "green"))
1576 (mdw-define-face message-header-to
1577 (((min-colors 64)) :foreground "SeaGreen1")
1578 (((class color)) :foreground "green"))
1579 (mdw-define-face message-header-xheader
1580 (default :slant italic)
1581 (((min-colors 64)) :foreground "SeaGreen1")
1582 (((class color)) :foreground "green"))
1583 (mdw-define-face message-header-other
1584 (default :slant italic)
1585 (((min-colors 64)) :foreground "SeaGreen1")
1586 (((class color)) :foreground "green"))
1587 (mdw-define-face message-header-name
1588 (default :weight bold)
1589 (((min-colors 64)) :foreground "SeaGreen1")
1590 (((class color)) :foreground "green"))
1592 (mdw-define-face which-func
1595 (mdw-define-face gnus-header-name
1596 (default :weight bold)
1597 (((min-colors 64)) :foreground "SeaGreen1")
1598 (((class color)) :foreground "green"))
1599 (mdw-define-face gnus-header-subject
1600 (((min-colors 64)) :foreground "SeaGreen1")
1601 (((class color)) :foreground "green"))
1602 (mdw-define-face gnus-header-from
1603 (((min-colors 64)) :foreground "SeaGreen1")
1604 (((class color)) :foreground "green"))
1605 (mdw-define-face gnus-header-to
1606 (((min-colors 64)) :foreground "SeaGreen1")
1607 (((class color)) :foreground "green"))
1608 (mdw-define-face gnus-header-content
1609 (default :slant italic)
1610 (((min-colors 64)) :foreground "SeaGreen1")
1611 (((class color)) :foreground "green"))
1613 (mdw-define-face gnus-cite-1
1614 (((min-colors 64)) :foreground "SkyBlue1")
1615 (((class color)) :foreground "cyan"))
1616 (mdw-define-face gnus-cite-2
1617 (((min-colors 64)) :foreground "RoyalBlue2")
1618 (((class color)) :foreground "blue"))
1619 (mdw-define-face gnus-cite-3
1620 (((min-colors 64)) :foreground "MediumOrchid")
1621 (((class color)) :foreground "magenta"))
1622 (mdw-define-face gnus-cite-4
1623 (((min-colors 64)) :foreground "firebrick2")
1624 (((class color)) :foreground "red"))
1625 (mdw-define-face gnus-cite-5
1626 (((min-colors 64)) :foreground "burlywood2")
1627 (((class color)) :foreground "yellow"))
1628 (mdw-define-face gnus-cite-6
1629 (((min-colors 64)) :foreground "SeaGreen1")
1630 (((class color)) :foreground "green"))
1631 (mdw-define-face gnus-cite-7
1632 (((min-colors 64)) :foreground "SlateBlue1")
1633 (((class color)) :foreground "cyan"))
1634 (mdw-define-face gnus-cite-8
1635 (((min-colors 64)) :foreground "RoyalBlue2")
1636 (((class color)) :foreground "blue"))
1637 (mdw-define-face gnus-cite-9
1638 (((min-colors 64)) :foreground "purple2")
1639 (((class color)) :foreground "magenta"))
1640 (mdw-define-face gnus-cite-10
1641 (((min-colors 64)) :foreground "DarkOrange2")
1642 (((class color)) :foreground "red"))
1643 (mdw-define-face gnus-cite-11
1644 (t :foreground "grey"))
1646 (mdw-define-face diff-header
1648 (mdw-define-face diff-index
1650 (mdw-define-face diff-file-header
1652 (mdw-define-face diff-hunk-header
1653 (((min-colors 64)) :foreground "SkyBlue1")
1654 (((class color)) :foreground "cyan"))
1655 (mdw-define-face diff-function
1656 (default :weight bold)
1657 (((min-colors 64)) :foreground "SkyBlue1")
1658 (((class color)) :foreground "cyan"))
1659 (mdw-define-face diff-header
1660 (((min-colors 64)) :background "grey10"))
1661 (mdw-define-face diff-added
1662 (((class color)) :foreground "green"))
1663 (mdw-define-face diff-removed
1664 (((class color)) :foreground "red"))
1665 (mdw-define-face diff-context
1667 (mdw-define-face diff-refine-change
1668 (((min-colors 64)) :background "RoyalBlue4")
1670 (mdw-define-face diff-refine-removed
1671 (((min-colors 64)) :background "#500")
1673 (mdw-define-face diff-refine-added
1674 (((min-colors 64)) :background "#050")
1677 (setq ediff-force-faces t)
1678 (mdw-define-face ediff-current-diff-A
1679 (((min-colors 64)) :background "darkred")
1680 (((class color)) :background "red")
1681 (t :inverse-video t))
1682 (mdw-define-face ediff-fine-diff-A
1683 (((min-colors 64)) :background "red3")
1684 (((class color)) :inverse-video t)
1685 (t :inverse-video nil))
1686 (mdw-define-face ediff-even-diff-A
1687 (((min-colors 64)) :background "#300"))
1688 (mdw-define-face ediff-odd-diff-A
1689 (((min-colors 64)) :background "#300"))
1690 (mdw-define-face ediff-current-diff-B
1691 (((min-colors 64)) :background "darkgreen")
1692 (((class color)) :background "magenta")
1693 (t :inverse-video t))
1694 (mdw-define-face ediff-fine-diff-B
1695 (((min-colors 64)) :background "green4")
1696 (((class color)) :inverse-video t)
1697 (t :inverse-video nil))
1698 (mdw-define-face ediff-even-diff-B
1699 (((min-colors 64)) :background "#020"))
1700 (mdw-define-face ediff-odd-diff-B
1701 (((min-colors 64)) :background "#020"))
1702 (mdw-define-face ediff-current-diff-C
1703 (((min-colors 64)) :background "darkblue")
1704 (((class color)) :background "blue")
1705 (t :inverse-video t))
1706 (mdw-define-face ediff-fine-diff-C
1707 (((min-colors 64)) :background "blue1")
1708 (((class color)) :inverse-video t)
1709 (t :inverse-video nil))
1710 (mdw-define-face ediff-even-diff-C
1711 (((min-colors 64)) :background "#004"))
1712 (mdw-define-face ediff-odd-diff-C
1713 (((min-colors 64)) :background "#004"))
1714 (mdw-define-face ediff-current-diff-Ancestor
1715 (((min-colors 64)) :background "#630")
1716 (((class color)) :background "blue")
1717 (t :inverse-video t))
1718 (mdw-define-face ediff-even-diff-Ancestor
1719 (((min-colors 64)) :background "#320"))
1720 (mdw-define-face ediff-odd-diff-Ancestor
1721 (((min-colors 64)) :background "#320"))
1723 (mdw-define-face magit-hash
1724 (((min-colors 64)) :foreground "grey40")
1725 (((class color)) :foreground "blue"))
1726 (mdw-define-face magit-diff-hunk-heading
1727 (((min-colors 64)) :foreground "grey70" :background "grey25")
1728 (((class color)) :foreground "yellow"))
1729 (mdw-define-face magit-diff-hunk-heading-highlight
1730 (((min-colors 64)) :foreground "grey70" :background "grey35")
1731 (((class color)) :foreground "yellow" :background "blue"))
1732 (mdw-define-face magit-diff-added
1733 (((min-colors 64)) :foreground "#ddffdd" :background "#335533")
1734 (((class color)) :foreground "green"))
1735 (mdw-define-face magit-diff-added-highlight
1736 (((min-colors 64)) :foreground "#cceecc" :background "#336633")
1737 (((class color)) :foreground "green" :background "blue"))
1738 (mdw-define-face magit-diff-removed
1739 (((min-colors 64)) :foreground "#ffdddd" :background "#553333")
1740 (((class color)) :foreground "red"))
1741 (mdw-define-face magit-diff-removed-highlight
1742 (((min-colors 64)) :foreground "#eecccc" :background "#663333")
1743 (((class color)) :foreground "red" :background "blue"))
1744 (mdw-define-face magit-blame-heading
1745 (((min-colors 64)) :foreground "white" :background "grey25"
1746 :weight normal :slant normal)
1747 (((class color)) :foreground "white" :background "blue"
1748 :weight normal :slant normal))
1749 (mdw-define-face magit-blame-name
1750 (t :inherit magit-blame-heading :slant italic))
1751 (mdw-define-face magit-blame-date
1752 (((min-colors 64)) :inherit magit-blame-heading :foreground "grey60")
1753 (((class color)) :inherit magit-blame-heading :foreground "cyan"))
1754 (mdw-define-face magit-blame-summary
1755 (t :inherit magit-blame-heading :weight bold))
1757 (mdw-define-face dylan-header-background
1758 (((min-colors 64)) :background "NavyBlue")
1759 (((class color)) :background "blue"))
1761 (mdw-define-face erc-input-face
1762 (t :foreground "red"))
1764 (mdw-define-face woman-bold
1766 (mdw-define-face woman-italic
1769 (eval-after-load "rst"
1771 (mdw-define-face rst-level-1-face
1772 (t :foreground "SkyBlue1" :weight bold))
1773 (mdw-define-face rst-level-2-face
1774 (t :foreground "SeaGreen1" :weight bold))
1775 (mdw-define-face rst-level-3-face
1777 (mdw-define-face rst-level-4-face
1779 (mdw-define-face rst-level-5-face
1781 (mdw-define-face rst-level-6-face
1784 (mdw-define-face p4-depot-added-face
1785 (t :foreground "green"))
1786 (mdw-define-face p4-depot-branch-op-face
1787 (t :foreground "yellow"))
1788 (mdw-define-face p4-depot-deleted-face
1789 (t :foreground "red"))
1790 (mdw-define-face p4-depot-unmapped-face
1791 (t :foreground "SkyBlue1"))
1792 (mdw-define-face p4-diff-change-face
1793 (t :foreground "yellow"))
1794 (mdw-define-face p4-diff-del-face
1795 (t :foreground "red"))
1796 (mdw-define-face p4-diff-file-face
1797 (t :foreground "SkyBlue1"))
1798 (mdw-define-face p4-diff-head-face
1799 (t :background "grey10"))
1800 (mdw-define-face p4-diff-ins-face
1801 (t :foreground "green"))
1803 (mdw-define-face w3m-anchor-face
1804 (t :foreground "SkyBlue1" :underline t))
1805 (mdw-define-face w3m-arrived-anchor-face
1806 (t :foreground "SkyBlue1" :underline t))
1808 (mdw-define-face whizzy-slice-face
1809 (t :background "grey10"))
1810 (mdw-define-face whizzy-error-face
1811 (t :background "darkred"))
1813 ;; Ellipses used to indicate hidden text (and similar).
1814 (mdw-define-face mdw-ellipsis-face
1815 (((type tty)) :foreground "blue") (t :foreground "grey60"))
1816 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
1817 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
1818 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
1819 (bar (make-glyph-code ?| mdw-ellipsis-face)))
1820 (set-display-table-slot standard-display-table 0 dollar)
1821 (set-display-table-slot standard-display-table 1 backslash)
1822 (set-display-table-slot standard-display-table 4
1823 (vector dot dot dot))
1824 (set-display-table-slot standard-display-table 5 bar))
1826 ;;;--------------------------------------------------------------------------
1829 (mdw-define-face mdw-point-overlay-face
1831 (((min-colors 64)) :background "darkblue")
1832 (((class color)) :background "blue")
1833 (((type tty) (class mono)) :inverse-video t))
1835 (defvar mdw-point-overlay-fringe-display '(vertical-bar . vertical-bar))
1837 (defun mdw-configure-point-overlay ()
1838 (let ((ov (make-overlay 0 0)))
1839 (overlay-put ov 'priority 0)
1840 (let* ((fringe (or mdw-point-overlay-fringe-display (cons nil nil)))
1841 (left (car fringe)) (right (cdr fringe))
1845 (put-text-property 0 1 'display `(left-fringe ,left) ss)
1846 (setq s (concat s ss))))
1849 (put-text-property 0 1 'display `(right-fringe ,right) ss)
1850 (setq s (concat s ss))))
1851 (when (or left right)
1852 (overlay-put ov 'before-string s)))
1853 (overlay-put ov 'face 'mdw-point-overlay-face)
1857 (defvar mdw-point-overlay (mdw-configure-point-overlay)
1858 "An overlay used for showing where point is in the selected window.")
1859 (defun mdw-reconfigure-point-overlay ()
1861 (setq mdw-point-overlay (mdw-configure-point-overlay)))
1863 (defun mdw-remove-point-overlay ()
1864 "Remove the current-point overlay."
1865 (delete-overlay mdw-point-overlay))
1867 (defun mdw-update-point-overlay ()
1868 "Mark the current point position with an overlay."
1869 (if (not mdw-point-overlay-mode)
1870 (mdw-remove-point-overlay)
1871 (overlay-put mdw-point-overlay 'window (selected-window))
1872 (move-overlay mdw-point-overlay
1873 (line-beginning-position)
1874 (+ (line-end-position) 1))))
1876 (defvar mdw-point-overlay-buffers nil
1877 "List of buffers using `mdw-point-overlay-mode'.")
1879 (define-minor-mode mdw-point-overlay-mode
1880 "Indicate current line with an overlay."
1882 (let ((buffer (current-buffer)))
1883 (setq mdw-point-overlay-buffers
1884 (mapcan (lambda (buf)
1885 (if (and (buffer-live-p buf)
1886 (not (eq buf buffer)))
1888 mdw-point-overlay-buffers))
1889 (if mdw-point-overlay-mode
1890 (setq mdw-point-overlay-buffers
1891 (cons buffer mdw-point-overlay-buffers))))
1892 (cond (mdw-point-overlay-buffers
1893 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
1894 (add-hook 'post-command-hook 'mdw-update-point-overlay))
1896 (mdw-remove-point-overlay)
1897 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
1898 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
1900 (define-globalized-minor-mode mdw-global-point-overlay-mode
1901 mdw-point-overlay-mode
1902 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
1904 (defvar mdw-terminal-title-alist nil)
1905 (defun mdw-update-terminal-title ()
1906 (when (let ((term (frame-parameter nil 'tty-type)))
1907 (and term (string-match "^xterm" term)))
1908 (let* ((tty (frame-parameter nil 'tty))
1909 (old (assoc tty mdw-terminal-title-alist))
1910 (new (format-mode-line frame-title-format)))
1911 (unless (and old (equal (cdr old) new))
1912 (if old (rplacd old new)
1913 (setq mdw-terminal-title-alist
1914 (cons (cons tty new) mdw-terminal-title-alist)))
1915 (send-string-to-terminal (concat "\e]2;" new "\e\\"))))))
1917 (add-hook 'post-command-hook 'mdw-update-terminal-title)
1919 ;;;--------------------------------------------------------------------------
1920 ;;; C programming configuration.
1922 ;; Make C indentation nice.
1924 (defun mdw-c-lineup-arglist (langelem)
1925 "Hack for DWIMmery in c-lineup-arglist."
1927 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1929 (c-lineup-arglist langelem)))
1931 (defun mdw-c-indent-extern-mumble (langelem)
1932 "Indent `extern \"...\" {' lines."
1934 (back-to-indentation)
1936 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1940 (defun mdw-c-indent-arglist-nested (langelem)
1941 "Indent continued argument lists.
1942 If we've nested more than one argument list, then only introduce a single
1943 indentation anyway."
1944 (let ((context c-syntactic-context)
1945 (pos (c-langelem-2nd-pos c-syntactic-element))
1946 (should-indent-p t))
1948 (eq (caar context) 'arglist-cont-nonempty))
1949 (when (and (= (caddr (pop context)) pos)
1951 (memq (caar context) '(arglist-intro
1952 arglist-cont-nonempty)))
1953 (setq should-indent-p nil)))
1954 (if should-indent-p '+ 0)))
1956 (defvar mdw-define-c-styles-hook nil
1957 "Hook run when `cc-mode' starts up to define styles.")
1959 (defmacro mdw-define-c-style (name &rest assocs)
1960 "Define a C style, called NAME (a symbol), setting ASSOCs.
1961 A function, named `mdw-define-c-style/NAME', is defined to actually install
1962 the style using `c-add-style', and added to the hook
1963 `mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
1965 (declare (indent defun))
1966 (let* ((name-string (symbol-name name))
1967 (func (intern (concat "mdw-define-c-style/" name-string))))
1969 (defun ,func () (c-add-style ,name-string ',assocs))
1970 (and (featurep 'cc-mode) (,func))
1971 (add-hook 'mdw-define-c-styles-hook ',func))))
1973 (eval-after-load "cc-mode"
1974 '(run-hooks 'mdw-define-c-styles-hook))
1976 (mdw-define-c-style mdw-trustonic-c
1977 (c-basic-offset . 4)
1978 (comment-column . 0)
1979 (c-indent-comment-alist (anchored-comment . (column . 0))
1980 (end-block . (space . 1))
1981 (cpp-end-block . (space . 1))
1982 (other . (space . 1)))
1983 (c-class-key . "class")
1984 (c-backslash-column . 0)
1985 (c-auto-align-backslashes . nil)
1986 (c-label-minimum-indentation . 0)
1987 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1988 (defun-open . (add 0 c-indent-one-line-block))
1989 (arglist-cont-nonempty . mdw-c-indent-arglist-nested)
1990 (topmost-intro . mdw-c-indent-extern-mumble)
1991 (cpp-define-intro . 0)
1993 (inextern-lang . [0])
1999 (statement-cont . +)
2000 (statement-case-intro . +)))
2002 (mdw-define-c-style mdw-c
2003 (c-basic-offset . 2)
2004 (comment-column . 40)
2005 (c-class-key . "class")
2006 (c-backslash-column . 72)
2007 (c-label-minimum-indentation . 0)
2008 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
2009 (defun-open . (add 0 c-indent-one-line-block))
2010 (arglist-cont-nonempty . mdw-c-lineup-arglist)
2011 (topmost-intro . mdw-c-indent-extern-mumble)
2012 (cpp-define-intro . 0)
2014 (inextern-lang . [0])
2020 (statement-cont . +)
2021 (statement-case-intro . +)))
2023 (defun mdw-set-default-c-style (modes style)
2024 "Update the default CC Mode style for MODES to be STYLE.
2026 MODES may be a list of major mode names or a singleton. STYLE is a style
2028 (let ((modes (if (listp modes) modes (list modes)))
2029 (style (symbol-name style)))
2030 (setq c-default-style
2031 (append (mapcar (lambda (mode)
2034 (remove-if (lambda (assoc)
2035 (memq (car assoc) modes))
2036 (if (listp c-default-style)
2038 (list (cons 'other c-default-style))))))))
2039 (setq c-default-style "mdw-c")
2041 (mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
2043 (defvar mdw-c-comment-fill-prefix
2044 `((,(concat "\\([ \t]*/?\\)"
2047 "\\([A-Za-z]+:[ \t]*\\)?"
2048 mdw-hanging-indents)
2049 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
2050 "Fill prefix matching C comments (both kinds).")
2052 (defun mdw-fontify-c-and-c++ ()
2054 ;; Fiddle with some syntax codes.
2055 (modify-syntax-entry ?* ". 23")
2056 (modify-syntax-entry ?/ ". 124b")
2057 (modify-syntax-entry ?\n "> b")
2060 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2062 ;; Now define things to be fontified.
2063 (make-local-variable 'font-lock-keywords)
2065 (mdw-regexps "alignas" ;C11 macro, C++11
2067 "and" ;C++, C95 macro
2068 "and_eq" ;C++, C95 macro
2069 "asm" ;K&R, C++, GCC
2070 "atomic" ;C11 macro, C++11 template type
2072 "bitand" ;C++, C95 macro
2073 "bitor" ;C++, C95 macro
2074 "bool" ;C++, C99 macro
2079 "char16_t" ;C++11, C11 library type
2080 "char32_t" ;C++11, C11 library type
2082 "complex" ;C99 macro, C++ template type
2083 "compl" ;C++, C95 macro
2087 "continue" ;K&R, C89
2089 "defined" ;C89 preprocessor
2096 ;; "entry" ;K&R -- never used
2107 "imaginary" ;C99 macro
2108 "inline" ;C++, C99, GCC
2115 "noreturn" ;C11 macro
2116 "not" ;C++, C95 macro
2117 "not_eq" ;C++, C95 macro
2120 "or" ;C++, C95 macro
2121 "or_eq" ;C++, C95 macro
2125 "register" ;K&R, C89
2126 "reinterpret_cast" ;C++
2133 "static_assert" ;C11 macro, C++11
2140 "thread_local" ;C11 macro, C++11
2146 "unsigned" ;K&R, C89
2151 "wchar_t" ;C++, C89 library type
2153 "xor" ;C++, C95 macro
2154 "xor_eq" ;C++, C95 macro
2163 "_Pragma" ;C99 preprocessor
2164 "_Static_assert" ;C11
2165 "_Thread_local" ;C11
2168 "__attribute__" ;GCC
2171 "__extension__" ;GCC
2181 (mdw-regexps "false" ;C++, C99 macro
2183 "true" ;C++, C99 macro
2185 (preprocessor-keywords
2186 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2187 "ident" "if" "ifdef" "ifndef" "import" "include"
2188 "line" "pragma" "unassert" "undef" "warning"))
2190 (mdw-regexps "class" "defs" "encode" "end" "implementation"
2191 "interface" "private" "protected" "protocol" "public"
2194 (setq font-lock-keywords
2197 ;; Fontify include files as strings.
2198 (list (concat "^[ \t]*\\#[ \t]*"
2199 "\\(include\\|import\\)"
2200 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2201 '(2 font-lock-string-face))
2203 ;; Preprocessor directives are `references'?.
2204 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2205 preprocessor-keywords
2206 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2207 '(1 font-lock-keyword-face))
2209 ;; Handle the keywords defined above.
2210 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
2211 '(0 font-lock-keyword-face))
2213 (list (concat "\\<\\(" c-keywords "\\)\\>")
2214 '(0 font-lock-keyword-face))
2216 (list (concat "\\<\\(" c-builtins "\\)\\>")
2217 '(0 font-lock-variable-name-face))
2219 ;; Handle numbers too.
2221 ;; This looks strange, I know. It corresponds to the
2222 ;; preprocessor's idea of what a number looks like, rather than
2223 ;; anything sensible.
2224 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2225 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2226 '(0 mdw-number-face))
2228 ;; And anything else is punctuation.
2229 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2230 '(0 mdw-punct-face))))))
2232 (define-derived-mode sod-mode c-mode "Sod"
2233 "Major mode for editing Sod code.")
2234 (push '("\\.sod$" . sod-mode) auto-mode-alist)
2236 (dolist (hook '(c-mode-hook objc-mode-hook c++-mode-hook))
2237 (add-hook hook 'mdw-misc-mode-config t)
2238 (add-hook hook 'mdw-fontify-c-and-c++ t))
2240 ;;;--------------------------------------------------------------------------
2243 (define-derived-mode apcalc-mode c-mode "AP Calc"
2244 "Major mode for editing Calc code.")
2246 (defun mdw-fontify-apcalc ()
2248 ;; Fiddle with some syntax codes.
2249 (modify-syntax-entry ?* ". 23")
2250 (modify-syntax-entry ?/ ". 14")
2253 (setq comment-start "/* ")
2254 (setq comment-end " */")
2255 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2257 ;; Now define things to be fontified.
2258 (make-local-variable 'font-lock-keywords)
2260 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
2261 "do" "else" "exit" "for" "global" "goto" "help" "if"
2262 "local" "mat" "obj" "print" "quit" "read" "return"
2263 "show" "static" "switch" "while" "write")))
2265 (setq font-lock-keywords
2268 ;; Handle the keywords defined above.
2269 (list (concat "\\<\\(" c-keywords "\\)\\>")
2270 '(0 font-lock-keyword-face))
2272 ;; Handle numbers too.
2274 ;; This looks strange, I know. It corresponds to the
2275 ;; preprocessor's idea of what a number looks like, rather than
2276 ;; anything sensible.
2277 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2278 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2279 '(0 mdw-number-face))
2281 ;; And anything else is punctuation.
2282 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2283 '(0 mdw-punct-face))))))
2286 (add-hook 'apcalc-mode-hook 'mdw-misc-mode-config t)
2287 (add-hook 'apcalc-mode-hook 'mdw-fontify-apcalc t))
2289 ;;;--------------------------------------------------------------------------
2290 ;;; Java programming configuration.
2292 ;; Make indentation nice.
2294 (mdw-define-c-style mdw-java
2295 (c-basic-offset . 2)
2296 (c-backslash-column . 72)
2297 (c-offsets-alist (substatement-open . 0)
2302 (statement-case-intro . +)))
2303 (mdw-set-default-c-style 'java-mode 'mdw-java)
2305 ;; Declare Java fontification style.
2307 (defun mdw-fontify-java ()
2309 ;; Fiddle with some syntax codes.
2310 (modify-syntax-entry ?@ ".")
2311 (modify-syntax-entry ?@ "." font-lock-syntax-table)
2314 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2316 ;; Now define things to be fontified.
2317 (make-local-variable 'font-lock-keywords)
2318 (let ((java-keywords
2319 (mdw-regexps "abstract" "assert"
2320 "boolean" "break" "byte"
2321 "case" "catch" "char" "class" "const" "continue"
2322 "default" "do" "double"
2323 "else" "enum" "extends"
2324 "final" "finally" "float" "for"
2326 "if" "implements" "import" "instanceof" "int"
2330 "package" "private" "protected" "public"
2332 "short" "static" "strictfp" "switch" "synchronized"
2333 "throw" "throws" "transient" "try"
2338 (mdw-regexps "false" "null" "super" "this" "true")))
2340 (setq font-lock-keywords
2343 ;; Handle the keywords defined above.
2344 (list (concat "\\<\\(" java-keywords "\\)\\>")
2345 '(0 font-lock-keyword-face))
2347 ;; Handle the magic builtins defined above.
2348 (list (concat "\\<\\(" java-builtins "\\)\\>")
2349 '(0 font-lock-variable-name-face))
2351 ;; Handle numbers too.
2353 ;; The following isn't quite right, but it's close enough.
2354 (list (concat "\\<\\("
2355 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2356 "[0-9]+\\(\\.[0-9]*\\|\\)"
2357 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2359 '(0 mdw-number-face))
2361 ;; And anything else is punctuation.
2362 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2363 '(0 mdw-punct-face))))))
2366 (add-hook 'java-mode-hook 'mdw-misc-mode-config t)
2367 (add-hook 'java-mode-hook 'mdw-fontify-java t))
2369 ;;;--------------------------------------------------------------------------
2370 ;;; Javascript programming configuration.
2372 (defun mdw-javascript-style ()
2373 (setq js-indent-level 2)
2374 (setq js-expr-indent-offset 0))
2376 (defun mdw-fontify-javascript ()
2379 (mdw-javascript-style)
2380 (setq js-auto-indent-flag t)
2382 ;; Now define things to be fontified.
2383 (make-local-variable 'font-lock-keywords)
2384 (let ((javascript-keywords
2385 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
2386 "char" "class" "const" "continue" "debugger" "default"
2387 "delete" "do" "double" "else" "enum" "export" "extends"
2388 "final" "finally" "float" "for" "function" "goto" "if"
2389 "implements" "import" "in" "instanceof" "int"
2390 "interface" "let" "long" "native" "new" "package"
2391 "private" "protected" "public" "return" "short"
2392 "static" "super" "switch" "synchronized" "throw"
2393 "throws" "transient" "try" "typeof" "var" "void"
2394 "volatile" "while" "with" "yield"))
2395 (javascript-builtins
2396 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
2397 "arguments" "this")))
2399 (setq font-lock-keywords
2402 ;; Handle the keywords defined above.
2403 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
2404 '(0 font-lock-keyword-face))
2406 ;; Handle the predefined builtins defined above.
2407 (list (concat "\\_<\\(" javascript-builtins "\\)\\_>")
2408 '(0 font-lock-variable-name-face))
2410 ;; Handle numbers too.
2412 ;; The following isn't quite right, but it's close enough.
2413 (list (concat "\\_<\\("
2414 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2415 "[0-9]+\\(\\.[0-9]*\\|\\)"
2416 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2418 '(0 mdw-number-face))
2420 ;; And anything else is punctuation.
2421 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2422 '(0 mdw-punct-face))))))
2425 (add-hook 'js-mode-hook 'mdw-misc-mode-config t)
2426 (add-hook 'js-mode-hook 'mdw-fontify-javascript t))
2428 ;;;--------------------------------------------------------------------------
2429 ;;; Scala programming configuration.
2431 (defun mdw-fontify-scala ()
2434 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2436 ;; Define things to be fontified.
2437 (make-local-variable 'font-lock-keywords)
2438 (let ((scala-keywords
2439 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
2440 "extends" "final" "finally" "for" "forSome" "if"
2441 "implicit" "import" "lazy" "match" "new" "object"
2442 "override" "package" "private" "protected" "return"
2443 "sealed" "throw" "trait" "try" "type" "val"
2444 "var" "while" "with" "yield"))
2446 (mdw-regexps "false" "null" "super" "this" "true"))
2447 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
2449 (setq font-lock-keywords
2452 ;; Magical identifiers between backticks.
2453 (list (concat "`\\([^`]+\\)`")
2454 '(1 font-lock-variable-name-face))
2456 ;; Handle the keywords defined above.
2457 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
2458 '(0 font-lock-keyword-face))
2460 ;; Handle the constants defined above.
2461 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
2462 '(0 font-lock-variable-name-face))
2464 ;; Magical identifiers between backticks.
2465 (list (concat "`\\([^`]+\\)`")
2466 '(1 font-lock-variable-name-face))
2468 ;; Handle numbers too.
2470 ;; As usual, not quite right.
2471 (list (concat "\\_<\\("
2472 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2473 "[0-9]+\\(\\.[0-9]*\\|\\)"
2474 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2476 '(0 mdw-number-face))
2478 ;; And everything else is punctuation.
2479 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2480 '(0 mdw-punct-face)))
2482 font-lock-syntactic-keywords
2485 ;; Single quotes around characters. But not when used to quote
2486 ;; symbol names. Ugh.
2487 (list (concat "\\('\\)"
2489 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
2490 "u+" "[0-9a-fA-F]\\{4\\}"
2491 "\\|" "\\\\" "[0-7]\\{1,3\\}"
2492 "\\|" "\\\\" "." "\\)"
2498 (add-hook 'scala-mode-hook 'mdw-misc-mode-config t)
2499 (add-hook 'scala-mode-hook 'mdw-fontify-scala t))
2501 ;;;--------------------------------------------------------------------------
2502 ;;; C# programming configuration.
2504 ;; Make indentation nice.
2506 (mdw-define-c-style mdw-csharp
2507 (c-basic-offset . 2)
2508 (c-backslash-column . 72)
2509 (c-offsets-alist (substatement-open . 0)
2514 (statement-case-intro . +)))
2515 (mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
2517 ;; Declare C# fontification style.
2519 (defun mdw-fontify-csharp ()
2522 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2524 ;; Now define things to be fontified.
2525 (make-local-variable 'font-lock-keywords)
2526 (let ((csharp-keywords
2527 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
2528 "char" "checked" "class" "const" "continue" "decimal"
2529 "default" "delegate" "do" "double" "else" "enum"
2530 "event" "explicit" "extern" "finally" "fixed" "float"
2531 "for" "foreach" "goto" "if" "implicit" "in" "int"
2532 "interface" "internal" "is" "lock" "long" "namespace"
2533 "new" "object" "operator" "out" "override" "params"
2534 "private" "protected" "public" "readonly" "ref"
2535 "return" "sbyte" "sealed" "short" "sizeof"
2536 "stackalloc" "static" "string" "struct" "switch"
2537 "throw" "try" "typeof" "uint" "ulong" "unchecked"
2538 "unsafe" "ushort" "using" "virtual" "void" "volatile"
2542 (mdw-regexps "base" "false" "null" "this" "true")))
2544 (setq font-lock-keywords
2547 ;; Handle the keywords defined above.
2548 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
2549 '(0 font-lock-keyword-face))
2551 ;; Handle the magic builtins defined above.
2552 (list (concat "\\<\\(" csharp-builtins "\\)\\>")
2553 '(0 font-lock-variable-name-face))
2555 ;; Handle numbers too.
2557 ;; The following isn't quite right, but it's close enough.
2558 (list (concat "\\<\\("
2559 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2560 "[0-9]+\\(\\.[0-9]*\\|\\)"
2561 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2563 '(0 mdw-number-face))
2565 ;; And anything else is punctuation.
2566 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2567 '(0 mdw-punct-face))))))
2569 (define-derived-mode csharp-mode java-mode "C#"
2570 "Major mode for editing C# code.")
2572 (add-hook 'csharp-mode-hook 'mdw-fontify-csharp t)
2574 ;;;--------------------------------------------------------------------------
2575 ;;; F# programming configuration.
2577 (setq fsharp-indent-offset 2)
2579 (defun mdw-fontify-fsharp ()
2581 (let ((punct "=<>+-*/|&%!@?"))
2583 ((>= i (length punct)))
2584 (modify-syntax-entry (aref punct i) ".")))
2586 (modify-syntax-entry ?_ "_")
2587 (modify-syntax-entry ?( "(")
2588 (modify-syntax-entry ?) ")")
2590 (setq indent-tabs-mode nil)
2592 (let ((fsharp-keywords
2593 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
2595 "checked" "class" "component" "const" "constraint"
2596 "constructor" "continue"
2597 "default" "delegate" "do" "done" "downcast" "downto"
2598 "eager" "elif" "else" "end" "exception" "extern"
2599 "finally" "fixed" "for" "fori" "fun" "function"
2602 "if" "in" "include" "inherit" "inline" "interface"
2605 "match" "measure" "member" "method" "mixin" "module"
2608 "object" "of" "open" "or" "override"
2609 "parallel" "params" "private" "process" "protected"
2611 "rec" "recursive" "return"
2612 "sealed" "sig" "static" "struct"
2613 "tailcall" "then" "to" "trait" "try" "type"
2615 "val" "virtual" "void" "volatile"
2616 "when" "while" "with"
2620 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
2621 "base" "false" "null" "true"))
2624 (mdw-regexps "do" "let" "return" "use" "yield"))
2626 (preprocessor-keywords
2627 (mdw-regexps "if" "indent" "else" "endif")))
2629 (setq font-lock-keywords
2630 (list (list (concat "\\(^\\|[^\"]\\)"
2633 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
2638 '(2 font-lock-comment-face))
2640 (list (concat "'" "\\("
2643 "\\|" "[0-9][0-9][0-9]"
2644 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
2645 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
2651 "\\(" "\\\\" "\\(.\\|\n\\)"
2654 '(0 font-lock-string-face))
2656 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
2657 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
2659 "\\_<\\(" fsharp-keywords "\\)\\_>")
2660 '(0 font-lock-keyword-face))
2661 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
2662 '(0 font-lock-variable-name-face))
2664 (list (concat "\\_<"
2665 "\\(" "0[bB][01]+" "\\|"
2667 "0[xX][0-9a-fA-F]+" "\\)"
2668 "\\(" "lf\\|LF" "\\|"
2669 "[uU]?[ysnlL]?" "\\)"
2676 "\\([eE][-+]?[0-9]+\\)?"
2681 '(0 mdw-number-face))
2683 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2684 '(0 mdw-punct-face))))))
2686 (defun mdw-fontify-inferior-fsharp ()
2687 (mdw-fontify-fsharp)
2688 (setq font-lock-keywords
2689 (append (list (list "^[#-]" '(0 font-lock-comment-face))
2690 (list "^>" '(0 font-lock-keyword-face)))
2691 font-lock-keywords)))
2694 (add-hook 'fsharp-mode-hook 'mdw-misc-mode-config t)
2695 (add-hook 'fsharp-mode-hook 'mdw-fontify-fsharp t)
2696 (add-hook 'inferior-fsharp-mode-hooks 'mdw-fontify-inferior-fsharp t))
2698 ;;;--------------------------------------------------------------------------
2699 ;;; Go programming configuration.
2701 (defun mdw-fontify-go ()
2703 (make-local-variable 'font-lock-keywords)
2705 (mdw-regexps "break" "case" "chan" "const" "continue"
2706 "default" "defer" "else" "fallthrough" "for"
2707 "func" "go" "goto" "if" "import"
2708 "interface" "map" "package" "range" "return"
2709 "select" "struct" "switch" "type" "var"))
2711 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
2712 "float32" "float64" "int" "uint8" "int16" "int32"
2713 "int64" "rune" "string" "uint" "uint8" "uint16"
2714 "uint32" "uint64" "uintptr" "void"
2715 "false" "iota" "nil" "true"
2717 "append" "cap" "copy" "delete" "imag" "len" "make"
2718 "new" "panic" "real" "recover")))
2720 (setq font-lock-keywords
2723 ;; Handle the keywords defined above.
2724 (list (concat "\\<\\(" go-keywords "\\)\\>")
2725 '(0 font-lock-keyword-face))
2726 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
2727 '(0 font-lock-variable-name-face))
2729 ;; Strings and characters.
2731 "\\(" "[^\\']" "\\|"
2733 "\\(" "[abfnrtv\\'\"]" "\\|"
2734 "[0-7]\\{3\\}" "\\|"
2735 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
2736 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
2737 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
2741 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
2745 '(0 font-lock-string-face))
2747 ;; Handle numbers too.
2749 ;; The following isn't quite right, but it's close enough.
2750 (list (concat "\\<\\("
2751 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2752 "[0-9]+\\(\\.[0-9]*\\|\\)"
2753 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
2754 '(0 mdw-number-face))
2756 ;; And anything else is punctuation.
2757 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2758 '(0 mdw-punct-face))))))
2760 (add-hook 'go-mode-hook 'mdw-misc-mode-config t)
2761 (add-hook 'go-mode-hook 'mdw-fontify-go t))
2763 ;;;--------------------------------------------------------------------------
2764 ;;; Rust programming configuration.
2766 (setq-default rust-indent-offset 2)
2768 (defun mdw-self-insert-and-indent (count)
2770 (self-insert-command count)
2771 (indent-according-to-mode))
2773 (defun mdw-fontify-rust ()
2775 ;; Hack syntax categories.
2776 (modify-syntax-entry ?$ ".")
2777 (modify-syntax-entry ?% ".")
2778 (modify-syntax-entry ?= ".")
2780 ;; Fontify keywords and things.
2781 (make-local-variable 'font-lock-keywords)
2782 (let ((rust-keywords
2783 (mdw-regexps "abstract" "alignof" "as" "async" "await"
2784 "become" "box" "break"
2785 "const" "continue" "crate"
2787 "else" "enum" "extern"
2791 "macro" "match" "mod" "move" "mut"
2792 "offsetof" "override"
2793 "priv" "proc" "pub" "pure"
2795 "sizeof" "static" "struct" "super"
2796 "trait" "try" "type" "typeof"
2797 "union" "unsafe" "unsized" "use"
2802 (mdw-regexps "array" "pointer" "slice" "tuple"
2803 "bool" "true" "false"
2805 "i8" "i16" "i32" "i64" "isize"
2806 "u8" "u16" "u32" "u64" "usize"
2809 (setq font-lock-keywords
2812 ;; Handle the keywords defined above.
2813 (list (concat "\\_<\\(" rust-keywords "\\)\\_>")
2814 '(0 font-lock-keyword-face))
2815 (list (concat "\\_<\\(" rust-builtins "\\)\\_>")
2816 '(0 font-lock-variable-name-face))
2818 ;; Handle numbers too.
2819 (list (concat "\\_<\\("
2821 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
2825 "\\|" "\\(" "[0-9][0-9_]*"
2826 "\\|" "0x[0-9a-fA-F_]+"
2830 "\\([ui]\\(8\\|16\\|32\\|64\\|size\\)\\)?"
2832 '(0 mdw-number-face))
2834 ;; And anything else is punctuation.
2835 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2836 '(0 mdw-punct-face)))))
2838 ;; Hack key bindings.
2839 (local-set-key [?{] 'mdw-self-insert-and-indent)
2840 (local-set-key [?}] 'mdw-self-insert-and-indent))
2843 (add-hook 'rust-mode-hook 'mdw-misc-mode-config t)
2844 (add-hook 'rust-mode-hook 'mdw-fontify-rust t))
2846 ;;;--------------------------------------------------------------------------
2847 ;;; Awk programming configuration.
2849 ;; Make Awk indentation nice.
2851 (mdw-define-c-style mdw-awk
2852 (c-basic-offset . 2)
2853 (c-offsets-alist (substatement-open . 0)
2854 (c-backslash-column . 72)
2855 (statement-cont . 0)
2856 (statement-case-intro . +)))
2857 (mdw-set-default-c-style 'awk-mode 'mdw-awk)
2859 ;; Declare Awk fontification style.
2861 (defun mdw-fontify-awk ()
2863 ;; Miscellaneous fiddling.
2864 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2866 ;; Now define things to be fontified.
2867 (make-local-variable 'font-lock-keywords)
2869 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
2870 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
2871 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
2872 "RSTART" "RLENGTH" "RT" "SUBSEP"
2873 "atan2" "break" "close" "continue" "cos" "delete"
2874 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
2875 "function" "gensub" "getline" "gsub" "if" "in"
2876 "index" "int" "length" "log" "match" "next" "rand"
2877 "return" "print" "printf" "sin" "split" "sprintf"
2878 "sqrt" "srand" "strftime" "sub" "substr" "system"
2879 "systime" "tolower" "toupper" "while")))
2881 (setq font-lock-keywords
2884 ;; Handle the keywords defined above.
2885 (list (concat "\\<\\(" c-keywords "\\)\\>")
2886 '(0 font-lock-keyword-face))
2888 ;; Handle numbers too.
2890 ;; The following isn't quite right, but it's close enough.
2891 (list (concat "\\<\\("
2892 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2893 "[0-9]+\\(\\.[0-9]*\\|\\)"
2894 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2896 '(0 mdw-number-face))
2898 ;; And anything else is punctuation.
2899 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2900 '(0 mdw-punct-face))))))
2903 (add-hook 'awk-mode-hook 'mdw-misc-mode-config t)
2904 (add-hook 'awk-mode-hook 'mdw-fontify-awk t))
2906 ;;;--------------------------------------------------------------------------
2907 ;;; Perl programming style.
2909 ;; Perl indentation style.
2911 (setq-default perl-indent-level 2)
2913 (setq-default cperl-indent-level 2
2914 cperl-continued-statement-offset 2
2915 cperl-continued-brace-offset 0
2916 cperl-brace-offset -2
2917 cperl-brace-imaginary-offset 0
2918 cperl-label-offset 0)
2920 ;; Define perl fontification style.
2922 (defun mdw-fontify-perl ()
2924 ;; Miscellaneous fiddling.
2925 (modify-syntax-entry ?$ "\\")
2926 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
2927 (modify-syntax-entry ?: "." font-lock-syntax-table)
2928 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2930 ;; Now define fontification things.
2931 (make-local-variable 'font-lock-keywords)
2932 (let ((perl-keywords
2939 "ge" "given" "gt" "goto"
2941 "last" "le" "local" "lt"
2946 "redo" "require" "return"
2948 "undef" "unless" "until" "use"
2951 (setq font-lock-keywords
2954 ;; Set up the keywords defined above.
2955 (list (concat "\\<\\(" perl-keywords "\\)\\>")
2956 '(0 font-lock-keyword-face))
2958 ;; At least numbers are simpler than C.
2959 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2960 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2961 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2962 '(0 mdw-number-face))
2964 ;; And anything else is punctuation.
2965 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2966 '(0 mdw-punct-face))))))
2968 (defun perl-number-tests (&optional arg)
2969 "Assign consecutive numbers to lines containing `#t'. With ARG,
2970 strip numbers instead."
2973 (goto-char (point-min))
2974 (let ((i 0) (fmt (if arg "" " %4d")))
2975 (while (search-forward "#t" nil t)
2976 (delete-region (point) (line-end-position))
2978 (insert (format fmt i)))
2979 (goto-char (point-min))
2980 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
2981 (replace-match (format "\\1%d" i))))))
2983 (dolist (hook '(perl-mode-hook cperl-mode-hook))
2984 (add-hook hook 'mdw-misc-mode-config t)
2985 (add-hook hook 'mdw-fontify-perl t))
2987 ;;;--------------------------------------------------------------------------
2988 ;;; Python programming style.
2990 (setq-default py-indent-offset 2
2992 python-indent-offset 2
2993 python-fill-docstring-style 'symmetric)
2995 (defun mdw-fontify-pythonic (keywords)
2997 ;; Miscellaneous fiddling.
2998 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2999 (setq indent-tabs-mode nil)
3001 ;; Now define fontification things.
3002 (make-local-variable 'font-lock-keywords)
3003 (setq font-lock-keywords
3006 ;; Set up the keywords defined above.
3007 (list (concat "\\_<\\(" keywords "\\)\\_>")
3008 '(0 font-lock-keyword-face))
3010 ;; At least numbers are simpler than C.
3011 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO]?[0-7]+\\|[bB][01]+\\)\\|"
3012 "\\_<[0-9][0-9]*\\(\\.[0-9]*\\|\\)"
3013 "\\([eE]\\([-+]\\|\\)[0-9]+\\|[lL]\\|\\)")
3014 '(0 mdw-number-face))
3016 ;; And anything else is punctuation.
3017 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3018 '(0 mdw-punct-face)))))
3020 ;; Define Python fontification styles.
3022 (defun mdw-fontify-python ()
3023 (mdw-fontify-pythonic
3024 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
3025 "del" "elif" "else" "except" "exec" "finally" "for"
3026 "from" "global" "if" "import" "in" "is" "lambda"
3027 "not" "or" "pass" "print" "raise" "return" "try"
3028 "while" "with" "yield")))
3030 (defun mdw-fontify-pyrex ()
3031 (mdw-fontify-pythonic
3032 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
3033 "ctypedef" "def" "del" "elif" "else" "enum" "except" "exec"
3034 "extern" "finally" "for" "from" "global" "if"
3035 "import" "in" "is" "lambda" "not" "or" "pass" "print"
3036 "property" "raise" "return" "struct" "try" "while" "with"
3039 (define-derived-mode pyrex-mode python-mode "Pyrex"
3040 "Major mode for editing Pyrex source code")
3041 (setq auto-mode-alist
3042 (append '(("\\.pyx$" . pyrex-mode)
3043 ("\\.pxd$" . pyrex-mode)
3044 ("\\.pxi$" . pyrex-mode))
3048 (add-hook 'python-mode-hook 'mdw-misc-mode-config t)
3049 (add-hook 'python-mode-hook 'mdw-fontify-python t)
3050 (add-hook 'pyrex-mode-hook 'mdw-fontify-pyrex t))
3052 ;;;--------------------------------------------------------------------------
3053 ;;; Lua programming style.
3055 (setq-default lua-indent-level 2)
3057 (defun mdw-fontify-lua ()
3059 ;; Miscellaneous fiddling.
3060 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3062 ;; Now define fontification things.
3063 (make-local-variable 'font-lock-keywords)
3065 (mdw-regexps "and" "break" "do" "else" "elseif" "end"
3066 "false" "for" "function" "goto" "if" "in" "local"
3067 "nil" "not" "or" "repeat" "return" "then" "true"
3069 (setq font-lock-keywords
3072 ;; Set up the keywords defined above.
3073 (list (concat "\\_<\\(" lua-keywords "\\)\\_>")
3074 '(0 font-lock-keyword-face))
3076 ;; At least numbers are simpler than C.
3077 (list (concat "\\_<\\(" "0[xX]"
3078 "\\(" "[0-9a-fA-F]+"
3079 "\\(\\.[0-9a-fA-F]*\\)?"
3080 "\\|" "\\.[0-9a-fA-F]+"
3082 "\\([pP][-+]?[0-9]+\\)?"
3083 "\\|" "\\(" "[0-9]+"
3087 "\\([eE][-+]?[0-9]+\\)?"
3089 '(0 mdw-number-face))
3091 ;; And anything else is punctuation.
3092 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3093 '(0 mdw-punct-face))))))
3096 (add-hook 'lua-mode-hook 'mdw-misc-mode-config t)
3097 (add-hook 'lua-mode-hook 'mdw-fontify-lua t))
3099 ;;;--------------------------------------------------------------------------
3100 ;;; Icon programming style.
3102 ;; Icon indentation style.
3104 (setq-default icon-brace-offset 0
3105 icon-continued-brace-offset 0
3106 icon-continued-statement-offset 2
3107 icon-indent-level 2)
3109 ;; Define Icon fontification style.
3111 (defun mdw-fontify-icon ()
3113 ;; Miscellaneous fiddling.
3114 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3116 ;; Now define fontification things.
3117 (make-local-variable 'font-lock-keywords)
3118 (let ((icon-keywords
3119 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
3120 "end" "every" "fail" "global" "if" "initial"
3121 "invocable" "link" "local" "next" "not" "of"
3122 "procedure" "record" "repeat" "return" "static"
3123 "suspend" "then" "to" "until" "while"))
3124 (preprocessor-keywords
3125 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
3126 "include" "line" "undef")))
3127 (setq font-lock-keywords
3130 ;; Set up the keywords defined above.
3131 (list (concat "\\<\\(" icon-keywords "\\)\\>")
3132 '(0 font-lock-keyword-face))
3134 ;; The things that Icon calls keywords.
3135 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
3137 ;; At least numbers are simpler than C.
3138 (list (concat "\\<[0-9]+"
3139 "\\([rR][0-9a-zA-Z]+\\|"
3140 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
3141 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
3142 '(0 mdw-number-face))
3145 (list (concat "^[ \t]*$[ \t]*\\<\\("
3146 preprocessor-keywords
3148 '(0 font-lock-keyword-face))
3150 ;; And anything else is punctuation.
3151 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3152 '(0 mdw-punct-face))))))
3155 (add-hook 'icon-mode-hook 'mdw-misc-mode-config t)
3156 (add-hook 'icon-mode-hook 'mdw-fontify-icon t))
3158 ;;;--------------------------------------------------------------------------
3161 (defun mdw-fontify-asm ()
3162 (modify-syntax-entry ?' "\"")
3163 (modify-syntax-entry ?. "w")
3164 (modify-syntax-entry ?\n ">")
3165 (setf fill-prefix nil)
3166 (modify-syntax-entry ?. "_")
3167 (modify-syntax-entry ?* ". 23")
3168 (modify-syntax-entry ?/ ". 124b")
3169 (modify-syntax-entry ?\n "> b")
3170 (local-set-key ";" 'self-insert-command)
3171 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
3173 (defun mdw-asm-set-comment ()
3174 (modify-syntax-entry ?; "."
3176 (modify-syntax-entry asm-comment-char "< b")
3177 (setq comment-start (string asm-comment-char ? )))
3178 (add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
3179 (put 'asm-comment-char 'safe-local-variable 'characterp)
3182 (add-hook 'asm-mode-hook 'mdw-misc-mode-config t)
3183 (add-hook 'asm-mode-hook 'mdw-fontify-asm t))
3185 ;;;--------------------------------------------------------------------------
3186 ;;; TCL configuration.
3188 (setq-default tcl-indent-level 2)
3190 (defun mdw-fontify-tcl ()
3192 (modify-syntax-entry ch "."))
3193 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3194 (make-local-variable 'font-lock-keywords)
3195 (setq font-lock-keywords
3197 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3198 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
3199 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
3200 '(0 mdw-number-face))
3201 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3202 '(0 mdw-punct-face)))))
3205 (add-hook 'tcl-mode-hook 'mdw-misc-mode-config t)
3206 (add-hook 'tcl-mode-hook 'mdw-fontify-tcl t))
3208 ;;;--------------------------------------------------------------------------
3209 ;;; Dylan programming configuration.
3211 (defun mdw-fontify-dylan ()
3213 (make-local-variable 'font-lock-keywords)
3215 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
3216 ;; hook, which undoes all of our configuration.
3217 (setq major-mode 'dylan-mode)
3218 (font-lock-set-defaults)
3220 (let* ((word "[-_a-zA-Z!*@<>$%]+")
3221 (dylan-keywords (mdw-regexps
3223 "C-address" "C-callable-wrapper" "C-function"
3224 "C-mapped-subtype" "C-pointer-type" "C-struct"
3225 "C-subtype" "C-union" "C-variable"
3227 "above" "abstract" "afterwards" "all"
3228 "begin" "below" "block" "by"
3229 "case" "class" "cleanup" "constant" "create"
3231 "else" "elseif" "end" "exception" "export"
3232 "finally" "for" "from" "function"
3235 "if" "in" "instance" "interface" "iterate"
3237 "let" "library" "local"
3238 "macro" "method" "module"
3241 "select" "slot" "subclass"
3243 "unless" "until" "use"
3244 "variable" "virtual"
3246 (sharp-keywords (mdw-regexps
3247 "all-keys" "key" "next" "rest" "include"
3249 (setq font-lock-keywords
3250 (list (list (concat "\\<\\(" dylan-keywords
3251 "\\|" "with\\(out\\)?-" word
3253 '(0 font-lock-keyword-face))
3254 (list (concat "\\<" word ":" "\\|"
3255 "#\\(" sharp-keywords "\\)\\>")
3256 '(0 font-lock-variable-name-face))
3258 "\\([-+]\\|\\<\\)[0-9]+" "\\("
3259 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
3262 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
3265 "\\|" "#x[0-9a-zA-Z]+"
3267 '(0 mdw-number-face))
3269 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
3270 "\\_<[-+*/=<>:&|]+\\_>"
3272 '(0 mdw-punct-face))))))
3275 (add-hook 'dylan-mode-hook 'mdw-misc-mode-config t)
3276 (add-hook 'dylan-mode-hook 'mdw-fontify-dylan t))
3278 ;;;--------------------------------------------------------------------------
3279 ;;; Algol 68 configuration.
3281 (setq-default a68-indent-step 2)
3283 (defun mdw-fontify-algol-68 ()
3285 ;; Fix up the syntax table.
3286 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
3287 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
3288 (modify-syntax-entry ch "." a68-mode-syntax-table))
3290 (make-local-variable 'font-lock-keywords)
3293 (let ((word "COMMENT"))
3294 (do ((regexp (concat "[^" (substring word 0 1) "]+")
3295 (concat regexp "\\|"
3296 (substring word 0 i)
3297 "[^" (substring word i (1+ i)) "]"))
3299 ((>= i (length word)) regexp)))))
3300 (setq font-lock-keywords
3301 (list (list (concat "\\<COMMENT\\>"
3302 "\\(" not-comment "\\)\\{0,5\\}"
3303 "\\(\\'\\|\\<COMMENT\\>\\)")
3304 '(0 font-lock-comment-face))
3305 (list (concat "\\<CO\\>"
3306 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
3307 "\\($\\|\\<CO\\>\\)")
3308 '(0 font-lock-comment-face))
3309 (list "\\<[A-Z_]+\\>"
3310 '(0 font-lock-keyword-face))
3314 "\\([eE][-+]?[0-9]+\\)?"
3316 '(0 mdw-number-face))
3317 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
3318 '(0 mdw-punct-face))))))
3320 (dolist (hook '(a68-mode-hook a68-mode-hooks))
3321 (add-hook hook 'mdw-misc-mode-config t)
3322 (add-hook hook 'mdw-fontify-algol-68 t))
3324 ;;;--------------------------------------------------------------------------
3325 ;;; REXX configuration.
3327 (defun mdw-rexx-electric-* ()
3332 (defun mdw-rexx-indent-newline-indent ()
3335 (if abbrev-mode (expand-abbrev))
3336 (newline-and-indent))
3338 (defun mdw-fontify-rexx ()
3340 ;; Various bits of fiddling.
3341 (setq mdw-auto-indent nil)
3342 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
3343 (local-set-key [?*] 'mdw-rexx-electric-*)
3344 (dolist (ch '(?! ?? ?# ?@ ?$)) (modify-syntax-entry ch "w"))
3345 (dolist (ch '(?¬)) (modify-syntax-entry ch "."))
3346 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
3348 ;; Set up keywords and things for fontification.
3349 (make-local-variable 'font-lock-keywords-case-fold-search)
3350 (setq font-lock-keywords-case-fold-search t)
3352 (setq rexx-indent 2)
3353 (setq rexx-end-indent rexx-indent)
3354 (setq rexx-cont-indent rexx-indent)
3356 (make-local-variable 'font-lock-keywords)
3357 (let ((rexx-keywords
3358 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
3359 "else" "end" "engineering" "exit" "expose" "for"
3360 "forever" "form" "fuzz" "if" "interpret" "iterate"
3361 "leave" "linein" "name" "nop" "numeric" "off" "on"
3362 "options" "otherwise" "parse" "procedure" "pull"
3363 "push" "queue" "return" "say" "select" "signal"
3364 "scientific" "source" "then" "trace" "to" "until"
3365 "upper" "value" "var" "version" "when" "while"
3368 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
3369 "center" "center" "charin" "charout" "chars"
3370 "compare" "condition" "copies" "c2d" "c2x"
3371 "datatype" "date" "delstr" "delword" "d2c" "d2x"
3372 "errortext" "format" "fuzz" "insert" "lastpos"
3373 "left" "length" "lineout" "lines" "max" "min"
3374 "overlay" "pos" "queued" "random" "reverse" "right"
3375 "sign" "sourceline" "space" "stream" "strip"
3376 "substr" "subword" "symbol" "time" "translate"
3377 "trunc" "value" "verify" "word" "wordindex"
3378 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
3381 (setq font-lock-keywords
3384 ;; Set up the keywords defined above.
3385 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
3386 '(0 font-lock-keyword-face))
3388 ;; Fontify all symbols the same way.
3389 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
3390 "[A-Za-z0-9.!?_#@$]+\\)")
3391 '(0 font-lock-variable-name-face))
3393 ;; And everything else is punctuation.
3394 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3395 '(0 mdw-punct-face))))))
3398 (add-hook 'rexx-mode-hook 'mdw-misc-mode-config t)
3399 (add-hook 'rexx-mode-hook 'mdw-fontify-rexx t))
3401 ;;;--------------------------------------------------------------------------
3402 ;;; Standard ML programming style.
3404 (setq-default sml-nested-if-indent t
3407 sml-type-of-indent nil)
3409 (defun mdw-fontify-sml ()
3411 ;; Make underscore an honorary letter.
3412 (modify-syntax-entry ?' "w")
3415 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
3417 ;; Now define fontification things.
3418 (make-local-variable 'font-lock-keywords)
3420 (mdw-regexps "abstype" "and" "andalso" "as"
3423 "else" "end" "eqtype" "exception"
3424 "fn" "fun" "functor"
3426 "if" "in" "include" "infix" "infixr"
3429 "of" "op" "open" "orelse"
3431 "sharing" "sig" "signature" "struct" "structure"
3434 "where" "while" "with" "withtype")))
3436 (setq font-lock-keywords
3439 ;; Set up the keywords defined above.
3440 (list (concat "\\<\\(" sml-keywords "\\)\\>")
3441 '(0 font-lock-keyword-face))
3443 ;; At least numbers are simpler than C.
3444 (list (concat "\\<\\(\\~\\|\\)"
3445 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
3447 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
3448 "\\([eE]\\(\\~\\|\\)"
3449 "[0-9]+\\|\\)\\)\\)")
3450 '(0 mdw-number-face))
3452 ;; And anything else is punctuation.
3453 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3454 '(0 mdw-punct-face))))))
3457 (add-hook 'sml-mode-hook 'mdw-misc-mode-config t)
3458 (add-hook 'sml-mode-hook 'mdw-fontify-sml t))
3460 ;;;--------------------------------------------------------------------------
3461 ;;; Haskell configuration.
3463 (setq-default haskell-indent-offset 2)
3465 (defun mdw-fontify-haskell ()
3467 ;; Fiddle with syntax table to get comments right.
3468 (modify-syntax-entry ?' "_")
3469 (modify-syntax-entry ?- ". 12")
3470 (modify-syntax-entry ?\n ">")
3472 ;; Make punctuation be punctuation
3473 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
3475 ((>= i (length punct)))
3476 (modify-syntax-entry (aref punct i) ".")))
3479 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
3481 ;; Fiddle with fontification.
3482 (make-local-variable 'font-lock-keywords)
3483 (let ((haskell-keywords
3485 "case" "ccall" "class"
3486 "data" "default" "deriving" "do"
3490 "if" "import" "in" "infix" "infixl" "infixr" "instance"
3503 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
3504 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
3505 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
3506 "SP" "STX" "SUB" "SYN" "US" "VT")))
3508 (setq font-lock-keywords
3510 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
3514 '(0 font-lock-comment-face))
3515 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
3516 '(0 font-lock-keyword-face))
3517 (list (concat "'\\("
3521 "\\(" "[abfnrtv\\\"']" "\\|"
3522 "^" "\\(" control-sequences "\\|"
3523 "[]A-Z@[\\^_]" "\\)" "\\|"
3530 '(0 font-lock-string-face))
3531 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
3532 '(0 font-lock-variable-name-face))
3533 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
3534 "\\_<[0-9]+\\(\\.[0-9]*\\|\\)"
3535 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
3536 '(0 mdw-number-face))
3537 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3538 '(0 mdw-punct-face))))))
3541 (add-hook 'haskell-mode-hook 'mdw-misc-mode-config t)
3542 (add-hook 'haskell-mode-hook 'mdw-fontify-haskell t))
3544 ;;;--------------------------------------------------------------------------
3545 ;;; Erlang configuration.
3547 (setq-default erlang-electric-commands nil)
3549 (defun mdw-fontify-erlang ()
3552 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
3554 ;; Fiddle with fontification.
3555 (make-local-variable 'font-lock-keywords)
3556 (let ((erlang-keywords
3557 (mdw-regexps "after" "and" "andalso"
3558 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
3559 "case" "catch" "cond"
3560 "div" "end" "fun" "if" "let" "not"
3562 "query" "receive" "rem" "try" "when" "xor")))
3564 (setq font-lock-keywords
3567 '(0 font-lock-comment-face))
3568 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
3569 '(0 font-lock-keyword-face))
3570 (list (concat "^-\\sw+\\>")
3571 '(0 font-lock-keyword-face))
3572 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
3573 '(0 mdw-number-face))
3574 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3575 '(0 mdw-punct-face))))))
3578 (add-hook 'erlang-mode-hook 'mdw-misc-mode-config t)
3579 (add-hook 'erlang-mode-hook 'mdw-fontify-erlang t))
3581 ;;;--------------------------------------------------------------------------
3582 ;;; Texinfo configuration.
3584 (defun mdw-fontify-texinfo ()
3587 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
3589 ;; Real fontification things.
3590 (make-local-variable 'font-lock-keywords)
3591 (setq font-lock-keywords
3594 ;; Environment names are keywords.
3595 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
3596 '(2 font-lock-keyword-face))
3598 ;; Unmark escaped magic characters.
3599 (list "\\(@\\)\\([@{}]\\)"
3600 '(1 font-lock-keyword-face)
3601 '(2 font-lock-variable-name-face))
3603 ;; Make sure we get comments properly.
3604 (list "@c\\(\\|omment\\)\\( .*\\)?$"
3605 '(0 font-lock-comment-face))
3607 ;; Command names are keywords.
3608 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3609 '(0 font-lock-keyword-face))
3611 ;; Fontify TeX special characters as punctuation.
3613 '(0 mdw-punct-face)))))
3615 (dolist (hook '(texinfo-mode-hook TeXinfo-mode-hook))
3616 (add-hook hook 'mdw-misc-mode-config t)
3617 (add-hook hook 'mdw-fontify-texinfo t))
3619 ;;;--------------------------------------------------------------------------
3620 ;;; TeX and LaTeX configuration.
3622 (setq-default LaTeX-table-label "tbl:"
3623 TeX-auto-untabify nil
3624 LaTeX-syntactic-comments nil
3625 LaTeX-fill-break-at-separators '(\\\[))
3627 (defun mdw-fontify-tex ()
3628 (setq ispell-parser 'tex)
3631 ;; Don't make maths into a string.
3632 (modify-syntax-entry ?$ ".")
3633 (modify-syntax-entry ?$ "." font-lock-syntax-table)
3634 (local-set-key [?$] 'self-insert-command)
3636 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
3637 (local-set-key "\C-\M-i" 'indent-relative)
3638 (setq indent-tabs-mode nil)
3641 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
3643 ;; Real fontification things.
3644 (make-local-variable 'font-lock-keywords)
3645 (setq font-lock-keywords
3648 ;; Environment names are keywords.
3649 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
3651 '(2 font-lock-keyword-face))
3653 ;; Suspended environment names are keywords too.
3654 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
3656 '(3 font-lock-keyword-face))
3658 ;; Command names are keywords.
3659 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3660 '(0 font-lock-keyword-face))
3662 ;; Handle @/.../ for italics.
3663 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
3664 ;; '(1 font-lock-keyword-face)
3665 ;; '(3 font-lock-keyword-face))
3667 ;; Handle @*...* for boldness.
3668 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
3669 ;; '(1 font-lock-keyword-face)
3670 ;; '(3 font-lock-keyword-face))
3672 ;; Handle @`...' for literal syntax things.
3673 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
3674 ;; '(1 font-lock-keyword-face)
3675 ;; '(3 font-lock-keyword-face))
3677 ;; Handle @<...> for nonterminals.
3678 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
3679 ;; '(1 font-lock-keyword-face)
3680 ;; '(3 font-lock-keyword-face))
3682 ;; Handle other @-commands.
3683 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
3684 ;; '(0 font-lock-keyword-face))
3686 ;; Make sure we get comments properly.
3688 '(0 font-lock-comment-face))
3690 ;; Fontify TeX special characters as punctuation.
3692 '(0 mdw-punct-face)))))
3694 (setq TeX-install-font-lock 'tex-font-setup)
3696 (eval-after-load 'font-latex
3697 '(defun font-latex-jit-lock-force-redisplay (buf start end)
3698 "Compatibility for Emacsen not offering `jit-lock-force-redisplay'."
3699 ;; The following block is an expansion of `jit-lock-force-redisplay'
3700 ;; and involved macros taken from CVS Emacs on 2007-04-28.
3701 (with-current-buffer buf
3702 (let ((modified (buffer-modified-p)))
3704 (let ((buffer-undo-list t)
3705 (inhibit-read-only t)
3706 (inhibit-point-motion-hooks t)
3707 (inhibit-modification-hooks t)
3710 buffer-file-truename)
3711 (put-text-property start end 'fontified t))
3713 (restore-buffer-modified-p nil)))))))
3715 (setq TeX-output-view-style
3717 ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$")
3718 "%(o?)dvips -t landscape %d -o && xdg-open %f")
3719 ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$"
3720 "%(o?)dvips %d -o && xdg-open %f")
3722 ("^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "^landscape$")
3723 "%(o?)xdvi %dS -paper a4r -s 0 %d")
3724 ("^dvi$" "^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$"
3725 "%(o?)xdvi %dS -paper a4 %d")
3727 ("^a5\\(?:comb\\|paper\\)$" "^landscape$")
3728 "%(o?)xdvi %dS -paper a5r -s 0 %d")
3729 ("^dvi$" "^a5\\(?:comb\\|paper\\)$" "%(o?)xdvi %dS -paper a5 %d")
3730 ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
3731 ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d")
3732 ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
3733 ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
3734 ("^dvi$" "." "%(o?)xdvi %dS %d")
3735 ("^pdf$" "." "xdg-open %o")
3736 ("^html?$" "." "sensible-browser %o")))
3738 (setq TeX-view-program-list
3739 '(("mupdf" ("mupdf %o" (mode-io-correlate " %(outpage)")))))
3741 (setq TeX-view-program-selection
3742 '(((output-dvi style-pstricks) "dvips and gv")
3744 (output-pdf "mupdf")
3745 (output-html "sensible-browser")))
3747 (setq TeX-open-quote "\""
3748 TeX-close-quote "\"")
3750 (setq reftex-use-external-file-finders t
3751 reftex-auto-recenter-toc t)
3753 (setq reftex-label-alist
3754 '(("theorem" ?T "th:" "~\\ref{%s}" t ("theorems?" "th\\.") -2)
3755 ("axiom" ?A "ax:" "~\\ref{%s}" t ("axioms?" "ax\\.") -2)
3756 ("definition" ?D "def:" "~\\ref{%s}" t ("definitions?" "def\\.") -2)
3757 ("proposition" ?P "prop:" "~\\ref{%s}" t
3758 ("propositions?" "prop\\.") -2)
3759 ("lemma" ?L "lem:" "~\\ref{%s}" t ("lemmas?" "lem\\.") -2)
3760 ("example" ?X "eg:" "~\\ref{%s}" t ("examples?") -2)
3761 ("exercise" ?E "ex:" "~\\ref{%s}" t ("exercises?" "ex\\.") -2)
3762 ("enumerate" ?i "i:" "~\\ref{%s}" item ("items?"))))
3763 (setq reftex-section-prefixes
3768 (setq bibtex-field-delimiters 'double-quotes
3769 bibtex-align-at-equal-sign t
3770 bibtex-entry-format '(realign opts-or-alts required-fields
3771 numerical-fields last-comma delimiters
3772 unify-case sort-fields braces)
3773 bibtex-sort-ignore-string-entries nil
3774 bibtex-maintain-sorted-entries 'entry-class
3775 bibtex-include-OPTkey t
3776 bibtex-autokey-names-stretch 1
3777 bibtex-autokey-expand-strings t
3778 bibtex-autokey-name-separator "-"
3779 bibtex-autokey-year-length 4
3780 bibtex-autokey-titleword-separator "-"
3781 bibtex-autokey-name-year-separator "-"
3782 bibtex-autokey-year-title-separator ":")
3785 (dolist (hook '(tex-mode-hook latex-mode-hook
3786 TeX-mode-hook LaTeX-mode-hook))
3787 (add-hook hook 'mdw-misc-mode-config t)
3788 (add-hook hook 'mdw-fontify-tex t))
3789 (add-hook 'bibtex-mode-hook (lambda () (setq fill-column 76))))
3791 ;;;--------------------------------------------------------------------------
3792 ;;; HTML, CSS, and other web foolishness.
3794 (setq-default css-indent-offset 2)
3796 ;;;--------------------------------------------------------------------------
3799 (setq-default psgml-html-build-new-buffer nil)
3801 (defun mdw-sgml-mode ()
3804 (mdw-standard-fill-prefix "")
3805 (make-local-variable 'sgml-delimiters)
3806 (setq sgml-delimiters
3807 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
3808 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
3809 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
3810 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
3811 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
3812 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
3813 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
3815 (setq major-mode 'mdw-sgml-mode)
3816 (setq mode-name "[mdw] SGML")
3817 (run-hooks 'mdw-sgml-mode-hook))
3819 ;;;--------------------------------------------------------------------------
3820 ;;; Configuration files.
3822 (defvar mdw-conf-quote-normal nil
3823 "*Control syntax category of quote characters `\"' and `''.
3824 If this is `t', consider quote characters to be normal
3825 punctuation, as for `conf-quote-normal'. If this is `nil' then
3826 leave quote characters as quotes. If this is a list, then
3827 consider the quote characters in the list to be normal
3828 punctuation. If this is a single quote character, then consider
3829 that character only to be normal punctuation.")
3830 (defun mdw-conf-quote-normal-acceptable-value-p (value)
3831 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
3832 (or (booleanp value)
3833 (every (lambda (v) (memq v '(?\" ?')))
3834 (if (listp value) value (list value)))))
3835 (put 'mdw-conf-quote-normal 'safe-local-variable
3836 'mdw-conf-quote-normal-acceptable-value-p)
3838 (defun mdw-fix-up-quote ()
3839 "Apply the setting of `mdw-conf-quote-normal'."
3840 (let ((flag mdw-conf-quote-normal))
3842 (conf-quote-normal t))
3846 (let ((table (copy-syntax-table (syntax-table))))
3847 (dolist (ch (if (listp flag) flag (list flag)))
3848 (modify-syntax-entry ch "." table))
3849 (set-syntax-table table)
3850 (and font-lock-mode (font-lock-fontify-buffer)))))))
3853 (add-hook 'conf-mode-hook 'mdw-misc-mode-config t)
3854 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t))
3856 ;;;--------------------------------------------------------------------------
3859 (defun mdw-setup-sh-script-mode ()
3861 ;; Fetch the shell interpreter's name.
3862 (let ((shell-name sh-shell-file))
3864 ;; Try reading the hash-bang line.
3866 (goto-char (point-min))
3867 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
3868 (setq shell-name (match-string 1))))
3870 ;; Now try to set the shell.
3872 ;; Don't let `sh-set-shell' bugger up my script.
3873 (let ((executable-set-magic #'(lambda (s &rest r) s)))
3874 (sh-set-shell shell-name)))
3876 ;; Don't insert here-document scaffolding automatically.
3877 (local-set-key "<" 'self-insert-command)
3879 ;; Now enable my keys and the fontification.
3880 (mdw-misc-mode-config)
3882 ;; Set the indentation level correctly.
3883 (setq sh-indentation 2)
3884 (setq sh-basic-offset 2))
3886 (setq sh-shell-file "/bin/sh")
3888 ;; Awful hacking to override the shell detection for particular scripts.
3889 (defmacro define-custom-shell-mode (name shell)
3892 (set (make-local-variable 'sh-shell-file) ,shell)
3894 (define-custom-shell-mode bash-mode "/bin/bash")
3895 (define-custom-shell-mode rc-mode "/usr/bin/rc")
3896 (put 'sh-shell-file 'permanent-local t)
3898 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
3899 (eval-after-load "sh-script"
3900 '(or (assq 'rc sh-mode-syntax-table-input)
3917 (assoc (assq 'rc sh-mode-syntax-table-input)))
3920 (setq sh-mode-syntax-table-input
3921 (cons (cons 'rc frag)
3922 sh-mode-syntax-table-input))))))
3925 (add-hook 'sh-mode-hook 'mdw-misc-mode-config t)
3926 (add-hook 'sh-mode-hook 'mdw-setup-sh-script-mode t))
3928 ;;;--------------------------------------------------------------------------
3929 ;;; Emacs shell mode.
3931 (defun mdw-eshell-prompt ()
3932 (let ((left "[") (right "]"))
3933 (when (= (user-uid) 0)
3934 (setq left "«" right "»"))
3937 (replace-regexp-in-string "\\..*$" "" (system-name)))
3939 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
3940 (home (expand-file-name "~")) (nhome (length home)))
3941 (if (and (>= npwd nhome)
3943 (= (elt pwd nhome) ?/))
3944 (string= (substring pwd 0 nhome) home))
3945 (concat "~" (substring pwd (length home)))
3948 (setq-default eshell-prompt-function 'mdw-eshell-prompt)
3949 (setq-default eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
3951 (defun eshell/e (file) (find-file file) nil)
3952 (defun eshell/ee (file) (find-file-other-window file) nil)
3953 (defun eshell/w3m (url) (w3m-goto-url url) nil)
3955 (mdw-define-face eshell-prompt (t :weight bold))
3956 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
3957 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
3958 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
3959 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
3960 (mdw-define-face eshell-ls-executable (t :weight bold))
3961 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
3962 (mdw-define-face eshell-ls-readonly (t nil))
3963 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
3965 (defun mdw-eshell-hack () (setenv "LD_PRELOAD" nil))
3966 (add-hook 'eshell-mode-hook 'mdw-eshell-hack)
3968 ;;;--------------------------------------------------------------------------
3969 ;;; Messages-file mode.
3971 (defun messages-mode-guts ()
3972 (setq messages-mode-syntax-table (make-syntax-table))
3973 (set-syntax-table messages-mode-syntax-table)
3974 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
3975 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
3976 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
3977 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
3978 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
3979 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
3980 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
3981 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
3982 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
3983 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
3984 (make-local-variable 'comment-start)
3985 (make-local-variable 'comment-end)
3986 (make-local-variable 'indent-line-function)
3987 (setq indent-line-function 'indent-relative)
3988 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3989 (make-local-variable 'font-lock-defaults)
3990 (make-local-variable 'messages-mode-keywords)
3992 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
3993 "export" "enum" "fixed-octetstring" "flags"
3994 "harmless" "map" "nested" "optional"
3995 "optional-tagged" "package" "primitive"
3996 "primitive-nullfree" "relaxed[ \t]+enum"
3997 "set" "table" "tagged-optional" "union"
3998 "variadic" "vector" "version" "version-tag")))
3999 (setq messages-mode-keywords
4001 (list (concat "\\<\\(" keywords "\\)\\>:")
4002 '(0 font-lock-keyword-face))
4003 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
4004 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
4005 (0 font-lock-variable-name-face))
4006 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
4007 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4008 (0 mdw-punct-face)))))
4009 (setq font-lock-defaults
4010 '(messages-mode-keywords nil nil nil nil))
4011 (run-hooks 'messages-file-hook))
4013 (defun messages-mode ()
4016 (setq major-mode 'messages-mode)
4017 (setq mode-name "Messages")
4018 (messages-mode-guts)
4019 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
4020 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
4021 (setq comment-start "# ")
4022 (setq comment-end "")
4023 (run-hooks 'messages-mode-hook))
4025 (defun cpp-messages-mode ()
4028 (setq major-mode 'cpp-messages-mode)
4029 (setq mode-name "CPP Messages")
4030 (messages-mode-guts)
4031 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
4032 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
4033 (setq comment-start "/* ")
4034 (setq comment-end " */")
4035 (let ((preprocessor-keywords
4036 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
4037 "ident" "if" "ifdef" "ifndef" "import" "include"
4038 "line" "pragma" "unassert" "undef" "warning")))
4039 (setq messages-mode-keywords
4040 (append (list (list (concat "^[ \t]*\\#[ \t]*"
4041 "\\(include\\|import\\)"
4042 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
4043 '(2 font-lock-string-face))
4044 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
4045 preprocessor-keywords
4046 "\\)\\>\\|[0-9]+\\|$\\)\\)")
4047 '(1 font-lock-keyword-face)))
4048 messages-mode-keywords)))
4049 (run-hooks 'cpp-messages-mode-hook))
4052 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
4053 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
4054 ;; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
4057 ;;;--------------------------------------------------------------------------
4058 ;;; Messages-file mode.
4060 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
4061 "Face to use for subsittution directives.")
4062 (make-face 'mallow-driver-substitution-face)
4063 (defvar mallow-driver-text-face 'mallow-driver-text-face
4064 "Face to use for body text.")
4065 (make-face 'mallow-driver-text-face)
4067 (defun mallow-driver-mode ()
4070 (setq major-mode 'mallow-driver-mode)
4071 (setq mode-name "Mallow driver")
4072 (setq mallow-driver-mode-syntax-table (make-syntax-table))
4073 (set-syntax-table mallow-driver-mode-syntax-table)
4074 (make-local-variable 'comment-start)
4075 (make-local-variable 'comment-end)
4076 (make-local-variable 'indent-line-function)
4077 (setq indent-line-function 'indent-relative)
4078 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4079 (make-local-variable 'font-lock-defaults)
4080 (make-local-variable 'mallow-driver-mode-keywords)
4082 (mdw-regexps "each" "divert" "file" "if"
4083 "perl" "set" "string" "type" "write")))
4084 (setq mallow-driver-mode-keywords
4086 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
4087 '(0 font-lock-keyword-face))
4088 (list "^%\\s *\\(#.*\\|\\)$"
4089 '(0 font-lock-comment-face))
4091 '(0 font-lock-keyword-face))
4092 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
4094 '(0 mallow-driver-substitution-face t)))))
4095 (setq font-lock-defaults
4096 '(mallow-driver-mode-keywords nil nil nil nil))
4097 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
4098 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
4099 (setq comment-start "%# ")
4100 (setq comment-end "")
4101 (run-hooks 'mallow-driver-mode-hook))
4104 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t))
4106 ;;;--------------------------------------------------------------------------
4109 (defun nfast-debug-mode ()
4112 (setq major-mode 'nfast-debug-mode)
4113 (setq mode-name "NFast debug")
4114 (setq messages-mode-syntax-table (make-syntax-table))
4115 (set-syntax-table messages-mode-syntax-table)
4116 (make-local-variable 'font-lock-defaults)
4117 (make-local-variable 'nfast-debug-mode-keywords)
4118 (setq truncate-lines t)
4119 (setq nfast-debug-mode-keywords
4121 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
4122 (0 font-lock-keyword-face))
4123 (list (concat "^[ \t]+\\(\\("
4124 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4125 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4127 "[0-9a-fA-F]+\\)[ \t]*$")
4128 '(0 mdw-number-face))
4129 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
4130 (1 font-lock-keyword-face))
4131 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
4132 (1 font-lock-warning-face))
4133 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
4135 (list (concat "^[ \t]+\\.cmd=[ \t]+"
4136 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
4137 '(1 font-lock-keyword-face))
4138 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
4139 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
4140 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
4141 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
4142 (setq font-lock-defaults
4143 '(nfast-debug-mode-keywords nil nil nil nil))
4144 (run-hooks 'nfast-debug-mode-hook))
4146 ;;;--------------------------------------------------------------------------
4147 ;;; Lispy languages.
4149 ;; Unpleasant bodge.
4150 (unless (boundp 'slime-repl-mode-map)
4151 (setq slime-repl-mode-map (make-sparse-keymap)))
4153 (defun mdw-indent-newline-and-indent ()
4155 (indent-for-tab-command)
4156 (newline-and-indent))
4158 (eval-after-load "cl-indent"
4160 (mapc #'(lambda (pair)
4162 'common-lisp-indent-function
4164 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
4165 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
4167 (defun mdw-common-lisp-indent ()
4168 (make-local-variable 'lisp-indent-function)
4169 (setq lisp-indent-function 'common-lisp-indent-function))
4171 (setq-default lisp-simple-loop-indentation 2
4172 lisp-loop-keyword-indentation 6
4173 lisp-loop-forms-indentation 6)
4175 (defmacro mdw-advise-hyperspec-lookup (func args)
4176 `(defadvice ,func (around mdw-browse-w3m ,args activate compile)
4178 (let ((browse-url-browser-function #'mdw-w3m-browse-url))
4181 (mdw-advise-hyperspec-lookup common-lisp-hyperspec (symbol))
4182 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-format (char))
4183 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-lookup-reader-macro (char))
4185 (defun mdw-fontify-lispy ()
4188 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
4190 ;; Not much fontification needed.
4191 (make-local-variable 'font-lock-keywords)
4192 (setq font-lock-keywords
4193 (list (list (concat "\\("
4195 "\\(" "[0-9]+/[0-9]+"
4196 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
4198 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
4203 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
4204 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
4205 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
4206 "\\|" "[0-9]+" "r" "[-+]?"
4207 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
4210 '(0 mdw-number-face))
4211 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4212 '(0 mdw-punct-face)))))
4217 (if (not mdw-fast-startup)
4219 (require 'slime-autoloads)
4220 (slime-setup '(slime-autodoc slime-c-p-c)))))
4222 (let ((stuff '((cmucl ("cmucl"))
4223 (sbcl ("sbcl") :coding-system utf-8-unix)
4224 (clisp ("clisp") :coding-system utf-8-unix))))
4225 (or (boundp 'slime-lisp-implementations)
4226 (setq slime-lisp-implementations nil))
4228 (let* ((head (car stuff))
4229 (found (assq (car head) slime-lisp-implementations)))
4230 (setq stuff (cdr stuff))
4232 (rplacd found (cdr head))
4233 (setq slime-lisp-implementations
4234 (cons head slime-lisp-implementations))))))
4235 (setq slime-default-lisp 'sbcl)
4240 (dolist (hook '(emacs-lisp-mode-hook
4243 inferior-lisp-mode-hook
4244 lisp-interaction-mode-hook
4246 slime-repl-mode-hook))
4247 (add-hook hook 'mdw-misc-mode-config t)
4248 (add-hook hook 'mdw-fontify-lispy t))
4249 (add-hook 'lisp-mode-hook 'mdw-common-lisp-indent t)
4250 (add-hook 'inferior-lisp-mode-hook
4251 #'(lambda () (local-set-key "\C-m" 'comint-send-and-indent)) t))
4253 ;;;--------------------------------------------------------------------------
4254 ;;; Other languages.
4258 (defun mdw-setup-smalltalk ()
4259 (and mdw-auto-indent
4260 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
4261 (make-local-variable 'mdw-auto-indent)
4262 (setq mdw-auto-indent nil)
4263 (local-set-key "\C-i" 'smalltalk-reindent))
4265 (defun mdw-fontify-smalltalk ()
4266 (make-local-variable 'font-lock-keywords)
4267 (setq font-lock-keywords
4269 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
4270 '(0 font-lock-keyword-face))
4271 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
4272 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
4273 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
4274 '(0 mdw-number-face))
4275 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4276 '(0 mdw-punct-face)))))
4279 (add-hook 'smalltalk-mode 'mdw-misc-mode-config t)
4280 (add-hook 'smalltalk-mode 'mdw-fontify-smalltalk t))
4284 (defun mdw-setup-m4 ()
4286 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
4287 ;; annoying: fix it.
4288 (modify-syntax-entry ?{ "(")
4289 (modify-syntax-entry ?} ")")
4292 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
4294 (dolist (hook '(m4-mode-hook autoconf-mode-hook autotest-mode-hook))
4295 (add-hook hook #'mdw-misc-mode-config t)
4296 (add-hook hook #'mdw-setup-m4 t))
4301 (add-hook 'makefile-mode-hook 'mdw-misc-mode-config t))
4303 ;;;--------------------------------------------------------------------------
4306 (defun mdw-text-mode ()
4307 (setq fill-column 72)
4309 (mdw-standard-fill-prefix
4310 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
4313 (eval-after-load "flyspell"
4314 '(define-key flyspell-mode-map "\C-\M-i" nil))
4317 (add-hook 'text-mode-hook 'mdw-text-mode t))
4319 ;;;--------------------------------------------------------------------------
4320 ;;; Outline and hide/show modes.
4322 (defun mdw-outline-collapse-all ()
4323 "Completely collapse everything in the entire buffer."
4326 (goto-char (point-min))
4327 (while (< (point) (point-max))
4331 (setq hs-hide-comments-when-hiding-all nil)
4333 (defadvice hs-hide-all (after hide-first-comment activate)
4334 (save-excursion (hs-hide-initial-comment-block)))
4336 ;;;--------------------------------------------------------------------------
4339 (defun mdw-sh-mode-setup ()
4340 (local-set-key [?\C-a] 'comint-bol)
4341 (add-hook 'comint-output-filter-functions
4342 'comint-watch-for-password-prompt))
4344 (defun mdw-term-mode-setup ()
4345 (setq term-prompt-regexp shell-prompt-pattern)
4346 (make-local-variable 'mouse-yank-at-point)
4347 (make-local-variable 'transient-mark-mode)
4348 (setq mouse-yank-at-point t)
4352 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
4353 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
4354 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
4355 (defun term-send-meta-meta-something ()
4357 (term-send-raw-string "\e\e")
4359 (eval-after-load 'term
4361 (define-key term-raw-map [?\e ?\e] nil)
4362 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
4363 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
4364 (define-key term-raw-map [M-right] 'term-send-meta-right)
4365 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
4366 (define-key term-raw-map [M-left] 'term-send-meta-left)
4367 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
4369 (defadvice term-exec (before program-args-list compile activate)
4370 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
4371 This allows you to pass a list of arguments through `ansi-term'."
4372 (let ((program (ad-get-arg 2)))
4375 (ad-set-arg 2 (car program))
4376 (ad-set-arg 4 (cdr program))))))
4378 (defadvice term-exec-1 (around hack-environment compile activate)
4379 "Hack the environment inherited by inferiors in the terminal."
4380 (let ((process-environment (copy-tree process-environment)))
4381 (setenv "LD_PRELOAD" nil)
4384 (defadvice shell (around hack-environment compile activate)
4385 "Hack the environment inherited by inferiors in the shell."
4386 (let ((process-environment (copy-tree process-environment)))
4387 (setenv "LD_PRELOAD" nil)
4391 "Open a terminal containing an ssh session to the HOST."
4392 (interactive "sHost: ")
4393 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
4395 (defvar git-grep-command
4396 "env GIT_PAGER=cat git grep --no-color -nH -e "
4397 "*The default command for \\[git-grep].")
4399 (defvar git-grep-history nil)
4401 (defun git-grep (command-args)
4402 "Run `git grep' with user-specified args and collect output in a buffer."
4404 (list (read-shell-command "Run git grep (like this): "
4405 git-grep-command 'git-grep-history)))
4406 (let ((grep-use-null-device nil))
4407 (grep command-args)))
4409 ;;;--------------------------------------------------------------------------
4410 ;;; Magit configuration.
4412 (setq magit-diff-refine-hunk 't
4413 magit-view-git-manual-method 'man
4414 magit-log-margin '(nil age magit-log-margin-width t 18)
4415 magit-wip-after-save-local-mode-lighter ""
4416 magit-wip-after-apply-mode-lighter ""
4417 magit-wip-before-change-mode-lighter "")
4418 (eval-after-load "magit"
4419 '(progn (global-magit-file-mode 1)
4420 (magit-wip-after-save-mode 1)
4421 (magit-wip-after-apply-mode 1)
4422 (magit-wip-before-change-mode 1)
4423 (add-to-list 'magit-no-confirm 'safe-with-wip)
4424 (add-to-list 'magit-no-confirm 'trash)
4425 (push '(:eval (if (or magit-wip-after-save-local-mode
4426 magit-wip-after-apply-mode
4427 magit-wip-before-change-mode)
4428 (format " wip:%s%s%s"
4429 (if magit-wip-after-apply-mode "A" "")
4430 (if magit-wip-before-change-mode "C" "")
4431 (if magit-wip-after-save-local-mode "S" ""))))
4433 (dolist (popup '(magit-diff-popup
4434 magit-diff-refresh-popup
4435 magit-diff-mode-refresh-popup
4436 magit-revision-mode-refresh-popup))
4437 (magit-define-popup-switch popup ?R "Reverse diff" "-R"))))
4439 (defadvice magit-wip-commit-buffer-file
4440 (around mdw-just-this-buffer activate compile)
4441 (let ((magit-save-repository-buffers nil)) ad-do-it))
4443 (defadvice magit-discard
4444 (around mdw-delete-if-prefix-argument activate compile)
4445 (let ((magit-delete-by-moving-to-trash
4446 (and (null current-prefix-arg)
4447 magit-delete-by-moving-to-trash)))
4450 (setq magit-repolist-columns
4451 '(("Name" 16 magit-repolist-column-ident nil)
4452 ("Version" 18 magit-repolist-column-version nil)
4453 ("St" 2 magit-repolist-column-dirty nil)
4454 ("L<U" 3 mdw-repolist-column-unpulled-from-upstream nil)
4455 ("L>U" 3 mdw-repolist-column-unpushed-to-upstream nil)
4456 ("Path" 32 magit-repolist-column-path nil)))
4458 (setq magit-repository-directories '(("~/etc/profile" . 0)
4461 (defadvice magit-list-repos (around mdw-dirname () activate compile)
4462 "Make sure the returned names are directory names.
4463 Otherwise child processes get started in the wrong directory and
4465 (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it)))
4467 (defun mdw-repolist-column-unpulled-from-upstream (_id)
4468 "Insert number of upstream commits not in the current branch."
4469 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
4471 (let ((n (cadr (magit-rev-diff-count "HEAD" upstream))))
4472 (propertize (number-to-string n) 'face
4473 (if (> n 0) 'bold 'shadow))))))
4475 (defun mdw-repolist-column-unpushed-to-upstream (_id)
4476 "Insert number of commits in the current branch but not its upstream."
4477 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
4479 (let ((n (car (magit-rev-diff-count "HEAD" upstream))))
4480 (propertize (number-to-string n) 'face
4481 (if (> n 0) 'bold 'shadow))))))
4483 (defun mdw-try-smerge ()
4485 (goto-char (point-min))
4486 (when (re-search-forward "^<<<<<<< " nil t)
4488 (add-hook 'find-file-hook 'mdw-try-smerge t)
4490 ;;;--------------------------------------------------------------------------
4491 ;;; GUD, and especially GDB.
4493 ;; Inhibit window dedication. I mean, seriously, wtf?
4494 (defadvice gdb-display-buffer (after mdw-undedicated (buf) compile activate)
4495 "Don't make windows dedicated. Seriously."
4496 (set-window-dedicated-p ad-return-value nil))
4497 (defadvice gdb-set-window-buffer
4498 (after mdw-undedicated (name &optional ignore-dedicated window)
4500 "Don't make windows dedicated. Seriously."
4501 (set-window-dedicated-p (or window (selected-window)) nil))
4503 ;;;--------------------------------------------------------------------------
4506 ;; Turn off `noip' when running `man': it interferes with `man-db''s own
4507 ;; seccomp(2)-based sandboxing, which is (in this case, at least) strictly
4509 (defadvice Man-getpage-in-background
4510 (around mdw-inhibit-noip (topic) compile activate)
4511 "Inhibit the `noip' preload hack when invoking `man'."
4512 (let* ((old-preload (getenv "LD_PRELOAD"))
4513 (preloads (save-match-data (split-string old-preload ":")))
4517 (let ((item (pop preloads)))
4518 (if (save-match-data
4519 (string-match "\\(/\\|^\\)noip\.so\\(:\\|$\\)" item))
4521 (push item filtered))))
4525 (setenv "LD_PRELOAD"
4527 (with-output-to-string
4528 (setq filtered (nreverse filtered))
4531 (if first (setq first nil)
4533 (write-string (pop filtered)))))))
4535 (setenv "LD_PRELOAD" old-preload))
4538 ;;;--------------------------------------------------------------------------
4539 ;;; MPC configuration.
4541 (eval-when-compile (trap (require 'mpc)))
4543 (setq mpc-browser-tags '(Artist|Composer|Performer Album|Playlist))
4545 (defun mdw-mpc-now-playing ()
4549 (set-buffer (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))))
4550 (mpc--status-callback))
4551 (let ((state (cdr (assq 'state mpc-status))))
4552 (cond ((member state '("stop"))
4553 (message "mpd stopped."))
4554 ((member state '("play" "pause"))
4555 (let* ((artist (cdr (assq 'Artist mpc-status)))
4556 (album (cdr (assq 'Album mpc-status)))
4557 (title (cdr (assq 'Title mpc-status)))
4558 (file (cdr (assq 'file mpc-status)))
4559 (duration-string (cdr (assq 'Time mpc-status)))
4560 (time-string (cdr (assq 'time mpc-status)))
4561 (time (and time-string
4563 (if (string-match ":" time-string)
4564 (substring time-string
4565 0 (match-beginning 0))
4567 (duration (and duration-string
4568 (string-to-number duration-string)))
4569 (pos (and time duration
4570 (format " [%d:%02d/%d:%02d]"
4571 (/ time 60) (mod time 60)
4572 (/ duration 60) (mod duration 60))))
4573 (fmt (cond ((and artist title)
4574 (format "`%s' by %s%s" title artist
4575 (if album (format ", from `%s'" album)
4578 (format "`%s' (no tags)" file))
4580 "(no idea what's playing!)"))))
4581 (if (string= state "play")
4582 (message "mpd playing %s%s" fmt (or pos ""))
4583 (message "mpd paused in %s%s" fmt (or pos "")))))
4585 (message "mpd in unknown state `%s'" state)))))
4587 (defmacro mdw-define-mpc-wrapper (func bvl interactive &rest body)
4589 (interactive ,@interactive)
4592 (mdw-mpc-now-playing)))
4594 (mdw-define-mpc-wrapper mdw-mpc-play-or-pause () nil
4595 (if (member (cdr (assq 'state (mpc-cmd-status))) '("play"))
4599 (mdw-define-mpc-wrapper mdw-mpc-next () nil (mpc-next))
4600 (mdw-define-mpc-wrapper mdw-mpc-prev () nil (mpc-prev))
4601 (mdw-define-mpc-wrapper mdw-mpc-stop () nil (mpc-stop))
4603 (defun mdw-mpc-louder (step)
4604 (interactive (list (if current-prefix-arg
4605 (prefix-numeric-value current-prefix-arg)
4607 (mpc-proc-cmd (format "volume %+d" step)))
4609 (defun mdw-mpc-quieter (step)
4610 (interactive (list (if current-prefix-arg
4611 (prefix-numeric-value current-prefix-arg)
4613 (mpc-proc-cmd (format "volume %+d" (- step))))
4615 (defun mdw-mpc-hack-lines (arg interactivep func)
4616 (if (and interactivep (use-region-p))
4617 (let ((from (region-beginning)) (to (region-end)))
4622 (while (< (point) to)
4625 (let ((n (prefix-numeric-value arg)))
4642 (defun mdw-mpc-select-one ()
4643 (when (and (get-char-property (point) 'mpc-file)
4644 (not (get-char-property (point) 'mpc-select)))
4645 (mpc-select-toggle)))
4647 (defun mdw-mpc-unselect-one ()
4648 (when (get-char-property (point) 'mpc-select)
4649 (mpc-select-toggle)))
4651 (defun mdw-mpc-select (&optional arg interactivep)
4652 (interactive (list current-prefix-arg t))
4653 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4655 (defun mdw-mpc-unselect (&optional arg interactivep)
4656 (interactive (list current-prefix-arg t))
4657 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one))
4659 (defun mdw-mpc-unselect-backwards (arg)
4661 (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one))
4663 (defun mdw-mpc-unselect-all ()
4665 (setq mpc-select nil)
4666 (mpc-selection-refresh))
4668 (defun mdw-mpc-next-line (arg)
4673 (defun mdw-mpc-previous-line (arg)
4676 (forward-line (- arg)))
4678 (defun mdw-mpc-playlist-add (&optional arg interactivep)
4679 (interactive (list current-prefix-arg t))
4680 (let ((mpc-select mpc-select))
4681 (when (or arg (and interactivep (use-region-p)))
4682 (setq mpc-select nil)
4683 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4684 (setq mpc-select (reverse mpc-select))
4685 (mpc-playlist-add)))
4687 (defun mdw-mpc-playlist-delete (&optional arg interactivep)
4688 (interactive (list current-prefix-arg t))
4689 (setq mpc-select (nreverse mpc-select))
4691 (when (or arg (and interactivep (use-region-p)))
4692 (setq mpc-select nil)
4693 (mpc-selection-refresh)
4694 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4695 (mpc-playlist-delete)))
4697 (defun mdw-mpc-hack-tagbrowsers ()
4698 (setq-local mode-line-format
4700 mode-line-frame-identification
4701 mode-line-buffer-identification)))
4702 (add-hook 'mpc-tagbrowser-mode-hook 'mdw-mpc-hack-tagbrowsers)
4704 (defun mdw-mpc-hack-songs ()
4705 (setq-local header-line-format
4706 ;; '("MPC " mpc-volume " " mpc-current-song)
4707 (list (propertize " " 'display '(space :align-to 0))
4708 ;; 'mpc-songs-format-description
4710 (let ((deactivate-mark) (hscroll (window-hscroll)))
4712 (mpc-format mpc-songs-format 'self hscroll)
4713 ;; That would be simpler than the hscroll handling in
4714 ;; mpc-format, but currently move-to-column does not
4715 ;; recognize :space display properties.
4716 ;; (move-to-column hscroll)
4717 ;; (delete-region (point-min) (point))
4718 (buffer-string)))))))
4719 (add-hook 'mpc-songs-mode-hook 'mdw-mpc-hack-songs)
4721 (eval-after-load "mpc"
4723 (define-key mpc-mode-map "m" 'mdw-mpc-select)
4724 (define-key mpc-mode-map "u" 'mdw-mpc-unselect)
4725 (define-key mpc-mode-map "\177" 'mdw-mpc-unselect-backwards)
4726 (define-key mpc-mode-map "\e\177" 'mdw-mpc-unselect-all)
4727 (define-key mpc-mode-map "n" 'mdw-mpc-next-line)
4728 (define-key mpc-mode-map "p" 'mdw-mpc-previous-line)
4729 (define-key mpc-mode-map "/" 'mpc-songs-search)
4730 (setq mpc-songs-mode-map (make-sparse-keymap))
4731 (set-keymap-parent mpc-songs-mode-map mpc-mode-map)
4732 (define-key mpc-songs-mode-map "l" 'mpc-playlist)
4733 (define-key mpc-songs-mode-map "+" 'mdw-mpc-playlist-add)
4734 (define-key mpc-songs-mode-map "-" 'mdw-mpc-playlist-delete)
4735 (define-key mpc-songs-mode-map "\r" 'mpc-songs-jump-to)))
4737 ;;;--------------------------------------------------------------------------
4738 ;;; Inferior Emacs Lisp.
4740 (setq comint-prompt-read-only t)
4742 (eval-after-load "comint"
4744 (define-key comint-mode-map "\C-w" 'comint-kill-region)
4745 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
4747 (eval-after-load "ielm"
4749 (define-key ielm-map "\C-w" 'comint-kill-region)
4750 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
4752 ;;;----- That's all, folks --------------------------------------------------
4754 (provide 'dot-emacs)