texinfo.el 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  1. ;;; texinfo.el --- major mode for editing Texinfo files
  2. ;; Copyright (C) 1985, 1988-1993, 1996-1997, 2000-2017 Free Software
  3. ;; Foundation, Inc.
  4. ;; Author: Robert J. Chassell
  5. ;; Date: [See date below for texinfo-version]
  6. ;; Maintainer: emacs-devel@gnu.org
  7. ;; Keywords: maint, tex, docs
  8. ;; This file is part of GNU Emacs.
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Todo:
  20. ;; - facemenu support.
  21. ;; - command completion.
  22. ;;; Commentary:
  23. ;;; Code:
  24. (eval-when-compile (require 'tex-mode))
  25. (declare-function tex-buffer "tex-mode" ())
  26. (declare-function tex-region "tex-mode" (beg end))
  27. (declare-function tex-send-command "tex-mode")
  28. (declare-function tex-recenter-output-buffer "tex-mode" (linenum))
  29. (declare-function tex-print "tex-mode" (&optional alt))
  30. (declare-function tex-view "tex-mode" ())
  31. (declare-function tex-shell-running "tex-mode" ())
  32. (declare-function tex-kill-job "tex-mode" ())
  33. (defvar outline-heading-alist)
  34. (defvar skeleton-end-newline)
  35. (defgroup texinfo nil
  36. "Texinfo Mode."
  37. :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
  38. :group 'docs)
  39. ;;;###autoload
  40. (defcustom texinfo-open-quote (purecopy "``")
  41. "String inserted by typing \\[texinfo-insert-quote] to open a quotation."
  42. :type 'string
  43. :group 'texinfo)
  44. ;;;###autoload
  45. (defcustom texinfo-close-quote (purecopy "''")
  46. "String inserted by typing \\[texinfo-insert-quote] to close a quotation."
  47. :type 'string
  48. :group 'texinfo)
  49. (defcustom texinfo-mode-hook nil
  50. "Normal hook run when entering Texinfo mode."
  51. :type 'hook
  52. :options '(turn-on-auto-fill flyspell-mode)
  53. :group 'texinfo)
  54. ;;; Autoloads:
  55. (autoload 'makeinfo-region
  56. "makeinfo"
  57. "Make Info file from region of current Texinfo file, and switch to it.
  58. This command does not offer the `next-error' feature since it would
  59. apply to a temporary file, not the original; use the `makeinfo-buffer'
  60. command to gain use of `next-error'."
  61. t nil)
  62. (autoload 'makeinfo-buffer
  63. "makeinfo"
  64. "Make Info file from current buffer.
  65. Use the \\[next-error] command to move to the next error
  66. \(if there are errors)."
  67. t nil)
  68. (autoload 'kill-compilation
  69. "compile"
  70. "Kill the process made by the \\[compile] command."
  71. t nil)
  72. (autoload 'makeinfo-recenter-compilation-buffer
  73. "makeinfo"
  74. "Redisplay `*compilation*' buffer so most recent output can be seen.
  75. The last line of the buffer is displayed on
  76. line LINE of the window, or centered if LINE is nil."
  77. t nil)
  78. (autoload 'texinfo-update-node
  79. "texnfo-upd"
  80. "Without any prefix argument, update the node in which point is located.
  81. Non-nil argument (prefix, if interactive) means update the nodes in the
  82. marked region.
  83. The functions for creating or updating nodes and menus, and their
  84. keybindings, are:
  85. `texinfo-update-node' (&optional region-p) \\[texinfo-update-node]
  86. `texinfo-every-node-update' () \\[texinfo-every-node-update]
  87. `texinfo-sequential-node-update' (&optional region-p)
  88. `texinfo-make-menu' (&optional region-p) \\[texinfo-make-menu]
  89. `texinfo-all-menus-update' () \\[texinfo-all-menus-update]
  90. `texinfo-master-menu' ()
  91. `texinfo-indent-menu-description' (column &optional region-p)
  92. The `texinfo-column-for-description' variable specifies the column to
  93. which menu descriptions are indented. Its default value is 32."
  94. t nil)
  95. (autoload 'texinfo-every-node-update
  96. "texnfo-upd"
  97. "Update every node in a Texinfo file."
  98. t nil)
  99. (autoload 'texinfo-sequential-node-update
  100. "texnfo-upd"
  101. "Update one node (or many) in a Texinfo file with sequential pointers.
  102. This function causes the `Next' or `Previous' pointer to point to the
  103. immediately preceding or following node, even if it is at a higher or
  104. lower hierarchical level in the document. Continually pressing `n' or
  105. `p' takes you straight through the file.
  106. Without any prefix argument, update the node in which point is located.
  107. Non-nil argument (prefix, if interactive) means update the nodes in the
  108. marked region.
  109. This command makes it awkward to navigate among sections and
  110. subsections; it should be used only for those documents that are meant
  111. to be read like a novel rather than a reference, and for which the
  112. Info `g*' command is inadequate."
  113. t nil)
  114. (autoload 'texinfo-make-menu
  115. "texnfo-upd"
  116. "Without any prefix argument, make or update a menu.
  117. Make the menu for the section enclosing the node found following point.
  118. Non-nil argument (prefix, if interactive) means make or update menus
  119. for nodes within or part of the marked region.
  120. Whenever a menu exists, and is being updated, the descriptions that
  121. are associated with node names in the pre-existing menu are
  122. incorporated into the new menu. Otherwise, the nodes' section titles
  123. are inserted as descriptions."
  124. t nil)
  125. (autoload 'texinfo-all-menus-update
  126. "texnfo-upd"
  127. "Update every regular menu in a Texinfo file.
  128. Remove pre-existing master menu, if there is one.
  129. If called with a non-nil argument, this function first updates all the
  130. nodes in the buffer before updating the menus."
  131. t nil)
  132. (autoload 'texinfo-master-menu
  133. "texnfo-upd"
  134. "Make a master menu for a whole Texinfo file.
  135. Non-nil argument (prefix, if interactive) means first update all
  136. existing nodes and menus. Remove pre-existing master menu, if there is one.
  137. This function creates a master menu that follows the top node. The
  138. master menu includes every entry from all the other menus. It
  139. replaces any existing ordinary menu that follows the top node.
  140. If called with a non-nil argument, this function first updates all the
  141. menus in the buffer (incorporating descriptions from pre-existing
  142. menus) before it constructs the master menu.
  143. The function removes the detailed part of an already existing master
  144. menu. This action depends on the pre-existing master menu using the
  145. standard `texinfo-master-menu-header'.
  146. The master menu has the following format, which is adapted from the
  147. recommendation in the Texinfo Manual:
  148. * The first part contains the major nodes in the Texinfo file: the
  149. nodes for the chapters, chapter-like sections, and the major
  150. appendices. This includes the indices, so long as they are in
  151. chapter-like sections, such as unnumbered sections.
  152. * The second and subsequent parts contain a listing of the other,
  153. lower level menus, in order. This way, an inquirer can go
  154. directly to a particular node if he or she is searching for
  155. specific information.
  156. Each of the menus in the detailed node listing is introduced by the
  157. title of the section containing the menu."
  158. t nil)
  159. (autoload 'texinfo-indent-menu-description
  160. "texnfo-upd"
  161. "Indent every description in menu following point to COLUMN.
  162. Non-nil argument (prefix, if interactive) means indent every
  163. description in every menu in the region. Does not indent second and
  164. subsequent lines of a multi-line description."
  165. t nil)
  166. (autoload 'texinfo-insert-node-lines
  167. "texnfo-upd"
  168. "Insert missing `@node' lines in region of Texinfo file.
  169. Non-nil argument (prefix, if interactive) means also to insert the
  170. section titles as node names; and also to insert the section titles as
  171. node names in pre-existing @node lines that lack names."
  172. t nil)
  173. (autoload 'texinfo-start-menu-description
  174. "texnfo-upd"
  175. "In this menu entry, insert the node's section title as a description.
  176. Position point at beginning of description ready for editing.
  177. Do not insert a title if the line contains an existing description.
  178. You will need to edit the inserted text since a useful description
  179. complements the node name rather than repeats it as a title does."
  180. t nil)
  181. (autoload 'texinfo-multiple-files-update
  182. "texnfo-upd"
  183. "Update first node pointers in each file included in OUTER-FILE;
  184. create or update main menu in the outer file that refers to such nodes.
  185. This does not create or update menus or pointers within the included files.
  186. With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
  187. insert a master menu in OUTER-FILE. This does not create or update
  188. menus or pointers within the included files.
  189. With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
  190. interactive), update all the menus and all the `Next', `Previous', and
  191. `Up' pointers of all the files included in OUTER-FILE before inserting
  192. a master menu in OUTER-FILE.
  193. The command also updates the `Top' level node pointers of OUTER-FILE.
  194. Notes:
  195. * this command does NOT save any files--you must save the
  196. outer file and any modified, included files.
  197. * except for the `Top' node, this command does NOT handle any
  198. pre-existing nodes in the outer file; hence, indices must be
  199. enclosed in an included file.
  200. Requirements:
  201. * each of the included files must contain exactly one highest
  202. hierarchical level node,
  203. * this highest node must be the first node in the included file,
  204. * each highest hierarchical level node must be of the same type.
  205. Thus, normally, each included file contains one, and only one,
  206. chapter."
  207. t nil)
  208. ;;; Code:
  209. ;;; Don't you dare insert any `require' calls at top level in this file--rms.
  210. (defvar texinfo-section-list
  211. '(("top" 1)
  212. ("chapter" 2)
  213. ("section" 3)
  214. ("subsection" 4)
  215. ("subsubsection" 5)
  216. ("unnumbered" 2)
  217. ("unnumberedsec" 3)
  218. ("unnumberedsubsec" 4)
  219. ("unnumberedsubsubsec" 5)
  220. ("appendix" 2)
  221. ("appendixsec" 3)
  222. ("appendixsection" 3)
  223. ("appendixsubsec" 4)
  224. ("appendixsubsubsec" 5)
  225. ("majorheading" 2)
  226. ("chapheading" 2)
  227. ("heading" 3)
  228. ("subheading" 4)
  229. ("subsubheading" 5))
  230. "Alist of sectioning commands and their relative level.")
  231. ;;; Syntax table
  232. (defvar texinfo-mode-syntax-table
  233. (let ((st (make-syntax-table)))
  234. (modify-syntax-entry ?\" "." st)
  235. (modify-syntax-entry ?\\ "." st)
  236. (modify-syntax-entry ?@ "\\" st)
  237. (modify-syntax-entry ?\^q "\\" st)
  238. (modify-syntax-entry ?\[ "(]" st)
  239. (modify-syntax-entry ?\] ")[" st)
  240. (modify-syntax-entry ?{ "(}" st)
  241. (modify-syntax-entry ?} "){" st)
  242. (modify-syntax-entry ?\n ">" st)
  243. (modify-syntax-entry ?\' "w" st)
  244. st))
  245. ;; Written by Wolfgang Bangerth <zcg51122@rpool1.rus.uni-stuttgart.de>
  246. ;; To override this example, set either `imenu-generic-expression'
  247. ;; or `imenu-create-index-function'.
  248. (defvar texinfo-imenu-generic-expression
  249. '((nil "^@\\(node\\|anchor\\)[ \t]+\\([^,\n]*\\)" 2)
  250. ("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1))
  251. "Imenu generic expression for Texinfo mode. See `imenu-generic-expression'.")
  252. (defconst texinfo-syntax-propertize-function
  253. (syntax-propertize-rules
  254. ("\\(@\\)c\\(omment\\)?\\>" (1 "<"))
  255. ("^\\(@\\)ignore\\>" (1 "< b"))
  256. ("^@end ignore\\(\n\\)" (1 "> b")))
  257. "Syntactic keywords to catch comment delimiters in `texinfo-mode'.")
  258. (defconst texinfo-environments
  259. '("cartouche" "copying" "defcv" "deffn" "defivar" "defmac"
  260. "defmethod" "defop" "defopt" "defspec" "deftp" "deftypecv"
  261. "deftypefn" "deftypefun" "deftypeivar" "deftypemethod"
  262. "deftypeop" "deftypevar" "deftypevr" "defun" "defvar"
  263. "defvr" "description" "detailmenu" "direntry" "display"
  264. "documentdescription" "enumerate" "example" "flushleft"
  265. "flushright" "format" "ftable" "group" "html" "ifclear" "ifset"
  266. "ifhtml" "ifinfo" "ifnothtml" "ifnotinfo" "ifnotplaintext"
  267. "ifnottex" "ifplaintext" "iftex" "ignore" "itemize" "lisp"
  268. "macro" "menu" "multitable" "quotation" "smalldisplay"
  269. "smallexample" "smallformat" "smalllisp" "table" "tex"
  270. "titlepage" "verbatim" "vtable")
  271. "List of Texinfo environments.")
  272. (defconst texinfo-environment-regexp
  273. (concat "^@" (regexp-opt (cons "end" texinfo-environments) t) "\\>")
  274. "Regexp for environment-like Texinfo list commands.
  275. Subexpression 1 is what goes into the corresponding `@end' statement.")
  276. (defface texinfo-heading
  277. '((t (:inherit font-lock-function-name-face)))
  278. "Face used for section headings in `texinfo-mode'."
  279. :group 'texinfo)
  280. (defvar texinfo-font-lock-keywords
  281. `(;; All but the first had an OVERRIDE of t.
  282. ;; It didn't seem to be any better, and it's slower--simon.
  283. ;; Robert J. Chassell <bob@gnu.org> says remove this line.
  284. ;;("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
  285. ("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face) ;commands
  286. ("^\\*\\([^\n:]*\\)" 1 font-lock-function-name-face t) ;menu items
  287. ("@\\(emph\\|i\\|sc\\){\\([^}]+\\)" 2 'italic)
  288. ("@\\(strong\\|b\\){\\([^}]+\\)" 2 'bold)
  289. ("@\\(kbd\\|key\\|url\\|uref\\){\\([^}]+\\)" 2 font-lock-string-face)
  290. ;; The following two groups have an OVERRIDE of `keep' because
  291. ;; their arguments frequently include a @@, and we don't want that
  292. ;; to overwrite the normal fontification of the argument.
  293. ("@\\(file\\|email\\){\\([^}]+\\)" 2 font-lock-string-face keep)
  294. ("@\\(samp\\|code\\|var\\|env\\|command\\|option\\){\\([^}]+\\)"
  295. 2 font-lock-variable-name-face keep)
  296. ;; @math allows nested braces like @math{2^{12}}
  297. ("@math{\\([^{}]*{?[^{}]*}?[^{}]*\\)}" 1 font-lock-variable-name-face)
  298. ("@\\(cite\\|x?ref\\|pxref\\|dfn\\|inforef\\){\\([^}]+\\)"
  299. 2 font-lock-constant-face)
  300. ("@\\(anchor\\){\\([^}]+\\)" 2 font-lock-type-face)
  301. ("@\\(dmn\\|acronym\\|value\\){\\([^}]+\\)" 2 font-lock-builtin-face)
  302. ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-keyword-face keep)
  303. ;; (,texinfo-environment-regexp
  304. ;; 1 (texinfo-clone-environment (match-beginning 1) (match-end 1)) keep)
  305. (,(concat "^@" (regexp-opt (mapcar 'car texinfo-section-list) t)
  306. ".*\n")
  307. 0 'texinfo-heading t))
  308. "Additional expressions to highlight in Texinfo mode.")
  309. (defun texinfo-clone-environment (start end)
  310. (let ((endp nil))
  311. (save-excursion
  312. (ignore-errors
  313. (goto-char start)
  314. (when (looking-at "end\\Sw+\\(\\sw+\\)")
  315. (setq endp t start (match-beginning 1) end (match-end 1)))
  316. (unless (get-char-property start 'text-clones)
  317. (if endp
  318. (texinfo-last-unended-begin)
  319. (forward-word-strictly 1)
  320. (texinfo-next-unmatched-end))
  321. (skip-syntax-forward "^w")
  322. (when (looking-at
  323. (concat (regexp-quote (buffer-substring start end)) "\\>"))
  324. (text-clone-create start end 'spread "\\w*")))))))
  325. ;;; Keybindings
  326. ;;; Keys common both to Texinfo mode and to TeX shell.
  327. (defun texinfo-define-common-keys (keymap)
  328. "Define the keys both in Texinfo mode and in the texinfo-tex-shell."
  329. (define-key keymap "\C-c\C-t\C-k" 'tex-kill-job)
  330. (define-key keymap "\C-c\C-t\C-x" 'texinfo-quit-job)
  331. (define-key keymap "\C-c\C-t\C-l" 'tex-recenter-output-buffer)
  332. (define-key keymap "\C-c\C-t\C-d" 'texinfo-delete-from-print-queue)
  333. (define-key keymap "\C-c\C-t\C-q" 'tex-show-print-queue)
  334. (define-key keymap "\C-c\C-t\C-p" 'texinfo-tex-print)
  335. (define-key keymap "\C-c\C-t\C-v" 'texinfo-tex-view)
  336. (define-key keymap "\C-c\C-t\C-i" 'texinfo-texindex)
  337. (define-key keymap "\C-c\C-t\C-r" 'texinfo-tex-region)
  338. (define-key keymap "\C-c\C-t\C-b" 'texinfo-tex-buffer))
  339. ;; Mode documentation displays commands in reverse order
  340. ;; from how they are listed in the texinfo-mode-map.
  341. (defvar texinfo-mode-map
  342. (let ((map (make-sparse-keymap)))
  343. ;; bindings for `texnfo-tex.el'
  344. (texinfo-define-common-keys map)
  345. (define-key map "\"" 'texinfo-insert-quote)
  346. ;; bindings for `makeinfo.el'
  347. (define-key map "\C-c\C-m\C-k" 'kill-compilation)
  348. (define-key map "\C-c\C-m\C-l"
  349. 'makeinfo-recenter-compilation-buffer)
  350. (define-key map "\C-c\C-m\C-r" 'makeinfo-region)
  351. (define-key map "\C-c\C-m\C-b" 'makeinfo-buffer)
  352. ;; bindings for `texinfmt.el'
  353. (define-key map "\C-c\C-e\C-r" 'texinfo-format-region)
  354. (define-key map "\C-c\C-e\C-b" 'texinfo-format-buffer)
  355. ;; AUCTeX-like bindings
  356. (define-key map "\e\r" 'texinfo-insert-@item)
  357. ;; bindings for updating nodes and menus
  358. (define-key map "\C-c\C-um" 'texinfo-master-menu)
  359. (define-key map "\C-c\C-u\C-m" 'texinfo-make-menu)
  360. (define-key map "\C-c\C-u\C-n" 'texinfo-update-node)
  361. (define-key map "\C-c\C-u\C-e" 'texinfo-every-node-update)
  362. (define-key map "\C-c\C-u\C-a" 'texinfo-all-menus-update)
  363. (define-key map "\C-c\C-s" 'texinfo-show-structure)
  364. (define-key map "\C-c}" 'up-list)
  365. ;; FIXME: This is often used for "close block" aka texinfo-insert-@end.
  366. (define-key map "\C-c]" 'up-list)
  367. (define-key map "\C-c/" 'texinfo-insert-@end)
  368. (define-key map "\C-c{" 'texinfo-insert-braces)
  369. ;; bindings for inserting strings
  370. (define-key map "\C-c\C-o" 'texinfo-insert-block)
  371. (define-key map "\C-c\C-c\C-d" 'texinfo-start-menu-description)
  372. (define-key map "\C-c\C-c\C-s" 'texinfo-insert-@strong)
  373. (define-key map "\C-c\C-c\C-e" 'texinfo-insert-@emph)
  374. (define-key map "\C-c\C-cv" 'texinfo-insert-@var)
  375. (define-key map "\C-c\C-cu" 'texinfo-insert-@uref)
  376. (define-key map "\C-c\C-ct" 'texinfo-insert-@table)
  377. (define-key map "\C-c\C-cs" 'texinfo-insert-@samp)
  378. (define-key map "\C-c\C-cq" 'texinfo-insert-@quotation)
  379. (define-key map "\C-c\C-co" 'texinfo-insert-@noindent)
  380. (define-key map "\C-c\C-cn" 'texinfo-insert-@node)
  381. (define-key map "\C-c\C-cm" 'texinfo-insert-@email)
  382. (define-key map "\C-c\C-ck" 'texinfo-insert-@kbd)
  383. (define-key map "\C-c\C-ci" 'texinfo-insert-@item)
  384. (define-key map "\C-c\C-cf" 'texinfo-insert-@file)
  385. (define-key map "\C-c\C-cx" 'texinfo-insert-@example)
  386. (define-key map "\C-c\C-ce" 'texinfo-insert-@end)
  387. (define-key map "\C-c\C-cd" 'texinfo-insert-@dfn)
  388. (define-key map "\C-c\C-cc" 'texinfo-insert-@code)
  389. map))
  390. (easy-menu-define texinfo-mode-menu
  391. texinfo-mode-map
  392. "Menu used for `texinfo-mode'."
  393. '("Texinfo"
  394. ["Insert block" texinfo-insert-block t]
  395. ;; ["Insert node" texinfo-insert-@node t]
  396. "----"
  397. ["Update All" (lambda () (interactive) (texinfo-master-menu t))
  398. :keys "\\[universal-argument] \\[texinfo-master-menu]"]
  399. ["Update every node" texinfo-every-node-update t]
  400. ["Update node" texinfo-update-node t]
  401. ["Make Master menu" texinfo-master-menu t]
  402. ["Make menu" texinfo-make-menu t]
  403. ["Update all menus" texinfo-all-menus-update t]
  404. "----"
  405. ["Show structure" texinfo-show-structure t]
  406. ["Format region" texinfo-format-region t]
  407. ["Format buffer" texinfo-format-buffer t]
  408. ["Makeinfo region" makeinfo-region t]
  409. ["Makeinfo buffer" makeinfo-buffer t]))
  410. (defun texinfo-filter (section list)
  411. (let (res)
  412. (dolist (x list) (if (eq section (cadr x)) (push (car x) res)))
  413. res))
  414. (defvar texinfo-chapter-level-regexp
  415. (regexp-opt (texinfo-filter 2 texinfo-section-list))
  416. "Regular expression matching just the Texinfo chapter level headings.")
  417. (defun texinfo-current-defun-name ()
  418. "Return the name of the Texinfo node at point, or nil."
  419. (save-excursion
  420. (if (re-search-backward "^@node[ \t]+\\([^,\n]+\\)" nil t)
  421. (match-string-no-properties 1))))
  422. ;;; Texinfo mode
  423. ;;;###autoload
  424. (define-derived-mode texinfo-mode text-mode "Texinfo"
  425. "Major mode for editing Texinfo files.
  426. It has these extra commands:
  427. \\{texinfo-mode-map}
  428. These are files that are used as input for TeX to make printed manuals
  429. and also to be turned into Info files with \\[makeinfo-buffer] or
  430. the `makeinfo' program. These files must be written in a very restricted and
  431. modified version of TeX input format.
  432. Editing commands are like text-mode except that the syntax table is
  433. set up so expression commands skip Texinfo bracket groups. To see
  434. what the Info version of a region of the Texinfo file will look like,
  435. use \\[makeinfo-region], which runs `makeinfo' on the current region.
  436. You can show the structure of a Texinfo file with \\[texinfo-show-structure].
  437. This command shows the structure of a Texinfo file by listing the
  438. lines with the @-sign commands for @chapter, @section, and the like.
  439. These lines are displayed in another window called the *Occur* window.
  440. In that window, you can position the cursor over one of the lines and
  441. use \\[occur-mode-goto-occurrence], to jump to the corresponding spot
  442. in the Texinfo file.
  443. In addition, Texinfo mode provides commands that insert various
  444. frequently used @-sign commands into the buffer. You can use these
  445. commands to save keystrokes. And you can insert balanced braces with
  446. \\[texinfo-insert-braces] and later use the command \\[up-list] to
  447. move forward past the closing brace.
  448. Also, Texinfo mode provides functions for automatically creating or
  449. updating menus and node pointers. These functions
  450. * insert the `Next', `Previous' and `Up' pointers of a node,
  451. * insert or update the menu for a section, and
  452. * create a master menu for a Texinfo source file.
  453. Here are the functions:
  454. texinfo-update-node \\[texinfo-update-node]
  455. texinfo-every-node-update \\[texinfo-every-node-update]
  456. texinfo-sequential-node-update
  457. texinfo-make-menu \\[texinfo-make-menu]
  458. texinfo-all-menus-update \\[texinfo-all-menus-update]
  459. texinfo-master-menu
  460. texinfo-indent-menu-description (column &optional region-p)
  461. The `texinfo-column-for-description' variable specifies the column to
  462. which menu descriptions are indented.
  463. Passed an argument (a prefix argument, if interactive), the
  464. `texinfo-update-node' and `texinfo-make-menu' functions do their jobs
  465. in the region.
  466. To use the updating commands, you must structure your Texinfo file
  467. hierarchically, such that each `@node' line, with the exception of the
  468. Top node, is accompanied by some kind of section line, such as an
  469. `@chapter' or `@section' line.
  470. If the file has a `top' node, it must be called `top' or `Top' and
  471. be the first node in the file.
  472. Entering Texinfo mode calls the value of `text-mode-hook', and then the
  473. value of `texinfo-mode-hook'."
  474. (setq-local page-delimiter
  475. (concat "^@node [ \t]*[Tt]op\\|^@\\("
  476. texinfo-chapter-level-regexp
  477. "\\)\\>"))
  478. (setq-local require-final-newline mode-require-final-newline)
  479. (setq-local indent-tabs-mode nil)
  480. (setq-local paragraph-separate
  481. (concat "\b\\|@[a-zA-Z]*[ \n]\\|"
  482. paragraph-separate))
  483. (setq-local paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|"
  484. paragraph-start))
  485. (setq-local sentence-end-base "\\(@\\(end\\)?dots{}\\|[.?!]\\)[]\"'”)}]*")
  486. (setq-local fill-column 70)
  487. (setq-local comment-start "@c ")
  488. (setq-local comment-start-skip "@c +\\|@comment +")
  489. (setq-local words-include-escapes t)
  490. (setq-local imenu-generic-expression texinfo-imenu-generic-expression)
  491. (setq imenu-case-fold-search nil)
  492. (setq font-lock-defaults
  493. '(texinfo-font-lock-keywords nil nil nil backward-paragraph))
  494. (setq-local syntax-propertize-function texinfo-syntax-propertize-function)
  495. (setq-local parse-sexp-lookup-properties t)
  496. (setq-local add-log-current-defun-function #'texinfo-current-defun-name)
  497. ;; Outline settings.
  498. (setq-local outline-heading-alist
  499. ;; We should merge `outline-heading-alist' and
  500. ;; `texinfo-section-list'. But in the mean time, let's
  501. ;; just generate one from the other.
  502. (mapcar (lambda (x) (cons (concat "@" (car x)) (cadr x)))
  503. texinfo-section-list))
  504. (setq-local outline-regexp
  505. (concat (regexp-opt (mapcar 'car outline-heading-alist) t)
  506. "\\>"))
  507. (setq-local tex-start-of-header "%\\*\\*start")
  508. (setq-local tex-end-of-header "%\\*\\*end")
  509. (setq-local tex-first-line-header-regexp "^\\\\input")
  510. (setq-local tex-trailer "@bye\n")
  511. ;; Prevent skeleton.el from adding a newline to each inserted
  512. ;; skeleton. Those which do want a newline do that explicitly in
  513. ;; their define-skeleton form.
  514. (setq-local skeleton-end-newline nil)
  515. ;; Prevent filling certain lines, in addition to ones specified by
  516. ;; the user.
  517. (setq-local auto-fill-inhibit-regexp
  518. (let ((prevent-filling "^@\\(def\\|multitable\\)"))
  519. (if (null auto-fill-inhibit-regexp)
  520. prevent-filling
  521. (concat auto-fill-inhibit-regexp "\\|" prevent-filling)))))
  522. ;;; Insert string commands
  523. (defvar texinfo-block-default "example")
  524. (define-skeleton texinfo-insert-block
  525. "Create a matching pair @<cmd> .. @end <cmd> at point.
  526. Puts point on a blank line between them."
  527. (setq texinfo-block-default
  528. (completing-read (format "Block name [%s]: " texinfo-block-default)
  529. texinfo-environments
  530. nil nil nil nil texinfo-block-default))
  531. \n "@" str
  532. ;; Blocks that take parameters: all the def* blocks take parameters,
  533. ;; plus a few others.
  534. (if (or (string-match "\\`def" str)
  535. (member str '("table" "ftable" "vtable")))
  536. '(nil " " -))
  537. \n _ \n "@end " str \n \n)
  538. (defun texinfo-inside-macro-p (macro &optional bound)
  539. "Non-nil if inside a macro matching the regexp MACRO."
  540. (condition-case nil
  541. (save-excursion
  542. (save-restriction
  543. (narrow-to-region bound (point))
  544. (while (progn
  545. (up-list -1)
  546. (not (condition-case nil
  547. (save-excursion
  548. (backward-sexp 1)
  549. (looking-at macro))
  550. (scan-error nil)))))
  551. t))
  552. (scan-error nil)))
  553. (defun texinfo-inside-env-p (env &optional bound)
  554. "Non-nil if inside an environment matching the regexp @ENV."
  555. (save-excursion
  556. (and (re-search-backward (concat "@\\(end\\s +\\)?" env) bound t)
  557. (not (match-end 1)))))
  558. (defvar texinfo-enable-quote-macros "@\\(code\\|samp\\|kbd\\)\\>")
  559. (defvar texinfo-enable-quote-envs
  560. '("example\\>" "smallexample\\>" "lisp\\>"))
  561. (defun texinfo-insert-quote (&optional arg)
  562. "Insert the appropriate quote mark for Texinfo.
  563. Usually inserts the value of `texinfo-open-quote' (normally \\=`\\=`) or
  564. `texinfo-close-quote' (normally \\='\\='), depending on the context.
  565. With prefix argument or inside @code or @example, inserts a plain \"."
  566. (interactive "*P")
  567. (let ((top (or (save-excursion (re-search-backward "@node\\>" nil t))
  568. (point-min))))
  569. (if (or arg
  570. (= (preceding-char) ?\\)
  571. (save-excursion
  572. ;; Might be near the start of a (narrowed) buffer.
  573. (ignore-errors (backward-char (length texinfo-open-quote)))
  574. (when (or (looking-at texinfo-open-quote)
  575. (looking-at texinfo-close-quote))
  576. (delete-char (length texinfo-open-quote))
  577. t))
  578. (texinfo-inside-macro-p texinfo-enable-quote-macros top)
  579. (let ((in-env nil))
  580. (dolist (env texinfo-enable-quote-envs in-env)
  581. (if (texinfo-inside-env-p env top)
  582. (setq in-env t)))))
  583. (self-insert-command (prefix-numeric-value arg))
  584. (insert
  585. (if (or (bobp)
  586. (memq (char-syntax (preceding-char)) '(?\( ?> ?\s)))
  587. texinfo-open-quote
  588. texinfo-close-quote)))))
  589. ;; The following texinfo-insert-@end command not only inserts a SPC
  590. ;; after the @end, but tries to find out what belongs there. It is
  591. ;; not very smart: it does not understand nested lists.
  592. (defun texinfo-last-unended-begin ()
  593. (while (and (re-search-backward texinfo-environment-regexp)
  594. (looking-at "@end"))
  595. (texinfo-last-unended-begin)))
  596. (defun texinfo-next-unmatched-end ()
  597. (while (and (re-search-forward texinfo-environment-regexp)
  598. (save-excursion
  599. (goto-char (match-beginning 0))
  600. (not (looking-at "@end"))))
  601. (texinfo-next-unmatched-end)))
  602. (define-skeleton texinfo-insert-@end
  603. "Insert the matching `@end' for the last Texinfo command that needs one."
  604. (ignore-errors
  605. (save-excursion
  606. (backward-word-strictly 1)
  607. (texinfo-last-unended-begin)
  608. (or (match-string 1) '-)))
  609. \n "@end " str \n \n)
  610. (define-skeleton texinfo-insert-braces
  611. "Make a pair of braces and be poised to type inside of them.
  612. Use \\[up-list] to move forward out of the braces."
  613. nil
  614. "{" _ "}")
  615. (define-skeleton texinfo-insert-@code
  616. "Insert a `@code{...}' command in a Texinfo buffer.
  617. A numeric argument says how many words the braces should surround.
  618. The default is not to surround any existing words with the braces."
  619. nil
  620. "@code{" _ "}")
  621. (define-skeleton texinfo-insert-@dfn
  622. "Insert a `@dfn{...}' command in a Texinfo buffer.
  623. A numeric argument says how many words the braces should surround.
  624. The default is not to surround any existing words with the braces."
  625. nil
  626. "@dfn{" _ "}")
  627. (define-skeleton texinfo-insert-@email
  628. "Insert a `@email{...}' command in a Texinfo buffer.
  629. A numeric argument says how many words the braces should surround.
  630. The default is not to surround any existing words with the braces."
  631. nil
  632. "@email{" _ "}")
  633. (define-skeleton texinfo-insert-@emph
  634. "Insert a `@emph{...}' command in a Texinfo buffer.
  635. A numeric argument says how many words the braces should surround.
  636. The default is not to surround any existing words with the braces."
  637. nil
  638. "@emph{" _ "}")
  639. (define-skeleton texinfo-insert-@example
  640. "Insert the string `@example' in a Texinfo buffer."
  641. nil
  642. \n "@example" \n \n)
  643. (define-skeleton texinfo-insert-@file
  644. "Insert a `@file{...}' command in a Texinfo buffer.
  645. A numeric argument says how many words the braces should surround.
  646. The default is not to surround any existing words with the braces."
  647. nil
  648. "@file{" _ "}")
  649. (define-skeleton texinfo-insert-@item
  650. "Insert the string `@item' in a Texinfo buffer.
  651. If in a table defined by @table, follow said string with a space.
  652. Otherwise, follow with a newline."
  653. nil
  654. \n "@item"
  655. (if (equal (ignore-errors
  656. (save-excursion
  657. (texinfo-last-unended-begin)
  658. (match-string 1)))
  659. "table")
  660. " " '\n)
  661. _ \n)
  662. (define-skeleton texinfo-insert-@kbd
  663. "Insert a `@kbd{...}' command in a Texinfo buffer.
  664. A numeric argument says how many words the braces should surround.
  665. The default is not to surround any existing words with the braces."
  666. nil
  667. "@kbd{" _ "}")
  668. (define-skeleton texinfo-insert-@node
  669. "Insert the string `@node' in a Texinfo buffer.
  670. Insert a comment on the following line indicating the order of
  671. arguments to @node. Insert a carriage return after the comment line.
  672. Leave point after `@node'."
  673. nil
  674. \n "@node " _ \n)
  675. (define-skeleton texinfo-insert-@noindent
  676. "Insert the string `@noindent' in a Texinfo buffer."
  677. nil
  678. \n "@noindent" \n)
  679. (define-skeleton texinfo-insert-@quotation
  680. "Insert the string `@quotation' in a Texinfo buffer."
  681. \n "@quotation" \n _ \n)
  682. (define-skeleton texinfo-insert-@samp
  683. "Insert a `@samp{...}' command in a Texinfo buffer.
  684. A numeric argument says how many words the braces should surround.
  685. The default is not to surround any existing words with the braces."
  686. nil
  687. "@samp{" _ "}")
  688. (define-skeleton texinfo-insert-@strong
  689. "Insert a `@strong{...}' command in a Texinfo buffer.
  690. A numeric argument says how many words the braces should surround.
  691. The default is not to surround any existing words with the braces."
  692. nil
  693. "@strong{" _ "}")
  694. (define-skeleton texinfo-insert-@table
  695. "Insert the string `@table' in a Texinfo buffer."
  696. nil
  697. \n "@table " _ \n)
  698. (define-skeleton texinfo-insert-@var
  699. "Insert a `@var{}' command in a Texinfo buffer.
  700. A numeric argument says how many words the braces should surround.
  701. The default is not to surround any existing words with the braces."
  702. nil
  703. "@var{" _ "}")
  704. (define-skeleton texinfo-insert-@uref
  705. "Insert a `@uref{}' command in a Texinfo buffer.
  706. A numeric argument says how many words the braces should surround.
  707. The default is not to surround any existing words with the braces."
  708. nil
  709. "@uref{" _ "}")
  710. (defalias 'texinfo-insert-@url 'texinfo-insert-@uref)
  711. ;;; Texinfo file structure
  712. (defun texinfo-show-structure (&optional nodes-too)
  713. "Show the structure of a Texinfo file.
  714. List the lines in the file that begin with the @-sign commands for
  715. @chapter, @section, and the like.
  716. With optional argument (prefix if interactive), list both the lines
  717. with @-sign commands for @chapter, @section, and the like, and list
  718. @node lines.
  719. Lines with structuring commands beginning in them are displayed in
  720. another buffer named `*Occur*'. In that buffer, you can move point to
  721. one of those lines and then use
  722. \\<occur-mode-map>\\[occur-mode-goto-occurrence],
  723. to jump to the corresponding spot in the Texinfo source file."
  724. (interactive "P")
  725. ;; First, remember current location
  726. (let (current-location)
  727. (save-excursion
  728. (end-of-line) ; so as to find section on current line
  729. (if (re-search-backward
  730. ;; do not require `texinfo-section-types-regexp' in texnfo-upd.el
  731. "^@\\(chapter \\|sect\\|subs\\|subh\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
  732. nil t)
  733. (setq current-location
  734. (progn
  735. (beginning-of-line)
  736. (buffer-substring (point) (progn (end-of-line) (point)))))
  737. ;; else point is located before any section command.
  738. (setq current-location "tex")))
  739. ;; Second, create and format an *Occur* buffer
  740. (save-excursion
  741. (goto-char (point-min))
  742. (occur (concat "^\\(?:" (if nodes-too "@node\\>\\|")
  743. outline-regexp "\\)")))
  744. (pop-to-buffer "*Occur*")
  745. (goto-char (point-min))
  746. (let ((inhibit-read-only t))
  747. (flush-lines "-----")
  748. ;; Now format the "*Occur*" buffer to show the structure.
  749. ;; Thanks to ceder@signum.se (Per Cederqvist)
  750. (goto-char (point-max))
  751. (let (level)
  752. (while (re-search-backward "^ *[0-9]*:@\\(\\sw+\\)" nil 0)
  753. (goto-char (1- (match-beginning 1)))
  754. (setq level
  755. (or (cadr (assoc (match-string 1) texinfo-section-list)) 2))
  756. (indent-to-column (+ (current-column) (* 4 (- level 2))))
  757. (beginning-of-line))))
  758. ;; Third, go to line corresponding to location in source file
  759. ;; potential bug: two exactly similar `current-location' lines ...
  760. (goto-char (point-min))
  761. (re-search-forward current-location nil t)
  762. (beginning-of-line)
  763. ))
  764. ;;; The tex and print function definitions:
  765. (defcustom texinfo-texi2dvi-command "texi2dvi"
  766. "Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer."
  767. :type 'string
  768. :group 'texinfo)
  769. (defcustom texinfo-tex-command "tex"
  770. "Command used by `texinfo-tex-region' to run TeX on a region."
  771. :type 'string
  772. :group 'texinfo)
  773. (defcustom texinfo-texindex-command "texindex"
  774. "Command used by `texinfo-texindex' to sort unsorted index files."
  775. :type 'string
  776. :group 'texinfo)
  777. (defcustom texinfo-delete-from-print-queue-command "lprm"
  778. "Command string used to delete a job from the line printer queue.
  779. Command is used by \\[texinfo-delete-from-print-queue] based on
  780. number provided by a previous \\[tex-show-print-queue]
  781. command."
  782. :type 'string
  783. :group 'texinfo)
  784. (defvar texinfo-tex-trailer "@bye"
  785. "String appended after a region sent to TeX by `texinfo-tex-region'.")
  786. (defun texinfo-tex-region (beg end)
  787. "Run TeX on the current region.
  788. This works by writing a temporary file (`tex-zap-file') in the directory
  789. that is the value of `tex-directory', then running TeX on that file.
  790. The first line of the buffer is copied to the
  791. temporary file; and if the buffer has a header, it is written to the
  792. temporary file before the region itself. The buffer's header is all lines
  793. between the strings defined by `tex-start-of-header' and `tex-end-of-header'
  794. inclusive. The header must start in the first 100 lines.
  795. The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
  796. (interactive "r")
  797. (require 'tex-mode)
  798. (let ((tex-command texinfo-tex-command)
  799. (tex-trailer texinfo-tex-trailer))
  800. (tex-region beg end)))
  801. (defun texinfo-tex-buffer ()
  802. "Run TeX on visited file, once or twice, to make a correct `.dvi' file."
  803. (interactive)
  804. (require 'tex-mode)
  805. (let ((tex-command texinfo-texi2dvi-command)
  806. ;; Disable tex-start-options-string. texi2dvi would not
  807. ;; understand anything specified here.
  808. (tex-start-options-string ""))
  809. (tex-buffer)))
  810. (defun texinfo-texindex ()
  811. "Run `texindex' on unsorted index files.
  812. The index files are made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
  813. This runs the shell command defined by `texinfo-texindex-command'."
  814. (interactive)
  815. (require 'tex-mode)
  816. (tex-send-command texinfo-texindex-command (concat tex-zap-file ".??"))
  817. ;; alternatively
  818. ;; (send-string "tex-shell"
  819. ;; (concat texinfo-texindex-command
  820. ;; " " tex-zap-file ".??" "\n"))
  821. (tex-recenter-output-buffer nil))
  822. (defun texinfo-tex-print ()
  823. "Print `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
  824. This runs the shell command defined by `tex-dvi-print-command'."
  825. (interactive)
  826. (require 'tex-mode)
  827. (tex-print))
  828. (defun texinfo-tex-view ()
  829. "View `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
  830. This runs the shell command defined by `tex-dvi-view-command'."
  831. (interactive)
  832. (require 'tex-mode)
  833. (tex-view))
  834. (defun texinfo-quit-job ()
  835. "Quit currently running TeX job, by sending an `x' to it."
  836. (interactive)
  837. (if (not (get-process "tex-shell"))
  838. (error "No TeX shell running"))
  839. (tex-send-command "x"))
  840. ;; alternatively:
  841. ;; save-excursion
  842. ;; (set-buffer (get-buffer "*tex-shell*"))
  843. ;; (goto-char (point-max))
  844. ;; (insert "x")
  845. ;; (comint-send-input)
  846. (defun texinfo-delete-from-print-queue (job-number)
  847. "Delete job from the line printer spooling queue.
  848. You are prompted for the job number (use a number shown by a previous
  849. \\[tex-show-print-queue] command)."
  850. (interactive "nPrinter job number for deletion: ")
  851. (require 'tex-mode)
  852. (if (tex-shell-running)
  853. (tex-kill-job)
  854. (tex-start-shell))
  855. (tex-send-command texinfo-delete-from-print-queue-command job-number)
  856. ;; alternatively
  857. ;; (send-string "tex-shell"
  858. ;; (concat
  859. ;; texinfo-delete-from-print-queue-command
  860. ;; " "
  861. ;; job-number"\n"))
  862. (tex-recenter-output-buffer nil))
  863. (provide 'texinfo)
  864. ;;; texinfo.el ends here