aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/forms.el
diff options
context:
space:
mode:
authorKarl Heuer1997-06-10 18:32:33 +0000
committerKarl Heuer1997-06-10 18:32:33 +0000
commit38bd9da2df4b7702bc74a3fbb64a5af8afe98c21 (patch)
treebce9a73a41329ddb5ccdabdeb9ef2b31022ebdab /lisp/forms.el
parent1a2b7f51aa13630bfb0126be6dbafd0d8e277711 (diff)
downloademacs-38bd9da2df4b7702bc74a3fbb64a5af8afe98c21.tar.gz
emacs-38bd9da2df4b7702bc74a3fbb64a5af8afe98c21.zip
Use `error' where possible to signal errors.
Remove (beep)s for warnings. Change comment about the iif hook to reflect the actual reason. Correct error in field numbering. (forms-mode): Make `forms--elements' local before calling `forms--process-format-list'. (forms-save-buffer): `forms-write-file-filter' and `forms-read-file-filter' were not called correctly.
Diffstat (limited to 'lisp/forms.el')
-rw-r--r--lisp/forms.el155
1 files changed, 75 insertions, 80 deletions
diff --git a/lisp/forms.el b/lisp/forms.el
index 0aa5f0f7130..ccca6d396d0 100644
--- a/lisp/forms.el
+++ b/lisp/forms.el
@@ -1,6 +1,6 @@
1;;; forms.el --- Forms mode: edit a file as a form to fill in 1;;; forms.el --- Forms mode: edit a file as a form to fill in
2 2
3;; Copyright (C) 1991, 1994, 1995, 1996 Free Software Foundation, Inc. 3;; Copyright (C) 1991, 1994, 1995, 1996, 1997 Free Software Foundation, Inc.
4 4
5;; Author: Johan Vromans <jvromans@squirrel.nl> 5;; Author: Johan Vromans <jvromans@squirrel.nl>
6 6
@@ -292,10 +292,10 @@
292(provide 'forms) ;;; official 292(provide 'forms) ;;; official
293(provide 'forms-mode) ;;; for compatibility 293(provide 'forms-mode) ;;; for compatibility
294 294
295(defconst forms-version (substring "$Revision: 2.20 $" 11 -2) 295(defconst forms-version (substring "$Revision: 2.29 $" 11 -2)
296 "The version number of forms-mode (as string). The complete RCS id is: 296 "The version number of forms-mode (as string). The complete RCS id is:
297 297
298 $Id: forms.el,v 2.20 1996/03/01 20:31:29 jv Exp $") 298 $Id: forms.el,v 2.29 1996/03/01 21:13:01 jvromans Exp kwzh $")
299 299
300(defvar forms-mode-hooks nil 300(defvar forms-mode-hooks nil
301 "Hook functions to be run upon entering Forms mode.") 301 "Hook functions to be run upon entering Forms mode.")
@@ -538,6 +538,7 @@ Commands: Equivalent keys in read-only mode:
538 538
539 ;; Validate and process forms-format-list. 539 ;; Validate and process forms-format-list.
540 ;;(message "forms: pre-processing format list...") 540 ;;(message "forms: pre-processing format list...")
541 (make-local-variable 'forms--elements)
541 (forms--process-format-list) 542 (forms--process-format-list)
542 543
543 ;; Build the formatter and parser. 544 ;; Build the formatter and parser.
@@ -545,7 +546,6 @@ Commands: Equivalent keys in read-only mode:
545 (make-local-variable 'forms--format) 546 (make-local-variable 'forms--format)
546 (make-local-variable 'forms--markers) 547 (make-local-variable 'forms--markers)
547 (make-local-variable 'forms--dyntexts) 548 (make-local-variable 'forms--dyntexts)
548 (make-local-variable 'forms--elements)
549 ;;(message "forms: building parser...") 549 ;;(message "forms: building parser...")
550 (forms--make-format) 550 (forms--make-format)
551 (make-local-variable 'forms--parser) 551 (make-local-variable 'forms--parser)
@@ -770,7 +770,7 @@ Commands: Equivalent keys in read-only mode:
770 el forms-number-of-fields)) 770 el forms-number-of-fields))
771 771
772 ;; Store forms order. 772 ;; Store forms order.
773 (if (> field-num (length forms--elements)) 773 (if (>= field-num (length forms--elements))
774 (setq forms--elements (vconcat forms--elements (1- el))) 774 (setq forms--elements (vconcat forms--elements (1- el)))
775 (aset forms--elements field-num (1- el))) 775 (aset forms--elements field-num (1- el)))
776 (setq field-num (1+ field-num)) 776 (setq field-num (1+ field-num))
@@ -821,13 +821,13 @@ Commands: Equivalent keys in read-only mode:
821 821
822;; Special treatment for read-only segments. 822;; Special treatment for read-only segments.
823;; 823;;
824;; If text is inserted between two read-only segments, it inherits the 824;; If text is inserted between two read-only segments, there seems to
825;; read-only properties. This is not what we want. 825;; be no way to give the newly inserted text the RW face.
826;; To solve this, read-only segments get the `insert-in-front-hooks' 826;; To solve this, read-only segments get the `insert-in-front-hooks'
827;; property set with a function that temporarily switches the properties 827;; property set with a function that temporarily switches the
828;; of the first character of the segment to read-write, so the new 828;; properties of the first character of the segment to the RW face, so
829;; text gets the right properties. 829;; the new text gets the right face. The `post-command-hook' is
830;; The `post-command-hook' is used to restore the original properties. 830;; used to restore the original properties.
831 831
832(defvar forms--iif-start nil 832(defvar forms--iif-start nil
833 "Record start of modification command.") 833 "Record start of modification command.")
@@ -1458,10 +1458,8 @@ Commands: Equivalent keys in read-only mode:
1458 (delete-auto-save-file-if-necessary) 1458 (delete-auto-save-file-if-necessary)
1459 (kill-buffer (current-buffer))) 1459 (kill-buffer (current-buffer)))
1460 (if (get-buffer buf) ; not killed??? 1460 (if (get-buffer buf) ; not killed???
1461 (if save 1461 (if save
1462 (progn 1462 (error "Problem saving buffer %s" (buffer-name buf)))
1463 (beep)
1464 (message "Problem saving buffers?")))
1465 (delete-auto-save-file-if-necessary) 1463 (delete-auto-save-file-if-necessary)
1466 (kill-buffer (current-buffer))))) 1464 (kill-buffer (current-buffer)))))
1467 1465
@@ -1508,7 +1506,6 @@ Commands: Equivalent keys in read-only mode:
1508 nil 1506 nil
1509 (if (null forms-check-number-of-fields) 1507 (if (null forms-check-number-of-fields)
1510 nil 1508 nil
1511 (beep)
1512 (message "Warning: this record has %d fields instead of %d" 1509 (message "Warning: this record has %d fields instead of %d"
1513 (length forms--the-record-list) forms-number-of-fields)) 1510 (length forms--the-record-list) forms-number-of-fields))
1514 (if (< (length forms--the-record-list) forms-number-of-fields) 1511 (if (< (length forms--the-record-list) forms-number-of-fields)
@@ -1563,38 +1560,34 @@ Commands: Equivalent keys in read-only mode:
1563As a side effect: sets `forms--the-record-list'." 1560As a side effect: sets `forms--the-record-list'."
1564 1561
1565 (if forms-read-only 1562 (if forms-read-only
1566 (progn 1563 (error "Buffer is read-only"))
1567 (message "Read-only buffer!")
1568 (beep))
1569
1570 (let (the-record)
1571 ;; Build new record.
1572 (setq forms--the-record-list (forms--parse-form))
1573 (setq the-record
1574 (mapconcat 'identity forms--the-record-list forms-field-sep))
1575
1576 (if (string-match (regexp-quote forms-field-sep)
1577 (mapconcat 'identity forms--the-record-list ""))
1578 (error "Field separator occurs in record - update refused!"))
1579 1564
1580 ;; Handle multi-line fields, if allowed. 1565 (let (the-record)
1581 (if forms-multi-line 1566 ;; Build new record.
1582 (forms--trans the-record "\n" forms-multi-line)) 1567 (setq forms--the-record-list (forms--parse-form))
1568 (setq the-record
1569 (mapconcat 'identity forms--the-record-list forms-field-sep))
1570
1571 (if (string-match (regexp-quote forms-field-sep)
1572 (mapconcat 'identity forms--the-record-list ""))
1573 (error "Field separator occurs in record - update refused"))
1574
1575 ;; Handle multi-line fields, if allowed.
1576 (if forms-multi-line
1577 (forms--trans the-record "\n" forms-multi-line))
1583 1578
1584 ;; A final sanity check before updating. 1579 ;; A final sanity check before updating.
1585 (if (string-match "\n" the-record) 1580 (if (string-match "\n" the-record)
1586 (progn 1581 (error "Multi-line fields in this record - update refused"))
1587 (message "Multi-line fields in this record - update refused!")
1588 (beep))
1589 1582
1590 (save-excursion 1583 (save-excursion
1591 (set-buffer forms--file-buffer) 1584 (set-buffer forms--file-buffer)
1592 ;; Use delete-region instead of kill-region, to avoid 1585 ;; Use delete-region instead of kill-region, to avoid
1593 ;; adding junk to the kill-ring. 1586 ;; adding junk to the kill-ring.
1594 (delete-region (save-excursion (beginning-of-line) (point)) 1587 (delete-region (save-excursion (beginning-of-line) (point))
1595 (save-excursion (end-of-line) (point))) 1588 (save-excursion (end-of-line) (point)))
1596 (insert the-record) 1589 (insert the-record)
1597 (beginning-of-line)))))) 1590 (beginning-of-line))))
1598 1591
1599(defun forms--checkmod () 1592(defun forms--checkmod ()
1600 "Check if this form has been modified, and call forms--update if so." 1593 "Check if this form has been modified, and call forms--update if so."
@@ -1653,45 +1646,43 @@ As a side effect: sets `forms--the-record-list'."
1653 ;; Verify that the record number is within range. 1646 ;; Verify that the record number is within range.
1654 (if (or (> arg forms--total-records) 1647 (if (or (> arg forms--total-records)
1655 (<= arg 0)) 1648 (<= arg 0))
1656 (progn 1649 (error
1657 (beep)
1658 ;; Don't give the message if just paging. 1650 ;; Don't give the message if just paging.
1659 (if (not relative) 1651 (if (not relative)
1660 (message "Record number %d out of range 1..%d" 1652 (message "Record number %d out of range 1..%d"
1661 arg forms--total-records)) 1653 arg forms--total-records)
1662 ) 1654 "")))
1663 1655
1664 ;; Flush. 1656 ;; Flush.
1665 (forms--checkmod) 1657 (forms--checkmod)
1666 1658
1667 ;; Calculate displacement. 1659 ;; Calculate displacement.
1668 (let ((disp (- arg forms--current-record)) 1660 (let ((disp (- arg forms--current-record))
1669 (cur forms--current-record)) 1661 (cur forms--current-record))
1670 1662
1671 ;; `forms--show-record' needs it now. 1663 ;; `forms--show-record' needs it now.
1672 (setq forms--current-record arg) 1664 (setq forms--current-record arg)
1673 1665
1674 ;; Get the record and show it. 1666 ;; Get the record and show it.
1675 (forms--show-record 1667 (forms--show-record
1676 (save-excursion 1668 (save-excursion
1677 (set-buffer forms--file-buffer) 1669 (set-buffer forms--file-buffer)
1678 (beginning-of-line) 1670 (beginning-of-line)
1679 1671
1680 ;; Move, and adjust the amount if needed (shouldn't happen). 1672 ;; Move, and adjust the amount if needed (shouldn't happen).
1681 (if relative 1673 (if relative
1682 (if (zerop disp) 1674 (if (zerop disp)
1683 nil 1675 nil
1684 (setq cur (+ cur disp (- (forward-line disp))))) 1676 (setq cur (+ cur disp (- (forward-line disp)))))
1685 (setq cur (+ cur disp (- (goto-line arg))))) 1677 (setq cur (+ cur disp (- (goto-line arg)))))
1686 1678
1687 (forms--get-record))) 1679 (forms--get-record)))
1688 1680
1689 ;; This shouldn't happen. 1681 ;; This shouldn't happen.
1690 (if (/= forms--current-record cur) 1682 (if (/= forms--current-record cur)
1691 (progn 1683 (progn
1692 (setq forms--current-record cur) 1684 (setq forms--current-record cur)
1693 (beep) 1685 (error "Stuck at record %d" cur)))))
1694 (message "Stuck at record %d" cur))))))
1695 1686
1696(defun forms-first-record () 1687(defun forms-first-record ()
1697 "Jump to first record." 1688 "Jump to first record."
@@ -1709,7 +1700,6 @@ As a side effect: re-calculates the number of records in the data file."
1709 (count-lines (point-min) (point-max))))) 1700 (count-lines (point-min) (point-max)))))
1710 (if (= numrec forms--total-records) 1701 (if (= numrec forms--total-records)
1711 nil 1702 nil
1712 (beep)
1713 (setq forms--total-records numrec) 1703 (setq forms--total-records numrec)
1714 (message "Warning: number of records changed to %d" forms--total-records))) 1704 (message "Warning: number of records changed to %d" forms--total-records)))
1715 (forms-jump-record forms--total-records)) 1705 (forms-jump-record forms--total-records))
@@ -1736,8 +1726,7 @@ Otherwise enables edit mode if the visited file is writable."
1736 buffer-read-only) 1726 buffer-read-only)
1737 (progn 1727 (progn
1738 (setq forms-read-only t) 1728 (setq forms-read-only t)
1739 (message "No write access to `%s'" forms-file) 1729 (message "No write access to `%s'" forms-file))
1740 (beep))
1741 (setq forms-read-only nil)) 1730 (setq forms-read-only nil))
1742 (if (equal ro forms-read-only) 1731 (if (equal ro forms-read-only)
1743 nil 1732 nil
@@ -1896,16 +1885,22 @@ after the current record."
1896(defun forms-save-buffer (&optional args) 1885(defun forms-save-buffer (&optional args)
1897 "Forms mode replacement for save-buffer. 1886 "Forms mode replacement for save-buffer.
1898It saves the data buffer instead of the forms buffer. 1887It saves the data buffer instead of the forms buffer.
1899Calls `forms-write-file-filter' before writing out the data." 1888Calls `forms-write-file-filter' before, and `forms-read-file-filter'
1889after writing out the data."
1900 (interactive "p") 1890 (interactive "p")
1901 (forms--checkmod) 1891 (forms--checkmod)
1902 (let ((read-file-filter forms-read-file-filter)) 1892 (let ((write-file-filter forms-write-file-filter)
1893 (read-file-filter forms-read-file-filter))
1903 (save-excursion 1894 (save-excursion
1904 (set-buffer forms--file-buffer) 1895 (set-buffer forms--file-buffer)
1905 (let ((inhibit-read-only t)) 1896 (let ((inhibit-read-only t))
1897 (if write-file-filter
1898 (save-excursion
1899 (run-hooks 'write-file-filter)))
1906 (save-buffer args) 1900 (save-buffer args)
1907 (if read-file-filter 1901 (if read-file-filter
1908 (run-hooks 'read-file-filter)) 1902 (save-excursion
1903 (run-hooks 'read-file-filter)))
1909 (set-buffer-modified-p nil)))) 1904 (set-buffer-modified-p nil))))
1910 t) 1905 t)
1911 1906