X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=infohack.el;h=69f4d66f69a310bf770db1db41c376ab9fd5cc3b;hb=edaf37f9c1d5e8992965d6c25480f0d9704e9786;hp=2b3bea2f3e339f828f197f7ad73ec33203472481;hpb=b3bca6e7855f1461a039a2334bcac176c1827b94;p=elisp%2Fgnus-doc-ja.git diff --git a/infohack.el b/infohack.el index 2b3bea2..69f4d66 100644 --- a/infohack.el +++ b/infohack.el @@ -1,5 +1,5 @@ ;;; infohack.el --- a hack to format info file. -;; Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc. +;; Copyright (C) 2001, 2003, 2004, 2008, 2009 Free Software Foundation, Inc. ;; Author: Shenghuo Zhu ;; Keywords: info @@ -27,39 +27,6 @@ (load-file (expand-file-name "ptexinfmt.el" "./")) -(if (fboundp 'texinfo-copying) - nil - ;; Support @copying and @insertcopying for Emacs 21.3 and lesser and - ;; XEmacs. - (defvar texinfo-copying-text "" - "Text of the copyright notice and copying permissions.") - - (defun texinfo-copying () - "Copy the copyright notice and copying permissions from the Texinfo file, -as indicated by the @copying ... @end copying command; -insert the text with the @insertcopying command." - (let ((beg (progn (beginning-of-line) (point))) - (end (progn (re-search-forward "^@end copying[ \t]*\n") (point)))) - (setq texinfo-copying-text - (buffer-substring-no-properties - (save-excursion (goto-char beg) (forward-line 1) (point)) - (save-excursion (goto-char end) (forward-line -1) (point)))) - (delete-region beg end))) - - (defun texinfo-insertcopying () - "Insert the copyright notice and copying permissions from the Texinfo file, -which are indicated by the @copying ... @end copying command." - (insert (concat "\n" texinfo-copying-text))) - - (defadvice texinfo-format-scan (before expand-@copying-section activate) - "Extract @copying and replace @insertcopying with it." - (goto-char (point-min)) - (when (search-forward "@copying" nil t) - (texinfo-copying)) - (while (search-forward "@insertcopying" nil t) - (delete-region (match-beginning 0) (match-end 0)) - (texinfo-insertcopying)))) - (defun infohack-remove-unsupported () (goto-char (point-min)) (while (re-search-forward "@\\(end \\)?ifnottex" nil t) @@ -69,6 +36,29 @@ which are indicated by the @copying ... @end copying command." (delete-region (1+ (match-beginning 0)) (search-forward "\n@end iflatex\n")))) +(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 +71,7 @@ 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) (texinfo-every-node-update) (texinfo-format-buffer t) ;; Don't save any file. (setq default-directory dest-directory) @@ -88,7 +79,9 @@ 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) + (if (> (buffer-size) (if (boundp 'Info-split-threshold) + (+ 50000 Info-split-threshold) + 100000)) (Info-split)) (save-buffer))) @@ -122,9 +115,36 @@ Both characters must have the same length of multi-byte form." (require 'bytecomp) +;; Reduce the number of split Info files. +(unless (boundp 'Info-split-threshold) + (if (featurep 'xemacs) + (if (load "informat.el" t t) + (let* ((fn (symbol-function 'Info-split)) + (fns (prin1-to-string fn))) + (load "informat.elc" t t) + (when (and (string-match "\\([\t\n ]+\\)50000\\([\t\n )]+\\)" fns) + (condition-case nil + (setq fn (byte-compile + (read (replace-match "\\1262144\\2" + nil nil fns)))) + (error nil)) + (fset 'Info-split fn))))) + (require 'informat) + (let* ((fn (symbol-function 'Info-split)) + (fns (prin1-to-string fn))) + (when (string-match "\\([\t\n ]+\\)50000\\([\t\n ]+\\)" fns) + (condition-case nil + (fset 'Info-split (read (replace-match "\\1262144\\2" + nil nil fns))) + (error + (fset 'Info-split fn))))))) + (defun infohack-texi-format (file &optional addsuffix) (let ((auto-save-default nil) (find-file-run-dired nil) + (coding-system-for-read (if (featurep 'xemacs) + 'iso-2022-7bit + coding-system-for-read)) coding-system-for-write (error 0)) (condition-case err @@ -133,38 +153,6 @@ Both characters must have the same length of multi-byte form." (setq buffer-read-only nil) (buffer-disable-undo (current-buffer)) (setq coding-system-for-write buffer-file-coding-system) - ;; process @include before updating node - ;; This might produce some problem if we use @lowersection or - ;; such. - (let ((input-directory default-directory) - (texinfo-command-end)) - (while (re-search-forward "^@include" nil t) - (setq texinfo-command-end (point)) - (let ((filename (concat input-directory - (texinfo-parse-line-arg)))) - (re-search-backward "^@include") - (delete-region (point) (save-excursion - (forward-line 1) - (point))) - (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" - (save-excursion - (forward-line 100) - (point)) - t) - (progn - (beginning-of-line) - (delete-region (point) (save-excursion - (forward-line 1) - (point)))))))))) ;; Remove ignored areas. (goto-char (point-min)) (while (re-search-forward "^@ignore[\t\r ]*$" nil t) @@ -182,11 +170,16 @@ Both characters must have the same length of multi-byte form." nil t) (not (string-match "\\.info$" (match-string 1)))) (insert ".info")) - (texinfo-mode) + (infohack-include-files) (texinfo-every-node-update) (set-buffer-modified-p nil) (message "texinfo formatting %s..." file) - (let ((si:message (symbol-function 'message))) + (let ((si:message (symbol-function 'message)) + (coding (or (and (string-match "\\`Japanese" + current-language-environment) + (boundp 'locale-coding-system) + locale-coding-system) + 'iso-2022-7bit))) ;; Encode messages to terminal. (fset 'message @@ -197,11 +190,11 @@ Both characters must have the same length of multi-byte form." (equal (car args) buffer-file-name)) (funcall ,si:message "%s" (encode-coding-string (apply 'format fmt args) - 'iso-2022-7bit)))) + ',coding)))) `(lambda (fmt &rest args) (funcall ,si:message "%s" (encode-coding-string (apply 'format fmt args) - 'iso-2022-7bit)))))) + ',coding)))))) (unwind-protect (texinfo-format-buffer nil) (fset 'message si:message)))