Initial Commit
[packages] / xemacs-packages / auctex / style / pst-node.el
1 ;;; pst-node.el --- AUCTeX style for `pst-node.sty'
2
3 ;; Copyright (C) 2007, 2013 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-node.sty'.
30
31 ;;; TODO:
32 ;;
33 ;; -- self parsing of possible node names
34 ;; -- adding more macro support
35
36 ;;; Code:
37
38 (defalias 'LaTeX-pst-node 'LaTeX-pst-point)
39
40 (defvar LaTeX-pstnode-parameters-completion-regexp
41   "\\(npos\\|nrot\\)"
42   "Regexp for `string-match'ing a parameter.")
43
44 (defvar LaTeX-pstnode-parameters-boolean-regexp "show\\([a-zA-Z]+\\)"
45   "Regexp for `string-match'ing a parameter.")
46
47 (defvar LaTeX-pstnode-npos-list '(".25" ".5" ".75" "1" "1.5" "2")
48   "A list of values for npos in nput.")
49
50 (defvar LaTeX-pstnode-nrot-list '(":U" ":D" ":R" ":L")
51   "A list of values for nrot in nput.")
52
53 (defvar LaTeX-pstnode-psmatrix-list
54   '("mnode" "emnode" "name" "nodealign" "mocl" "rowsep" "colsep"
55     "mnodesize")
56   "A list of values for trimode in pstribox.")
57
58 ;;; Parameters
59 (defvar LaTeX-pstnode-parameters-history nil
60   "History of values for parameters in pst-node.")
61
62 (defvar LaTeX-pstnode-parameters-value-history nil
63   "History of parameter values in pst-node.")
64
65 (defvar LaTeX-pstnode-parameters-name-list
66   '("angle" "angleA" "angleB" "arcangle" "arcangleA" "arcangleB" "arm"
67     "armA" "armB" "boxsize" "colsep" "framesize" "href" "loopsize"
68     "ncurv" "ncurvA" "ncurvB" "nodesepA" "nodesepB" "npos" "nrot"
69     "offset" "offsetA" "offsetB" "radius" "vref" "Xnodesep" "XnodesepA"
70     "XnodesepB" "Ynodesep" "YnodesepA" "YnodesepB")
71   "A list of parameters' name in pst-node.")
72
73 (defvar LaTeX-pstnode-parameters-name-history nil
74   "History of parameter names in pst-node.")
75
76 ;;; Derived Functions from pstricks.el defuns
77 (defun LaTeX-pstnode-parameter-value (param)
78   "See documentation of `LaTeX-package-parameter-value'."
79   (LaTeX-package-parameter-value param "pstnode"))
80
81 (defun LaTeX-pstnode-parameters-pref-and-chosen (param &optional noskip)
82   "See documentation of `LaTeX-package-parameters-pref-and-chosen'."
83   (LaTeX-package-parameters-pref-and-chosen param "pstnode" noskip))
84
85 (defun LaTeX-pstnode-parameters (optional &optional preparam param)
86   "See documentation of `LaTeX-package-parameters-pref-and-chosen'."
87   (LaTeX-package-parameters optional "pstnode" preparam param))
88
89 ;;; Macros
90 (defun LaTeX-pstnode-macro-nput (optional &optional arg)
91   "Return \\nput arguments after querying."
92   (insert "[rot=" (LaTeX-pst-angle) "]{" (LaTeX-pst-angle) "}{"
93           (LaTeX-pst-node) "}"))
94
95 (defun LaTeX-pstnode-macro-cnodeput (optional &optional arg)
96   "Return \\cnodeput arguments after querying."
97   (let ((rotation (if current-prefix-arg (LaTeX-pst-angle) nil))
98         (pnt (if current-prefix-arg (LaTeX-pst-point) nil)))
99     (insert (if rotation (format "{%s}" rotation) "")
100             (if pnt (format "(%s)" pnt) "") "{" (LaTeX-pst-node) "}")))
101
102 (defun LaTeX-pstnode-macro-nc (optional &optional arg)
103   "Return \\nc* arguments after querying."
104   (let ((arrows (LaTeX-pst-arrows)))
105     (insert (if arrows (format "{%s}" arrows) "") "{" (LaTeX-pst-node)
106             "}{" (LaTeX-pst-node) "}")))
107
108 (defun LaTeX-pstnode-macro-pc (optional &optional arg)
109   "Return \\pc* arguments after querying."
110   (let ((arrows (LaTeX-pst-arrows)))
111     (insert (if arrows (format "{%s}" arrows) "") "(" (LaTeX-pst-point)
112             ")(" (LaTeX-pst-point) ")")))
113
114 (defun LaTeX-pstnode-macro-tnabcput (optional &optional arg)
115   "Return \\t?put or \\n?put arguments after querying."
116   (TeX-argument-insert (LaTeX-pstnode-parameters-pref-and-chosen
117                         '("nrot" "npos")) optional))
118
119 ;;; Environments
120 (defun LaTeX-pstnode-env-psmatrix (env)
121   "Return psmatrix environment with arguments."
122   (let ((opt (TeX-completing-read-multiple "Options: "
123                                            LaTeX-pstnode-psmatrix-list)))
124     (LaTeX-insert-environment env opt)))
125
126 (TeX-add-style-hook
127  "pst-node"
128  (function
129   (lambda ()
130     (LaTeX-add-environments
131      '("psmatrix" LaTeX-pstnode-env-psmatrix))
132     (TeX-add-symbols
133      '("MakeShortNab" 2) '("MakeShortTablr" 4) '("PSTnodesLoaded" 0)
134      '("nput" LaTeX-pstnode-macro-nput TeX-arg-macro)
135      '("cnodeput" [LaTeX-pst-parameters] LaTeX-pstnode-macro-cnodeput t)
136      '("Cnode" [LaTeX-pstnode-parameters] LaTeX-pst-point-in-parens t)
137      '("cnode" [LaTeX-pstnode-parameters] "Radius" t)
138      '("fnode" [LaTeX-pstnode-parameters] LaTeX-pst-point-in-parens t)
139      '("fnode*" [LaTeX-pstnode-parameters] LaTeX-pst-point-in-parens t)
140      '("dotnode" [LaTeX-pstnode-parameters] LaTeX-pst-point-in-parens t)
141      '("pnode" LaTeX-pst-point-in-parens t)
142      '("Rnode" [LaTeX-pstnode-parameters ("href" "vref")]
143        (TeX-arg-eval LaTeX-pst-point) t)
144      '("rnode" [LaTeX-pstnode-parameters ("ref")]
145        (TeX-arg-eval LaTeX-pst-point) t)
146      '("circlenode" [LaTeX-pst-parameters]
147        (TeX-arg-eval LaTeX-pst-point) t)
148      '("dianode" [LaTeX-pst-parameters] "Node Name" t)
149      '("ovalnode" [LaTeX-pst-parameters] "Node Name" t)
150      '("trinode" [LaTeX-pst-parameters] "Node Name" t)
151      '("dotnode" [LaTeX-pst-parameters] LaTeX-pst-point-in-parens
152        "Node Name")
153      '("naput" [LaTeX-pstnode-macro-tnabcput] t)
154      '("nbput" [LaTeX-pstnode-macro-tnabcput] t)
155      '("ncput" [LaTeX-pstnode-macro-tnabcput] t)
156      '("taput" [LaTeX-pstnode-macro-tnabcput] t)
157      '("tbput" [LaTeX-pstnode-macro-tnabcput] t)
158      '("thput" [LaTeX-pstnode-macro-tnabcput] t)
159      '("tlput" [LaTeX-pstnode-macro-tnabcput] t)
160      '("trput" [LaTeX-pstnode-macro-tnabcput] t)
161      '("tvput" [LaTeX-pstnode-macro-tnabcput] t)
162      '("ncline" [LaTeX-pst-parameters] LaTeX-pstnode-macro-nc)
163      '("ncarc" [LaTeX-pst-parameters] LaTeX-pstnode-macro-nc)
164      '("ncdiag" [LaTeX-pst-parameters] LaTeX-pstnode-macro-nc)
165      '("ncdiagg" [LaTeX-pst-parameters] LaTeX-pstnode-macro-nc)
166      '("ncbar" [LaTeX-pst-parameters] LaTeX-pstnode-macro-nc)
167      '("ncangle" [LaTeX-pst-parameters] LaTeX-pstnode-macro-nc)
168      '("ncangles" [LaTeX-pst-parameters] LaTeX-pstnode-macro-nc)
169      '("ncloop" [LaTeX-pst-parameters] LaTeX-pstnode-macro-nc)
170      '("nccurve" [LaTeX-pst-parameters] LaTeX-pstnode-macro-nc)
171      '("nccircle" [LaTeX-pst-parameters] LaTeX-pstnode-macro-nc)
172      '("ncbox" [LaTeX-pst-parameters] LaTeX-pstnode-macro-nc)
173      '("ncarcbox" [LaTeX-pst-parameters] LaTeX-pstnode-macro-nc)
174      '("pcline" [LaTeX-pst-parameters] LaTeX-pstnode-macro-pc)
175      '("pccurve" [LaTeX-pst-parameters] LaTeX-pstnode-macro-pc)
176      '("pcarc" [LaTeX-pst-parameters] LaTeX-pstnode-macro-pc)
177      '("pcbar" [LaTeX-pst-parameters] LaTeX-pstnode-macro-pc)
178      '("pcdiag" [LaTeX-pst-parameters] LaTeX-pstnode-macro-pc)
179      '("pcdiagg" [LaTeX-pst-parameters] LaTeX-pstnode-macro-pc)
180      '("pcangle" [LaTeX-pst-parameters] LaTeX-pstnode-macro-pc)
181      '("pcangles" [LaTeX-pst-parameters] LaTeX-pstnode-macro-pc)
182      '("pcloop" [LaTeX-pst-parameters] LaTeX-pstnode-macro-pc)
183      '("pcbox" [LaTeX-pst-parameters] LaTeX-pstnode-macro-pc)
184      '("pcarcbox" [LaTeX-pst-parameters] LaTeX-pstnode-macro-pc)
185      '("psspan" (TeX-arg-eval LaTeX-pst-input-int))
186      '("psrowhook" t)
187      '("pscolhook" t))
188     (TeX-run-style-hooks
189      "pstricks")))
190  LaTeX-dialect)
191
192 ;;; pst-node.el ends here