summaryrefslogtreecommitdiff
path: root/bog.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-02-15 22:15:39 -0500
committerKyle Meyer <kyle@kyleam.com>2015-02-15 22:15:39 -0500
commit679a8e978afed699d487fe6b74b488aa930927b5 (patch)
treeff8bcb3255a3f22f5554a170ac93bd6b81c85deb /bog.el
parent83fa0e4993ed620e46906cbde9f3ccd1d760aed5 (diff)
downloadbog-679a8e978afed699d487fe6b74b488aa930927b5.tar.gz
Decouple Org and Bog tree-to-indirect commands
- Use Bog-specific record of last indirect buffer instead of clobbering org-last-indirect-buffer. - Add variable that controls whether or not previous buffer from bog-citekey-tree-to-indirect-buffer is replaced during the next call (default behavior). - Show indirect buffer in other window regardless of org-indirect-buffer-display setting.
Diffstat (limited to 'bog.el')
-rw-r--r--bog.el35
1 files changed, 27 insertions, 8 deletions
diff --git a/bog.el b/bog.el
index e060e9f..317adf4 100644
--- a/bog.el
+++ b/bog.el
@@ -197,6 +197,13 @@ added citekeys, clear the cache with `bog-clear-citekey-cache'."
:group 'bog
:type 'boolean)
+(defcustom bog-keep-indirect nil
+ "Keep the previous buffer from `bog-citekey-tree-to-indirect-buffer'.
+Otherwise, each call to `bog-citekey-tree-to-indirect-buffer'
+kills the indirect buffer created by the previous call."
+ :group 'bog
+ :type 'boolean)
+
(defvar bog-citekey-syntax-table
(let ((st (make-syntax-table org-mode-syntax-table)))
(modify-syntax-entry ?- "w" st)
@@ -826,9 +833,14 @@ there first."
(when (and (not m) (not visiting)) (kill-buffer buffer))
(and m (throw 'found m))))))
+(defvar bog--last-indirect-buffer nil)
+
(defun bog-citekey-tree-to-indirect-buffer (&optional no-context)
"Open subtree for citekey in an indirect buffer.
+Unless `bog-keep-indirect' is non-nil, replace the indirect
+buffer from the previous call.
+
The citekey is taken from the text under point if it matches
`bog-citekey-format'.
@@ -839,14 +851,21 @@ context fails.
If the citekey file prompt is slow to appear, consider enabling
`bog-use-citekey-cache'."
(interactive "P")
- (let* ((citekey (bog-citekey-from-point-or-all-headings no-context))
- (marker (bog--find-citekey-heading-in-notes citekey)))
- (if marker
- (with-current-buffer (marker-buffer marker)
- (org-with-wide-buffer
- (goto-char marker)
- (org-tree-to-indirect-buffer)))
- (message "Heading for %s not found in notes" citekey))))
+ (-if-let* ((orig-buf (current-buffer))
+ (citekey (bog-citekey-from-point-or-all-headings no-context))
+ (marker (bog--find-citekey-heading-in-notes citekey)))
+ (with-current-buffer (marker-buffer marker)
+ (org-with-wide-buffer
+ (goto-char marker)
+ (let ((org-indirect-buffer-display
+ (if (and (not bog-keep-indirect)
+ (eq bog--last-indirect-buffer orig-buf))
+ 'current-window
+ 'other-window))
+ (last-buf-p (not (buffer-live-p bog--last-indirect-buffer))))
+ (org-tree-to-indirect-buffer (or bog-keep-indirect last-buf-p))
+ (setq bog--last-indirect-buffer org-last-indirect-buffer))))
+ (message "Heading for %s not found in notes" citekey)))
(defun bog-refile ()
"Refile heading within notes.