]> code.delx.au - gnu-emacs-elpa/blob - packages/auctex-11.86/tex-bar.el
(debbugs-emacs): New function and modes for listing the Emacs bugs, reading them...
[gnu-emacs-elpa] / packages / auctex-11.86 / tex-bar.el
1 ;;; tex-bar.el --- toolbar icons on AUCTeX in GNU emacs and XEmacs
2
3 ;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4
5 ;; This program is free software; you can redistribute it and/or
6 ;; modify it under the terms of the GNU General Public License as
7 ;; published by the Free Software Foundation; either version 3 of
8 ;; the License, or (at your option) any later version.
9
10 ;; This program is distributed in the hope that it will be
11 ;; useful, but WITHOUT ANY WARRANTY; without even the implied
12 ;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 ;; PURPOSE. See the GNU General Public License for more details.
14
15 ;; You should have received a copy of the GNU General Public
16 ;; License along with this program; if not, write to the Free
17 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
18 ;; MA 02110-1301 USA
19
20 ;; Author: Miguel V. S. Frasson <frasson@math.leidenuniv.nl>
21 ;; Keywords: tool-bar, tex, latex
22
23 ;;; Commentary:
24 ;;
25
26 ;; This package also needs `toolbar-x.el', and `latex.el' for the
27 ;; symbol-toolbar.
28
29 ;;; Use of this preliminary version:
30
31 ;; - Add `LaTeX-install-toolbar' to `LaTeX-mode-hook'.
32
33 ;; Special requirements for the use of experimental symbol-toolbar:
34
35 ;; - Customize `TeX-bar-LaTeX-buttons', adding the label
36 ;; `LaTeX-symbols-experimental' at the end.
37
38 ;; - You should have a folder called "symb-pics" with the pics of the
39 ;; symbols (xpm format is a good one), and the *parent* of this
40 ;; folder should be in `load-path'.
41
42 ;; Did you read carefully this item? I will say again: the folder
43 ;; "symb-pics" should *not* be in `load-path', but its *parent*.
44
45 ;; - each image file is named after the command that it represents in
46 ;; the following rules: the base name is the name of the command
47 ;; without the escape character "\", like \delta -> "delta.xpm";
48 ;; however, since in some OS filenames are case insensitive, all
49 ;; occurences of capital letter should be replaced by the letter
50 ;; plus a dash: \Rightarrow -> "R-ightarrow.xpm" --- actually, for
51 ;; the correct name, apply `TeX-bar-img-filename' to "Rightarrow"
52 ;; (TeX-bar-img-filename "Rightarrow")
53 ;; --> "R-ightarrow"
54 ;; The function `TeX-bar-img-filename' also treats special commands
55 ;; like `\{', `\|', etc.
56
57 ;; You can get the symbol images on (temporary solution)
58 ;; http://www.math.leidenuniv.nl/~frasson/symb-pics.tar.gz
59
60 ;;; Code:
61
62 (require 'custom)
63
64 (require 'toolbar-x)
65
66 ;; for error handling
67 (require 'tex-buf)
68
69 ;; For the symbol toolbar
70 (require 'latex)
71
72 ;;; Standard buttons
73
74 ;; help strings
75 (defun TeX-bar-help-from-command-list (item)
76 "Return the help string of ITEM in `TeX-command-list'.
77 If there is no help, the empty string is returned."
78 (let ((help (nth 1 (memq :help (assoc item TeX-command-list)))))
79 (if help help "")))
80
81 (defgroup TeX-tool-bar nil
82 "Tool bar support in AUCTeX."
83 :group 'AUCTeX)
84
85 (defcustom TeX-bar-TeX-buttons
86 '(new-file open-file dired kill-buffer save-buffer cut copy paste undo
87 [separator nil] tex next-error view bibtex)
88 "List of buttons available in `tex-mode'.
89 It should be a list in the same format of the BUTTONS parameter
90 in function `toolbarx-install-toolbar', often a symbol that
91 labels a button or Emacs/XEmacs choice of buttons.
92
93 Type `\\[TeX-bar-TeX-buttons]' for a list of available buttons.
94
95 Buttons are defined in alists (labels associated to properties
96 that define a button). For a list of variables that hold such
97 alists, see variable `TeX-bar-TeX-all-button-alists'."
98 :type '(list (set :inline t
99 (const new-file)
100 (const open-file)
101 (const dired)
102 (const kill-buffer)
103 (const save-buffer)
104 (const write-file)
105 (const undo)
106 (const cut)
107 (const copy)
108 (const paste)
109 (const search-forward)
110 (const print-buffer)
111 (const [separator nil])
112 (const tex)
113 (const next-error)
114 (const view)
115 (const file)
116 (const bibtex)
117 (const clean))
118 ;; (const latex-symbols-experimental)
119 (repeat (choice (symbol :tag "Label")
120 (vector :args ((symbol :tag "Label in Emacs ")
121 (symbol :tag "Label in XEmacs"))
122 :tag "Emacs/XEmacs choice")
123 (sexp :tag "General element"))))
124 :group 'TeX-tool-bar)
125
126 (defun TeX-bar-TeX-buttons ()
127 "Display in a buffer a list of buttons for `tex-bar.el'."
128 (interactive)
129 (let ((assqs-button-alists)
130 (labels))
131 (dolist (m-alist TeX-bar-TeX-all-button-alists)
132 (setq labels nil)
133 (dolist (as (eval m-alist))
134 (setq labels (cons (car as) labels)))
135 (setq assqs-button-alists (cons (cons m-alist (nreverse labels))
136 assqs-button-alists)))
137 (setq assqs-button-alists (nreverse assqs-button-alists))
138 ;; displaying results
139 (save-excursion
140 (set-buffer (get-buffer-create "*TeX tool bar buttons*"))
141 (erase-buffer)
142 (insert "Available buttons for TeX mode
143 ================================")
144 (dolist (i assqs-button-alists)
145 (insert (format "\n\n`%s' provides the following buttons:\n " (car i)))
146 (dolist (j (cdr i))
147 (insert (format " %s" j)))
148 (fill-region (point-at-bol) (point-at-eol))))
149 (display-buffer "*TeX tool bar buttons*" t)))
150
151 (defgroup TeX-tool-bar-button-definitions nil
152 "Collections of button definitions."
153 :group 'TeX-tool-bar)
154
155 (defcustom TeX-bar-TeX-all-button-alists
156 '(TeX-bar-TeX-button-alist
157 toolbarx-default-toolbar-meaning-alist)
158 "List of variables that hold buttons properties.
159 Each element should be a symbol bound to list in the format of
160 the argument BUTTON-ALIST in function `toolbarx-install-toolbar'."
161 :type '(repeat variable)
162 :group 'TeX-tool-bar-button-definitions)
163
164 (defcustom TeX-bar-TeX-button-alist
165 '((tex :image (lambda nil (if TeX-PDF-mode "pdftex" "tex"))
166 :command (progn
167 (TeX-save-document (TeX-master-file))
168 (TeX-command "TeX" 'TeX-master-file -1))
169 :help (lambda (&rest ignored)
170 (TeX-bar-help-from-command-list "TeX")))
171 (pdftex :image "pdftex"
172 :command (progn
173 (TeX-save-document (TeX-master-file))
174 (TeX-command "PDFTeX" 'TeX-master-file -1))
175 :help (lambda (&rest ignored)
176 (TeX-bar-help-from-command-list "PDFTeX")))
177 (next-error :image "error"
178 :command TeX-next-error
179 :enable (plist-get TeX-error-report-switches
180 (intern (TeX-master-file)))
181 :visible (plist-get TeX-error-report-switches
182 (intern (TeX-master-file))))
183 (view :image (lambda nil (if TeX-PDF-mode "viewpdf" "viewdvi"))
184 :command (TeX-command "View" 'TeX-master-file -1)
185 :help (lambda (&rest ignored)
186 (TeX-bar-help-from-command-list "View")))
187 (file :image "dvips"
188 :command (TeX-command "File" 'TeX-master-file -1)
189 :visible (not TeX-PDF-mode)
190 :help (lambda (&rest ignored)
191 (TeX-bar-help-from-command-list "File")))
192 (bibtex :image "bibtex"
193 :command (TeX-command "BibTeX" 'TeX-master-file -1)
194 :help (lambda (&rest ignored)
195 (TeX-bar-help-from-command-list "BibTeX")))
196 (clean :image "delete"
197 :command (TeX-command "Clean" 'TeX-master-file -1)
198 :help (lambda (&rest ignored)
199 (TeX-bar-help-from-command-list "Clean"))))
200 ;; latex-symbols-experimental?
201 "Alist for button definitions in TeX bar.
202 Value should le a list where each element is of format (KEY .
203 PROPS), where KEY is a symbol that labels the button and PROPS is
204 a list of properties of the button. For a description of the
205 format of PROPS, please see documentation of function
206 `toolbarx-install-toolbar'. This custom variable is in the same
207 format of the argument MEANING-ALIST in the mentioned function."
208 :type '(alist :key-type symbol :value-type sexp)
209 :group 'TeX-tool-bar-button-definitions)
210
211 ;;; Installation of the tool bar
212 ;;;###autoload
213 (defun TeX-install-toolbar ()
214 "Install toolbar buttons for TeX mode."
215 (interactive)
216 (require 'toolbar-x)
217 (add-to-list 'toolbarx-image-path
218 (expand-file-name "images" TeX-data-directory))
219 (add-hook 'TeX-PDF-mode-hook 'toolbarx-refresh nil t)
220 (toolbarx-install-toolbar TeX-bar-TeX-buttons
221 (let ((append-list))
222 (dolist (elt TeX-bar-TeX-all-button-alists)
223 (setq append-list (append append-list
224 (eval elt))))
225 append-list)))
226
227 (defcustom TeX-bar-LaTeX-buttons
228 '(new-file open-file dired kill-buffer save-buffer cut copy paste undo
229 [separator nil] latex next-error view bibtex)
230 "List of buttons available in `latex-mode'.
231 It should be a list in the same format of the BUTTONS parameter
232 in function `toolbarx-install-toolbar', often a symbol that
233 labels a button or Emacs/XEmacs choice of buttons.
234
235 Type `\\[TeX-bar-LaTeX-buttons]' for a list of available buttons.
236
237 Buttons are defined in alists (labels associated to properties
238 that define a button). For a list of variables that hold such
239 alists, see variable `TeX-bar-LaTeX-all-button-alists'."
240 :type '(list (set :inline t
241 (const new-file)
242 (const open-file)
243 (const dired)
244 (const kill-buffer)
245 (const save-buffer)
246 (const write-file)
247 (const undo)
248 (const cut)
249 (const copy)
250 (const paste)
251 (const search-forward)
252 (const print-buffer)
253 (const [separator nil])
254 (const latex)
255 (const next-error)
256 (const view)
257 (const file)
258 (const bibtex)
259 (const clean)
260 (const latex-symbols-experimental))
261 (repeat (choice (symbol :tag "Label")
262 (vector :args ((symbol :tag "Label in Emacs ")
263 (symbol :tag "Label in XEmacs"))
264 :tag "Emacs/XEmacs choice")
265 (sexp :tag "General element"))))
266 :group 'TeX-tool-bar)
267
268 (defun TeX-bar-LaTeX-buttons ()
269 "Display in a buffer a list of buttons for `tex-bar.el'."
270 (interactive)
271 (let ((assqs-button-alists)
272 (labels))
273 (dolist (m-alist TeX-bar-LaTeX-all-button-alists)
274 (setq labels nil)
275 (dolist (as (eval m-alist))
276 (setq labels (cons (car as) labels)))
277 (setq assqs-button-alists (cons (cons m-alist (nreverse labels))
278 assqs-button-alists)))
279 (setq assqs-button-alists (nreverse assqs-button-alists))
280 ;; displaying results
281 (save-excursion
282 (set-buffer (get-buffer-create "*TeX tool bar buttons*"))
283 (erase-buffer)
284 (insert "Available buttons for LaTeX mode
285 ================================")
286 (dolist (i assqs-button-alists)
287 (insert (format "\n\n`%s' provides the following buttons:\n " (car i)))
288 (dolist (j (cdr i))
289 (insert (format " %s" j)))
290 (fill-region (point-at-bol) (point-at-eol))))
291 (display-buffer "*TeX tool bar buttons*" t)))
292
293 (defgroup TeX-tool-bar-button-definitions nil
294 "Collections of button definitions."
295 :group 'TeX-tool-bar)
296
297 (defcustom TeX-bar-LaTeX-all-button-alists
298 '(TeX-bar-LaTeX-button-alist
299 toolbarx-default-toolbar-meaning-alist)
300 "List of variables that hold buttons properties.
301 Each element should be a symbol bound to list in the format of
302 the argument BUTTON-ALIST in function `toolbarx-install-toolbar'."
303 :type '(repeat variable)
304 :group 'TeX-tool-bar-button-definitions)
305
306 (defcustom TeX-bar-LaTeX-button-alist
307 '((latex :image (lambda nil (if TeX-PDF-mode "pdftex" "tex"))
308 :command (progn
309 (TeX-save-document (TeX-master-file))
310 (TeX-command "LaTeX" 'TeX-master-file -1))
311 :help (lambda (&rest ignored)
312 (TeX-bar-help-from-command-list "LaTeX")))
313 (pdflatex :image "pdftex"
314 :command (progn
315 (TeX-save-document (TeX-master-file))
316 (TeX-command "PDFLaTeX" 'TeX-master-file -1))
317 :help (lambda (&rest ignored)
318 (TeX-bar-help-from-command-list "PDFLaTeX")))
319 (next-error :image "error"
320 :command TeX-next-error
321 :enable (plist-get TeX-error-report-switches
322 (intern (TeX-master-file)))
323 :visible (plist-get TeX-error-report-switches
324 (intern (TeX-master-file))))
325 (view :image (lambda nil (if TeX-PDF-mode "viewpdf" "viewdvi"))
326 :command (TeX-command "View" 'TeX-master-file -1)
327 :help (lambda (&rest ignored)
328 (TeX-bar-help-from-command-list "View")))
329 (file :image "dvips"
330 :command (TeX-command "File" 'TeX-master-file -1)
331 :visible (not TeX-PDF-mode)
332 :help (lambda (&rest ignored)
333 (TeX-bar-help-from-command-list "File")))
334 (bibtex :image "bibtex"
335 :command (TeX-command "BibTeX" 'TeX-master-file -1)
336 :help (lambda (&rest ignored)
337 (TeX-bar-help-from-command-list "BibTeX")))
338 (clean :image "delete"
339 :command (TeX-command "Clean" 'TeX-master-file -1)
340 :help (lambda (&rest ignored)
341 (TeX-bar-help-from-command-list "Clean")))
342 (latex-symbols-experimental . (:alias :eval-group
343 LaTeX-symbols-toolbar-switch-contents
344 LaTeX-symbols-toolbar-contents)))
345 "Alist for button definitions in TeX bar.
346 Value should le a list where each element is of format (KEY .
347 PROPS), where KEY is a symbol that labels the button and PROPS is
348 a list of properties of the button. For a description of the
349 format of PROPS, please see documentation of function
350 `toolbarx-install-toolbar'. This custom variable is in the same
351 format of the argument MEANING-ALIST in the mentioned function."
352 :type '(alist :key-type symbol :value-type sexp)
353 :group 'TeX-tool-bar-button-definitions)
354
355 ;;; Installation of the tool bar
356 ;;;###autoload
357 (defun LaTeX-install-toolbar ()
358 "Install toolbar buttons for LaTeX mode."
359 (interactive)
360 (require 'toolbar-x)
361 (add-to-list 'toolbarx-image-path
362 (expand-file-name "images" TeX-data-directory))
363 (add-hook 'TeX-PDF-mode-hook 'toolbarx-refresh nil t)
364 (toolbarx-install-toolbar TeX-bar-LaTeX-buttons
365 (let ((append-list))
366 (dolist (elt TeX-bar-LaTeX-all-button-alists)
367 (setq append-list (append append-list
368 (eval elt))))
369 append-list)))
370
371 ;;; Experimental Symbol Toolbar
372
373 ;;; symbol toolbar
374 (defun TeX-bar-img-filename (tex-command)
375 "Return the filename (no extension) for the image button of TEX-COMMAND."
376 (let ((str-list (append tex-command nil))
377 (str-result))
378 (dolist (i str-list)
379 (cond
380 ;; capital letter -> letter + "-"
381 ((and (>= i ?A) (<= i ?Z))
382 (setq str-result (cons ?- (cons i str-result))))
383 ;; lowercase letter -> letter
384 ((and (>= i ?a) (<= i ?z))
385 (setq str-result (cons i str-result)))
386 ;; open curly brackets `{' -> "ocb--"
387 ((eq i ?{)
388 (setq str-result (cons ?o str-result))
389 (setq str-result (cons ?c str-result))
390 (setq str-result (cons ?b str-result))
391 (setq str-result (cons ?- str-result))
392 (setq str-result (cons ?- str-result)))
393 ;; close curly brackets `}' -> "ccb--"
394 ((eq i ?})
395 (setq str-result (cons ?c str-result))
396 (setq str-result (cons ?c str-result))
397 (setq str-result (cons ?b str-result))
398 (setq str-result (cons ?- str-result))
399 (setq str-result (cons ?- str-result)))
400 ;; vertical bar `|' -> "v--"
401 ((eq i ?|)
402 (setq str-result (cons ?v str-result))
403 (setq str-result (cons ?- str-result))
404 (setq str-result (cons ?- str-result)))
405 ;; slash `/' -> "s--"
406 ((eq i ?/)
407 (setq str-result (cons ?s str-result))
408 (setq str-result (cons ?- str-result))
409 (setq str-result (cons ?- str-result)))))
410 (concat (nreverse str-result))))
411
412 (let* ((menu-strings-buttons-alist
413 ;; make a alist os strings with the symbol classes and store it in
414 ;; `menu-strings-alist'
415 (let* ((menu-strings-alist-temp))
416 (dolist (item-external (cdr LaTeX-math-menu)
417 (nreverse menu-strings-alist-temp))
418 (when (listp item-external)
419 ;; if first element is vector, I am supposing that all are
420 ;; vectors as well
421 (if (vectorp (cadr item-external))
422 (let* ((menu-str (car item-external))
423 (menu-buttons))
424 (dolist (button (cdr item-external))
425 (setq menu-buttons
426 (cons (list (intern (TeX-bar-img-filename
427 (aref button 0)))
428 :image
429 (concat "symb-pics/"
430 (TeX-bar-img-filename
431 (aref button 0)))
432 :help (aref button 0)
433 :command (aref button 1))
434 menu-buttons)))
435 (setq menu-buttons (nreverse menu-buttons))
436 (setq menu-strings-alist-temp
437 (cons (cons menu-str (list menu-buttons))
438 menu-strings-alist-temp)))
439 ;; if another list (therefore, up to second level menu)
440 (let ((parent-str (concat (car item-external) " ")))
441 (dolist (item-internal (cdr item-external))
442 (unless (equal (car item-internal) "Special")
443 (let* ((menu-str (concat parent-str
444 (car item-internal)))
445 (menu-buttons))
446 (dolist (button (cdr item-internal))
447 (setq menu-buttons
448 (cons (list (intern (aref button 0))
449 :image
450 (concat "symb-pics/"
451 (TeX-bar-img-filename
452 (aref button 0)))
453 :help (aref button 0)
454 :command (aref button 1))
455 menu-buttons)))
456 (setq menu-buttons (nreverse menu-buttons))
457 (setq menu-strings-alist-temp
458 (cons (cons menu-str (list menu-buttons))
459 menu-strings-alist-temp)))))))))))
460 (list-strings (let* ((list-str-temp))
461 (dolist (i menu-strings-buttons-alist
462 (nreverse list-str-temp))
463 (setq list-str-temp (cons (car i)
464 list-str-temp))))))
465 (defvar LaTeX-symbols-toolbar-visible-flag nil
466 "Non-nil means that the LaTeX symbols on toolbar are visible.
467 Internal variable.")
468 (defconst LaTeX-symbols-toolbar-switch-contents
469 `(;; the on-off switch button
470 (latex-symbols-switch
471 :image (lambda nil (if LaTeX-symbols-toolbar-visible-flag
472 "ltx-symb-turn-off"
473 "ltx-symb-turn-on"))
474 :command (progn
475 (setq LaTeX-symbols-toolbar-visible-flag
476 (not LaTeX-symbols-toolbar-visible-flag))
477 (toolbarx-refresh))
478 ;; help message depends on if symb-toolbar is on or off, and in
479 ;; the name of the current class of symbols
480 :help (lambda (&rest ignore)
481 (concat "Turn "
482 (if LaTeX-symbols-toolbar-visible-flag "off " "on ")
483 "the toolbar of LaTeX symbols (current class: "
484 (nth (1- LaTeX-symbols-active-menuitem)
485 (quote ,list-strings))
486 ")")))
487 ;; the dropdown button, that also switch on the symbols
488 ,(append '(:dropdown-group)
489 list-strings
490 '(:variable
491 LaTeX-symbols-active-menuitem
492 :save offer
493 :dropdown-prepend-command
494 (setq LaTeX-symbols-toolbar-visible-flag t)
495 :dropdown-help "Select a class of symbols to be displayed"))))
496 (defconst LaTeX-symbols-toolbar-contents
497 (let* ((ltx-symb)
498 (count 0))
499 (dolist (i menu-strings-buttons-alist
500 (append (nreverse ltx-symb)
501 '(:insert
502 LaTeX-symbols-toolbar-visible-flag
503 :toolbar (bottom . top))))
504 (setq count (1+ count))
505 (setq ltx-symb
506 (cons (append (cdr i)
507 `(:insert (eq LaTeX-symbols-active-menuitem
508 ,count)))
509 ltx-symb))))))
510
511 (provide 'tex-bar)
512
513 ;;; tex-bar.el ends here