doc: Fix pdflayout.sty to produce orgcard_letter.pdf correctly.
[org-mode/org-mode-NeilSmithlineMods.git] / contrib / lisp / org-bookmark.el
blobe57b2e6b81f48aea0e45f382889e76a60f4fa142
1 ;;; org-bookmark.el - Support for links to bookmark
2 ;; Copyright (C) 2008-2012 Free Software Foundation, Inc.
3 ;;
4 ;; Author: Tokuya Kameshima <kames AT fa2.so-net.ne.jp>
5 ;; Version: 1.0
6 ;; Keywords: outlines, hypermedia, calendar, wp
7 ;;
8 ;; This file is not part of GNU Emacs.
9 ;;
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)
13 ;; any later version.
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 (require 'org)
27 (require 'bookmark)
29 (defgroup org-bookmark nil
30 "Options concerning the bookmark link."
31 :tag "Org Startup"
32 :group 'org-link)
34 (defcustom org-bookmark-in-dired nil
35 "Use org-bookmark in dired."
36 :group 'org-bookmark
37 :type 'boolean)
39 (defcustom org-bookmark-when-visiting-a-file nil
40 "Use org-bookmark in any buffer visiting a file."
41 :group 'org-bookmark
42 :type 'boolean)
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."
47 :group 'org-bookmark
48 :type 'boolean)
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))))))
67 (if (not file)
68 (when (eq major-mode 'bookmark-bmenu-mode)
69 (setq bookmark (bookmark-bmenu-bookmark)))
70 (when (and (setq bmks
71 (mapcar (lambda (name)
72 (if (equal file
73 (abbreviate-file-name
74 (bookmark-location name)))
75 name))
76 (bookmark-all-names)))
77 (setq bmks (delete nil bmks)))
78 (setq bookmark
79 (if (or (eq 1 (length bmks)) org-bookmark-use-first-bookmark)
80 (car bmks)
81 (completing-read "Bookmark: " bmks nil t nil nil (car bmks))))))
82 (if bookmark
83 (org-store-link-props :link (org-make-link "bookmark:" bookmark)
84 :description bookmark))))
86 (provide 'org-bookmark)
88 ;;; org-bookmark.el ends here