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

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

[nongnu] elpa/hyperdrive b2afbfaa60 046/102: Change: Replace -entry-desc


From: ELPA Syncer
Subject: [nongnu] elpa/hyperdrive b2afbfaa60 046/102: Change: Replace -entry-description with --format-entry, etc.
Date: Wed, 29 Nov 2023 04:00:52 -0500 (EST)

branch: elpa/hyperdrive
commit b2afbfaa6042eaf055970e5f5f7ea1661357096d
Author: Adam Porter <adam@alphapapa.net>
Commit: Joseph Turner <joseph@ushin.org>

    Change: Replace -entry-description with --format-entry, etc.
---
 hyperdrive-diff.el    | 10 ++++---
 hyperdrive-dir.el     |  6 ++--
 hyperdrive-history.el |  2 +-
 hyperdrive-lib.el     | 81 ++++++++++++++++++++-------------------------------
 hyperdrive-org.el     |  4 +--
 hyperdrive-vars.el    | 15 ++++++++--
 hyperdrive.el         | 21 ++++++-------
 7 files changed, 68 insertions(+), 71 deletions(-)

diff --git a/hyperdrive-diff.el b/hyperdrive-diff.el
index ed4954b916..05c2440ba8 100644
--- a/hyperdrive-diff.el
+++ b/hyperdrive-diff.el
@@ -71,9 +71,11 @@ This function is intended to diff files, not directories."
                             (unless (or old-response new-response)
                               (hyperdrive-error "Files non-existent"))
                             (let ((old-buffer (generate-new-buffer
-                                               (hyperdrive-entry-description 
old-entry)))
+                                               (hyperdrive--format-entry
+                                                old-entry 
hyperdrive-buffer-name-format)))
                                   (new-buffer (generate-new-buffer
-                                               (hyperdrive-entry-description 
new-entry)))
+                                               (hyperdrive--format-entry
+                                                new-entry 
hyperdrive-buffer-name-format)))
                                   ;; TODO: Improve diff buffer name.
                                   (diff-buffer (get-buffer-create 
"*hyperdrive-diff*")))
                               (when old-response
@@ -119,8 +121,8 @@ This function is intended to diff files, not directories."
         (insert (format "No difference between entries:
 %s
 %s"
-                        (hyperdrive-entry-description (car 
hyperdrive-diff-entries))
-                        (hyperdrive-entry-description (cdr 
hyperdrive-diff-entries)))))
+                        (hyperdrive--format-entry (car 
hyperdrive-diff-entries))
+                        (hyperdrive--format-entry (cdr 
hyperdrive-diff-entries)))))
       (goto-char (point-max))
       (forward-line -1)
       (delete-region (point) (point-max)))))
diff --git a/hyperdrive-dir.el b/hyperdrive-dir.el
index 4074f3a008..706f699e0a 100644
--- a/hyperdrive-dir.el
+++ b/hyperdrive-dir.el
@@ -63,7 +63,8 @@ If THEN, call it in the directory buffer with no arguments."
                   ;; of this function (e.g. so it will be available if
                   ;; the user loads a non-directory file directly).
                   (hyperdrive-fill-metadata hyperdrive)
-                  (hyperdrive-dir-column-headers (hyperdrive-entry-description 
directory-entry))))
+                  (hyperdrive-dir-column-headers
+                   (hyperdrive--format-entry directory-entry))))
                (num-entries (length entries)) (num-filled 0)
               ;; (debug-start-time (current-time))
                (metadata-queue) (ewoc) (prev-entry) (prev-point))
@@ -344,7 +345,8 @@ DIRECTORY-SORT should be a valid value of
       (dolist (entry (hyperdrive-sort-entries entries))
         (ewoc-enter-last hyperdrive-ewoc entry))
       (ewoc-set-hf hyperdrive-ewoc
-                   (hyperdrive-dir-column-headers 
(hyperdrive-entry-description hyperdrive-current-entry))
+                   (hyperdrive-dir-column-headers
+                    (hyperdrive--format-entry hyperdrive-current-entry))
                    ""))))
 
 ;;;; Imenu support
