]> code.delx.au - gnu-emacs/blobdiff - lisp/forms.el
(compilation-mode): Add a mode-class property.
[gnu-emacs] / lisp / forms.el
index 9a8217fb185de2eed025812624201a60ee53bfcd..0aa5f0f71302ec6ae5483c574709cb1c1fd796f9 100644 (file)
@@ -1,6 +1,6 @@
 ;;; forms.el --- Forms mode: edit a file as a form to fill in
 
-;; Copyright (C) 1991, 1994, 1995 Free Software Foundation, Inc.
+;; Copyright (C) 1991, 1994, 1995, 1996 Free Software Foundation, Inc.
 
 ;; Author: Johan Vromans <jvromans@squirrel.nl>
 
 ;;                     If no write access to the data file is
 ;;                     possible, view mode is enforced. 
 ;;
-;;     forms-check-number-of-fields            [bool, default t]
-;;                   If non-nil, a warning will be issued whenever
-;;                   a record is found that does not have the number
-;;                   of fields specified by `forms-number-of-fields'.
+;;     forms-check-number-of-fields            [bool, default t]
+;;                     If non-nil, a warning will be issued whenever
+;;                     a record is found that does not have the number
+;;                     of fields specified by `forms-number-of-fields'.
 ;;
 ;;     forms-multi-line                        [string, default "^K"]
 ;;                     If non-null the records of the data file may
 ;;
 ;;     forms-forms-jump                        [bool, default nil]
 ;;                     Non-nil means: rebind locally the commands that
