Mention Emacs Muse in README.
[planner-el.git] / planner-bookmark.el
blob43fa1fa2f210c7bf80b5601f81b40bac86f54c87
1 ;;; planner-bookmark.el --- bookmark URL support for the Emacs planner
2 ;;
4 ;; Copyright (C) 2004, 2005 Dryice Dong Liu. All rights reserved.
5 ;; Parts copyright (C) 2005 Free Software Foundation, Inc.
7 ;; Keywords: emacs planner bookmark remember note
8 ;; Author: Dryice Liu <dryice AT liu DOT com DOT cn>
9 ;; Description: use bookmark.el in Emacs planner
11 ;; This file is part of Planner. It is not part of GNU Emacs.
13 ;; Planner is free software; you can redistribute it and/or modify it
14 ;; under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; any later version.
18 ;; Planner is distributed in the hope that it will be useful, but
19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 ;; General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with Planner; see the file COPYING. If not, write to the
25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26 ;; Boston, MA 02110-1301, USA.
28 ;;; Commentary:
30 ;; Place planner-bookmark.el in your load path and add this to your .emacs:
32 ;; (require 'planner-bookmark)
34 ;; Annotations will be of the form
35 ;; [[bookmark://bookmark-name][bookmark-description]]
36 ;; bookmark-description will use bookmark-annotation if available,
37 ;; else bookmark-name will be used.
39 ;; Note this file advice `bookmark-set'. If you don't want to take a
40 ;; note everytime you set a bookmark, set
41 ;; `planner-bookmark-take-note-after-set-bookmark-flag' to nil
43 ;;; CODE
45 (require 'planner)
46 (require 'bookmark)
48 ;;; User variables
50 ;;; Code:
52 (defgroup planner-bookmark nil
53 "Bookmark URL support for planner.el."
54 :prefix "planner-bookmark"
55 :group 'planner)
57 (defcustom planner-bookmark-take-note-after-set-bookmark-flag
59 "Non-nil means show a `remember' buffer after setting a new bookmark."
60 :type 'boolean
61 :group 'planner-bookmark)
63 (defcustom planner-bookmark-add-note-title-flag
65 "Non-nil means add the bookmark name as the default note title"
66 :type 'boolean
67 :group 'planner-bookmark)
69 ;;;; User variables stop here
71 (defadvice bookmark-set (after planner-bookmark activate)
72 "Display a `remember' buffer for the bookmark.
73 This code is run only if
74 `planner-bookmark-take-note-after-set-bookmark-flag' is non-nil."
75 (if (and planner-bookmark-take-note-after-set-bookmark-flag
76 (condition-case nil
77 (require 'remember)
78 ('file-error nil)))
79 ;; bookmark can take us where we want. we don't need two URLs
80 (let ((remember-annotation-functions nil))
81 (remember (concat
82 (if planner-bookmark-add-note-title-flag
83 bookmark-current-bookmark)
84 "\n\n" (planner-bookmark-make-url
85 bookmark-current-bookmark))))))
87 ;;;###autoload
88 (defun planner-bookmark-annotation-from-bookmark ()
89 "If called from a bookmark buffer, return an annotation.
90 Suitable for use in `planner-annotation-functions'."
91 (if (and (eq major-mode 'bookmark-bmenu-mode)
92 (bookmark-bmenu-check-position))
93 (planner-bookmark-make-url (bookmark-bmenu-bookmark))))
95 (defun planner-bookmark-make-url (bookmark-name)
96 "Make the bookmark URL by given BOOKMARK-NAME."
97 (let ((bookmark-annotation (bookmark-get-annotation bookmark-name)))
98 (if (string-equal bookmark-annotation "")
99 (setq bookmark-annotation nil))
100 (planner-make-link
101 (concat "bookmark://" bookmark-name)
102 (or bookmark-annotation bookmark-name)
103 t)))
105 ;;;###autoload
106 (defun planner-bookmark-browse-url (url)
107 "If this is a bookmark URL, jump to it."
108 (when (string-match "\\`bookmark:/?/?\\(.+\\)" url)
109 (bookmark-jump (match-string 1 url))
112 (planner-add-protocol "bookmark:/?/?" 'planner-bookmark-browse-url nil)
113 (add-hook 'planner-annotation-functions 'planner-bookmark-annotation-from-bookmark)
114 (custom-add-option 'planner-annotation-functions 'planner-bookmark-annotation-from-bookmark)
116 (provide 'planner-bookmark)
118 ;;; planner-bookmark.el ends here