]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/meta-mode.el
American English spelling fix.
[gnu-emacs] / lisp / progmodes / meta-mode.el
index 6b911dd1e7a6a793230dabd40a846cd16937f2b1..471a969b6234929836199abdec0693335e9bde64 100644 (file)
@@ -1,6 +1,6 @@
 ;;; meta-mode.el --- major mode for editing Metafont or MetaPost sources
 
-;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+;; Copyright (C) 1997, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
 ;; Free Software Foundation, Inc.
 
 ;; Author: Ulrik Vieth <vieth@thphy.uni-duesseldorf.de>
@@ -9,10 +9,10 @@
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs 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 3, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,9 +20,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
 ;;
 ;; This package was begun on February 1, 1997, exactly 20 years after
 ;; the genesis of TeX took place according to Don Knuth's own account
-;; (cf. ``The Errors of TeX'', reprinted in ``Literate Programming'',
+;; (cf.  ``The Errors of TeX'', reprinted in ``Literate Programming'',
 ;; Chapter 10, p. 249).  What better date could there be to choose?
 ;;
 
         (list
          ;; embedded TeX code in btex ... etex
          (cons (concat "\\(btex\\|verbatimtex\\)"
-                       "[ \t]+\\(.*\\)[ \t]+"
+                       "[ \t\f]+\\(.*\\)[ \t\f]+"
                        "\\(etex\\)")
                '((1 font-lock-keyword-face)
                  (2 font-lock-string-face)
                  (3 font-lock-keyword-face)))
          ;; unary macro definitions: def, vardef, let
          (cons (concat "\\<" macro-keywords-1 "\\>"
-                       "[ \t]+\\(\\sw+\\|\\s_+\\|\\s.+\\)")
+                       "[ \t\f]+\\(\\sw+\\|\\s_+\\|\\s.+\\)")
                '((1 font-lock-keyword-face)
                  (2 font-lock-function-name-face)))
          ;; binary macro defintions: <leveldef> x operator y
          (cons (concat "\\<" macro-keywords-2 "\\>"
-                       "[ \t]+\\(\\sw+\\)"
-                       "[ \t]*\\(\\sw+\\|\\s.+\\)"
-                       "[ \t]*\\(\\sw+\\)")
+                       "[ \t\f]+\\(\\sw+\\)"
+                       "[ \t\f]*\\(\\sw+\\|\\s.+\\)"
+                       "[ \t\f]*\\(\\sw+\\)")
                '((1 font-lock-keyword-face)
                  (2 font-lock-variable-name-face nil t)
                  (3 font-lock-function-name-face nil t)
                  (4 font-lock-variable-name-face nil t)))
          ;; variable declarations: numeric, pair, color, ...
          (cons (concat "\\<" type-keywords "\\>"
-                       "\\([ \t]+\\(\\sw+\\)\\)*")
+                       "\\([ \t\f]+\\(\\sw+\\)\\)*")
                '((1 font-lock-type-face)
                  (font-lock-match-meta-declaration-item-and-skip-to-next
                   (goto-char (match-end 1)) nil
                   (1 font-lock-variable-name-face nil t))))
          ;; argument declarations: expr, suffix, text, ...
          (cons (concat "\\<" args-keywords "\\>"
-                       "\\([ \t]+\\(\\sw+\\|\\s_+\\)\\)*")
+                       "\\([ \t\f]+\\(\\sw+\\|\\s_+\\)\\)*")
                '((1 font-lock-type-face)
                  (font-lock-match-meta-declaration-item-and-skip-to-next
                   (goto-char (match-end 1)) nil
                   (1 font-lock-variable-name-face nil t))))
          ;; special case of arguments: expr x of y
