[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] elpa 608e874 01/23: Add the beginnings of TikZ support.
From: |
Tassilo Horn |
Subject: |
[elpa] elpa 608e874 01/23: Add the beginnings of TikZ support. |
Date: |
Wed, 30 Mar 2016 19:08:02 +0000 |
branch: elpa
commit 608e8748a0197bb9da4c3636f46ea8cc70a026c0
Author: Matthew Leach <address@hidden>
Commit: Matthew Leach <address@hidden>
Add the beginnings of TikZ support.
* style/tikz.el: New
* doc/changes.texi: Document TikZ style.
* Makefile.in: Add TikZ style to the build.
---
Makefile.in | 2 +-
doc/changes.texi | 5 ++
style/tikz.el | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 128 insertions(+), 1 deletions(-)
diff --git a/Makefile.in b/Makefile.in
index 471ff21..b390c66 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -154,7 +154,7 @@ STYLESRC = style/prosper.el \
style/fontenc.el style/Alegreya.el style/gloss-italian.el \
style/newfloat.el style/subcaption.el style/AlegreyaSans.el \
style/hologo.el style/theorem.el style/ntheorem.el \
- style/splitidx.el
+ style/splitidx.el style/tikz.el
STYLEELC = $(STYLESRC:.el=.elc)
diff --git a/doc/changes.texi b/doc/changes.texi
index 9d39db2..9d36f09 100644
--- a/doc/changes.texi
+++ b/doc/changes.texi
@@ -12,6 +12,11 @@
@itemize @bullet
@item
address@hidden now has limited support for the TikZ package. For the moment,
+this includes some basic support for prompting the user of arguments to
+the @samp{\draw} macro.
+
address@hidden
When inserting a new float, @AUCTeX{} will now prompt for a
short-caption if the length of the caption provided is greater than a
certain size. This size is controlled via a new user option
diff --git a/style/tikz.el b/style/tikz.el
new file mode 100644
index 0000000..de8a655
--- /dev/null
+++ b/style/tikz.el
@@ -0,0 +1,122 @@
+;;; tikz.el --- AUCTeX style for `tikz.sty'
+
+;; Copyright (C) 2016 Free Software Foundation, Inc.
+
+;; Author: Matthew Leach <address@hidden>
+;; Maintainer: address@hidden
+;; Created: 2016-22-03
+;; Keywords: tex tikz
+
+;; This file is part of AUCTeX.
+
+;; AUCTeX is free software; you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; AUCTeX is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with AUCTeX; see the file COPYING. If not, write to the Free
+;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+;; 02110-1301, USA.
+
+;;; Commentary:
+
+;; This file adds some support for `tikz.sty'
+
+;;; Code:
+
+(defun TeX-TikZ-get-opt-arg-string (arg &optional open close)
+ "Return a string for optional arguments.
+If ARG is nil or \"\", return \"\". Otherwise return \"OPEN ARG
+CLOSE\". If OPEN or CLOSE are nil, set them to `LaTeX-optop' and
+`LaTeX-optcl' respectively."
+ (unless (or open close)
+ (setq open LaTeX-optop)
+ (setq close LaTeX-optcl))
+ (if (and arg (> (length arg) 0))
+ (concat open arg close)
+ ""))
+
+(defun TeX-TikZ-arg-rect-point (_ignored)
+ "Prompt the user for a point on the Cartesian plane.
+Ask the user for an X and Y coordinate, and return the string
+\"(X,Y)\"."
+ (let ((x (TeX-read-string (TeX-argument-prompt nil nil "X-coordinate")))
+ (y (TeX-read-string (TeX-argument-prompt nil nil "Y-coordinate"))))
+ (concat " (" x ", " y") ")))
+
+(defun TeX-TikZ-arg-polar-point (_ignored)
+ "Prompt the user for a point on the polar plane.
+Ask the user for r and theta values, and return the string
+\"(THETA:R)\"."
+ (let ((r (TeX-read-string (TeX-argument-prompt nil nil "R")))
+ (theta (TeX-read-string (TeX-argument-prompt nil nil "Theta"))))
+ (concat " (" theta ":" r ") ")))
+
+(defun TeX-TikZ-arg-node (_ignored)
+ "Prompt the user for the deatils of a node.
+Ask the user for the name and text for a node and return the
+string \"node[OPTIONS](NAME){TEXT}\"."
+ (let ((options (TeX-read-string (TeX-argument-prompt t nil "Options" )))
+ (name (TeX-read-string (TeX-argument-prompt t nil "Name")))
+ (text (TeX-read-string (TeX-argument-prompt nil nil "Text"))))
+ (concat "node"
+ (TeX-TikZ-get-opt-arg-string options)
+ (TeX-TikZ-get-opt-arg-string name "(" ")")
+ TeX-grop text TeX-grcl " ")))
+
+(defun TeX-TikZ-get-arg-type (types)
+ "Prompt the user for the next argument type.
+TYPES is a list of possible types that the user can specify."
+ (completing-read "Next argument type (RET to finish): " types nil t))
+
+(defun TeX-TikZ-macro-arg (function-alist)
+ "Prompt the user for arguments to compose a TikZ macro.
+FUNCTION-ALIST is a mapping of argument-types to functions. The
+user is repeatedly prompted for the next argument-type; they can
+choose form the cars in FUNCTION-ALIST and the appropriate
+function is then called. If the user enters \"\", then the macro
+is finished."
+ (let* ((options (TeX-read-string (TeX-argument-prompt t nil "Options")))
+ (argument-types `("" ,@(mapcar 'car function-alist)))
+ (argument-type (TeX-TikZ-get-arg-type argument-types)))
+
+ ;; Insert the macro options.
+ (insert (TeX-TikZ-get-opt-arg-string options)
+ " ")
+
+ ;; Iteratively prompt the user for TikZ's arguments until "" is
+ ;; returned.
+ (while (not (string= argument-type ""))
+ (insert (funcall
+ (cadr (assoc argument-type TeX-TikZ-draw-arg-function-map))
+ argument-type))
+ (setq argument-type (TeX-TikZ-get-arg-type argument-types)))
+
+ ;; Finish the macro.
+ (insert ";")))
+
+(defconst TeX-TikZ-draw-arg-function-map
+ '(("Rect Point" TeX-TikZ-arg-rect-point)
+ ("Polar Point" TeX-TikZ-arg-polar-point)
+ ("Node" TeX-TikZ-arg-node)
+ ("--" identity)
+ ("-+" identity))
+ "An alist of argument type names to their respecitve functions
+ for TikZ's \draw macro.")
+
+(defun TeX-TikZ-draw-arg (optional)
+ (TeX-TikZ-macro-arg TeX-TikZ-draw-arg-function-map))
+
+(TeX-add-style-hook
+ "tikz"
+ (lambda ()
+ (TeX-add-symbols
+ '("draw" (TeX-TikZ-draw-arg)))
+ (LaTeX-add-environments
+ '("tikzpicture"))))
- [elpa] elpa updated (df2c08f -> 7573813), Tassilo Horn, 2016/03/30
- [elpa] elpa a8a803c 02/23: Call TeX-after-compilation-finished-functions on warnings, Tassilo Horn, 2016/03/30
- [elpa] elpa ae34515 03/23: Better control for presence of errors, Tassilo Horn, 2016/03/30
- [elpa] elpa 0f8baf6 16/23: TikZ: Ignore case when prompting for argument types., Tassilo Horn, 2016/03/30
- [elpa] elpa 4a1728b 15/23: TikZ: Apply suggestions from checkdoc., Tassilo Horn, 2016/03/30
- [elpa] elpa cf4ce35 18/23: TikZ: Add more path connector types., Tassilo Horn, 2016/03/30
- [elpa] elpa f23fbd6 14/23: Fill environment content onley when auto-fill-mode is active, Tassilo Horn, 2016/03/30
- [elpa] elpa eddf3ff 20/23: Fix previous commit, Tassilo Horn, 2016/03/30
- [elpa] elpa 608e874 01/23: Add the beginnings of TikZ support.,
Tassilo Horn <=
- [elpa] elpa 201ed15 06/23: Fix a misplaced closing parenthesis, Tassilo Horn, 2016/03/30
- [elpa] elpa 1288609 07/23: Add fontification support, Tassilo Horn, 2016/03/30
- [elpa] elpa 00740ed 08/23: TikZ: split out the prompts to TeX-TikZ-arg-node & TeX-TikZ-macro-arg., Tassilo Horn, 2016/03/30
- [elpa] elpa c49b547 17/23: TikZ: Rename 'text' to 'label' to be consistent with TikZ terminology., Tassilo Horn, 2016/03/30
- [elpa] elpa 1cb2678 04/23: Delete redundant code, Tassilo Horn, 2016/03/30
- [elpa] elpa bb67e18 13/23: TikZ: Add 'Named Point' point type with completion., Tassilo Horn, 2016/03/30
- [elpa] elpa 0423aae 19/23: New function TeX-error-report-has-errors-p, Tassilo Horn, 2016/03/30
- [elpa] elpa df60ed5 05/23: Fix the name of argument in function body, Tassilo Horn, 2016/03/30
- [elpa] elpa 00430f2 21/23: Restore compatibility with XEmacs, Tassilo Horn, 2016/03/30
- [elpa] elpa b211827 10/23: TikZ: Extract the prompting of the next arg from TeX-TikZ-macro-arg., Tassilo Horn, 2016/03/30