blob: 4e479107fa40aae7809b9bf6f2fc8b09eb6c0655 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
;;; bookmark-conf.el --- My configurations for bookmark -*- lexical-binding: t; -*-
;; Copyright (C) 2021 Durand
;; Author: Durand <mmemmew@gmail.com>
;; Keywords: convenience
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; My configurations for bookmarks.
;;; Code:
;; dependency of blist
(use-package "ilist" 'ilist)
(use-package "blist" 'blist)
;;; replace the original key-binding
(define-key ctl-x-r-map (vector ?l) #'blist-list-bookmarks)
;;; Customizations
;;;; I am not an expert
;; I prefer not being an expert now, as deleting bookmarks is quite
;; dangerous for me, as I start to depend my workflow on these
;; bookmarks. It might be difficult to restore the bookmark of a PDF
;; file deeply buried somewhere inside my file system, if I
;; accidentally delete it.
(setq blist-expert nil)
;;;; Discard empty groups
(setq blist-discard-empty-p t)
;;;; I love cycling
(setq blist-movement-cycle t)
;;;; Filter groups
(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 "Org" #'blist-org-p)
(cons "C" #'blist-c-p)
(cons "Default" #'blist-default-p)))
;;; More bookmark groups
;;;; 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)))
;;;; EWW group
(blist-define-criterion "eww" "EWW"
(eq (bookmark-get-handler bookmark)
#'durand-eww-bookmark-jump))
;;;; Info group
(blist-define-criterion "info" "Info"
(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))
;;;; Org group
(defvar org-directory)
(blist-define-criterion "org" "Org"
(let ((location (blist-get-location bookmark)))
(or
(string-match-p
"\\.org$" location)
(and
(file-directory-p (or org-directory "/non-existing"))
(file-in-directory-p location org-directory)))))
;;;; C group
(blist-define-criterion "c" "C"
;; `rx' is a macro, so that we don't have to compute the regular
;; expression every time we match a line.
(string-match-p
(rx
(or
(seq ".c"
(zero-or-one "pp")
eos)
(seq ".h"
(zero-or-one "pp")
eos)))
(blist-get-location bookmark)))
;;;; ELisp group
(blist-define-criterion "elisp" "ELisp"
(string-match-p "\\.el$" (blist-get-location bookmark)))
;;; Fit annotations buffer to window
(defun durand-bookmark-jump-fit-to-window (&rest _args)
"Fit the annotations buffer to its window, if needed.
ARGS are ignored."
(let ((window (get-buffer-window "*Bookmark Annotation*")))
(cond
((and window (windowp window) (window-live-p window))
(durand-fit-window-to-buffer-with-max
window)))))
(advice-add #'bookmark-jump
:after
#'durand-bookmark-jump-fit-to-window)
;;; Display of the list
(cond
((assoc blist-buffer-name display-buffer-alist #'string-match-p)
(setcdr (assoc durand-chercher-pdf-buffer-name
display-buffer-alist #'string-match-p)
'((display-buffer-same-window))))
(t
(add-to-list 'display-buffer-alist
`(,(rx bos (eval blist-buffer-name) eos)
(display-buffer-same-window)))))
(provide 'bookmark-conf)
;;; bookmark-conf.el ends here
|