1 ;;; org-bookmark.el - Support for links to bookmark
2 ;; Copyright (C) 2008-2017 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 ;; This program 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-link-set-parameters "bookmark"
51 :follow
#'org-bookmark-open
52 :store
#'org-bookmark-store-link
)
54 (defun org-bookmark-open (bookmark)
55 "Visit the bookmark BOOKMARK."
56 (bookmark-jump bookmark
))
58 (defun org-bookmark-store-link ()
59 "Store a link to the current line's bookmark in bookmark list."
60 (let (file bookmark bmks
)
61 (cond ((and org-bookmark-in-dired
62 (eq major-mode
'dired-mode
))
63 (setq file
(abbreviate-file-name (dired-get-filename))))
64 ((and org-bookmark-when-visiting-a-file
65 (buffer-file-name (buffer-base-buffer)))
66 (setq file
(abbreviate-file-name
67 (buffer-file-name (buffer-base-buffer))))))
69 (when (eq major-mode
'bookmark-bmenu-mode
)
70 (setq bookmark
(bookmark-bmenu-bookmark)))
72 (mapcar (lambda (name)
75 (bookmark-location name
)))
77 (bookmark-all-names)))
78 (setq bmks
(delete nil bmks
)))
80 (if (or (eq 1 (length bmks
)) org-bookmark-use-first-bookmark
)
82 (completing-read "Bookmark: " bmks nil t nil nil
(car bmks
))))))
84 (org-store-link-props :link
(concat "bookmark:" bookmark
)
85 :description bookmark
))))
87 (provide 'org-bookmark
)
89 ;;; org-bookmark.el ends here