auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX-devel] TikZ Style Patches


From: Matthew Leach
Subject: [AUCTeX-devel] TikZ Style Patches
Date: Mon, 04 Apr 2016 22:07:00 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

Hi all,

I've just finished working on a small set of TikZ style patches and
posting for a quick review to make sure there's nothing obviously wrong.
The patches consist of adding a few more TikZ command prompts and a bit
of code cleanup.

Thanks,
-- 
Matt
>From c58162a642a1544dc5757c3ca0aabf80edb0e033 Mon Sep 17 00:00:00 2001
From: Matthew Leach <address@hidden>
Date: Thu, 31 Mar 2016 13:37:31 +0100
Subject: [PATCH 1/5] TikZ: Add circle command.

* style/tikz.el (TeX-TikZ-arg-circle): New.
  (TeX-TikZ-draw-arg-function-map): Add mapping from 'Circle' to
  `TeX-TikZ-arg-circle'.
---
 style/tikz.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/style/tikz.el b/style/tikz.el
index be93110..d187d24 100644
--- a/style/tikz.el
+++ b/style/tikz.el
@@ -173,6 +173,11 @@ them as a list of strings, dropping the '()'."
                                      (TeX-TikZ-find-named-points))))
     (concat " (" point-name ") ")))
 
+(defun TeX-TikZ-arg-circle (_ignored)
+  "Prompt the user for the arguments to the circle command."
+  (let ((options (TeX-TikZ-arg-options t)))
+    (concat "circle" options)))
+
 (defconst TeX-TikZ-point-function-map
   '(("Rect Point" TeX-TikZ-arg-rect-point)
     ("Polar Point" TeX-TikZ-arg-polar-point)
@@ -194,7 +199,8 @@ A set of base connectors along with variants that have \" 
+\" and
 (defconst TeX-TikZ-draw-arg-function-map
   `(,@TeX-TikZ-point-function-map
     ,@TeX-TikZ-path-connector-function-map
-    ("Node" TeX-TikZ-arg-node))
+    ("Node" TeX-TikZ-arg-node)
+    ("Circle" TeX-TikZ-arg-circle))
   "An alist of argument names and functoins for TikZ's \draw.")
 
 (defun TeX-TikZ-draw-arg (_ignored)
-- 
2.7.4

>From 310008b94765bc324c6fd4813d1994833b4929f9 Mon Sep 17 00:00:00 2001
From: Matthew Leach <address@hidden>
Date: Mon, 4 Apr 2016 20:59:38 +0100
Subject: [PATCH 2/5] TikZ: Add the arc command.

* style/tikz.el (TeX-TikZ-arg-arc): New.
  (TeX-TikZ-draw-arg-function-map): Map the 'Arc' command to
  `Tex-TikZ-arg-arc'.
---
 style/tikz.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/style/tikz.el b/style/tikz.el
index d187d24..b29abf8 100644
--- a/style/tikz.el
+++ b/style/tikz.el
@@ -178,6 +178,11 @@ them as a list of strings, dropping the '()'."
   (let ((options (TeX-TikZ-arg-options t)))
     (concat "circle" options)))
 
+(defun TeX-TikZ-arg-arc (_ignored)
+  "Prompt the user for the arguments to the arc command."
+  (let ((options (TeX-TikZ-arg-options t)))
+    (concat "arc" options)))
+
 (defconst TeX-TikZ-point-function-map
   '(("Rect Point" TeX-TikZ-arg-rect-point)
     ("Polar Point" TeX-TikZ-arg-polar-point)
@@ -200,7 +205,8 @@ A set of base connectors along with variants that have \" 
+\" and
   `(,@TeX-TikZ-point-function-map
     ,@TeX-TikZ-path-connector-function-map
     ("Node" TeX-TikZ-arg-node)
-    ("Circle" TeX-TikZ-arg-circle))
+    ("Circle" TeX-TikZ-arg-circle)
+    ("Arc" TeX-TikZ-arg-arc))
   "An alist of argument names and functoins for TikZ's \draw.")
 
 (defun TeX-TikZ-draw-arg (_ignored)
-- 
2.7.4

>From ae6ed8b21742ae50189084e4a2d95baebb87052b Mon Sep 17 00:00:00 2001
From: Matthew Leach <address@hidden>
Date: Mon, 4 Apr 2016 21:32:07 +0100
Subject: [PATCH 3/5] TikZ: make `TeX-TikZ-single-macro-arg' prompt required.

* style/tikz.el (TeX-TikZ-get-arg-type): Make prompt non-optional.
  (TeX-TikZ-single-macro-arg): Likewise.
  (TeX-TikZ-macro-arg): Make prompt explicit.
---
 style/tikz.el | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/style/tikz.el b/style/tikz.el
index b29abf8..d335cbc 100644
--- a/style/tikz.el
+++ b/style/tikz.el
@@ -94,17 +94,14 @@ string \"node[OPTIONS](NAME){TEXT}\"."
         (label (TeX-TikZ-arg-label nil)))
     (concat "node" options name label " ")))
 
-(defun TeX-TikZ-get-arg-type (types &optional prompt)
+(defun TeX-TikZ-get-arg-type (types prompt)
   "Prompt the user for an argument type.
-TYPES is a list of possible types that the user can specify.  If
-PROMPT is non-nil use that prompt instead."
-  (let ((completion-ignore-case t)
-        (prompt (if prompt
-                    prompt
-                  "Next argument type (RET to finish): ")))
+TYPES is a list of possible types that the user can specify.  Use
+PROMPT as the prompt for input."
+  (let ((completion-ignore-case t))
     (completing-read prompt types nil t)))
 
-(defun TeX-TikZ-single-macro-arg (function-alist &optional prompt)
+(defun TeX-TikZ-single-macro-arg (function-alist prompt)
   "Prompt the user for a single argument to compose a TikZ macro.
 FUNCTION-ALIST is a mapping of argument-types to functions.  The
 user is prompted for the argument type, the chosen function is
@@ -128,7 +125,8 @@ is finished."
          ;; For the iterative version, we need to add "" to the
          ;; function-alist, allowing the user to end the macro.
          (function-alist-iterative `(,@function-alist ("" identity)))