diff --git a/hyperdrive-history.el b/hyperdrive-history.el
index 4ff74e2ee9..8231acd2f2 100644
--- a/hyperdrive-history.el
+++ b/hyperdrive-history.el
@@ -179,7 +179,7 @@ prefix argument \\[universal-argument], prompt for ENTRY."
                                  :version (car range))))
                         ;; Display in reverse chronological order
                         (nreverse (hyperdrive-entry-version-ranges-no-gaps 
entry))))
-               (main-header (hyperdrive-entry-description entry :with-version 
nil))
+               (main-header (hyperdrive--format-entry entry "[%H] %p"))
                (header (concat main-header "\n"
                                (format "%7s  %19s  %6s  %s"
                                        (propertize "Exists" 'face 
'hyperdrive-column-header)
diff --git a/hyperdrive-lib.el b/hyperdrive-lib.el
index e0f7486246..d1fdbc0774 100644
--- a/hyperdrive-lib.el
+++ b/hyperdrive-lib.el
@@ -557,7 +557,8 @@ echo area when the request for the file is made."
                          ;; alert the user that the entry no longer exists.
                          (progn
                            (switch-to-buffer buffer)
-                           (hyperdrive-message "Entry no longer exists!  %s" 
(hyperdrive-entry-description entry)))
+                           (hyperdrive-message "Entry no longer exists!  %s"
+                                               (hyperdrive--format-entry 
entry)))
                        ;; Make and switch to new buffer.
                        (switch-to-buffer (hyperdrive--get-buffer-create 
entry))))
                     (t
@@ -916,28 +917,6 @@ Call ELSE if request fails."
   (hyperdrive--write (hyperdrive-entry-url entry)
     :body body :then then :else else :queue queue))
 
-(cl-defun hyperdrive-entry-description (entry &key (format-path 'path) 
(with-version t))
-  "Return description for ENTRY.
-When ENTRY has a non-nil VERSION slot, include it.  Returned
-string looks like:
-
-  FORMAT-PATH [HOST] (version:VERSION)
-
-When FORMAT-PATH is `path', use full path to entry.  When
-FORMAT-PATH is `name', use only last part of path, as in
-`file-name-non-directory'.
-
-When WITH-VERSION or ENTRY's version is nil, omit (version:VERSION)."
-  (pcase-let* (((cl-struct hyperdrive-entry hyperdrive version path name) 
entry)
-               (handle (hyperdrive--format-host hyperdrive :with-label t)))
-    (propertize (concat (format "[%s] " handle)
-                        (pcase format-path
-                          ('path path)
-                          ('name name))
-                        (when (and version with-version)
-                          (format " (version:%s)" version)))
-                'help-echo (hyperdrive-entry-url entry))))
-
 (cl-defun hyperdrive--format-entry-url
     (entry &key (host-format '(public-key domain))
            (with-path t) (with-protocol t) (with-help-echo t)
@@ -1371,7 +1350,7 @@ Affected by option `hyperdrive-reuse-buffers', which see."
   ;; TODO: This function is a workaround for bug#65797
   (lambda (buffer) (hyperdrive--buffer-visiting-entry-p buffer entry)))
 
-(defun hyperdrive--format-entry (entry format)
+(cl-defun hyperdrive--format-entry (entry &optional (format 
hyperdrive-default-entry-format))
   "Return ENTRY formatted according to FORMAT.
 FORMAT may be a format string like the value of
 `hyperdrive-buffer-name-format', which see."
@@ -1379,32 +1358,34 @@ FORMAT may be a format string like the value of
                ((cl-struct hyperdrive domains public-key petname seed
                            (metadata (map ('name nickname))))
                 hyperdrive))
-    (format-spec format
-                 ;; TODO(deprecate-28): Use lambdas in each specifier.
-                 `((?n . ,name)
-                   (?p . ,path)
-                   (?v . ,(if version
-                              (format hyperdrive-entry-version-format version)
-                            ""))
-                   (?D . ,(if domains
-                              (format hyperdrive-entry-domains-format
-                                      (string-join domains ","))
-                            ""))
-                   (?H . ,(hyperdrive--format-host
-                           hyperdrive :with-label t :with-faces nil))
-                   (?k . ,(format hyperdrive-entry-public-key-short-format
-                                  (concat (substring public-key 0 6) "…")))
-                   (?K . ,(format hyperdrive-entry-public-key-full-format
-                                  public-key))
-                   (?N . ,(if nickname
-                              (format hyperdrive-entry-nickname-format 
nickname)
-                            ""))
-                   (?P . ,(if petname
-                              (format hyperdrive-entry-petname-format petname)
-                            ""))
-                   (?S . ,(if seed
-                              (format hyperdrive-entry-seed-format seed)
-                            ""))))))
+    (propertize
+     (format-spec format
+                  ;; TODO(deprecate-28): Use lambdas in each specifier.
+                  `((?n . ,name)
+                    (?p . ,path)
+                    (?v . ,(if version
+                               (format hyperdrive-entry-version-format version)
+                             ""))
+                    (?D . ,(if domains
+                               (format hyperdrive-entry-domains-format
+                                       (string-join domains ","))
+                             ""))
+                    (?H . ,(hyperdrive--format-host
+                            hyperdrive :with-label t :with-faces nil))
+                    (?k . ,(format hyperdrive-entry-public-key-short-format
+                                   (concat (substring public-key 0 6) "…")))
+                    (?K . ,(format hyperdrive-entry-public-key-full-format
+                                   public-key))
+                    (?N . ,(if nickname
+                               (format hyperdrive-entry-nickname-format 
nickname)
+                             ""))
+                    (?P . ,(if petname
+                               (format hyperdrive-entry-petname-format petname)
+                             ""))
+                    (?S . ,(if seed
+                               (format hyperdrive-entry-seed-format seed)
+                             ""))))
+     'help-echo (hyperdrive-entry-url entry))))
 
 (defun hyperdrive--entry-directory-p (entry)
   "Return non-nil if ENTRY is a directory."
diff --git a/hyperdrive-org.el b/hyperdrive-org.el
index 235a729b20..dcf3130c69 100644
--- a/hyperdrive-org.el
+++ b/hyperdrive-org.el
@@ -64,10 +64,10 @@ which see."
                     (let ((entry (hyperdrive-dir--entry-at-point)))
                       `((type . "hyper://")
                         (link . ,(hyperdrive-entry-url entry))
-                        (description . ,(hyperdrive-entry-description 
entry)))))
+                        (description . ,(hyperdrive--format-entry entry)))))
                    (_ `((type . "hyper://")
                         (link . ,(hyperdrive-entry-url 
hyperdrive-current-entry))
-                        (description . ,(hyperdrive-entry-description 
hyperdrive-current-entry)))))))
+                        (description . ,(hyperdrive--format-entry 
hyperdrive-current-entry)))))))
       (org-link-store-props :type type :link link :description description)
       t)))
 
diff --git a/hyperdrive-vars.el b/hyperdrive-vars.el
index f5a5bb27b7..b90a36b6b5 100644
--- a/hyperdrive-vars.el
+++ b/hyperdrive-vars.el
@@ -171,8 +171,8 @@ an existing buffer at the same version, or make a new 
buffer."
   "Formatting of entries for buffer names, etc."
   :group 'hyperdrive)
 
-(defcustom hyperdrive-buffer-name-format "[%H] %n%v"
-  "Format string for buffer names.
+(defcustom hyperdrive-default-entry-format "[%H] %p%v"
+  "Format string for displaying entries.
 Specifiers:
 
 %n  Entry name
@@ -190,6 +190,17 @@ Specifiers:
 %S  Hyperdrive seed"
   :type 'string)
 
+(defvar hyperdrive-default-entry-format-without-version "[%H] %p"
+  "Format string for displaying entries without displaying the version.
+The format of the following specifiers can be configured using
+`hyperdrive-entry-format-alist', which see.")
+
+(defcustom hyperdrive-buffer-name-format "[%H] %n%v"
+  "Format string for buffer names.
+Specifiers are as in `hyperdrive-default-entry-format', which
+see."
+  :type 'string)
+
 (defcustom hyperdrive-entry-version-format " (version:%s)"
   "Format string for entry version.
 \"%s\" is replaced with the entry version.  Used in
diff --git a/hyperdrive.el b/hyperdrive.el
index 02b3eb6ddb..b19133bfe6 100644
--- a/hyperdrive.el
+++ b/hyperdrive.el
@@ -361,7 +361,7 @@ directory.  Otherwise, or with universal prefix argument
   (declare (indent defun))
   (interactive
    (let* ((entry (hyperdrive--context-entry :latest-version t))
-          (description (hyperdrive-entry-description entry))
+          (description (hyperdrive--format-entry entry))
           (buffer (current-buffer)))
      (when (and (hyperdrive--entry-directory-p entry)
                 (or (eq entry hyperdrive-current-entry)
@@ -450,11 +450,11 @@ use, see `hyperdrive-write'."
                      current-prefix-arg))
   (unless (or overwritep (not (hyperdrive-entry-at nil entry)))
     (unless (y-or-n-p
-            (format "File %s exists; overwrite?" (hyperdrive-entry-description 
entry)))
+            (format "File %s exists; overwrite?" (hyperdrive--format-entry 
entry)))
       (hyperdrive-user-error "Canceled"))
     (when-let ((buffers (match-buffers (hyperdrive--buffer-for-entry entry))))
       (unless (y-or-n-p
-              (format "A buffer is visiting %s; proceed?" 
(hyperdrive-entry-description entry)))
+              (format "A buffer is visiting %s; proceed?" 
(hyperdrive--format-entry entry)))
         (hyperdrive-user-error "Aborted"))
       ;; TODO: In BUFFERS, when user attempts to modify the buffer,
       ;; offer warning like "FILE has been modified in hyperdrive; are
