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 ;; Don't raise windows unless I say so.
245 (defvar mdw-inhibit-raise-frame nil
246 "*Whether `raise-frame' should do nothing when the frame is mapped.")
248 (defadvice raise-frame
249 (around mdw-inhibit (&optional frame) activate compile)
250 "Don't actually do anything if `mdw-inhibit-raise-frame' is true, and the
251 frame is actually mapped on the screen."
252 (if mdw-inhibit-raise-frame
253 (make-frame-visible frame)
256 (defmacro mdw-advise-to-inhibit-raise-frame (function)
257 "Advise the FUNCTION not to raise frames, even if it wants to."
258 `(defadvice ,function
259 (around mdw-inhibit-raise (&rest hunoz) activate compile)
260 "Don't raise the window unless you have to."
261 (let ((mdw-inhibit-raise-frame t))
264 (mdw-advise-to-inhibit-raise-frame select-frame-set-input-focus)
265 (mdw-advise-to-inhibit-raise-frame appt-disp-window)
266 (mdw-advise-to-inhibit-raise-frame mouse-select-window)
268 ;; Bug fix for markdown-mode, which breaks point positioning during
270 (defadvice markdown-check-change-for-wiki-link
271 (around mdw-save-match activate compile)
272 "Save match data around the `markdown-mode' `after-change-functions' hook."
273 (save-match-data ad-do-it))
275 ;; Bug fix for `bbdb-canonicalize-address': on Emacs 24, `run-hook-with-args'
276 ;; always returns nil, with the result that all email addresses are lost.
277 ;; Replace the function entirely.
278 (defadvice bbdb-canonicalize-address
279 (around mdw-bug-fix activate compile)
280 "Don't use `run-hook-with-args', because that doesn't work."
281 (let ((net (ad-get-arg 0)))
283 ;; Make sure this is a proper hook list.
284 (if (functionp bbdb-canonicalize-net-hook)
285 (setq bbdb-canonicalize-net-hook (list bbdb-canonicalize-net-hook)))
287 ;; Iterate over the hooks until things converge.
290 (let (next (changep nil)
291 hook (hooks bbdb-canonicalize-net-hook))
293 (setq hook (pop hooks))
294 (setq next (funcall hook net))
295 (if (not (equal next net))
298 (setq donep (not changep)))))
299 (setq ad-return-value net)))
301 ;; Transient mark mode hacks.
303 (defadvice exchange-point-and-mark
304 (around mdw-highlight (&optional arg) activate compile)
305 "Maybe don't actually exchange point and mark.
306 If `transient-mark-mode' is on and the mark is inactive, then
307 just activate it. A non-trivial prefix argument will force the
308 usual behaviour. A trivial prefix argument (i.e., just C-u) will
309 activate the mark and temporarily enable `transient-mark-mode' if
311 (cond ((or mark-active
312 (and (not transient-mark-mode) (not arg))
313 (and arg (or (not (consp arg))
314 (not (= (car arg) 4)))))
317 (or transient-mark-mode (setq transient-mark-mode 'only))
318 (set-mark (mark t)))))
320 ;; Functions for sexp diary entries.
322 (defun mdw-not-org-mode (form)
323 "As FORM, but not in Org mode agenda."
324 (and (not mdw-diary-for-org-mode-p)
327 (defun mdw-weekday (l)
328 "Return non-nil if `date' falls on one of the days of the week in L.
329 L is a list of day numbers (from 0 to 6 for Sunday through to
330 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
331 the date stored in `date' falls on a listed day, then the
332 function returns non-nil."
333 (let ((d (calendar-day-of-week date)))
335 (memq (nth d '(sunday monday tuesday wednesday
336 thursday friday saturday)) l))))
338 (defun mdw-discordian-date (date)
339 "Return the Discordian calendar date corresponding to DATE.
341 The return value is (YOLD . st-tibs-day) or (YOLD SEASON DAYNUM DOW).
343 The original is by David Pearson. I modified it to produce date components
344 as output rather than a string."
345 (let* ((days ["Sweetmorn" "Boomtime" "Pungenday"
346 "Prickle-Prickle" "Setting Orange"])
347 (months ["Chaos" "Discord" "Confusion"
348 "Bureaucracy" "Aftermath"])
349 (day-count [0 31 59 90 120 151 181 212 243 273 304 334])
350 (year (- (extract-calendar-year date) 1900))
351 (month (1- (extract-calendar-month date)))
352 (day (1- (extract-calendar-day date)))
353 (julian (+ (aref day-count month) day))
354 (dyear (+ year 3066)))
355 (if (and (= month 1) (= day 28))
356 (cons dyear 'st-tibs-day)
358 (aref months (floor (/ julian 73)))
360 (aref days (mod julian 5))))))
362 (defun mdw-diary-discordian-date ()
363 "Convert the date in `date' to a string giving the Discordian date."
364 (let* ((ddate (mdw-discordian-date date))
365 (tail (format "in the YOLD %d" (car ddate))))
366 (if (eq (cdr ddate) 'st-tibs-day)
367 (format "St Tib's Day %s" tail)
368 (let ((season (cadr ddate))
369 (daynum (caddr ddate))
370 (dayname (cadddr ddate)))
371 (format "%s, the %d%s day of %s %s"
374 (let ((ldig (mod daynum 10)))
375 (cond ((= ldig 1) "st")
382 (defun mdw-todo (&optional when)
383 "Return non-nil today, or on WHEN, whichever is later."
384 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
385 (d (calendar-absolute-from-gregorian date)))
387 (setq w (max w (calendar-absolute-from-gregorian
389 ((not european-calendar-style)
401 (defvar mdw-diary-for-org-mode-p nil)
403 (defadvice org-agenda-list (around mdw-preserve-links activate)
404 (let ((mdw-diary-for-org-mode-p t))
407 (defvar diary-time-regexp nil)
409 (defadvice diary-add-to-list (before mdw-trim-leading-space compile activate)
410 "Trim leading space from the diary entry string."
412 (let ((str (ad-get-arg 1))
416 (setq str (cond ((null str) nil)
417 ((string-match "\\(^\\|\n\\)[ \t]+" str)
418 (replace-match "\\1" nil nil str))
419 ((and mdw-diary-for-org-mode-p
420 (string-match (concat
422 "\\(" diary-time-regexp
423 "\\(-" diary-time-regexp "\\)?"
425 "\\(\t[ \t]*\\| [ \t]+\\)")
427 (replace-match "\\1\\2 " nil nil str))
428 ((and (not mdw-diary-for-org-mode-p)
429 (string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]"
431 (replace-match "\\1" nil nil str))
433 (if (equal str old) (setq done t)))
434 (ad-set-arg 1 str))))
436 (defadvice org-bbdb-anniversaries (after mdw-fixup-list compile activate)
437 "Return a string rather than a list."
440 (dolist (e (let ((ee ad-return-value))
441 (if (atom ee) (list ee) ee)))
443 (when anyp (insert ?\n))
446 (setq ad-return-value
447 (and anyp (buffer-string))))))
449 ;; Fighting with Org-mode's evil key maps.
451 (defvar mdw-evil-keymap-keys
452 '(([S-up] . [?\C-c up])
453 ([S-down] . [?\C-c down])
454 ([S-left] . [?\C-c left])
455 ([S-right] . [?\C-c right])
456 (([M-up] [?\e up]) . [C-up])
457 (([M-down] [?\e down]) . [C-down])
458 (([M-left] [?\e left]) . [C-left])
459 (([M-right] [?\e right]) . [C-right]))
460 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
461 The value is an alist mapping evil keys (as a list, or singleton)
462 to good keys (in the same form).")
464 (defun mdw-clobber-evil-keymap (keymap)
465 "Replace evil key bindings in the KEYMAP.
466 Evil key bindings are defined in `mdw-evil-keymap-keys'."
467 (dolist (entry mdw-evil-keymap-keys)
469 (keys (if (listp (car entry))
472 (replacements (if (listp (cdr entry))
474 (list (cdr entry)))))
477 (setq binding (lookup-key keymap key))
479 (throw 'found nil))))
482 (define-key keymap key nil))
483 (dolist (key replacements)
484 (define-key keymap key binding))))))
486 (defvar mdw-org-latex-defs
488 "\\documentclass{strayman}
489 \\usepackage[utf8]{inputenc}
490 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
491 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
492 ("\\section{%s}" . "\\section*{%s}")
493 ("\\subsection{%s}" . "\\subsection*{%s}")
494 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
495 ("\\paragraph{%s}" . "\\paragraph*{%s}")
496 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))
498 (eval-after-load "org-latex"
499 '(setq org-export-latex-classes
500 (append mdw-org-latex-defs org-export-latex-classes)))
502 (eval-after-load "ox-latex"
503 '(setq org-latex-classes (append mdw-org-latex-defs org-latex-classes)
504 org-latex-default-packages-alist '(("AUTO" "inputenc" t)
512 ("normalem" "ulem" t)
518 "\\tolerance=1000")))
521 (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
522 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
523 org-export-docbook-xslt-stylesheet
524 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
528 (setq glasses-separator "-"
529 glasses-separate-parentheses-p nil
530 glasses-uncapitalize-p t)
532 ;; Some hacks to do with window placement.
534 (defun mdw-clobber-other-windows-showing-buffer (buffer-or-name)
535 "Arrange that no windows on other frames are showing BUFFER-OR-NAME."
536 (interactive "bBuffer: ")
537 (let ((home-frame (selected-frame))
538 (buffer (get-buffer buffer-or-name))
539 (safe-buffer (get-buffer "*scratch*")))
540 (dolist (frame (frame-list))
541 (unless (eq frame home-frame)
542 (dolist (window (window-list frame))
543 (when (eq (window-buffer window) buffer)
544 (set-window-buffer window safe-buffer)))))))
546 (defvar mdw-inhibit-walk-windows nil
547 "If non-nil, then `walk-windows' does nothing.
548 This is used by advice on `switch-to-buffer-other-frame' to inhibit finding
549 buffers in random frames.")
551 (setq display-buffer--other-frame-action
552 '((display-buffer-reuse-window display-buffer-pop-up-frame)
553 (reusable-frames . nil)
554 (inhibit-same-window . t)))
556 (defadvice walk-windows (around mdw-inhibit activate)
557 "If `mdw-inhibit-walk-windows' is non-nil, then do nothing."
558 (and (not mdw-inhibit-walk-windows)
561 (defadvice switch-to-buffer-other-frame
562 (around mdw-always-new-frame activate)
563 "Always make a new frame.
564 Even if an existing window in some random frame looks tempting."
565 (let ((mdw-inhibit-walk-windows t)) ad-do-it))
567 (defadvice display-buffer (before mdw-inhibit-other-frames activate)
568 "Don't try to do anything fancy with other frames.
569 Pretend they don't exist. They might be on other display devices."
572 ;;;--------------------------------------------------------------------------
573 ;;; Improved compilation machinery.
575 ;; Uprated version of M-x compile.
577 (setq compile-command
578 (let ((ncpu (with-temp-buffer
579 (insert-file-contents "/proc/cpuinfo")
581 (count-matches "^processor\\s-*:"))))
582 (format "make -j%d -k" (* 2 ncpu))))
584 (defun mdw-compilation-buffer-name (mode)
585 (concat "*" (downcase mode) ": "
586 (abbreviate-file-name default-directory) "*"))
587 (setq compilation-buffer-name-function 'mdw-compilation-buffer-name)
589 (eval-after-load "compile"
591 (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile)))
593 (defadvice compile (around hack-environment compile activate)
594 "Hack the environment inherited by inferiors in the compilation."
595 (let ((process-environment (copy-tree process-environment)))
596 (setenv "LD_PRELOAD" nil)
599 (defun mdw-compile (command &optional directory comint)
600 "Initiate a compilation COMMAND, maybe in a different DIRECTORY.
601 The DIRECTORY may be nil to not change. If COMINT is t, then
602 start an interactive compilation.
604 Interactively, prompt for the command if the variable
605 `compilation-read-command' is non-nil, or if requested through
606 the prefix argument. Prompt for the directory, and run
607 interactively, if requested through the prefix.
609 Use a prefix of 4, 6, 12, or 14, or type C-u between one and three times, to
610 force prompting for a directory.
612 Use a prefix of 2, 6, 10, or 14, or type C-u three times, to force
613 prompting for the command.
615 Use a prefix of 8, 10, 12, or 14, or type C-u twice or three times,
616 to force interactive compilation."
618 (let* ((prefix (prefix-numeric-value current-prefix-arg))
619 (command (eval compile-command))
620 (dir (and (plusp (logand prefix #x54))
621 (read-directory-name "Compile in directory: "))))
622 (list (if (or compilation-read-command
623 (plusp (logand prefix #x42)))
624 (compilation-read-command command)
627 (plusp (logand prefix #x58)))))
628 (let ((default-directory (or directory default-directory)))
629 (compile command comint)))
633 (defun mdw-find-build-dir (build-file)
635 (let* ((src-dir (file-name-as-directory (expand-file-name ".")))
638 (when (file-exists-p (concat dir build-file))
640 (let ((sub (expand-file-name (file-relative-name src-dir dir)
641 (concat dir "build/"))))
644 (when (file-exists-p (concat sub build-file))
646 (when (string= sub dir) (throw 'give-up nil))
647 (setq sub (file-name-directory (directory-file-name sub))))))
649 (setq dir (file-name-directory
650 (directory-file-name dir))))
651 (throw 'found nil))))))
653 (defun mdw-flymake-make-init ()
654 (let ((build-dir (mdw-find-build-dir "Makefile")))
656 (let ((tmp-src (flymake-init-create-temp-buffer-copy
657 #'flymake-create-temp-inplace)))
658 (flymake-get-syntax-check-program-args
659 tmp-src build-dir t t
660 #'flymake-get-make-cmdline)))))
662 (setq flymake-allowed-file-name-masks
663 '(("\\.\\(?:[cC]\\|cc\\|cpp\\|cxx\\|c\\+\\+\\)\\'"
664 mdw-flymake-make-init)
665 ("\\.\\(?:[hH]\\|hh\\|hpp\\|hxx\\|h\\+\\+\\)\\'"
666 mdw-flymake-master-make-init)
667 ("\\.p[lm]" flymake-perl-init)))
669 (setq flymake-mode-map
670 (let ((map (if (boundp 'flymake-mode-map)
672 (make-sparse-keymap))))
673 (define-key map [?\C-c ?\C-f ?\C-p] 'flymake-goto-prev-error)
674 (define-key map [?\C-c ?\C-f ?\C-n] 'flymake-goto-next-error)
675 (define-key map [?\C-c ?\C-f ?\C-c] 'flymake-compile)
676 (define-key map [?\C-c ?\C-f ?\C-k] 'flymake-stop-all-syntax-checks)
677 (define-key map [?\C-c ?\C-f ?\C-e] 'flymake-popup-current-error-menu)
680 ;;;--------------------------------------------------------------------------
681 ;;; Mail and news hacking.
683 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
684 "Major mode for editing news and mail messages from external programs.
685 Not much right now. Just support for doing MailCrypt stuff."
688 (run-hooks 'mail-setup-hook))
690 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
692 (add-hook 'mdwail-mode-hook
694 (set-buffer-file-coding-system 'utf-8)
695 (make-local-variable 'paragraph-separate)
696 (make-local-variable 'paragraph-start)
697 (setq paragraph-start
698 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
700 (setq paragraph-separate
701 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
702 paragraph-separate))))
704 ;; How to encrypt in mdwmail.
706 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
708 (setq start (save-excursion
709 (goto-char (point-min))
710 (or (search-forward "\n\n" nil t) (point-min)))))
712 (setq end (point-max)))
713 (mc-encrypt-generic recip scm start end from sign))
715 ;; How to sign in mdwmail.
717 (defun mdwmail-mc-sign (key scm start end uclr)
719 (setq start (save-excursion
720 (goto-char (point-min))
721 (or (search-forward "\n\n" nil t) (point-min)))))
723 (setq end (point-max)))
724 (mc-sign-generic key scm start end uclr))
726 ;; Some signature mangling.
728 (defun mdwmail-mangle-signature ()
730 (goto-char (point-min))
731 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
732 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
733 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
735 ;; Insert my login name into message-ids, so I can score replies.
737 (defadvice message-unique-id (after mdw-user-name last activate compile)
738 "Ensure that the user's name appears at the end of the message-id string,
739 so that it can be used for convenient filtering."
740 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
742 ;; Tell my movemail hack where movemail is.
744 ;; This is needed to shup up warnings about LD_PRELOAD.
746 (let ((path exec-path))
748 (let ((try (expand-file-name "movemail" (car path))))
749 (if (file-executable-p try)
750 (setenv "REAL_MOVEMAIL" try))
751 (setq path (cdr path)))))
753 ;; AUTHINFO GENERIC kludge.
755 (defvar nntp-authinfo-generic nil
756 "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'.
758 Use this to arrange for per-server settings.")
760 (defun nntp-open-authinfo-kludge (buffer)
761 "Open a connection to SERVER using `authinfo-kludge'."
762 (let ((proc (start-process "nntpd" buffer
763 "env" (concat "NNTPAUTH="
764 (or nntp-authinfo-generic
766 (error "NNTPAUTH unset")))
767 "authinfo-kludge" nntp-address)))
769 (nntp-wait-for-string "^\r*200")
771 (delete-region (point-min) (point))
774 (eval-after-load "erc"
775 '(load "~/.ercrc.el"))
777 ;; Heavy-duty Gnus patching.
779 (defun mdw-nnimap-transform-headers ()
780 (goto-char (point-min))
781 (let (article lines size string)
784 (while (not (looking-at "\\* [0-9]+ FETCH"))
785 (delete-region (point) (progn (forward-line 1) (point)))
788 (goto-char (match-end 0))
789 ;; Unfold quoted {number} strings.
790 (while (re-search-forward
791 "[^]][ (]{\\([0-9]+\\)}\r?\n"
793 ;; Start of the header section.
794 (or (re-search-forward "] {[0-9]+}\r?\n" nil t)
795 ;; Start of the next FETCH.
796 (re-search-forward "\\* [0-9]+ FETCH" nil t)
799 (setq size (string-to-number (match-string 1)))
800 (delete-region (+ (match-beginning 0) 2) (point))
801 (setq string (buffer-substring (point) (+ (point) size)))
802 (delete-region (point) (+ (point) size))
803 (insert (format "%S" (subst-char-in-string ?\n ?\s string)))
804 ;; [mdw] missing from upstream
808 (and (re-search-forward "UID \\([0-9]+\\)" (line-end-position)
813 (and (re-search-forward "RFC822.SIZE \\([0-9]+\\)"
818 (when (search-forward "BODYSTRUCTURE" (line-end-position) t)
819 (let ((structure (ignore-errors
820 (read (current-buffer)))))
821 (while (and (consp structure)
822 (not (atom (car structure))))
823 (setq structure (car structure)))
825 (stringp (car structure))
826 (equal (upcase (nth 0 structure)) "MESSAGE")
827 (equal (upcase (nth 1 structure)) "RFC822"))
829 (nth 7 structure)))))
830 (delete-region (line-beginning-position) (line-end-position))
831 (insert (format "211 %s Article retrieved." article))
834 (insert (format "Chars: %s\n" size)))
836 (insert (format "Lines: %s\n" lines)))
837 ;; Most servers have a blank line after the headers, but
839 (unless (re-search-forward "^\r$\\|^)\r?$" nil t)
840 (goto-char (point-max)))
841 (delete-region (line-beginning-position) (line-end-position))
845 (eval-after-load 'nnimap
846 '(defalias 'nnimap-transform-headers
847 (symbol-function 'mdw-nnimap-transform-headers)))
849 ;;;--------------------------------------------------------------------------
850 ;;; Utility functions.
852 (or (fboundp 'line-number-at-pos)
853 (defun line-number-at-pos (&optional pos)
854 (let ((opoint (or pos (point))) start)
857 (goto-char (point-min))
863 (1+ (count-lines 1 (point))))))))
865 (defun mdw-uniquify-alist (&rest alists)
866 "Return the concatenation of the ALISTS with duplicate elements removed.
867 The first association with a given key prevails; others are
868 ignored. The input lists are not modified, although they'll
869 probably become garbage."
871 (let ((start-list (cons nil nil)))
872 (mdw-do-uniquify start-list
877 (defun mdw-do-uniquify (done end l rest)
878 "A helper function for mdw-uniquify-alist.
879 The DONE argument is a list whose first element is `nil'. It
880 contains the uniquified alist built so far. The leading `nil' is
881 stripped off at the end of the operation; it's only there so that
882 DONE always references a cons cell. END refers to the final cons
883 cell in the DONE list; it is modified in place each time to avoid
884 the overheads of `append'ing all the time. The L argument is the
885 alist we're currently processing; the remaining alists are given
888 ;; There are several different cases to deal with here.
891 ;; Current list isn't empty. Add the first item to the DONE list if
892 ;; there's not an item with the same KEY already there.
893 (l (or (assoc (car (car l)) done)
895 (setcdr end (cons (car l) nil))
896 (setq end (cdr end))))
897 (mdw-do-uniquify done end (cdr l) rest))
899 ;; The list we were working on is empty. Shunt the next list into the
900 ;; current list position and go round again.
901 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
903 ;; Everything's done. Remove the leading `nil' from the DONE list and
904 ;; return it. Finished!
908 "Insert the current date in a pleasing way."
910 (insert (save-excursion
911 (let ((buffer (get-buffer-create "*tmp*")))
912 (unwind-protect (progn (set-buffer buffer)
914 (shell-command "date +%Y-%m-%d" t)
918 (kill-buffer buffer))))))
920 (defun uuencode (file &optional name)
921 "UUencodes a file, maybe calling it NAME, into the current buffer."
922 (interactive "fInput file name: ")
924 ;; If NAME isn't specified, then guess from the filename.
928 (or (string-match "[^/]*$" file) 0))))
929 (print (format "uuencode `%s' `%s'" file name))
931 ;; Now actually do the thing.
932 (call-process "uuencode" file t nil name))
934 (defvar np-file "~/.np"
935 "*Where the `now-playing' file is.")
937 (defun np (&optional arg)
938 "Grabs a `now-playing' string."
942 (goto-char (point-max))
944 (insert-file-contents np-file)))))
946 (defun mdw-version-< (ver-a ver-b)
947 "Answer whether VER-A is strictly earlier than VER-B.
948 VER-A and VER-B are version numbers, which are strings containing digit
949 sequences separated by `.'."
950 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
951 (split-string ver-a "\\.")))
952 (lb (mapcar (lambda (x) (car (read-from-string x)))
953 (split-string ver-b "\\."))))
956 (cond ((null la) (throw 'done lb))
957 ((null lb) (throw 'done nil))
958 ((< (car la) (car lb)) (throw 'done t))
959 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))
960 (t (throw 'done nil)))))))
962 (defun mdw-check-autorevert ()
963 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
964 This takes into consideration whether it's been found using
965 tramp, which seems to get itself into a twist."
966 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
968 ((and (buffer-file-name)
969 (fboundp 'tramp-tramp-file-p)
970 (tramp-tramp-file-p (buffer-file-name)))
971 (unless global-auto-revert-ignore-buffer
972 (setq global-auto-revert-ignore-buffer 'tramp)))
973 ((eq global-auto-revert-ignore-buffer 'tramp)
974 (setq global-auto-revert-ignore-buffer nil))))
976 (defadvice find-file (after mdw-autorevert activate)
977 (mdw-check-autorevert))
978 (defadvice write-file (after mdw-autorevert activate)
979 (mdw-check-autorevert))
981 (defun mdw-auto-revert ()
982 "Recheck all of the autorevertable buffers, and update VC modelines."
984 (let ((auto-revert-check-vc-info t))
985 (auto-revert-buffers)))
987 (defun comint-send-and-indent ()
991 (indent-for-tab-command)))
993 (defadvice comint-line-beginning-position
994 (around mdw-calculate-it-properly () activate compile)
995 "Calculate the actual line start for multi-line input."
996 (if (or comint-use-prompt-regexp
997 (eq (field-at-pos (point)) 'output))
999 (setq ad-return-value
1000 (constrain-to-field (line-beginning-position) (point)))))
1002 ;;;--------------------------------------------------------------------------
1005 (defadvice dired-maybe-insert-subdir
1006 (around mdw-marked-insertion first activate)
1007 "The DIRNAME may be a list of directory names to insert.
1008 Interactively, if files are marked, then insert all of them.
1009 With a numeric prefix argument, select that many entries near
1010 point; with a non-numeric prefix argument, prompt for listing
1013 (list (dired-get-marked-files nil
1014 (and (integerp current-prefix-arg)
1017 (and current-prefix-arg
1018 (not (integerp current-prefix-arg))
1019 (read-string "Switches for listing: "
1020 (or dired-subdir-switches
1021 dired-actual-switches)))))
1022 (let ((dirs (ad-get-arg 0)))
1023 (dolist (dir (if (listp dirs) dirs (list dirs)))
1027 (defun mdw-dired-run (args &optional syncp)
1028 (interactive (let ((file (dired-get-filename t)))
1029 (list (read-string (format "Arguments for %s: " file))
1030 current-prefix-arg)))
1031 (funcall (if syncp 'shell-command 'async-shell-command)
1032 (concat (shell-quote-argument (dired-get-filename nil))
1035 (defadvice dired-do-flagged-delete
1036 (around mdw-delete-if-prefix-argument activate compile)
1037 (let ((delete-by-moving-to-trash (and (null current-prefix-arg)
1038 delete-by-moving-to-trash)))
1041 (eval-after-load "dired"
1042 '(define-key dired-mode-map "X" 'mdw-dired-run))
1044 ;;;--------------------------------------------------------------------------
1047 (defun mdw-w3m-browse-url (url &optional new-session-p)
1048 "Invoke w3m on the URL in its current window, or at least a different one.
1049 If NEW-SESSION-P, start a new session."
1050 (interactive "sURL: \nP")
1052 (let ((window (selected-window)))
1055 (select-window (or (and (not new-session-p)
1056 (get-buffer-window "*w3m*"))
1058 (if (one-window-p t) (split-window))
1060 (w3m-browse-url url new-session-p))
1061 (select-window window)))))
1063 (eval-after-load 'w3m
1064 '(define-key w3m-mode-map [?\e ?\r] 'w3m-view-this-url-new-session))
1066 (defvar mdw-good-url-browsers
1067 '(browse-url-mozilla
1069 (w3m . mdw-w3m-browse-url)
1071 "List of good browsers for mdw-good-url-browsers.
1072 Each item is a browser function name, or a cons (CHECK . FUNC).
1073 A symbol FOO stands for (FOO . FOO).")
1075 (defun mdw-good-url-browser ()
1076 "Return a good URL browser.
1077 Trundle the list of such things, finding the first item for which
1078 CHECK is fboundp, and returning the correponding FUNC."
1079 (let ((bs mdw-good-url-browsers) b check func answer)
1080 (while (and bs (not answer))
1084 (setq check (car b) func (cdr b))
1085 (setq check b func b))
1087 (setq answer func)))
1090 (eval-after-load "w3m-search"
1094 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
1095 ("gd" "Google Directory"
1096 "http://www.google.com/search?cat=gwd/Top&q=%s")
1097 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
1098 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
1099 ("gi" "Images" "http://images.google.com/images?q=%s")
1101 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
1103 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
1104 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
1105 ("nc-wiki" "nCipher wiki"
1106 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
1107 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
1108 ("lp" "Launchpad bug by number"
1109 "https://bugs.launchpad.net/bugs/%s")
1110 ("lppkg" "Launchpad bugs by package"
1111 "https://bugs.launchpad.net/%s")
1113 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
1114 ("debbug" "Debian bug by number"
1115 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
1116 ("debbugpkg" "Debian bugs by package"
1117 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
1118 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
1119 (add-to-list 'w3m-search-engine-alist
1120 (list (cadr item) (caddr item) nil))
1121 (add-to-list 'w3m-uri-replace-alist
1122 (list (concat "\\`" (car item) ":")
1123 'w3m-search-uri-replace
1126 ;;;--------------------------------------------------------------------------
1127 ;;; Paragraph filling.
1129 ;; Useful variables.
1131 (defvar mdw-fill-prefix nil
1132 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
1133 If there's no fill prefix currently set (by the `fill-prefix'
1134 variable) and there's a match from one of the regexps here, it
1135 gets used to set the fill-prefix for the current operation.
1137 The variable is a list of items of the form `REGEXP . PREFIX'; if
1138 the REGEXP matches, the PREFIX is used to set the fill prefix.
1139 It in turn is a list of things:
1141 STRING -- insert a literal string
1142 (match . N) -- insert the thing matched by bracketed subexpression N
1143 (pad . N) -- a string of whitespace the same width as subexpression N
1144 (expr . FORM) -- the result of evaluating FORM")
1146 (make-variable-buffer-local 'mdw-fill-prefix)
1148 (defvar mdw-hanging-indents
1150 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
1153 "*Standard regexp matching parts of a hanging indent.
1154 This is mainly useful in `auto-fill-mode'.")
1156 ;; Utility functions.
1158 (defun mdw-maybe-tabify (s)
1159 "Tabify or untabify the string S, according to `indent-tabs-mode'."
1160 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
1164 (let ((start (point-min)) (end (point-max)))
1165 (funcall tabfun (point-min) (point-max))
1166 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
1168 (defun mdw-examine-fill-prefixes (l)
1169 "Given a list of dynamic fill prefixes, pick one which matches
1170 context and return the static fill prefix to use. Point must be
1171 at the start of a line, and match data must be saved."
1173 ((looking-at (car (car l)))
1174 (mdw-maybe-tabify (apply #'concat
1175 (mapcar #'mdw-do-prefix-match
1177 (t (mdw-examine-fill-prefixes (cdr l)))))
1179 (defun mdw-maybe-car (p)
1180 "If P is a pair, return (car P), otherwise just return P."
1181 (if (consp p) (car p) p))
1183 (defun mdw-padding (s)
1184 "Return a string the same width as S but made entirely from whitespace."
1185 (let* ((l (length s)) (i 0) (n (make-string l ? )))
1187 (if (= 9 (aref s i))
1192 (defun mdw-do-prefix-match (m)
1193 "Expand a dynamic prefix match element.
1194 See `mdw-fill-prefix' for details."
1195 (cond ((not (consp m)) (format "%s" m))
1196 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
1197 ((eq (car m) 'pad) (mdw-padding (match-string
1198 (mdw-maybe-car (cdr m)))))
1199 ((eq (car m) 'eval) (eval (cdr m)))
1202 (defun mdw-choose-dynamic-fill-prefix ()
1203 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
1204 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
1205 ((not mdw-fill-prefix) fill-prefix)
1209 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
1211 (defadvice do-auto-fill (around mdw-dynamic-fill-prefix () activate compile)
1212 "Handle auto-filling, working out a dynamic fill prefix in the
1213 case where there isn't a sensible static one."
1214 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1217 (defun mdw-fill-paragraph ()
1218 "Fill paragraph, getting a dynamic fill prefix."
1220 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1221 (fill-paragraph nil)))
1223 (defun mdw-standard-fill-prefix (rx &optional mat)
1224 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
1225 This is just a short-cut for setting the thing by hand, and by
1226 design it doesn't cope with anything approximating a complicated
1228 (setq mdw-fill-prefix
1229 `((,(concat rx mdw-hanging-indents)
1231 (pad . ,(or mat 2))))))
1233 ;;;--------------------------------------------------------------------------
1234 ;;; Other common declarations.
1236 ;; Common mode settings.
1238 (defvar mdw-auto-indent t
1239 "Whether to indent automatically after a newline.")
1241 (defun mdw-whitespace-mode (&optional arg)
1242 "Turn on/off whitespace mode, but don't highlight trailing space."
1244 (when (and (boundp 'whitespace-style)
1245 (fboundp 'whitespace-mode))
1246 (let ((whitespace-style (remove 'trailing whitespace-style)))
1247 (whitespace-mode arg))
1248 (setq show-trailing-whitespace whitespace-mode)))
1250 (defvar mdw-do-misc-mode-hacking nil)
1252 (defun mdw-misc-mode-config ()
1253 (and mdw-auto-indent
1254 (cond ((eq major-mode 'lisp-mode)
1255 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
1256 ((derived-mode-p 'slime-repl-mode 'asm-mode 'comint-mode)
1259 (local-set-key "\C-m" 'newline-and-indent))))
1260 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
1261 (local-set-key [C-return] 'newline)
1262 (make-local-variable 'page-delimiter)
1263 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
1264 (setq comment-column 40)
1266 (setq fill-column mdw-text-width)
1267 (and (fboundp 'gtags-mode)
1269 (if (fboundp 'hs-minor-mode)
1270 (trap (hs-minor-mode t))
1271 (outline-minor-mode t))
1273 (trap (turn-on-font-lock)))
1275 (defun mdw-post-local-vars-misc-mode-config ()
1276 (setq whitespace-line-column mdw-text-width)
1277 (when (and mdw-do-misc-mode-hacking
1278 (not buffer-read-only))
1279 (setq show-trailing-whitespace t)
1280 (mdw-whitespace-mode 1)))
1281 (add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
1283 (defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1284 `(progn ,@(mapcar (lambda (func)
1286 (after mdw-angry-fruit-salad activate)
1287 (when mdw-do-misc-mode-hacking
1288 (setq show-trailing-whitespace
1289 (not buffer-read-only))
1290 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1292 (mdw-advise-update-angry-fruit-salad toggle-read-only
1298 (eval-after-load 'gtags
1300 (dolist (key '([mouse-2] [mouse-3]))
1301 (define-key gtags-mode-map key nil))
1302 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1303 (define-key gtags-select-mode-map [C-S-mouse-2]
1304 'gtags-select-tag-by-event)
1305 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1306 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
1308 ;; Backup file handling.
1310 (defvar mdw-backup-disable-regexps nil
1311 "*List of regular expressions: if a file name matches any of
1312 these then the file is not backed up.")
1314 (defun mdw-backup-enable-predicate (name)
1315 "[mdw]'s default backup predicate.
1316 Allows a backup if the standard predicate would allow it, and it
1317 doesn't match any of the regular expressions in
1318 `mdw-backup-disable-regexps'."
1319 (and (normal-backup-enable-predicate name)
1320 (let ((answer t) (list mdw-backup-disable-regexps))
1323 (if (string-match (car list) name)
1325 (setq list (cdr list)))
1327 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
1331 (defun mdw-last-one-out-turn-off-the-lights (frame)
1332 "Disconnect from an X display if this was the last frame on that display."
1333 (let ((frame-display (frame-parameter frame 'display)))
1334 (when (and frame-display
1335 (eq window-system 'x)
1336 (not (some (lambda (fr)
1337 (and (not (eq fr frame))
1338 (string= (frame-parameter fr 'display)
1341 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1342 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1344 ;;;--------------------------------------------------------------------------
1345 ;;; Fullscreen-ness.
1347 (defvar mdw-full-screen-parameters
1348 '((menu-bar-lines . 0)
1349 ;(vertical-scroll-bars . nil)
1351 "Frame parameters to set when making a frame fullscreen.")
1353 (defvar mdw-full-screen-save
1355 "Extra frame parameters to save when setting fullscreen.")
1357 (defun mdw-toggle-full-screen (&optional frame)
1358 "Show the FRAME fullscreen."
1361 (cond ((frame-parameter frame 'fullscreen)
1362 (set-frame-parameter frame 'fullscreen nil)
1363 (modify-frame-parameters
1365 (or (frame-parameter frame 'mdw-full-screen-saved)
1366 (mapcar (lambda (assoc)
1367 (assq (car assoc) default-frame-alist))
1368 mdw-full-screen-parameters))))
1370 (let ((saved (mapcar (lambda (param)
1371 (cons param (frame-parameter frame param)))
1372 (append (mapcar #'car
1373 mdw-full-screen-parameters)
1374 mdw-full-screen-save))))
1375 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1376 (modify-frame-parameters frame mdw-full-screen-parameters)
1377 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1379 ;;;--------------------------------------------------------------------------
1380 ;;; General fontification.
1382 (make-face 'mdw-virgin-face)
1384 (defmacro mdw-define-face (name &rest body)
1385 "Define a face, and make sure it's actually set as the definition."
1389 (copy-face 'mdw-virgin-face ',name)
1390 (defvar ,name ',name)
1391 (put ',name 'face-defface-spec ',body)
1392 (face-spec-set ',name ',body nil)))
1394 (mdw-define-face default
1395 (((type w32)) :family "courier new" :height 85)
1396 (((type x)) :family "6x13" :foundry "trad" :height 130)
1397 (((type color)) :foreground "white" :background "black")
1399 (mdw-define-face fixed-pitch
1400 (((type w32)) :family "courier new" :height 85)
1401 (((type x)) :family "6x13" :foundry "trad" :height 130)
1402 (t :foreground "white" :background "black"))
1403 (mdw-define-face fixed-pitch-serif
1404 (((type w32)) :family "courier new" :height 85 :weight bold)
1405 (((type x)) :family "6x13" :foundry "trad" :height 130 :weight bold)
1406 (t :foreground "white" :background "black" :weight bold))
1407 (if (mdw-emacs-version-p 23)
1408 (mdw-define-face variable-pitch
1409 (((type x)) :family "sans" :height 100))
1410 (mdw-define-face variable-pitch
1411 (((type x)) :family "helvetica" :height 90)))
1412 (mdw-define-face region
1413 (((min-colors 64)) :background "grey30")
1414 (((class color)) :background "blue")
1415 (t :inverse-video t))
1416 (mdw-define-face match
1417 (((class color)) :background "blue")
1418 (t :inverse-video t))
1419 (mdw-define-face mc/cursor-face
1420 (((class color)) :background "red")
1421 (t :inverse-video t))
1422 (mdw-define-face minibuffer-prompt
1424 (mdw-define-face mode-line
1425 (((class color)) :foreground "blue" :background "yellow"
1426 :box (:line-width 1 :style released-button))
1427 (t :inverse-video t))
1428 (mdw-define-face mode-line-inactive
1429 (((class color)) :foreground "yellow" :background "blue"
1430 :box (:line-width 1 :style released-button))
1431 (t :inverse-video t))
1432 (mdw-define-face nobreak-space
1434 (t :inherit escape-glyph :underline t))
1435 (mdw-define-face scroll-bar
1436 (t :foreground "black" :background "lightgrey"))
1437 (mdw-define-face fringe
1438 (t :foreground "yellow"))
1439 (mdw-define-face show-paren-match
1440 (((min-colors 64)) :background "darkgreen")
1441 (((class color)) :background "green")
1443 (mdw-define-face show-paren-mismatch
1444 (((class color)) :background "red")
1445 (t :inverse-video t))
1446 (mdw-define-face highlight
1447 (((min-colors 64)) :background "DarkSeaGreen4")
1448 (((class color)) :background "cyan")
1449 (t :inverse-video t))
1451 (mdw-define-face holiday-face
1452 (t :background "red"))
1453 (mdw-define-face calendar-today-face
1454 (t :foreground "yellow" :weight bold))
1456 (mdw-define-face comint-highlight-prompt
1458 (mdw-define-face comint-highlight-input
1461 (mdw-define-face Man-underline
1462 (((type tty)) :underline t)
1465 (mdw-define-face ido-subdir
1466 (t :foreground "cyan" :weight bold))
1468 (mdw-define-face dired-directory
1469 (t :foreground "cyan" :weight bold))
1470 (mdw-define-face dired-symlink
1471 (t :foreground "cyan"))
1472 (mdw-define-face dired-perm-write
1475 (mdw-define-face trailing-whitespace
1476 (((class color)) :background "red")
1477 (t :inverse-video t))
1478 (mdw-define-face whitespace-line
1479 (((class color)) :background "darkred")
1480 (t :inverse-video t))
1481 (mdw-define-face mdw-punct-face
1482 (((min-colors 64)) :foreground "burlywood2")
1483 (((class color)) :foreground "yellow"))
1484 (mdw-define-face mdw-number-face
1485 (t :foreground "yellow"))
1486 (mdw-define-face mdw-trivial-face)
1487 (mdw-define-face font-lock-function-name-face
1489 (mdw-define-face font-lock-keyword-face
1491 (mdw-define-face font-lock-constant-face
1493 (mdw-define-face font-lock-builtin-face
1495 (mdw-define-face font-lock-type-face
1496 (t :weight bold :slant italic))
1497 (mdw-define-face font-lock-reference-face
1499 (mdw-define-face font-lock-variable-name-face
1501 (mdw-define-face font-lock-comment-delimiter-face
1502 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1503 (((class color)) :foreground "green")
1505 (mdw-define-face font-lock-comment-face
1506 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1507 (((class color)) :foreground "green")
1509 (mdw-define-face font-lock-string-face
1510 (((min-colors 64)) :foreground "SkyBlue1")
1511 (((class color)) :foreground "cyan")
1514 (mdw-define-face message-separator
1515 (t :background "red" :foreground "white" :weight bold))
1516 (mdw-define-face message-cited-text
1517 (default :slant italic)
1518 (((min-colors 64)) :foreground "SkyBlue1")
1519 (((class color)) :foreground "cyan"))
1520 (mdw-define-face message-header-cc
1521 (default :slant italic)
1522 (((min-colors 64)) :foreground "SeaGreen1")
1523 (((class color)) :foreground "green"))
1524 (mdw-define-face message-header-newsgroups
1525 (default :slant italic)
1526 (((min-colors 64)) :foreground "SeaGreen1")
1527 (((class color)) :foreground "green"))
1528 (mdw-define-face message-header-subject
1529 (((min-colors 64)) :foreground "SeaGreen1")
1530 (((class color)) :foreground "green"))
1531 (mdw-define-face message-header-to
1532 (((min-colors 64)) :foreground "SeaGreen1")
1533 (((class color)) :foreground "green"))
1534 (mdw-define-face message-header-xheader
1535 (default :slant italic)
1536 (((min-colors 64)) :foreground "SeaGreen1")
1537 (((class color)) :foreground "green"))
1538 (mdw-define-face message-header-other
1539 (default :slant italic)
1540 (((min-colors 64)) :foreground "SeaGreen1")
1541 (((class color)) :foreground "green"))
1542 (mdw-define-face message-header-name
1543 (default :weight bold)
1544 (((min-colors 64)) :foreground "SeaGreen1")
1545 (((class color)) :foreground "green"))
1547 (mdw-define-face which-func
1550 (mdw-define-face gnus-header-name
1551 (default :weight bold)
1552 (((min-colors 64)) :foreground "SeaGreen1")
1553 (((class color)) :foreground "green"))
1554 (mdw-define-face gnus-header-subject
1555 (((min-colors 64)) :foreground "SeaGreen1")
1556 (((class color)) :foreground "green"))
1557 (mdw-define-face gnus-header-from
1558 (((min-colors 64)) :foreground "SeaGreen1")
1559 (((class color)) :foreground "green"))
1560 (mdw-define-face gnus-header-to
1561 (((min-colors 64)) :foreground "SeaGreen1")
1562 (((class color)) :foreground "green"))
1563 (mdw-define-face gnus-header-content
1564 (default :slant italic)
1565 (((min-colors 64)) :foreground "SeaGreen1")
1566 (((class color)) :foreground "green"))
1568 (mdw-define-face gnus-cite-1
1569 (((min-colors 64)) :foreground "SkyBlue1")
1570 (((class color)) :foreground "cyan"))
1571 (mdw-define-face gnus-cite-2
1572 (((min-colors 64)) :foreground "RoyalBlue2")
1573 (((class color)) :foreground "blue"))
1574 (mdw-define-face gnus-cite-3
1575 (((min-colors 64)) :foreground "MediumOrchid")
1576 (((class color)) :foreground "magenta"))
1577 (mdw-define-face gnus-cite-4
1578 (((min-colors 64)) :foreground "firebrick2")
1579 (((class color)) :foreground "red"))
1580 (mdw-define-face gnus-cite-5
1581 (((min-colors 64)) :foreground "burlywood2")
1582 (((class color)) :foreground "yellow"))
1583 (mdw-define-face gnus-cite-6
1584 (((min-colors 64)) :foreground "SeaGreen1")
1585 (((class color)) :foreground "green"))
1586 (mdw-define-face gnus-cite-7
1587 (((min-colors 64)) :foreground "SlateBlue1")
1588 (((class color)) :foreground "cyan"))
1589 (mdw-define-face gnus-cite-8
1590 (((min-colors 64)) :foreground "RoyalBlue2")
1591 (((class color)) :foreground "blue"))
1592 (mdw-define-face gnus-cite-9
1593 (((min-colors 64)) :foreground "purple2")
1594 (((class color)) :foreground "magenta"))
1595 (mdw-define-face gnus-cite-10
1596 (((min-colors 64)) :foreground "DarkOrange2")
1597 (((class color)) :foreground "red"))
1598 (mdw-define-face gnus-cite-11
1599 (t :foreground "grey"))
1601 (mdw-define-face diff-header
1603 (mdw-define-face diff-index
1605 (mdw-define-face diff-file-header
1607 (mdw-define-face diff-hunk-header
1608 (((min-colors 64)) :foreground "SkyBlue1")
1609 (((class color)) :foreground "cyan"))
1610 (mdw-define-face diff-function
1611 (default :weight bold)
1612 (((min-colors 64)) :foreground "SkyBlue1")
1613 (((class color)) :foreground "cyan"))
1614 (mdw-define-face diff-header
1615 (((min-colors 64)) :background "grey10"))
1616 (mdw-define-face diff-added
1617 (((class color)) :foreground "green"))
1618 (mdw-define-face diff-removed
1619 (((class color)) :foreground "red"))
1620 (mdw-define-face diff-context
1622 (mdw-define-face diff-refine-change
1623 (((min-colors 64)) :background "RoyalBlue4")
1625 (mdw-define-face diff-refine-removed
1626 (((min-colors 64)) :background "#500")
1628 (mdw-define-face diff-refine-added
1629 (((min-colors 64)) :background "#050")
1632 (setq ediff-force-faces t)
1633 (mdw-define-face ediff-current-diff-A
1634 (((min-colors 64)) :background "darkred")
1635 (((class color)) :background "red")
1636 (t :inverse-video t))
1637 (mdw-define-face ediff-fine-diff-A
1638 (((min-colors 64)) :background "red3")
1639 (((class color)) :inverse-video t)
1640 (t :inverse-video nil))
1641 (mdw-define-face ediff-even-diff-A
1642 (((min-colors 64)) :background "#300"))
1643 (mdw-define-face ediff-odd-diff-A
1644 (((min-colors 64)) :background "#300"))
1645 (mdw-define-face ediff-current-diff-B
1646 (((min-colors 64)) :background "darkgreen")
1647 (((class color)) :background "magenta")
1648 (t :inverse-video t))
1649 (mdw-define-face ediff-fine-diff-B
1650 (((min-colors 64)) :background "green4")
1651 (((class color)) :inverse-video t)
1652 (t :inverse-video nil))
1653 (mdw-define-face ediff-even-diff-B
1654 (((min-colors 64)) :background "#020"))
1655 (mdw-define-face ediff-odd-diff-B
1656 (((min-colors 64)) :background "#020"))
1657 (mdw-define-face ediff-current-diff-C
1658 (((min-colors 64)) :background "darkblue")
1659 (((class color)) :background "blue")
1660 (t :inverse-video t))
1661 (mdw-define-face ediff-fine-diff-C
1662 (((min-colors 64)) :background "blue1")
1663 (((class color)) :inverse-video t)
1664 (t :inverse-video nil))
1665 (mdw-define-face ediff-even-diff-C
1666 (((min-colors 64)) :background "#004"))
1667 (mdw-define-face ediff-odd-diff-C
1668 (((min-colors 64)) :background "#004"))
1669 (mdw-define-face ediff-current-diff-Ancestor
1670 (((min-colors 64)) :background "#630")
1671 (((class color)) :background "blue")
1672 (t :inverse-video t))
1673 (mdw-define-face ediff-even-diff-Ancestor
1674 (((min-colors 64)) :background "#320"))
1675 (mdw-define-face ediff-odd-diff-Ancestor
1676 (((min-colors 64)) :background "#320"))
1678 (mdw-define-face magit-hash
1679 (((min-colors 64)) :foreground "grey40")
1680 (((class color)) :foreground "blue"))
1681 (mdw-define-face magit-diff-hunk-heading
1682 (((min-colors 64)) :foreground "grey70" :background "grey25")
1683 (((class color)) :foreground "yellow"))
1684 (mdw-define-face magit-diff-hunk-heading-highlight
1685 (((min-colors 64)) :foreground "grey70" :background "grey35")
1686 (((class color)) :foreground "yellow" :background "blue"))
1687 (mdw-define-face magit-diff-added
1688 (((min-colors 64)) :foreground "#ddffdd" :background "#335533")
1689 (((class color)) :foreground "green"))
1690 (mdw-define-face magit-diff-added-highlight
1691 (((min-colors 64)) :foreground "#cceecc" :background "#336633")
1692 (((class color)) :foreground "green" :background "blue"))
1693 (mdw-define-face magit-diff-removed
1694 (((min-colors 64)) :foreground "#ffdddd" :background "#553333")
1695 (((class color)) :foreground "red"))
1696 (mdw-define-face magit-diff-removed-highlight
1697 (((min-colors 64)) :foreground "#eecccc" :background "#663333")
1698 (((class color)) :foreground "red" :background "blue"))
1699 (mdw-define-face magit-blame-heading
1700 (((min-colors 64)) :foreground "white" :background "grey25"
1701 :weight normal :slant normal)
1702 (((class color)) :foreground "white" :background "blue"
1703 :weight normal :slant normal))
1704 (mdw-define-face magit-blame-name
1705 (t :inherit magit-blame-heading :slant italic))
1706 (mdw-define-face magit-blame-date
1707 (((min-colors 64)) :inherit magit-blame-heading :foreground "grey60")
1708 (((class color)) :inherit magit-blame-heading :foreground "cyan"))
1709 (mdw-define-face magit-blame-summary
1710 (t :inherit magit-blame-heading :weight bold))
1712 (mdw-define-face dylan-header-background
1713 (((min-colors 64)) :background "NavyBlue")
1714 (((class color)) :background "blue"))
1716 (mdw-define-face erc-input-face
1717 (t :foreground "red"))
1719 (mdw-define-face woman-bold
1721 (mdw-define-face woman-italic
1724 (eval-after-load "rst"
1726 (mdw-define-face rst-level-1-face
1727 (t :foreground "SkyBlue1" :weight bold))
1728 (mdw-define-face rst-level-2-face
1729 (t :foreground "SeaGreen1" :weight bold))
1730 (mdw-define-face rst-level-3-face
1732 (mdw-define-face rst-level-4-face
1734 (mdw-define-face rst-level-5-face
1736 (mdw-define-face rst-level-6-face
1739 (mdw-define-face p4-depot-added-face
1740 (t :foreground "green"))
1741 (mdw-define-face p4-depot-branch-op-face
1742 (t :foreground "yellow"))
1743 (mdw-define-face p4-depot-deleted-face
1744 (t :foreground "red"))
1745 (mdw-define-face p4-depot-unmapped-face
1746 (t :foreground "SkyBlue1"))
1747 (mdw-define-face p4-diff-change-face
1748 (t :foreground "yellow"))
1749 (mdw-define-face p4-diff-del-face
1750 (t :foreground "red"))
1751 (mdw-define-face p4-diff-file-face
1752 (t :foreground "SkyBlue1"))
1753 (mdw-define-face p4-diff-head-face
1754 (t :background "grey10"))
1755 (mdw-define-face p4-diff-ins-face
1756 (t :foreground "green"))
1758 (mdw-define-face w3m-anchor-face
1759 (t :foreground "SkyBlue1" :underline t))
1760 (mdw-define-face w3m-arrived-anchor-face
1761 (t :foreground "SkyBlue1" :underline t))
1763 (mdw-define-face whizzy-slice-face
1764 (t :background "grey10"))
1765 (mdw-define-face whizzy-error-face
1766 (t :background "darkred"))
1768 ;; Ellipses used to indicate hidden text (and similar).
1769 (mdw-define-face mdw-ellipsis-face
1770 (((type tty)) :foreground "blue") (t :foreground "grey60"))
1771 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
1772 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
1773 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
1774 (bar (make-glyph-code ?| mdw-ellipsis-face)))
1775 (set-display-table-slot standard-display-table 0 dollar)
1776 (set-display-table-slot standard-display-table 1 backslash)
1777 (set-display-table-slot standard-display-table 4
1778 (vector dot dot dot))
1779 (set-display-table-slot standard-display-table 5 bar))
1781 ;;;--------------------------------------------------------------------------
1784 (mdw-define-face mdw-point-overlay-face
1786 (((min-colors 64)) :background "darkblue")
1787 (((class color)) :background "blue")
1788 (((type tty) (class mono)) :inverse-video t))
1790 (defvar mdw-point-overlay-fringe-display '(vertical-bar . vertical-bar))
1792 (defun mdw-configure-point-overlay ()
1793 (let ((ov (make-overlay 0 0)))
1794 (overlay-put ov 'priority 0)
1795 (let* ((fringe (or mdw-point-overlay-fringe-display (cons nil nil)))
1796 (left (car fringe)) (right (cdr fringe))
1800 (put-text-property 0 1 'display `(left-fringe ,left) ss)
1801 (setq s (concat s ss))))
1804 (put-text-property 0 1 'display `(right-fringe ,right) ss)
1805 (setq s (concat s ss))))
1806 (when (or left right)
1807 (overlay-put ov 'before-string s)))
1808 (overlay-put ov 'face 'mdw-point-overlay-face)
1812 (defvar mdw-point-overlay (mdw-configure-point-overlay)
1813 "An overlay used for showing where point is in the selected window.")
1814 (defun mdw-reconfigure-point-overlay ()
1816 (setq mdw-point-overlay (mdw-configure-point-overlay)))
1818 (defun mdw-remove-point-overlay ()
1819 "Remove the current-point overlay."
1820 (delete-overlay mdw-point-overlay))
1822 (defun mdw-update-point-overlay ()
1823 "Mark the current point position with an overlay."
1824 (if (not mdw-point-overlay-mode)
1825 (mdw-remove-point-overlay)
1826 (overlay-put mdw-point-overlay 'window (selected-window))
1827 (move-overlay mdw-point-overlay
1828 (line-beginning-position)
1829 (+ (line-end-position) 1))))
1831 (defvar mdw-point-overlay-buffers nil
1832 "List of buffers using `mdw-point-overlay-mode'.")
1834 (define-minor-mode mdw-point-overlay-mode
1835 "Indicate current line with an overlay."
1837 (let ((buffer (current-buffer)))
1838 (setq mdw-point-overlay-buffers
1839 (mapcan (lambda (buf)
1840 (if (and (buffer-live-p buf)
1841 (not (eq buf buffer)))
1843 mdw-point-overlay-buffers))
1844 (if mdw-point-overlay-mode
1845 (setq mdw-point-overlay-buffers
1846 (cons buffer mdw-point-overlay-buffers))))
1847 (cond (mdw-point-overlay-buffers
1848 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
1849 (add-hook 'post-command-hook 'mdw-update-point-overlay))
1851 (mdw-remove-point-overlay)
1852 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
1853 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
1855 (define-globalized-minor-mode mdw-global-point-overlay-mode
1856 mdw-point-overlay-mode
1857 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
1859 ;;;--------------------------------------------------------------------------
1860 ;;; C programming configuration.
1862 ;; Make C indentation nice.
1864 (defun mdw-c-lineup-arglist (langelem)
1865 "Hack for DWIMmery in c-lineup-arglist."
1867 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1869 (c-lineup-arglist langelem)))
1871 (defun mdw-c-indent-extern-mumble (langelem)
1872 "Indent `extern \"...\" {' lines."
1874 (back-to-indentation)
1876 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1880 (defun mdw-c-indent-arglist-nested (langelem)
1881 "Indent continued argument lists.
1882 If we've nested more than one argument list, then only introduce a single
1883 indentation anyway."
1884 (let ((context c-syntactic-context)
1885 (pos (c-langelem-2nd-pos c-syntactic-element))
1886 (should-indent-p t))
1888 (eq (caar context) 'arglist-cont-nonempty))
1889 (when (and (= (caddr (pop context)) pos)
1891 (memq (caar context) '(arglist-intro
1892 arglist-cont-nonempty)))
1893 (setq should-indent-p nil)))
1894 (if should-indent-p '+ 0)))
1896 (defvar mdw-define-c-styles-hook nil
1897 "Hook run when `cc-mode' starts up to define styles.")
1899 (defmacro mdw-define-c-style (name &rest assocs)
1900 "Define a C style, called NAME (a symbol), setting ASSOCs.
1901 A function, named `mdw-define-c-style/NAME', is defined to actually install
1902 the style using `c-add-style', and added to the hook
1903 `mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
1905 (declare (indent defun))
1906 (let* ((name-string (symbol-name name))
1907 (func (intern (concat "mdw-define-c-style/" name-string))))
1909 (defun ,func () (c-add-style ,name-string ',assocs))
1910 (and (featurep 'cc-mode) (,func))
1911 (add-hook 'mdw-define-c-styles-hook ',func))))
1913 (eval-after-load "cc-mode"
1914 '(run-hooks 'mdw-define-c-styles-hook))
1916 (mdw-define-c-style mdw-trustonic-c
1917 (c-basic-offset . 4)
1918 (comment-column . 0)
1919 (c-indent-comment-alist (anchored-comment . (column . 0))
1920 (end-block . (space . 1))
1921 (cpp-end-block . (space . 1))
1922 (other . (space . 1)))
1923 (c-class-key . "class")
1924 (c-backslash-column . 0)
1925 (c-auto-align-backslashes . nil)
1926 (c-label-minimum-indentation . 0)
1927 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1928 (defun-open . (add 0 c-indent-one-line-block))
1929 (arglist-cont-nonempty . mdw-c-indent-arglist-nested)
1930 (topmost-intro . mdw-c-indent-extern-mumble)
1931 (cpp-define-intro . 0)
1933 (inextern-lang . [0])
1939 (statement-cont . +)
1940 (statement-case-intro . +)))
1942 (mdw-define-c-style mdw-c
1943 (c-basic-offset . 2)
1944 (comment-column . 40)
1945 (c-class-key . "class")
1946 (c-backslash-column . 72)
1947 (c-label-minimum-indentation . 0)
1948 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1949 (defun-open . (add 0 c-indent-one-line-block))
1950 (arglist-cont-nonempty . mdw-c-lineup-arglist)
1951 (topmost-intro . mdw-c-indent-extern-mumble)
1952 (cpp-define-intro . 0)
1954 (inextern-lang . [0])
1960 (statement-cont . +)
1961 (statement-case-intro . +)))
1963 (defun mdw-set-default-c-style (modes style)
1964 "Update the default CC Mode style for MODES to be STYLE.
1966 MODES may be a list of major mode names or a singleton. STYLE is a style
1968 (let ((modes (if (listp modes) modes (list modes)))
1969 (style (symbol-name style)))
1970 (setq c-default-style
1971 (append (mapcar (lambda (mode)
1974 (remove-if (lambda (assoc)
1975 (memq (car assoc) modes))
1976 (if (listp c-default-style)
1978 (list (cons 'other c-default-style))))))))
1979 (setq c-default-style "mdw-c")
1981 (mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
1983 (defvar mdw-c-comment-fill-prefix
1984 `((,(concat "\\([ \t]*/?\\)"
1987 "\\([A-Za-z]+:[ \t]*\\)?"
1988 mdw-hanging-indents)
1989 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1990 "Fill prefix matching C comments (both kinds).")
1992 (defun mdw-fontify-c-and-c++ ()
1994 ;; Fiddle with some syntax codes.
1995 (modify-syntax-entry ?* ". 23")
1996 (modify-syntax-entry ?/ ". 124b")
1997 (modify-syntax-entry ?\n "> b")
2000 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2002 ;; Now define things to be fontified.
2003 (make-local-variable 'font-lock-keywords)
2005 (mdw-regexps "alignas" ;C11 macro, C++11
2007 "and" ;C++, C95 macro
2008 "and_eq" ;C++, C95 macro
2009 "asm" ;K&R, C++, GCC
2010 "atomic" ;C11 macro, C++11 template type
2012 "bitand" ;C++, C95 macro
2013 "bitor" ;C++, C95 macro
2014 "bool" ;C++, C99 macro
2019 "char16_t" ;C++11, C11 library type
2020 "char32_t" ;C++11, C11 library type
2022 "complex" ;C99 macro, C++ template type
2023 "compl" ;C++, C95 macro
2027 "continue" ;K&R, C89
2029 "defined" ;C89 preprocessor
2036 ;; "entry" ;K&R -- never used
2047 "imaginary" ;C99 macro
2048 "inline" ;C++, C99, GCC
2055 "noreturn" ;C11 macro
2056 "not" ;C++, C95 macro
2057 "not_eq" ;C++, C95 macro
2060 "or" ;C++, C95 macro
2061 "or_eq" ;C++, C95 macro
2065 "register" ;K&R, C89
2066 "reinterpret_cast" ;C++
2073 "static_assert" ;C11 macro, C++11
2080 "thread_local" ;C11 macro, C++11
2086 "unsigned" ;K&R, C89
2091 "wchar_t" ;C++, C89 library type
2093 "xor" ;C++, C95 macro
2094 "xor_eq" ;C++, C95 macro
2103 "_Pragma" ;C99 preprocessor
2104 "_Static_assert" ;C11
2105 "_Thread_local" ;C11
2108 "__attribute__" ;GCC
2111 "__extension__" ;GCC
2121 (mdw-regexps "false" ;C++, C99 macro
2123 "true" ;C++, C99 macro
2125 (preprocessor-keywords
2126 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
2127 "ident" "if" "ifdef" "ifndef" "import" "include"
2128 "line" "pragma" "unassert" "undef" "warning"))
2130 (mdw-regexps "class" "defs" "encode" "end" "implementation"
2131 "interface" "private" "protected" "protocol" "public"
2134 (setq font-lock-keywords
2137 ;; Fontify include files as strings.
2138 (list (concat "^[ \t]*\\#[ \t]*"
2139 "\\(include\\|import\\)"
2140 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
2141 '(2 font-lock-string-face))
2143 ;; Preprocessor directives are `references'?.
2144 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
2145 preprocessor-keywords
2146 "\\)\\>\\|[0-9]+\\|$\\)\\)")
2147 '(1 font-lock-keyword-face))
2149 ;; Handle the keywords defined above.
2150 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
2151 '(0 font-lock-keyword-face))
2153 (list (concat "\\<\\(" c-keywords "\\)\\>")
2154 '(0 font-lock-keyword-face))
2156 (list (concat "\\<\\(" c-builtins "\\)\\>")
2157 '(0 font-lock-variable-name-face))
2159 ;; Handle numbers too.
2161 ;; This looks strange, I know. It corresponds to the
2162 ;; preprocessor's idea of what a number looks like, rather than
2163 ;; anything sensible.
2164 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2165 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2166 '(0 mdw-number-face))
2168 ;; And anything else is punctuation.
2169 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2170 '(0 mdw-punct-face))))))
2172 (define-derived-mode sod-mode c-mode "Sod"
2173 "Major mode for editing Sod code.")
2174 (push '("\\.sod$" . sod-mode) auto-mode-alist)
2176 (dolist (hook '(c-mode-hook objc-mode-hook c++-mode-hook))
2177 (add-hook hook 'mdw-misc-mode-config t)
2178 (add-hook hook 'mdw-fontify-c-and-c++ t))
2180 ;;;--------------------------------------------------------------------------
2183 (define-derived-mode apcalc-mode c-mode "AP Calc"
2184 "Major mode for editing Calc code.")
2186 (defun mdw-fontify-apcalc ()
2188 ;; Fiddle with some syntax codes.
2189 (modify-syntax-entry ?* ". 23")
2190 (modify-syntax-entry ?/ ". 14")
2193 (setq comment-start "/* ")
2194 (setq comment-end " */")
2195 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2197 ;; Now define things to be fontified.
2198 (make-local-variable 'font-lock-keywords)
2200 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
2201 "do" "else" "exit" "for" "global" "goto" "help" "if"
2202 "local" "mat" "obj" "print" "quit" "read" "return"
2203 "show" "static" "switch" "while" "write")))
2205 (setq font-lock-keywords
2208 ;; Handle the keywords defined above.
2209 (list (concat "\\<\\(" c-keywords "\\)\\>")
2210 '(0 font-lock-keyword-face))
2212 ;; Handle numbers too.
2214 ;; This looks strange, I know. It corresponds to the
2215 ;; preprocessor's idea of what a number looks like, rather than
2216 ;; anything sensible.
2217 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2218 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2219 '(0 mdw-number-face))
2221 ;; And anything else is punctuation.
2222 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2223 '(0 mdw-punct-face))))))
2226 (add-hook 'apcalc-mode-hook 'mdw-misc-mode-config t)
2227 (add-hook 'apcalc-mode-hook 'mdw-fontify-apcalc t))
2229 ;;;--------------------------------------------------------------------------
2230 ;;; Java programming configuration.
2232 ;; Make indentation nice.
2234 (mdw-define-c-style mdw-java
2235 (c-basic-offset . 2)
2236 (c-backslash-column . 72)
2237 (c-offsets-alist (substatement-open . 0)
2242 (statement-case-intro . +)))
2243 (mdw-set-default-c-style 'java-mode 'mdw-java)
2245 ;; Declare Java fontification style.
2247 (defun mdw-fontify-java ()
2249 ;; Fiddle with some syntax codes.
2250 (modify-syntax-entry ?@ ".")
2251 (modify-syntax-entry ?@ "." font-lock-syntax-table)
2254 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2256 ;; Now define things to be fontified.
2257 (make-local-variable 'font-lock-keywords)
2258 (let ((java-keywords
2259 (mdw-regexps "abstract" "assert"
2260 "boolean" "break" "byte"
2261 "case" "catch" "char" "class" "const" "continue"
2262 "default" "do" "double"
2263 "else" "enum" "extends"
2264 "final" "finally" "float" "for"
2266 "if" "implements" "import" "instanceof" "int"
2270 "package" "private" "protected" "public"
2272 "short" "static" "strictfp" "switch" "synchronized"
2273 "throw" "throws" "transient" "try"
2278 (mdw-regexps "false" "null" "super" "this" "true")))
2280 (setq font-lock-keywords
2283 ;; Handle the keywords defined above.
2284 (list (concat "\\<\\(" java-keywords "\\)\\>")
2285 '(0 font-lock-keyword-face))
2287 ;; Handle the magic builtins defined above.
2288 (list (concat "\\<\\(" java-builtins "\\)\\>")
2289 '(0 font-lock-variable-name-face))
2291 ;; Handle numbers too.
2293 ;; The following isn't quite right, but it's close enough.
2294 (list (concat "\\<\\("
2295 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2296 "[0-9]+\\(\\.[0-9]*\\|\\)"
2297 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2299 '(0 mdw-number-face))
2301 ;; And anything else is punctuation.
2302 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2303 '(0 mdw-punct-face))))))
2306 (add-hook 'java-mode-hook 'mdw-misc-mode-config t)
2307 (add-hook 'java-mode-hook 'mdw-fontify-java t))
2309 ;;;--------------------------------------------------------------------------
2310 ;;; Javascript programming configuration.
2312 (defun mdw-javascript-style ()
2313 (setq js-indent-level 2)
2314 (setq js-expr-indent-offset 0))
2316 (defun mdw-fontify-javascript ()
2319 (mdw-javascript-style)
2320 (setq js-auto-indent-flag t)
2322 ;; Now define things to be fontified.
2323 (make-local-variable 'font-lock-keywords)
2324 (let ((javascript-keywords
2325 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
2326 "char" "class" "const" "continue" "debugger" "default"
2327 "delete" "do" "double" "else" "enum" "export" "extends"
2328 "final" "finally" "float" "for" "function" "goto" "if"
2329 "implements" "import" "in" "instanceof" "int"
2330 "interface" "let" "long" "native" "new" "package"
2331 "private" "protected" "public" "return" "short"
2332 "static" "super" "switch" "synchronized" "throw"
2333 "throws" "transient" "try" "typeof" "var" "void"
2334 "volatile" "while" "with" "yield"))
2335 (javascript-builtins
2336 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
2337 "arguments" "this")))
2339 (setq font-lock-keywords
2342 ;; Handle the keywords defined above.
2343 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
2344 '(0 font-lock-keyword-face))
2346 ;; Handle the predefined builtins defined above.
2347 (list (concat "\\_<\\(" javascript-builtins "\\)\\_>")
2348 '(0 font-lock-variable-name-face))
2350 ;; Handle numbers too.
2352 ;; The following isn't quite right, but it's close enough.
2353 (list (concat "\\_<\\("
2354 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2355 "[0-9]+\\(\\.[0-9]*\\|\\)"
2356 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2358 '(0 mdw-number-face))
2360 ;; And anything else is punctuation.
2361 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2362 '(0 mdw-punct-face))))))
2365 (add-hook 'js-mode-hook 'mdw-misc-mode-config t)
2366 (add-hook 'js-mode-hook 'mdw-fontify-javascript t))
2368 ;;;--------------------------------------------------------------------------
2369 ;;; Scala programming configuration.
2371 (defun mdw-fontify-scala ()
2374 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2376 ;; Define things to be fontified.
2377 (make-local-variable 'font-lock-keywords)
2378 (let ((scala-keywords
2379 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
2380 "extends" "final" "finally" "for" "forSome" "if"
2381 "implicit" "import" "lazy" "match" "new" "object"
2382 "override" "package" "private" "protected" "return"
2383 "sealed" "throw" "trait" "try" "type" "val"
2384 "var" "while" "with" "yield"))
2386 (mdw-regexps "false" "null" "super" "this" "true"))
2387 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
2389 (setq font-lock-keywords
2392 ;; Magical identifiers between backticks.
2393 (list (concat "`\\([^`]+\\)`")
2394 '(1 font-lock-variable-name-face))
2396 ;; Handle the keywords defined above.
2397 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
2398 '(0 font-lock-keyword-face))
2400 ;; Handle the constants defined above.
2401 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
2402 '(0 font-lock-variable-name-face))
2404 ;; Magical identifiers between backticks.
2405 (list (concat "`\\([^`]+\\)`")
2406 '(1 font-lock-variable-name-face))
2408 ;; Handle numbers too.
2410 ;; As usual, not quite right.
2411 (list (concat "\\_<\\("
2412 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2413 "[0-9]+\\(\\.[0-9]*\\|\\)"
2414 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2416 '(0 mdw-number-face))
2418 ;; And everything else is punctuation.
2419 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2420 '(0 mdw-punct-face)))
2422 font-lock-syntactic-keywords
2425 ;; Single quotes around characters. But not when used to quote
2426 ;; symbol names. Ugh.
2427 (list (concat "\\('\\)"
2429 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
2430 "u+" "[0-9a-fA-F]\\{4\\}"
2431 "\\|" "\\\\" "[0-7]\\{1,3\\}"
2432 "\\|" "\\\\" "." "\\)"
2438 (add-hook 'scala-mode-hook 'mdw-misc-mode-config t)
2439 (add-hook 'scala-mode-hook 'mdw-fontify-scala t))
2441 ;;;--------------------------------------------------------------------------
2442 ;;; C# programming configuration.
2444 ;; Make indentation nice.
2446 (mdw-define-c-style mdw-csharp
2447 (c-basic-offset . 2)
2448 (c-backslash-column . 72)
2449 (c-offsets-alist (substatement-open . 0)
2454 (statement-case-intro . +)))
2455 (mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
2457 ;; Declare C# fontification style.
2459 (defun mdw-fontify-csharp ()
2462 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2464 ;; Now define things to be fontified.
2465 (make-local-variable 'font-lock-keywords)
2466 (let ((csharp-keywords
2467 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
2468 "char" "checked" "class" "const" "continue" "decimal"
2469 "default" "delegate" "do" "double" "else" "enum"
2470 "event" "explicit" "extern" "finally" "fixed" "float"
2471 "for" "foreach" "goto" "if" "implicit" "in" "int"
2472 "interface" "internal" "is" "lock" "long" "namespace"
2473 "new" "object" "operator" "out" "override" "params"
2474 "private" "protected" "public" "readonly" "ref"
2475 "return" "sbyte" "sealed" "short" "sizeof"
2476 "stackalloc" "static" "string" "struct" "switch"
2477 "throw" "try" "typeof" "uint" "ulong" "unchecked"
2478 "unsafe" "ushort" "using" "virtual" "void" "volatile"
2482 (mdw-regexps "base" "false" "null" "this" "true")))
2484 (setq font-lock-keywords
2487 ;; Handle the keywords defined above.
2488 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
2489 '(0 font-lock-keyword-face))
2491 ;; Handle the magic builtins defined above.
2492 (list (concat "\\<\\(" csharp-builtins "\\)\\>")
2493 '(0 font-lock-variable-name-face))
2495 ;; Handle numbers too.
2497 ;; The following isn't quite right, but it's close enough.
2498 (list (concat "\\<\\("
2499 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2500 "[0-9]+\\(\\.[0-9]*\\|\\)"
2501 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2503 '(0 mdw-number-face))
2505 ;; And anything else is punctuation.
2506 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2507 '(0 mdw-punct-face))))))
2509 (define-derived-mode csharp-mode java-mode "C#"
2510 "Major mode for editing C# code.")
2512 (add-hook 'csharp-mode-hook 'mdw-fontify-csharp t)
2514 ;;;--------------------------------------------------------------------------
2515 ;;; F# programming configuration.
2517 (setq fsharp-indent-offset 2)
2519 (defun mdw-fontify-fsharp ()
2521 (let ((punct "=<>+-*/|&%!@?"))
2523 ((>= i (length punct)))
2524 (modify-syntax-entry (aref punct i) ".")))
2526 (modify-syntax-entry ?_ "_")
2527 (modify-syntax-entry ?( "(")
2528 (modify-syntax-entry ?) ")")
2530 (setq indent-tabs-mode nil)
2532 (let ((fsharp-keywords
2533 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
2535 "checked" "class" "component" "const" "constraint"
2536 "constructor" "continue"
2537 "default" "delegate" "do" "done" "downcast" "downto"
2538 "eager" "elif" "else" "end" "exception" "extern"
2539 "finally" "fixed" "for" "fori" "fun" "function"
2542 "if" "in" "include" "inherit" "inline" "interface"
2545 "match" "measure" "member" "method" "mixin" "module"
2548 "object" "of" "open" "or" "override"
2549 "parallel" "params" "private" "process" "protected"
2551 "rec" "recursive" "return"
2552 "sealed" "sig" "static" "struct"
2553 "tailcall" "then" "to" "trait" "try" "type"
2555 "val" "virtual" "void" "volatile"
2556 "when" "while" "with"
2560 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
2561 "base" "false" "null" "true"))
2564 (mdw-regexps "do" "let" "return" "use" "yield"))
2566 (preprocessor-keywords
2567 (mdw-regexps "if" "indent" "else" "endif")))
2569 (setq font-lock-keywords
2570 (list (list (concat "\\(^\\|[^\"]\\)"
2573 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
2578 '(2 font-lock-comment-face))
2580 (list (concat "'" "\\("
2583 "\\|" "[0-9][0-9][0-9]"
2584 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
2585 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
2591 "\\(" "\\\\" "\\(.\\|\n\\)"
2594 '(0 font-lock-string-face))
2596 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
2597 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
2599 "\\_<\\(" fsharp-keywords "\\)\\_>")
2600 '(0 font-lock-keyword-face))
2601 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
2602 '(0 font-lock-variable-name-face))
2604 (list (concat "\\_<"
2605 "\\(" "0[bB][01]+" "\\|"
2607 "0[xX][0-9a-fA-F]+" "\\)"
2608 "\\(" "lf\\|LF" "\\|"
2609 "[uU]?[ysnlL]?" "\\)"
2616 "\\([eE][-+]?[0-9]+\\)?"
2621 '(0 mdw-number-face))
2623 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2624 '(0 mdw-punct-face))))))
2626 (defun mdw-fontify-inferior-fsharp ()
2627 (mdw-fontify-fsharp)
2628 (setq font-lock-keywords
2629 (append (list (list "^[#-]" '(0 font-lock-comment-face))
2630 (list "^>" '(0 font-lock-keyword-face)))
2631 font-lock-keywords)))
2634 (add-hook 'fsharp-mode-hook 'mdw-misc-mode-config t)
2635 (add-hook 'fsharp-mode-hook 'mdw-fontify-fsharp t)
2636 (add-hook 'inferior-fsharp-mode-hooks 'mdw-fontify-inferior-fsharp t))
2638 ;;;--------------------------------------------------------------------------
2639 ;;; Go programming configuration.
2641 (defun mdw-fontify-go ()
2643 (make-local-variable 'font-lock-keywords)
2645 (mdw-regexps "break" "case" "chan" "const" "continue"
2646 "default" "defer" "else" "fallthrough" "for"
2647 "func" "go" "goto" "if" "import"
2648 "interface" "map" "package" "range" "return"
2649 "select" "struct" "switch" "type" "var"))
2651 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
2652 "float32" "float64" "int" "uint8" "int16" "int32"
2653 "int64" "rune" "string" "uint" "uint8" "uint16"
2654 "uint32" "uint64" "uintptr" "void"
2655 "false" "iota" "nil" "true"
2657 "append" "cap" "copy" "delete" "imag" "len" "make"
2658 "new" "panic" "real" "recover")))
2660 (setq font-lock-keywords
2663 ;; Handle the keywords defined above.
2664 (list (concat "\\<\\(" go-keywords "\\)\\>")
2665 '(0 font-lock-keyword-face))
2666 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
2667 '(0 font-lock-variable-name-face))
2669 ;; Strings and characters.
2671 "\\(" "[^\\']" "\\|"
2673 "\\(" "[abfnrtv\\'\"]" "\\|"
2674 "[0-7]\\{3\\}" "\\|"
2675 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
2676 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
2677 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
2681 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
2685 '(0 font-lock-string-face))
2687 ;; Handle numbers too.
2689 ;; The following isn't quite right, but it's close enough.
2690 (list (concat "\\<\\("
2691 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2692 "[0-9]+\\(\\.[0-9]*\\|\\)"
2693 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
2694 '(0 mdw-number-face))
2696 ;; And anything else is punctuation.
2697 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2698 '(0 mdw-punct-face))))))
2700 (add-hook 'go-mode-hook 'mdw-misc-mode-config t)
2701 (add-hook 'go-mode-hook 'mdw-fontify-go t))
2703 ;;;--------------------------------------------------------------------------
2704 ;;; Rust programming configuration.
2706 (setq-default rust-indent-offset 2)
2708 (defun mdw-self-insert-and-indent (count)
2710 (self-insert-command count)
2711 (indent-according-to-mode))
2713 (defun mdw-fontify-rust ()
2715 ;; Hack syntax categories.
2716 (modify-syntax-entry ?$ ".")
2717 (modify-syntax-entry ?% ".")
2718 (modify-syntax-entry ?= ".")
2720 ;; Fontify keywords and things.
2721 (make-local-variable 'font-lock-keywords)
2722 (let ((rust-keywords
2723 (mdw-regexps "abstract" "alignof" "as" "async" "await"
2724 "become" "box" "break"
2725 "const" "continue" "crate"
2727 "else" "enum" "extern"
2731 "macro" "match" "mod" "move" "mut"
2732 "offsetof" "override"
2733 "priv" "proc" "pub" "pure"
2735 "sizeof" "static" "struct" "super"
2736 "trait" "try" "type" "typeof"
2737 "union" "unsafe" "unsized" "use"
2742 (mdw-regexps "array" "pointer" "slice" "tuple"
2743 "bool" "true" "false"
2745 "i8" "i16" "i32" "i64" "isize"
2746 "u8" "u16" "u32" "u64" "usize"
2749 (setq font-lock-keywords
2752 ;; Handle the keywords defined above.
2753 (list (concat "\\_<\\(" rust-keywords "\\)\\_>")
2754 '(0 font-lock-keyword-face))
2755 (list (concat "\\_<\\(" rust-builtins "\\)\\_>")
2756 '(0 font-lock-variable-name-face))
2758 ;; Handle numbers too.
2759 (list (concat "\\_<\\("
2761 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
2765 "\\|" "\\(" "[0-9][0-9_]*"
2766 "\\|" "0x[0-9a-fA-F_]+"
2770 "\\([ui]\\(8\\|16\\|32\\|64\\|size\\)\\)?"
2772 '(0 mdw-number-face))
2774 ;; And anything else is punctuation.
2775 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2776 '(0 mdw-punct-face)))))
2778 ;; Hack key bindings.
2779 (local-set-key [?{] 'mdw-self-insert-and-indent)
2780 (local-set-key [?}] 'mdw-self-insert-and-indent))
2783 (add-hook 'rust-mode-hook 'mdw-misc-mode-config t)
2784 (add-hook 'rust-mode-hook 'mdw-fontify-rust t))
2786 ;;;--------------------------------------------------------------------------
2787 ;;; Awk programming configuration.
2789 ;; Make Awk indentation nice.
2791 (mdw-define-c-style mdw-awk
2792 (c-basic-offset . 2)
2793 (c-offsets-alist (substatement-open . 0)
2794 (c-backslash-column . 72)
2795 (statement-cont . 0)
2796 (statement-case-intro . +)))
2797 (mdw-set-default-c-style 'awk-mode 'mdw-awk)
2799 ;; Declare Awk fontification style.
2801 (defun mdw-fontify-awk ()
2803 ;; Miscellaneous fiddling.
2804 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2806 ;; Now define things to be fontified.
2807 (make-local-variable 'font-lock-keywords)
2809 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
2810 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
2811 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
2812 "RSTART" "RLENGTH" "RT" "SUBSEP"
2813 "atan2" "break" "close" "continue" "cos" "delete"
2814 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
2815 "function" "gensub" "getline" "gsub" "if" "in"
2816 "index" "int" "length" "log" "match" "next" "rand"
2817 "return" "print" "printf" "sin" "split" "sprintf"
2818 "sqrt" "srand" "strftime" "sub" "substr" "system"
2819 "systime" "tolower" "toupper" "while")))
2821 (setq font-lock-keywords
2824 ;; Handle the keywords defined above.
2825 (list (concat "\\<\\(" c-keywords "\\)\\>")
2826 '(0 font-lock-keyword-face))
2828 ;; Handle numbers too.
2830 ;; The following isn't quite right, but it's close enough.
2831 (list (concat "\\<\\("
2832 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2833 "[0-9]+\\(\\.[0-9]*\\|\\)"
2834 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2836 '(0 mdw-number-face))
2838 ;; And anything else is punctuation.
2839 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2840 '(0 mdw-punct-face))))))
2843 (add-hook 'awk-mode-hook 'mdw-misc-mode-config t)
2844 (add-hook 'awk-mode-hook 'mdw-fontify-awk t))
2846 ;;;--------------------------------------------------------------------------
2847 ;;; Perl programming style.
2849 ;; Perl indentation style.
2851 (setq-default perl-indent-level 2)
2853 (setq-default cperl-indent-level 2
2854 cperl-continued-statement-offset 2
2855 cperl-continued-brace-offset 0
2856 cperl-brace-offset -2
2857 cperl-brace-imaginary-offset 0
2858 cperl-label-offset 0)
2860 ;; Define perl fontification style.
2862 (defun mdw-fontify-perl ()
2864 ;; Miscellaneous fiddling.
2865 (modify-syntax-entry ?$ "\\")
2866 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
2867 (modify-syntax-entry ?: "." font-lock-syntax-table)
2868 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2870 ;; Now define fontification things.
2871 (make-local-variable 'font-lock-keywords)
2872 (let ((perl-keywords
2879 "ge" "given" "gt" "goto"
2881 "last" "le" "local" "lt"
2886 "redo" "require" "return"
2888 "undef" "unless" "until" "use"
2891 (setq font-lock-keywords
2894 ;; Set up the keywords defined above.
2895 (list (concat "\\<\\(" perl-keywords "\\)\\>")
2896 '(0 font-lock-keyword-face))
2898 ;; At least numbers are simpler than C.
2899 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2900 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2901 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2902 '(0 mdw-number-face))
2904 ;; And anything else is punctuation.
2905 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2906 '(0 mdw-punct-face))))))
2908 (defun perl-number-tests (&optional arg)
2909 "Assign consecutive numbers to lines containing `#t'. With ARG,
2910 strip numbers instead."
2913 (goto-char (point-min))
2914 (let ((i 0) (fmt (if arg "" " %4d")))
2915 (while (search-forward "#t" nil t)
2916 (delete-region (point) (line-end-position))
2918 (insert (format fmt i)))
2919 (goto-char (point-min))
2920 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
2921 (replace-match (format "\\1%d" i))))))
2923 (dolist (hook '(perl-mode-hook cperl-mode-hook))
2924 (add-hook hook 'mdw-misc-mode-config t)
2925 (add-hook hook 'mdw-fontify-perl t))
2927 ;;;--------------------------------------------------------------------------
2928 ;;; Python programming style.
2930 (setq-default py-indent-offset 2
2932 python-indent-offset 2
2933 python-fill-docstring-style 'symmetric)
2935 (defun mdw-fontify-pythonic (keywords)
2937 ;; Miscellaneous fiddling.
2938 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2939 (setq indent-tabs-mode nil)
2941 ;; Now define fontification things.
2942 (make-local-variable 'font-lock-keywords)
2943 (setq font-lock-keywords
2946 ;; Set up the keywords defined above.
2947 (list (concat "\\_<\\(" keywords "\\)\\_>")
2948 '(0 font-lock-keyword-face))
2950 ;; At least numbers are simpler than C.
2951 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO]?[0-7]+\\|[bB][01]+\\)\\|"
2952 "\\_<[0-9][0-9]*\\(\\.[0-9]*\\|\\)"
2953 "\\([eE]\\([-+]\\|\\)[0-9]+\\|[lL]\\|\\)")
2954 '(0 mdw-number-face))
2956 ;; And anything else is punctuation.
2957 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2958 '(0 mdw-punct-face)))))
2960 ;; Define Python fontification styles.
2962 (defun mdw-fontify-python ()
2963 (mdw-fontify-pythonic
2964 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
2965 "del" "elif" "else" "except" "exec" "finally" "for"
2966 "from" "global" "if" "import" "in" "is" "lambda"
2967 "not" "or" "pass" "print" "raise" "return" "try"
2968 "while" "with" "yield")))
2970 (defun mdw-fontify-pyrex ()
2971 (mdw-fontify-pythonic
2972 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
2973 "ctypedef" "def" "del" "elif" "else" "enum" "except" "exec"
2974 "extern" "finally" "for" "from" "global" "if"
2975 "import" "in" "is" "lambda" "not" "or" "pass" "print"
2976 "property" "raise" "return" "struct" "try" "while" "with"
2979 (define-derived-mode pyrex-mode python-mode "Pyrex"
2980 "Major mode for editing Pyrex source code")
2981 (setq auto-mode-alist
2982 (append '(("\\.pyx$" . pyrex-mode)
2983 ("\\.pxd$" . pyrex-mode)
2984 ("\\.pxi$" . pyrex-mode))
2988 (add-hook 'python-mode-hook 'mdw-misc-mode-config t)
2989 (add-hook 'python-mode-hook 'mdw-fontify-python t)
2990 (add-hook 'pyrex-mode-hook 'mdw-fontify-pyrex t))
2992 ;;;--------------------------------------------------------------------------
2993 ;;; Lua programming style.
2995 (setq-default lua-indent-level 2)
2997 (defun mdw-fontify-lua ()
2999 ;; Miscellaneous fiddling.
3000 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3002 ;; Now define fontification things.
3003 (make-local-variable 'font-lock-keywords)
3005 (mdw-regexps "and" "break" "do" "else" "elseif" "end"
3006 "false" "for" "function" "goto" "if" "in" "local"
3007 "nil" "not" "or" "repeat" "return" "then" "true"
3009 (setq font-lock-keywords
3012 ;; Set up the keywords defined above.
3013 (list (concat "\\_<\\(" lua-keywords "\\)\\_>")
3014 '(0 font-lock-keyword-face))
3016 ;; At least numbers are simpler than C.
3017 (list (concat "\\_<\\(" "0[xX]"
3018 "\\(" "[0-9a-fA-F]+"
3019 "\\(\\.[0-9a-fA-F]*\\)?"
3020 "\\|" "\\.[0-9a-fA-F]+"
3022 "\\([pP][-+]?[0-9]+\\)?"
3023 "\\|" "\\(" "[0-9]+"
3027 "\\([eE][-+]?[0-9]+\\)?"
3029 '(0 mdw-number-face))
3031 ;; And anything else is punctuation.
3032 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3033 '(0 mdw-punct-face))))))
3036 (add-hook 'lua-mode-hook 'mdw-misc-mode-config t)
3037 (add-hook 'lua-mode-hook 'mdw-fontify-lua t))
3039 ;;;--------------------------------------------------------------------------
3040 ;;; Icon programming style.
3042 ;; Icon indentation style.
3044 (setq-default icon-brace-offset 0
3045 icon-continued-brace-offset 0
3046 icon-continued-statement-offset 2
3047 icon-indent-level 2)
3049 ;; Define Icon fontification style.
3051 (defun mdw-fontify-icon ()
3053 ;; Miscellaneous fiddling.
3054 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3056 ;; Now define fontification things.
3057 (make-local-variable 'font-lock-keywords)
3058 (let ((icon-keywords
3059 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
3060 "end" "every" "fail" "global" "if" "initial"
3061 "invocable" "link" "local" "next" "not" "of"
3062 "procedure" "record" "repeat" "return" "static"
3063 "suspend" "then" "to" "until" "while"))
3064 (preprocessor-keywords
3065 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
3066 "include" "line" "undef")))
3067 (setq font-lock-keywords
3070 ;; Set up the keywords defined above.
3071 (list (concat "\\<\\(" icon-keywords "\\)\\>")
3072 '(0 font-lock-keyword-face))
3074 ;; The things that Icon calls keywords.
3075 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
3077 ;; At least numbers are simpler than C.
3078 (list (concat "\\<[0-9]+"
3079 "\\([rR][0-9a-zA-Z]+\\|"
3080 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
3081 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
3082 '(0 mdw-number-face))
3085 (list (concat "^[ \t]*$[ \t]*\\<\\("
3086 preprocessor-keywords
3088 '(0 font-lock-keyword-face))
3090 ;; And anything else is punctuation.
3091 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3092 '(0 mdw-punct-face))))))
3095 (add-hook 'icon-mode-hook 'mdw-misc-mode-config t)
3096 (add-hook 'icon-mode-hook 'mdw-fontify-icon t))
3098 ;;;--------------------------------------------------------------------------
3101 (defun mdw-fontify-asm ()
3102 (modify-syntax-entry ?' "\"")
3103 (modify-syntax-entry ?. "w")
3104 (modify-syntax-entry ?\n ">")
3105 (setf fill-prefix nil)
3106 (modify-syntax-entry ?. "_")
3107 (modify-syntax-entry ?* ". 23")
3108 (modify-syntax-entry ?/ ". 124b")
3109 (modify-syntax-entry ?\n "> b")
3110 (local-set-key ";" 'self-insert-command)
3111 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
3113 (defun mdw-asm-set-comment ()
3114 (modify-syntax-entry ?; "."
3116 (modify-syntax-entry asm-comment-char "< b")
3117 (setq comment-start (string asm-comment-char ? )))
3118 (add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
3119 (put 'asm-comment-char 'safe-local-variable 'characterp)
3122 (add-hook 'asm-mode-hook 'mdw-misc-mode-config t)
3123 (add-hook 'asm-mode-hook 'mdw-fontify-asm t))
3125 ;;;--------------------------------------------------------------------------
3126 ;;; TCL configuration.
3128 (setq-default tcl-indent-level 2)
3130 (defun mdw-fontify-tcl ()
3132 (modify-syntax-entry ch "."))
3133 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
3134 (make-local-variable 'font-lock-keywords)
3135 (setq font-lock-keywords
3137 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3138 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
3139 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
3140 '(0 mdw-number-face))
3141 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3142 '(0 mdw-punct-face)))))
3145 (add-hook 'tcl-mode-hook 'mdw-misc-mode-config t)
3146 (add-hook 'tcl-mode-hook 'mdw-fontify-tcl t))
3148 ;;;--------------------------------------------------------------------------
3149 ;;; Dylan programming configuration.
3151 (defun mdw-fontify-dylan ()
3153 (make-local-variable 'font-lock-keywords)
3155 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
3156 ;; hook, which undoes all of our configuration.
3157 (setq major-mode 'dylan-mode)
3158 (font-lock-set-defaults)
3160 (let* ((word "[-_a-zA-Z!*@<>$%]+")
3161 (dylan-keywords (mdw-regexps
3163 "C-address" "C-callable-wrapper" "C-function"
3164 "C-mapped-subtype" "C-pointer-type" "C-struct"
3165 "C-subtype" "C-union" "C-variable"
3167 "above" "abstract" "afterwards" "all"
3168 "begin" "below" "block" "by"
3169 "case" "class" "cleanup" "constant" "create"
3171 "else" "elseif" "end" "exception" "export"
3172 "finally" "for" "from" "function"
3175 "if" "in" "instance" "interface" "iterate"
3177 "let" "library" "local"
3178 "macro" "method" "module"
3181 "select" "slot" "subclass"
3183 "unless" "until" "use"
3184 "variable" "virtual"
3186 (sharp-keywords (mdw-regexps
3187 "all-keys" "key" "next" "rest" "include"
3189 (setq font-lock-keywords
3190 (list (list (concat "\\<\\(" dylan-keywords
3191 "\\|" "with\\(out\\)?-" word
3193 '(0 font-lock-keyword-face))
3194 (list (concat "\\<" word ":" "\\|"
3195 "#\\(" sharp-keywords "\\)\\>")
3196 '(0 font-lock-variable-name-face))
3198 "\\([-+]\\|\\<\\)[0-9]+" "\\("
3199 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
3202 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
3205 "\\|" "#x[0-9a-zA-Z]+"
3207 '(0 mdw-number-face))
3209 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
3210 "\\_<[-+*/=<>:&|]+\\_>"
3212 '(0 mdw-punct-face))))))
3215 (add-hook 'dylan-mode-hook 'mdw-misc-mode-config t)
3216 (add-hook 'dylan-mode-hook 'mdw-fontify-dylan t))
3218 ;;;--------------------------------------------------------------------------
3219 ;;; Algol 68 configuration.
3221 (setq-default a68-indent-step 2)
3223 (defun mdw-fontify-algol-68 ()
3225 ;; Fix up the syntax table.
3226 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
3227 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
3228 (modify-syntax-entry ch "." a68-mode-syntax-table))
3230 (make-local-variable 'font-lock-keywords)
3233 (let ((word "COMMENT"))
3234 (do ((regexp (concat "[^" (substring word 0 1) "]+")
3235 (concat regexp "\\|"
3236 (substring word 0 i)
3237 "[^" (substring word i (1+ i)) "]"))
3239 ((>= i (length word)) regexp)))))
3240 (setq font-lock-keywords
3241 (list (list (concat "\\<COMMENT\\>"
3242 "\\(" not-comment "\\)\\{0,5\\}"
3243 "\\(\\'\\|\\<COMMENT\\>\\)")
3244 '(0 font-lock-comment-face))
3245 (list (concat "\\<CO\\>"
3246 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
3247 "\\($\\|\\<CO\\>\\)")
3248 '(0 font-lock-comment-face))
3249 (list "\\<[A-Z_]+\\>"
3250 '(0 font-lock-keyword-face))
3254 "\\([eE][-+]?[0-9]+\\)?"
3256 '(0 mdw-number-face))
3257 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
3258 '(0 mdw-punct-face))))))
3260 (dolist (hook '(a68-mode-hook a68-mode-hooks))
3261 (add-hook hook 'mdw-misc-mode-config t)
3262 (add-hook hook 'mdw-fontify-algol-68 t))
3264 ;;;--------------------------------------------------------------------------
3265 ;;; REXX configuration.
3267 (defun mdw-rexx-electric-* ()
3272 (defun mdw-rexx-indent-newline-indent ()
3275 (if abbrev-mode (expand-abbrev))
3276 (newline-and-indent))
3278 (defun mdw-fontify-rexx ()
3280 ;; Various bits of fiddling.
3281 (setq mdw-auto-indent nil)
3282 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
3283 (local-set-key [?*] 'mdw-rexx-electric-*)
3284 (dolist (ch '(?! ?? ?# ?@ ?$)) (modify-syntax-entry ch "w"))
3285 (dolist (ch '(?¬)) (modify-syntax-entry ch "."))
3286 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
3288 ;; Set up keywords and things for fontification.
3289 (make-local-variable 'font-lock-keywords-case-fold-search)
3290 (setq font-lock-keywords-case-fold-search t)
3292 (setq rexx-indent 2)
3293 (setq rexx-end-indent rexx-indent)
3294 (setq rexx-cont-indent rexx-indent)
3296 (make-local-variable 'font-lock-keywords)
3297 (let ((rexx-keywords
3298 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
3299 "else" "end" "engineering" "exit" "expose" "for"
3300 "forever" "form" "fuzz" "if" "interpret" "iterate"
3301 "leave" "linein" "name" "nop" "numeric" "off" "on"
3302 "options" "otherwise" "parse" "procedure" "pull"
3303 "push" "queue" "return" "say" "select" "signal"
3304 "scientific" "source" "then" "trace" "to" "until"
3305 "upper" "value" "var" "version" "when" "while"
3308 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
3309 "center" "center" "charin" "charout" "chars"
3310 "compare" "condition" "copies" "c2d" "c2x"
3311 "datatype" "date" "delstr" "delword" "d2c" "d2x"
3312 "errortext" "format" "fuzz" "insert" "lastpos"
3313 "left" "length" "lineout" "lines" "max" "min"
3314 "overlay" "pos" "queued" "random" "reverse" "right"
3315 "sign" "sourceline" "space" "stream" "strip"
3316 "substr" "subword" "symbol" "time" "translate"
3317 "trunc" "value" "verify" "word" "wordindex"
3318 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
3321 (setq font-lock-keywords
3324 ;; Set up the keywords defined above.
3325 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
3326 '(0 font-lock-keyword-face))
3328 ;; Fontify all symbols the same way.
3329 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
3330 "[A-Za-z0-9.!?_#@$]+\\)")
3331 '(0 font-lock-variable-name-face))
3333 ;; And everything else is punctuation.
3334 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3335 '(0 mdw-punct-face))))))
3338 (add-hook 'rexx-mode-hook 'mdw-misc-mode-config t)
3339 (add-hook 'rexx-mode-hook 'mdw-fontify-rexx t))
3341 ;;;--------------------------------------------------------------------------
3342 ;;; Standard ML programming style.
3344 (setq-default sml-nested-if-indent t
3347 sml-type-of-indent nil)
3349 (defun mdw-fontify-sml ()
3351 ;; Make underscore an honorary letter.
3352 (modify-syntax-entry ?' "w")
3355 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
3357 ;; Now define fontification things.
3358 (make-local-variable 'font-lock-keywords)
3360 (mdw-regexps "abstype" "and" "andalso" "as"
3363 "else" "end" "eqtype" "exception"
3364 "fn" "fun" "functor"
3366 "if" "in" "include" "infix" "infixr"
3369 "of" "op" "open" "orelse"
3371 "sharing" "sig" "signature" "struct" "structure"
3374 "where" "while" "with" "withtype")))
3376 (setq font-lock-keywords
3379 ;; Set up the keywords defined above.
3380 (list (concat "\\<\\(" sml-keywords "\\)\\>")
3381 '(0 font-lock-keyword-face))
3383 ;; At least numbers are simpler than C.
3384 (list (concat "\\<\\(\\~\\|\\)"
3385 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
3387 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
3388 "\\([eE]\\(\\~\\|\\)"
3389 "[0-9]+\\|\\)\\)\\)")
3390 '(0 mdw-number-face))
3392 ;; And anything else is punctuation.
3393 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3394 '(0 mdw-punct-face))))))
3397 (add-hook 'sml-mode-hook 'mdw-misc-mode-config t)
3398 (add-hook 'sml-mode-hook 'mdw-fontify-sml t))
3400 ;;;--------------------------------------------------------------------------
3401 ;;; Haskell configuration.
3403 (setq-default haskell-indent-offset 2)
3405 (defun mdw-fontify-haskell ()
3407 ;; Fiddle with syntax table to get comments right.
3408 (modify-syntax-entry ?' "_")
3409 (modify-syntax-entry ?- ". 12")
3410 (modify-syntax-entry ?\n ">")
3412 ;; Make punctuation be punctuation
3413 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
3415 ((>= i (length punct)))
3416 (modify-syntax-entry (aref punct i) ".")))
3419 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
3421 ;; Fiddle with fontification.
3422 (make-local-variable 'font-lock-keywords)
3423 (let ((haskell-keywords
3425 "case" "ccall" "class"
3426 "data" "default" "deriving" "do"
3430 "if" "import" "in" "infix" "infixl" "infixr" "instance"
3443 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
3444 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
3445 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
3446 "SP" "STX" "SUB" "SYN" "US" "VT")))
3448 (setq font-lock-keywords
3450 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
3454 '(0 font-lock-comment-face))
3455 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
3456 '(0 font-lock-keyword-face))
3457 (list (concat "'\\("
3461 "\\(" "[abfnrtv\\\"']" "\\|"
3462 "^" "\\(" control-sequences "\\|"
3463 "[]A-Z@[\\^_]" "\\)" "\\|"
3470 '(0 font-lock-string-face))
3471 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
3472 '(0 font-lock-variable-name-face))
3473 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
3474 "\\_<[0-9]+\\(\\.[0-9]*\\|\\)"
3475 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
3476 '(0 mdw-number-face))
3477 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3478 '(0 mdw-punct-face))))))
3481 (add-hook 'haskell-mode-hook 'mdw-misc-mode-config t)
3482 (add-hook 'haskell-mode-hook 'mdw-fontify-haskell t))
3484 ;;;--------------------------------------------------------------------------
3485 ;;; Erlang configuration.
3487 (setq-default erlang-electric-commands nil)
3489 (defun mdw-fontify-erlang ()
3492 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
3494 ;; Fiddle with fontification.
3495 (make-local-variable 'font-lock-keywords)
3496 (let ((erlang-keywords
3497 (mdw-regexps "after" "and" "andalso"
3498 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
3499 "case" "catch" "cond"
3500 "div" "end" "fun" "if" "let" "not"
3502 "query" "receive" "rem" "try" "when" "xor")))
3504 (setq font-lock-keywords
3507 '(0 font-lock-comment-face))
3508 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
3509 '(0 font-lock-keyword-face))
3510 (list (concat "^-\\sw+\\>")
3511 '(0 font-lock-keyword-face))
3512 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
3513 '(0 mdw-number-face))
3514 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3515 '(0 mdw-punct-face))))))
3518 (add-hook 'erlang-mode-hook 'mdw-misc-mode-config t)
3519 (add-hook 'erlang-mode-hook 'mdw-fontify-erlang t))
3521 ;;;--------------------------------------------------------------------------
3522 ;;; Texinfo configuration.
3524 (defun mdw-fontify-texinfo ()
3527 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
3529 ;; Real fontification things.
3530 (make-local-variable 'font-lock-keywords)
3531 (setq font-lock-keywords
3534 ;; Environment names are keywords.
3535 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
3536 '(2 font-lock-keyword-face))
3538 ;; Unmark escaped magic characters.
3539 (list "\\(@\\)\\([@{}]\\)"
3540 '(1 font-lock-keyword-face)
3541 '(2 font-lock-variable-name-face))
3543 ;; Make sure we get comments properly.
3544 (list "@c\\(\\|omment\\)\\( .*\\)?$"
3545 '(0 font-lock-comment-face))
3547 ;; Command names are keywords.
3548 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3549 '(0 font-lock-keyword-face))
3551 ;; Fontify TeX special characters as punctuation.
3553 '(0 mdw-punct-face)))))
3555 (dolist (hook '(texinfo-mode-hook TeXinfo-mode-hook))
3556 (add-hook hook 'mdw-misc-mode-config t)
3557 (add-hook hook 'mdw-fontify-texinfo t))
3559 ;;;--------------------------------------------------------------------------
3560 ;;; TeX and LaTeX configuration.
3562 (setq-default LaTeX-table-label "tbl:"
3563 TeX-auto-untabify nil
3564 LaTeX-syntactic-comments nil
3565 LaTeX-fill-break-at-separators '(\\\[))
3567 (defun mdw-fontify-tex ()
3568 (setq ispell-parser 'tex)
3571 ;; Don't make maths into a string.
3572 (modify-syntax-entry ?$ ".")
3573 (modify-syntax-entry ?$ "." font-lock-syntax-table)
3574 (local-set-key [?$] 'self-insert-command)
3576 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
3577 (local-set-key "\C-\M-i" 'indent-relative)
3578 (setq indent-tabs-mode nil)
3581 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
3583 ;; Real fontification things.
3584 (make-local-variable 'font-lock-keywords)
3585 (setq font-lock-keywords
3588 ;; Environment names are keywords.
3589 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
3591 '(2 font-lock-keyword-face))
3593 ;; Suspended environment names are keywords too.
3594 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
3596 '(3 font-lock-keyword-face))
3598 ;; Command names are keywords.
3599 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3600 '(0 font-lock-keyword-face))
3602 ;; Handle @/.../ for italics.
3603 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
3604 ;; '(1 font-lock-keyword-face)
3605 ;; '(3 font-lock-keyword-face))
3607 ;; Handle @*...* for boldness.
3608 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
3609 ;; '(1 font-lock-keyword-face)
3610 ;; '(3 font-lock-keyword-face))
3612 ;; Handle @`...' for literal syntax things.
3613 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
3614 ;; '(1 font-lock-keyword-face)
3615 ;; '(3 font-lock-keyword-face))
3617 ;; Handle @<...> for nonterminals.
3618 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
3619 ;; '(1 font-lock-keyword-face)
3620 ;; '(3 font-lock-keyword-face))
3622 ;; Handle other @-commands.
3623 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
3624 ;; '(0 font-lock-keyword-face))
3626 ;; Make sure we get comments properly.
3628 '(0 font-lock-comment-face))
3630 ;; Fontify TeX special characters as punctuation.
3632 '(0 mdw-punct-face)))))
3634 (setq TeX-install-font-lock 'tex-font-setup)
3636 (eval-after-load 'font-latex
3637 '(defun font-latex-jit-lock-force-redisplay (buf start end)
3638 "Compatibility for Emacsen not offering `jit-lock-force-redisplay'."
3639 ;; The following block is an expansion of `jit-lock-force-redisplay'
3640 ;; and involved macros taken from CVS Emacs on 2007-04-28.
3641 (with-current-buffer buf
3642 (let ((modified (buffer-modified-p)))
3644 (let ((buffer-undo-list t)
3645 (inhibit-read-only t)
3646 (inhibit-point-motion-hooks t)
3647 (inhibit-modification-hooks t)
3650 buffer-file-truename)
3651 (put-text-property start end 'fontified t))
3653 (restore-buffer-modified-p nil)))))))
3655 (setq TeX-output-view-style
3657 ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$")
3658 "%(o?)dvips -t landscape %d -o && xdg-open %f")
3659 ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$"
3660 "%(o?)dvips %d -o && xdg-open %f")
3662 ("^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$" "^landscape$")
3663 "%(o?)xdvi %dS -paper a4r -s 0 %d")
3664 ("^dvi$" "^a4\\(?:dutch\\|paper\\|wide\\)\\|sem-a4$"
3665 "%(o?)xdvi %dS -paper a4 %d")
3667 ("^a5\\(?:comb\\|paper\\)$" "^landscape$")
3668 "%(o?)xdvi %dS -paper a5r -s 0 %d")
3669 ("^dvi$" "^a5\\(?:comb\\|paper\\)$" "%(o?)xdvi %dS -paper a5 %d")
3670 ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
3671 ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d")
3672 ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
3673 ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
3674 ("^dvi$" "." "%(o?)xdvi %dS %d")
3675 ("^pdf$" "." "xdg-open %o")
3676 ("^html?$" "." "sensible-browser %o")))
3678 (setq TeX-view-program-list
3679 '(("mupdf" ("mupdf %o" (mode-io-correlate " %(outpage)")))))
3681 (setq TeX-view-program-selection
3682 '(((output-dvi style-pstricks) "dvips and gv")
3684 (output-pdf "mupdf")
3685 (output-html "sensible-browser")))
3687 (setq TeX-open-quote "\""
3688 TeX-close-quote "\"")
3690 (setq reftex-use-external-file-finders t
3691 reftex-auto-recenter-toc t)
3693 (setq reftex-label-alist
3694 '(("theorem" ?T "th:" "~\\ref{%s}" t ("theorems?" "th\\.") -2)
3695 ("axiom" ?A "ax:" "~\\ref{%s}" t ("axioms?" "ax\\.") -2)
3696 ("definition" ?D "def:" "~\\ref{%s}" t ("definitions?" "def\\.") -2)
3697 ("proposition" ?P "prop:" "~\\ref{%s}" t
3698 ("propositions?" "prop\\.") -2)
3699 ("lemma" ?L "lem:" "~\\ref{%s}" t ("lemmas?" "lem\\.") -2)
3700 ("example" ?X "eg:" "~\\ref{%s}" t ("examples?") -2)
3701 ("exercise" ?E "ex:" "~\\ref{%s}" t ("exercises?" "ex\\.") -2)
3702 ("enumerate" ?i "i:" "~\\ref{%s}" item ("items?"))))
3703 (setq reftex-section-prefixes
3708 (setq bibtex-field-delimiters 'double-quotes
3709 bibtex-align-at-equal-sign t
3710 bibtex-entry-format '(realign opts-or-alts required-fields
3711 numerical-fields last-comma delimiters
3712 unify-case sort-fields braces)
3713 bibtex-sort-ignore-string-entries nil
3714 bibtex-maintain-sorted-entries 'entry-class
3715 bibtex-include-OPTkey t
3716 bibtex-autokey-names-stretch 1
3717 bibtex-autokey-expand-strings t
3718 bibtex-autokey-name-separator "-"
3719 bibtex-autokey-year-length 4
3720 bibtex-autokey-titleword-separator "-"
3721 bibtex-autokey-name-year-separator "-"
3722 bibtex-autokey-year-title-separator ":")
3725 (dolist (hook '(tex-mode-hook latex-mode-hook
3726 TeX-mode-hook LaTeX-mode-hook))
3727 (add-hook hook 'mdw-misc-mode-config t)
3728 (add-hook hook 'mdw-fontify-tex t))
3729 (add-hook 'bibtex-mode-hook (lambda () (setq fill-column 76))))
3731 ;;;--------------------------------------------------------------------------
3732 ;;; HTML, CSS, and other web foolishness.
3734 (setq-default css-indent-offset 2)
3736 ;;;--------------------------------------------------------------------------
3739 (setq-default psgml-html-build-new-buffer nil)
3741 (defun mdw-sgml-mode ()
3744 (mdw-standard-fill-prefix "")
3745 (make-local-variable 'sgml-delimiters)
3746 (setq sgml-delimiters
3747 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
3748 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
3749 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
3750 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
3751 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
3752 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
3753 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
3755 (setq major-mode 'mdw-sgml-mode)
3756 (setq mode-name "[mdw] SGML")
3757 (run-hooks 'mdw-sgml-mode-hook))
3759 ;;;--------------------------------------------------------------------------
3760 ;;; Configuration files.
3762 (defvar mdw-conf-quote-normal nil
3763 "*Control syntax category of quote characters `\"' and `''.
3764 If this is `t', consider quote characters to be normal
3765 punctuation, as for `conf-quote-normal'. If this is `nil' then
3766 leave quote characters as quotes. If this is a list, then
3767 consider the quote characters in the list to be normal
3768 punctuation. If this is a single quote character, then consider
3769 that character only to be normal punctuation.")
3770 (defun mdw-conf-quote-normal-acceptable-value-p (value)
3771 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
3772 (or (booleanp value)
3773 (every (lambda (v) (memq v '(?\" ?')))
3774 (if (listp value) value (list value)))))
3775 (put 'mdw-conf-quote-normal 'safe-local-variable
3776 'mdw-conf-quote-normal-acceptable-value-p)
3778 (defun mdw-fix-up-quote ()
3779 "Apply the setting of `mdw-conf-quote-normal'."
3780 (let ((flag mdw-conf-quote-normal))
3782 (conf-quote-normal t))
3786 (let ((table (copy-syntax-table (syntax-table))))
3787 (dolist (ch (if (listp flag) flag (list flag)))
3788 (modify-syntax-entry ch "." table))
3789 (set-syntax-table table)
3790 (and font-lock-mode (font-lock-fontify-buffer)))))))
3793 (add-hook 'conf-mode-hook 'mdw-misc-mode-config t)
3794 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t))
3796 ;;;--------------------------------------------------------------------------
3799 (defun mdw-setup-sh-script-mode ()
3801 ;; Fetch the shell interpreter's name.
3802 (let ((shell-name sh-shell-file))
3804 ;; Try reading the hash-bang line.
3806 (goto-char (point-min))
3807 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
3808 (setq shell-name (match-string 1))))
3810 ;; Now try to set the shell.
3812 ;; Don't let `sh-set-shell' bugger up my script.
3813 (let ((executable-set-magic #'(lambda (s &rest r) s)))
3814 (sh-set-shell shell-name)))
3816 ;; Don't insert here-document scaffolding automatically.
3817 (local-set-key "<" 'self-insert-command)
3819 ;; Now enable my keys and the fontification.
3820 (mdw-misc-mode-config)
3822 ;; Set the indentation level correctly.
3823 (setq sh-indentation 2)
3824 (setq sh-basic-offset 2))
3826 (setq sh-shell-file "/bin/sh")
3828 ;; Awful hacking to override the shell detection for particular scripts.
3829 (defmacro define-custom-shell-mode (name shell)
3832 (set (make-local-variable 'sh-shell-file) ,shell)
3834 (define-custom-shell-mode bash-mode "/bin/bash")
3835 (define-custom-shell-mode rc-mode "/usr/bin/rc")
3836 (put 'sh-shell-file 'permanent-local t)
3838 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
3839 (eval-after-load "sh-script"
3840 '(or (assq 'rc sh-mode-syntax-table-input)
3857 (assoc (assq 'rc sh-mode-syntax-table-input)))
3860 (setq sh-mode-syntax-table-input
3861 (cons (cons 'rc frag)
3862 sh-mode-syntax-table-input))))))
3865 (add-hook 'sh-mode-hook 'mdw-misc-mode-config t)
3866 (add-hook 'sh-mode-hook 'mdw-setup-sh-script-mode t))
3868 ;;;--------------------------------------------------------------------------
3869 ;;; Emacs shell mode.
3871 (defun mdw-eshell-prompt ()
3872 (let ((left "[") (right "]"))
3873 (when (= (user-uid) 0)
3874 (setq left "«" right "»"))
3877 (replace-regexp-in-string "\\..*$" "" (system-name)))
3879 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
3880 (home (expand-file-name "~")) (nhome (length home)))
3881 (if (and (>= npwd nhome)
3883 (= (elt pwd nhome) ?/))
3884 (string= (substring pwd 0 nhome) home))
3885 (concat "~" (substring pwd (length home)))
3888 (setq-default eshell-prompt-function 'mdw-eshell-prompt)
3889 (setq-default eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
3891 (defun eshell/e (file) (find-file file) nil)
3892 (defun eshell/ee (file) (find-file-other-window file) nil)
3893 (defun eshell/w3m (url) (w3m-goto-url url) nil)
3895 (mdw-define-face eshell-prompt (t :weight bold))
3896 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
3897 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
3898 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
3899 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
3900 (mdw-define-face eshell-ls-executable (t :weight bold))
3901 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
3902 (mdw-define-face eshell-ls-readonly (t nil))
3903 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
3905 (defun mdw-eshell-hack () (setenv "LD_PRELOAD" nil))
3906 (add-hook 'eshell-mode-hook 'mdw-eshell-hack)
3908 ;;;--------------------------------------------------------------------------
3909 ;;; Messages-file mode.
3911 (defun messages-mode-guts ()
3912 (setq messages-mode-syntax-table (make-syntax-table))
3913 (set-syntax-table messages-mode-syntax-table)
3914 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
3915 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
3916 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
3917 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
3918 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
3919 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
3920 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
3921 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
3922 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
3923 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
3924 (make-local-variable 'comment-start)
3925 (make-local-variable 'comment-end)
3926 (make-local-variable 'indent-line-function)
3927 (setq indent-line-function 'indent-relative)
3928 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3929 (make-local-variable 'font-lock-defaults)
3930 (make-local-variable 'messages-mode-keywords)
3932 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
3933 "export" "enum" "fixed-octetstring" "flags"
3934 "harmless" "map" "nested" "optional"
3935 "optional-tagged" "package" "primitive"
3936 "primitive-nullfree" "relaxed[ \t]+enum"
3937 "set" "table" "tagged-optional" "union"
3938 "variadic" "vector" "version" "version-tag")))
3939 (setq messages-mode-keywords
3941 (list (concat "\\<\\(" keywords "\\)\\>:")
3942 '(0 font-lock-keyword-face))
3943 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
3944 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
3945 (0 font-lock-variable-name-face))
3946 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
3947 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3948 (0 mdw-punct-face)))))
3949 (setq font-lock-defaults
3950 '(messages-mode-keywords nil nil nil nil))
3951 (run-hooks 'messages-file-hook))
3953 (defun messages-mode ()
3956 (setq major-mode 'messages-mode)
3957 (setq mode-name "Messages")
3958 (messages-mode-guts)
3959 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
3960 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
3961 (setq comment-start "# ")
3962 (setq comment-end "")
3963 (run-hooks 'messages-mode-hook))
3965 (defun cpp-messages-mode ()
3968 (setq major-mode 'cpp-messages-mode)
3969 (setq mode-name "CPP Messages")
3970 (messages-mode-guts)
3971 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
3972 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
3973 (setq comment-start "/* ")
3974 (setq comment-end " */")
3975 (let ((preprocessor-keywords
3976 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
3977 "ident" "if" "ifdef" "ifndef" "import" "include"
3978 "line" "pragma" "unassert" "undef" "warning")))
3979 (setq messages-mode-keywords
3980 (append (list (list (concat "^[ \t]*\\#[ \t]*"
3981 "\\(include\\|import\\)"
3982 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
3983 '(2 font-lock-string-face))
3984 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
3985 preprocessor-keywords
3986 "\\)\\>\\|[0-9]+\\|$\\)\\)")
3987 '(1 font-lock-keyword-face)))
3988 messages-mode-keywords)))
3989 (run-hooks 'cpp-messages-mode-hook))
3992 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
3993 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
3994 ;; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
3997 ;;;--------------------------------------------------------------------------
3998 ;;; Messages-file mode.
4000 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
4001 "Face to use for subsittution directives.")
4002 (make-face 'mallow-driver-substitution-face)
4003 (defvar mallow-driver-text-face 'mallow-driver-text-face
4004 "Face to use for body text.")
4005 (make-face 'mallow-driver-text-face)
4007 (defun mallow-driver-mode ()
4010 (setq major-mode 'mallow-driver-mode)
4011 (setq mode-name "Mallow driver")
4012 (setq mallow-driver-mode-syntax-table (make-syntax-table))
4013 (set-syntax-table mallow-driver-mode-syntax-table)
4014 (make-local-variable 'comment-start)
4015 (make-local-variable 'comment-end)
4016 (make-local-variable 'indent-line-function)
4017 (setq indent-line-function 'indent-relative)
4018 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
4019 (make-local-variable 'font-lock-defaults)
4020 (make-local-variable 'mallow-driver-mode-keywords)
4022 (mdw-regexps "each" "divert" "file" "if"
4023 "perl" "set" "string" "type" "write")))
4024 (setq mallow-driver-mode-keywords
4026 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
4027 '(0 font-lock-keyword-face))
4028 (list "^%\\s *\\(#.*\\|\\)$"
4029 '(0 font-lock-comment-face))
4031 '(0 font-lock-keyword-face))
4032 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
4034 '(0 mallow-driver-substitution-face t)))))
4035 (setq font-lock-defaults
4036 '(mallow-driver-mode-keywords nil nil nil nil))
4037 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
4038 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
4039 (setq comment-start "%# ")
4040 (setq comment-end "")
4041 (run-hooks 'mallow-driver-mode-hook))
4044 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t))
4046 ;;;--------------------------------------------------------------------------
4049 (defun nfast-debug-mode ()
4052 (setq major-mode 'nfast-debug-mode)
4053 (setq mode-name "NFast debug")
4054 (setq messages-mode-syntax-table (make-syntax-table))
4055 (set-syntax-table messages-mode-syntax-table)
4056 (make-local-variable 'font-lock-defaults)
4057 (make-local-variable 'nfast-debug-mode-keywords)
4058 (setq truncate-lines t)
4059 (setq nfast-debug-mode-keywords
4061 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
4062 (0 font-lock-keyword-face))
4063 (list (concat "^[ \t]+\\(\\("
4064 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4065 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
4067 "[0-9a-fA-F]+\\)[ \t]*$")
4068 '(0 mdw-number-face))
4069 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
4070 (1 font-lock-keyword-face))
4071 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
4072 (1 font-lock-warning-face))
4073 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
4075 (list (concat "^[ \t]+\\.cmd=[ \t]+"
4076 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
4077 '(1 font-lock-keyword-face))
4078 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
4079 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
4080 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
4081 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
4082 (setq font-lock-defaults
4083 '(nfast-debug-mode-keywords nil nil nil nil))
4084 (run-hooks 'nfast-debug-mode-hook))
4086 ;;;--------------------------------------------------------------------------
4087 ;;; Lispy languages.
4089 ;; Unpleasant bodge.
4090 (unless (boundp 'slime-repl-mode-map)
4091 (setq slime-repl-mode-map (make-sparse-keymap)))
4093 (defun mdw-indent-newline-and-indent ()
4095 (indent-for-tab-command)
4096 (newline-and-indent))
4098 (eval-after-load "cl-indent"
4100 (mapc #'(lambda (pair)
4102 'common-lisp-indent-function
4104 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
4105 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
4107 (defun mdw-common-lisp-indent ()
4108 (make-local-variable 'lisp-indent-function)
4109 (setq lisp-indent-function 'common-lisp-indent-function))
4111 (setq-default lisp-simple-loop-indentation 2
4112 lisp-loop-keyword-indentation 6
4113 lisp-loop-forms-indentation 6)
4115 (defmacro mdw-advise-hyperspec-lookup (func args)
4116 `(defadvice ,func (around mdw-browse-w3m ,args activate compile)
4118 (let ((browse-url-browser-function #'mdw-w3m-browse-url))
4121 (mdw-advise-hyperspec-lookup common-lisp-hyperspec (symbol))
4122 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-format (char))
4123 (mdw-advise-hyperspec-lookup common-lisp-hyperspec-lookup-reader-macro (char))
4125 (defun mdw-fontify-lispy ()
4128 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
4130 ;; Not much fontification needed.
4131 (make-local-variable 'font-lock-keywords)
4132 (setq font-lock-keywords
4133 (list (list (concat "\\("
4135 "\\(" "[0-9]+/[0-9]+"
4136 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
4138 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
4143 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
4144 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
4145 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
4146 "\\|" "[0-9]+" "r" "[-+]?"
4147 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
4150 '(0 mdw-number-face))
4151 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4152 '(0 mdw-punct-face)))))
4157 (if (not mdw-fast-startup)
4159 (require 'slime-autoloads)
4160 (slime-setup '(slime-autodoc slime-c-p-c)))))
4162 (let ((stuff '((cmucl ("cmucl"))
4163 (sbcl ("sbcl") :coding-system utf-8-unix)
4164 (clisp ("clisp") :coding-system utf-8-unix))))
4165 (or (boundp 'slime-lisp-implementations)
4166 (setq slime-lisp-implementations nil))
4168 (let* ((head (car stuff))
4169 (found (assq (car head) slime-lisp-implementations)))
4170 (setq stuff (cdr stuff))
4172 (rplacd found (cdr head))
4173 (setq slime-lisp-implementations
4174 (cons head slime-lisp-implementations))))))
4175 (setq slime-default-lisp 'sbcl)
4180 (dolist (hook '(emacs-lisp-mode-hook
4183 inferior-lisp-mode-hook
4184 lisp-interaction-mode-hook
4186 slime-repl-mode-hook))
4187 (add-hook hook 'mdw-misc-mode-config t)
4188 (add-hook hook 'mdw-fontify-lispy t))
4189 (add-hook 'lisp-mode-hook 'mdw-common-lisp-indent t)
4190 (add-hook 'inferior-lisp-mode-hook
4191 #'(lambda () (local-set-key "\C-m" 'comint-send-and-indent)) t))
4193 ;;;--------------------------------------------------------------------------
4194 ;;; Other languages.
4198 (defun mdw-setup-smalltalk ()
4199 (and mdw-auto-indent
4200 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
4201 (make-local-variable 'mdw-auto-indent)
4202 (setq mdw-auto-indent nil)
4203 (local-set-key "\C-i" 'smalltalk-reindent))
4205 (defun mdw-fontify-smalltalk ()
4206 (make-local-variable 'font-lock-keywords)
4207 (setq font-lock-keywords
4209 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
4210 '(0 font-lock-keyword-face))
4211 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
4212 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
4213 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
4214 '(0 mdw-number-face))
4215 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
4216 '(0 mdw-punct-face)))))
4219 (add-hook 'smalltalk-mode 'mdw-misc-mode-config t)
4220 (add-hook 'smalltalk-mode 'mdw-fontify-smalltalk t))
4224 (defun mdw-setup-m4 ()
4226 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
4227 ;; annoying: fix it.
4228 (modify-syntax-entry ?{ "(")
4229 (modify-syntax-entry ?} ")")
4232 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
4234 (dolist (hook '(m4-mode-hook autoconf-mode-hook autotest-mode-hook))
4235 (add-hook hook #'mdw-misc-mode-config t)
4236 (add-hook hook #'mdw-setup-m4 t))
4241 (add-hook 'makefile-mode-hook 'mdw-misc-mode-config t))
4243 ;;;--------------------------------------------------------------------------
4246 (defun mdw-text-mode ()
4247 (setq fill-column 72)
4249 (mdw-standard-fill-prefix
4250 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
4253 (eval-after-load "flyspell"
4254 '(define-key flyspell-mode-map "\C-\M-i" nil))
4257 (add-hook 'text-mode-hook 'mdw-text-mode t))
4259 ;;;--------------------------------------------------------------------------
4260 ;;; Outline and hide/show modes.
4262 (defun mdw-outline-collapse-all ()
4263 "Completely collapse everything in the entire buffer."
4266 (goto-char (point-min))
4267 (while (< (point) (point-max))
4271 (setq hs-hide-comments-when-hiding-all nil)
4273 (defadvice hs-hide-all (after hide-first-comment activate)
4274 (save-excursion (hs-hide-initial-comment-block)))
4276 ;;;--------------------------------------------------------------------------
4279 (defun mdw-sh-mode-setup ()
4280 (local-set-key [?\C-a] 'comint-bol)
4281 (add-hook 'comint-output-filter-functions
4282 'comint-watch-for-password-prompt))
4284 (defun mdw-term-mode-setup ()
4285 (setq term-prompt-regexp shell-prompt-pattern)
4286 (make-local-variable 'mouse-yank-at-point)
4287 (make-local-variable 'transient-mark-mode)
4288 (setq mouse-yank-at-point t)
4292 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
4293 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
4294 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
4295 (defun term-send-meta-meta-something ()
4297 (term-send-raw-string "\e\e")
4299 (eval-after-load 'term
4301 (define-key term-raw-map [?\e ?\e] nil)
4302 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
4303 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
4304 (define-key term-raw-map [M-right] 'term-send-meta-right)
4305 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
4306 (define-key term-raw-map [M-left] 'term-send-meta-left)
4307 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
4309 (defadvice term-exec (before program-args-list compile activate)
4310 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
4311 This allows you to pass a list of arguments through `ansi-term'."
4312 (let ((program (ad-get-arg 2)))
4315 (ad-set-arg 2 (car program))
4316 (ad-set-arg 4 (cdr program))))))
4318 (defadvice term-exec-1 (around hack-environment compile activate)
4319 "Hack the environment inherited by inferiors in the terminal."
4320 (let ((process-environment (copy-tree process-environment)))
4321 (setenv "LD_PRELOAD" nil)
4324 (defadvice shell (around hack-environment compile activate)
4325 "Hack the environment inherited by inferiors in the shell."
4326 (let ((process-environment (copy-tree process-environment)))
4327 (setenv "LD_PRELOAD" nil)
4331 "Open a terminal containing an ssh session to the HOST."
4332 (interactive "sHost: ")
4333 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
4335 (defvar git-grep-command
4336 "env GIT_PAGER=cat git grep --no-color -nH -e "
4337 "*The default command for \\[git-grep].")
4339 (defvar git-grep-history nil)
4341 (defun git-grep (command-args)
4342 "Run `git grep' with user-specified args and collect output in a buffer."
4344 (list (read-shell-command "Run git grep (like this): "
4345 git-grep-command 'git-grep-history)))
4346 (let ((grep-use-null-device nil))
4347 (grep command-args)))
4349 ;;;--------------------------------------------------------------------------
4350 ;;; Magit configuration.
4352 (setq magit-diff-refine-hunk 't
4353 magit-view-git-manual-method 'man
4354 magit-log-margin '(nil age magit-log-margin-width t 18)
4355 magit-wip-after-save-local-mode-lighter ""
4356 magit-wip-after-apply-mode-lighter ""
4357 magit-wip-before-change-mode-lighter "")
4358 (eval-after-load "magit"
4359 '(progn (global-magit-file-mode 1)
4360 (magit-wip-after-save-mode 1)
4361 (magit-wip-after-apply-mode 1)
4362 (magit-wip-before-change-mode 1)
4363 (add-to-list 'magit-no-confirm 'safe-with-wip)
4364 (add-to-list 'magit-no-confirm 'trash)
4365 (push '(:eval (if (or magit-wip-after-save-local-mode
4366 magit-wip-after-apply-mode
4367 magit-wip-before-change-mode)
4368 (format " wip:%s%s%s"
4369 (if magit-wip-after-apply-mode "A" "")
4370 (if magit-wip-before-change-mode "C" "")
4371 (if magit-wip-after-save-local-mode "S" ""))))
4373 (dolist (popup '(magit-diff-popup
4374 magit-diff-refresh-popup
4375 magit-diff-mode-refresh-popup
4376 magit-revision-mode-refresh-popup))
4377 (magit-define-popup-switch popup ?R "Reverse diff" "-R"))))
4379 (defadvice magit-wip-commit-buffer-file
4380 (around mdw-just-this-buffer activate compile)
4381 (let ((magit-save-repository-buffers nil)) ad-do-it))
4383 (defadvice magit-discard
4384 (around mdw-delete-if-prefix-argument activate compile)
4385 (let ((magit-delete-by-moving-to-trash
4386 (and (null current-prefix-arg)
4387 magit-delete-by-moving-to-trash)))
4390 (setq magit-repolist-columns
4391 '(("Name" 16 magit-repolist-column-ident nil)
4392 ("Version" 18 magit-repolist-column-version nil)
4393 ("St" 2 magit-repolist-column-dirty nil)
4394 ("L<U" 3 mdw-repolist-column-unpulled-from-upstream nil)
4395 ("L>U" 3 mdw-repolist-column-unpushed-to-upstream nil)
4396 ("Path" 32 magit-repolist-column-path nil)))
4398 (setq magit-repository-directories '(("~/etc/profile" . 0)
4401 (defadvice magit-list-repos (around mdw-dirname () activate compile)
4402 "Make sure the returned names are directory names.
4403 Otherwise child processes get started in the wrong directory and
4405 (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it)))
4407 (defun mdw-repolist-column-unpulled-from-upstream (_id)
4408 "Insert number of upstream commits not in the current branch."
4409 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
4411 (let ((n (cadr (magit-rev-diff-count "HEAD" upstream))))
4412 (propertize (number-to-string n) 'face
4413 (if (> n 0) 'bold 'shadow))))))
4415 (defun mdw-repolist-column-unpushed-to-upstream (_id)
4416 "Insert number of commits in the current branch but not its upstream."
4417 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
4419 (let ((n (car (magit-rev-diff-count "HEAD" upstream))))
4420 (propertize (number-to-string n) 'face
4421 (if (> n 0) 'bold 'shadow))))))
4423 (defun mdw-try-smerge ()
4425 (goto-char (point-min))
4426 (when (re-search-forward "^<<<<<<< " nil t)
4428 (add-hook 'find-file-hook 'mdw-try-smerge t)
4430 ;;;--------------------------------------------------------------------------
4431 ;;; GUD, and especially GDB.
4433 ;; Inhibit window dedication. I mean, seriously, wtf?
4434 (defadvice gdb-display-buffer (after mdw-undedicated (buf) compile activate)
4435 "Don't make windows dedicated. Seriously."
4436 (set-window-dedicated-p ad-return-value nil))
4437 (defadvice gdb-set-window-buffer
4438 (after mdw-undedicated (name &optional ignore-dedicated window)
4440 "Don't make windows dedicated. Seriously."
4441 (set-window-dedicated-p (or window (selected-window)) nil))
4443 ;;;--------------------------------------------------------------------------
4446 ;; Turn off `noip' when running `man': it interferes with `man-db''s own
4447 ;; seccomp(2)-based sandboxing, which is (in this case, at least) strictly
4449 (defadvice Man-getpage-in-background
4450 (around mdw-inhibit-noip (topic) compile activate)
4451 "Inhibit the `noip' preload hack when invoking `man'."
4452 (let* ((old-preload (getenv "LD_PRELOAD"))
4453 (preloads (save-match-data (split-string old-preload ":")))
4457 (let ((item (pop preloads)))
4458 (if (save-match-data
4459 (string-match "\\(/\\|^\\)noip\.so\\(:\\|$\\)" item))
4461 (push item filtered))))
4465 (setenv "LD_PRELOAD"
4467 (with-output-to-string
4468 (setq filtered (nreverse filtered))
4471 (if first (setq first nil)
4473 (write-string (pop filtered)))))))
4475 (setenv "LD_PRELOAD" old-preload))
4478 ;;;--------------------------------------------------------------------------
4479 ;;; MPC configuration.
4481 (eval-when-compile (trap (require 'mpc)))
4483 (setq mpc-browser-tags '(Artist|Composer|Performer Album|Playlist))
4485 (defun mdw-mpc-now-playing ()
4489 (set-buffer (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))))
4490 (mpc--status-callback))
4491 (let ((state (cdr (assq 'state mpc-status))))
4492 (cond ((member state '("stop"))
4493 (message "mpd stopped."))
4494 ((member state '("play" "pause"))
4495 (let* ((artist (cdr (assq 'Artist mpc-status)))
4496 (album (cdr (assq 'Album mpc-status)))
4497 (title (cdr (assq 'Title mpc-status)))
4498 (file (cdr (assq 'file mpc-status)))
4499 (duration-string (cdr (assq 'Time mpc-status)))
4500 (time-string (cdr (assq 'time mpc-status)))
4501 (time (and time-string
4503 (if (string-match ":" time-string)
4504 (substring time-string
4505 0 (match-beginning 0))
4507 (duration (and duration-string
4508 (string-to-number duration-string)))
4509 (pos (and time duration
4510 (format " [%d:%02d/%d:%02d]"
4511 (/ time 60) (mod time 60)
4512 (/ duration 60) (mod duration 60))))
4513 (fmt (cond ((and artist title)
4514 (format "`%s' by %s%s" title artist
4515 (if album (format ", from `%s'" album)
4518 (format "`%s' (no tags)" file))
4520 "(no idea what's playing!)"))))
4521 (if (string= state "play")
4522 (message "mpd playing %s%s" fmt (or pos ""))
4523 (message "mpd paused in %s%s" fmt (or pos "")))))
4525 (message "mpd in unknown state `%s'" state)))))
4527 (defmacro mdw-define-mpc-wrapper (func bvl interactive &rest body)
4529 (interactive ,@interactive)
4532 (mdw-mpc-now-playing)))
4534 (mdw-define-mpc-wrapper mdw-mpc-play-or-pause () nil
4535 (if (member (cdr (assq 'state (mpc-cmd-status))) '("play"))
4539 (mdw-define-mpc-wrapper mdw-mpc-next () nil (mpc-next))
4540 (mdw-define-mpc-wrapper mdw-mpc-prev () nil (mpc-prev))
4541 (mdw-define-mpc-wrapper mdw-mpc-stop () nil (mpc-stop))
4543 (defun mdw-mpc-louder (step)
4544 (interactive (list (if current-prefix-arg
4545 (prefix-numeric-value current-prefix-arg)
4547 (mpc-proc-cmd (format "volume %+d" step)))
4549 (defun mdw-mpc-quieter (step)
4550 (interactive (list (if current-prefix-arg
4551 (prefix-numeric-value current-prefix-arg)
4553 (mpc-proc-cmd (format "volume %+d" (- step))))
4555 (defun mdw-mpc-hack-lines (arg interactivep func)
4556 (if (and interactivep (use-region-p))
4557 (let ((from (region-beginning)) (to (region-end)))
4562 (while (< (point) to)
4565 (let ((n (prefix-numeric-value arg)))
4582 (defun mdw-mpc-select-one ()
4583 (when (and (get-char-property (point) 'mpc-file)
4584 (not (get-char-property (point) 'mpc-select)))
4585 (mpc-select-toggle)))
4587 (defun mdw-mpc-unselect-one ()
4588 (when (get-char-property (point) 'mpc-select)
4589 (mpc-select-toggle)))
4591 (defun mdw-mpc-select (&optional arg interactivep)
4592 (interactive (list current-prefix-arg t))
4593 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4595 (defun mdw-mpc-unselect (&optional arg interactivep)
4596 (interactive (list current-prefix-arg t))
4597 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one))
4599 (defun mdw-mpc-unselect-backwards (arg)
4601 (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one))
4603 (defun mdw-mpc-unselect-all ()
4605 (setq mpc-select nil)
4606 (mpc-selection-refresh))
4608 (defun mdw-mpc-next-line (arg)
4613 (defun mdw-mpc-previous-line (arg)
4616 (forward-line (- arg)))
4618 (defun mdw-mpc-playlist-add (&optional arg interactivep)
4619 (interactive (list current-prefix-arg t))
4620 (let ((mpc-select mpc-select))
4621 (when (or arg (and interactivep (use-region-p)))
4622 (setq mpc-select nil)
4623 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4624 (setq mpc-select (reverse mpc-select))
4625 (mpc-playlist-add)))
4627 (defun mdw-mpc-playlist-delete (&optional arg interactivep)
4628 (interactive (list current-prefix-arg t))
4629 (setq mpc-select (nreverse mpc-select))
4631 (when (or arg (and interactivep (use-region-p)))
4632 (setq mpc-select nil)
4633 (mpc-selection-refresh)
4634 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4635 (mpc-playlist-delete)))
4637 (defun mdw-mpc-hack-tagbrowsers ()
4638 (setq-local mode-line-format
4640 mode-line-frame-identification
4641 mode-line-buffer-identification)))
4642 (add-hook 'mpc-tagbrowser-mode-hook 'mdw-mpc-hack-tagbrowsers)
4644 (defun mdw-mpc-hack-songs ()
4645 (setq-local header-line-format
4646 ;; '("MPC " mpc-volume " " mpc-current-song)
4647 (list (propertize " " 'display '(space :align-to 0))
4648 ;; 'mpc-songs-format-description
4650 (let ((deactivate-mark) (hscroll (window-hscroll)))
4652 (mpc-format mpc-songs-format 'self hscroll)
4653 ;; That would be simpler than the hscroll handling in
4654 ;; mpc-format, but currently move-to-column does not
4655 ;; recognize :space display properties.
4656 ;; (move-to-column hscroll)
4657 ;; (delete-region (point-min) (point))
4658 (buffer-string)))))))
4659 (add-hook 'mpc-songs-mode-hook 'mdw-mpc-hack-songs)
4661 (eval-after-load "mpc"
4663 (define-key mpc-mode-map "m" 'mdw-mpc-select)
4664 (define-key mpc-mode-map "u" 'mdw-mpc-unselect)
4665 (define-key mpc-mode-map "\177" 'mdw-mpc-unselect-backwards)
4666 (define-key mpc-mode-map "\e\177" 'mdw-mpc-unselect-all)
4667 (define-key mpc-mode-map "n" 'mdw-mpc-next-line)
4668 (define-key mpc-mode-map "p" 'mdw-mpc-previous-line)
4669 (define-key mpc-mode-map "/" 'mpc-songs-search)
4670 (setq mpc-songs-mode-map (make-sparse-keymap))
4671 (set-keymap-parent mpc-songs-mode-map mpc-mode-map)
4672 (define-key mpc-songs-mode-map "l" 'mpc-playlist)
4673 (define-key mpc-songs-mode-map "+" 'mdw-mpc-playlist-add)
4674 (define-key mpc-songs-mode-map "-" 'mdw-mpc-playlist-delete)
4675 (define-key mpc-songs-mode-map "\r" 'mpc-songs-jump-to)))
4677 ;;;--------------------------------------------------------------------------
4678 ;;; Inferior Emacs Lisp.
4680 (setq comint-prompt-read-only t)
4682 (eval-after-load "comint"
4684 (define-key comint-mode-map "\C-w" 'comint-kill-region)
4685 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
4687 (eval-after-load "ielm"
4689 (define-key ielm-map "\C-w" 'comint-kill-region)
4690 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
4692 ;;;----- That's all, folks --------------------------------------------------
4694 (provide 'dot-emacs)