Mercurial > emacs
comparison lisp/textmodes/texinfmt.el @ 88155:d7ddb3e565de
sync with trunk
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Mon, 16 Jan 2006 00:03:54 +0000 |
parents | 176bfa5ffebf |
children |
comparison
equal
deleted
inserted
replaced
88154:8ce476d3ba36 | 88155:d7ddb3e565de |
---|---|
1 ;;; texinfmt.el --- format Texinfo files into Info files | 1 ;;; texinfmt.el --- format Texinfo files into Info files |
2 | 2 |
3 ;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993, | 3 ;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993, |
4 ;; 1994, 1995, 1996, 1997, 1998, 2000, 2001 | 4 ;; 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, |
5 ;; Free Software Foundation, Inc. | 5 ;; 2004, 2005 Free Software Foundation, Inc. |
6 | 6 |
7 ;; Maintainer: Robert J. Chassell <bug-texinfo@gnu.org> | 7 ;; Maintainer: Robert J. Chassell <bug-texinfo@gnu.org> |
8 ;; Keywords: maint, tex, docs | 8 ;; Keywords: maint, tex, docs |
9 | 9 |
10 ;; This file is part of GNU Emacs. | 10 ;; This file is part of GNU Emacs. |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 ;; GNU General Public License for more details. | 20 ;; GNU General Public License for more details. |
21 | 21 |
22 ;; You should have received a copy of the GNU General Public License | 22 ;; You should have received a copy of the GNU General Public License |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02111-1307, USA. | 25 ;; Boston, MA 02110-1301, USA. |
26 | 26 |
27 ;;; Commentary: | 27 ;;; Commentary: |
28 | 28 |
29 ;;; Code: | 29 ;;; Code: |
30 | 30 |
35 | 35 |
36 (or (fboundp 'defcustom) | 36 (or (fboundp 'defcustom) |
37 (defmacro defcustom (var value doc &rest ignore) | 37 (defmacro defcustom (var value doc &rest ignore) |
38 `(defvar ,var ,value ,doc))) | 38 `(defvar ,var ,value ,doc))) |
39 | 39 |
40 (defvar texinfmt-version "2.40 of 6 Dec 2002") | 40 (defvar texinfmt-version "2.41 of 1 Mar 2005") |
41 | 41 |
42 (defun texinfmt-version (&optional here) | 42 (defun texinfmt-version (&optional here) |
43 "Show the version of texinfmt.el in the minibuffer. | 43 "Show the version of texinfmt.el in the minibuffer. |
44 If optional argument HERE is non-nil, insert info at point." | 44 If optional argument HERE is non-nil, insert info at point." |
45 (interactive "P") | 45 (interactive "P") |
131 (message (concat lastmessage | 131 (message (concat lastmessage |
132 (if (interactive-p) "done. Now save it." "done."))))) | 132 (if (interactive-p) "done. Now save it." "done."))))) |
133 | 133 |
134 (defvar texinfo-region-buffer-name "*Info Region*" | 134 (defvar texinfo-region-buffer-name "*Info Region*" |
135 "*Name of the temporary buffer used by \\[texinfo-format-region].") | 135 "*Name of the temporary buffer used by \\[texinfo-format-region].") |
136 | |
137 (defvar texinfo-pre-format-hook nil | |
138 "Hook called before the conversion of the Texinfo file to Info format. | |
139 The functions on this hook are called with argument BUFFER, the buffer | |
140 containing the Texinfo file.") | |
136 | 141 |
137 ;; These come from tex-mode.el. | 142 ;; These come from tex-mode.el. |
138 (defvar tex-start-of-header) | 143 (defvar tex-start-of-header) |
139 (defvar tex-end-of-header) | 144 (defvar tex-end-of-header) |
140 | 145 |
205 (min header-beginning region-beginning) | 210 (min header-beginning region-beginning) |
206 header-end)))))) | 211 header-end)))))) |
207 | 212 |
208 ;;; Find a buffer to use. | 213 ;;; Find a buffer to use. |
209 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name)) | 214 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name)) |
215 (setq buffer-read-only t) | |
216 (let ((inhibit-read-only t)) | |
210 (erase-buffer) | 217 (erase-buffer) |
211 ;; Insert the header into the buffer. | 218 ;; Insert the header into the buffer. |
212 (insert header-text) | 219 (insert header-text) |
213 ;; Insert the region into the buffer. | 220 ;; Insert the region into the buffer. |
214 (insert-buffer-substring | 221 (insert-buffer-substring |
215 input-buffer | 222 input-buffer |
216 (max region-beginning header-end) | 223 (max region-beginning header-end) |
217 region-end) | 224 region-end) |
225 (run-hook-with-args 'texinfo-pre-format-hook input-buffer) | |
218 ;; Make sure region ends in a newline. | 226 ;; Make sure region ends in a newline. |
219 (or (= (preceding-char) ?\n) | 227 (or (= (preceding-char) ?\n) |
220 (insert "\n")) | 228 (insert "\n")) |
221 | 229 |
222 (goto-char (point-min)) | 230 (goto-char (point-min)) |
305 (goto-char (point-min)) | 313 (goto-char (point-min)) |
306 (texinfo-format-scan) | 314 (texinfo-format-scan) |
307 (goto-char (point-min)) | 315 (goto-char (point-min)) |
308 (Info-tagify input-buffer) | 316 (Info-tagify input-buffer) |
309 (goto-char (point-min)) | 317 (goto-char (point-min)) |
310 (message "Done."))) | 318 (message "Done.")))) |
311 | 319 |
312 ;;;###autoload | 320 ;;;###autoload |
313 (defun texi2info (&optional nosplit) | 321 (defun texi2info (&optional nosplit) |
314 "Convert the current buffer (written in Texinfo code) into an Info file. | 322 "Convert the current buffer (written in Texinfo code) into an Info file. |
315 The Info file output is generated in a buffer visiting the Info file | 323 The Info file output is generated in a buffer visiting the Info file |
370 (setq outfile (texinfo-parse-line-arg))) | 378 (setq outfile (texinfo-parse-line-arg))) |
371 | 379 |
372 (find-file outfile) | 380 (find-file outfile) |
373 (texinfo-mode) | 381 (texinfo-mode) |
374 (erase-buffer) | 382 (erase-buffer) |
383 (buffer-disable-undo) | |
375 | 384 |
376 (message "Formatting Info file: %s" outfile) | 385 (message "Formatting Info file: %s" outfile) |
377 (setq texinfo-format-filename | 386 (setq texinfo-format-filename |
378 (file-name-nondirectory (expand-file-name outfile))) | 387 (file-name-nondirectory (expand-file-name outfile))) |
379 | 388 |
380 (setq fill-column fill-column-for-info) | 389 (setq fill-column fill-column-for-info) |
381 (set-syntax-table texinfo-format-syntax-table) | 390 (set-syntax-table texinfo-format-syntax-table) |
382 | 391 |
383 (insert-buffer-substring input-buffer) | 392 (insert-buffer-substring input-buffer) |
393 (run-hook-with-args 'texinfo-pre-format-hook input-buffer) | |
384 (message "Converting %s to Info format..." (buffer-name input-buffer)) | 394 (message "Converting %s to Info format..." (buffer-name input-buffer)) |
385 | 395 |
386 ;; Insert @include files so `texinfo-raise-lower-sections' can | 396 ;; Insert @include files so `texinfo-raise-lower-sections' can |
387 ;; work on them without losing track of multiple | 397 ;; work on them without losing track of multiple |
388 ;; @raise/@lowersections commands. | 398 ;; @raise/@lowersections commands. |
476 ;; add "itemize\\|" (from experiment of 2001 Nov 28) | 486 ;; add "itemize\\|" (from experiment of 2001 Nov 28) |
477 ;; because of a problem with @end itemize@refill | 487 ;; because of a problem with @end itemize@refill |
478 ;; I don't know if this causes other problems. | 488 ;; I don't know if this causes other problems. |
479 ;; I suspect itemized lists don't get filled properly and a | 489 ;; I suspect itemized lists don't get filled properly and a |
480 ;; more precise fix is required. Bob | 490 ;; more precise fix is required. Bob |
481 "itemize\\|" | 491 ;; commented out on 2005 Feb 28 by Bob |
492 ;; "itemize\\|" | |
482 "direntry\\|" | 493 "direntry\\|" |
483 "lisp\\|" | 494 "lisp\\|" |
484 "smalllisp\\|" | 495 "smalllisp\\|" |
485 "example\\|" | 496 "example\\|" |
486 "smallexample\\|" | 497 "smallexample\\|" |
626 (point) | 637 (point) |
627 (save-excursion (skip-chars-backward " \t") (point))) | 638 (save-excursion (skip-chars-backward " \t") (point))) |
628 (forward-char 1) | 639 (forward-char 1) |
629 (unless (re-search-backward "@c[ \t\n]\\|@comment[ \t\n]" line-beg t) | 640 (unless (re-search-backward "@c[ \t\n]\\|@comment[ \t\n]" line-beg t) |
630 (forward-char -1)) | 641 (forward-char -1)) |
631 (unless (re-search-backward "@refill\\|@bye" line-beg t) | 642 (unless (re-search-backward "@refill\\|^[ \t]*@" line-beg t) |
632 (insert "@refill"))) | 643 (insert "@refill"))) |
633 (forward-line 1)))))) | 644 (forward-line 1)))))) |
634 | 645 |
635 | 646 |
636 ;;; Handle `@raisesections' and `@lowersections' commands | 647 ;;; Handle `@raisesections' and `@lowersections' commands |
933 (cond (texinfo-stack | 944 (cond (texinfo-stack |
934 (goto-char (nth 2 (car texinfo-stack))) | 945 (goto-char (nth 2 (car texinfo-stack))) |
935 (error "Unterminated @%s" (car (car texinfo-stack))))) | 946 (error "Unterminated @%s" (car (car texinfo-stack))))) |
936 | 947 |
937 ;; Remove excess whitespace | 948 ;; Remove excess whitespace |
938 (whitespace-cleanup)) | 949 (let ((whitespace-silent t)) |
950 (whitespace-cleanup))) | |
939 | 951 |
940 (defvar texinfo-copying-text "" | 952 (defvar texinfo-copying-text "" |
941 "Text of the copyright notice and copying permissions.") | 953 "Text of the copyright notice and copying permissions.") |
942 | 954 |
943 (defun texinfo-copying () | 955 (defun texinfo-copying () |
2795 "Specify the number of spaces for @refill to indent a paragraph. | 2807 "Specify the number of spaces for @refill to indent a paragraph. |
2796 Default is to leave the number of spaces as is." | 2808 Default is to leave the number of spaces as is." |
2797 (let ((arg (texinfo-parse-arg-discard))) | 2809 (let ((arg (texinfo-parse-arg-discard))) |
2798 (if (string= "asis" arg) | 2810 (if (string= "asis" arg) |
2799 (setq texinfo-paragraph-indent "asis") | 2811 (setq texinfo-paragraph-indent "asis") |
2800 (setq texinfo-paragraph-indent (string-to-int arg))))) | 2812 (setq texinfo-paragraph-indent (string-to-number arg))))) |
2801 | 2813 |
2802 (put 'refill 'texinfo-format 'texinfo-format-refill) | 2814 (put 'refill 'texinfo-format 'texinfo-format-refill) |
2803 (defun texinfo-format-refill () | 2815 (defun texinfo-format-refill () |
2804 "Refill paragraph. Also, indent first line as set by @paragraphindent. | 2816 "Refill paragraph. Also, indent first line as set by @paragraphindent. |
2805 Default is to leave paragraph indentation as is." | 2817 Default is to leave paragraph indentation as is." |
2889 (if texinfo-last-node-pos | 2901 (if texinfo-last-node-pos |
2890 (1+ (count-lines texinfo-last-node-pos (point))) | 2902 (1+ (count-lines texinfo-last-node-pos (point))) |
2891 1)) | 2903 1)) |
2892 (symbol-value indexvar))))) | 2904 (symbol-value indexvar))))) |
2893 | 2905 |
2894 (defconst texinfo-indexvar-alist | 2906 (defvar texinfo-indexvar-alist |
2895 '(("cp" . texinfo-cindex) | 2907 '(("cp" . texinfo-cindex) |
2896 ("fn" . texinfo-findex) | 2908 ("fn" . texinfo-findex) |
2897 ("vr" . texinfo-vindex) | 2909 ("vr" . texinfo-vindex) |
2898 ("tp" . texinfo-tindex) | 2910 ("tp" . texinfo-tindex) |
2899 ("pg" . texinfo-pindex) | 2911 ("pg" . texinfo-pindex) |
3022 (if file (concat "(" file ")") "") | 3034 (if file (concat "(" file ")") "") |
3023 (nth 1 (car indexelts)) ".") | 3035 (nth 1 (car indexelts)) ".") |
3024 (indent-to 54) | 3036 (indent-to 54) |
3025 (insert | 3037 (insert |
3026 (if (nth 2 (car indexelts)) | 3038 (if (nth 2 (car indexelts)) |
3027 (format " %d." (nth 2 (car indexelts))) | 3039 (format " (line %3d)" (1+ (nth 2 (car indexelts)))) |
3028 "") | 3040 "") |
3029 "\n")) | 3041 "\n")) |
3030 ;; index entries from @include'd file | 3042 ;; index entries from @include'd file |
3031 (texinfo-print-index (nth 1 (car indexelts)) | 3043 (texinfo-print-index (nth 1 (car indexelts)) |
3032 (nth 2 (car indexelts)))) | 3044 (nth 2 (car indexelts)))) |
4331 | 4343 |
4332 | 4344 |
4333 ;;; Place `provide' at end of file. | 4345 ;;; Place `provide' at end of file. |
4334 (provide 'texinfmt) | 4346 (provide 'texinfmt) |
4335 | 4347 |
4348 ;;; arch-tag: 1e8d9a2d-bca0-40a0-ac6c-dab01bc6f725 | |
4336 ;;; texinfmt.el ends here | 4349 ;;; texinfmt.el ends here |