2019-03-01 19:01:32 -05:00
|
|
|
;;; ol-bookmark.el - Links to bookmarks
|
2020-01-01 13:38:46 -05:00
|
|
|
;; Copyright (C) 2008-2020 Free Software Foundation, Inc.
|
2008-02-28 09:58:19 -05:00
|
|
|
;;
|
|
|
|
;; Author: Tokuya Kameshima <kames AT fa2.so-net.ne.jp>
|
|
|
|
;; Version: 1.0
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;; Emacs 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.
|
|
|
|
|
2013-03-10 12:57:47 -04:00
|
|
|
;; This program is distributed in the hope that it will be useful,
|
2008-02-28 09:58:19 -05:00
|
|
|
;; 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 GNU Emacs; see the file COPYING. If not, write to the
|
|
|
|
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
;; Boston, MA 02110-1301, USA.
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(require 'org)
|
|
|
|
(require 'bookmark)
|
2019-03-01 19:01:32 -05:00
|
|
|
(require 'ol)
|
2008-02-28 09:58:19 -05:00
|
|
|
|
2008-02-28 19:58:22 -05:00
|
|
|
(defgroup org-bookmark nil
|
|
|
|
"Options concerning the bookmark link."
|
|
|
|
:tag "Org Startup"
|
|
|
|
:group 'org-link)
|
|
|
|
|
|
|
|
(defcustom org-bookmark-in-dired nil
|
|
|
|
"Use org-bookmark in dired."
|
|
|
|
:group 'org-bookmark
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defcustom org-bookmark-when-visiting-a-file nil
|
|
|
|
"Use org-bookmark in any buffer visiting a file."
|
|
|
|
:group 'org-bookmark
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defcustom org-bookmark-use-first-bookmark nil
|
|
|
|
"If several bookmarks links to the buffer, take the first one.
|
|
|
|
Otherwise prompt the user for the right bookmark to use."
|
|
|
|
:group 'org-bookmark
|
|
|
|
:type 'boolean)
|
|
|
|
|
2016-08-07 21:24:09 -04:00
|
|
|
(org-link-set-parameters "bookmark"
|
|
|
|
:follow #'org-bookmark-open
|
|
|
|
:store #'org-bookmark-store-link)
|
2008-02-28 09:58:19 -05:00
|
|
|
|
2020-02-17 05:28:50 -05:00
|
|
|
(defun org-bookmark-open (bookmark _)
|
2008-02-28 09:58:19 -05:00
|
|
|
"Visit the bookmark BOOKMARK."
|
|
|
|
(bookmark-jump bookmark))
|
|
|
|
|
|
|
|
(defun org-bookmark-store-link ()
|
2008-02-28 19:58:22 -05:00
|
|
|
"Store a link to the current line's bookmark in bookmark list."
|
2008-02-29 13:46:42 -05:00
|
|
|
(let (file bookmark bmks)
|
2008-02-28 19:58:22 -05:00
|
|
|
(cond ((and org-bookmark-in-dired
|
|
|
|
(eq major-mode 'dired-mode))
|
2008-02-28 18:57:15 -05:00
|
|
|
(setq file (abbreviate-file-name (dired-get-filename))))
|
2008-02-28 19:58:22 -05:00
|
|
|
((and org-bookmark-when-visiting-a-file
|
|
|
|
(buffer-file-name (buffer-base-buffer)))
|
|
|
|
(setq file (abbreviate-file-name
|
2008-02-28 18:57:15 -05:00
|
|
|
(buffer-file-name (buffer-base-buffer))))))
|
|
|
|
(if (not file)
|
|
|
|
(when (eq major-mode 'bookmark-bmenu-mode)
|
|
|
|
(setq bookmark (bookmark-bmenu-bookmark)))
|
2012-03-19 16:38:12 -04:00
|
|
|
(when (and (setq bmks
|
2008-02-29 13:46:42 -05:00
|
|
|
(mapcar (lambda (name)
|
|
|
|
(if (equal file
|
|
|
|
(abbreviate-file-name
|
|
|
|
(bookmark-location name)))
|
|
|
|
name))
|
|
|
|
(bookmark-all-names)))
|
2008-02-28 19:58:22 -05:00
|
|
|
(setq bmks (delete nil bmks)))
|
2012-03-19 16:38:12 -04:00
|
|
|
(setq bookmark
|
2008-02-28 19:58:22 -05:00
|
|
|
(if (or (eq 1 (length bmks)) org-bookmark-use-first-bookmark)
|
|
|
|
(car bmks)
|
|
|
|
(completing-read "Bookmark: " bmks nil t nil nil (car bmks))))))
|
|
|
|
(if bookmark
|
2013-01-04 07:47:59 -05:00
|
|
|
(org-store-link-props :link (concat "bookmark:" bookmark)
|
2008-02-28 19:58:22 -05:00
|
|
|
:description bookmark))))
|
2008-02-28 09:58:19 -05:00
|
|
|
|
2019-03-01 19:01:32 -05:00
|
|
|
(provide 'ol-bookmark)
|
2008-02-28 09:58:19 -05:00
|
|
|
|
2019-03-01 19:01:32 -05:00
|
|
|
;;; ol-bookmark.el ends here
|