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

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

[nongnu] elpa/hyperdrive 109452e780 09/14: Merge branch 'view-file'


From: ELPA Syncer
Subject: [nongnu] elpa/hyperdrive 109452e780 09/14: Merge branch 'view-file'
Date: Wed, 6 Sep 2023 04:00:03 -0400 (EDT)

branch: elpa/hyperdrive
commit 109452e7806a5583d81010d9c96a052ef4be56cc
Merge: 466cbdd551 dff584bbe9
Author: Joseph Turner <joseph@ushin.org>
Commit: Joseph Turner <joseph@ushin.org>

    Merge branch 'view-file'
---
 CHANGELOG.org             |  1 +
 doc/hyperdrive-manual.org | 15 +++++++++++----
 hyperdrive-dir.el         | 10 ++++++++++
 hyperdrive-history.el     | 23 +++++++++++++++++++++++
 hyperdrive-lib.el         | 15 ++++++++++-----
 hyperdrive.el             | 12 ++++++++++++
 6 files changed, 67 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index 1aa7066a01..4960fd0dea 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -10,6 +10,7 @@ This project adheres to 
[[https://semver.org/spec/v2.0.0.html][Semantic Versioni
 - ~yank-media~ support (on Emacs 29 or later)
 - ~save-some-buffers~ integration
 - ~info-look~ integration
+- ~view-mode~ integration
 - Org-mode link completion
 - directory view sorting by column
 
diff --git a/doc/hyperdrive-manual.org b/doc/hyperdrive-manual.org
index 41065a5b75..3140c4344f 100644
--- a/doc/hyperdrive-manual.org
+++ b/doc/hyperdrive-manual.org
@@ -151,11 +151,14 @@ seed cannot be changed.
 ** Open a hyperdrive
 #+findex: hyperdrive-open-url
 #+findex: hyperdrive-find-file
+#+findex: hyperdrive-view-file
 
-You can open a hyperdrive folder or file by pasting in a ~hyper://~ URL
-after ~M-x hyperdrive-open-url~. Alternatively, ~M-x hyperdrive-find-file~
-remembers hyperdrives you have already created or visited. It will
-prompt you for a known hyperdrive and a path inside it.
+You can open a hyperdrive folder or file by pasting in a ~hyper://~
+URL after ~M-x hyperdrive-open-url~. Alternatively, ~M-x
+hyperdrive-find-file~ remembers hyperdrives you have already created
+or visited. It will prompt you for a known hyperdrive and a path
+inside it. ~hyperdrive-view-file~ is like ~hyperdrive-find-file~, but
+it opens the file in [[info:emacs#View Mode][view-mode]].
 
 *** Directory view
 
@@ -167,6 +170,8 @@ default:
 - ~n~ and ~p~ move between entries
 #+kindex: hyperdrive-dir-find-file
 - ~RET~ opens file or directory at point
+#+kindex: hyperdrive-dir-view-file
+- ~v~ opens file or directory at point in [[info:emacs#View Mode][view-mode]].
 #+kindex: hyperdrive-up
 - ~^~ goes up to the parent directory
 #+kindex: revert-buffer
@@ -287,6 +292,8 @@ default:
 
 #+kindex: hyperdrive-history-find-file
 - ~RET~ opens the file at the start of the range at point
+#+kindex: hyperdrive-history-view-file
+- ~v~ opens the file at the start of the range at point in [[info:emacs#View 
Mode][view-mode]]
 #+kindex: hyperdrive-history-copy-url
 - ~w~ copies the URL of the file at the start of the range at point
 #+kindex: hyperdrive-history-download-file
diff --git a/hyperdrive-dir.el b/hyperdrive-dir.el
index ce2ba3351b..840597f83e 100644
--- a/hyperdrive-dir.el
+++ b/hyperdrive-dir.el
@@ -199,6 +199,7 @@ With point on header, returns directory entry."
   :doc "Local keymap for `hyperdrive-dir-mode' buffers."
   "RET" #'hyperdrive-dir-find-file
   "f"   #'hyperdrive-find-file ;; Alternatively, define new function which 
fills in name of entry at point.
+  "v"   #'hyperdrive-dir-view-file
   "j"   #'imenu
   "w"   #'hyperdrive-dir-copy-url
   "d"   #'hyperdrive-dir-download-file
@@ -229,6 +230,15 @@ Interactively, visit file or directory at point in
   (interactive (list (hyperdrive-dir--entry-at-point)))
   (hyperdrive-open entry))
 
+(declare-function hyperdrive-view-file "hyperdrive")
+(defun hyperdrive-dir-view-file (entry)
+  "Open hyperdrive ENTRY at point in `view-mode'.
+Interactively, opens file or directory at point in
+`hyperdrive-dir' buffer."
+  (declare (modes hyperdrive-dir-mode))
+  (interactive (list (hyperdrive-dir--entry-at-point)))
+  (hyperdrive-view-file entry))
+
 (declare-function hyperdrive-copy-url "hyperdrive")
 
 (defun hyperdrive-dir-copy-url (entry)
diff --git a/hyperdrive-history.el b/hyperdrive-history.el
index 08372a033f..27a04e2d38 100644
--- a/hyperdrive-history.el
+++ b/hyperdrive-history.el
@@ -119,6 +119,7 @@ and ENTRY's version are nil."
   :parent  hyperdrive-ewoc-mode-map
   :doc "Local keymap for `hyperdrive-history-mode' buffers."
   "RET" #'hyperdrive-history-find-file
+  "v"   #'hyperdrive-history-view-file
   "="   #'hyperdrive-history-diff
   "w"   #'hyperdrive-history-copy-url
   "d"   #'hyperdrive-history-download-file)
@@ -263,6 +264,28 @@ buffer."
      ;; TODO: Design options
      (hyperdrive-message "File not known to exist. What do you want to do?"))))
 
+(declare-function hyperdrive-view-file "hyperdrive")
+(defun hyperdrive-history-view-file (range-entry)
+  "Open hyperdrive entry in RANGE-ENTRY at point in `view-mode'.
+When entry does not exist or is not known to exist, does nothing
+and returns nil.
+
+Interactively, visit entry at point in `hyperdrive-history'
+buffer."
+  (declare (modes hyperdrive-history-mode))
+  (interactive (list (hyperdrive-history-range-entry-at-point)))
+  (pcase-exhaustive (hyperdrive-range-entry-exists-p range-entry)
+    ('t
+     ;; Known to exist: open it.
+     (hyperdrive-view-file (cdr range-entry)))
+    ('nil
+     ;; Known to not exist: warn user.
+     (hyperdrive-user-error "File does not exist!"))
+    ('unknown
+     ;; Not known to exist: prompt user
+     ;; TODO: Design options
+     (hyperdrive-message "File not known to exist. What do you want to do?"))))
+
 (declare-function hyperdrive-copy-url "hyperdrive")
 
 (defun hyperdrive-history-copy-url (range-entry)
diff --git a/hyperdrive-lib.el b/hyperdrive-lib.el
index 03114f3f71..211e8f1cb0 100644
--- a/hyperdrive-lib.el
+++ b/hyperdrive-lib.el
@@ -393,11 +393,13 @@ When VERSION is nil, return latest version of ENTRY."
          (_ (signal (car err) (cdr err))))))))
 
 (declare-function hyperdrive-history "hyperdrive-history")
-(cl-defun hyperdrive-open (entry &key then recurse)
+(cl-defun hyperdrive-open (entry &key then recurse (createp t))
   "Open hyperdrive ENTRY.
 If RECURSE, proceed up the directory hierarchy if given path is
-not found.  THEN may be a function to pass to the handler to call
-in the buffer opened by the handler."
+not found. THEN is a function to pass to the handler which will
+be called with no arguments in the buffer opened by the handler.
+When a writable ENTRY is not found and CREATEP is non-nil, create
+a new buffer for ENTRY."
   (declare (indent defun))
   ;; TODO: Add `find-file'-like interface. See 
<https://todo.sr.ht/~ushin/ushin/16>
   ;; TODO: When possible, check whether drive is writable with a HEAD request, 
and set writablep in the
@@ -446,7 +448,8 @@ in the buffer opened by the handler."
                      ;; Root directory not found: Drive has not been
                      ;; loaded locally, and no peers are found seeding it.
                      (hyperdrive-message "No peers found for %s" 
(hyperdrive-entry-url entry)))
-                    ((and (not (hyperdrive--entry-directory-p entry))
+                    ((and createp
+                          (not (hyperdrive--entry-directory-p entry))
                           (hyperdrive-writablep hyperdrive)
                           (not (hyperdrive-entry-version entry)))
                      ;; Entry is a writable file: create a new buffer
@@ -529,7 +532,9 @@ The following ENTRY slots are filled:
 
 The following ENTRY hyperdrive slots are filled:
 - public-key
-- domains (merged with current persisted value)"
+- domains (merged with current persisted value)
+
+Returns filled ENTRY."
   (pcase-let* (((cl-struct hyperdrive-entry hyperdrive) entry)
                ((map link content-length content-type etag last-modified) 
headers)
                ;; If URL hostname was a DNSLink domain, entry doesn't yet have 
a public-key slot.
diff --git a/hyperdrive.el b/hyperdrive.el
index 214b2e9594..4aa808f79b 100644
--- a/hyperdrive.el
+++ b/hyperdrive.el
@@ -349,6 +349,18 @@ for more information.  See `hyperdrive-read-entry' and
   (interactive (list (hyperdrive-read-entry :force-prompt current-prefix-arg)))
   (hyperdrive-open entry))
 
+;;;###autoload
+(defun hyperdrive-view-file (entry)
+  "View ENTRY in `view-mode', returning to previous buffer when done.
+Interactively, prompts for known hyperdrive and path.
+
+With universal prefix argument \\[universal-argument], prompts
+for more information.  See `hyperdrive-read-entry' and
+`hyperdrive-complete-hyperdrive'."
+  (interactive (list (hyperdrive-read-entry :force-prompt current-prefix-arg)))
+  (hyperdrive-open entry
+    :createp nil :then (lambda () (view-buffer (current-buffer)))))
+
 ;;;###autoload
 (defun hyperdrive-open-url (url)
   "Open hyperdrive URL."



reply via email to

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