[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[AUCTeX-devel] TiKZ: Complete on previously defined named points.
From: |
Matthew Leach |
Subject: |
[AUCTeX-devel] TiKZ: Complete on previously defined named points. |
Date: |
Mon, 28 Mar 2016 12:20:42 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux) |
Hi all,
This patch adds support for searching for named points within the
current environment and completes when adding a point-type called 'Named
Point'.
For example,
\begin{tikzpicture}
\draw (2, 5) -- (42:3) node(node1){This node.};
\draw (2, 5) -- (90:3) node(node2){This node.};
\draw .
\end{tikzpicture}
When point is at '.', and one selects 'Named Point' as the next argument
type, you can complete and the previously defined nodes, 'node1' and
'node2'.
Comments & feedback welcome :-).
Thanks,
--
Matt
>From c6d61ec57045e0907ef7cb67df451a05f67d22c1 Mon Sep 17 00:00:00 2001
From: Matthew Leach <address@hidden>
Date: Mon, 28 Mar 2016 12:10:56 +0100
Subject: [PATCH] TikZ: Add 'Named Point' point type with completion.
* style/tikz.el (TeX-TikZ-point-name-regexp): New.
(TeX-TikZ-find-named-points): New.
(TeX-TikZ-arg-named-point): New.
(TeX-TikZ-point-function-map): Add 'Named Point' element that maps to
`TeX-TikZ-arg-named-point'.
---
style/tikz.el | 34 +++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)
diff --git a/style/tikz.el b/style/tikz.el
index d002811..abcb0bb 100644
--- a/style/tikz.el
+++ b/style/tikz.el
@@ -142,9 +142,41 @@ is finished."
;; Finish the macro.
(insert ";")))
+(defcustom TeX-TikZ-point-name-regexp
+ "(\\([A-Za-z0-9]+\\))"
+ "A regexp that matches TikZ names, i.e. alpha-numeric
+ characters enclosed in a ()."
+ :type 'regexp
+ :group 'auctex-tikz)
+
+(defun TeX-TikZ-find-named-points ()
+ "Find TiKZ named points in current enviroment.
+Begin by finding the span of the current TikZ enviroment and then
+searching within that span to find all named-points and return
+them as a list of strings, dropping the '()'."
+ (let* ((env-end (save-excursion
+ (LaTeX-find-matching-end)
+ (point)))
+ (matches ()))
+ ;; TODO: Handle cases where we are in a nested environment, \scope
+ ;; for example.
+ (save-excursion
+ (LaTeX-find-matching-begin)
+ (save-match-data
+ (while (re-search-forward TeX-TikZ-point-name-regexp env-end t)
+ (add-to-list 'matches (match-string 1)))))
+ matches))
+
+(defun TeX-TikZ-arg-named-point (_ignored)
+ "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 ") ")))
+
(defconst TeX-TikZ-point-function-map
'(("Rect Point" TeX-TikZ-arg-rect-point)
- ("Polar Point" TeX-TikZ-arg-polar-point))
+ ("Polar Point" TeX-TikZ-arg-polar-point)
+ ("Named Point" TeX-TikZ-arg-named-point))
"An alist of point specification types to their respective
functions.")
--
2.7.4
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [AUCTeX-devel] TiKZ: Complete on previously defined named points.,
Matthew Leach <=