dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

ol-bookmark.el (3003B)


      1 ;;; ol-bookmark.el --- Links to bookmarks
      2 
      3 ;; Copyright (C) 2008-2021 Free Software Foundation, Inc.
      4 ;;
      5 ;; Author: Tokuya Kameshima <kames AT fa2.so-net.ne.jp>
      6 ;; Version: 1.0
      7 ;; Keywords: outlines, hypermedia, calendar, wp
      8 ;;
      9 ;; This file is not part of GNU Emacs.
     10 ;;
     11 ;; Emacs is free software; you can redistribute it and/or modify
     12 ;; it under the terms of the GNU General Public License as published by
     13 ;; the Free Software Foundation; either version 3, or (at your option)
     14 ;; any later version.
     15 
     16 ;; This program is distributed in the hope that it will be useful,
     17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19 ;; GNU General Public License for more details.
     20 
     21 ;; You should have received a copy of the GNU General Public License
     22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
     23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     24 ;; Boston, MA 02110-1301, USA.
     25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     26 
     27 (require 'org)
     28 (require 'bookmark)
     29 (require 'ol)
     30 
     31 (defgroup org-bookmark nil
     32   "Options concerning the bookmark link."
     33   :tag "Org Startup"
     34   :group 'org-link)
     35 
     36 (defcustom org-bookmark-in-dired nil
     37   "Use org-bookmark in dired."
     38   :group 'org-bookmark
     39   :type 'boolean)
     40 
     41 (defcustom org-bookmark-when-visiting-a-file nil
     42   "Use org-bookmark in any buffer visiting a file."
     43   :group 'org-bookmark
     44   :type 'boolean)
     45 
     46 (defcustom org-bookmark-use-first-bookmark nil
     47   "If several bookmarks links to the buffer, take the first one.
     48 Otherwise prompt the user for the right bookmark to use."
     49   :group 'org-bookmark
     50   :type 'boolean)
     51 
     52 (org-link-set-parameters "bookmark"
     53 			 :follow #'org-bookmark-open
     54 			 :store #'org-bookmark-store-link)
     55 
     56 (defun org-bookmark-open (bookmark _)
     57   "Visit the bookmark BOOKMARK."
     58   (bookmark-jump bookmark))
     59 
     60 (defun org-bookmark-store-link ()
     61   "Store a link to the current line's bookmark in bookmark list."
     62   (let (file bookmark bmks)
     63     (cond ((and org-bookmark-in-dired
     64 		(eq major-mode 'dired-mode))
     65 	   (setq file (abbreviate-file-name (dired-get-filename))))
     66 	  ((and org-bookmark-when-visiting-a-file
     67 		(buffer-file-name (buffer-base-buffer)))
     68 	   (setq file (abbreviate-file-name
     69 		       (buffer-file-name (buffer-base-buffer))))))
     70     (if (not file)
     71 	(when (eq major-mode 'bookmark-bmenu-mode)
     72 	  (setq bookmark (bookmark-bmenu-bookmark)))
     73       (when (and (setq bmks
     74 		       (mapcar (lambda (name)
     75 				 (if (equal file
     76 					    (abbreviate-file-name
     77 					     (bookmark-location name)))
     78 				     name))
     79 			       (bookmark-all-names)))
     80 		 (setq bmks (delete nil bmks)))
     81 	(setq bookmark
     82 	      (if (or (eq 1 (length bmks)) org-bookmark-use-first-bookmark)
     83 		  (car bmks)
     84 		(completing-read "Bookmark: " bmks nil t nil nil (car bmks))))))
     85     (if bookmark
     86 	(org-store-link-props :link (concat "bookmark:" bookmark)
     87 			      :description bookmark))))
     88 
     89 (provide 'ol-bookmark)
     90 
     91 ;;; ol-bookmark.el ends here