From b00aaa377b8a300bf6436fed6aca8416bd0727ea Mon Sep 17 00:00:00 2001 From: tj Date: Wed, 12 Mar 2014 14:43:16 +0100 Subject: [PATCH] Use outorg functions slightly refactored. --- outshine.el | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/outshine.el b/outshine.el index 2775f4c..66b5fe6 100644 --- a/outshine.el +++ b/outshine.el @@ -300,6 +300,11 @@ them set by set, separated by a nil element. See the example for (defvar outshine-current-buffer-visibility-state nil "Stores current visibility state of buffer.") +(defvar outshine-use-outorg-last-headline-marker nil + "Stores current visibility state of buffer.") +(make-variable-buffer-local + 'outshine-use-outorg-last-headline-marker) + ;;;; Hooks (defvar outshine-hook nil @@ -1112,15 +1117,35 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names." "Use outorg to call FUN with FUNARGS on subtree. FUN should be an Org-mode function that acts on the subtree at -point." - (when (outline-on-heading-p) - (save-excursion - (save-restriction - (outorg-edit-as-org) - (if funargs - (funcall fun funargs) - (funcall fun)) - (outorg-copy-edits-and-exit)))))) +point. + +Sets the variable `outshine-use-outorg-last-headline-marker' so +that it always contains a point-marker to the last headline this +function was called upon. + +The old marker is removed first. Then a new point-marker is +created before `outorg-edit-as-org' is called on the headline." + (save-excursion + (unless (outline-on-heading-p) + (outline-previous-heading)) + (outshine--set-outorg-last-headline-marker) + (outorg-edit-as-org) + (if funargs + (funcall fun funargs) + (funcall fun)) + (outorg-copy-edits-and-exit)))) + +(defun outshine--set-outorg-last-headline-marker () + "Set a point-marker to current header and remove old marker. + +Sets the variable `outshine-use-outorg-last-headline-marker'." + (and + (integer-or-marker-p + outshine-use-outorg-last-headline-marker) + (set-marker outshine-use-outorg-last-headline-marker nil)) + (setq outshine-use-outorg-last-headline-marker + (point-marker))) + ;;;;; Hook function