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)))
172 ;; Splitting windows.
174 (unless (fboundp 'scroll-bar-columns)
175 (defun scroll-bar-columns (side)
176 (cond ((eq side 'left) 0)
179 (unless (fboundp 'fringe-columns)
180 (defun fringe-columns (side)
181 (cond ((not window-system) 0)
185 (defun mdw-horizontal-window-overhead ()
186 "Computes the horizontal window overhead.
187 This is the number of columns used by fringes, scroll bars and other such
189 (if (not window-system)
192 (dolist (what '(scroll-bar fringe))
193 (dolist (side '(left right))
194 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
198 (defun mdw-split-window-horizontally (&optional width)
199 "Split a window horizontally.
200 Without a numeric argument, split the window approximately in
201 half. With a numeric argument WIDTH, allocate WIDTH columns to
202 the left-hand window (if positive) or -WIDTH columns to the
203 right-hand window (if negative). Space for scroll bars and
204 fringes is not taken out of the allowance for WIDTH, unlike
205 \\[split-window-horizontally]."
207 (split-window-horizontally
208 (cond ((null width) nil)
209 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
210 ((< width 0) width))))
212 (defun mdw-preferred-column-width ()
213 "Return the preferred column width."
214 (if (and window-system (mdw-emacs-version-p 22)) mdw-column-width
215 (1+ mdw-column-width)))
217 (defun mdw-divvy-window (&optional width)
218 "Split a wide window into appropriate widths."
220 (setq width (if width (prefix-numeric-value width)
221 (mdw-preferred-column-width)))
222 (let* ((win (selected-window))
223 (sb-width (mdw-horizontal-window-overhead))
224 (c (/ (+ (window-width) sb-width)
225 (+ width sb-width))))
228 (split-window-horizontally (+ width sb-width))
230 (select-window win)))
232 (defun mdw-set-frame-width (columns &optional width)
233 (interactive "nColumns:
235 (setq width (if width (prefix-numeric-value width)
236 (mdw-preferred-column-width)))
237 (let ((sb-width (mdw-horizontal-window-overhead)))
238 (set-frame-width (selected-frame)
239 (- (* columns (+ width sb-width))
241 (mdw-divvy-window width)))
243 (defvar mdw-frame-width-fudge
244 (cond ((<= emacs-major-version 20) 1)
245 ((= emacs-major-version 26) 3)
247 "The number of extra columns to add to the desired frame width.
249 This is sadly necessary because Emacs 26 is broken in this regard.")
251 ;; Don't raise windows unless I say so.
253 (defvar mdw-inhibit-raise-frame nil
254 "*Whether `raise-frame' should do nothing when the frame is mapped.")
256 (defadvice raise-frame
257 (around mdw-inhibit (&optional frame) activate compile)
258 "Don't actually do anything if `mdw-inhibit-raise-frame' is true, and the
259 frame is actually mapped on the screen."
260 (if mdw-inhibit-raise-frame
261 (make-frame-visible frame)
264 (defmacro mdw-advise-to-inhibit-raise-frame (function)
265 "Advise the FUNCTION not to raise frames, even if it wants to."
266 `(defadvice ,function
267 (around mdw-inhibit-raise (&rest hunoz) activate compile)
268 "Don't raise the window unless you have to."
269 (let ((mdw-inhibit-raise-frame t))
272 (mdw-advise-to-inhibit-raise-frame select-frame-set-input-focus)
273 (mdw-advise-to-inhibit-raise-frame appt-disp-window)
274 (mdw-advise-to-inhibit-raise-frame mouse-select-window)
276 ;; Bug fix for markdown-mode, which breaks point positioning during
278 (defadvice markdown-check-change-for-wiki-link
279 (around mdw-save-match activate compile)
280 "Save match data around the `markdown-mode' `after-change-functions' hook."
281 (save-match-data ad-do-it))
283 ;; Bug fix for `bbdb-canonicalize-address': on Emacs 24, `run-hook-with-args'
284 ;; always returns nil, with the result that all email addresses are lost.
285 ;; Replace the function entirely.
286 (defadvice bbdb-canonicalize-address
287 (around mdw-bug-fix activate compile)
288 "Don't use `run-hook-with-args', because that doesn't work."
289 (let ((net (ad-get-arg 0)))
291 ;; Make sure this is a proper hook list.
292 (if (functionp bbdb-canonicalize-net-hook)
293 (setq bbdb-canonicalize-net-hook (list bbdb-canonicalize-net-hook)))
295 ;; Iterate over the hooks until things converge.
298 (let (next (changep nil)
299 hook (hooks bbdb-canonicalize-net-hook))
301 (setq hook (pop hooks))
302 (setq next (funcall hook net))
303 (if (not (equal next net))
306 (setq donep (not changep)))))
307 (setq ad-return-value net)))
309 ;; Transient mark mode hacks.
311 (defadvice exchange-point-and-mark
312 (around mdw-highlight (&optional arg) activate compile)
313 "Maybe don't actually exchange point and mark.
314 If `transient-mark-mode' is on and the mark is inactive, then
315 just activate it. A non-trivial prefix argument will force the
316 usual behaviour. A trivial prefix argument (i.e., just C-u) will
317 activate the mark and temporarily enable `transient-mark-mode' if
319 (cond ((or mark-active
320 (and (not transient-mark-mode) (not arg))
321 (and arg (or (not (consp arg))
322 (not (= (car arg) 4)))))
325 (or transient-mark-mode (setq transient-mark-mode 'only))
326 (set-mark (mark t)))))
328 ;; Functions for sexp diary entries.
330 (defun mdw-not-org-mode (form)
331 "As FORM, but not in Org mode agenda."
332 (and (not mdw-diary-for-org-mode-p)
335 (defun mdw-weekday (l)
336 "Return non-nil if `date' falls on one of the days of the week in L.
337 L is a list of day numbers (from 0 to 6 for Sunday through to
338 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
339 the date stored in `date' falls on a listed day, then the
340 function returns non-nil."
341 (let ((d (calendar-day-of-week date)))
343 (memq (nth d '(sunday monday tuesday wednesday
344 thursday friday saturday)) l))))
346 (defun mdw-discordian-date (date)
347 "Return the Discordian calendar date corresponding to DATE.
349 The return value is (YOLD . st-tibs-day) or (YOLD SEASON DAYNUM DOW).
351 The original is by David Pearson. I modified it to produce date components
352 as output rather than a string."
353 (let* ((days ["Sweetmorn" "Boomtime" "Pungenday"
354 "Prickle-Prickle" "Setting Orange"])
355 (months ["Chaos" "Discord" "Confusion"
356 "Bureaucracy" "Aftermath"])
357 (day-count [0 31 59 90 120 151 181 212 243 273 304 334])
358 (year (- (extract-calendar-year date) 1900))
359 (month (1- (extract-calendar-month date)))
360 (day (1- (extract-calendar-day date)))
361 (julian (+ (aref day-count month) day))
362 (dyear (+ year 3066)))
363 (if (and (= month 1) (= day 28))
364 (cons dyear 'st-tibs-day)
366 (aref months (floor (/ julian 73)))
368 (aref days (mod julian 5))))))
370 (defun mdw-diary-discordian-date ()
371 "Convert the date in `date' to a string giving the Discordian date."
372 (let* ((ddate (mdw-discordian-date date))
373 (tail (format "in the YOLD %d" (car ddate))))
374 (if (eq (cdr ddate) 'st-tibs-day)
375 (format "St Tib's Day %s" tail)
376 (let ((season (cadr ddate))
377 (daynum (caddr ddate))
378 (dayname (cadddr ddate)))
379 (format "%s, the %d%s day of %s %s"
382 (let ((ldig (mod daynum 10)))
383 (cond ((= ldig 1) "st")
390 (defun mdw-todo (&optional when)
391 "Return non-nil today, or on WHEN, whichever is later."
392 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
393 (d (calendar-absolute-from-gregorian date)))
395 (setq w (max w (calendar-absolute-from-gregorian
397 ((not european-calendar-style)
409 (defvar mdw-diary-for-org-mode-p nil)
411 (defadvice org-agenda-list (around mdw-preserve-links activate)
412 (let ((mdw-diary-for-org-mode-p t))
415 (defvar diary-time-regexp nil)
417 (defadvice diary-add-to-list (before mdw-trim-leading-space compile activate)
418 "Trim leading space from the diary entry string."
420 (let ((str (ad-get-arg 1))
424 (setq str (cond ((null str) nil)
425 ((string-match "\\(^\\|\n\\)[ \t]+" str)
426 (replace-match "\\1" nil nil str))
427 ((and mdw-diary-for-org-mode-p
428 (string-match (concat
430 "\\(" diary-time-regexp
431 "\\(-" diary-time-regexp "\\)?"
433 "\\(\t[ \t]*\\| [ \t]+\\)")
435 (replace-match "\\1\\2 " nil nil str))
436 ((and (not mdw-diary-for-org-mode-p)
437 (string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]"
439 (replace-match "\\1" nil nil str))
441 (if (equal str old) (setq done t)))
442 (ad-set-arg 1 str))))
444 (defadvice org-bbdb-anniversaries (after mdw-fixup-list compile activate)
445 "Return a string rather than a list."
448 (dolist (e (let ((ee ad-return-value))
449 (if (atom ee) (list ee) ee)))
451 (when anyp (insert ?\n))
454 (setq ad-return-value
455 (and anyp (buffer-string))))))
457 ;; Fighting with Org-mode's evil key maps.
459 (defvar mdw-evil-keymap-keys
460 '(([S-up] . [?\C-c up])
461 ([S-down] . [?\C-c down])
462 ([S-left] . [?\C-c left])
463 ([S-right] . [?\C-c right])
464 (([M-up] [?\e up]) . [C-up])
465 (([M-down] [?\e down]) . [C-down])
466 (([M-left] [?\e left]) . [C-left])
467 (([M-right] [?\e right]) . [C-right]))
468 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
469 The value is an alist mapping evil keys (as a list, or singleton)
470 to good keys (in the same form).")
472 (defun mdw-clobber-evil-keymap (keymap)
473 "Replace evil key bindings in the KEYMAP.
474 Evil key bindings are defined in `mdw-evil-keymap-keys'."
475 (dolist (entry mdw-evil-keymap-keys)
477 (keys (if (listp (car entry))
480 (replacements (if (listp (cdr entry))
482 (list (cdr entry)))))
485 (setq binding (lookup-key keymap key))
487 (throw 'found nil))))
490 (define-key keymap key nil))
491 (dolist (key replacements)
492 (define-key keymap key binding))))))
494 (defvar mdw-org-latex-defs
496 "\\documentclass{strayman}
497 \\usepackage[utf8]{inputenc}
498 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
499 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
500 ("\\section{%s}" . "\\section*{%s}")
501 ("\\subsection{%s}" . "\\subsection*{%s}")
502 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
503 ("\\paragraph{%s}" . "\\paragraph*{%s}")
504 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))
506 (eval-after-load "org-latex"
507 '(setq org-export-latex-classes
508 (append mdw-org-latex-defs org-export-latex-classes)))
510 (eval-after-load "ox-latex"
511 '(setq org-latex-classes (append mdw-org-latex-defs org-latex-classes)
512 org-latex-default-packages-alist '(("AUTO" "inputenc" t)
520 ("normalem" "ulem" t)
526 "\\tolerance=1000")))
529 (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
530 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
531 org-export-docbook-xslt-stylesheet
532 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
536 (setq glasses-separator "-"
537 glasses-separate-parentheses-p nil
538 glasses-uncapitalize-p t)
540 ;; Some hacks to do with window placement.
542 (defun mdw-clobber-other-windows-showing-buffer (buffer-or-name)
543 "Arrange that no windows on other frames are showing BUFFER-OR-NAME."
544 (interactive "bBuffer: ")
545 (let ((home-frame (selected-frame))
546 (buffer (get-buffer buffer-or-name))
547 (safe-buffer (get-buffer "*scratch*")))
548 (dolist (frame (frame-list))
549 (unless (eq frame home-frame)
550 (dolist (window (window-list frame))
551 (when (eq (window-buffer window) buffer)
552 (set-window-buffer window safe-buffer)))))))
554 (defvar mdw-inhibit-walk-windows nil
555 "If non-nil, then `walk-windows' does nothing.
556 This is used by advice on `switch-to-buffer-other-frame' to inhibit finding
557 buffers in random frames.")
559 (setq display-buffer--other-frame-action
560 '((display-buffer-reuse-window display-buffer-pop-up-frame)
561 (reusable-frames . nil)
562 (inhibit-same-window . t)))
564 (defadvice walk-windows (around mdw-inhibit activate)
565 "If `mdw-inhibit-walk-windows' is non-nil, then do nothing."
566 (and (not mdw-inhibit-walk-windows)
569 (defadvice switch-to-buffer-other-frame
570 (around mdw-always-new-frame activate)
571 "Always make a new frame.
572 Even if an existing window in some random frame looks tempting."
573 (let ((mdw-inhibit-walk-windows t)) ad-do-it))
575 (defadvice display-buffer (before mdw-inhibit-other-frames activate)
576 "Don't try to do anything fancy with other frames.
577 Pretend they don't exist. They might be on other display devices."
580 ;;;--------------------------------------------------------------------------
581 ;;; Improved compilation machinery.
583 ;; Uprated version of M-x compile.
585 (setq compile-command
586 (let ((ncpu (with-temp-buffer
587 (insert-file-contents "/proc/cpuinfo")
589 (count-matches "^processor\\s-*:"))))
590 (format "make -j%d -k" (* 2 ncpu))))
592 (defun mdw-compilation-buffer-name (mode)
593 (concat "*" (downcase mode) ": "
594 (abbreviate-file-name default-directory) "*"))
595 (setq compilation-buffer-name-function 'mdw-compilation-buffer-name)
597 (eval-after-load "compile"
599 (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile)))
601 (defadvice compile (around hack-environment compile activate)
602 "Hack the environment inherited by inferiors in the compilation."
603 (let ((process-environment (copy-tree process-environment)))
604 (setenv "LD_PRELOAD" nil)
607 (defun mdw-compile (command &optional directory comint)
608 "Initiate a compilation COMMAND, maybe in a different DIRECTORY.
609 The DIRECTORY may be nil to not change. If COMINT is t, then
610 start an interactive compilation.
612 Interactively, prompt for the command if the variable
613 `compilation-read-command' is non-nil, or if requested through
614 the prefix argument. Prompt for the directory, and run
615 interactively, if requested through the prefix.
617 Use a prefix of 4, 6, 12, or 14, or type C-u between one and three times, to
618 force prompting for a directory.
620 Use a prefix of 2, 6, 10, or 14, or type C-u three times, to force
621 prompting for the command.
623 Use a prefix of 8, 10, 12, or 14, or type C-u twice or three times,
624 to force interactive compilation."
626 (let* ((prefix (prefix-numeric-value current-prefix-arg))
627 (command (eval compile-command))
628 (dir (and (plusp (logand prefix #x54))
629 (read-directory-name "Compile in directory: "))))
630 (list (if (or compilation-read-command
631 (plusp (logand prefix #x42)))
632 (compilation-read-command command)
635 (plusp (logand prefix #x58)))))
636 (let ((default-directory (or directory default-directory)))
637 (compile command comint)))
641 (defun mdw-find-build-dir (build-file)
643 (let* ((src-dir (file-name-as-directory (expand-file-name ".")))
646 (when (file-exists-p (concat dir build-file))
648 (let ((sub (expand-file-name (file-relative-name src-dir dir)
649 (concat dir "build/"))))
652 (when (file-exists-p (concat sub build-file))
654 (when (string= sub dir) (throw 'give-up nil))
655 (setq sub (file-name-directory (directory-file-name sub))))))
657 (setq dir (file-name-directory
658 (directory-file-name dir))))
659 (throw 'found nil))))))
661 (defun mdw-flymake-make-init ()
662 (let ((build-dir (mdw-find-build-dir "Makefile")))
664 (let ((tmp-src (flymake-init-create-temp-buffer-copy
665 #'flymake-create-temp-inplace)))
666 (flymake-get-syntax-check-program-args
667 tmp-src build-dir t t
668 #'flymake-get-make-cmdline)))))
670 (setq flymake-allowed-file-name-masks
671 '(("\\.\\(?:[cC]\\|cc\\|cpp\\|cxx\\|c\\+\\+\\)\\'"
672 mdw-flymake-make-init)
673 ("\\.\\(?:[hH]\\|hh\\|hpp\\|hxx\\|h\\+\\+\\)\\'"
674 mdw-flymake-master-make-init)
675 ("\\.p[lm]" flymake-perl-init)))
677 (setq flymake-mode-map
678 (let ((map (if (boundp 'flymake-mode-map)
680 (make-sparse-keymap))))
681 (define-key map [?\C-c ?\C-f ?\C-p] 'flymake-goto-prev-error)
682 (define-key map [?\C-c ?\C-f ?\C-n] 'flymake-goto-next-error)
683 (define-key map [?\C-c ?\C-f ?\C-c] 'flymake-compile)
684 (define-key map [?\C-c ?\C-f ?\C-k] 'flymake-stop-all-syntax-checks)
685 (define-key map [?\C-c ?\C-f ?\C-e] 'flymake-popup-current-error-menu)
688 ;;;--------------------------------------------------------------------------
689 ;;; Mail and news hacking.
691 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
692 "Major mode for editing news and mail messages from external programs.
693 Not much right now. Just support for doing MailCrypt stuff."
696 (run-hooks 'mail-setup-hook))
698 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
700 (add-hook 'mdwail-mode-hook
702 (set-buffer-file-coding-system 'utf-8)
703 (make-local-variable 'paragraph-separate)
704 (make-local-variable 'paragraph-start)
705 (setq paragraph-start
706 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
708 (setq paragraph-separate
709 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
710 paragraph-separate))))
712 ;; How to encrypt in mdwmail.
714 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
716 (setq start (save-excursion
717 (goto-char (point-min))
718 (or (search-forward "\n\n" nil t) (point-min)))))
720 (setq end (point-max)))
721 (mc-encrypt-generic recip scm start end from sign))
723 ;; How to sign in mdwmail.
725 (defun mdwmail-mc-sign (key scm start end uclr)
727 (setq start (save-excursion
728 (goto-char (point-min))
729 (or (search-forward "\n\n" nil t) (point-min)))))
731 (setq end (point-max)))
732 (mc-sign-generic key scm start end uclr))
734 ;; Some signature mangling.
736 (defun mdwmail-mangle-signature ()
738 (goto-char (point-min))
739 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
740 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
741 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
743 ;; Insert my login name into message-ids, so I can score replies.
745 (defadvice message-unique-id (after mdw-user-name last activate compile)
746 "Ensure that the user's name appears at the end of the message-id string,
747 so that it can be used for convenient filtering."
748 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
750 ;; Tell my movemail hack where movemail is.
752 ;; This is needed to shup up warnings about LD_PRELOAD.
754 (let ((path exec-path))
756 (let ((try (expand-file-name "movemail" (car path))))
757 (if (file-executable-p try)
758 (setenv "REAL_MOVEMAIL" try))
759 (setq path (cdr path)))))
761 ;; AUTHINFO GENERIC kludge.
763 (defvar nntp-authinfo-generic nil
764 "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'.
766 Use this to arrange for per-server settings.")
768 (defun nntp-open-authinfo-kludge (buffer)
769 "Open a connection to SERVER using `authinfo-kludge'."
770 (let ((proc (start-process "nntpd" buffer
771 "env" (concat "NNTPAUTH="
772 (or nntp-authinfo-generic
774 (error "NNTPAUTH unset")))
775 "authinfo-kludge" nntp-address)))
777 (nntp-wait-for-string "^\r*200")
779 (delete-region (point-min) (point))
782 (eval-after-load "erc"
783 '(load "~/.ercrc.el"))
785 ;; Heavy-duty Gnus patching.
787 (defun mdw-nnimap-transform-headers ()
788 (goto-char (point-min))
789 (let (article lines size string)
792 (while (not (looking-at "\\* [0-9]+ FETCH"))
793 (delete-region (point) (progn (forward-line 1) (point)))
796 (goto-char (match-end 0))
797 ;; Unfold quoted {number} strings.
798 (while (re-search-forward
799 "[^]][ (]{\\([0-9]+\\)}\r?\n"
801 ;; Start of the header section.
802 (or (re-search-forward "] {[0-9]+}\r?\n" nil t)
803 ;; Start of the next FETCH.
804 (re-search-forward "\\* [0-9]+ FETCH" nil t)
807 (setq size (string-to-number (match-string 1)))
808 (delete-region (+ (match-beginning 0) 2) (point))
809 (setq string (buffer-substring (point) (+ (point) size)))
810 (delete-region (point) (+ (point) size))
811 (insert (format "%S" (subst-char-in-string ?\n ?\s string)))
812 ;; [mdw] missing from upstream
816 (and (re-search-forward "UID \\([0-9]+\\)" (line-end-position)
821 (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)"
826 (when (search-forward "BODYSTRUCTURE" (line-end-position) t)
827 (let ((structure (ignore-errors
828 (read (current-buffer)))))
829 (while (and (consp structure)
830 (not (atom (car structure))))
831 (setq structure (car structure)))
833 (stringp (car structure))
834 (equal (upcase (nth 0 structure)) "MESSAGE")
835 (equal (upcase (nth 1 structure)) "RFC822"))
837 (nth 7 structure)))))
838 (delete-region (line-beginning-position) (line-end-position))
839 (insert (format "211 %s Article retrieved." article))
842 (insert (format "Chars: %s\n" size)))
844 (insert (format "Lines: %s\n" lines)))
845 ;; Most servers have a blank line after the headers, but
847 (unless (re-search-forward "^\r$\\|^)\r?$" nil t)
848 (goto-char (point-max)))
849 (delete-region (line-beginning-position) (line-end-position))
853 (eval-after-load 'nnimap
854 '(defalias 'nnimap-transform-headers
855 (symbol-function 'mdw-nnimap-transform-headers)))
857 ;;;--------------------------------------------------------------------------
858 ;;; Utility functions.
860 (or (fboundp 'line-number-at-pos)
861 (defun line-number-at-pos (&optional pos)
862 (let ((opoint (or pos (point))) start)
865 (goto-char (point-min))
871 (1+ (count-lines 1 (point))))))))
873 (defun mdw-uniquify-alist (&rest alists)
874 "Return the concatenation of the ALISTS with duplicate elements removed.
875 The first association with a given key prevails; others are
876 ignored. The input lists are not modified, although they'll
877 probably become garbage."
879 (let ((start-list (cons nil nil)))
880 (mdw-do-uniquify start-list
885 (defun mdw-do-uniquify (done end l rest)
886 "A helper function for mdw-uniquify-alist.
887 The DONE argument is a list whose first element is `nil'. It
888 contains the uniquified alist built so far. The leading `nil' is
889 stripped off at the end of the operation; it's only there so that
890 DONE always references a cons cell. END refers to the final cons
891 cell in the DONE list; it is modified in place each time to avoid
892 the overheads of `append'ing all the time. The L argument is the
893 alist we're currently processing; the remaining alists are given
896 ;; There are several different cases to deal with here.
899 ;; Current list isn't empty. Add the first item to the DONE list if
900 ;; there's not an item with the same KEY already there.
901 (l (or (assoc (car (car l)) done)
903 (setcdr end (cons (car l) nil))
904 (setq end (cdr end))))
905 (mdw-do-uniquify done end (cdr l) rest))
907 ;; The list we were working on is empty. Shunt the next list into the
908 ;; current list position and go round again.
909 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
911 ;; Everything's done. Remove the leading `nil' from the DONE list and
912 ;; return it. Finished!
916 "Insert the current date in a pleasing way."
918 (insert (save-excursion
919 (let ((buffer (get-buffer-create "*tmp*")))
920 (unwind-protect (progn (set-buffer buffer)
922 (shell-command "date +%Y-%m-%d" t)
926 (kill-buffer buffer))))))
928 (defun uuencode (file &optional name)
929 "UUencodes a file, maybe calling it NAME, into the current buffer."
930 (interactive "fInput file name: ")
932 ;; If NAME isn't specified, then guess from the filename.
936 (or (string-match "[^/]*$" file) 0))))
937 (print (format "uuencode `%s' `%s'" file name))
939 ;; Now actually do the thing.
940 (call-process "uuencode" file t nil name))
942 (defvar np-file "~/.np"
943 "*Where the `now-playing' file is.")
945 (defun np (&optional arg)
946 "Grabs a `now-playing' string."
950 (goto-char (point-max))
952 (insert-file-contents np-file)))))
954 (defun mdw-version-< (ver-a ver-b)
955 "Answer whether VER-A is strictly earlier than VER-B.
956 VER-A and VER-B are version numbers, which are strings containing digit
957 sequences separated by `.'."
958 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
959 (split-string ver-a "\\.")))
960 (lb (mapcar (lambda (x) (car (read-from-string x)))
961 (split-string ver-b "\\."))))
964 (cond ((null la) (throw 'done lb))
965 ((null lb) (throw 'done nil))
966 ((< (car la) (car lb)) (throw 'done t))
967 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))
968 (t (throw 'done nil)))))))
970 (defun mdw-check-autorevert ()
971 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
972 This takes into consideration whether it's been found using
973 tramp, which seems to get itself into a twist."
974 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
976 ((and (buffer-file-name)
977 (fboundp 'tramp-tramp-file-p)
978 (tramp-tramp-file-p (buffer-file-name)))
979 (unless global-auto-revert-ignore-buffer
980 (setq global-auto-revert-ignore-buffer 'tramp)))
981 ((eq global-auto-revert-ignore-buffer 'tramp)
982 (setq global-auto-revert-ignore-buffer nil))))
984 (defadvice find-file (after mdw-autorevert activate)
985 (mdw-check-autorevert))
986 (defadvice write-file (after mdw-autorevert activate)
987 (mdw-check-autorevert))
989 (defun mdw-auto-revert ()
990 "Recheck all of the autorevertable buffers, and update VC modelines."
992 (let ((auto-revert-check-vc-info t))
993 (auto-revert-buffers)))
995 (defun comint-send-and-indent ()
999 (indent-for-tab-command)))
1001 (defadvice comint-line-beginning-position
1002 (around mdw-calculate-it-properly () activate compile)
1003 "Calculate the actual line start for multi-line input."
1004 (if (or comint-use-prompt-regexp
1005 (eq (field-at-pos (point)) 'output))
1007 (setq ad-return-value
1008 (constrain-to-field (line-beginning-position) (point)))))
1010 ;;;--------------------------------------------------------------------------
1013 (defadvice dired-maybe-insert-subdir
1014 (around mdw-marked-insertion first activate)
1015 "The DIRNAME may be a list of directory names to insert.
1016 Interactively, if files are marked, then insert all of them.
1017 With a numeric prefix argument, select that many entries near
1018 point; with a non-numeric prefix argument, prompt for listing
1021 (list (dired-get-marked-files nil
1022 (and (integerp current-prefix-arg)
1025 (and current-prefix-arg
1026 (not (integerp current-prefix-arg))
1027 (read-string "Switches for listing: "
1028 (or dired-subdir-switches
1029 dired-actual-switches)))))
1030 (let ((dirs (ad-get-arg 0)))
1031 (dolist (dir (if (listp dirs) dirs (list dirs)))
1035 (defun mdw-dired-run (args &optional syncp)
1036 (interactive (let ((file (dired-get-filename t)))
1037 (list (read-string (format "Arguments for %s: " file))
1038 current-prefix-arg)))
1039 (funcall (if syncp 'shell-command 'async-shell-command)
1040 (concat (shell-quote-argument (dired-get-filename nil))
1043 (defadvice dired-do-flagged-delete
1044 (around mdw-delete-if-prefix-argument activate compile)
1045 (let ((delete-by-moving-to-trash (and (null current-prefix-arg)
1046 delete-by-moving-to-trash)))
1049 (eval-after-load "dired"
1050 '(define-key dired-mode-map "X" 'mdw-dired-run))
1052 ;;;--------------------------------------------------------------------------
1055 (defun mdw-w3m-browse-url (url &optional new-session-p)
1056 "Invoke w3m on the URL in its current window, or at least a different one.
1057 If NEW-SESSION-P, start a new session."
1058 (interactive "sURL: \nP")
1060 (let ((window (selected-window)))
1063 (select-window (or (and (not new-session-p)
1064 (get-buffer-window "*w3m*"))
1066 (if (one-window-p t) (split-window))
1068 (w3m-browse-url url new-session-p))
1069 (select-window window)))))
1071 (eval-after-load 'w3m
1072 '(define-key w3m-mode-map [?\e ?\r] 'w3m-view-this-url-new-session))
1074 (defvar mdw-good-url-browsers
1075 '(browse-url-mozilla
1077 (w3m . mdw-w3m-browse-url)
1079 "List of good browsers for mdw-good-url-browsers.
1080 Each item is a browser function name, or a cons (CHECK . FUNC).
1081 A symbol FOO stands for (FOO . FOO).")
1083 (defun mdw-good-url-browser ()
1084 "Return a good URL browser.
1085 Trundle the list of such things, finding the first item for which
1086 CHECK is fboundp, and returning the correponding FUNC."
1087 (let ((bs mdw-good-url-browsers) b check func answer)
1088 (while (and bs (not answer))
1092 (setq check (car b) func (cdr b))
1093 (setq check b func b))
1095 (setq answer func)))
1098 (eval-after-load "w3m-search"
1102 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
1103 ("gd" "Google Directory"
1104 "http://www.google.com/search?cat=gwd/Top&q=%s")
1105 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
1106 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
1107 ("gi" "Images" "http://images.google.com/images?q=%s")
1109 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
1111 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
1112 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
1113 ("nc-wiki" "nCipher wiki"
1114 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
1115 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
1116 ("lp" "Launchpad bug by number"
1117 "https://bugs.launchpad.net/bugs/%s")
1118 ("lppkg" "Launchpad bugs by package"
1119 "https://bugs.launchpad.net/%s")
1121 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
1122 ("debbug" "Debian bug by number"
1123 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
1124 ("debbugpkg" "Debian bugs by package"
1125 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
1126 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
1127 (add-to-list 'w3m-search-engine-alist
1128 (list (cadr item) (caddr item) nil))
1129 (add-to-list 'w3m-uri-replace-alist
1130 (list (concat "\\`" (car item) ":")
1131 'w3m-search-uri-replace
1134 ;;;--------------------------------------------------------------------------
1135 ;;; Paragraph filling.
1137 ;; Useful variables.
1139 (defvar mdw-fill-prefix nil
1140 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
1141 If there's no fill prefix currently set (by the `fill-prefix'
1142 variable) and there's a match from one of the regexps here, it
1143 gets used to set the fill-prefix for the current operation.
1145 The variable is a list of items of the form `REGEXP . PREFIX'; if
1146 the REGEXP matches, the PREFIX is used to set the fill prefix.
1147 It in turn is a list of things:
1149 STRING -- insert a literal string
1150 (match . N) -- insert the thing matched by bracketed subexpression N
1151 (pad . N) -- a string of whitespace the same width as subexpression N
1152 (expr . FORM) -- the result of evaluating FORM")
1154 (make-variable-buffer-local 'mdw-fill-prefix)
1156 (defvar mdw-hanging-indents
1158 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
1161 "*Standard regexp matching parts of a hanging indent.
1162 This is mainly useful in `auto-fill-mode'.")
1164 ;; Utility functions.
1166 (defun mdw-maybe-tabify (s)
1167 "Tabify or untabify the string S, according to `indent-tabs-mode'."
1168 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
1172 (let ((start (point-min)) (end (point-max)))
1173 (funcall tabfun (point-min) (point-max))
1174 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
1176 (defun mdw-examine-fill-prefixes (l)
1177 "Given a list of dynamic fill prefixes, pick one which matches
1178 context and return the static fill prefix to use. Point must be
1179 at the start of a line, and match data must be saved."
1181 ((looking-at (car (car l)))
1182 (mdw-maybe-tabify (apply #'concat
1183 (mapcar #'mdw-do-prefix-match
1185 (t (mdw-examine-fill-prefixes (cdr l)))))
1187 (defun mdw-maybe-car (p)
1188 "If P is a pair, return (car P), otherwise just return P."
1189 (if (consp p) (car p) p))
1191 (defun mdw-padding (s)
1192 "Return a string the same width as S but made entirely from whitespace."
1193 (let* ((l (length s)) (i 0) (n (make-string l ? )))
1195 (if (= 9 (aref s i))
1200 (defun mdw-do-prefix-match (m)
1201 "Expand a dynamic prefix match element.
1202 See `mdw-fill-prefix' for details."
1203 (cond ((not (consp m)) (format "%s" m))
1204 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
1205 ((eq (car m) 'pad) (mdw-padding (match-string
1206 (mdw-maybe-car (cdr m)))))
1207 ((eq (car m) 'eval) (eval (cdr m)))
1210 (defun mdw-choose-dynamic-fill-prefix ()
1211 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
1212 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
1213 ((not mdw-fill-prefix) fill-prefix)
1217 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
1219 (defadvice do-auto-fill (around mdw-dynamic-fill-prefix () activate compile)
1220 "Handle auto-filling, working out a dynamic fill prefix in the
1221 case where there isn't a sensible static one."
1222 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1225 (defun mdw-fill-paragraph ()
1226 "Fill paragraph, getting a dynamic fill prefix."
1228 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1229 (fill-paragraph nil)))
1231 (defun mdw-standard-fill-prefix (rx &optional mat)
1232 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
1233 This is just a short-cut for setting the thing by hand, and by
1234 design it doesn't cope with anything approximating a complicated
1236 (setq mdw-fill-prefix
1237 `((,(concat rx mdw-hanging-indents)
1239 (pad . ,(or mat 2))))))
1241 ;;;--------------------------------------------------------------------------
1242 ;;; Other common declarations.
1244 ;; Common mode settings.
1246 (defvar mdw-auto-indent t
1247 "Whether to indent automatically after a newline.")
1249 (defun mdw-whitespace-mode (&optional arg)
1250 "Turn on/off whitespace mode, but don't highlight trailing space."
1252 (when (and (boundp 'whitespace-style)
1253 (fboundp 'whitespace-mode))
1254 (let ((whitespace-style (remove 'trailing whitespace-style)))
1255 (whitespace-mode arg))
1256 (setq show-trailing-whitespace whitespace-mode)))
1258 (defvar mdw-do-misc-mode-hacking nil)
1260 (defun mdw-misc-mode-config ()
1261 (and mdw-auto-indent
1262 (cond ((eq major-mode 'lisp-mode)
1263 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
1264 ((derived-mode-p 'slime-repl-mode 'asm-mode 'comint-mode)
1267 (local-set-key "\C-m" 'newline-and-indent))))
1268 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
1269 (local-set-key [C-return] 'newline)
1270 (make-local-variable 'page-delimiter)
1271 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
1272 (setq comment-column 40)
1274 (setq fill-column mdw-text-width)
1275 (and (fboundp 'gtags-mode)
1277 (if (fboundp 'hs-minor-mode)
1278 (trap (hs-minor-mode t))
1279 (outline-minor-mode t))
1281 (trap (turn-on-font-lock)))
1283 (defun mdw-post-local-vars-misc-mode-config ()
1284 (setq whitespace-line-column mdw-text-width)
1285 (when (and mdw-do-misc-mode-hacking
1286 (not buffer-read-only))
1287 (setq show-trailing-whitespace t)
1288 (mdw-whitespace-mode 1)))
1289 (add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
1291 (defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1292 `(progn ,@(mapcar (lambda (func)
1294 (after mdw-angry-fruit-salad activate)
1295 (when mdw-do-misc-mode-hacking
1296 (setq show-trailing-whitespace
1297 (not buffer-read-only))
1298 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1300 (mdw-advise-update-angry-fruit-salad toggle-read-only
1306 (eval-after-load 'gtags
1308 (dolist (key '([mouse-2] [mouse-3]))
1309 (define-key gtags-mode-map key nil))
1310 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1311 (define-key gtags-select-mode-map [C-S-mouse-2]
1312 'gtags-select-tag-by-event)
1313 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1314 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
1316 ;; Backup file handling.
1318 (defvar mdw-backup-disable-regexps nil
1319 "*List of regular expressions: if a file name matches any of
1320 these then the file is not backed up.")
1322 (defun mdw-backup-enable-predicate (name)
1323 "[mdw]'s default backup predicate.
1324 Allows a backup if the standard predicate would allow it, and it
1325 doesn't match any of the regular expressions in
1326 `mdw-backup-disable-regexps'."
1327 (and (normal-backup-enable-predicate name)
1328 (let ((answer t) (list mdw-backup-disable-regexps))
1331 (if (string-match (car list) name)
1333 (setq list (cdr list)))
1335 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
1339 (defun mdw-last-one-out-turn-off-the-lights (frame)
1340 "Disconnect from an X display if this was the last frame on that display."
1341 (let ((frame-display (frame-parameter frame 'display)))
1342 (when (and frame-display
1343 (eq window-system 'x)
1344 (not (some (lambda (fr)
1345 (and (not (eq fr frame))
1346 (string= (frame-parameter fr 'display)
1349 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1350 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1352 ;;;--------------------------------------------------------------------------
1353 ;;; Fullscreen-ness.
1355 (defvar mdw-full-screen-parameters
1356 '((menu-bar-lines . 0)
1357 ;(vertical-scroll-bars . nil)
1359 "Frame parameters to set when making a frame fullscreen.")
1361 (defvar mdw-full-screen-save
1363 "Extra frame parameters to save when setting fullscreen.")
1365 (defun mdw-toggle-full-screen (&optional frame)
1366 "Show the FRAME fullscreen."
1369 (cond ((frame-parameter frame 'fullscreen)
1370 (set-frame-parameter frame 'fullscreen nil)
1371 (modify-frame-parameters
1373 (or (frame-parameter frame 'mdw-full-screen-saved)
1374 (mapcar (lambda (assoc)
1375 (assq (car assoc) default-frame-alist))
1376 mdw-full-screen-parameters))))
1378 (let ((saved (mapcar (lambda (param)
1379 (cons param (frame-parameter frame param)))
1380 (append (mapcar #'car
1381 mdw-full-screen-parameters)
1382 mdw-full-screen-save))))
1383 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1384 (modify-frame-parameters frame mdw-full-screen-parameters)
1385 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1387 ;;;--------------------------------------------------------------------------
1388 ;;; General fontification.
1390 (make-face 'mdw-virgin-face)
1392 (defmacro mdw-define-face (name &rest body)
1393 "Define a face, and make sure it's actually set as the definition."
1397 (copy-face 'mdw-virgin-face ',name)
1398 (defvar ,name ',name)
1399 (put ',name 'face-defface-spec ',body)
1400 (face-spec-set ',name ',body nil)))
1402 (mdw-define-face default
1403 (((type w32)) :family "courier new" :height 85)
1404 (((type x)) :family "6x13" :foundry "trad" :height 130)
1405 (((type color)) :foreground "white" :background "black")
1407 (mdw-define-face fixed-pitch
1408 (((type w32)) :family "courier new" :height 85)
1409 (((type x)) :family "6x13" :foundry "trad" :height 130)
1410 (t :foreground "white" :background "black"))
1411 (mdw-define-face fixed-pitch-serif
1412 (((type w32)) :family "courier new" :height 85 :weight bold)
1413 (((type x)) :family "6x13" :foundry "trad" :height 130 :weight bold)
1414 (t :foreground "white" :background "black" :weight bold))
1415 (if (mdw-emacs-version-p 23)
1416 (mdw-define-face variable-pitch
1417 (((type x)) :family "sans" :height 100))
1418 (mdw-define-face variable-pitch
1419 (((type x)) :family "helvetica" :height 90)))
1420 (mdw-define-face region
1421 (((min-colors 64)) :background "grey30")
1422 (((class color)) :background "blue")
1423 (t :inverse-video t))
1424 (mdw-define-face match
1425 (((class color)) :background "blue")
1426 (t :inverse-video t))
1427 (mdw-define-face mc/cursor-face
1428 (((class color)) :background "red")
1429 (t :inverse-video t))
1430 (mdw-define-face minibuffer-prompt
1432 (mdw-define-face mode-line
1433 (((class color)) :foreground "blue" :background "yellow"
1434 :box (:line-width 1 :style released-button))
1435 (t :inverse-video t))
1436 (mdw-define-face mode-line-inactive
1437 (((class color)) :foreground "yellow" :background "blue"
1438 :box (:line-width 1 :style released-button))
1439 (t :inverse-video t))
1440 (mdw-define-face nobreak-space
1442 (t :inherit escape-glyph :underline t))
1443 (mdw-define-face scroll-bar
1444 (t :foreground "black" :background "lightgrey"))
1445 (mdw-define-face fringe
1446 (t :foreground "yellow"))
1447 (mdw-define-face show-paren-match
1448 (((min-colors 64)) :background "darkgreen")
1449 (((class color)) :background "green")
1451 (mdw-define-face show-paren-mismatch
1452 (((class color)) :background "red")
1453 (t :inverse-video t))
1454 (mdw-define-face highlight
1455 (((min-colors 64)) :background "DarkSeaGreen4")
1456 (((class color)) :background "cyan")
1457 (t :inverse-video t))
1459 (mdw-define-face holiday-face
1460 (t :background "red"))
1461 (mdw-define-face calendar-today-face
1462 (t :foreground "yellow" :weight bold))
1464 (mdw-define-face comint-highlight-prompt
1466 (mdw-define-face comint-highlight-input
1469 (mdw-define-face Man-underline
1470 (((type tty)) :underline t)
1473 (mdw-define-face ido-subdir
1474 (t :foreground "cyan" :weight bold))
1476 (mdw-define-face dired-directory
1477 (t :foreground "cyan" :weight bold))
1478 (mdw-define-face dired-symlink
1479 (t :foreground "cyan"))
1480 (mdw-define-face dired-perm-write
1483 (mdw-define-face trailing-whitespace
1484 (((class color)) :background "red")
1485 (t :inverse-video t))
1486 (mdw-define-face whitespace-line
1487 (((class color)) :background "darkred")
1488 (t :inverse-video t))
1489 (mdw-define-face mdw-punct-face
1490 (((min-colors 64)) :foreground "burlywood2")
1491 (((class color)) :foreground "yellow"))
1492 (mdw-define-face mdw-number-face
1493 (t :foreground "yellow"))
1494 (mdw-define-face mdw-trivial-face)
1495 (mdw-define-face font-lock-function-name-face
1497 (mdw-define-face font-lock-keyword-face
1499 (mdw-define-face font-lock-constant-face
1501 (mdw-define-face font-lock-builtin-face
1503 (mdw-define-face font-lock-type-face
1504 (t :weight bold :slant italic))
1505 (mdw-define-face font-lock-reference-face
1507 (mdw-define-face font-lock-variable-name-face
1509 (mdw-define-face font-lock-comment-delimiter-face
1510 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1511 (((class color)) :foreground "green")
1513 (mdw-define-face font-lock-comment-face
1514 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1515 (((class color)) :foreground "green")
1517 (mdw-define-face font-lock-string-face
1518 (((min-colors 64)) :foreground "SkyBlue1")
1519 (((class color)) :foreground "cyan")
1522 (mdw-define-face message-separator
1523 (t :background "red" :foreground "white" :weight bold))
1524 (mdw-define-face message-cited-text
1525 (default :slant italic)
1526 (((min-colors 64)) :foreground "SkyBlue1")
1527 (((class color)) :foreground "cyan"))
1528 (mdw-define-face message-header-cc
1529 (default :slant italic)
1530 (((min-colors 64)) :foreground "SeaGreen1")
1531 (((class color)) :foreground "green"))
1532 (mdw-define-face message-header-newsgroups
1533 (default :slant italic)
1534 (((min-colors 64)) :foreground "SeaGreen1")
1535 (((class color)) :foreground "green"))
1536 (mdw-define-face message-header-subject
1537 (((min-colors 64)) :foreground "SeaGreen1")
1538 (((class color)) :foreground "green"))
1539 (mdw-define-face message-header-to
1540 (((min-colors 64)) :foreground "SeaGreen1")
1541 (((class color)) :foreground "green"))
1542 (mdw-define-face message-header-xheader
1543 (default :slant italic)
1544 (((min-colors 64)) :foreground "SeaGreen1")
1545 (((class color)) :foreground "green"))
1546 (mdw-define-face message-header-other
1547 (default :slant italic)
1548 (((min-colors 64)) :foreground "SeaGreen1")
1549 (((class color)) :foreground "green"))
1550 (mdw-define-face message-header-name
1551 (default :weight bold)
1552 (((min-colors 64)) :foreground "SeaGreen1")
1553 (((class color)) :foreground "green"))
1555 (mdw-define-face which-func
1558 (mdw-define-face gnus-header-name
1559 (default :weight bold)
1560 (((min-colors 64)) :foreground "SeaGreen1")
1561 (((class color)) :foreground "green"))
1562 (mdw-define-face gnus-header-subject
1563 (((min-colors 64)) :foreground "SeaGreen1")
1564 (((class color)) :foreground "green"))
1565 (mdw-define-face gnus-header-from
1566 (((min-colors 64)) :foreground "SeaGreen1")
1567 (((class color)) :foreground "green"))
1568 (mdw-define-face gnus-header-to
1569 (((min-colors 64)) :foreground "SeaGreen1")
1570 (((class color)) :foreground "green"))
1571 (mdw-define-face gnus-header-content
1572 (default :slant italic)
1573 (((min-colors 64)) :foreground "SeaGreen1")
1574 (((class color)) :foreground "green"))
1576 (mdw-define-face gnus-cite-1
1577 (((min-colors 64)) :foreground "SkyBlue1")
1578 (((class color)) :foreground "cyan"))
1579 (mdw-define-face gnus-cite-2
1580 (((min-colors 64)) :foreground "RoyalBlue2")
1581 (((class color)) :foreground "blue"))
1582 (mdw-define-face gnus-cite-3
1583 (((min-colors 64)) :foreground "MediumOrchid")
1584 (((class color)) :foreground "magenta"))
1585 (mdw-define-face gnus-cite-4
1586 (((min-colors 64)) :foreground "firebrick2")
1587 (((class color)) :foreground "red"))
1588 (mdw-define-face gnus-cite-5
1589 (((min-colors 64)) :foreground "burlywood2")
1590 (((class color)) :foreground "yellow"))
1591 (mdw-define-face gnus-cite-6
1592 (((min-colors 64)) :foreground "SeaGreen1")
1593 (((class color)) :foreground "green"))
1594 (mdw-define-face gnus-cite-7
1595 (((min-colors 64)) :foreground "SlateBlue1")
1596 (((class color)) :foreground "cyan"))
1597 (mdw-define-face gnus-cite-8
1598 (((min-colors 64)) :foreground "RoyalBlue2")
1599 (((class color)) :foreground "blue"))
1600 (mdw-define-face gnus-cite-9
1601 (((min-colors 64)) :foreground "purple2")
1602 (((class color)) :foreground "magenta"))
1603 (mdw-define-face gnus-cite-10
1604 (((min-colors 64)) :foreground "DarkOrange2")
1605 (((class color)) :foreground "red"))
1606 (mdw-define-face gnus-cite-11
1607 (t :foreground "grey"))
1609 (mdw-define-face diff-header
1611 (mdw-define-face diff-index
1613 (mdw-define-face diff-file-header
1615 (mdw-define-face diff-hunk-header
1616 (((min-colors 64)) :foreground "SkyBlue1")
1617 (((class color)) :foreground "cyan"))
1618 (mdw-define-face diff-function
1619 (default :weight bold)
1620 (((min-colors 64)) :foreground "SkyBlue1")
1621 (((class color)) :foreground "cyan"))
1622 (mdw-define-face diff-header
1623 (((min-colors 64)) :background "grey10"))
1624 (mdw-define-face diff-added
1625 (((class color)) :foreground "green"))
1626 (mdw-define-face diff-removed
1627 (((class color)) :foreground "red"))
1628 (mdw-define-face diff-context
1630 (mdw-define-face diff-refine-change
1631 (((min-colors 64)) :background "RoyalBlue4")
1633 (mdw-define-face diff-refine-removed
1634 (((min-colors 64)) :background "#500")
1636 (mdw-define-face diff-refine-added
1637 (((min-colors 64)) :background "#050")
1640 (setq ediff-force-faces t)
1641 (mdw-define-face ediff-current-diff-A
1642 (((min-colors 64)) :background "darkred")
1643 (((class color)) :background "red")
1644 (t :inverse-video t))
1645 (mdw-define-face ediff-fine-diff-A
1646 (((min-colors 64)) :background "red3")
1647 (((class color)) :inverse-video t)
1648 (t :inverse-video nil))
1649 (mdw-define-face ediff-even-diff-A
1650 (((min-colors 64)) :background "#300"))
1651 (mdw-define-face ediff-odd-diff-A
1652 (((min-colors 64)) :background "#300"))
1653 (mdw-define-face ediff-current-diff-B
1654 (((min-colors 64)) :background "darkgreen")
1655 (((class color)) :background "magenta")
1656 (t :inverse-video t))
1657 (mdw-define-face ediff-fine-diff-B
1658 (((min-colors 64)) :background "green4")
1659 (((class color)) :inverse-video t)
1660 (t :inverse-video nil))
1661 (mdw-define-face ediff-even-diff-B
1662 (((min-colors 64)) :background "#020"))
1663 (mdw-define-face ediff-odd-diff-B
1664 (((min-colors 64)) :background "#020"))
1665 (mdw-define-face ediff-current-diff-C
1666 (((min-colors 64)) :background "darkblue")
1667 (((class color)) :background "blue")
1668 (t :inverse-video t))
1669 (mdw-define-face ediff-fine-diff-C
1670 (((min-colors 64)) :background "blue1")
1671 (((class color)) :inverse-video t)
1672 (t :inverse-video nil))
1673 (mdw-define-face ediff-even-diff-C
1674 (((min-colors 64)) :background "#004"))
1675 (mdw-define-face ediff-odd-diff-C
1676 (((min-colors 64)) :background "#004"))
1677 (mdw-define-face ediff-current-diff-Ancestor
1678 (((min-colors 64)) :background "#630")
1679 (((class color)) :background "blue")
1680 (t :inverse-video t))
1681 (mdw-define-face ediff-even-diff-Ancestor
1682 (((min-colors 64)) :background "#320"))
1683 (mdw-define-face ediff-odd-diff-Ancestor
1684 (((min-colors 64)) :background "#320"))
1686 (mdw-define-face magit-hash
1687 (((min-colors 64)) :foreground "grey40")
1688 (((class color)) :foreground "blue"))
1689 (mdw-define-face magit-diff-hunk-heading
1690 (((min-colors 64)) :foreground "grey70" :background "grey25")
1691 (((class color)) :foreground "yellow"))
1692 (mdw-define-face magit-diff-hunk-heading-highlight
1693 (((min-colors 64)) :foreground "grey70" :background "grey35")
1694 (((class color)) :foreground "yellow" :background "blue"))
1695 (mdw-define-face magit-diff-added
1696 (((min-colors 64)) :foreground "#ddffdd" :background "#335533")
1697 (((class color)) :foreground "green"))
1698 (mdw-define-face magit-diff-added-highlight
1699 (((min-colors 64)) :foreground "#cceecc" :background "#336633")
1700 (((class color)) :foreground "green" :background "blue"))
1701 (mdw-define-face magit-diff-removed
1702 (((min-colors 64)) :foreground "#ffdddd" :background "#553333")
1703 (((class color)) :foreground "red"))
1704 (mdw-define-face magit-diff-removed-highlight
1705 (((min-colors 64)) :foreground "#eecccc" :background "#663333")
1706 (((class color)) :foreground "red" :background "blue"))
1707 (mdw-define-face magit-blame-heading
1708 (((min-colors 64)) :foreground "white" :background "grey25"
1709 :weight normal :slant normal)
1710 (((class color)) :foreground "white" :background "blue"
1711 :weight normal :slant normal))
1712 (mdw-define-face magit-blame-name
1713 (t :inherit magit-blame-heading :slant italic))
1714 (mdw-define-face magit-blame-date
1715 (((min-colors 64)) :inherit magit-blame-heading :foreground "grey60")
1716 (((class color)) :inherit magit-blame-heading :foreground "cyan"))
1717 (mdw-define-face magit-blame-summary
1718 (t :inherit magit-blame-heading :weight bold))
1720 (mdw-define-face dylan-header-background
1721 (((min-colors 64)) :background "NavyBlue")
1722 (((class color)) :background "blue"))
1724 (mdw-define-face erc-input-face
1725 (t :foreground "red"))
1727 (mdw-define-face woman-bold
1729 (mdw-define-face woman-italic
1732 (eval-after-load "rst"
1734 (mdw-define-face rst-level-1-face
1735 (t :foreground "SkyBlue1" :weight bold))
1736 (mdw-define-face rst-level-2-face
1737 (t :foreground "SeaGreen1" :weight bold))
1738 (mdw-define-face rst-level-3-face
1740 (mdw-define-face rst-level-4-face
1742 (mdw-define-face rst-level-5-face
1744 (mdw-define-face rst-level-6-face
1747 (mdw-define-face p4-depot-added-face
1748 (t :foreground "green"))
1749 (mdw-define-face p4-depot-branch-op-face
1750 (t :foreground "yellow"))
1751 (mdw-define-face p4-depot-deleted-face
1752 (t :foreground "red"))
1753 (mdw-define-face p4-depot-unmapped-face
1754 (t :foreground "SkyBlue1"))
1755 (mdw-define-face p4-diff-change-face
1756 (t :foreground "yellow"))
1757 (mdw-define-face p4-diff-del-face
1758 (t :foreground "red"))
1759 (mdw-define-face p4-diff-file-face
1760 (t :foreground "SkyBlue1"))
1761 (mdw-define-face p4-diff-head-face
1762 (t :background "grey10"))
1763 (mdw-define-face p4-diff-ins-face
1764 (t :foreground "green"))
1766 (mdw-define-face w3m-anchor-face
1767 (t :foreground "SkyBlue1" :underline t))
1768 (mdw-define-face w3m-arrived-anchor-face
1769 (t :foreground "SkyBlue1" :underline t))
1771 (mdw-define-face whizzy-slice-face
1772 (t :background "grey10"))
1773 (mdw-define-face whizzy-error-face
1774 (t :background "darkred"))
1776 ;; Ellipses used to indicate hidden text (and similar).
1777 (mdw-define-face mdw-ellipsis-face
1778 (((type tty)) :foreground "blue") (t :foreground "grey60"))
1779 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
1780 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
1781 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
1782 (bar (make-glyph-code ?| mdw-ellipsis-face)))
1783 (set-display-table-slot standard-display-table 0 dollar)
1784 (set-display-table-slot standard-display-table 1 backslash)
1785 (set-display-table-slot standard-display-table 4
1786 (vector dot dot dot))
1787 (set-display-table-slot standard-display-table 5 bar))
1789 ;;;--------------------------------------------------------------------------
1792 (mdw-define-face mdw-point-overlay-face
1794 (((min-colors 64)) :background "darkblue")
1795 (((class color)) :background "blue")
1796 (((type tty) (class mono)) :inverse-video t))
1798 (defvar mdw-point-overlay-fringe-display '(vertical-bar . vertical-bar))
1800 (defun mdw-configure-point-overlay ()
1801 (let ((ov (make-overlay 0 0)))
1802 (overlay-put ov 'priority 0)
1803 (let* ((fringe (or mdw-point-overlay-fringe-display (cons nil nil)))
1804 (left (car fringe)) (right (cdr fringe))
1808 (put-text-property 0 1 'display `(left-fringe ,left) ss)
1809 (setq s (concat s ss))))
1812 (put-text-property 0 1 'display `(right-fringe ,right) ss)
1813 (setq s (concat s ss))))
1814 (when (or left right)
1815 (overlay-put ov 'before-string s)))
1816 (overlay-put ov 'face 'mdw-point-overlay-face)
1820 (defvar mdw-point-overlay (mdw-configure-point-overlay)
1821 "An overlay used for showing where point is in the selected window.")
1822 (defun mdw-reconfigure-point-overlay ()
1824 (setq mdw-point-overlay (mdw-configure-point-overlay)))
1826 (defun mdw-remove-point-overlay ()
1827 "Remove the current-point overlay."
1828 (delete-overlay mdw-point-overlay))
1830 (defun mdw-update-point-overlay ()
1831 "Mark the current point position with an overlay."
1832 (if (not mdw-point-overlay-mode)
1833 (mdw-remove-point-overlay)
1834 (overlay-put mdw-point-overlay 'window (selected-window))
1835 (move-overlay mdw-point-overlay
1836 (line-beginning-position)
1837 (+ (line-end-position) 1))))
1839 (defvar mdw-point-overlay-buffers nil
1840 "List of buffers using `mdw-point-overlay-mode'.")
1842 (define-minor-mode mdw-point-overlay-mode
1843 "Indicate current line with an overlay."
1845 (let ((buffer (current-buffer)))
1846 (setq mdw-point-overlay-buffers
1847 (mapcan (lambda (buf)
1848 (if (and (buffer-live-p buf)
1849 (not (eq buf buffer)))
1851 mdw-point-overlay-buffers))
1852 (if mdw-point-overlay-mode
1853 (setq mdw-point-overlay-buffers
1854 (cons buffer mdw-point-overlay-buffers))))
1855 (cond (mdw-point-overlay-buffers
1856 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
1857 (add-hook 'post-command-hook 'mdw-update-point-overlay))
1859 (mdw-remove-point-overlay)
1860 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
1861 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
1863 (define-globalized-minor-mode mdw-global-point-overlay-mode
1864 mdw-point-overlay-mode
1865 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
1867 ;;;--------------------------------------------------------------------------
1868 ;;; C programming configuration.
1870 ;; Make C indentation nice.
1872 (defun mdw-c-lineup-arglist (langelem)
1873 "Hack for DWIMmery in c-lineup-arglist."
1875 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1877 (c-lineup-arglist langelem)))
1879 (defun mdw-c-indent-extern-mumble (langelem)
1880 "Indent `extern \"...\" {' lines."
1882 (back-to-indentation)
1884 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1888 (defun mdw-c-indent-arglist-nested (langelem)
1889 "Indent continued argument lists.
1890 If we've nested more than one argument list, then only introduce a single
1891 indentation anyway."
1892 (let ((context c-syntactic-context)
1893 (pos (c-langelem-2nd-pos c-syntactic-element))
1894 (should-indent-p t))
1896 (eq (caar context) 'arglist-cont-nonempty))
1897 (when (and (= (caddr (pop context)) pos)
1899 (memq (caar context) '(arglist-intro
1900 arglist-cont-nonempty)))
1901 (setq should-indent-p nil)))
1902 (if should-indent-p '+ 0)))
1904 (defvar mdw-define-c-styles-hook nil
1905 "Hook run when `cc-mode' starts up to define styles.")
1907 (defmacro mdw-define-c-style (name &rest assocs)
1908 "Define a C style, called NAME (a symbol), setting ASSOCs.
1909 A function, named `mdw-define-c-style/NAME', is defined to actually install
1910 the style using `c-add-style', and added to the hook
1911 `mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
1913 (declare (indent defun))
1914 (let* ((name-string (symbol-name name))
1915 (func (intern (concat "mdw-define-c-style/" name-string))))
1917 (defun ,func () (c-add-style ,name-string ',assocs))
1918 (and (featurep 'cc-mode) (,func))
1919 (add-hook 'mdw-define-c-styles-hook ',func))))
1921 (eval-after-load "cc-mode"
1922 '(run-hooks 'mdw-define-c-styles-hook))
1924 (mdw-define-c-style mdw-trustonic-c
1925 (c-basic-offset . 4)
1926 (comment-column . 0)
1927 (c-indent-comment-alist (anchored-comment . (column . 0))
1928 (end-block . (space . 1))
1929 (cpp-end-block . (space . 1))
1930 (other . (space . 1)))
1931 (c-class-key . "class")
1932 (c-backslash-column . 0)
1933 (c-auto-align-backslashes . nil)
1934 (c-label-minimum-indentation . 0)
1935 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1936 (defun-open . (add 0 c-indent-one-line-block))
1937 (arglist-cont-nonempty . mdw-c-indent-arglist-nested)
1938 (topmost-intro . mdw-c-indent-extern-mumble)
1939 (cpp-define-intro . 0)
1941 (inextern-lang . [0])
1947 (statement-cont . +)
1948 (statement-case-intro . +)))
1950 (mdw-define-c-style mdw-c
1951 (c-basic-offset . 2)
1952 (comment-column . 40)
1953 (c-class-key . "class")
1954 (c-backslash-column . 72)
1955 (c-label-minimum-indentation . 0)
1956 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1957 (defun-open . (add 0 c-indent-one-line-block))
1958 (arglist-cont-nonempty . mdw-c-lineup-arglist)
1959 (topmost-intro . mdw-c-indent-extern-mumble)
1960 (cpp-define-intro . 0)
1962 (inextern-lang . [0])
1968 (statement-cont . +)
1969 (statement-case-intro . +)))
1971 (defun mdw-set-default-c-style (modes style)
1972 "Update the default CC Mode style for MODES to be STYLE.
1974 MODES may be a list of major mode names or a singleton. STYLE is a style
1976 (let ((modes (if (listp modes) modes (list modes)))
1977 (style (symbol-name style)))
1978 (setq c-default-style
1979 (append (mapcar (lambda (mode)
1982 (remove-if (lambda (assoc)
1983 (memq (car assoc) modes))
1984 (if (listp c-default-style)
1986 (list (cons 'other c-default-style))))))))
1987 (setq c-default-style "mdw-c")
1989 (mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
1991 (defvar mdw-c-comment-fill-prefix
1992 `((,(concat "\\([ \t]*/?\\)"
1995 "\\([A-Za-z]+:[ \t]*\\)?"
1996 mdw-hanging-indents)
1997 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1998 "Fill prefix matching C comments (both kinds).")
2000 (defun mdw-fontify-c-and-c++ ()
2002 ;; Fiddle with some syntax codes.
2003 (modify-syntax-entry ?* ". 23")
2004 (modify-syntax-entry ?/ ". 124b")
2005 (modify-syntax-entry ?\n "> b")
2008 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2010 ;; Now define things to be fontified.
2011 (make-local-variable 'font-lock-keywords)
2013 (mdw-regexps "alignas" ;C11 macro, C++11
2015 "and" ;C++, C95 macro
2016 "and_eq" ;C++, C95 macro
2017 "asm" ;K&R, C++, GCC
2018 "atomic" ;C11 macro, C++11 template type
2020 "bitand" ;C++, C95 macro
2021 "bitor" ;C++, C95 macro
2022 "bool" ;C++, C99 macro
2027 "char16_t" ;C++11, C11 library type
2028 "char32_t" ;C++11, C11 library type
2030 "complex" ;C99 macro, C++ template type
2031 "compl" ;C++, C95 macro
2035 "continue" ;K&R, C89
2037 "defined" ;C89 preprocessor
2044 ;; "entry" ;K&R -- never used
2055 "imaginary" ;C99 macro
2056 "inline" ;C++, C99, GCC
2063 "noreturn" ;C11 macro
2064 "not" ;C++, C95 macro
2065 "not_eq" ;C++, C95 macro
2068 "or" ;C++, C95 macro
2069 "or_eq" ;C++, C95 macro
2073 "register" ;K&R, C89
2074 "reinterpret_cast" ;C++
2081 "static_assert" ;C11 macro, C++11
2088 "thread_local" ;C11 macro, C++11
2094 "unsigned" ;K&R, C89
2099 "wchar_t" ;C++, C89 library type
2101 "xor" ;C++, C95 macro
2102 "xor_eq" ;C++, C95 macro
2111 "_Pragma" ;C99 preprocessor
2112 "_Static_assert" ;C11
2113 "_Thread_local" ;C11
2116 "__attribute__" ;GCC
2119 "__extension__" ;GCC
2129 (mdw-regexps "false" ;C++, C99 macro
2131 "true" ;C++, C99 macro
2133 (preprocessor-keywords
2134 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2135 "ident" "if" "ifdef" "ifndef" "import" "include"
2136 "line" "pragma" "unassert" "undef" "warning"))
2138 (mdw-regexps "class" "defs" "encode" "end" "implementation"
2139 "interface" "private" "protected" "protocol" "public"
2142 (setq font-lock-keywords
2145 ;; Fontify include files as strings.
2146 (list (concat "^[ \t]*\\#[ \t]*"
2147 "\\(include\\|import\\)"
2148 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2149 '(2 font-lock-string-face))
2151 ;; Preprocessor directives are `references'?.
2152 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2153 preprocessor-keywords
2154 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2155 '(1 font-lock-keyword-face))
2157 ;; Handle the keywords defined above.
2158 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
2159 '(0 font-lock-keyword-face))
2161 (list (concat "\\<\\(" c-keywords "\\)\\>")
2162 '(0 font-lock-keyword-face))
2164 (list (concat "\\<\\(" c-builtins "\\)\\>")
2165 '(0 font-lock-variable-name-face))
2167 ;; Handle numbers too.
2169 ;; This looks strange, I know. It corresponds to the
2170 ;; preprocessor's idea of what a number looks like, rather than
2171 ;; anything sensible.
2172 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2173 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2174 '(0 mdw-number-face))
2176 ;; And anything else is punctuation.
2177 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2178 '(0 mdw-punct-face))))))
2180 (define-derived-mode sod-mode c-mode "Sod"
2181 "Major mode for editing Sod code.")
2182 (push '("\\.sod$" . sod-mode) auto-mode-alist)
2184 (dolist (hook '(c-mode-hook objc-mode-hook c++-mode-hook))
2185 (add-hook hook 'mdw-misc-mode-config t)
2186 (add-hook hook 'mdw-fontify-c-and-c++ t))
2188 ;;;--------------------------------------------------------------------------
2191 (define-derived-mode apcalc-mode c-mode "AP Calc"
2192 "Major mode for editing Calc code.")
2194 (defun mdw-fontify-apcalc ()
2196 ;; Fiddle with some syntax codes.
2197 (modify-syntax-entry ?* ". 23")
2198 (modify-syntax-entry ?/ ". 14")
2201 (setq comment-start "/* ")
2202 (setq comment-end " */")
2203 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2205 ;; Now define things to be fontified.
2206 (make-local-variable 'font-lock-keywords)
2208 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
2209 "do" "else" "exit" "for" "global" "goto" "help" "if"
2210 "local" "mat" "obj" "print" "quit" "read" "return"
2211 "show" "static" "switch" "while" "write")))
2213 (setq font-lock-keywords
2216 ;; Handle the keywords defined above.
2217 (list (concat "\\<\\(" c-keywords "\\)\\>")
2218 '(0 font-lock-keyword-face))
2220 ;; Handle numbers too.
2222 ;; This looks strange, I know. It corresponds to the
2223 ;; preprocessor's idea of what a number looks like, rather than
2224 ;; anything sensible.
2225 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2226 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2227 '(0 mdw-number-face))
2229 ;; And anything else is punctuation.
2230 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2231 '(0 mdw-punct-face))))))
2234 (add-hook 'apcalc-mode-hook 'mdw-misc-mode-config t)
2235 (add-hook 'apcalc-mode-hook 'mdw-fontify-apcalc t))
2237 ;;;--------------------------------------------------------------------------
2238 ;;; Java programming configuration.
2240 ;; Make indentation nice.
2242 (mdw-define-c-style mdw-java
2243 (c-basic-offset . 2)
2244 (c-backslash-column . 72)
2245 (c-offsets-alist (substatement-open . 0)
2250 (statement-case-intro . +)))
2251 (mdw-set-default-c-style 'java-mode 'mdw-java)
2253 ;; Declare Java fontification style.
2255 (defun mdw-fontify-java ()
2257 ;; Fiddle with some syntax codes.
2258 (modify-syntax-entry ?@ ".")
2259 (modify-syntax-entry ?@ "." font-lock-syntax-table)
2262 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2264 ;; Now define things to be fontified.
2265 (make-local-variable 'font-lock-keywords)
2266 (let ((java-keywords
2267 (mdw-regexps "abstract" "assert"
2268 "boolean" "break" "byte"
2269 "case" "catch" "char" "class" "const" "continue"
2270 "default" "do" "double"
2271 "else" "enum" "extends"
2272 "final" "finally" "float" "for"
2274 "if" "implements" "import" "instanceof" "int"
2278 "package" "private" "protected" "public"
2280 "short" "static" "strictfp" "switch" "synchronized"
2281 "throw" "throws" "transient" "try"
2286 (mdw-regexps "false" "null" "super" "this" "true")))
2288 (setq font-lock-keywords
2291 ;; Handle the keywords defined above.
2292 (list (concat "\\<\\(" java-keywords "\\)\\>")
2293 '(0 font-lock-keyword-face))
2295 ;; Handle the magic builtins defined above.
2296 (list (concat "\\<\\(" java-builtins "\\)\\>")
2297 '(0 font-lock-variable-name-face))
2299 ;; Handle numbers too.
2301 ;; The following isn't quite right, but it's close enough.
2302 (list (concat "\\<\\("
2303 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2304 "[0-9]+\\(\\.[0-9]*\\|\\)"
2305 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2307 '(0 mdw-number-face))
2309 ;; And anything else is punctuation.
2310 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2311 '(0 mdw-punct-face))))))
2314 (add-hook 'java-mode-hook 'mdw-misc-mode-config t)
2315 (add-hook 'java-mode-hook 'mdw-fontify-java t))
2317 ;;;--------------------------------------------------------------------------
2318 ;;; Javascript programming configuration.
2320 (defun mdw-javascript-style ()
2321 (setq js-indent-level 2)
2322 (setq js-expr-indent-offset 0))
2324 (defun mdw-fontify-javascript ()
2327 (mdw-javascript-style)
2328 (setq js-auto-indent-flag t)
2330 ;; Now define things to be fontified.
2331 (make-local-variable 'font-lock-keywords)
2332 (let ((javascript-keywords
2333 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
2334 "char" "class" "const" "continue" "debugger" "default"
2335 "delete" "do" "double" "else" "enum" "export" "extends"
2336 "final" "finally" "float" "for" "function" "goto" "if"
2337 "implements" "import" "in" "instanceof" "int"
2338 "interface" "let" "long" "native" "new" "package"
2339 "private" "protected" "public" "return" "short"
2340 "static" "super" "switch" "synchronized" "throw"
2341 "throws" "transient" "try" "typeof" "var" "void"
2342 "volatile" "while" "with" "yield"))
2343 (javascript-builtins
2344 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
2345 "arguments" "this")))
2347 (setq font-lock-keywords
2350 ;; Handle the keywords defined above.
2351 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
2352 '(0 font-lock-keyword-face))
2354 ;; Handle the predefined builtins defined above.
2355 (list (concat "\\_<\\(" javascript-builtins "\\)\\_>")
2356 '(0 font-lock-variable-name-face))
2358 ;; Handle numbers too.
2360 ;; The following isn't quite right, but it's close enough.
2361 (list (concat "\\_<\\("
2362 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2363 "[0-9]+\\(\\.[0-9]*\\|\\)"
2364 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2366 '(0 mdw-number-face))
2368 ;; And anything else is punctuation.
2369 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2370 '(0 mdw-punct-face))))))
2373 (add-hook 'js-mode-hook 'mdw-misc-mode-config t)
2374 (add-hook 'js-mode-hook 'mdw-fontify-javascript t))
2376 ;;;--------------------------------------------------------------------------
2377 ;;; Scala programming configuration.
2379 (defun mdw-fontify-scala ()
2382 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2384 ;; Define things to be fontified.
2385 (make-local-variable 'font-lock-keywords)
2386 (let ((scala-keywords
2387 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
2388 "extends" "final" "finally" "for" "forSome" "if"
2389 "implicit" "import" "lazy" "match" "new" "object"
2390 "override" "package" "private" "protected" "return"
2391 "sealed" "throw" "trait" "try" "type" "val"
2392 "var" "while" "with" "yield"))
2394 (mdw-regexps "false" "null" "super" "this" "true"))
2395 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
2397 (setq font-lock-keywords
2400 ;; Magical identifiers between backticks.
2401 (list (concat "`\\([^`]+\\)`")
2402 '(1 font-lock-variable-name-face))
2404 ;; Handle the keywords defined above.
2405 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
2406 '(0 font-lock-keyword-face))
2408 ;; Handle the constants defined above.
2409 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
2410 '(0 font-lock-variable-name-face))
2412 ;; Magical identifiers between backticks.
2413 (list (concat "`\\([^`]+\\)`")
2414 '(1 font-lock-variable-name-face))
2416 ;; Handle numbers too.
2418 ;; As usual, not quite right.
2419 (list (concat "\\_<\\("
2420 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2421 "[0-9]+\\(\\.[0-9]*\\|\\)"
2422 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2424 '(0 mdw-number-face))
2426 ;; And everything else is punctuation.
2427 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2428 '(0 mdw-punct-face)))
2430 font-lock-syntactic-keywords
2433 ;; Single quotes around characters. But not when used to quote
2434 ;; symbol names. Ugh.
2435 (list (concat "\\('\\)"
2437 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
2438 "u+" "[0-9a-fA-F]\\{4\\}"
2439 "\\|" "\\\\" "[0-7]\\{1,3\\}"
2440 "\\|" "\\\\" "." "\\)"
2446 (add-hook 'scala-mode-hook 'mdw-misc-mode-config t)
2447 (add-hook 'scala-mode-hook 'mdw-fontify-scala t))
2449 ;;;--------------------------------------------------------------------------
2450 ;;; C# programming configuration.
2452 ;; Make indentation nice.
2454 (mdw-define-c-style mdw-csharp
2455 (c-basic-offset . 2)
2456 (c-backslash-column . 72)
2457 (c-offsets-alist (substatement-open . 0)
2462 (statement-case-intro . +)))
2463 (mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
2465 ;; Declare C# fontification style.
2467 (defun mdw-fontify-csharp ()
2470 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2472 ;; Now define things to be fontified.
2473 (make-local-variable 'font-lock-keywords)
2474 (let ((csharp-keywords
2475 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
2476 "char" "checked" "class" "const" "continue" "decimal"
2477 "default" "delegate" "do" "double" "else" "enum"
2478 "event" "explicit" "extern" "finally" "fixed" "float"
2479 "for" "foreach" "goto" "if" "implicit" "in" "int"
2480 "interface" "internal" "is" "lock" "long" "namespace"
2481 "new" "object" "operator" "out" "override" "params"
2482 "private" "protected" "public" "readonly" "ref"
2483 "return" "sbyte" "sealed" "short" "sizeof"
2484 "stackalloc" "static" "string" "struct" "switch"
2485 "throw" "try" "typeof" "uint" "ulong" "unchecked"
2486 "unsafe" "ushort" "using" "virtual" "void" "volatile"
2490 (mdw-regexps "base" "false" "null" "this" "true")))
2492 (setq font-lock-keywords
2495 ;; Handle the keywords defined above.
2496 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
2497 '(0 font-lock-keyword-face))
2499 ;; Handle the magic builtins defined above.
2500 (list (concat "\\<\\(" csharp-builtins "\\)\\>")
2501 '(0 font-lock-variable-name-face))
2503 ;; Handle numbers too.
2505 ;; The following isn't quite right, but it's close enough.
2506 (list (concat "\\<\\("
2507 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2508 "[0-9]+\\(\\.[0-9]*\\|\\)"
2509 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2511 '(0 mdw-number-face))
2513 ;; And anything else is punctuation.
2514 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2515 '(0 mdw-punct-face))))))
2517 (define-derived-mode csharp-mode java-mode "C#"
2518 "Major mode for editing C# code.")
2520 (add-hook 'csharp-mode-hook 'mdw-fontify-csharp t)
2522 ;;;--------------------------------------------------------------------------
2523 ;;; F# programming configuration.
2525 (setq fsharp-indent-offset 2)
2527 (defun mdw-fontify-fsharp ()
2529 (let ((punct "=<>+-*/|&%!@?"))
2531 ((>= i (length punct)))
2532 (modify-syntax-entry (aref punct i) ".")))
2534 (modify-syntax-entry ?_ "_")
2535 (modify-syntax-entry ?( "(")
2536 (modify-syntax-entry ?) ")")
2538 (setq indent-tabs-mode nil)
2540 (let ((fsharp-keywords
2541 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
2543 "checked" "class" "component" "const" "constraint"
2544 "constructor" "continue"
2545 "default" "delegate" "do" "done" "downcast" "downto"
2546 "eager" "elif" "else" "end" "exception" "extern"
2547 "finally" "fixed" "for" "fori" "fun" "function"
2550 "if" "in" "include" "inherit" "inline" "interface"
2553 "match" "measure" "member" "method" "mixin" "module"
2556 "object" "of" "open" "or" "override"
2557 "parallel" "params" "private" "process" "protected"
2559 "rec" "recursive" "return"
2560 "sealed" "sig" "static" "struct"
2561 "tailcall" "then" "to" "trait" "try" "type"
2563 "val" "virtual" "void" "volatile"
2564 "when" "while" "with"
2568 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
2569 "base" "false" "null" "true"))
2572 (mdw-regexps "do" "let" "return" "use" "yield"))
2574 (preprocessor-keywords
2575 (mdw-regexps "if" "indent" "else" "endif")))
2577 (setq font-lock-keywords
2578 (list (list (concat "\\(^\\|[^\"]\\)"
2581 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
2586 '(2 font-lock-comment-face))
2588 (list (concat "'" "\\("
2591 "\\|" "[0-9][0-9][0-9]"
2592 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
2593 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
2599 "\\(" "\\\\" "\\(.\\|\n\\)"
2602 '(0 font-lock-string-face))
2604 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
2605 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
2607 "\\_<\\(" fsharp-keywords "\\)\\_>")
2608 '(0 font-lock-keyword-face))
2609 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
2610 '(0 font-lock-variable-name-face))
2612 (list (concat "\\_<"
2613 "\\(" "0[bB][01]+" "\\|"
2615 "0[xX][0-9a-fA-F]+" "\\)"
2616 "\\(" "lf\\|LF" "\\|"
2617 "[uU]?[ysnlL]?" "\\)"
2624 "\\([eE][-+]?[0-9]+\\)?"
2629 '(0 mdw-number-face))
2631 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2632 '(0 mdw-punct-face))))))
2634 (defun mdw-fontify-inferior-fsharp ()
2635 (mdw-fontify-fsharp)
2636 (setq font-lock-keywords
2637 (append (list (list "^[#-]" '(0 font-lock-comment-face))
2638 (list "^>" '(0 font-lock-keyword-face)))
2639 font-lock-keywords)))
2642 (add-hook 'fsharp-mode-hook 'mdw-misc-mode-config t)
2643 (add-hook 'fsharp-mode-hook 'mdw-fontify-fsharp t)
2644 (add-hook 'inferior-fsharp-mode-hooks 'mdw-fontify-inferior-fsharp t))
2646 ;;;--------------------------------------------------------------------------
2647 ;;; Go programming configuration.
2649 (defun mdw-fontify-go ()
2651 (make-local-variable 'font-lock-keywords)
2653 (mdw-regexps "break" "case" "chan" "const" "continue"
2654 "default" "defer" "else" "fallthrough" "for"
2655 "func" "go" "goto" "if" "import"
2656 "interface" "map" "package" "range" "return"
2657 "select" "struct" "switch" "type" "var"))
2659 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
2660 "float32" "float64" "int" "uint8" "int16" "int32"
2661 "int64" "rune" "string" "uint" "uint8" "uint16"
2662 "uint32" "uint64" "uintptr" "void"
2663 "false" "iota" "nil" "true"
2665 "append" "cap" "copy" "delete" "imag" "len" "make"
2666 "new" "panic" "real" "recover")))
2668 (setq font-lock-keywords
2671 ;; Handle the keywords defined above.
2672 (list (concat "\\<\\(" go-keywords "\\)\\>")
2673 '(0 font-lock-keyword-face))
2674 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
2675 '(0 font-lock-variable-name-face))
2677 ;; Strings and characters.
2679 "\\(" "[^\\']" "\\|"
2681 "\\(" "[abfnrtv\\'\"]" "\\|"
2682 "[0-7]\\{3\\}" "\\|"
2683 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
2684 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
2685 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
2689 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
2693 '(0 font-lock-string-face))
2695 ;; Handle numbers too.
2697 ;; The following isn't quite right, but it's close enough.
2698 (list (concat "\\<\\("
2699 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2700 "[0-9]+\\(\\.[0-9]*\\|\\)"
2701 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
2702 '(0 mdw-number-face))
2704 ;; And anything else is punctuation.
2705 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2706 '(0 mdw-punct-face))))))
2708 (add-hook 'go-mode-hook 'mdw-misc-mode-config t)
2709 (add-hook 'go-mode-hook 'mdw-fontify-go t))
2711 ;;;--------------------------------------------------------------------------
2712 ;;; Rust programming configuration.
2714 (setq-default rust-indent-offset 2)
2716 (defun mdw-self-insert-and-indent (count)
2718 (self-insert-command count)
2719 (indent-according-to-mode))
2721 (defun mdw-fontify-rust ()
2723 ;; Hack syntax categories.
2724 (modify-syntax-entry ?$ ".")
2725 (modify-syntax-entry ?% ".")
2726 (modify-syntax-entry ?= ".")
2728 ;; Fontify keywords and things.
2729 (make-local-variable 'font-lock-keywords)
2730 (let ((rust-keywords
2731 (mdw-regexps "abstract" "alignof" "as" "async" "await"
2732 "become" "box" "break"
2733 "const" "continue" "crate"
2735 "else" "enum" "extern"
2739 "macro" "match" "mod" "move" "mut"
2740 "offsetof" "override"
2741 "priv" "proc" "pub" "pure"
2743 "sizeof" "static" "struct" "super"
2744 "trait" "try" "type" "typeof"
2745 "union" "unsafe" "unsized" "use"
2750 (mdw-regexps "array" "pointer" "slice" "tuple"
2751 "bool" "true" "false"
2753 "i8" "i16" "i32" "i64" "isize"
2754 "u8" "u16" "u32" "u64" "usize"
2757 (setq font-lock-keywords
2760 ;; Handle the keywords defined above.
2761 (list (concat "\\_<\\(" rust-keywords "\\)\\_>")
2762 '(0 font-lock-keyword-face))
2763 (list (concat "\\_<\\(" rust-builtins "\\)\\_>")
2764 '(0 font-lock-variable-name-face))
2766 ;; Handle numbers too.
2767 (list (concat "\\_<\\("
2769 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
2773 "\\|" "\\(" "[0-9][0-9_]*"
2774 "\\|" "0x[0-9a-fA-F_]+"
2778 "\\([ui]\\(8\\|16\\|32\\|64\\|size\\)\\)?"
2780 '(0 mdw-number-face))
2782 ;; And anything else is punctuation.
2783 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2784 '(0 mdw-punct-face)))))
2786 ;; Hack key bindings.
2787 (local-set-key [?{] 'mdw-self-insert-and-indent)
2788 (local-set-key [?}] 'mdw-self-insert-and-indent))
2791 (add-hook 'rust-mode-hook 'mdw-misc-mode-config t)
2792 (add-hook 'rust-mode-hook 'mdw-fontify-rust t))
2794 ;;;--------------------------------------------------------------------------
2795 ;;; Awk programming configuration.
2797 ;; Make Awk indentation nice.
2799 (mdw-define-c-style mdw-awk
2800 (c-basic-offset . 2)
2801 (c-offsets-alist (substatement-open . 0)
2802 (c-backslash-column . 72)
2803 (statement-cont . 0)
2804 (statement-case-intro . +)))
2805 (mdw-set-default-c-style 'awk-mode 'mdw-awk)
2807 ;; Declare Awk fontification style.
2809 (defun mdw-fontify-awk ()
2811 ;; Miscellaneous fiddling.
2812 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2814 ;; Now define things to be fontified.
2815 (make-local-variable 'font-lock-keywords)
2817 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
2818 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
2819 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
2820 "RSTART" "RLENGTH" "RT" "SUBSEP"
2821 "atan2" "break" "close" "continue" "cos" "delete"
2822 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
2823 "function" "gensub" "getline" "gsub" "if" "in"
2824 "index" "int" "length" "log" "match" "next" "rand"
2825 "return" "print" "printf" "sin" "split" "sprintf"
2826 "sqrt" "srand" "strftime" "sub" "substr" "system"
2827 "systime" "tolower" "toupper" "while")))
2829 (setq font-lock-keywords
2832 ;; Handle the keywords defined above.
2833 (list (concat "\\<\\(" c-keywords "\\)\\>")
2834 '(0 font-lock-keyword-face))
2836 ;; Handle numbers too.
2838 ;; The following isn't quite right, but it's close enough.
2839 (list (concat "\\<\\("
2840 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2841 "[0-9]+\\(\\.[0-9]*\\|\\)"
2842 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2844 '(0 mdw-number-face))
2846 ;; And anything else is punctuation.
2847 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2848 '(0 mdw-punct-face))))))
2851 (add-hook 'awk-mode-hook 'mdw-misc-mode-config t)
2852 (add-hook 'awk-mode-hook 'mdw-fontify-awk t))
2854 ;;;--------------------------------------------------------------------------
2855 ;;; Perl programming style.
2857 ;; Perl indentation style.
2859 (setq-default perl-indent-level 2)
2861 (setq-default cperl-indent-level 2
2862 cperl-continued-statement-offset 2
2863 cperl-continued-brace-offset 0
2864 cperl-brace-offset -2
2865 cperl-brace-imaginary-offset 0
2866 cperl-label-offset 0)
2868 ;; Define perl fontification style.
2870 (defun mdw-fontify-perl ()
2872 ;; Miscellaneous fiddling.
2873 (modify-syntax-entry ?$ "\\")
2874 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
2875 (modify-syntax-entry ?: "." font-lock-syntax-table)
2876 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2878 ;; Now define fontification things.
2879 (make-local-variable 'font-lock-keywords)
2880 (let ((perl-keywords
2887 "ge" "given" "gt" "goto"
2889 "last" "le" "local" "lt"
2894 "redo" "require" "return"
2896 "undef" "unless" "until" "use"
2899 (setq font-lock-keywords
2902 ;; Set up the keywords defined above.
2903 (list (concat "\\<\\(" perl-keywords "\\)\\>")
2904 '(0 font-lock-keyword-face))
2906 ;; At least numbers are simpler than C.
2907 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2908 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2909 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2910 '(0 mdw-number-face))
2912 ;; And anything else is punctuation.
2913 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2914 '(0 mdw-punct-face))))))
2916 (defun perl-number-tests (&optional arg)
2917 "Assign consecutive numbers to lines containing `#t'. With ARG,
2918 strip numbers instead."
2921 (goto-char (point-min))
2922 (let ((i 0) (fmt (if arg "" " %4d")))
2923 (while (search-forward "#t" nil t)
2924 (delete-region (point) (line-end-position))
2926 (insert (format fmt i)))
2927 (goto-char (point-min))
2928 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
2929 (replace-match (format "\\1%d" i))))))
2931 (dolist (hook '(perl-mode-hook cperl-mode-hook))
2932 (add-hook hook 'mdw-misc-mode-config t)
2933 (add-hook hook 'mdw-fontify-perl t))
2935 ;;;--------------------------------------------------------------------------
2936 ;;; Python programming style.
2938 (setq-default py-indent-offset 2
2940 python-indent-offset 2
2941 python-fill-docstring-style 'symmetric)
2943 (defun mdw-fontify-pythonic (keywords)
2945 ;; Miscellaneous fiddling.
2946 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2947 (setq indent-tabs-mode nil)
2949 ;; Now define fontification things.
2950 (make-local-variable 'font-lock-keywords)
2951 (setq font-lock-keywords
2954 ;; Set up the keywords defined above.
2955 (list (concat "\\_<\\(" keywords "\\)\\_>")
2956 '(0 font-lock-keyword-face))
2958 ;; At least numbers are simpler than C.
2959 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO]?[0-7]+\\|[bB][01]+\\)\\|"
2960 "\\_<[0-9][0-9]*\\(\\.[0-9]*\\|\\)"
2961 "\\([eE]\\([-+]\\|\\)[0-9]+\\|[lL]\\|\\)")
2962 '(0 mdw-number-face))
2964 ;; And anything else is punctuation.
2965 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2966 '(0 mdw-punct-face)))))
2968 ;; Define Python fontification styles.
2970 (defun mdw-fontify-python ()
2971 (mdw-fontify-pythonic
2972 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
2973 "del" "elif" "else" "except" "exec" "finally" "for"
2974 "from" "global" "if" "import" "in" "is" "lambda"
2975 "not" "or" "pass" "print" "raise" "return" "try"
2976 "while" "with" "yield")))
2978 (defun mdw-fontify-pyrex ()
2979 (mdw-fontify-pythonic
2980 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
2981 "ctypedef" "def" "del" "elif" "else" "enum" "except" "exec"
2982 "extern" "finally" "for" "from" "global" "if"
2983 "import" "in" "is" "lambda" "not" "or" "pass" "print"
2984 "property" "raise" "return" "struct" "try" "while" "with"
2987 (define-derived-mode pyrex-mode python-mode "Pyrex"
2988 "Major mode for editing Pyrex source code")
2989 (setq auto-mode-alist
2990 (append '(("\\.pyx$" . pyrex-mode)
2991 ("\\.pxd$" . pyrex-mode)
2992 ("\\.pxi$" . pyrex-mode))
2996 (add-hook 'python-mode-hook 'mdw-misc-mode-config t)
2997 (add-hook 'python-mode-hook 'mdw-fontify-python t)
2998 (add-hook 'pyrex-mode-hook 'mdw-fontify-pyrex t))
3000 ;;;--------------------------------------------------------------------------
3001 ;;; Lua programming style.
3003 (setq-default lua-indent-level 2)
3005 (defun mdw-fontify-lua ()
3007 ;; Miscellaneous fiddling.
3008 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3010 ;; Now define fontification things.
3011 (make-local-variable 'font-lock-keywords)
3013 (mdw-regexps "and" "break" "do" "else" "elseif" "end"
3014 "false" "for" "function" "goto" "if" "in" "local"
3015 "nil" "not" "or" "repeat" "return" "then" "true"
3017 (setq font-lock-keywords
3020 ;; Set up the keywords defined above.
3021 (list (concat "\\_<\\(" lua-keywords "\\)\\_>")
3022 '(0 font-lock-keyword-face))
3024 ;; At least numbers are simpler than C.
3025 (list (concat "\\_<\\(" "0[xX]"
3026 "\\(" "[0-9a-fA-F]+"
3027 "\\(\\.[0-9a-fA-F]*\\)?"
3028 "\\|" "\\.[0-9a-fA-F]+"
3030 "\\([pP][-+]?[0-9]+\\)?"
3031 "\\|" "\\(" "[0-9]+"
3035 "\\([eE][-+]?[0-9]+\\)?"
3037 '(0 mdw-number-face))
3039 ;; And anything else is punctuation.
3040 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3041 '(0 mdw-punct-face))))))
3044 (add-hook 'lua-mode-hook 'mdw-misc-mode-config t)
3045 (add-hook 'lua-mode-hook 'mdw-fontify-lua t))
3047 ;;;--------------------------------------------------------------------------
3048 ;;; Icon programming style.
3050 ;; Icon indentation style.
3052 (setq-default icon-brace-offset 0
3053 icon-continued-brace-offset 0
3054 icon-continued-statement-offset 2
3055 icon-indent-level 2)
3057 ;; Define Icon fontification style.
3059 (defun mdw-fontify-icon ()
3061 ;; Miscellaneous fiddling.
3062 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3064 ;; Now define fontification things.
3065 (make-local-variable 'font-lock-keywords)
3066 (let ((icon-keywords
3067 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
3068 "end" "every" "fail" "global" "if" "initial"
3069 "invocable" "link" "local" "next" "not" "of"
3070 "procedure" "record" "repeat" "return" "static"
3071 "suspend" "then" "to" "until" "while"))
3072 (preprocessor-keywords
3073 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
3074 "include" "line" "undef")))
3075 (setq font-lock-keywords
3078 ;; Set up the keywords defined above.
3079 (list (concat "\\<\\(" icon-keywords "\\)\\>")
3080 '(0 font-lock-keyword-face))
3082 ;; The things that Icon calls keywords.
3083 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
3085 ;; At least numbers are simpler than C.
3086 (list (concat "\\<[0-9]+"
3087 "\\([rR][0-9a-zA-Z]+\\|"
3088 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
3089 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
3090 '(0 mdw-number-face))
3093 (list (concat "^[ \t]*$[ \t]*\\<\\("
3094 preprocessor-keywords
3096 '(0 font-lock-keyword-face))
3098 ;; And anything else is punctuation.
3099 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3100 '(0 mdw-punct-face))))))
3103 (add-hook 'icon-mode-hook 'mdw-misc-mode-config t)
3104 (add-hook 'icon-mode-hook 'mdw-fontify-icon t))
3106 ;;;--------------------------------------------------------------------------
3109 (defun mdw-fontify-asm ()
3110 (modify-syntax-entry ?' "\"")
3111 (modify-syntax-entry ?. "w")
3112 (modify-syntax-entry ?\n ">")
3113 (setf fill-prefix nil)
3114 (modify-syntax-entry ?. "_")
3115 (modify-syntax-entry ?* ". 23")
3116 (modify-syntax-entry ?/ ". 124b")
3117 (modify-syntax-entry ?\n "> b")
3118 (local-set-key ";" 'self-insert-command)
3119 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
3121 (defun mdw-asm-set-comment ()
3122 (modify-syntax-entry ?; "."
3124 (modify-syntax-entry asm-comment-char "< b")
3125 (setq comment-start (string asm-comment-char ? )))
3126 (add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
3127 (put 'asm-comment-char 'safe-local-variable 'characterp)
3130 (add-hook 'asm-mode-hook 'mdw-misc-mode-config t)
3131 (add-hook 'asm-mode-hook 'mdw-fontify-asm t))
3133 ;;;--------------------------------------------------------------------------
3134 ;;; TCL configuration.
3136 (setq-default tcl-indent-level 2)
3138 (defun mdw-fontify-tcl ()
3140 (modify-syntax-entry ch "."))
3141 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3142 (make-local-variable 'font-lock-keywords)
3143 (setq font-lock-keywords
3145 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3146 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
3147 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
3148 '(0 mdw-number-face))
3149 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3150 '(0 mdw-punct-face)))))
3153 (add-hook 'tcl-mode-hook 'mdw-misc-mode-config t)
3154 (add-hook 'tcl-mode-hook 'mdw-fontify-tcl t))
3156 ;;;--------------------------------------------------------------------------
3157 ;;; Dylan programming configuration.
3159 (defun mdw-fontify-dylan ()
3161 (make-local-variable 'font-lock-keywords)
3163 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
3164 ;; hook, which undoes all of our configuration.
3165 (setq major-mode 'dylan-mode)
3166 (font-lock-set-defaults)
3168 (let* ((word "[-_a-zA-Z!*@<>$%]+")
3169 (dylan-keywords (mdw-regexps
3171 "C-address" "C-callable-wrapper" "C-function"
3172 "C-mapped-subtype" "C-pointer-type" "C-struct"
3173 "C-subtype" "C-union" "C-variable"
3175 "above" "abstract" "afterwards" "all"
3176 "begin" "below" "block" "by"
3177 "case" "class" "cleanup" "constant" "create"
3179 "else" "elseif" "end" "exception" "export"
3180 "finally" "for" "from" "function"
3183 "if" "in" "instance" "interface" "iterate"
3185 "let" "library" "local"
3186 "macro" "method" "module"
3189 "select" "slot" "subclass"
3191 "unless" "until" "use"
3192 "variable" "virtual"
3194 (sharp-keywords (mdw-regexps
3195 "all-keys" "key" "next" "rest" "include"
3197 (setq font-lock-keywords
3198 (list (list (concat "\\<\\(" dylan-keywords
3199 "\\|" "with\\(out\\)?-" word
3201 '(0 font-lock-keyword-face))
3202 (list (concat "\\<" word ":" "\\|"
3203 "#\\(" sharp-keywords "\\)\\>")
3204 '(0 font-lock-variable-name-face))
3206 "\\([-+]\\|\\<\\)[0-9]+" "\\("
3207 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
3210 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
3213 "\\|" "#x[0-9a-zA-Z]+"
3215 '(0 mdw-number-face))
3217 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
3218 "\\_<[-+*/=<>:&|]+\\_>"
3220 '(0 mdw-punct-face))))))
3223 (add-hook 'dylan-mode-hook 'mdw-misc-mode-config t)
3224 (add-hook 'dylan-mode-hook 'mdw-fontify-dylan t))
3226 ;;;--------------------------------------------------------------------------
3227 ;;; Algol 68 configuration.
3229 (setq-default a68-indent-step 2)
3231 (defun mdw-fontify-algol-68 ()
3233 ;; Fix up the syntax table.
3234 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
3235 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
3236 (modify-syntax-entry ch "." a68-mode-syntax-table))
3238 (make-local-variable 'font-lock-keywords)
3241 (let ((word "COMMENT"))
3242 (do ((regexp (concat "[^" (substring word 0 1) "]+")
3243 (concat regexp "\\|"
3244 (substring word 0 i)
3245 "[^" (substring word i (1+ i)) "]"))
3247 ((>= i (length word)) regexp)))))
3248 (setq font-lock-keywords
3249 (list (list (concat "\\<COMMENT\\>"
3250 "\\(" not-comment "\\)\\{0,5\\}"
3251 "\\(\\'\\|\\<COMMENT\\>\\)")
3252 '(0 font-lock-comment-face))
3253 (list (concat "\\<CO\\>"
3254 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
3255 "\\($\\|\\<CO\\>\\)")
3256 '(0 font-lock-comment-face))
3257 (list "\\<[A-Z_]+\\>"
3258 '(0 font-lock-keyword-face))
3262 "\\([eE][-+]?[0-9]+\\)?"
3264 '(0 mdw-number-face))
3265 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
3266 '(0 mdw-punct-face))))))
3268 (dolist (hook '(a68-mode-hook a68-mode-hooks))
3269 (add-hook hook 'mdw-misc-mode-config t)
3270 (add-hook hook 'mdw-fontify-algol-68 t))
3272 ;;;--------------------------------------------------------------------------
3273 ;;; REXX configuration.
3275 (defun mdw-rexx-electric-* ()
3280 (defun mdw-rexx-indent-newline-indent ()
3283 (if abbrev-mode (expand-abbrev))
3284 (newline-and-indent))
3286 (defun mdw-fontify-rexx ()
3288 ;; Various bits of fiddling.
3289 (setq mdw-auto-indent nil)
3290 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
3291 (local-set-key [?*] 'mdw-rexx-electric-*)
3292 (dolist (ch '(?! ?? ?# ?@ ?$)) (modify-syntax-entry ch "w"))
3293 (dolist (ch '(?¬)) (modify-syntax-entry ch "."))
3294 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
3296 ;; Set up keywords and things for fontification.
3297 (make-local-variable 'font-lock-keywords-case-fold-search)
3298 (setq font-lock-keywords-case-fold-search t)
3300 (setq rexx-indent 2)
3301 (setq rexx-end-indent rexx-indent)
3302 (setq rexx-cont-indent rexx-indent)
3304 (make-local-variable 'font-lock-keywords)
3305 (let ((rexx-keywords
3306 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
3307 "else" "end" "engineering" "exit" "expose" "for"
3308 "forever" "form" "fuzz" "if" "interpret" "iterate"
3309 "leave" "linein" "name" "nop" "numeric" "off" "on"
3310 "options" "otherwise" "parse" "procedure" "pull"
3311 "push" "queue" "return" "say" "select" "signal"
3312 "scientific" "source" "then" "trace" "to" "until"
3313 "upper" "value" "var" "version" "when" "while"
3316 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
3317 "center" "center" "charin" "charout" "chars"
3318 "compare" "condition" "copies" "c2d" "c2x"
3319 "datatype" "date" "delstr" "delword" "d2c" "d2x"
3320 "errortext" "format" "fuzz" "insert" "lastpos"
3321 "left" "length" "lineout" "lines" "max" "min"
3322 "overlay" "pos" "queued" "random" "reverse" "right"
3323 "sign" "sourceline" "space" "stream" "strip"
3324 "substr" "subword" "symbol" "time" "translate"
3325 "trunc" "value" "verify" "word" "wordindex"
3326 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
3329 (setq font-lock-keywords
3332 ;; Set up the keywords defined above.
3333 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
3334 '(0 font-lock-keyword-face))
3336 ;; Fontify all symbols the same way.
3337 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
3338 "[A-Za-z0-9.!?_#@$]+\\)")
3339 '(0 font-lock-variable-name-face))
3341 ;; And everything else is punctuation.
3342 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3343 '(0 mdw-punct-face))))))
3346 (add-hook 'rexx-mode-hook 'mdw-misc-mode-config t)
3347 (add-hook 'rexx-mode-hook 'mdw-fontify-rexx t))
3349 ;;;--------------------------------------------------------------------------
3350 ;;; Standard ML programming style.
3352 (setq-default sml-nested-if-indent t
3355 sml-type-of-indent nil)
3357 (defun mdw-fontify-sml ()
3359 ;; Make underscore an honorary letter.
3360 (modify-syntax-entry ?' "w")
3363 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
3365 ;; Now define fontification things.
3366 (make-local-variable 'font-lock-keywords)
3368 (mdw-regexps "abstype" "and" "andalso" "as"
3371 "else" "end" "eqtype" "exception"
3372 "fn" "fun" "functor"
3374 "if" "in" "include" "infix" "infixr"
3377 "of" "op" "open" "orelse"
3379 "sharing" "sig" "signature" "struct" "structure"
3382 "where" "while" "with" "withtype")))
3384 (setq font-lock-keywords
3387 ;; Set up the keywords defined above.
3388 (list (concat "\\<\\(" sml-keywords "\\)\\>")
3389 '(0 font-lock-keyword-face))
3391 ;; At least numbers are simpler than C.
3392 (list (concat "\\<\\(\\~\\|\\)"
3393 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
3395 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
3396 "\\([eE]\\(\\~\\|\\)"
3397 "[0-9]+\\|\\)\\)\\)")
3398 '(0 mdw-number-face))
3400 ;; And anything else is punctuation.
3401 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3402 '(0 mdw-punct-face))))))
3405 (add-hook 'sml-mode-hook 'mdw-misc-mode-config t)
3406 (add-hook 'sml-mode-hook 'mdw-fontify-sml t))
3408 ;;;--------------------------------------------------------------------------
3409 ;;; Haskell configuration.
3411 (setq-default haskell-indent-offset 2)
3413 (defun mdw-fontify-haskell ()
3415 ;; Fiddle with syntax table to get comments right.
3416 (modify-syntax-entry ?' "_")
3417 (modify-syntax-entry ?- ". 12")
3418 (modify-syntax-entry ?\n ">")
3420 ;; Make punctuation be punctuation
3421 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
3423 ((>= i (length punct)))
3424 (modify-syntax-entry (aref punct i) ".")))
3427 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
3429 ;; Fiddle with fontification.
3430 (make-local-variable 'font-lock-keywords)
3431 (let ((haskell-keywords
3433 "case" "ccall" "class"
3434 "data" "default" "deriving" "do"
3438 "if" "import" "in" "infix" "infixl" "infixr" "instance"
3451 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
3452 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
3453 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
3454 "SP" "STX" "SUB" "SYN" "US" "VT")))
3456 (setq font-lock-keywords
3458 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
3462 '(0 font-lock-comment-face))
3463 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
3464 '(0 font-lock-keyword-face))
3465 (list (concat "'\\("
3469 "\\(" "[abfnrtv\\\"']" "\\|"
3470 "^" "\\(" control-sequences "\\|"
3471 "[]A-Z@[\\^_]" "\\)" "\\|"
3478 '(0 font-lock-string-face))
3479 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
3480 '(0 font-lock-variable-name-face))
3481 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
3482 "\\_<[0-9]+\\(\\.[0-9]*\\|\\)"
3483 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
3484 '(0 mdw-number-face))
3485 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3486 '(0 mdw-punct-face))))))
3489 (add-hook 'haskell-mode-hook 'mdw-misc-mode-config t)
3490 (add-hook 'haskell-mode-hook 'mdw-fontify-haskell t))
3492 ;;;--------------------------------------------------------------------------
3493 ;;; Erlang configuration.
3495 (setq-default erlang-electric-commands nil)
3497 (defun mdw-fontify-erlang ()
3500 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
3502 ;; Fiddle with fontification.
3503 (make-local-variable 'font-lock-keywords)
3504 (let ((erlang-keywords
3505 (mdw-regexps "after" "and" "andalso"
3506 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
3507 "case" "catch" "cond"
3508 "div" "end" "fun" "if" "let" "not"
3510 "query" "receive" "rem" "try" "when" "xor")))
3512 (setq font-lock-keywords
3515 '(0 font-lock-comment-face))
3516 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
3517 '(0 font-lock-keyword-face))
3518 (list (concat "^-\\sw+\\>")
3519 '(0 font-lock-keyword-face))
3520 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
3521 '(0 mdw-number-face))
3522 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3523 '(0 mdw-punct-face))))))
3526 (add-hook 'erlang-mode-hook 'mdw-misc-mode-config t)
3527 (add-hook 'erlang-mode-hook 'mdw-fontify-erlang t))
3529 ;;;--------------------------------------------------------------------------
3530 ;;; Texinfo configuration.
3532 (defun mdw-fontify-texinfo ()
3535 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
3537 ;; Real fontification things.
3538 (make-local-variable 'font-lock-keywords)
3539 (setq font-lock-keywords
3542 ;; Environment names are keywords.
3543 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
3544 '(2 font-lock-keyword-face))
3546 ;; Unmark escaped magic characters.
3547 (list "\\(@\\)\\([@{}]\\)"
3548 '(1 font-lock-keyword-face)
3549 '(2 font-lock-variable-name-face))
3551 ;; Make sure we get comments properly.
3552 (list "@c\\(\\|omment\\)\\( .*\\)?$"
3553 '(0 font-lock-comment-face))
3555 ;; Command names are keywords.
3556 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3557 '(0 font-lock-keyword-face))
3559 ;; Fontify TeX special characters as punctuation.
3561 '(0 mdw-punct-face)))))
3563 (dolist (hook '(texinfo-mode-hook TeXinfo-mode-hook))
3564 (add-hook hook 'mdw-misc-mode-config t)
3565 (add-hook hook 'mdw-fontify-texinfo t))
3567 ;;;--------------------------------------------------------------------------
3568 ;;; TeX and LaTeX configuration.
3570 (setq-default LaTeX-table-label "tbl:"
3571 TeX-auto-untabify nil
3572 LaTeX-syntactic-comments nil
3573 LaTeX-fill-break-at-separators '(\\\[))
3575 (defun mdw-fontify-tex ()
3576 (setq ispell-parser 'tex)
3579 ;; Don't make maths into a string.
3580 (modify-syntax-entry ?$ ".")
3581 (modify-syntax-entry ?$ "." font-lock-syntax-table)
3582 (local-set-key [?$] 'self-insert-command)
3584 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
3585 (local-set-key "\C-\M-i" 'indent-relative)
3586 (setq indent-tabs-mode nil)
3589 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
3591 ;; Real fontification things.
3592 (make-local-variable 'font-lock-keywords)
3593 (setq font-lock-keywords
3596 ;; Environment names are keywords.
3597 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
3599 '(2 font-lock-keyword-face))
3601 ;; Suspended environment names are keywords too.
3602 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
3604 '(3 font-lock-keyword-face))
3606 ;; Command names are keywords.
3607 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3608 '(0 font-lock-keyword-face))
3610 ;; Handle @/.../ for italics.
3611 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
3612 ;; '(1 font-lock-keyword-face)
3613 ;; '(3 font-lock-keyword-face))
3615 ;; Handle @*...* for boldness.
3616 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
3617 ;; '(1 font-lock-keyword-face)
3618 ;; '(3 font-lock-keyword-face))
3620 ;; Handle @`...' for literal syntax things.
3621 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
3622 ;; '(1 font-lock-keyword-face)
3623 ;; '(3 font-lock-keyword-face))
3625 ;; Handle @<...> for nonterminals.
3626 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
3627 ;; '(1 font-lock-keyword-face)
3628 ;; '(3 font-lock-keyword-face))
3630 ;; Handle other @-commands.
3631 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
3632 ;; '(0 font-lock-keyword-face))
3634 ;; Make sure we get comments properly.
3636 '(0 font-lock-comment-face))
3638 ;; Fontify TeX special characters as punctuation.
3640 '(0 mdw-punct-face)))))
3642 (setq TeX-install-font-lock 'tex-font-setup)
3644 (eval-after-load 'font-latex
3645 '(defun font-latex-jit-lock-force-redisplay (buf start end)
3646 "Compatibility for Emacsen not offering `jit-lock-force-redisplay'."
3647 ;; The following block is an expansion of `jit-lock-force-redisplay'
3648 ;; and involved macros taken from CVS Emacs on 2007-04-28.
3649 (with-current-buffer buf
3650 (let ((modified (buffer-modified-p)))
3652 (let ((buffer-undo-list t)
3653 (inhibit-read-only t)
3654 (inhibit-point-motion-hooks t)
3655 (inhibit-modification-hooks t)
3658 buffer-file-truename)
3659 (put-text-property start end 'fontified t))
3661 (restore-buffer-modified-p nil)))))))
3663 (setq TeX-output-view-style
3665 ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$")
3666 "%(o?)dvips -t landscape %d -o && xdg-open %f")
3667 ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$"
3668 "%(o?)dvips %d -o && xdg-open %f")
3670 ("^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "^landscape$")
3671 "%(o?)xdvi %dS -paper a4r -s 0 %d")
3672 ("^dvi$" "^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$"
3673 "%(o?)xdvi %dS -paper a4 %d")
3675 ("^a5\\(?:comb\\|paper\\)$" "^landscape$")
3676 "%(o?)xdvi %dS -paper a5r -s 0 %d")
3677 ("^dvi$" "^a5\\(?:comb\\|paper\\)$" "%(o?)xdvi %dS -paper a5 %d")
3678 ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
3679 ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d")
3680 ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
3681 ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
3682 ("^dvi$" "." "%(o?)xdvi %dS %d")
3683 ("^pdf$" "." "xdg-open %o")
3684 ("^html?$" "." "sensible-browser %o")))
3686 (setq TeX-view-program-list
3687 '(("mupdf" ("mupdf %o" (mode-io-correlate " %(outpage)")))))
3689 (setq TeX-view-program-selection
3690 '(((output-dvi style-pstricks) "dvips and gv")
3692 (output-pdf "mupdf")
3693 (output-html "sensible-browser")))
3695 (setq TeX-open-quote "\""
3696 TeX-close-quote "\"")
3698 (setq reftex-use-external-file-finders t
3699 reftex-auto-recenter-toc t)
3701 (setq reftex-label-alist
3702 '(("theorem" ?T "th:" "~\\ref{%s}" t ("theorems?" "th\\.") -2)
3703 ("axiom" ?A "ax:" "~\\ref{%s}" t ("axioms?" "ax\\.") -2)
3704 ("definition" ?D "def:" "~\\ref{%s}" t ("definitions?" "def\\.") -2)
3705 ("proposition" ?P "prop:" "~\\ref{%s}" t
3706 ("propositions?" "prop\\.") -2)
3707 ("lemma" ?L "lem:" "~\\ref{%s}" t ("lemmas?" "lem\\.") -2)
3708 ("example" ?X "eg:" "~\\ref{%s}" t ("examples?") -2)
3709 ("exercise" ?E "ex:" "~\\ref{%s}" t ("exercises?" "ex\\.") -2)
3710 ("enumerate" ?i "i:" "~\\ref{%s}" item ("items?"))))
3711 (setq reftex-section-prefixes
3716 (setq bibtex-field-delimiters 'double-quotes
3717 bibtex-align-at-equal-sign t
3718 bibtex-entry-format '(realign opts-or-alts required-fields
3719 numerical-fields last-comma delimiters
3720 unify-case sort-fields braces)
3721 bibtex-sort-ignore-string-entries nil
3722 bibtex-maintain-sorted-entries 'entry-class
3723 bibtex-include-OPTkey t
3724 bibtex-autokey-names-stretch 1
3725 bibtex-autokey-expand-strings t
3726 bibtex-autokey-name-separator "-"
3727 bibtex-autokey-year-length 4
3728 bibtex-autokey-titleword-separator "-"
3729 bibtex-autokey-name-year-separator "-"
3730 bibtex-autokey-year-title-separator ":")
3733 (dolist (hook '(tex-mode-hook latex-mode-hook
3734 TeX-mode-hook LaTeX-mode-hook))
3735 (add-hook hook 'mdw-misc-mode-config t)
3736 (add-hook hook 'mdw-fontify-tex t))
3737 (add-hook 'bibtex-mode-hook (lambda () (setq fill-column 76))))
3739 ;;;--------------------------------------------------------------------------
3740 ;;; HTML, CSS, and other web foolishness.
3742 (setq-default css-indent-offset 2)
3744 ;;;--------------------------------------------------------------------------
3747 (setq-default psgml-html-build-new-buffer nil)
3749 (defun mdw-sgml-mode ()
3752 (mdw-standard-fill-prefix "")
3753 (make-local-variable 'sgml-delimiters)
3754 (setq sgml-delimiters
3755 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
3756 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
3757 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
3758 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
3759 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
3760 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
3761 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
3763 (setq major-mode 'mdw-sgml-mode)
3764 (setq mode-name "[mdw] SGML")
3765 (run-hooks 'mdw-sgml-mode-hook))
3767 ;;;--------------------------------------------------------------------------
3768 ;;; Configuration files.
3770 (defvar mdw-conf-quote-normal nil
3771 "*Control syntax category of quote characters `\"' and `''.
3772 If this is `t', consider quote characters to be normal
3773 punctuation, as for `conf-quote-normal'. If this is `nil' then
3774 leave quote characters as quotes. If this is a list, then
3775 consider the quote characters in the list to be normal
3776 punctuation. If this is a single quote character, then consider
3777 that character only to be normal punctuation.")
3778 (defun mdw-conf-quote-normal-acceptable-value-p (value)
3779 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
3780 (or (booleanp value)
3781 (every (lambda (v) (memq v '(?\" ?')))
3782 (if (listp value) value (list value)))))
3783 (put 'mdw-conf-quote-normal 'safe-local-variable
3784 'mdw-conf-quote-normal-acceptable-value-p)
3786 (defun mdw-fix-up-quote ()
3787 "Apply the setting of `mdw-conf-quote-normal'."
3788 (let ((flag mdw-conf-quote-normal))
3790 (conf-quote-normal t))
3794 (let ((table (copy-syntax-table (syntax-table))))
3795 (dolist (ch (if (listp flag) flag (list flag)))
3796 (modify-syntax-entry ch "." table))
3797 (set-syntax-table table)
3798 (and font-lock-mode (font-lock-fontify-buffer)))))))
3801 (add-hook 'conf-mode-hook 'mdw-misc-mode-config t)
3802 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t))
3804 ;;;--------------------------------------------------------------------------
3807 (defun mdw-setup-sh-script-mode ()
3809 ;; Fetch the shell interpreter's name.
3810 (let ((shell-name sh-shell-file))
3812 ;; Try reading the hash-bang line.
3814 (goto-char (point-min))
3815 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
3816 (setq shell-name (match-string 1))))
3818 ;; Now try to set the shell.
3820 ;; Don't let `sh-set-shell' bugger up my script.
3821 (let ((executable-set-magic #'(lambda (s &rest r) s)))
3822 (sh-set-shell shell-name)))
3824 ;; Don't insert here-document scaffolding automatically.
3825 (local-set-key "<" 'self-insert-command)
3827 ;; Now enable my keys and the fontification.
3828 (mdw-misc-mode-config)
3830 ;; Set the indentation level correctly.
3831 (setq sh-indentation 2)
3832 (setq sh-basic-offset 2))
3834 (setq sh-shell-file "/bin/sh")
3836 ;; Awful hacking to override the shell detection for particular scripts.
3837 (defmacro define-custom-shell-mode (name shell)
3840 (set (make-local-variable 'sh-shell-file) ,shell)
3842 (define-custom-shell-mode bash-mode "/bin/bash")
3843 (define-custom-shell-mode rc-mode "/usr/bin/rc")
3844 (put 'sh-shell-file 'permanent-local t)
3846 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
3847 (eval-after-load "sh-script"
3848 '(or (assq 'rc sh-mode-syntax-table-input)
3865 (assoc (assq 'rc sh-mode-syntax-table-input)))
3868 (setq sh-mode-syntax-table-input
3869 (cons (cons 'rc frag)
3870 sh-mode-syntax-table-input))))))
3873 (add-hook 'sh-mode-hook 'mdw-misc-mode-config t)
3874 (add-hook 'sh-mode-hook 'mdw-setup-sh-script-mode t))
3876 ;;;--------------------------------------------------------------------------
3877 ;;; Emacs shell mode.
3879 (defun mdw-eshell-prompt ()
3880 (let ((left "[") (right "]"))
3881 (when (= (user-uid) 0)
3882 (setq left "«" right "»"))
3885 (replace-regexp-in-string "\\..*$" "" (system-name)))
3887 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
3888 (home (expand-file-name "~")) (nhome (length home)))
3889 (if (and (>= npwd nhome)
3891 (= (elt pwd nhome) ?/))
3892 (string= (substring pwd 0 nhome) home))
3893 (concat "~" (substring pwd (length home)))
3896 (setq-default eshell-prompt-function 'mdw-eshell-prompt)
3897 (setq-default eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
3899 (defun eshell/e (file) (find-file file) nil)
3900 (defun eshell/ee (file) (find-file-other-window file) nil)
3901 (defun eshell/w3m (url) (w3m-goto-url url) nil)
3903 (mdw-define-face eshell-prompt (t :weight bold))
3904 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
3905 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
3906 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
3907 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
3908 (mdw-define-face eshell-ls-executable (t :weight bold))
3909 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
3910 (mdw-define-face eshell-ls-readonly (t nil))
3911 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
3913 (defun mdw-eshell-hack () (setenv "LD_PRELOAD" nil))
3914 (add-hook 'eshell-mode-hook 'mdw-eshell-hack)
3916 ;;;--------------------------------------------------------------------------
3917 ;;; Messages-file mode.
3919 (defun messages-mode-guts ()
3920 (setq messages-mode-syntax-table (make-syntax-table))
3921 (set-syntax-table messages-mode-syntax-table)
3922 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
3923 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
3924 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
3925 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
3926 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
3927 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
3928 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
3929 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
3930 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
3931 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
3932 (make-local-variable 'comment-start)
3933 (make-local-variable 'comment-end)
3934 (make-local-variable 'indent-line-function)
3935 (setq indent-line-function 'indent-relative)
3936 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3937 (make-local-variable 'font-lock-defaults)
3938 (make-local-variable 'messages-mode-keywords)
3940 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
3941 "export" "enum" "fixed-octetstring" "flags"
3942 "harmless" "map" "nested" "optional"
3943 "optional-tagged" "package" "primitive"
3944 "primitive-nullfree" "relaxed[ \t]+enum"
3945 "set" "table" "tagged-optional" "union"
3946 "variadic" "vector" "version" "version-tag")))
3947 (setq messages-mode-keywords
3949 (list (concat "\\<\\(" keywords "\\)\\>:")
3950 '(0 font-lock-keyword-face))
3951 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
3952 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
3953 (0 font-lock-variable-name-face))
3954 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
3955 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3956 (0 mdw-punct-face)))))
3957 (setq font-lock-defaults
3958 '(messages-mode-keywords nil nil nil nil))
3959 (run-hooks 'messages-file-hook))
3961 (defun messages-mode ()
3964 (setq major-mode 'messages-mode)
3965 (setq mode-name "Messages")
3966 (messages-mode-guts)
3967 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
3968 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
3969 (setq comment-start "# ")
3970 (setq comment-end "")
3971 (run-hooks 'messages-mode-hook))
3973 (defun cpp-messages-mode ()
3976 (setq major-mode 'cpp-messages-mode)
3977 (setq mode-name "CPP Messages")
3978 (messages-mode-guts)
3979 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
3980 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
3981 (setq comment-start "/* ")
3982 (setq comment-end " */")
3983 (let ((preprocessor-keywords
3984 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
3985 "ident" "if" "ifdef" "ifndef" "import" "include"
3986 "line" "pragma" "unassert" "undef" "warning")))
3987 (setq messages-mode-keywords
3988 (append (list (list (concat "^[ \t]*\\#[ \t]*"
3989 "\\(include\\|import\\)"
3990 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
3991 '(2 font-lock-string-face))
3992 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
3993 preprocessor-keywords
3994 "\\)\\>\\|[0-9]+\\|$\\)\\)")
3995 '(1 font-lock-keyword-face)))
3996 messages-mode-keywords)))
3997 (run-hooks 'cpp-messages-mode-hook))
4000 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
4001 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
4002 ;; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
4005 ;;;--------------------------------------------------------------------------
4006 ;;; Messages-file mode.
4008 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
4009 "Face to use for subsittution directives.")
4010 (make-face 'mallow-driver-substitution-face)
4011 (defvar mallow-driver-text-face 'mallow-driver-text-face
4012 "Face to use for body text.")
4013 (make-face 'mallow-driver-text-face)
4015 (defun mallow-driver-mode ()
4018 (setq major-mode 'mallow-driver-mode)
4019 (setq mode-name "Mallow driver")
4020 (setq mallow-driver-mode-syntax-table (make-syntax-table))
4021 (set-syntax-table mallow-driver-mode-syntax-table)
4022 (make-local-variable 'comment-start)
4023 (make-local-variable 'comment-end)
4024 (make-local-variable 'indent-line-function)
4025 (setq indent-line-function 'indent-relative)
4026 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4027 (make-local-variable 'font-lock-defaults)
4028 (make-local-variable 'mallow-driver-mode-keywords)
4030 (mdw-regexps "each" "divert" "file" "if"
4031 "perl" "set" "string" "type" "write")))
4032 (setq mallow-driver-mode-keywords
4034 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
4035 '(0 font-lock-keyword-face))
4036 (list "^%\\s *\\(#.*\\|\\)$"
4037 '(0 font-lock-comment-face))
4039 '(0 font-lock-keyword-face))
4040 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
4042 '(0 mallow-driver-substitution-face t)))))
4043 (setq font-lock-defaults
4044 '(mallow-driver-mode-keywords nil nil nil nil))
4045 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
4046 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
4047 (setq comment-start "%# ")
4048 (setq comment-end "")
4049 (run-hooks 'mallow-driver-mode-hook))
4052 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t))
4054 ;;;--------------------------------------------------------------------------
4057 (defun nfast-debug-mode ()
4060 (setq major-mode 'nfast-debug-mode)
4061 (setq mode-name "NFast debug")
4062 (setq messages-mode-syntax-table (make-syntax-table))
4063 (set-syntax-table messages-mode-syntax-table)
4064 (make-local-variable 'font-lock-defaults)
4065 (make-local-variable 'nfast-debug-mode-keywords)
4066 (setq truncate-lines t)
4067 (setq nfast-debug-mode-keywords
4069 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
4070 (0 font-lock-keyword-face))
4071 (list (concat "^[ \t]+\\(\\("
4072 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4073 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4075 "[0-9a-fA-F]+\\)[ \t]*$")
4076 '(0 mdw-number-face))
4077 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
4078 (1 font-lock-keyword-face))
4079 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
4080 (1 font-lock-warning-face))
4081 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
4083 (list (concat "^[ \t]+\\.cmd=[ \t]+"
4084 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
4085 '(1 font-lock-keyword-face))
4086 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
4087 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
4088 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
4089 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
4090 (setq font-lock-defaults
4091 '(nfast-debug-mode-keywords nil nil nil nil))
4092 (run-hooks 'nfast-debug-mode-hook))
4094 ;;;--------------------------------------------------------------------------
4095 ;;; Lispy languages.
4097 ;; Unpleasant bodge.
4098 (unless (boundp 'slime-repl-mode-map)
4099 (setq slime-repl-mode-map (make-sparse-keymap)))
4101 (defun mdw-indent-newline-and-indent ()
4103 (indent-for-tab-command)
4104 (newline-and-indent))
4106 (eval-after-load "cl-indent"
4108 (mapc #'(lambda (pair)
4110 'common-lisp-indent-function
4112 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
4113 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
4115 (defun mdw-common-lisp-indent ()
4116 (make-local-variable 'lisp-indent-function)
4117 (setq lisp-indent-function 'common-lisp-indent-function))
4119 (setq-default lisp-simple-loop-indentation 2
4120 lisp-loop-keyword-indentation 6
4121 lisp-loop-forms-indentation 6)
4123 (defmacro mdw-advise-hyperspec-lookup (func args)
4124 `(defadvice ,func (around mdw-browse-w3m ,args activate compile)
4126 (let ((browse-url-browser-function #'mdw-w3m-browse-url))
4129 (mdw-advise-hyperspec-lookup common-lisp-hyperspec (symbol))
4130 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-format (char))
4131 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-lookup-reader-macro (char))
4133 (defun mdw-fontify-lispy ()
4136 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
4138 ;; Not much fontification needed.
4139 (make-local-variable 'font-lock-keywords)
4140 (setq font-lock-keywords
4141 (list (list (concat "\\("
4143 "\\(" "[0-9]+/[0-9]+"
4144 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
4146 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
4151 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
4152 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
4153 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
4154 "\\|" "[0-9]+" "r" "[-+]?"
4155 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
4158 '(0 mdw-number-face))
4159 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4160 '(0 mdw-punct-face)))))
4165 (if (not mdw-fast-startup)
4167 (require 'slime-autoloads)
4168 (slime-setup '(slime-autodoc slime-c-p-c)))))
4170 (let ((stuff '((cmucl ("cmucl"))
4171 (sbcl ("sbcl") :coding-system utf-8-unix)
4172 (clisp ("clisp") :coding-system utf-8-unix))))
4173 (or (boundp 'slime-lisp-implementations)
4174 (setq slime-lisp-implementations nil))
4176 (let* ((head (car stuff))
4177 (found (assq (car head) slime-lisp-implementations)))
4178 (setq stuff (cdr stuff))
4180 (rplacd found (cdr head))
4181 (setq slime-lisp-implementations
4182 (cons head slime-lisp-implementations))))))
4183 (setq slime-default-lisp 'sbcl)
4188 (dolist (hook '(emacs-lisp-mode-hook
4191 inferior-lisp-mode-hook
4192 lisp-interaction-mode-hook
4194 slime-repl-mode-hook))
4195 (add-hook hook 'mdw-misc-mode-config t)
4196 (add-hook hook 'mdw-fontify-lispy t))
4197 (add-hook 'lisp-mode-hook 'mdw-common-lisp-indent t)
4198 (add-hook 'inferior-lisp-mode-hook
4199 #'(lambda () (local-set-key "\C-m" 'comint-send-and-indent)) t))
4201 ;;;--------------------------------------------------------------------------
4202 ;;; Other languages.
4206 (defun mdw-setup-smalltalk ()
4207 (and mdw-auto-indent
4208 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
4209 (make-local-variable 'mdw-auto-indent)
4210 (setq mdw-auto-indent nil)
4211 (local-set-key "\C-i" 'smalltalk-reindent))
4213 (defun mdw-fontify-smalltalk ()
4214 (make-local-variable 'font-lock-keywords)
4215 (setq font-lock-keywords
4217 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
4218 '(0 font-lock-keyword-face))
4219 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
4220 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
4221 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
4222 '(0 mdw-number-face))
4223 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4224 '(0 mdw-punct-face)))))
4227 (add-hook 'smalltalk-mode 'mdw-misc-mode-config t)
4228 (add-hook 'smalltalk-mode 'mdw-fontify-smalltalk t))
4232 (defun mdw-setup-m4 ()
4234 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
4235 ;; annoying: fix it.
4236 (modify-syntax-entry ?{ "(")
4237 (modify-syntax-entry ?} ")")
4240 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
4242 (dolist (hook '(m4-mode-hook autoconf-mode-hook autotest-mode-hook))
4243 (add-hook hook #'mdw-misc-mode-config t)
4244 (add-hook hook #'mdw-setup-m4 t))
4249 (add-hook 'makefile-mode-hook 'mdw-misc-mode-config t))
4251 ;;;--------------------------------------------------------------------------
4254 (defun mdw-text-mode ()
4255 (setq fill-column 72)
4257 (mdw-standard-fill-prefix
4258 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
4261 (eval-after-load "flyspell"
4262 '(define-key flyspell-mode-map "\C-\M-i" nil))
4265 (add-hook 'text-mode-hook 'mdw-text-mode t))
4267 ;;;--------------------------------------------------------------------------
4268 ;;; Outline and hide/show modes.
4270 (defun mdw-outline-collapse-all ()
4271 "Completely collapse everything in the entire buffer."
4274 (goto-char (point-min))
4275 (while (< (point) (point-max))
4279 (setq hs-hide-comments-when-hiding-all nil)
4281 (defadvice hs-hide-all (after hide-first-comment activate)
4282 (save-excursion (hs-hide-initial-comment-block)))
4284 ;;;--------------------------------------------------------------------------
4287 (defun mdw-sh-mode-setup ()
4288 (local-set-key [?\C-a] 'comint-bol)
4289 (add-hook 'comint-output-filter-functions
4290 'comint-watch-for-password-prompt))
4292 (defun mdw-term-mode-setup ()
4293 (setq term-prompt-regexp shell-prompt-pattern)
4294 (make-local-variable 'mouse-yank-at-point)
4295 (make-local-variable 'transient-mark-mode)
4296 (setq mouse-yank-at-point t)
4300 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
4301 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
4302 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
4303 (defun term-send-meta-meta-something ()
4305 (term-send-raw-string "\e\e")
4307 (eval-after-load 'term
4309 (define-key term-raw-map [?\e ?\e] nil)
4310 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
4311 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
4312 (define-key term-raw-map [M-right] 'term-send-meta-right)
4313 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
4314 (define-key term-raw-map [M-left] 'term-send-meta-left)
4315 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
4317 (defadvice term-exec (before program-args-list compile activate)
4318 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
4319 This allows you to pass a list of arguments through `ansi-term'."
4320 (let ((program (ad-get-arg 2)))
4323 (ad-set-arg 2 (car program))
4324 (ad-set-arg 4 (cdr program))))))
4326 (defadvice term-exec-1 (around hack-environment compile activate)
4327 "Hack the environment inherited by inferiors in the terminal."
4328 (let ((process-environment (copy-tree process-environment)))
4329 (setenv "LD_PRELOAD" nil)
4332 (defadvice shell (around hack-environment compile activate)
4333 "Hack the environment inherited by inferiors in the shell."
4334 (let ((process-environment (copy-tree process-environment)))
4335 (setenv "LD_PRELOAD" nil)
4339 "Open a terminal containing an ssh session to the HOST."
4340 (interactive "sHost: ")
4341 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
4343 (defvar git-grep-command
4344 "env GIT_PAGER=cat git grep --no-color -nH -e "
4345 "*The default command for \\[git-grep].")
4347 (defvar git-grep-history nil)
4349 (defun git-grep (command-args)
4350 "Run `git grep' with user-specified args and collect output in a buffer."
4352 (list (read-shell-command "Run git grep (like this): "
4353 git-grep-command 'git-grep-history)))
4354 (let ((grep-use-null-device nil))
4355 (grep command-args)))
4357 ;;;--------------------------------------------------------------------------
4358 ;;; Magit configuration.
4360 (setq magit-diff-refine-hunk 't
4361 magit-view-git-manual-method 'man
4362 magit-log-margin '(nil age magit-log-margin-width t 18)
4363 magit-wip-after-save-local-mode-lighter ""
4364 magit-wip-after-apply-mode-lighter ""
4365 magit-wip-before-change-mode-lighter "")
4366 (eval-after-load "magit"
4367 '(progn (global-magit-file-mode 1)
4368 (magit-wip-after-save-mode 1)
4369 (magit-wip-after-apply-mode 1)
4370 (magit-wip-before-change-mode 1)
4371 (add-to-list 'magit-no-confirm 'safe-with-wip)
4372 (add-to-list 'magit-no-confirm 'trash)
4373 (push '(:eval (if (or magit-wip-after-save-local-mode
4374 magit-wip-after-apply-mode
4375 magit-wip-before-change-mode)
4376 (format " wip:%s%s%s"
4377 (if magit-wip-after-apply-mode "A" "")
4378 (if magit-wip-before-change-mode "C" "")
4379 (if magit-wip-after-save-local-mode "S" ""))))
4381 (dolist (popup '(magit-diff-popup
4382 magit-diff-refresh-popup
4383 magit-diff-mode-refresh-popup
4384 magit-revision-mode-refresh-popup))
4385 (magit-define-popup-switch popup ?R "Reverse diff" "-R"))))
4387 (defadvice magit-wip-commit-buffer-file
4388 (around mdw-just-this-buffer activate compile)
4389 (let ((magit-save-repository-buffers nil)) ad-do-it))
4391 (defadvice magit-discard
4392 (around mdw-delete-if-prefix-argument activate compile)
4393 (let ((magit-delete-by-moving-to-trash
4394 (and (null current-prefix-arg)
4395 magit-delete-by-moving-to-trash)))
4398 (setq magit-repolist-columns
4399 '(("Name" 16 magit-repolist-column-ident nil)
4400 ("Version" 18 magit-repolist-column-version nil)
4401 ("St" 2 magit-repolist-column-dirty nil)
4402 ("L<U" 3 mdw-repolist-column-unpulled-from-upstream nil)
4403 ("L>U" 3 mdw-repolist-column-unpushed-to-upstream nil)
4404 ("Path" 32 magit-repolist-column-path nil)))
4406 (setq magit-repository-directories '(("~/etc/profile" . 0)
4409 (defadvice magit-list-repos (around mdw-dirname () activate compile)
4410 "Make sure the returned names are directory names.
4411 Otherwise child processes get started in the wrong directory and
4413 (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it)))
4415 (defun mdw-repolist-column-unpulled-from-upstream (_id)
4416 "Insert number of upstream commits not in the current branch."
4417 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
4419 (let ((n (cadr (magit-rev-diff-count "HEAD" upstream))))
4420 (propertize (number-to-string n) 'face
4421 (if (> n 0) 'bold 'shadow))))))
4423 (defun mdw-repolist-column-unpushed-to-upstream (_id)
4424 "Insert number of commits in the current branch but not its upstream."
4425 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
4427 (let ((n (car (magit-rev-diff-count "HEAD" upstream))))
4428 (propertize (number-to-string n) 'face
4429 (if (> n 0) 'bold 'shadow))))))
4431 (defun mdw-try-smerge ()
4433 (goto-char (point-min))
4434 (when (re-search-forward "^<<<<<<< " nil t)
4436 (add-hook 'find-file-hook 'mdw-try-smerge t)
4438 ;;;--------------------------------------------------------------------------
4439 ;;; GUD, and especially GDB.
4441 ;; Inhibit window dedication. I mean, seriously, wtf?
4442 (defadvice gdb-display-buffer (after mdw-undedicated (buf) compile activate)
4443 "Don't make windows dedicated. Seriously."
4444 (set-window-dedicated-p ad-return-value nil))
4445 (defadvice gdb-set-window-buffer
4446 (after mdw-undedicated (name &optional ignore-dedicated window)
4448 "Don't make windows dedicated. Seriously."
4449 (set-window-dedicated-p (or window (selected-window)) nil))
4451 ;;;--------------------------------------------------------------------------
4454 ;; Turn off `noip' when running `man': it interferes with `man-db''s own
4455 ;; seccomp(2)-based sandboxing, which is (in this case, at least) strictly
4457 (defadvice Man-getpage-in-background
4458 (around mdw-inhibit-noip (topic) compile activate)
4459 "Inhibit the `noip' preload hack when invoking `man'."
4460 (let* ((old-preload (getenv "LD_PRELOAD"))
4461 (preloads (save-match-data (split-string old-preload ":")))
4465 (let ((item (pop preloads)))
4466 (if (save-match-data
4467 (string-match "\\(/\\|^\\)noip\.so\\(:\\|$\\)" item))
4469 (push item filtered))))
4473 (setenv "LD_PRELOAD"
4475 (with-output-to-string
4476 (setq filtered (nreverse filtered))
4479 (if first (setq first nil)
4481 (write-string (pop filtered)))))))
4483 (setenv "LD_PRELOAD" old-preload))
4486 ;;;--------------------------------------------------------------------------
4487 ;;; MPC configuration.
4489 (eval-when-compile (trap (require 'mpc)))
4491 (setq mpc-browser-tags '(Artist|Composer|Performer Album|Playlist))
4493 (defun mdw-mpc-now-playing ()
4497 (set-buffer (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))))
4498 (mpc--status-callback))
4499 (let ((state (cdr (assq 'state mpc-status))))
4500 (cond ((member state '("stop"))
4501 (message "mpd stopped."))
4502 ((member state '("play" "pause"))
4503 (let* ((artist (cdr (assq 'Artist mpc-status)))
4504 (album (cdr (assq 'Album mpc-status)))
4505 (title (cdr (assq 'Title mpc-status)))
4506 (file (cdr (assq 'file mpc-status)))
4507 (duration-string (cdr (assq 'Time mpc-status)))
4508 (time-string (cdr (assq 'time mpc-status)))
4509 (time (and time-string
4511 (if (string-match ":" time-string)
4512 (substring time-string
4513 0 (match-beginning 0))
4515 (duration (and duration-string
4516 (string-to-number duration-string)))
4517 (pos (and time duration
4518 (format " [%d:%02d/%d:%02d]"
4519 (/ time 60) (mod time 60)
4520 (/ duration 60) (mod duration 60))))
4521 (fmt (cond ((and artist title)
4522 (format "`%s' by %s%s" title artist
4523 (if album (format ", from `%s'" album)
4526 (format "`%s' (no tags)" file))
4528 "(no idea what's playing!)"))))
4529 (if (string= state "play")
4530 (message "mpd playing %s%s" fmt (or pos ""))
4531 (message "mpd paused in %s%s" fmt (or pos "")))))
4533 (message "mpd in unknown state `%s'" state)))))
4535 (defmacro mdw-define-mpc-wrapper (func bvl interactive &rest body)
4537 (interactive ,@interactive)
4540 (mdw-mpc-now-playing)))
4542 (mdw-define-mpc-wrapper mdw-mpc-play-or-pause () nil
4543 (if (member (cdr (assq 'state (mpc-cmd-status))) '("play"))
4547 (mdw-define-mpc-wrapper mdw-mpc-next () nil (mpc-next))
4548 (mdw-define-mpc-wrapper mdw-mpc-prev () nil (mpc-prev))
4549 (mdw-define-mpc-wrapper mdw-mpc-stop () nil (mpc-stop))
4551 (defun mdw-mpc-louder (step)
4552 (interactive (list (if current-prefix-arg
4553 (prefix-numeric-value current-prefix-arg)
4555 (mpc-proc-cmd (format "volume %+d" step)))
4557 (defun mdw-mpc-quieter (step)
4558 (interactive (list (if current-prefix-arg
4559 (prefix-numeric-value current-prefix-arg)
4561 (mpc-proc-cmd (format "volume %+d" (- step))))
4563 (defun mdw-mpc-hack-lines (arg interactivep func)
4564 (if (and interactivep (use-region-p))
4565 (let ((from (region-beginning)) (to (region-end)))
4570 (while (< (point) to)
4573 (let ((n (prefix-numeric-value arg)))
4590 (defun mdw-mpc-select-one ()
4591 (when (and (get-char-property (point) 'mpc-file)
4592 (not (get-char-property (point) 'mpc-select)))
4593 (mpc-select-toggle)))
4595 (defun mdw-mpc-unselect-one ()
4596 (when (get-char-property (point) 'mpc-select)
4597 (mpc-select-toggle)))
4599 (defun mdw-mpc-select (&optional arg interactivep)
4600 (interactive (list current-prefix-arg t))
4601 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4603 (defun mdw-mpc-unselect (&optional arg interactivep)
4604 (interactive (list current-prefix-arg t))
4605 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one))
4607 (defun mdw-mpc-unselect-backwards (arg)
4609 (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one))
4611 (defun mdw-mpc-unselect-all ()
4613 (setq mpc-select nil)
4614 (mpc-selection-refresh))
4616 (defun mdw-mpc-next-line (arg)
4621 (defun mdw-mpc-previous-line (arg)
4624 (forward-line (- arg)))
4626 (defun mdw-mpc-playlist-add (&optional arg interactivep)
4627 (interactive (list current-prefix-arg t))
4628 (let ((mpc-select mpc-select))
4629 (when (or arg (and interactivep (use-region-p)))
4630 (setq mpc-select nil)
4631 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4632 (setq mpc-select (reverse mpc-select))
4633 (mpc-playlist-add)))
4635 (defun mdw-mpc-playlist-delete (&optional arg interactivep)
4636 (interactive (list current-prefix-arg t))
4637 (setq mpc-select (nreverse mpc-select))
4639 (when (or arg (and interactivep (use-region-p)))
4640 (setq mpc-select nil)
4641 (mpc-selection-refresh)
4642 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4643 (mpc-playlist-delete)))
4645 (defun mdw-mpc-hack-tagbrowsers ()
4646 (setq-local mode-line-format
4648 mode-line-frame-identification
4649 mode-line-buffer-identification)))
4650 (add-hook 'mpc-tagbrowser-mode-hook 'mdw-mpc-hack-tagbrowsers)
4652 (defun mdw-mpc-hack-songs ()
4653 (setq-local header-line-format
4654 ;; '("MPC " mpc-volume " " mpc-current-song)
4655 (list (propertize " " 'display '(space :align-to 0))
4656 ;; 'mpc-songs-format-description
4658 (let ((deactivate-mark) (hscroll (window-hscroll)))
4660 (mpc-format mpc-songs-format 'self hscroll)
4661 ;; That would be simpler than the hscroll handling in
4662 ;; mpc-format, but currently move-to-column does not
4663 ;; recognize :space display properties.
4664 ;; (move-to-column hscroll)
4665 ;; (delete-region (point-min) (point))
4666 (buffer-string)))))))
4667 (add-hook 'mpc-songs-mode-hook 'mdw-mpc-hack-songs)
4669 (eval-after-load "mpc"
4671 (define-key mpc-mode-map "m" 'mdw-mpc-select)
4672 (define-key mpc-mode-map "u" 'mdw-mpc-unselect)
4673 (define-key mpc-mode-map "\177" 'mdw-mpc-unselect-backwards)
4674 (define-key mpc-mode-map "\e\177" 'mdw-mpc-unselect-all)
4675 (define-key mpc-mode-map "n" 'mdw-mpc-next-line)
4676 (define-key mpc-mode-map "p" 'mdw-mpc-previous-line)
4677 (define-key mpc-mode-map "/" 'mpc-songs-search)
4678 (setq mpc-songs-mode-map (make-sparse-keymap))
4679 (set-keymap-parent mpc-songs-mode-map mpc-mode-map)
4680 (define-key mpc-songs-mode-map "l" 'mpc-playlist)
4681 (define-key mpc-songs-mode-map "+" 'mdw-mpc-playlist-add)
4682 (define-key mpc-songs-mode-map "-" 'mdw-mpc-playlist-delete)
4683 (define-key mpc-songs-mode-map "\r" 'mpc-songs-jump-to)))
4685 ;;;--------------------------------------------------------------------------
4686 ;;; Inferior Emacs Lisp.
4688 (setq comint-prompt-read-only t)
4690 (eval-after-load "comint"
4692 (define-key comint-mode-map "\C-w" 'comint-kill-region)
4693 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
4695 (eval-after-load "ielm"
4697 (define-key ielm-map "\C-w" 'comint-kill-region)
4698 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
4700 ;;;----- That's all, folks --------------------------------------------------
4702 (provide 'dot-emacs)