Mercurial > emacs
comparison lisp/textmodes/texinfmt.el @ 81631:67d88e663c87
(texinfo-raisesections-alist, texinfo-lowersections-alist): Merge definition
and declaration.
(texinfo-start-of-header, texinfo-end-of-header): Remove.
(texinfo-format-syntax-table): Merge init into declaration.
(texinfo-format-parse-line-args, texinfo-format-parse-args)
(texinfo-format-parse-defun-args, texinfo-format-node)
(texinfo-push-stack, texinfo-multitable-widths)
(texinfo-define-info-enclosure, texinfo-alias)
(texinfo-format-defindex, batch-texinfo-format): Use push.
(texinfo-footnote-number): Remove duplicate declaration.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 27 Jun 2007 18:06:14 +0000 |
parents | e3694f1cb928 |
children | b98604865ea0 988f1edc9674 |
comparison
equal
deleted
inserted
replaced
81630:0eefd2198a9d | 81631:67d88e663c87 |
---|---|
55 ;;; Variable definitions | 55 ;;; Variable definitions |
56 | 56 |
57 (require 'texinfo) ; So `texinfo-footnote-style' is defined. | 57 (require 'texinfo) ; So `texinfo-footnote-style' is defined. |
58 (require 'texnfo-upd) ; So `texinfo-section-types-regexp' is defined. | 58 (require 'texnfo-upd) ; So `texinfo-section-types-regexp' is defined. |
59 | 59 |
60 (defvar texinfo-format-syntax-table nil) | |
61 | |
62 (defvar texinfo-vindex) | 60 (defvar texinfo-vindex) |
63 (defvar texinfo-findex) | 61 (defvar texinfo-findex) |
64 (defvar texinfo-cindex) | 62 (defvar texinfo-cindex) |
65 (defvar texinfo-pindex) | 63 (defvar texinfo-pindex) |
66 (defvar texinfo-tindex) | 64 (defvar texinfo-tindex) |
79 (defvar texinfo-stack) | 77 (defvar texinfo-stack) |
80 (defvar texinfo-short-index-cmds-alist) | 78 (defvar texinfo-short-index-cmds-alist) |
81 (defvar texinfo-short-index-format-cmds-alist) | 79 (defvar texinfo-short-index-format-cmds-alist) |
82 (defvar texinfo-format-filename) | 80 (defvar texinfo-format-filename) |
83 (defvar texinfo-footnote-number) | 81 (defvar texinfo-footnote-number) |
84 (defvar texinfo-start-of-header) | 82 |
85 (defvar texinfo-end-of-header) | 83 (defvar texinfo-raisesections-alist |
86 (defvar texinfo-raisesections-alist) | 84 '((@chapter . @chapter) ; Cannot go higher |
87 (defvar texinfo-lowersections-alist) | 85 (@unnumbered . @unnumbered) |
86 (@centerchap . @unnumbered) | |
87 | |
88 (@majorheading . @majorheading) | |
89 (@chapheading . @chapheading) | |
90 (@appendix . @appendix) | |
91 | |
92 (@section . @chapter) | |
93 (@unnumberedsec . @unnumbered) | |
94 (@heading . @chapheading) | |
95 (@appendixsec . @appendix) | |
96 | |
97 (@subsection . @section) | |
98 (@unnumberedsubsec . @unnumberedsec) | |
99 (@subheading . @heading) | |
100 (@appendixsubsec . @appendixsec) | |
101 | |
102 (@subsubsection . @subsection) | |
103 (@unnumberedsubsubsec . @unnumberedsubsec) | |
104 (@subsubheading . @subheading) | |
105 (@appendixsubsubsec . @appendixsubsec)) | |
106 "*An alist of next higher levels for chapters, sections, etc... | |
107 For example, section to chapter, subsection to section. | |
108 Used by `texinfo-raise-lower-sections'. | |
109 The keys specify types of section; the values correspond to the next | |
110 higher types.") | |
111 | |
112 (defvar texinfo-lowersections-alist | |
113 '((@chapter . @section) | |
114 (@unnumbered . @unnumberedsec) | |
115 (@centerchap . @unnumberedsec) | |
116 (@majorheading . @heading) | |
117 (@chapheading . @heading) | |
118 (@appendix . @appendixsec) | |
119 | |
120 (@section . @subsection) | |
121 (@unnumberedsec . @unnumberedsubsec) | |
122 (@heading . @subheading) | |
123 (@appendixsec . @appendixsubsec) | |
124 | |
125 (@subsection . @subsubsection) | |
126 (@unnumberedsubsec . @unnumberedsubsubsec) | |
127 (@subheading . @subsubheading) | |
128 (@appendixsubsec . @appendixsubsubsec) | |
129 | |
130 (@subsubsection . @subsubsection) ; Cannot go lower. | |
131 (@unnumberedsubsubsec . @unnumberedsubsubsec) | |
132 (@subsubheading . @subsubheading) | |
133 (@appendixsubsubsec . @appendixsubsubsec)) | |
134 "*An alist of next lower levels for chapters, sections, etc... | |
135 For example, chapter to section, section to subsection. | |
136 Used by `texinfo-raise-lower-sections'. | |
137 The keys specify types of section; the values correspond to the next | |
138 lower types.") | |
88 | 139 |
89 ;;; Syntax table | 140 ;;; Syntax table |
90 | 141 |
91 (if texinfo-format-syntax-table | 142 (defvar texinfo-format-syntax-table |
92 nil | 143 (let ((st (make-syntax-table))) |
93 (setq texinfo-format-syntax-table (make-syntax-table)) | 144 (modify-syntax-entry ?\" " " st) |
94 (modify-syntax-entry ?\" " " texinfo-format-syntax-table) | 145 (modify-syntax-entry ?\\ " " st) |
95 (modify-syntax-entry ?\\ " " texinfo-format-syntax-table) | 146 (modify-syntax-entry ?@ "\\" st) |
96 (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table) | 147 (modify-syntax-entry ?\^q "\\" st) |
97 (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table) | 148 (modify-syntax-entry ?\[ "." st) |
98 (modify-syntax-entry ?\[ "." texinfo-format-syntax-table) | 149 (modify-syntax-entry ?\] "." st) |
99 (modify-syntax-entry ?\] "." texinfo-format-syntax-table) | 150 (modify-syntax-entry ?\( "." st) |
100 (modify-syntax-entry ?\( "." texinfo-format-syntax-table) | 151 (modify-syntax-entry ?\) "." st) |
101 (modify-syntax-entry ?\) "." texinfo-format-syntax-table) | 152 (modify-syntax-entry ?{ "(}" st) |
102 (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table) | 153 (modify-syntax-entry ?} "){" st) |
103 (modify-syntax-entry ?} "){" texinfo-format-syntax-table) | 154 (modify-syntax-entry ?\' "." st) |
104 (modify-syntax-entry ?\' "." texinfo-format-syntax-table)) | 155 st)) |
105 | 156 |
106 | 157 |
107 ;;; Top level buffer and region formatting functions | 158 ;;; Top level buffer and region formatting functions |
108 | 159 |
109 ;;;###autoload | 160 ;;;###autoload |
111 "Process the current buffer as texinfo code, into an Info file. | 162 "Process the current buffer as texinfo code, into an Info file. |
112 The Info file output is generated in a buffer visiting the Info file | 163 The Info file output is generated in a buffer visiting the Info file |
113 name specified in the @setfilename command. | 164 name specified in the @setfilename command. |
114 | 165 |
115 Non-nil argument (prefix, if interactive) means don't make tag table | 166 Non-nil argument (prefix, if interactive) means don't make tag table |
116 and don't split the file if large. You can use Info-tagify and | 167 and don't split the file if large. You can use `Info-tagify' and |
117 Info-split to do these manually." | 168 `Info-split' to do these manually." |
118 (interactive "P") | 169 (interactive "P") |
119 (let ((lastmessage "Formatting Info file...") | 170 (let ((lastmessage "Formatting Info file...") |
120 (coding-system-for-write buffer-file-coding-system)) | 171 (coding-system-for-write buffer-file-coding-system)) |
121 (message lastmessage) | 172 (message lastmessage) |
122 (widen) | 173 (widen) |
327 creates a master menu. This work is done on a temporary buffer that | 378 creates a master menu. This work is done on a temporary buffer that |
328 is automatically removed when the Info file is created. The original | 379 is automatically removed when the Info file is created. The original |
329 Texinfo source buffer is not changed. | 380 Texinfo source buffer is not changed. |
330 | 381 |
331 Non-nil argument (prefix, if interactive) means don't split the file | 382 Non-nil argument (prefix, if interactive) means don't split the file |
332 if large. You can use Info-split to do this manually." | 383 if large. You can use `Info-split' to do this manually." |
333 (interactive "P") | 384 (interactive "P") |
334 (let ((temp-buffer (concat "*--" (buffer-name) "--temporary-buffer*" ))) | 385 (let ((temp-buffer (concat "*--" (buffer-name) "--temporary-buffer*" ))) |
335 (message "First updating nodes and menus, then creating Info file.") | 386 (message "First updating nodes and menus, then creating Info file.") |
336 ;; (sit-for 2) | 387 ;; (sit-for 2) |
337 (copy-to-buffer temp-buffer (point-min) (point-max)) | 388 (copy-to-buffer temp-buffer (point-min) (point-max)) |
762 (setq new-level | 813 (setq new-level |
763 (cdr (assq new-level texinfo-lowersections-alist))) | 814 (cdr (assq new-level texinfo-lowersections-alist))) |
764 (setq count (1+ count))) | 815 (setq count (1+ count))) |
765 (kill-word 1) | 816 (kill-word 1) |
766 (insert (symbol-name new-level)))))))))) | 817 (insert (symbol-name new-level)))))))))) |
767 | |
768 (defvar texinfo-raisesections-alist | |
769 '((@chapter . @chapter) ; Cannot go higher | |
770 (@unnumbered . @unnumbered) | |
771 (@centerchap . @unnumbered) | |
772 | |
773 (@majorheading . @majorheading) | |
774 (@chapheading . @chapheading) | |
775 (@appendix . @appendix) | |
776 | |
777 (@section . @chapter) | |
778 (@unnumberedsec . @unnumbered) | |
779 (@heading . @chapheading) | |
780 (@appendixsec . @appendix) | |
781 | |
782 (@subsection . @section) | |
783 (@unnumberedsubsec . @unnumberedsec) | |
784 (@subheading . @heading) | |
785 (@appendixsubsec . @appendixsec) | |
786 | |
787 (@subsubsection . @subsection) | |
788 (@unnumberedsubsubsec . @unnumberedsubsec) | |
789 (@subsubheading . @subheading) | |
790 (@appendixsubsubsec . @appendixsubsec)) | |
791 "*An alist of next higher levels for chapters, sections. etc. | |
792 For example, section to chapter, subsection to section. | |
793 Used by `texinfo-raise-lower-sections'. | |
794 The keys specify types of section; the values correspond to the next | |
795 higher types.") | |
796 | |
797 (defvar texinfo-lowersections-alist | |
798 '((@chapter . @section) | |
799 (@unnumbered . @unnumberedsec) | |
800 (@centerchap . @unnumberedsec) | |
801 (@majorheading . @heading) | |
802 (@chapheading . @heading) | |
803 (@appendix . @appendixsec) | |
804 | |
805 (@section . @subsection) | |
806 (@unnumberedsec . @unnumberedsubsec) | |
807 (@heading . @subheading) | |
808 (@appendixsec . @appendixsubsec) | |
809 | |
810 (@subsection . @subsubsection) | |
811 (@unnumberedsubsec . @unnumberedsubsubsec) | |
812 (@subheading . @subsubheading) | |
813 (@appendixsubsec . @appendixsubsubsec) | |
814 | |
815 (@subsubsection . @subsubsection) ; Cannot go lower. | |
816 (@unnumberedsubsubsec . @unnumberedsubsubsec) | |
817 (@subsubheading . @subsubheading) | |
818 (@appendixsubsubsec . @appendixsubsubsec)) | |
819 "*An alist of next lower levels for chapters, sections. etc. | |
820 For example, chapter to section, section to subsection. | |
821 Used by `texinfo-raise-lower-sections'. | |
822 The keys specify types of section; the values correspond to the next | |
823 lower types.") | |
824 | |
825 | 818 |
826 ;;; Perform those texinfo-to-info conversions that apply to the whole input | 819 ;;; Perform those texinfo-to-info conversions that apply to the whole input |
827 ;;; uniformly. | 820 ;;; uniformly. |
828 | 821 |
829 (defun texinfo-format-scan () | 822 (defun texinfo-format-scan () |
1075 (setq next (point)) | 1068 (setq next (point)) |
1076 (if (bolp) (setq next (1- next))) | 1069 (if (bolp) (setq next (1- next))) |
1077 (forward-char -1) | 1070 (forward-char -1) |
1078 (skip-chars-backward " ") | 1071 (skip-chars-backward " ") |
1079 (setq end (point)) | 1072 (setq end (point)) |
1080 (setq args (cons (if (> end beg) (buffer-substring-no-properties beg end)) | 1073 (push (if (> end beg) (buffer-substring-no-properties beg end)) |
1081 args)) | 1074 args) |
1082 (goto-char next) | 1075 (goto-char next) |
1083 (skip-chars-forward " ")) | 1076 (skip-chars-forward " ")) |
1084 (if (eolp) (forward-char 1)) | 1077 (if (eolp) (forward-char 1)) |
1085 (setq texinfo-command-end (point)) | 1078 (setq texinfo-command-end (point)) |
1086 (nreverse args))) | 1079 (nreverse args))) |
1108 (setq end (point)) | 1101 (setq end (point)) |
1109 (cond ((< beg end) | 1102 (cond ((< beg end) |
1110 (goto-char beg) | 1103 (goto-char beg) |
1111 (while (search-forward "\n" end t) | 1104 (while (search-forward "\n" end t) |
1112 (replace-match " ")))) | 1105 (replace-match " ")))) |
1113 (setq args (cons (if (> end beg) (buffer-substring-no-properties beg end)) | 1106 (push (if (> end beg) (buffer-substring-no-properties beg end)) |
1114 args)) | 1107 args) |
1115 (goto-char next)) | 1108 (goto-char next)) |
1116 ;;(if (eolp) (forward-char 1)) | 1109 ;;(if (eolp) (forward-char 1)) |
1117 (setq texinfo-command-end (point)) | 1110 (setq texinfo-command-end (point)) |
1118 (nreverse args))) | 1111 (nreverse args))) |
1119 | 1112 |
1138 (t | 1131 (t |
1139 (setq beg (point)) | 1132 (setq beg (point)) |
1140 (re-search-forward "[\n ]") | 1133 (re-search-forward "[\n ]") |
1141 (forward-char -1) | 1134 (forward-char -1) |
1142 (setq end (point)))) | 1135 (setq end (point)))) |
1143 (setq args (cons (buffer-substring-no-properties beg end) args)) | 1136 (push (buffer-substring-no-properties beg end) args) |
1144 (skip-chars-forward " ")) | 1137 (skip-chars-forward " ")) |
1145 (forward-char 1) | 1138 (forward-char 1) |
1146 (nreverse args)))) | 1139 (nreverse args)))) |
1147 | 1140 |
1148 (defun texinfo-discard-line () | 1141 (defun texinfo-discard-line () |
1182 (texinfo-discard-command) | 1175 (texinfo-discard-command) |
1183 (setq texinfo-last-node name) | 1176 (setq texinfo-last-node name) |
1184 (let ((tem (if texinfo-fold-nodename-case (downcase name) name))) | 1177 (let ((tem (if texinfo-fold-nodename-case (downcase name) name))) |
1185 (if (assoc tem texinfo-node-names) | 1178 (if (assoc tem texinfo-node-names) |
1186 (error "Duplicate node name: %s" name) | 1179 (error "Duplicate node name: %s" name) |
1187 (setq texinfo-node-names (cons (list tem) texinfo-node-names)))) | 1180 (push (list tem) texinfo-node-names))) |
1188 (setq texinfo-footnote-number 0) | 1181 (setq texinfo-footnote-number 0) |
1189 ;; insert "\n\^_" unconditionally since this is what info is looking for | 1182 ;; insert "\n\^_" unconditionally since this is what info is looking for |
1190 (insert "\n\^_\nFile: " texinfo-format-filename | 1183 (insert "\n\^_\nFile: " texinfo-format-filename |
1191 ", Node: " name) | 1184 ", Node: " name) |
1192 (if next | 1185 (if next |
1491 (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle) | 1484 (put 'footnotestyle 'texinfo-format 'texinfo-footnotestyle) |
1492 (defun texinfo-footnotestyle () | 1485 (defun texinfo-footnotestyle () |
1493 "Specify whether footnotes are at end of node or in separate nodes. | 1486 "Specify whether footnotes are at end of node or in separate nodes. |
1494 Argument is either end or separate." | 1487 Argument is either end or separate." |
1495 (setq texinfo-footnote-style (texinfo-parse-arg-discard))) | 1488 (setq texinfo-footnote-style (texinfo-parse-arg-discard))) |
1496 | |
1497 (defvar texinfo-footnote-number) | |
1498 | 1489 |
1499 (put 'footnote 'texinfo-format 'texinfo-format-footnote) | 1490 (put 'footnote 'texinfo-format 'texinfo-format-footnote) |
1500 (defun texinfo-format-footnote () | 1491 (defun texinfo-format-footnote () |
1501 "Format a footnote in either end of node or separate node style. | 1492 "Format a footnote in either end of node or separate node style. |
1502 The texinfo-footnote-style variable controls which style is used." | 1493 The texinfo-footnote-style variable controls which style is used." |
1599 "Count of number of unpopped texinfo-push-stack calls. | 1590 "Count of number of unpopped texinfo-push-stack calls. |
1600 Used by @refill indenting command to avoid indenting within lists, etc.") | 1591 Used by @refill indenting command to avoid indenting within lists, etc.") |
1601 | 1592 |
1602 (defun texinfo-push-stack (check arg) | 1593 (defun texinfo-push-stack (check arg) |
1603 (setq texinfo-stack-depth (1+ texinfo-stack-depth)) | 1594 (setq texinfo-stack-depth (1+ texinfo-stack-depth)) |
1604 (setq texinfo-stack | 1595 (push (list check arg texinfo-command-start) |
1605 (cons (list check arg texinfo-command-start) | 1596 texinfo-stack)) |
1606 texinfo-stack))) | |
1607 | 1597 |
1608 (defun texinfo-pop-stack (check) | 1598 (defun texinfo-pop-stack (check) |
1609 (setq texinfo-stack-depth (1- texinfo-stack-depth)) | 1599 (setq texinfo-stack-depth (1- texinfo-stack-depth)) |
1610 (if (null texinfo-stack) | 1600 (if (null texinfo-stack) |
1611 (error "Unmatched @end %s" check)) | 1601 (error "Unmatched @end %s" check)) |
1972 @item A1 @tab A2 @tab A3 | 1962 @item A1 @tab A2 @tab A3 |
1973 @item B1 @tab B2 @tab B3 | 1963 @item B1 @tab B2 @tab B3 |
1974 @end multitable | 1964 @end multitable |
1975 | 1965 |
1976 where the fractions specify the width of each column as a percent | 1966 where the fractions specify the width of each column as a percent |
1977 of the current width of the text (i.e., of the fill-column). | 1967 of the current width of the text (i.e., of the `fill-column'). |
1978 | 1968 |
1979 Long lines of text are filled within columns. | 1969 Long lines of text are filled within columns. |
1980 | 1970 |
1981 Using the Emacs Lisp formatter, texinfmt.el, | 1971 Using the Emacs Lisp formatter, texinfmt.el, |
1982 the whitespace between columns can be increased by setting | 1972 the whitespace between columns can be increased by setting |
2026 (error "In @multitable, @columnfractions misspelled")) | 2016 (error "In @multitable, @columnfractions misspelled")) |
2027 ;; Case 1: @columnfractions .25 .3 .45 | 2017 ;; Case 1: @columnfractions .25 .3 .45 |
2028 ((looking-at "@columnfractions") | 2018 ((looking-at "@columnfractions") |
2029 (forward-word 1) | 2019 (forward-word 1) |
2030 (while (not (eolp)) | 2020 (while (not (eolp)) |
2031 (setq texinfo-multitable-width-list | 2021 (push (truncate |
2032 (cons | 2022 (1- |
2033 (truncate | 2023 (* fill-column (read (get-buffer (current-buffer)))))) |
2034 (1- | 2024 texinfo-multitable-width-list))) |
2035 (* fill-column (read (get-buffer (current-buffer)))))) | |
2036 texinfo-multitable-width-list)))) | |
2037 ;; | 2025 ;; |
2038 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example} | 2026 ;; Case 2: {Column 1 template} {Column 2} {Column 3 example} |
2039 ((looking-at "{") | 2027 ((looking-at "{") |
2040 (let ((start-of-templates (point))) | 2028 (let ((start-of-templates (point))) |
2041 (while (not (eolp)) | 2029 (while (not (eolp)) |
2042 (skip-chars-forward " \t") | 2030 (skip-chars-forward " \t") |
2043 (let* ((start-of-template (1+ (point))) | 2031 (let* ((start-of-template (1+ (point))) |
2044 (end-of-template | 2032 (end-of-template |
2045 ;; forward-sexp works with braces in Texinfo mode | 2033 ;; forward-sexp works with braces in Texinfo mode |
2046 (progn (forward-sexp 1) (1- (point))))) | 2034 (progn (forward-sexp 1) (1- (point))))) |
2047 (setq texinfo-multitable-width-list | 2035 (push (- end-of-template start-of-template) |
2048 (cons (- end-of-template start-of-template) | 2036 texinfo-multitable-width-list) |
2049 texinfo-multitable-width-list)) | |
2050 ;; Remove carriage return from within a template, if any. | 2037 ;; Remove carriage return from within a template, if any. |
2051 ;; This helps those those who want to use more than | 2038 ;; This helps those those who want to use more than |
2052 ;; one line's worth of words in @multitable line. | 2039 ;; one line's worth of words in @multitable line. |
2053 (narrow-to-region start-of-template end-of-template) | 2040 (narrow-to-region start-of-template end-of-template) |
2054 (goto-char (point-min)) | 2041 (goto-char (point-min)) |
2415 (let* ((args (texinfo-format-parse-line-args)) | 2402 (let* ((args (texinfo-format-parse-line-args)) |
2416 (command-name (nth 0 args)) | 2403 (command-name (nth 0 args)) |
2417 (beginning-delimiter (or (nth 1 args) "")) | 2404 (beginning-delimiter (or (nth 1 args) "")) |
2418 (end-delimiter (or (nth 2 args) ""))) | 2405 (end-delimiter (or (nth 2 args) ""))) |
2419 (texinfo-discard-command) | 2406 (texinfo-discard-command) |
2420 (setq texinfo-enclosure-list | 2407 (push (list command-name |
2421 (cons | 2408 (list |
2422 (list command-name | 2409 beginning-delimiter |
2423 (list | 2410 end-delimiter)) |
2424 beginning-delimiter | 2411 texinfo-enclosure-list))) |
2425 end-delimiter)) | |
2426 texinfo-enclosure-list)))) | |
2427 | 2412 |
2428 | 2413 |
2429 ;;; @alias | 2414 ;;; @alias |
2430 | 2415 |
2431 (put 'alias 'texinfo-format 'texinfo-alias) | 2416 (put 'alias 'texinfo-format 'texinfo-alias) |
2434 args) | 2419 args) |
2435 (skip-chars-forward " ") | 2420 (skip-chars-forward " ") |
2436 (save-excursion (end-of-line) (setq texinfo-command-end (point))) | 2421 (save-excursion (end-of-line) (setq texinfo-command-end (point))) |
2437 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)")) | 2422 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)")) |
2438 (error "Invalid alias command") | 2423 (error "Invalid alias command") |
2439 (setq texinfo-alias-list | 2424 (push (cons |
2440 (cons | 2425 (match-string-no-properties 1) |
2441 (cons | 2426 (match-string-no-properties 2)) |
2442 (match-string-no-properties 1) | 2427 texinfo-alias-list) |
2443 (match-string-no-properties 2)) | |
2444 texinfo-alias-list)) | |
2445 (texinfo-discard-command)) | 2428 (texinfo-discard-command)) |
2446 ) | 2429 ) |
2447 ) | 2430 ) |
2448 | 2431 |
2449 | 2432 |
2568 "example\\|" | 2551 "example\\|" |
2569 "smallexample\\|" | 2552 "smallexample\\|" |
2570 "lisp\\|" | 2553 "lisp\\|" |
2571 "smalllisp" | 2554 "smalllisp" |
2572 "\\)") | 2555 "\\)") |
2573 "Regexp specifying environments in which @kbd does not put `...' | 2556 "Regexp matching environments in which @kbd does not put `...' around arg.") |
2574 around argument.") | |
2575 | 2557 |
2576 (defvar texinfo-format-kbd-end-regexp | 2558 (defvar texinfo-format-kbd-end-regexp |
2577 (concat | 2559 (concat |
2578 "^@end " | 2560 "^@end " |
2579 "\\(" | 2561 "\\(" |
2582 "smallexample\\|" | 2564 "smallexample\\|" |
2583 "lisp\\|" | 2565 "lisp\\|" |
2584 "smalllisp" | 2566 "smalllisp" |
2585 "\\)") | 2567 "\\)") |
2586 "Regexp specifying end of environments in which @kbd does not put `...' | 2568 "Regexp specifying end of environments in which @kbd does not put `...' |
2587 around argument. (See `texinfo-format-kbd-regexp')") | 2569 around argument. (See `texinfo-format-kbd-regexp')") |
2588 | 2570 |
2589 (put 'kbd 'texinfo-format 'texinfo-format-kbd) | 2571 (put 'kbd 'texinfo-format 'texinfo-format-kbd) |
2590 (defun texinfo-format-kbd () | 2572 (defun texinfo-format-kbd () |
2591 "Place single quote marks around arg, except in @example and similar." | 2573 "Place single quote marks around arg, except in @example and similar." |
2592 ;; Search forward for @end example closer than an @example. | 2574 ;; Search forward for @end example closer than an @example. |
2791 (insert "#")) | 2773 (insert "#")) |
2792 | 2774 |
2793 | 2775 |
2794 ;;; Refilling and indenting: @refill, @paragraphindent, @noindent | 2776 ;;; Refilling and indenting: @refill, @paragraphindent, @noindent |
2795 | 2777 |
2796 ;;; Indent only those paragraphs that are refilled as a result of an | 2778 ;; Indent only those paragraphs that are refilled as a result of an |
2797 ;;; @refill command. | 2779 ;; @refill command. |
2798 | 2780 |
2799 ;; * If the value is `asis', do not change the existing indentation at | 2781 ;; * If the value is `asis', do not change the existing indentation at |
2800 ;; the starts of paragraphs. | 2782 ;; the starts of paragraphs. |
2801 | 2783 |
2802 ;; * If the value zero, delete any existing indentation. | 2784 ;; * If the value zero, delete any existing indentation. |
2803 | 2785 |
2804 ;; * If the value is greater than zero, indent each paragraph by that | 2786 ;; * If the value is greater than zero, indent each paragraph by that |
2805 ;; number of spaces. | 2787 ;; number of spaces. |
2806 | 2788 |
2807 ;;; But do not refill paragraphs with an @refill command that are | 2789 ;; But do not refill paragraphs with an @refill command that are |
2808 ;;; preceded by @noindent or are part of a table, list, or deffn. | 2790 ;; preceded by @noindent or are part of a table, list, or deffn. |
2809 | 2791 |
2810 (defvar texinfo-paragraph-indent "asis" | 2792 (defvar texinfo-paragraph-indent "asis" |
2811 "Number of spaces for @refill to indent a paragraph; else to leave as is.") | 2793 "Number of spaces for @refill to indent a paragraph; else to leave as is.") |
2812 | 2794 |
2813 (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent) | 2795 (put 'paragraphindent 'texinfo-format 'texinfo-paragraphindent) |
2820 (setq texinfo-paragraph-indent "asis") | 2802 (setq texinfo-paragraph-indent "asis") |
2821 (setq texinfo-paragraph-indent (string-to-number arg))))) | 2803 (setq texinfo-paragraph-indent (string-to-number arg))))) |
2822 | 2804 |
2823 (put 'refill 'texinfo-format 'texinfo-format-refill) | 2805 (put 'refill 'texinfo-format 'texinfo-format-refill) |
2824 (defun texinfo-format-refill () | 2806 (defun texinfo-format-refill () |
2825 "Refill paragraph. Also, indent first line as set by @paragraphindent. | 2807 "Refill paragraph. Also, indent first line as set by @paragraphindent. |
2826 Default is to leave paragraph indentation as is." | 2808 Default is to leave paragraph indentation as is." |
2827 (texinfo-discard-command) | 2809 (texinfo-discard-command) |
2828 (let ((position (point-marker))) | 2810 (let ((position (point-marker))) |
2829 (forward-paragraph -1) | 2811 (forward-paragraph -1) |
2830 (if (looking-at "[ \t\n]*$") (forward-line 1)) | 2812 (if (looking-at "[ \t\n]*$") (forward-line 1)) |
2939 'texinfo-format | 2921 'texinfo-format |
2940 index-formatting-command) ; eg, texinfo-format-aaindex | 2922 index-formatting-command) ; eg, texinfo-format-aaindex |
2941 | 2923 |
2942 ;; eg: "aa" . texinfo-aaindex | 2924 ;; eg: "aa" . texinfo-aaindex |
2943 (or (assoc index-name texinfo-indexvar-alist) | 2925 (or (assoc index-name texinfo-indexvar-alist) |
2944 (setq texinfo-indexvar-alist | 2926 (push (cons index-name |
2945 (cons | 2927 index-alist-name) |
2946 (cons index-name | 2928 texinfo-indexvar-alist)) |
2947 index-alist-name) | |
2948 texinfo-indexvar-alist))) | |
2949 | 2929 |
2950 (fset index-formatting-command | 2930 (fset index-formatting-command |
2951 (list 'lambda 'nil | 2931 (list 'lambda 'nil |
2952 (list 'texinfo-index | 2932 (list 'texinfo-index |
2953 (list 'quote index-alist-name)))))) | 2933 (list 'quote index-alist-name)))))) |
4022 (insert (format "{No value for \"%s\"}" arg)))))) | 4002 (insert (format "{No value for \"%s\"}" arg)))))) |
4023 | 4003 |
4024 (put 'ifset 'texinfo-end 'texinfo-discard-command) | 4004 (put 'ifset 'texinfo-end 'texinfo-discard-command) |
4025 (put 'ifset 'texinfo-format 'texinfo-if-set) | 4005 (put 'ifset 'texinfo-format 'texinfo-if-set) |
4026 (defun texinfo-if-set () | 4006 (defun texinfo-if-set () |
4027 "If set, continue formatting; else do not format region up to @end ifset" | 4007 "If set, continue formatting; else do not format region up to @end ifset." |
4028 (let ((arg (texinfo-parse-arg-discard))) | 4008 (let ((arg (texinfo-parse-arg-discard))) |
4029 (cond | 4009 (cond |
4030 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) | 4010 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) |
4031 'flag-set) | 4011 'flag-set) |
4032 ;; Format the text (i.e., do not remove it); do nothing here. | 4012 ;; Format the text (i.e., do not remove it); do nothing here. |
4043 ())))) | 4023 ())))) |
4044 | 4024 |
4045 (put 'ifclear 'texinfo-end 'texinfo-discard-command) | 4025 (put 'ifclear 'texinfo-end 'texinfo-discard-command) |
4046 (put 'ifclear 'texinfo-format 'texinfo-if-clear) | 4026 (put 'ifclear 'texinfo-format 'texinfo-if-clear) |
4047 (defun texinfo-if-clear () | 4027 (defun texinfo-if-clear () |
4048 "If clear, continue formatting; if set, do not format up to @end ifset" | 4028 "If clear, continue formatting; if set, do not format up to @end ifset." |
4049 (let ((arg (texinfo-parse-arg-discard))) | 4029 (let ((arg (texinfo-parse-arg-discard))) |
4050 (cond | 4030 (cond |
4051 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) | 4031 ((eq (get (car (read-from-string arg)) 'texinfo-whether-setp) |
4052 'flag-set) | 4032 'flag-set) |
4053 ;; Clear region (i.e., cause the text to be ignored). | 4033 ;; Clear region (i.e., cause the text to be ignored). |
4289 (buffer-substring-no-properties texinfo-command-start texinfo-command-end))) | 4269 (buffer-substring-no-properties texinfo-command-start texinfo-command-end))) |
4290 | 4270 |
4291 ;;; Batch formatting | 4271 ;;; Batch formatting |
4292 | 4272 |
4293 (defun batch-texinfo-format () | 4273 (defun batch-texinfo-format () |
4294 "Runs texinfo-format-buffer on the files remaining on the command line. | 4274 "Run `texinfo-format-buffer' on the files remaining on the command line. |
4295 Must be used only with -batch, and kills Emacs on completion. | 4275 Must be used only with -batch, and kills Emacs on completion. |
4296 Each file will be processed even if an error occurred previously. | 4276 Each file will be processed even if an error occurred previously. |
4297 For example, invoke | 4277 For example, invoke |
4298 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"." | 4278 \"emacs -batch -funcall batch-texinfo-format $docs/ ~/*.texinfo\"." |
4299 (if (not noninteractive) | 4279 (if (not noninteractive) |
4315 ((file-directory-p file) | 4295 ((file-directory-p file) |
4316 (setq command-line-args-left | 4296 (setq command-line-args-left |
4317 (nconc (directory-files file) | 4297 (nconc (directory-files file) |
4318 (cdr command-line-args-left)))) | 4298 (cdr command-line-args-left)))) |
4319 (t | 4299 (t |
4320 (setq files (cons file files) | 4300 (push file files) |
4321 command-line-args-left (cdr command-line-args-left))))) | 4301 (setq command-line-args-left (cdr command-line-args-left))))) |
4322 (while files | 4302 (while files |
4323 (setq file (car files) | 4303 (setq file (car files) |
4324 files (cdr files)) | 4304 files (cdr files)) |
4325 (condition-case err | 4305 (condition-case err |
4326 (progn | 4306 (progn |
4352 | 4332 |
4353 | 4333 |
4354 ;;; Place `provide' at end of file. | 4334 ;;; Place `provide' at end of file. |
4355 (provide 'texinfmt) | 4335 (provide 'texinfmt) |
4356 | 4336 |
4357 ;;; arch-tag: 1e8d9a2d-bca0-40a0-ac6c-dab01bc6f725 | 4337 ;; arch-tag: 1e8d9a2d-bca0-40a0-ac6c-dab01bc6f725 |
4358 ;;; texinfmt.el ends here | 4338 ;;; texinfmt.el ends here |