emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] elpa d83900b 09/51: TikZ: Make '+' and '++' prefixes apply to Tik


From: Tassilo Horn
Subject: [elpa] elpa d83900b 09/51: TikZ: Make '+' and '++' prefixes apply to TikZ points
Date: Sun, 22 May 2016 07:22:48 +0000 (UTC)

branch: elpa
commit d83900b9fd15081049e0217dce881e2b709d0617
Author: Matthew Leach <address@hidden>
Commit: Matthew Leach <address@hidden>

    TikZ: Make '+' and '++' prefixes apply to TikZ points
    
    * style/tikz.el (TeX-TikZ-get-prefix-string): New.
      (TeX-TikZ-arg-rect-point): Add optional argument `prefix'.
      (TeX-TikZ-arg-polar-point): Likewise.
      (TeX-TikZ-arg-named-point): Likewise.
      (TeX-TikZ-single-macro-arg): Allow a variable number of arguments to
      the argument name function map.
      (TeX-TikZ-point-function-map): Prefix all point types with '+' and
      '++'.
      (TeX-TikZ-path-connector-function-map): Remove the '+' and '++'
      suffixes.
---
 style/tikz.el |   71 +++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 44 insertions(+), 27 deletions(-)

diff --git a/style/tikz.el b/style/tikz.el
index 9754347..849d937 100644
--- a/style/tikz.el
+++ b/style/tikz.el
@@ -42,21 +42,25 @@ CLOSE\". If OPEN or CLOSE are nil, set them to 
`LaTeX-optop' and
       (concat open arg close)
     ""))
 
-(defun TeX-TikZ-arg-rect-point (_ignored)
+(defun TeX-TikZ-get-prefix-string (prefix)
+  "Return a string for the prefix to a command.
+")
+
+(defun TeX-TikZ-arg-rect-point (_ignored &optional prefix)
   "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") ")))
+   (concat " " prefix "(" x ", " y") ")))
 
-(defun TeX-TikZ-arg-polar-point (_ignored)
+(defun TeX-TikZ-arg-polar-point (_ignored &optional prefix)
   "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 ") ")))
+   (concat " " prefix "(" theta ":" r ") ")))
 
 (defun TeX-TikZ-arg-options (optional)
   "Prompt the user for options to a TikZ macro.
@@ -109,13 +113,22 @@ then called and the value returned.  PROMPT is used as 
the prompt
 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)))
+  (let* ((argument-type-names (mapcar 'car function-alist))
+         (selected-argument-type (TeX-TikZ-get-arg-type argument-type-names 
prompt))
+         (fn-alist-with-optional-elm (if optional
+                                         `(,@function-alist ("" identity))
+                                       function-alist))
+         (selected-mapping (assoc selected-argument-type
+                                  fn-alist-with-optional-elm)))
+
+    (eval
+     ;; Build the form we wish to evaluate.  This will be the function
+     ;; to be called (the second element in the assoc element),
+     ;; followed by the type name (the first element), followed by any
+     ;; other elements in the list as extra arguments.
+     `(,(cadr selected-mapping)
+       ,(car selected-mapping)
+       ,@(cddr selected-mapping)))))
 
 
 (defun TeX-TikZ-macro-arg (function-alist)
@@ -166,11 +179,11 @@ them as a list of strings, dropping the '()'."
           (add-to-list 'matches (match-string 1)))))
     matches))
 
-(defun TeX-TikZ-arg-named-point (_ignored)
+(defun TeX-TikZ-arg-named-point (_ignored &optional prefix)
   "Prompt the user for the name of a previous named-point."
   (let ((point-name (completing-read "Point name: "
                                      (TeX-TikZ-find-named-points))))
-    (concat " (" point-name ") ")))
+    (concat " " prefix "(" point-name ") ")))
 
 (defun TeX-TikZ-arg-circle (_ignored)
   "Prompt the user for the arguments to the circle command."
@@ -201,22 +214,26 @@ If OPTIONAL is non-nil and the user doesn't provide a 
point,
        (concat "parabola" options bend)))
 
 (defconst TeX-TikZ-point-function-map
-  '(("Rect Point" TeX-TikZ-arg-rect-point)
-    ("Polar Point" TeX-TikZ-arg-polar-point)
-    ("Named Point" TeX-TikZ-arg-named-point))
-  "An alist of point specification types and their functions." )
+  (let ((point-alist '(("Rect Point" TeX-TikZ-arg-rect-point)
+                       ("Polar Point" TeX-TikZ-arg-polar-point)
+                       ("Named Point" TeX-TikZ-arg-named-point))))
+    (apply 'append (mapcar
+                    (lambda (point-map)
+                      (let ((key (car point-map))
+                            (value (cadr point-map)))
+                        `((,key ,value)
+                          (,(concat "+" key) ,value "+")
+                          (,(concat "++" key) ,value "++"))))
+                    point-alist)))
+  "An alist of point specification types and their functions.
+A set of base point types along with variants that have \"+\" and
+\"++\" as a prefix."  )
 
 (defconst TeX-TikZ-path-connector-function-map
-  (let ((connectors '("--" "|-" "-|")))
-    (apply 'append (mapcar
-                     (lambda (connector)
-                       `((,connector identity)
-                         (,(concat connector " +") identity)
-                         (,(concat connector " ++") identity)))
-                     connectors)))
-  "An alist of path connectors.
-A set of base connectors along with variants that have \" +\" and
-\" ++\" appended to them, mapping to the identity function.")
+  '(("--" identity)
+    ("|-" identity)
+    ( "-|" identity))
+  "An alist of path connectors.")
 
 (defconst TeX-TikZ-draw-arg-function-map
   `(,@TeX-TikZ-point-function-map



reply via email to

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