New file
[gnus] / texi / infohack.el
index 40fd5be..601fce1 100644 (file)
@@ -1,5 +1,5 @@
 ;;; infohack.el --- a hack to format info file.
-;; Copyright (C)  2001, 2003, 2004, 2008  Free Software Foundation, Inc.
+;; Copyright (C) 2001-2015 Free Software Foundation, Inc.
 
 ;; Author: Shenghuo Zhu <zsh@cs.rochester.edu>
 ;; Keywords: info
@@ -17,9 +17,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:
 
@@ -60,6 +58,51 @@ which are indicated by the @copying ... @end copying command."
       (delete-region (match-beginning 0) (match-end 0))
       (texinfo-insertcopying))))
 
+(if (fboundp 'texinfo-format-comma)
+    nil
+  (put 'comma 'texinfo-format 'texinfo-format-comma)
+  (defun texinfo-format-comma ()
+    (texinfo-parse-arg-discard)
+    (insert ",")
+    (put-text-property (1- (point)) (point) 'ignore t))
+
+  ;; Redefine this function so as to work for @comma
+  (defun texinfo-format-parse-args ()
+    (let ((start (1- (point)))
+         next beg end
+         args)
+      (search-forward "{")
+      (save-excursion
+       (texinfo-format-expand-region
+        (point)
+        (save-excursion (up-list 1) (1- (point)))))
+      ;; The following does not handle cross references of the form:
+      ;; `@xref{bullet, , @code{@@bullet}@{@}}.' because the
+      ;; re-search-forward finds the first right brace after the second
+      ;; comma.
+      (while (/= (preceding-char) ?\})
+       (skip-chars-forward " \t\n")
+       (setq beg (point))
+;;;    (re-search-forward "[},]")
+       ;; Ignore commas that are derived from @comma{}.
+       (while (and (re-search-forward "[},]" nil t)
+                   (get-text-property (match-beginning 0) 'ignore)))
+;;;
+       (setq next (point))
+       (forward-char -1)
+       (skip-chars-backward " \t\n")
+       (setq end (point))
+       (cond ((< beg end)
+              (goto-char beg)
+              (while (search-forward "\n" end t)
+                (replace-match " "))))
+       (push (if (> end beg) (buffer-substring-no-properties beg end))
+             args)
+       (goto-char next))
+      ;;(if (eolp) (forward-char 1))
+      (setq texinfo-command-end (point))
+      (nreverse args))))
+
 (defun infohack-remove-unsupported ()
   (goto-char (point-min))
   (while (re-search-forward "@\\(end \\)?ifnottex" nil t) 
@@ -69,6 +112,34 @@ which are indicated by the @copying ... @end copying command."
     (delete-region (1+ (match-beginning 0))
                   (search-forward "\n@end iflatex\n"))))
 
+(defun infohack-replace-unsupported ()
+  (goto-char (point-min))
+  (while (search-forward "@indicateurl{" nil t)
+    (replace-match "@url{")))
+
+(defun infohack-include-files ()
+  "Insert @include files."
+  (goto-char (point-min))
+  (set-syntax-table texinfo-format-syntax-table)
+  (let (start texinfo-command-end filename)
+    (while (re-search-forward "^@include" nil t)
+      (setq start (match-beginning 0)
+           texinfo-command-end (point)
+           filename (texinfo-parse-line-arg))
+      (delete-region start (point-at-bol 2))
+      (message "Reading included file: %s" filename)
+      (save-excursion
+       (save-restriction
+         (narrow-to-region
+          (point)
+          (+ (point) (car (cdr (insert-file-contents filename)))))
+         (goto-char (point-min))
+         ;; Remove `@setfilename' line from included file, if any,
+         ;; so @setfilename command not duplicated.
+         (if (re-search-forward "^@setfilename" (point-at-eol 100) t)
+             (delete-region (point-at-bol 1)
+                            (point-at-bol 2))))))))
+
 (defun infohack (file)
   (let ((dest-directory default-directory)
        (max-lisp-eval-depth (max max-lisp-eval-depth 600))
@@ -81,6 +152,8 @@ which are indicated by the @copying ... @end copying command."
     (setq buffer-read-only nil)
     (setq coding-system buffer-file-coding-system)
     (infohack-remove-unsupported)
+    (infohack-include-files)
+    (infohack-replace-unsupported)
     (texinfo-every-node-update) 
     (texinfo-format-buffer t) ;; Don't save any file.
     (setq default-directory dest-directory)
@@ -88,8 +161,10 @@ which are indicated by the @copying ... @end copying command."
          (expand-file-name (file-name-nondirectory buffer-file-name)
                            default-directory))
     (setq buffer-file-coding-system coding-system)
-    (if (> (buffer-size) 100000)
-       (Info-split))
+    ;;(if (> (buffer-size) (if (boundp 'Info-split-threshold)
+    ;;                        (+ 50000 Info-split-threshold)
+    ;;                      100000))
+    ;;   (Info-split))
     (save-buffer)))
 
 (eval-and-compile
@@ -118,5 +193,4 @@ Both characters must have the same length of multi-byte form."
   (infohack (car command-line-args-left))
   (setq command-line-args-left nil))
 
-;;; arch-tag: 9ca2f71f-b280-48b3-9826-8dc052dfbbfe
 ;;; infohack.el ends here