summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-12-28 21:19:17 +0800
committerJSDurand <mmemmew@gmail.com>2021-12-28 21:19:17 +0800
commit89a50085a72db763863f22483226e10dfb6a7e45 (patch)
tree988d39305d850165814110d7de466a6b6a39aa79
parent5c211004d66d7fb267eafcaecdb472cee1141609 (diff)
bookmark-conf: The era of automation comes by!
Adapt to use an automatic filter group.
-rw-r--r--bookmark-conf.el85
1 files changed, 68 insertions, 17 deletions
diff --git a/bookmark-conf.el b/bookmark-conf.el
index 4d33e1e..eaf6dbc 100644
--- a/bookmark-conf.el
+++ b/bookmark-conf.el
@@ -24,11 +24,17 @@
;;; Code:
+(require 'bookmark)
+
+(autoload 'use-package "basic")
+
;; dependency of blist
(use-package "ilist" 'ilist)
+(require 'ilist)
(use-package "blist" 'blist)
+(require 'blist)
;;; replace the original key-binding
@@ -64,47 +70,88 @@
;;;; Filter groups
+;;;;; Features
+
+(setq blist-filter-features (list 'auto 'manual))
+
+;;;;; Fixed groups
+
+;; Now that I have automatic groups, I only need some of these manual
+;; groups to keep certain groups in the order I prefer, and placed at
+;; the top of the list.
+
(setq
blist-filter-groups
(list
(cons "PDF" #'blist-pdf-p)
- (cons "Eshell" #'blist-eshell-p)
- (cons "ELisp" #'blist-elisp-p)
- (cons "Gnus" #'blist-gnus-p)
- (cons "EWW" #'blist-eww-p)
- (cons "Info" #'blist-info-p)
- (cons "External" #'blist-external-p)
- (cons "Org" #'blist-org-p)
(cons "C" #'blist-c-p)
- (cons "Default" #'blist-default-p)))
+ (cons "Gnus" #'blist-gnus-p)
+ (cons "ELisp" #'blist-elisp-p)
+ (cons "Eshell" #'blist-eshell-p)))
+
+;;;;; Automatic groups
+
+(ilist-dag "durand" blist-filter-default-label
+ (cond
+ ;; The following two clauses ensure that the default group
+ ;; stays at the bottom of the list.
+ ((string= x "Default") nil)
+ ((string= y "Default"))
+ ((string-lessp x y)))
+ (save-match-data
+ (let* ((handler (bookmark-get-handler element))
+ (handler-name (and handler (format "%S" handler)))
+ (location (bookmark-location element)))
+ ;; replace repeating parts
+ (cond
+ ((and handler-name
+ (string-match "\\([^z-a]+\\)-jump" handler-name))
+ (setq
+ handler-name
+ (replace-regexp-in-string
+ "^durand-" ""
+ (replace-regexp-in-string
+ "-bookmark$" "" (match-string 1 handler-name))))))
+ ;; take case of file extensions
+ (cond
+ ((and (null handler-name) location
+ (string-match "\\.\\([^.]+\\)\\'" location))
+ (setq handler-name (match-string 1 location))))
+ (cond
+ (handler-name
+ (cond
+ ((<= (length handler-name) 3) (upcase handler-name))
+ ((capitalize handler-name))))))))
+
+(setq blist-automatic-filter-groups #'ilist-automatic-group-durand)
;;; More bookmark groups
+;; Some of these are not needed anymore, but I still keep them here as
+;; a reference. Or maybe I just don't want to delete them.
+
;;;; Gnus group
;; There seems to be only two GNUS bookmark handlers (or one?)
(blist-define-criterion "gnus" "Gnus"
(memq (bookmark-get-handler bookmark)
- (list #'gnus-summary-bookmark-jump
- #'gnus-bookmark-jump)))
+ (list #'gnus-summary-bookmark-jump #'gnus-bookmark-jump)))
;;;; EWW group
(blist-define-criterion "eww" "EWW"
- (eq (bookmark-get-handler bookmark)
- #'durand-eww-bookmark-jump))
+ (eq (bookmark-get-handler bookmark) 'durand-eww-bookmark-jump))
;;;; Info group
(blist-define-criterion "info" "Info"
- (eq (bookmark-get-handler bookmark)
- #'Info-bookmark-jump))
+ (eq (bookmark-get-handler bookmark) 'Info-bookmark-jump))
;;;; PDF group
(blist-define-criterion "pdf" "PDF"
- (eq (bookmark-get-handler bookmark)
- #'pdf-view-bookmark-jump-handler))
+ (eq
+ (bookmark-get-handler bookmark) 'pdf-view-bookmark-jump-handler))
;;;; Org group
@@ -148,6 +195,8 @@
;;; Fit annotations buffer to window
+(autoload 'durand-fit-window-to-buffer-with-max "common")
+
(defun durand-bookmark-jump-fit-to-window (&rest _args)
"Fit the annotations buffer to its window, if needed.
ARGS are ignored."
@@ -165,7 +214,7 @@ ARGS are ignored."
(cond
((assoc blist-buffer-name display-buffer-alist #'string-match-p)
- (setcdr (assoc durand-chercher-pdf-buffer-name
+ (setcdr (assoc blist-buffer-name
display-buffer-alist #'string-match-p)
'((display-buffer-same-window))))
(t
@@ -225,6 +274,8 @@ This will be opened by the function `browse-url-default-browser'."
(cons 'handler #'durand-external-jump))
nil))
+(autoload 'browse-url-default-browser "browse-url")
+
(defun durand-external-jump (bookmark)
"Jump to the external BOOKMARK.
BOOKMARK should be set by `durand-set-external-bookmark'."