Initial Commit
[packages] / xemacs-packages / auctex / style / latexinfo.el
1 ;;; latexinfo.el - Support for LaTeXinfo files.
2
3 ;; Copyright (C) 1993 Marc Gemis <makke@wins.uia.ac.be>
4
5 ;; Author: Marc Gemis <makke@wins.uia.ac.be>
6
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
10 ;; any later version.
11 ;; 
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;; GNU General Public License for more details.
16 ;; 
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program; if not, write to the Free Software
19 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 ;;; Code:
22
23 ;;; LaTeXinfo mode
24
25 (defvar TeX-latexinfo-node-regexp
26   '("\\\\node[ \t]+\\([^,\n\r%]+\\)" 1 TeX-auto-label)
27   "Matches LaTeXinfo \\node commands, only current node will be found.
28 We ignore next, previous and up fields.")
29
30 (defvar LaTeXinfo-mode nil
31   "Non-nil means LaTeXinfo minor mode is active.")
32   (make-variable-buffer-local 'LaTeXinfo-mode)
33
34 (defvar LaTeXinfo-mode-map nil
35   "Keymap containing LaTeXinfo commands.")
36
37 (if LaTeXinfo-mode-map
38     ()
39   (setq LaTeXinfo-mode-map (make-sparse-keymap))
40   (define-key LaTeXinfo-mode-map "\C-c\C-u\C-b" 'latexinfo-format-buffer)
41   (define-key LaTeXinfo-mode-map "\C-c\C-u\C-r" 'latexinfo-format-region)
42   (define-key LaTeXinfo-mode-map "\C-c\C-u\C-s" 'latexinfo-show-structure)
43   (define-key LaTeXinfo-mode-map "\C-c\C-ud" 'makke:latexinfo-delete-structure)
44   (define-key LaTeXinfo-mode-map "\C-c\C-ug" 'latexinfo-goto-node)
45   (define-key LaTeXinfo-mode-map "\C-c\C-ui" 'makke:latexinfo-structure))
46
47 (or (assq 'LaTeXinfo-mode minor-mode-map-alist)
48     (setq minor-mode-map-alist
49           (cons (cons 'LaTeXinfo-mode LaTeXinfo-mode-map)
50                 minor-mode-map-alist)))
51
52 (defun TeX-arg-latexinfo-index (optional &optional prompt)
53   "Prompt for a LaTeXinfo index type with completion."
54   (TeX-argument-insert
55    (completing-read (TeX-argument-prompt optional prompt "Index")
56                     '(("cp") ("vr") ("fn") ("tp") ("pg") ("ky"))
57                     nil t)
58    optional))
59
60 (defun LaTeX-item-latexinfo-menu ()
61   "Insert a new menu item"
62   (insert "* ::")
63   (backward-char 2))
64
65 (defun latexinfo-goto-node () ; temporarily here, later in latexinfo-upd.el ??
66   "Place pointer on the node given by the user, read node with completion
67 This fails when the user types in the label of something else"
68   (interactive)
69   (let ((node-name (completing-read "Goto Node: " (LaTeX-label-list))))
70     (goto-char (point-min))
71     (if (re-search-forward
72          (concat
73           TeX-esc "node[ \\t]+" node-name ","
74           "\\|"
75           TeX-esc "label{" LaTeX-section-label node-name
76           "\\|"
77           TeX-esc "label{" node-name
78           )
79          (point-max) t)
80         (beginning-of-line 1)
81     (error "No such node"))))
82
83 ;;; Hook
84
85 (TeX-add-style-hook "latexinfo"
86  (function
87   (lambda ()
88     (require 'latexinfo)
89     (require 'latexinfo-structure)
90
91     (require 'min-map)
92     (setq LaTeXinfo-mode t)
93     
94     (TeX-auto-add-regexp TeX-latexinfo-node-regexp)
95
96     (TeX-add-symbols
97      '("node"
98        (TeX-arg-literal " ")
99        (TeX-arg-free TeX-arg-define-label "Node name")
100        (TeX-arg-literal ", ")
101        (TeX-arg-free TeX-arg-ref "Next node")
102        (TeX-arg-literal ", ")
103        (TeX-arg-free TeX-arg-ref "Previous node")
104        (TeX-arg-literal ", ")
105        (TeX-arg-free TeX-arg-ref "Up node"))
106      '("setfilename" TeX-arg-file)
107
108      '("var" t)
109      '("dfn" t)
110      '("emph" t)
111      '("kbd" t)
112      '("code" t)
113      '("samp" t)
114      '("key" t)
115      '("ctrl" t)
116      '("file" t)
117
118      '("comment"
119        (TeX-arg-literal " ")
120        (TeX-arg-free "Comment"))
121      '("c"
122        (TeX-arg-literal " ")
123        (TeX-arg-free "Comment"))
124
125      '("cindex" t)
126      '("cpsubindex" 2)
127      '("cpindexbold" t)
128
129      '("newindex" TeX-arg-latexinfo-index)
130
131      '("br" nil)
132      '("w" "Text")
133      '("dots" nil)
134      '("refill" nil)
135      '("bullet" nil)
136      '("copyright" nil)
137      '("sp" nil)
138
139      '("xref" TeX-arg-ref)
140      '("pxref" TeX-arg-ref)
141      '("inforef"
142        (TeX-arg-literal "{")
143        (TeX-arg-free "Name of node")
144        (TeX-arg-literal ", ")
145        (TeX-arg-free "Name for note")
146        (TeX-arg-literal ", ")
147        (TeX-arg-free TeX-arg-file "Info file")
148        (TeX-arg-literal "}")))
149
150     (LaTeX-add-environments "menu" "tex" "ignore" "ifinfo" "iftex"
151                             "example" "same" "display" "format")
152
153     ; Menu's have a special kind of items
154     (make-local-variable 'LaTeX-item-list)
155     (setq LaTeX-item-list (cons '("menu" . LaTeX-item-latexinfo-menu)
156                                 LaTeX-item-list))
157
158     (make-local-variable 'TeX-font-list)
159     (setq TeX-font-list
160           (list (list ?\C-b (concat TeX-esc "b{") "}")
161                 (list ?\C-c (concat TeX-esc "sc{") "}")
162                 (list ?\C-e (concat TeX-esc "emph{") "}")
163                 (list ?\C-i (concat TeX-esc "i{") "}")
164                 (list ?\C-r (concat TeX-esc "r{") "}")
165                 (list ?\C-s (concat TeX-esc "samp{") "}")
166                 (list ?\C-t (concat TeX-esc "t{") "}")
167                 (list ?s    (concat TeX-esc "strong{") "}")
168                 (list ?\C-f (concat TeX-esc "file{") "}")
169                 (list ?\C-d (concat TeX-esc "dfn{") "}")
170                 (list ?\C-v (concat TeX-esc "var{") "}")
171                 (list ?k    (concat TeX-esc "key{") "}")
172                 (list ?\C-k (concat TeX-esc "kbd{") "}")
173                 (list ?c    (concat TeX-esc "code{") "}")
174                 (list ?C    (concat TeX-esc "cite{") "}")))
175
176     ;; need the following stuff to let xref and pxref work
177     (make-local-variable 'LaTeX-section-label)
178     (setq LaTeX-section-label "")))
179  LaTeX-dialect)
180
181 ;;; latexinfo.el ends here