1 ;;; gnus-bookmark.el --- Bookmarks in Gnus
3 ;; Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011
4 ;; Free Software Foundation, Inc.
6 ;; Author: Bastien Guerry <bzg AT altern DOT org>
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This file implements real bookmarks for Gnus, closely following the way
27 ;; `bookmark.el' handles bookmarks. Most of the code comes from
30 ;; Set a Gnus bookmark:
31 ;; M-x `gnus-bookmark-set' from the summary buffer.
33 ;; Jump to a Gnus bookmark:
34 ;; M-x `gnus-bookmark-jump'.
36 ;; Display a list of bookmarks
37 ;; M-x `gnus-bookmark-bmenu-list'.
42 ;; - add tags to bookmarks
43 ;; - don't write file each time a bookmark is created
44 ;; - better annotation interactive buffer
45 ;; - edit annotation in gnus-bookmark-bmenu
46 ;; - sort gnus-bookmark-buffer by author/subject/date/group/message-id
47 ;; - auto-bmk-name customizable format
48 ;; - renaming bookmarks in gnus-bookmark-bmenu-list
49 ;; - better (formatted string) display in bmenu-list
51 ;; - Integrate the `gnus-summary-*-bookmark' functionality
52 ;; - Initialize defcustoms from corresponding `bookmark.el' variables?
58 ;; FIXME: should avoid using C-c (no?)
59 ;; (define-key gnus-summary-mode-map "\C-crm" 'gnus-bookmark-set)
60 ;; (define-key global-map "\C-crb" 'gnus-bookmark-jump)
61 ;; (define-key global-map "\C-crj" 'gnus-bookmark-jump)
62 ;; (define-key global-map "\C-crl" 'gnus-bookmark-bmenu-list)
64 ;; FIXME: Add keybindings, see
65 ;; http://thread.gmane.org/gmane.emacs.gnus.general/63101/focus=63379
66 ;; http://thread.gmane.org/v9fxx9fkm4.fsf@marauder.physik.uni-ulm.de
68 ;; FIXME: Check if `gnus-bookmark.el' should use
69 ;; `bookmark-make-cell-function'.
70 ;; Cf. http://article.gmane.org/gmane.emacs.gnus.general/66076
72 (defgroup gnus-bookmark nil
73 "Setting, annotation and jumping to Gnus bookmarks."
76 (defcustom gnus-bookmark-default-file
78 ;; Backward compatibility with previous versions:
79 ((file-exists-p "~/.gnus.bmk") "~/.gnus.bmk")
80 (t (nnheader-concat gnus-directory "bookmarks.el")))
81 "The default Gnus bookmarks file."
83 :group 'gnus-bookmark)
85 (defcustom gnus-bookmark-file-coding-system
86 (if (mm-coding-system-p 'iso-2022-7bit)
88 "Coding system used for writing Gnus bookmark files."
89 :type '(symbol :tag "Coding system")
90 :group 'gnus-bookmark)
92 (defcustom gnus-bookmark-sort-flag t
93 "Non-nil means Gnus bookmarks are sorted by bookmark names.
94 Otherwise they will be displayed in LIFO order (that is,
95 most recently set ones come first, oldest ones come last)."
97 :group 'gnus-bookmark)
99 (defcustom gnus-bookmark-bmenu-toggle-infos t
100 "Non-nil means show details when listing Gnus bookmarks.
101 List of details is defined in `gnus-bookmark-bookmark-inline-details'.
102 This may result in truncated bookmark names. To disable this, put the
103 following in your `.emacs' file:
105 \(setq gnus-bookmark-bmenu-toggle-infos nil\)"
107 :group 'gnus-bookmark)
109 (defcustom gnus-bookmark-bmenu-file-column 30
110 "Column at which to display details in a buffer listing Gnus bookmarks.
111 You can toggle whether details are shown with \\<gnus-bookmark-bmenu-mode-map>\\[gnus-bookmark-bmenu-toggle-infos]."
113 :group 'gnus-bookmark)
115 (defcustom gnus-bookmark-use-annotations nil
116 "If non-nil, ask for an annotation when setting a bookmark."
118 :group 'gnus-bookmark)
120 (defcustom gnus-bookmark-bookmark-inline-details '(author)
121 "Details to be shown with `gnus-bookmark-bmenu-toggle-infos'.
122 The default value is \(subject\)."
123 :type '(list :tag "Gnus bookmark details"
125 (const :tag "Author" author)
126 (const :tag "Subject" subject)
127 (const :tag "Date" date)
128 (const :tag "Group" group)
129 (const :tag "Message-id" message-id)))
130 :group 'gnus-bookmark)
132 (defcustom gnus-bookmark-bookmark-details
133 '(author subject date group annotation)
134 "Details to be shown with `gnus-bookmark-bmenu-show-details'.
135 The default value is \(author subject date group annotation\)."
136 :type '(list :tag "Gnus bookmark details"
138 (const :tag "Author" author)
139 (const :tag "Subject" subject)
140 (const :tag "Date" date)
141 (const :tag "Group" group)
142 (const :tag "Message-id" message-id)
143 (const :tag "Annotation" annotation)))
144 :group 'gnus-bookmark)
146 (defface gnus-bookmark-menu-heading
147 '((t (:inherit font-lock-type-face)))
148 "Face used to highlight the heading in Gnus bookmark menu buffers."
149 :version "23.1" ;; No Gnus
150 :group 'gnus-bookmark)
152 (defconst gnus-bookmark-end-of-version-stamp-marker
153 "-*- End Of Bookmark File Format Version Stamp -*-\n"
154 "This string marks the end of the version stamp in a Gnus bookmark file.")
156 (defconst gnus-bookmark-file-format-version 0
157 "The current version of the format used by bookmark files.
158 You should never need to change this.")
160 (defvar gnus-bookmark-alist ()
161 "Association list of Gnus bookmarks and their records.
162 The format of the alist is
166 where each BMK is of the form
170 \(message-id . MESSAGE-ID\)
173 \(subject . SUBJECT\)
174 \(annotation . ANNOTATION\)\)
176 So the cdr of each bookmark is an alist too.")
178 (defmacro gnus-bookmark-mouse-available-p ()
179 "Return non-nil if a mouse is available."
180 (if (featurep 'xemacs)
181 '(device-on-window-system-p)
184 (defun gnus-bookmark-remove-properties (string)
185 "Remove all text properties from STRING."
186 (set-text-properties 0 (length string) nil string)
190 (defun gnus-bookmark-set ()
191 "Set a bookmark for this article."
193 (gnus-bookmark-maybe-load-default-file)
194 (if (or (not (eq major-mode 'gnus-summary-mode))
195 (not gnus-article-current))
196 (error "Please select an article in the Gnus summary buffer")
197 (let* ((group (car gnus-article-current))
198 (article (cdr gnus-article-current))
199 (header (gnus-summary-article-header article))
200 (author (mail-header-from header))
201 (message-id (mail-header-id header))
202 (date (mail-header-date header))
203 (subject (gnus-summary-subject-string))
204 (bmk-name (gnus-bookmark-set-bookmark-name group author subject))
205 ;; Maybe ask for annotation
207 (if gnus-bookmark-use-annotations
208 (read-from-minibuffer
209 (format "Annotation for %s: " bmk-name)) "")))
210 ;; Set the bookmark list