1 ;;; gnus-bookmark.el --- Bookmarks in Gnus
3 ;; Copyright (C) 2006-2017 Free Software Foundation, Inc.
5 ;; Author: Bastien Guerry <bzg AT altern DOT org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
25 ;; This file implements real bookmarks for Gnus, closely following the way
26 ;; `bookmark.el' handles bookmarks. Most of the code comes from
29 ;; Set a Gnus bookmark:
30 ;; M-x `gnus-bookmark-set' from the summary buffer.
32 ;; Jump to a Gnus bookmark:
33 ;; M-x `gnus-bookmark-jump'.
35 ;; Display a list of bookmarks
36 ;; M-x `gnus-bookmark-bmenu-list'.
41 ;; - add tags to bookmarks
42 ;; - don't write file each time a bookmark is created
43 ;; - better annotation interactive buffer
44 ;; - edit annotation in gnus-bookmark-bmenu
45 ;; - sort gnus-bookmark-buffer by author/subject/date/group/message-id
46 ;; - auto-bmk-name customizable format
47 ;; - renaming bookmarks in gnus-bookmark-bmenu-list
48 ;; - better (formatted string) display in bmenu-list
50 ;; - Integrate the `gnus-summary-*-bookmark' functionality
51 ;; - Initialize defcustoms from corresponding `bookmark.el' variables?
57 ;; FIXME: should avoid using C-c (no?)
58 ;; (define-key gnus-summary-mode-map "\C-crm" 'gnus-bookmark-set)
59 ;; (define-key global-map "\C-crb" 'gnus-bookmark-jump)
60 ;; (define-key global-map "\C-crj" 'gnus-bookmark-jump)
61 ;; (define-key global-map "\C-crl" 'gnus-bookmark-bmenu-list)
63 ;; FIXME: Add keybindings, see
64 ;; http://thread.gmane.org/gmane.emacs.gnus.general/63101/focus=63379
65 ;; http://thread.gmane.org/v9fxx9fkm4.fsf@marauder.physik.uni-ulm.de
67 ;; FIXME: Check if `gnus-bookmark.el' should use
68 ;; `bookmark-make-cell-function'.
69 ;; Cf. http://article.gmane.org/gmane.emacs.gnus.general/66076
71 (defgroup gnus-bookmark nil
72 "Setting, annotation and jumping to Gnus bookmarks."
75 (defcustom gnus-bookmark-default-file
77 ;; Backward compatibility with previous versions:
78 ((file-exists-p "~/.gnus.bmk") "~/.gnus.bmk")
79 (t (nnheader-concat gnus-directory
"bookmarks.el")))
80 "The default Gnus bookmarks file."
82 :group
'gnus-bookmark
)
84 (defcustom gnus-bookmark-file-coding-system
85 (if (mm-coding-system-p 'iso-2022-7bit
)
87 "Coding system used for writing Gnus bookmark files."
88 :type
'(symbol :tag
"Coding system")
89 :group
'gnus-bookmark
)
91 (defcustom gnus-bookmark-sort-flag t
92 "Non-nil means Gnus bookmarks are sorted by bookmark names.
93 Otherwise they will be displayed in LIFO order (that is,
94 most recently set ones come first, oldest ones come last)."
96 :group
'gnus-bookmark
)
98 (defcustom gnus-bookmark-bmenu-toggle-infos t
99 "Non-nil means show details when listing Gnus bookmarks.
100 List of details is defined in `gnus-bookmark-bookmark-inline-details'.
101 This may result in truncated bookmark names. To disable this, put the
102 following in your `.emacs' file:
104 \(setq gnus-bookmark-bmenu-toggle-infos nil)"
106 :group
'gnus-bookmark
)
108 (defcustom gnus-bookmark-bmenu-file-column
30
109 "Column at which to display details in a buffer listing Gnus bookmarks.
110 You can toggle whether details are shown with \\<gnus-bookmark-bmenu-mode-map>\\[gnus-bookmark-bmenu-toggle-infos]."
112 :group
'gnus-bookmark
)
114 (defcustom gnus-bookmark-use-annotations nil
115 "If non-nil, ask for an annotation when setting a bookmark."
117 :group
'gnus-bookmark
)
119 (defcustom gnus-bookmark-bookmark-inline-details
'(author)
120 "Details to be shown with `gnus-bookmark-bmenu-toggle-infos'.
121 The default value is \(subject)."
122 :type
'(list :tag
"Gnus bookmark details"
124 (const :tag
"Author" author
)
125 (const :tag
"Subject" subject
)
126 (const :tag
"Date" date
)
127 (const :tag
"Group" group
)
128 (const :tag
"Message-id" message-id
)))
129 :group
'gnus-bookmark
)
131 (defcustom gnus-bookmark-bookmark-details
132 '(author subject date group annotation
)
133 "Details to be shown with `gnus-bookmark-bmenu-show-details'.
134 The default value is \(author subject date group annotation)."
135 :type
'(list :tag
"Gnus bookmark details"
137 (const :tag
"Author" author
)
138 (const :tag
"Subject" subject
)
139 (const :tag
"Date" date
)
140 (const :tag
"Group" group
)
141 (const :tag
"Message-id" message-id
)
142 (const :tag
"Annotation" annotation
)))
143 :group
'gnus-bookmark
)
145 (defface gnus-bookmark-menu-heading
146 '((t (:inherit font-lock-type-face
)))
147 "Face used to highlight the heading in Gnus bookmark menu buffers."
148 :version
"23.1" ;; No Gnus
149 :group
'gnus-bookmark
)
151 (defconst gnus-bookmark-end-of-version-stamp-marker
152 "-*- End Of Bookmark File Format Version Stamp -*-\n"
153 "This string marks the end of the version stamp in a Gnus bookmark file.")
155 (defconst gnus-bookmark-file-format-version
0
156 "The current version of the format used by bookmark files.
157 You should never need to change this.")
159 (defvar gnus-bookmark-alist
()
160 "Association list of Gnus bookmarks and their records.
161 The format of the alist is
165 where each BMK is of the form
169 (message-id . MESSAGE-ID)
173 (annotation . ANNOTATION))
175 So the cdr of each bookmark is an alist too.")
178 (defun gnus-bookmark-set ()
179 "Set a bookmark for this article."
181 (gnus-bookmark-maybe-load-default-file)
182 (if (or (not (derived-mode-p 'gnus-summary-mode
))
183 (not gnus-article-current
))
184 (error "Please select an article in the Gnus summary buffer")
185 (let* ((group (car gnus-article-current
))
186 (article (cdr gnus-article-current
))
187 (header (gnus-summary-article-header article
))
188 (author (mail-header-from header
))
189 (message-id (mail-header-id header
))
190 (date (mail-header-date header
))
191 (subject (gnus-summary-subject-string))
192 (bmk-name (gnus-bookmark-set-bookmark-name group author subject
))
193 ;; Maybe ask for annotation
195 (if gnus-bookmark-use-annotations
196 (read-from-minibuffer
197 (format "Annotation for %s: " bmk-name
)) "")))
198 ;; Set the bookmark list
199 (setq gnus-bookmark-alist
201 (list (substring-no-properties bmk-name
)
202 (gnus-bookmark-make-record
203 group message-id author date subject annotation
))
204 gnus-bookmark-alist
))))
205 (gnus-bookmark-bmenu-surreptitiously-rebuild-list)
206 (gnus-bookmark-write-file))
208 (defun gnus-bookmark-make-record
209 (group message-id author date subject annotation
)
210 "Return the record part of a new bookmark, given GROUP MESSAGE-ID AUTHOR DATE SUBJECT and ANNOTATION."
212 `((group .
,(substring-no-properties group
))
213 (message-id .
,(substring-no-properties message-id
))
214 (author .
,(substring-no-properties author
))
215 (date .
,(substring-no-properties date
))
216 (subject .
,(substring-no-properties subject
))
217 (annotation .
,(substring-no-properties annotation
)))))
220 (defun gnus-bookmark-set-bookmark-name (group author subject
)
221 "Set bookmark name from GROUP AUTHOR and SUBJECT."
222 (let* ((subject (split-string subject
))
223 (default-name-0 ;; Should be merged with -1?
224 (concat (car (nreverse (delete "" (split-string group
"[\\.:]"))))
225 "-" (car (split-string author
))
226 "-" (car subject
) "-" (cadr subject
)))
228 ;; Strip "[]" chars from the bookmark name:
229 (replace-regexp-in-string "[]_[]" "" default-name-0
))
230 (name (read-from-minibuffer
231 (format "Set bookmark (%s): " default-name-1
)
234 (if (string-equal name
"")
238 (defun gnus-bookmark-write-file ()
239 "Write currently defined Gnus bookmarks into `gnus-bookmark-default-file'."
242 (save-window-excursion
244 ;; (message "Saving Gnus bookmarks to file %s..." gnus-bookmark-default-file)
245 (set-buffer (get-buffer-create " *Gnus bookmarks*"))
247 (gnus-bookmark-insert-file-format-version-stamp)
248 (pp gnus-bookmark-alist
(current-buffer))
250 (let ((coding-system-for-write gnus-bookmark-file-coding-system
))
251 (write-region (point-min) (point-max)
252 gnus-bookmark-default-file
))
253 (file-error (message "Can't write %s"
254 gnus-bookmark-default-file
)))
255 (kill-buffer (current-buffer))
257 "Saving Gnus bookmarks to file %s...done"
258 gnus-bookmark-default-file
))))
260 (defun gnus-bookmark-insert-file-format-version-stamp ()
261 "Insert text indicating current version of Gnus bookmark file format."
263 (format ";;;; Gnus Bookmark Format Version %d %s;;;;\n"
264 gnus-bookmark-file-format-version
265 (if gnus-bookmark-file-coding-system
266 (concat "-*- coding: "
267 (symbol-name gnus-bookmark-file-coding-system
)
270 (insert ";;; This format is meant to be slightly human-readable;\n"
271 ";;; nevertheless, you probably don't want to edit it.\n"
273 gnus-bookmark-end-of-version-stamp-marker
))
276 (defun gnus-bookmark-jump (&optional bmk-name
)
277 "Jump to a Gnus bookmark (BMK-NAME)."
279 (gnus-bookmark-maybe-load-default-file)
280 (let* ((bookmark (or bmk-name
281 (gnus-completing-read "Jump to bookmarked article"
282 (mapcar 'car gnus-bookmark-alist
))))
283 (bmk-record (cadr (assoc bookmark gnus-bookmark-alist
)))
284 (group (cdr (assoc 'group bmk-record
)))
285 (message-id (cdr (assoc 'message-id bmk-record
))))
287 (unless (get-buffer gnus-group-buffer
)
289 (gnus-activate-group group
)
290 (gnus-group-quick-select-group 0 group
))
292 (or (gnus-summary-goto-article message-id nil
'force
)
293 (if (fboundp 'gnus-summary-insert-cached-articles
)
295 (gnus-summary-insert-cached-articles)
296 (gnus-summary-goto-article message-id nil
'force
))
297 (message "Message could not be found."))))))
299 (defvar gnus-bookmark-already-loaded nil
)
301 (defun gnus-bookmark-alist-from-buffer ()
302 "Return a `gnus-bookmark-alist' from the current buffer.
303 The buffer must of course contain Gnus bookmark format information.
304 Does not care from where in the buffer it is called, and does not
307 (goto-char (point-min))
309 gnus-bookmark-end-of-version-stamp-marker nil t
)
310 (read (current-buffer))
311 ;; Else no hope of getting information here.
312 (error "Not Gnus bookmark format"))))
314 (defun gnus-bookmark-load (file)
315 "Load Gnus bookmarks from FILE (which must be in bookmark format)."
317 (list (read-file-name
318 (format "Load Gnus bookmarks from: (%s) "
319 gnus-bookmark-default-file
)
320 "~/" gnus-bookmark-default-file
'confirm
)))
321 (setq file
(expand-file-name file
))
322 (if (file-readable-p file
)
324 (save-window-excursion
325 (set-buffer (let ((enable-local-variables nil
))
326 (find-file-noselect file
)))
327 (goto-char (point-min))
328 (let ((blist (gnus-bookmark-alist-from-buffer)))
330 (progn (setq gnus-bookmark-already-loaded t
)
331 (setq gnus-bookmark-alist blist
))
332 (error "Not Gnus bookmark format")))))))
334 (defun gnus-bookmark-maybe-load-default-file ()
335 "Maybe load Gnus bookmarks in `gnus-bookmark-alist'."
336 (and (not gnus-bookmark-already-loaded
)
337 (null gnus-bookmark-alist
)
338 (file-readable-p (expand-file-name gnus-bookmark-default-file
))
339 (gnus-bookmark-load gnus-bookmark-default-file
)))
341 (defun gnus-bookmark-maybe-sort-alist ()
342 "Return the gnus-bookmark-alist for display.
343 If the gnus-bookmark-sort-flag is non-nil, then return a sorted
345 (when gnus-bookmark-sort-flag
346 (setq gnus-bookmark-alist
347 (sort (copy-alist gnus-bookmark-alist
)
349 (lambda (x y
) (string-lessp (car x
) (car y
))))))))
352 (defun gnus-bookmark-bmenu-list ()
353 "Display a list of existing Gnus bookmarks.
354 The list is displayed in a buffer named `*Gnus Bookmark List*'.
355 The leftmost column displays a D if the bookmark is flagged for
356 deletion, or > if it is flagged for displaying."
358 (gnus-bookmark-maybe-load-default-file)
359 (if (called-interactively-p 'any
)
360 (switch-to-buffer (get-buffer-create "*Gnus Bookmark List*"))
361 (set-buffer (get-buffer-create "*Gnus Bookmark List*")))
362 (let ((inhibit-read-only t
)
363 alist name start end
)
365 (insert "% Gnus Bookmark\n- --------\n")
366 (add-text-properties (point-min) (point)
367 '(font-lock-face gnus-bookmark-menu-heading
))
368 ;; sort before displaying
369 (gnus-bookmark-maybe-sort-alist)
370 ;; Display gnus bookmarks
371 (setq alist gnus-bookmark-alist
)
373 (setq name
(gnus-bookmark-name-from-full-record (pop alist
)))
374 ;; if a Gnus bookmark has an annotation, prepend a "*"
375 ;; in the list of bookmarks.
376 (insert (if (member (gnus-bookmark-get-annotation name
) (list nil
""))
379 (if (display-mouse-p)
386 (re-search-backward "[^ \t]")
390 `(mouse-face highlight follow-link t
391 help-echo
,(format "%s: go to this article"
394 (goto-char (point-min))
396 (gnus-bookmark-bmenu-mode)
397 (if gnus-bookmark-bmenu-toggle-infos
398 (gnus-bookmark-bmenu-toggle-infos t
))))
400 (defun gnus-bookmark-bmenu-surreptitiously-rebuild-list ()
401 "Rebuild the Bookmark List if it exists.
402 Don't affect the buffer ring order."
403 (if (get-buffer "*Gnus Bookmark List*")
405 (save-window-excursion
406 (gnus-bookmark-bmenu-list)))))
408 (defun gnus-bookmark-get-annotation (bookmark)
409 "Return the annotation of Gnus BOOKMARK, or nil if none."
410 (cdr (assq 'annotation
(gnus-bookmark-get-bookmark-record bookmark
))))
412 (defun gnus-bookmark-get-bookmark (bookmark)
413 "Return the full entry for Gnus BOOKMARK in `gnus-bookmark-alist'.
414 If BOOKMARK is not a string, return nil."
415 (when (stringp bookmark
)
416 (assoc bookmark gnus-bookmark-alist
)))
418 (defun gnus-bookmark-get-bookmark-record (bookmark)
419 "Return the guts of the entry for Gnus BOOKMARK in `gnus-bookmark-alist'.
420 That is, all information but the name."
421 (car (cdr (gnus-bookmark-get-bookmark bookmark
))))
423 (defun gnus-bookmark-name-from-full-record (full-record)
424 "Return name of FULL-RECORD (an alist element instead of a string)."
427 (defvar gnus-bookmark-bmenu-bookmark-column nil
)
428 (defvar gnus-bookmark-bmenu-hidden-bookmarks
())
429 (defvar gnus-bookmark-bmenu-mode-map nil
)
431 (if gnus-bookmark-bmenu-mode-map
433 (setq gnus-bookmark-bmenu-mode-map
(make-keymap))
434 (suppress-keymap gnus-bookmark-bmenu-mode-map t
)
435 (define-key gnus-bookmark-bmenu-mode-map
"q" 'quit-window
)
436 (define-key gnus-bookmark-bmenu-mode-map
"\C-m" 'gnus-bookmark-bmenu-select
)
437 (define-key gnus-bookmark-bmenu-mode-map
"v" 'gnus-bookmark-bmenu-select
)
438 (define-key gnus-bookmark-bmenu-mode-map
"d" 'gnus-bookmark-bmenu-delete
)
439 (define-key gnus-bookmark-bmenu-mode-map
"k" 'gnus-bookmark-bmenu-delete
)
440 (define-key gnus-bookmark-bmenu-mode-map
"\C-d" 'gnus-bookmark-bmenu-delete-backwards
)
441 (define-key gnus-bookmark-bmenu-mode-map
"x" 'gnus-bookmark-bmenu-execute-deletions
)
442 (define-key gnus-bookmark-bmenu-mode-map
" " 'next-line
)
443 (define-key gnus-bookmark-bmenu-mode-map
"n" 'next-line
)
444 (define-key gnus-bookmark-bmenu-mode-map
"p" 'previous-line
)
445 (define-key gnus-bookmark-bmenu-mode-map
"\177" 'gnus-bookmark-bmenu-backup-unmark
)
446 (define-key gnus-bookmark-bmenu-mode-map
"?" 'describe-mode
)
447 (define-key gnus-bookmark-bmenu-mode-map
"u" 'gnus-bookmark-bmenu-unmark
)
448 (define-key gnus-bookmark-bmenu-mode-map
"m" 'gnus-bookmark-bmenu-mark
)
449 (define-key gnus-bookmark-bmenu-mode-map
"l" 'gnus-bookmark-bmenu-load
)
450 (define-key gnus-bookmark-bmenu-mode-map
"s" 'gnus-bookmark-bmenu-save
)
451 (define-key gnus-bookmark-bmenu-mode-map
"t" 'gnus-bookmark-bmenu-toggle-infos
)
452 (define-key gnus-bookmark-bmenu-mode-map
"a" 'gnus-bookmark-bmenu-show-details
)
453 (define-key gnus-bookmark-bmenu-mode-map
[mouse-2
]
454 'gnus-bookmark-bmenu-select-by-mouse
))
456 ;; Bookmark Buffer Menu mode is suitable only for specially formatted
458 (put 'gnus-bookmark-bmenu-mode
'mode-class
'special
)
460 ;; Been to lazy to use gnus-bookmark-save...
461 (defalias 'gnus-bookmark-bmenu-save
'gnus-bookmark-write-file
)
463 (define-derived-mode gnus-bookmark-bmenu-mode fundamental-mode
"Bookmark Menu"
464 "Major mode for editing a list of Gnus bookmarks.
465 Each line describes one of the bookmarks in Gnus.
466 Letters do not insert themselves; instead, they are commands.
467 Gnus bookmarks names preceded by a \"*\" have annotations.
468 \\<gnus-bookmark-bmenu-mode-map>
469 \\[gnus-bookmark-bmenu-mark] -- mark bookmark to be displayed.
470 \\[gnus-bookmark-bmenu-select] -- select bookmark of line point is on.
471 Also show bookmarks marked using m in other windows.
472 \\[gnus-bookmark-bmenu-toggle-infos] -- toggle displaying of details (they may obscure long bookmark names).
473 \\[gnus-bookmark-bmenu-locate] -- display (in minibuffer) location of this bookmark.
474 \\[gnus-bookmark-bmenu-rename] -- rename this bookmark (prompts for new name).
475 \\[gnus-bookmark-bmenu-delete] -- mark this bookmark to be deleted, and move down.
476 \\[gnus-bookmark-bmenu-delete-backwards] -- mark this bookmark to be deleted, and move up.
477 \\[gnus-bookmark-bmenu-execute-deletions] -- delete bookmarks marked with `\\[gnus-bookmark-bmenu-delete]'.
478 \\[gnus-bookmark-bmenu-load] -- load in a file of bookmarks (prompts for file.)
479 \\[gnus-bookmark-bmenu-save] -- load in a file of bookmarks (prompts for file.)
480 \\[gnus-bookmark-bmenu-unmark] -- remove all kinds of marks from current line.
481 With prefix argument, also move up one line.
482 \\[gnus-bookmark-bmenu-backup-unmark] -- back up a line and remove marks.
483 \\[gnus-bookmark-bmenu-show-details] -- show the annotation, if it exists, for the current bookmark
485 \\[gnus-bookmark-bmenu-show-all-annotations] -- show the annotations of all bookmarks in another buffer.
486 \\[gnus-bookmark-bmenu-edit-annotation] -- edit the annotation for the current bookmark."
487 (setq truncate-lines t
)
488 (setq buffer-read-only t
))
490 ;; avoid compilation warnings
491 (defvar gnus-bookmark-bmenu-toggle-infos nil
)
493 (defun gnus-bookmark-bmenu-toggle-infos (&optional show
)
494 "Toggle whether details are shown in the Gnus bookmark list.
495 Optional argument SHOW means show them unconditionally."
499 (setq gnus-bookmark-bmenu-toggle-infos nil
)
500 (gnus-bookmark-bmenu-show-infos)
501 (setq gnus-bookmark-bmenu-toggle-infos t
))
502 (gnus-bookmark-bmenu-toggle-infos
503 (gnus-bookmark-bmenu-hide-infos)
504 (setq gnus-bookmark-bmenu-toggle-infos nil
))
506 (gnus-bookmark-bmenu-show-infos)
507 (setq gnus-bookmark-bmenu-toggle-infos t
))))
509 (defun gnus-bookmark-bmenu-show-infos (&optional force
)
510 "Show infos in bmenu, maybe FORCE display of infos."
511 (if (and (not force
) gnus-bookmark-bmenu-toggle-infos
)
512 nil
;already shown, so do nothing
514 (save-window-excursion
515 (goto-char (point-min))
517 (setq gnus-bookmark-bmenu-hidden-bookmarks
())
518 (let ((inhibit-read-only t
))
519 (while (< (point) (point-max))
520 (let ((bmrk (gnus-bookmark-bmenu-bookmark)))
521 (setq gnus-bookmark-bmenu-hidden-bookmarks
522 (cons bmrk gnus-bookmark-bmenu-hidden-bookmarks
))
523 (let ((start (point-at-eol)))
524 (move-to-column gnus-bookmark-bmenu-file-column t
)
525 ;; Strip off `mouse-face' from the white spaces region.
526 (if (display-mouse-p)
527 (remove-text-properties start
(point)
528 '(mouse-face nil help-echo nil
))))
529 (delete-region (point) (progn (end-of-line) (point)))
531 ;; Pass the NO-HISTORY arg:
532 (gnus-bookmark-insert-details bmrk
)
533 (forward-line 1))))))))
535 (defun gnus-bookmark-insert-details (bmk-name)
536 "Insert the details of the article associated with BMK-NAME."
537 (let ((start (point)))
539 (insert (gnus-bookmark-get-details
541 gnus-bookmark-bookmark-inline-details
))
542 (if (display-mouse-p)
545 (save-excursion (re-search-backward
548 `(mouse-face highlight
550 help-echo
,(format "%s: go to this article"
553 (defun gnus-bookmark-kill-line (&optional newline-too
)
554 "Kill from point to end of line.
555 If optional arg NEWLINE-TOO is non-nil, delete the newline too.
556 Does not affect the kill ring."
557 (delete-region (point) (point-at-eol))
558 (if (and newline-too
(looking-at "\n"))
561 (defun gnus-bookmark-get-details (bmk-name details-list
)
562 "Get details for a Gnus BMK-NAME depending on DETAILS-LIST."
563 (let ((details (cadr (assoc bmk-name gnus-bookmark-alist
))))
566 (cdr (assoc info details
)))
567 details-list
" | ")))
569 (defun gnus-bookmark-bmenu-hide-infos (&optional force
)
570 "Hide infos in bmenu, maybe FORCE."
571 (if (and (not force
) gnus-bookmark-bmenu-toggle-infos
)
572 ;; nothing to hide if above is nil
574 (save-window-excursion
575 (goto-char (point-min))
577 (setq gnus-bookmark-bmenu-hidden-bookmarks
578 (nreverse gnus-bookmark-bmenu-hidden-bookmarks
))
580 (goto-char (point-min))
581 (search-forward "Gnus Bookmark")
583 (setq gnus-bookmark-bmenu-bookmark-column
(current-column)))
585 (let ((inhibit-read-only t
))
586 (while gnus-bookmark-bmenu-hidden-bookmarks
587 (move-to-column gnus-bookmark-bmenu-bookmark-column t
)
588 (gnus-bookmark-kill-line)
589 (let ((start (point)))
590 (insert (car gnus-bookmark-bmenu-hidden-bookmarks
))
591 (if (display-mouse-p)
594 (save-excursion (re-search-backward
597 `(mouse-face highlight
600 ,(format "%s: go to this bookmark in other window"
602 (setq gnus-bookmark-bmenu-hidden-bookmarks
603 (cdr gnus-bookmark-bmenu-hidden-bookmarks
))
604 (forward-line 1))))))))
606 (defun gnus-bookmark-bmenu-check-position ()
607 "Return non-nil if on a line with a bookmark.
608 The actual value returned is gnus-bookmark-alist. Else
609 reposition and try again, else return nil."
610 (cond ((< (count-lines (point-min) (point)) 2)
611 (goto-char (point-min))
615 (beginning-of-line 0)
618 gnus-bookmark-alist
)))
620 (defun gnus-bookmark-bmenu-bookmark ()
621 "Return a string which is bookmark of this line."
622 (if (gnus-bookmark-bmenu-check-position)
624 (save-window-excursion
625 (goto-char (point-min))
626 (search-forward "Gnus Bookmark")
628 (setq gnus-bookmark-bmenu-bookmark-column
(current-column)))))
629 (if gnus-bookmark-bmenu-toggle-infos
630 (gnus-bookmark-bmenu-hide-infos))
632 (save-window-excursion
634 (forward-char gnus-bookmark-bmenu-bookmark-column
)
636 (buffer-substring-no-properties (point)
640 ;; well, this is certainly crystal-clear:
641 (if gnus-bookmark-bmenu-toggle-infos
642 (gnus-bookmark-bmenu-toggle-infos t
))))))
644 (defun gnus-bookmark-show-details (bookmark)
645 "Display the annotation for BOOKMARK in a buffer."
646 (let ((record (gnus-bookmark-get-bookmark-record bookmark
))
647 (old-buf (current-buffer))
648 (details gnus-bookmark-bookmark-details
)
651 (pop-to-buffer (get-buffer-create "*Gnus Bookmark Annotation*") t
)
654 (setq detail
(pop details
))
655 (unless (equal (cdr (assoc detail record
)) "")
656 (insert (symbol-name detail
) ": " (cdr (assoc detail record
)) "\n")))
657 (goto-char (point-min))
658 (pop-to-buffer old-buf
))))
660 (defun gnus-bookmark-bmenu-show-details ()
661 "Show the annotation for the current bookmark in another window."
663 (let ((bookmark (gnus-bookmark-bmenu-bookmark)))
664 (if (gnus-bookmark-bmenu-check-position)
665 (gnus-bookmark-show-details bookmark
))))
667 (defun gnus-bookmark-bmenu-mark ()
668 "Mark bookmark on this line to be displayed by \\<gnus-bookmark-bmenu-mode-map>\\[gnus-bookmark-bmenu-select]."
671 (if (gnus-bookmark-bmenu-check-position)
672 (let ((inhibit-read-only t
))
676 (gnus-bookmark-bmenu-check-position))))
678 (defun gnus-bookmark-bmenu-unmark (&optional backup
)
679 "Cancel all requested operations on bookmark on this line and move down.
680 Optional BACKUP means move up."
683 (if (gnus-bookmark-bmenu-check-position)
685 (let ((inhibit-read-only t
))
687 ;; any flags to reset according to circumstances? How about a
688 ;; flag indicating whether this bookmark is being visited?
689 ;; well, we don't have this now, so maybe later.
691 (forward-line (if backup -
1 1))
692 (gnus-bookmark-bmenu-check-position))))
694 (defun gnus-bookmark-bmenu-backup-unmark ()
695 "Move up and cancel all requested operations on bookmark on line above."
698 (if (gnus-bookmark-bmenu-check-position)
700 (gnus-bookmark-bmenu-unmark)
702 (gnus-bookmark-bmenu-check-position))))
704 (defun gnus-bookmark-bmenu-delete ()
705 "Mark Gnus bookmark on this line to be deleted.
706 To carry out the deletions that you've marked, use
707 \\<gnus-bookmark-bmenu-mode-map>\\[gnus-bookmark-bmenu-execute-deletions]."
710 (if (gnus-bookmark-bmenu-check-position)
711 (let ((inhibit-read-only t
))
715 (gnus-bookmark-bmenu-check-position))))
717 (defun gnus-bookmark-bmenu-delete-backwards ()
718 "Mark bookmark on this line to be deleted, then move up one line.
719 To carry out the deletions that you've marked, use
720 \\<gnus-bookmark-bmenu-mode-map>\\[gnus-bookmark-bmenu-execute-deletions]."
722 (gnus-bookmark-bmenu-delete)
724 (if (gnus-bookmark-bmenu-check-position)
726 (gnus-bookmark-bmenu-check-position))
728 (defun gnus-bookmark-bmenu-select ()
729 "Select this line's bookmark; also display bookmarks marked with `>'.
730 You can mark bookmarks with the
731 \\<gnus-bookmark-bmenu-mode-map>\\[gnus-bookmark-bmenu-mark]
734 (if (gnus-bookmark-bmenu-check-position)
735 (let ((bmrk (gnus-bookmark-bmenu-bookmark))
736 (menu (current-buffer)))
737 (goto-char (point-min))
738 (delete-other-windows)
739 (gnus-bookmark-jump bmrk
)
740 (bury-buffer menu
))))
742 (defun gnus-bookmark-bmenu-select-by-mouse (event)
744 (mouse-set-point event
)
745 (gnus-bookmark-bmenu-select))
747 (defun gnus-bookmark-bmenu-load ()
748 "Load the Gnus bookmark file and rebuild the bookmark menu-buffer."
750 (if (gnus-bookmark-bmenu-check-position)
752 (save-window-excursion
753 ;; This will call `gnus-bookmark-bmenu-list'
754 (call-interactively 'gnus-bookmark-load
)))))
756 (defun gnus-bookmark-bmenu-execute-deletions ()
757 "Delete Gnus bookmarks marked with \\<Buffer-menu-mode-map>\\[Buffer-menu-delete] commands."
759 (message "Deleting Gnus bookmarks...")
760 (let ((hide-em gnus-bookmark-bmenu-toggle-infos
)
762 (o-str (save-excursion
764 (if (looking-at "^D")
768 (progn (end-of-line) (point))))))
769 (o-col (current-column)))
770 (if hide-em
(gnus-bookmark-bmenu-hide-infos))
771 (setq gnus-bookmark-bmenu-toggle-infos nil
)
772 (goto-char (point-min))
774 (while (re-search-forward "^D" (point-max) t
)
775 (gnus-bookmark-delete (gnus-bookmark-bmenu-bookmark) t
)) ; pass BATCH arg
776 (gnus-bookmark-bmenu-list)
777 (setq gnus-bookmark-bmenu-toggle-infos hide-em
)
778 (if gnus-bookmark-bmenu-toggle-infos
779 (gnus-bookmark-bmenu-toggle-infos t
))
782 (goto-char (point-min))
783 (search-forward o-str
)
785 (forward-char o-col
))
788 (gnus-bookmark-write-file)
789 (message "Deleting bookmarks...done")))
791 (defun gnus-bookmark-delete (bookmark &optional batch
)
792 "Delete BOOKMARK from the bookmark list.
793 Removes only the first instance of a bookmark with that name. If
794 there are one or more other bookmarks with the same name, they will
795 not be deleted. Defaults to the \"current\" bookmark \(that is, the
796 one most recently used in this file, if any).
797 Optional second arg BATCH means don't update the bookmark list buffer,
798 probably because we were called from there."
799 (gnus-bookmark-maybe-load-default-file)
800 (let ((will-go (gnus-bookmark-get-bookmark bookmark
)))
801 (setq gnus-bookmark-alist
(delq will-go gnus-bookmark-alist
)))
802 ;; Don't rebuild the list
805 (gnus-bookmark-bmenu-surreptitiously-rebuild-list)))
807 (provide 'gnus-bookmark
)
809 ;;; gnus-bookmark.el ends here