Initial Commit
[packages] / xemacs-packages / auctex / tex-info.el
1 ;;; tex-info.el --- Support for editing Texinfo source.
2
3 ;; Copyright (C) 1993, 1994, 1997, 2000, 2001, 2004, 2005, 2006, 2011
4 ;;   Free Software Foundation, Inc.
5
6 ;; Maintainer: auctex-devel@gnu.org
7 ;; Keywords: tex
8
9 ;; This file is part of AUCTeX.
10
11 ;; AUCTeX is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
14 ;; any later version.
15
16 ;; AUCTeX is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with AUCTeX; see the file COPYING.  If not, write to the Free
23 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 ;; 02110-1301, USA.
25
26 ;;; Code:
27
28 (require 'tex)
29
30 (require 'texinfo)
31 ;; Make sure the Texinfo mode of AUCTeX is still used after loading
32 ;; texinfo.el.  (This is only an issue on Emacs 21.)
33 (when (and (boundp 'TeX-modes)
34            (memq 'texinfo-mode TeX-modes))
35   (defalias 'texinfo-mode 'TeX-texinfo-mode))
36
37 ;;; Environments:
38 (defvar Texinfo-environment-list
39   '(("cartouche") ("command") ("copying") ("defcv") ("deffn") ("defivar")
40     ("defmac") ("defmethod") ("defop") ("defopt") ("defspec")
41     ("deftp") ("deftypefn") ("deftypefun") ("deftypevar") ("deftypevr")
42     ("defun") ("defvar") ("defvr") ("description") ("detailmenu")
43     ("direntry") ("display") ("documentdescription") ("enumerate")
44     ("example") ("float") ("flushleft") ("flushright") ("format") ("ftable")
45     ("group") ("html") ("ifclear") ("ifdocbook") ("ifhtml") ("ifinfo")
46     ("ifnotdocbook") ("ifnothtml") ("ifnotinfo") ("ifnotplaintext")
47     ("ifnottex") ("ifnotxml") ("ifplaintext") ("ifset") ("iftex")
48     ("ifxml") ("ignore") ("itemize") ("lisp") ("macro") ("menu")
49     ("multitable") ("quotation") ("smalldisplay") ("smallexample")
50     ("smallformat") ("smalllisp") ("table") ("tex") ("titlepage")
51     ("verbatim") ("vtable"))
52   "Alist of Texinfo environments.")
53
54 (defconst texinfo-environment-regexp
55   ;; Overwrite version from `texinfo.el'.
56   (concat "^@\\("
57           (mapconcat 'car Texinfo-environment-list "\\|")
58           "\\|end\\)\\>")
59   "Regexp for environment-like Texinfo list commands.
60 Subexpression 1 is what goes into the corresponding `@end' statement.")
61
62 (defun Texinfo-environment (env &optional arg)
63   "Make Texinfo environment ENV.
64 With optional ARG, modify current environment."
65   ;; XXX: This could be enhanced to act like `LaTeX-environment',
66   ;; i.e. suggest a default environment and have its own history.
67   (interactive (list (completing-read "Environment: "
68                                       Texinfo-environment-list)
69                      current-prefix-arg))
70   (if arg
71       (Texinfo-modify-environment env)
72     (Texinfo-insert-environment env)))
73
74 (defun Texinfo-insert-environment (env)
75   "Insert Texinfo environment ENV."
76   (if (and (TeX-active-mark)
77            (not (eq (mark) (point))))
78       (progn
79         (when (< (mark) (point))
80           (exchange-point-and-mark))
81         (unless (TeX-looking-at-backward "^[ \t]*")
82           (newline))
83         (insert "@" env)
84         (newline)
85         (goto-char (mark))
86         (unless (TeX-looking-at-backward "^[ \t]*")
87           (newline))
88         (insert "@end " env)
89         (save-excursion (newline))
90         (end-of-line 0))
91     (insert "@" env "\n\n@end " env "\n")
92     (if (null (cdr-safe (assoc "defcv" Texinfo-environment-list)))
93         (forward-line -2))))
94
95 (defun Texinfo-modify-environment (env)
96   "Change current environment to environment ENV."
97   (save-excursion
98     (Texinfo-find-env-end)
99     (re-search-backward (concat (regexp-quote TeX-esc) "end \\([a-zA-Z]*\\)")
100                         (line-beginning-position))
101     (replace-match env t t nil 1)
102     (beginning-of-line)
103     (Texinfo-find-env-start)
104     (re-search-forward (concat (regexp-quote TeX-esc) "\\([a-zA-Z]*\\)")
105                        (line-end-position))
106     (replace-match env t t nil 1)))
107
108 (defun Texinfo-find-env-end ()
109   "Move point to the end of the current environment."
110   (interactive)
111   (let* ((envs (mapcar 'car Texinfo-environment-list))
112          (regexp (concat "^[ \t]*" (regexp-quote TeX-esc) "\\(end \\)*"
113                          (regexp-opt envs t) "\\b"))
114          (orig-pos (point))
115          (level 1)
116          case-fold-search)
117     (save-restriction
118       (save-excursion
119         (save-excursion
120           (beginning-of-line)
121           ;; Stop if point is inside of an @end <env> command, but not
122           ;; if it is behind it.
123           (when (and (looking-at regexp)
124                      (match-string 1)
125                      (> (match-end 0) orig-pos))
126             (setq level 0)))
127         (while (and (> level 0) (re-search-forward regexp nil t))
128           (if (match-string 1)
129               (setq level (1- level))
130             (setq level (1+ level)))))
131       (if (= level 0)
132           (goto-char (match-end 0))
133         (error "Can't locate end of current environment")))))
134
135 (defun Texinfo-find-env-start ()
136   "Move point to the start of the current environment."
137   (interactive)
138   (let* ((envs (mapcar 'car Texinfo-environment-list))
139          (regexp (concat "^[ \t]*\\(" (regexp-quote TeX-esc) "\\)\\(end \\)*"
140                          (regexp-opt envs t) "\\b"))
141          (level 1)
142          (orig-pos (point))
143          case-fold-search)
144     (save-restriction
145       (save-excursion
146         (save-excursion
147           (beginning-of-line)
148           ;; Stop if point is inside of an @<env> command, but not if
149           ;; it is before it.
150           (when (and (looking-at regexp)
151                      (not (match-string 2))
152                      (< (match-beginning 1) orig-pos))
153             (setq level 0)))
154         (while (and (> level 0) (re-search-backward regexp nil t))
155           (if (match-string 2)
156               (setq level (1+ level))
157             (setq level (1- level)))))
158       (if (= level 0)
159           (goto-char (match-beginning 0))
160         (error "Can't locate start of current environment")))))
161
162 (defun Texinfo-mark-environment (&optional count)
163   "Set mark to end of current environment and point to the matching begin.
164 If prefix argument COUNT is given, mark the respective number of
165 enclosing environments.  The command will not work properly if
166 there are unbalanced begin-end pairs in comments and verbatim
167 environments."
168   ;; TODO:
169   ;; This is identical to the LaTeX counterpart but for the find begin/end
170   ;; functions. So some day the implemenation should be factorized.
171   (interactive "p")
172   (setq count (if count (abs count) 1))
173   (let ((cur (point)) beg end)
174     ;; Only change point and mark after beginning and end were found.
175     ;; Point should not end up in the middle of nowhere if the search fails.
176     (save-excursion
177       (dotimes (c count)
178         (Texinfo-find-env-end))
179       (setq end (line-beginning-position 2))
180       (goto-char cur)
181       (dotimes (c count)
182         (Texinfo-find-env-start)
183         (unless (= (1+ c) count)
184           (beginning-of-line 0)))
185       (setq beg (point)))
186     (push-mark end)
187     (goto-char beg)
188     (TeX-activate-region)))
189
190 (defun Texinfo-mark-section (&optional no-subsection)
191   "Mark current section, with inclusion of any containing node.
192
193 The current section is detected as starting by any of the
194 structuring commands matched by regexp in variable
195 `outline-regexp' which in turn is a regexp matching any element
196 of variable `texinfo-section-list'.
197
198 If optional argument NO-SUBSECTION is set to any integer or is a
199 non nil empty argument (i.e. `C-u \\[Texinfo-mark-section]'),
200 then mark the current section with exclusion of any subsections.
201
202 Otherwise, any included subsections are also marked along with
203 current section.
204
205 Note that when current section is starting immediatley after a
206 node commande, then the node command is also marked as part as
207 the section."
208   (interactive "P")
209   (let (beg end is-beg-section is-end-section
210             (section-re (concat "^\\s-*" outline-regexp)))
211     (if (and (consp no-subsection) (eq (car no-subsection) 4))
212         ;; section with exclusion of any subsection
213         (setq beg (save-excursion
214                     (unless (looking-at section-re)
215                       (end-of-line))
216                     (re-search-backward section-re nil t))
217               is-beg-section t
218               end (save-excursion
219                     (beginning-of-line)
220                     (when
221                         (re-search-forward (concat section-re
222                                                    "\\|^\\s-*@bye\\_>" ) nil t)
223                       (save-match-data
224                         (beginning-of-line)
225                         (point))))
226               is-end-section (match-string 1))
227       ;; full section without exclusion of any subsection
228       (let (section-command-level)
229         (setq beg
230               (save-excursion
231                 (end-of-line)
232                 (re-search-backward section-re nil t)))
233         (when beg
234           (setq is-beg-section t
235                 section-command-level
236                 (cadr (assoc (match-string 1) texinfo-section-list))
237                 end
238                 (save-excursion
239                   (beginning-of-line)
240                   (while
241                       (and (re-search-forward
242                             (concat section-re "\\|^\\s-*@bye\\_>" ) nil t)
243                            (or (null (setq is-end-section  (match-string 1)))
244                                (> (cadr (assoc is-end-section
245                                                texinfo-section-list))
246                                   section-command-level))))
247                   (when (match-string 0)
248                     (beginning-of-line)
249                     (point)))))));  (if ...)
250     (when (and beg end)
251       ;; now take also enclosing node of beg and end
252       (dolist
253           (boundary '(beg end))
254         (when (symbol-value (intern (concat "is-" (symbol-name boundary)
255                                             "-section")))
256           (save-excursion
257             (goto-char (symbol-value boundary))
258             (while
259                 (and
260                  (null (bobp))
261                  (progn
262                    (beginning-of-line 0)
263                    (looking-at "^\\s-*\\($\\|@\\(c\\|comment\\)\\_>\\)"))))
264             (when  (looking-at "^\\s-*@node\\_>")
265               (set boundary (point))))))
266
267       (push-mark end)
268       (goto-char beg)
269       (TeX-activate-region) )))
270
271 (defun Texinfo-mark-node ()
272   "Mark the current node.  \
273 This is the node in which the pointer is.  It is starting at
274 previous beginning of keyword `@node' and ending at next
275 beginning of keyword `@node' or `@bye'."
276   (interactive)
277   (let ((beg (save-excursion
278                (unless (looking-at "^\\s-*@\\(?:node\\)\\_>")
279                  (end-of-line))
280                (re-search-backward "^\\s-*@\\(?:node\\)\\_>" nil t )))
281         (end (save-excursion
282                (beginning-of-line)
283                (and (re-search-forward "^\\s-*@\\(?:node\\|bye\\)\\_>" nil t )
284                     (progn (beginning-of-line) (point))))))
285
286     (when (and beg end)
287       (push-mark end)
288       (goto-char beg)
289       (TeX-activate-region) )))
290
291 (defun Texinfo-insert-node ()
292   "Insert a Texinfo node in the current buffer.
293 That means, insert the string `@node' and prompt for current,
294 next, previous and upper node.  If there is an active region, use
295 this for the current node and inhibit the prompt for it.  Insert
296 a comment on the following line indicating the order of arguments
297 for @node."
298   (interactive)
299   (let ((active-mark (and (TeX-active-mark) (not (eq (mark) (point)))))
300         nodes node-name next-node previous-node up-node)
301     ;; Build list of nodes in current buffer.
302     ;; (What about using `imenu--index-alist'?)
303     ;; FIXME: Support multi-file documents.
304     (save-excursion
305       (goto-char (point-min))
306       (while (re-search-forward "^@node\\b" nil t)
307         (skip-chars-forward " \t")
308         (add-to-list 'nodes
309                      (list (buffer-substring-no-properties
310                             (point) (progn (skip-chars-forward "^,")
311                                            (point)))))))
312     (unless active-mark
313       (setq node-name (read-string "Node name: ")))
314     ;; FIXME: What if key binding for `minibuffer-complete' was changed?
315     ;; `substitute-command-keys' doesn't return the correct value.
316     (setq next-node (completing-read "Next node (TAB completes): " nodes))
317     (setq previous-node
318           (completing-read "Previous node (TAB completes): " nodes))
319     (setq up-node (completing-read "Upper node (TAB completes): " nodes))
320     (when (and active-mark
321                (< (mark) (point)))
322       (exchange-point-and-mark))
323     (insert "@node ")
324     (if active-mark
325         (goto-char (mark))
326       (insert node-name))
327     (insert ", " next-node ", " previous-node ", " up-node
328             "\n@comment  node-name,  next,  previous,  up\n")
329     ;; Position point at first empty field.
330     (unless (and (or (> (length node-name) 0) active-mark)
331                  (> (length next-node) 0)
332                  (> (length previous-node) 0)
333                  (> (length  up-node) 0))
334       (forward-line -2)
335       (forward-char 6)
336       (catch 'break
337         (if (or (> (length node-name) 0) active-mark)
338             (progn (skip-chars-forward "^,") (forward-char 2))
339           (throw 'break nil))
340         (dolist (node (list next-node previous-node up-node))
341           (if (> (length node) 0)
342               (progn (skip-chars-forward "^,") (forward-char 2))
343             (throw 'break nil)))))))
344
345 ;; Silence the byte-compiler from warnings for variables and functions declared
346 ;; in reftex.
347 (eval-when-compile
348   (defvar reftex-section-levels-all)
349   (defvar reftex-level-indent)
350   (defvar reftex-label-menu-flags)
351   (defvar reftex-tables-dirty)
352
353   (when (fboundp 'declare-function)
354     (declare-function reftex-match-string "reftex" (n))
355     (declare-function reftex-section-number "reftex-parse" (&optional level star))
356     (declare-function reftex-nicify-text "reftex" (text))
357     (declare-function reftex-ensure-compiled-variables "reftex" ())))
358
359 (defun Texinfo-reftex-section-info (file)
360   ;; Return a section entry for the current match.
361   ;; Carefull: This function expects the match-data to be still in place!
362   (let* ((marker (set-marker (make-marker) (1- (match-beginning 3))))
363          (macro (reftex-match-string 3))
364          (level-exp (cdr (assoc macro reftex-section-levels-all)))
365          (level (if (symbolp level-exp)
366                     (save-match-data (funcall level-exp))
367                   level-exp))
368          (unnumbered  (< level 0))
369          (level (abs level))
370          (section-number (reftex-section-number level unnumbered))
371          (text1 (save-match-data
372                   (save-excursion
373                     (buffer-substring-no-properties (point) (progn (end-of-line) (point))))))
374          (literal (buffer-substring-no-properties
375                    (1- (match-beginning 3))
376                    (min (point-max) (+ (match-end 0) (length text1) 1))))
377          ;; Literal can be too short since text1 too short. No big problem.
378          (text (reftex-nicify-text text1)))
379
380     ;; Add section number and indentation
381     (setq text
382           (concat
383            (make-string (* reftex-level-indent level) ?\ )
384            (if (nth 1 reftex-label-menu-flags) ; section number flag
385                (concat section-number " "))
386            text))
387     (list 'toc "toc" text file marker level section-number
388           literal (marker-position marker))))
389
390 (defun Texinfo-reftex-hook ()
391   "Hook function to plug Texinfo into RefTeX."
392   ;; force recompilation of variables
393   (when (string= TeX-base-mode-name "Texinfo")
394     ;; dirty temporary hook to remove when reftex has a Texinfo builtin
395     ;; TODO --- taken on <2014-01-06 mon> --- remove the dirty trick once reftex
396     ;; has been corrected for long enough a time
397     (unless (assq 'Texinfo reftex-label-alist-builtin)
398       (setq reftex-label-alist-builtin (append reftex-label-alist-builtin
399                                                '((Texinfo "Texinfo default environments" nil)))))
400     (dolist (v `((reftex-section-pre-regexp . "@")
401                  ; section post-regexp must contain exactly one group
402                  (reftex-section-post-regexp . "\\([ \t]+\\)")
403                  (reftex-section-info-function . Texinfo-reftex-section-info)
404                  (reftex-default-label-alist-entries . (Texinfo))
405                (reftex-section-levels
406                 . ,(mapcar
407                     (lambda (x)
408                       (if (string-match "\\(\\`unnumbered\\)\\|\\(heading\\'\\)\\|\\(\\`top\\'\\)"
409                                         (car x))
410                           (cons (car x) (- (cadr x)))
411                         (cons (car x) (cadr x))))
412                     texinfo-section-list))))
413       (set (make-local-variable (car v) ) (cdr v)))
414     (reftex-ensure-compiled-variables)))
415
416 ;;; Keymap:
417
418 (defvar Texinfo-mode-map
419   (let ((map (make-sparse-keymap)))
420     (set-keymap-parent map TeX-mode-map)
421
422     ;; From texinfo.el
423     ;; bindings for updating nodes and menus
424     (define-key map "\C-c\C-um"      'texinfo-master-menu)
425     (define-key map "\C-c\C-u\C-m"   'texinfo-make-menu)
426     (define-key map "\C-c\C-u\C-n"   'texinfo-update-node)
427     (define-key map "\C-c\C-u\C-e"   'texinfo-every-node-update)
428     (define-key map "\C-c\C-u\C-a"   'texinfo-all-menus-update)
429
430     ;; Simulating LaTeX-mode
431     (define-key map "\C-c\C-e" 'Texinfo-environment)
432     (define-key map "\C-c." 'Texinfo-mark-environment)
433     (define-key map "\C-c*" 'Texinfo-mark-section)
434     (define-key map "\M-\C-h" 'Texinfo-mark-node)
435     (define-key map "\C-c\n"   'texinfo-insert-@item)
436     (or (key-binding "\e\r")
437         (define-key map "\e\r" 'texinfo-insert-@item)) ;*** Alias
438     (define-key map "\C-c\C-s" 'Texinfo-insert-node)
439     (define-key map "\C-c]" 'texinfo-insert-@end)
440     map)
441   "Keymap for Texinfo mode.")
442
443 (easy-menu-define Texinfo-command-menu
444   Texinfo-mode-map
445   "Menu used in Texinfo mode for external commands."
446   (TeX-mode-specific-command-menu 'texinfo-mode))
447
448 (easy-menu-define Texinfo-mode-menu
449   Texinfo-mode-map
450   "Menu used in Texinfo mode."
451   (TeX-menu-with-help
452    `("Texinfo"
453      ["Node ..." texinfo-insert-@node
454       :help "Insert a node"]
455      ["Macro ..." TeX-insert-macro
456       :help "Insert a macro and possibly arguments"]
457      ["Complete Macro" TeX-complete-symbol
458       :help "Complete the current macro"]
459      ["Environment ..." Texinfo-insert-environment
460       :help "Insert an environment"]
461      ["Item" texinfo-insert-@item
462       :help "Insert an @item"]
463      "-"
464      ("Insert Font"
465       ["Emphasize"  (TeX-font nil ?\C-e) :keys "C-c C-f C-e"]
466       ["Bold"       (TeX-font nil ?\C-b) :keys "C-c C-f C-b"]
467       ["Typewriter" (TeX-font nil ?\C-t) :keys "C-c C-f C-t"]
468       ["Small Caps" (TeX-font nil ?\C-c) :keys "C-c C-f C-c"]
469       ["Italic"     (TeX-font nil ?\C-i) :keys "C-c C-f C-i"]
470       ["Sample"    (TeX-font nil ?\C-s) :keys "C-c C-f C-s"]
471       ["Roman"      (TeX-font nil ?\C-r) :keys "C-c C-f C-r"])
472      ("Replace Font"
473       ["Emphasize"  (TeX-font t ?\C-e) :keys "C-u C-c C-f C-e"]
474       ["Bold"       (TeX-font t ?\C-b) :keys "C-u C-c C-f C-b"]
475       ["Typewriter" (TeX-font t ?\C-t) :keys "C-u C-c C-f C-t"]
476       ["Small Caps" (TeX-font t ?\C-c) :keys "C-u C-c C-f C-c"]
477       ["Italic"     (TeX-font t ?\C-i) :keys "C-u C-c C-f C-i"]
478       ["Sample"    (TeX-font t ?\C-s) :keys "C-u C-c C-f C-s"]
479       ["Roman"      (TeX-font t ?\C-r) :keys "C-u C-c C-f C-r"])
480      ["Delete Font" (TeX-font t ?\C-d) :keys "C-c C-f C-d"]
481      "-"
482      ["Create Master Menu" texinfo-master-menu
483       :help "Make a master menu for the whole Texinfo file"]
484      ["Create Menu" texinfo-make-menu
485       :help "Make or update the menu for the current section"]
486      ["Update Node" texinfo-update-node
487       :help "Update the current node"]
488      ["Update Every Node" texinfo-every-node-update
489       :help "Update every node in the current file"]
490      ["Update All Menus" texinfo-all-menus-update
491       :help "Update every menu in the current file"]
492      "-"
493      ("Commenting"
494       ["Comment or Uncomment Region"
495        TeX-comment-or-uncomment-region
496        :help "Comment or uncomment the currently selected region"]
497       ["Comment or Uncomment Paragraph"
498        TeX-comment-or-uncomment-paragraph
499        :help "Comment or uncomment the current paragraph"])
500      ,TeX-fold-menu
501      "-"
502      . ,TeX-common-menu-entries)))
503
504 (defvar Texinfo-font-list
505   '((?\C-b "@b{" "}")
506     (?\C-c "@sc{" "}")
507     (?\C-e "@emph{" "}")
508     (?\C-i "@i{" "}")
509     (?\C-r "@r{" "}")
510     (?\C-s "@samp{" "}")
511     (?\C-t "@t{" "}")
512     (?s    "@strong{" "}")
513     (?\C-f "@file{" "}")
514     (?d "@dfn{" "}")
515     (?\C-v "@var{" "}")
516     (?k    "@key{" "}")
517     (?\C-k "@kbd{" "}")
518     (?c    "@code{" "}")
519     (?C    "@cite{" "}")
520     (?\C-d "" "" t))
521   "Font commands used in Texinfo mode.  See `TeX-font-list'.")
522
523 ;;; Mode:
524
525 ;;;###autoload
526 (defalias 'Texinfo-mode 'texinfo-mode)
527
528 ;;;###autoload
529 (defun TeX-texinfo-mode ()
530   "Major mode in AUCTeX for editing Texinfo files.
531
532 Special commands:
533 \\{Texinfo-mode-map}
534
535 Entering Texinfo mode calls the value of `text-mode-hook'  and then the
536 value of `Texinfo-mode-hook'."
537   (interactive)
538   (kill-all-local-variables)
539   (setq TeX-mode-p t)
540   (setq TeX-sentinel-default-function 'TeX-TeX-sentinel)
541   ;; Mostly stolen from texinfo.el
542   (setq TeX-base-mode-name "Texinfo")
543   (setq major-mode 'texinfo-mode)
544   (use-local-map Texinfo-mode-map)
545   (set-syntax-table texinfo-mode-syntax-table)
546
547   (set (make-local-variable 'page-delimiter)
548        (concat
549         "^@node [ \t]*[Tt]op\\|^@\\("
550         texinfo-chapter-level-regexp
551         "\\)"))
552   (set (make-local-variable 'require-final-newline) t)
553   (set (make-local-variable 'indent-tabs-mode) nil)
554   (set (make-local-variable 'paragraph-separate)
555        (concat "\b\\|^@[a-zA-Z]*[ \n]\\|" paragraph-separate))
556   (set (make-local-variable 'paragraph-start)
557        (concat "\b\\|^@[a-zA-Z]*[ \n]\\|" paragraph-start))
558   (set (make-local-variable 'fill-column) 72)
559   (set (make-local-variable 'comment-start) "@c ")
560   (set (make-local-variable 'comment-start-skip) "@c +\\|@comment +")
561   (set (make-local-variable 'comment-use-syntax) nil)
562   (set (make-local-variable 'words-include-escapes) t)
563   (if (boundp 'texinfo-imenu-generic-expression)
564       ;; This was introduced in 19.30.
565       (set (make-local-variable 'imenu-generic-expression) texinfo-imenu-generic-expression))
566
567   (set (make-local-variable 'font-lock-defaults)
568         ;; COMPATIBILITY for Emacs 20
569         (if (boundp 'texinfo-font-lock-syntactic-keywords)
570             '(texinfo-font-lock-keywords
571               nil nil nil backward-paragraph
572               (font-lock-syntactic-keywords
573                . texinfo-font-lock-syntactic-keywords))
574           '(texinfo-font-lock-keywords t)))
575   (if (not (boundp 'texinfo-section-list))
576       ;; This was included in 19.31.
577       ()
578     (set (make-local-variable 'outline-regexp)
579          (concat "@\\("
580                  (mapconcat 'car texinfo-section-list "\\>\\|")
581                  "\\>\\)"))
582     (set (make-local-variable 'outline-level) 'texinfo-outline-level))
583
584   ;; Mostly AUCTeX stuff
585   (easy-menu-add Texinfo-mode-menu Texinfo-mode-map)
586   (easy-menu-add Texinfo-command-menu Texinfo-mode-map)
587   (set (make-local-variable 'TeX-command-current) 'TeX-command-master)
588
589   (setq TeX-default-extension "texi")
590   (set (make-local-variable 'TeX-esc) "@")
591
592   (set (make-local-variable 'TeX-auto-regexp-list) 'TeX-auto-empty-regexp-list)
593   (set (make-local-variable 'TeX-auto-update) t)
594
595   (setq TeX-command-default "TeX")
596   (setq TeX-header-end "%*end")
597   (setq TeX-trailer-start (regexp-quote (concat TeX-esc "bye")))
598
599   (set (make-local-variable 'TeX-complete-list)
600         (list (list "@\\([a-zA-Z]*\\)" 1 'TeX-symbol-list-filtered nil)
601               (list "" TeX-complete-word)))
602
603   (set (make-local-variable 'TeX-font-list) Texinfo-font-list)
604   (set (make-local-variable 'TeX-font-replace-function) 'TeX-font-replace-macro)
605   (set (make-local-variable 'TeX-style-hook-dialect) :texinfo)
606
607   (add-hook 'find-file-hooks (lambda ()
608                                (unless (file-exists-p (buffer-file-name))
609                                  (TeX-master-file nil nil t))) nil t)
610
611   (when (and (boundp 'add-log-current-defun-function)
612              (fboundp 'texinfo-current-defun-name))
613     (setq add-log-current-defun-function
614           #'texinfo-current-defun-name))
615
616   (TeX-add-symbols
617    '("acronym" "Acronym")
618    '("appendix" (TeX-arg-literal " ") (TeX-arg-free "Title"))
619    '("appendixsec" (TeX-arg-literal " ") (TeX-arg-free "Title"))
620    '("appendixsection" (TeX-arg-literal " ") (TeX-arg-free "Title"))
621    '("appendixsubsec" (TeX-arg-literal " ") (TeX-arg-free "Title"))
622    '("appendixsubsubsec" (TeX-arg-literal " ") (TeX-arg-free "Title"))
623    '("asis")
624    '("author" (TeX-arg-literal " ") (TeX-arg-free "Author"))
625    '("b" "Text")
626    '("bullet")
627    '("bye")
628    '("c" (TeX-arg-literal " ") (TeX-arg-free "Comment"))
629    '("caption" "Caption"
630      ;; TODO: caption is meaningful only inside float env. Maybe some checking
631      ;; and warning would be good.
632      )
633    '("center" (TeX-arg-literal " ") (TeX-arg-free "Line of text"))
634    '("chapheading" (TeX-arg-literal " ") (TeX-arg-free "Title"))
635    '("chapter" (TeX-arg-literal " ") (TeX-arg-free "Title"))
636    '("cindex" (TeX-arg-literal " ") (TeX-arg-free "Entry"))
637    '("cite" "Reference")
638    '("clear" (TeX-arg-literal " ") (TeX-arg-free "Flag"))
639    '("code" "Sample code")
640    '("command" "Command")
641    '("comment" (TeX-arg-literal " ") (TeX-arg-free "Comment"))
642    '("contents")
643    '("copyright" nil)
644    '("defcodeindex" (TeX-arg-literal " ") (TeX-arg-free "Index name"))
645    '("defindex" (TeX-arg-literal " ") (TeX-arg-free "Index name"))
646    '("dfn" "Term")
647    '("dmn" "Dimension")
648    '("dots" nil)
649    '("emph" "Text")
650    '("email" "Email address")
651    '("equiv" nil)
652    '("error")
653    '("evenfooting" Texinfo-lrc-argument-hook)
654    '("evenheading" Texinfo-lrc-argument-hook)
655    '("everyfooting" Texinfo-lrc-argument-hook)
656    '("everyheading" Texinfo-lrc-argument-hook)
657    '("exdent" (TeX-arg-literal " ") (TeX-arg-free "Line of text"))
658    '("expansion" nil)
659    '("file" "Filename")
660    '("finalout")
661    '("findex" (TeX-arg-literal " ") (TeX-arg-free "Entry"))
662    '("footnote" "Text of footnote")
663    '("footnotestyle" (TeX-arg-literal " ") (TeX-arg-free "Style"))
664    '("group")
665    '("heading" (TeX-arg-literal " ") (TeX-arg-free "Title"))
666    ;; XXX: Would be nice with completion.
667    '("headings" (TeX-arg-literal " ") (TeX-arg-free "On off single double"))
668    '("i" "Text")
669    '("ignore")
670    '("include" (TeX-arg-literal " ") (TeX-arg-free "Filename"))
671    '("inforef" "Node name" "Info file name")
672    '("item")
673    '("itemx")
674    '("kbd" "Keyboard characters")
675    '("key" "Key name")
676    '("kindex" (TeX-arg-literal " ") (TeX-arg-free "Entry"))
677    '("lowersections" 0)
678    '("majorheading" (TeX-arg-literal " ") (TeX-arg-free "Title"))
679    '("menu")
680    '("minus")
681    '("need" "N")
682    '("node" (TeX-arg-literal " ") (TeX-arg-free "Name")
683      (TeX-arg-literal ", ") (TeX-arg-free "Next")
684      (TeX-arg-literal ", ") (TeX-arg-free "Previous")
685      (TeX-arg-literal ", ") (TeX-arg-free "Up"))
686    '("noindent")
687    '("oddfooting" Texinfo-lrc-argument-hook)
688    '("oddheading" Texinfo-lrc-argument-hook)
689    '("page")
690    '("paragraphindent" (TeX-arg-literal " ") (TeX-arg-free "Indent"))
691    '("pindex" "Entry")
692    '("point" nil)
693    '("print")
694    '("printindex" (TeX-arg-literal " ") (TeX-arg-free "Index name"))
695    '("pxref" "Node name")
696    '("r" "Text")
697    '("raisesections" 0)
698    '("ref" "Node name")
699    '("refill")
700    '("result")
701    '("samp" "Text")
702    '("sc" "Text")
703    '("section" (TeX-arg-literal " ") (TeX-arg-free "Title"))
704    '("set" (TeX-arg-literal " ") (TeX-arg-free "Flag"))
705    ;; XXX: Would be nice with completion.
706    '("setchapternewpage" (TeX-arg-literal " ") (TeX-arg-free "On off odd"))
707    '("setfilename" (TeX-arg-literal " ") (TeX-arg-free "Info file name"))
708    '("settitle" (TeX-arg-literal " ") (TeX-arg-free "Title"))
709    '("shortcontents")
710    '("smallbook")
711    '("sp" "N")
712    '("strong" "Text")
713    '("subheading" (TeX-arg-literal " ") (TeX-arg-free "Title"))
714    '("subsection" (TeX-arg-literal " ") (TeX-arg-free "Title"))
715    '("subsubheading" (TeX-arg-literal " ") (TeX-arg-free "Title"))
716    '("subsubsection" (TeX-arg-literal " ") (TeX-arg-free "Title"))
717    '("subtitle" (TeX-arg-literal " ") (TeX-arg-free "Title"))
718    '("summarycontents")
719    '("syncodeindex" (TeX-arg-literal " ") (TeX-arg-free "From index")
720      (TeX-arg-literal " ") (TeX-arg-free "Into index"))
721    '("synindex" (TeX-arg-literal " ") (TeX-arg-free "From index")
722      (TeX-arg-literal " ") (TeX-arg-free "Into index"))
723    '("t" "Text")
724    '("TeX" nil)
725    '("thischapter")
726    '("thischaptername")
727    '("thisfile")
728    '("thispage")
729    '("tie")
730    '("tindex" (TeX-arg-literal " ") (TeX-arg-free "Entry"))
731    '("title" (TeX-arg-literal " ") (TeX-arg-free "Title"))
732    '("titlefont" "Text")
733    '("titlepage")
734    '("today" nil)
735    '("top" (TeX-arg-literal " ") (TeX-arg-free "Title"))
736    '("unnumbered" (TeX-arg-literal " ") (TeX-arg-free "Title"))
737    '("unnumberedsec" (TeX-arg-literal " ") (TeX-arg-free "Title"))
738    '("unnumberedsubsec" (TeX-arg-literal " ") (TeX-arg-free "Title"))
739    '("unnumberedsubsubsec" (TeX-arg-literal " ") (TeX-arg-free "Title"))
740    '("value" "Flag")
741    '("var" "Metasyntactic variable")
742    '("vindex" (TeX-arg-literal " ") (TeX-arg-free "Entry"))
743    '("vskip" (TeX-arg-literal " ") (TeX-arg-free "Amount"))
744    '("w" "Text")
745    '("xref" "Node name"))
746
747   ;; RefTeX plugging
748   (add-hook 'reftex-mode-hook 'Texinfo-reftex-hook)
749   (if (and (boundp 'reftex-mode) reftex-mode)
750       (Texinfo-reftex-hook))
751
752   (TeX-run-mode-hooks 'text-mode-hook 'Texinfo-mode-hook)
753   (TeX-set-mode-name))
754
755 (defcustom Texinfo-clean-intermediate-suffixes nil
756   "List of regexps matching suffixes of files to be deleted.
757 The regexps will be anchored at the end of the file name to be matched,
758 i.e. you do _not_ have to cater for this yourself by adding \\\\' or $."
759   :type '(repeat regexp)
760   :group 'TeX-command)
761
762 (defcustom Texinfo-clean-output-suffixes
763   ;; See `man texi2html' for the HTML stuff.
764   '("\\.info\\(-[0-9]+\\)?" "\\.dvi" "\\.pdf" "\\.ps" "\\.html"
765     "_toc\\.html" "_fot\\.html" "_abt\\.html" "_[0-9]+\\.html" "_l2h_img.+")
766   "List of regexps matching suffixes of files to be deleted.
767 The regexps will be anchored at the end of the file name to be matched,
768 i.e. you do _not_ have to cater for this yourself by adding \\\\' or $."
769   :type '(repeat regexp)
770   :group 'TeX-command)
771
772 (provide 'tex-info)
773
774 ;;; tex-info.el ends here