forked from mirrors/org-mode
Make repeating a subtree-restricted export command remember the subtree
Export commands can be restricted to a specific subtree. When using a prefix argument to org-export-dispatch, the restriction did not stick, i.e. the command would be restricted to whatever note the cursor happens to be in. This made it difficult to repeat export of a subtree while editing it. This change introduces a new marker and uses this marker to remember the cursor position of the previous export command. So repeating a subtree-restricted command will now re-export the same subtree, provided you are still in the same buffer. To break this connection, just make a new export without relying on the prefix argument. * lisp/ox.el (org-export-dispatch-last-position): New variable (org-export-dispatch): Save position of cursor at the moment when the export command is called. Restore that position temporarily when repeating the previous export command.
This commit is contained in:
parent
cbba811a73
commit
9c58082c46
28
lisp/ox.el
28
lisp/ox.el
|
@ -297,6 +297,10 @@ This variable is set with `org-export-define-backend' and
|
||||||
The value should be a list. Its CAR is the action, as a symbol,
|
The value should be a list. Its CAR is the action, as a symbol,
|
||||||
and its CDR is a list of export options.")
|
and its CDR is a list of export options.")
|
||||||
|
|
||||||
|
(defvar org-export-dispatch-last-position (make-marker)
|
||||||
|
"The position where the last export command was created using the dispatcher.
|
||||||
|
This marker will be used with `C-u C-c C-e' to make sure export repetition
|
||||||
|
uses the same subtree if the previous command was restricted to a subtree.")
|
||||||
|
|
||||||
|
|
||||||
;;; User-configurable Variables
|
;;; User-configurable Variables
|
||||||
|
@ -5310,17 +5314,23 @@ When ARG is \\[universal-argument] \\[universal-argument], display the asynchron
|
||||||
((and arg org-export-dispatch-last-action))
|
((and arg org-export-dispatch-last-action))
|
||||||
(t (save-window-excursion
|
(t (save-window-excursion
|
||||||
(unwind-protect
|
(unwind-protect
|
||||||
;; Store this export command.
|
(progn
|
||||||
|
;; Remember where we are
|
||||||
|
(move-marker org-export-dispatch-last-position
|
||||||
|
(point))
|
||||||
|
;; Get and store an export command
|
||||||
(setq org-export-dispatch-last-action
|
(setq org-export-dispatch-last-action
|
||||||
(org-export--dispatch-ui
|
(org-export--dispatch-ui
|
||||||
(list org-export-initial-scope
|
(list org-export-initial-scope
|
||||||
(and org-export-in-background 'async))
|
(and org-export-in-background 'async))
|
||||||
nil
|
nil
|
||||||
org-export-dispatch-use-expert-ui))
|
org-export-dispatch-use-expert-ui)))
|
||||||
(and (get-buffer "*Org Export Dispatcher*")
|
(and (get-buffer "*Org Export Dispatcher*")
|
||||||
(kill-buffer "*Org Export Dispatcher*")))))))
|
(kill-buffer "*Org Export Dispatcher*")))))))
|
||||||
(action (car input))
|
(action (car input))
|
||||||
(optns (cdr input)))
|
(optns (cdr input)))
|
||||||
|
(unless (memq 'subtree optns)
|
||||||
|
(move-marker org-export-dispatch-last-position nil))
|
||||||
(case action
|
(case action
|
||||||
;; First handle special hard-coded actions.
|
;; First handle special hard-coded actions.
|
||||||
(stack (org-export-stack))
|
(stack (org-export-stack))
|
||||||
|
@ -5336,13 +5346,23 @@ When ARG is \\[universal-argument] \\[universal-argument], display the asynchron
|
||||||
(memq 'force optns)
|
(memq 'force optns)
|
||||||
(memq 'async optns)))
|
(memq 'async optns)))
|
||||||
(publish-all (org-publish-all (memq 'force optns) (memq 'async optns)))
|
(publish-all (org-publish-all (memq 'force optns) (memq 'async optns)))
|
||||||
(otherwise (funcall action
|
(otherwise
|
||||||
|
(save-excursion
|
||||||
|
(when arg
|
||||||
|
;; Repeating command, maybe move cursor
|
||||||
|
;; to restore subtree context
|
||||||
|
(if (eq (marker-buffer org-export-dispatch-last-position)
|
||||||
|
(current-buffer))
|
||||||
|
(goto-char org-export-dispatch-last-position)
|
||||||
|
;; We are in a differnet buffer, forget position
|
||||||
|
(move-marker org-export-dispatch-last-position nil)))
|
||||||
|
(funcall action
|
||||||
;; Return a symbol instead of a list to ease
|
;; Return a symbol instead of a list to ease
|
||||||
;; asynchronous export macro use.
|
;; asynchronous export macro use.
|
||||||
(and (memq 'async optns) t)
|
(and (memq 'async optns) t)
|
||||||
(and (memq 'subtree optns) t)
|
(and (memq 'subtree optns) t)
|
||||||
(and (memq 'visible optns) t)
|
(and (memq 'visible optns) t)
|
||||||
(and (memq 'body optns) t))))))
|
(and (memq 'body optns) t)))))))
|
||||||
|
|
||||||
(defun org-export--dispatch-ui (options first-key expertp)
|
(defun org-export--dispatch-ui (options first-key expertp)
|
||||||
"Handle interface for `org-export-dispatch'.
|
"Handle interface for `org-export-dispatch'.
|
||||||
|
|
Loading…
Reference in a new issue