comparison lisp/textmodes/texinfmt.el @ 48518:0eb01081d9f5

(texinfo-format-separate-node): Handle node names with properties and with regular expression symbols in them.
author Robert J. Chassell <bob@rattlesnake.com>
date Sun, 24 Nov 2002 01:39:02 +0000
parents 4cef5030d270
children ba7e7cf495b0
comparison
equal deleted inserted replaced
48517:2941d71711f3 48518:0eb01081d9f5
195 (forward-line 1) 195 (forward-line 1)
196 (setq header-end (point)))) 196 (setq header-end (point))))
197 197
198 ;; Copy header 198 ;; Copy header
199 (setq header-text 199 (setq header-text
200 (buffer-substring 200 (buffer-substring-no-properties
201 (min header-beginning region-beginning) 201 (min header-beginning region-beginning)
202 header-end)))))) 202 header-end))))))
203 203
204 ;;; Find a buffer to use. 204 ;;; Find a buffer to use.
205 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name)) 205 (switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
601 (< (point) (point-max))) 601 (< (point) (point-max)))
602 (forward-line 1)) 602 (forward-line 1))
603 ;; 2. Skip over @example and similar no-refill environments. 603 ;; 2. Skip over @example and similar no-refill environments.
604 (if (looking-at texinfo-no-refill-regexp) 604 (if (looking-at texinfo-no-refill-regexp)
605 (let ((environment 605 (let ((environment
606 (buffer-substring (match-beginning 1) (match-end 1)))) 606 (buffer-substring-no-properties (match-beginning 1) (match-end 1))))
607 (progn (re-search-forward (concat "^@end " environment) nil t) 607 (progn (re-search-forward (concat "^@end " environment) nil t)
608 (forward-line 1))) 608 (forward-line 1)))
609 ;; Else 609 ;; Else
610 ;; 3. Do not refill a paragraph containing @w or @*, or ending 610 ;; 3. Do not refill a paragraph containing @w or @*, or ending
611 ;; with @<newline> followed by a newline. 611 ;; with @<newline> followed by a newline.
901 (setq texinfo-command-end (point)) 901 (setq texinfo-command-end (point))
902 ;; Handle let aliasing 902 ;; Handle let aliasing
903 (setq texinfo-command-name 903 (setq texinfo-command-name
904 (let (trial 904 (let (trial
905 (cmdname 905 (cmdname
906 (buffer-substring 906 (buffer-substring-no-properties
907 (1+ texinfo-command-start) texinfo-command-end))) 907 (1+ texinfo-command-start) texinfo-command-end)))
908 (while (setq trial (assoc cmdname texinfo-alias-list)) 908 (while (setq trial (assoc cmdname texinfo-alias-list))
909 (setq cmdname (cdr trial))) 909 (setq cmdname (cdr trial)))
910 (intern cmdname))) 910 (intern cmdname)))
911 ;; Call the handler for this command. 911 ;; Call the handler for this command.
963 (forward-list 1) 963 (forward-list 1)
964 (setq texinfo-command-end (point)) 964 (setq texinfo-command-end (point))
965 (forward-char -1)) 965 (forward-char -1))
966 (t 966 (t
967 (error "Invalid texinfo command arg format"))) 967 (error "Invalid texinfo command arg format")))
968 (prog1 (buffer-substring start (point)) 968 (prog1 (buffer-substring-no-properties start (point))
969 (if (eolp) (forward-char 1))))) 969 (if (eolp) (forward-char 1)))))
970 970
971 (defun texinfo-parse-expanded-arg () 971 (defun texinfo-parse-expanded-arg ()
972 (goto-char texinfo-command-end) 972 (goto-char texinfo-command-end)
973 (let ((start (point)) 973 (let ((start (point))
986 (error "Invalid texinfo command arg format"))) 986 (error "Invalid texinfo command arg format")))
987 (setq marker (move-marker (make-marker) texinfo-command-end)) 987 (setq marker (move-marker (make-marker) texinfo-command-end))
988 (texinfo-format-expand-region start (point)) 988 (texinfo-format-expand-region start (point))
989 (setq texinfo-command-end (marker-position marker)) 989 (setq texinfo-command-end (marker-position marker))
990 (move-marker marker nil) 990 (move-marker marker nil)
991 (prog1 (buffer-substring start (point)) 991 (prog1 (buffer-substring-no-properties start (point))
992 (if (eolp) (forward-char 1))))) 992 (if (eolp) (forward-char 1)))))
993 993
994 (defun texinfo-format-expand-region (start end) 994 (defun texinfo-format-expand-region (start end)
995 (save-restriction 995 (save-restriction
996 (narrow-to-region start end) 996 (narrow-to-region start end)
1033 (setq next (point)) 1033 (setq next (point))
1034 (if (bolp) (setq next (1- next))) 1034 (if (bolp) (setq next (1- next)))
1035 (forward-char -1) 1035 (forward-char -1)
1036 (skip-chars-backward " ") 1036 (skip-chars-backward " ")
1037 (setq end (point)) 1037 (setq end (point))
1038 (setq args (cons (if (> end beg) (buffer-substring beg end)) 1038 (setq args (cons (if (> end beg) (buffer-substring-no-properties beg end))
1039 args)) 1039 args))
1040 (goto-char next) 1040 (goto-char next)
1041 (skip-chars-forward " ")) 1041 (skip-chars-forward " "))
1042 (if (eolp) (forward-char 1)) 1042 (if (eolp) (forward-char 1))
1043 (setq texinfo-command-end (point)) 1043 (setq texinfo-command-end (point))
1066 (setq end (point)) 1066 (setq end (point))
1067 (cond ((< beg end) 1067 (cond ((< beg end)
1068 (goto-char beg) 1068 (goto-char beg)
1069 (while (search-forward "\n" end t) 1069 (while (search-forward "\n" end t)
1070 (replace-match " ")))) 1070 (replace-match " "))))
1071 (setq args (cons (if (> end beg) (buffer-substring beg end)) 1071 (setq args (cons (if (> end beg) (buffer-substring-no-properties beg end))
1072 args)) 1072 args))
1073 (goto-char next)) 1073 (goto-char next))
1074 ;;(if (eolp) (forward-char 1)) 1074 ;;(if (eolp) (forward-char 1))
1075 (setq texinfo-command-end (point)) 1075 (setq texinfo-command-end (point))
1076 (nreverse args))) 1076 (nreverse args)))
1096 (t 1096 (t
1097 (setq beg (point)) 1097 (setq beg (point))
1098 (re-search-forward "[\n ]") 1098 (re-search-forward "[\n ]")
1099 (forward-char -1) 1099 (forward-char -1)
1100 (setq end (point)))) 1100 (setq end (point))))
1101 (setq args (cons (buffer-substring beg end) args)) 1101 (setq args (cons (buffer-substring-no-properties beg end) args))
1102 (skip-chars-forward " ")) 1102 (skip-chars-forward " "))
1103 (forward-char 1) 1103 (forward-char 1)
1104 (nreverse args)))) 1104 (nreverse args))))
1105 1105
1106 (defun texinfo-discard-line () 1106 (defun texinfo-discard-line ()
1441 (re-search-backward 1441 (re-search-backward
1442 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:") 1442 "^File: \\w+\\(\\w\\|\\s_\\|\\.\\|,\\)*[ \t]+Node:")
1443 (match-end 0))) 1443 (match-end 0)))
1444 (node-name 1444 (node-name
1445 (save-excursion 1445 (save-excursion
1446 (buffer-substring 1446 (buffer-substring-no-properties
1447 (progn (goto-char node-name-beginning) ; skip over node command 1447 (progn (goto-char node-name-beginning) ; skip over node command
1448 (skip-chars-forward " \t") ; and over spaces 1448 (skip-chars-forward " \t") ; and over spaces
1449 (point)) 1449 (point))
1450 (if (search-forward 1450 (if (search-forward
1451 "," 1451 ","
1465 ;; two cases: for the first footnote, we must insert a node header; 1465 ;; two cases: for the first footnote, we must insert a node header;
1466 ;; for the second and subsequent footnotes, we need only insert 1466 ;; for the second and subsequent footnotes, we need only insert
1467 ;; the text of the footnote. 1467 ;; the text of the footnote.
1468 1468
1469 (if (save-excursion 1469 (if (save-excursion
1470 (re-search-backward 1470 (search-backward
1471 (concat node-name "-Footnotes, Up: ") 1471 (concat node-name "-Footnotes, Up: ")
1472 node-name-beginning 1472 node-name-beginning
1473 t)) 1473 t))
1474 (progn ; already at least one footnote 1474 (progn ; already at least one footnote
1475 (setq start (point)) 1475 (setq start (point))
2014 (match-beginning 0))) 2014 (match-beginning 0)))
2015 (row (progn (goto-char end) 2015 (row (progn (goto-char end)
2016 (skip-chars-backward " ") 2016 (skip-chars-backward " ")
2017 ;; remove whitespace at end of argument 2017 ;; remove whitespace at end of argument
2018 (delete-region (point) end) 2018 (delete-region (point) end)
2019 (buffer-substring start (point))))) 2019 (buffer-substring-no-properties start (point)))))
2020 (delete-region texinfo-command-start end) 2020 (delete-region texinfo-command-start end)
2021 row)) 2021 row))
2022 2022
2023 (put 'multitable 'texinfo-item 'texinfo-multitable-item) 2023 (put 'multitable 'texinfo-item 'texinfo-multitable-item)
2024 (defun texinfo-multitable-item () 2024 (defun texinfo-multitable-item ()
2326 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)")) 2326 (if (not (looking-at "\\([^=]+\\)=\\(.*\\)"))
2327 (error "Invalid alias command") 2327 (error "Invalid alias command")
2328 (setq texinfo-alias-list 2328 (setq texinfo-alias-list
2329 (cons 2329 (cons
2330 (cons 2330 (cons
2331 (buffer-substring (match-beginning 1) (match-end 1)) 2331 (buffer-substring-no-properties (match-beginning 1) (match-end 1))
2332 (buffer-substring (match-beginning 2) (match-end 2))) 2332 (buffer-substring-no-properties (match-beginning 2) (match-end 2)))
2333 texinfo-alias-list)) 2333 texinfo-alias-list))
2334 (texinfo-discard-command)) 2334 (texinfo-discard-command))
2335 ) 2335 )
2336 ) 2336 )
2337 2337
2866 2866
2867 ;; Subroutine for sorting an index. 2867 ;; Subroutine for sorting an index.
2868 ;; At start of a line, return a string to sort the line under. 2868 ;; At start of a line, return a string to sort the line under.
2869 (defun texinfo-sort-startkeyfun () 2869 (defun texinfo-sort-startkeyfun ()
2870 (let ((line 2870 (let ((line
2871 (buffer-substring (point) (save-excursion (end-of-line) (point))))) 2871 (buffer-substring-no-properties (point) (save-excursion (end-of-line) (point)))))
2872 ;; Canonicalize whitespace and eliminate funny chars. 2872 ;; Canonicalize whitespace and eliminate funny chars.
2873 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line) 2873 (while (string-match "[ \t][ \t]+\\|[^a-z0-9 ]+" line)
2874 (setq line (concat (substring line 0 (match-beginning 0)) 2874 (setq line (concat (substring line 0 (match-beginning 0))
2875 " " 2875 " "
2876 (substring line (match-end 0) (length line))))) 2876 (substring line (match-end 0) (length line)))))
3955 (forward-char 1) 3955 (forward-char 1)
3956 (skip-chars-forward " ") 3956 (skip-chars-forward " ")
3957 (setq start (point)) 3957 (setq start (point))
3958 (search-forward "," stop t) 3958 (search-forward "," stop t)
3959 (skip-chars-backward ", ") 3959 (skip-chars-backward ", ")
3960 (buffer-substring start (point)))) 3960 (buffer-substring-no-properties start (point))))
3961 (arg2 3961 (arg2
3962 (progn 3962 (progn
3963 (search-forward "," stop t) 3963 (search-forward "," stop t)
3964 (skip-chars-forward " ") 3964 (skip-chars-forward " ")
3965 (setq start (point)) 3965 (setq start (point))
3966 (search-forward "," stop t) 3966 (search-forward "," stop t)
3967 (skip-chars-backward ", ") 3967 (skip-chars-backward ", ")
3968 (buffer-substring start (point)))) 3968 (buffer-substring-no-properties start (point))))
3969 (texinfo-command 3969 (texinfo-command
3970 (progn 3970 (progn
3971 (search-forward "," stop t) 3971 (search-forward "," stop t)
3972 (skip-chars-forward " ") 3972 (skip-chars-forward " ")
3973 (setq start (point)) 3973 (setq start (point))
3974 (goto-char (1- stop)) 3974 (goto-char (1- stop))
3975 (skip-chars-backward " ") 3975 (skip-chars-backward " ")
3976 (buffer-substring start (point))))) 3976 (buffer-substring-no-properties start (point)))))
3977 (delete-region texinfo-command-start stop) 3977 (delete-region texinfo-command-start stop)
3978 (if (equal arg1 arg2) 3978 (if (equal arg1 arg2)
3979 (insert texinfo-command)) 3979 (insert texinfo-command))
3980 (goto-char texinfo-command-start))) 3980 (goto-char texinfo-command-start)))
3981 3981
4147 4147
4148 ;;; Some commands cannot be handled 4148 ;;; Some commands cannot be handled
4149 4149
4150 (defun texinfo-unsupported () 4150 (defun texinfo-unsupported ()
4151 (error "%s is not handled by texinfo" 4151 (error "%s is not handled by texinfo"
4152 (buffer-substring texinfo-command-start texinfo-command-end))) 4152 (buffer-substring-no-properties texinfo-command-start texinfo-command-end)))
4153 4153
4154 ;;; Batch formatting 4154 ;;; Batch formatting
4155 4155
4156 (defun batch-texinfo-format () 4156 (defun batch-texinfo-format ()
4157 "Runs texinfo-format-buffer on the files remaining on the command line. 4157 "Runs texinfo-format-buffer on the files remaining on the command line.
4198 (progn (message "Saving modified %s" (buffer-file-name)) 4198 (progn (message "Saving modified %s" (buffer-file-name))
4199 (save-buffer)))) 4199 (save-buffer))))
4200 (error 4200 (error
4201 (message ">> Error: %s" (prin1-to-string err)) 4201 (message ">> Error: %s" (prin1-to-string err))
4202 (message ">> point at") 4202 (message ">> point at")
4203 (let ((s (buffer-substring (point) 4203 (let ((s (buffer-substring-no-properties (point)
4204 (min (+ (point) 100) 4204 (min (+ (point) 100)
4205 (point-max)))) 4205 (point-max))))
4206 (tem 0)) 4206 (tem 0))
4207 (while (setq tem (string-match "\n+" s tem)) 4207 (while (setq tem (string-match "\n+" s tem))
4208 (setq s (concat (substring s 0 (match-beginning 0)) 4208 (setq s (concat (substring s 0 (match-beginning 0))