1 ;;; org-bookmark.el - Support for links to bookmark
2 ;; Copyright (C) 2008-2012 Free Software Foundation, Inc.
4 ;; Author: Tokuya Kameshima <kames AT fa2.so-net.ne.jp>
6 ;; Keywords: outlines, hypermedia, calendar, wp
8 ;; This file is not part of GNU Emacs.
10 ;; 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, or (at your option)
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; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
29 (defgroup org-bookmark nil
30 "Options concerning the bookmark link."
34 (defcustom org-bookmark-in-dired nil
35 "Use org-bookmark in dired."
39 (defcustom org-bookmark-when-visiting-a-file nil
40 "Use org-bookmark in any buffer visiting a file."
44 (defcustom org-bookmark-use-first-bookmark nil
45 "If several bookmarks links to the buffer, take the first one.
46 Otherwise prompt the user for the right bookmark to use."
50 (org-add-link-type "bookmark" 'org-bookmark-open
)
51 (add-hook 'org-store-link-functions
'org-bookmark-store-link
)
53 (defun org-bookmark-open (bookmark)
54 "Visit the bookmark BOOKMARK."
55 (bookmark-jump bookmark
))
57 (defun org-bookmark-store-link ()
58 "Store a link to the current line's bookmark in bookmark list."
59 (let (file bookmark bmks
)
60 (cond ((and org-bookmark-in-dired
61 (eq major-mode
'dired-mode
))
62 (setq file
(abbreviate-file-name (dired-get-filename))))
63 ((and org-bookmark-when-visiting-a-file
64 (buffer-file-name (buffer-base-buffer)))
65 (setq file
(abbreviate-file-name
66 (buffer-file-name (buffer-base-buffer))))))
68 (when (eq major-mode
'bookmark-bmenu-mode
)
69 (setq bookmark
(bookmark-bmenu-bookmark)))
71 (mapcar (lambda (name)
74 (bookmark-location name
)))
76 (bookmark-all-names)))
77 (setq bmks
(delete nil bmks
)))
79 (if (or (eq 1 (length bmks
)) org-bookmark-use-first-bookmark
)
81 (completing-read "Bookmark: " bmks nil t nil nil
(car bmks
))))))
83 (org-store-link-props :link
(org-make-link "bookmark:" bookmark
)
84 :description bookmark
))))
86 (provide 'org-bookmark
)
88 ;;; org-bookmark.el ends here