📄 texinfmt.el
字号:
;;; texinfmt.el --- format Texinfo files into Info files.;; Copyright (C) 1985, 1986, 1988, 1990, 1991, 1992, 1993, ;; 1994, 1995, 1996, 1997 Free Software Foundation, Inc.;; Maintainer: Robert J. Chassell <bug-texinfo@prep.ai.mit.edu>;; Keywords: maint, tex, docs;; This file is part of GNU Emacs.;; GNU Emacs is free software; you can redistribute it and/or modify;; it under the terms of the GNU General Public License as published by;; the Free Software Foundation; either version 2, or (at your option);; any later version.;; GNU Emacs is distributed in the hope that it will be useful,;; but WITHOUT ANY WARRANTY; without even the implied warranty of;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the;; GNU General Public License for more details.;; You should have received a copy of the GNU General Public License;; along with GNU Emacs; see the file COPYING. If not, write to the;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,;; Boston, MA 02111-1307, USA.;;; Code:;;; Emacs lisp functions to convert Texinfo files to Info files.(defvar texinfmt-version "2.37 of 24 May 1997")(defun texinfmt-version (&optional here) "Show the version of texinfmt.el in the minibuffer.If optional argument HERE is non-nil, insert info at point." (interactive "P") (let ((version-string (format "Version of \`texinfmt.el\': %s" texinfmt-version))) (if here (insert version-string) (if (interactive-p) (message "%s" version-string) version-string))));;; Variable definitions(require 'texinfo) ; So `texinfo-footnote-style' is defined.(require 'texnfo-upd) ; So `texinfo-section-types-regexp' is defined.(defvar texinfo-format-syntax-table nil)(defvar texinfo-vindex)(defvar texinfo-findex)(defvar texinfo-cindex)(defvar texinfo-pindex)(defvar texinfo-tindex)(defvar texinfo-kindex)(defvar texinfo-last-node)(defvar texinfo-node-names)(defvar texinfo-enclosure-list)(defvar texinfo-alias-list)(defvar texinfo-command-start)(defvar texinfo-command-end)(defvar texinfo-command-name)(defvar texinfo-defun-type)(defvar texinfo-last-node-pos)(defvar texinfo-stack)(defvar texinfo-short-index-cmds-alist)(defvar texinfo-short-index-format-cmds-alist)(defvar texinfo-format-filename)(defvar texinfo-footnote-number)(defvar texinfo-start-of-header)(defvar texinfo-end-of-header)(defvar texinfo-raisesections-alist)(defvar texinfo-lowersections-alist);;; Syntax table(if texinfo-format-syntax-table nil (setq texinfo-format-syntax-table (make-syntax-table)) (modify-syntax-entry ?\" " " texinfo-format-syntax-table) (modify-syntax-entry ?\\ " " texinfo-format-syntax-table) (modify-syntax-entry ?@ "\\" texinfo-format-syntax-table) (modify-syntax-entry ?\^q "\\" texinfo-format-syntax-table) (modify-syntax-entry ?\[ "." texinfo-format-syntax-table) (modify-syntax-entry ?\] "." texinfo-format-syntax-table) (modify-syntax-entry ?\( "." texinfo-format-syntax-table) (modify-syntax-entry ?\) "." texinfo-format-syntax-table) (modify-syntax-entry ?{ "(}" texinfo-format-syntax-table) (modify-syntax-entry ?} "){" texinfo-format-syntax-table) (modify-syntax-entry ?\' "." texinfo-format-syntax-table));;; Top level buffer and region formatting functions;;;###autoload(defun texinfo-format-buffer (&optional notagify) "Process the current buffer as texinfo code, into an Info file.The Info file output is generated in a buffer visiting the Info filename specified in the @setfilename command.Non-nil argument (prefix, if interactive) means don't make tag tableand don't split the file if large. You can use Info-tagify andInfo-split to do these manually." (interactive "P") (let ((lastmessage "Formatting Info file...")) (message lastmessage) (texinfo-format-buffer-1) (if notagify nil (if (> (buffer-size) 30000) (progn (message (setq lastmessage "Making tags table for Info file...")) (Info-tagify))) (if (> (buffer-size) 100000) (progn (message (setq lastmessage "Splitting Info file...")) (Info-split)))) (message (concat lastmessage (if (interactive-p) "done. Now save it." "done.")))))(defvar texinfo-region-buffer-name "*Info Region*" "*Name of the temporary buffer used by \\[texinfo-format-region].");;;###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 isconverted 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 (save-excursion (forward-line 100) (point)))) (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 (min header-beginning region-beginning) header-end))))));;; Find a buffer to use. (switch-to-buffer (get-buffer-create texinfo-region-buffer-name)) (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) ;; 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) (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))))))))) ;; 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) (save-excursion (forward-line 1) (point)))) ;; Insert Info region title text. (goto-char (point-min)) (if (search-forward "@setfilename" (save-excursion (forward-line 100) (point)) 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 " buffer for: `") (insert (file-name-nondirectory (expand-file-name arg))) (insert "', -*-Text-*-\n"))) ;; Else no `@setfilename' line (insert " " texinfo-region-buffer-name " buffer -*-Text-*-\n")) (insert "produced by `texinfo-format-region'\n" "from a region in: " (if (buffer-file-name input-buffer) (concat "`" (file-name-sans-versions (file-name-nondirectory (buffer-file-name input-buffer))) "'") (concat "buffer `" (buffer-name input-buffer) "'")) "\nusing `texinfmt.el' version " texinfmt-version ".\n\n") ;; Now convert for real. (goto-char (point-min)) (texinfo-format-scan) (goto-char (point-min)) (message "Done.")));;;###autoload(defun texi2info (&optional notagify) "Convert the current buffer (written in Texinfo code) into an Info file.The Info file output is generated in a buffer visiting the Info filenames specified in the @setfilename command.This function automatically updates all node pointers and menus, andcreates a master menu. This work is done on a temporary buffer thatis automatically removed when the Info file is created. The originalTexinfo source buffer is not changed.Non-nil argument (prefix, if interactive) means don't make tag tableand don't split the file if large. You can use Info-tagify andInfo-split to do these manually." (interactive "P") (let ((temp-buffer (concat "*--" (buffer-name) "--temporary-buffer*" ))) (message "First updating nodes and menus, then creating Info file.") ;; (sit-for 2) (copy-to-buffer temp-buffer (point-min) (point-max)) (switch-to-buffer temp-buffer) (texinfo-master-menu t) (message "Now creating Info file.") (sit-for 2) (texinfo-format-buffer notagify) (save-buffer) (kill-buffer temp-buffer)));;; Primary internal formatting function for the whole buffer.(defun texinfo-format-buffer-1 () (let (texinfo-format-filename texinfo-example-start texinfo-command-start texinfo-command-end texinfo-command-name texinfo-last-node texinfo-last-node-pos texinfo-vindex texinfo-findex texinfo-cindex texinfo-pindex texinfo-tindex texinfo-kindex texinfo-stack texinfo-node-names (texinfo-footnote-number 0) last-input-buffer outfile (fill-column-for-info fill-column) (input-buffer (current-buffer)) (input-directory default-directory)) (setq texinfo-enclosure-list nil) (setq texinfo-alias-list nil) (save-excursion (goto-char (point-min)) (or (search-forward "@setfilename" nil t) (error "Texinfo file needs an `@setfilename FILENAME' line.")) (setq texinfo-command-end (point)) (setq outfile (texinfo-parse-line-arg))) (find-file outfile) (texinfo-mode) (setq fill-column fill-column-for-info) (set-syntax-table texinfo-format-syntax-table) (erase-buffer) (insert-buffer-substring input-buffer) (message "Converting %s to Info format..." (buffer-name input-buffer)) ;; Insert @include files so `texinfo-raise-lower-sections' can ;; work on them without losing track of multiple ;; @raise/@lowersections commands. (goto-char (point-min)) (while (re-search-forward "^@include" nil t)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -