Repository navigation
Expand file tree
/
Copy pathpoimap-bookmark.el
More file actions
116 lines (97 loc) · 3.96 KB
/
Copy pathpoimap-bookmark.el
File metadata and controls
116 lines (97 loc) · 3.96 KB
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
;;; poimap-bookmark.el --- Bookmark POIs for poimap -*- lexical-binding: t; -*-
;; Copyright (C) 2026 Florian Rommel
;; Author: Florian Rommel <mail@florommel.de>
;; Maintainer: Florian Rommel <mail@florommel.de>
;; URL: https://github.com/florommel/poimap
;; Created: 2026-06-25
;; Version: 0.1
;; Package-Requires: ((emacs "29.1") (poimap "0.1"))
;; Keywords: convenience, bookmark
;; 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:
;; Display bookmarks as poimap points of interest.
;;; Code:
(require 'bookmark)
(require 'poimap)
(require 'seq)
(defface poimap-bookmark-face
'((t :inherit font-lock-constant-face))
"Face for poimap bookmark POIs.
The foreground color is used."
:group 'poimap)
(defcustom poimap-bookmark-shape-function #'poimap-diamond
"Function used to draw bookmark POIs."
:type 'function
:group 'poimap)
(defcustom poimap-bookmark-vertical-position 0.6
"Vertical position of bookmark POIs."
:type 'number
:group 'poimap)
(defcustom poimap-bookmark-size 7
"Size passed to `poimap-bookmark-shape-function'."
:type '(choice number (cons number number))
:group 'poimap)
(defun poimap-bookmark--update (force)
"Update SVG for bookmarks if FORCE is non-nil."
(poimap-update-pois
'poimap-bookmark
(when force
(let* ((shape-fn poimap-bookmark-shape-function)
(vert poimap-bookmark-vertical-position)
(size poimap-bookmark-size)
(color (poimap-emacs-to-svg-color
(face-foreground 'poimap-bookmark-face nil 'default)))
(file (buffer-file-name))
(bms (when file
(seq-filter
(lambda (bookmark)
(let ((bookmark-filename
(bookmark-get-filename bookmark)))
(and bookmark-filename
(file-equal-p file bookmark-filename))))
bookmark-alist)))
(bps (mapcar #'bookmark-get-position bms))
(svg))
(dolist (bp bps)
(when-let (pos (poimap-map-position bp))
(push (funcall shape-fn pos vert size color) svg)))
(mapconcat #'identity (mapcan #'identity (nreverse svg)))))))
(defun poimap-bookmark--bookmark-count-watcher
(_symbol _newval _operation _where)
"Watch changes to `bookmark-alist-modification-count`."
(let ((buffers (delete-dups
(mapcar #'window-buffer
(window-list-1 nil 'no-minibuffer t)))))
(dolist (buffer buffers)
(with-current-buffer buffer
(when (poimap-bookmark--update t)
(force-mode-line-update))))))
;;;###autoload
(define-minor-mode poimap-bookmark
"Display Emacs bookmarks as poimap points of interest."
:global t
:group 'poimap
(if poimap-bookmark
(progn
(poimap--warn-unless-mode 'poimap-bookmark)
(add-hook 'poimap-idle-update-functions #'poimap-bookmark--update)
(add-variable-watcher
'bookmark-alist-modification-count
#'poimap-bookmark--bookmark-count-watcher)
(poimap--for-all-visible-window-buffers #'poimap-bookmark--update t))
(remove-hook 'poimap-idle-update-functions #'poimap-bookmark--update)
(remove-variable-watcher
'bookmark-alist-modification-count
#'poimap-bookmark--bookmark-count-watcher)
(poimap--clear-buffer-state 'poimap-bookmark)))
(provide 'poimap-bookmark)
;;; poimap-bookmark.el ends here