Last active
          March 31, 2019 01:01 
        
      - 
      
- 
        Save takaxp/2f812322e6ad3e1900df7901120535f3 to your computer and use it in GitHub Desktop. 
    org-capture-with-bookmark
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | (with-eval-after-load "org" | |
| ;; [[bookmark:hoge][hogehoge]] 形式のリンクを有効化 | |
| (add-to-list 'org-modules 'ol-bookmark) | |
| ;; ブックマークを読み込む | |
| (when (require 'bookmark nil t) | |
| ;; ブックマークファイルの指定 | |
| ;; (setq bookmark-default-file "/path/to/bookmark") | |
| ;; 変更直後に保存 | |
| (setq bookmark-save-flag 1) | |
| ;; `bookmark-default-file' の読み込み | |
| (bookmark-maybe-load-default-file))) | |
| (with-eval-after-load "org-capture" | |
| ;; ブックマーク入りのノートをキャプチャするテンプレートを追加 | |
| (setq org-capture-templates | |
| `(("u" "subtree with a bookmark" entry | |
| (file+headline "~/Desktop/hoge1.org" "INBOX") | |
| "** TODO %(message \"%s\" my-captured-bookmark-last)\n%?\n%(my-get-org-bookmark)"))) | |
| ;; キャプチャ直前に記録するブックマークの名前を記録 | |
| (defvar my-captured-bookmark-last nil) | |
| (defun my-org-capture-bookmark-set () | |
| "Bookmark the location when capture is activated." | |
| (let ((name (format "%s::%s" | |
| (bookmark-buffer-file-name) | |
| (buffer-substring-no-properties | |
| (point-at-bol) (point-at-eol))))) | |
| (bookmark-set (setq my-captured-bookmark-last name)))) | |
| (defun my-get-org-bookmark () | |
| "Format a link compliant with `ol-bookmark'." | |
| (if my-captured-bookmark-last | |
| (format " -> [[bookmark:%s][jump to source]]" my-captured-bookmark-last) | |
| (warn "Nothing is stored in `my-captured-bookmark-last'"))) | |
| (defun ad:org-capture (&optional goto keys) | |
| (my-org-capture-bookmark-set)) | |
| (advice-add 'org-capture :before #'ad:org-capture) | |
| (defun ad:org-capture-kill () | |
| (when my-captured-bookmark-last | |
| (bookmark-delete my-captured-bookmark-last))) | |
| (advice-add 'org-capture-kill :before #'ad:org-capture-kill)) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment