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

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

[elpa] externals/org-real 5f5f352 117/160: Jump to location when enterin


From: ELPA Syncer
Subject: [elpa] externals/org-real 5f5f352 117/160: Jump to location when entering org real mode
Date: Wed, 6 Oct 2021 16:58:28 -0400 (EDT)

branch: externals/org-real
commit 5f5f352795e7676b5103d7f11bf93a40edd36c1a
Author: Tyler Grinn <tylergrinn@gmail.com>
Commit: Tyler Grinn <tylergrinn@gmail.com>

    Jump to location when entering org real mode
    
    With either org-real-world or org-real-headlines, the cursor will be
    at the position of the box in the diagram matching where the cursor is
    originally.
---
 demo/garage.org | 30 ++++++++++++++---------------
 org-real.el     | 60 +++++++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 63 insertions(+), 27 deletions(-)

diff --git a/demo/garage.org b/demo/garage.org
index ae95ec8..9cef143 100644
--- a/demo/garage.org
+++ b/demo/garage.org
@@ -1,17 +1,17 @@
 * Items in the garage
-  - [[real://garage/workbench?rel=in][workbench]]
-  - [[real://garage/workbench?rel=in/paintbrush?rel=in front of][paintbrush]]
-  - [[real://garage/workbench?rel=in/paintbrush?rel=in front of/wrench?rel=to 
the left of][wrench]]
-  - [[real://garage/workbench?rel=in/nails?rel=on top of/screwdriver?rel=on 
top of][screwdriver]]
-  - [[real://garage/workbench?rel=in/ratchet?rel=on top of][ratchet]]
-  - [[real://garage/east wall?rel=in/rake?rel=on/hoe?rel=to the left 
of/snowblower?rel=above/shovel?rel=above][shovel]]
-  - [[real://garage/east wall?rel=in/rake?rel=on][rake]]
-  - [[real://garage/workbench?rel=in/hammer?rel=on][hammer]]
-  - [[real://garage/east wall?rel=in/rake?rel=on/hoe?rel=to the left of][hoe]]
-  - [[real://garage/car?rel=in/air freshener?rel=in][air freshener]]
-  - [[real://garage/workbench?rel=in/nails?rel=on top of][nails]]
-  - [[real://garage/east wall?rel=in][East wall]]
-  - [[real://garage/east wall?rel=in/rake?rel=on/hoe?rel=to the left 
of/snowblower?rel=above][snowblower]]
-  - [[real://garage/workbench?rel=in/hammer?rel=on/screws?rel=to the right 
of][screws]]
+  - [[real://garage/workbench][workbench]]
+  - [[real://garage/workbench/paintbrush?rel=in front of][paintbrush]]
+  - [[real://garage/workbench/paintbrush?rel=in front of/wrench?rel=to the 
left of][wrench]]
+  - [[real://garage/workbench/nails?rel=on top of/screwdriver?rel=on top 
of][screwdriver]]
+  - [[real://garage/workbench/ratchet?rel=on top of][ratchet]]
+  - [[real://garage/east wall/rake?rel=on/hoe?rel=to the left 
of/snowblower?rel=above/shovel?rel=above][shovel]]
+  - [[real://garage/east wall/rake?rel=on][rake]]
+  - [[real://garage/workbench/hammer?rel=on][hammer]]
+  - [[real://garage/east wall/rake?rel=on/hoe?rel=to the left of][hoe]]
+  - [[real://garage/car/air freshener][air freshener]]
+  - [[real://garage/workbench/nails?rel=on top of][nails]]
+  - [[real://garage/east wall][East wall]]
+  - [[real://garage/east wall/rake?rel=on/hoe?rel=to the left 
of/snowblower?rel=above][snowblower]]
+  - [[real://garage/workbench/hammer?rel=on/screws?rel=to the right 
of][screws]]
   - [[real://garage/saw?rel=on][saw]]
-  - [[real://garage/workbench?rel=in/paintbrush?rel=in front of/wrench?rel=to 
the left of/pliers?rel=below][pliers]]
+  - [[real://garage/workbench/paintbrush?rel=in front of/wrench?rel=to the 
left of/pliers?rel=below][pliers]]
diff --git a/org-real.el b/org-real.el
index 3f13785..aceb019 100644
--- a/org-real.el
+++ b/org-real.el
@@ -217,24 +217,60 @@
 (defun org-real-world ()
   "View all real links in the current buffer."
   (interactive)
-  (org-real--pp
-   (org-real--merge
-    (mapcar
-     (lambda (containers)
-       (org-real--make-instance 'org-real-box containers))
-     (org-real--parse-buffer)))
-   nil nil t))
+  (let ((link (cond
+               ((org-in-regexp org-link-bracket-re 1)
+                (match-string-no-properties 1))
+               ((org-in-regexp org-link-plain-re)
+                (org-unbracket-string "<" ">" (match-string 0)))))
+        (world (org-real--merge
+                (mapcar
+                 (lambda (containers)
+                   (org-real--make-instance 'org-real-box containers))
+                 (org-real--parse-buffer)))))
+    (org-real--pp world nil nil t)
+    (if (and link (string= "real" (ignore-errors (url-type 
(url-generic-parse-url link)))))
+        (let ((containers (reverse (org-real--parse-url link)))
+              match parent)
+          (while (and containers (not match))
+            (setq match (org-real--find-matching
+                         (org-real-box :name (plist-get (pop containers) 
:name))
+                         world)))
+          (when match
+            (setq parent (with-slots (parent) match parent))
+            (while (not (org-real--is-visible parent))
+              (setq match parent)
+              (setq parent (with-slots (parent) match parent)))
+            (run-with-timer
+             0 nil
+             (lambda ()
+             (let ((top (org-real--get-top match))
+                   (left (org-real--get-left match)))
+               (forward-line (- (+ org-real--current-offset top 1 
org-real-padding-y)
+                                (line-number-at-pos)))
+               (move-to-column (+ left 1 org-real-padding-x))))))))))
 
 (defun org-real-headlines ()
   "View all org headlines as an org real diagram.
 
 MAX-LEVEL is the maximum level to show headlines for."
   (interactive)
-  (org-real--pp
-   (org-real--parse-headlines)
-   nil
-   'display-buffer-same-window
-   t 1 2))
+  (let ((path (seq-filter 'identity (append (list (org-entry-get nil "ITEM")) 
(reverse (org-get-outline-path)))))
+        (world (save-excursion (org-real--parse-headlines)))
+        match)
+    (org-real--pp world nil 'display-buffer-same-window t 1 2)
+    (while (and path (not match))
+      (setq match (org-real--find-matching (org-real-box :name (pop path)) 
world)))
+    (when match
+      (while (not (org-real--is-visible match))
+        (setq match (with-slots (parent) match parent)))
+      (let ((top (org-real--get-top match))
+            (left (org-real--get-left match)))
+        (run-with-timer
+         0 nil
+         (lambda ()
+           (forward-line (- (+ org-real--current-offset top 1 
org-real-padding-y)
+                            (line-number-at-pos)))
+           (move-to-column (+ left 1 org-real-padding-x))))))))
 
 (defun org-real-apply ()
   "Apply any change from the real link at point to the current buffer."



reply via email to

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