]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/texnfo-upd.el
Add defgroup's; use defcustom for user vars.
[gnu-emacs] / lisp / textmodes / texnfo-upd.el
index 48da6614960560ed82cbcc0b38017bb3e543d04f..724d3617d13b9c60365c236bb1094578aafca7b4 100644 (file)
 ;; 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, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
 
 ;;; Commentary:
 
-;;; Known bug: update commands fail to ignore @ignore.
+;; Known bug: update commands fail to ignore @ignore.
 
-;;; Summary: how to use the updating commands
+;; Summary: how to use the updating commands
 
-; The node and menu updating functions automatically
+;; The node and menu updating functions automatically
 
-;   * insert missing `@node' lines,
-;   * insert the `Next', `Previous' and `Up' pointers of a node,
-;   * insert or update the menu for a section, 
-;   * create a master menu for a Texinfo source file.
-;
-; Passed an argument, the `texinfo-update-node' and
-; `texinfo-make-menu' functions do their jobs in the region.
-;
-; In brief, the functions for creating or updating nodes and menus, are:
-; 
-;     texinfo-update-node (&optional region-p)            
-;     texinfo-every-node-update ()                        
-;     texinfo-sequential-node-update (&optional region-p)
-; 
-;     texinfo-make-menu (&optional region-p)              
-;     texinfo-all-menus-update ()                         
-;     texinfo-master-menu ()
-;
-;     texinfo-insert-node-lines  (&optional title-p)
-; 
-;     texinfo-indent-menu-description (column &optional region-p)
+;;   * insert missing `@node' lines,
+;;   * insert the `Next', `Previous' and `Up' pointers of a node,
+;;   * insert or update the menu for a section, 
+;;   * create a master menu for a Texinfo source file.
+;;
+;; With a prefix argument, the `texinfo-update-node' and
+;; `texinfo-make-menu' functions do their jobs in the region.
+;;
+;; In brief, the functions for creating or updating nodes and menus, are:
+;; 
+;;     texinfo-update-node (&optional beginning end)            
+;;     texinfo-every-node-update ()                        
+;;     texinfo-sequential-node-update (&optional region-p)
+;; 
+;;     texinfo-make-menu (&optional beginning end)              
+;;     texinfo-all-menus-update ()                         
+;;     texinfo-master-menu ()
+;;
+;;     texinfo-insert-node-lines  (&optional title-p)
+;; 
+;;     texinfo-indent-menu-description (column &optional region-p)
 
-; The `texinfo-column-for-description' variable specifies the column to
-; which menu descriptions are indented. 
+;; The `texinfo-column-for-description' variable specifies the column to
+;; which menu descriptions are indented. 
 
-; Texinfo file structure
-; ----------------------
+;; Texinfo file structure
+;; ----------------------
 
-; To use the updating commands, you must structure your Texinfo file
-; hierarchically.  Each `@node' line, with the exception of the top
-; node, must be accompanied by some kind of section line, such as an
-; `@chapter' or `@section' line.  Each node-line/section-line
-; combination must look like this:
+;; To use the updating commands, you must structure your Texinfo file
+;; hierarchically.  Each `@node' line, with the exception of the top
+;; node, must be accompanied by some kind of section line, such as an
+;; `@chapter' or `@section' line.  Each node-line/section-line
+;; combination must look like this:
 
-;      @node    Lists and Tables, Cross References, Structuring, Top
-;      @comment node-name,        next,             previous,    up
-;      @chapter Making Lists and Tables
+;;      @node    Lists and Tables, Cross References, Structuring, Top
+;;      @comment node-name,        next,             previous,    up
+;;      @chapter Making Lists and Tables
 
