[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/hyperdrive 62c487448f 06/82: WIP
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/hyperdrive 62c487448f 06/82: WIP |
Date: |
Mon, 25 Sep 2023 19:00:49 -0400 (EDT) |
branch: elpa/hyperdrive
commit 62c487448f66fd9ddc945bc251183b2145f54715
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
WIP
---
hyperdrive-org.el | 11 +++++
hyperdrive.el | 9 +++-
tests/test-hyperdrive.el | 104 +++++++++++++++++++++++++++++++----------------
3 files changed, 86 insertions(+), 38 deletions(-)
diff --git a/hyperdrive-org.el b/hyperdrive-org.el
index c6d484686a..0a497c5909 100644
--- a/hyperdrive-org.el
+++ b/hyperdrive-org.el
@@ -155,6 +155,17 @@ the current location."
;; FIXME: For fuzzy links, passing to hyperdrive-expand-url is a no-no.
(hyperdrive-open-url (hyperdrive-expand-url (org-element-property
:path context)))))))
+(defun hyperdrive--org-insert-link-after-advice (&rest _)
+ "Modify just-inserted link as appropriate for `hyperdrive-mode' buffers."
+ (when (and hyperdrive-mode hyperdrive-current-entry)
+ (let* ((element (org-element-context))
+ (_ (cl-assert (eq 'link (car element))))
+ (entry (hyperdrive-url-entry (org-element-property :raw-link
element))))
+ entry
+
+ )
+ ))
+
;;;###autoload
(with-eval-after-load 'org
(org-link-set-parameters "hyper"
diff --git a/hyperdrive.el b/hyperdrive.el
index 2f7e905945..bc7e8d3742 100644
--- a/hyperdrive.el
+++ b/hyperdrive.el
@@ -303,10 +303,15 @@ Intended to be passed to `buffer-local-restore-state'.")
;; to allow diffing modified buffer with hyperdrive file
buffer-offer-save t))
(add-hook 'after-change-major-mode-hook
- #'hyperdrive--hack-write-contents-functions nil 'local))
+ #'hyperdrive--hack-write-contents-functions nil 'local)
+ ;; TODO: Consider checking for existing advice before adding our own.
+ (advice-add #'org-insert-link :after
#'hyperdrive--org-insert-link-after-advice))
(buffer-local-restore-state hyperdrive-mode--state)
(remove-hook 'after-change-major-mode-hook
- #'hyperdrive--hack-write-contents-functions 'local)))
+ #'hyperdrive--hack-write-contents-functions 'local)
+ ;; FIXME: Only remove advice when all hyperdrive-mode buffers are killed.
+ ;; (advice-remove #'org-insert-link #'hyperdrive--org-insert-link)
+ ))
;; Making it permanent-local keeps the minor mode active even if the
;; user changes the major mode, so the buffer can still be saved back
;; to the hyperdrive.
diff --git a/tests/test-hyperdrive.el b/tests/test-hyperdrive.el
index 37b5794b06..6cb6e46495 100644
--- a/tests/test-hyperdrive.el
+++ b/tests/test-hyperdrive.el
@@ -194,64 +194,96 @@ LINK is an Org link as a string."
(org-insert-link)
(buffer-string)))
-(defun hyperdrive-test-org-link-roundtrip (contents)
+(cl-defun hyperdrive-test-org-link-roundtrip
+ (contents &key store-from insert-into)
(let ((org-id-link-to-org-use-id nil)
(default-directory "/")
(org-link-file-path-type
(lambda (path)
(replace-regexp-in-string (rx bos (optional "file:")
- "/hyper:/") "hyper://" path)))
+ "/hyper:/")
+ "hyper://" path)))
;; (org-link-file-path-type
;; (lambda (path)
;; (string-trim-left (file-relative-name path)
;; (rx "file:"))))
+ (store-from-entry (hyperdrive-entry-create
+ :hyperdrive (hyperdrive-create :public-key (car
store-from))
+ :path (cdr store-from)))
+ (insert-into-entry (hyperdrive-entry-create
+ :hyperdrive (hyperdrive-create :public-key (car
insert-into))
+ :path (cdr insert-into)))
org-stored-links)
(with-temp-buffer
(insert contents)
(org-mode)
(hyperdrive-mode)
- (setq-local hyperdrive-current-entry
- (hyperdrive-entry-create
- :hyperdrive (hyperdrive-create :public-key "public-key")
- :path "/foo/bar"))
+ (setq-local hyperdrive-current-entry store-from-entry)
(goto-char (point-min))
(re-search-forward (rx "<|>"))
(org-store-link nil 'interactive))
(with-temp-buffer
(org-mode)
+ (hyperdrive-mode)
+ (setq-local hyperdrive-current-entry insert-into-entry)
(with-simulated-input "RET"
(org-insert-link))
(buffer-substring-no-properties (point-min) (point-max)))))
-(hyperdrive-test-org-link-roundtrip
- "<|>
+(ert-deftest hyperdrive-link-same-drive-different-file-before-heading ()
+ "Linking to a file (before the first heading) and on same drive."
+ (should
+ (equal "[[./foo/bar]]"
+ (hyperdrive-test-org-link-roundtrip
+ "<|>
* Heading A
-* Heading B")
-"[[hyper://public-key/foo/bar]]"
-
-(hyperdrive-test-org-link-roundtrip
- "* Heading A
-<|>
-* Heading B")
-"[[hyper://public-key/foo/bar#Heading%20A][Heading A]]"
-
-(hyperdrive-test-org-link-roundtrip
- "* Heading A
-:PROPERTIES:
-:ID: deadbeef
-:END:
+* Heading B"
+ :store-from '("public-key" . "/foo/bar")
+ :insert-into '("public-key" . "/foo/zot")))))
+
+(ert-deftest hyperdrive-link-same-drive-same-file-in-heading-without-custom-id
()
+ "Linking to a heading within the same file (and on same drive)."
+ (should
+ (equal "[[*Heading A]]"
+ (hyperdrive-test-org-link-roundtrip
+ "* Heading A
<|>
-* Heading B")
-"[[hyper://public-key/foo/bar#deadbeef][Heading A]]"
-
-(hyperdrive-test-org-link-roundtrip
- "* Heading A
-:PROPERTIES:
-:CUSTOM_ID: custom-id
-:END:
-<|>
-* Heading B")
-"[[hyper://public-key/foo/bar#custom-id][Heading A]]"
-
-
-"hyper://public-key/foo/bar#deadbeef"
+* Heading B"
+ :store-from '("public-key" . "/foo/bar")
+ :insert-into '("public-key" . "/foo/bar")))))
+
+(ert-deftest hyperdrive-link-heading-within-drive ()
+ "Linking to a heading within the same drive but different file.")
+
+;; (hyperdrive-test-org-link-roundtrip
+;; "<|>
+;; * Heading A
+;; * Heading B")
+;; "[[hyper://public-key/foo/bar]]"
+
+;; (hyperdrive-test-org-link-roundtrip
+;; "* Heading A
+;; <|>
+;; * Heading B")
+;; "[[hyper://public-key/foo/bar#Heading%20A][Heading A]]"
+
+;; (hyperdrive-test-org-link-roundtrip
+;; "* Heading A
+;; :PROPERTIES:
+;; :ID: deadbeef
+;; :END:
+;; <|>
+;; * Heading B")
+;; "[[hyper://public-key/foo/bar#deadbeef][Heading A]]"
+
+;; (hyperdrive-test-org-link-roundtrip
+;; "* Heading A
+;; :PROPERTIES:
+;; :CUSTOM_ID: custom-id
+;; :END:
+;; <|>
+;; * Heading B")
+;; "[[hyper://public-key/foo/bar#custom-id][Heading A]]"
+
+
+;; "hyper://public-key/foo/bar#deadbeef"
- [nongnu] elpa/hyperdrive dafc7f1b93 72/82: Fix: (hyperdrive--org-link-goto) Use org-link-search, (continued)
- [nongnu] elpa/hyperdrive dafc7f1b93 72/82: Fix: (hyperdrive--org-link-goto) Use org-link-search, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive c1932fb6fd 74/82: Change: (hyperdrive--org-open-at-point) Include target, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 20dd9efc70 76/82: Tidy, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 0a875bef41 78/82: Fix: Docstring, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive fe3c0c374a 79/82: Tests: Add relative/absolute link parsing tests, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 7d06ffd037 80/82: Meta: Update .gitignore, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 7826c10faa 81/82: Merge branch 'wip/org-heading-links', ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 903847d50e 82/82: Tidy: Docstrings, comments, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 670ae8050f 03/82: WIP: Add link tests, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 9b3b215444 04/82: WIP, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 62c487448f 06/82: WIP,
ELPA Syncer <=
- [nongnu] elpa/hyperdrive 28d4b1a6d6 08/82: Add: (hyperdrive-equal-p, -entry-hyperdrive-equal-p), ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive bdf9a94b49 09/82: WIP, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 96d458868b 10/82: WIP, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 8a453f0eb4 14/82: WIP: All tests passing! (so far), ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 82305e861b 15/82: WIP: Have macro define narrower tests, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive a72cf3820d 17/82: WIP: All tests pass, etc., ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive a040fa2686 18/82: WIP, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 5726648878 21/82: Change: (hyperdrive--format-entry-url) Docstring, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 7d3662f842 25/82: Comment: Add TODO, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 016582b1a2 26/82: Tidy: (--org-insert-link-after-advice) Bind search-option at top, ELPA Syncer, 2023/09/25