]> code.delx.au - gnu-emacs/blobdiff - lisp/progmodes/vera-mode.el
American English spelling fix.
[gnu-emacs] / lisp / progmodes / vera-mode.el
index 60debef2f047d82c9d5a78059010f97e481c4492..b8c5850cf6a08d90a0894bc4c48f2d29649e446c 100644 (file)
@@ -1,26 +1,31 @@
 ;;; vera-mode.el --- major mode for editing Vera files.
 
 ;; Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-;;   2006, 2007 Free Software Foundation, Inc.
+;;   2006, 2007, 2008 Free Software Foundation, Inc.
 
 ;; Author:      Reto Zimmermann <reto@gnu.org>
 ;; Maintainer:  Reto Zimmermann <reto@gnu.org>
-;; Version:     2.26
+;; Version:     2.28
 ;; Keywords:    languages vera
 ;; WWW:         http://www.iis.ee.ethz.ch/~zimmi/emacs/vera-mode.html
 
+;; Yoni Rabkin <yoni@rabkins.net> contacted the maintainer of this
+;; file on 18/3/2008, and the maintainer agreed that when a bug is
+;; filed in the Emacs bug reporting system against this file, a copy
+;; of the bug report be sent to the maintainer's email address.
+
 (defconst vera-version "2.18"
   "Vera Mode version number.")
 
