[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-real 7f33978 027/160: Added apply function for rear
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org-real 7f33978 027/160: Added apply function for rearranging other links |
Date: |
Wed, 6 Oct 2021 16:58:08 -0400 (EDT) |
branch: externals/org-real
commit 7f33978800cd3366f1ad24ec57af3989ceecb039
Author: Tyler Grinn <tylergrinn@gmail.com>
Commit: Tyler Grinn <tylergrinn@gmail.com>
Added apply function for rearranging other links
---
org-real.el | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 75 insertions(+), 1 deletion(-)
diff --git a/org-real.el b/org-real.el
index a260f7f..bcefb29 100644
--- a/org-real.el
+++ b/org-real.el
@@ -444,11 +444,85 @@ ARGS are the arguments passed to `org-insert-link'."
"Advise `org-insert-link' to advise `read-string' during editing of a link.
ARGS are the arguments passed to `org-insert-link'."
- (advice-remove 'read-string #'org-real--read-string-advice))
+ (advice-remove 'read-string #'org-real--read-string-advice)
+ (org-real--apply))
+
(advice-add 'org-insert-link :before #'org-real--insert-link-before)
(advice-add 'org-insert-link :after #'org-real--insert-link-after)
+(defun org-real--apply ()
+ "Apply any changes to the current buffer from the last inserted real link."
+ (let (new-link new-desc 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))))
+ (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))))
+
+ (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))))
+ (old-desc ""))
+ (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)
+ (goto-char begin)
+ (if (org-in-regexp org-link-bracket-re 1)
+ (setq old-desc (when (match-end 2)
(match-string-no-properties 2))))
+ (push
+ `(lambda ()
+ (delete-region ,begin ,end)
+ (goto-char ,begin)
+ (insert (org-link-make-string ,replace-link
,old-desc)))
+ 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 &optional containers)
- [elpa] externals/org-real d161250 041/160: Removed reference to org-real-box, (continued)
- [elpa] externals/org-real d161250 041/160: Removed reference to org-real-box, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 9ac40b5 042/160: v0.1.0, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 181c538 043/160: Patch for using cl-defmethod rather than defun, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real d81217c 045/160: Refactoring, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real cf2778a 049/160: Whitespace cleanup, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real cdce61e 058/160: Linting, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 03234f7 059/160: Requirements before patches, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 8550ace 004/160: Added alias "on" for "in", ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 72bf24b 007/160: Added documentation, ci/cd, and completion, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real c513e06 016/160: Updated readme, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 7f33978 027/160: Added apply function for rearranging other links,
ELPA Syncer <=
- [elpa] externals/org-real 371024e 035/160: Satisfying ELC compiler, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 3e325b3 021/160: Simplified merge function, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real abb5aed 061/160: More edge cases, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 1160749 066/160: v0.2.0, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 256060a 064/160: Updated readme, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real a5736f1 070/160: Created buttons that link back to the location of the link, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 4c81b19 071/160: org-real-headlines; Added more keys to Org Real mode, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real e46eb9c 075/160: Added ability to cycle children of a box, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real 8ab3459 083/160: Added test framework, ELPA Syncer, 2021/10/06
- [elpa] externals/org-real f6417b0 076/160: Added ability to collapse and expand boxes, ELPA Syncer, 2021/10/06