;;; texinfo.el --- major mode for editing Texinfo files
-;; Copyright (C) 1985, '88, '89, '90, '91,
+;; Copyright (C) 1985, '88, '89, '90, '91, '01,
;; '92, '93, '96, '97, 2000 Free Software Foundation, Inc.
;; Author: Robert J. Chassell
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
+;;; Todo:
+
+;; - facemenu support.
+
+;;; Commentary:
+
;;; Code:
(or (fboundp 'defgroup)
(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)
("^@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'.")
;; 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
- ("^\\*\\(.*\\)[\t ]*$" 1 font-lock-function-name-face t) ;menu items
- ("@\\(emph\\|strong\\|b\\|i\\|sc\\){\\([^}]+\\)" 2 font-lock-comment-face)
- ("@\\(file\\|kbd\\|key\\|url\\|uref\\|email\\){\\([^}]+\\)" 2 font-lock-string-face)
+ ("^\\*\\([^\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)
- ("@\\(cite\\|[ux]?ref\\|pxref\\){\\([^}]+\\)" 2 font-lock-constant-face)
- ("@\\(end\\|itemx?\\) +\\(.+\\)" 2 font-lock-function-name-face keep)
+ 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.")
+(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 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'."
(set (make-local-variable 'page-delimiter)
(setq imenu-case-fold-search nil)
(make-local-variable 'font-lock-defaults)
(setq font-lock-defaults
- '(texinfo-font-lock-keywords nil nil nil nil
+ '(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)
(set (make-local-variable 'auto-fill-inhibit-regexp)
(if (null auto-fill-inhibit-regexp)
prevent-filling
- (concat "\\(" auto-fill-inhibit-regexp "\\)\\|\\("
- prevent-filling "\\)")))))
+ (concat auto-fill-inhibit-regexp "\\|" prevent-filling)))))
+
\f
;;; Insert string commands
-(defconst texinfo-environments
- '("cartouche"
- "defcv"
- "deffn"
- "defivar"
- "defmac"
- "defmethod"
- "defop"
- "defopt"
- "defspec"
- "deftp"
- "deftypefn"
- "deftypefun"
- "deftypevar"
- "deftypevr"
- "defun"
- "defvar"
- "defvr"
- "description"
- "display"
- "enumerate"
- "example"
- "flushleft"
- "flushright"
- "format"
- "ftable"
- "group"
- "ifclear"
- "ifset"
- "ifhtml"
- "ifinfo"
- "ifnothtml"
- "ifnotinfo"
- "ifnottex"
- "iftex"
- "ignore"
- "itemize"
- "lisp"
- "macro"
- "multitable"
- "quotation"
- "smalldisplay"
- "smallexample"
- "smallformat"
- "smalllisp"
- "table"
- "tex"
- "titlepage"
- "vtable")
- "List of TeXinfo environments.")
-
-;; Keep as concatenated lists for ease of maintenance
-(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.")
-
(defvar texinfo-block-default "example")
(define-skeleton texinfo-insert-block
(completing-read (format "Block name [%s]: " texinfo-block-default)
(mapcar 'list texinfo-environments)
nil nil nil nil texinfo-block-default))
- (unless (save-excursion (beginning-of-line) (looking-at "[ \t]*$")) '\n)
- "@" str \n _ \n "@end " str \n)
+ \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."
(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)
- (texinfo-inside-macro-p "@\\(code\\|samp\\|kbd\\)\\>" top))
+ (texinfo-inside-env-p "lisp\\>" top))
(self-insert-command (prefix-numeric-value arg))
(insert
- (cond ((= (preceding-char) ?\\) ?\")
- ((memq (char-syntax (preceding-char)) '(?\( ?> ?\ ))
- texinfo-open-quote)
- (t texinfo-close-quote))))))
+ (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))
- (setq depth (if (looking-at "@end") (1+ depth) (1- depth))))
- (when (zerop depth)
- ;; This looking-at is unnecessary since if depth==0,
- ;; (looking-at "@end") has just failed, so the match data is still
- ;; the one from re-search-backward -sm
- ;; (looking-at texinfo-environment-regexp)
- (setq string (match-string 1))))
+ (let ((string
+ (ignore-errors
+ (save-excursion
+ (texinfo-last-unended-begin)
+ (match-string 1)))))
(insert "@end ")
(if string (insert string "\n"))))
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")
- (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\\>\\|" 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)))))
+ (re-search-forward current-location nil t)
+ (beginning-of-line)
+ ))
+
\f
;;; The tex and print function definitions: