From 162f99881a9dce7d83668effb197c5e08fa12d5d Mon Sep 17 00:00:00 2001 From: Eric Danan Date: Fri, 13 Jul 2018 11:28:32 +0200 Subject: [PATCH] cp-org-capture: fix when used as switch-project action Make sure `counsel-org-capture' is called from the initial buffer (the one from which we called `counsel-projectile-switch-project') rather than the switch-project buffer. --- counsel-projectile.el | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/counsel-projectile.el b/counsel-projectile.el index 61c924e..017352e 100644 --- a/counsel-projectile.el +++ b/counsel-projectile.el @@ -904,7 +904,7 @@ The format is the same as in `org-capture-templates-contexts'." :group 'counsel-projectile) ;;;###autoload -(defun counsel-projectile-org-capture () +(defun counsel-projectile-org-capture (&optional from-buffer) "Org-capture into the current project. The capture templates are read from the variables @@ -940,7 +940,8 @@ The capture templates are read from the variables (lambda () (ivy-add-prompt-count (projectile-prepend-project-name (ivy-state-prompt ivy-last))))) - (counsel-org-capture))) + (with-current-buffer (or from-buffer (current-buffer)) + (counsel-org-capture)))) ;;;; counsel-projectile-switch-project @@ -1138,7 +1139,9 @@ action." (defun counsel-projectile-switch-project-action-org-capture (project) "Org-capture into PROJECT." - (let ((projectile-switch-project-action 'counsel-projectile-org-capture)) + (let* ((from-buffer (ivy-state-buffer ivy-last)) + (projectile-switch-project-action `(lambda () + (counsel-projectile-org-capture ,from-buffer)))) (counsel-projectile-switch-project-by-name project))) ;;;###autoload