-; or like this (without the `@comment' line):
+;; or like this (without the `@comment' line):
 
-;      @node    Lists and Tables, Cross References, Structuring, Top
-;      @chapter Making Lists and Tables
+;;      @node    Lists and Tables, Cross References, Structuring, Top
+;;      @chapter Making Lists and Tables
 
-; If the file has a `top' node, it must be called `top' or `Top' and
-; be the first node in the file.
+;; If the file has a `top' node, it must be called `top' or `Top' and
+;; be the first node in the file.
 
 \f
 ;;; The update node functions described in detail
 
-; The `texinfo-update-node' function without an argument inserts
-; the correct next, previous and up pointers for the node in which
-; point is located (i.e., for the node preceding point).
+;; The `texinfo-update-node' command with no prefix argument inserts
+;; the correct next, previous and up pointers for the node in which
+;; point is located (i.e., for the node preceding point).
 
-; With an argument, the `texinfo-update-node' function inserts the
-; correct next, previous and up pointers for the nodes inside the
-; region.
+;; With prefix argument, the `texinfo-update-node' function inserts the
+;; correct next, previous and up pointers for the nodes inside the
+;; region.
 
-; It does not matter whether the  `@node' line has pre-existing
-; `Next', `Previous', or `Up' pointers in it.  They are removed.
+;; It does not matter whether the  `@node' line has pre-existing
+;; `Next', `Previous', or `Up' pointers in it.  They are removed.
 
-; The `texinfo-every-node-update' function runs `texinfo-update-node'
-; on the whole buffer.
+;; The `texinfo-every-node-update' function runs `texinfo-update-node'
+;; on the whole buffer.
 
-; The `texinfo-sequential-node-update' function inserts the
-; immediately following and preceding node into the `Next' or
-; `Previous' pointers regardless of their hierarchical level.  This is
-; only useful for certain kinds of text, like a novel, which you go
-; through sequentially.
+;; The `texinfo-sequential-node-update' function inserts the
+;; immediately following and preceding node into the `Next' or
+;; `Previous' pointers regardless of their hierarchical level.  This is
+;; only useful for certain kinds of text, like a novel, which you go
+;; through sequentially.
 
 \f
 ;;; The menu making functions described in detail
 
-; The `texinfo-make-menu' function without an argument creates or
-; updates a menu for the section encompassing the node that follows
-; point.  With an argument, it makes or updates menus for the nodes
-; within or part of the marked region.
-
-; Whenever an existing menu is updated, the descriptions from
-; that menu are incorporated into the new menu.  This is done by copying
-; descriptions from the existing menu to the entries in the new menu
-; that have the same node names.  If the node names are different, the
-; descriptions are not copied to the new menu.
-
-; Menu entries that refer to other Info files are removed since they
-; are not a node within current buffer.  This is a deficiency.
-
-; The `texinfo-all-menus-update' function runs `texinfo-make-menu'
-; on the whole buffer.
-
-; The `texinfo-master-menu' function creates an extended menu located
-; after the top node.  (The file must have a top node.)  The function
-; first updates all the regular menus in the buffer (incorporating the
-; descriptions from pre-existing menus), and then constructs a master
-; menu that includes every entry from every other menu.  (However, the
-; function cannot update an already existing master menu; if one
-; exists, it must be removed before calling the function.)
-
-; The `texinfo-indent-menu-description' function indents every
-; description in the menu following point, to the specified column.
-; Non-nil argument (prefix, if interactive) means indent every
-; description in every menu in the region.  This function does not
-; indent second and subsequent lines of a multi-line description.
-
-; The `texinfo-insert-node-lines' function inserts `@node' before the
-; `@chapter', `@section', and such like lines of a region in a Texinfo
-; file where the `@node' lines are missing.
-; 
-; With a non-nil argument (prefix, if interactive), the function not
-; only inserts `@node' lines but also inserts the chapter or section
-; titles as the names of the corresponding nodes; and inserts titles
-; as node names in pre-existing `@node' lines that lack names.
-; 
-; Since node names should be more concise than section or chapter
-; titles, node names so inserted will need to be edited manually.
+;; The `texinfo-make-menu' function without an argument creates or
+;; updates a menu for the section encompassing the node that follows
+;; point.  With an argument, it makes or updates menus for the nodes
+;; within or part of the marked region.
+
+;; Whenever an existing menu is updated, the descriptions from
+;; that menu are incorporated into the new menu.  This is done by copying
+;; descriptions from the existing menu to the entries in the new menu
+;; that have the same node names.  If the node names are different, the
+;; descriptions are not copied to the new menu.
+
+;; Menu entries that refer to other Info files are removed since they
+;; are not a node within current buffer.  This is a deficiency.
+
+;; The `texinfo-all-menus-update' function runs `texinfo-make-menu'
+;; on the whole buffer.
+
+;; The `texinfo-master-menu' function creates an extended menu located
+;; after the top node.  (The file must have a top node.)  The function
+;; first updates all the regular menus in the buffer (incorporating the
+;; descriptions from pre-existing menus), and then constructs a master
+;; menu that includes every entry from every other menu.  (However, the
+;; function cannot update an already existing master menu; if one
+;; exists, it must be removed before calling the function.)
+
+;; The `texinfo-indent-menu-description' function indents every
+;; description in the menu following point, to the specified column.
+;; Non-nil argument (prefix, if interactive) means indent every
+;; description in every menu in the region.  This function does not
+;; indent second and subsequent lines of a multi-line description.
+
+;; The `texinfo-insert-node-lines' function inserts `@node' before the
+;; `@chapter', `@section', and such like lines of a region in a Texinfo
+;; file where the `@node' lines are missing.
+;; 
+;; With a non-nil argument (prefix, if interactive), the function not
+;; only inserts `@node' lines but also inserts the chapter or section
+;; titles as the names of the corresponding nodes; and inserts titles
+;; as node names in pre-existing `@node' lines that lack names.
+;; 
+;; Since node names should be more concise than section or chapter
+;; titles, node names so inserted will need to be edited manually.
 
 \f 
 ;;; Code:
 
-;;; The menu making functions
-
-(defun texinfo-make-menu (&optional region-p)
+(defun texinfo-make-menu (&optional beginning end)
   "Without any prefix argument, make or update a menu.
 Make the menu for the section enclosing the node found following point.
 
-Non-nil argument (prefix, if interactive) means make or update menus
+A prefix argument means make or update menus
 for nodes within or part of the marked region.
 
 Whenever a menu exists, and is being updated, the descriptions that
@@ -162,25 +161,24 @@ are associated with node names in the pre-existing menu are
 incorporated into the new menu.  Otherwise, the nodes' section titles
 are inserted as descriptions."
   
-  (interactive "P")
-  (if (not region-p)
+  (interactive
+   (if prefix-arg
+       (list (point) (mark))))
+  (if (null beginning)
       (let ((level (texinfo-hierarchic-level)))
         (texinfo-make-one-menu level)
-        (message "Done...updated the menu.  You may save the buffer."))
+        (message "Menu updated"))
     ;; else
     (message "Making or updating menus in %s... " (buffer-name))
-    (let ((beginning (region-beginning))
-         (region-end (region-end))
-          (level (progn         ; find section type following point
-                   (goto-char (region-beginning))
-                   (texinfo-hierarchic-level))))
-      (if (= region-end beginning)
-          (error "Please mark a region!"))
-      (save-excursion
+    (save-excursion
+      (goto-char (min beginning end))
+      ;; find section type following point
+      (let ((level (texinfo-hierarchic-level))
+           (region-end (max beginning end)))
         (save-restriction
           (widen)
           
-          (while  (texinfo-find-lower-level-node level region-end)
+          (while (texinfo-find-lower-level-node level region-end)
             (setq level (texinfo-hierarchic-level)) ; new, lower level
             (texinfo-make-one-menu level))
           
@@ -190,7 +188,7 @@ are inserted as descriptions."
             (while (texinfo-find-lower-level-node level region-end)
               (setq level (texinfo-hierarchic-level)) ; new, lower level
               (texinfo-make-one-menu level))))))
-    (message "Done...updated menus.  You may save the buffer.")))
+    (message "Making or updating menus in %s...done" (buffer-name))))
 
 (defun texinfo-make-one-menu (level)
   "Make a menu of all the appropriate nodes in this section.
@@ -247,21 +245,11 @@ nodes in the buffer before updating the menus."
           (progn
             (message "Updating all nodes in %s ... " (buffer-name))
             (sleep-for 2)
-            (push-mark (point-max) t)
-            (goto-char (point-min))
-           ;; Using the mark to pass bounds this way
-           ;; is kludgy, but it's not worth fixing. -- rms.
-           (let ((mark-active t))
-             (texinfo-update-node t))))
+           (texinfo-update-node (point-min) (point-max))))
       
       (message "Updating all menus in %s ... " (buffer-name))        
       (sleep-for 2)
-      (push-mark (point-max) t)
-      (goto-char (point-min))
-      ;; Using the mark to pass bounds this way
-      ;; is kludgy, but it's not worth fixing. -- rms.
-      (let ((mark-active t))
-       (texinfo-make-menu t))
+      (texinfo-make-menu (point-max) (point-min))
       
       (if master-menu-p
           (progn
@@ -450,9 +438,9 @@ The old menu is the menu as it appears in the texinfo file."
              ;; 
              ;; Recognize both when looking for the description.
              (concat "\\* \\("              ; so only menu entries are found
-                     (car (car new-menu-list)) "::"
+                     (regexp-quote (car (car new-menu-list))) "::"
                      "\\|"
-                     ".*: " (car (car new-menu-list)) "[.,\t\n]"
+                     ".*: " (regexp-quote (car (car new-menu-list))) "[.,\t\n]"
                      "\\)"
                      )               ; so only complete entries are found
              end-of-menu
@@ -749,7 +737,7 @@ menus in the buffer (incorporating descriptions from pre-existing
 menus) before it constructs the master menu.
 
 The function removes the detailed part of an already existing master
-menu.  This action depends on the pre-exisitng master menu using the
+menu.  This action depends on the pre-existing master menu using the
 standard `texinfo-master-menu-header'.
 
 The master menu has the following format, which is adapted from the
@@ -798,15 +786,11 @@ title of the section containing the menu."
           (message "Making a master menu in %s ...first updating all nodes... "
                    (buffer-name))
           (sleep-for 2)
-          (push-mark (point-max) t)
-          (goto-char (point-min))
-          (texinfo-update-node t)
+          (texinfo-update-node (point-min) (point-max))
           
           (message "Updating all menus in %s ... " (buffer-name))        
           (sleep-for 2)
-          (push-mark (point-max) t)
-          (goto-char (point-min))
-          (texinfo-make-menu t)))
+          (texinfo-make-menu (point-min) (point-max))))
     
     (message "Now making the master menu in %s... " (buffer-name))
     (sleep-for 2)
