Function: texinfo-format-region
texinfo-format-region is an autoloaded, interactive and byte-compiled
function defined in texinfmt.el.gz.
Signature
(texinfo-format-region REGION-BEGINNING REGION-END)
Documentation
Convert the current region of the Texinfo file to Info format.
This lets you see what that part of the file will look like in Info.
The command is bound to M-x texinfo-format-region (texinfo-format-region). The text that is
converted to Info is stored in a temporary buffer.
Probably introduced at or before Emacs version 18.52.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/texinfmt.el.gz
;;;###autoload
(defun texinfo-format-region (region-beginning region-end)
"Convert the current region of the Texinfo file to Info format.
This lets you see what that part of the file will look like in Info.
The command is bound to \\[texinfo-format-region]. The text that is
converted to Info is stored in a temporary buffer."
(interactive "r")
(message "Converting region to Info format...")
(let (texinfo-command-start
texinfo-command-end
texinfo-command-name
texinfo-vindex
texinfo-findex
texinfo-cindex
texinfo-pindex
texinfo-tindex
texinfo-kindex
texinfo-stack
(texinfo-format-filename "")
texinfo-example-start
texinfo-last-node-pos
texinfo-last-node
texinfo-node-names
(texinfo-footnote-number 0)
;; last-input-buffer
(fill-column-for-info fill-column)
(input-buffer (current-buffer))
(input-directory default-directory)
(header-text "")
(header-beginning 1)
(header-end 1))
;;; Copy lines between beginning and end of header lines,
;;; if any, or else copy the `@setfilename' line, if any.
(save-excursion
(save-restriction
(widen)
(goto-char (point-min))
(let ((search-end (line-beginning-position 101)))
(if (or
;; Either copy header text.
(and
(prog1
(search-forward tex-start-of-header search-end t)
(forward-line 1)
;; Mark beginning of header.
(setq header-beginning (point)))
(prog1
(search-forward tex-end-of-header nil t)
(beginning-of-line)
;; Mark end of header
(setq header-end (point))))
;; Or copy @filename line.
(prog2
(goto-char (point-min))
(search-forward "@setfilename" search-end t)
(beginning-of-line)
(setq header-beginning (point))
(forward-line 1)
(setq header-end (point))))
;; Copy header
(setq header-text
(buffer-substring-no-properties
(min header-beginning region-beginning)
header-end))))))
;;; Find a buffer to use.
(switch-to-buffer (get-buffer-create texinfo-region-buffer-name))
(setq buffer-read-only t)
(let ((inhibit-read-only t))
(erase-buffer)
;; Insert the header into the buffer.
(insert header-text)
;; Insert the region into the buffer.
(insert-buffer-substring
input-buffer
(max region-beginning header-end)
region-end)
(run-hook-with-args 'texinfo-pre-format-hook input-buffer)
;; Make sure region ends in a newline.
(or (= (preceding-char) ?\n)
(insert "\n"))
(goto-char (point-min))
(texinfo-mode)
(message "Converting region to Info format...")
(setq fill-column fill-column-for-info)
;; Install a syntax table useful for scanning command operands.
(set-syntax-table texinfo-format-syntax-table)
;; Insert @include files so `texinfo-raise-lower-sections' can
;; work on them without losing track of multiple
;; @raise/@lowersections commands.
(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) (line-beginning-position 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" (line-end-position 100) t)
(delete-region (line-beginning-position 1)
(line-beginning-position 2)))))))
;; Raise or lower level of each section, if necessary.
(goto-char (point-min))
(texinfo-raise-lower-sections)
;; Append @refill to appropriate paragraphs for filling.
(goto-char (point-min))
(texinfo-append-refill)
;; If the region includes the effective end of the data,
;; discard everything after that.
(goto-char (point-max))
(if (re-search-backward "^@bye" nil t)
(delete-region (point) (point-max)))
;; Make sure buffer ends in a newline.
(or (= (preceding-char) ?\n)
(insert "\n"))
;; Don't use a previous value of texinfo-enclosure-list.
(setq texinfo-enclosure-list nil)
(setq texinfo-alias-list nil)
(goto-char (point-min))
(if (looking-at "\\\\input[ \t]+texinfo")
(delete-region (point) (line-beginning-position 2)))
;; Insert Info region title text.
(goto-char (point-min))
(if (search-forward "@setfilename" (line-beginning-position 101) t)
(progn
(setq texinfo-command-end (point))
(beginning-of-line)
(setq texinfo-command-start (point))
(let ((arg (texinfo-parse-arg-discard)))
(insert " "
texinfo-region-buffer-name
(format-message " buffer for: `"))
(insert (file-name-nondirectory (expand-file-name arg)))
(insert (format-message "', -*-Text-*-\n"))))
;; Else no `@setfilename' line
(insert " "
texinfo-region-buffer-name
" buffer -*-Text-*-\n"))
(insert (format-message "produced by `texinfo-format-region'\n")
"from a region in: "
(if (buffer-file-name input-buffer)
(format-message "`%s'"
(file-name-sans-versions
(file-name-nondirectory
(buffer-file-name input-buffer))))
(format-message "buffer `%s'" (buffer-name input-buffer)))
(format-message "\nusing `texinfmt.el' on Emacs version ")
emacs-version
".\n\n")
;; Now convert for real.
(goto-char (point-min))
(texinfo-format-scan)
(goto-char (point-min))
(Info-tagify input-buffer)
(goto-char (point-min))
(message "Done."))))