5 ;;; Functions and macros for .emacs
7 ;;; (c) 2004 Mark Wooding
10 ;;;----- Licensing notice ---------------------------------------------------
12 ;;; This program is free software; you can redistribute it and/or modify
13 ;;; it under the terms of the GNU General Public License as published by
14 ;;; the Free Software Foundation; either version 2 of the License, or
15 ;;; (at your option) any later version.
17 ;;; This program is distributed in the hope that it will be useful,
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;;; GNU General Public License for more details.
22 ;;; You should have received a copy of the GNU General Public License
23 ;;; along with this program; if not, write to the Free Software Foundation,
24 ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 ;;;----- Some general utilities ---------------------------------------------
28 ;; --- Some error trapping ---
30 ;; If individual bits of this file go tits-up, we don't particularly want
31 ;; the whole lot to stop right there and then, because it's bloody annoying.
33 (defmacro trap (&rest forms)
34 "Execute FORMS without allowing errors to propagate outside."
36 ,(if (cdr forms) (cons 'progn forms) (car forms))
37 (error (message "Error (trapped): %s" (error-message-string err)))))
39 ;; --- Configuration reading ---
41 (defvar mdw-config nil)
42 (defun mdw-config (sym)
43 "Read the configuration variable named SYM."
45 (setq mdw-config (with-temp-buffer
46 (insert-file-contents "~/.mdw.conf")
47 (replace-regexp "^[ \t]*\\(#.*\\|\\)\n" ""
48 nil (point-min) (point-max))
49 (replace-regexp (concat "^[ \t]*"
50 "\\([-a-zA-Z0-9_.]*\\)"
53 "[ \t]**\\(\n\\|$\\)")
55 nil (point-min) (point-max))
56 (car (read-from-string
57 (concat "(" (buffer-string) ")"))))))
58 (cdr (assq sym mdw-config)))
60 ;; --- Splitting windows ---
62 (defconst mdw-scrollbar-width (if window-system 6 1)
63 "Guessed width of scroll bar.")
64 (defun mdw-divvy-window (&optional w)
65 "Split a wide window into appropriate widths."
68 (let ((win (selected-window))
69 (c (/ (+ (window-width) mdw-scrollbar-width)
70 (+ w mdw-scrollbar-width))))
73 (split-window-horizontally (+ w mdw-scrollbar-width))
77 ;; --- Functions for sexp diary entries ---
79 (defun mdw-weekday (l)
80 "Return non-nil if `date' falls on one of the days of the week in L.
82 L is a list of day numbers (from 0 to 6 for Sunday through to Saturday) or
83 symbols `sunday', `monday', etc. (or a mixture). If the date stored in
84 `date' falls on a listed day, then the function returns non-nil."
85 (let ((d (calendar-day-of-week date)))
87 (memq (nth d '(sunday monday tuesday wednesday
88 thursday friday saturday)) l))))
90 (defun mdw-todo (&optional when)
91 "Return non-nil today, or on WHEN, whichever is later."
92 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
93 (d (calendar-absolute-from-gregorian date)))
95 (setq w (max w (calendar-absolute-from-gregorian
97 ((not european-calendar-style)
109 ;;;----- Utility functions --------------------------------------------------
111 ;; --- mdw-uniquify-alist ---
113 (defun mdw-uniquify-alist (&rest alists)
115 "Return the concatenation of the ALISTS with duplicate elements removed.
117 The first association with a given key prevails; others are ignored. The
118 input lists are not modified, although they'll probably become garbage."
121 (let ((start-list (cons nil nil)))
122 (mdw-do-uniquify start-list
127 ;; --- mdw-do-uniquify ---
129 ;; The DONE argument is a list whose first element is `nil'. It contains the
130 ;; uniquified alist built so far. The leading `nil' is stripped off at the
131 ;; end of the operation; it's only there so that DONE always references a
132 ;; cons cell. END refers to the final cons cell in the DONE list; it is
133 ;; modified in place each time to avoid the overheads of `append'ing all the
134 ;; time. The L argument is the alist we're currently processing; the
135 ;; remaining alists are given in REST.
137 (defun mdw-do-uniquify (done end l rest)
138 "A helper function for mdw-uniquify-alist."
140 ;; --- There are several different cases to deal with here ---
144 ;; --- Current list isn't empty ---
146 ;; Add the first item to the DONE list if there's not an item with the
147 ;; same KEY already there.
149 (l (or (assoc (car (car l)) done)
151 (setcdr end (cons (car l) nil))
152 (setq end (cdr end))))
153 (mdw-do-uniquify done end (cdr l) rest))
155 ;; --- The list we were working on is empty ---
157 ;; Shunt the next list into the current list position and go round again.
159 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
161 ;; --- Everything's done ---
163 ;; Remove the leading `nil' from the DONE list and return it. Finished!
167 ;; --- Insert a date ---
170 "Insert the current date in a pleasing way."
172 (insert (save-excursion
173 (let ((buffer (get-buffer-create "*tmp*")))
174 (unwind-protect (progn (set-buffer buffer)
176 (shell-command "date +%Y-%m-%d" t)
178 (delete-backward-char 1)
180 (kill-buffer buffer))))))
182 ;; --- UUencoding ---
184 (defun uuencode (file &optional name)
185 "UUencodes a file, maybe calling it NAME, into the current buffer."
186 (interactive "fInput file name: ")
188 ;; --- If NAME isn't specified, then guess from the filename ---
193 (or (string-match "[^/]*$" file) 0))))
195 (print (format "uuencode `%s' `%s'" file name))
197 ;; --- Now actually do the thing ---
199 (call-process "uuencode" file t nil name))
201 (defvar np-file "~/.np"
202 "*Where the `now-playing' file is.")
204 (defun np (&optional arg)
205 "Grabs a `now-playing' string."
209 (goto-char (point-max))
211 (insert-file np-file)))))
215 (require 'autorevert)
216 (defun mdw-check-autorevert ()
217 (if (and (buffer-file-name)
218 (tramp-tramp-file-p (buffer-file-name)))
219 (unless global-auto-revert-ignore-buffer
220 (setq global-auto-revert-ignore-buffer 'tramp))
221 (if (eq global-auto-revert-ignore-buffer 'tramp)
222 (setq global-auto-revert-ignore-buffer nil))))
223 (defadvice find-file (after mdw-autorevert activate)
224 (mdw-check-autorevert))
225 (defadvice write-file (after mdw-autorevert activate)
226 (mdw-check-autorevert)))
228 (defun mdwmail-mode ()
229 "Major mode for editing news and mail messages from external programs
230 Not much right now. Just support for doing MailCrypt stuff."
232 (kill-all-local-variables)
233 (use-local-map text-mode-map)
234 (setq local-abbrev-table text-mode-abbrev-table)
235 (setq major-mode 'mdwmail-mode)
236 (setq mode-name "[mdw] mail")
237 (make-local-variable 'paragraph-separate)
238 (make-local-variable 'paragraph-start)
239 (setq paragraph-start (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
241 (setq paragraph-separate (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
243 (run-hooks 'text-mode-hook 'mdwmail-mode-hook 'mail-setup-hook))
245 ;; --- How to encrypt in mdwmail ---
247 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
249 (setq start (save-excursion
250 (goto-char (point-min))
251 (or (search-forward "\n\n" nil t) (point-min)))))
253 (setq end (point-max)))
254 (mc-encrypt-generic recip scm start end from sign))
256 ;; --- How to sign in mdwmail ---
258 (defun mdwmail-mc-sign (key scm start end uclr)
260 (setq start (save-excursion
261 (goto-char (point-min))
262 (or (search-forward "\n\n" nil t) (point-min)))))
264 (setq end (point-max)))
265 (mc-sign-generic key scm start end uclr))
267 ;; --- Some signature mangling ---
269 (defun mdwmail-mangle-signature ()
271 (goto-char (point-min))
272 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
273 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
275 ;;;----- Paragraph filling --------------------------------------------------
277 ;; --- Useful variables ---
279 (defvar mdw-fill-prefix nil
280 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'. If there's
281 no fill prefix currently set (by the `fill-prefix' variable) and there's
282 a match from one of the regexps here, it gets used to set the fill-prefix
283 for the current operation.
285 The variable is a list of items of the form `REGEXP . PREFIX'; if the
286 REGEXP matches, the PREFIX is used to set the fill prefix. It in turn is
289 STRING -- insert a literal string
290 (match . N) -- insert the thing matched by bracketed subexpression N
291 (pad . N) -- a string of whitespace the same width as subexpression N
292 (expr . FORM) -- the result of evaluating FORM")
294 (make-variable-buffer-local 'mdw-fill-prefix)
296 (defvar mdw-hanging-indents
297 "\\(\\(\\([*o]\\|--\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)[ \t]+\\)?\\)"
298 "*Standard regular expression matching things which might be part of a
299 hanging indent. This is mainly useful in `auto-fill-mode'.")
301 ;; --- Setting things up ---
303 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
305 ;; --- Utility functions ---
307 (defun mdw-tabify (s)
308 "Tabify the string S. This is a horrid hack."
313 (setq start (point-marker))
315 (setq end (point-marker))
317 (setq s (buffer-substring start (1- end)))
318 (delete-region start end)
319 (set-marker start nil)
323 (defun mdw-examine-fill-prefixes (l)
324 "Given a list of dynamic fill prefixes, pick one which matches context and
325 return the static fill prefix to use. Point must be at the start of a line,
326 and match data must be saved."
328 ((looking-at (car (car l)))
329 (mdw-tabify (apply (function concat)
330 (mapcar (function mdw-do-prefix-match)
332 (t (mdw-examine-fill-prefixes (cdr l)))))
334 (defun mdw-maybe-car (p)
335 "If P is a pair, return (car P), otherwise just return P."
336 (if (consp p) (car p) p))
338 (defun mdw-padding (s)
339 "Return a string the same width as S but made entirely from whitespace."
340 (let* ((l (length s)) (i 0) (n (make-string l ? )))
347 (defun mdw-do-prefix-match (m)
348 "Expand a dynamic prefix match element. See `mdw-fill-prefix' for
350 (cond ((not (consp m)) (format "%s" m))
351 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
352 ((eq (car m) 'pad) (mdw-padding (match-string
353 (mdw-maybe-car (cdr m)))))
354 ((eq (car m) 'eval) (eval (cdr m)))
357 (defun mdw-choose-dynamic-fill-prefix ()
358 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
359 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
360 ((not mdw-fill-prefix) fill-prefix)
364 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
366 (defun do-auto-fill ()
367 "Handle auto-filling, working out a dynamic fill prefix in the case where
368 there isn't a sensible static one."
369 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
372 (defun mdw-fill-paragraph ()
373 "Fill paragraph, getting a dynamic fill prefix."
375 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
376 (fill-paragraph nil)))
378 (defun mdw-standard-fill-prefix (rx &optional mat)
379 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
380 This is just a short-cut for setting the thing by hand, and by design it
381 doesn't cope with anything approximating a complicated case."
382 (setq mdw-fill-prefix
383 `((,(concat rx mdw-hanging-indents)
385 (pad . ,(or mat 2))))))
387 ;;;----- Other common declarations ------------------------------------------
389 (defun mdw-set-frame-transparency (&optional n)
391 (let* ((alist (frame-parameters))
392 (trans (assq 'transparency alist)))
394 (rplacd trans (not (if n (zerop n) (cdr trans))))
395 (setq trans (cons 'transparency (not (equal 0 n)))))
396 (modify-frame-parameters (selected-frame) (list trans))))
398 ;; --- Mouse wheel support ---
400 (defconst mdw-wheel-scroll-amount 15)
401 (defun mdw-wheel-up (click)
403 (mdw-wheel-scroll click (function scroll-down)))
404 (defun mdw-wheel-down (click)
406 (mdw-wheel-scroll click (function scroll-up)))
408 (defun mdw-wheel-scroll (click func)
409 (let ((win (selected-window)))
412 (select-window (posn-window (event-start click)))
414 (funcall func (/ (window-height) 2))))
415 (select-window win))))
417 ;; --- Going backwards ---
419 (defun other-window-backwards (arg)
421 (other-window (- arg)))
423 ;; --- Common mode settings ---
425 (defvar mdw-auto-indent t
426 "Whether to indent automatically after a newline.")
428 (defun mdw-misc-mode-config ()
430 (cond ((eq major-mode 'lisp-mode)
431 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
432 ((eq major-mode 'slime-repl-mode) nil)
434 (local-set-key "\C-m" 'newline-and-indent))))
435 (local-set-key [C-return] 'newline)
436 (local-set-key [?\;] 'self-insert-command)
437 (local-set-key [?\#] 'self-insert-command)
438 (local-set-key [?\"] 'self-insert-command)
439 (setq comment-column 40)
441 (setq fill-column 77)
444 ;; --- Set up all sorts of faces ---
446 (defvar mdw-set-font nil)
448 (defvar mdw-punct-face 'mdw-punct-face "Face to use for punctuation")
449 (make-face 'mdw-punct-face)
450 (defvar mdw-number-face 'mdw-number-face "Face to use for numbers")
451 (make-face 'mdw-number-face)
453 ;;;----- General fontification ----------------------------------------------
455 (defun mdw-set-fonts (frame ff)
456 (if ff (progn (set-face-attribute (caar ff) frame
462 :foreground 'unspecified
463 :background 'unspecified
464 :underline 'unspecified
465 :overline 'unspecified
466 :strike-through 'unspecified
468 :inverse-video 'unspecified
469 :stipple 'unspecified
471 :inherit 'unspecified
473 (apply 'set-face-attribute (caar ff) frame (cdar ff))
474 (mdw-set-fonts frame (cdr ff)))))
476 (defun mdw-do-set-font (&optional frame)
478 (mdw-set-fonts (and (boundp 'frame) frame) `(
479 (default :foreground "white" :background "black"
480 ,@(cond ((eq window-system 'w32)
481 '(:family "courier new" :height 85))
482 ((eq window-system 'x)
483 '(:family "misc-fixed" :width semi-condensed))))
484 (modeline :foreground "blue" :background "yellow"
485 :box (:line-width 1 :style released-button))
486 (scroll-bar :foreground "black" :background "lightgrey")
487 (fringe :foreground "yellow" :background "grey30")
488 (show-paren-match-face :background "darkgreen")
489 (show-paren-mismatch-face :background "red")
490 (font-lock-warning-face :background "red" :weight bold)
491 (highlight :background "DarkSeaGreen4")
492 (holiday-face :background "red")
493 (calendar-today-face :foreground "yellow" :weight bold)
494 (comint-highlight-prompt :weight bold)
495 (comint-highlight-input)
496 (font-lock-builtin-face :weight bold)
497 (font-lock-type-face :weight bold)
498 (region :background "grey30")
499 (isearch :background "palevioletred2")
500 (mdw-punct-face :foreground ,(if window-system "burlywood2" "yellow"))
501 (mdw-number-face :foreground "yellow")
502 (font-lock-function-name-face :weight bold)
503 (font-lock-variable-name-face :slant italic)
504 (font-lock-comment-face
505 :foreground ,(if window-system "SeaGreen1" "green")
507 (font-lock-string-face :foreground ,(if window-system "SkyBlue1" "cyan"))
508 (font-lock-keyword-face :weight bold)
509 (font-lock-constant-face :weight bold)
510 (font-lock-reference-face :weight bold)
511 (woman-bold-face :weight bold)
512 (woman-italic-face :slant italic)
513 (diff-header-face :foreground "skyblue1")
514 (diff-index-face :weight bold)
515 (diff-file-header-face)
516 (diff-context-face :foreground "grey70")
517 (diff-added-face :foreground "white")
518 (diff-removed-face :foreground "white" :slant italic)
519 (whizzy-slice-face :background "grey10")
520 (whizzy-error-face :background "darkred")
523 (defun mdw-set-font ()
526 (if (not mdw-set-font)
528 (setq mdw-set-font t)
529 (mdw-do-set-font nil)))))
531 ;;;----- C programming configuration ----------------------------------------
533 ;; --- Linux kernel hacking ---
535 (defvar linux-c-mode-hook)
537 (defun linux-c-mode ()
540 (setq major-mode 'linux-c-mode)
541 (setq mode-name "Linux C")
542 (run-hooks 'linux-c-mode-hook))
544 ;; --- Make C indentation nice ---
546 (defun mdw-c-style ()
547 (c-add-style "[mdw] C and C++ style"
548 '((c-basic-offset . 2)
549 (c-tab-always-indent . nil)
550 (comment-column . 40)
551 (c-class-key . "class")
552 (c-offsets-alist (substatement-open . 0)
559 (statement-case-intro . +)))
562 (defun mdw-fontify-c-and-c++ ()
564 ;; --- Fiddle with some syntax codes ---
566 (modify-syntax-entry ?_ "w")
567 (modify-syntax-entry ?* ". 23")
568 (modify-syntax-entry ?/ ". 124b")
569 (modify-syntax-entry ?\n "> b")
571 ;; --- Other stuff ---
574 (setq c-hanging-comment-ender-p nil)
575 (setq c-backslash-column 72)
576 (setq c-label-minimum-indentation 0)
577 (setq comment-start "/* ")
578 (setq comment-end " */")
579 (setq mdw-fill-prefix
580 `((,(concat "\\([ \t]*/?\\)"
582 "\\([A-Za-z]+:[ \t]*\\)?"
584 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
586 ;; --- Now define things to be fontified ---
588 (make-local-variable 'font-lock-keywords)
597 "bool" ;C++, C9X macro
603 "complex" ;C9X macro, C++ template type
608 "defined" ;C89 preprocessor
615 ;; "entry" ;K&R -- never used
620 "false" ;C++, C9X macro
627 "imaginary" ;C9X macro
628 "inline" ;C++, C9X, GCC
641 "reinterpret_cast" ;C++
654 "true" ;C++, C9X macro
667 "wchar_t" ;C++, C89 library type
674 "_Pragma" ;C9X preprocessor
689 (preprocessor-keywords
690 (make-regexp '("assert" "define" "elif" "else" "endif" "error"
691 "ident" "if" "ifdef" "ifndef" "import" "include"
692 "line" "pragma" "unassert" "undef" "warning")))
694 (make-regexp '("class" "defs" "encode" "end" "implementation"
695 "interface" "private" "protected" "protocol" "public"
698 (setq font-lock-keywords
702 ;; --- Fontify include files as strings ---
704 (list (concat "^[ \t]*\\#[ \t]*"
705 "\\(include\\|import\\)"
706 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
707 '(2 font-lock-string-face))
709 ;; --- Preprocessor directives are `references'? ---
711 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
712 preprocessor-keywords
713 "\\)\\>\\|[0-9]+\\|$\\)\\)")
714 '(1 font-lock-keyword-face))
716 ;; --- Handle the keywords defined above ---
718 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
719 '(0 font-lock-keyword-face))
721 (list (concat "\\<\\(" c-keywords "\\)\\>")
722 '(0 font-lock-keyword-face))
724 ;; --- Handle numbers too ---
726 ;; This looks strange, I know. It corresponds to the
727 ;; preprocessor's idea of what a number looks like, rather than
728 ;; anything sensible.
730 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
731 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
732 '(0 mdw-number-face))
734 ;; --- And anything else is punctuation ---
736 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
737 '(0 mdw-punct-face))))))
739 ;;;----- AP calc mode -------------------------------------------------------
741 (defun apcalc-mode ()
744 (setq major-mode 'apcalc-mode)
745 (setq mode-name "AP Calc")
746 (run-hooks 'apcalc-mode-hook))
748 (defun mdw-fontify-apcalc ()
750 ;; --- Fiddle with some syntax codes ---
752 (modify-syntax-entry ?_ "w")
753 (modify-syntax-entry ?* ". 23")
754 (modify-syntax-entry ?/ ". 14")
756 ;; --- Other stuff ---
759 (setq c-hanging-comment-ender-p nil)
760 (setq c-backslash-column 72)
761 (setq comment-start "/* ")
762 (setq comment-end " */")
763 (setq mdw-fill-prefix
764 `((,(concat "\\([ \t]*/?\\)"
766 "\\([A-Za-z]+:[ \t]*\\)?"
768 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
770 ;; --- Now define things to be fontified ---
772 (make-local-variable 'font-lock-keywords)
774 (make-regexp '("break" "case" "cd" "continue" "define" "default"
775 "do" "else" "exit" "for" "global" "goto" "help" "if"
776 "local" "mat" "obj" "print" "quit" "read" "return"
777 "show" "static" "switch" "while" "write"))))
779 (setq font-lock-keywords
783 ;; --- Handle the keywords defined above ---
785 (list (concat "\\<\\(" c-keywords "\\)\\>")
786 '(0 font-lock-keyword-face))
788 ;; --- Handle numbers too ---
790 ;; This looks strange, I know. It corresponds to the
791 ;; preprocessor's idea of what a number looks like, rather than
792 ;; anything sensible.
794 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
795 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
796 '(0 mdw-number-face))
798 ;; --- And anything else is punctuation ---
800 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
801 '(0 mdw-punct-face))))))
803 ;;;----- Java programming configuration -------------------------------------
805 ;; --- Make indentation nice ---
807 (defun mdw-java-style ()
808 (c-add-style "[mdw] Java style"
809 '((c-basic-offset . 2)
810 (c-tab-always-indent . nil)
811 (c-offsets-alist (substatement-open . 0)
816 (statement-case-intro . +)))
819 ;; --- Declare Java fontification style ---
821 (defun mdw-fontify-java ()
823 ;; --- Other stuff ---
826 (modify-syntax-entry ?_ "w")
827 (setq c-hanging-comment-ender-p nil)
828 (setq c-backslash-column 72)
829 (setq comment-start "/* ")
830 (setq comment-end " */")
831 (setq mdw-fill-prefix
832 `((,(concat "\\([ \t]*/?\\)"
834 "\\([A-Za-z]+:[ \t]*\\)?"
836 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
838 ;; --- Now define things to be fontified ---
840 (make-local-variable 'font-lock-keywords)
842 (make-regexp '("abstract" "boolean" "break" "byte" "case" "catch"
843 "char" "class" "const" "continue" "default" "do"
844 "double" "else" "extends" "final" "finally" "float"
845 "for" "goto" "if" "implements" "import" "instanceof"
846 "int" "interface" "long" "native" "new" "package"
847 "private" "protected" "public" "return" "short"
848 "static" "super" "switch" "synchronized" "this"
849 "throw" "throws" "transient" "try" "void" "volatile"
852 "false" "null" "true"))))
854 (setq font-lock-keywords
858 ;; --- Handle the keywords defined above ---
860 (list (concat "\\<\\(" java-keywords "\\)\\>")
861 '(0 font-lock-keyword-face))
863 ;; --- Handle numbers too ---
865 ;; The following isn't quite right, but it's close enough.
867 (list (concat "\\<\\("
868 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
869 "[0-9]+\\(\\.[0-9]*\\|\\)"
870 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
872 '(0 mdw-number-face))
874 ;; --- And anything else is punctuation ---
876 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
877 '(0 mdw-punct-face))))))
879 ;;;----- Awk programming configuration --------------------------------------
881 ;; --- Make Awk indentation nice ---
883 (defun mdw-awk-style ()
884 (c-add-style "[mdw] Awk style"
885 '((c-basic-offset . 2)
886 (c-tab-always-indent . nil)
887 (c-offsets-alist (substatement-open . 0)
889 (statement-case-intro . +)))
892 ;; --- Declare Awk fontification style ---
894 (defun mdw-fontify-awk ()
896 ;; --- Miscellaneous fiddling ---
898 (modify-syntax-entry ?_ "w")
900 (setq c-backslash-column 72)
901 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
903 ;; --- Now define things to be fontified ---
905 (make-local-variable 'font-lock-keywords)
907 (make-regexp '("BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
908 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
909 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
910 "RSTART" "RLENGTH" "RT" "SUBSEP"
911 "atan2" "break" "close" "continue" "cos" "delete"
912 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
913 "function" "gensub" "getline" "gsub" "if" "in"
914 "index" "int" "length" "log" "match" "next" "rand"
915 "return" "print" "printf" "sin" "split" "sprintf"
916 "sqrt" "srand" "strftime" "sub" "substr" "system"
917 "systime" "tolower" "toupper" "while"))))
919 (setq font-lock-keywords
923 ;; --- Handle the keywords defined above ---
925 (list (concat "\\<\\(" c-keywords "\\)\\>")
926 '(0 font-lock-keyword-face))
928 ;; --- Handle numbers too ---
930 ;; The following isn't quite right, but it's close enough.
932 (list (concat "\\<\\("
933 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
934 "[0-9]+\\(\\.[0-9]*\\|\\)"
935 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
937 '(0 mdw-number-face))
939 ;; --- And anything else is punctuation ---
941 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
942 '(0 mdw-punct-face))))))
944 ;;;----- Perl programming style ---------------------------------------------
946 ;; --- Perl indentation style ---
948 (setq cperl-tab-always-indent nil)
950 (setq cperl-indent-level 2)
951 (setq cperl-continued-statement-offset 2)
952 (setq cperl-continued-brace-offset 0)
953 (setq cperl-brace-offset -2)
954 (setq cperl-brace-imaginary-offset 0)
955 (setq cperl-label-offset 0)
957 ;; --- Define perl fontification style ---
959 (defun mdw-fontify-perl ()
961 ;; --- Miscellaneous fiddling ---
963 (modify-syntax-entry ?_ "w")
964 (modify-syntax-entry ?$ "\\")
965 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
966 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
968 ;; --- Now define fontification things ---
970 (make-local-variable 'font-lock-keywords)
972 (make-regexp '("and" "cmp" "continue" "do" "else" "elsif" "eq"
973 "for" "foreach" "ge" "gt" "goto" "if"
974 "last" "le" "lt" "local" "my" "ne" "next" "or"
975 "package" "redo" "require" "return" "sub"
976 "undef" "unless" "until" "use" "while"))))
978 (setq font-lock-keywords
982 ;; --- Set up the keywords defined above ---
984 (list (concat "\\<\\(" perl-keywords "\\)\\>")
985 '(0 font-lock-keyword-face))
987 ;; --- At least numbers are simpler than C ---
989 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
990 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
991 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
992 '(0 mdw-number-face))
994 ;; --- And anything else is punctuation ---
996 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
997 '(0 mdw-punct-face))))))
999 (defun perl-number-tests (&optional arg)
1000 "Assign consecutive numbers to lines containing `#t'. With ARG,
1001 strip numbers instead."
1004 (goto-char (point-min))
1005 (let ((i 0) (fmt (if arg "" " %4d")))
1006 (while (search-forward "#t" nil t)
1007 (delete-region (point) (line-end-position))
1009 (insert (format fmt i)))
1010 (goto-char (point-min))
1011 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1012 (replace-match (format "\\1%d" i))))))
1014 ;;;----- Python programming style -------------------------------------------
1016 ;; --- Define Python fontification style ---
1018 (trap (require 'pyrex-mode))
1019 (defun mdw-fontify-python ()
1021 ;; --- Miscellaneous fiddling ---
1023 (modify-syntax-entry ?_ "w")
1024 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1026 ;; --- Now define fontification things ---
1028 (make-local-variable 'font-lock-keywords)
1029 (let ((python-keywords
1030 (make-regexp '("and" "as" "assert" "break" "class" "continue" "def"
1031 "del" "elif" "else" "except" "exec" "finally" "for"
1032 "from" "global" "if" "import" "in" "is" "lambda"
1033 "not" "or" "pass" "print" "raise" "return" "try"
1035 (setq font-lock-keywords
1039 ;; --- Set up the keywords defined above ---
1041 (list (concat "\\<\\(" python-keywords "\\)\\>")
1042 '(0 font-lock-keyword-face))
1044 ;; --- At least numbers are simpler than C ---
1046 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1047 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1048 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1049 '(0 mdw-number-face))
1051 ;; --- And anything else is punctuation ---
1053 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1054 '(0 mdw-punct-face))))))
1056 ;;;----- ARM assembler programming configuration ----------------------------
1058 ;; --- There doesn't appear to be an Emacs mode for this yet ---
1060 ;; Better do something about that, I suppose.
1062 (defvar arm-assembler-mode-map nil)
1063 (defvar arm-assembler-abbrev-table nil)
1064 (defvar arm-assembler-mode-syntax-table (make-syntax-table))
1066 (or arm-assembler-mode-map
1068 (setq arm-assembler-mode-map (make-sparse-keymap))
1069 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1070 (define-key arm-assembler-mode-map [C-return] 'newline)
1071 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1073 (defun arm-assembler-mode ()
1074 "Major mode for ARM assembler programs"
1077 ;; --- Do standard major mode things ---
1079 (kill-all-local-variables)
1080 (use-local-map arm-assembler-mode-map)
1081 (setq local-abbrev-table arm-assembler-abbrev-table)
1082 (setq major-mode 'arm-assembler-mode)
1083 (setq mode-name "ARM assembler")
1085 ;; --- Set up syntax table ---
1087 (set-syntax-table arm-assembler-mode-syntax-table)
1088 (modify-syntax-entry ?; ; Nasty hack
1089 "<" arm-assembler-mode-syntax-table)
1090 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1091 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1093 (make-local-variable 'comment-start)
1094 (setq comment-start ";")
1095 (make-local-variable 'comment-end)
1096 (setq comment-end "")
1097 (make-local-variable 'comment-column)
1098 (setq comment-column 48)
1099 (make-local-variable 'comment-start-skip)
1100 (setq comment-start-skip ";+[ \t]*")
1102 ;; --- Play with indentation ---
1104 (make-local-variable 'indent-line-function)
1105 (setq indent-line-function 'indent-relative-maybe)
1107 ;; --- Set fill prefix ---
1109 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1111 ;; --- Fiddle with fontification ---
1113 (make-local-variable 'font-lock-keywords)
1114 (setq font-lock-keywords
1118 ;; --- Handle numbers too ---
1120 ;; The following isn't quite right, but it's close enough.
1124 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1126 '(0 mdw-number-face))
1128 ;; --- Do something about operators ---
1130 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1131 '(1 font-lock-keyword-face)
1132 '(2 font-lock-string-face))
1134 '(0 font-lock-keyword-face))
1136 ;; --- Do menemonics and directives ---
1138 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1139 '(1 font-lock-keyword-face))
1141 ;; --- And anything else is punctuation ---
1143 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1144 '(0 mdw-punct-face))))
1146 (run-hooks 'arm-assembler-mode-hook))
1148 ;;;----- TCL configuration --------------------------------------------------
1150 (defun mdw-fontify-tcl ()
1151 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1152 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1153 (make-local-variable 'font-lock-keywords)
1154 (setq font-lock-keywords
1157 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1158 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1159 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1160 '(0 mdw-number-face))
1161 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1162 '(0 mdw-punct-face)))))
1164 ;;;----- REXX configuration -------------------------------------------------
1166 (defun mdw-rexx-electric-* ()
1171 (defun mdw-rexx-indent-newline-indent ()
1174 (if abbrev-mode (expand-abbrev))
1175 (newline-and-indent))
1177 (defun mdw-fontify-rexx ()
1179 ;; --- Various bits of fiddling ---
1181 (setq mdw-auto-indent nil)
1182 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1183 (local-set-key [?*] 'mdw-rexx-electric-*)
1184 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
1185 '(?. ?! ?? ?_ ?# ?@ ?$))
1186 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1188 ;; --- Set up keywords and things for fontification ---
1190 (make-local-variable 'font-lock-keywords-case-fold-search)
1191 (setq font-lock-keywords-case-fold-search t)
1193 (setq rexx-indent 2)
1194 (setq rexx-end-indent rexx-indent)
1195 (setq rexx-tab-always-indent nil)
1196 (setq rexx-cont-indent rexx-indent)
1198 (make-local-variable 'font-lock-keywords)
1199 (let ((rexx-keywords
1200 (make-regexp '("address" "arg" "by" "call" "digits" "do" "drop"
1201 "else" "end" "engineering" "exit" "expose" "for"
1202 "forever" "form" "fuzz" "if" "interpret" "iterate"
1203 "leave" "linein" "name" "nop" "numeric" "off" "on"
1204 "options" "otherwise" "parse" "procedure" "pull"
1205 "push" "queue" "return" "say" "select" "signal"
1206 "scientific" "source" "then" "trace" "to" "until"
1207 "upper" "value" "var" "version" "when" "while"
1210 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1211 "center" "center" "charin" "charout" "chars"
1212 "compare" "condition" "copies" "c2d" "c2x"
1213 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1214 "errortext" "format" "fuzz" "insert" "lastpos"
1215 "left" "length" "lineout" "lines" "max" "min"
1216 "overlay" "pos" "queued" "random" "reverse" "right"
1217 "sign" "sourceline" "space" "stream" "strip"
1218 "substr" "subword" "symbol" "time" "translate"
1219 "trunc" "value" "verify" "word" "wordindex"
1220 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1223 (setq font-lock-keywords
1227 ;; --- Set up the keywords defined above ---
1229 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1230 '(0 font-lock-keyword-face))
1232 ;; --- Fontify all symbols the same way ---
1234 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1235 "[A-Za-z0-9.!?_#@$]+\\)")
1236 '(0 font-lock-variable-name-face))
1238 ;; --- And everything else is punctuation ---
1240 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1241 '(0 mdw-punct-face))))))
1243 ;;;----- Standard ML programming style --------------------------------------
1245 (defun mdw-fontify-sml ()
1247 ;; --- Make underscore an honorary letter ---
1249 (modify-syntax-entry ?_ "w")
1250 (modify-syntax-entry ?' "w")
1252 ;; --- Set fill prefix ---
1254 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1256 ;; --- Now define fontification things ---
1258 (make-local-variable 'font-lock-keywords)
1260 (make-regexp '("abstype" "and" "andalso" "as"
1263 "else" "end" "eqtype" "exception"
1264 "fn" "fun" "functor"
1266 "if" "in" "include" "infix" "infixr"
1269 "of" "op" "open" "orelse"
1271 "sharing" "sig" "signature" "struct" "structure"
1274 "where" "while" "with" "withtype"))))
1276 (setq font-lock-keywords
1280 ;; --- Set up the keywords defined above ---
1282 (list (concat "\\<\\(" sml-keywords "\\)\\>")
1283 '(0 font-lock-keyword-face))
1285 ;; --- At least numbers are simpler than C ---
1287 (list (concat "\\<\\(\\~\\|\\)"
1288 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
1290 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
1291 "\\([eE]\\(\\~\\|\\)"
1292 "[0-9]+\\|\\)\\)\\)")
1293 '(0 mdw-number-face))
1295 ;; --- And anything else is punctuation ---
1297 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1298 '(0 mdw-punct-face))))))
1300 ;;;----- Haskell configuration ----------------------------------------------
1302 (defun mdw-fontify-haskell ()
1304 ;; --- Fiddle with syntax table to get comments right ---
1306 (modify-syntax-entry ?_ "w")
1307 (modify-syntax-entry ?' "\"")
1308 (modify-syntax-entry ?- ". 123")
1309 (modify-syntax-entry ?{ ". 1b")
1310 (modify-syntax-entry ?} ". 4b")
1311 (modify-syntax-entry ?\n ">")
1313 ;; --- Set fill prefix ---
1315 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
1317 ;; --- Fiddle with fontification ---
1319 (make-local-variable 'font-lock-keywords)
1320 (let ((haskell-keywords
1321 (make-regexp '("as" "case" "ccall" "class" "data" "default"
1322 "deriving" "do" "else" "foreign" "hiding" "if"
1323 "import" "in" "infix" "infixl" "infixr" "instance"
1324 "let" "module" "newtype" "of" "qualified" "safe"
1325 "stdcall" "then" "type" "unsafe" "where"))))
1327 (setq font-lock-keywords
1331 '(0 font-lock-comment-face))
1332 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
1333 '(0 font-lock-keyword-face))
1334 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1335 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
1336 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
1337 '(0 mdw-number-face))
1338 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1339 '(0 mdw-punct-face))))))
1341 ;;;----- Texinfo configuration ----------------------------------------------
1343 (defun mdw-fontify-texinfo ()
1345 ;; --- Set fill prefix ---
1347 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
1349 ;; --- Real fontification things ---
1351 (make-local-variable 'font-lock-keywords)
1352 (setq font-lock-keywords
1356 ;; --- Environment names are keywords ---
1358 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
1359 '(2 font-lock-keyword-face))
1361 ;; --- Unmark escaped magic characters ---
1363 (list "\\(@\\)\\([@{}]\\)"
1364 '(1 font-lock-keyword-face)
1365 '(2 font-lock-variable-name-face))
1367 ;; --- Make sure we get comments properly ---
1369 (list "@c\\(\\|omment\\)\\( .*\\)?$"
1370 '(0 font-lock-comment-face))
1372 ;; --- Command names are keywords ---
1374 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1375 '(0 font-lock-keyword-face))
1377 ;; --- Fontify TeX special characters as punctuation ---
1380 '(0 mdw-punct-face)))))
1382 ;;;----- TeX and LaTeX configuration ----------------------------------------
1384 (defun mdw-fontify-tex ()
1385 (setq ispell-parser 'tex)
1387 ;; --- Don't make maths into a string ---
1389 (modify-syntax-entry ?$ ".")
1390 (modify-syntax-entry ?$ "." font-lock-syntax-table)
1391 (local-set-key [?$] 'self-insert-command)
1393 ;; --- Set fill prefix ---
1395 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
1397 ;; --- Real fontification things ---
1399 (make-local-variable 'font-lock-keywords)
1400 (setq font-lock-keywords
1404 ;; --- Environment names are keywords ---
1406 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
1408 '(2 font-lock-keyword-face))
1410 ;; --- Suspended environment names are keywords too ---
1412 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
1414 '(3 font-lock-keyword-face))
1416 ;; --- Command names are keywords ---
1418 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1419 '(0 font-lock-keyword-face))
1421 ;; --- Handle @/.../ for italics ---
1423 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
1424 ;; '(1 font-lock-keyword-face)
1425 ;; '(3 font-lock-keyword-face))
1427 ;; --- Handle @*...* for boldness ---
1429 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
1430 ;; '(1 font-lock-keyword-face)
1431 ;; '(3 font-lock-keyword-face))
1433 ;; --- Handle @`...' for literal syntax things ---
1435 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
1436 ;; '(1 font-lock-keyword-face)
1437 ;; '(3 font-lock-keyword-face))
1439 ;; --- Handle @<...> for nonterminals ---
1441 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
1442 ;; '(1 font-lock-keyword-face)
1443 ;; '(3 font-lock-keyword-face))
1445 ;; --- Handle other @-commands ---
1447 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
1448 ;; '(0 font-lock-keyword-face))
1450 ;; --- Make sure we get comments properly ---
1453 '(0 font-lock-comment-face))
1455 ;; --- Fontify TeX special characters as punctuation ---
1458 '(0 mdw-punct-face)))))
1460 ;;;----- Shell scripts ------------------------------------------------------
1462 (defun mdw-setup-sh-script-mode ()
1464 ;; --- Fetch the shell interpreter's name ---
1466 (let ((shell-name sh-shell-file))
1468 ;; --- Try reading the hash-bang line ---
1471 (goto-char (point-min))
1472 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
1473 (setq shell-name (match-string 1))))
1475 ;; --- Now try to set the shell ---
1477 ;; Don't let `sh-set-shell' bugger up my script.
1479 (let ((executable-set-magic #'(lambda (s &rest r) s)))
1480 (sh-set-shell shell-name)))
1482 ;; --- Now enable my keys and the fontification ---
1484 (mdw-misc-mode-config)
1486 ;; --- Set the indentation level correctly ---
1488 (setq sh-indentation 2)
1489 (setq sh-basic-offset 2))
1491 ;;;----- Messages-file mode -------------------------------------------------
1493 (defun message-mode-guts ()
1494 (setq messages-mode-syntax-table (make-syntax-table))
1495 (set-syntax-table messages-mode-syntax-table)
1496 (modify-syntax-entry ?_ "w" messages-mode-syntax-table)
1497 (modify-syntax-entry ?- "w" messages-mode-syntax-table)
1498 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
1499 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
1500 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
1501 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
1502 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
1503 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
1504 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
1505 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
1506 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
1507 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
1508 (make-local-variable 'comment-start)
1509 (make-local-variable 'comment-end)
1510 (make-local-variable 'indent-line-function)
1511 (setq indent-line-function 'indent-relative)
1512 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
1513 (make-local-variable 'font-lock-defaults)
1514 (make-local-variable 'message-mode-keywords)
1516 (make-regexp '("array" "bitmap" "callback" "docs[ \t]+enum"
1517 "export" "enum" "fixed-octetstring" "flags"
1518 "harmless" "map" "nested" "optional"
1519 "optional-tagged" "package" "primitive"
1520 "primitive-nullfree" "relaxed[ \t]+enum"
1521 "set" "table" "tagged-optional" "union"
1522 "variadic" "vector" "version" "version-tag"))))
1523 (setq message-mode-keywords
1525 (list (concat "\\<\\(" keywords "\\)\\>:")
1526 '(0 font-lock-keyword-face))
1527 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
1528 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
1529 (0 font-lock-variable-name-face))
1530 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
1531 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1532 (0 mdw-punct-face)))))
1533 (setq font-lock-defaults
1534 '(message-mode-keywords nil nil nil nil))
1535 (run-hooks 'messages-file-hook))
1537 (defun messages-mode ()
1540 (setq major-mode 'messages-mode)
1541 (setq mode-name "Messages")
1543 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
1544 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
1545 (setq comment-start "# ")
1546 (setq comment-end "")
1547 (turn-on-font-lock-if-enabled)
1548 (run-hooks 'messages-mode-hook))
1550 (defun cpp-messages-mode ()
1553 (setq major-mode 'cpp-messages-mode)
1554 (setq mode-name "CPP Messages")
1556 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
1557 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
1558 (setq comment-start "/* ")
1559 (setq comment-end " */")
1560 (let ((preprocessor-keywords
1561 (make-regexp '("assert" "define" "elif" "else" "endif" "error"
1562 "ident" "if" "ifdef" "ifndef" "import" "include"
1563 "line" "pragma" "unassert" "undef" "warning"))))
1564 (setq message-mode-keywords
1565 (append (list (list (concat "^[ \t]*\\#[ \t]*"
1566 "\\(include\\|import\\)"
1567 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1568 '(2 font-lock-string-face))
1569 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1570 preprocessor-keywords
1571 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1572 '(1 font-lock-keyword-face)))
1573 message-mode-keywords)))
1574 (setq font-lock-defaults
1575 '(message-mode-keywords nil nil nil nil))
1576 (turn-on-font-lock-if-enabled)
1577 (run-hooks 'messages-mode-hook))
1579 (add-hook 'messages-file-hook 'mdw-misc-mode-config t)
1580 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
1582 ;;;----- Messages-file mode -------------------------------------------------
1584 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
1585 "Face to use for subsittution directives.")
1586 (make-face 'mallow-driver-substitution-face)
1587 (defvar mallow-driver-text-face 'mallow-driver-text-face
1588 "Face to use for body text.")
1589 (make-face 'mallow-driver-text-face)
1591 (defun mallow-driver-mode ()
1594 (setq major-mode 'mallow-driver-mode)
1595 (setq mode-name "Mallow driver")
1596 (setq mallow-driver-mode-syntax-table (make-syntax-table))
1597 (set-syntax-table mallow-driver-mode-syntax-table)
1598 (make-local-variable 'comment-start)
1599 (make-local-variable 'comment-end)
1600 (make-local-variable 'indent-line-function)
1601 (setq indent-line-function 'indent-relative)
1602 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
1603 (make-local-variable 'font-lock-defaults)
1604 (make-local-variable 'mallow-driver-mode-keywords)
1606 (make-regexp '("each" "divert" "file" "if"
1607 "perl" "set" "string" "type" "write"))))
1608 (setq mallow-driver-mode-keywords
1610 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
1611 '(0 font-lock-keyword-face))
1612 (list "^%\\s *\\(#.*\\|\\)$"
1613 '(0 font-lock-comment-face))
1615 '(0 font-lock-keyword-face))
1616 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
1618 '(0 mallow-driver-substitution-face t)))))
1619 (setq font-lock-defaults
1620 '(mallow-driver-mode-keywords nil nil nil nil))
1621 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
1622 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
1623 (setq comment-start "%# ")
1624 (setq comment-end "")
1625 (turn-on-font-lock-if-enabled)
1626 (run-hooks 'mallow-driver-mode-hook))
1628 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
1630 ;;;----- NFast debugs -------------------------------------------------------
1632 (defun nfast-debug-mode ()
1635 (setq major-mode 'nfast-debug-mode)
1636 (setq mode-name "NFast debug")
1637 (setq messages-mode-syntax-table (make-syntax-table))
1638 (set-syntax-table messages-mode-syntax-table)
1639 (make-local-variable 'font-lock-defaults)
1640 (make-local-variable 'nfast-debug-mode-keywords)
1641 (setq truncate-lines t)
1642 (setq nfast-debug-mode-keywords
1644 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
1645 (0 font-lock-keyword-face))
1646 (list (concat "^[ \t]+\\(\\("
1647 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
1648 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
1650 "[0-9a-fA-F]+\\)[ \t]*$")
1651 '(0 mdw-number-face))
1652 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
1653 (1 font-lock-keyword-face))
1654 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
1655 (1 font-lock-warning-face))
1656 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
1658 (list (concat "^[ \t]+\\.cmd=[ \t]+"
1659 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
1660 '(1 font-lock-keyword-face))
1661 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
1662 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
1663 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
1664 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
1665 (setq font-lock-defaults
1666 '(nfast-debug-mode-keywords nil nil nil nil))
1667 (turn-on-font-lock-if-enabled)
1668 (run-hooks 'nfast-debug-mode-hook))
1670 ;;;----- Other languages ----------------------------------------------------
1672 ;; --- Smalltalk ---
1674 (defun mdw-setup-smalltalk ()
1675 (and mdw-auto-indent
1676 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
1677 (make-variable-buffer-local 'mdw-auto-indent)
1678 (setq mdw-auto-indent nil)
1679 (local-set-key "\C-i" 'smalltalk-reindent))
1681 (defun mdw-fontify-smalltalk ()
1682 (make-local-variable 'font-lock-keywords)
1683 (setq font-lock-keywords
1686 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
1687 '(0 font-lock-keyword-face))
1688 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1689 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1690 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1691 '(0 mdw-number-face))
1692 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1693 '(0 mdw-punct-face)))))
1695 ;; --- Lispy languages ---
1697 (defun mdw-indent-newline-and-indent ()
1699 (indent-for-tab-command)
1700 (newline-and-indent))
1702 (eval-after-load "cl-indent"
1704 (mapc #'(lambda (pair)
1706 'common-lisp-indent-function
1708 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
1709 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
1711 (defun mdw-common-lisp-indent ()
1712 (make-variable-buffer-local 'lisp-indent-function)
1713 (setq lisp-indent-function 'common-lisp-indent-function))
1715 (defun mdw-fontify-lispy ()
1717 ;; --- Set fill prefix ---
1719 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1721 ;; --- Not much fontification needed ---
1723 (make-local-variable 'font-lock-keywords)
1724 (setq font-lock-keywords
1727 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1728 '(0 mdw-punct-face)))))
1730 (defun comint-send-and-indent ()
1733 (and mdw-auto-indent
1734 (indent-for-tab-command)))
1736 ;;;----- Text mode ----------------------------------------------------------
1738 (defun mdw-text-mode ()
1739 (setq fill-column 72)
1741 (mdw-standard-fill-prefix
1742 "\\([ \t]*\\([A-Za-z0-9]*[>#|:] ?\\)*[ \t]*\\)" 3)
1745 ;;;----- Shell mode ---------------------------------------------------------
1747 (defun mdw-sh-mode-setup ()
1748 (local-set-key [?\C-a] 'comint-bol)
1749 (add-hook 'comint-output-filter-functions
1750 'comint-watch-for-password-prompt))
1752 (defun mdw-term-mode-setup ()
1753 (setq term-prompt-regexp "^[^]#$%>»}\n]*[]#$%>»}] *")
1754 (make-local-variable 'mouse-yank-at-point)
1755 (make-local-variable 'transient-mark-mode)
1756 (setq mouse-yank-at-point t)
1757 (setq transient-mark-mode nil)
1761 ;;;----- That's all, folks --------------------------------------------------
1763 (provide 'dot-emacs)