-;;                     perform `beginning-of-buffer' or `end-of-buffer'
-;;                     to perform `forms-first-field' resp. `forms-last-field'.
+;;
+;;     forms-insert-after                      [bool, default nil]
+;;                     Non-nil means: inserts of new records go after
+;;                     current record, also initial position is at last
+;;                     record.
 ;;
 ;;     forms-read-file-filter                  [symbol, default nil]
 ;;                     If not nil: this should be the name of a 
 (provide 'forms)                       ;;; official
 (provide 'forms-mode)                  ;;; for compatibility
 
-(defconst forms-version (substring "$Revision: 2.24 $" 11 -2)
+(defconst forms-version (substring "$Revision: 2.20 $" 11 -2)
   "The version number of forms-mode (as string).  The complete RCS id is:
 
-  $Id: forms.el,v 2.24 1996/01/04 23:38:16 kwzh Exp erik $")
+  $Id: forms.el,v 2.20 1996/03/01 20:31:29 jv Exp $")
 
 (defvar forms-mode-hooks nil
   "Hook functions to be run upon entering Forms mode.")
@@ -355,6 +358,10 @@ The contents may NOT be modified.")
   "*Non-nil means: use emacs-19 text properties.
 Defaults to t if this emacs is capable of handling text properties.")
 
+(defvar forms-insert-after nil
+  "*Non-nil means: inserts of new records go after current record.
+Also, initial position is at last record.")
+
 (defvar forms-ro-face 'default
   "The face (a symbol) that is used to display read-only text on the screen.")
 
@@ -463,6 +470,7 @@ Commands:                        Equivalent keys in read-only mode:
         (make-local-variable 'forms-multi-line)
        (make-local-variable 'forms-forms-scroll)
        (make-local-variable 'forms-forms-jump)
+       (make-local-variable 'forms-insert-after)
        (make-local-variable 'forms-use-text-properties)
 
        ;; Filter functions.
@@ -669,8 +677,8 @@ Commands:                        Equivalent keys in read-only mode:
        (insert 
         "GNU Emacs Forms Mode version " forms-version "\n\n"
         (if (file-exists-p forms-file)
-            (concat "No records available in file \"" forms-file "\".\n\n")
-          (format "Creating new file \"%s\"\nwith %d field%s per record.\n\n"
+            (concat "No records available in file `" forms-file "'\n\n")
+          (format "Creating new file `%s'\nwith %d field%s per record\n\n"
                   forms-file forms-number-of-fields
                   (if (= 1 forms-number-of-fields) "" "s")))
         "Use " (substitute-command-keys "\\[forms-insert-record]")
@@ -685,6 +693,10 @@ Commands:                        Equivalent keys in read-only mode:
     (forms-jump-record forms--current-record)
     )
 
+  (if forms-insert-after
+      (forms-last-record)
+    (forms-first-record))
+
   ;; user customising
   ;;(message "forms: proceeding setup (user hooks)...")
   (run-hooks 'forms-mode-hooks)
@@ -774,8 +786,8 @@ Commands:                        Equivalent keys in read-only mode:
          ;; Validate.
          (or (fboundp (car-safe el))
              (error (concat "Forms format error: "
-                            "not a function "
-                            (prin1-to-string (car-safe el)))))
+                            "not a function %S")
+                    (car-safe el)))
 
          ;; Shift.
          (if prev-item
@@ -786,8 +798,8 @@ Commands:                        Equivalent keys in read-only mode:
         ;; else
         (t
          (error (concat "Forms format error: "
-                        "invalid element "
-                        (prin1-to-string el)))))
+                        "invalid element %S")
+                el)))
 
        ;; Advance to next element of the list.
        (setq the-list rem)))
@@ -1279,7 +1291,7 @@ Commands:                        Equivalent keys in read-only mode:
   (define-key map [menu-bar forms]
     (cons "Forms" (make-sparse-keymap "Forms")))
   (define-key map [menu-bar forms menu-forms-exit]
-    '("Exit" . forms-exit))
+    '("Exit Forms Mode" . forms-exit))
   (define-key map [menu-bar forms menu-forms-sep1]
     '("----"))
   (define-key map [menu-bar forms menu-forms-save]
@@ -1415,7 +1427,7 @@ Commands:                        Equivalent keys in read-only mode:
 
 (defun forms--help ()
   "Initial help for Forms mode."
-  (message (substitute-command-keys (concat
+  (message "%s" (substitute-command-keys (concat
   "\\[forms-next-record]:next"
   "   \\[forms-prev-record]:prev"
   "   \\[forms-first-record]:first"
@@ -1724,7 +1736,7 @@ Otherwise enables edit mode if the visited file is writable."
              buffer-read-only)
            (progn
              (setq forms-read-only t)
-             (message "No write access to \"%s\"" forms-file)
+             (message "No write access to `%s'" forms-file)
              (beep))
          (setq forms-read-only nil))
        (if (equal ro forms-read-only)
@@ -1750,15 +1762,21 @@ Otherwise enables edit mode if the visited file is writable."
   "Create a new record before the current one.
 With ARG: store the record after the current one.
 If `forms-new-record-filter' contains the name of a function, 
-it is called to fill (some of) the fields with default values."
+it is called to fill (some of) the fields with default values.
+If `forms-insert-after is non-nil, the default behavior is to insert
+after the current record."
 
   (interactive "P")
 
   (if forms-read-only
       (error ""))
 
-  (let ((ln (if arg (1+ forms--current-record) forms--current-record))
-        the-list the-record)
+  (let (ln the-list the-record)
+
+    (if (or (and arg forms-insert-after)
+           (and (not arg) (not forms-insert-after)))
+       (setq ln forms--current-record)
+      (setq ln (1+ forms--current-record)))
 
     (forms--checkmod)
     (if forms-new-record-filter
@@ -1833,7 +1851,7 @@ it is called to fill (some of) the fields with default values."
          (if (null (re-search-forward regexp nil t))
              (progn
                (goto-char here)
-               (message (concat "\"" regexp "\" not found."))
+               (message "\"%s\" not found" regexp)
                nil)
            (setq the-record (forms--get-record))
            (setq the-line (1+ (count-lines (point-min) (point))))))
@@ -1865,7 +1883,7 @@ it is called to fill (some of) the fields with default values."
          (if (null (re-search-backward regexp nil t))
              (progn
                (goto-char here)
-               (message (concat "\"" regexp "\" not found."))
+               (message "\"%s\" not found" regexp)
                nil)
            (setq the-record (forms--get-record))
            (setq the-line (1+ (count-lines (point-min) (point))))))