]> code.delx.au - gnu-emacs/blobdiff - lisp/informat.el
Some fixes to follow coding conventions in files maintained by FSF.
[gnu-emacs] / lisp / informat.el
index 36a9bf1113490543caa5aafb67a4d7ebba774d5e..baec500ec785e418d49c5e3397f082a31e740e9a 100644 (file)
 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 ;; Boston, MA 02111-1307, USA.
 
+;;; Commentary:
+
+;; Nowadays, the Texinfo formatting commands always tagify a buffer
+;; (as does `makeinfo') since @anchor commands need tag tables.
+
 ;;; Code:
 
 (require 'info)
 
 ;;;###autoload
-(defun Info-tagify ()
-  "Create or update Info-file tag table in current buffer."
+(defun Info-tagify (&optional input-buffer-name)
+  "Create or update Info file tag table in current buffer or in a region."
   (interactive)
   ;; Save and restore point and restrictions.
   ;; save-restrictions would not work
   ;; because it records the old max relative to the end.
   ;; We record it relative to the beginning.
-  (message "Tagifying %s ..." (file-name-nondirectory (buffer-file-name)))
+  (if input-buffer-name
+      (message "Tagifying region in %s ..." input-buffer-name)
+      (message
+       "Tagifying %s ..."  (file-name-nondirectory (buffer-file-name))))
   (let ((omin (point-min))
        (omax (point-max))
        (nomax (= (point-max) (1+ (buffer-size))))
        (opoint (point)))
     (unwind-protect
-       (progn
-         (widen)
-         (goto-char (point-min))
-         (if (search-forward "\^_\nIndirect:\n" nil t)
-             (message "Cannot tagify split info file")
-           (let ((regexp "Node:[ \t]*\\([^,\n\t]*\\)[,\t\n]")
-                 (case-fold-search t)
-                 list)
-             (while (search-forward "\n\^_" nil t)
-               ;; We want the 0-origin character position of the ^_.
-               ;; That is the same as the Emacs (1-origin) position
-               ;; of the newline before it.
-               (let ((beg (match-beginning 0)))
-                 (forward-line 2)
-                 (if (re-search-backward regexp beg t)
-                     (setq list
-                           (cons (list (buffer-substring-no-properties
-                                         (match-beginning 1)
-                                         (match-end 1))
-                                       beg)
-                                 list)))))
+    (progn
+      (widen)
+      (goto-char (point-min))
+      (if (search-forward "\^_\nIndirect:\n" nil t)
+          (message
+           "Cannot tagify split info file.  Run this before splitting.")
+        (let (tag-list
+              refillp
+              (case-fold-search t)
+              (regexp 
+               (concat
+                "\\("
+
+
+                "\\("
+                "@anchor"        ; match-string 2 matches @anchor
+                "\\)"
+                "\\(-no\\|-yes\\)"  ; match-string 3 matches -no or -yes
+                "\\("
+                "-refill"
+                "\\)"
+
+                "\\("
+                "{"
+                "\\)"
+                "\\("
+                "[^}]+"          ; match-string 6 matches arg to anchor
+                "\\)"
+                "\\("
+                "}"
+                "\\)"
+
+                "\\|"
+
+                "\\("
+                "\n\^_\\(\^L\\)?"
+                "\\)"
+
+                "\\("
+                "\n\\(File:[ \t]*\\([^,\n\t]*\\)[,\t\n]+[ \t\n]*\\)?"
+                "Node:[ \t]*"
+                "\\("
+                "[^,\n\t]*"      ; match-string 13 matches arg to node name
+                "\\)"
+                "[,\t\n]"
+                "\\)"
+
+                "\\)"
+                )))
+          (while (re-search-forward regexp nil t)
+            (if (string-equal "@anchor" (match-string 2))
+                (progn
+                  ;; kludge lest lose match-data
+                  (if (string-equal "-yes" (match-string 3))
+                      (setq refillp t))
+                  (setq tag-list
+                        (cons (list
+                               (concat "Ref: " (match-string 6))
+                               (match-beginning 0))
+                              tag-list))
+                  (if (eq refillp t)
+                      ;; set start and end so texinfo-format-refill works
+                      (let ((texinfo-command-start (match-beginning 0))
+                            (texinfo-command-end (match-end 0)))
+                        (texinfo-format-refill))
+                  (delete-region  (match-beginning 0) (match-end 0))))
+              ;; else this is a Node
+              (setq tag-list
+                    (cons (list 
+                           (concat "Node: " (match-string-no-properties 13))
+                           (1+ (match-beginning 10)))
+                          tag-list))))
+
              (goto-char (point-max))
              (forward-line -8)
              (let ((buffer-read-only nil))
                      (beginning-of-line)
                      (delete-region (point) end)))
                (goto-char (point-max))
+               (or (bolp)
+                   (newline))
                (insert "\^_\f\nTag table:\n")
                (if (eq major-mode 'info-mode)
                    (move-marker Info-tag-table-marker (point)))
-               (setq list (nreverse list))
-               (while list
-                 (insert "Node: " (car (car list)) ?\177)
-                 (princ (position-bytes (car (cdr (car list))))
-                        (current-buffer))
+               (setq tag-list (nreverse tag-list))
+               (while tag-list
+                 (insert (car (car tag-list)) ?\177)
+                 (princ (car (cdr (car tag-list))) (current-buffer))
                  (insert ?\n)
-                 (setq list (cdr list)))
+                 (setq tag-list (cdr tag-list)))
                (insert "\^_\nEnd tag table\n")))))
       (goto-char opoint)
       (narrow-to-region omin (if nomax (1+ (buffer-size))
                               (min omax (point-max))))))
-  (message "Tagifying %s ... done" (file-name-nondirectory (buffer-file-name))))
+  (if input-buffer-name
+      (message "Tagifying region in %s done" input-buffer-name)
+      (message
+       "Tagifying %s done"  (file-name-nondirectory (buffer-file-name)))))
+
 \f
 ;;;###autoload
 (defun Info-split ()
@@ -107,8 +172,7 @@ contains just the tag table and a directory of subfiles."
   (search-forward "\^_")
   (forward-char -1)
   (let ((start (point))
-       (start-byte (position-bytes (point)))
-       (bytes-deleted 0)
+       (chars-deleted 0)
        subfiles
        (subfile-number 1)
        (case-fold-search t)
@@ -130,7 +194,7 @@ contains just the tag table and a directory of subfiles."
        (goto-char (min (+ (point) 50000) (point-max)))
        (search-forward "\^_" nil 'move)
        (setq subfiles
-             (cons (list (+ start-byte bytes-deleted)
+             (cons (list (+ start chars-deleted)
                          (concat (file-name-nondirectory filename)
                                  (format "-%d" subfile-number)))
                    subfiles))
@@ -141,8 +205,7 @@ contains just the tag table and a directory of subfiles."
        (delete-region (1- (point)) (point))
        ;; Back up over the final ^_.
        (forward-char -1)
-       (setq bytes-deleted (+ bytes-deleted (- (position-bytes (point))
-                                               start-byte)))
+       (setq chars-deleted (+ chars-deleted (- (point) start)))
        (delete-region start (point))
        (setq subfile-number (1+ subfile-number))))
     (while subfiles
@@ -214,8 +277,10 @@ Check that every node pointer points to an existing node."
            (forward-line 1)
            (if (re-search-backward regexp beg t)
                (save-restriction
-                 (search-forward "\n\^_" nil 'move)
-                 (narrow-to-region beg (point))
+                 (let ((md (match-data)))
+                   (search-forward "\n\^_" nil 'move)
+                   (narrow-to-region beg (point))
+                   (set-match-data md))
                  (setq Info-validate-thisnode (downcase
                                                (buffer-substring-no-properties
                                                 (match-beginning 1)
@@ -374,7 +439,7 @@ Must be used only with -batch, and kills Emacs on completion.
 Each file will be processed even if an error occurred previously.
 For example, invoke \"emacs -batch -f batch-info-validate $info/ ~/*.info\""
   (if (not noninteractive)
-      (error "batch-info-validate may only be used -batch."))
+      (error "batch-info-validate may only be used -batch"))
   (let ((version-control t)
        (auto-save-default nil)
        (find-file-run-dired nil)