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 ;;;----- Check command-line -------------------------------------------------
26 (defvar mdw-fast-startup nil
27 "Whether .emacs should optimize for rapid startup.
28 This may be at the expense of cool features.")
29 (let ((probe nil) (next command-line-args))
31 (cond ((string= (car next) "--mdw-fast-startup")
32 (setq mdw-fast-startup t)
34 (rplacd probe (cdr next))
35 (setq command-line-args (cdr next))))
38 (setq next (cdr next))))
40 ;;;----- Some general utilities ---------------------------------------------
43 (unless (fboundp 'make-regexp)
47 (defmacro mdw-regexps (&rest list)
48 "Turn a LIST of strings into a single regular expression at compile-time."
49 `',(make-regexp list))
51 ;; --- Some error trapping ---
53 ;; If individual bits of this file go tits-up, we don't particularly want
54 ;; the whole lot to stop right there and then, because it's bloody annoying.
56 (defmacro trap (&rest forms)
57 "Execute FORMS without allowing errors to propagate outside."
59 ,(if (cdr forms) (cons 'progn forms) (car forms))
60 (error (message "Error (trapped): %s in %s"
61 (error-message-string err)
64 ;; --- Configuration reading ---
66 (defvar mdw-config nil)
67 (defun mdw-config (sym)
68 "Read the configuration variable named SYM."
71 (flet ((replace (what with)
72 (goto-char (point-min))
73 (while (re-search-forward what nil t)
74 (replace-match with t))))
76 (insert-file-contents "~/.mdw.conf")
77 (replace "^[ \t]*\\(#.*\\|\\)\n" "")
78 (replace (concat "^[ \t]*"
79 "\\([-a-zA-Z0-9_.]*\\)"
82 "[ \t]**\\(\n\\|$\\)")
84 (car (read-from-string
85 (concat "(" (buffer-string) ")")))))))
86 (cdr (assq sym mdw-config)))
88 ;; --- Is an Emacs library available? ---
90 (defun library-exists-p (name)
91 "Return non-nil if NAME.el (or NAME.elc) is somewhere on the Emacs load
92 path. The non-nil value is the filename we found for the library."
93 (let ((path load-path) elt (foundp nil))
94 (while (and path (not foundp))
96 (setq path (cdr path))
97 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
98 (and (file-exists-p file) file))
99 (let ((file (concat elt "/" name ".el")))
100 (and (file-exists-p file) file)))))
103 (defun maybe-autoload (symbol file &optional docstring interactivep type)
104 "Set an autoload if the file actually exists."
105 (and (library-exists-p file)
106 (autoload symbol file docstring interactivep type)))
108 ;; --- Splitting windows ---
110 (unless (fboundp 'scroll-bar-columns)
111 (defun scroll-bar-columns (side)
112 (cond ((eq side 'left) 0)
115 (unless (fboundp 'fringe-columns)
116 (defun fringe-columns (side)
117 (cond ((not window-system) 0)
121 (defun mdw-divvy-window (&optional width)
122 "Split a wide window into appropriate widths."
124 (setq width (cond (width (prefix-numeric-value width))
126 (>= emacs-major-version 22))
129 (let* ((win (selected-window))
130 (sb-width (if (not window-system)
133 (dolist (what '(scroll-bar fringe))
134 (dolist (side '(left right))
136 (funcall (intern (concat (symbol-name what)
140 (c (/ (+ (window-width) sb-width)
141 (+ width sb-width))))
144 (split-window-horizontally (+ width sb-width))
146 (select-window win)))
148 ;; --- Functions for sexp diary entries ---
150 (defun mdw-weekday (l)
151 "Return non-nil if `date' falls on one of the days of the week in L.
153 L is a list of day numbers (from 0 to 6 for Sunday through to Saturday) or
154 symbols `sunday', `monday', etc. (or a mixture). If the date stored in
155 `date' falls on a listed day, then the function returns non-nil."
156 (let ((d (calendar-day-of-week date)))
158 (memq (nth d '(sunday monday tuesday wednesday
159 thursday friday saturday)) l))))
161 (defun mdw-todo (&optional when)
162 "Return non-nil today, or on WHEN, whichever is later."
163 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
164 (d (calendar-absolute-from-gregorian date)))
166 (setq w (max w (calendar-absolute-from-gregorian
168 ((not european-calendar-style)
180 ;;;----- Utility functions --------------------------------------------------
182 (or (fboundp 'line-number-at-pos)
183 (defun line-number-at-pos (&optional pos)
184 (let ((opoint (or pos (point))) start)
187 (goto-char (point-min))
193 (1+ (count-lines 1 (point))))))))
195 ;; --- mdw-uniquify-alist ---
197 (defun mdw-uniquify-alist (&rest alists)
199 "Return the concatenation of the ALISTS with duplicate elements removed.
201 The first association with a given key prevails; others are ignored. The
202 input lists are not modified, although they'll probably become garbage."
205 (let ((start-list (cons nil nil)))
206 (mdw-do-uniquify start-list
211 ;; --- mdw-do-uniquify ---
213 ;; The DONE argument is a list whose first element is `nil'. It contains the
214 ;; uniquified alist built so far. The leading `nil' is stripped off at the
215 ;; end of the operation; it's only there so that DONE always references a
216 ;; cons cell. END refers to the final cons cell in the DONE list; it is
217 ;; modified in place each time to avoid the overheads of `append'ing all the
218 ;; time. The L argument is the alist we're currently processing; the
219 ;; remaining alists are given in REST.
221 (defun mdw-do-uniquify (done end l rest)
222 "A helper function for mdw-uniquify-alist."
224 ;; --- There are several different cases to deal with here ---
228 ;; --- Current list isn't empty ---
230 ;; Add the first item to the DONE list if there's not an item with the
231 ;; same KEY already there.
233 (l (or (assoc (car (car l)) done)
235 (setcdr end (cons (car l) nil))
236 (setq end (cdr end))))
237 (mdw-do-uniquify done end (cdr l) rest))
239 ;; --- The list we were working on is empty ---
241 ;; Shunt the next list into the current list position and go round again.
243 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
245 ;; --- Everything's done ---
247 ;; Remove the leading `nil' from the DONE list and return it. Finished!
251 ;; --- Insert a date ---
254 "Insert the current date in a pleasing way."
256 (insert (save-excursion
257 (let ((buffer (get-buffer-create "*tmp*")))
258 (unwind-protect (progn (set-buffer buffer)
260 (shell-command "date +%Y-%m-%d" t)
262 (delete-backward-char 1)
264 (kill-buffer buffer))))))
266 ;; --- UUencoding ---
268 (defun uuencode (file &optional name)
269 "UUencodes a file, maybe calling it NAME, into the current buffer."
270 (interactive "fInput file name: ")
272 ;; --- If NAME isn't specified, then guess from the filename ---
277 (or (string-match "[^/]*$" file) 0))))
279 (print (format "uuencode `%s' `%s'" file name))
281 ;; --- Now actually do the thing ---
283 (call-process "uuencode" file t nil name))
285 (defvar np-file "~/.np"
286 "*Where the `now-playing' file is.")
288 (defun np (&optional arg)
289 "Grabs a `now-playing' string."
293 (goto-char (point-max))
295 (insert-file-contents np-file)))))
297 (defun mdw-check-autorevert ()
298 "Sets global-auto-revert-ignore-buffer appropriately for this buffer,
299 taking into consideration whether it's been found using tramp, which seems to
300 get itself into a twist."
301 (cond ((not (boundp 'global-auto-revert-ignore-buffer))
303 ((and (buffer-file-name)
304 (fboundp 'tramp-tramp-file-p)
305 (tramp-tramp-file-p (buffer-file-name)))
306 (unless global-auto-revert-ignore-buffer
307 (setq global-auto-revert-ignore-buffer 'tramp)))
308 ((eq global-auto-revert-ignore-buffer 'tramp)
309 (setq global-auto-revert-ignore-buffer nil))))
311 (defadvice find-file (after mdw-autorevert activate)
312 (mdw-check-autorevert))
313 (defadvice write-file (after mdw-autorevert activate)
314 (mdw-check-autorevert))
316 (defun mdwmail-mode ()
317 "Major mode for editing news and mail messages from external programs
318 Not much right now. Just support for doing MailCrypt stuff."
320 (kill-all-local-variables)
321 (use-local-map text-mode-map)
322 (setq local-abbrev-table text-mode-abbrev-table)
323 (setq major-mode 'mdwmail-mode)
324 (setq mode-name "[mdw] mail")
325 (set-buffer-file-coding-system 'utf-8)
326 (make-local-variable 'paragraph-separate)
327 (make-local-variable 'paragraph-start)
328 (setq paragraph-start (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
330 (setq paragraph-separate (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
332 (run-hooks 'text-mode-hook 'mdwmail-mode-hook 'mail-setup-hook))
334 ;; --- How to encrypt in mdwmail ---
336 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
338 (setq start (save-excursion
339 (goto-char (point-min))
340 (or (search-forward "\n\n" nil t) (point-min)))))
342 (setq end (point-max)))
343 (mc-encrypt-generic recip scm start end from sign))
345 ;; --- How to sign in mdwmail ---
347 (defun mdwmail-mc-sign (key scm start end uclr)
349 (setq start (save-excursion
350 (goto-char (point-min))
351 (or (search-forward "\n\n" nil t) (point-min)))))
353 (setq end (point-max)))
354 (mc-sign-generic key scm start end uclr))
356 ;; --- Some signature mangling ---
358 (defun mdwmail-mangle-signature ()
360 (goto-char (point-min))
361 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
362 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
364 ;;;----- Dired hacking ------------------------------------------------------
366 (defadvice dired-maybe-insert-subdir
367 (around mdw-marked-insertion first activate)
368 "The DIRNAME may be a list of directory names to insert. Interactively, if
369 files are marked, then insert all of them. With a numeric prefix argument,
370 select that many entries near point; with a non-numeric prefix argument,
371 prompt for listing options."
373 (list (dired-get-marked-files nil
374 (and (integerp current-prefix-arg)
377 (and current-prefix-arg
378 (not (integerp current-prefix-arg))
379 (read-string "Switches for listing: "
380 (or dired-subdir-switches
381 dired-actual-switches)))))
382 (let ((dirs (ad-get-arg 0)))
383 (dolist (dir (if (listp dirs) dirs (list dirs)))
387 ;;;----- URL viewing --------------------------------------------------------
389 (defun mdw-w3m-browse-url (url &optional new-session-p)
390 "Invoke w3m on the URL in its current window, or at least a different one.
391 If NEW-SESSION-P, start a new session."
392 (interactive "sURL: \nP")
394 (let ((window (selected-window)))
397 (select-window (or (and (not new-session-p)
398 (get-buffer-window "*w3m*"))
400 (if (one-window-p t) (split-window))
402 (w3m-browse-url url new-session-p))
403 (select-window window)))))
405 (defvar mdw-good-url-browsers
406 '((w3m . mdw-w3m-browse-url)
409 "List of good browsers for mdw-good-url-browsers; each item is a browser
410 function name, or a cons (CHECK . FUNC). A symbol FOO stands for (FOO
413 (defun mdw-good-url-browser ()
414 "Return a good URL browser. Trundle the list of such things, finding the
415 first item for which CHECK is fboundp, and returning the correponding FUNC."
416 (let ((bs mdw-good-url-browsers) b check func answer)
417 (while (and bs (not answer))
421 (setq check (car b) func (cdr b))
422 (setq check b func b))
427 ;;;----- Paragraph filling --------------------------------------------------
429 ;; --- Useful variables ---
431 (defvar mdw-fill-prefix nil
432 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'. If there's
433 no fill prefix currently set (by the `fill-prefix' variable) and there's
434 a match from one of the regexps here, it gets used to set the fill-prefix
435 for the current operation.
437 The variable is a list of items of the form `REGEXP . PREFIX'; if the
438 REGEXP matches, the PREFIX is used to set the fill prefix. It in turn is
441 STRING -- insert a literal string
442 (match . N) -- insert the thing matched by bracketed subexpression N
443 (pad . N) -- a string of whitespace the same width as subexpression N
444 (expr . FORM) -- the result of evaluating FORM")
446 (make-variable-buffer-local 'mdw-fill-prefix)
448 (defvar mdw-hanging-indents
450 "\\([*o]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)"
453 "*Standard regular expression matching things which might be part of a
454 hanging indent. This is mainly useful in `auto-fill-mode'.")
456 ;; --- Setting things up ---
458 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
460 ;; --- Utility functions ---
462 (defun mdw-tabify (s)
463 "Tabify the string S. This is a horrid hack."
468 (setq start (point-marker))
470 (setq end (point-marker))
472 (setq s (buffer-substring start (1- end)))
473 (delete-region start end)
474 (set-marker start nil)
478 (defun mdw-examine-fill-prefixes (l)
479 "Given a list of dynamic fill prefixes, pick one which matches context and
480 return the static fill prefix to use. Point must be at the start of a line,
481 and match data must be saved."
483 ((looking-at (car (car l)))
484 (mdw-tabify (apply (function concat)
485 (mapcar (function mdw-do-prefix-match)
487 (t (mdw-examine-fill-prefixes (cdr l)))))
489 (defun mdw-maybe-car (p)
490 "If P is a pair, return (car P), otherwise just return P."
491 (if (consp p) (car p) p))
493 (defun mdw-padding (s)
494 "Return a string the same width as S but made entirely from whitespace."
495 (let* ((l (length s)) (i 0) (n (make-string l ? )))
502 (defun mdw-do-prefix-match (m)
503 "Expand a dynamic prefix match element. See `mdw-fill-prefix' for
505 (cond ((not (consp m)) (format "%s" m))
506 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
507 ((eq (car m) 'pad) (mdw-padding (match-string
508 (mdw-maybe-car (cdr m)))))
509 ((eq (car m) 'eval) (eval (cdr m)))
512 (defun mdw-choose-dynamic-fill-prefix ()
513 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
514 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
515 ((not mdw-fill-prefix) fill-prefix)
519 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
521 (defun do-auto-fill ()
522 "Handle auto-filling, working out a dynamic fill prefix in the case where
523 there isn't a sensible static one."
524 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
527 (defun mdw-fill-paragraph ()
528 "Fill paragraph, getting a dynamic fill prefix."
530 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
531 (fill-paragraph nil)))
533 (defun mdw-standard-fill-prefix (rx &optional mat)
534 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
535 This is just a short-cut for setting the thing by hand, and by design it
536 doesn't cope with anything approximating a complicated case."
537 (setq mdw-fill-prefix
538 `((,(concat rx mdw-hanging-indents)
540 (pad . ,(or mat 2))))))
542 ;;;----- Other common declarations ------------------------------------------
544 ;; --- Common mode settings ---
546 (defvar mdw-auto-indent t
547 "Whether to indent automatically after a newline.")
549 (defun mdw-misc-mode-config ()
551 (cond ((eq major-mode 'lisp-mode)
552 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
553 ((or (eq major-mode 'slime-repl-mode)
554 (eq major-mode 'asm-mode))
557 (local-set-key "\C-m" 'newline-and-indent))))
558 (local-set-key [C-return] 'newline)
559 (make-variable-buffer-local 'page-delimiter)
560 (setq page-delimiter "\f\\|^.*-\\{6\\}.*$")
561 (setq comment-column 40)
563 (setq fill-column 77)
564 (setq show-trailing-whitespace t)
565 (outline-minor-mode t)
568 ;; --- Set up all sorts of faces ---
570 (defvar mdw-set-font nil)
572 (defvar mdw-punct-face 'mdw-punct-face "Face to use for punctuation")
573 (make-face 'mdw-punct-face)
574 (defvar mdw-number-face 'mdw-number-face "Face to use for numbers")
575 (make-face 'mdw-number-face)
577 ;; --- Backup file handling ---
579 (defvar mdw-backup-disable-regexps nil
580 "*List of regular expressions: if a file name matches any of these then the
581 file is not backed up.")
583 (defun mdw-backup-enable-predicate (name)
584 "[mdw]'s default backup predicate: allows a backup if the
585 standard predicate would allow it, and it doesn't match any of
586 the regular expressions in `mdw-backup-disable-regexps'."
587 (and (normal-backup-enable-predicate name)
588 (let ((answer t) (list mdw-backup-disable-regexps))
591 (if (string-match (car list) name)
593 (setq list (cdr list)))
595 (setq backup-enable-predicate 'mdw-backup-enable-predicate)
597 ;;;----- General fontification ----------------------------------------------
599 (defun mdw-set-fonts (frame faces)
601 (let ((face (caar faces)))
602 (or (facep face) (make-face face))
603 (set-face-attribute face frame
609 :foreground 'unspecified
610 :background 'unspecified
611 :underline 'unspecified
612 :overline 'unspecified
613 :strike-through 'unspecified
615 :inverse-video 'unspecified
616 :stipple 'unspecified
618 :inherit 'unspecified)
619 (apply 'set-face-attribute face frame (cdar faces))
620 (setq faces (cdr faces)))))
622 (defun mdw-do-set-font (&optional frame)
624 (mdw-set-fonts (and (boundp 'frame) frame) `(
625 (default :foreground "white" :background "black"
626 ,@(cond ((eq window-system 'w32)
627 '(:family "courier new" :height 85))
628 ((eq window-system 'x)
629 '(:family "misc-fixed" :height 130 :width semi-condensed))))
632 (mode-line :foreground "blue" :background "yellow"
633 :box (:line-width 1 :style released-button))
634 (mode-line-inactive :foreground "yellow" :background "blue"
635 :box (:line-width 1 :style released-button))
636 (scroll-bar :foreground "black" :background "lightgrey")
637 (fringe :foreground "yellow" :background "black")
638 (show-paren-match-face :background "darkgreen")
639 (show-paren-mismatch-face :background "red")
640 (font-lock-warning-face :background "red" :weight bold)
641 (highlight :background "DarkSeaGreen4")
642 (holiday-face :background "red")
643 (calendar-today-face :foreground "yellow" :weight bold)
644 (comint-highlight-prompt :weight bold)
645 (comint-highlight-input)
646 (font-lock-builtin-face :weight bold)
647 (font-lock-type-face :weight bold)
648 (region :background ,(if window-system "grey30" "blue"))
649 (isearch :background "palevioletred2")
650 (mdw-punct-face :foreground ,(if window-system "burlywood2" "yellow"))
651 (mdw-number-face :foreground "yellow")
652 (font-lock-function-name-face :weight bold)
653 (font-lock-variable-name-face :slant italic)
654 (font-lock-comment-delimiter-face
655 :foreground ,(if window-system "SeaGreen1" "green")
657 (font-lock-comment-face
658 :foreground ,(if window-system "SeaGreen1" "green")
660 (font-lock-string-face :foreground ,(if window-system "SkyBlue1" "cyan"))
661 (font-lock-keyword-face :weight bold)
662 (font-lock-constant-face :weight bold)
663 (font-lock-reference-face :weight bold)
664 (woman-bold :weight bold)
665 (woman-italic :slant italic)
666 (diff-index :weight bold)
667 (diff-file-header :weight bold)
668 (diff-hunk-header :foreground "SkyBlue1")
669 (diff-function :foreground "SkyBlue1" :weight bold)
670 (diff-header :background "grey10")
671 (diff-added :foreground "green")
672 (diff-removed :foreground "red")
674 (whizzy-slice-face :background "grey10")
675 (whizzy-error-face :background "darkred")
676 (trailing-whitespace :background "red")
679 (defun mdw-set-font ()
682 (if (not mdw-set-font)
684 (setq mdw-set-font t)
685 (mdw-do-set-font nil)))))
687 ;;;----- C programming configuration ----------------------------------------
689 ;; --- Linux kernel hacking ---
691 (defvar linux-c-mode-hook)
693 (defun linux-c-mode ()
696 (setq major-mode 'linux-c-mode)
697 (setq mode-name "Linux C")
698 (run-hooks 'linux-c-mode-hook))
700 ;; --- Make C indentation nice ---
702 (defun mdw-c-style ()
703 (c-add-style "[mdw] C and C++ style"
704 '((c-basic-offset . 2)
705 (comment-column . 40)
706 (c-class-key . "class")
707 (c-offsets-alist (substatement-open . 0)
714 (statement-case-intro . +)))
717 (defun mdw-fontify-c-and-c++ ()
719 ;; --- Fiddle with some syntax codes ---
721 (modify-syntax-entry ?* ". 23")
722 (modify-syntax-entry ?/ ". 124b")
723 (modify-syntax-entry ?\n "> b")
725 ;; --- Other stuff ---
728 (setq c-hanging-comment-ender-p nil)
729 (setq c-backslash-column 72)
730 (setq c-label-minimum-indentation 0)
731 (setq mdw-fill-prefix
732 `((,(concat "\\([ \t]*/?\\)"
734 "\\([A-Za-z]+:[ \t]*\\)?"
736 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
738 ;; --- Now define things to be fontified ---
740 (make-local-variable 'font-lock-keywords)
742 (mdw-regexps "and" ;C++
748 "bool" ;C++, C9X macro
754 "complex" ;C9X macro, C++ template type
759 "defined" ;C89 preprocessor
766 ;; "entry" ;K&R -- never used
771 "false" ;C++, C9X macro
778 "imaginary" ;C9X macro
779 "inline" ;C++, C9X, GCC
792 "reinterpret_cast" ;C++
805 "true" ;C++, C9X macro
818 "wchar_t" ;C++, C89 library type
825 "_Pragma" ;C9X preprocessor
840 (preprocessor-keywords
841 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
842 "ident" "if" "ifdef" "ifndef" "import" "include"
843 "line" "pragma" "unassert" "undef" "warning"))
845 (mdw-regexps "class" "defs" "encode" "end" "implementation"
846 "interface" "private" "protected" "protocol" "public"
849 (setq font-lock-keywords
852 ;; --- Fontify include files as strings ---
854 (list (concat "^[ \t]*\\#[ \t]*"
855 "\\(include\\|import\\)"
856 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
857 '(2 font-lock-string-face))
859 ;; --- Preprocessor directives are `references'? ---
861 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
862 preprocessor-keywords
863 "\\)\\>\\|[0-9]+\\|$\\)\\)")
864 '(1 font-lock-keyword-face))
866 ;; --- Handle the keywords defined above ---
868 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
869 '(0 font-lock-keyword-face))
871 (list (concat "\\<\\(" c-keywords "\\)\\>")
872 '(0 font-lock-keyword-face))
874 ;; --- Handle numbers too ---
876 ;; This looks strange, I know. It corresponds to the
877 ;; preprocessor's idea of what a number looks like, rather than
878 ;; anything sensible.
880 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
881 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
882 '(0 mdw-number-face))
884 ;; --- And anything else is punctuation ---
886 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
887 '(0 mdw-punct-face))))))
889 ;;;----- AP calc mode -------------------------------------------------------
891 (defun apcalc-mode ()
894 (setq major-mode 'apcalc-mode)
895 (setq mode-name "AP Calc")
896 (run-hooks 'apcalc-mode-hook))
898 (defun mdw-fontify-apcalc ()
900 ;; --- Fiddle with some syntax codes ---
902 (modify-syntax-entry ?* ". 23")
903 (modify-syntax-entry ?/ ". 14")
905 ;; --- Other stuff ---
908 (setq c-hanging-comment-ender-p nil)
909 (setq c-backslash-column 72)
910 (setq comment-start "/* ")
911 (setq comment-end " */")
912 (setq mdw-fill-prefix
913 `((,(concat "\\([ \t]*/?\\)"
915 "\\([A-Za-z]+:[ \t]*\\)?"
917 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
919 ;; --- Now define things to be fontified ---
921 (make-local-variable 'font-lock-keywords)
923 (mdw-regexps "break" "case" "cd" "continue" "define" "default"
924 "do" "else" "exit" "for" "global" "goto" "help" "if"
925 "local" "mat" "obj" "print" "quit" "read" "return"
926 "show" "static" "switch" "while" "write")))
928 (setq font-lock-keywords
931 ;; --- Handle the keywords defined above ---
933 (list (concat "\\<\\(" c-keywords "\\)\\>")
934 '(0 font-lock-keyword-face))
936 ;; --- Handle numbers too ---
938 ;; This looks strange, I know. It corresponds to the
939 ;; preprocessor's idea of what a number looks like, rather than
940 ;; anything sensible.
942 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
943 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
944 '(0 mdw-number-face))
946 ;; --- And anything else is punctuation ---
948 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
949 '(0 mdw-punct-face))))))
951 ;;;----- Java programming configuration -------------------------------------
953 ;; --- Make indentation nice ---
955 (defun mdw-java-style ()
956 (c-add-style "[mdw] Java style"
957 '((c-basic-offset . 2)
958 (c-offsets-alist (substatement-open . 0)
963 (statement-case-intro . +)))
966 ;; --- Declare Java fontification style ---
968 (defun mdw-fontify-java ()
970 ;; --- Other stuff ---
973 (setq c-hanging-comment-ender-p nil)
974 (setq c-backslash-column 72)
975 (setq comment-start "/* ")
976 (setq comment-end " */")
977 (setq mdw-fill-prefix
978 `((,(concat "\\([ \t]*/?\\)"
980 "\\([A-Za-z]+:[ \t]*\\)?"
982 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
984 ;; --- Now define things to be fontified ---
986 (make-local-variable 'font-lock-keywords)
988 (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch"
989 "char" "class" "const" "continue" "default" "do"
990 "double" "else" "extends" "final" "finally" "float"
991 "for" "goto" "if" "implements" "import" "instanceof"
992 "int" "interface" "long" "native" "new" "package"
993 "private" "protected" "public" "return" "short"
994 "static" "super" "switch" "synchronized" "this"
995 "throw" "throws" "transient" "try" "void" "volatile"
998 "false" "null" "true")))
1000 (setq font-lock-keywords
1003 ;; --- Handle the keywords defined above ---
1005 (list (concat "\\<\\(" java-keywords "\\)\\>")
1006 '(0 font-lock-keyword-face))
1008 ;; --- Handle numbers too ---
1010 ;; The following isn't quite right, but it's close enough.
1012 (list (concat "\\<\\("
1013 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1014 "[0-9]+\\(\\.[0-9]*\\|\\)"
1015 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1017 '(0 mdw-number-face))
1019 ;; --- And anything else is punctuation ---
1021 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1022 '(0 mdw-punct-face))))))
1024 ;;;----- C# programming configuration ---------------------------------------
1026 ;; --- Make indentation nice ---
1028 (defun mdw-csharp-style ()
1029 (c-add-style "[mdw] C# style"
1030 '((c-basic-offset . 2)
1031 (c-offsets-alist (substatement-open . 0)
1036 (statement-case-intro . +)))
1039 ;; --- Declare C# fontification style ---
1041 (defun mdw-fontify-csharp ()
1043 ;; --- Other stuff ---
1046 (setq c-hanging-comment-ender-p nil)
1047 (setq c-backslash-column 72)
1048 (setq comment-start "/* ")
1049 (setq comment-end " */")
1050 (setq mdw-fill-prefix
1051 `((,(concat "\\([ \t]*/?\\)"
1053 "\\([A-Za-z]+:[ \t]*\\)?"
1054 mdw-hanging-indents)
1055 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
1057 ;; --- Now define things to be fontified ---
1059 (make-local-variable 'font-lock-keywords)
1060 (let ((csharp-keywords
1061 (mdw-regexps "abstract" "as" "base" "bool" "break"
1062 "byte" "case" "catch" "char" "checked"
1063 "class" "const" "continue" "decimal" "default"
1064 "delegate" "do" "double" "else" "enum"
1065 "event" "explicit" "extern" "false" "finally"
1066 "fixed" "float" "for" "foreach" "goto"
1067 "if" "implicit" "in" "int" "interface"
1068 "internal" "is" "lock" "long" "namespace"
1069 "new" "null" "object" "operator" "out"
1070 "override" "params" "private" "protected" "public"
1071 "readonly" "ref" "return" "sbyte" "sealed"
1072 "short" "sizeof" "stackalloc" "static" "string"
1073 "struct" "switch" "this" "throw" "true"
1074 "try" "typeof" "uint" "ulong" "unchecked"
1075 "unsafe" "ushort" "using" "virtual" "void"
1076 "volatile" "while" "yield")))
1078 (setq font-lock-keywords
1081 ;; --- Handle the keywords defined above ---
1083 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1084 '(0 font-lock-keyword-face))
1086 ;; --- Handle numbers too ---
1088 ;; The following isn't quite right, but it's close enough.
1090 (list (concat "\\<\\("
1091 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1092 "[0-9]+\\(\\.[0-9]*\\|\\)"
1093 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1095 '(0 mdw-number-face))
1097 ;; --- And anything else is punctuation ---
1099 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1100 '(0 mdw-punct-face))))))
1102 (defun csharp-mode ()
1105 (setq major-mode 'csharp-mode)
1106 (setq mode-name "C#")
1107 (mdw-fontify-csharp)
1108 (run-hooks 'csharp-mode-hook))
1110 ;;;----- Awk programming configuration --------------------------------------
1112 ;; --- Make Awk indentation nice ---
1114 (defun mdw-awk-style ()
1115 (c-add-style "[mdw] Awk style"
1116 '((c-basic-offset . 2)
1117 (c-offsets-alist (substatement-open . 0)
1118 (statement-cont . 0)
1119 (statement-case-intro . +)))
1122 ;; --- Declare Awk fontification style ---
1124 (defun mdw-fontify-awk ()
1126 ;; --- Miscellaneous fiddling ---
1129 (setq c-backslash-column 72)
1130 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1132 ;; --- Now define things to be fontified ---
1134 (make-local-variable 'font-lock-keywords)
1136 (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1137 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1138 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1139 "RSTART" "RLENGTH" "RT" "SUBSEP"
1140 "atan2" "break" "close" "continue" "cos" "delete"
1141 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1142 "function" "gensub" "getline" "gsub" "if" "in"
1143 "index" "int" "length" "log" "match" "next" "rand"
1144 "return" "print" "printf" "sin" "split" "sprintf"
1145 "sqrt" "srand" "strftime" "sub" "substr" "system"
1146 "systime" "tolower" "toupper" "while")))
1148 (setq font-lock-keywords
1151 ;; --- Handle the keywords defined above ---
1153 (list (concat "\\<\\(" c-keywords "\\)\\>")
1154 '(0 font-lock-keyword-face))
1156 ;; --- Handle numbers too ---
1158 ;; The following isn't quite right, but it's close enough.
1160 (list (concat "\\<\\("
1161 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1162 "[0-9]+\\(\\.[0-9]*\\|\\)"
1163 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1165 '(0 mdw-number-face))
1167 ;; --- And anything else is punctuation ---
1169 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1170 '(0 mdw-punct-face))))))
1172 ;;;----- Perl programming style ---------------------------------------------
1174 ;; --- Perl indentation style ---
1176 (setq cperl-indent-level 2)
1177 (setq cperl-continued-statement-offset 2)
1178 (setq cperl-continued-brace-offset 0)
1179 (setq cperl-brace-offset -2)
1180 (setq cperl-brace-imaginary-offset 0)
1181 (setq cperl-label-offset 0)
1183 ;; --- Define perl fontification style ---
1185 (defun mdw-fontify-perl ()
1187 ;; --- Miscellaneous fiddling ---
1189 (modify-syntax-entry ?$ "\\")
1190 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1191 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1193 ;; --- Now define fontification things ---
1195 (make-local-variable 'font-lock-keywords)
1196 (let ((perl-keywords
1197 (mdw-regexps "and" "cmp" "continue" "do" "else" "elsif" "eq"
1198 "for" "foreach" "ge" "gt" "goto" "if"
1199 "last" "le" "lt" "local" "my" "ne" "next" "or"
1200 "package" "redo" "require" "return" "sub"
1201 "undef" "unless" "until" "use" "while")))
1203 (setq font-lock-keywords
1206 ;; --- Set up the keywords defined above ---
1208 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1209 '(0 font-lock-keyword-face))
1211 ;; --- At least numbers are simpler than C ---
1213 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1214 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1215 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1216 '(0 mdw-number-face))
1218 ;; --- And anything else is punctuation ---
1220 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1221 '(0 mdw-punct-face))))))
1223 (defun perl-number-tests (&optional arg)
1224 "Assign consecutive numbers to lines containing `#t'. With ARG,
1225 strip numbers instead."
1228 (goto-char (point-min))
1229 (let ((i 0) (fmt (if arg "" " %4d")))
1230 (while (search-forward "#t" nil t)
1231 (delete-region (point) (line-end-position))
1233 (insert (format fmt i)))
1234 (goto-char (point-min))
1235 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1236 (replace-match (format "\\1%d" i))))))
1238 ;;;----- Python programming style -------------------------------------------
1240 ;; --- Define Python fontification style ---
1242 (defun mdw-fontify-python ()
1244 ;; --- Miscellaneous fiddling ---
1246 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1248 ;; --- Now define fontification things ---
1250 (make-local-variable 'font-lock-keywords)
1251 (let ((python-keywords
1252 (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def"
1253 "del" "elif" "else" "except" "exec" "finally" "for"
1254 "from" "global" "if" "import" "in" "is" "lambda"
1255 "not" "or" "pass" "print" "raise" "return" "try"
1256 "while" "with" "yield")))
1257 (setq font-lock-keywords
1260 ;; --- Set up the keywords defined above ---
1262 (list (concat "\\<\\(" python-keywords "\\)\\>")
1263 '(0 font-lock-keyword-face))
1265 ;; --- At least numbers are simpler than C ---
1267 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1268 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1269 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1270 '(0 mdw-number-face))
1272 ;; --- And anything else is punctuation ---
1274 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1275 '(0 mdw-punct-face))))))
1277 ;;;----- ARM assembler programming configuration ----------------------------
1279 ;; --- There doesn't appear to be an Emacs mode for this yet ---
1281 ;; Better do something about that, I suppose.
1283 (defvar arm-assembler-mode-map nil)
1284 (defvar arm-assembler-abbrev-table nil)
1285 (defvar arm-assembler-mode-syntax-table (make-syntax-table))
1287 (or arm-assembler-mode-map
1289 (setq arm-assembler-mode-map (make-sparse-keymap))
1290 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1291 (define-key arm-assembler-mode-map [C-return] 'newline)
1292 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1294 (defun arm-assembler-mode ()
1295 "Major mode for ARM assembler programs"
1298 ;; --- Do standard major mode things ---
1300 (kill-all-local-variables)
1301 (use-local-map arm-assembler-mode-map)
1302 (setq local-abbrev-table arm-assembler-abbrev-table)
1303 (setq major-mode 'arm-assembler-mode)
1304 (setq mode-name "ARM assembler")
1306 ;; --- Set up syntax table ---
1308 (set-syntax-table arm-assembler-mode-syntax-table)
1309 (modify-syntax-entry ?; ; Nasty hack
1310 "<" arm-assembler-mode-syntax-table)
1311 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1312 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1314 (make-local-variable 'comment-start)
1315 (setq comment-start ";")
1316 (make-local-variable 'comment-end)
1317 (setq comment-end "")
1318 (make-local-variable 'comment-column)
1319 (setq comment-column 48)
1320 (make-local-variable 'comment-start-skip)
1321 (setq comment-start-skip ";+[ \t]*")
1323 ;; --- Play with indentation ---
1325 (make-local-variable 'indent-line-function)
1326 (setq indent-line-function 'indent-relative-maybe)
1328 ;; --- Set fill prefix ---
1330 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1332 ;; --- Fiddle with fontification ---
1334 (make-local-variable 'font-lock-keywords)
1335 (setq font-lock-keywords
1338 ;; --- Handle numbers too ---
1340 ;; The following isn't quite right, but it's close enough.
1344 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1346 '(0 mdw-number-face))
1348 ;; --- Do something about operators ---
1350 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1351 '(1 font-lock-keyword-face)
1352 '(2 font-lock-string-face))
1354 '(0 font-lock-keyword-face))
1356 ;; --- Do menemonics and directives ---
1358 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1359 '(1 font-lock-keyword-face))
1361 ;; --- And anything else is punctuation ---
1363 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1364 '(0 mdw-punct-face))))
1366 (run-hooks 'arm-assembler-mode-hook))
1368 ;;;----- Assembler mode -----------------------------------------------------
1370 (defun mdw-fontify-asm ()
1371 (modify-syntax-entry ?' "\"")
1372 (modify-syntax-entry ?. "w")
1373 (setf fill-prefix nil)
1374 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
1376 ;;;----- TCL configuration --------------------------------------------------
1378 (defun mdw-fontify-tcl ()
1379 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1380 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1381 (make-local-variable 'font-lock-keywords)
1382 (setq font-lock-keywords
1384 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1385 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1386 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1387 '(0 mdw-number-face))
1388 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1389 '(0 mdw-punct-face)))))
1391 ;;;----- REXX configuration -------------------------------------------------
1393 (defun mdw-rexx-electric-* ()
1398 (defun mdw-rexx-indent-newline-indent ()
1401 (if abbrev-mode (expand-abbrev))
1402 (newline-and-indent))
1404 (defun mdw-fontify-rexx ()
1406 ;; --- Various bits of fiddling ---
1408 (setq mdw-auto-indent nil)
1409 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1410 (local-set-key [?*] 'mdw-rexx-electric-*)
1411 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
1413 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1415 ;; --- Set up keywords and things for fontification ---
1417 (make-local-variable 'font-lock-keywords-case-fold-search)
1418 (setq font-lock-keywords-case-fold-search t)
1420 (setq rexx-indent 2)
1421 (setq rexx-end-indent rexx-indent)
1422 (setq rexx-cont-indent rexx-indent)
1424 (make-local-variable 'font-lock-keywords)
1425 (let ((rexx-keywords
1426 (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop"
1427 "else" "end" "engineering" "exit" "expose" "for"
1428 "forever" "form" "fuzz" "if" "interpret" "iterate"
1429 "leave" "linein" "name" "nop" "numeric" "off" "on"
1430 "options" "otherwise" "parse" "procedure" "pull"
1431 "push" "queue" "return" "say" "select" "signal"
1432 "scientific" "source" "then" "trace" "to" "until"
1433 "upper" "value" "var" "version" "when" "while"
1436 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1437 "center" "center" "charin" "charout" "chars"
1438 "compare" "condition" "copies" "c2d" "c2x"
1439 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1440 "errortext" "format" "fuzz" "insert" "lastpos"
1441 "left" "length" "lineout" "lines" "max" "min"
1442 "overlay" "pos" "queued" "random" "reverse" "right"
1443 "sign" "sourceline" "space" "stream" "strip"
1444 "substr" "subword" "symbol" "time" "translate"
1445 "trunc" "value" "verify" "word" "wordindex"
1446 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1449 (setq font-lock-keywords
1452 ;; --- Set up the keywords defined above ---
1454 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1455 '(0 font-lock-keyword-face))
1457 ;; --- Fontify all symbols the same way ---
1459 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1460 "[A-Za-z0-9.!?_#@$]+\\)")
1461 '(0 font-lock-variable-name-face))
1463 ;; --- And everything else is punctuation ---
1465 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1466 '(0 mdw-punct-face))))))
1468 ;;;----- Standard ML programming style --------------------------------------
1470 (defun mdw-fontify-sml ()
1472 ;; --- Make underscore an honorary letter ---
1474 (modify-syntax-entry ?' "w")
1476 ;; --- Set fill prefix ---
1478 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1480 ;; --- Now define fontification things ---
1482 (make-local-variable 'font-lock-keywords)
1484 (mdw-regexps "abstype" "and" "andalso" "as"
1487 "else" "end" "eqtype" "exception"
1488 "fn" "fun" "functor"
1490 "if" "in" "include" "infix" "infixr"
1493 "of" "op" "open" "orelse"
1495 "sharing" "sig" "signature" "struct" "structure"
1498 "where" "while" "with" "withtype")))
1500 (setq font-lock-keywords
1503 ;; --- Set up the keywords defined above ---
1505 (list (concat "\\<\\(" sml-keywords "\\)\\>")
1506 '(0 font-lock-keyword-face))
1508 ;; --- At least numbers are simpler than C ---
1510 (list (concat "\\<\\(\\~\\|\\)"
1511 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
1513 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
1514 "\\([eE]\\(\\~\\|\\)"
1515 "[0-9]+\\|\\)\\)\\)")
1516 '(0 mdw-number-face))
1518 ;; --- And anything else is punctuation ---
1520 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1521 '(0 mdw-punct-face))))))
1523 ;;;----- Haskell configuration ----------------------------------------------
1525 (defun mdw-fontify-haskell ()
1527 ;; --- Fiddle with syntax table to get comments right ---
1529 (modify-syntax-entry ?' "\"")
1530 (modify-syntax-entry ?- ". 123")
1531 (modify-syntax-entry ?{ ". 1b")
1532 (modify-syntax-entry ?} ". 4b")
1533 (modify-syntax-entry ?\n ">")
1535 ;; --- Set fill prefix ---
1537 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
1539 ;; --- Fiddle with fontification ---
1541 (make-local-variable 'font-lock-keywords)
1542 (let ((haskell-keywords
1543 (mdw-regexps "as" "case" "ccall" "class" "data" "default"
1544 "deriving" "do" "else" "foreign" "hiding" "if"
1545 "import" "in" "infix" "infixl" "infixr" "instance"
1546 "let" "module" "newtype" "of" "qualified" "safe"
1547 "stdcall" "then" "type" "unsafe" "where")))
1549 (setq font-lock-keywords
1552 '(0 font-lock-comment-face))
1553 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
1554 '(0 font-lock-keyword-face))
1555 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1556 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
1557 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
1558 '(0 mdw-number-face))
1559 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1560 '(0 mdw-punct-face))))))
1562 ;;;----- Texinfo configuration ----------------------------------------------
1564 (defun mdw-fontify-texinfo ()
1566 ;; --- Set fill prefix ---
1568 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
1570 ;; --- Real fontification things ---
1572 (make-local-variable 'font-lock-keywords)
1573 (setq font-lock-keywords
1576 ;; --- Environment names are keywords ---
1578 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
1579 '(2 font-lock-keyword-face))
1581 ;; --- Unmark escaped magic characters ---
1583 (list "\\(@\\)\\([@{}]\\)"
1584 '(1 font-lock-keyword-face)
1585 '(2 font-lock-variable-name-face))
1587 ;; --- Make sure we get comments properly ---
1589 (list "@c\\(\\|omment\\)\\( .*\\)?$"
1590 '(0 font-lock-comment-face))
1592 ;; --- Command names are keywords ---
1594 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1595 '(0 font-lock-keyword-face))
1597 ;; --- Fontify TeX special characters as punctuation ---
1600 '(0 mdw-punct-face)))))
1602 ;;;----- TeX and LaTeX configuration ----------------------------------------
1604 (defun mdw-fontify-tex ()
1605 (setq ispell-parser 'tex)
1607 ;; --- Don't make maths into a string ---
1609 (modify-syntax-entry ?$ ".")
1610 (modify-syntax-entry ?$ "." font-lock-syntax-table)
1611 (local-set-key [?$] 'self-insert-command)
1613 ;; --- Set fill prefix ---
1615 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
1617 ;; --- Real fontification things ---
1619 (make-local-variable 'font-lock-keywords)
1620 (setq font-lock-keywords
1623 ;; --- Environment names are keywords ---
1625 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
1627 '(2 font-lock-keyword-face))
1629 ;; --- Suspended environment names are keywords too ---
1631 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
1633 '(3 font-lock-keyword-face))
1635 ;; --- Command names are keywords ---
1637 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1638 '(0 font-lock-keyword-face))
1640 ;; --- Handle @/.../ for italics ---
1642 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
1643 ;; '(1 font-lock-keyword-face)
1644 ;; '(3 font-lock-keyword-face))
1646 ;; --- Handle @*...* for boldness ---
1648 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
1649 ;; '(1 font-lock-keyword-face)
1650 ;; '(3 font-lock-keyword-face))
1652 ;; --- Handle @`...' for literal syntax things ---
1654 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
1655 ;; '(1 font-lock-keyword-face)
1656 ;; '(3 font-lock-keyword-face))
1658 ;; --- Handle @<...> for nonterminals ---
1660 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
1661 ;; '(1 font-lock-keyword-face)
1662 ;; '(3 font-lock-keyword-face))
1664 ;; --- Handle other @-commands ---
1666 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
1667 ;; '(0 font-lock-keyword-face))
1669 ;; --- Make sure we get comments properly ---
1672 '(0 font-lock-comment-face))
1674 ;; --- Fontify TeX special characters as punctuation ---
1677 '(0 mdw-punct-face)))))
1679 ;;;----- SGML hacking -------------------------------------------------------
1681 (defun mdw-sgml-mode ()
1684 (mdw-standard-fill-prefix "")
1685 (make-variable-buffer-local 'sgml-delimiters)
1686 (setq sgml-delimiters
1687 '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]"
1688 "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\""
1689 "LITA" "'" "MDC" ">" "MDO" "<!" "MINUS" "-" "MSC" "]]" "NESTC" "{"
1690 "NET" "}" "OPT" "?" "OR" "|" "PERO" "%" "PIC" ">" "PIO" "<?"
1691 "PLUS" "+" "REFC" "." "REP" "*" "RNI" "#" "SEQ" "," "STAGO" ":"
1692 "TAGC" "." "VI" "=" "MS-START" "<![" "MS-END" "]]>"
1693 "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "<!--" "XML-TAGCE" "/>"
1695 (setq major-mode 'mdw-sgml-mode)
1696 (setq mode-name "[mdw] SGML")
1697 (run-hooks 'mdw-sgml-mode-hook))
1699 ;;;----- Shell scripts ------------------------------------------------------
1701 (defun mdw-setup-sh-script-mode ()
1703 ;; --- Fetch the shell interpreter's name ---
1705 (let ((shell-name sh-shell-file))
1707 ;; --- Try reading the hash-bang line ---
1710 (goto-char (point-min))
1711 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
1712 (setq shell-name (match-string 1))))
1714 ;; --- Now try to set the shell ---
1716 ;; Don't let `sh-set-shell' bugger up my script.
1718 (let ((executable-set-magic #'(lambda (s &rest r) s)))
1719 (sh-set-shell shell-name)))
1721 ;; --- Now enable my keys and the fontification ---
1723 (mdw-misc-mode-config)
1725 ;; --- Set the indentation level correctly ---
1727 (setq sh-indentation 2)
1728 (setq sh-basic-offset 2))
1730 ;;;----- Messages-file mode -------------------------------------------------
1732 (defun message-mode-guts ()
1733 (setq messages-mode-syntax-table (make-syntax-table))
1734 (set-syntax-table messages-mode-syntax-table)
1735 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
1736 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
1737 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
1738 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
1739 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
1740 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
1741 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
1742 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
1743 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
1744 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
1745 (make-local-variable 'comment-start)
1746 (make-local-variable 'comment-end)
1747 (make-local-variable 'indent-line-function)
1748 (setq indent-line-function 'indent-relative)
1749 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
1750 (make-local-variable 'font-lock-defaults)
1751 (make-local-variable 'message-mode-keywords)
1753 (mdw-regexps "array" "bitmap" "callback" "docs[ \t]+enum"
1754 "export" "enum" "fixed-octetstring" "flags"
1755 "harmless" "map" "nested" "optional"
1756 "optional-tagged" "package" "primitive"
1757 "primitive-nullfree" "relaxed[ \t]+enum"
1758 "set" "table" "tagged-optional" "union"
1759 "variadic" "vector" "version" "version-tag")))
1760 (setq message-mode-keywords
1762 (list (concat "\\<\\(" keywords "\\)\\>:")
1763 '(0 font-lock-keyword-face))
1764 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
1765 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
1766 (0 font-lock-variable-name-face))
1767 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
1768 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1769 (0 mdw-punct-face)))))
1770 (setq font-lock-defaults
1771 '(message-mode-keywords nil nil nil nil))
1772 (run-hooks 'messages-file-hook))
1774 (defun messages-mode ()
1777 (setq major-mode 'messages-mode)
1778 (setq mode-name "Messages")
1780 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
1781 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
1782 (setq comment-start "# ")
1783 (setq comment-end "")
1784 (turn-on-font-lock-if-enabled)
1785 (run-hooks 'messages-mode-hook))
1787 (defun cpp-messages-mode ()
1790 (setq major-mode 'cpp-messages-mode)
1791 (setq mode-name "CPP Messages")
1793 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
1794 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
1795 (setq comment-start "/* ")
1796 (setq comment-end " */")
1797 (let ((preprocessor-keywords
1798 (mdw-regexps "assert" "define" "elif" "else" "endif" "error"
1799 "ident" "if" "ifdef" "ifndef" "import" "include"
1800 "line" "pragma" "unassert" "undef" "warning")))
1801 (setq message-mode-keywords
1802 (append (list (list (concat "^[ \t]*\\#[ \t]*"
1803 "\\(include\\|import\\)"
1804 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1805 '(2 font-lock-string-face))
1806 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1807 preprocessor-keywords
1808 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1809 '(1 font-lock-keyword-face)))
1810 message-mode-keywords)))
1811 (turn-on-font-lock-if-enabled)
1812 (run-hooks 'cpp-messages-mode-hook))
1814 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
1815 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
1816 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
1818 ;;;----- Messages-file mode -------------------------------------------------
1820 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
1821 "Face to use for subsittution directives.")
1822 (make-face 'mallow-driver-substitution-face)
1823 (defvar mallow-driver-text-face 'mallow-driver-text-face
1824 "Face to use for body text.")
1825 (make-face 'mallow-driver-text-face)
1827 (defun mallow-driver-mode ()
1830 (setq major-mode 'mallow-driver-mode)
1831 (setq mode-name "Mallow driver")
1832 (setq mallow-driver-mode-syntax-table (make-syntax-table))
1833 (set-syntax-table mallow-driver-mode-syntax-table)
1834 (make-local-variable 'comment-start)
1835 (make-local-variable 'comment-end)
1836 (make-local-variable 'indent-line-function)
1837 (setq indent-line-function 'indent-relative)
1838 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
1839 (make-local-variable 'font-lock-defaults)
1840 (make-local-variable 'mallow-driver-mode-keywords)
1842 (mdw-regexps "each" "divert" "file" "if"
1843 "perl" "set" "string" "type" "write")))
1844 (setq mallow-driver-mode-keywords
1846 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
1847 '(0 font-lock-keyword-face))
1848 (list "^%\\s *\\(#.*\\|\\)$"
1849 '(0 font-lock-comment-face))
1851 '(0 font-lock-keyword-face))
1852 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
1854 '(0 mallow-driver-substitution-face t)))))
1855 (setq font-lock-defaults
1856 '(mallow-driver-mode-keywords nil nil nil nil))
1857 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
1858 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
1859 (setq comment-start "%# ")
1860 (setq comment-end "")
1861 (turn-on-font-lock-if-enabled)
1862 (run-hooks 'mallow-driver-mode-hook))
1864 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
1866 ;;;----- NFast debugs -------------------------------------------------------
1868 (defun nfast-debug-mode ()
1871 (setq major-mode 'nfast-debug-mode)
1872 (setq mode-name "NFast debug")
1873 (setq messages-mode-syntax-table (make-syntax-table))
1874 (set-syntax-table messages-mode-syntax-table)
1875 (make-local-variable 'font-lock-defaults)
1876 (make-local-variable 'nfast-debug-mode-keywords)
1877 (setq truncate-lines t)
1878 (setq nfast-debug-mode-keywords
1880 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
1881 (0 font-lock-keyword-face))
1882 (list (concat "^[ \t]+\\(\\("
1883 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
1884 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
1886 "[0-9a-fA-F]+\\)[ \t]*$")
1887 '(0 mdw-number-face))
1888 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
1889 (1 font-lock-keyword-face))
1890 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
1891 (1 font-lock-warning-face))
1892 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
1894 (list (concat "^[ \t]+\\.cmd=[ \t]+"
1895 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
1896 '(1 font-lock-keyword-face))
1897 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
1898 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
1899 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
1900 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
1901 (setq font-lock-defaults
1902 '(nfast-debug-mode-keywords nil nil nil nil))
1903 (turn-on-font-lock-if-enabled)
1904 (run-hooks 'nfast-debug-mode-hook))
1906 ;;;----- Other languages ----------------------------------------------------
1908 ;; --- Smalltalk ---
1910 (defun mdw-setup-smalltalk ()
1911 (and mdw-auto-indent
1912 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
1913 (make-variable-buffer-local 'mdw-auto-indent)
1914 (setq mdw-auto-indent nil)
1915 (local-set-key "\C-i" 'smalltalk-reindent))
1917 (defun mdw-fontify-smalltalk ()
1918 (make-local-variable 'font-lock-keywords)
1919 (setq font-lock-keywords
1921 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
1922 '(0 font-lock-keyword-face))
1923 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1924 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1925 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1926 '(0 mdw-number-face))
1927 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1928 '(0 mdw-punct-face)))))
1930 ;; --- Lispy languages ---
1932 (defun mdw-indent-newline-and-indent ()
1934 (indent-for-tab-command)
1935 (newline-and-indent))
1937 (eval-after-load "cl-indent"
1939 (mapc #'(lambda (pair)
1941 'common-lisp-indent-function
1943 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
1944 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
1946 (defun mdw-common-lisp-indent ()
1947 (make-variable-buffer-local 'lisp-indent-function)
1948 (setq lisp-indent-function 'common-lisp-indent-function))
1950 (defun mdw-fontify-lispy ()
1952 ;; --- Set fill prefix ---
1954 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1956 ;; --- Not much fontification needed ---
1958 (make-local-variable 'font-lock-keywords)
1959 (setq font-lock-keywords
1961 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1962 '(0 mdw-punct-face)))))
1964 (defun comint-send-and-indent ()
1967 (and mdw-auto-indent
1968 (indent-for-tab-command)))
1970 (defun mdw-setup-m4 ()
1971 (mdw-standard-fill-prefix "\\([ \t]*\\(?:#+\\|\\<dnl\\>\\)[ \t]*\\)"))
1973 ;;;----- Text mode ----------------------------------------------------------
1975 (defun mdw-text-mode ()
1976 (setq fill-column 72)
1978 (mdw-standard-fill-prefix
1979 "\\([ \t]*\\([>#|:] ?\\)*[ \t]*\\)" 3)
1982 ;;;----- Outline mode -------------------------------------------------------
1984 (defun mdw-outline-collapse-all ()
1985 "Completely collapse everything in the entire buffer."
1988 (goto-char (point-min))
1989 (while (< (point) (point-max))
1993 ;;;----- Shell mode ---------------------------------------------------------
1995 (defun mdw-sh-mode-setup ()
1996 (local-set-key [?\C-a] 'comint-bol)
1997 (add-hook 'comint-output-filter-functions
1998 'comint-watch-for-password-prompt))
2000 (defun mdw-term-mode-setup ()
2001 (setq term-prompt-regexp "^[^]#$%>»}\n]*[]#$%>»}] *")
2002 (make-local-variable 'mouse-yank-at-point)
2003 (make-local-variable 'transient-mark-mode)
2004 (setq mouse-yank-at-point t)
2005 (setq transient-mark-mode nil)
2009 ;;;----- That's all, folks --------------------------------------------------
2011 (provide 'dot-emacs)