;;; -*- mode: emacs-lisp; coding: utf-8 -*- ;;; ;;; Functions and macros for .emacs ;;; ;;; (c) 2004 Mark Wooding ;;; ;;;----- Licensing notice --------------------------------------------------- ;;; ;;; This program is free software; you can redistribute it and/or modify ;;; it under the terms of the GNU General Public License as published by ;;; the Free Software Foundation; either version 2 of the License, or ;;; (at your option) any later version. ;;; ;;; This program is distributed in the hope that it will be useful, ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;;; GNU General Public License for more details. ;;; ;;; You should have received a copy of the GNU General Public License ;;; along with this program; if not, write to the Free Software Foundation, ;;; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ;;;----- Check command-line ------------------------------------------------- (defvar mdw-fast-startup nil "Whether .emacs should optimize for rapid startup. This may be at the expense of cool features.") (let ((probe nil) (next command-line-args)) (while next (cond ((string= (car next) "--mdw-fast-startup") (setq mdw-fast-startup t) (if probe (rplacd probe (cdr next)) (setq command-line-args (cdr next)))) (t (setq probe next))) (setq next (cdr next)))) ;;;----- Some general utilities --------------------------------------------- (eval-when-compile (unless (fboundp 'make-regexp) (load "make-regexp")) (require 'cl)) (defmacro mdw-regexps (&rest list) "Turn a LIST of strings into a single regular expression at compile-time." `',(make-regexp list)) ;; --- Some error trapping --- ;; ;; If individual bits of this file go tits-up, we don't particularly want ;; the whole lot to stop right there and then, because it's bloody annoying. (defmacro trap (&rest forms) "Execute FORMS without allowing errors to propagate outside." `(condition-case err ,(if (cdr forms) (cons 'progn forms) (car forms)) (error (message "Error (trapped): %s in %s" (error-message-string err) ',forms)))) ;; --- Configuration reading --- (defvar mdw-config nil) (defun mdw-config (sym) "Read the configuration variable named SYM." (unless mdw-config (setq mdw-config (flet ((replace (what with) (goto-char (point-min)) (while (re-search-forward what nil t) (replace-match with t)))) (with-temp-buffer (insert-file-contents "~/.mdw.conf") (replace "^[ \t]*\\(#.*\\|\\)\n" "") (replace (concat "^[ \t]*" "\\([-a-zA-Z0-9_.]*\\)" "[ \t]*=[ \t]*" "\\(.*[^ \t\n]\\|\\)" "[ \t]**\\(\n\\|$\\)") "(\\1 . \"\\2\")\n") (car (read-from-string (concat "(" (buffer-string) ")"))))))) (cdr (assq sym mdw-config))) ;; --- Is an Emacs library available? --- (defun library-exists-p (name) "Return non-nil if NAME.el (or NAME.elc) is somewhere on the Emacs load path. The non-nil value is the filename we found for the library." (let ((path load-path) elt (foundp nil)) (while (and path (not foundp)) (setq elt (car path)) (setq path (cdr path)) (setq foundp (or (let ((file (concat elt "/" name ".elc"))) (and (file-exists-p file) file)) (let ((file (concat elt "/" name ".el"))) (and (file-exists-p file) file))))) foundp)) (defun maybe-autoload (symbol file &optional docstring interactivep type) "Set an autoload if the file actually exists." (and (library-exists-p file) (autoload symbol file docstring interactivep type))) ;; --- Splitting windows --- (unless (fboundp 'scroll-bar-columns) (defun scroll-bar-columns (side) (cond ((eq side 'left) 0) (window-system 3) (t 1)))) (unless (fboundp 'fringe-columns) (defun fringe-columns (side) (cond ((not window-system) 0) ((eq side 'left) 1) (t 2)))) (defun mdw-divvy-window (&optional width) "Split a wide window into appropriate widths." (interactive "P") (setq width (cond (width (prefix-numeric-value width)) ((and window-system (>= emacs-major-version 22)) 77) (t 78))) (let* ((win (selected-window)) (sb-width (if (not window-system) 1 (let ((tot 0)) (dolist (what '(scroll-bar fringe)) (dolist (side '(left right)) (incf tot (funcall (intern (concat (symbol-name what) "-columns")) side)))) tot))) (c (/ (+ (window-width) sb-width) (+ width sb-width)))) (while (> c 1) (setq c (1- c)) (split-window-horizontally (+ width sb-width)) (other-window 1)) (select-window win))) ;; --- Functions for sexp diary entries --- (defun mdw-weekday (l) "Return non-nil if `date' falls on one of the days of the week in L. L is a list of day numbers (from 0 to 6 for Sunday through to Saturday) or symbols `sunday', `monday', etc. (or a mixture). If the date stored in `date' falls on a listed day, then the function returns non-nil." (let ((d (calendar-day-of-week date))) (or (memq d l) (memq (nth d '(sunday monday tuesday wednesday thursday friday saturday)) l)))) (defun mdw-todo (&optional when) "Return non-nil today, or on WHEN, whichever is later." (let ((w (calendar-absolute-from-gregorian (calendar-current-date))) (d (calendar-absolute-from-gregorian date))) (if when (setq w (max w (calendar-absolute-from-gregorian (cond ((not european-calendar-style) when) ((> (car when) 100) (list (nth 1 when) (nth 2 when) (nth 0 when))) (t (list (nth 1 when) (nth 0 when) (nth 2 when)))))))) (eq w d))) ;;;----- Utility functions -------------------------------------------------- (or (fboundp 'line-number-at-pos) (defun line-number-at-pos (&optional pos) (let ((opoint (or pos (point))) start) (save-excursion (save-restriction (goto-char (point-min)) (widen) (forward-line 0) (setq start (point)) (goto-char opoint) (forward-line 0) (1+ (count-lines 1 (point)))))))) ;; --- mdw-uniquify-alist --- (defun mdw-uniquify-alist (&rest alists) "Return the concatenation of the ALISTS with duplicate elements removed. The first association with a given key prevails; others are ignored. The input lists are not modified, although they'll probably become garbage." (and alists (let ((start-list (cons nil nil))) (mdw-do-uniquify start-list start-list (car alists) (cdr alists))))) ;; --- mdw-do-uniquify --- ;; ;; The DONE argument is a list whose first element is `nil'. It contains the ;; uniquified alist built so far. The leading `nil' is stripped off at the ;; end of the operation; it's only there so that DONE always references a ;; cons cell. END refers to the final cons cell in the DONE list; it is ;; modified in place each time to avoid the overheads of `append'ing all the ;; time. The L argument is the alist we're currently processing; the ;; remaining alists are given in REST. (defun mdw-do-uniquify (done end l rest) "A helper function for mdw-uniquify-alist." ;; --- There are several different cases to deal with here --- (cond ;; --- Current list isn't empty --- ;; ;; Add the first item to the DONE list if there's not an item with the ;; same KEY already there. (l (or (assoc (car (car l)) done) (progn (setcdr end (cons (car l) nil)) (setq end (cdr end)))) (mdw-do-uniquify done end (cdr l) rest)) ;; --- The list we were working on is empty --- ;; ;; Shunt the next list into the current list position and go round again. (rest (mdw-do-uniquify done end (car rest) (cdr rest))) ;; --- Everything's done --- ;; ;; Remove the leading `nil' from the DONE list and return it. Finished! (t (cdr done)))) ;; --- Insert a date --- (defun date () "Insert the current date in a pleasing way." (interactive) (insert (save-excursion (let ((buffer (get-buffer-create "*tmp*"))) (unwind-protect (progn (set-buffer buffer) (erase-buffer) (shell-command "date +%Y-%m-%d" t) (goto-char (mark)) (delete-backward-char 1) (buffer-string)) (kill-buffer buffer)))))) ;; --- UUencoding --- (defun uuencode (file &optional name) "UUencodes a file, maybe calling it NAME, into the current buffer." (interactive "fInput file name: ") ;; --- If NAME isn't specified, then guess from the filename --- (if (not name) (setq name (substring file (or (string-match "[^/]*$" file) 0)))) (print (format "uuencode `%s' `%s'" file name)) ;; --- Now actually do the thing --- (call-process "uuencode" file t nil name)) (defvar np-file "~/.np" "*Where the `now-playing' file is.") (defun np (&optional arg) "Grabs a `now-playing' string." (interactive) (save-excursion (or arg (progn (goto-char (point-max)) (insert "\nNP: ") (insert-file-contents np-file))))) (defun mdw-check-autorevert () "Sets global-auto-revert-ignore-buffer appropriately for this buffer, taking into consideration whether it's been found using tramp, which seems to get itself into a twist." (cond ((not (boundp 'global-auto-revert-ignore-buffer)) nil) ((and (buffer-file-name) (fboundp 'tramp-tramp-file-p) (tramp-tramp-file-p (buffer-file-name))) (unless global-auto-revert-ignore-buffer (setq global-auto-revert-ignore-buffer 'tramp))) ((eq global-auto-revert-ignore-buffer 'tramp) (setq global-auto-revert-ignore-buffer nil)))) (defadvice find-file (after mdw-autorevert activate) (mdw-check-autorevert)) (defadvice write-file (after mdw-autorevert activate) (mdw-check-autorevert)) (defun mdwmail-mode () "Major mode for editing news and mail messages from external programs Not much right now. Just support for doing MailCrypt stuff." (interactive) (kill-all-local-variables) (use-local-map text-mode-map) (setq local-abbrev-table text-mode-abbrev-table) (setq major-mode 'mdwmail-mode) (setq mode-name "[mdw] mail") (set-buffer-file-coding-system 'utf-8) (make-local-variable 'paragraph-separate) (make-local-variable 'paragraph-start) (setq paragraph-start (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|" paragraph-start)) (setq paragraph-separate (concat "[ \t]*[-_][-_][-_]+$\\|^-- \\|-----\\|" paragraph-separate)) (run-hooks 'text-mode-hook 'mdwmail-mode-hook 'mail-setup-hook)) ;; --- How to encrypt in mdwmail --- (defun mdwmail-mc-encrypt (&optional recip scm start end from sign) (or start (setq start (save-excursion (goto-char (point-min)) (or (search-forward "\n\n" nil t) (point-min))))) (or end (setq end (point-max))) (mc-encrypt-generic recip scm start end from sign)) ;; --- How to sign in mdwmail --- (defun mdwmail-mc-sign (key scm start end uclr) (or start (setq start (save-excursion (goto-char (point-min)) (or (search-forward "\n\n" nil t) (point-min))))) (or end (setq end (point-max))) (mc-sign-generic key scm start end uclr)) ;; --- Some signature mangling --- (defun mdwmail-mangle-signature () (save-excursion (goto-char (point-min)) (perform-replace "\n-- \n" "\n-- " nil nil nil))) (add-hook 'mail-setup-hook 'mdwmail-mangle-signature) ;;;----- Dired hacking ------------------------------------------------------ (defadvice dired-maybe-insert-subdir (around mdw-marked-insertion first activate) "The DIRNAME may be a list of directory names to insert. Interactively, if files are marked, then insert all of them. With a numeric prefix argument, select that many entries near point; with a non-numeric prefix argument, prompt for listing options." (interactive (list (dired-get-marked-files nil (and (integerp current-prefix-arg) current-prefix-arg) #'file-directory-p) (and current-prefix-arg (not (integerp current-prefix-arg)) (read-string "Switches for listing: " (or dired-subdir-switches dired-actual-switches))))) (let ((dirs (ad-get-arg 0))) (dolist (dir (if (listp dirs) dirs (list dirs))) (ad-set-arg 0 dir) ad-do-it))) ;;;----- URL viewing -------------------------------------------------------- (defun mdw-w3m-browse-url (url &optional new-session-p) "Invoke w3m on the URL in its current window, or at least a different one. If NEW-SESSION-P, start a new session." (interactive "sURL: \nP") (save-excursion (let ((window (selected-window))) (unwind-protect (progn (select-window (or (and (not new-session-p) (get-buffer-window "*w3m*")) (progn (if (one-window-p t) (split-window)) (get-lru-window)))) (w3m-browse-url url new-session-p)) (select-window window))))) (defvar mdw-good-url-browsers '((w3m . mdw-w3m-browse-url) browse-url-w3 browse-url-mozilla) "List of good browsers for mdw-good-url-browsers; each item is a browser function name, or a cons (CHECK . FUNC). A symbol FOO stands for (FOO . FOO).") (defun mdw-good-url-browser () "Return a good URL browser. Trundle the list of such things, finding the first item for which CHECK is fboundp, and returning the correponding FUNC." (let ((bs mdw-good-url-browsers) b check func answer) (while (and bs (not answer)) (setq b (car bs) bs (cdr bs)) (if (consp b) (setq check (car b) func (cdr b)) (setq check b func b)) (if (fboundp check) (setq answer func))) answer)) ;;;----- Paragraph filling -------------------------------------------------- ;; --- Useful variables --- (defvar mdw-fill-prefix nil "*Used by `mdw-line-prefix' and `mdw-fill-paragraph'. If there's no fill prefix currently set (by the `fill-prefix' variable) and there's a match from one of the regexps here, it gets used to set the fill-prefix for the current operation. The variable is a list of items of the form `REGEXP . PREFIX'; if the REGEXP matches, the PREFIX is used to set the fill prefix. It in turn is a list of things: STRING -- insert a literal string (match . N) -- insert the thing matched by bracketed subexpression N (pad . N) -- a string of whitespace the same width as subexpression N (expr . FORM) -- the result of evaluating FORM") (make-variable-buffer-local 'mdw-fill-prefix) (defvar mdw-hanging-indents (concat "\\(\\(" "\\([*o]\\|-[-#]?\\|[0-9]+\\.\\|\\[[0-9]+\\]\\|([a-zA-Z])\\)" "[ \t]+" "\\)?\\)") "*Standard regular expression matching things which might be part of a hanging indent. This is mainly useful in `auto-fill-mode'.") ;; --- Setting things up --- (fset 'mdw-do-auto-fill (symbol-function 'do-auto-fill)) ;; --- Utility functions --- (defun mdw-tabify (s) "Tabify the string S. This is a horrid hack." (save-excursion (save-match-data (let (start end) (beginning-of-line) (setq start (point-marker)) (insert s "\n") (setq end (point-marker)) (tabify start end) (setq s (buffer-substring start (1- end))) (delete-region start end) (set-marker start nil) (set-marker end nil) s)))) (defun mdw-examine-fill-prefixes (l) "Given a list of dynamic fill prefixes, pick one which matches context and return the static fill prefix to use. Point must be at the start of a line, and match data must be saved." (cond ((not l) nil) ((looking-at (car (car l))) (mdw-tabify (apply (function concat) (mapcar (function mdw-do-prefix-match) (cdr (car l)))))) (t (mdw-examine-fill-prefixes (cdr l))))) (defun mdw-maybe-car (p) "If P is a pair, return (car P), otherwise just return P." (if (consp p) (car p) p)) (defun mdw-padding (s) "Return a string the same width as S but made entirely from whitespace." (let* ((l (length s)) (i 0) (n (make-string l ? ))) (while (< i l) (if (= 9 (aref s i)) (aset n i 9)) (setq i (1+ i))) n)) (defun mdw-do-prefix-match (m) "Expand a dynamic prefix match element. See `mdw-fill-prefix' for details." (cond ((not (consp m)) (format "%s" m)) ((eq (car m) 'match) (match-string (mdw-maybe-car (cdr m)))) ((eq (car m) 'pad) (mdw-padding (match-string (mdw-maybe-car (cdr m))))) ((eq (car m) 'eval) (eval (cdr m))) (t ""))) (defun mdw-choose-dynamic-fill-prefix () "Work out the dynamic fill prefix based on the variable `mdw-fill-prefix'." (cond ((and fill-prefix (not (string= fill-prefix ""))) fill-prefix) ((not mdw-fill-prefix) fill-prefix) (t (save-excursion (beginning-of-line) (save-match-data (mdw-examine-fill-prefixes mdw-fill-prefix)))))) (defun do-auto-fill () "Handle auto-filling, working out a dynamic fill prefix in the case where there isn't a sensible static one." (let ((fill-prefix (mdw-choose-dynamic-fill-prefix))) (mdw-do-auto-fill))) (defun mdw-fill-paragraph () "Fill paragraph, getting a dynamic fill prefix." (interactive) (let ((fill-prefix (mdw-choose-dynamic-fill-prefix))) (fill-paragraph nil))) (defun mdw-standard-fill-prefix (rx &optional mat) "Set the dynamic fill prefix, handling standard hanging indents and stuff. This is just a short-cut for setting the thing by hand, and by design it doesn't cope with anything approximating a complicated case." (setq mdw-fill-prefix `((,(concat rx mdw-hanging-indents) (match . 1) (pad . ,(or mat 2)))))) ;;;----- Other common declarations ------------------------------------------ ;; --- Common mode settings --- (defvar mdw-auto-indent t "Whether to indent automatically after a newline.") (defun mdw-misc-mode-config () (and mdw-auto-indent (cond ((eq major-mode 'lisp-mode) (local-set-key "\C-m" 'mdw-indent-newline-and-indent)) ((or (eq major-mode 'slime-repl-mode) (eq major-mode 'asm-mode)) nil) (t (local-set-key "\C-m" 'newline-and-indent)))) (local-set-key [C-return] 'newline) (or (eq major-mode 'asm-mode) (local-set-key [?\;] 'self-insert-command)) (local-set-key [?\#] 'self-insert-command) (local-set-key [?\"] 'self-insert-command) (setq comment-column 40) (auto-fill-mode 1) (setq fill-column 77) (setq show-trailing-whitespace t) (mdw-set-font)) ;; --- Set up all sorts of faces --- (defvar mdw-set-font nil) (defvar mdw-punct-face 'mdw-punct-face "Face to use for punctuation") (make-face 'mdw-punct-face) (defvar mdw-number-face 'mdw-number-face "Face to use for numbers") (make-face 'mdw-number-face) ;; --- Backup file handling --- (defvar mdw-backup-disable-regexps nil "*List of regular expressions: if a file name matches any of these then the file is not backed up.") (defun mdw-backup-enable-predicate (name) "[mdw]'s default backup predicate: allows a backup if the standard predicate would allow it, and it doesn't match any of the regular expressions in `mdw-backup-disable-regexps'." (and (normal-backup-enable-predicate name) (let ((answer t) (list mdw-backup-disable-regexps)) (save-match-data (while list (if (string-match (car list) name) (setq answer nil)) (setq list (cdr list))) answer)))) (setq backup-enable-predicate 'mdw-backup-enable-predicate) ;;;----- General fontification ---------------------------------------------- (defun mdw-set-fonts (frame faces) (while faces (let ((face (caar faces))) (or (facep face) (make-face face)) (set-face-attribute face frame :family 'unspecified :width 'unspecified :height 'unspecified :weight 'unspecified :slant 'unspecified :foreground 'unspecified :background 'unspecified :underline 'unspecified :overline 'unspecified :strike-through 'unspecified :box 'unspecified :inverse-video 'unspecified :stipple 'unspecified ;:font 'unspecified :inherit 'unspecified) (apply 'set-face-attribute face frame (cdar faces)) (setq faces (cdr faces))))) (defun mdw-do-set-font (&optional frame) (interactive) (mdw-set-fonts (and (boundp 'frame) frame) `( (default :foreground "white" :background "black" ,@(cond ((eq window-system 'w32) '(:family "courier new" :height 85)) ((eq window-system 'x) '(:family "misc-fixed" :height 130 :width semi-condensed)))) (fixed-pitch) (minibuffer-prompt) (mode-line :foreground "blue" :background "yellow" :box (:line-width 1 :style released-button)) (mode-line-inactive :foreground "yellow" :background "blue" :box (:line-width 1 :style released-button)) (scroll-bar :foreground "black" :background "lightgrey") (fringe :foreground "yellow" :background "black") (show-paren-match-face :background "darkgreen") (show-paren-mismatch-face :background "red") (font-lock-warning-face :background "red" :weight bold) (highlight :background "DarkSeaGreen4") (holiday-face :background "red") (calendar-today-face :foreground "yellow" :weight bold) (comint-highlight-prompt :weight bold) (comint-highlight-input) (font-lock-builtin-face :weight bold) (font-lock-type-face :weight bold) (region :background "grey30") (isearch :background "palevioletred2") (mdw-punct-face :foreground ,(if window-system "burlywood2" "yellow")) (mdw-number-face :foreground "yellow") (font-lock-function-name-face :weight bold) (font-lock-variable-name-face :slant italic) (font-lock-comment-delimiter-face :foreground ,(if window-system "SeaGreen1" "green") :slant italic) (font-lock-comment-face :foreground ,(if window-system "SeaGreen1" "green") :slant italic) (font-lock-string-face :foreground ,(if window-system "SkyBlue1" "cyan")) (font-lock-keyword-face :weight bold) (font-lock-constant-face :weight bold) (font-lock-reference-face :weight bold) (woman-bold :weight bold) (woman-italic :slant italic) (diff-index :weight bold) (diff-file-header :weight bold) (diff-hunk-header :foreground "SkyBlue1") (diff-function :foreground "SkyBlue1" :weight bold) (diff-header :background "grey10") (diff-added :foreground "green") (diff-removed :foreground "red") (diff-context) (whizzy-slice-face :background "grey10") (whizzy-error-face :background "darkred") (trailing-whitespace :background "red") ))) (defun mdw-set-font () (trap (turn-on-font-lock) (if (not mdw-set-font) (progn (setq mdw-set-font t) (mdw-do-set-font nil))))) ;;;----- C programming configuration ---------------------------------------- ;; --- Linux kernel hacking --- (defvar linux-c-mode-hook) (defun linux-c-mode () (interactive) (c-mode) (setq major-mode 'linux-c-mode) (setq mode-name "Linux C") (run-hooks 'linux-c-mode-hook)) ;; --- Make C indentation nice --- (defun mdw-c-style () (c-add-style "[mdw] C and C++ style" '((c-basic-offset . 2) (comment-column . 40) (c-class-key . "class") (c-offsets-alist (substatement-open . 0) (label . 0) (case-label . +) (access-label . -) (inclass . +) (inline-open . ++) (statement-cont . 0) (statement-case-intro . +))) t)) (defun mdw-fontify-c-and-c++ () ;; --- Fiddle with some syntax codes --- (modify-syntax-entry ?_ "w") (modify-syntax-entry ?* ". 23") (modify-syntax-entry ?/ ". 124b") (modify-syntax-entry ?\n "> b") ;; --- Other stuff --- (mdw-c-style) (setq c-hanging-comment-ender-p nil) (setq c-backslash-column 72) (setq c-label-minimum-indentation 0) (setq mdw-fill-prefix `((,(concat "\\([ \t]*/?\\)" "\\([\*/][ \t]*\\)" "\\([A-Za-z]+:[ \t]*\\)?" mdw-hanging-indents) (pad . 1) (match . 2) (pad . 3) (pad . 4)))) ;; --- Now define things to be fontified --- (make-local-variable 'font-lock-keywords) (let ((c-keywords (mdw-regexps "and" ;C++ "and_eq" ;C++ "asm" ;K&R, GCC "auto" ;K&R, C89 "bitand" ;C++ "bitor" ;C++ "bool" ;C++, C9X macro "break" ;K&R, C89 "case" ;K&R, C89 "catch" ;C++ "char" ;K&R, C89 "class" ;C++ "complex" ;C9X macro, C++ template type "compl" ;C++ "const" ;C89 "const_cast" ;C++ "continue" ;K&R, C89 "defined" ;C89 preprocessor "default" ;K&R, C89 "delete" ;C++ "do" ;K&R, C89 "double" ;K&R, C89 "dynamic_cast" ;C++ "else" ;K&R, C89 ;; "entry" ;K&R -- never used "enum" ;C89 "explicit" ;C++ "export" ;C++ "extern" ;K&R, C89 "false" ;C++, C9X macro "float" ;K&R, C89 "for" ;K&R, C89 ;; "fortran" ;K&R "friend" ;C++ "goto" ;K&R, C89 "if" ;K&R, C89 "imaginary" ;C9X macro "inline" ;C++, C9X, GCC "int" ;K&R, C89 "long" ;K&R, C89 "mutable" ;C++ "namespace" ;C++ "new" ;C++ "operator" ;C++ "or" ;C++ "or_eq" ;C++ "private" ;C++ "protected" ;C++ "public" ;C++ "register" ;K&R, C89 "reinterpret_cast" ;C++ "restrict" ;C9X "return" ;K&R, C89 "short" ;K&R, C89 "signed" ;C89 "sizeof" ;K&R, C89 "static" ;K&R, C89 "static_cast" ;C++ "struct" ;K&R, C89 "switch" ;K&R, C89 "template" ;C++ "this" ;C++ "throw" ;C++ "true" ;C++, C9X macro "try" ;C++ "this" ;C++ "typedef" ;C89 "typeid" ;C++ "typeof" ;GCC "typename" ;C++ "union" ;K&R, C89 "unsigned" ;K&R, C89 "using" ;C++ "virtual" ;C++ "void" ;C89 "volatile" ;C89 "wchar_t" ;C++, C89 library type "while" ;K&R, C89 "xor" ;C++ "xor_eq" ;C++ "_Bool" ;C9X "_Complex" ;C9X "_Imaginary" ;C9X "_Pragma" ;C9X preprocessor "__alignof__" ;GCC "__asm__" ;GCC "__attribute__" ;GCC "__complex__" ;GCC "__const__" ;GCC "__extension__" ;GCC "__imag__" ;GCC "__inline__" ;GCC "__label__" ;GCC "__real__" ;GCC "__signed__" ;GCC "__typeof__" ;GCC "__volatile__" ;GCC )) (preprocessor-keywords (mdw-regexps "assert" "define" "elif" "else" "endif" "error" "ident" "if" "ifdef" "ifndef" "import" "include" "line" "pragma" "unassert" "undef" "warning")) (objc-keywords (mdw-regexps "class" "defs" "encode" "end" "implementation" "interface" "private" "protected" "protocol" "public" "selector"))) (setq font-lock-keywords (list ;; --- Fontify include files as strings --- (list (concat "^[ \t]*\\#[ \t]*" "\\(include\\|import\\)" "[ \t]*\\(<[^>]+\\(>\\|\\)\\)") '(2 font-lock-string-face)) ;; --- Preprocessor directives are `references'? --- (list (concat "^\\([ \t]*#[ \t]*\\(\\(" preprocessor-keywords "\\)\\>\\|[0-9]+\\|$\\)\\)") '(1 font-lock-keyword-face)) ;; --- Handle the keywords defined above --- (list (concat "@\\<\\(" objc-keywords "\\)\\>") '(0 font-lock-keyword-face)) (list (concat "\\<\\(" c-keywords "\\)\\>") '(0 font-lock-keyword-face)) ;; --- Handle numbers too --- ;; ;; This looks strange, I know. It corresponds to the ;; preprocessor's idea of what a number looks like, rather than ;; anything sensible. (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)" "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*") '(0 mdw-number-face)) ;; --- And anything else is punctuation --- (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" '(0 mdw-punct-face)))))) ;;;----- AP calc mode ------------------------------------------------------- (defun apcalc-mode () (interactive) (c-mode) (setq major-mode 'apcalc-mode) (setq mode-name "AP Calc") (run-hooks 'apcalc-mode-hook)) (defun mdw-fontify-apcalc () ;; --- Fiddle with some syntax codes --- (modify-syntax-entry ?_ "w") (modify-syntax-entry ?* ". 23") (modify-syntax-entry ?/ ". 14") ;; --- Other stuff --- (mdw-c-style) (setq c-hanging-comment-ender-p nil) (setq c-backslash-column 72) (setq comment-start "/* ") (setq comment-end " */") (setq mdw-fill-prefix `((,(concat "\\([ \t]*/?\\)" "\\([\*/][ \t]*\\)" "\\([A-Za-z]+:[ \t]*\\)?" mdw-hanging-indents) (pad . 1) (match . 2) (pad . 3) (pad . 4)))) ;; --- Now define things to be fontified --- (make-local-variable 'font-lock-keywords) (let ((c-keywords (mdw-regexps "break" "case" "cd" "continue" "define" "default" "do" "else" "exit" "for" "global" "goto" "help" "if" "local" "mat" "obj" "print" "quit" "read" "return" "show" "static" "switch" "while" "write"))) (setq font-lock-keywords (list ;; --- Handle the keywords defined above --- (list (concat "\\<\\(" c-keywords "\\)\\>") '(0 font-lock-keyword-face)) ;; --- Handle numbers too --- ;; ;; This looks strange, I know. It corresponds to the ;; preprocessor's idea of what a number looks like, rather than ;; anything sensible. (list (concat "\\(\\<[0-9]\\|\\.[0-9]\\)" "\\([Ee][+-]\\|[0-9A-Za-z_.]\\)*") '(0 mdw-number-face)) ;; --- And anything else is punctuation --- (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" '(0 mdw-punct-face)))))) ;;;----- Java programming configuration ------------------------------------- ;; --- Make indentation nice --- (defun mdw-java-style () (c-add-style "[mdw] Java style" '((c-basic-offset . 2) (c-offsets-alist (substatement-open . 0) (label . +) (case-label . +) (access-label . 0) (inclass . +) (statement-case-intro . +))) t)) ;; --- Declare Java fontification style --- (defun mdw-fontify-java () ;; --- Other stuff --- (mdw-java-style) (modify-syntax-entry ?_ "w") (setq c-hanging-comment-ender-p nil) (setq c-backslash-column 72) (setq comment-start "/* ") (setq comment-end " */") (setq mdw-fill-prefix `((,(concat "\\([ \t]*/?\\)" "\\([\*/][ \t]*\\)" "\\([A-Za-z]+:[ \t]*\\)?" mdw-hanging-indents) (pad . 1) (match . 2) (pad . 3) (pad . 4)))) ;; --- Now define things to be fontified --- (make-local-variable 'font-lock-keywords) (let ((java-keywords (mdw-regexps "abstract" "boolean" "break" "byte" "case" "catch" "char" "class" "const" "continue" "default" "do" "double" "else" "extends" "final" "finally" "float" "for" "goto" "if" "implements" "import" "instanceof" "int" "interface" "long" "native" "new" "package" "private" "protected" "public" "return" "short" "static" "super" "switch" "synchronized" "this" "throw" "throws" "transient" "try" "void" "volatile" "while" "false" "null" "true"))) (setq font-lock-keywords (list ;; --- Handle the keywords defined above --- (list (concat "\\<\\(" java-keywords "\\)\\>") '(0 font-lock-keyword-face)) ;; --- Handle numbers too --- ;; ;; The following isn't quite right, but it's close enough. (list (concat "\\<\\(" "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" "[0-9]+\\(\\.[0-9]*\\|\\)" "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" "[lLfFdD]?") '(0 mdw-number-face)) ;; --- And anything else is punctuation --- (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" '(0 mdw-punct-face)))))) ;;;----- C# programming configuration --------------------------------------- ;; --- Make indentation nice --- (defun mdw-csharp-style () (c-add-style "[mdw] C# style" '((c-basic-offset . 2) (c-offsets-alist (substatement-open . 0) (label . 0) (case-label . +) (access-label . 0) (inclass . +) (statement-case-intro . +))) t)) ;; --- Declare C# fontification style --- (defun mdw-fontify-csharp () ;; --- Other stuff --- (mdw-csharp-style) (modify-syntax-entry ?_ "w") (setq c-hanging-comment-ender-p nil) (setq c-backslash-column 72) (setq comment-start "/* ") (setq comment-end " */") (setq mdw-fill-prefix `((,(concat "\\([ \t]*/?\\)" "\\([\*/][ \t]*\\)" "\\([A-Za-z]+:[ \t]*\\)?" mdw-hanging-indents) (pad . 1) (match . 2) (pad . 3) (pad . 4)))) ;; --- Now define things to be fontified --- (make-local-variable 'font-lock-keywords) (let ((csharp-keywords (mdw-regexps "abstract" "as" "base" "bool" "break" "byte" "case" "catch" "char" "checked" "class" "const" "continue" "decimal" "default" "delegate" "do" "double" "else" "enum" "event" "explicit" "extern" "false" "finally" "fixed" "float" "for" "foreach" "goto" "if" "implicit" "in" "int" "interface" "internal" "is" "lock" "long" "namespace" "new" "null" "object" "operator" "out" "override" "params" "private" "protected" "public" "readonly" "ref" "return" "sbyte" "sealed" "short" "sizeof" "stackalloc" "static" "string" "struct" "switch" "this" "throw" "true" "try" "typeof" "uint" "ulong" "unchecked" "unsafe" "ushort" "using" "virtual" "void" "volatile" "while" "yield"))) (setq font-lock-keywords (list ;; --- Handle the keywords defined above --- (list (concat "\\<\\(" csharp-keywords "\\)\\>") '(0 font-lock-keyword-face)) ;; --- Handle numbers too --- ;; ;; The following isn't quite right, but it's close enough. (list (concat "\\<\\(" "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" "[0-9]+\\(\\.[0-9]*\\|\\)" "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" "[lLfFdD]?") '(0 mdw-number-face)) ;; --- And anything else is punctuation --- (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" '(0 mdw-punct-face)))))) (defun csharp-mode () (interactive) (java-mode) (setq major-mode 'csharp-mode) (setq mode-name "C#") (mdw-fontify-csharp) (run-hooks 'csharp-mode-hook)) ;;;----- Awk programming configuration -------------------------------------- ;; --- Make Awk indentation nice --- (defun mdw-awk-style () (c-add-style "[mdw] Awk style" '((c-basic-offset . 2) (c-offsets-alist (substatement-open . 0) (statement-cont . 0) (statement-case-intro . +))) t)) ;; --- Declare Awk fontification style --- (defun mdw-fontify-awk () ;; --- Miscellaneous fiddling --- (modify-syntax-entry ?_ "w") (mdw-awk-style) (setq c-backslash-column 72) (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") ;; --- Now define things to be fontified --- (make-local-variable 'font-lock-keywords) (let ((c-keywords (mdw-regexps "BEGIN" "END" "ARGC" "ARGIND" "ARGV" "CONVFMT" "ENVIRON" "ERRNO" "FIELDWIDTHS" "FILENAME" "FNR" "FS" "IGNORECASE" "NF" "NR" "OFMT" "OFS" "ORS" "RS" "RSTART" "RLENGTH" "RT" "SUBSEP" "atan2" "break" "close" "continue" "cos" "delete" "do" "else" "exit" "exp" "fflush" "file" "for" "func" "function" "gensub" "getline" "gsub" "if" "in" "index" "int" "length" "log" "match" "next" "rand" "return" "print" "printf" "sin" "split" "sprintf" "sqrt" "srand" "strftime" "sub" "substr" "system" "systime" "tolower" "toupper" "while"))) (setq font-lock-keywords (list ;; --- Handle the keywords defined above --- (list (concat "\\<\\(" c-keywords "\\)\\>") '(0 font-lock-keyword-face)) ;; --- Handle numbers too --- ;; ;; The following isn't quite right, but it's close enough. (list (concat "\\<\\(" "0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" "[0-9]+\\(\\.[0-9]*\\|\\)" "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)\\)" "[uUlL]*") '(0 mdw-number-face)) ;; --- And anything else is punctuation --- (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" '(0 mdw-punct-face)))))) ;;;----- Perl programming style --------------------------------------------- ;; --- Perl indentation style --- (setq cperl-indent-level 2) (setq cperl-continued-statement-offset 2) (setq cperl-continued-brace-offset 0) (setq cperl-brace-offset -2) (setq cperl-brace-imaginary-offset 0) (setq cperl-label-offset 0) ;; --- Define perl fontification style --- (defun mdw-fontify-perl () ;; --- Miscellaneous fiddling --- (modify-syntax-entry ?_ "w") (modify-syntax-entry ?$ "\\") (modify-syntax-entry ?$ "\\" font-lock-syntax-table) (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") ;; --- Now define fontification things --- (make-local-variable 'font-lock-keywords) (let ((perl-keywords (mdw-regexps "and" "cmp" "continue" "do" "else" "elsif" "eq" "for" "foreach" "ge" "gt" "goto" "if" "last" "le" "lt" "local" "my" "ne" "next" "or" "package" "redo" "require" "return" "sub" "undef" "unless" "until" "use" "while"))) (setq font-lock-keywords (list ;; --- Set up the keywords defined above --- (list (concat "\\<\\(" perl-keywords "\\)\\>") '(0 font-lock-keyword-face)) ;; --- At least numbers are simpler than C --- (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") '(0 mdw-number-face)) ;; --- And anything else is punctuation --- (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" '(0 mdw-punct-face)))))) (defun perl-number-tests (&optional arg) "Assign consecutive numbers to lines containing `#t'. With ARG, strip numbers instead." (interactive "P") (save-excursion (goto-char (point-min)) (let ((i 0) (fmt (if arg "" " %4d"))) (while (search-forward "#t" nil t) (delete-region (point) (line-end-position)) (setq i (1+ i)) (insert (format fmt i))) (goto-char (point-min)) (if (re-search-forward "\\(tests\\s-*=>\\s-*\\)\\w*" nil t) (replace-match (format "\\1%d" i)))))) ;;;----- Python programming style ------------------------------------------- ;; --- Define Python fontification style --- (defun mdw-fontify-python () ;; --- Miscellaneous fiddling --- (modify-syntax-entry ?_ "w") (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") ;; --- Now define fontification things --- (make-local-variable 'font-lock-keywords) (let ((python-keywords (mdw-regexps "and" "as" "assert" "break" "class" "continue" "def" "del" "elif" "else" "except" "exec" "finally" "for" "from" "global" "if" "import" "in" "is" "lambda" "not" "or" "pass" "print" "raise" "return" "try" "while" "with" "yield"))) (setq font-lock-keywords (list ;; --- Set up the keywords defined above --- (list (concat "\\<\\(" python-keywords "\\)\\>") '(0 font-lock-keyword-face)) ;; --- At least numbers are simpler than C --- (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" "\\([eE]\\([-+]\\|\\)[0-9_]+\\|[lL]\\|\\)") '(0 mdw-number-face)) ;; --- And anything else is punctuation --- (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" '(0 mdw-punct-face)))))) ;;;----- ARM assembler programming configuration ---------------------------- ;; --- There doesn't appear to be an Emacs mode for this yet --- ;; ;; Better do something about that, I suppose. (defvar arm-assembler-mode-map nil) (defvar arm-assembler-abbrev-table nil) (defvar arm-assembler-mode-syntax-table (make-syntax-table)) (or arm-assembler-mode-map (progn (setq arm-assembler-mode-map (make-sparse-keymap)) (define-key arm-assembler-mode-map "\C-m" 'arm-assembler-newline) (define-key arm-assembler-mode-map [C-return] 'newline) (define-key arm-assembler-mode-map "\t" 'tab-to-tab-stop))) (defun arm-assembler-mode () "Major mode for ARM assembler programs" (interactive) ;; --- Do standard major mode things --- (kill-all-local-variables) (use-local-map arm-assembler-mode-map) (setq local-abbrev-table arm-assembler-abbrev-table) (setq major-mode 'arm-assembler-mode) (setq mode-name "ARM assembler") ;; --- Set up syntax table --- (set-syntax-table arm-assembler-mode-syntax-table) (modify-syntax-entry ?; ; Nasty hack "<" arm-assembler-mode-syntax-table) (modify-syntax-entry ?\n ">" arm-assembler-mode-syntax-table) (modify-syntax-entry ?_ "_" arm-assembler-mode-syntax-table) (make-local-variable 'comment-start) (setq comment-start ";") (make-local-variable 'comment-end) (setq comment-end "") (make-local-variable 'comment-column) (setq comment-column 48) (make-local-variable 'comment-start-skip) (setq comment-start-skip ";+[ \t]*") ;; --- Play with indentation --- (make-local-variable 'indent-line-function) (setq indent-line-function 'indent-relative-maybe) ;; --- Set fill prefix --- (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)") ;; --- Fiddle with fontification --- (make-local-variable 'font-lock-keywords) (setq font-lock-keywords (list ;; --- Handle numbers too --- ;; ;; The following isn't quite right, but it's close enough. (list (concat "\\(" "&[0-9a-fA-F]+\\|" "\\<[0-9]+\\(\\.[0-9]*\\|_[0-9a-zA-Z]+\\|\\)" "\\)") '(0 mdw-number-face)) ;; --- Do something about operators --- (list "^[^ \t]*[ \t]+\\(GET\\|LNK\\)[ \t]+\\([^;\n]*\\)" '(1 font-lock-keyword-face) '(2 font-lock-string-face)) (list ":[a-zA-Z]+:" '(0 font-lock-keyword-face)) ;; --- Do menemonics and directives --- (list "^[^ \t]*[ \t]+\\([a-zA-Z]+\\)" '(1 font-lock-keyword-face)) ;; --- And anything else is punctuation --- (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" '(0 mdw-punct-face)))) (run-hooks 'arm-assembler-mode-hook)) ;;;----- Assembler mode ----------------------------------------------------- (defun mdw-fontify-asm () (modify-syntax-entry ?' "\"") (modify-syntax-entry ?. "w") (setf fill-prefix nil) (mdw-standard-fill-prefix "\\([ \t]*;+[ \t]*\\)")) ;;;----- TCL configuration -------------------------------------------------- (defun mdw-fontify-tcl () (mapcar #'(lambda (ch) (modify-syntax-entry ch ".")) '(?$)) (mdw-standard-fill-prefix "\\([ \t]*#+[ \t]*\\)") (make-local-variable 'font-lock-keywords) (setq font-lock-keywords (list (list (concat "\\<0\\([xX][0-9a-fA-F_]+\\|[0-7_]+\\)\\|" "\\<[0-9][0-9_]*\\(\\.[0-9_]*\\|\\)" "\\([eE]\\([-+]\\|\\)[0-9_]+\\|\\)") '(0 mdw-number-face)) (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" '(0 mdw-punct-face))))) ;;;----- REXX configuration ------------------------------------------------- (defun mdw-rexx-electric-* () (interactive) (insert ?*) (rexx-indent-line)) (defun mdw-rexx-indent-newline-indent () (interactive) (rexx-indent-line) (if abbrev-mode (expand-abbrev)) (newline-and-indent)) (defun mdw-fontify-rexx () ;; --- Various bits of fiddling --- (setq mdw-auto-indent nil) (local-set-key [?\C-m] 'mdw-rexx-indent-newline-indent) (local-set-key [?*] 'mdw-rexx-electric-*) (mapcar #'(lambda (ch) (modify-syntax-entry ch "w")) '(?. ?! ?? ?_ ?# ?@ ?$)) (mdw-standard-fill-prefix "\\([ \t]*/?\*[ \t]*\\)") ;; --- Set up keywords and things for fontification --- (make-local-variable 'font-lock-keywords-case-fold-search) (setq font-lock-keywords-case-fold-search t) (setq rexx-indent 2) (setq rexx-end-indent rexx-indent) (setq rexx-cont-indent rexx-indent) (make-local-variable 'font-lock-keywords) (let ((rexx-keywords (mdw-regexps "address" "arg" "by" "call" "digits" "do" "drop" "else" "end" "engineering" "exit" "expose" "for" "forever" "form" "fuzz" "if" "interpret" "iterate" "leave" "linein" "name" "nop" "numeric" "off" "on" "options" "otherwise" "parse" "procedure" "pull" "push" "queue" "return" "say" "select" "signal" "scientific" "source" "then" "trace" "to" "until" "upper" "value" "var" "version" "when" "while" "with" "abbrev" "abs" "bitand" "bitor" "bitxor" "b2x" "center" "center" "charin" "charout" "chars" "compare" "condition" "copies" "c2d" "c2x" "datatype" "date" "delstr" "delword" "d2c" "d2x" "errortext" "format" "fuzz" "insert" "lastpos" "left" "length" "lineout" "lines" "max" "min" "overlay" "pos" "queued" "random" "reverse" "right" "sign" "sourceline" "space" "stream" "strip" "substr" "subword" "symbol" "time" "translate" "trunc" "value" "verify" "word" "wordindex" "wordlength" "wordpos" "words" "xrange" "x2b" "x2c" "x2d"))) (setq font-lock-keywords (list ;; --- Set up the keywords defined above --- (list (concat "\\<\\(" rexx-keywords "\\)\\>") '(0 font-lock-keyword-face)) ;; --- Fontify all symbols the same way --- (list (concat "\\<\\([0-9.][A-Za-z0-9.!?_#@$]*[Ee][+-]?[0-9]+\\|" "[A-Za-z0-9.!?_#@$]+\\)") '(0 font-lock-variable-name-face)) ;; --- And everything else is punctuation --- (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" '(0 mdw-punct-face)))))) ;;;----- Standard ML programming style -------------------------------------- (defun mdw-fontify-sml () ;; --- Make underscore an honorary letter --- (modify-syntax-entry ?_ "w") (modify-syntax-entry ?' "w") ;; --- Set fill prefix --- (mdw-standard-fill-prefix "\\([ \t]*(\*[ \t]*\\)") ;; --- Now define fontification things --- (make-local-variable 'font-lock-keywords) (let ((sml-keywords (mdw-regexps "abstype" "and" "andalso" "as" "case" "datatype" "do" "else" "end" "eqtype" "exception" "fn" "fun" "functor" "handle" "if" "in" "include" "infix" "infixr" "let" "local" "nonfix" "of" "op" "open" "orelse" "raise" "rec" "sharing" "sig" "signature" "struct" "structure" "then" "type" "val" "where" "while" "with" "withtype"))) (setq font-lock-keywords (list ;; --- Set up the keywords defined above --- (list (concat "\\<\\(" sml-keywords "\\)\\>") '(0 font-lock-keyword-face)) ;; --- At least numbers are simpler than C --- (list (concat "\\<\\(\\~\\|\\)" "\\(0\\(\\([wW]\\|\\)[xX][0-9a-fA-F]+\\|" "[wW][0-9]+\\)\\|" "\\([0-9]+\\(\\.[0-9]+\\|\\)" "\\([eE]\\(\\~\\|\\)" "[0-9]+\\|\\)\\)\\)") '(0 mdw-number-face)) ;; --- And anything else is punctuation --- (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" '(0 mdw-punct-face)))))) ;;;----- Haskell configuration ---------------------------------------------- (defun mdw-fontify-haskell () ;; --- Fiddle with syntax table to get comments right --- (modify-syntax-entry ?_ "w") (modify-syntax-entry ?' "\"") (modify-syntax-entry ?- ". 123") (modify-syntax-entry ?{ ". 1b") (modify-syntax-entry ?} ". 4b") (modify-syntax-entry ?\n ">") ;; --- Set fill prefix --- (mdw-standard-fill-prefix "\\([ \t]*{?--?[ \t]*\\)") ;; --- Fiddle with fontification --- (make-local-variable 'font-lock-keywords) (let ((haskell-keywords (mdw-regexps "as" "case" "ccall" "class" "data" "default" "deriving" "do" "else" "foreign" "hiding" "if" "import" "in" "infix" "infixl" "infixr" "instance" "let" "module" "newtype" "of" "qualified" "safe" "stdcall" "then" "type" "unsafe" "where"))) (setq font-lock-keywords (list (list "--.*$" '(0 font-lock-comment-face)) (list (concat "\\<\\(" haskell-keywords "\\)\\>") '(0 font-lock-keyword-face)) (list (concat "\\<0\\([xX][0-9a-fA-F]+\\|[0-7]+\\)\\|" "\\<[0-9][0-9_]*\\(\\.[0-9]*\\|\\)" "\\([eE]\\([-+]\\|\\)[0-9]+\\|\\)") '(0 mdw-number-face)) (list "\\(\\s.\\|\\s(\\|\\s)\\|\\s\\\\|\\s/\\)" '(0 mdw-punct-face)))))) ;;;----- Texinfo configuration ---------------------------------------------- (defun mdw-fontify-texinfo () ;; --- Set fill prefix --- (mdw-standard-fill-prefix "\\([ \t]*@c[ \t]+\\)") ;; --- Real fontification things --- (make-local-variable 'font-lock-keywords) (setq font-lock-keywords (list ;; --- Environment names are keywords --- (list "@\\(end\\) *\\([a-zA-Z]*\\)?" '(2 font-lock-keyword-face)) ;; --- Unmark escaped magic characters --- (list "\\(@\\)\\([@{}]\\)" '(1 font-lock-keyword-face) '(2 font-lock-variable-name-face)) ;; --- Make sure we get comments properly --- (list "@c\\(\\|omment\\)\\( .*\\)?$" '(0 font-lock-comment-face)) ;; --- Command names are keywords --- (list "@\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)" '(0 font-lock-keyword-face)) ;; --- Fontify TeX special characters as punctuation --- (list "[{}]+" '(0 mdw-punct-face))))) ;;;----- TeX and LaTeX configuration ---------------------------------------- (defun mdw-fontify-tex () (setq ispell-parser 'tex) ;; --- Don't make maths into a string --- (modify-syntax-entry ?$ ".") (modify-syntax-entry ?$ "." font-lock-syntax-table) (local-set-key [?$] 'self-insert-command) ;; --- Set fill prefix --- (mdw-standard-fill-prefix "\\([ \t]*%+[ \t]*\\)") ;; --- Real fontification things --- (make-local-variable 'font-lock-keywords) (setq font-lock-keywords (list ;; --- Environment names are keywords --- (list (concat "\\\\\\(begin\\|end\\|newenvironment\\)" "{\\([^}\n]*\\)}") '(2 font-lock-keyword-face)) ;; --- Suspended environment names are keywords too --- (list (concat "\\\\\\(suspend\\|resume\\)\\(\\[[^]]*\\]\\)?" "{\\([^}\n]*\\)}") '(3 font-lock-keyword-face)) ;; --- Command names are keywords --- (list "\\\\\\([^a-zA-Z@]\\|[a-zA-Z@]*\\)" '(0 font-lock-keyword-face)) ;; --- Handle @/.../ for italics --- ;; (list "\\(@/\\)\\([^/]*\\)\\(/\\)" ;; '(1 font-lock-keyword-face) ;; '(3 font-lock-keyword-face)) ;; --- Handle @*...* for boldness --- ;; (list "\\(@\\*\\)\\([^*]*\\)\\(\\*\\)" ;; '(1 font-lock-keyword-face) ;; '(3 font-lock-keyword-face)) ;; --- Handle @`...' for literal syntax things --- ;; (list "\\(@`\\)\\([^']*\\)\\('\\)" ;; '(1 font-lock-keyword-face) ;; '(3 font-lock-keyword-face)) ;; --- Handle @<...> for nonterminals --- ;; (list "\\(@<\\)\\([^>]*\\)\\(>\\)" ;; '(1 font-lock-keyword-face) ;; '(3 font-lock-keyword-face)) ;; --- Handle other @-commands --- ;; (list "@\\([^a-zA-Z]\\|[a-zA-Z]*\\)" ;; '(0 font-lock-keyword-face)) ;; --- Make sure we get comments properly --- (list "%.*" '(0 font-lock-comment-face)) ;; --- Fontify TeX special characters as punctuation --- (list "[$^_{}#&]" '(0 mdw-punct-face))))) ;;;----- SGML hacking ------------------------------------------------------- (defun mdw-sgml-mode () (interactive) (sgml-mode) (mdw-standard-fill-prefix "") (make-variable-buffer-local 'sgml-delimiters) (setq sgml-delimiters '("AND" "&" "COM" "--" "CRO" "&#" "DSC" "]" "DSO" "[" "DTGC" "]" "DTGO" "[" "ERO" "&" "ETAGO" ":e" "GRPC" ")" "GRPO" "(" "LIT" "\"" "LITA" "'" "MDC" ">" "MDO" "" "PIO" "" "XML-ECOM" "-->" "XML-PIC" "?>" "XML-SCOM" "