Commits

Ivan Andrus committed f83ed97

Added support for round, and duplicate
Commented all show's

Comments (0)

Files changed (2)

           (and (whizzy-goto-file file)
                (prog1 (goto-line (string-to-number line))
                  (end-of-line))
-               (show 'here)
+               ;; (show 'here)
                ;; (insert "xxx")
                (or (re-search-backward regexp (point-min) t)
                    (re-search-forward regexp (point-max) t))
-               (show 'there)
-               (show (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
+               ;; (show 'there)
+               ;; (show (buffer-substring-no-properties (match-beginning 1) (match-end 1)))
                (let ((begin  (match-beginning 1))
                      (modified  (buffer-modified-p))
                      (edited))
   (save-window-excursion
     (save-excursion
       (save-restriction
-        (show file)
-        (show name)
+        ;; (show file)
+        ;; (show name)
         (and (prog1 (whizzy-goto-file file)
                (widen))
              (goto-char (point-min))
              ;; (narrow-to-defun)
              ;; (show line)
              ;; (sit-for 2)
-             (show (whizzy-narrow-to-tikz))
+             ;; (show
+             (whizzy-narrow-to-tikz)
+             ;; )
 
              ;; Here we need strict methods of finding and keep loosening them...
 
              (let* (;; type orig x y xmid ymid
                     ;;  0    1   2 3  4    5
                     (pieces (split-string name "@"))
+                    ;; tikz,matcher,precision,duplicate?
+                    ;;   0 ,   1   ,    2    ,    3
+                    (style-pieces (split-string (car pieces) ":"))
+                    (precision (string-to-number (nth 2 style-pieces)))
                     (newx (+ (string-to-number (nth 4 pieces))
                              (- (string-to-number dx)
                                 (string-to-number (nth 2 pieces)))))
                     (newy (+ (string-to-number (nth 5 pieces))
                              (- (string-to-number dy)
                                 (string-to-number (nth 3 pieces)))))
-                    (replacement (format "%s,%s" newx newy))
+                    ;; TODO: don't include trailing zeros? -- should I round instead?
+                    (specifier (format "%%.%df,%%.%df" precision precision))
+                    (replacement (format specifier newx newy))
                     ;; (regexp (aget whizzy-tikz-node-regexp 'lax))
                     (modified  (buffer-modified-p)))
-               (show pieces)
-               (show replacement)
+               ;; (show pieces)
+               ;; (show style-pieces)
+               ;; (show precision)
+               ;; (show specifier)
+               ;; (show replacement)
                (dolist (regexp (list
                                 ;; Check for an exact match
                                 (concat "\\b\\(" (nth 1 pieces) "\\)\\b")
 
                    ;; (show 'there)
                    ;; (sit-for 5)
+
+                   ;; We found one --
                    (let (;(begin  (match-beginning 1))
                          (edited
                           ;;  (save-match-data
                           ;;    (and (string= (match-string-no-properties 1) dx)
                           ;;         (string= (match-string-no-properties 2) dy))))
                           t)
-                         )
+                         (saved-line (and (string= "duplicate" (nth 3 style-pieces))
+                                          (buffer-substring-no-properties
+                                           (line-beginning-position)
+                                           (line-end-position)))))
+                     (sit-for 1)
+                     ;; (goto-char )
+
+
                      ;; (show (match-string-no-properties 0))
                      ;; (show (match-beginning 1))
                      ;; (show (match-end 1))
                      ;; (show (replace-match replacement t t nil 1))
                      (replace-match replacement t t nil 1)
+                     (when saved-line
+                       (beginning-of-line)
+                       (insert saved-line))
                      ;; Have to figure out how to account for center vs lower left
                      ;; (replace-match dx t t nil 1)
                      ;; (replace-match dy t t nil 2) ;or the other order??? Can you do both?
 
 % We need to use some internal commands with `@`s in them for getting
 % the widths of the nodes
-\makeatletter
+% \makeatletter
 % \show\tikz@node@at
 
 % \def \advi@special #1{\advi@special@ {advi: #1}\message{#1}}
   \expandafter\tikz@@scan@@no@calculator\expandafter#1\tikz@temp%
 }
 
-
 \tikzset{
 % This is the workhorse style
   ADVI/.style={
 % get access to its width and height.  What this means is that our
 % node ends up being equivalent to
 %  \node[at=(x-value,y-value)] {node text} [advi/set advi={x=,y=}];
-    append after command={[ADVI/set advi]},
+    append after command={[ADVI/set advi={#1}]},
 % As the advi boxes are specified by lower-left corner, we anchor our
 % node at the lower-left so that the given coordinate is the node
 % coordinate
 % and `/tikz/advi/y` to specify the location of the node via the
 % `at` key.  We need to give the full path as we're currently in at
 % `/tikz/advi`
+    #1,
     % /tikz/at/.store=\origPos,
-    type/.default=node
+    % type/.default=node
   },
-% This next bit ensures that the `/tikz/advi/x` and `y` keys can be
-% used to store values.
-  % ADVI/.cd,
+  % This next bit ensures that the `/tikz/advi/type` and `precision` keys can be
+  % used to store values.
+  ADVI/.cd,
+  type/.initial=node,
+  precision/.initial=4,
+  duplicate/.initial=no,
 % This is the part that specifies the boxes in the dvi.  This is
 % actually executed after the node has been processed
-  ADVI/set advi/.code={
+  set advi/.code={
     \let\this@nodes@def\my@node@def
     \pgfpointxy{1}{1}
     \advixunit \pgf@x
     \pgfmathsetmacro{\advi@node@h}{(\pgf@ya - \pgf@y)/\the\advi@edit@yunit}%
     \pgfmathsetmacro{\advi@node@x}{(\pgf@x)/\the\advi@edit@xunit}%
     \pgfmathsetmacro{\advi@node@y}{(\pgf@y)/\the\advi@edit@yunit}%
-
+    %
     \tikz@scan@one@point\pgfutil@firstofone(\tikzlastnode)
     \pgfmathsetmacro{\advi@node@xm}{(\pgf@x)/\the\advi@edit@xunit}%
     \pgfmathsetmacro{\advi@node@ym}{(\pgf@y)/\the\advi@edit@yunit}%
     % \message{^^J}
     % \pgfkeysgetvalue{\pgfkeyscurrentpath}{\temp}%
     % \pgfkeys{/tikz/at/.print to log}
-    \adviedit[tikznode@\this@nodes@def @\advi@node@x @\advi@node@y @\advi@node@xm @\advi@node@ym]{comm=\advinode,w=\advi@node@w,h=\advi@node@h,x=\advi@node@x,y=\advi@node@y}{}
+    % TODO: Why do I have to do this?  Why didn't it take before?
+    \tikzset{/tikz/ADVI/.cd,#1}
+    \adviedit[tikz:\pgfkeysvalueof{/tikz/ADVI/type}:\pgfkeysvalueof{/tikz/ADVI/precision}:\pgfkeysvalueof{/tikz/ADVI/duplicate}@\this@nodes@def @\advi@node@x @\advi@node@y @\advi@node@xm @\advi@node@ym]{comm=\advinode,w=\advi@node@w,h=\advi@node@h,x=\advi@node@x,y=\advi@node@y}{}
     % \adviedit[tikznode:\advi@node@xm:\advi@node@ym:\val:\pgfkeysvalueof{/tikz/at}]{comm=\advinode,w=\advi@node@w,h=\advi@node@h,x=\advi@node@x,y=\advi@node@y}{}
     % \my@adviedit{advinode:\advi@node@x}{\advi@node@w}{\advi@node@h}{\advi@node@x}{\advi@node@y}
   }