;;; texinfo.el --- major mode for editing Texinfo files
-;; Copyright (C) 1985, 1988, 1989, 1990, 1991, 1992, 1993 Free Software
-;; Foundation, Inc.
+;; Copyright (C) 1985, '88, '89, '90, '91, '01,
+;; '92, '93, '96, '97, 2000 Free Software Foundation, Inc.
-;; Author: Robert J. Chassell
-;; Maintainer: FSF
+;; Author: Robert J. Chassell
+;; Date: [See date below for texinfo-version]
+;; Maintainer: bug-texinfo@gnu.org
+;; Keywords: maint, tex, docs
;; This file is part of GNU Emacs.
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
+;;; Todo:
+
+;; - facemenu support.
+
+;;; Commentary:
+
+;;; Code:
+
+(or (fboundp 'defgroup)
+ (defmacro defgroup (&rest ignore) nil))
+
+(or (fboundp 'defcustom)
+ (defmacro defcustom (var value doc &rest ignore)
+ `(defvar ,var ,value ,doc)))
+
+(eval-when-compile (require 'tex-mode) (require 'cl))
+
+(defgroup texinfo nil
+ "Texinfo Mode"
+ :group 'docs)
+
+;;;###autoload
+(defcustom texinfo-open-quote "``"
+ "*String inserted by typing \\[texinfo-insert-quote] to open a quotation."
+ :type 'string
+ :group 'texinfo)
+
+;;;###autoload
+(defcustom texinfo-close-quote "''"
+ "*String inserted by typing \\[texinfo-insert-quote] to close a quotation."
+ :type 'string
+ :group 'texinfo)
+
\f
;;; Autoloads:
(autoload 'makeinfo-region
- "makeinfo"
+ "makeinfo"
"Make Info file from region of current Texinfo file, and switch to it.
This command does not offer the `next-error' feature since it would
apply to a temporary file, not the original; use the `makeinfo-buffer'
command to gain use of `next-error'."
- t nil)
+ t nil)
(autoload 'makeinfo-buffer
- "makeinfo"
+ "makeinfo"
"Make Info file from current buffer.
-Use the \\[next-error] command to move to the next error
+Use the \\[next-error] command to move to the next error
\(if there are errors\)."
- t nil)
+ t nil)
(autoload 'kill-compilation
- "compile"
+ "compile"
"Kill the process made by the \\[compile] command."
- t nil)
+ t nil)
(autoload 'makeinfo-recenter-compilation-buffer
- "makeinfo"
+ "makeinfo"
"Redisplay `*compilation*' buffer so most recent output can be seen.
The last line of the buffer is displayed on
line LINE of the window, or centered if LINE is nil."
- t nil)
+ t nil)
+
+(autoload 'texinfo-update-node
+ "texnfo-upd"
+ "Without any prefix argument, update the node in which point is located.
+Non-nil argument (prefix, if interactive) means update the nodes in the
+marked region.
+
+The functions for creating or updating nodes and menus, and their
+keybindings, are:
+
+ `texinfo-update-node' (&optional region-p) \\[texinfo-update-node]
+ `texinfo-every-node-update' () \\[texinfo-every-node-update]
+ `texinfo-sequential-node-update' (&optional region-p)
+
+ `texinfo-make-menu' (&optional region-p) \\[texinfo-make-menu]
+ `texinfo-all-menus-update' () \\[texinfo-all-menus-update]
+ `texinfo-master-menu' ()
+
+ `texinfo-indent-menu-description' (column &optional region-p)
+
+The `texinfo-column-for-description' variable specifies the column to
+which menu descriptions are indented. Its default value is 32."
+ t nil)
+
+(autoload 'texinfo-every-node-update
+ "texnfo-upd"
+ "Update every node in a Texinfo file."
+ t nil)
+
+(autoload 'texinfo-sequential-node-update
+ "texnfo-upd"
+ "Update one node (or many) in a Texinfo file with sequential pointers.
+
+This function causes the `Next' or `Previous' pointer to point to the
+immediately preceding or following node, even if it is at a higher or
+lower hierarchical level in the document. Continually pressing `n' or
+`p' takes you straight through the file.
+
+Without any prefix argument, update the node in which point is located.
+Non-nil argument (prefix, if interactive) means update the nodes in the
+marked region.
+
+This command makes it awkward to navigate among sections and
+subsections; it should be used only for those documents that are meant
+to be read like a novel rather than a reference, and for which the
+Info `g*' command is inadequate."
+ t nil)
(autoload 'texinfo-make-menu
- "texnfo-upd"
+ "texnfo-upd"
"Without any prefix argument, make or update a menu.
Make the menu for the section enclosing the node found following point.
are associated with node names in the pre-existing menu are
incorporated into the new menu. Otherwise, the nodes' section titles
are inserted as descriptions."
- t nil)
+ t nil)
(autoload 'texinfo-all-menus-update
- "texnfo-upd"
+ "texnfo-upd"
"Update every regular menu in a Texinfo file.
Remove pre-existing master menu, if there is one.
If called with a non-nil argument, this function first updates all the
nodes in the buffer before updating the menus."
- t nil)
+ t nil)
(autoload 'texinfo-master-menu
- "texnfo-upd"
+ "texnfo-upd"
"Make a master menu for a whole Texinfo file.
Non-nil argument (prefix, if interactive) means first update all
existing nodes and menus. Remove pre-existing master menu, if there is one.
Each of the menus in the detailed node listing is introduced by the
title of the section containing the menu."
- t nil)
+ t nil)
(autoload 'texinfo-indent-menu-description
- "texnfo-upd"
- "Indent every description in menu following point to COLUMN.
+ "texnfo-upd"
+ "Indent every description in menu following point to COLUMN.
Non-nil argument (prefix, if interactive) means indent every
description in every menu in the region. Does not indent second and
subsequent lines of a multi-line description."
- t nil)
+ t nil)
(autoload 'texinfo-insert-node-lines
- "texnfo-upd"
+ "texnfo-upd"
"Insert missing `@node' lines in region of Texinfo file.
Non-nil argument (prefix, if interactive) means also to insert the
section titles as node names; and also to insert the section titles as
node names in pre-existing @node lines that lack names."
- t nil)
+ t nil)
(autoload 'texinfo-start-menu-description
- "texnfo-upd"
- "In this menu entry, insert the node's section title as a description.
+ "texnfo-upd"
+ "In this menu entry, insert the node's section title as a description.
Position point at beginning of description ready for editing.
Do not insert a title if the line contains an existing description.
You will need to edit the inserted text since a useful description
complements the node name rather than repeats it as a title does."
- t nil)
+ t nil)
(autoload 'texinfo-multiple-files-update
- "texnfo-upd"
+ "texnfo-upd"
"Update first node pointers in each file included in OUTER-FILE;
-create or update main menu in the outer file that refers to such nodes.
+create or update main menu in the outer file that refers to such nodes.
This does not create or update menus or pointers within the included files.
With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
The command also updates the `Top' level node pointers of OUTER-FILE.
-Notes:
+Notes:
* this command does NOT save any files--you must save the
outer file and any modified, included files.
Requirements:
* each of the included files must contain exactly one highest
- hierarchical level node,
+ hierarchical level node,
* this highest node must be the first node in the included file,
* each highest hierarchical level node must be of the same type.
Thus, normally, each included file contains one, and only one,
chapter."
- t nil)
+ t nil)
\f
;;; Code:
;;; Don't you dare insert any `require' calls at top level in this file--rms.
+(defvar texinfo-section-list
+ '(("top" 1)
+ ("majorheading" 2)
+ ("chapter" 2)
+ ("unnumbered" 2)
+ ("appendix" 2)
+ ("chapheading" 2)
+ ("section" 3)
+ ("unnumberedsec" 3)
+ ("appendixsec" 3)
+ ("heading" 3)
+ ("subsection" 4)
+ ("unnumberedsubsec" 4)
+ ("appendixsubsec" 4)
+ ("subheading" 4)
+ ("subsubsection" 5)
+ ("unnumberedsubsubsec" 5)
+ ("appendixsubsubsec" 5)
+ ("subsubheading" 5))
+ "Alist of sectioning commands and their relative level.")
+
;;; Syntax table
(defvar texinfo-mode-syntax-table nil)
(if texinfo-mode-syntax-table
nil
(setq texinfo-mode-syntax-table (make-syntax-table))
- (modify-syntax-entry ?\" " " texinfo-mode-syntax-table)
- (modify-syntax-entry ?\\ " " texinfo-mode-syntax-table)
+ (modify-syntax-entry ?\" "." texinfo-mode-syntax-table)
+ (modify-syntax-entry ?\\ "." texinfo-mode-syntax-table)
(modify-syntax-entry ?@ "\\" texinfo-mode-syntax-table)
(modify-syntax-entry ?\^q "\\" texinfo-mode-syntax-table)
(modify-syntax-entry ?\[ "(]" texinfo-mode-syntax-table)
(modify-syntax-entry ?\] ")[" texinfo-mode-syntax-table)
(modify-syntax-entry ?{ "(}" texinfo-mode-syntax-table)
(modify-syntax-entry ?} "){" texinfo-mode-syntax-table)
+ (modify-syntax-entry ?\n ">" texinfo-mode-syntax-table)
(modify-syntax-entry ?\' "w" texinfo-mode-syntax-table))
;; Written by Wolfgang Bangerth <zcg51122@rpool1.rus.uni-stuttgart.de>
;; To override this example, set either `imenu-generic-expression'
;; or `imenu-create-index-function'.
(defvar texinfo-imenu-generic-expression
- '((nil "^@node[ \t]+\\([^,\n]*\\)" 1)
+ '((nil "^@\\(node\\|anchor\\)[ \t]+\\([^,\n]*\\)" 2)
("Chapters" "^@chapter[ \t]+\\(.*\\)$" 1))
-
"Imenu generic expression for TexInfo mode. See `imenu-generic-expression'.")
+(defvar texinfo-font-lock-syntactic-keywords
+ '(("\\(@\\)c\\(omment\\)?\\>" (1 "<"))
+ ("^\\(@\\)ignore\\>" (1 "< b"))
+ ("^@end ignore\\(\n\\)" (1 "> b")))
+ "Syntactic keywords to catch comment delimiters in `texinfo-mode'.")
+
+(defconst texinfo-environments
+ '("cartouche" "defcv" "deffn" "defivar" "defmac" "defmethod" "defop"
+ "defopt" "defspec" "deftp" "deftypefn" "deftypefun" "deftypevar"
+ "deftypevr" "defun" "defvar" "defvr" "description" "detailmenu"
+ "direntry" "display" "enumerate" "example" "flushleft" "flushright"
+ "format" "ftable" "group" "ifclear" "ifset" "ifhtml" "ifinfo"
+ "ifnothtml" "ifnotinfo" "ifnottex" "iftex" "ignore" "itemize" "lisp"
+ "macro" "menu" "multitable" "quotation" "smalldisplay" "smallexample"
+ "smallformat" "smalllisp" "table" "tex" "titlepage" "vtable")
+ "List of TeXinfo environments.")
+
+(defconst texinfo-environment-regexp
+ (concat "^@" (regexp-opt (cons "end" texinfo-environments) t) "\\>")
+ "Regexp for environment-like TexInfo list commands.
+Subexpression 1 is what goes into the corresponding `@end' statement.")
+
+(defface texinfo-heading-face
+ '((t (:inherit font-lock-function-name-face)))
+ "Face used for section headings in `texinfo-mode'.")
+(defvar texinfo-heading-face 'texinfo-heading-face)
+
(defvar texinfo-font-lock-keywords
- '(;; All but the first 2 had an OVERRIDE of t.
+ `(;; All but the first had an OVERRIDE of t.
;; It didn't seem to be any better, and it's slower--simon.
- ("^\\(@c\\|@comment\\)\\>.*" . font-lock-comment-face) ;comments
- ;; Robert J. Chassell <bob@gnu.ai.mit.edu> says remove this line.
- ;("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
- ("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face) ;commands
- ("^\\*\\(.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items
- ("@\\(emph\\|strong\\|b\\|i\\){\\([^}]+\\)" 2 font-lock-comment-face)
- ("@\\(file\\|kbd\\|key\\|url\\|email\\){\\([^}]+\\)" 2 font-lock-string-face)
- ("@\\(samp\\|code\\|var\\|math\\){\\([^}]+\\)"
- 2 font-lock-variable-name-face)
- ("@\\(cite\\|xref\\|pxref\\){\\([^}]+\\)" 2 font-lock-reference-face)
- ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-function-name-face keep)
- )
+ ;; Robert J. Chassell <bob@gnu.org> says remove this line.
+ ;;("\\$\\([^$]*\\)\\$" 1 font-lock-string-face t)
+ ("@\\([a-zA-Z]+\\|[^ \t\n]\\)" 1 font-lock-keyword-face) ;commands
+ ("^\\*\\([^\n:]*\\)" 1 font-lock-function-name-face t) ;menu items
+ ("@\\(emph\\|i\\|sc\\){\\([^}]+\\)" 2 'italic)
+ ("@\\(strong\\|b\\){\\([^}]+\\)" 2 'bold)
+ ("@\\(kbd\\|key\\|url\\|uref\\){\\([^}]+\\)" 2 font-lock-string-face)
+ ;; The following two groups have an OVERRIDE of `keep' because
+ ;; their arguments frequently include a @@, and we don't want that
+ ;; to overwrite the normal fontification of the argument.
+ ("@\\(file\\|email\\){\\([^}]+\\)" 2 font-lock-string-face keep)
+ ("@\\(samp\\|code\\|var\\|math\\|env\\|command\\|option\\){\\([^}]+\\)"
+ 2 font-lock-variable-name-face keep)
+ ("@\\(cite\\|x?ref\\|pxref\\|dfn\\|inforef\\){\\([^}]+\\)"
+ 2 font-lock-constant-face)
+ ("@\\(anchor\\){\\([^}]+\\)" 2 font-lock-type-face)
+ ("@\\(dmn\\|acronym\\|value\\){\\([^}]+\\)" 2 font-lock-builtin-face)
+ ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-keyword-face keep)
+ (,texinfo-environment-regexp
+ 1 (texinfo-clone-environment (match-beginning 1) (match-end 1)) keep)
+ (,(concat "^@" (regexp-opt (mapcar 'car texinfo-section-list) t)
+ ".*\n") 0 texinfo-heading-face t))
"Additional expressions to highlight in TeXinfo mode.")
-(defvar texinfo-section-list
- '(("top" 1)
- ("majorheading" 1)
- ("chapter" 2)
- ("unnumbered" 2)
- ("appendix" 2)
- ("chapheading" 2)
- ("section" 3)
- ("unnumberedsec" 3)
- ("appendixsec" 3)
- ("heading" 3)
- ("subsection" 4)
- ("unnumberedsubsec" 4)
- ("appendixsubsec" 4)
- ("subheading" 4)
- ("subsubsection" 5)
- ("unnumberedsubsubsec" 5)
- ("appendixsubsubsec" 5)
- ("subsubheading" 5))
- "Alist of sectioning commands and their relative level.")
+(defun texinfo-clone-environment (start end)
+ (let ((endp nil))
+ (save-excursion
+ (ignore-errors
+ (goto-char start)
+ (when (looking-at "end\\Sw+\\(\\sw+\\)")
+ (setq endp t start (match-beginning 1) end (match-end 1)))
+ (unless (get-char-property start 'text-clones)
+ (if endp
+ (texinfo-last-unended-begin)
+ (forward-word 1)
+ (texinfo-next-unmatched-end))
+ (skip-syntax-forward "^w")
+ (when (looking-at (regexp-quote (buffer-substring start end)))
+ (text-clone-create start end 'spread "\\w*")))))))
(defun texinfo-outline-level ()
;; Calculate level of current texinfo outline heading.
(save-excursion
(if (bobp)
- 0
+ 0
(forward-char 1)
- (let* ((word (buffer-substring-no-properties
- (point) (progn (forward-word 1) (point))))
- (entry (assoc word texinfo-section-list)))
- (if entry
- (nth 1 entry)
- 5)))))
+ (let* ((word (buffer-substring-no-properties
+ (point) (progn (forward-word 1) (point))))
+ (entry (assoc word texinfo-section-list)))
+ (if entry
+ (nth 1 entry)
+ 5)))))
+
\f
;;; Keybindings
(defvar texinfo-mode-map nil)
(define-key keymap "\C-c\C-t\C-d" 'texinfo-delete-from-print-queue)
(define-key keymap "\C-c\C-t\C-q" 'tex-show-print-queue)
(define-key keymap "\C-c\C-t\C-p" 'texinfo-tex-print)
+ (define-key keymap "\C-c\C-t\C-v" 'texinfo-tex-view)
(define-key keymap "\C-c\C-t\C-i" 'texinfo-texindex)
(define-key keymap "\C-c\C-t\C-r" 'texinfo-tex-region)
(define-key keymap "\C-c\C-t\C-b" 'texinfo-tex-buffer))
-;; Mode documentation displays commands in reverse order
+;; Mode documentation displays commands in reverse order
;; from how they are listed in the texinfo-mode-map.
(if texinfo-mode-map
;; bindings for `texnfo-tex.el'
(texinfo-define-common-keys texinfo-mode-map)
+ (define-key texinfo-mode-map "\"" 'texinfo-insert-quote)
+
;; bindings for `makeinfo.el'
(define-key texinfo-mode-map "\C-c\C-m\C-k" 'kill-compilation)
- (define-key texinfo-mode-map "\C-c\C-m\C-l"
+ (define-key texinfo-mode-map "\C-c\C-m\C-l"
'makeinfo-recenter-compilation-buffer)
(define-key texinfo-mode-map "\C-c\C-m\C-r" 'makeinfo-region)
(define-key texinfo-mode-map "\C-c\C-m\C-b" 'makeinfo-buffer)
- ; Bindings for texinfmt.el.
+ ;; bindings for `texinfmt.el'
(define-key texinfo-mode-map "\C-c\C-e\C-r" 'texinfo-format-region)
(define-key texinfo-mode-map "\C-c\C-e\C-b" 'texinfo-format-buffer)
+ ;; AUCTeX-like bindings
+ (define-key texinfo-mode-map "\e\r" 'texinfo-insert-@item)
+
;; bindings for updating nodes and menus
(define-key texinfo-mode-map "\C-c\C-um" 'texinfo-master-menu)
(define-key texinfo-mode-map "\C-c\C-s" 'texinfo-show-structure)
- (define-key texinfo-mode-map "\C-c}" 'up-list)
- (define-key texinfo-mode-map "\C-c{" 'texinfo-insert-braces)
+ (define-key texinfo-mode-map "\C-c}" 'up-list)
+ (define-key texinfo-mode-map "\C-c]" 'up-list)
+ (define-key texinfo-mode-map "\C-c{" 'texinfo-insert-braces)
;; bindings for inserting strings
-
+ (define-key texinfo-mode-map "\C-c\C-o" 'texinfo-insert-block)
(define-key texinfo-mode-map "\C-c\C-c\C-d" 'texinfo-start-menu-description)
+ (define-key texinfo-mode-map "\C-c\C-c\C-s" 'texinfo-insert-@strong)
+ (define-key texinfo-mode-map "\C-c\C-c\C-e" 'texinfo-insert-@emph)
(define-key texinfo-mode-map "\C-c\C-cv" 'texinfo-insert-@var)
+ (define-key texinfo-mode-map "\C-c\C-cu" 'texinfo-insert-@uref)
(define-key texinfo-mode-map "\C-c\C-ct" 'texinfo-insert-@table)
(define-key texinfo-mode-map "\C-c\C-cs" 'texinfo-insert-@samp)
+ (define-key texinfo-mode-map "\C-c\C-cq" 'texinfo-insert-@quotation)
(define-key texinfo-mode-map "\C-c\C-co" 'texinfo-insert-@noindent)
(define-key texinfo-mode-map "\C-c\C-cn" 'texinfo-insert-@node)
+ (define-key texinfo-mode-map "\C-c\C-cm" 'texinfo-insert-@email)
(define-key texinfo-mode-map "\C-c\C-ck" 'texinfo-insert-@kbd)
(define-key texinfo-mode-map "\C-c\C-ci" 'texinfo-insert-@item)
(define-key texinfo-mode-map "\C-c\C-cf" 'texinfo-insert-@file)
(define-key texinfo-mode-map "\C-c\C-cd" 'texinfo-insert-@dfn)
(define-key texinfo-mode-map "\C-c\C-cc" 'texinfo-insert-@code))
+(easy-menu-define texinfo-mode-menu
+ texinfo-mode-map
+ "Menu used for `texinfo-mode'."
+ '("Texinfo"
+ ["Insert block" texinfo-insert-block t]
+ ;; ["Insert node" texinfo-insert-@node t]
+ "----"
+ ["Update All" (lambda () (interactive) (texinfo-master-menu t))
+ :keys "\\[universal-argument] \\[texinfo-master-menu]"]
+ ["Update every node" texinfo-every-node-update t]
+ ["Update node" texinfo-update-node t]
+ ["Make Master menu" texinfo-master-menu t]
+ ["Make menu" texinfo-make-menu t]
+ ["Update all menus" texinfo-all-menus-update t]
+ "----"
+ ["Show structure" texinfo-show-structure t]
+ ["Format region" texinfo-format-region t]
+ ["Format buffer" texinfo-format-buffer t]
+ ["Makeinfo region" makeinfo-region t]
+ ["Makeinfo buffer" makeinfo-buffer t]))
+
\f
-;;; Texinfo mode
+(defun texinfo-filter (section list)
+ (let (res)
+ (dolist (x list) (if (eq section (cadr x)) (push (car x) res)))
+ res))
+
+(defvar texinfo-chapter-level-regexp
+ (regexp-opt (texinfo-filter 2 texinfo-section-list))
+ "Regular expression matching just the Texinfo chapter level headings.")
-(defvar texinfo-chapter-level-regexp
- "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
- "Regular expression matching Texinfo chapter-level headings.
-This does not match `@node' and does not match the `@top' command.")
+;;; Texinfo mode
;;;###autoload
-(defun texinfo-mode ()
+(define-derived-mode texinfo-mode text-mode "Texinfo"
"Major mode for editing Texinfo files.
It has these extra commands:
texinfo-update-node \\[texinfo-update-node]
texinfo-every-node-update \\[texinfo-every-node-update]
- texinfo-sequential-node-update
+ texinfo-sequential-node-update
texinfo-make-menu \\[texinfo-make-menu]
texinfo-all-menus-update \\[texinfo-all-menus-update]
texinfo-indent-menu-description (column &optional region-p)
The `texinfo-column-for-description' variable specifies the column to
-which menu descriptions are indented.
+which menu descriptions are indented.
Passed an argument (a prefix argument, if interactive), the
`texinfo-update-node' and `texinfo-make-menu' functions do their jobs
If the file has a `top' node, it must be called `top' or `Top' and
be the first node in the file.
-Entering Texinfo mode calls the value of text-mode-hook, and then the
-value of texinfo-mode-hook."
- (interactive)
- (text-mode)
- (setq mode-name "Texinfo")
- (setq major-mode 'texinfo-mode)
- (use-local-map texinfo-mode-map)
- (set-syntax-table texinfo-mode-syntax-table)
- (make-local-variable 'page-delimiter)
- (setq page-delimiter
- (concat
- "^@node [ \t]*[Tt]op\\|^@\\("
- texinfo-chapter-level-regexp
- "\\)"))
+Entering Texinfo mode calls the value of `text-mode-hook', and then the
+value of `texinfo-mode-hook'."
+ (set (make-local-variable 'page-delimiter)
+ (concat
+ "^@node [ \t]*[Tt]op\\|^@\\("
+ texinfo-chapter-level-regexp
+ "\\)\\>"))
(make-local-variable 'require-final-newline)
(setq require-final-newline t)
(make-local-variable 'indent-tabs-mode)
(setq indent-tabs-mode nil)
(make-local-variable 'paragraph-separate)
- (setq paragraph-separate (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate))
+ (setq paragraph-separate
+ (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-separate))
(make-local-variable 'paragraph-start)
(setq paragraph-start (concat "\b\\|@[a-zA-Z]*[ \n]\\|" paragraph-start))
+ (make-local-variable 'adaptive-fill-mode)
+ (setq adaptive-fill-mode nil)
(make-local-variable 'fill-column)
- (setq fill-column 72)
+ (setq fill-column 70)
(make-local-variable 'comment-start)
(setq comment-start "@c ")
(make-local-variable 'comment-start-skip)
- (setq comment-start-skip "@c +")
+ (setq comment-start-skip "@c +\\|@comment +")
(make-local-variable 'words-include-escapes)
(setq words-include-escapes t)
(make-local-variable 'imenu-generic-expression)
(setq imenu-generic-expression texinfo-imenu-generic-expression)
+ (setq imenu-case-fold-search nil)
(make-local-variable 'font-lock-defaults)
- (setq font-lock-defaults '(texinfo-font-lock-keywords t))
+ (setq font-lock-defaults
+ '(texinfo-font-lock-keywords nil nil nil backward-paragraph
+ (font-lock-syntactic-keywords
+ . texinfo-font-lock-syntactic-keywords)))
+ (set (make-local-variable 'parse-sexp-lookup-properties) t)
(make-local-variable 'outline-regexp)
- (setq outline-regexp
- (concat "@\\("
- (mapconcat 'car texinfo-section-list "\\>\\|")
- "\\>\\)"))
+ (setq outline-regexp
+ (concat "@" (regexp-opt (mapcar 'car texinfo-section-list) t) "\\>"))
(make-local-variable 'outline-level)
(setq outline-level 'texinfo-outline-level)
(make-local-variable 'tex-start-of-header)
- (setq tex-start-of-header "%**start")
+ (setq tex-start-of-header "%\\*\\*start")
(make-local-variable 'tex-end-of-header)
- (setq tex-end-of-header "%**end")
- (run-hooks 'text-mode-hook 'texinfo-mode-hook))
+ (setq tex-end-of-header "%\\*\\*end")
+ (make-local-variable 'tex-first-line-header-regexp)
+ (setq tex-first-line-header-regexp "^\\\\input")
+ (make-local-variable 'tex-trailer)
+ (setq tex-trailer "@bye\n")
+
+ ;; Prevent filling certain lines, in addition to ones specified
+ ;; by the user.
+ (let ((prevent-filling "^@\\(def\\|multitable\\)"))
+ (set (make-local-variable 'auto-fill-inhibit-regexp)
+ (if (null auto-fill-inhibit-regexp)
+ prevent-filling
+ (concat auto-fill-inhibit-regexp "\\|" prevent-filling)))))
+
\f
;;; Insert string commands
-(defconst texinfo-environment-regexp
- "^[ \t]*@\\(f?table\\|enumerate\\|itemize\
-\\|ifhtml\\|ifinfo\\|iftex\\|ifset\\|ifclear\
-\\|example\\|quotation\\|lisp\\|smallexample\\|smalllisp\\|display\\|format\
-\\|flushleft\\|flushright\\|ignore\\|group\\|tex\\|html\\|cartouche\\|menu\
-\\|titlepage\\|end\\|def[a-z]*[a-wyz]\\>\\)"
- "Regexp for environment-like Texinfo list commands.
-Subexpression 1 is what goes into the corresponding `@end' statement.")
+(defvar texinfo-block-default "example")
+
+(define-skeleton texinfo-insert-block
+ "Create a matching pair @<cmd> .. @end <cmd> at point.
+Puts point on a blank line between them."
+ (setq texinfo-block-default
+ (completing-read (format "Block name [%s]: " texinfo-block-default)
+ (mapcar 'list texinfo-environments)
+ nil nil nil nil texinfo-block-default))
+ \n "@" str \n _ \n "@end " str \n)
+
+(defun texinfo-inside-macro-p (macro &optional bound)
+ "Non-nil if inside a macro matching the regexp MACRO."
+ (condition-case nil
+ (save-excursion
+ (save-restriction
+ (narrow-to-region bound (point))
+ (while (progn
+ (up-list -1)
+ (not (condition-case nil
+ (save-excursion
+ (backward-sexp 1)
+ (looking-at macro))
+ (scan-error nil)))))
+ t))
+ (scan-error nil)))
+
+(defun texinfo-inside-env-p (env &optional bound)
+ "Non-nil if inside an environment matching the regexp @ENV."
+ (save-excursion
+ (and (re-search-backward (concat "@\\(end\\s +\\)?" env) bound t)
+ (not (match-end 1)))))
+
+(defun texinfo-insert-quote (&optional arg)
+ "Insert the appropriate quote mark for TeXinfo.
+Usually inserts the value of `texinfo-open-quote' (normally ``) or
+`texinfo-close-quote' (normally ''), depending on the context.
+With prefix argument or inside @code or @example, inserts a plain \"."
+ (interactive "*P")
+ (let ((top (or (save-excursion (re-search-backward "@node\\>" nil t))
+ (point-min))))
+ (if (or arg
+ (= (preceding-char) ?\\)
+ (save-excursion
+ (backward-char (length texinfo-open-quote))
+ (when (or (looking-at texinfo-open-quote)
+ (looking-at texinfo-close-quote))
+ (delete-char (length texinfo-open-quote))
+ t))
+ (texinfo-inside-macro-p "@\\(code\\|samp\\|kbd\\)\\>" top)
+ (texinfo-inside-env-p "example\\>" top)
+ (texinfo-inside-env-p "lisp\\>" top))
+ (self-insert-command (prefix-numeric-value arg))
+ (insert
+ (if (memq (char-syntax (preceding-char)) '(?\( ?> ?\ ))
+ texinfo-open-quote
+ texinfo-close-quote)))))
+
+;; The following texinfo-insert-@end command not only inserts a SPC
+;; after the @end, but tries to find out what belongs there. It is
+;; not very smart: it does not understand nested lists.
+
+(defun texinfo-last-unended-begin ()
+ (while (and (re-search-backward texinfo-environment-regexp)
+ (looking-at "@end"))
+ (texinfo-last-unended-begin)))
+
+(defun texinfo-next-unmatched-end ()
+ (while (and (re-search-forward texinfo-environment-regexp)
+ (save-excursion
+ (goto-char (match-beginning 0))
+ (not (looking-at "@end"))))
+ (texinfo-next-unmatched-end)))
(defun texinfo-insert-@end ()
"Insert the matching `@end' for the last Texinfo command that needs one."
(interactive)
- (let ((depth 1) string)
- (save-excursion
- (while (and (> depth 0)
- (re-search-backward texinfo-environment-regexp nil t)
- (if (looking-at "@end")
- (setq depth (1+ depth))
- (setq depth (1- depth)))))
- (looking-at texinfo-environment-regexp)
- (if (zerop depth)
- (setq string
- (buffer-substring (match-beginning 1)
- (match-end 1)))))
+ (let ((string
+ (ignore-errors
+ (save-excursion
+ (texinfo-last-unended-begin)
+ (match-string 1)))))
(insert "@end ")
(if string (insert string "\n"))))
;; These commands use texinfo-insert-@-with-arg
(defun texinfo-insert-@-with-arg (string &optional arg)
- (if arg
+ (if arg
(progn
(setq arg (prefix-numeric-value arg))
(if (< arg 0)
(interactive "P")
(texinfo-insert-@-with-arg "dfn" arg))
+(defun texinfo-insert-@email (&optional arg)
+ "Insert a `@email{...}' command in a Texinfo buffer.
+A numeric argument says how many words the braces should surround.
+The default is not to surround any existing words with the braces."
+ (interactive "P")
+ (texinfo-insert-@-with-arg "email" arg))
+
+(defun texinfo-insert-@emph (&optional arg)
+ "Insert a `@emph{...}' command in a Texinfo buffer.
+A numeric argument says how many words the braces should surround.
+The default is not to surround any existing words with the braces."
+ (interactive "P")
+ (texinfo-insert-@-with-arg "emph" arg))
+
(defun texinfo-insert-@example ()
"Insert the string `@example' in a Texinfo buffer."
(interactive)
(interactive)
(insert "@noindent\n"))
+(defun texinfo-insert-@quotation ()
+ "Insert the string `@quotation' in a Texinfo buffer."
+ (interactive)
+ (insert "@quotation\n"))
+
(defun texinfo-insert-@samp (&optional arg)
"Insert a `@samp{...}' command in a Texinfo buffer.
A numeric argument says how many words the braces should surround.
(interactive "P")
(texinfo-insert-@-with-arg "samp" arg))
+(defun texinfo-insert-@strong (&optional arg)
+ "Insert a `@strong{...}' command in a Texinfo buffer.
+A numeric argument says how many words the braces should surround.
+The default is not to surround any existing words with the braces."
+ (interactive "P")
+ (texinfo-insert-@-with-arg "strong" arg))
+
(defun texinfo-insert-@table (&optional arg)
"Insert the string `@table' in a Texinfo buffer."
(interactive "P")
The default is not to surround any existing words with the braces."
(interactive "P")
(texinfo-insert-@-with-arg "var" arg))
+
+(defun texinfo-insert-@uref (&optional arg)
+ "Insert a `@uref{}' command in a Texinfo buffer.
+A numeric argument says how many words the braces should surround.
+The default is not to surround any existing words with the braces."
+ (interactive "P")
+ (texinfo-insert-@-with-arg "uref" arg))
+(defalias 'texinfo-insert-@url 'texinfo-insert-@uref)
\f
;;; Texinfo file structure
-;; These are defined in tenfo-upd.el.
-(defvar texinfo-section-types-regexp)
-(defvar texinfo-section-level-regexp)
-(defvar texinfo-subsection-level-regexp)
-(defvar texinfo-subsubsection-level-regexp)
-
-(defun texinfo-show-structure (&optional nodes-too)
+(defun texinfo-show-structure (&optional nodes-too)
"Show the structure of a Texinfo file.
List the lines in the file that begin with the @-sign commands for
@chapter, @section, and the like.
Lines with structuring commands beginning in them are displayed in
another buffer named `*Occur*'. In that buffer, you can move point to
-one of those lines and then use \\<occur-mode-map>\\[occur-mode-goto-occurrence],
+one of those lines and then use
+\\<occur-mode-map>\\[occur-mode-goto-occurrence],
to jump to the corresponding spot in the Texinfo source file."
(interactive "P")
- (require 'texnfo-upd)
- (save-excursion
+ ;; First, remember current location
+ (let ((source-buffer (current-buffer))
+ current-location)
+ (save-excursion
+ (end-of-line) ; so as to find section on current line
+ (if (re-search-backward
+ ;; do not require `texinfo-section-types-regexp' in texnfo-upd.el
+ "^@\\(chapter \\|sect\\|subs\\|subh\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
+ nil t)
+ (setq current-location
+ (progn
+ (beginning-of-line)
+ (buffer-substring (point) (progn (end-of-line) (point)))))
+ ;; else point is located before before any section command
+ (setq current-location "tex")))
+ ;; Second, create and format an *Occur* buffer
+ (save-excursion
+ (goto-char (point-min))
+ (if nodes-too
+ (occur (concat "^@node\\>\\|" outline-regexp))
+ (occur outline-regexp)))
+ (pop-to-buffer "*Occur*")
+ (goto-char (point-min))
+ (let ((inhibit-read-only t))
+ (flush-lines "-----")
+ ;; Now format the "*Occur*" buffer to show the structure.
+ ;; Thanks to ceder@signum.se (Per Cederqvist)
+ (goto-char (point-max))
+ (let (level)
+ (while (re-search-backward "^ *[0-9]*:@\\(\\sw+\\)" nil 0)
+ (goto-char (1- (match-beginning 1)))
+ (setq level
+ (or (cadr (assoc (match-string 1) texinfo-section-list)) 2))
+ (indent-to-column (+ (current-column) (* 4 (- level 2))))
+ (beginning-of-line))))
+ ;; Third, go to line corresponding to location in source file
+ ;; potential bug: two exactly similar `current-location' lines ...
(goto-char (point-min))
- (if nodes-too
- (occur (concat "\\(^@node\\)\\|" texinfo-section-types-regexp))
- (occur texinfo-section-types-regexp)))
- (pop-to-buffer "*Occur*")
- (goto-char (point-min))
- (flush-lines "-----")
- ;; Now format the "*Occur*" buffer to show the structure.
- ;; Thanks to ceder@signum.se (Per Cederqvist)
- (goto-char (point-max))
- (let ((margin 5))
- (while (re-search-backward "^ *[0-9]*:" nil 0)
- (re-search-forward ":")
- (setq margin
- (cond
- ((looking-at
- (concat "@\\(" texinfo-chapter-level-regexp "\\)")) 5)
- ;; ((looking-at "@chapter ") 5)
- ;; ((looking-at "@unnumbered ") 5)
- ;; ((looking-at "@appendix ") 5)
- ;; ((looking-at "@majorheading ") 5)
- ;; ((looking-at "@chapheading ") 5)
-
- ((looking-at
- (concat "@\\(" texinfo-section-level-regexp "\\)")) 9)
- ;; ((looking-at "@section ") 9)
- ;; ((looking-at "@unnumberedsec ") 9)
- ;; ((looking-at "@appendixsec ") 9)
- ;; ((looking-at "@heading ") 9)
-
- ((looking-at
- (concat "@\\(" texinfo-subsection-level-regexp "\\)")) 13)
- ;; ((looking-at "@subsection ") 13)
- ;; ((looking-at "@unnumberedsubsec ") 13)
- ;; ((looking-at "@appendixsubsec ") 13)
- ;; ((looking-at "@subheading ") 13)
-
- ((looking-at
- (concat "@\\(" texinfo-subsubsection-level-regexp "\\)")) 17)
- ;; ((looking-at "@subsubsection ") 17)
- ;; ((looking-at "@unnumberedsubsubsec ") 17)
- ;; ((looking-at "@appendixsubsubsec ") 17)
- ;; ((looking-at "@subsubheading ") 17)
- (t margin)))
- (indent-to-column margin)
- (beginning-of-line))))
+ (re-search-forward current-location nil t)
+ (beginning-of-line)
+ ))
+
\f
;;; The tex and print function definitions:
-(defvar texinfo-texi2dvi-command "texi2dvi"
- "*Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer.")
+(defcustom texinfo-texi2dvi-command "texi2dvi"
+ "*Command used by `texinfo-tex-buffer' to run TeX and texindex on a buffer."
+ :type 'string
+ :group 'texinfo)
-(defvar texinfo-tex-command "tex"
- "*Command used by `texinfo-tex-region' to run TeX on a region.")
+(defcustom texinfo-tex-command "tex"
+ "*Command used by `texinfo-tex-region' to run TeX on a region."
+ :type 'string
+ :group 'texinfo)
-(defvar texinfo-texindex-command "texindex"
- "*Command used by `texinfo-texindex' to sort unsorted index files.")
+(defcustom texinfo-texindex-command "texindex"
+ "*Command used by `texinfo-texindex' to sort unsorted index files."
+ :type 'string
+ :group 'texinfo)
-(defvar texinfo-delete-from-print-queue-command "lprm"
+(defcustom texinfo-delete-from-print-queue-command "lprm"
"*Command string used to delete a job from the line printer queue.
Command is used by \\[texinfo-delete-from-print-queue] based on
number provided by a previous \\[tex-show-print-queue]
-command.")
+command."
+ :type 'string
+ :group 'texinfo)
(defvar texinfo-tex-trailer "@bye"
"String appended after a region sent to TeX by `texinfo-tex-region'.")
The value of `texinfo-tex-trailer' is appended to the temporary file after the region."
(interactive "r")
(require 'tex-mode)
- (if (get-buffer "*tex-shell*")
- (tex-kill-job)
- (tex-start-shell))
- (or tex-zap-file (setq tex-zap-file (make-temp-name "#tz")))
- (let ((tex-out-file (concat tex-zap-file ".tex"))
- (temp-buffer (get-buffer-create " tex-Output-Buffer"))
- (zap-directory
- (file-name-as-directory (expand-file-name tex-directory))))
- (save-excursion
- (save-restriction
- (widen)
- (goto-char (point-min))
- (forward-line 100)
- (let ((search-end (point))
- (hbeg (point-min)) (hend (point-min))
- (default-directory zap-directory))
- (goto-char (point-min))
-
- ;; Copy first line, the `\input texinfo' line, to temp file
- (write-region (point)
- (save-excursion (end-of-line) (point))
- tex-out-file nil nil)
-
- ;; Don't copy first line twice if region includes it.
- (forward-line 1)
- (if (< beg (point)) (setq beg (point)))
-
- ;; Initialize the temp file with either the header or nothing
- (if (search-forward tex-start-of-header search-end t)
- (progn
- (beginning-of-line)
- (setq hbeg (point)) ; Mark beginning of header.
- (if (search-forward tex-end-of-header nil t)
- (progn (beginning-of-line)
- (setq hend (point))) ; Mark end of header.
- (setq hbeg (point-min))))) ; Else no header.
-
- ;; Copy header to temp file.
- (write-region (min hbeg beg) hend tex-out-file t nil)
-
- ;; Copy region to temp file.
- (write-region (max beg hend) end tex-out-file t nil))
-
- ;; This is a kludge to insert the tex-trailer into the tex-out-file.
- ;; We have to create a special buffer in which to insert
- ;; the tex-trailer first because there is no function with
- ;; which to append a literal string directly to a file.
- (let ((local-tex-trailer texinfo-tex-trailer))
- (set-buffer temp-buffer)
- (erase-buffer)
- ;; make sure trailer isn't hidden by a comment
- (insert-string "\n")
- (if local-tex-trailer (insert-string local-tex-trailer))
- (tex-set-buffer-directory temp-buffer zap-directory)
- (write-region (point-min) (point-max) tex-out-file t nil))
-
-;;; The following is sufficient in Emacs 19.
-;;; (write-region (concat "\n" texinfo-tex-trailer) nil
-;;; tex-out-file t nil)
- ))
-
- (tex-set-buffer-directory "*tex-shell*" zap-directory)
- (tex-send-command tex-shell-cd-command zap-directory)
- (tex-send-command texinfo-tex-command tex-out-file))
- (tex-recenter-output-buffer 0))
+ (let ((tex-command texinfo-tex-command)
+ (tex-trailer texinfo-tex-trailer))
+ (tex-region beg end)))
(defun texinfo-tex-buffer ()
"Run TeX on visited file, once or twice, to make a correct `.dvi' file."
(interactive)
-
- ;; Make sure TeX shell is running.
(require 'tex-mode)
- (if (get-buffer "*tex-shell*")
- (quit-process (get-process "tex-shell") t)
- (tex-start-shell))
-
- (cond ((null buffer-file-name)
- (error "Buffer not visiting any file!"))
- ((buffer-modified-p)
- (error "Buffer has been modified since last saved!")))
-
- (setq tex-zap-file buffer-file-name)
-
- (tex-send-command tex-shell-cd-command (file-name-directory tex-zap-file))
-
- (tex-send-command texinfo-texi2dvi-command tex-zap-file)
-
- (tex-recenter-output-buffer 0))
+ (let ((tex-command texinfo-texi2dvi-command)
+ ;; Disable tex-start-options-string. texi2dvi would not
+ ;; understand anything specified here.
+ (tex-start-options-string ""))
+ (tex-buffer)))
(defun texinfo-texindex ()
"Run `texindex' on unsorted index files.
(interactive)
(require 'tex-mode)
(tex-send-command texinfo-texindex-command (concat tex-zap-file ".??"))
+ ;; alternatively
+ ;; (send-string "tex-shell"
+ ;; (concat texinfo-texindex-command
+ ;; " " tex-zap-file ".??" "\n"))
(tex-recenter-output-buffer nil))
(defun texinfo-tex-print ()
This runs the shell command defined by `tex-dvi-print-command'."
(interactive)
(require 'tex-mode)
- (tex-send-command tex-dvi-print-command (concat tex-zap-file ".dvi"))
- (tex-recenter-output-buffer nil))
+ (tex-print))
+
+(defun texinfo-tex-view ()
+ "View `.dvi' file made by \\[texinfo-tex-region] or \\[texinfo-tex-buffer].
+This runs the shell command defined by `tex-dvi-view-command'."
+ (interactive)
+ (require 'tex-mode)
+ (tex-view))
(defun texinfo-quit-job ()
"Quit currently running TeX job, by sending an `x' to it."
(if (not (get-process "tex-shell"))
(error "No TeX shell running"))
(tex-send-command "x"))
+;; alternatively:
+;; save-excursion
+;; (set-buffer (get-buffer "*tex-shell*"))
+;; (goto-char (point-max))
+;; (insert "x")
+;; (comint-send-input)
(defun texinfo-delete-from-print-queue (job-number)
"Delete job from the line printer spooling queue.
You are prompted for the job number (use a number shown by a previous
-\\[texinfo-show-print-queue] command)."
+\\[tex-show-print-queue] command)."
(interactive "nPrinter job number for deletion: ")
(require 'tex-mode)
(if (tex-shell-running)
(tex-kill-job)
(tex-start-shell))
(tex-send-command texinfo-delete-from-print-queue-command job-number)
+ ;; alternatively
+ ;; (send-string "tex-shell"
+ ;; (concat
+ ;; texinfo-delete-from-print-queue-command
+ ;; " "
+ ;; job-number"\n"))
(tex-recenter-output-buffer nil))
(provide 'texinfo)