-         (cons (concat "\\(expr\\)[ \t]+\\(\\sw+\\)"
-                       "[ \t]+\\(of\\)[ \t]+\\(\\sw+\\)")
+         (cons (concat "\\(expr\\)[ \t\f]+\\(\\sw+\\)"
+                       "[ \t\f]+\\(of\\)[ \t\f]+\\(\\sw+\\)")
                '((1 font-lock-type-face)
                  (2 font-lock-variable-name-face)
                  (3 font-lock-keyword-face nil t)
                'font-lock-keyword-face)
          ;; input, generate
          (cons (concat "\\<" input-keywords "\\>"
-                       "[ \t]+\\(\\sw+\\)")
+                       "[ \t\f]+\\(\\sw+\\)")
                '((1 font-lock-keyword-face)
                  (2 font-lock-constant-face)))
          ;; embedded Metafont/MetaPost code in comments
   ;; `forward-sexp'.  The list of items is expected to be separated
   ;; by commas and terminated by semicolons or equals signs.
   ;;
-  (if (looking-at "[ \t]*\\(\\sw+\\|\\s_+\\)")
+  (if (looking-at "[ \t\f]*\\(\\sw+\\|\\s_+\\)")
       (save-match-data
         (condition-case nil
             (save-restriction
               (narrow-to-region (point-min) limit)
               (goto-char (match-end 1))
               ;; Move over any item value, etc., to the next item.
-              (while (not (looking-at "[ \t]*\\(\\(,\\)\\|;\\|=\\|$\\)"))
+              (while (not (looking-at "[ \t\f]*\\(\\(,\\)\\|;\\|=\\|$\\)"))
                 (goto-char (or (scan-sexps (point) 1) (point-max))))
               (goto-char (match-end 2)))
           (error t)))))
@@ -586,7 +584,7 @@ If the list was changed, sort the list and remove duplicates first."
   (if (and meta-left-comment-regexp
            (looking-at meta-left-comment-regexp))
       (current-column)
-    (skip-chars-backward "\t ")
+    (skip-chars-backward "\t\f ")
     (max (if (bolp) 0 (1+ (current-column)))
          comment-column)))
 
@@ -647,20 +645,24 @@ If the list was changed, sort the list and remove duplicates first."
 
 (defun meta-indent-previous-line ()
   "Go to the previous line of code, skipping comments."
-  (skip-chars-backward "\n\t ")
+  (skip-chars-backward "\n\t\f ")
   (move-to-column (current-indentation))
   ;; Ignore comments.
   (while (and (looking-at comment-start) (not (bobp)))
-    (skip-chars-backward "\n\t ")
-    (if (not (bobp))
-       (move-to-column (current-indentation)))))
+    (skip-chars-backward "\n\t\f ")
+    (when (not (bobp))
+      (move-to-column (current-indentation)))))
 
 (defun meta-indent-unfinished-line ()
   "Tell if the current line of code ends with an unfinished expression."
   (save-excursion
     (end-of-line)
     ;; Skip backward the comments.
-    (while (search-backward comment-start (point-at-bol) t))
+    (let ((point-not-in-string (point)))
+      (while (search-backward comment-start (point-at-bol) t)
+       (unless (meta-indent-in-string-p)
+         (setq point-not-in-string (point))))
+      (goto-char point-not-in-string))
     ;; Search for the end of the previous expression.
     (if (search-backward ";" (point-at-bol) t)
        (progn (while (and (meta-indent-in-string-p)
@@ -672,7 +674,7 @@ If the list was changed, sort the list and remove duplicates first."
     ;; See if the last statement of the line is environment-related,
     ;; or exists at all.
     (if (meta-indent-looking-at-code
-        (concat "[ \t]*\\($\\|" (regexp-quote comment-start)
+        (concat "[ \t\f]*\\($\\|" (regexp-quote comment-start)
                 "\\|\\<" meta-end-environment-regexp "\\>"
                 "\\|\\<" meta-begin-environment-regexp "\\>"
                 "\\|\\<" meta-within-environment-regexp "\\>\\)"))
@@ -782,7 +784,7 @@ Returns t unless search stops due to beginning or end of buffer."
         (concat "\\<" meta-begin-defun-regexp "\\>") nil t arg)
        (progn (goto-char (match-beginning 0))
               (skip-chars-backward "%")
-              (skip-chars-backward " \t") t)))
+              (skip-chars-backward " \t\f") t)))
 
 (defun meta-end-of-defun (&optional arg)
   "Move forward to end of a defun in Metafont or MetaPost code.
@@ -796,7 +798,7 @@ Returns t unless search stops due to beginning or end of buffer."
         (concat "\\<" meta-end-defun-regexp "\\>") nil t arg)
        (progn (goto-char (match-end 0))
               (skip-chars-forward ";")
-              (skip-chars-forward " \t")
+              (skip-chars-forward " \t\f")
               (if (looking-at "\n") (forward-line 1)) t)))
 
 
@@ -864,78 +866,74 @@ The environment marked is the one that contains point or follows point."
   "Abbrev table used in Metafont or MetaPost mode.")
 (define-abbrev-table 'meta-mode-abbrev-table ())
 
-(defvar meta-mode-syntax-table nil
+(defvar meta-mode-syntax-table
+  (let ((st (make-syntax-table)))
+    ;; underscores are word constituents
+    (modify-syntax-entry ?_  "w"  st)
+    ;; miscellaneous non-word symbols
+    (modify-syntax-entry ?#  "_"  st)
+    (modify-syntax-entry ?@  "_"  st)
+    (modify-syntax-entry ?$  "_"  st)
+    (modify-syntax-entry ??  "_"  st)
+    (modify-syntax-entry ?!  "_"  st)
+    ;; binary operators
+    (modify-syntax-entry ?&  "."  st)
+    (modify-syntax-entry ?+  "."  st)
+    (modify-syntax-entry ?-  "."  st)
+    (modify-syntax-entry ?/  "."  st)
+    (modify-syntax-entry ?*  "."  st)
+    (modify-syntax-entry ?.  "."  st)
+    (modify-syntax-entry ?:  "."  st)
+    (modify-syntax-entry ?=  "."  st)
+    (modify-syntax-entry ?<  "."  st)
+    (modify-syntax-entry ?>  "."  st)
+    (modify-syntax-entry ?|  "."  st)
+    ;; opening and closing delimiters
+    (modify-syntax-entry ?\( "()" st)
+    (modify-syntax-entry ?\) ")(" st)
+    (modify-syntax-entry ?\[ "(]" st)
+    (modify-syntax-entry ?\] ")[" st)
+    (modify-syntax-entry ?\{ "(}" st)
+    (modify-syntax-entry ?\} "){" st)
+    ;; comment character
+    (modify-syntax-entry ?%  "<"  st)
+    (modify-syntax-entry ?\n ">"  st)
+    ;; escape character, needed for embedded TeX code
+    (modify-syntax-entry ?\\ "\\" st)
+    st)
   "Syntax table used in Metafont or MetaPost mode.")
-(if meta-mode-syntax-table
-    ()
-  (setq meta-mode-syntax-table (make-syntax-table))
-  ;; underscores are word constituents
-  (modify-syntax-entry ?_  "w"  meta-mode-syntax-table)
-  ;; miscellaneous non-word symbols
-  (modify-syntax-entry ?#  "_"  meta-mode-syntax-table)
-  (modify-syntax-entry ?@  "_"  meta-mode-syntax-table)
-  (modify-syntax-entry ?$  "_"  meta-mode-syntax-table)
-  (modify-syntax-entry ??  "_"  meta-mode-syntax-table)
-  (modify-syntax-entry ?!  "_"  meta-mode-syntax-table)
-  ;; binary operators
-  (modify-syntax-entry ?&  "."  meta-mode-syntax-table)
-  (modify-syntax-entry ?+  "."  meta-mode-syntax-table)
-  (modify-syntax-entry ?-  "."  meta-mode-syntax-table)
-  (modify-syntax-entry ?/  "."  meta-mode-syntax-table)
-  (modify-syntax-entry ?*  "."  meta-mode-syntax-table)
-  (modify-syntax-entry ?.  "."  meta-mode-syntax-table)
-  (modify-syntax-entry ?:  "."  meta-mode-syntax-table)
-  (modify-syntax-entry ?=  "."  meta-mode-syntax-table)
-  (modify-syntax-entry ?<  "."  meta-mode-syntax-table)
-  (modify-syntax-entry ?>  "."  meta-mode-syntax-table)
-  (modify-syntax-entry ?|  "."  meta-mode-syntax-table)
-  ;; opening and closing delimiters
-  (modify-syntax-entry ?\( "()" meta-mode-syntax-table)
-  (modify-syntax-entry ?\) ")(" meta-mode-syntax-table)
-  (modify-syntax-entry ?\[ "(]" meta-mode-syntax-table)
-  (modify-syntax-entry ?\] ")[" meta-mode-syntax-table)
-  (modify-syntax-entry ?\{ "(}" meta-mode-syntax-table)
-  (modify-syntax-entry ?\} "){" meta-mode-syntax-table)
-  ;; comment character
-  (modify-syntax-entry ?%  "<"  meta-mode-syntax-table)
-  (modify-syntax-entry ?\n ">"  meta-mode-syntax-table)
-  ;; escape character, needed for embedded TeX code
-  (modify-syntax-entry ?\\ "\\" meta-mode-syntax-table)
-  )
 
-(defvar meta-mode-map nil
+(defvar meta-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-m"      'reindent-then-newline-and-indent)
+    ;; Comment Paragraphs:
+    ;; (define-key map "\M-a"      'backward-sentence)
+    ;; (define-key map "\M-e"      'forward-sentence)
+    ;; (define-key map "\M-h"      'mark-paragraph)
+    ;; (define-key map "\M-q"      'fill-paragraph)
+    ;; Navigation:
+    (define-key map "\M-\C-a"   'meta-beginning-of-defun)
+    (define-key map "\M-\C-e"   'meta-end-of-defun)
+    (define-key map "\M-\C-h"   'meta-mark-defun)
+    ;; Indentation:
+    (define-key map "\M-\C-q"   'meta-indent-defun)
+    (define-key map "\C-c\C-qe" 'meta-indent-defun)
+    (define-key map "\C-c\C-qr" 'meta-indent-region)
+    (define-key map "\C-c\C-qb" 'meta-indent-buffer)
+    ;; Commenting Out:
+    (define-key map "\C-c%"     'meta-comment-defun)
+    ;; (define-key map "\C-uC-c%"  'meta-uncomment-defun)
+    (define-key map "\C-c;"     'meta-comment-region)
+    (define-key map "\C-c:"     'meta-uncomment-region)
+    ;; Symbol Completion:
+    (define-key map "\M-\t"     'meta-complete-symbol)
+    ;; Shell Commands:
+    ;; (define-key map "\C-c\C-c"  'meta-command-file)
+    ;; (define-key map "\C-c\C-k"  'meta-kill-job)
+    ;; (define-key map "\C-c\C-l"  'meta-recenter-output)
+    map)
   "Keymap used in Metafont or MetaPost mode.")
-(if meta-mode-map
-    ()
-  (setq meta-mode-map (make-sparse-keymap))
-  (define-key meta-mode-map "\t"        'meta-indent-line)
-  (define-key meta-mode-map "\C-m"      'reindent-then-newline-and-indent)
-  ;; Comment Paragraphs:
-; (define-key meta-mode-map "\M-a"      'backward-sentence)
-; (define-key meta-mode-map "\M-e"      'forward-sentence)
-; (define-key meta-mode-map "\M-h"      'mark-paragraph)
-; (define-key meta-mode-map "\M-q"      'fill-paragraph)
-  ;; Navigation:
-  (define-key meta-mode-map "\M-\C-a"   'meta-beginning-of-defun)
-  (define-key meta-mode-map "\M-\C-e"   'meta-end-of-defun)
-  (define-key meta-mode-map "\M-\C-h"   'meta-mark-defun)
-  ;; Indentation:
-  (define-key meta-mode-map "\M-\C-q"   'meta-indent-defun)
-  (define-key meta-mode-map "\C-c\C-qe" 'meta-indent-defun)
-  (define-key meta-mode-map "\C-c\C-qr" 'meta-indent-region)
-  (define-key meta-mode-map "\C-c\C-qb" 'meta-indent-buffer)
-  ;; Commenting Out:
-  (define-key meta-mode-map "\C-c%"     'meta-comment-defun)
-; (define-key meta-mode-map "\C-uC-c%"  'meta-uncomment-defun)
-  (define-key meta-mode-map "\C-c;"     'meta-comment-region)
-  (define-key meta-mode-map "\C-c:"     'meta-uncomment-region)
-  ;; Symbol Completion:
-  (define-key meta-mode-map "\M-\t"     'meta-complete-symbol)
-  ;; Shell Commands:
-; (define-key meta-mode-map "\C-c\C-c"  'meta-command-file)
-; (define-key meta-mode-map "\C-c\C-k"  'meta-kill-job)
-; (define-key meta-mode-map "\C-c\C-l"  'meta-recenter-output)
-  )
+
 
 (easy-menu-define
  meta-mode-menu meta-mode-map
@@ -1014,11 +1012,14 @@ The environment marked is the one that contains point or follows point."
   (make-local-variable 'comment-start)
   (make-local-variable 'comment-end)
   (make-local-variable 'comment-multi-line)
-  (setq comment-start-skip "%+[ \t]*")
+  (setq comment-start-skip "%+[ \t\f]*")
   (setq comment-start "%")
   (setq comment-end "")
   (setq comment-multi-line nil)
 
+  ;; We use `back-to-indentation' but \f is no indentation sign.
+  (modify-syntax-entry ?\f "_   ")
+
   (make-local-variable 'parse-sexp-ignore-comments)
   (setq parse-sexp-ignore-comments t)
 
@@ -1100,5 +1101,5 @@ Turning on MetaPost mode calls the value of the variable
 (provide 'meta-mode)
 (run-hooks 'meta-mode-load-hook)
 
-;;; arch-tag: ec2916b2-3a83-4cf7-962d-d8019370c006
+;; arch-tag: ec2916b2-3a83-4cf7-962d-d8019370c006
 ;;; meta-mode.el ends here