Initial Commit
[packages] / xemacs-packages / auctex / style / pst-plot.el
1 ;;; pst-plot.el --- AUCTeX style for `pst-plot.sty'
2
3 ;; Copyright (C) 2007 Free Software Foundation, Inc.
4
5 ;; Author: Holger Sparr <holger.sparr@gmx.net>
6 ;; Created: 21 Jun 2007
7 ;; Based on: Jean-Philippe Georget's pst-plot.el
8 ;; Keywords: latex, pstricks, auctex, emacs
9
10 ;; This file is part of AUCTeX.
11
12 ;; AUCTeX is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
16
17 ;; AUCTeX is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 ;; General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with AUCTeX; see the file COPYING.  If not, write to the Free
24 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 ;; 02110-1301, USA.
26
27 ;;; Commentary:
28
29 ;; This file adds support for `pst-plot.sty'.
30
31 ;;; TODO:
32 ;;
33 ;; -- improve symbol support (especially the pstScalePoints macros)
34 ;; -- check for multido.el necessity
35
36 ;;; Code:
37
38 ;; Self Parsing -- see (info "(auctex)Hacking the Parser")
39 (defvar LaTeX-auto-pstplot-regexp-list
40   '(("\\\\\\(save\\|read\\)data{?\\(\\\\[a-zA-Z]+\\)}?"
41      2 LaTeX-auto-pstplot))
42   "List of regular expressions to extract arguments of \\*data
43   macros.")
44
45 (defvar LaTeX-auto-pstplot nil
46   "Temporary for parsing \\*data definitions.")
47
48 (defun LaTeX-pstplot-cleanup ()
49   "Move symbols from `LaTeX-auto-pstplot to `TeX-auto-symbol'."
50   (mapcar (lambda (symbol)
51             ;; (setq TeX-symbol-list (cons (list symbol 0) TeX-symbol-list))
52             ;; (setq TeX-auto-symbol (cons (list symbol 0) TeX-auto-symbol)))
53             (add-to-list 'LaTeX-pstplot-datasets symbol))
54             LaTeX-auto-pstplot))
55
56 (defun LaTeX-pstplot-prepare ()
57   "Clear `LaTeX-auto-pstplot' before use."
58   (setq LaTeX-auto-pstplot nil))
59
60 (add-hook 'TeX-auto-prepare-hook 'LaTeX-pstplot-prepare)
61 (add-hook 'TeX-auto-cleanup-hook 'LaTeX-pstplot-cleanup)
62
63 ;;; Parameters
64 (defvar LaTeX-pstplot-datasets nil
65   "List of parsed data sets defined with \\savedata or \\readdata.")
66
67 (defvar LaTeX-pstplot-parameters-name-list
68   '("axesstyle" "labels" "plotpoints" "plotstyle" "showorigin" "ticks"
69     "ticksize" "tickstyle")
70   "A list of parameters' name in pst-plot.")
71
72 (defvar LaTeX-pst-ticks-list '(t "none" "all" "x" "y")
73   "A list of values for ticks in pst-plot.")
74
75 (defvaralias 'LaTeX-pst-labels-list 'LaTeX-pst-ticks-list)
76
77 (defvar LaTeX-pst-plotstyle-list
78   '(t "dots" "line" "polygon" "curve" "ecurve" "ccurve")
79   "A list of values for tickstyles in pst-plot.")
80
81 (defvar LaTeX-pst-tickstyle-list '(t "full" "top" "bottom")
82   "A list of values for tickstyles in pst-plot.")
83
84 (defvar LaTeX-pst-axesstyle-list '(t "axes" "frame" "none")
85   "A list of values for axesstyles in pst-plot.")
86
87 ;;; Macros
88 (defun LaTeX-pst-macro-psaxes (optional &optional arg)
89   "Return \\psaxes arguments after querying."
90 (let* ((cpref (if current-prefix-arg (car current-prefix-arg) 0))
91        (arrows (LaTeX-pst-arrows))
92        (pnt1 (if (> cpref 4) (LaTeX-pst-point) nil))
93        (pnt2 (if (> cpref 0) (LaTeX-pst-point) nil))
94        (pnt3 (LaTeX-pst-point)))
95   ;; insert \psaxes arguments
96   (insert (if arrows (format "{%s}" arrows) "")
97           (if pnt1 (format "(%s)" pnt1) "")
98           (if pnt2 (format "(%s)" pnt2) "") "(" pnt3 ")")))
99
100 ;;; Derived defuns
101 (defun LaTeX-pstplot-datasets-read ()
102   (TeX-arg-compl-list "Datasets" LaTeX-pstplot-datasets))
103
104 ;;; Hook
105 (TeX-add-style-hook
106  "pst-plot"
107  (function
108   (lambda ()
109     (mapcar 'TeX-auto-add-regexp LaTeX-auto-pstplot-regexp-list)
110     (TeX-add-symbols
111      '("readdata" "Macro Name" TeX-arg-file)
112      '("savedata" "Macro Name" ["Values"])
113      '("dataplot" ["Options"]
114        (TeX-arg-eval LaTeX-pstplot-datasets-read))
115      '("fileplot" ["Options"] TeX-arg-file)
116      '("listplot" ["Options"] "Values")
117      '("pstScalePoints" "X-Mod" "Y-Mod")
118      '("psplot" [LaTeX-pst-parameter] "xmin" "xmax" t)
119      '("parametricplot" [LaTeX-pst-parameter] "xmin" "xmax" t)
120      '("psaxes" [LaTeX-pst-parameters] LaTeX-pst-macro-psaxes)
121      "pshlabel"
122      "psvlabel")
123     (TeX-run-style-hooks
124      "pstricks"
125      "multido")
126     (unless (string-match "plotstyle"
127                           LaTeX-pst-parameters-completion-regexp)
128       (setq LaTeX-pst-parameters-completion-regexp
129             (concat
130              (substring LaTeX-pst-parameters-completion-regexp 0 -2)
131              "\\|plotstyle\\|ticks\\|tickstyle\\|axesstyle\\|labels\\)")))
132     (make-local-variable 'LaTeX-pst-parameters-name-list)
133     (setq LaTeX-pst-parameters-name-list
134           (append LaTeX-pstplot-parameters-name-list
135                   LaTeX-pst-parameters-name-list))))
136  LaTeX-dialect)
137
138 ;;; pst-plot.el ends here