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

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

[nongnu] elpa/hyperdrive 89fa2fe4a9 30/82: Tidy: (hyperdrive--org-normal


From: ELPA Syncer
Subject: [nongnu] elpa/hyperdrive 89fa2fe4a9 30/82: Tidy: (hyperdrive--org-normalize-link) Deduplicate full URL codepath
Date: Mon, 25 Sep 2023 19:00:52 -0400 (EDT)

branch: elpa/hyperdrive
commit 89fa2fe4a961bcf3453076435d7734ab1e990ec2
Author: Joseph Turner <joseph@ushin.org>
Commit: Joseph Turner <joseph@ushin.org>

    Tidy: (hyperdrive--org-normalize-link) Deduplicate full URL codepath
---
 hyperdrive-org.el | 31 ++++++++++++++-----------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/hyperdrive-org.el b/hyperdrive-org.el
index bcd3ad719e..54aa7b0925 100644
--- a/hyperdrive-org.el
+++ b/hyperdrive-org.el
@@ -178,7 +178,7 @@ the current location."
                      (org-element-property :end link-element))
       (insert (org-link-make-string (hyperdrive--org-normalize-link 
link-element))))))
 
-(defun hyperdrive--org-normalize-link (link-element)
+(cl-defun hyperdrive--org-normalize-link (link-element)
   "Return normalized copy of \"hyper://\" LINK-ELEMENT.
 Respects `hyperdrive-org-link-full-url' and `org-link-file-path-type'."
   (cl-assert hyperdrive-current-entry)
@@ -187,15 +187,18 @@ Respects `hyperdrive-org-link-full-url' and 
`org-link-file-path-type'."
          (search-option (alist-get 'target (hyperdrive-entry-etc 
target-entry)))
          (host-format '(public-key)) (with-path t) (with-protocol t)
          fragment-prefix destination)
-    (cond (hyperdrive-org-link-full-url
-           ;; User wants only full "hyper://" URLs.
-           (when search-option
-             (setf fragment-prefix (concat "#" (url-hexify-string "::"))))
-           (setf destination (hyperdrive--format-entry-url
-                              target-entry :fragment-prefix fragment-prefix
-                              :with-path with-path
-                              :with-protocol with-protocol :host-format 
host-format)))
-          ((hyperdrive-entry-equal-p hyperdrive-current-entry target-entry)
+    (when (or hyperdrive-org-link-full-url
+              (not (hyperdrive-entry-hyperdrive-equal-p
+                    hyperdrive-current-entry target-entry)))
+      ;; Full "hyper://" URL
+      (when search-option
+        (setf fragment-prefix (concat "#" (url-hexify-string "::"))))
+      (cl-return-from hyperdrive--org-normalize-link
+        (hyperdrive--format-entry-url
+         target-entry :fragment-prefix fragment-prefix
+         :with-path with-path
+         :with-protocol with-protocol :host-format host-format)))
+    (cond ((hyperdrive-entry-equal-p hyperdrive-current-entry target-entry)
            ;; Link points to same file on same hyperdrive: make link
            ;; relative.
            (setf destination
@@ -229,13 +232,7 @@ Respects `hyperdrive-org-link-full-url' and 
`org-link-file-path-type'."
            (setf destination (concat "./"
                                      (file-relative-name
                                       (hyperdrive-entry-path target-entry)
-                                      (file-name-directory 
(hyperdrive-entry-path target-entry))))))
-          (t
-           (setf fragment-prefix (concat "#" (url-hexify-string "::")))
-           (setf destination (hyperdrive--format-entry-url
-                              target-entry :fragment-prefix fragment-prefix
-                              :with-path with-path
-                              :with-protocol with-protocol :host-format 
host-format))))
+                                      (file-name-directory 
(hyperdrive-entry-path target-entry)))))))
     destination))
 
 ;;;###autoload



reply via email to

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