Blame style/pst-plot.el

Packit f2bd10
;;; pst-plot.el --- AUCTeX style for `pst-plot.sty'
Packit f2bd10
Packit f2bd10
;; Copyright (C) 2007, 2014, 2015 Free Software Foundation, Inc.
Packit f2bd10
Packit f2bd10
;; Author: Holger Sparr <holger.sparr@gmx.net>
Packit f2bd10
;; Created: 21 Jun 2007
Packit f2bd10
;; Based on: Jean-Philippe Georget's pst-plot.el
Packit f2bd10
;; Keywords: latex, pstricks, auctex, emacs
Packit f2bd10
Packit f2bd10
;; This file is part of AUCTeX.
Packit f2bd10
Packit f2bd10
;; AUCTeX is free software; you can redistribute it and/or modify it
Packit f2bd10
;; under the terms of the GNU General Public License as published by
Packit f2bd10
;; the Free Software Foundation; either version 3, or (at your option)
Packit f2bd10
;; any later version.
Packit f2bd10
Packit f2bd10
;; AUCTeX is distributed in the hope that it will be useful, but
Packit f2bd10
;; WITHOUT ANY WARRANTY; without even the implied warranty of
Packit f2bd10
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit f2bd10
;; General Public License for more details.
Packit f2bd10
Packit f2bd10
;; You should have received a copy of the GNU General Public License
Packit f2bd10
;; along with AUCTeX; see the file COPYING.  If not, write to the Free
Packit f2bd10
;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
Packit f2bd10
;; 02110-1301, USA.
Packit f2bd10
Packit f2bd10
;;; Commentary:
Packit f2bd10
Packit f2bd10
;; This file adds support for `pst-plot.sty'.
Packit f2bd10
Packit f2bd10
;;; TODO:
Packit f2bd10
;;
Packit f2bd10
;; -- improve symbol support (especially the pstScalePoints macros)
Packit f2bd10
;; -- check for multido.el necessity
Packit f2bd10
Packit f2bd10
;;; Code:
Packit f2bd10
Packit f2bd10
;; Self Parsing -- see (info "(auctex)Hacking the Parser")
Packit f2bd10
(defvar LaTeX-auto-pstplot-regexp-list
Packit f2bd10
  '(("\\\\\\(save\\|read\\)data{?\\(\\\\[a-zA-Z]+\\)}?"
Packit f2bd10
     2 LaTeX-auto-pstplot))
Packit f2bd10
  "List of regular expressions to extract arguments of \\*data
Packit f2bd10
  macros.")
Packit f2bd10
Packit f2bd10
(defvar LaTeX-auto-pstplot nil
Packit f2bd10
  "Temporary for parsing \\*data definitions.")
