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 ;; --- Is an Emacs library available? ---
62 (defun library-exists-p (name)
63 "Return non-nil if NAME.el (or NAME.elc) is somewhere on the Emacs load
64 path. The non-nil value is the filename we found for the library."
65 (let ((path load-path) elt (foundp nil))
66 (while (and path (not foundp))
68 (setq path (cdr path))
69 (setq foundp (or (let ((file (concat elt "/" name ".elc")))
70 (and (file-exists-p file) file))
71 (let ((file (concat elt "/" name ".el")))
72 (and (file-exists-p file) file)))))
75 (defun maybe-autoload (symbol file &optional docstring interactivep type)
76 "Set an autoload if the file actually exists."
77 (and (library-exists-p file)
78 (autoload symbol file docstring interactivep type)))
80 ;; --- Splitting windows ---
82 (defconst mdw-scrollbar-width (if window-system 6 1)
83 "Guessed width of scroll bar.")
84 (defun mdw-divvy-window (&optional w)
85 "Split a wide window into appropriate widths."
88 (let ((win (selected-window))
89 (c (/ (+ (window-width) mdw-scrollbar-width)
90 (+ w mdw-scrollbar-width))))
93 (split-window-horizontally (+ w mdw-scrollbar-width))
97 ;; --- Functions for sexp diary entries ---
99 (defun mdw-weekday (l)
100 "Return non-nil if `date' falls on one of the days of the week in L.
102 L is a list of day numbers (from 0 to 6 for Sunday through to Saturday) or
103 symbols `sunday', `monday', etc. (or a mixture). If the date stored in
104 `date' falls on a listed day, then the function returns non-nil."
105 (let ((d (calendar-day-of-week date)))
107 (memq (nth d '(sunday monday tuesday wednesday
108 thursday friday saturday)) l))))
110 (defun mdw-todo (&optional when)
111 "Return non-nil today, or on WHEN, whichever is later."
112 (let ((w (calendar-absolute-from-gregorian (calendar-current-date)))
113 (d (calendar-absolute-from-gregorian date)))
115 (setq w (max w (calendar-absolute-from-gregorian
117 ((not european-calendar-style)
129 ;;;----- Utility functions --------------------------------------------------
131 ;; --- mdw-uniquify-alist ---
133 (defun mdw-uniquify-alist (&rest alists)
135 "Return the concatenation of the ALISTS with duplicate elements removed.
137 The first association with a given key prevails; others are ignored. The
138 input lists are not modified, although they'll probably become garbage."
141 (let ((start-list (cons nil nil)))
142 (mdw-do-uniquify start-list
147 ;; --- mdw-do-uniquify ---
149 ;; The DONE argument is a list whose first element is `nil'. It contains the
150 ;; uniquified alist built so far. The leading `nil' is stripped off at the
151 ;; end of the operation; it's only there so that DONE always references a
152 ;; cons cell. END refers to the final cons cell in the DONE list; it is
153 ;; modified in place each time to avoid the overheads of `append'ing all the
154 ;; time. The L argument is the alist we're currently processing; the
155 ;; remaining alists are given in REST.
157 (defun mdw-do-uniquify (done end l rest)
158 "A helper function for mdw-uniquify-alist."
160 ;; --- There are several different cases to deal with here ---
164 ;; --- Current list isn't empty ---
166 ;; Add the first item to the DONE list if there's not an item with the
167 ;; same KEY already there.
169 (l (or (assoc (car (car l)) done)
171 (setcdr end (cons (car l) nil))
172 (setq end (cdr end))))
173 (mdw-do-uniquify done end (cdr l) rest))
175 ;; --- The list we were working on is empty ---
177 ;; Shunt the next list into the current list position and go round again.
179 (rest (mdw-do-uniquify done end (car rest) (cdr rest)))
181 ;; --- Everything's done ---
183 ;; Remove the leading `nil' from the DONE list and return it. Finished!
187 ;; --- Insert a date ---
190 "Insert the current date in a pleasing way."
192 (insert (save-excursion
193 (let ((buffer (get-buffer-create "*tmp*")))
194 (unwind-protect (progn (set-buffer buffer)
196 (shell-command "date +%Y-%m-%d" t)
198 (delete-backward-char 1)
200 (kill-buffer buffer))))))
202 ;; --- UUencoding ---
204 (defun uuencode (file &optional name)
205 "UUencodes a file, maybe calling it NAME, into the current buffer."
206 (interactive "fInput file name: ")
208 ;; --- If NAME isn't specified, then guess from the filename ---
213 (or (string-match "[^/]*$" file) 0))))
215 (print (format "uuencode `%s' `%s'" file name))
217 ;; --- Now actually do the thing ---
219 (call-process "uuencode" file t nil name))
221 (defvar np-file "~/.np"
222 "*Where the `now-playing' file is.")
224 (defun np (&optional arg)
225 "Grabs a `now-playing' string."
229 (goto-char (point-max))
231 (insert-file np-file)))))
235 (require 'autorevert)
236 (defun mdw-check-autorevert ()
237 (if (and (buffer-file-name)
238 (tramp-tramp-file-p (buffer-file-name)))
239 (unless global-auto-revert-ignore-buffer
240 (setq global-auto-revert-ignore-buffer 'tramp))
241 (if (eq global-auto-revert-ignore-buffer 'tramp)
242 (setq global-auto-revert-ignore-buffer nil))))
243 (defadvice find-file (after mdw-autorevert activate)
244 (mdw-check-autorevert))
245 (defadvice write-file (after mdw-autorevert activate)
246 (mdw-check-autorevert)))
248 (defun mdwmail-mode ()
249 "Major mode for editing news and mail messages from external programs
250 Not much right now. Just support for doing MailCrypt stuff."
252 (kill-all-local-variables)
253 (use-local-map text-mode-map)
254 (setq local-abbrev-table text-mode-abbrev-table)
255 (setq major-mode 'mdwmail-mode)
256 (setq mode-name "[mdw] mail")
257 (make-local-variable 'paragraph-separate)
258 (make-local-variable 'paragraph-start)
259 (setq paragraph-start (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
261 (setq paragraph-separate (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|"
263 (run-hooks 'text-mode-hook 'mdwmail-mode-hook 'mail-setup-hook))
265 ;; --- How to encrypt in mdwmail ---
267 (defun mdwmail-mc-encrypt (&optional recip scm start end from sign)
269 (setq start (save-excursion
270 (goto-char (point-min))
271 (or (search-forward "\n\n" nil t) (point-min)))))
273 (setq end (point-max)))
274 (mc-encrypt-generic recip scm start end from sign))
276 ;; --- How to sign in mdwmail ---
278 (defun mdwmail-mc-sign (key scm start end uclr)
280 (setq start (save-excursion
281 (goto-char (point-min))
282 (or (search-forward "\n\n" nil t) (point-min)))))
284 (setq end (point-max)))
285 (mc-sign-generic key scm start end uclr))
287 ;; --- Some signature mangling ---
289 (defun mdwmail-mangle-signature ()
291 (goto-char (point-min))
292 (perform-replace "\n-- \n" "\n-- " nil nil nil)))
293 (add-hook 'mail-setup-hook 'mdwmail-mangle-signature)
295 ;;;----- URL viewing --------------------------------------------------------
297 (defun mdw-w3m-browse-url (url &optional new-session-p)
298 "Invoke w3m on the URL in its current window, or at least a different one.
299 If NEW-SESSION-P, start a new session."
300 (interactive "sURL: \nP")
302 (let ((window (selected-window)))
305 (select-window (or (and (not new-session-p)
306 (get-buffer-window "*w3m*"))
308 (if (one-window-p t) (split-window))
310 (w3m-browse-url url new-session-p))
311 (select-window window)))))
313 (defvar mdw-good-url-browsers
314 '((w3m . mdw-w3m-browse-url)
317 "List of good browsers for mdw-good-url-browsers; each item is a browser
318 function name, or a cons (CHECK . FUNC). A symbol FOO stands for (FOO
321 (defun mdw-good-url-browser ()
322 "Return a good URL browser. Trundle the list of such things, finding the
323 first item for which CHECK is fboundp, and returning the correponding FUNC."
324 (let ((bs mdw-good-url-browsers) b check func answer)
325 (while (and bs (not answer))
329 (setq check (car b) func (cdr b))
330 (setq check b func b))
335 ;;;----- Paragraph filling --------------------------------------------------
337 ;; --- Useful variables ---
339 (defvar mdw-fill-prefix nil
340 "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'. If there's
341 no fill prefix currently set (by the `fill-prefix' variable) and there's
342 a match from one of the regexps here, it gets used to set the fill-prefix
343 for the current operation.
345 The variable is a list of items of the form `REGEXP . PREFIX'; if the
346 REGEXP matches, the PREFIX is used to set the fill prefix. It in turn is
349 STRING -- insert a literal string
350 (match . N) -- insert the thing matched by bracketed subexpression N
351 (pad . N) -- a string of whitespace the same width as subexpression N
352 (expr . FORM) -- the result of evaluating FORM")
354 (make-variable-buffer-local 'mdw-fill-prefix)
356 (defvar mdw-hanging-indents
357 "\\(\\(\\([*o]\\|--\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)[ \t]+\\)?\\)"
358 "*Standard regular expression matching things which might be part of a
359 hanging indent. This is mainly useful in `auto-fill-mode'.")
361 ;; --- Setting things up ---
363 (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill))
365 ;; --- Utility functions ---
367 (defun mdw-tabify (s)
368 "Tabify the string S. This is a horrid hack."
373 (setq start (point-marker))
375 (setq end (point-marker))
377 (setq s (buffer-substring start (1- end)))
378 (delete-region start end)
379 (set-marker start nil)
383 (defun mdw-examine-fill-prefixes (l)
384 "Given a list of dynamic fill prefixes, pick one which matches context and
385 return the static fill prefix to use. Point must be at the start of a line,
386 and match data must be saved."
388 ((looking-at (car (car l)))
389 (mdw-tabify (apply (function concat)
390 (mapcar (function mdw-do-prefix-match)
392 (t (mdw-examine-fill-prefixes (cdr l)))))
394 (defun mdw-maybe-car (p)
395 "If P is a pair, return (car P), otherwise just return P."
396 (if (consp p) (car p) p))
398 (defun mdw-padding (s)
399 "Return a string the same width as S but made entirely from whitespace."
400 (let* ((l (length s)) (i 0) (n (make-string l ? )))
407 (defun mdw-do-prefix-match (m)
408 "Expand a dynamic prefix match element. See `mdw-fill-prefix' for
410 (cond ((not (consp m)) (format "%s" m))
411 ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m))))
412 ((eq (car m) 'pad) (mdw-padding (match-string
413 (mdw-maybe-car (cdr m)))))
414 ((eq (car m) 'eval) (eval (cdr m)))
417 (defun mdw-choose-dynamic-fill-prefix ()
418 "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'."
419 (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix)
420 ((not mdw-fill-prefix) fill-prefix)
424 (mdw-examine-fill-prefixes mdw-fill-prefix))))))
426 (defun do-auto-fill ()
427 "Handle auto-filling, working out a dynamic fill prefix in the case where
428 there isn't a sensible static one."
429 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
432 (defun mdw-fill-paragraph ()
433 "Fill paragraph, getting a dynamic fill prefix."
435 (let ((fill-prefix (mdw-choose-dynamic-fill-prefix)))
436 (fill-paragraph nil)))
438 (defun mdw-standard-fill-prefix (rx &optional mat)
439 "Set the dynamic fill prefix, handling standard hanging indents and stuff.
440 This is just a short-cut for setting the thing by hand, and by design it
441 doesn't cope with anything approximating a complicated case."
442 (setq mdw-fill-prefix
443 `((,(concat rx mdw-hanging-indents)
445 (pad . ,(or mat 2))))))
447 ;;;----- Other common declarations ------------------------------------------
449 (defun mdw-set-frame-transparency (&optional n)
451 (let* ((alist (frame-parameters))
452 (trans (assq 'transparency alist)))
454 (rplacd trans (not (if n (zerop n) (cdr trans))))
455 (setq trans (cons 'transparency (not (equal 0 n)))))
456 (modify-frame-parameters (selected-frame) (list trans))))
458 ;; --- Mouse wheel support ---
460 (defconst mdw-wheel-scroll-amount 15)
461 (defun mdw-wheel-up (click)
463 (mdw-wheel-scroll click (function scroll-down)))
464 (defun mdw-wheel-down (click)
466 (mdw-wheel-scroll click (function scroll-up)))
468 (defun mdw-wheel-scroll (click func)
469 (let ((win (selected-window)))
472 (select-window (posn-window (event-start click)))
474 (funcall func (/ (window-height) 2))))
475 (select-window win))))
477 ;; --- Going backwards ---
479 (defun other-window-backwards (arg)
481 (other-window (- arg)))
483 ;; --- Common mode settings ---
485 (defvar mdw-auto-indent t
486 "Whether to indent automatically after a newline.")
488 (defun mdw-misc-mode-config ()
490 (cond ((eq major-mode 'lisp-mode)
491 (local-set-key "\C-m" 'mdw-indent-newline-and-indent))
492 ((or (eq major-mode 'slime-repl-mode)
493 (eq major-mode 'asm-mode))
496 (local-set-key "\C-m" 'newline-and-indent))))
497 (local-set-key [C-return] 'newline)
498 (or (eq major-mode 'asm-mode)
499 (local-set-key [?\;] 'self-insert-command))
500 (local-set-key [?\#] 'self-insert-command)
501 (local-set-key [?\"] 'self-insert-command)
502 (setq comment-column 40)
504 (setq fill-column 77)
505 (setq show-trailing-whitespace t)
508 ;; --- Set up all sorts of faces ---
510 (defvar mdw-set-font nil)
512 (defvar mdw-punct-face 'mdw-punct-face "Face to use for punctuation")
513 (make-face 'mdw-punct-face)
514 (defvar mdw-number-face 'mdw-number-face "Face to use for numbers")
515 (make-face 'mdw-number-face)
517 ;;;----- General fontification ----------------------------------------------
519 (defun mdw-set-fonts (frame faces)
521 (let ((face (caar faces)))
522 (or (facep face) (make-face face))
523 (set-face-attribute face frame
529 :foreground 'unspecified
530 :background 'unspecified
531 :underline 'unspecified
532 :overline 'unspecified
533 :strike-through 'unspecified
535 :inverse-video 'unspecified
536 :stipple 'unspecified
538 :inherit 'unspecified)
539 (apply 'set-face-attribute face frame (cdar faces))
540 (setq faces (cdr faces)))))
542 (defun mdw-do-set-font (&optional frame)
544 (mdw-set-fonts (and (boundp 'frame) frame) `(
545 (default :foreground "white" :background "black"
546 ,@(cond ((eq window-system 'w32)
547 '(:family "courier new" :height 85))
548 ((eq window-system 'x)
549 '(:family "misc-fixed" :width semi-condensed))))
550 (modeline :foreground "blue" :background "yellow"
551 :box (:line-width 1 :style released-button))
552 (scroll-bar :foreground "black" :background "lightgrey")
553 (fringe :foreground "yellow" :background "grey30")
554 (show-paren-match-face :background "darkgreen")
555 (show-paren-mismatch-face :background "red")
556 (font-lock-warning-face :background "red" :weight bold)
557 (highlight :background "DarkSeaGreen4")
558 (holiday-face :background "red")
559 (calendar-today-face :foreground "yellow" :weight bold)
560 (comint-highlight-prompt :weight bold)
561 (comint-highlight-input)
562 (font-lock-builtin-face :weight bold)
563 (font-lock-type-face :weight bold)
564 (region :background "grey30")
565 (isearch :background "palevioletred2")
566 (mdw-punct-face :foreground ,(if window-system "burlywood2" "yellow"))
567 (mdw-number-face :foreground "yellow")
568 (font-lock-function-name-face :weight bold)
569 (font-lock-variable-name-face :slant italic)
570 (font-lock-comment-face
571 :foreground ,(if window-system "SeaGreen1" "green")
573 (font-lock-string-face :foreground ,(if window-system "SkyBlue1" "cyan"))
574 (font-lock-keyword-face :weight bold)
575 (font-lock-constant-face :weight bold)
576 (font-lock-reference-face :weight bold)
577 (woman-bold-face :weight bold)
578 (woman-italic-face :slant italic)
579 (diff-header-face :foreground "skyblue1")
580 (diff-index-face :weight bold)
581 (diff-file-header-face)
582 (diff-context-face :foreground "grey70")
583 (diff-added-face :foreground "white")
584 (diff-removed-face :foreground "white" :slant italic)
585 (whizzy-slice-face :background "grey10")
586 (whizzy-error-face :background "darkred")
587 (trailing-whitespace :background "red")
590 (defun mdw-set-font ()
593 (if (not mdw-set-font)
595 (setq mdw-set-font t)
596 (mdw-do-set-font nil)))))
598 ;;;----- C programming configuration ----------------------------------------
600 ;; --- Linux kernel hacking ---
602 (defvar linux-c-mode-hook)
604 (defun linux-c-mode ()
607 (setq major-mode 'linux-c-mode)
608 (setq mode-name "Linux C")
609 (run-hooks 'linux-c-mode-hook))
611 ;; --- Make C indentation nice ---
613 (defun mdw-c-style ()
614 (c-add-style "[mdw] C and C++ style"
615 '((c-basic-offset . 2)
616 (c-tab-always-indent . nil)
617 (comment-column . 40)
618 (c-class-key . "class")
619 (c-offsets-alist (substatement-open . 0)
626 (statement-case-intro . +)))
629 (defun mdw-fontify-c-and-c++ ()
631 ;; --- Fiddle with some syntax codes ---
633 (modify-syntax-entry ?_ "w")
634 (modify-syntax-entry ?* ". 23")
635 (modify-syntax-entry ?/ ". 124b")
636 (modify-syntax-entry ?\n "> b")
638 ;; --- Other stuff ---
641 (setq c-hanging-comment-ender-p nil)
642 (setq c-backslash-column 72)
643 (setq c-label-minimum-indentation 0)
644 (setq mdw-fill-prefix
645 `((,(concat "\\([ \t]*/?\\)"
647 "\\([A-Za-z]+:[ \t]*\\)?"
649 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
651 ;; --- Now define things to be fontified ---
653 (make-local-variable 'font-lock-keywords)
662 "bool" ;C++, C9X macro
668 "complex" ;C9X macro, C++ template type
673 "defined" ;C89 preprocessor
680 ;; "entry" ;K&R -- never used
685 "false" ;C++, C9X macro
692 "imaginary" ;C9X macro
693 "inline" ;C++, C9X, GCC
706 "reinterpret_cast" ;C++
719 "true" ;C++, C9X macro
732 "wchar_t" ;C++, C89 library type
739 "_Pragma" ;C9X preprocessor
754 (preprocessor-keywords
755 (make-regexp '("assert" "define" "elif" "else" "endif" "error"
756 "ident" "if" "ifdef" "ifndef" "import" "include"
757 "line" "pragma" "unassert" "undef" "warning")))
759 (make-regexp '("class" "defs" "encode" "end" "implementation"
760 "interface" "private" "protected" "protocol" "public"
763 (setq font-lock-keywords
767 ;; --- Fontify include files as strings ---
769 (list (concat "^[ \t]*\\#[ \t]*"
770 "\\(include\\|import\\)"
771 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
772 '(2 font-lock-string-face))
774 ;; --- Preprocessor directives are `references'? ---
776 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
777 preprocessor-keywords
778 "\\)\\>\\|[0-9]+\\|$\\)\\)")
779 '(1 font-lock-keyword-face))
781 ;; --- Handle the keywords defined above ---
783 (list (concat "@\\<\\(" objc-keywords "\\)\\>")
784 '(0 font-lock-keyword-face))
786 (list (concat "\\<\\(" c-keywords "\\)\\>")
787 '(0 font-lock-keyword-face))
789 ;; --- Handle numbers too ---
791 ;; This looks strange, I know. It corresponds to the
792 ;; preprocessor's idea of what a number looks like, rather than
793 ;; anything sensible.
795 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
796 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
797 '(0 mdw-number-face))
799 ;; --- And anything else is punctuation ---
801 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
802 '(0 mdw-punct-face))))))
804 ;;;----- AP calc mode -------------------------------------------------------
806 (defun apcalc-mode ()
809 (setq major-mode 'apcalc-mode)
810 (setq mode-name "AP Calc")
811 (run-hooks 'apcalc-mode-hook))
813 (defun mdw-fontify-apcalc ()
815 ;; --- Fiddle with some syntax codes ---
817 (modify-syntax-entry ?_ "w")
818 (modify-syntax-entry ?* ". 23")
819 (modify-syntax-entry ?/ ". 14")
821 ;; --- Other stuff ---
824 (setq c-hanging-comment-ender-p nil)
825 (setq c-backslash-column 72)
826 (setq comment-start "/* ")
827 (setq comment-end " */")
828 (setq mdw-fill-prefix
829 `((,(concat "\\([ \t]*/?\\)"
831 "\\([A-Za-z]+:[ \t]*\\)?"
833 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
835 ;; --- Now define things to be fontified ---
837 (make-local-variable 'font-lock-keywords)
839 (make-regexp '("break" "case" "cd" "continue" "define" "default"
840 "do" "else" "exit" "for" "global" "goto" "help" "if"
841 "local" "mat" "obj" "print" "quit" "read" "return"
842 "show" "static" "switch" "while" "write"))))
844 (setq font-lock-keywords
848 ;; --- Handle the keywords defined above ---
850 (list (concat "\\<\\(" c-keywords "\\)\\>")
851 '(0 font-lock-keyword-face))
853 ;; --- Handle numbers too ---
855 ;; This looks strange, I know. It corresponds to the
856 ;; preprocessor's idea of what a number looks like, rather than
857 ;; anything sensible.
859 (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)"
860 "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*")
861 '(0 mdw-number-face))
863 ;; --- And anything else is punctuation ---
865 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
866 '(0 mdw-punct-face))))))
868 ;;;----- Java programming configuration -------------------------------------
870 ;; --- Make indentation nice ---
872 (defun mdw-java-style ()
873 (c-add-style "[mdw] Java style"
874 '((c-basic-offset . 2)
875 (c-tab-always-indent . nil)
876 (c-offsets-alist (substatement-open . 0)
881 (statement-case-intro . +)))
884 ;; --- Declare Java fontification style ---
886 (defun mdw-fontify-java ()
888 ;; --- Other stuff ---
891 (modify-syntax-entry ?_ "w")
892 (setq c-hanging-comment-ender-p nil)
893 (setq c-backslash-column 72)
894 (setq comment-start "/* ")
895 (setq comment-end " */")
896 (setq mdw-fill-prefix
897 `((,(concat "\\([ \t]*/?\\)"
899 "\\([A-Za-z]+:[ \t]*\\)?"
901 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
903 ;; --- Now define things to be fontified ---
905 (make-local-variable 'font-lock-keywords)
907 (make-regexp '("abstract" "boolean" "break" "byte" "case" "catch"
908 "char" "class" "const" "continue" "default" "do"
909 "double" "else" "extends" "final" "finally" "float"
910 "for" "goto" "if" "implements" "import" "instanceof"
911 "int" "interface" "long" "native" "new" "package"
912 "private" "protected" "public" "return" "short"
913 "static" "super" "switch" "synchronized" "this"
914 "throw" "throws" "transient" "try" "void" "volatile"
917 "false" "null" "true"))))
919 (setq font-lock-keywords
923 ;; --- Handle the keywords defined above ---
925 (list (concat "\\<\\(" java-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 ;;;----- C# programming configuration ---------------------------------------
946 ;; --- Make indentation nice ---
948 (defun mdw-csharp-style ()
949 (c-add-style "[mdw] C# style"
950 '((c-basic-offset . 2)
951 (c-tab-always-indent . nil)
952 (c-offsets-alist (substatement-open . 0)
957 (statement-case-intro . +)))
960 ;; --- Declare C# fontification style ---
962 (defun mdw-fontify-csharp ()
964 ;; --- Other stuff ---
967 (modify-syntax-entry ?_ "w")
968 (setq c-hanging-comment-ender-p nil)
969 (setq c-backslash-column 72)
970 (setq comment-start "/* ")
971 (setq comment-end " */")
972 (setq mdw-fill-prefix
973 `((,(concat "\\([ \t]*/?\\)"
975 "\\([A-Za-z]+:[ \t]*\\)?"
977 (pad . 1) (match . 2) (pad . 3) (pad . 4))))
979 ;; --- Now define things to be fontified ---
981 (make-local-variable 'font-lock-keywords)
982 (let ((csharp-keywords
983 (make-regexp '("abstract" "as" "base" "bool" "break"
984 "byte" "case" "catch" "char" "checked"
985 "class" "const" "continue" "decimal" "default"
986 "delegate" "do" "double" "else" "enum"
987 "event" "explicit" "extern" "false" "finally"
988 "fixed" "float" "for" "foreach" "goto"
989 "if" "implicit" "in" "int" "interface"
990 "internal" "is" "lock" "long" "namespace"
991 "new" "null" "object" "operator" "out"
992 "override" "params" "private" "protected" "public"
993 "readonly" "ref" "return" "sbyte" "sealed"
994 "short" "sizeof" "stackalloc" "static" "string"
995 "struct" "switch" "this" "throw" "true"
996 "try" "typeof" "uint" "ulong" "unchecked"
997 "unsafe" "ushort" "using" "virtual" "void"
998 "volatile" "while" "yield"))))
1000 (setq font-lock-keywords
1004 ;; --- Handle the keywords defined above ---
1006 (list (concat "\\<\\(" csharp-keywords "\\)\\>")
1007 '(0 font-lock-keyword-face))
1009 ;; --- Handle numbers too ---
1011 ;; The following isn't quite right, but it's close enough.
1013 (list (concat "\\<\\("
1014 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1015 "[0-9]+\\(\\.[0-9]*\\|\\)"
1016 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1018 '(0 mdw-number-face))
1020 ;; --- And anything else is punctuation ---
1022 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1023 '(0 mdw-punct-face))))))
1025 (defun csharp-mode ()
1028 (setq major-mode 'csharp-mode)
1029 (setq mode-name "C#")
1030 (mdw-fontify-csharp)
1031 (run-hooks 'csharp-mode-hook))
1033 ;;;----- Awk programming configuration --------------------------------------
1035 ;; --- Make Awk indentation nice ---
1037 (defun mdw-awk-style ()
1038 (c-add-style "[mdw] Awk style"
1039 '((c-basic-offset . 2)
1040 (c-tab-always-indent . nil)
1041 (c-offsets-alist (substatement-open . 0)
1042 (statement-cont . 0)
1043 (statement-case-intro . +)))
1046 ;; --- Declare Awk fontification style ---
1048 (defun mdw-fontify-awk ()
1050 ;; --- Miscellaneous fiddling ---
1052 (modify-syntax-entry ?_ "w")
1054 (setq c-backslash-column 72)
1055 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1057 ;; --- Now define things to be fontified ---
1059 (make-local-variable 'font-lock-keywords)
1061 (make-regexp '("BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT"
1062 "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR"
1063 "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS"
1064 "RSTART" "RLENGTH" "RT" "SUBSEP"
1065 "atan2" "break" "close" "continue" "cos" "delete"
1066 "do" "else" "exit" "exp" "fflush" "file" "for" "func"
1067 "function" "gensub" "getline" "gsub" "if" "in"
1068 "index" "int" "length" "log" "match" "next" "rand"
1069 "return" "print" "printf" "sin" "split" "sprintf"
1070 "sqrt" "srand" "strftime" "sub" "substr" "system"
1071 "systime" "tolower" "toupper" "while"))))
1073 (setq font-lock-keywords
1077 ;; --- Handle the keywords defined above ---
1079 (list (concat "\\<\\(" c-keywords "\\)\\>")
1080 '(0 font-lock-keyword-face))
1082 ;; --- Handle numbers too ---
1084 ;; The following isn't quite right, but it's close enough.
1086 (list (concat "\\<\\("
1087 "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1088 "[0-9]+\\(\\.[0-9]*\\|\\)"
1089 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)"
1091 '(0 mdw-number-face))
1093 ;; --- And anything else is punctuation ---
1095 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1096 '(0 mdw-punct-face))))))
1098 ;;;----- Perl programming style ---------------------------------------------
1100 ;; --- Perl indentation style ---
1102 (setq cperl-tab-always-indent nil)
1104 (setq cperl-indent-level 2)
1105 (setq cperl-continued-statement-offset 2)
1106 (setq cperl-continued-brace-offset 0)
1107 (setq cperl-brace-offset -2)
1108 (setq cperl-brace-imaginary-offset 0)
1109 (setq cperl-label-offset 0)
1111 ;; --- Define perl fontification style ---
1113 (defun mdw-fontify-perl ()
1115 ;; --- Miscellaneous fiddling ---
1117 (modify-syntax-entry ?_ "w")
1118 (modify-syntax-entry ?$ "\\")
1119 (modify-syntax-entry ?$ "\\" font-lock-syntax-table)
1120 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1122 ;; --- Now define fontification things ---
1124 (make-local-variable 'font-lock-keywords)
1125 (let ((perl-keywords
1126 (make-regexp '("and" "cmp" "continue" "do" "else" "elsif" "eq"
1127 "for" "foreach" "ge" "gt" "goto" "if"
1128 "last" "le" "lt" "local" "my" "ne" "next" "or"
1129 "package" "redo" "require" "return" "sub"
1130 "undef" "unless" "until" "use" "while"))))
1132 (setq font-lock-keywords
1136 ;; --- Set up the keywords defined above ---
1138 (list (concat "\\<\\(" perl-keywords "\\)\\>")
1139 '(0 font-lock-keyword-face))
1141 ;; --- At least numbers are simpler than C ---
1143 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1144 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1145 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1146 '(0 mdw-number-face))
1148 ;; --- And anything else is punctuation ---
1150 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1151 '(0 mdw-punct-face))))))
1153 (defun perl-number-tests (&optional arg)
1154 "Assign consecutive numbers to lines containing `#t'. With ARG,
1155 strip numbers instead."
1158 (goto-char (point-min))
1159 (let ((i 0) (fmt (if arg "" " %4d")))
1160 (while (search-forward "#t" nil t)
1161 (delete-region (point) (line-end-position))
1163 (insert (format fmt i)))
1164 (goto-char (point-min))
1165 (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t)
1166 (replace-match (format "\\1%d" i))))))
1168 ;;;----- Python programming style -------------------------------------------
1170 ;; --- Define Python fontification style ---
1172 (trap (require 'pyrex-mode))
1173 (defun mdw-fontify-python ()
1175 ;; --- Miscellaneous fiddling ---
1177 (modify-syntax-entry ?_ "w")
1178 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1180 ;; --- Now define fontification things ---
1182 (make-local-variable 'font-lock-keywords)
1183 (let ((python-keywords
1184 (make-regexp '("and" "as" "assert" "break" "class" "continue" "def"
1185 "del" "elif" "else" "except" "exec" "finally" "for"
1186 "from" "global" "if" "import" "in" "is" "lambda"
1187 "not" "or" "pass" "print" "raise" "return" "try"
1189 (setq font-lock-keywords
1193 ;; --- Set up the keywords defined above ---
1195 (list (concat "\\<\\(" python-keywords "\\)\\>")
1196 '(0 font-lock-keyword-face))
1198 ;; --- At least numbers are simpler than C ---
1200 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1201 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1202 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)")
1203 '(0 mdw-number-face))
1205 ;; --- And anything else is punctuation ---
1207 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1208 '(0 mdw-punct-face))))))
1210 ;;;----- ARM assembler programming configuration ----------------------------
1212 ;; --- There doesn't appear to be an Emacs mode for this yet ---
1214 ;; Better do something about that, I suppose.
1216 (defvar arm-assembler-mode-map nil)
1217 (defvar arm-assembler-abbrev-table nil)
1218 (defvar arm-assembler-mode-syntax-table (make-syntax-table))
1220 (or arm-assembler-mode-map
1222 (setq arm-assembler-mode-map (make-sparse-keymap))
1223 (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline)
1224 (define-key arm-assembler-mode-map [C-return] 'newline)
1225 (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop)))
1227 (defun arm-assembler-mode ()
1228 "Major mode for ARM assembler programs"
1231 ;; --- Do standard major mode things ---
1233 (kill-all-local-variables)
1234 (use-local-map arm-assembler-mode-map)
1235 (setq local-abbrev-table arm-assembler-abbrev-table)
1236 (setq major-mode 'arm-assembler-mode)
1237 (setq mode-name "ARM assembler")
1239 ;; --- Set up syntax table ---
1241 (set-syntax-table arm-assembler-mode-syntax-table)
1242 (modify-syntax-entry ?; ; Nasty hack
1243 "<" arm-assembler-mode-syntax-table)
1244 (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table)
1245 (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table)
1247 (make-local-variable 'comment-start)
1248 (setq comment-start ";")
1249 (make-local-variable 'comment-end)
1250 (setq comment-end "")
1251 (make-local-variable 'comment-column)
1252 (setq comment-column 48)
1253 (make-local-variable 'comment-start-skip)
1254 (setq comment-start-skip ";+[ \t]*")
1256 ;; --- Play with indentation ---
1258 (make-local-variable 'indent-line-function)
1259 (setq indent-line-function 'indent-relative-maybe)
1261 ;; --- Set fill prefix ---
1263 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1265 ;; --- Fiddle with fontification ---
1267 (make-local-variable 'font-lock-keywords)
1268 (setq font-lock-keywords
1272 ;; --- Handle numbers too ---
1274 ;; The following isn't quite right, but it's close enough.
1278 "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)"
1280 '(0 mdw-number-face))
1282 ;; --- Do something about operators ---
1284 (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)"
1285 '(1 font-lock-keyword-face)
1286 '(2 font-lock-string-face))
1288 '(0 font-lock-keyword-face))
1290 ;; --- Do menemonics and directives ---
1292 (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)"
1293 '(1 font-lock-keyword-face))
1295 ;; --- And anything else is punctuation ---
1297 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1298 '(0 mdw-punct-face))))
1300 (run-hooks 'arm-assembler-mode-hook))
1302 ;;;----- Assembler mode -----------------------------------------------------
1304 (defun mdw-fontify-asm ()
1305 (modify-syntax-entry ?' "\"")
1306 (modify-syntax-entry ?. "w")
1307 (setf fill-prefix nil)
1308 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)"))
1310 ;;;----- TCL configuration --------------------------------------------------
1312 (defun mdw-fontify-tcl ()
1313 (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$))
1314 (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)")
1315 (make-local-variable 'font-lock-keywords)
1316 (setq font-lock-keywords
1319 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1320 "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1321 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1322 '(0 mdw-number-face))
1323 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1324 '(0 mdw-punct-face)))))
1326 ;;;----- REXX configuration -------------------------------------------------
1328 (defun mdw-rexx-electric-* ()
1333 (defun mdw-rexx-indent-newline-indent ()
1336 (if abbrev-mode (expand-abbrev))
1337 (newline-and-indent))
1339 (defun mdw-fontify-rexx ()
1341 ;; --- Various bits of fiddling ---
1343 (setq mdw-auto-indent nil)
1344 (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent)
1345 (local-set-key [?*] 'mdw-rexx-electric-*)
1346 (mapcar #'(lambda (ch) (modify-syntax-entry ch "w"))
1347 '(?. ?! ?? ?_ ?# ?@ ?$))
1348 (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)")
1350 ;; --- Set up keywords and things for fontification ---
1352 (make-local-variable 'font-lock-keywords-case-fold-search)
1353 (setq font-lock-keywords-case-fold-search t)
1355 (setq rexx-indent 2)
1356 (setq rexx-end-indent rexx-indent)
1357 (setq rexx-tab-always-indent nil)
1358 (setq rexx-cont-indent rexx-indent)
1360 (make-local-variable 'font-lock-keywords)
1361 (let ((rexx-keywords
1362 (make-regexp '("address" "arg" "by" "call" "digits" "do" "drop"
1363 "else" "end" "engineering" "exit" "expose" "for"
1364 "forever" "form" "fuzz" "if" "interpret" "iterate"
1365 "leave" "linein" "name" "nop" "numeric" "off" "on"
1366 "options" "otherwise" "parse" "procedure" "pull"
1367 "push" "queue" "return" "say" "select" "signal"
1368 "scientific" "source" "then" "trace" "to" "until"
1369 "upper" "value" "var" "version" "when" "while"
1372 "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x"
1373 "center" "center" "charin" "charout" "chars"
1374 "compare" "condition" "copies" "c2d" "c2x"
1375 "datatype" "date" "delstr" "delword" "d2c" "d2x"
1376 "errortext" "format" "fuzz" "insert" "lastpos"
1377 "left" "length" "lineout" "lines" "max" "min"
1378 "overlay" "pos" "queued" "random" "reverse" "right"
1379 "sign" "sourceline" "space" "stream" "strip"
1380 "substr" "subword" "symbol" "time" "translate"
1381 "trunc" "value" "verify" "word" "wordindex"
1382 "wordlength" "wordpos" "words" "xrange" "x2b" "x2c"
1385 (setq font-lock-keywords
1389 ;; --- Set up the keywords defined above ---
1391 (list (concat "\\<\\(" rexx-keywords "\\)\\>")
1392 '(0 font-lock-keyword-face))
1394 ;; --- Fontify all symbols the same way ---
1396 (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|"
1397 "[A-Za-z0-9.!?_#@$]+\\)")
1398 '(0 font-lock-variable-name-face))
1400 ;; --- And everything else is punctuation ---
1402 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1403 '(0 mdw-punct-face))))))
1405 ;;;----- Standard ML programming style --------------------------------------
1407 (defun mdw-fontify-sml ()
1409 ;; --- Make underscore an honorary letter ---
1411 (modify-syntax-entry ?_ "w")
1412 (modify-syntax-entry ?' "w")
1414 ;; --- Set fill prefix ---
1416 (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)")
1418 ;; --- Now define fontification things ---
1420 (make-local-variable 'font-lock-keywords)
1422 (make-regexp '("abstype" "and" "andalso" "as"
1425 "else" "end" "eqtype" "exception"
1426 "fn" "fun" "functor"
1428 "if" "in" "include" "infix" "infixr"
1431 "of" "op" "open" "orelse"
1433 "sharing" "sig" "signature" "struct" "structure"
1436 "where" "while" "with" "withtype"))))
1438 (setq font-lock-keywords
1442 ;; --- Set up the keywords defined above ---
1444 (list (concat "\\<\\(" sml-keywords "\\)\\>")
1445 '(0 font-lock-keyword-face))
1447 ;; --- At least numbers are simpler than C ---
1449 (list (concat "\\<\\(\\~\\|\\)"
1450 "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|"
1452 "\\([0-9]+\\(\\.[0-9]+\\|\\)"
1453 "\\([eE]\\(\\~\\|\\)"
1454 "[0-9]+\\|\\)\\)\\)")
1455 '(0 mdw-number-face))
1457 ;; --- And anything else is punctuation ---
1459 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1460 '(0 mdw-punct-face))))))
1462 ;;;----- Haskell configuration ----------------------------------------------
1464 (defun mdw-fontify-haskell ()
1466 ;; --- Fiddle with syntax table to get comments right ---
1468 (modify-syntax-entry ?_ "w")
1469 (modify-syntax-entry ?' "\"")
1470 (modify-syntax-entry ?- ". 123")
1471 (modify-syntax-entry ?{ ". 1b")
1472 (modify-syntax-entry ?} ". 4b")
1473 (modify-syntax-entry ?\n ">")
1475 ;; --- Set fill prefix ---
1477 (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)")
1479 ;; --- Fiddle with fontification ---
1481 (make-local-variable 'font-lock-keywords)
1482 (let ((haskell-keywords
1483 (make-regexp '("as" "case" "ccall" "class" "data" "default"
1484 "deriving" "do" "else" "foreign" "hiding" "if"
1485 "import" "in" "infix" "infixl" "infixr" "instance"
1486 "let" "module" "newtype" "of" "qualified" "safe"
1487 "stdcall" "then" "type" "unsafe" "where"))))
1489 (setq font-lock-keywords
1493 '(0 font-lock-comment-face))
1494 (list (concat "\\<\\(" haskell-keywords "\\)\\>")
1495 '(0 font-lock-keyword-face))
1496 (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|"
1497 "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)"
1498 "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)")
1499 '(0 mdw-number-face))
1500 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1501 '(0 mdw-punct-face))))))
1503 ;;;----- Texinfo configuration ----------------------------------------------
1505 (defun mdw-fontify-texinfo ()
1507 ;; --- Set fill prefix ---
1509 (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)")
1511 ;; --- Real fontification things ---
1513 (make-local-variable 'font-lock-keywords)
1514 (setq font-lock-keywords
1518 ;; --- Environment names are keywords ---
1520 (list "@\\(end\\) *\\([a-zA-Z]*\\)?"
1521 '(2 font-lock-keyword-face))
1523 ;; --- Unmark escaped magic characters ---
1525 (list "\\(@\\)\\([@{}]\\)"
1526 '(1 font-lock-keyword-face)
1527 '(2 font-lock-variable-name-face))
1529 ;; --- Make sure we get comments properly ---
1531 (list "@c\\(\\|omment\\)\\( .*\\)?$"
1532 '(0 font-lock-comment-face))
1534 ;; --- Command names are keywords ---
1536 (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1537 '(0 font-lock-keyword-face))
1539 ;; --- Fontify TeX special characters as punctuation ---
1542 '(0 mdw-punct-face)))))
1544 ;;;----- TeX and LaTeX configuration ----------------------------------------
1546 (defun mdw-fontify-tex ()
1547 (setq ispell-parser 'tex)
1549 ;; --- Don't make maths into a string ---
1551 (modify-syntax-entry ?$ ".")
1552 (modify-syntax-entry ?$ "." font-lock-syntax-table)
1553 (local-set-key [?$] 'self-insert-command)
1555 ;; --- Set fill prefix ---
1557 (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)")
1559 ;; --- Real fontification things ---
1561 (make-local-variable 'font-lock-keywords)
1562 (setq font-lock-keywords
1566 ;; --- Environment names are keywords ---
1568 (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)"
1570 '(2 font-lock-keyword-face))
1572 ;; --- Suspended environment names are keywords too ---
1574 (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?"
1576 '(3 font-lock-keyword-face))
1578 ;; --- Command names are keywords ---
1580 (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)"
1581 '(0 font-lock-keyword-face))
1583 ;; --- Handle @/.../ for italics ---
1585 ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)"
1586 ;; '(1 font-lock-keyword-face)
1587 ;; '(3 font-lock-keyword-face))
1589 ;; --- Handle @*...* for boldness ---
1591 ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)"
1592 ;; '(1 font-lock-keyword-face)
1593 ;; '(3 font-lock-keyword-face))
1595 ;; --- Handle @`...' for literal syntax things ---
1597 ;; (list "\\(@`\\)\\([^']*\\)\\('\\)"
1598 ;; '(1 font-lock-keyword-face)
1599 ;; '(3 font-lock-keyword-face))
1601 ;; --- Handle @<...> for nonterminals ---
1603 ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)"
1604 ;; '(1 font-lock-keyword-face)
1605 ;; '(3 font-lock-keyword-face))
1607 ;; --- Handle other @-commands ---
1609 ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)"
1610 ;; '(0 font-lock-keyword-face))
1612 ;; --- Make sure we get comments properly ---
1615 '(0 font-lock-comment-face))
1617 ;; --- Fontify TeX special characters as punctuation ---
1620 '(0 mdw-punct-face)))))
1622 ;;;----- Shell scripts ------------------------------------------------------
1624 (defun mdw-setup-sh-script-mode ()
1626 ;; --- Fetch the shell interpreter's name ---
1628 (let ((shell-name sh-shell-file))
1630 ;; --- Try reading the hash-bang line ---
1633 (goto-char (point-min))
1634 (if (looking-at "#![ \t]*\\([^ \t\n]*\\)")
1635 (setq shell-name (match-string 1))))
1637 ;; --- Now try to set the shell ---
1639 ;; Don't let `sh-set-shell' bugger up my script.
1641 (let ((executable-set-magic #'(lambda (s &rest r) s)))
1642 (sh-set-shell shell-name)))
1644 ;; --- Now enable my keys and the fontification ---
1646 (mdw-misc-mode-config)
1648 ;; --- Set the indentation level correctly ---
1650 (setq sh-indentation 2)
1651 (setq sh-basic-offset 2))
1653 ;;;----- Messages-file mode -------------------------------------------------
1655 (defun message-mode-guts ()
1656 (setq messages-mode-syntax-table (make-syntax-table))
1657 (set-syntax-table messages-mode-syntax-table)
1658 (modify-syntax-entry ?_ "w" messages-mode-syntax-table)
1659 (modify-syntax-entry ?- "w" messages-mode-syntax-table)
1660 (modify-syntax-entry ?0 "w" messages-mode-syntax-table)
1661 (modify-syntax-entry ?1 "w" messages-mode-syntax-table)
1662 (modify-syntax-entry ?2 "w" messages-mode-syntax-table)
1663 (modify-syntax-entry ?3 "w" messages-mode-syntax-table)
1664 (modify-syntax-entry ?4 "w" messages-mode-syntax-table)
1665 (modify-syntax-entry ?5 "w" messages-mode-syntax-table)
1666 (modify-syntax-entry ?6 "w" messages-mode-syntax-table)
1667 (modify-syntax-entry ?7 "w" messages-mode-syntax-table)
1668 (modify-syntax-entry ?8 "w" messages-mode-syntax-table)
1669 (modify-syntax-entry ?9 "w" messages-mode-syntax-table)
1670 (make-local-variable 'comment-start)
1671 (make-local-variable 'comment-end)
1672 (make-local-variable 'indent-line-function)
1673 (setq indent-line-function 'indent-relative)
1674 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
1675 (make-local-variable 'font-lock-defaults)
1676 (make-local-variable 'message-mode-keywords)
1678 (make-regexp '("array" "bitmap" "callback" "docs[ \t]+enum"
1679 "export" "enum" "fixed-octetstring" "flags"
1680 "harmless" "map" "nested" "optional"
1681 "optional-tagged" "package" "primitive"
1682 "primitive-nullfree" "relaxed[ \t]+enum"
1683 "set" "table" "tagged-optional" "union"
1684 "variadic" "vector" "version" "version-tag"))))
1685 (setq message-mode-keywords
1687 (list (concat "\\<\\(" keywords "\\)\\>:")
1688 '(0 font-lock-keyword-face))
1689 '("\\([-a-zA-Z0-9]+:\\)" (0 font-lock-warning-face))
1690 '("\\(\\<[a-z][-_a-zA-Z0-9]*\\)"
1691 (0 font-lock-variable-name-face))
1692 '("\\<\\([0-9]+\\)\\>" (0 mdw-number-face))
1693 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1694 (0 mdw-punct-face)))))
1695 (setq font-lock-defaults
1696 '(message-mode-keywords nil nil nil nil))
1697 (run-hooks 'messages-file-hook))
1699 (defun messages-mode ()
1702 (setq major-mode 'messages-mode)
1703 (setq mode-name "Messages")
1705 (modify-syntax-entry ?# "<" messages-mode-syntax-table)
1706 (modify-syntax-entry ?\n ">" messages-mode-syntax-table)
1707 (setq comment-start "# ")
1708 (setq comment-end "")
1709 (turn-on-font-lock-if-enabled)
1710 (run-hooks 'messages-mode-hook))
1712 (defun cpp-messages-mode ()
1715 (setq major-mode 'cpp-messages-mode)
1716 (setq mode-name "CPP Messages")
1718 (modify-syntax-entry ?* ". 23" messages-mode-syntax-table)
1719 (modify-syntax-entry ?/ ". 14" messages-mode-syntax-table)
1720 (setq comment-start "/* ")
1721 (setq comment-end " */")
1722 (let ((preprocessor-keywords
1723 (make-regexp '("assert" "define" "elif" "else" "endif" "error"
1724 "ident" "if" "ifdef" "ifndef" "import" "include"
1725 "line" "pragma" "unassert" "undef" "warning"))))
1726 (setq message-mode-keywords
1727 (append (list (list (concat "^[ \t]*\\#[ \t]*"
1728 "\\(include\\|import\\)"
1729 "[ \t]*\\(<[^>]+\\(>\\|\\)\\)")
1730 '(2 font-lock-string-face))
1731 (list (concat "^\\([ \t]*#[ \t]*\\(\\("
1732 preprocessor-keywords
1733 "\\)\\>\\|[0-9]+\\|$\\)\\)")
1734 '(1 font-lock-keyword-face)))
1735 message-mode-keywords)))
1736 (turn-on-font-lock-if-enabled)
1737 (run-hooks 'cpp-messages-mode-hook))
1739 (add-hook 'messages-mode-hook 'mdw-misc-mode-config t)
1740 (add-hook 'cpp-messages-mode-hook 'mdw-misc-mode-config t)
1741 ; (add-hook 'messages-file-hook 'mdw-fontify-messages t)
1743 ;;;----- Messages-file mode -------------------------------------------------
1745 (defvar mallow-driver-substitution-face 'mallow-driver-substitution-face
1746 "Face to use for subsittution directives.")
1747 (make-face 'mallow-driver-substitution-face)
1748 (defvar mallow-driver-text-face 'mallow-driver-text-face
1749 "Face to use for body text.")
1750 (make-face 'mallow-driver-text-face)
1752 (defun mallow-driver-mode ()
1755 (setq major-mode 'mallow-driver-mode)
1756 (setq mode-name "Mallow driver")
1757 (setq mallow-driver-mode-syntax-table (make-syntax-table))
1758 (set-syntax-table mallow-driver-mode-syntax-table)
1759 (make-local-variable 'comment-start)
1760 (make-local-variable 'comment-end)
1761 (make-local-variable 'indent-line-function)
1762 (setq indent-line-function 'indent-relative)
1763 (mdw-standard-fill-prefix "\\([ \t]*\\(;\\|/?\\*\\)+[ \t]*\\)")
1764 (make-local-variable 'font-lock-defaults)
1765 (make-local-variable 'mallow-driver-mode-keywords)
1767 (make-regexp '("each" "divert" "file" "if"
1768 "perl" "set" "string" "type" "write"))))
1769 (setq mallow-driver-mode-keywords
1771 (list (concat "^%\\s *\\(}\\|\\(" keywords "\\)\\>\\).*$")
1772 '(0 font-lock-keyword-face))
1773 (list "^%\\s *\\(#.*\\|\\)$"
1774 '(0 font-lock-comment-face))
1776 '(0 font-lock-keyword-face))
1777 (list "^|?\\(.+\\)$" '(1 mallow-driver-text-face))
1779 '(0 mallow-driver-substitution-face t)))))
1780 (setq font-lock-defaults
1781 '(mallow-driver-mode-keywords nil nil nil nil))
1782 (modify-syntax-entry ?\" "_" mallow-driver-mode-syntax-table)
1783 (modify-syntax-entry ?\n ">" mallow-driver-mode-syntax-table)
1784 (setq comment-start "%# ")
1785 (setq comment-end "")
1786 (turn-on-font-lock-if-enabled)
1787 (run-hooks 'mallow-driver-mode-hook))
1789 (add-hook 'mallow-driver-hook 'mdw-misc-mode-config t)
1791 ;;;----- NFast debugs -------------------------------------------------------
1793 (defun nfast-debug-mode ()
1796 (setq major-mode 'nfast-debug-mode)
1797 (setq mode-name "NFast debug")
1798 (setq messages-mode-syntax-table (make-syntax-table))
1799 (set-syntax-table messages-mode-syntax-table)
1800 (make-local-variable 'font-lock-defaults)
1801 (make-local-variable 'nfast-debug-mode-keywords)
1802 (setq truncate-lines t)
1803 (setq nfast-debug-mode-keywords
1805 '("^\\(NFast_\\(Connect\\|Disconnect\\|Submit\\|Wait\\)\\)"
1806 (0 font-lock-keyword-face))
1807 (list (concat "^[ \t]+\\(\\("
1808 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
1809 "[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]"
1811 "[0-9a-fA-F]+\\)[ \t]*$")
1812 '(0 mdw-number-face))
1813 '("^[ \t]+\.status=[ \t]+\\<\\(OK\\)\\>"
1814 (1 font-lock-keyword-face))
1815 '("^[ \t]+\.status=[ \t]+\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>"
1816 (1 font-lock-warning-face))
1817 '("^[ \t]+\.status[ \t]+\\<\\(zero\\)\\>"
1819 (list (concat "^[ \t]+\\.cmd=[ \t]+"
1820 "\\<\\([a-zA-Z][0-9a-zA-Z]*\\)\\>")
1821 '(1 font-lock-keyword-face))
1822 '("-?\\<\\([0-9]+\\|0x[0-9a-fA-F]+\\)\\>" (0 mdw-number-face))
1823 '("^\\([ \t]+[a-z0-9.]+\\)" (0 font-lock-variable-name-face))
1824 '("\\<\\([a-z][a-z0-9.]+\\)\\>=" (1 font-lock-variable-name-face))
1825 '("\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" (0 mdw-punct-face))))
1826 (setq font-lock-defaults
1827 '(nfast-debug-mode-keywords nil nil nil nil))
1828 (turn-on-font-lock-if-enabled)
1829 (run-hooks 'nfast-debug-mode-hook))
1831 ;;;----- Other languages ----------------------------------------------------
1833 ;; --- Smalltalk ---
1835 (defun mdw-setup-smalltalk ()
1836 (and mdw-auto-indent
1837 (local-set-key "\C-m" 'smalltalk-newline-and-indent))
1838 (make-variable-buffer-local 'mdw-auto-indent)
1839 (setq mdw-auto-indent nil)
1840 (local-set-key "\C-i" 'smalltalk-reindent))
1842 (defun mdw-fontify-smalltalk ()
1843 (make-local-variable 'font-lock-keywords)
1844 (setq font-lock-keywords
1847 (list "\\<[A-Z][a-zA-Z0-9]*\\>"
1848 '(0 font-lock-keyword-face))
1849 (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|"
1850 "[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)"
1851 "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)")
1852 '(0 mdw-number-face))
1853 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1854 '(0 mdw-punct-face)))))
1856 ;; --- Lispy languages ---
1858 (defun mdw-indent-newline-and-indent ()
1860 (indent-for-tab-command)
1861 (newline-and-indent))
1863 (eval-after-load "cl-indent"
1865 (mapc #'(lambda (pair)
1867 'common-lisp-indent-function
1869 '((destructuring-bind . ((&whole 4 &rest 1) 4 &body))
1870 (multiple-value-bind . ((&whole 4 &rest 1) 4 &body))))))
1872 (defun mdw-common-lisp-indent ()
1873 (make-variable-buffer-local 'lisp-indent-function)
1874 (setq lisp-indent-function 'common-lisp-indent-function))
1876 (defun mdw-fontify-lispy ()
1878 ;; --- Set fill prefix ---
1880 (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")
1882 ;; --- Not much fontification needed ---
1884 (make-local-variable 'font-lock-keywords)
1885 (setq font-lock-keywords
1888 (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)"
1889 '(0 mdw-punct-face)))))
1891 (defun comint-send-and-indent ()
1894 (and mdw-auto-indent
1895 (indent-for-tab-command)))
1897 ;;;----- Text mode ----------------------------------------------------------
1899 (defun mdw-text-mode ()
1900 (setq fill-column 72)
1902 (mdw-standard-fill-prefix
1903 "\\([ \t]*\\([A-Za-z0-9]*[>#|:] ?\\)*[ \t]*\\)" 3)
1906 ;;;----- Shell mode ---------------------------------------------------------
1908 (defun mdw-sh-mode-setup ()
1909 (local-set-key [?\C-a] 'comint-bol)
1910 (add-hook 'comint-output-filter-functions
1911 'comint-watch-for-password-prompt))
1913 (defun mdw-term-mode-setup ()
1914 (setq term-prompt-regexp "^[^]#$%>»}\n]*[]#$%>»}] *")
1915 (make-local-variable 'mouse-yank-at-point)
1916 (make-local-variable 'transient-mark-mode)
1917 (setq mouse-yank-at-point t)
1918 (setq transient-mark-mode nil)
1922 ;;;----- That's all, folks --------------------------------------------------
1924 (provide 'dot-emacs)