12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- (require 'org)
- (require 'bookmark)
- (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)
- (org-add-link-type "bookmark" 'org-bookmark-open)
- (add-hook 'org-store-link-functions 'org-bookmark-store-link)
- (defun org-bookmark-open (bookmark)
- "Visit the bookmark BOOKMARK."
- (bookmark-jump bookmark))
- (defun org-bookmark-store-link ()
- "Store a link to the current line's bookmark in bookmark list."
- (let (file bookmark bmks)
- (cond ((and org-bookmark-in-dired
- (eq major-mode 'dired-mode))
- (setq file (abbreviate-file-name (dired-get-filename))))
- ((and org-bookmark-when-visiting-a-file
- (buffer-file-name (buffer-base-buffer)))
- (setq file (abbreviate-file-name
- (buffer-file-name (buffer-base-buffer))))))
- (if (not file)
- (when (eq major-mode 'bookmark-bmenu-mode)
- (setq bookmark (bookmark-bmenu-bookmark)))
- (when (and (setq bmks
- (mapcar (lambda (name)
- (if (equal file
- (abbreviate-file-name
- (bookmark-location name)))
- name))
- (bookmark-all-names)))
- (setq bmks (delete nil bmks)))
- (setq bookmark
- (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
- (org-store-link-props :link (contact "bookmark:" bookmark)
- :description bookmark))))
- (provide 'org-bookmark)
|