Packit f2bd10
Packit f2bd10
(defun LaTeX-pstplot-cleanup ()
Packit f2bd10
  "Move symbols from `LaTeX-auto-pstplot to `TeX-auto-symbol'."
Packit f2bd10
  (mapcar (lambda (symbol)
Packit f2bd10
            ;; (setq TeX-symbol-list (cons (list symbol 0) TeX-symbol-list))
Packit f2bd10
            ;; (setq TeX-auto-symbol (cons (list symbol 0) TeX-auto-symbol)))
Packit f2bd10
            (add-to-list 'LaTeX-pstplot-datasets symbol))
Packit f2bd10
            LaTeX-auto-pstplot))
Packit f2bd10
Packit f2bd10
(defun LaTeX-pstplot-prepare ()
Packit f2bd10
  "Clear `LaTeX-auto-pstplot' before use."
Packit f2bd10
  (setq LaTeX-auto-pstplot nil))
Packit f2bd10
Packit f2bd10
(add-hook 'TeX-auto-prepare-hook #'LaTeX-pstplot-prepare t)
Packit f2bd10
(add-hook 'TeX-auto-cleanup-hook #'LaTeX-pstplot-cleanup t)
Packit f2bd10
(add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
Packit f2bd10
Packit f2bd10
;;; Parameters
Packit f2bd10
(defvar LaTeX-pstplot-datasets nil
Packit f2bd10
  "List of parsed data sets defined with \\savedata or \\readdata.")
Packit f2bd10
Packit f2bd10
(defvar LaTeX-pstplot-parameters-name-list
Packit f2bd10
  '("axesstyle" "labels" "plotpoints" "plotstyle" "showorigin" "ticks"
Packit f2bd10
    "ticksize" "tickstyle")
Packit f2bd10
  "A list of parameters' name in pst-plot.")
Packit f2bd10
Packit f2bd10
(defvar LaTeX-pst-ticks-list '(t "none" "all" "x" "y")
Packit f2bd10
  "A list of values for ticks in pst-plot.")
Packit f2bd10
Packit f2bd10
(defvaralias 'LaTeX-pst-labels-list 'LaTeX-pst-ticks-list)
Packit f2bd10
Packit f2bd10
(defvar LaTeX-pst-plotstyle-list
Packit f2bd10
  '(t "dots" "line" "polygon" "curve" "ecurve" "ccurve")
Packit f2bd10
  "A list of values for tickstyles in pst-plot.")
Packit f2bd10
Packit f2bd10
(defvar LaTeX-pst-tickstyle-list '(t "full" "top" "bottom")
Packit f2bd10
  "A list of values for tickstyles in pst-plot.")
Packit f2bd10
Packit f2bd10
(defvar LaTeX-pst-axesstyle-list '(t "axes" "frame" "none")
Packit f2bd10
  "A list of values for axesstyles in pst-plot.")
Packit f2bd10
Packit f2bd10
;;; Macros
Packit f2bd10
(defun LaTeX-pst-macro-psaxes (_optional &optional _arg)
Packit f2bd10
  "Return \\psaxes arguments after querying."
Packit f2bd10
  (let* ((cpref (if current-prefix-arg (car current-prefix-arg) 0))
Packit f2bd10
         (arrows (LaTeX-pst-arrows))
Packit f2bd10
         (pnt1 (if (> cpref 4) (LaTeX-pst-point) nil))
Packit f2bd10
         (pnt2 (if (> cpref 0) (LaTeX-pst-point) nil))
Packit f2bd10
         (pnt3 (LaTeX-pst-point)))
Packit f2bd10
    ;; Insert \psaxes arguments.
Packit f2bd10
    (insert (if arrows (format "{%s}" arrows) "")
Packit f2bd10
            (if pnt1 (format "(%s)" pnt1) "")
Packit f2bd10
            (if pnt2 (format "(%s)" pnt2) "") "(" pnt3 ")")))
Packit f2bd10
Packit f2bd10
;;; Derived defuns
Packit f2bd10
(defun LaTeX-pstplot-datasets-read ()
Packit f2bd10
  (TeX-arg-compl-list "Datasets" LaTeX-pstplot-datasets))
Packit f2bd10
Packit f2bd10
;;; Hook
Packit f2bd10
(TeX-add-style-hook
Packit f2bd10
 "pst-plot"
Packit f2bd10
 (function
Packit f2bd10
  (lambda ()
Packit f2bd10
    (mapc #'TeX-auto-add-regexp LaTeX-auto-pstplot-regexp-list)
Packit f2bd10
    (TeX-add-symbols
Packit f2bd10
     '("readdata" "Macro Name" TeX-arg-file)
Packit f2bd10
     '("savedata" "Macro Name" ["Values"])
Packit f2bd10
     '("dataplot" ["Options"]
Packit f2bd10
       (TeX-arg-eval LaTeX-pstplot-datasets-read))
Packit f2bd10
     '("fileplot" ["Options"] TeX-arg-file)
Packit f2bd10
     '("listplot" ["Options"] "Values")
Packit f2bd10
     '("pstScalePoints" "X-Mod" "Y-Mod")
Packit f2bd10
     '("psplot" [LaTeX-pst-parameter] "xmin" "xmax" t)
Packit f2bd10
     '("parametricplot" [LaTeX-pst-parameter] "xmin" "xmax" t)
Packit f2bd10
     '("psaxes" [LaTeX-pst-parameters] LaTeX-pst-macro-psaxes)
Packit f2bd10
     "pshlabel"
Packit f2bd10
     "psvlabel")
Packit f2bd10
    (TeX-run-style-hooks
Packit f2bd10
     "pstricks"
Packit f2bd10
     "multido")
Packit f2bd10
    (unless (string-match "plotstyle"
Packit f2bd10
                          LaTeX-pst-parameters-completion-regexp)
Packit f2bd10
      (setq LaTeX-pst-parameters-completion-regexp
Packit f2bd10
            (concat
Packit f2bd10
             (substring LaTeX-pst-parameters-completion-regexp 0 -2)
Packit f2bd10
             "\\|plotstyle\\|ticks\\|tickstyle\\|axesstyle\\|labels\\)")))
Packit f2bd10
    (make-local-variable 'LaTeX-pst-parameters-name-list)
Packit f2bd10
    (setq LaTeX-pst-parameters-name-list
Packit f2bd10
          (append LaTeX-pstplot-parameters-name-list
Packit f2bd10
                  LaTeX-pst-parameters-name-list))))
Packit f2bd10
 LaTeX-dialect)
Packit f2bd10
Packit f2bd10
;;; pst-plot.el ends here