-         (string-to-insert (TeX-TikZ-single-macro-arg 
function-alist-iterative)))
+         (prompt "Next argument type (RET to finish): ")
+         (string-to-insert (TeX-TikZ-single-macro-arg function-alist-iterative 
prompt)))
 
     ;; Insert the macro options.
     (insert options " ")
@@ -138,7 +136,7 @@ is finished."
     (while (not (string= string-to-insert ""))
       (insert string-to-insert)
       (setq string-to-insert
-            (TeX-TikZ-single-macro-arg function-alist-iterative)))
+            (TeX-TikZ-single-macro-arg function-alist-iterative prompt)))
 
     ;; Finish the macro.
     (insert ";")))
-- 
2.7.4

>From de0d445ea13a772d9cd842863c4d49217be7553b Mon Sep 17 00:00:00 2001
From: Matthew Leach <address@hidden>
Date: Mon, 4 Apr 2016 21:38:18 +0100
Subject: [PATCH 4/5] TikZ: Add optional parameter to
 `TeX-TikZ-single-macro-arg'.

* style/tikz.el (TeX-TikZ-single-macro-arg): New argument OPTIONAL.
  (TeX-TikZ-macro-arg): Use OPTIONAL argument when calling
  `TeX-TikZ-single-macro-arg'.
---
 style/tikz.el | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/style/tikz.el b/style/tikz.el
index d335cbc..222be06 100644
--- a/style/tikz.el
+++ b/style/tikz.el
@@ -101,14 +101,18 @@ PROMPT as the prompt for input."
   (let ((completion-ignore-case t))
     (completing-read prompt types nil t)))
 