@@ -963,11 +947,11 @@ and leave point on the line before the `@end menu' line."
                                           ; last `* ' entry
                       (goto-char end-of-menu)
                       ;; handle multi-line description
-                      (if (not (re-search-backward "^\* " nil t))
+                      (if (not (re-search-backward "^\\* " nil t))
                           (error "No entries in menu."))
                       (point))))
     (while (< (point) last-entry)
-      (if (re-search-forward  "^\* " end-of-menu t)
+      (if (re-search-forward  "^\\* " end-of-menu t)
           (progn
             (setq this-menu-list
                   (cons
@@ -975,7 +959,7 @@ and leave point on the line before the `@end menu' line."
                     (point)
                     ;; copy multi-line descriptions
                     (save-excursion
-                      (re-search-forward "\\(^\* \\|^@e\\)" nil t)
+                      (re-search-forward "\\(^\\* \\|^@e\\)" nil t)
                       (- (point) 3)))
                    this-menu-list)))))
     this-menu-list))
@@ -1226,15 +1210,14 @@ document; the values are regular expressions.")
 ;;; Updating a node
 
 ;;;###autoload
-(defun texinfo-update-node (&optional region-p)
+(defun texinfo-update-node (&optional beginning end)
   "Without any prefix argument, update the node in which point is located.
-Non-nil argument (prefix, if interactive) means update the nodes in the
-marked region.
+Interactively, a prefix argument means to operate on the region.
 
 The functions for creating or updating nodes and menus, and their
 keybindings, are:
 
-    texinfo-update-node (&optional region-p)    \\[texinfo-update-node]
+    texinfo-update-node (&optional beginning end)    \\[texinfo-update-node]
     texinfo-every-node-update ()                \\[texinfo-every-node-update]
     texinfo-sequential-node-update (&optional region-p)
 
@@ -1247,41 +1230,35 @@ keybindings, are:
 The `texinfo-column-for-description' variable specifies the column to
 which menu descriptions are indented. Its default value is 32."
   
-  (interactive "P")
-  (if (not region-p)
-      ;; update a single node
+  (interactive
+   (if prefix-arg
+       (list (point) (mark))))
+  (if (null beginning)
+      ;; Update a single node.
       (let ((auto-fill-function nil) (auto-fill-hook nil))
         (if (not (re-search-backward "^@node" (point-min) t))
-            (error "Node line not found before this position."))
+            (error "Node line not found before this position"))
         (texinfo-update-the-node)
         (message "Done...updated the node.  You may save the buffer."))
     ;; else
     (let ((auto-fill-function nil)
-         (auto-fill-hook nil)
-          (beginning (region-beginning))
-         (end (region-end)))
-      (if (= end beginning)
-          (error "Please mark a region!"))
-      (save-restriction
-       (narrow-to-region beginning end)
-       (goto-char beginning)
-        (push-mark (point) t)
-       (while (re-search-forward "^@node" (point-max) t)
-          (beginning-of-line)            
-          (texinfo-update-the-node))
-        (message "Done...updated nodes in region.  You may save the buffer.")))))
+         (auto-fill-hook nil))
+      (save-excursion
+       (save-restriction
+         (narrow-to-region beginning end)
+         (goto-char (point-min))
+         (while (re-search-forward "^@node" (point-max) t)
+           (beginning-of-line)            
+           (texinfo-update-the-node))
+         (goto-char (point-max))
+         (message "Done...nodes updated in region.  You may save the buffer."))))))
 
 ;;;###autoload
 (defun texinfo-every-node-update ()
   "Update every node in a Texinfo file."
   (interactive)
   (save-excursion
-    (push-mark (point-max) t)
-    (goto-char (point-min))
-    ;; Using the mark to pass bounds this way
-    ;; is kludgy, but it's not worth fixing. -- rms.
-    (let ((mark-active t))
-      (texinfo-update-node t))
+    (texinfo-update-node (point-min) (point-max))
     (message "Done...updated every node.       You may save the buffer.")))
 
 (defun texinfo-update-the-node ()
@@ -1361,7 +1338,7 @@ Return type of pointer (either 'normal or 'no-pointer).
 The first and second arguments bound the search for a pointer to the
 beginning and end, respectively, of the enclosing higher level
 section.  The third argument is a string specifying the general kind
-of section such as \"chapter\ or \"section\".  When looking for the
+of section such as \"chapter\" or \"section\".  When looking for the
 `Next' pointer, the section found will be at the same hierarchical
 level in the Texinfo file; when looking for the `Previous' pointer,
 the section found will be at the same or higher hierarchical level in
@@ -1558,7 +1535,7 @@ it is in a different section.
 Return type of pointer (either 'normal or 'no-pointer).
 
 The first argument is a string specifying the general kind of section
-such as \"chapter\ or \"section\".  The section found will be at the
+such as \"chapter\" or \"section\".  The section found will be at the
 same hierarchical level in the Texinfo file, or, in the case of the up
 pointer, some level higher.  The second argument (one of 'next,
 'previous, or 'up) specifies whether to find the `Next', `Previous',