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 (defvar mdw-fast-startup nil
28 "Whether .emacs should optimize for rapid startup.
29 This may be at the expense of cool features.")
30 (let ((probe nil) (next command-line-args))
32 (cond ((string= (car next) "--mdw-fast-startup")
33 (setq mdw-fast-startup t)
35 (rplacd probe (cdr next))
36 (setq command-line-args (cdr next))))
39 (setq next (cdr next))))
41 ;;;--------------------------------------------------------------------------
42 ;;; Some general utilities.
45 (unless (fboundp 'make-regexp)
49 (defmacro mdw-regexps (&rest list)
50 "Turn a LIST of strings into a single regular expression at compile-time."
53 `',(make-regexp list))
56 "This is not the key sequence you're looking for."
58 (error "wrong button"))
60 (defun mdw-emacs-version-p (major &optional minor)
61 "Return non-nil if the running Emacs is at least version MAJOR.MINOR."
62 (or (> emacs-major-version major)
63 (and (= emacs-major-version major)
64 (>= emacs-minor-version (or minor 0)))))
66 ;; Some error trapping.
68 ;; If individual bits of this file go tits-up, we don't particularly want
69 ;; the whole lot to stop right there and then, because it's bloody annoying.
71 (defmacro trap (&rest forms)
72 "Execute FORMS without allowing errors to propagate outside."
76 ,(if (cdr forms) (cons 'progn forms) (car forms))
77 (error (message "Error (trapped): %s in %s"
78 (error-message-string err)
81 ;; Configuration reading.
83 (defvar mdw-config nil)
84 (defun mdw-config (sym)
85 "Read the configuration variable named SYM."
88 (flet ((replace (what with)
89 (goto-char (point-min))
90 (while (re-search-forward what nil t)
91 (replace-match with t))))
93 (insert-file-contents "~/.mdw.conf")
94 (replace "^[ \t]*\\(#.*\\|\\)\n" "")
95 (replace (concat "^[ \t]*"
96 "\\([-a-zA-Z0-9_.]*\\)"
99 "[ \t]**\\(\n\\|$\\)")
101 (car (read-from-string
102 (concat "(" (buffer-string) ")")))))))
103 (cdr (assq sym mdw-config)))
105 ;; Width configuration.
107 (defvar mdw-column-width
108 (string-to-number (or (mdw-config 'emacs-width) "77"))
109 "Width of Emacs columns.")
110 (defvar mdw-text-width mdw-column-width
111 "Expected width of text within columns.")
112 (put 'mdw-text-width 'safe-local-variable 'integerp)
114 ;; Local variables hacking.
116 (defun run-local-vars-mode-hook ()
117 "Run a hook for the major-mode after local variables have been processed."
118 (run-hooks (intern (concat (symbol-name major-mode)
119 "-local-variables-hook"))))
120 (add-hook 'hack-local-variables-hook 'run-local-vars-mode-hook)
122 ;; Set up the load path convincingly.
124 (dolist (dir (append (and (boundp 'debian-emacs-flavor)
125 (list (concat "/usr/share/"
126 (symbol-name debian-emacs-flavor)
128 (dolist (sub (directory-files dir t))
129 (when (and (file-accessible-directory-p sub)
130 (not (member sub load-path)))
131 (setq load-path (nconc load-path (list sub))))))
133 ;; Is an Emacs library available?
135 (defun library-exists-p (name)
136 "Return non-nil if NAME is an available library.
137 Return non-nil if NAME.el (or NAME.elc) somewhere on the Emacs
138 load path. The non-nil value is the filename we found for the
140 (let ((path load-path) elt (foundp nil))
141 (while (and path (not foundp))
142 (setq elt (car path))
143 (setq path (cdr path))
144 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
145 (and (file-exists-p file) file))
146 (let ((file (concat elt "/" name ".el")))
147 (and (file-exists-p file) file)))))
150 (defun maybe-autoload (symbol file &optional docstring interactivep type)
151 "Set an autoload if the file actually exists."
152 (and (library-exists-p file)
153 (autoload symbol file docstring interactivep type)))
155 (defun mdw-kick-menu-bar (&optional frame)
156 "Regenerate FRAME's menu bar so it doesn't have empty menus."
158 (unless frame (setq frame (selected-frame)))
159 (let ((old (frame-parameter frame 'menu-bar-lines)))
160 (set-frame-parameter frame 'menu-bar-lines 0)
161 (set-frame-parameter frame 'menu-bar-lines old)))
163 ;; Splitting windows.
165 (unless (fboundp 'scroll-bar-columns)
166 (defun scroll-bar-columns (side)
167 (cond ((eq side 'left) 0)
170 (unless (fboundp 'fringe-columns)
171 (defun fringe-columns (side)
172 (cond ((not window-system) 0)
176 (defun mdw-horizontal-window-overhead ()
177 "Computes the horizontal window overhead.
178 This is the number of columns used by fringes, scroll bars and other such
180 (if (not window-system)
183 (dolist (what '(scroll-bar fringe))
184 (dolist (side '(left right))
185 (incf tot (funcall (intern (concat (symbol-name what) "-columns"))
189 (defun mdw-split-window-horizontally (&optional width)
190 "Split a window horizontally.
191 Without a numeric argument, split the window approximately in
192 half. With a numeric argument WIDTH, allocate WIDTH columns to
193 the left-hand window (if positive) or -WIDTH columns to the
194 right-hand window (if negative). Space for scroll bars and
195 fringes is not taken out of the allowance for WIDTH, unlike
196 \\[split-window-horizontally]."
198 (split-window-horizontally
199 (cond ((null width) nil)
200 ((>= width 0) (+ width (mdw-horizontal-window-overhead)))
201 ((< width 0) width))))
203 (defun mdw-divvy-window (&optional width)
204 "Split a wide window into appropriate widths."
206 (setq width (cond (width (prefix-numeric-value width))
207 ((and window-system (mdw-emacs-version-p 22))
209 (t (1+ mdw-column-width))))
210 (let* ((win (selected-window))
211 (sb-width (mdw-horizontal-window-overhead))
212 (c (/ (+ (window-width) sb-width)
213 (+ width sb-width))))
216 (split-window-horizontally (+ width sb-width))
218 (select-window win)))
220 ;; Don't raise windows unless I say so.
222 (defvar mdw-inhibit-raise-frame nil
223 "*Whether `raise-frame' should do nothing when the frame is mapped.")
225 (defadvice raise-frame
226 (around mdw-inhibit (&optional frame) activate compile)
227 "Don't actually do anything if `mdw-inhibit-raise-frame' is true, and the
228 frame is actually mapped on the screen."
229 (if mdw-inhibit-raise-frame
230 (make-frame-visible frame)
233 (defmacro mdw-advise-to-inhibit-raise-frame (function)
234 "Advise the FUNCTION not to raise frames, even if it wants to."
235 `(defadvice ,function
236 (around mdw-inhibit-raise (&rest hunoz) activate compile)
237 "Don't raise the window unless you have to."
238 (let ((mdw-inhibit-raise-frame t))
241 (mdw-advise-to-inhibit-raise-frame select-frame-set-input-focus)
242 (mdw-advise-to-inhibit-raise-frame appt-disp-window)
244 ;; Bug fix for markdown-mode, which breaks point positioning during
246 (defadvice markdown-check-change-for-wiki-link
247 (around mdw-save-match activate compile)
248 "Save match data around the `markdown-mode' `after-change-functions' hook."
249 (save-match-data ad-do-it))
251 ;; Bug fix for `bbdb-canonicalize-address': on Emacs 24, `run-hook-with-args'
252 ;; always returns nil, with the result that all email addresses are lost.
253 ;; Replace the function entirely.
254 (defadvice bbdb-canonicalize-address
255 (around mdw-bug-fix activate compile)
256 "Don't use `run-hook-with-args', because that doesn't work."
257 (let ((net (ad-get-arg 0)))
259 ;; Make sure this is a proper hook list.
260 (if (functionp bbdb-canonicalize-net-hook)
261 (setq bbdb-canonicalize-net-hook (list bbdb-canonicalize-net-hook)))
263 ;; Iterate over the hooks until things converge.
266 (let (next (changep nil)
267 hook (hooks bbdb-canonicalize-net-hook))
269 (setq hook (pop hooks))
270 (setq next (funcall hook net))
271 (if (not (equal next net))
274 (setq donep (not changep)))))
275 (setq ad-return-value net)))
277 ;; Transient mark mode hacks.
279 (defadvice exchange-point-and-mark
280 (around mdw-highlight (&optional arg) activate compile)
281 "Maybe don't actually exchange point and mark.
282 If `transient-mark-mode' is on and the mark is inactive, then
283 just activate it. A non-trivial prefix argument will force the
284 usual behaviour. A trivial prefix argument (i.e., just C-u) will
285 activate the mark and temporarily enable `transient-mark-mode' if
287 (cond ((or mark-active
288 (and (not transient-mark-mode) (not arg))
289 (and arg (or (not (consp arg))
290 (not (= (car arg) 4)))))
293 (or transient-mark-mode (setq transient-mark-mode 'only))
294 (set-mark (mark t)))))
296 ;; Functions for sexp diary entries.
298 (defun mdw-not-org-mode (form)
299 "As FORM, but not in Org mode agenda."
300 (and (not mdw-diary-for-org-mode-p)
303 (defun mdw-weekday (l)
304 "Return non-nil if `date' falls on one of the days of the week in L.
305 L is a list of day numbers (from 0 to 6 for Sunday through to
306 Saturday) or symbols `sunday', `monday', etc. (or a mixture). If
307 the date stored in `date' falls on a listed day, then the
308 function returns non-nil."
309 (let ((d (calendar-day-of-week date)))
311 (memq (nth d '(sunday monday tuesday wednesday
312 thursday friday saturday)) l))))
314 (defun mdw-discordian-date (date)
315 "Return the Discordian calendar date corresponding to DATE.
317 The return value is (YOLD . st-tibs-day) or (YOLD SEASON DAYNUM DOW).
319 The original is by David Pearson. I modified it to produce date components
320 as output rather than a string."
321 (let* ((days ["Sweetmorn" "Boomtime" "Pungenday"
322 "Prickle-Prickle" "Setting Orange"])
323 (months ["Chaos" "Discord" "Confusion"
324 "Bureaucracy" "Aftermath"])
325 (day-count [0 31 59 90 120 151 181 212 243 273 304 334])
326 (year (- (extract-calendar-year date) 1900))
327 (month (1- (extract-calendar-month date)))
328 (day (1- (extract-calendar-day date)))
329 (julian (+ (aref day-count month) day))
330 (dyear (+ year 3066)))
331 (if (and (= month 1) (= day 28))
332 (cons dyear 'st-tibs-day)
334 (aref months (floor (/ julian 73)))
336 (aref days (mod julian 5))))))
338 (defun mdw-diary-discordian-date ()
339 "Convert the date in `date' to a string giving the Discordian date."
340 (let* ((ddate (mdw-discordian-date date))
341 (tail (format "in the YOLD %d" (car ddate))))
342 (if (eq (cdr ddate) 'st-tibs-day)
343 (format "St Tib's Day %s" tail)
344 (let ((season (cadr ddate))
345 (daynum (caddr ddate))
346 (dayname (cadddr ddate)))
347 (format "%s, the %d%s day of %s %s"
350 (let ((ldig (mod daynum 10)))
351 (cond ((= ldig 1) "st")
358 (defun mdw-todo (&optional when)
359 "Return non-nil today, or on WHEN, whichever is later."
360 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
361 (d (calendar-absolute-from-gregorian date)))
363 (setq w (max w (calendar-absolute-from-gregorian
365 ((not european-calendar-style)
377 (defvar mdw-diary-for-org-mode-p nil)
379 (defadvice org-agenda-list (around mdw-preserve-links activate)
380 (let ((mdw-diary-for-org-mode-p t))
383 (defadvice diary-add-to-list (before mdw-trim-leading-space compile activate)
384 "Trim leading space from the diary entry string."
386 (let ((str (ad-get-arg 1))
390 (setq str (cond ((null str) nil)
391 ((string-match "\\(^\\|\n\\)[ \t]+" str)
392 (replace-match "\\1" nil nil str))
393 ((and mdw-diary-for-org-mode-p
394 (string-match (concat
396 "\\(" diary-time-regexp
397 "\\(-" diary-time-regexp "\\)?"
399 "\\(\t[ \t]*\\| [ \t]+\\)")
401 (replace-match "\\1\\2 " nil nil str))
402 ((and (not mdw-diary-for-org-mode-p)
403 (string-match "\\[\\[[^][]*]\\[\\([^][]*\\)]]"
405 (replace-match "\\1" nil nil str))
407 (if (equal str old) (setq done t)))
408 (ad-set-arg 1 str))))
410 (defadvice org-bbdb-anniversaries (after mdw-fixup-list compile activate)
411 "Return a string rather than a list."
414 (dolist (e (let ((ee ad-return-value))
415 (if (atom ee) (list ee) ee)))
417 (when anyp (insert ?\n))
420 (setq ad-return-value
421 (and anyp (buffer-string))))))
423 ;; Fighting with Org-mode's evil key maps.
425 (defvar mdw-evil-keymap-keys
426 '(([S-up] . [?\C-c up])
427 ([S-down] . [?\C-c down])
428 ([S-left] . [?\C-c left])
429 ([S-right] . [?\C-c right])
430 (([M-up] [?\e up]) . [C-up])
431 (([M-down] [?\e down]) . [C-down])
432 (([M-left] [?\e left]) . [C-left])
433 (([M-right] [?\e right]) . [C-right]))
434 "Defines evil keybindings to clobber in `mdw-clobber-evil-keymap'.
435 The value is an alist mapping evil keys (as a list, or singleton)
436 to good keys (in the same form).")
438 (defun mdw-clobber-evil-keymap (keymap)
439 "Replace evil key bindings in the KEYMAP.
440 Evil key bindings are defined in `mdw-evil-keymap-keys'."
441 (dolist (entry mdw-evil-keymap-keys)
443 (keys (if (listp (car entry))
446 (replacements (if (listp (cdr entry))
448 (list (cdr entry)))))
451 (setq binding (lookup-key keymap key))
453 (throw 'found nil))))
456 (define-key keymap key nil))
457 (dolist (key replacements)
458 (define-key keymap key binding))))))
460 (eval-after-load "org-latex"
463 "\\documentclass{strayman}
464 \\usepackage[utf8]{inputenc}
465 \\usepackage[palatino, helvetica, courier, maths=cmr]{mdwfonts}
466 \\usepackage[T1]{fontenc}
467 \\usepackage{graphicx, tikz, mdwtab, mdwmath, crypto, longtable}"
468 ("\\section{%s}" . "\\section*{%s}")
469 ("\\subsection{%s}" . "\\subsection*{%s}")
470 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
471 ("\\paragraph{%s}" . "\\paragraph*{%s}")
472 ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
473 org-export-latex-classes)))
475 (setq org-export-docbook-xslt-proc-command "xsltproc --output %o %s %i"
476 org-export-docbook-xsl-fo-proc-command "fop %i.safe %o"
477 org-export-docbook-xslt-stylesheet
478 "/usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl")
480 ;; Some hacks to do with window placement.
482 (defun mdw-clobber-other-windows-showing-buffer (buffer-or-name)
483 "Arrange that no windows on other frames are showing BUFFER-OR-NAME."
484 (interactive "bBuffer: ")
485 (let ((home-frame (selected-frame))
486 (buffer (get-buffer buffer-or-name))
487 (safe-buffer (get-buffer "*scratch*")))
488 (mapc (lambda (frame)
489 (or (eq frame home-frame)
490 (mapc (lambda (window)
491 (and (eq (window-buffer window) buffer)
492 (set-window-buffer window safe-buffer)))
493 (window-list frame))))
496 (defvar mdw-inhibit-walk-windows nil
497 "If non-nil, then `walk-windows' does nothing.
498 This is used by advice on `switch-to-buffer-other-frame' to inhibit finding
499 buffers in random frames.")
501 (defadvice walk-windows (around mdw-inhibit activate)
502 "If `mdw-inhibit-walk-windows' is non-nil, then do nothing."
503 (and (not mdw-inhibit-walk-windows)
506 (defadvice switch-to-buffer-other-frame
507 (around mdw-always-new-frame activate)
508 "Always make a new frame.
509 Even if an existing window in some random frame looks tempting."
510 (let ((mdw-inhibit-walk-windows t)) ad-do-it))
512 (defadvice display-buffer (before mdw-inhibit-other-frames activate)
513 "Don't try to do anything fancy with other frames.
514 Pretend they don't exist. They might be on other display devices."
517 ;;;--------------------------------------------------------------------------
518 ;;; Improved compilation machinery.
520 ;; Uprated version of M-x compile.
522 (setq compile-command
523 (let ((ncpu (with-temp-buffer
524 (insert-file-contents "/proc/cpuinfo")
526 (count-matches "^processor\\s-*:"))))
527 (format "make -j%d -k" (* 2 ncpu))))
529 (defun mdw-compilation-buffer-name (mode)
530 (concat "*" (downcase mode) ": "
531 (abbreviate-file-name default-directory) "*"))
532 (setq compilation-buffer-name-function 'mdw-compilation-buffer-name)
534 (eval-after-load "compile"
536 (define-key compilation-shell-minor-mode-map "\C-c\M-g" 'recompile)))
538 (defadvice compile (around hack-environment compile activate)
539 "Hack the environment inherited by inferiors in the compilation."
540 (let ((process-environment process-environment))
541 (setenv "LD_PRELOAD" nil)
544 (defun mdw-compile (command &optional directory comint)
545 "Initiate a compilation COMMAND, maybe in a different DIRECTORY.
546 The DIRECTORY may be nil to not change. If COMINT is t, then
547 start an interactive compilation.
549 Interactively, prompt for the command if the variable
550 `compilation-read-command' is non-nil, or if requested through
551 the prefix argument. Prompt for the directory, and run
552 interactively, if requested through the prefix.
554 Use a prefix of 4, 6, 12, or 14, or type C-u between one and three times, to
555 force prompting for a directory.
557 Use a prefix of 2, 6, 10, or 14, or type C-u three times, to force
558 prompting for the command.
560 Use a prefix of 8, 10, 12, or 14, or type C-u twice or three times,
561 to force interactive compilation."
563 (let* ((prefix (prefix-numeric-value current-prefix-arg))
564 (command (eval compile-command))
565 (dir (and (plusp (logand prefix #x54))
566 (read-directory-name "Compile in directory: "))))
567 (list (if (or compilation-read-command
568 (plusp (logand prefix #x42)))
569 (compilation-read-command command)
572 (plusp (logand prefix #x58)))))
573 (let ((default-directory (or directory default-directory)))
574 (compile command comint)))
578 (defun mdw-find-build-dir (build-file)
580 (let* ((src-dir (file-name-as-directory (expand-file-name ".")))
583 (when (file-exists-p (concat dir build-file))
585 (let ((sub (expand-file-name (file-relative-name src-dir dir)
586 (concat dir "build/"))))
589 (when (file-exists-p (concat sub build-file))
591 (when (string= sub dir) (throw 'give-up nil))
592 (setq sub (file-name-directory (directory-file-name sub))))))
594 (setq dir (file-name-directory
595 (directory-file-name dir))))
596 (throw 'found nil))))))
598 (defun mdw-flymake-make-init ()
599 (let ((build-dir (mdw-find-build-dir "Makefile")))
601 (let ((tmp-src (flymake-init-create-temp-buffer-copy
602 #'flymake-create-temp-inplace)))
603 (flymake-get-syntax-check-program-args
604 tmp-src build-dir t t
605 #'flymake-get-make-cmdline)))))
607 (setq flymake-allowed-file-name-masks
608 '(("\\.\\(?:[cC]\\|cc\\|cpp\\|cxx\\|c\\+\\+\\)\\'"
609 mdw-flymake-make-init)
610 ("\\.\\(?:[hH]\\|hh\\|hpp\\|hxx\\|h\\+\\+\\)\\'"
611 mdw-flymake-master-make-init)
612 ("\\.p[lm]" flymake-perl-init)))
614 (setq flymake-mode-map
615 (let ((map (if (boundp 'flymake-mode-map)
617 (make-sparse-keymap))))
618 (define-key map [?\C-c ?\C-f ?\C-p] 'flymake-goto-prev-error)
619 (define-key map [?\C-c ?\C-f ?\C-n] 'flymake-goto-next-error)
620 (define-key map [?\C-c ?\C-f ?\C-c] 'flymake-compile)
621 (define-key map [?\C-c ?\C-f ?\C-k] 'flymake-stop-all-syntax-checks)
622 (define-key map [?\C-c ?\C-f ?\C-e] 'flymake-popup-current-error-menu)
625 ;;;--------------------------------------------------------------------------
626 ;;; Mail and news hacking.
628 (define-derived-mode mdwmail-mode mail-mode "[mdw] mail"
629 "Major mode for editing news and mail messages from external programs.
630 Not much right now. Just support for doing MailCrypt stuff."
633 (run-hooks 'mail-setup-hook))
635 (define-key mdwmail-mode-map [?\C-c ?\C-c] 'disabled-operation)
637 (add-hook 'mdwail-mode-hook
639 (set-buffer-file-coding-system 'utf-8)
640 (make-local-variable 'paragraph-separate)
641 (make-local-variable 'paragraph-start)
642 (setq paragraph-start
643 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
645 (setq paragraph-separate
646 (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
647 paragraph-separate))))
649 ;; How to encrypt in mdwmail.
651 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
653 (setq start (save-excursion
654 (goto-char (point-min))
655 (or (search-forward "\n\n" nil t) (point-min)))))
657 (setq end (point-max)))
658 (mc-encrypt-generic recip scm start end from sign))
660 ;; How to sign in mdwmail.
662 (defun mdwmail-mc-sign (key scm start end uclr)
664 (setq start (save-excursion
665 (goto-char (point-min))
666 (or (search-forward "\n\n" nil t) (point-min)))))
668 (setq end (point-max)))
669 (mc-sign-generic key scm start end uclr))
671 ;; Some signature mangling.
673 (defun mdwmail-mangle-signature ()
675 (goto-char (point-min))
676 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
677 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
678 (add-hook 'message-setup-hook 'mdwmail-mangle-signature)
680 ;; Insert my login name into message-ids, so I can score replies.
682 (defadvice message-unique-id (after mdw-user-name last activate compile)
683 "Ensure that the user's name appears at the end of the message-id string,
684 so that it can be used for convenient filtering."
685 (setq ad-return-value (concat ad-return-value "." (user-login-name))))
687 ;; Tell my movemail hack where movemail is.
689 ;; This is needed to shup up warnings about LD_PRELOAD.
691 (let ((path exec-path))
693 (let ((try (expand-file-name "movemail" (car path))))
694 (if (file-executable-p try)
695 (setenv "REAL_MOVEMAIL" try))
696 (setq path (cdr path)))))
698 ;; AUTHINFO GENERIC kludge.
700 (defvar nntp-authinfo-generic nil
701 "Set to the `NNTPAUTH' string to pass on to `authinfo-kludge'.
703 Use this to arrange for per-server settings.")
705 (defun nntp-open-authinfo-kludge (buffer)
706 "Open a connection to SERVER using `authinfo-kludge'."
707 (let ((proc (start-process "nntpd" buffer
708 "env" (concat "NNTPAUTH="
709 (or nntp-authinfo-generic
711 (error "NNTPAUTH unset")))
712 "authinfo-kludge" nntp-address)))
714 (nntp-wait-for-string "^\r*200")
716 (delete-region (point-min) (point))
719 (eval-after-load "erc"
720 '(load "~/.ercrc.el"))
722 ;;;--------------------------------------------------------------------------
723 ;;; Utility functions.
725 (or (fboundp 'line-number-at-pos)
726 (defun line-number-at-pos (&optional pos)
727 (let ((opoint (or pos (point))) start)
730 (goto-char (point-min))
736 (1+ (count-lines 1 (point))))))))
738 (defun mdw-uniquify-alist (&rest alists)
739 "Return the concatenation of the ALISTS with duplicate elements removed.
740 The first association with a given key prevails; others are
741 ignored. The input lists are not modified, although they'll
742 probably become garbage."
744 (let ((start-list (cons nil nil)))
745 (mdw-do-uniquify start-list
750 (defun mdw-do-uniquify (done end l rest)
751 "A helper function for mdw-uniquify-alist.
752 The DONE argument is a list whose first element is `nil'. It
753 contains the uniquified alist built so far. The leading `nil' is
754 stripped off at the end of the operation; it's only there so that
755 DONE always references a cons cell. END refers to the final cons
756 cell in the DONE list; it is modified in place each time to avoid
757 the overheads of `append'ing all the time. The L argument is the
758 alist we're currently processing; the remaining alists are given
761 ;; There are several different cases to deal with here.
764 ;; Current list isn't empty. Add the first item to the DONE list if
765 ;; there's not an item with the same KEY already there.
766 (l (or (assoc (car (car l)) done)
768 (setcdr end (cons (car l) nil))
769 (setq end (cdr end))))
770 (mdw-do-uniquify done end (cdr l) rest))
772 ;; The list we were working on is empty. Shunt the next list into the
773 ;; current list position and go round again.
774 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
776 ;; Everything's done. Remove the leading `nil' from the DONE list and
777 ;; return it. Finished!
781 "Insert the current date in a pleasing way."
783 (insert (save-excursion
784 (let ((buffer (get-buffer-create "*tmp*")))
785 (unwind-protect (progn (set-buffer buffer)
787 (shell-command "date +%Y-%m-%d" t)
789 (delete-backward-char 1)
791 (kill-buffer buffer))))))
793 (defun uuencode (file &optional name)
794 "UUencodes a file, maybe calling it NAME, into the current buffer."
795 (interactive "fInput file name: ")
797 ;; If NAME isn't specified, then guess from the filename.
801 (or (string-match "[^/]*$" file) 0))))
802 (print (format "uuencode `%s' `%s'" file name))
804 ;; Now actually do the thing.
805 (call-process "uuencode" file t nil name))
807 (defvar np-file "~/.np"
808 "*Where the `now-playing' file is.")
810 (defun np (&optional arg)
811 "Grabs a `now-playing' string."
815 (goto-char (point-max))
817 (insert-file-contents np-file)))))
819 (defun mdw-version-< (ver-a ver-b)
820 "Answer whether VER-A is strictly earlier than VER-B.
821 VER-A and VER-B are version numbers, which are strings containing digit
822 sequences separated by `.'."
823 (let* ((la (mapcar (lambda (x) (car (read-from-string x)))
824 (split-string ver-a "\\.")))
825 (lb (mapcar (lambda (x) (car (read-from-string x)))
826 (split-string ver-b "\\."))))
829 (cond ((null la) (throw 'done lb))
830 ((null lb) (throw 'done nil))
831 ((< (car la) (car lb)) (throw 'done t))
832 ((= (car la) (car lb)) (setq la (cdr la) lb (cdr lb)))
833 (t (throw 'done nil)))))))
835 (defun mdw-check-autorevert ()
836 "Sets global-auto-revert-ignore-buffer appropriately for this buffer.
837 This takes into consideration whether it's been found using
838 tramp, which seems to get itself into a twist."
839 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
841 ((and (buffer-file-name)
842 (fboundp 'tramp-tramp-file-p)
843 (tramp-tramp-file-p (buffer-file-name)))
844 (unless global-auto-revert-ignore-buffer
845 (setq global-auto-revert-ignore-buffer 'tramp)))
846 ((eq global-auto-revert-ignore-buffer 'tramp)
847 (setq global-auto-revert-ignore-buffer nil))))
849 (defadvice find-file (after mdw-autorevert activate)
850 (mdw-check-autorevert))
851 (defadvice write-file (after mdw-autorevert activate)
852 (mdw-check-autorevert))
854 ;;;--------------------------------------------------------------------------
857 (defadvice dired-maybe-insert-subdir
858 (around mdw-marked-insertion first activate)
859 "The DIRNAME may be a list of directory names to insert.
860 Interactively, if files are marked, then insert all of them.
861 With a numeric prefix argument, select that many entries near
862 point; with a non-numeric prefix argument, prompt for listing
865 (list (dired-get-marked-files nil
866 (and (integerp current-prefix-arg)
869 (and current-prefix-arg
870 (not (integerp current-prefix-arg))
871 (read-string "Switches for listing: "
872 (or dired-subdir-switches
873 dired-actual-switches)))))
874 (let ((dirs (ad-get-arg 0)))
875 (dolist (dir (if (listp dirs) dirs (list dirs)))
879 (defun mdw-dired-run (args &optional syncp)
880 (interactive (let ((file (dired-get-filename t)))
881 (list (read-string (format "Arguments for %s: " file))
882 current-prefix-arg)))
883 (funcall (if syncp 'shell-command 'async-shell-command)
884 (concat (shell-quote-argument (dired-get-filename nil))
887 (eval-after-load "dired"
888 '(define-key dired-mode-map "X" 'mdw-dired-run))
890 ;;;--------------------------------------------------------------------------
893 (defun mdw-w3m-browse-url (url &optional new-session-p)
894 "Invoke w3m on the URL in its current window, or at least a different one.
895 If NEW-SESSION-P, start a new session."
896 (interactive "sURL: \nP")
898 (let ((window (selected-window)))
901 (select-window (or (and (not new-session-p)
902 (get-buffer-window "*w3m*"))
904 (if (one-window-p t) (split-window))
906 (w3m-browse-url url new-session-p))
907 (select-window window)))))
909 (defvar mdw-good-url-browsers
912 (w3m . mdw-w3m-browse-url)
914 "List of good browsers for mdw-good-url-browsers.
915 Each item is a browser function name, or a cons (CHECK . FUNC).
916 A symbol FOO stands for (FOO . FOO).")
918 (defun mdw-good-url-browser ()
919 "Return a good URL browser.
920 Trundle the list of such things, finding the first item for which
921 CHECK is fboundp, and returning the correponding FUNC."
922 (let ((bs mdw-good-url-browsers) b check func answer)
923 (while (and bs (not answer))
927 (setq check (car b) func (cdr b))
928 (setq check b func b))
933 (eval-after-load "w3m-search"
937 '(("g" "Google" "http://www.google.co.uk/search?q=%s")
938 ("gd" "Google Directory"
939 "http://www.google.com/search?cat=gwd/Top&q=%s")
940 ("gg" "Google Groups" "http://groups.google.com/groups?q=%s")
941 ("ward" "Ward's wiki" "http://c2.com/cgi/wiki?%s")
942 ("gi" "Images" "http://images.google.com/images?q=%s")
944 "http://metalzone.distorted.org.uk/ftp/pub/mirrors/rfc/rfc%s.txt.gz")
946 "http://en.wikipedia.org/wiki/Special:Search?go=Go&search=%s")
947 ("imdb" "IMDb" "http://www.imdb.com/Find?%s")
948 ("nc-wiki" "nCipher wiki"
949 "http://wiki.ncipher.com/wiki/bin/view/Devel/?topic=%s")
950 ("map" "Google maps" "http://maps.google.co.uk/maps?q=%s&hl=en")
951 ("lp" "Launchpad bug by number"
952 "https://bugs.launchpad.net/bugs/%s")
953 ("lppkg" "Launchpad bugs by package"
954 "https://bugs.launchpad.net/%s")
956 "http://social.msdn.microsoft.com/Search/en-GB/?query=%s&ac=8")
957 ("debbug" "Debian bug by number"
958 "http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=%s")
959 ("debbugpkg" "Debian bugs by package"
960 "http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=%s")
961 ("ljlogin" "LJ login" "http://www.livejournal.com/login.bml")))
962 (add-to-list 'w3m-search-engine-alist
963 (list (cadr item) (caddr item) nil))
964 (add-to-list 'w3m-uri-replace-alist
965 (list (concat "\\`" (car item) ":")
966 'w3m-search-uri-replace
969 ;;;--------------------------------------------------------------------------
970 ;;; Paragraph filling.
974 (defvar mdw-fill-prefix nil
975 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'.
976 If there's no fill prefix currently set (by the `fill-prefix'
977 variable) and there's a match from one of the regexps here, it
978 gets used to set the fill-prefix for the current operation.
980 The variable is a list of items of the form `REGEXP . PREFIX'; if
981 the REGEXP matches, the PREFIX is used to set the fill prefix.
982 It in turn is a list of things:
984 STRING -- insert a literal string
985 (match . N) -- insert the thing matched by bracketed subexpression N
986 (pad . N) -- a string of whitespace the same width as subexpression N
987 (expr . FORM) -- the result of evaluating FORM")
989 (make-variable-buffer-local 'mdw-fill-prefix)
991 (defvar mdw-hanging-indents
993 "\\([*o+]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
996 "*Standard regexp matching parts of a hanging indent.
997 This is mainly useful in `auto-fill-mode'.")
999 ;; Setting things up.
1001 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
1003 ;; Utility functions.
1005 (defun mdw-maybe-tabify (s)
1006 "Tabify or untabify the string S, according to `indent-tabs-mode'."
1007 (let ((tabfun (if indent-tabs-mode #'tabify #'untabify)))
1011 (let ((start (point-min)) (end (point-max)))
1012 (funcall tabfun (point-min) (point-max))
1013 (setq s (buffer-substring (point-min) (1- (point-max)))))))))
1015 (defun mdw-examine-fill-prefixes (l)
1016 "Given a list of dynamic fill prefixes, pick one which matches
1017 context and return the static fill prefix to use. Point must be
1018 at the start of a line, and match data must be saved."
1020 ((looking-at (car (car l)))
1021 (mdw-maybe-tabify (apply #'concat
1022 (mapcar #'mdw-do-prefix-match
1024 (t (mdw-examine-fill-prefixes (cdr l)))))
1026 (defun mdw-maybe-car (p)
1027 "If P is a pair, return (car P), otherwise just return P."
1028 (if (consp p) (car p) p))
1030 (defun mdw-padding (s)
1031 "Return a string the same width as S but made entirely from whitespace."
1032 (let* ((l (length s)) (i 0) (n (make-string l ? )))
1034 (if (= 9 (aref s i))
1039 (defun mdw-do-prefix-match (m)
1040 "Expand a dynamic prefix match element.
1041 See `mdw-fill-prefix' for details."
1042 (cond ((not (consp m)) (format "%s" m))
1043 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
1044 ((eq (car m) 'pad) (mdw-padding (match-string
1045 (mdw-maybe-car (cdr m)))))
1046 ((eq (car m) 'eval) (eval (cdr m)))
1049 (defun mdw-choose-dynamic-fill-prefix ()
1050 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
1051 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
1052 ((not mdw-fill-prefix) fill-prefix)
1056 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
1058 (defun do-auto-fill ()
1059 "Handle auto-filling, working out a dynamic fill prefix in the
1060 case where there isn't a sensible static one."
1061 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1062 (mdw-do-auto-fill)))
1064 (defun mdw-fill-paragraph ()
1065 "Fill paragraph, getting a dynamic fill prefix."
1067 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
1068 (fill-paragraph nil)))
1070 (defun mdw-standard-fill-prefix (rx &optional mat)
1071 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
1072 This is just a short-cut for setting the thing by hand, and by
1073 design it doesn't cope with anything approximating a complicated
1075 (setq mdw-fill-prefix
1076 `((,(concat rx mdw-hanging-indents)
1078 (pad . ,(or mat 2))))))
1080 ;;;--------------------------------------------------------------------------
1081 ;;; Other common declarations.
1083 ;; Common mode settings.
1085 (defvar mdw-auto-indent t
1086 "Whether to indent automatically after a newline.")
1088 (defun mdw-whitespace-mode (&optional arg)
1089 "Turn on/off whitespace mode, but don't highlight trailing space."
1091 (when (and (boundp 'whitespace-style)
1092 (fboundp 'whitespace-mode))
1093 (let ((whitespace-style (remove 'trailing whitespace-style)))
1094 (whitespace-mode arg))
1095 (setq show-trailing-whitespace whitespace-mode)))
1097 (defvar mdw-do-misc-mode-hacking nil)
1099 (defun mdw-misc-mode-config ()
1100 (and mdw-auto-indent
1101 (cond ((eq major-mode 'lisp-mode)
1102 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
1103 ((derived-mode-p 'slime-repl-mode 'asm-mode 'comint-mode)
1106 (local-set-key "\C-m" 'newline-and-indent))))
1107 (set (make-local-variable 'mdw-do-misc-mode-hacking) t)
1108 (local-set-key [C-return] 'newline)
1109 (make-local-variable 'page-delimiter)
1110 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
1111 (setq comment-column 40)
1113 (setq fill-column mdw-text-width)
1114 (and (fboundp 'gtags-mode)
1116 (if (fboundp 'hs-minor-mode)
1117 (trap (hs-minor-mode t))
1118 (outline-minor-mode t))
1120 (trap (turn-on-font-lock)))
1122 (defun mdw-post-local-vars-misc-mode-config ()
1123 (setq whitespace-line-column mdw-text-width)
1124 (when (and mdw-do-misc-mode-hacking
1125 (not buffer-read-only))
1126 (setq show-trailing-whitespace t)
1127 (mdw-whitespace-mode 1)))
1128 (add-hook 'hack-local-variables-hook 'mdw-post-local-vars-misc-mode-config)
1130 (defmacro mdw-advise-update-angry-fruit-salad (&rest funcs)
1131 `(progn ,@(mapcar (lambda (func)
1133 (after mdw-angry-fruit-salad activate)
1134 (when mdw-do-misc-mode-hacking
1135 (setq show-trailing-whitespace
1136 (not buffer-read-only))
1137 (mdw-whitespace-mode (if buffer-read-only 0 1)))))
1139 (mdw-advise-update-angry-fruit-salad toggle-read-only
1145 (eval-after-load 'gtags
1147 (dolist (key '([mouse-2] [mouse-3]))
1148 (define-key gtags-mode-map key nil))
1149 (define-key gtags-mode-map [C-S-mouse-2] 'gtags-find-tag-by-event)
1150 (define-key gtags-select-mode-map [C-S-mouse-2]
1151 'gtags-select-tag-by-event)
1152 (dolist (map (list gtags-mode-map gtags-select-mode-map))
1153 (define-key map [C-S-mouse-3] 'gtags-pop-stack))))
1155 ;; Backup file handling.
1157 (defvar mdw-backup-disable-regexps nil
1158 "*List of regular expressions: if a file name matches any of
1159 these then the file is not backed up.")
1161 (defun mdw-backup-enable-predicate (name)
1162 "[mdw]'s default backup predicate.
1163 Allows a backup if the standard predicate would allow it, and it
1164 doesn't match any of the regular expressions in
1165 `mdw-backup-disable-regexps'."
1166 (and (normal-backup-enable-predicate name)
1167 (let ((answer t) (list mdw-backup-disable-regexps))
1170 (if (string-match (car list) name)
1172 (setq list (cdr list)))
1174 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
1178 (defun mdw-last-one-out-turn-off-the-lights (frame)
1179 "Disconnect from an X display if this was the last frame on that display."
1180 (let ((frame-display (frame-parameter frame 'display)))
1181 (when (and frame-display
1182 (eq window-system 'x)
1183 (not (some (lambda (fr)
1184 (and (not (eq fr frame))
1185 (string= (frame-parameter fr 'display)
1188 (run-with-idle-timer 0 nil #'x-close-connection frame-display))))
1189 (add-hook 'delete-frame-functions 'mdw-last-one-out-turn-off-the-lights)
1191 ;;;--------------------------------------------------------------------------
1192 ;;; Fullscreen-ness.
1194 (defvar mdw-full-screen-parameters
1195 '((menu-bar-lines . 0)
1196 ;(vertical-scroll-bars . nil)
1198 "Frame parameters to set when making a frame fullscreen.")
1200 (defvar mdw-full-screen-save
1202 "Extra frame parameters to save when setting fullscreen.")
1204 (defun mdw-toggle-full-screen (&optional frame)
1205 "Show the FRAME fullscreen."
1208 (cond ((frame-parameter frame 'fullscreen)
1209 (set-frame-parameter frame 'fullscreen nil)
1210 (modify-frame-parameters
1212 (or (frame-parameter frame 'mdw-full-screen-saved)
1213 (mapcar (lambda (assoc)
1214 (assq (car assoc) default-frame-alist))
1215 mdw-full-screen-parameters))))
1217 (let ((saved (mapcar (lambda (param)
1218 (cons param (frame-parameter frame param)))
1219 (append (mapcar #'car
1220 mdw-full-screen-parameters)
1221 mdw-full-screen-save))))
1222 (set-frame-parameter frame 'mdw-full-screen-saved saved))
1223 (modify-frame-parameters frame mdw-full-screen-parameters)
1224 (set-frame-parameter frame 'fullscreen 'fullboth)))))
1226 ;;;--------------------------------------------------------------------------
1227 ;;; General fontification.
1229 (make-face 'mdw-virgin-face)
1231 (defmacro mdw-define-face (name &rest body)
1232 "Define a face, and make sure it's actually set as the definition."
1236 (copy-face 'mdw-virgin-face ',name)
1237 (defvar ,name ',name)
1238 (put ',name 'face-defface-spec ',body)
1239 (face-spec-set ',name ',body nil)))
1241 (mdw-define-face default
1242 (((type w32)) :family "courier new" :height 85)
1243 (((type x)) :family "6x13" :foundry "trad" :height 130)
1244 (((type color)) :foreground "white" :background "black")
1246 (mdw-define-face fixed-pitch
1247 (((type w32)) :family "courier new" :height 85)
1248 (((type x)) :family "6x13" :foundry "trad" :height 130)
1249 (t :foreground "white" :background "black"))
1250 (if (mdw-emacs-version-p 23)
1251 (mdw-define-face variable-pitch
1252 (((type x)) :family "sans" :height 100))
1253 (mdw-define-face variable-pitch
1254 (((type x)) :family "helvetica" :height 90)))
1255 (mdw-define-face region
1256 (((min-colors 64)) :background "grey30")
1257 (((class color)) :background "blue")
1258 (t :inverse-video t))
1259 (mdw-define-face match
1260 (((class color)) :background "blue")
1261 (t :inverse-video t))
1262 (mdw-define-face mc/cursor-face
1263 (((class color)) :background "red")
1264 (t :inverse-video t))
1265 (mdw-define-face minibuffer-prompt
1267 (mdw-define-face mode-line
1268 (((class color)) :foreground "blue" :background "yellow"
1269 :box (:line-width 1 :style released-button))
1270 (t :inverse-video t))
1271 (mdw-define-face mode-line-inactive
1272 (((class color)) :foreground "yellow" :background "blue"
1273 :box (:line-width 1 :style released-button))
1274 (t :inverse-video t))
1275 (mdw-define-face nobreak-space
1277 (t :inherit escape-glyph :underline t))
1278 (mdw-define-face scroll-bar
1279 (t :foreground "black" :background "lightgrey"))
1280 (mdw-define-face fringe
1281 (t :foreground "yellow"))
1282 (mdw-define-face show-paren-match
1283 (((min-colors 64)) :background "darkgreen")
1284 (((class color)) :background "green")
1286 (mdw-define-face show-paren-mismatch
1287 (((class color)) :background "red")
1288 (t :inverse-video t))
1289 (mdw-define-face highlight
1290 (((min-colors 64)) :background "DarkSeaGreen4")
1291 (((class color)) :background "cyan")
1292 (t :inverse-video t))
1294 (mdw-define-face holiday-face
1295 (t :background "red"))
1296 (mdw-define-face calendar-today-face
1297 (t :foreground "yellow" :weight bold))
1299 (mdw-define-face comint-highlight-prompt
1301 (mdw-define-face comint-highlight-input
1304 (mdw-define-face ido-subdir
1305 (t :foreground "cyan" :weight bold))
1307 (mdw-define-face dired-directory
1308 (t :foreground "cyan" :weight bold))
1309 (mdw-define-face dired-symlink
1310 (t :foreground "cyan"))
1311 (mdw-define-face dired-perm-write
1314 (mdw-define-face trailing-whitespace
1315 (((class color)) :background "red")
1316 (t :inverse-video t))
1317 (mdw-define-face whitespace-line
1318 (((class color)) :background "darkred")
1319 (t :inverse-video t))
1320 (mdw-define-face mdw-punct-face
1321 (((min-colors 64)) :foreground "burlywood2")
1322 (((class color)) :foreground "yellow"))
1323 (mdw-define-face mdw-number-face
1324 (t :foreground "yellow"))
1325 (mdw-define-face mdw-trivial-face)
1326 (mdw-define-face font-lock-function-name-face
1328 (mdw-define-face font-lock-keyword-face
1330 (mdw-define-face font-lock-constant-face
1332 (mdw-define-face font-lock-builtin-face
1334 (mdw-define-face font-lock-type-face
1335 (t :weight bold :slant italic))
1336 (mdw-define-face font-lock-reference-face
1338 (mdw-define-face font-lock-variable-name-face
1340 (mdw-define-face font-lock-comment-delimiter-face
1341 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1342 (((class color)) :foreground "green")
1344 (mdw-define-face font-lock-comment-face
1345 (((min-colors 64)) :slant italic :foreground "SeaGreen1")
1346 (((class color)) :foreground "green")
1348 (mdw-define-face font-lock-string-face
1349 (((min-colors 64)) :foreground "SkyBlue1")
1350 (((class color)) :foreground "cyan")
1353 (mdw-define-face message-separator
1354 (t :background "red" :foreground "white" :weight bold))
1355 (mdw-define-face message-cited-text
1356 (default :slant italic)
1357 (((min-colors 64)) :foreground "SkyBlue1")
1358 (((class color)) :foreground "cyan"))
1359 (mdw-define-face message-header-cc
1360 (default :slant italic)
1361 (((min-colors 64)) :foreground "SeaGreen1")
1362 (((class color)) :foreground "green"))
1363 (mdw-define-face message-header-newsgroups
1364 (default :slant italic)
1365 (((min-colors 64)) :foreground "SeaGreen1")
1366 (((class color)) :foreground "green"))
1367 (mdw-define-face message-header-subject
1368 (((min-colors 64)) :foreground "SeaGreen1")
1369 (((class color)) :foreground "green"))
1370 (mdw-define-face message-header-to
1371 (((min-colors 64)) :foreground "SeaGreen1")
1372 (((class color)) :foreground "green"))
1373 (mdw-define-face message-header-xheader
1374 (default :slant italic)
1375 (((min-colors 64)) :foreground "SeaGreen1")
1376 (((class color)) :foreground "green"))
1377 (mdw-define-face message-header-other
1378 (default :slant italic)
1379 (((min-colors 64)) :foreground "SeaGreen1")
1380 (((class color)) :foreground "green"))
1381 (mdw-define-face message-header-name
1382 (default :weight bold)
1383 (((min-colors 64)) :foreground "SeaGreen1")
1384 (((class color)) :foreground "green"))
1386 (mdw-define-face which-func
1389 (mdw-define-face gnus-header-name
1390 (default :weight bold)
1391 (((min-colors 64)) :foreground "SeaGreen1")
1392 (((class color)) :foreground "green"))
1393 (mdw-define-face gnus-header-subject
1394 (((min-colors 64)) :foreground "SeaGreen1")
1395 (((class color)) :foreground "green"))
1396 (mdw-define-face gnus-header-from
1397 (((min-colors 64)) :foreground "SeaGreen1")
1398 (((class color)) :foreground "green"))
1399 (mdw-define-face gnus-header-to
1400 (((min-colors 64)) :foreground "SeaGreen1")
1401 (((class color)) :foreground "green"))
1402 (mdw-define-face gnus-header-content
1403 (default :slant italic)
1404 (((min-colors 64)) :foreground "SeaGreen1")
1405 (((class color)) :foreground "green"))
1407 (mdw-define-face gnus-cite-1
1408 (((min-colors 64)) :foreground "SkyBlue1")
1409 (((class color)) :foreground "cyan"))
1410 (mdw-define-face gnus-cite-2
1411 (((min-colors 64)) :foreground "RoyalBlue2")
1412 (((class color)) :foreground "blue"))
1413 (mdw-define-face gnus-cite-3
1414 (((min-colors 64)) :foreground "MediumOrchid")
1415 (((class color)) :foreground "magenta"))
1416 (mdw-define-face gnus-cite-4
1417 (((min-colors 64)) :foreground "firebrick2")
1418 (((class color)) :foreground "red"))
1419 (mdw-define-face gnus-cite-5
1420 (((min-colors 64)) :foreground "burlywood2")
1421 (((class color)) :foreground "yellow"))
1422 (mdw-define-face gnus-cite-6
1423 (((min-colors 64)) :foreground "SeaGreen1")
1424 (((class color)) :foreground "green"))
1425 (mdw-define-face gnus-cite-7
1426 (((min-colors 64)) :foreground "SlateBlue1")
1427 (((class color)) :foreground "cyan"))
1428 (mdw-define-face gnus-cite-8
1429 (((min-colors 64)) :foreground "RoyalBlue2")
1430 (((class color)) :foreground "blue"))
1431 (mdw-define-face gnus-cite-9
1432 (((min-colors 64)) :foreground "purple2")
1433 (((class color)) :foreground "magenta"))
1434 (mdw-define-face gnus-cite-10
1435 (((min-colors 64)) :foreground "DarkOrange2")
1436 (((class color)) :foreground "red"))
1437 (mdw-define-face gnus-cite-11
1438 (t :foreground "grey"))
1440 (mdw-define-face diff-header
1442 (mdw-define-face diff-index
1444 (mdw-define-face diff-file-header
1446 (mdw-define-face diff-hunk-header
1447 (((min-colors 64)) :foreground "SkyBlue1")
1448 (((class color)) :foreground "cyan"))
1449 (mdw-define-face diff-function
1450 (default :weight bold)
1451 (((min-colors 64)) :foreground "SkyBlue1")
1452 (((class color)) :foreground "cyan"))
1453 (mdw-define-face diff-header
1454 (((min-colors 64)) :background "grey10"))
1455 (mdw-define-face diff-added
1456 (((class color)) :foreground "green"))
1457 (mdw-define-face diff-removed
1458 (((class color)) :foreground "red"))
1459 (mdw-define-face diff-context
1461 (mdw-define-face diff-refine-change
1462 (((min-colors 64)) :background "RoyalBlue4")
1464 (mdw-define-face diff-refine-removed
1465 (((min-colors 64)) :background "#500")
1467 (mdw-define-face diff-refine-added
1468 (((min-colors 64)) :background "#050")
1471 (setq ediff-force-faces t)
1472 (mdw-define-face ediff-current-diff-A
1473 (((min-colors 64)) :background "darkred")
1474 (((class color)) :background "red")
1475 (t :inverse-video t))
1476 (mdw-define-face ediff-fine-diff-A
1477 (((min-colors 64)) :background "red3")
1478 (((class color)) :inverse-video t)
1479 (t :inverse-video nil))
1480 (mdw-define-face ediff-even-diff-A
1481 (((min-colors 64)) :background "#300"))
1482 (mdw-define-face ediff-odd-diff-A
1483 (((min-colors 64)) :background "#300"))
1484 (mdw-define-face ediff-current-diff-B
1485 (((min-colors 64)) :background "darkgreen")
1486 (((class color)) :background "magenta")
1487 (t :inverse-video t))
1488 (mdw-define-face ediff-fine-diff-B
1489 (((min-colors 64)) :background "green4")
1490 (((class color)) :inverse-video t)
1491 (t :inverse-video nil))
1492 (mdw-define-face ediff-even-diff-B
1493 (((min-colors 64)) :background "#020"))
1494 (mdw-define-face ediff-odd-diff-B
1495 (((min-colors 64)) :background "#020"))
1496 (mdw-define-face ediff-current-diff-C
1497 (((min-colors 64)) :background "darkblue")
1498 (((class color)) :background "blue")
1499 (t :inverse-video t))
1500 (mdw-define-face ediff-fine-diff-C
1501 (((min-colors 64)) :background "blue1")
1502 (((class color)) :inverse-video t)
1503 (t :inverse-video nil))
1504 (mdw-define-face ediff-even-diff-C
1505 (((min-colors 64)) :background "#004"))
1506 (mdw-define-face ediff-odd-diff-C
1507 (((min-colors 64)) :background "#004"))
1508 (mdw-define-face ediff-current-diff-Ancestor
1509 (((min-colors 64)) :background "#630")
1510 (((class color)) :background "blue")
1511 (t :inverse-video t))
1512 (mdw-define-face ediff-even-diff-Ancestor
1513 (((min-colors 64)) :background "#320"))
1514 (mdw-define-face ediff-odd-diff-Ancestor
1515 (((min-colors 64)) :background "#320"))
1517 (mdw-define-face magit-hash
1518 (((min-colors 64)) :foreground "grey40")
1519 (((class color)) :foreground "blue"))
1520 (mdw-define-face magit-diff-hunk-heading
1521 (((min-colors 64)) :foreground "grey70" :background "grey25")
1522 (((class color)) :foreground "yellow"))
1523 (mdw-define-face magit-diff-hunk-heading-highlight
1524 (((min-colors 64)) :foreground "grey70" :background "grey35")
1525 (((class color)) :foreground "yellow" :background "blue"))
1526 (mdw-define-face magit-diff-added
1527 (((min-colors 64)) :foreground "#ddffdd" :background "#335533")
1528 (((class color)) :foreground "green"))
1529 (mdw-define-face magit-diff-added-highlight
1530 (((min-colors 64)) :foreground "#cceecc" :background "#336633")
1531 (((class color)) :foreground "green" :background "blue"))
1532 (mdw-define-face magit-diff-removed
1533 (((min-colors 64)) :foreground "#ffdddd" :background "#553333")
1534 (((class color)) :foreground "red"))
1535 (mdw-define-face magit-diff-removed-highlight
1536 (((min-colors 64)) :foreground "#eecccc" :background "#663333")
1537 (((class color)) :foreground "red" :background "blue"))
1539 (mdw-define-face dylan-header-background
1540 (((min-colors 64)) :background "NavyBlue")
1541 (((class color)) :background "blue"))
1543 (mdw-define-face erc-input-face
1544 (t :foreground "red"))
1546 (mdw-define-face woman-bold
1548 (mdw-define-face woman-italic
1551 (eval-after-load "rst"
1553 (mdw-define-face rst-level-1-face
1554 (t :foreground "SkyBlue1" :weight bold))
1555 (mdw-define-face rst-level-2-face
1556 (t :foreground "SeaGreen1" :weight bold))
1557 (mdw-define-face rst-level-3-face
1559 (mdw-define-face rst-level-4-face
1561 (mdw-define-face rst-level-5-face
1563 (mdw-define-face rst-level-6-face
1566 (mdw-define-face p4-depot-added-face
1567 (t :foreground "green"))
1568 (mdw-define-face p4-depot-branch-op-face
1569 (t :foreground "yellow"))
1570 (mdw-define-face p4-depot-deleted-face
1571 (t :foreground "red"))
1572 (mdw-define-face p4-depot-unmapped-face
1573 (t :foreground "SkyBlue1"))
1574 (mdw-define-face p4-diff-change-face
1575 (t :foreground "yellow"))
1576 (mdw-define-face p4-diff-del-face
1577 (t :foreground "red"))
1578 (mdw-define-face p4-diff-file-face
1579 (t :foreground "SkyBlue1"))
1580 (mdw-define-face p4-diff-head-face
1581 (t :background "grey10"))
1582 (mdw-define-face p4-diff-ins-face
1583 (t :foreground "green"))
1585 (mdw-define-face w3m-anchor-face
1586 (t :foreground "SkyBlue1" :underline t))
1587 (mdw-define-face w3m-arrived-anchor-face
1588 (t :foreground "SkyBlue1" :underline t))
1590 (mdw-define-face whizzy-slice-face
1591 (t :background "grey10"))
1592 (mdw-define-face whizzy-error-face
1593 (t :background "darkred"))
1595 ;; Ellipses used to indicate hidden text (and similar).
1596 (mdw-define-face mdw-ellipsis-face
1597 (((type tty)) :foreground "blue") (t :foreground "grey60"))
1598 (let ((dollar (make-glyph-code ?$ 'mdw-ellipsis-face))
1599 (backslash (make-glyph-code ?\\ 'mdw-ellipsis-face))
1600 (dot (make-glyph-code ?. 'mdw-ellipsis-face))
1601 (bar (make-glyph-code ?| mdw-ellipsis-face)))
1602 (set-display-table-slot standard-display-table 0 dollar)
1603 (set-display-table-slot standard-display-table 1 backslash)
1604 (set-display-table-slot standard-display-table 4
1605 (vector dot dot dot))
1606 (set-display-table-slot standard-display-table 5 bar))
1608 ;;;--------------------------------------------------------------------------
1611 (mdw-define-face mdw-point-overlay-face
1613 (((min-colors 64)) :background "darkblue")
1614 (((class color)) :background "blue")
1615 (((type tty) (class mono)) :inverse-video t))
1617 (defvar mdw-point-overlay-fringe-display '(vertical-bar . vertical-bar))
1619 (defun mdw-configure-point-overlay ()
1620 (let ((ov (make-overlay 0 0)))
1621 (overlay-put ov 'priority 0)
1622 (let* ((fringe (or mdw-point-overlay-fringe-display (cons nil nil)))
1623 (left (car fringe)) (right (cdr fringe))
1627 (put-text-property 0 1 'display `(left-fringe ,left) ss)
1628 (setq s (concat s ss))))
1631 (put-text-property 0 1 'display `(right-fringe ,right) ss)
1632 (setq s (concat s ss))))
1633 (when (or left right)
1634 (overlay-put ov 'before-string s)))
1635 (overlay-put ov 'face 'mdw-point-overlay-face)
1639 (defvar mdw-point-overlay (mdw-configure-point-overlay)
1640 "An overlay used for showing where point is in the selected window.")
1641 (defun mdw-reconfigure-point-overlay ()
1643 (setq mdw-point-overlay (mdw-configure-point-overlay)))
1645 (defun mdw-remove-point-overlay ()
1646 "Remove the current-point overlay."
1647 (delete-overlay mdw-point-overlay))
1649 (defun mdw-update-point-overlay ()
1650 "Mark the current point position with an overlay."
1651 (if (not mdw-point-overlay-mode)
1652 (mdw-remove-point-overlay)
1653 (overlay-put mdw-point-overlay 'window (selected-window))
1654 (move-overlay mdw-point-overlay
1655 (line-beginning-position)
1656 (+ (line-end-position) 1))))
1658 (defvar mdw-point-overlay-buffers nil
1659 "List of buffers using `mdw-point-overlay-mode'.")
1661 (define-minor-mode mdw-point-overlay-mode
1662 "Indicate current line with an overlay."
1664 (let ((buffer (current-buffer)))
1665 (setq mdw-point-overlay-buffers
1666 (mapcan (lambda (buf)
1667 (if (and (buffer-live-p buf)
1668 (not (eq buf buffer)))
1670 mdw-point-overlay-buffers))
1671 (if mdw-point-overlay-mode
1672 (setq mdw-point-overlay-buffers
1673 (cons buffer mdw-point-overlay-buffers))))
1674 (cond (mdw-point-overlay-buffers
1675 (add-hook 'pre-command-hook 'mdw-remove-point-overlay)
1676 (add-hook 'post-command-hook 'mdw-update-point-overlay))
1678 (mdw-remove-point-overlay)
1679 (remove-hook 'pre-command-hook 'mdw-remove-point-overlay)
1680 (remove-hook 'post-command-hook 'mdw-update-point-overlay))))
1682 (define-globalized-minor-mode mdw-global-point-overlay-mode
1683 mdw-point-overlay-mode
1684 (lambda () (if (not (minibufferp)) (mdw-point-overlay-mode t))))
1686 ;;;--------------------------------------------------------------------------
1687 ;;; C programming configuration.
1689 ;; Make C indentation nice.
1691 (defun mdw-c-lineup-arglist (langelem)
1692 "Hack for DWIMmery in c-lineup-arglist."
1694 (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)))
1696 (c-lineup-arglist langelem)))
1698 (defun mdw-c-indent-extern-mumble (langelem)
1699 "Indent `extern \"...\" {' lines."
1701 (back-to-indentation)
1703 "\\s-*\\<extern\\>\\s-*\"\\([^\\\\\"]+\\|\\.\\)*\"\\s-*{")
1707 (defun mdw-c-indent-arglist-nested (langelem)
1708 "Indent continued argument lists.
1709 If we've nested more than one argument list, then only introduce a single
1710 indentation anyway."
1711 (let ((context c-syntactic-context)
1712 (pos (c-langelem-2nd-pos c-syntactic-element))
1713 (should-indent-p t))
1715 (eq (caar context) 'arglist-cont-nonempty))
1716 (when (and (= (caddr (pop context)) pos)
1718 (memq (caar context) '(arglist-intro
1719 arglist-cont-nonempty)))
1720 (setq should-indent-p nil)))
1721 (if should-indent-p '+ 0)))
1723 (defvar mdw-define-c-styles-hook nil
1724 "Hook run when `cc-mode' starts up to define styles.")
1726 (defmacro mdw-define-c-style (name &rest assocs)
1727 "Define a C style, called NAME (a symbol), setting ASSOCs.
1728 A function, named `mdw-define-c-style/NAME', is defined to actually install
1729 the style using `c-add-style', and added to the hook
1730 `mdw-define-c-styles-hook'. If CC Mode is already loaded, then the style is
1732 (declare (indent defun))
1733 (let* ((name-string (symbol-name name))
1734 (func (intern (concat "mdw-define-c-style/" name-string))))
1736 (defun ,func () (c-add-style ,name-string ',assocs))
1737 (and (featurep 'cc-mode) (,func))
1738 (add-hook 'mdw-define-c-styles-hook ',func))))
1740 (eval-after-load "cc-mode"
1741 '(run-hooks 'mdw-define-c-styles-hook))
1743 (mdw-define-c-style mdw-trustonic-c
1744 (c-basic-offset . 4)
1745 (comment-column . 0)
1746 (c-indent-comment-alist (anchored-comment . (column . 0))
1747 (end-block . (space . 1))
1748 (cpp-end-block . (space . 1))
1749 (other . (space . 1)))
1750 (c-class-key . "class")
1751 (c-backslash-column . 0)
1752 (c-auto-align-backslashes . nil)
1753 (c-label-minimum-indentation . 0)
1754 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1755 (defun-open . (add 0 c-indent-one-line-block))
1756 (arglist-cont-nonempty . mdw-c-indent-arglist-nested)
1757 (topmost-intro . mdw-c-indent-extern-mumble)
1758 (cpp-define-intro . 0)
1760 (inextern-lang . [0])
1766 (statement-cont . +)
1767 (statement-case-intro . +)))
1769 (mdw-define-c-style mdw-c
1770 (c-basic-offset . 2)
1771 (comment-column . 40)
1772 (c-class-key . "class")
1773 (c-backslash-column . 72)
1774 (c-label-minimum-indentation . 0)
1775 (c-offsets-alist (substatement-open . (add 0 c-indent-one-line-block))
1776 (defun-open . (add 0 c-indent-one-line-block))
1777 (arglist-cont-nonempty . mdw-c-lineup-arglist)
1778 (topmost-intro . mdw-c-indent-extern-mumble)
1779 (cpp-define-intro . 0)
1781 (inextern-lang . [0])
1787 (statement-cont . +)
1788 (statement-case-intro . +)))
1790 (defun mdw-set-default-c-style (modes style)
1791 "Update the default CC Mode style for MODES to be STYLE.
1793 MODES may be a list of major mode names or a singleton. STYLE is a style
1795 (let ((modes (if (listp modes) modes (list modes)))
1796 (style (symbol-name style)))
1797 (setq c-default-style
1798 (append (mapcar (lambda (mode)
1801 (remove-if (lambda (assoc)
1802 (memq (car assoc) modes))
1803 (if (listp c-default-style)
1805 (list (cons 'other c-default-style))))))))
1806 (setq c-default-style "mdw-c")
1808 (mdw-set-default-c-style '(c-mode c++-mode) 'mdw-c)
1810 (defvar mdw-c-comment-fill-prefix
1811 `((,(concat "\\([ \t]*/?\\)"
1814 "\\([A-Za-z]+:[ \t]*\\)?"
1815 mdw-hanging-indents)
1816 (pad . 1) (match . 2) (pad . 3) (pad . 4) (pad . 5)))
1817 "Fill prefix matching C comments (both kinds).")
1819 (defun mdw-fontify-c-and-c++ ()
1821 ;; Fiddle with some syntax codes.
1822 (modify-syntax-entry ?* ". 23")
1823 (modify-syntax-entry ?/ ". 124b")
1824 (modify-syntax-entry ?\n "> b")
1827 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
1829 ;; Now define things to be fontified.
1830 (make-local-variable 'font-lock-keywords)
1832 (mdw-regexps "alignas" ;C11 macro, C++11
1834 "and" ;C++, C95 macro
1835 "and_eq" ;C++, C95 macro
1836 "asm" ;K&R, C++, GCC
1837 "atomic" ;C11 macro, C++11 template type
1839 "bitand" ;C++, C95 macro
1840 "bitor" ;C++, C95 macro
1841 "bool" ;C++, C99 macro
1846 "char16_t" ;C++11, C11 library type
1847 "char32_t" ;C++11, C11 library type
1849 "complex" ;C99 macro, C++ template type
1850 "compl" ;C++, C95 macro
1854 "continue" ;K&R, C89
1856 "defined" ;C89 preprocessor
1863 ;; "entry" ;K&R -- never used
1874 "imaginary" ;C99 macro
1875 "inline" ;C++, C99, GCC
1882 "noreturn" ;C11 macro
1883 "not" ;C++, C95 macro
1884 "not_eq" ;C++, C95 macro
1887 "or" ;C++, C95 macro
1888 "or_eq" ;C++, C95 macro
1892 "register" ;K&R, C89
1893 "reinterpret_cast" ;C++
1900 "static_assert" ;C11 macro, C++11
1907 "thread_local" ;C11 macro, C++11
1913 "unsigned" ;K&R, C89
1918 "wchar_t" ;C++, C89 library type
1920 "xor" ;C++, C95 macro
1921 "xor_eq" ;C++, C95 macro
1930 "_Pragma" ;C99 preprocessor
1931 "_Static_assert" ;C11
1932 "_Thread_local" ;C11
1935 "__attribute__" ;GCC
1938 "__extension__" ;GCC
1948 (mdw-regexps "false" ;C++, C99 macro
1950 "true" ;C++, C99 macro
1952 (preprocessor-keywords
1953 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1954 "ident" "if" "ifdef" "ifndef" "import" "include"
1955 "line" "pragma" "unassert" "undef" "warning"))
1957 (mdw-regexps "class" "defs" "encode" "end" "implementation"
1958 "interface" "private" "protected" "protocol" "public"
1961 (setq font-lock-keywords
1964 ;; Fontify include files as strings.
1965 (list (concat "^[ \t]*\\#[ \t]*"
1966 "\\(include\\|import\\)"
1967 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1968 '(2 font-lock-string-face))
1970 ;; Preprocessor directives are `references'?.
1971 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1972 preprocessor-keywords
1973 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1974 '(1 font-lock-keyword-face))
1976 ;; Handle the keywords defined above.
1977 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
1978 '(0 font-lock-keyword-face))
1980 (list (concat "\\<\\(" c-keywords "\\)\\>")
1981 '(0 font-lock-keyword-face))
1983 (list (concat "\\<\\(" c-constants "\\)\\>")
1984 '(0 font-lock-variable-name-face))
1986 ;; Handle numbers too.
1988 ;; This looks strange, I know. It corresponds to the
1989 ;; preprocessor's idea of what a number looks like, rather than
1990 ;; anything sensible.
1991 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
1992 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
1993 '(0 mdw-number-face))
1995 ;; And anything else is punctuation.
1996 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1997 '(0 mdw-punct-face))))))
1999 (define-derived-mode sod-mode c-mode "Sod"
2000 "Major mode for editing Sod code.")
2001 (push '("\\.sod$" . sod-mode) auto-mode-alist)
2003 ;;;--------------------------------------------------------------------------
2006 (define-derived-mode apcalc-mode c-mode "AP Calc"
2007 "Major mode for editing Calc code.")
2009 (defun mdw-fontify-apcalc ()
2011 ;; Fiddle with some syntax codes.
2012 (modify-syntax-entry ?* ". 23")
2013 (modify-syntax-entry ?/ ". 14")
2016 (setq comment-start "/* ")
2017 (setq comment-end " */")
2018 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2020 ;; Now define things to be fontified.
2021 (make-local-variable 'font-lock-keywords)
2023 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
2024 "do" "else" "exit" "for" "global" "goto" "help" "if"
2025 "local" "mat" "obj" "print" "quit" "read" "return"
2026 "show" "static" "switch" "while" "write")))
2028 (setq font-lock-keywords
2031 ;; Handle the keywords defined above.
2032 (list (concat "\\<\\(" c-keywords "\\)\\>")
2033 '(0 font-lock-keyword-face))
2035 ;; Handle numbers too.
2037 ;; This looks strange, I know. It corresponds to the
2038 ;; preprocessor's idea of what a number looks like, rather than
2039 ;; anything sensible.
2040 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
2041 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
2042 '(0 mdw-number-face))
2044 ;; And anything else is punctuation.
2045 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2046 '(0 mdw-punct-face))))))
2048 ;;;--------------------------------------------------------------------------
2049 ;;; Java programming configuration.
2051 ;; Make indentation nice.
2053 (mdw-define-c-style mdw-java
2054 (c-basic-offset . 2)
2055 (c-backslash-column . 72)
2056 (c-offsets-alist (substatement-open . 0)
2061 (statement-case-intro . +)))
2062 (mdw-set-default-c-style 'java-mode 'mdw-java)
2064 ;; Declare Java fontification style.
2066 (defun mdw-fontify-java ()
2069 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2071 ;; Now define things to be fontified.
2072 (make-local-variable 'font-lock-keywords)
2073 (let ((java-keywords
2074 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
2075 "char" "class" "const" "continue" "default" "do"
2076 "double" "else" "extends" "final" "finally" "float"
2077 "for" "goto" "if" "implements" "import" "instanceof"
2078 "int" "interface" "long" "native" "new" "package"
2079 "private" "protected" "public" "return" "short"
2080 "static" "switch" "synchronized" "throw" "throws"
2081 "transient" "try" "void" "volatile" "while"))
2084 (mdw-regexps "false" "null" "super" "this" "true")))
2086 (setq font-lock-keywords
2089 ;; Handle the keywords defined above.
2090 (list (concat "\\<\\(" java-keywords "\\)\\>")
2091 '(0 font-lock-keyword-face))
2093 ;; Handle the magic constants defined above.
2094 (list (concat "\\<\\(" java-constants "\\)\\>")
2095 '(0 font-lock-variable-name-face))
2097 ;; Handle numbers too.
2099 ;; The following isn't quite right, but it's close enough.
2100 (list (concat "\\<\\("
2101 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2102 "[0-9]+\\(\\.[0-9]*\\|\\)"
2103 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2105 '(0 mdw-number-face))
2107 ;; And anything else is punctuation.
2108 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2109 '(0 mdw-punct-face))))))
2111 ;;;--------------------------------------------------------------------------
2112 ;;; Javascript programming configuration.
2114 (defun mdw-javascript-style ()
2115 (setq js-indent-level 2)
2116 (setq js-expr-indent-offset 0))
2118 (defun mdw-fontify-javascript ()
2121 (mdw-javascript-style)
2122 (setq js-auto-indent-flag t)
2124 ;; Now define things to be fontified.
2125 (make-local-variable 'font-lock-keywords)
2126 (let ((javascript-keywords
2127 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
2128 "char" "class" "const" "continue" "debugger" "default"
2129 "delete" "do" "double" "else" "enum" "export" "extends"
2130 "final" "finally" "float" "for" "function" "goto" "if"
2131 "implements" "import" "in" "instanceof" "int"
2132 "interface" "let" "long" "native" "new" "package"
2133 "private" "protected" "public" "return" "short"
2134 "static" "super" "switch" "synchronized" "throw"
2135 "throws" "transient" "try" "typeof" "var" "void"
2136 "volatile" "while" "with" "yield"
2138 "boolean" "byte" "char" "double" "float" "int" "long"
2140 (javascript-constants
2141 (mdw-regexps "false" "null" "undefined" "Infinity" "NaN" "true"
2142 "arguments" "this")))
2144 (setq font-lock-keywords
2147 ;; Handle the keywords defined above.
2148 (list (concat "\\_<\\(" javascript-keywords "\\)\\_>")
2149 '(0 font-lock-keyword-face))
2151 ;; Handle the predefined constants defined above.
2152 (list (concat "\\_<\\(" javascript-constants "\\)\\_>")
2153 '(0 font-lock-variable-name-face))
2155 ;; Handle numbers too.
2157 ;; The following isn't quite right, but it's close enough.
2158 (list (concat "\\_<\\("
2159 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2160 "[0-9]+\\(\\.[0-9]*\\|\\)"
2161 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2163 '(0 mdw-number-face))
2165 ;; And anything else is punctuation.
2166 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2167 '(0 mdw-punct-face))))))
2169 ;;;--------------------------------------------------------------------------
2170 ;;; Scala programming configuration.
2172 (defun mdw-fontify-scala ()
2175 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2177 ;; Define things to be fontified.
2178 (make-local-variable 'font-lock-keywords)
2179 (let ((scala-keywords
2180 (mdw-regexps "abstract" "case" "catch" "class" "def" "do" "else"
2181 "extends" "final" "finally" "for" "forSome" "if"
2182 "implicit" "import" "lazy" "match" "new" "object"
2183 "override" "package" "private" "protected" "return"
2184 "sealed" "throw" "trait" "try" "type" "val"
2185 "var" "while" "with" "yield"))
2187 (mdw-regexps "false" "null" "super" "this" "true"))
2188 (punctuation "[-!%^&*=+:@#~/?\\|`]"))
2190 (setq font-lock-keywords
2193 ;; Magical identifiers between backticks.
2194 (list (concat "`\\([^`]+\\)`")
2195 '(1 font-lock-variable-name-face))
2197 ;; Handle the keywords defined above.
2198 (list (concat "\\_<\\(" scala-keywords "\\)\\_>")
2199 '(0 font-lock-keyword-face))
2201 ;; Handle the constants defined above.
2202 (list (concat "\\_<\\(" scala-constants "\\)\\_>")
2203 '(0 font-lock-variable-name-face))
2205 ;; Magical identifiers between backticks.
2206 (list (concat "`\\([^`]+\\)`")
2207 '(1 font-lock-variable-name-face))
2209 ;; Handle numbers too.
2211 ;; As usual, not quite right.
2212 (list (concat "\\_<\\("
2213 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2214 "[0-9]+\\(\\.[0-9]*\\|\\)"
2215 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2217 '(0 mdw-number-face))
2219 ;; Identifiers with trailing operators.
2220 (list (concat "_\\(" punctuation "\\)+")
2221 '(0 mdw-trivial-face))
2223 ;; And everything else is punctuation.
2224 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2225 '(0 mdw-punct-face)))
2227 font-lock-syntactic-keywords
2230 ;; Single quotes around characters. But not when used to quote
2231 ;; symbol names. Ugh.
2232 (list (concat "\\('\\)"
2234 "\\|" "\\\\" "\\(" "\\\\\\\\" "\\)*"
2235 "u+" "[0-9a-fA-F]\\{4\\}"
2236 "\\|" "\\\\" "[0-7]\\{1,3\\}"
2237 "\\|" "\\\\" "." "\\)"
2242 ;;;--------------------------------------------------------------------------
2243 ;;; C# programming configuration.
2245 ;; Make indentation nice.
2247 (mdw-define-c-style mdw-csharp
2248 (c-basic-offset . 2)
2249 (c-backslash-column . 72)
2250 (c-offsets-alist (substatement-open . 0)
2255 (statement-case-intro . +)))
2256 (mdw-set-default-c-style 'csharp-mode 'mdw-csharp)
2258 ;; Declare C# fontification style.
2260 (defun mdw-fontify-csharp ()
2263 (setq mdw-fill-prefix mdw-c-comment-fill-prefix)
2265 ;; Now define things to be fontified.
2266 (make-local-variable 'font-lock-keywords)
2267 (let ((csharp-keywords
2268 (mdw-regexps "abstract" "as" "bool" "break" "byte" "case" "catch"
2269 "char" "checked" "class" "const" "continue" "decimal"
2270 "default" "delegate" "do" "double" "else" "enum"
2271 "event" "explicit" "extern" "finally" "fixed" "float"
2272 "for" "foreach" "goto" "if" "implicit" "in" "int"
2273 "interface" "internal" "is" "lock" "long" "namespace"
2274 "new" "object" "operator" "out" "override" "params"
2275 "private" "protected" "public" "readonly" "ref"
2276 "return" "sbyte" "sealed" "short" "sizeof"
2277 "stackalloc" "static" "string" "struct" "switch"
2278 "throw" "try" "typeof" "uint" "ulong" "unchecked"
2279 "unsafe" "ushort" "using" "virtual" "void" "volatile"
2283 (mdw-regexps "base" "false" "null" "this" "true")))
2285 (setq font-lock-keywords
2288 ;; Handle the keywords defined above.
2289 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
2290 '(0 font-lock-keyword-face))
2292 ;; Handle the magic constants defined above.
2293 (list (concat "\\<\\(" csharp-constants "\\)\\>")
2294 '(0 font-lock-variable-name-face))
2296 ;; Handle numbers too.
2298 ;; The following isn't quite right, but it's close enough.
2299 (list (concat "\\<\\("
2300 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2301 "[0-9]+\\(\\.[0-9]*\\|\\)"
2302 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2304 '(0 mdw-number-face))
2306 ;; And anything else is punctuation.
2307 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2308 '(0 mdw-punct-face))))))
2310 (define-derived-mode csharp-mode java-mode "C#"
2311 "Major mode for editing C# code.")
2313 ;;;--------------------------------------------------------------------------
2314 ;;; F# programming configuration.
2316 (setq fsharp-indent-offset 2)
2318 (defun mdw-fontify-fsharp ()
2320 (let ((punct "=<>+-*/|&%!@?"))
2322 ((>= i (length punct)))
2323 (modify-syntax-entry (aref punct i) ".")))
2325 (modify-syntax-entry ?_ "_")
2326 (modify-syntax-entry ?( "(")
2327 (modify-syntax-entry ?) ")")
2329 (setq indent-tabs-mode nil)
2331 (let ((fsharp-keywords
2332 (mdw-regexps "abstract" "and" "as" "assert" "atomic"
2334 "checked" "class" "component" "const" "constraint"
2335 "constructor" "continue"
2336 "default" "delegate" "do" "done" "downcast" "downto"
2337 "eager" "elif" "else" "end" "exception" "extern"
2338 "finally" "fixed" "for" "fori" "fun" "function"
2341 "if" "in" "include" "inherit" "inline" "interface"
2344 "match" "measure" "member" "method" "mixin" "module"
2347 "object" "of" "open" "or" "override"
2348 "parallel" "params" "private" "process" "protected"
2350 "rec" "recursive" "return"
2351 "sealed" "sig" "static" "struct"
2352 "tailcall" "then" "to" "trait" "try" "type"
2354 "val" "virtual" "void" "volatile"
2355 "when" "while" "with"
2359 (mdw-regexps "asr" "land" "lor" "lsl" "lsr" "lxor" "mod"
2360 "base" "false" "null" "true"))
2363 (mdw-regexps "do" "let" "return" "use" "yield"))
2365 (preprocessor-keywords
2366 (mdw-regexps "if" "indent" "else" "endif")))
2368 (setq font-lock-keywords
2369 (list (list (concat "\\(^\\|[^\"]\\)"
2372 "\\(" "[^)*]" "[^*]*" "\\*+" "\\)*"
2377 '(2 font-lock-comment-face))
2379 (list (concat "'" "\\("
2382 "\\|" "[0-9][0-9][0-9]"
2383 "\\|" "u" "[0-9a-fA-F]\\{4\\}"
2384 "\\|" "U" "[0-9a-fA-F]\\{8\\}"
2390 "\\(" "\\\\" "\\(.\\|\n\\)"
2393 '(0 font-lock-string-face))
2395 (list (concat "\\_<\\(" bang-keywords "\\)!" "\\|"
2396 "^#[ \t]*\\(" preprocessor-keywords "\\)\\_>"
2398 "\\_<\\(" fsharp-keywords "\\)\\_>")
2399 '(0 font-lock-keyword-face))
2400 (list (concat "\\<\\(" fsharp-builtins "\\)\\_>")
2401 '(0 font-lock-variable-name-face))
2403 (list (concat "\\_<"
2404 "\\(" "0[bB][01]+" "\\|"
2406 "0[xX][0-9a-fA-F]+" "\\)"
2407 "\\(" "lf\\|LF" "\\|"
2408 "[uU]?[ysnlL]?" "\\)"
2415 "\\([eE][-+]?[0-9]+\\)?"
2420 '(0 mdw-number-face))
2422 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2423 '(0 mdw-punct-face))))))
2425 (defun mdw-fontify-inferior-fsharp ()
2426 (mdw-fontify-fsharp)
2427 (setq font-lock-keywords
2428 (append (list (list "^[#-]" '(0 font-lock-comment-face))
2429 (list "^>" '(0 font-lock-keyword-face)))
2430 font-lock-keywords)))
2432 ;;;--------------------------------------------------------------------------
2433 ;;; Go programming configuration.
2435 (defun mdw-fontify-go ()
2437 (make-local-variable 'font-lock-keywords)
2439 (mdw-regexps "break" "case" "chan" "const" "continue"
2440 "default" "defer" "else" "fallthrough" "for"
2441 "func" "go" "goto" "if" "import"
2442 "interface" "map" "package" "range" "return"
2443 "select" "struct" "switch" "type" "var"))
2445 (mdw-regexps "bool" "byte" "complex64" "complex128" "error"
2446 "float32" "float64" "int" "uint8" "int16" "int32"
2447 "int64" "rune" "string" "uint" "uint8" "uint16"
2448 "uint32" "uint64" "uintptr" "void"
2449 "false" "iota" "nil" "true"
2451 "append" "cap" "copy" "delete" "imag" "len" "make"
2452 "new" "panic" "real" "recover")))
2454 (setq font-lock-keywords
2457 ;; Handle the keywords defined above.
2458 (list (concat "\\<\\(" go-keywords "\\)\\>")
2459 '(0 font-lock-keyword-face))
2460 (list (concat "\\<\\(" go-intrinsics "\\)\\>")
2461 '(0 font-lock-variable-name-face))
2463 ;; Strings and characters.
2465 "\\(" "[^\\']" "\\|"
2467 "\\(" "[abfnrtv\\'\"]" "\\|"
2468 "[0-7]\\{3\\}" "\\|"
2469 "x" "[0-9A-Fa-f]\\{2\\}" "\\|"
2470 "u" "[0-9A-Fa-f]\\{4\\}" "\\|"
2471 "U" "[0-9A-Fa-f]\\{8\\}" "\\)" "\\)"
2475 "\\(" "[^\n\\\"]+" "\\|" "\\\\." "\\)*"
2479 '(0 font-lock-string-face))
2481 ;; Handle numbers too.
2483 ;; The following isn't quite right, but it's close enough.
2484 (list (concat "\\<\\("
2485 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2486 "[0-9]+\\(\\.[0-9]*\\|\\)"
2487 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)")
2488 '(0 mdw-number-face))
2490 ;; And anything else is punctuation.
2491 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2492 '(0 mdw-punct-face))))))
2494 ;;;--------------------------------------------------------------------------
2495 ;;; Rust programming configuration.
2497 (setq-default rust-indent-offset 2)
2499 (defun mdw-self-insert-and-indent (count)
2501 (self-insert-command count)
2502 (indent-according-to-mode))
2504 (defun mdw-fontify-rust ()
2506 ;; Hack syntax categories.
2507 (modify-syntax-entry ?= ".")
2509 ;; Fontify keywords and things.
2510 (make-local-variable 'font-lock-keywords)
2511 (let ((rust-keywords
2512 (mdw-regexps "abstract" "alignof" "as"
2513 "become" "box" "break"
2514 "const" "continue" "create"
2516 "else" "enum" "extern"
2517 "false" "final" "fn" "for"
2520 "macro" "match" "mod" "move" "mut"
2521 "offsetof" "override"
2524 "self" "sizeof" "static" "struct" "super"
2525 "true" "trait" "type" "typeof"
2526 "unsafe" "unsized" "use"
2531 (mdw-regexps "array" "pointer" "slice" "tuple"
2532 "bool" "true" "false"
2534 "i8" "i16" "i32" "i64" "isize"
2535 "u8" "u16" "u32" "u64" "usize"
2537 (setq font-lock-keywords
2540 ;; Handle the keywords defined above.
2541 (list (concat "\\_<\\(" rust-keywords "\\)\\_>")
2542 '(0 font-lock-keyword-face))
2543 (list (concat "\\_<\\(" rust-builtins "\\)\\_>")
2544 '(0 font-lock-variable-name-face))
2546 ;; Handle numbers too.
2547 (list (concat "\\_<\\("
2549 "\\(" "\\(\\.[0-9_]+\\)?[eE][-+]?[0-9_]+"
2553 "\\|" "\\(" "[0-9][0-9_]*"
2554 "\\|" "0x[0-9a-fA-F_]+"
2558 "\\([ui]\\(8\\|16\\|32\\|64\\|s\\|size\\)\\)?"
2560 '(0 mdw-number-face))
2562 ;; And anything else is punctuation.
2563 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2564 '(0 mdw-punct-face)))))
2566 ;; Hack key bindings.
2567 (local-set-key [?{] 'mdw-self-insert-and-indent)
2568 (local-set-key [?}] 'mdw-self-insert-and-indent))
2570 ;;;--------------------------------------------------------------------------
2571 ;;; Awk programming configuration.
2573 ;; Make Awk indentation nice.
2575 (mdw-define-c-style mdw-awk
2576 (c-basic-offset . 2)
2577 (c-offsets-alist (substatement-open . 0)
2578 (c-backslash-column . 72)
2579 (statement-cont . 0)
2580 (statement-case-intro . +)))
2581 (mdw-set-default-c-style 'awk-mode 'mdw-awk)
2583 ;; Declare Awk fontification style.
2585 (defun mdw-fontify-awk ()
2587 ;; Miscellaneous fiddling.
2588 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2590 ;; Now define things to be fontified.
2591 (make-local-variable 'font-lock-keywords)
2593 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
2594 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
2595 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
2596 "RSTART" "RLENGTH" "RT" "SUBSEP"
2597 "atan2" "break" "close" "continue" "cos" "delete"
2598 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
2599 "function" "gensub" "getline" "gsub" "if" "in"
2600 "index" "int" "length" "log" "match" "next" "rand"
2601 "return" "print" "printf" "sin" "split" "sprintf"
2602 "sqrt" "srand" "strftime" "sub" "substr" "system"
2603 "systime" "tolower" "toupper" "while")))
2605 (setq font-lock-keywords
2608 ;; Handle the keywords defined above.
2609 (list (concat "\\<\\(" c-keywords "\\)\\>")
2610 '(0 font-lock-keyword-face))
2612 ;; Handle numbers too.
2614 ;; The following isn't quite right, but it's close enough.
2615 (list (concat "\\<\\("
2616 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
2617 "[0-9]+\\(\\.[0-9]*\\|\\)"
2618 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
2620 '(0 mdw-number-face))
2622 ;; And anything else is punctuation.
2623 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2624 '(0 mdw-punct-face))))))
2626 ;;;--------------------------------------------------------------------------
2627 ;;; Perl programming style.
2629 ;; Perl indentation style.
2631 (setq perl-indent-level 2)
2633 (setq cperl-indent-level 2)
2634 (setq cperl-continued-statement-offset 2)
2635 (setq cperl-continued-brace-offset 0)
2636 (setq cperl-brace-offset -2)
2637 (setq cperl-brace-imaginary-offset 0)
2638 (setq cperl-label-offset 0)
2640 ;; Define perl fontification style.
2642 (defun mdw-fontify-perl ()
2644 ;; Miscellaneous fiddling.
2645 (modify-syntax-entry ?$ "\\")
2646 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
2647 (modify-syntax-entry ?: "." font-lock-syntax-table)
2648 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2650 ;; Now define fontification things.
2651 (make-local-variable 'font-lock-keywords)
2652 (let ((perl-keywords
2659 "ge" "given" "gt" "goto"
2661 "last" "le" "local" "lt"
2666 "redo" "require" "return"
2668 "undef" "unless" "until" "use"
2671 (setq font-lock-keywords
2674 ;; Set up the keywords defined above.
2675 (list (concat "\\<\\(" perl-keywords "\\)\\>")
2676 '(0 font-lock-keyword-face))
2678 ;; At least numbers are simpler than C.
2679 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2680 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2681 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2682 '(0 mdw-number-face))
2684 ;; And anything else is punctuation.
2685 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2686 '(0 mdw-punct-face))))))
2688 (defun perl-number-tests (&optional arg)
2689 "Assign consecutive numbers to lines containing `#t'. With ARG,
2690 strip numbers instead."
2693 (goto-char (point-min))
2694 (let ((i 0) (fmt (if arg "" " %4d")))
2695 (while (search-forward "#t" nil t)
2696 (delete-region (point) (line-end-position))
2698 (insert (format fmt i)))
2699 (goto-char (point-min))
2700 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
2701 (replace-match (format "\\1%d" i))))))
2703 ;;;--------------------------------------------------------------------------
2704 ;;; Python programming style.
2706 (defun mdw-fontify-pythonic (keywords)
2708 ;; Miscellaneous fiddling.
2709 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2710 (setq indent-tabs-mode nil)
2712 ;; Now define fontification things.
2713 (make-local-variable 'font-lock-keywords)
2714 (setq font-lock-keywords
2717 ;; Set up the keywords defined above.
2718 (list (concat "\\_<\\(" keywords "\\)\\_>")
2719 '(0 font-lock-keyword-face))
2721 ;; At least numbers are simpler than C.
2722 (list (concat "\\_<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2723 "\\_<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2724 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
2725 '(0 mdw-number-face))
2727 ;; And anything else is punctuation.
2728 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2729 '(0 mdw-punct-face)))))
2731 ;; Define Python fontification styles.
2733 (defun mdw-fontify-python ()
2734 (mdw-fontify-pythonic
2735 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
2736 "del" "elif" "else" "except" "exec" "finally" "for"
2737 "from" "global" "if" "import" "in" "is" "lambda"
2738 "not" "or" "pass" "print" "raise" "return" "try"
2739 "while" "with" "yield")))
2741 (defun mdw-fontify-pyrex ()
2742 (mdw-fontify-pythonic
2743 (mdw-regexps "and" "as" "assert" "break" "cdef" "class" "continue"
2744 "ctypedef" "def" "del" "elif" "else" "enum" "except" "exec"
2745 "extern" "finally" "for" "from" "global" "if"
2746 "import" "in" "is" "lambda" "not" "or" "pass" "print"
2747 "property" "raise" "return" "struct" "try" "while" "with"
2750 (define-derived-mode pyrex-mode python-mode "Pyrex"
2751 "Major mode for editing Pyrex source code")
2752 (setq auto-mode-alist
2753 (append '(("\\.pyx$" . pyrex-mode)
2754 ("\\.pxd$" . pyrex-mode)
2755 ("\\.pxi$" . pyrex-mode))
2758 ;;;--------------------------------------------------------------------------
2759 ;;; Lua programming style.
2761 (setq lua-indent-level 2)
2763 (defun mdw-fontify-lua ()
2765 ;; Miscellaneous fiddling.
2766 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2768 ;; Now define fontification things.
2769 (make-local-variable 'font-lock-keywords)
2771 (mdw-regexps "and" "break" "do" "else" "elseif" "end"
2772 "false" "for" "function" "goto" "if" "in" "local"
2773 "nil" "not" "or" "repeat" "return" "then" "true"
2775 (setq font-lock-keywords
2778 ;; Set up the keywords defined above.
2779 (list (concat "\\_<\\(" lua-keywords "\\)\\_>")
2780 '(0 font-lock-keyword-face))
2782 ;; At least numbers are simpler than C.
2783 (list (concat "\\_<\\(" "0[xX]"
2784 "\\(" "[0-9a-fA-F]+"
2785 "\\(\\.[0-9a-fA-F]*\\)?"
2786 "\\|" "\\.[0-9a-fA-F]+"
2788 "\\([pP][-+]?[0-9]+\\)?"
2789 "\\|" "\\(" "[0-9]+"
2793 "\\([eE][-+]?[0-9]+\\)?"
2795 '(0 mdw-number-face))
2797 ;; And anything else is punctuation.
2798 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2799 '(0 mdw-punct-face))))))
2801 ;;;--------------------------------------------------------------------------
2802 ;;; Icon programming style.
2804 ;; Icon indentation style.
2806 (setq icon-brace-offset 0
2807 icon-continued-brace-offset 0
2808 icon-continued-statement-offset 2
2809 icon-indent-level 2)
2811 ;; Define Icon fontification style.
2813 (defun mdw-fontify-icon ()
2815 ;; Miscellaneous fiddling.
2816 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2818 ;; Now define fontification things.
2819 (make-local-variable 'font-lock-keywords)
2820 (let ((icon-keywords
2821 (mdw-regexps "break" "by" "case" "create" "default" "do" "else"
2822 "end" "every" "fail" "global" "if" "initial"
2823 "invocable" "link" "local" "next" "not" "of"
2824 "procedure" "record" "repeat" "return" "static"
2825 "suspend" "then" "to" "until" "while"))
2826 (preprocessor-keywords
2827 (mdw-regexps "define" "else" "endif" "error" "ifdef" "ifndef"
2828 "include" "line" "undef")))
2829 (setq font-lock-keywords
2832 ;; Set up the keywords defined above.
2833 (list (concat "\\<\\(" icon-keywords "\\)\\>")
2834 '(0 font-lock-keyword-face))
2836 ;; The things that Icon calls keywords.
2837 (list "&\\sw+\\>" '(0 font-lock-variable-name-face))
2839 ;; At least numbers are simpler than C.
2840 (list (concat "\\<[0-9]+"
2841 "\\([rR][0-9a-zA-Z]+\\|"
2842 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\)\\>\\|"
2843 "\\.[0-9]+\\([eE][+-]?[0-9]+\\)?\\>")
2844 '(0 mdw-number-face))
2847 (list (concat "^[ \t]*$[ \t]*\\<\\("
2848 preprocessor-keywords
2850 '(0 font-lock-keyword-face))
2852 ;; And anything else is punctuation.
2853 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2854 '(0 mdw-punct-face))))))
2856 ;;;--------------------------------------------------------------------------
2859 (defun mdw-fontify-asm ()
2860 (modify-syntax-entry ?' "\"")
2861 (modify-syntax-entry ?. "w")
2862 (modify-syntax-entry ?\n ">")
2863 (setf fill-prefix nil)
2864 (local-set-key ";" 'self-insert-command)
2865 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
2867 (defun mdw-asm-set-comment ()
2868 (modify-syntax-entry ?; "."
2870 (modify-syntax-entry asm-comment-char "<b")
2871 (setq comment-start (string asm-comment-char ? )))
2872 (add-hook 'asm-mode-local-variables-hook 'mdw-asm-set-comment)
2873 (put 'asm-comment-char 'safe-local-variable 'characterp)
2875 ;;;--------------------------------------------------------------------------
2876 ;;; TCL configuration.
2878 (defun mdw-fontify-tcl ()
2879 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
2880 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
2881 (make-local-variable 'font-lock-keywords)
2882 (setq font-lock-keywords
2884 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
2885 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
2886 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
2887 '(0 mdw-number-face))
2888 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
2889 '(0 mdw-punct-face)))))
2891 ;;;--------------------------------------------------------------------------
2892 ;;; Dylan programming configuration.
2894 (defun mdw-fontify-dylan ()
2896 (make-local-variable 'font-lock-keywords)
2898 ;; Horrors. `dylan-mode' sets the `major-mode' name after calling this
2899 ;; hook, which undoes all of our configuration.
2900 (setq major-mode 'dylan-mode)
2901 (font-lock-set-defaults)
2903 (let* ((word "[-_a-zA-Z!*@<>$%]+")
2904 (dylan-keywords (mdw-regexps
2906 "C-address" "C-callable-wrapper" "C-function"
2907 "C-mapped-subtype" "C-pointer-type" "C-struct"
2908 "C-subtype" "C-union" "C-variable"
2910 "above" "abstract" "afterwards" "all"
2911 "begin" "below" "block" "by"
2912 "case" "class" "cleanup" "constant" "create"
2914 "else" "elseif" "end" "exception" "export"
2915 "finally" "for" "from" "function"
2918 "if" "in" "instance" "interface" "iterate"
2920 "let" "library" "local"
2921 "macro" "method" "module"
2924 "select" "slot" "subclass"
2926 "unless" "until" "use"
2927 "variable" "virtual"
2929 (sharp-keywords (mdw-regexps
2930 "all-keys" "key" "next" "rest" "include"
2932 (setq font-lock-keywords
2933 (list (list (concat "\\<\\(" dylan-keywords
2934 "\\|" "with\\(out\\)?-" word
2936 '(0 font-lock-keyword-face))
2937 (list (concat "\\<" word ":" "\\|"
2938 "#\\(" sharp-keywords "\\)\\>")
2939 '(0 font-lock-variable-name-face))
2941 "\\([-+]\\|\\<\\)[0-9]+" "\\("
2942 "\\(\\.[0-9]+\\)?" "\\([eE][-+][0-9]+\\)?"
2945 "\\|" "\\.[0-9]+" "\\([eE][-+][0-9]+\\)?"
2948 "\\|" "#x[0-9a-zA-Z]+"
2950 '(0 mdw-number-face))
2952 "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\|"
2953 "\\_<[-+*/=<>:&|]+\\_>"
2955 '(0 mdw-punct-face))))))
2957 ;;;--------------------------------------------------------------------------
2958 ;;; Algol 68 configuration.
2960 (setq a68-indent-step 2)
2962 (defun mdw-fontify-algol-68 ()
2964 ;; Fix up the syntax table.
2965 (modify-syntax-entry ?# "!" a68-mode-syntax-table)
2966 (dolist (ch '(?- ?+ ?= ?< ?> ?* ?/ ?| ?&))
2967 (modify-syntax-entry ch "." a68-mode-syntax-table))
2969 (make-local-variable 'font-lock-keywords)
2972 (let ((word "COMMENT"))
2973 (do ((regexp (concat "[^" (substring word 0 1) "]+")
2974 (concat regexp "\\|"
2975 (substring word 0 i)
2976 "[^" (substring word i (1+ i)) "]"))
2978 ((>= i (length word)) regexp)))))
2979 (setq font-lock-keywords
2980 (list (list (concat "\\<COMMENT\\>"
2981 "\\(" not-comment "\\)\\{0,5\\}"
2982 "\\(\\'\\|\\<COMMENT\\>\\)")
2983 '(0 font-lock-comment-face))
2984 (list (concat "\\<CO\\>"
2985 "\\([^C]+\\|C[^O]\\)\\{0,5\\}"
2986 "\\($\\|\\<CO\\>\\)")
2987 '(0 font-lock-comment-face))
2988 (list "\\<[A-Z_]+\\>"
2989 '(0 font-lock-keyword-face))
2993 "\\([eE][-+]?[0-9]+\\)?"
2995 '(0 mdw-number-face))
2996 (list "\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/"
2997 '(0 mdw-punct-face))))))
2999 ;;;--------------------------------------------------------------------------
3000 ;;; REXX configuration.
3002 (defun mdw-rexx-electric-* ()
3007 (defun mdw-rexx-indent-newline-indent ()
3010 (if abbrev-mode (expand-abbrev))
3011 (newline-and-indent))
3013 (defun mdw-fontify-rexx ()
3015 ;; Various bits of fiddling.
3016 (setq mdw-auto-indent nil)
3017 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
3018 (local-set-key [?*] 'mdw-rexx-electric-*)
3019 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
3021 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
3023 ;; Set up keywords and things for fontification.
3024 (make-local-variable 'font-lock-keywords-case-fold-search)
3025 (setq font-lock-keywords-case-fold-search t)
3027 (setq rexx-indent 2)
3028 (setq rexx-end-indent rexx-indent)
3029 (setq rexx-cont-indent rexx-indent)
3031 (make-local-variable 'font-lock-keywords)
3032 (let ((rexx-keywords
3033 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
3034 "else" "end" "engineering" "exit" "expose" "for"
3035 "forever" "form" "fuzz" "if" "interpret" "iterate"
3036 "leave" "linein" "name" "nop" "numeric" "off" "on"
3037 "options" "otherwise" "parse" "procedure" "pull"
3038 "push" "queue" "return" "say" "select" "signal"
3039 "scientific" "source" "then" "trace" "to" "until"
3040 "upper" "value" "var" "version" "when" "while"
3043 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
3044 "center" "center" "charin" "charout" "chars"
3045 "compare" "condition" "copies" "c2d" "c2x"
3046 "datatype" "date" "delstr" "delword" "d2c" "d2x"
3047 "errortext" "format" "fuzz" "insert" "lastpos"
3048 "left" "length" "lineout" "lines" "max" "min"
3049 "overlay" "pos" "queued" "random" "reverse" "right"
3050 "sign" "sourceline" "space" "stream" "strip"
3051 "substr" "subword" "symbol" "time" "translate"
3052 "trunc" "value" "verify" "word" "wordindex"
3053 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
3056 (setq font-lock-keywords
3059 ;; Set up the keywords defined above.
3060 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
3061 '(0 font-lock-keyword-face))
3063 ;; Fontify all symbols the same way.
3064 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
3065 "[A-Za-z0-9.!?_#@$]+\\)")
3066 '(0 font-lock-variable-name-face))
3068 ;; And everything else is punctuation.
3069 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3070 '(0 mdw-punct-face))))))
3072 ;;;--------------------------------------------------------------------------
3073 ;;; Standard ML programming style.
3075 (defun mdw-fontify-sml ()
3077 ;; Make underscore an honorary letter.
3078 (modify-syntax-entry ?' "w")
3081 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
3083 ;; Now define fontification things.
3084 (make-local-variable 'font-lock-keywords)
3086 (mdw-regexps "abstype" "and" "andalso" "as"
3089 "else" "end" "eqtype" "exception"
3090 "fn" "fun" "functor"
3092 "if" "in" "include" "infix" "infixr"
3095 "of" "op" "open" "orelse"
3097 "sharing" "sig" "signature" "struct" "structure"
3100 "where" "while" "with" "withtype")))
3102 (setq font-lock-keywords
3105 ;; Set up the keywords defined above.
3106 (list (concat "\\<\\(" sml-keywords "\\)\\>")
3107 '(0 font-lock-keyword-face))
3109 ;; At least numbers are simpler than C.
3110 (list (concat "\\<\\(\\~\\|\\)"
3111 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
3113 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
3114 "\\([eE]\\(\\~\\|\\)"
3115 "[0-9]+\\|\\)\\)\\)")
3116 '(0 mdw-number-face))
3118 ;; And anything else is punctuation.
3119 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3120 '(0 mdw-punct-face))))))
3122 ;;;--------------------------------------------------------------------------
3123 ;;; Haskell configuration.
3125 (defun mdw-fontify-haskell ()
3127 ;; Fiddle with syntax table to get comments right.
3128 (modify-syntax-entry ?' "_")
3129 (modify-syntax-entry ?- ". 12")
3130 (modify-syntax-entry ?\n ">")
3132 ;; Make punctuation be punctuation
3133 (let ((punct "=<>+-*/|&%!@?$.^:#`"))
3135 ((>= i (length punct)))
3136 (modify-syntax-entry (aref punct i) ".")))
3139 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
3141 ;; Fiddle with fontification.
3142 (make-local-variable 'font-lock-keywords)
3143 (let ((haskell-keywords
3145 "case" "ccall" "class"
3146 "data" "default" "deriving" "do"
3150 "if" "import" "in" "infix" "infixl" "infixr" "instance"
3163 (mdw-regexps "ACK" "BEL" "BS" "CAN" "CR" "DC1" "DC2" "DC3" "DC4"
3164 "DEL" "DLE" "EM" "ENQ" "EOT" "ESC" "ETB" "ETX" "FF"
3165 "FS" "GS" "HT" "LF" "NAK" "NUL" "RS" "SI" "SO" "SOH"
3166 "SP" "STX" "SUB" "SYN" "US" "VT")))
3168 (setq font-lock-keywords
3170 (list (concat "{-" "[^-]*" "\\(-+[^-}][^-]*\\)*"
3174 '(0 font-lock-comment-face))
3175 (list (concat "\\_<\\(" haskell-keywords "\\)\\_>")
3176 '(0 font-lock-keyword-face))
3177 (list (concat "'\\("
3181 "\\(" "[abfnrtv\\\"']" "\\|"
3182 "^" "\\(" control-sequences "\\|"
3183 "[]A-Z@[\\^_]" "\\)" "\\|"
3190 '(0 font-lock-string-face))
3191 (list "\\_<[A-Z]\\(\\sw+\\|\\s_+\\)*\\_>"
3192 '(0 font-lock-variable-name-face))
3193 (list (concat "\\_<0\\([xX][0-9a-fA-F]+\\|[oO][0-7]+\\)\\|"
3194 "\\_<[0-9]+\\(\\.[0-9]*\\|\\)"
3195 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
3196 '(0 mdw-number-face))
3197 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3198 '(0 mdw-punct-face))))))
3200 ;;;--------------------------------------------------------------------------
3201 ;;; Erlang configuration.
3203 (setq erlang-electric-commands nil)
3205 (defun mdw-fontify-erlang ()
3208 (mdw-standard-fill-prefix "\\([ \t]*{?%*[ \t]*\\)")
3210 ;; Fiddle with fontification.
3211 (make-local-variable 'font-lock-keywords)
3212 (let ((erlang-keywords
3213 (mdw-regexps "after" "and" "andalso"
3214 "band" "begin" "bnot" "bor" "bsl" "bsr" "bxor"
3215 "case" "catch" "cond"
3216 "div" "end" "fun" "if" "let" "not"
3218 "query" "receive" "rem" "try" "when" "xor")))
3220 (setq font-lock-keywords
3223 '(0 font-lock-comment-face))
3224 (list (concat "\\<\\(" erlang-keywords "\\)\\>")
3225 '(0 font-lock-keyword-face))
3226 (list (concat "^-\\sw+\\>")
3227 '(0 font-lock-keyword-face))
3228 (list "\\<[0-9]+\\(\\|#[0-9a-zA-Z]+\\|[eE][+-]?[0-9]+\\)\\>"
3229 '(0 mdw-number-face))
3230 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3231 '(0 mdw-punct-face))))))
3233 ;;;--------------------------------------------------------------------------
3234 ;;; Texinfo configuration.
3236 (defun mdw-fontify-texinfo ()
3239 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
3241 ;; Real fontification things.
3242 (make-local-variable 'font-lock-keywords)
3243 (setq font-lock-keywords
3246 ;; Environment names are keywords.
3247 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
3248 '(2 font-lock-keyword-face))
3250 ;; Unmark escaped magic characters.
3251 (list "\\(@\\)\\([@{}]\\)"
3252 '(1 font-lock-keyword-face)
3253 '(2 font-lock-variable-name-face))
3255 ;; Make sure we get comments properly.
3256 (list "@c\\(\\|omment\\)\\( .*\\)?$"
3257 '(0 font-lock-comment-face))
3259 ;; Command names are keywords.
3260 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3261 '(0 font-lock-keyword-face))
3263 ;; Fontify TeX special characters as punctuation.
3265 '(0 mdw-punct-face)))))
3267 ;;;--------------------------------------------------------------------------
3268 ;;; TeX and LaTeX configuration.
3270 (defun mdw-fontify-tex ()
3271 (setq ispell-parser 'tex)
3274 ;; Don't make maths into a string.
3275 (modify-syntax-entry ?$ ".")
3276 (modify-syntax-entry ?$ "." font-lock-syntax-table)
3277 (local-set-key [?$] 'self-insert-command)
3279 ;; Make `tab' be useful, given that tab stops in TeX don't work well.
3280 (local-set-key "\C-\M-i" 'indent-relative)
3281 (setq indent-tabs-mode nil)
3284 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
3286 ;; Real fontification things.
3287 (make-local-variable 'font-lock-keywords)
3288 (setq font-lock-keywords
3291 ;; Environment names are keywords.
3292 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
3294 '(2 font-lock-keyword-face))
3296 ;; Suspended environment names are keywords too.
3297 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
3299 '(3 font-lock-keyword-face))
3301 ;; Command names are keywords.
3302 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
3303 '(0 font-lock-keyword-face))
3305 ;; Handle @/.../ for italics.
3306 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
3307 ;; '(1 font-lock-keyword-face)
3308 ;; '(3 font-lock-keyword-face))
3310 ;; Handle @*...* for boldness.
3311 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
3312 ;; '(1 font-lock-keyword-face)
3313 ;; '(3 font-lock-keyword-face))
3315 ;; Handle @`...' for literal syntax things.
3316 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
3317 ;; '(1 font-lock-keyword-face)
3318 ;; '(3 font-lock-keyword-face))
3320 ;; Handle @<...> for nonterminals.
3321 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
3322 ;; '(1 font-lock-keyword-face)
3323 ;; '(3 font-lock-keyword-face))
3325 ;; Handle other @-commands.
3326 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
3327 ;; '(0 font-lock-keyword-face))
3329 ;; Make sure we get comments properly.
3331 '(0 font-lock-comment-face))
3333 ;; Fontify TeX special characters as punctuation.
3335 '(0 mdw-punct-face)))))
3337 (eval-after-load 'font-latex
3338 '(defun font-latex-jit-lock-force-redisplay (buf start end)
3339 "Compatibility for Emacsen not offering `jit-lock-force-redisplay'."
3340 ;; The following block is an expansion of `jit-lock-force-redisplay'
3341 ;; and involved macros taken from CVS Emacs on 2007-04-28.
3342 (with-current-buffer buf
3343 (let ((modified (buffer-modified-p)))
3345 (let ((buffer-undo-list t)
3346 (inhibit-read-only t)
3347 (inhibit-point-motion-hooks t)
3348 (inhibit-modification-hooks t)
3351 buffer-file-truename)
3352 (put-text-property start end 'fontified t))
3354 (restore-buffer-modified-p nil)))))))
3356 ;;;--------------------------------------------------------------------------
3359 (defun mdw-sgml-mode ()
3362 (mdw-standard-fill-prefix "")
3363 (make-local-variable 'sgml-delimiters)
3364 (setq sgml-delimiters
3365 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
3366 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
3367 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
3368 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
3369 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
3370 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
3371 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
3373 (setq major-mode 'mdw-sgml-mode)
3374 (setq mode-name "[mdw] SGML")
3375 (run-hooks 'mdw-sgml-mode-hook))
3377 ;;;--------------------------------------------------------------------------
3378 ;;; Configuration files.
3380 (defvar mdw-conf-quote-normal nil
3381 "*Control syntax category of quote characters `\"' and `''.
3382 If this is `t', consider quote characters to be normal
3383 punctuation, as for `conf-quote-normal'. If this is `nil' then
3384 leave quote characters as quotes. If this is a list, then
3385 consider the quote characters in the list to be normal
3386 punctuation. If this is a single quote character, then consider
3387 that character only to be normal punctuation.")
3388 (defun mdw-conf-quote-normal-acceptable-value-p (value)
3389 "Is the VALUE is an acceptable value for `mdw-conf-quote-normal'?"
3390 (or (booleanp value)
3391 (every (lambda (v) (memq v '(?\" ?')))
3392 (if (listp value) value (list value)))))
3393 (put 'mdw-conf-quote-normal 'safe-local-variable
3394 'mdw-conf-quote-normal-acceptable-value-p)
3396 (defun mdw-fix-up-quote ()
3397 "Apply the setting of `mdw-conf-quote-normal'."
3398 (let ((flag mdw-conf-quote-normal))
3400 (conf-quote-normal t))
3404 (let ((table (copy-syntax-table (syntax-table))))
3405 (mapc (lambda (ch) (modify-syntax-entry ch "." table))
3406 (if (listp flag) flag (list flag)))
3407 (set-syntax-table table)
3408 (and font-lock-mode (font-lock-fontify-buffer)))))))
3409 (add-hook 'conf-mode-local-variables-hook 'mdw-fix-up-quote t t)
3411 ;;;--------------------------------------------------------------------------
3414 (defun mdw-setup-sh-script-mode ()
3416 ;; Fetch the shell interpreter's name.
3417 (let ((shell-name sh-shell-file))
3419 ;; Try reading the hash-bang line.
3421 (goto-char (point-min))
3422 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
3423 (setq shell-name (match-string 1))))
3425 ;; Now try to set the shell.
3427 ;; Don't let `sh-set-shell' bugger up my script.
3428 (let ((executable-set-magic #'(lambda (s &rest r) s)))
3429 (sh-set-shell shell-name)))
3431 ;; Don't insert here-document scaffolding automatically.
3432 (local-set-key "<" 'self-insert-command)
3434 ;; Now enable my keys and the fontification.
3435 (mdw-misc-mode-config)
3437 ;; Set the indentation level correctly.
3438 (setq sh-indentation 2)
3439 (setq sh-basic-offset 2))
3441 (setq sh-shell-file "/bin/sh")
3443 ;; Awful hacking to override the shell detection for particular scripts.
3444 (defmacro define-custom-shell-mode (name shell)
3447 (set (make-local-variable 'sh-shell-file) ,shell)
3449 (define-custom-shell-mode bash-mode "/bin/bash")
3450 (define-custom-shell-mode rc-mode "/usr/bin/rc")
3451 (put 'sh-shell-file 'permanent-local t)
3453 ;; Hack the rc syntax table. Backquotes aren't paired in rc.
3454 (eval-after-load "sh-script"
3455 '(or (assq 'rc sh-mode-syntax-table-input)
3472 (assoc (assq 'rc sh-mode-syntax-table-input)))
3475 (setq sh-mode-syntax-table-input
3476 (cons (cons 'rc frag)
3477 sh-mode-syntax-table-input))))))
3479 ;;;--------------------------------------------------------------------------
3480 ;;; Emacs shell mode.
3482 (defun mdw-eshell-prompt ()
3483 (let ((left "[") (right "]"))
3484 (when (= (user-uid) 0)
3485 (setq left "«" right "»"))
3488 (replace-regexp-in-string "\\..*$" "" (system-name)))
3490 (let* ((pwd (eshell/pwd)) (npwd (length pwd))
3491 (home (expand-file-name "~")) (nhome (length home)))
3492 (if (and (>= npwd nhome)
3494 (= (elt pwd nhome) ?/))
3495 (string= (substring pwd 0 nhome) home))
3496 (concat "~" (substring pwd (length home)))
3499 (setq eshell-prompt-function 'mdw-eshell-prompt)
3500 (setq eshell-prompt-regexp "^\\[[^]>]+\\(\\]\\|>>?\\)")
3502 (defun eshell/e (file) (find-file file) nil)
3503 (defun eshell/ee (file) (find-file-other-window file) nil)
3504 (defun eshell/w3m (url) (w3m-goto-url url) nil)
3506 (mdw-define-face eshell-prompt (t :weight bold))
3507 (mdw-define-face eshell-ls-archive (t :weight bold :foreground "red"))
3508 (mdw-define-face eshell-ls-backup (t :foreground "lightgrey" :slant italic))
3509 (mdw-define-face eshell-ls-product (t :foreground "lightgrey" :slant italic))
3510 (mdw-define-face eshell-ls-clutter (t :foreground "lightgrey" :slant italic))
3511 (mdw-define-face eshell-ls-executable (t :weight bold))
3512 (mdw-define-face eshell-ls-directory (t :foreground "cyan" :weight bold))
3513 (mdw-define-face eshell-ls-readonly (t nil))
3514 (mdw-define-face eshell-ls-symlink (t :foreground "cyan"))
3516 (defun mdw-eshell-hack ()
3517 (when mdw-preload-hacks
3518 (setenv "LD_PRELOAD" nil)))
3519 (add-hook 'eshell-mode-hook 'mdw-eshell-hack)
3521 ;;;--------------------------------------------------------------------------
3522 ;;; Messages-file mode.
3524 (defun messages-mode-guts ()
3525 (setq messages-mode-syntax-table (make-syntax-table))
3526 (set-syntax-table messages-mode-syntax-table)
3527 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
3528 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
3529 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
3530 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
3531 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
3532 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
3533 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
3534 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
3535 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
3536 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
3537 (make-local-variable 'comment-start)
3538 (make-local-variable 'comment-end)
3539 (make-local-variable 'indent-line-function)
3540 (setq indent-line-function 'indent-relative)
3541 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3542 (make-local-variable 'font-lock-defaults)
3543 (make-local-variable 'messages-mode-keywords)
3545 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
3546 "export" "enum" "fixed-octetstring" "flags"
3547 "harmless" "map" "nested" "optional"
3548 "optional-tagged" "package" "primitive"
3549 "primitive-nullfree" "relaxed[ \t]+enum"
3550 "set" "table" "tagged-optional" "union"
3551 "variadic" "vector" "version" "version-tag")))
3552 (setq messages-mode-keywords
3554 (list (concat "\\<\\(" keywords "\\)\\>:")
3555 '(0 font-lock-keyword-face))
3556 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
3557 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
3558 (0 font-lock-variable-name-face))
3559 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
3560 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3561 (0 mdw-punct-face)))))
3562 (setq font-lock-defaults
3563 '(messages-mode-keywords nil nil nil nil))
3564 (run-hooks 'messages-file-hook))
3566 (defun messages-mode ()
3569 (setq major-mode 'messages-mode)
3570 (setq mode-name "Messages")
3571 (messages-mode-guts)
3572 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
3573 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
3574 (setq comment-start "# ")
3575 (setq comment-end "")
3576 (run-hooks 'messages-mode-hook))
3578 (defun cpp-messages-mode ()
3581 (setq major-mode 'cpp-messages-mode)
3582 (setq mode-name "CPP Messages")
3583 (messages-mode-guts)
3584 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
3585 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
3586 (setq comment-start "/* ")
3587 (setq comment-end " */")
3588 (let ((preprocessor-keywords
3589 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
3590 "ident" "if" "ifdef" "ifndef" "import" "include"
3591 "line" "pragma" "unassert" "undef" "warning")))
3592 (setq messages-mode-keywords
3593 (append (list (list (concat "^[ \t]*\\#[ \t]*"
3594 "\\(include\\|import\\)"
3595 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
3596 '(2 font-lock-string-face))
3597 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
3598 preprocessor-keywords
3599 "\\)\\>\\|[0-9]+\\|$\\)\\)")
3600 '(1 font-lock-keyword-face)))
3601 messages-mode-keywords)))
3602 (run-hooks 'cpp-messages-mode-hook))
3604 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
3605 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
3606 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
3608 ;;;--------------------------------------------------------------------------
3609 ;;; Messages-file mode.
3611 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
3612 "Face to use for subsittution directives.")
3613 (make-face 'mallow-driver-substitution-face)
3614 (defvar mallow-driver-text-face 'mallow-driver-text-face
3615 "Face to use for body text.")
3616 (make-face 'mallow-driver-text-face)
3618 (defun mallow-driver-mode ()
3621 (setq major-mode 'mallow-driver-mode)
3622 (setq mode-name "Mallow driver")
3623 (setq mallow-driver-mode-syntax-table (make-syntax-table))
3624 (set-syntax-table mallow-driver-mode-syntax-table)
3625 (make-local-variable 'comment-start)
3626 (make-local-variable 'comment-end)
3627 (make-local-variable 'indent-line-function)
3628 (setq indent-line-function 'indent-relative)
3629 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
3630 (make-local-variable 'font-lock-defaults)
3631 (make-local-variable 'mallow-driver-mode-keywords)
3633 (mdw-regexps "each" "divert" "file" "if"
3634 "perl" "set" "string" "type" "write")))
3635 (setq mallow-driver-mode-keywords
3637 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
3638 '(0 font-lock-keyword-face))
3639 (list "^%\\s *\\(#.*\\|\\)$"
3640 '(0 font-lock-comment-face))
3642 '(0 font-lock-keyword-face))
3643 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
3645 '(0 mallow-driver-substitution-face t)))))
3646 (setq font-lock-defaults
3647 '(mallow-driver-mode-keywords nil nil nil nil))
3648 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
3649 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
3650 (setq comment-start "%# ")
3651 (setq comment-end "")
3652 (run-hooks 'mallow-driver-mode-hook))
3654 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
3656 ;;;--------------------------------------------------------------------------
3659 (defun nfast-debug-mode ()
3662 (setq major-mode 'nfast-debug-mode)
3663 (setq mode-name "NFast debug")
3664 (setq messages-mode-syntax-table (make-syntax-table))
3665 (set-syntax-table messages-mode-syntax-table)
3666 (make-local-variable 'font-lock-defaults)
3667 (make-local-variable 'nfast-debug-mode-keywords)
3668 (setq truncate-lines t)
3669 (setq nfast-debug-mode-keywords
3671 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
3672 (0 font-lock-keyword-face))
3673 (list (concat "^[ \t]+\\(\\("
3674 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
3675 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
3677 "[0-9a-fA-F]+\\)[ \t]*$")
3678 '(0 mdw-number-face))
3679 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
3680 (1 font-lock-keyword-face))
3681 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
3682 (1 font-lock-warning-face))
3683 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
3685 (list (concat "^[ \t]+\\.cmd=[ \t]+"
3686 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
3687 '(1 font-lock-keyword-face))
3688 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
3689 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
3690 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
3691 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
3692 (setq font-lock-defaults
3693 '(nfast-debug-mode-keywords nil nil nil nil))
3694 (run-hooks 'nfast-debug-mode-hook))
3696 ;;;--------------------------------------------------------------------------
3697 ;;; Other languages.
3701 (defun mdw-setup-smalltalk ()
3702 (and mdw-auto-indent
3703 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
3704 (make-local-variable 'mdw-auto-indent)
3705 (setq mdw-auto-indent nil)
3706 (local-set-key "\C-i" 'smalltalk-reindent))
3708 (defun mdw-fontify-smalltalk ()
3709 (make-local-variable 'font-lock-keywords)
3710 (setq font-lock-keywords
3712 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
3713 '(0 font-lock-keyword-face))
3714 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
3715 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
3716 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
3717 '(0 mdw-number-face))
3718 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3719 '(0 mdw-punct-face)))))
3723 ;; Unpleasant bodge.
3724 (unless (boundp 'slime-repl-mode-map)
3725 (setq slime-repl-mode-map (make-sparse-keymap)))
3727 (defun mdw-indent-newline-and-indent ()
3729 (indent-for-tab-command)
3730 (newline-and-indent))
3732 (eval-after-load "cl-indent"
3734 (mapc #'(lambda (pair)
3736 'common-lisp-indent-function
3738 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
3739 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
3741 (defun mdw-common-lisp-indent ()
3742 (make-local-variable 'lisp-indent-function)
3743 (setq lisp-indent-function 'common-lisp-indent-function))
3745 (setq lisp-simple-loop-indentation 2
3746 lisp-loop-keyword-indentation 6
3747 lisp-loop-forms-indentation 6)
3749 (defun mdw-fontify-lispy ()
3752 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
3754 ;; Not much fontification needed.
3755 (make-local-variable 'font-lock-keywords)
3756 (setq font-lock-keywords
3757 (list (list (concat "\\("
3759 "\\(" "[0-9]+/[0-9]+"
3760 "\\|" "\\(" "[0-9]+" "\\(\\.[0-9]*\\)?" "\\|"
3762 "\\([dDeEfFlLsS][-+]?[0-9]+\\)?"
3767 "[0-9A-Fa-f]+" "\\(/[0-9A-Fa-f]+\\)?"
3768 "\\|" "o" "[-+]?" "[0-7]+" "\\(/[0-7]+\\)?"
3769 "\\|" "b" "[-+]?" "[01]+" "\\(/[01]+\\)?"
3770 "\\|" "[0-9]+" "r" "[-+]?"
3771 "[0-9a-zA-Z]+" "\\(/[0-9a-zA-Z]+\\)?"
3774 '(0 mdw-number-face))
3775 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
3776 '(0 mdw-punct-face)))))
3778 (defun comint-send-and-indent ()
3781 (and mdw-auto-indent
3782 (indent-for-tab-command)))
3784 (defadvice comint-line-beginning-position
3785 (around mdw-calculate-it-properly () activate compile)
3786 "Calculate the actual line start for multi-line input."
3787 (if (or comint-use-prompt-regexp
3788 (eq (field-at-pos (point)) 'output))
3790 (setq ad-return-value
3791 (constrain-to-field (line-beginning-position) (point)))))
3793 (defun mdw-setup-m4 ()
3795 ;; Inexplicably, Emacs doesn't match braces in m4 mode. This is very
3796 ;; annoying: fix it.
3797 (modify-syntax-entry ?{ "(")
3798 (modify-syntax-entry ?} ")")
3801 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
3803 ;;;--------------------------------------------------------------------------
3806 (defun mdw-text-mode ()
3807 (setq fill-column 72)
3809 (mdw-standard-fill-prefix
3810 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
3813 (eval-after-load "flyspell"
3814 '(define-key flyspell-mode-map "\C-\M-i" nil))
3816 ;;;--------------------------------------------------------------------------
3817 ;;; Outline and hide/show modes.
3819 (defun mdw-outline-collapse-all ()
3820 "Completely collapse everything in the entire buffer."
3823 (goto-char (point-min))
3824 (while (< (point) (point-max))
3828 (setq hs-hide-comments-when-hiding-all nil)
3830 (defadvice hs-hide-all (after hide-first-comment activate)
3831 (save-excursion (hs-hide-initial-comment-block)))
3833 ;;;--------------------------------------------------------------------------
3836 (defun mdw-sh-mode-setup ()
3837 (local-set-key [?\C-a] 'comint-bol)
3838 (add-hook 'comint-output-filter-functions
3839 'comint-watch-for-password-prompt))
3841 (defun mdw-term-mode-setup ()
3842 (setq term-prompt-regexp shell-prompt-pattern)
3843 (make-local-variable 'mouse-yank-at-point)
3844 (make-local-variable 'transient-mark-mode)
3845 (setq mouse-yank-at-point t)
3849 (defun term-send-meta-right () (interactive) (term-send-raw-string "\e\e[C"))
3850 (defun term-send-meta-left () (interactive) (term-send-raw-string "\e\e[D"))
3851 (defun term-send-ctrl-uscore () (interactive) (term-send-raw-string "\C-_"))
3852 (defun term-send-meta-meta-something ()
3854 (term-send-raw-string "\e\e")
3856 (eval-after-load 'term
3858 (define-key term-raw-map [?\e ?\e] nil)
3859 (define-key term-raw-map [?\e ?\e t] 'term-send-meta-meta-something)
3860 (define-key term-raw-map [?\C-/] 'term-send-ctrl-uscore)
3861 (define-key term-raw-map [M-right] 'term-send-meta-right)
3862 (define-key term-raw-map [?\e ?\M-O ?C] 'term-send-meta-right)
3863 (define-key term-raw-map [M-left] 'term-send-meta-left)
3864 (define-key term-raw-map [?\e ?\M-O ?D] 'term-send-meta-left)))
3866 (defadvice term-exec (before program-args-list compile activate)
3867 "If the PROGRAM argument is a list, interpret it as (PROGRAM . SWITCHES).
3868 This allows you to pass a list of arguments through `ansi-term'."
3869 (let ((program (ad-get-arg 2)))
3872 (ad-set-arg 2 (car program))
3873 (ad-set-arg 4 (cdr program))))))
3875 (defadvice term-exec-1 (around hack-environment compile activate)
3876 "Hack the environment inherited by inferiors in the terminal."
3877 (let ((process-environment process-environment))
3878 (setenv "LD_PRELOAD" nil)
3881 (defadvice shell (around hack-environment compile activate)
3882 "Hack the environment inherited by inferiors in the shell."
3883 (let ((process-environment process-environment))
3884 (setenv "LD_PRELOAD" nil)
3888 "Open a terminal containing an ssh session to the HOST."
3889 (interactive "sHost: ")
3890 (ansi-term (list "ssh" host) (format "ssh@%s" host)))
3892 (defvar git-grep-command
3893 "env PAGER=cat git grep --no-color -nH -e "
3894 "*The default command for \\[git-grep].")
3896 (defvar git-grep-history nil)
3898 (defun git-grep (command-args)
3899 "Run `git grep' with user-specified args and collect output in a buffer."
3901 (list (read-shell-command "Run git grep (like this): "
3902 git-grep-command 'git-grep-history)))
3903 (grep command-args))
3905 ;;;--------------------------------------------------------------------------
3906 ;;; Magit configuration.
3908 (setq magit-diff-refine-hunk 'all
3909 magit-view-git-manual-method 'man
3910 magit-log-margin '(nil age magit-log-margin-width t 18)
3911 magit-wip-after-save-local-mode-lighter ""
3912 magit-wip-after-apply-mode-lighter ""
3913 magit-wip-before-change-mode-lighter "")
3914 (eval-after-load "magit"
3915 '(progn (global-magit-file-mode 1)
3916 (magit-wip-after-save-mode 1)
3917 (magit-wip-after-apply-mode 1)
3918 (magit-wip-before-change-mode 1)
3919 (add-to-list 'magit-no-confirm 'safe-with-wip)
3920 (push '(:eval (if (or magit-wip-after-save-local-mode
3921 magit-wip-after-apply-mode
3922 magit-wip-before-change-mode)
3923 (format " wip:%s%s%s"
3924 (if magit-wip-after-apply-mode "A" "")
3925 (if magit-wip-before-change-mode "C" "")
3926 (if magit-wip-after-save-local-mode "S" ""))))
3928 (dolist (popup '(magit-diff-popup
3929 magit-diff-refresh-popup
3930 magit-diff-mode-refresh-popup
3931 magit-revision-mode-refresh-popup))
3932 (magit-define-popup-switch popup ?R "Reverse diff" "-R"))))
3934 (setq magit-repolist-columns
3935 '(("Name" 16 magit-repolist-column-ident nil)
3936 ("Version" 18 magit-repolist-column-version nil)
3937 ("St" 2 magit-repolist-column-dirty nil)
3938 ("L<U" 3 mdw-repolist-column-unpulled-from-upstream nil)
3939 ("L>U" 3 mdw-repolist-column-unpushed-to-upstream nil)
3940 ("Path" 32 magit-repolist-column-path nil)))
3942 (setq magit-repository-directories '(("~/etc/profile" . 0)
3945 (defadvice magit-list-repos (around mdw-dirname () activate compile)
3946 "Make sure the returned names are directory names.
3947 Otherwise child processes get started in the wrong directory and
3949 (setq ad-return-value (mapcar #'file-name-as-directory ad-do-it)))
3951 (defun mdw-repolist-column-unpulled-from-upstream (_id)
3952 "Insert number of upstream commits not in the current branch."
3953 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
3955 (let ((n (cadr (magit-rev-diff-count "HEAD" upstream))))
3956 (propertize (number-to-string n) 'face
3957 (if (> n 0) 'bold 'shadow))))))
3959 (defun mdw-repolist-column-unpushed-to-upstream (_id)
3960 "Insert number of commits in the current branch but not its upstream."
3961 (let ((upstream (magit-get-upstream-branch (magit-get-current-branch) t)))
3963 (let ((n (car (magit-rev-diff-count "HEAD" upstream))))
3964 (propertize (number-to-string n) 'face
3965 (if (> n 0) 'bold 'shadow))))))
3967 ;;;--------------------------------------------------------------------------
3968 ;;; MPC configuration.
3970 (eval-when-compile (trap (require 'mpc)))
3972 (setq mpc-browser-tags '(Artist|Composer|Performer Album|Playlist))
3974 (defun mdw-mpc-now-playing ()
3978 (set-buffer (mpc-proc-cmd (mpc-proc-cmd-list '("status" "currentsong"))))
3979 (mpc--status-callback))
3980 (let ((state (cdr (assq 'state mpc-status))))
3981 (cond ((member state '("stop"))
3982 (message "mpd stopped."))
3983 ((member state '("play" "pause"))
3984 (let* ((artist (cdr (assq 'Artist mpc-status)))
3985 (album (cdr (assq 'Album mpc-status)))
3986 (title (cdr (assq 'Title mpc-status)))
3987 (file (cdr (assq 'file mpc-status)))
3988 (duration-string (cdr (assq 'Time mpc-status)))
3989 (time-string (cdr (assq 'time mpc-status)))
3990 (time (and time-string
3992 (if (string-match ":" time-string)
3993 (substring time-string
3994 0 (match-beginning 0))
3996 (duration (and duration-string
3997 (string-to-number duration-string)))
3998 (pos (and time duration
3999 (format " [%d:%02d/%d:%02d]"
4000 (/ time 60) (mod time 60)
4001 (/ duration 60) (mod duration 60))))
4002 (fmt (cond ((and artist title)
4003 (format "`%s' by %s%s" title artist
4004 (if album (format ", from `%s'" album)
4007 (format "`%s' (no tags)" file))
4009 "(no idea what's playing!)"))))
4010 (if (string= state "play")
4011 (message "mpd playing %s%s" fmt (or pos ""))
4012 (message "mpd paused in %s%s" fmt (or pos "")))))
4014 (message "mpd in unknown state `%s'" state)))))
4016 (defmacro mdw-define-mpc-wrapper (func bvl interactive &rest body)
4018 (interactive ,@interactive)
4021 (mdw-mpc-now-playing)))
4023 (mdw-define-mpc-wrapper mdw-mpc-play-or-pause () nil
4024 (if (member (cdr (assq 'state (mpc-cmd-status))) '("play"))
4028 (mdw-define-mpc-wrapper mdw-mpc-next () nil (mpc-next))
4029 (mdw-define-mpc-wrapper mdw-mpc-prev () nil (mpc-prev))
4030 (mdw-define-mpc-wrapper mdw-mpc-stop () nil (mpc-stop))
4032 (defun mdw-mpc-louder (step)
4033 (interactive (list (if current-prefix-arg
4034 (prefix-numeric-value current-prefix-arg)
4036 (mpc-proc-cmd (format "volume %+d" step)))
4038 (defun mdw-mpc-quieter (step)
4039 (interactive (list (if current-prefix-arg
4040 (prefix-numeric-value current-prefix-arg)
4042 (mpc-proc-cmd (format "volume %+d" (- step))))
4044 (defun mdw-mpc-hack-lines (arg interactivep func)
4045 (if (and interactivep (use-region-p))
4046 (let ((from (region-beginning)) (to (region-end)))
4051 (while (< (point) to)
4054 (let ((n (prefix-numeric-value arg)))
4071 (defun mdw-mpc-select-one ()
4072 (when (and (get-char-property (point) 'mpc-file)
4073 (not (get-char-property (point) 'mpc-select)))
4074 (mpc-select-toggle)))
4076 (defun mdw-mpc-unselect-one ()
4077 (when (get-char-property (point) 'mpc-select)
4078 (mpc-select-toggle)))
4080 (defun mdw-mpc-select (&optional arg interactivep)
4081 (interactive (list current-prefix-arg t))
4082 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4084 (defun mdw-mpc-unselect (&optional arg interactivep)
4085 (interactive (list current-prefix-arg t))
4086 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-unselect-one))
4088 (defun mdw-mpc-unselect-backwards (arg)
4090 (mdw-mpc-hack-lines (- arg) t 'mdw-mpc-unselect-one))
4092 (defun mdw-mpc-unselect-all ()
4094 (setq mpc-select nil)
4095 (mpc-selection-refresh))
4097 (defun mdw-mpc-next-line (arg)
4102 (defun mdw-mpc-previous-line (arg)
4105 (forward-line (- arg)))
4107 (defun mdw-mpc-playlist-add (&optional arg interactivep)
4108 (interactive (list current-prefix-arg t))
4109 (let ((mpc-select mpc-select))
4110 (when (or arg (and interactivep (use-region-p)))
4111 (setq mpc-select nil)
4112 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4113 (setq mpc-select (reverse mpc-select))
4114 (mpc-playlist-add)))
4116 (defun mdw-mpc-playlist-delete (&optional arg interactivep)
4117 (interactive (list current-prefix-arg t))
4118 (setq mpc-select (nreverse mpc-select))
4120 (when (or arg (and interactivep (use-region-p)))
4121 (setq mpc-select nil)
4122 (mpc-selection-refresh)
4123 (mdw-mpc-hack-lines arg interactivep 'mdw-mpc-select-one))
4124 (mpc-playlist-delete)))
4126 (defun mdw-mpc-hack-tagbrowsers ()
4127 (setq-local mode-line-format
4129 mode-line-frame-identification
4130 mode-line-buffer-identification)))
4131 (add-hook 'mpc-tagbrowser-mode-hook 'mdw-mpc-hack-tagbrowsers)
4133 (defun mdw-mpc-hack-songs ()
4134 (setq-local header-line-format
4135 ;; '("MPC " mpc-volume " " mpc-current-song)
4136 (list (propertize " " 'display '(space :align-to 0))
4137 ;; 'mpc-songs-format-description
4139 (let ((deactivate-mark) (hscroll (window-hscroll)))
4141 (mpc-format mpc-songs-format 'self hscroll)
4142 ;; That would be simpler than the hscroll handling in
4143 ;; mpc-format, but currently move-to-column does not
4144 ;; recognize :space display properties.
4145 ;; (move-to-column hscroll)
4146 ;; (delete-region (point-min) (point))
4147 (buffer-string)))))))
4148 (add-hook 'mpc-songs-mode-hook 'mdw-mpc-hack-songs)
4150 (eval-after-load "mpc"
4152 (define-key mpc-mode-map "m" 'mdw-mpc-select)
4153 (define-key mpc-mode-map "u" 'mdw-mpc-unselect)
4154 (define-key mpc-mode-map "\177" 'mdw-mpc-unselect-backwards)
4155 (define-key mpc-mode-map "\e\177" 'mdw-mpc-unselect-all)
4156 (define-key mpc-mode-map "n" 'mdw-mpc-next-line)
4157 (define-key mpc-mode-map "p" 'mdw-mpc-previous-line)
4158 (define-key mpc-mode-map "/" 'mpc-songs-search)
4159 (setq mpc-songs-mode-map (make-sparse-keymap))
4160 (set-keymap-parent mpc-songs-mode-map mpc-mode-map)
4161 (define-key mpc-songs-mode-map "l" 'mpc-playlist)
4162 (define-key mpc-songs-mode-map "+" 'mdw-mpc-playlist-add)
4163 (define-key mpc-songs-mode-map "-" 'mdw-mpc-playlist-delete)
4164 (define-key mpc-songs-mode-map "\r" 'mpc-songs-jump-to)))
4166 ;;;--------------------------------------------------------------------------
4167 ;;; Inferior Emacs Lisp.
4169 (setq comint-prompt-read-only t)
4171 (eval-after-load "comint"
4173 (define-key comint-mode-map "\C-w" 'comint-kill-region)
4174 (define-key comint-mode-map [C-S-backspace] 'comint-kill-whole-line)))
4176 (eval-after-load "ielm"
4178 (define-key ielm-map "\C-w" 'comint-kill-region)
4179 (define-key ielm-map [C-S-backspace] 'comint-kill-whole-line)))
4181 ;;;----- That's all, folks --------------------------------------------------
4183 (provide 'dot-emacs)