-(defconst vera-time-stamp "2007-06-11"
+(defconst vera-time-stamp "2007-06-21"
   "Vera Mode time stamp for last update.")
 
 ;; 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 2, 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
@@ -28,9 +33,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:
@@ -48,7 +51,7 @@
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Documentation
 
-;; See comment string of function `vera-mode' or type `C-c C-h' in Emacs.
+;; See comment string of function `vera-mode' or type `C-h m' in Emacs.
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Installation
 
 ;;; Code:
 
-;; XEmacs handling
-(defconst vera-xemacs (string-match "XEmacs" emacs-version)
-  "Non-nil if XEmacs is used.")
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Variables
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -88,6 +87,7 @@
 (defgroup vera nil
   "Customizations for Vera Mode."
   :prefix "vera-"
+  :version "22.2"
   :group 'languages)
 
 (defcustom vera-basic-offset 2
@@ -105,7 +105,7 @@ are treated as single words otherwise."
 
 (defcustom vera-intelligent-tab t
   "*Non-nil means `TAB' does indentation, word completion and tab insertion.
-That is, if preceeding character is part of a word then complete word,
+That is, if preceding character is part of a word then complete word,
 else if not at beginning of line then insert tab,
 else if last command was a `TAB' or `RET' then dedent one step,
 else indent current line.
@@ -121,37 +121,37 @@ If nil, TAB always indents current line."
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Key bindings
 
-(defvar vera-mode-map ()
+(defvar vera-mode-map
+  (let ((map (make-sparse-keymap)))
+    ;; Backspace/delete key bindings.
+    (define-key map [backspace] 'backward-delete-char-untabify)
+    (unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
+      (define-key map [delete]       'delete-char)
+      (define-key map [(meta delete)] 'kill-word))
+    ;; Standard key bindings.
+    (define-key map "\M-e"     'vera-forward-statement)
+    (define-key map "\M-a"     'vera-backward-statement)
+    (define-key map "\M-\C-e"  'vera-forward-same-indent)
+    (define-key map "\M-\C-a"  'vera-backward-same-indent)
+    ;; Mode specific key bindings.
+    (define-key map "\C-c\t"   'indent-according-to-mode)
+    (define-key map "\M-\C-\\" 'vera-indent-region)
+    (define-key map "\C-c\C-c" 'vera-comment-uncomment-region)
+    (define-key map "\C-c\C-f" 'vera-fontify-buffer)
+    (define-key map "\C-c\C-v" 'vera-version)
+    (define-key map "\M-\t"    'tab-to-tab-stop)
+    ;; Electric key bindings.
+    (define-key map "\t"       'vera-electric-tab)
+    (define-key map "\r"       'vera-electric-return)
+    (define-key map " "        'vera-electric-space)
+    (define-key map "{"        'vera-electric-opening-brace)
+    (define-key map "}"        'vera-electric-closing-brace)
+    (define-key map "#"        'vera-electric-pound)
+    (define-key map "*"        'vera-electric-star)
+    (define-key map "/"        'vera-electric-slash)
+    map)
   "Keymap for Vera Mode.")
 
-(setq vera-mode-map (make-sparse-keymap))
-;; backspace/delete key bindings
-(define-key vera-mode-map [backspace] 'backward-delete-char-untabify)
-(unless (boundp 'delete-key-deletes-forward) ; XEmacs variable
-  (define-key vera-mode-map [delete]       'delete-char)
-  (define-key vera-mode-map [(meta delete)] 'kill-word))
-;; standard key bindings
-(define-key vera-mode-map "\M-e"     'vera-forward-statement)
-(define-key vera-mode-map "\M-a"     'vera-backward-statement)
-(define-key vera-mode-map "\M-\C-e"  'vera-forward-same-indent)
-(define-key vera-mode-map "\M-\C-a"  'vera-backward-same-indent)
-;; mode specific key bindings
-(define-key vera-mode-map "\C-c\t"   'indent-according-to-mode)
-(define-key vera-mode-map "\M-\C-\\" 'vera-indent-region)
-(define-key vera-mode-map "\C-c\C-c" 'vera-comment-uncomment-region)
-(define-key vera-mode-map "\C-c\C-f" 'vera-fontify-buffer)
-(define-key vera-mode-map "\C-c\C-v" 'vera-version)
-(define-key vera-mode-map "\M-\t"    'tab-to-tab-stop)
-;; electric key bindings
-(define-key vera-mode-map "\t"       'vera-electric-tab)
-(define-key vera-mode-map "\r"       'vera-electric-return)
-(define-key vera-mode-map " "        'vera-electric-space)
-(define-key vera-mode-map "{"        'vera-electric-opening-brace)
-(define-key vera-mode-map "}"        'vera-electric-closing-brace)
-(define-key vera-mode-map "#"        'vera-electric-pound)
-(define-key vera-mode-map "*"        'vera-electric-star)
-(define-key vera-mode-map "/"        'vera-electric-slash)
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Menu
 
@@ -230,7 +230,7 @@ If nil, TAB always indents current line."
     (modify-syntax-entry ?\{ "(}"   syntax-table)
     (modify-syntax-entry ?\} "){"   syntax-table)
     ;; comment
-    (if vera-xemacs
+    (if (featurep 'xemacs)
        (modify-syntax-entry ?\/ ". 1456" syntax-table) ; XEmacs
       (modify-syntax-entry ?\/ ". 124b" syntax-table)) ; Emacs
     (modify-syntax-entry ?\* ". 23" syntax-table)
@@ -314,7 +314,7 @@ Key bindings:
   (set (make-local-variable 'comment-end) "")
   (set (make-local-variable 'comment-column) 40)
   (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|//+ *")
-  (set (make-local-variable 'comment-end-skip) " *\\*+/\\| *//+")
+  (set (make-local-variable 'comment-end-skip) " *\\*+/\\| *\n")
   (set (make-local-variable 'comment-indent-function) 'c-comment-indent)
   (set (make-local-variable 'paragraph-start) "^$")
   (set (make-local-variable 'paragraph-separate) paragraph-start)
@@ -599,14 +599,14 @@ Key bindings:
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 ;; XEmacs compatibility
-(when vera-xemacs
+(when (featurep 'xemacs)
   (require 'font-lock)
   (copy-face 'font-lock-reference-face 'font-lock-constant-face)
   (copy-face 'font-lock-preprocessor-face 'font-lock-builtin-face))
 
 (defun vera-font-lock-match-item (limit)
-  "Match, and move over, any declaration item after point. Adapted from
-`font-lock-match-c-style-declaration-item-and-skip-to-next'."
+  "Match, and move over, any declaration item after point.
+Adapted from `font-lock-match-c-style-declaration-item-and-skip-to-next'."
   (condition-case nil
       (save-restriction
        (narrow-to-region (point-min) limit)
@@ -686,7 +686,6 @@ Key bindings:
     (t (:italic t :bold t)))
   "Font lock mode face used to highlight @ definitions."
   :group 'font-lock-highlighting-faces)
-(put 'vera-font-lock-number-face 'face-alias 'vera-font-lock-number)
 
 (defface vera-font-lock-function
   '((((class color) (background light)) (:foreground "DarkCyan"))
@@ -694,7 +693,6 @@ Key bindings:
     (t (:italic t :bold t)))
   "Font lock mode face used to highlight predefined functions and tasks."
   :group 'font-lock-highlighting-faces)
-(put 'vera-font-lock-function-face 'face-alias 'vera-font-lock-function)
 
 (defface vera-font-lock-interface
   '((((class color) (background light)) (:foreground "Grey40"))
@@ -702,13 +700,8 @@ Key bindings:
     (t (:italic t :bold t)))
   "Font lock mode face used to highlight interface names."
   :group 'font-lock-highlighting-faces)
-(put 'vera-font-lock-interface-face 'face-alias 'vera-font-lock-interface)
-
-(defun vera-fontify-buffer ()
-  "Fontify buffer."
-  (interactive)
-  (font-lock-fontify-buffer))
 
+(defalias 'vera-fontify-buffer 'font-lock-fontify-buffer)
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Indentation
@@ -788,7 +781,7 @@ the offset is simply returned."
 ;; help functions
 
 (defsubst vera-point (position)
-  "Returns the value of point at certain commonly referenced POSITIONs.
+  "Return the value of point at certain commonly referenced POSITIONs.
 POSITION can be one of the following symbols:
   bol  -- beginning of line
   eol  -- end of line
@@ -819,47 +812,50 @@ This function does not modify point or mark."
        ((nth 4 state) 'comment)
        (t nil)))))
 
-(defun vera-in-comment-p ()
-  "Determine if point is in a Vera comment."
-  (save-excursion
-    (re-search-backward "\\(/\\*\\)\\|\\(\\*/\\)" nil t)
-    (match-string 1)))
-
 (defun vera-skip-forward-literal ()
   "Skip forward literal and return t if within one."
-  (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
-    (cond
-     ((nth 3 state) (search-forward "\"") t) ; inside string
-     ((nth 7 state) (forward-line 1) t)             ; inside // comment
-     ((nth 4 state) (search-forward "*/") t) ; inside /* */ comment
-     (t nil))))
+  (let ((state (save-excursion
+                 (if (fboundp 'syntax-ppss)
+                     (syntax-ppss)
+                   (parse-partial-sexp (point-min) (point))))))
+    (when (nth 8 state)
+      ;; Inside a string or comment.
+      (goto-char (nth 8 state))
+      (if (nth 3 state)
+          ;; A string.
+          (condition-case nil (forward-sexp 1)
+            ;; Can't find end of string: it extends til end of buffer.
+            (error (goto-char (point-max))))
+        ;; A comment.
+        (forward-comment 1))
+      t)))
 
 (defun vera-skip-backward-literal ()
   "Skip backward literal and return t if within one."
-  (let ((state (save-excursion (parse-partial-sexp (point-min) (point)))))
-    (cond
-     ((nth 3 state) (search-backward "\"") t) ; inside string
-     ((nth 7 state) (search-backward "//") t) ; inside // comment
-     ((nth 4 state) (search-backward "/*") t) ; inside /* */ comment
-     (t nil))))
+  (let ((state (save-excursion
+                 (if (fboundp 'syntax-ppss)
+                     (syntax-ppss)
+                   (parse-partial-sexp (point-min) (point))))))
+    (when (nth 8 state)
+      ;; Inside a string or comment.
+      (goto-char (nth 8 state))
+      t)))
 
 (defsubst vera-re-search-forward (regexp &optional bound noerror)
   "Like `re-search-forward', but skips over matches in literals."
-  (store-match-data '(nil nil))
-  (while (and (re-search-forward regexp bound noerror)
-             (vera-skip-forward-literal)
-             (progn (store-match-data '(nil nil))
-                    (if bound (< (point) bound) t))))
-  (match-end 0))
+  (let (ret)
+    (while (and (setq ret (re-search-forward regexp bound noerror))
+                (vera-skip-forward-literal)
+                (if bound (< (point) bound) t)))
+    ret))
 
 (defsubst vera-re-search-backward (regexp &optional bound noerror)
   "Like `re-search-backward', but skips over matches in literals."
-  (store-match-data '(nil nil))
-  (while (and (re-search-backward regexp bound noerror)
-             (vera-skip-backward-literal)
-             (progn (store-match-data '(nil nil))
-                    (if bound (> (point) bound) t))))
-  (match-end 0))
+  (let (ret)
+    (while (and (setq ret (re-search-backward regexp bound noerror))
+                (vera-skip-backward-literal)
+                (if bound (> (point) bound) t)))
+    ret))
 
 (defun vera-forward-syntactic-ws (&optional lim skip-directive)
   "Forward skip of syntactic whitespace."
@@ -867,7 +863,7 @@ This function does not modify point or mark."
     (let* ((lim (or lim (point-max)))
           (here lim)
           (hugenum (point-max)))
-      (narrow-to-region lim (point))
+      (narrow-to-region (point) lim)
       (while (/= here (point))
        (setq here (point))
        (forward-comment hugenum)
@@ -891,25 +887,8 @@ This function does not modify point or mark."
            (beginning-of-line)))))))
 
 (defmacro vera-prepare-search (&rest body)
-  "Switch to syntax table that includes '_', then execute BODY, and finally
-restore the old environment.  Used for consistent searching."
-  `(let ((current-syntax-table (syntax-table))
-        result
-        (restore-prog                  ; program to restore enviroment
-         '(progn
-            ;; restore syntax table
-            (set-syntax-table current-syntax-table))))
-     ;; use extended syntax table
-     (set-syntax-table vera-mode-ext-syntax-table)
-     ;; execute BODY safely
-     (setq result
-          (condition-case info
-              (progn ,@body)
-            (error (eval restore-prog) ; restore environment on error
-                   (error (cadr info))))) ; pass error up
-     ;; restore environment
-     (eval restore-prog)
-     result))
+  "Execute BODY with a syntax table that includes '_'."
+  `(with-syntax-table vera-mode-ext-syntax-table ,@body))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; comment indentation functions
@@ -1197,7 +1176,7 @@ try to increase performance by using this macro."
        (goto-char placeholder)
        (vera-add-syntax 'statement (vera-point 'boi)))
        ;; CASE 9: at the beginning of a substatement?
-       ;; is this line preceeded by a substatement opening statement?
+       ;; is this line preceded by a substatement opening statement?
        ((save-excursion (vera-backward-syntactic-ws nil t)
                        (when (= (preceding-char) ?\)) (backward-sexp))
                        (backward-word 1)
@@ -1222,9 +1201,8 @@ try to increase performance by using this macro."
 ;; indentation functions
 
 (defun vera-indent-line ()
-  "Indent the current line as Vera code. Optional SYNTAX is the
-syntactic information for the current line. Returns the amount of
-indentation change (in columns)."
+  "Indent the current line as Vera code.
+Return the amount of indentation change (in columns)."
   (interactive)
   (vera-prepare-search
    (let* ((syntax (vera-guess-basic-syntax))
@@ -1273,8 +1251,9 @@ Calls `indent-region' for whole buffer."
 ;; electrifications
 
 (defun vera-electric-tab (&optional prefix-arg)
-  "If preceeding character is part of a word or a paren then hippie-expand,
-else if right of non whitespace on line then tab-to-tab-stop,
+  "Do what I mean (indent, expand, tab, change indent, etc..).
+If preceding character is part of a word or a paren then `hippie-expand',
+else if right of non whitespace on line then `tab-to-tab-stop',
 else if last command was a tab or return then dedent one step or if a comment
 toggle between normal indent and inline comment indent,
 else indent `correctly'.
@@ -1423,9 +1402,8 @@ If `vera-intelligent-tab' is nil, always indent line."
     t))
 
 ;; function for expanding abbrevs and dabbrevs
-(defun vera-expand-abbrev (arg))
-(fset 'vera-expand-abbrev (make-hippie-expand-function
-                              '(try-expand-dabbrev
+(defalias 'vera-expand-abbrev
+  (make-hippie-expand-function '(try-expand-dabbrev
                                 try-expand-dabbrev-all-buffers
                                 vera-try-expand-abbrev)))
 
@@ -1436,7 +1414,7 @@ If `vera-intelligent-tab' is nil, always indent line."
   "Comment region if not commented, uncomment region if already commented."
   (interactive "r\nP")
   (goto-char beg)
-  (if (looking-at (regexp-quote comment-start))
+  (if (looking-at comment-start-skip)
       (comment-region beg end '(4))
     (comment-region beg end)))
 
@@ -1502,4 +1480,5 @@ If `vera-intelligent-tab' is nil, always indent line."
 
 (provide 'vera-mode)
 
+;; arch-tag: 22eae722-7ac5-47ac-a713-c4db1cf623a9
 ;;; vera-mode.el ends here