;; simple-html-mode.el --- simple-html code editing commands for GNU Emacs ;; written by Mitch Fincher, 1998 ;; ;; font-lock commands adapted from: Ulrik Dickow ;; (http://www.nbi.dk/~dickow) implementation of font-html.el (defvar simple-html-font-lock-keywords (let ((tword "\\(h1\\|title\\)") ; Titles, like function defs (bword "\\(b\\|h[2-4]\\|strong\\)") ; Names of tags to boldify (iword "\\(address\\|cite\\|em\\|i\\|var\\)") ; ... to italify ;; Regexp to match shortest sequence that surely isn't a bold end. ;; We simplify a bit by extending "" to "]\\|" "h\\([^2-4]\\|[2-4][^>]\\)\\|" "s\\([^t]\\|t[^r]\\)\\)\\)\\)")) (not-iend (concat "\\([^<]\\|<\\([^/]\\|/\\([^aceiv]\\|" "a\\([^d]\\|d[^d]\\)\\|" "c\\([^i]\\|i[^t]\\)\\|" "e\\([^m]\\|m[^>]\\)\\|" "i[^>]\\|" "v\\([^a]\\|a[^r]\\)\\)\\)\\)")) (not-tend (concat "\\([^<]\\|<\\([^/]\\|/\\([^ht]\\|" "h[^1]\\|t\\([^i]\\|i[^t]\\)\\)\\)\\)"))) (list ; Avoid use of `keep', since XEmacs will treat it the same as `t'. ;; First fontify the text of a HREF anchor. It may be overridden later. ;; Anchors in headings will be made bold, for instance. '("]*>\\([^>]+\\)" 1 font-lock-reference-face t) ;; Tag pairs like ... etc. ;; Cunning repeated fontification to handle common cases of overlap. ;; Bold complex --- possibly with arbitrary other non-bold stuff inside. (list (concat "<" bword ">\\(" not-bend "*\\)") 2 'font-lock-type-face t) ;; Italic complex --- possibly with arbitrary non-italic kept inside. (list (concat "<" iword ">\\(" not-iend "*\\)") 2 'font-lock-type-face t) ;; Bold simple --- first fontify bold regions with no tags inside. (list (concat "<" bword ">\\(" "[^<]" "*\\)") 2 'font-lock-type-face t) ;; Any tag, general rule, just after bold/italic stuff. '("\\(<[^>]*>\\)" 1 font-lock-type-face t) ;; Titles and level 1 headings (anchors do sometimes appear in h1's) (list (concat "<" tword ">\\(" not-tend "*\\)") 2 'font-lock-function-name-face t) ;; Underline is rarely used. Only handle it when no tags inside. ;;'("\\([^<]*\\)" 1 simple-html-underline-face t) ;; Forms, anchors & images (also fontify strings inside) '("\\(<\\(form\\|i\\(mg\\|nput\\)\\)\\>[^>]*>\\)" 1 font-lock-variable-name-face t) '("" 0 font-lock-keyword-face t) '("\\(]*>\\)" 1 font-lock-keyword-face t) '("=[ \t\n]*\\(\"[^\"]+\"\\)" 1 font-lock-string-face t) ;; Large-scale structure keywords (like "program" in Fortran). ;; "" "" "" "" "" "" "" '("" 0 font-lock-variable-name-face t) ;; HTML special characters '("&[^;\n]*;" 0 font-lock-string-face t) ;; SGML things like with possible inside. '("\\([^<>]*\\(<[^>]*>[^<>]*\\)*>\\)" 1 font-lock-comment-face t) ;; Comments: . They traditionally override anything else. ;; It's complicated 'cause we won't allow "-->" inside a comment, and ;; font-lock colours the *longest* possible match of the regexp. '("\\(\\)" 1 font-lock-comment-face t))) "Additional expressions to highlight in HTML helper mode.") ;; (set-face-foreground 'font-lock-comment-face "Red") ;; (set-face-foreground 'font-lock-function-name-face "Blue") ;; (set-face-foreground 'font-lock-keyword-face "Gold") ;; (set-face-foreground 'font-lock-reference-face "Sienna") ;; (set-face-foreground 'font-lock-string-face "SeaGreen") ;; (set-face-foreground 'font-lock-type-face "Coral") ;; (set-face-foreground font-lock-variable-name-face "DarkGoldenrod") (defun simple-html-insert-list () "inserts a template for lists in HTML" (interactive "*") (beginning-of-line) (insert "
    \n
  1. \n
  2. \n
\n") (forward-line -3)(end-of-line) (message "inserting a list") ) (defun simple-html-insert-table (nrows ncols) "inserts a table template -mdf" (interactive "nNumber of Rows: \nnNumber of Columns: ") (beginning-of-line) (insert "\n") (setq i -1);; -1 instead of 0, since the header row takes up one loop (while (< i nrows) ;; loop over the rows (insert "") (setq j 0) (while (< j ncols) ;; loop over the cols (if (eq i -1) (insert "") (insert "") ) (setq j (1+ j)) ) (insert "\n") (setq i (1+ i)) ) (insert "
\n") (forward-line (- (+ nrows 3))) (message "%d rows, %d number of columns" nrows ncols) ) (defvar simple-html-mode-map nil "Keymap used in simple-html mode.") (defun simple-html-mode () "Major mode for editing html files. Special Commands: \\{simple-html-mode-map}" (interactive) (kill-all-local-variables) (setq major-mode 'simple-html-mode) (setq mode-name "simple-html") (use-local-map simple-html-mode-map) (run-hooks 'simple-html-mode-hook) ;(simple-html-mode-variables) ;; Tell font-lock.el how to handle simple-html. (make-local-variable 'font-lock-defaults) (setq font-lock-defaults '((simple-html-font-lock-keywords) nil nil ((?\_ . "w")))) (if simple-html-mode-map nil ; do nothing (setq simple-html-mode-map (make-sparse-keymap)) (define-key simple-html-mode-map "\C-t" 'simple-html-insert-table) (define-key simple-html-mode-map "\C-l" 'simple-html-insert-list) ) (provide 'simple-html) ) ;;;;;;;; C'est fini! ;;;;;;;;;