[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/blist 6e43d0a872 1/3: Adapt to the type information fro
From: |
ELPA Syncer |
Subject: |
[elpa] externals/blist 6e43d0a872 1/3: Adapt to the type information from Emacs 29. |
Date: |
Wed, 13 Dec 2023 03:57:38 -0500 (EST) |
branch: externals/blist
commit 6e43d0a8728c84a3e6d59108e71dff6a6ff73aa5
Author: JSDurand <mmemmew@gmail.com>
Commit: JSDurand <mmemmew@gmail.com>
Adapt to the type information from Emacs 29.
Emacs 29 adds a new feature to bookmark-handler-functions: they can
carry symbol property named "bookmark-handler-type", which should be
recognized as the type of the bookmarks associated with such handlers.
This commit adds an automatic group that uses this type information
for classification, which works for a lot of cases out of the box, and
can be easily extended to handle custom cases as well.
---
ChangeLog | 2 +-
README.org | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
blist.el | 29 ++++++++++++++++++++++---
3 files changed, 98 insertions(+), 6 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index be5157d1c6..3c803973f0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,4 @@
-2022-09-14 Sévère Durand <mmemmew@gmail.com>
+2022-09-14 Durand <mmemmew@gmail.com>
* README.org:
* blist.texinfo: Update documentation.
diff --git a/README.org b/README.org
index e551ee3ba8..1a76a1bf2b 100644
--- a/README.org
+++ b/README.org
@@ -30,8 +30,10 @@ how the list of bookmarks looks like on my end:
** Example configuration
-An example configuration is included so that it is easier to begin
-configuring the package.
+Some examples of configurations are included so that it is easier to
+begin configuring the package.
+
+*** Example of manual grouping
#+begin_src emacs-lisp :eval no :exports code
(setq blist-filter-groups
@@ -64,6 +66,51 @@ configuring the package.
#'Info-bookmark-jump))
#+end_src
+*** Example of automatic grouping
+
+#+begin_src emacs-lisp
+ (setq blist-filter-features (list 'auto))
+
+ ;; Either this
+ (setq blist-automatic-filter-groups
+ #'ilist-automatic-group-blist-default)
+
+ ;; Or this
+ (setq blist-automatic-filter-groups
+ #'ilist-automatic-group-blist-type-only)
+
+ ;; Or define ones own grouping function
+#+end_src
+
+*** Example of combining the two groupings
+
+#+begin_src emacs-lisp
+ ;; The order matters not.
+ (setq blist-filter-features (list 'manual 'auto))
+
+ ;; We can use manual groups to place certain important categories of
+ ;; bookmarks at the top of the list.
+ ;;
+ ;; Make sure not to include a default group, otherwise tha automatic
+ ;; grouping functions would have no chance of being run.
+ (setq blist-filter-groups
+ (list
+ (cons "Eshell" #'blist-eshell-p)
+ (cons "ELisp" #'blist-elisp-p)
+ (cons "PDF" #'blist-pdf-p)
+ (cons "Info" #'blist-info-p)))
+
+ ;; Either this
+ (setq blist-automatic-filter-groups
+ #'ilist-automatic-group-blist-default)
+
+ ;; Or this
+ (setq blist-automatic-filter-groups
+ #'ilist-automatic-group-blist-type-only)
+
+;; Or define ones own grouping function
+#+end_src
+
See the following subsections for more details.
** Header
@@ -163,6 +210,28 @@ If you want to define your own automatic filter group,
then the macro
might come in handy. The default automatic filter group is defined by
that macro, for your information.
+*** Two default automatic groups
+
+There are two pre-defined automatic groups in the package: the default
+one and the /type-only/ one.
+
+**** Default group
+
+In Emacs 29 or later, if a bookmark handler function symbol has a
+property called =bookmark-handler-type=, it will be recognized as the
+type of the bookmark, which can be retrieved by the function
+=bookmark-type-from-full-record=.
+
+The default group will use the type of a bookmark as the group header,
+if the type is available, otherwise it falls back to use file name
+extensions.
+
+**** Type-only group
+
+This automatic group only uses the type of a bookmark as the group
+header. If the type is not available, it always uses the default
+group.
+
*** Combine fixed and automatic filter groups
What if one wants to use both the fixed filter groups and the
diff --git a/blist.el b/blist.el
index c030f9400d..21b0f8b64b 100644
--- a/blist.el
+++ b/blist.el
@@ -1,6 +1,6 @@
;;; blist.el --- Display bookmarks in an ibuffer way -*- lexical-binding: t;
-*-
-;; Copyright (C) 2021 Free Software Foundation, Inc.
+;; Copyright (C) 2021, 2022, 2023 Free Software Foundation, Inc.
;; Author: Durand <durand@jsdurand.xyz>
;; Keywords: convenience
@@ -123,6 +123,12 @@ Used by `ilist-dag' to define an automatic filter group."
(save-match-data
(let* ((handler (bookmark-get-handler element))
(handler-name (and handler (format "%S" handler)))
+ (handler-type
+ (cond
+ ;; This is added in Emacs 29, so we test if this function
+ ;; is defined.
+ ((functionp #'bookmark-type-from-full-record)
+ (bookmark-type-from-full-record element))))
(location (bookmark-location element)))
;; replace repeating parts
(cond
@@ -138,6 +144,8 @@ Used by `ilist-dag' to define an automatic filter group."
(string-match "\\.\\([^.]+\\)\\'" location))
(setq handler-name (match-string 1 location))))
(cond
+ ;; If the type is available, we use it as the group header.
+ (handler-type)
(handler-name
(cond
;; Some special cases
@@ -146,7 +154,21 @@ Used by `ilist-dag' to define an automatic filter group."
((<= (length handler-name) 3) (upcase handler-name))
((capitalize handler-name))))))))
-;; the function defined above
+;;;;; An alternative, type-only, automatic grouping
+
+;; An alternative automatic group that only uses types of handlers as
+;; group headers.
+
+;; NOTE: bookmark-type-from-full-record is added in Emacs 29, so it is
+;; unavailable before this version, and hence this automatic filter
+;; group would always use the default group.
+
+(ilist-dag "blist-type-only" "Default" #'blist-filter-sorter-default
+ (cond
+ ((functionp #'bookmark-type-from-full-record)
+ (bookmark-type-from-full-record element))))
+
+;; For discoverability
(defalias 'blist-automatic-filter-groups-default
#'ilist-automatic-group-blist-default)
@@ -1279,7 +1301,8 @@ progress."
bookmark-alist))
(name-len (length names))
(new-len (length new-list))
- (table (make-hash-table :test 'equal :size name-len))
+ (table (make-hash-table
+ :test 'equal :size (+ name-len new_len)))
(count 0))
;; use a hash table so that testing for membership is a constant
;; time operation