-(defun TeX-TikZ-single-macro-arg (function-alist prompt)
+(defun TeX-TikZ-single-macro-arg (function-alist prompt &optional optional)
   "Prompt the user for a single argument to compose a TikZ macro.
 FUNCTION-ALIST is a mapping of argument-types to functions.  The
 user is prompted for the argument type, the chosen function is
 then called and the value returned.  PROMPT is used as the prompt
-for the argument type."
+for the argument type.  When OPTIONAL is non-nil, add \"\" to
+FUNCTION-ALIST with a mapping to `identity', permitting an
+optional input."
   (let* ((argument-types (mapcar 'car function-alist))
          (argument-type (TeX-TikZ-get-arg-type argument-types prompt)))
+    (when optional
+      (setq function-alist `(,@function-alist ("" identity))))
     (funcall
      (cadr (assoc argument-type function-alist))
      argument-type)))
@@ -122,11 +126,8 @@ 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-TikZ-arg-options t))
-         ;; For the iterative version, we need to add "" to the
-         ;; function-alist, allowing the user to end the macro.
-         (function-alist-iterative `(,@function-alist ("" identity)))
          (prompt "Next argument type (RET to finish): ")
-         (string-to-insert (TeX-TikZ-single-macro-arg function-alist-iterative 
prompt)))
+         (string-to-insert (TeX-TikZ-single-macro-arg function-alist prompt 
t)))
 
     ;; Insert the macro options.
     (insert options " ")
@@ -136,7 +137,7 @@ is finished."
     (while (not (string= string-to-insert ""))
       (insert string-to-insert)
       (setq string-to-insert
-            (TeX-TikZ-single-macro-arg function-alist-iterative prompt)))
+            (TeX-TikZ-single-macro-arg function-alist prompt t)))
 
     ;; Finish the macro.
     (insert ";")))
-- 
2.7.4

>From b66c10aa0ae12d3cf85cb75e097e82bd342278dc Mon Sep 17 00:00:00 2001
From: Matthew Leach <address@hidden>
Date: Mon, 4 Apr 2016 21:53:06 +0100
Subject: [PATCH 5/5] TikZ: Add parabola command.

* style/tikz.el (TeX-TikZ-arg-bend): New.
  (TeX-TikZ-arg-parabola): New.
  (TeX-TikZ-draw-arg-function-map): Add mapping from "Parabola" to
  `TeX-TikZ-arg-parabola'.
---
 style/tikz.el | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/style/tikz.el b/style/tikz.el
index 222be06..9754347 100644
--- a/style/tikz.el
+++ b/style/tikz.el
@@ -182,6 +182,24 @@ them as a list of strings, dropping the '()'."
   (let ((options (TeX-TikZ-arg-options t)))
     (concat "arc" options)))
 
+(defun TeX-TikZ-arg-bend (optional)
+  "Prompt the user for a bend argument.
+If OPTIONAL is non-nil and the user doesn't provide a point,
+  return \"\"."
+  (let ((point
+         (TeX-TikZ-single-macro-arg TeX-TikZ-point-function-map
+                                    (TeX-argument-prompt optional nil "Bend 
point")
+                                    optional)))
+    (if (string= point "")
+        point
+      (concat " bend" point))))
+
+(defun TeX-TikZ-arg-parabola (_ignored)
+  "Prompt the user for the arguments to the parabola command."
+  (let ((options (TeX-TikZ-arg-options t))
+        (bend (TeX-TikZ-arg-bend t)))
+       (concat "parabola" options bend)))
+
 (defconst TeX-TikZ-point-function-map
   '(("Rect Point" TeX-TikZ-arg-rect-point)
     ("Polar Point" TeX-TikZ-arg-polar-point)
@@ -205,7 +223,8 @@ A set of base connectors along with variants that have \" 
+\" and
     ,@TeX-TikZ-path-connector-function-map
     ("Node" TeX-TikZ-arg-node)
     ("Circle" TeX-TikZ-arg-circle)
-    ("Arc" TeX-TikZ-arg-arc))
+    ("Arc" TeX-TikZ-arg-arc)
+    ("Parabola" TeX-TikZ-arg-parabola))
   "An alist of argument names and functoins for TikZ's \draw.")
 
 (defun TeX-TikZ-draw-arg (_ignored)
-- 
2.7.4


reply via email to

[Prev in Thread] Current Thread [Next in Thread]