[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-real cd43923 119/160: Use original relationship for
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org-real cd43923 119/160: Use original relationship for tooltip if changed |
Date: |
Wed, 6 Oct 2021 16:58:28 -0400 (EDT) |
branch: externals/org-real
commit cd43923ddcaa65124dee2b65d602cec15eda5945
Author: Tyler Grinn <tylergrinn@gmail.com>
Commit: Tyler Grinn <tylergrinn@gmail.com>
Use original relationship for tooltip if changed
---
org-real.el | 309 +++++++++++++++++++++++++++++++-----------------------------
1 file changed, 162 insertions(+), 147 deletions(-)
diff --git a/org-real.el b/org-real.el
index 4a306ad..0b50b57 100644
--- a/org-real.el
+++ b/org-real.el
@@ -212,142 +212,6 @@
'("in" "on" "behind")
"List of prepositions for which boxes are flexibly added to their parent.")
-;;;; Interactive functions
-
-(defun org-real-world ()
- "View all real links in the current buffer."
- (interactive)
- (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)
- (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."
- (interactive)
- (let (new-link replace-all)
- (cond
- ((org-in-regexp org-link-bracket-re 1)
- (setq new-link (match-string-no-properties 1)))
- ((org-in-regexp org-link-plain-re)
- (setq new-link (org-unbracket-string "<" ">" (match-string 0)))))
- (when (and new-link
- (string= "real" (ignore-errors (url-type (url-generic-parse-url
new-link)))))
- (let ((new-containers (reverse (org-real--parse-url new-link
(point-marker)))))
- (while new-containers
- (let ((primary (plist-get (car new-containers) :name))
- (changes '())
- old-containers)
- (org-element-map (org-element-parse-buffer) 'link
- (lambda (old-link)
- (when (string= (org-element-property :type old-link) "real")
- (setq old-containers (reverse (org-real--parse-url
- (org-element-property
:raw-link old-link)
- (set-marker (point-marker)
(org-element-property :begin old-link)))))
- (when-let* ((new-index 0)
- (old-index (seq-position
- old-containers
- primary
- (lambda (a b) (string= (plist-get a
:name) b))))
- (begin (org-element-property :begin old-link))
- (end (org-element-property :end old-link))
- (replace-link (org-real--to-link
- (reverse
- (append (cl-subseq
old-containers 0 old-index)
- new-containers)))))
- (when (catch 'conflict
- (if (not (= (length new-containers) (- (length
old-containers) old-index)))
- (throw 'conflict t))
- (while (< new-index (length new-containers))
- (if (or (not (string= (plist-get (nth new-index
new-containers) :name)
- (plist-get (nth old-index
old-containers) :name)))
- (not (string= (plist-get (nth new-index
new-containers) :rel)
- (plist-get (nth old-index
old-containers) :rel))))
- (throw 'conflict t))
- (setq new-index (+ 1 new-index))
- (setq old-index (+ 1 old-index)))
- nil)
- (let* ((old-desc (save-excursion
- (and (goto-char begin)
- (org-in-regexp
org-link-bracket-re 1)
- (match-end 2)
- (match-string-no-properties 2))))
- (new-link (org-real--link-make-string
replace-link old-desc)))
- (push
- `(lambda ()
- (save-excursion
- (delete-region ,begin ,end)
- (goto-char ,begin)
- (insert ,new-link)))
- changes)))))))
- (when (and changes
- (or replace-all (let ((response
- (read-char-choice
- (concat
- "Replace all occurrences of "
- primary
- " in current buffer? y/n/a ")
- '(?y ?Y ?n ?N ?a ?A)
- t)))
- (cond
- ((or (= response ?y) (= response
?Y)) t)
- ((or (= response ?n) (= response
?N)) nil)
- ((or (= response ?a) (= response ?A))
- (setq replace-all t))))))
- (mapc 'funcall changes)))
- (pop new-containers)))))
- (message nil))
-
;;;; Org Real mode
(defvar org-real--box-ring '()
@@ -488,6 +352,136 @@ The following commands are available:
("n" . org-real-mode-cycle-down)
("<backtab>" . org-real-mode-cycle-visibility)))
+;;;; Interactive functions
+
+(defun org-real-world ()
+ "View all real links in the current buffer."
+ (interactive)
+ (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)
+ (while (and containers (or (not match) (not (org-real--is-visible
match))))
+ (setq match (org-real--find-matching
+ (org-real-box :name (plist-get (pop containers)
:name))
+ world)))
+ (when match
+ (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-headlines ()
+ "View all org headlines as an org real diagram.
+
+MAX-LEVEL is the maximum level to show headlines for."
+ (interactive)
+ (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 (or (not match) (not (org-real--is-visible match))))
+ (setq match (org-real--find-matching (org-real-box :name (pop path))
world)))
+ (when match
+ (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."
+ (interactive)
+ (let (new-link replace-all)
+ (cond
+ ((org-in-regexp org-link-bracket-re 1)
+ (setq new-link (match-string-no-properties 1)))
+ ((org-in-regexp org-link-plain-re)
+ (setq new-link (org-unbracket-string "<" ">" (match-string 0)))))
+ (when (and new-link
+ (string= "real" (ignore-errors (url-type (url-generic-parse-url
new-link)))))
+ (let ((new-containers (reverse (org-real--parse-url new-link
(point-marker)))))
+ (while new-containers
+ (let ((primary (plist-get (car new-containers) :name))
+ (changes '())
+ old-containers)
+ (org-element-map (org-element-parse-buffer) 'link
+ (lambda (old-link)
+ (when (string= (org-element-property :type old-link) "real")
+ (setq old-containers (reverse (org-real--parse-url
+ (org-element-property
:raw-link old-link)
+ (set-marker (point-marker)
(org-element-property :begin old-link)))))
+ (when-let* ((new-index 0)
+ (old-index (seq-position
+ old-containers
+ primary
+ (lambda (a b) (string= (plist-get a
:name) b))))
+ (begin (org-element-property :begin old-link))
+ (end (org-element-property :end old-link))
+ (replace-link (org-real--to-link
+ (reverse
+ (append (cl-subseq
old-containers 0 old-index)
+ new-containers)))))
+ (when (catch 'conflict
+ (if (not (= (length new-containers) (- (length
old-containers) old-index)))
+ (throw 'conflict t))
+ (while (< new-index (length new-containers))
+ (if (or (not (string= (plist-get (nth new-index
new-containers) :name)
+ (plist-get (nth old-index
old-containers) :name)))
+ (not (string= (plist-get (nth new-index
new-containers) :rel)
+ (plist-get (nth old-index
old-containers) :rel))))
+ (throw 'conflict t))
+ (setq new-index (+ 1 new-index))
+ (setq old-index (+ 1 old-index)))
+ nil)
+ (let* ((old-desc (save-excursion
+ (and (goto-char begin)
+ (org-in-regexp
org-link-bracket-re 1)
+ (match-end 2)
+ (match-string-no-properties 2))))
+ (new-link (org-real--link-make-string
replace-link old-desc)))
+ (push
+ `(lambda ()
+ (save-excursion
+ (delete-region ,begin ,end)
+ (goto-char ,begin)
+ (insert ,new-link)))
+ changes)))))))
+ (when (and changes
+ (or replace-all (let ((response
+ (read-char-choice
+ (concat
+ "Replace all occurrences of "
+ primary
+ " in current buffer? y/n/a ")
+ '(?y ?Y ?n ?N ?a ?A)
+ t)))
+ (cond
+ ((or (= response ?y) (= response
?Y)) t)
+ ((or (= response ?n) (= response
?N)) nil)
+ ((or (= response ?a) (= response ?A))
+ (setq replace-all t))))))
+ (mapc 'funcall changes)))
+ (pop new-containers)))))
+ (message nil))
+
;;;; Pretty printing
(defun org-real--pp (box
@@ -710,6 +704,10 @@ ORIG is `org-insert-link', ARGS are the arguments passed
to it."
:type string)
(rel-box :initarg :rel-box
:type org-real-box)
+ (display-rel :initarg :display-rel
+ :type string)
+ (display-rel-box :initarg :display-rel-box
+ :type org-real-box)
(x-order :initarg :x-order
:initform 0
:type number)
@@ -1169,7 +1167,7 @@ If INCLUDE-ON-TOP is non-nil, also include height on top
of box."
(cl-defmethod org-real--create-cursor-function ((box org-real-box))
"Create cursor functions for entering and leaving BOX."
- (with-slots (rel rel-box name metadata) box
+ (with-slots (rel rel-box display-rel-box display-rel name metadata) box
(let (tooltip-timer)
(lambda (_window _oldpos dir)
(let ((inhibit-read-only t))
@@ -1179,17 +1177,27 @@ If INCLUDE-ON-TOP is non-nil, also include height on
top of box."
(if (slot-boundp box :metadata)
(setq tooltip-timer (org-real--tooltip metadata))
(if (and (slot-boundp box :name) (slot-boundp box :rel))
- (with-slots ((rel-name name)) rel-box
+ (with-slots ((rel-name name)) (if (slot-boundp box
:display-rel-box)
+ display-rel-box
+ rel-box)
(setq tooltip-timer
(org-real--tooltip
(with-temp-buffer
(insert (format "The %s is %s the %s."
- name rel rel-name))
+ name
+ (if (slot-boundp box
:display-rel)
+ display-rel
+ rel)
+ rel-name))
(let ((fill-column
org-real-tooltip-max-width))
(fill-paragraph t))
(buffer-string)))))))
- (if (slot-boundp box :rel-box)
- (org-real--draw rel-box 'rel))
+ (if (slot-boundp box :display-rel-box)
+ (if (org-real--is-visible display-rel-box)
+ (org-real--draw display-rel-box 'rel))
+ (if (and (slot-boundp box :rel-box)
+ (org-real--is-visible rel-box))
+ (org-real--draw rel-box 'rel)))
(org-real--draw box 'selected))
(if tooltip-timer (cancel-timer tooltip-timer))
(if (slot-boundp box :rel-box)
@@ -1272,9 +1280,12 @@ BOX is the box the button is being made for."
(cl-defmethod org-real--is-visible ((box org-real-box))
"Determine if BOX is visible according to `org-real--visibility'."
- (with-slots (level) box
+ (with-slots (level parent) box
(or (= 0 org-real--visibility)
- (<= level org-real--visibility))))
+ (<= level org-real--visibility)
+ (seq-find
+ (lambda (sibling) (eq sibling box))
+ (org-real--get-children parent)))))
(cl-defmethod org-real--get-children ((box org-real-box) &optional arg)
"Get all visible children of BOX.
@@ -1408,14 +1419,18 @@ PREV must already exist in PARENT."
(setq cur-behind prev-behind)
(cond
((and prev-in-front (string= rel "below"))
+ (oset box :display-rel-box prev)
(while (with-slots (in-front) prev in-front)
(setq prev (with-slots (parent) prev parent)))
(setq parent (with-slots (parent) prev parent)))
((and prev-on-top (string= rel "above"))
+ (oset box :display-rel-box prev)
(while (with-slots (on-top) prev on-top)
(setq prev (with-slots (parent) prev parent)))
(setq parent (with-slots (parent) prev parent)))
((and prev-on-top (string= rel "below"))
+ (oset box :display-rel rel)
+ (oset box :display-rel-box prev)
(setq rel "in")
(setq prev parent))))
((member rel '("to the left of" "to the right of"))
@@ -1551,7 +1566,7 @@ NEXT."
(setq y-order 1.0e+INF))
(cond
((member rel '("to the left of" "to the right of"))
- (setq next-y rel-y)
+ (setq y-order rel-y)
(if (string= rel "to the left of")
(setq x-order rel-x)
(setq x-order (+ 1 rel-x)))
@@ -1567,7 +1582,7 @@ NEXT."
(setq sibling-x (+ 1 sibling-x)))))
row-siblings)))
((member rel '("above" "below"))
- (setq next-x rel-x)
+ (setq x-order rel-x)
(let ((sibling-y-orders (mapcar
(lambda (sibling) (with-slots (y-order)
sibling y-order))
(seq-filter
@@ -1597,7 +1612,7 @@ NEXT."
"Add BOX to a PARENT box flexibly.
This function ignores the :rel slot and adds BOX in such a way
-that the width of the world is kept below `org-real-flex-width'
+that the width of the WORLD is kept below `org-real-flex-width'
characters if possible."
(let ((cur-width (org-real--get-width world)))
(org-real--make-dirty world)
@@ -1656,7 +1671,7 @@ characters if possible."
(list pass fail))))
(cl-defmethod org-real--flex-adjust ((box org-real-box) (world org-real-box))
- "Adjust BOX x and y orders to try to fit BOX within `org-real-flex-width'."
+ "Adjust BOX x and y orders to try to fit WORLD within `org-real-flex-width'."
(with-slots (children) box
(let* ((partitioned (org-real--partition
(lambda (child) (with-slots (flex) child flex))
- [elpa] externals/org-real d23f9bf 112/160: If headline is a link, only display description, (continued)
- [elpa] externals/org-real d23f9bf 112/160: If headline is a link, only display description, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real f883078 101/160: Merge branch 'next' into 'main', ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 9707641 130/160: Allow boxes to not have location markers, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real add82f3 124/160: Added smoke test; fixed behind preposition, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 6428a6d 125/160: Smooth lines, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real e38ae9b 131/160: Added help-echo slot for minibuffer messages, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 5f5f352 117/160: Jump to location when entering org real mode, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real ce817a1 139/160: Merge display-rel-box, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 75871b1 140/160: Color theme update, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 5541420 143/160: Use buffer name instead of buffer-file-name for org-real-headlines, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real cd43923 119/160: Use original relationship for tooltip if changed,
ELPA Syncer <=
- [elpa] externals/org-real f03777b 132/160: Fixed hiding of rel-box border, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 8d5af75 144/160: Linting, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real ab46371 160/160: Merge branch 'next' into 'main', ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 20e80af 145/160: Bump version, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real babe4da 148/160: Add submodules during ci/cd pipeline, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real a13ee17 155/160: Added elpaignore, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 89c1120 153/160: Linting, rearranging, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 19711cb 159/160: Updated elpaignore, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real af8744b 151/160: Removed `org-real-headlines`, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real d95d469 156/160: Changed cl-defmethod to defun; linting, ELPA Syncer, 2021/10/06