[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/hyperdrive a72cf3820d 17/82: WIP: All tests pass, etc.
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/hyperdrive a72cf3820d 17/82: WIP: All tests pass, etc. |
Date: |
Mon, 25 Sep 2023 19:00:50 -0400 (EDT) |
branch: elpa/hyperdrive
commit a72cf3820d140f4507ce98ce5f9cddc3ae7fd881
Author: Adam Porter <adam@alphapapa.net>
Commit: Adam Porter <adam@alphapapa.net>
WIP: All tests pass, etc.
---
hyperdrive-lib.el | 1 +
hyperdrive-org.el | 72 +++++++++++++++++--------------------
tests/test-hyperdrive-org-link.el | 76 +++++++++++++++++++++++++++++++++++++++
3 files changed, 109 insertions(+), 40 deletions(-)
diff --git a/hyperdrive-lib.el b/hyperdrive-lib.el
index 8edcced9b2..7294606306 100644
--- a/hyperdrive-lib.el
+++ b/hyperdrive-lib.el
@@ -955,6 +955,7 @@ number in URL.
Note that, if HOST-FORMAT includes values other than `public-key'
and `domain', the resulting URL may not be a valid hyperdrive
URL."
+ ;; FIXME: Update docstring to explain that the URL parts are URL-encoded
when appropriate.
;; NOTE: Entries may have only a domain, not a public key yet, so we
;; include `domain' in HOST-FORMAT's default value. The public key
;; will be filled in later.
diff --git a/hyperdrive-org.el b/hyperdrive-org.el
index dcc38307e4..ac64f974a0 100644
--- a/hyperdrive-org.el
+++ b/hyperdrive-org.el
@@ -36,6 +36,12 @@
(declare-function hyperdrive-open-url "hyperdrive")
(declare-function hyperdrive-dir--entry-at-point "hyperdrive-dir")
+(defcustom hyperdrive-org-link-full-url nil
+ "Use full \"hyper://\" URLs when storing and inserting links in Org files.
+Otherwise, follow setting in `org-link-file-path-type'."
+ :type 'boolean
+ :group 'hyperdrive)
+
;; TODO: Determine whether it's really necessary to autoload these two
functions.
;;;###autoload
@@ -156,11 +162,6 @@ 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)))))))
-(defcustom hyperdrive-org-link-full-url nil
- "Use full \"hyper://\" URLs when storing and inserting links in Org files.
-Otherwise, follow setting in `org-link-file-path-type'."
- :type 'boolean)
-
(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)
@@ -173,8 +174,7 @@ Otherwise, follow setting in `org-link-file-path-type'."
(cond (hyperdrive-org-link-full-url
;; User wants only full "hyper://" URLs.
(when (alist-get 'target (hyperdrive-entry-etc target-entry))
- (setf fragment-prefix (concat "#" (url-hexify-string "::")))
- (cl-callf url-hexify-string (alist-get 'target
(hyperdrive-entry-etc target-entry))))
+ (setf fragment-prefix (concat "#" (url-hexify-string "::"))))
(setf destination (hyperdrive--format-entry-url
target-entry :fragment-prefix fragment-prefix
:with-path with-path
@@ -182,42 +182,34 @@ Otherwise, follow setting in `org-link-file-path-type'."
((hyperdrive-entry-equal-p hyperdrive-current-entry target-entry)
;; Link points to same file on same hyperdrive: make link
;; relative.
- (setf with-protocol nil
- host-format nil
- with-path (if (alist-get 'target (hyperdrive-entry-etc
target-entry))
- nil t)
- destination (concat "./"
- (file-relative-name
- (hyperdrive-entry-path target-entry)
- (file-name-directory
(hyperdrive-entry-path target-entry)))))
- (pcase org-link-file-path-type
- ((or 'absolute 'noabbrev)
- ;; These two options are the same for our purposes,
- ;; because hyperdrives have no home directory.
- (setf destination (hyperdrive-entry-path target-entry)))
- ('adaptive
- (setf destination
- (if (string-prefix-p (file-name-parent-directory
- (hyperdrive-entry-path
hyperdrive-current-entry))
- (hyperdrive-entry-path
target-entry))
- ;; Link points to file in same directory tree: use
relative link.
- (concat "./"
- (file-relative-name
- (hyperdrive-entry-path target-entry)
- (file-name-directory (hyperdrive-entry-path
target-entry))))
- (hyperdrive-entry-path target-entry))))
- ('relative
- (setf destination
- (concat "./"
- (file-relative-name
- (hyperdrive-entry-path target-entry)
- (file-name-directory (hyperdrive-entry-path
target-entry))))))))
+ (setf destination
+ (or (alist-get 'target (hyperdrive-entry-etc target-entry))
+ (pcase org-link-file-path-type
+ ((or 'absolute 'noabbrev)
+ ;; These two options are the same for our purposes,
+ ;; because hyperdrives have no home directory.
+ (setf destination (hyperdrive-entry-path
target-entry)))
+ ('adaptive
+ (setf destination
+ (if (string-prefix-p
(file-name-parent-directory
+ (hyperdrive-entry-path
hyperdrive-current-entry))
+ (hyperdrive-entry-path
target-entry))
+ ;; Link points to file in same directory
tree: use relative link.
+ (concat "./"
+ (file-relative-name
+ (hyperdrive-entry-path
target-entry)
+ (file-name-directory
(hyperdrive-entry-path target-entry))))
+ (hyperdrive-entry-path target-entry))))
+ ('relative
+ (setf destination
+ (concat "./"
+ (file-relative-name
+ (hyperdrive-entry-path target-entry)
+ (file-name-directory
(hyperdrive-entry-path target-entry))))))))))
((hyperdrive-entry-hyperdrive-equal-p hyperdrive-current-entry
target-entry)
;; Link points to same hyperdrive as the file the link is in:
;; make link relative.
- (setf with-protocol nil
- host-format nil
- destination (concat "./"
+ (setf destination (concat "./"
(file-relative-name
(hyperdrive-entry-path target-entry)
(file-name-directory
(hyperdrive-entry-path target-entry))))))
diff --git a/tests/test-hyperdrive-org-link.el
b/tests/test-hyperdrive-org-link.el
index 2353e69a12..80dc7dd49c 100644
--- a/tests/test-hyperdrive-org-link.el
+++ b/tests/test-hyperdrive-org-link.el
@@ -114,6 +114,9 @@
body-forms)))
`(progn ,@(nreverse body-forms))))
+;; TODO: We'll need at least one test for inserting a link into an Org
+;; file that is /not/ in a hyperdrive.
+
(hyperdrive-test-org-link-deftest same-drive-same-file-before-heading
:store-body "<|>
* Heading A
@@ -151,6 +154,79 @@
(hyperdrive-org-link-full-url t))
:result "[[hyper://deadbeef/foo/bar%20quux.org]]")))
+(hyperdrive-test-org-link-deftest
same-drive-same-file-on-heading-with-custom-id
+ :store-body "
+* Heading A
+:PROPERTIES:
+:CUSTOM_ID: baz zot
+:END:
+<|>
+* Heading B"
+ :store-from '("deadbeef" . "/foo/bar quux.org")
+ :insert-into '("deadbeef" . "/foo/bar quux.org")
+ :results (( :let ((org-link-file-path-type 'relative)
+ (hyperdrive-org-link-full-url nil))
+ :result "[[#baz zot]]")
+ ( :let ((org-link-file-path-type 'relative)
+ (hyperdrive-org-link-full-url t))
+ :result
"[[hyper://deadbeef/foo/bar%20quux.org#%3A%3A%23baz%20zot]]")
+
+ ( :let ((org-link-file-path-type 'absolute)
+ (hyperdrive-org-link-full-url nil))
+ :result "[[#baz zot]]")
+ ( :let ((org-link-file-path-type 'absolute)
+ (hyperdrive-org-link-full-url t))
+ :result
"[[hyper://deadbeef/foo/bar%20quux.org#%3A%3A%23baz%20zot]]")
+
+ ( :let ((org-link-file-path-type 'noabbrev)
+ (hyperdrive-org-link-full-url nil))
+ :result "[[#baz zot]]")
+ ( :let ((org-link-file-path-type 'noabbrev)
+ (hyperdrive-org-link-full-url t))
+ :result
"[[hyper://deadbeef/foo/bar%20quux.org#%3A%3A%23baz%20zot]]")
+
+ ( :let ((org-link-file-path-type 'adaptive)
+ (hyperdrive-org-link-full-url nil))
+ :result "[[#baz zot]]")
+ ( :let ((org-link-file-path-type 'adaptive)
+ (hyperdrive-org-link-full-url t))
+ :result
"[[hyper://deadbeef/foo/bar%20quux.org#%3A%3A%23baz%20zot]]")))
+
+(hyperdrive-test-org-link-deftest same-drive-same-file-on-heading-no-custom-id
+ :store-body "
+* Heading A
+<|>
+* Heading B"
+ :store-from '("deadbeef" . "/foo/bar quux.org")
+ :insert-into '("deadbeef" . "/foo/bar quux.org")
+ :results (( :let ((org-link-file-path-type 'relative)
+ (hyperdrive-org-link-full-url nil))
+ :result "[[*Heading A]]")
+ ( :let ((org-link-file-path-type 'relative)
+ (hyperdrive-org-link-full-url t))
+ :result
"[[hyper://deadbeef/foo/bar%20quux.org#%3A%3A%2AHeading%20A]]")
+
+ ( :let ((org-link-file-path-type 'absolute)
+ (hyperdrive-org-link-full-url nil))
+ :result "[[*Heading A]]")
+ ( :let ((org-link-file-path-type 'absolute)
+ (hyperdrive-org-link-full-url t))
+ :result
"[[hyper://deadbeef/foo/bar%20quux.org#%3A%3A%2AHeading%20A]]")
+
+ ( :let ((org-link-file-path-type 'noabbrev)
+ (hyperdrive-org-link-full-url nil))
+ :result "[[*Heading A]]")
+ ( :let ((org-link-file-path-type 'noabbrev)
+ (hyperdrive-org-link-full-url t))
+ :result
"[[hyper://deadbeef/foo/bar%20quux.org#%3A%3A%2AHeading%20A]]")
+
+ ( :let ((org-link-file-path-type 'adaptive)
+ (hyperdrive-org-link-full-url nil))
+ :result "[[*Heading A]]")
+ ( :let ((org-link-file-path-type 'adaptive)
+ (hyperdrive-org-link-full-url t))
+ :result
"[[hyper://deadbeef/foo/bar%20quux.org#%3A%3A%2AHeading%20A]]")))
+
;; * ~CUSTOM_ID~ :: e.g.
;; ~hyper://deadbeef/foo/bar%20quux.org#%3A%3A%23baz%20zot~, which
decodes to ~hyper://deadbeef/foo/bar quux.org#::#baz zot~
- [nongnu] elpa/hyperdrive 7826c10faa 81/82: Merge branch 'wip/org-heading-links', (continued)
- [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, 2023/09/25
- [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 <=
- [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
- [nongnu] elpa/hyperdrive 96129bb5db 27/82: Tidy: Whitespace, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 80ec05b3b5 28/82: Add: (--org-normalize-link) Gut --org-insert-link-after-advice, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 89fa2fe4a9 30/82: Tidy: (hyperdrive--org-normalize-link) Deduplicate full URL codepath, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive a4b2c538df 31/82: Tidy: (hyperdrive--org-normalize-link) Use if instead of cond, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 36a18f326e 34/82: Change: (--org-normalize-link) Return early with search option, ELPA Syncer, 2023/09/25
- [nongnu] elpa/hyperdrive 91c3478593 36/82: Change: (hyperdrive--org-normalize-link) Use file-name-directory, ELPA Syncer, 2023/09/25