Suppress localized settings in Tramp test.
[emacs.git] / lisp / gnus / gnus-bookmark.el
blobe26c78b65c5dc1815e860a7c4155e4010547bc2d
1 ;;; gnus-bookmark.el --- Bookmarks in Gnus
3 ;; Copyright (C) 2006-2015 Free Software Foundation, Inc.
5 ;; Author: Bastien Guerry <bzg AT altern DOT org>
6 ;; Keywords: news
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 <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;; This file implements real bookmarks for Gnus, closely following the way
26 ;; `bookmark.el' handles bookmarks. Most of the code comes from
27 ;; `bookmark.el'.
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'.
39 ;;; Todo:
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?
53 ;;; Code:
55 (require 'gnus-sum)
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."
73 :group 'gnus)
75 (defcustom gnus-bookmark-default-file
76 (cond
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."
81 :type 'string
82 :group 'gnus-bookmark)
84 (defcustom gnus-bookmark-file-coding-system
85 (if (mm-coding-system-p 'iso-2022-7bit)
86 '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)."
95 :type 'boolean
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\)"
105 :type 'boolean
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]."
111 :type 'integer
112 :group 'gnus-bookmark)
114 (defcustom gnus-bookmark-use-annotations nil
115 "If non-nil, ask for an annotation when setting a bookmark."
116 :type 'boolean
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"
123 (set :inline t
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"
136 (set :inline t
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
163 \(BMK1 BMK2 ...\)
165 where each BMK is of the form
167 \(NAME
168 \(group . GROUP\)
169 \(message-id . MESSAGE-ID\)
170 \(author . AUTHOR\)
171 \(date . DATE\)
172 \(subject . SUBJECT\)
173 \(annotation . ANNOTATION\)\)
175 So the cdr of each bookmark is an alist too.")
177 (defmacro gnus-bookmark-mouse-available-p ()
178 "Return non-nil if a mouse is available."
179 (if (featurep 'xemacs)
180 '(device-on-window-system-p)
181 '(display-mouse-p)))
183 (defun gnus-bookmark-remove-properties (string)
184 "Remove all text properties from STRING."
185 (set-text-properties 0 (length string) nil string)
186 string)
188 ;;;###autoload
189 (defun gnus-bookmark-set ()
190 "Set a bookmark for this article."
191 (interactive)
192 (gnus-bookmark-maybe-load-default-file)
193 (if (or (not (derived-mode-p 'gnus-summary-mode))
194 (not gnus-article-current))
195 (error "Please select an article in the Gnus summary buffer")
196 (let* ((group (car gnus-article-current))
197 (article (cdr gnus-article-current))
198 (header (gnus-summary-article-header article))
199 (author (mail-header-from header))
200 (message-id (mail-header-id header))
201 (date (mail-header-date header))
202 (subject (gnus-summary-subject-string))
203 (bmk-name (gnus-bookmark-set-bookmark-name group author subject))
204 ;; Maybe ask for annotation
205 (annotation
206 (if gnus-bookmark-use-annotations
207 (read-from-minibuffer
208 (format "Annotation for %s: " bmk-name)) "")))
209 ;; Set the bookmark list
210 (setq gnus-bookmark-alist
211 (cons
212 (list (gnus-bookmark-remove-properties bmk-name)
213 (gnus-bookmark-make-record
214 group message-id author date subject annotation))
215 gnus-bookmark-alist))))
216 (gnus-bookmark-bmenu-surreptitiously-rebuild-list)
217 (gnus-bookmark-write-file))
219 (defun gnus-bookmark-make-record
220 (group message-id author date subject annotation)
221 "Return the record part of a new bookmark, given GROUP MESSAGE-ID AUTHOR DATE SUBJECT and ANNOTATION."
222 (let ((the-record
223 `((group . ,(gnus-bookmark-remove-properties group))
224 (message-id . ,(gnus-bookmark-remove-properties message-id))
225 (author . ,(gnus-bookmark-remove-properties author))
226 (date . ,(gnus-bookmark-remove-properties date))
227 (subject . ,(gnus-bookmark-remove-properties subject))
228 (annotation . ,(gnus-bookmark-remove-properties annotation)))))
229 the-record))
231 (defun gnus-bookmark-set-bookmark-name (group author subject)
232 "Set bookmark name from GROUP AUTHOR and SUBJECT."
233 (let* ((subject (split-string subject))
234 (default-name-0 ;; Should be merged with -1?
235 (concat (car (nreverse (delete "" (split-string group "[\\.:]"))))
236 "-" (car (split-string author))
237 "-" (car subject) "-" (cadr subject)))
238 (default-name-1
239 ;; Strip "[]" chars from the bookmark name:
240 (gnus-replace-in-string default-name-0 "[]_[]" ""))
241 (name (read-from-minibuffer
242 (format "Set bookmark (%s): " default-name-1)
243 nil nil nil nil
244 default-name-1)))
245 (if (string-equal name "")
246 default-name-1
247 name)))
249 (defun gnus-bookmark-write-file ()
250 "Write currently defined Gnus bookmarks into `gnus-bookmark-default-file'."
251 (interactive)
252 (save-excursion
253 (save-window-excursion
254 ;; Avoid warnings?
255 ;; (message "Saving Gnus bookmarks to file %s..." gnus-bookmark-default-file)
256 (set-buffer (get-buffer-create " *Gnus bookmarks*"))
257 (erase-buffer)
258 (gnus-bookmark-insert-file-format-version-stamp)
259 (pp gnus-bookmark-alist (current-buffer))
260 (condition-case nil
261 (let ((coding-system-for-write gnus-bookmark-file-coding-system))
262 (write-region (point-min) (point-max)
263 gnus-bookmark-default-file))
264 (file-error (message "Can't write %s"
265 gnus-bookmark-default-file)))
266 (kill-buffer (current-buffer))
267 (message
268 "Saving Gnus bookmarks to file %s...done"
269 gnus-bookmark-default-file))))
271 (defun gnus-bookmark-insert-file-format-version-stamp ()
272 "Insert text indicating current version of Gnus bookmark file format."
273 (insert
274 (format ";;;; Gnus Bookmark Format Version %d %s;;;;\n"
275 gnus-bookmark-file-format-version
276 (if gnus-bookmark-file-coding-system
277 (concat "-*- coding: "
278 (symbol-name gnus-bookmark-file-coding-system)
279 "; -*- ")
280 "")))
281 (insert ";;; This format is meant to be slightly human-readable;\n"
282 ";;; nevertheless, you probably don't want to edit it.\n"
283 ";;; "
284 gnus-bookmark-end-of-version-stamp-marker))
286 ;;;###autoload
287 (defun gnus-bookmark-jump (&optional bmk-name)
288 "Jump to a Gnus bookmark (BMK-NAME)."
289 (interactive)
290 (gnus-bookmark-maybe-load-default-file)
291 (let* ((bookmark (or bmk-name
292 (gnus-completing-read "Jump to bookmarked article"
293 (mapcar 'car gnus-bookmark-alist))))
294 (bmk-record (cadr (assoc bookmark gnus-bookmark-alist)))
295 (group (cdr (assoc 'group bmk-record)))
296 (message-id (cdr (assoc 'message-id bmk-record))))
297 (when group
298 (unless (get-buffer gnus-group-buffer)
299 (gnus-no-server))
300 (gnus-activate-group group)
301 (gnus-group-quick-select-group 0 group))
302 (if message-id
303 (or (gnus-summary-goto-article message-id nil 'force)
304 (if (fboundp 'gnus-summary-insert-cached-articles)
305 (progn
306 (gnus-summary-insert-cached-articles)
307 (gnus-summary-goto-article message-id nil 'force))
308 (message "Message could not be found."))))))
310 (defvar gnus-bookmark-already-loaded nil)
312 (defun gnus-bookmark-alist-from-buffer ()
313 "Return a `gnus-bookmark-alist' from the current buffer.
314 The buffer must of course contain Gnus bookmark format information.
315 Does not care from where in the buffer it is called, and does not
316 affect point."
317 (save-excursion
318 (goto-char (point-min))
319 (if (search-forward
320 gnus-bookmark-end-of-version-stamp-marker nil t)
321 (read (current-buffer))
322 ;; Else no hope of getting information here.
323 (error "Not Gnus bookmark format"))))
325 (defun gnus-bookmark-load (file)
326 "Load Gnus bookmarks from FILE (which must be in bookmark format)."
327 (interactive
328 (list (read-file-name
329 (format "Load Gnus bookmarks from: (%s) "
330 gnus-bookmark-default-file)
331 "~/" gnus-bookmark-default-file 'confirm)))
332 (setq file (expand-file-name file))
333 (if (file-readable-p file)
334 (save-excursion
335 (save-window-excursion
336 (set-buffer (let ((enable-local-variables nil))
337 (find-file-noselect file)))
338 (goto-char (point-min))
339 (let ((blist (gnus-bookmark-alist-from-buffer)))
340 (if (listp blist)
341 (progn (setq gnus-bookmark-already-loaded t)
342 (setq gnus-bookmark-alist blist))
343 (error "Not Gnus bookmark format")))))))
345 (defun gnus-bookmark-maybe-load-default-file ()
346 "Maybe load Gnus bookmarks in `gnus-bookmark-alist'."
347 (and (not gnus-bookmark-already-loaded)
348 (null gnus-bookmark-alist)
349 (file-readable-p (expand-file-name gnus-bookmark-default-file))
350 (gnus-bookmark-load gnus-bookmark-default-file)))
352 (defun gnus-bookmark-maybe-sort-alist ()
353 "Return the gnus-bookmark-alist for display.
354 If the gnus-bookmark-sort-flag is non-nil, then return a sorted
355 copy of the alist."
356 (when gnus-bookmark-sort-flag
357 (setq gnus-bookmark-alist
358 (sort (copy-alist gnus-bookmark-alist)
359 (function
360 (lambda (x y) (string-lessp (car x) (car y))))))))
362 ;;;###autoload
363 (defun gnus-bookmark-bmenu-list ()
364 "Display a list of existing Gnus bookmarks.
365 The list is displayed in a buffer named `*Gnus Bookmark List*'.
366 The leftmost column displays a D if the bookmark is flagged for
367 deletion, or > if it is flagged for displaying."
368 (interactive)
369 (gnus-bookmark-maybe-load-default-file)
370 (if (gmm-called-interactively-p 'any)
371 (switch-to-buffer (get-buffer-create "*Gnus Bookmark List*"))
372 (set-buffer (get-buffer-create "*Gnus Bookmark List*")))
373 (let ((inhibit-read-only t)
374 alist name start end)
375 (erase-buffer)
376 (insert "% Gnus Bookmark\n- --------\n")
377 (add-text-properties (point-min) (point)
378 '(font-lock-face gnus-bookmark-menu-heading))
379 ;; sort before displaying
380 (gnus-bookmark-maybe-sort-alist)
381 ;; Display gnus bookmarks
382 (setq alist gnus-bookmark-alist)
383 (while alist
384 (setq name (gnus-bookmark-name-from-full-record (pop alist)))
385 ;; if a Gnus bookmark has an annotation, prepend a "*"
386 ;; in the list of bookmarks.
387 (insert (if (member (gnus-bookmark-get-annotation name) (list nil ""))
389 " *"))
390 (if (gnus-bookmark-mouse-available-p)
391 (add-text-properties
392 (prog1
393 (point)
394 (insert name))
395 (let ((end (point)))
396 (prog2
397 (re-search-backward "[^ \t]")
398 (1+ (point))
399 (goto-char end)
400 (insert "\n")))
401 `(mouse-face highlight follow-link t
402 help-echo ,(format "%s: go to this article"
403 (aref gnus-mouse-2 0))))
404 (insert name "\n")))
405 (goto-char (point-min))
406 (forward-line 2)
407 (gnus-bookmark-bmenu-mode)
408 (if gnus-bookmark-bmenu-toggle-infos
409 (gnus-bookmark-bmenu-toggle-infos t))))
411 (defun gnus-bookmark-bmenu-surreptitiously-rebuild-list ()
412 "Rebuild the Bookmark List if it exists.
413 Don't affect the buffer ring order."
414 (if (get-buffer "*Gnus Bookmark List*")
415 (save-excursion
416 (save-window-excursion
417 (gnus-bookmark-bmenu-list)))))
419 (defun gnus-bookmark-get-annotation (bookmark)
420 "Return the annotation of Gnus BOOKMARK, or nil if none."
421 (cdr (assq 'annotation (gnus-bookmark-get-bookmark-record bookmark))))
423 (defun gnus-bookmark-get-bookmark (bookmark)
424 "Return the full entry for Gnus BOOKMARK in `gnus-bookmark-alist'.
425 If BOOKMARK is not a string, return nil."
426 (when (stringp bookmark)
427 (assoc bookmark gnus-bookmark-alist)))
429 (defun gnus-bookmark-get-bookmark-record (bookmark)
430 "Return the guts of the entry for Gnus BOOKMARK in `gnus-bookmark-alist'.
431 That is, all information but the name."
432 (car (cdr (gnus-bookmark-get-bookmark bookmark))))
434 (defun gnus-bookmark-name-from-full-record (full-record)
435 "Return name of FULL-RECORD \(an alist element instead of a string\)."
436 (car full-record))
438 (defvar gnus-bookmark-bmenu-bookmark-column nil)
439 (defvar gnus-bookmark-bmenu-hidden-bookmarks ())
440 (defvar gnus-bookmark-bmenu-mode-map nil)
442 (if gnus-bookmark-bmenu-mode-map
444 (setq gnus-bookmark-bmenu-mode-map (make-keymap))
445 (suppress-keymap gnus-bookmark-bmenu-mode-map t)
446 (define-key gnus-bookmark-bmenu-mode-map "q" (if (fboundp 'quit-window)
447 'quit-window
448 'bury-buffer))
449 (define-key gnus-bookmark-bmenu-mode-map "\C-m" 'gnus-bookmark-bmenu-select)
450 (define-key gnus-bookmark-bmenu-mode-map "v" 'gnus-bookmark-bmenu-select)
451 (define-key gnus-bookmark-bmenu-mode-map "d" 'gnus-bookmark-bmenu-delete)
452 (define-key gnus-bookmark-bmenu-mode-map "k" 'gnus-bookmark-bmenu-delete)
453 (define-key gnus-bookmark-bmenu-mode-map "\C-d" 'gnus-bookmark-bmenu-delete-backwards)
454 (define-key gnus-bookmark-bmenu-mode-map "x" 'gnus-bookmark-bmenu-execute-deletions)
455 (define-key gnus-bookmark-bmenu-mode-map " " 'next-line)
456 (define-key gnus-bookmark-bmenu-mode-map "n" 'next-line)
457 (define-key gnus-bookmark-bmenu-mode-map "p" 'previous-line)
458 (define-key gnus-bookmark-bmenu-mode-map "\177" 'gnus-bookmark-bmenu-backup-unmark)
459 (define-key gnus-bookmark-bmenu-mode-map "?" 'describe-mode)
460 (define-key gnus-bookmark-bmenu-mode-map "u" 'gnus-bookmark-bmenu-unmark)
461 (define-key gnus-bookmark-bmenu-mode-map "m" 'gnus-bookmark-bmenu-mark)
462 (define-key gnus-bookmark-bmenu-mode-map "l" 'gnus-bookmark-bmenu-load)
463 (define-key gnus-bookmark-bmenu-mode-map "s" 'gnus-bookmark-bmenu-save)
464 (define-key gnus-bookmark-bmenu-mode-map "t" 'gnus-bookmark-bmenu-toggle-infos)
465 (define-key gnus-bookmark-bmenu-mode-map "a" 'gnus-bookmark-bmenu-show-details)
466 (define-key gnus-bookmark-bmenu-mode-map gnus-mouse-2
467 'gnus-bookmark-bmenu-select-by-mouse))
469 ;; Bookmark Buffer Menu mode is suitable only for specially formatted
470 ;; data.
471 (put 'gnus-bookmark-bmenu-mode 'mode-class 'special)
473 ;; Been to lazy to use gnus-bookmark-save...
474 (defalias 'gnus-bookmark-bmenu-save 'gnus-bookmark-write-file)
476 (define-derived-mode gnus-bookmark-bmenu-mode fundamental-mode "Bookmark Menu"
477 "Major mode for editing a list of Gnus bookmarks.
478 Each line describes one of the bookmarks in Gnus.
479 Letters do not insert themselves; instead, they are commands.
480 Gnus bookmarks names preceded by a \"*\" have annotations.
481 \\<gnus-bookmark-bmenu-mode-map>
482 \\[gnus-bookmark-bmenu-mark] -- mark bookmark to be displayed.
483 \\[gnus-bookmark-bmenu-select] -- select bookmark of line point is on.
484 Also show bookmarks marked using m in other windows.
485 \\[gnus-bookmark-bmenu-toggle-infos] -- toggle displaying of details (they may obscure long bookmark names).
486 \\[gnus-bookmark-bmenu-locate] -- display (in minibuffer) location of this bookmark.
487 \\[gnus-bookmark-bmenu-rename] -- rename this bookmark \(prompts for new name\).
488 \\[gnus-bookmark-bmenu-delete] -- mark this bookmark to be deleted, and move down.
489 \\[gnus-bookmark-bmenu-delete-backwards] -- mark this bookmark to be deleted, and move up.
490 \\[gnus-bookmark-bmenu-execute-deletions] -- delete bookmarks marked with `\\[gnus-bookmark-bmenu-delete]'.
491 \\[gnus-bookmark-bmenu-load] -- load in a file of bookmarks (prompts for file.)
492 \\[gnus-bookmark-bmenu-save] -- load in a file of bookmarks (prompts for file.)
493 \\[gnus-bookmark-bmenu-unmark] -- remove all kinds of marks from current line.
494 With prefix argument, also move up one line.
495 \\[gnus-bookmark-bmenu-backup-unmark] -- back up a line and remove marks.
496 \\[gnus-bookmark-bmenu-show-details] -- show the annotation, if it exists, for the current bookmark
497 in another buffer.
498 \\[gnus-bookmark-bmenu-show-all-annotations] -- show the annotations of all bookmarks in another buffer.
499 \\[gnus-bookmark-bmenu-edit-annotation] -- edit the annotation for the current bookmark."
500 (setq truncate-lines t)
501 (setq buffer-read-only t))
503 ;; avoid compilation warnings
504 (defvar gnus-bookmark-bmenu-toggle-infos nil)
506 (defun gnus-bookmark-bmenu-toggle-infos (&optional show)
507 "Toggle whether details are shown in the Gnus bookmark list.
508 Optional argument SHOW means show them unconditionally."
509 (interactive)
510 (cond
511 (show
512 (setq gnus-bookmark-bmenu-toggle-infos nil)
513 (gnus-bookmark-bmenu-show-infos)
514 (setq gnus-bookmark-bmenu-toggle-infos t))
515 (gnus-bookmark-bmenu-toggle-infos
516 (gnus-bookmark-bmenu-hide-infos)
517 (setq gnus-bookmark-bmenu-toggle-infos nil))
519 (gnus-bookmark-bmenu-show-infos)
520 (setq gnus-bookmark-bmenu-toggle-infos t))))
522 (defun gnus-bookmark-bmenu-show-infos (&optional force)
523 "Show infos in bmenu, maybe FORCE display of infos."
524 (if (and (not force) gnus-bookmark-bmenu-toggle-infos)
525 nil ;already shown, so do nothing
526 (save-excursion
527 (save-window-excursion
528 (goto-char (point-min))
529 (forward-line 2)
530 (setq gnus-bookmark-bmenu-hidden-bookmarks ())
531 (let ((inhibit-read-only t))
532 (while (< (point) (point-max))
533 (let ((bmrk (gnus-bookmark-bmenu-bookmark)))
534 (setq gnus-bookmark-bmenu-hidden-bookmarks
535 (cons bmrk gnus-bookmark-bmenu-hidden-bookmarks))
536 (let ((start (point-at-eol)))
537 (move-to-column gnus-bookmark-bmenu-file-column t)
538 ;; Strip off `mouse-face' from the white spaces region.
539 (if (gnus-bookmark-mouse-available-p)
540 (remove-text-properties start (point)
541 '(mouse-face nil help-echo nil))))
542 (delete-region (point) (progn (end-of-line) (point)))
543 (insert " ")
544 ;; Pass the NO-HISTORY arg:
545 (gnus-bookmark-insert-details bmrk)
546 (forward-line 1))))))))
548 (defun gnus-bookmark-insert-details (bmk-name)
549 "Insert the details of the article associated with BMK-NAME."
550 (let ((start (point)))
551 (prog1
552 (insert (gnus-bookmark-get-details
553 bmk-name
554 gnus-bookmark-bookmark-inline-details))
555 (if (gnus-bookmark-mouse-available-p)
556 (add-text-properties
557 start
558 (save-excursion (re-search-backward
559 "[^ \t]")
560 (1+ (point)))
561 `(mouse-face highlight
562 follow-link t
563 help-echo ,(format "%s: go to this article"
564 (aref gnus-mouse-2 0))))))))
566 (defun gnus-bookmark-kill-line (&optional newline-too)
567 "Kill from point to end of line.
568 If optional arg NEWLINE-TOO is non-nil, delete the newline too.
569 Does not affect the kill ring."
570 (delete-region (point) (point-at-eol))
571 (if (and newline-too (looking-at "\n"))
572 (delete-char 1)))
574 (defun gnus-bookmark-get-details (bmk-name details-list)
575 "Get details for a Gnus BMK-NAME depending on DETAILS-LIST."
576 (let ((details (cadr (assoc bmk-name gnus-bookmark-alist))))
577 (mapconcat
578 (lambda (info)
579 (cdr (assoc info details)))
580 details-list " | ")))
582 (defun gnus-bookmark-bmenu-hide-infos (&optional force)
583 "Hide infos in bmenu, maybe FORCE."
584 (if (and (not force) gnus-bookmark-bmenu-toggle-infos)
585 ;; nothing to hide if above is nil
586 (save-excursion
587 (save-window-excursion
588 (goto-char (point-min))
589 (forward-line 2)
590 (setq gnus-bookmark-bmenu-hidden-bookmarks
591 (nreverse gnus-bookmark-bmenu-hidden-bookmarks))
592 (save-excursion
593 (goto-char (point-min))
594 (search-forward "Gnus Bookmark")
595 (backward-word 2)
596 (setq gnus-bookmark-bmenu-bookmark-column (current-column)))
597 (save-excursion
598 (let ((inhibit-read-only t))
599 (while gnus-bookmark-bmenu-hidden-bookmarks
600 (move-to-column gnus-bookmark-bmenu-bookmark-column t)
601 (gnus-bookmark-kill-line)
602 (let ((start (point)))
603 (insert (car gnus-bookmark-bmenu-hidden-bookmarks))
604 (if (gnus-bookmark-mouse-available-p)
605 (add-text-properties
606 start
607 (save-excursion (re-search-backward
608 "[^ \t]")
609 (1+ (point)))
610 `(mouse-face highlight
611 follow-link t
612 help-echo
613 ,(format "%s: go to this bookmark in other window"
614 (aref gnus-mouse-2 0))))))
615 (setq gnus-bookmark-bmenu-hidden-bookmarks
616 (cdr gnus-bookmark-bmenu-hidden-bookmarks))
617 (forward-line 1))))))))
619 (defun gnus-bookmark-bmenu-check-position ()
620 "Return non-nil if on a line with a bookmark.
621 The actual value returned is gnus-bookmark-alist. Else
622 reposition and try again, else return nil."
623 (cond ((< (count-lines (point-min) (point)) 2)
624 (goto-char (point-min))
625 (forward-line 2)
626 gnus-bookmark-alist)
627 ((and (bolp) (eobp))
628 (beginning-of-line 0)
629 gnus-bookmark-alist)
631 gnus-bookmark-alist)))
633 (defun gnus-bookmark-bmenu-bookmark ()
634 "Return a string which is bookmark of this line."
635 (if (gnus-bookmark-bmenu-check-position)
636 (save-excursion
637 (save-window-excursion
638 (goto-char (point-min))
639 (search-forward "Gnus Bookmark")
640 (backward-word 2)
641 (setq gnus-bookmark-bmenu-bookmark-column (current-column)))))
642 (if gnus-bookmark-bmenu-toggle-infos
643 (gnus-bookmark-bmenu-hide-infos))
644 (save-excursion
645 (save-window-excursion
646 (beginning-of-line)
647 (forward-char gnus-bookmark-bmenu-bookmark-column)
648 (prog1
649 (buffer-substring-no-properties (point)
650 (progn
651 (end-of-line)
652 (point)))
653 ;; well, this is certainly crystal-clear:
654 (if gnus-bookmark-bmenu-toggle-infos
655 (gnus-bookmark-bmenu-toggle-infos t))))))
657 (defun gnus-bookmark-show-details (bookmark)
658 "Display the annotation for BOOKMARK in a buffer."
659 (let ((record (gnus-bookmark-get-bookmark-record bookmark))
660 (old-buf (current-buffer))
661 (details gnus-bookmark-bookmark-details)
662 detail)
663 (save-excursion
664 (pop-to-buffer (get-buffer-create "*Gnus Bookmark Annotation*") t)
665 (erase-buffer)
666 (while details
667 (setq detail (pop details))
668 (unless (equal (cdr (assoc detail record)) "")
669 (insert (symbol-name detail) ": " (cdr (assoc detail record)) "\n")))
670 (goto-char (point-min))
671 (pop-to-buffer old-buf))))
673 (defun gnus-bookmark-bmenu-show-details ()
674 "Show the annotation for the current bookmark in another window."
675 (interactive)
676 (let ((bookmark (gnus-bookmark-bmenu-bookmark)))
677 (if (gnus-bookmark-bmenu-check-position)
678 (gnus-bookmark-show-details bookmark))))
680 (defun gnus-bookmark-bmenu-mark ()
681 "Mark bookmark on this line to be displayed by \\<gnus-bookmark-bmenu-mode-map>\\[gnus-bookmark-bmenu-select]."
682 (interactive)
683 (beginning-of-line)
684 (if (gnus-bookmark-bmenu-check-position)
685 (let ((inhibit-read-only t))
686 (delete-char 1)
687 (insert ?>)
688 (forward-line 1)
689 (gnus-bookmark-bmenu-check-position))))
691 (defun gnus-bookmark-bmenu-unmark (&optional backup)
692 "Cancel all requested operations on bookmark on this line and move down.
693 Optional BACKUP means move up."
694 (interactive "P")
695 (beginning-of-line)
696 (if (gnus-bookmark-bmenu-check-position)
697 (progn
698 (let ((inhibit-read-only t))
699 (delete-char 1)
700 ;; any flags to reset according to circumstances? How about a
701 ;; flag indicating whether this bookmark is being visited?
702 ;; well, we don't have this now, so maybe later.
703 (insert " "))
704 (forward-line (if backup -1 1))
705 (gnus-bookmark-bmenu-check-position))))
707 (defun gnus-bookmark-bmenu-backup-unmark ()
708 "Move up and cancel all requested operations on bookmark on line above."
709 (interactive)
710 (forward-line -1)
711 (if (gnus-bookmark-bmenu-check-position)
712 (progn
713 (gnus-bookmark-bmenu-unmark)
714 (forward-line -1)
715 (gnus-bookmark-bmenu-check-position))))
717 (defun gnus-bookmark-bmenu-delete ()
718 "Mark Gnus bookmark on this line to be deleted.
719 To carry out the deletions that you've marked, use
720 \\<gnus-bookmark-bmenu-mode-map>\\[gnus-bookmark-bmenu-execute-deletions]."
721 (interactive)
722 (beginning-of-line)
723 (if (gnus-bookmark-bmenu-check-position)
724 (let ((inhibit-read-only t))
725 (delete-char 1)
726 (insert ?D)
727 (forward-line 1)
728 (gnus-bookmark-bmenu-check-position))))
730 (defun gnus-bookmark-bmenu-delete-backwards ()
731 "Mark bookmark on this line to be deleted, then move up one line.
732 To carry out the deletions that you've marked, use
733 \\<gnus-bookmark-bmenu-mode-map>\\[gnus-bookmark-bmenu-execute-deletions]."
734 (interactive)
735 (gnus-bookmark-bmenu-delete)
736 (forward-line -2)
737 (if (gnus-bookmark-bmenu-check-position)
738 (forward-line 1))
739 (gnus-bookmark-bmenu-check-position))
741 (defun gnus-bookmark-bmenu-select ()
742 "Select this line's bookmark; also display bookmarks marked with `>'.
743 You can mark bookmarks with the
744 \\<gnus-bookmark-bmenu-mode-map>\\[gnus-bookmark-bmenu-mark]
745 command."
746 (interactive)
747 (if (gnus-bookmark-bmenu-check-position)
748 (let ((bmrk (gnus-bookmark-bmenu-bookmark))
749 (menu (current-buffer)))
750 (goto-char (point-min))
751 (delete-other-windows)
752 (gnus-bookmark-jump bmrk)
753 (bury-buffer menu))))
755 (defun gnus-bookmark-bmenu-select-by-mouse (event)
756 (interactive "e")
757 (mouse-set-point event)
758 (gnus-bookmark-bmenu-select))
760 (defun gnus-bookmark-bmenu-load ()
761 "Load the Gnus bookmark file and rebuild the bookmark menu-buffer."
762 (interactive)
763 (if (gnus-bookmark-bmenu-check-position)
764 (save-excursion
765 (save-window-excursion
766 ;; This will call `gnus-bookmark-bmenu-list'
767 (call-interactively 'gnus-bookmark-load)))))
769 (defun gnus-bookmark-bmenu-execute-deletions ()
770 "Delete Gnus bookmarks marked with \\<Buffer-menu-mode-map>\\[Buffer-menu-delete] commands."
771 (interactive)
772 (message "Deleting Gnus bookmarks...")
773 (let ((hide-em gnus-bookmark-bmenu-toggle-infos)
774 (o-point (point))
775 (o-str (save-excursion
776 (beginning-of-line)
777 (if (looking-at "^D")
779 (buffer-substring
780 (point)
781 (progn (end-of-line) (point))))))
782 (o-col (current-column)))
783 (if hide-em (gnus-bookmark-bmenu-hide-infos))
784 (setq gnus-bookmark-bmenu-toggle-infos nil)
785 (goto-char (point-min))
786 (forward-line 1)
787 (while (re-search-forward "^D" (point-max) t)
788 (gnus-bookmark-delete (gnus-bookmark-bmenu-bookmark) t)) ; pass BATCH arg
789 (gnus-bookmark-bmenu-list)
790 (setq gnus-bookmark-bmenu-toggle-infos hide-em)
791 (if gnus-bookmark-bmenu-toggle-infos
792 (gnus-bookmark-bmenu-toggle-infos t))
793 (if o-str
794 (progn
795 (goto-char (point-min))
796 (search-forward o-str)
797 (beginning-of-line)
798 (forward-char o-col))
799 (goto-char o-point))
800 (beginning-of-line)
801 (gnus-bookmark-write-file)
802 (message "Deleting bookmarks...done")))
804 (defun gnus-bookmark-delete (bookmark &optional batch)
805 "Delete BOOKMARK from the bookmark list.
806 Removes only the first instance of a bookmark with that name. If
807 there are one or more other bookmarks with the same name, they will
808 not be deleted. Defaults to the \"current\" bookmark \(that is, the
809 one most recently used in this file, if any\).
810 Optional second arg BATCH means don't update the bookmark list buffer,
811 probably because we were called from there."
812 (gnus-bookmark-maybe-load-default-file)
813 (let ((will-go (gnus-bookmark-get-bookmark bookmark)))
814 (setq gnus-bookmark-alist (delq will-go gnus-bookmark-alist)))
815 ;; Don't rebuild the list
816 (if batch
818 (gnus-bookmark-bmenu-surreptitiously-rebuild-list)))
820 (provide 'gnus-bookmark)
822 ;;; gnus-bookmark.el ends here