[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 8ad0b816ed 6/6: Add three new user options for '
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 8ad0b816ed 6/6: Add three new user options for 'denote-sort-dired' |
Date: |
Thu, 1 Aug 2024 03:57:49 -0400 (EDT) |
branch: externals/denote
commit 8ad0b816ede166998fb73076b882b6526fa54f63
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Add three new user options for 'denote-sort-dired'
---
README.org | 46 +++++++++++++++++++++
denote-sort.el | 124 ++++++++++++++++++++++++++++++++++++++++++---------------
2 files changed, 138 insertions(+), 32 deletions(-)
diff --git a/README.org b/README.org
index 34397e3a44..25169aed1c 100644
--- a/README.org
+++ b/README.org
@@ -3431,6 +3431,52 @@ The resulting Dired listing is a regular Dired buffer,
unlike that of
The dynamic Org blocks that Denote defines to insert file contents
also use this feature ([[#h:f15fa143-5036-416f-9bff-1bcabbb03456][Org dynamic
block to insert file contents]]).
+** Configure what extra prompts ~denote-sort-dired~ issues
+:PROPERTIES:
+:CUSTOM_ID: h:a34228cb-484f-48fe-9cbc-8e41f313127b
+:END:
+
+[ Part of {{{development-version}}}. ]
+
+#+vindex: denote-sort-dired-extra-prompts
+By default, the ~denote-sort-dired~ command prompts for (i) a query to
+match file names, (ii) a file name component to sort by, and (iii)
+whether to reverse the sorting. Users can configure the latter two by
+modifying the user option ~denote-sort-dired-extra-prompts~.
+
+It accepts either a nil value or a list of symbols among ~sort-by-component~
+and ~reverse-sort~. The order those symbols appear in the list is
+significant, with the leftmost coming first.
+
+#+vindex: denote-sort-dired-default-sort-component
+#+vindex: denote-sort-dired-default-reverse-sort
+In case of a nil value, those extra prompts will not happen, meaning
+that ~denote-sort-dired~ will fall back to using
+~denote-sort-dired-default-sort-component~ and
+~denote-sort-dired-default-reverse-sort~.
+
+Here are some examples:
+
+#+begin_src emacs-lisp
+;; The default extra prompts...
+(setq denote-sort-dired-extra-prompts '(sort-by-component reverse-sort))
+
+;; When using `denote-sort-dired', ask whether to reverse the sort and
+;; then which file name component to sort by. These are always done
+;; after the prompt to search for files matching a regexp.
+(setq denote-sort-dired-extra-prompts '(reverse-sort sort-by-component))
+
+;; Do not prompt for a reverse sort. Just use the value of
+;; `denote-sort-dired-default-reverse-sort' (which is nil out-of-the-box).
+(setq denote-sort-dired-extra-prompts '(sort-by-component))
+
+;; Do not issue any extra prompts. Always sort by the `title' file
+;; name component and never do a reverse sort.
+(setq denote-sort-dired-extra-prompts nil)
+(setq denote-sort-dired-default-sort-component 'title)
+(setq denote-sort-dired-default-reverse-sort nil)
+#+end_src
+
** Define a sorting function per component
:PROPERTIES:
:CUSTOM_ID: h:c958e087-1d23-4a25-afdd-db7bf5606b4c
diff --git a/denote-sort.el b/denote-sort.el
index d52750583e..b3249bc9e6 100644
--- a/denote-sort.el
+++ b/denote-sort.el
@@ -66,6 +66,47 @@ the first argument is smaller than the second one."
:package-version '(denote . "3.1.0")
:group 'denote-sort)
+(defcustom denote-sort-dired-extra-prompts '(sort-by-component reverse-sort)
+ "Determine what `denote-sort-dired' prompts for beside a search query.
+This concerns the additional prompts issued by `denote-sort-dired' about
+whether to sort by a given file name component and to then reverse the
+sort.
+
+The value is a list of symbols, which can include the symbols
+`sort-by-component' and `reverse-sort'. The order is significant, with
+the leftmost symbol coming first.
+
+If the value is nil, skip all prompts. In this scenario, the sorting is
+done according to `denote-sort-dired-default-sort-component' and
+`denote-sort-dired-default-reverse-sort'."
+ :type '(radio (const :tag "Do not prompt for anything" nil)
+ (set :tag "Available prompts" :greedy t
+ (const :tag "Sort by file name component"
sort-by-component)
+ (const :tag "Reverse the sort" reverse-sort)))
+ :package-version '(denote . "3.1.0")
+ :group 'denote-sort)
+
+(defcustom denote-sort-dired-default-sort-component 'identifier
+ "Set the default file name component to sort by.
+This is used only if `denote-sort-dired-extra-prompts' omits the
+minibuffer prompt for which file name component to sort by."
+ :type '(radio
+ (const :tag "Sort by identifier (default)" identifier)
+ (const :tag "Sort by title" title)
+ (const :tag "Sort by keywords" keywords)
+ (const :tag "Sort by signature" signature))
+ :package-version '(denote . "3.1.0")
+ :group 'denote-sort)
+
+(defcustom denote-sort-dired-default-reverse-sort nil
+ "If non-nil, reverse the sorting order by default.
+This is used only if `denote-sort-dired-extra-prompts' omits the
+minibuffer prompt that asks for a reverse sort or not."
+ :type 'boolean
+ :package-version '(denote . "3.1.0")
+ :group 'denote-sort)
+
+
;; NOTE 2023-12-04: We can have compound sorting algorithms such as
;; title+signature, but I want to keep this simple for the time being.
;; Let us first hear from users to understand if there is a real need
@@ -178,48 +219,67 @@ With optional REVERSE as a non-nil value, reverse the
sort order."
(defvar-local denote-sort--dired-buffer nil
"Buffer object of current `denote-sort-dired'.")
+(defun denote-sort-dired--prompts ()
+ "Return list of prompts per `denote-sort-dired-extra-prompts'."
+ (let (sort-by-component reverse-sort)
+ (dolist (prompt denote-sort-dired-extra-prompts)
+ (pcase prompt
+ ('sort-by-component (setq sort-by-component
(denote-sort-component-prompt)))
+ ('reverse-sort (setq reverse-sort (y-or-n-p "Reverse sort? ")))))
+ (list sort-by-component reverse-sort)))
+
;;;###autoload
(defun denote-sort-dired (files-matching-regexp sort-by-component reverse)
- "Produce Dired dired-buffer with sorted files from variable
`denote-directory'.
-When called interactively, prompt for FILES-MATCHING-REGEXP,
-SORT-BY-COMPONENT, and REVERSE.
+ "Produce Dired buffer with sorted files from variable `denote-directory'.
+When called interactively, prompt for FILES-MATCHING-REGEXP and,
+depending on the value of the user option `denote-sort-dired-extra-prompts',
+also prompt for SORT-BY-COMPONENT and REVERSE.
1. FILES-MATCHING-REGEXP limits the list of Denote files to
those matching the provided regular expression.
-2. SORT-BY-COMPONENT sorts the files by their file name
- component (one among `denote-sort-components').
+2. SORT-BY-COMPONENT sorts the files by their file name component (one
+ among `denote-sort-components'). If it is nil, sorting is performed
+ according to the user option `denote-sort-dired-default-sort-component',
+ falling back to the identifier.
3. REVERSE is a boolean to reverse the order when it is a non-nil value.
+ If `denote-sort-dired-extra-prompts' is configured to skip this
+ prompt, then the sorting is done according to the user option
+ `denote-sort-dired-default-reverse-sort', falling back to
+ nil (i.e. no reverse sort).
-When called from Lisp, the arguments are a string, a keyword, and
-a non-nil value, respectively."
+When called from Lisp, the arguments are a string, a symbol among
+`denote-sort-components', and a non-nil value, respectively."
(interactive
- (list
- (denote-files-matching-regexp-prompt)
- (denote-sort-component-prompt)
- (y-or-n-p "Reverse sort? ")))
- (if-let ((default-directory (denote-directory))
- (files (denote-sort-get-directory-files files-matching-regexp
sort-by-component reverse))
- ;; NOTE 2023-12-04: Passing the FILES-MATCHING-REGEXP as
- ;; buffer-name produces an error if the regexp contains a
- ;; wildcard for a directory. I can reproduce this in emacs
- ;; -Q and am not sure if it is a bug. Anyway, I will report
- ;; it upstream, but even if it is fixed we cannot use it
- ;; for now (whatever fix will be available for Emacs 30+).
- (denote-sort-dired-buffer-name (format "Denote sort `%s' by `%s'"
files-matching-regexp sort-by-component))
- (buffer-name (format "Denote sort by `%s' at %s" sort-by-component
(format-time-string "%T"))))
- (let ((dired-buffer (dired (cons buffer-name (mapcar
#'file-relative-name files)))))
- (setq denote-sort--dired-buffer dired-buffer)
- (with-current-buffer dired-buffer
- (setq-local revert-buffer-function
- (lambda (&rest _)
- (kill-buffer dired-buffer)
- (denote-sort-dired files-matching-regexp
sort-by-component reverse))))
- ;; Because of the above NOTE, I am printing a message. Not
- ;; what I want, but it is better than nothing...
- (message denote-sort-dired-buffer-name))
- (message "No matching files for: %s" files-matching-regexp)))
+ (append (list (denote-files-matching-regexp-prompt))
(denote-sort-dired--prompts)))
+ (let ((component (or sort-by-component
+ denote-sort-dired-default-sort-component
+ 'identifier))
+ (reverse-sort (or reverse
+ denote-sort-dired-default-reverse-sort
+ nil)))
+ (if-let ((default-directory (denote-directory))
+ (files (denote-sort-get-directory-files files-matching-regexp
component reverse-sort))
+ ;; NOTE 2023-12-04: Passing the FILES-MATCHING-REGEXP as
+ ;; buffer-name produces an error if the regexp contains a
+ ;; wildcard for a directory. I can reproduce this in emacs
+ ;; -Q and am not sure if it is a bug. Anyway, I will report
+ ;; it upstream, but even if it is fixed we cannot use it
+ ;; for now (whatever fix will be available for Emacs 30+).
+ (denote-sort-dired-buffer-name (format "Denote sort `%s' by `%s'"
files-matching-regexp component))
+ (buffer-name (format "Denote sort by `%s' at %s" component
(format-time-string "%T"))))
+ (let ((dired-buffer (dired (cons buffer-name (mapcar
#'file-relative-name files)))))
+ (setq denote-sort--dired-buffer dired-buffer)
+ (with-current-buffer dired-buffer
+ (setq-local revert-buffer-function
+ (lambda (&rest _)
+ (kill-buffer dired-buffer)
+ (denote-sort-dired files-matching-regexp component
reverse-sort))))
+ ;; Because of the above NOTE, I am printing a message. Not
+ ;; what I want, but it is better than nothing...
+ (message denote-sort-dired-buffer-name))
+ (message "No matching files for: %s" files-matching-regexp))))
(provide 'denote-sort)
;;; denote-sort.el ends here
- [elpa] externals/denote updated (47e619feef -> 8ad0b816ed), ELPA Syncer, 2024/08/01
- [elpa] externals/denote 8ad0b816ed 6/6: Add three new user options for 'denote-sort-dired',
ELPA Syncer <=
- [elpa] externals/denote f806ed7db0 2/6: Add user options for the denote-sort-dired sorting functions per file name component, ELPA Syncer, 2024/08/01
- [elpa] externals/denote a506f3b364 5/6: Make denote-sort-components a defconst, ELPA Syncer, 2024/08/01
- [elpa] externals/denote 57b19e10ad 1/6: Remove outdated development note, ELPA Syncer, 2024/08/01
- [elpa] externals/denote d19a3ce882 3/6: Document how to sort Luhmann-style signatures (also see commit f806ed7), ELPA Syncer, 2024/08/01
- [elpa] externals/denote 6ea849b1be 4/6: Define a fallback comparison function in denote-sort, ELPA Syncer, 2024/08/01