File: planner-bookmark.el

package info (click to toggle)
planner-el 3.42-4
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,972 kB
  • ctags: 1,261
  • sloc: lisp: 15,249; python: 218; makefile: 133; sh: 39
file content (118 lines) | stat: -rw-r--r-- 4,104 bytes parent folder | download | duplicates (2)
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
117
118
;;; planner-bookmark.el --- bookmark URL support for the Emacs planner
;;

;; Copyright (C) 2004, 2005, 2008 Dryice Dong Liu.  All rights reserved.
;; Parts copyright (C) 2005, 2008 Free Software Foundation, Inc.

;; Keywords: emacs planner bookmark remember note
;; Author: Dryice Liu <dryice AT liu DOT com DOT cn>
;; Description: use bookmark.el in Emacs planner

;; This file is part of Planner.  It is not part of GNU Emacs.

;; Planner 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, or (at your option)
;; any later version.

;; Planner 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 Planner; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

;;; Commentary:
;;
;; Place planner-bookmark.el in your load path and add this to your .emacs:
;;
;;    (require 'planner-bookmark)
;;
;; Annotations will be of the form
;; [[bookmark://bookmark-name][bookmark-description]]
;; bookmark-description will use bookmark-annotation if available,
;; else bookmark-name will be used.
;;
;; Note this file advice `bookmark-set'. If you don't want to take a
;; note everytime you set a bookmark, set
;; `planner-bookmark-take-note-after-set-bookmark-flag' to nil

;;; CODE

(require 'planner)
(require 'bookmark)

;;; User variables

;;; Code:

(defgroup planner-bookmark nil
  "Bookmark URL support for planner.el."
  :prefix "planner-bookmark"
  :group 'planner)

(defcustom planner-bookmark-take-note-after-set-bookmark-flag
  t
  "Non-nil means show a `remember' buffer after setting a new bookmark."
  :type 'boolean
  :group 'planner-bookmark)

(defcustom planner-bookmark-add-note-title-flag
  t
  "Non-nil means add the bookmark name as the default note title"
  :type 'boolean
  :group 'planner-bookmark)

;;;; User variables stop here

(defadvice bookmark-set (after planner-bookmark activate)
  "Display a `remember' buffer for the bookmark.
This code is run only if
`planner-bookmark-take-note-after-set-bookmark-flag' is non-nil."
  (if (and planner-bookmark-take-note-after-set-bookmark-flag
           (condition-case nil
               (require 'remember)
             ('file-error nil)))
      ;; bookmark can take us where we want. we don't need two URLs
      (let ((remember-annotation-functions nil))
        (remember (concat 
		   (if planner-bookmark-add-note-title-flag
		       bookmark-current-bookmark)
		   "\n\n" (planner-bookmark-make-url
			   bookmark-current-bookmark))))))

;;;###autoload
(defun planner-bookmark-annotation-from-bookmark ()
  "If called from a bookmark buffer, return an annotation.
Suitable for use in `planner-annotation-functions'."
  (if (and (eq major-mode 'bookmark-bmenu-mode)
	   (bookmark-bmenu-check-position))
      (planner-bookmark-make-url (bookmark-bmenu-bookmark))))

(defun planner-bookmark-make-url (bookmark-name)
  "Make the bookmark URL by given BOOKMARK-NAME."
  (let ((bookmark-annotation (bookmark-get-annotation bookmark-name)))
    (if (string-equal bookmark-annotation "")
	(setq bookmark-annotation nil))
    (planner-make-link
     (concat "bookmark://" bookmark-name)
     (or bookmark-annotation bookmark-name)
     t)))

;;;###autoload
(defun planner-bookmark-browse-url (url)
  "If this is a bookmark URL, jump to it."
  (when (string-match "\\`bookmark:/?/?\\(.+\\)" url)
    (bookmark-jump (match-string 1 url))
    t))

(planner-add-protocol "bookmark:/?/?" 'planner-bookmark-browse-url nil)
(add-hook 'planner-annotation-functions 'planner-bookmark-annotation-from-bookmark)
(custom-add-option 'planner-annotation-functions 'planner-bookmark-annotation-from-bookmark)

(provide 'planner-bookmark)

;;; planner-bookmark.el ends here