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

[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"



reply via email to

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