@@ -557,7 +557,7 @@ it to `hyperdrive-open'."
   (if-let ((previous-entry (hyperdrive-entry-previous entry)))
       (hyperdrive-open previous-entry)
     (hyperdrive-message (substitute-command-keys "%s does not exist at version 
%s. Try \\[hyperdrive-history]")
-                        (hyperdrive-entry-description entry :with-version nil)
+                        (hyperdrive--format-entry entry "[%H] %p")
                         (1- (car (hyperdrive-entry-version-range entry))))))
 
 (defun hyperdrive-open-next-version (entry)
@@ -591,11 +591,12 @@ Nil VERSION means open the entry at its hyperdrive's 
latest version."
                  (list entry (hyperdrive-read-version
                               :hyperdrive (hyperdrive-entry-hyperdrive entry)
                               :prompt (format "Open «%s» at version (leave 
blank for latest version)"
-                                              (hyperdrive-entry-description 
entry :with-version nil))))))
+                                              (hyperdrive--format-entry 
entry))))))
   (if-let ((latest-entry (hyperdrive-entry-at version entry)))
       (hyperdrive-open latest-entry)
     (hyperdrive-message (substitute-command-keys "%s does not exist at version 
%s. Try \\[hyperdrive-history]")
-                        (hyperdrive-entry-description entry :with-version nil)
+                        (hyperdrive--format-entry
+                         entry hyperdrive-default-entry-format-without-version)
                         version)))
 
 ;;;; Bookmark support
@@ -609,7 +610,7 @@ Works in `hyperdrive-mode' and `hyperdrive-dir-mode' 
buffers."
   (let ((bookmark (bookmark-make-record-default 'no-file)))
     (setf (alist-get 'handler bookmark) #'hyperdrive-bookmark-handler
           (alist-get 'location bookmark) (hyperdrive-entry-url 
hyperdrive-current-entry))
-    (cons (format "hyperdrive: %s" (hyperdrive-entry-description 
hyperdrive-current-entry)) bookmark)))
+    (cons (format "hyperdrive: %s" (hyperdrive--format-entry 
hyperdrive-current-entry)) bookmark)))
 
 ;;;###autoload
 (defun hyperdrive-bookmark-handler (bookmark)
@@ -799,14 +800,14 @@ The return value of this function is the retrieval 
buffer."
           (if (< emacs-major-version 28)
               (read-multiple-choice
                (format "Hyperdrive file %s modified; kill anyway?"
-                       (hyperdrive-entry-description hyperdrive-current-entry))
+                       (hyperdrive--format-entry hyperdrive-current-entry))
                '((?y "yes" "kill buffer without saving")
                  (?n "no" "exit without doing anything")
                  (?s "save and then kill" "save the buffer and then kill it")))
             (with-suppressed-warnings ((free-vars use-short-answers))
               (compat-call read-multiple-choice
                            (format "Hyperdrive file %s modified; kill anyway?"
-                                   (hyperdrive-entry-description 
hyperdrive-current-entry))
+                                   (hyperdrive--format-entry 
hyperdrive-current-entry))
                            '((?y "yes" "kill buffer without saving")
                              (?n "no" "exit without doing anything")
                              (?s "save and then kill" "save the buffer and 
then kill it"))
@@ -962,7 +963,7 @@ The return value of this function is the retrieval buffer."
      :active hyperdrive-current-entry
      :label (if-let* ((entry hyperdrive-current-entry))
                 (format "Current: «%s»"
-                        (hyperdrive-entry-description entry))
+                        (hyperdrive--format-entry entry))
               "Current")
      ("Current Drive"
       :active hyperdrive-current-entry



reply via email to

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