cp-org-capture: Add extra-actions
By default, one action to switch project. Can be customized through the variable `counsel-projectile-org-capture-extra-actions'.
This commit is contained in:
parent
878f95c55d
commit
543454f551
1 changed files with 29 additions and 1 deletions
|
|
@ -943,6 +943,29 @@ The format is the same as in `org-capture-templates-contexts'."
|
||||||
(function :tag "Custom function")))))
|
(function :tag "Custom function")))))
|
||||||
:group 'counsel-projectile)
|
:group 'counsel-projectile)
|
||||||
|
|
||||||
|
(defcustom counsel-projectile-org-capture-extra-actions
|
||||||
|
'(("P" counsel-projectile-org-capture-action-switch-project
|
||||||
|
"switch project"))
|
||||||
|
"List of extra actions to add to
|
||||||
|
`counsel-projectile-org-capture' (in addition to the actions of
|
||||||
|
`counsel-org-capture')."
|
||||||
|
:type '(repeat :tag "Actions"
|
||||||
|
(list :tag "Action"
|
||||||
|
(string :tag " key")
|
||||||
|
(function :tag "function")
|
||||||
|
(string :tag " name")))
|
||||||
|
:group 'counsel-projectile)
|
||||||
|
|
||||||
|
(defvar counsel-projectile--org-capture-templates-backup nil
|
||||||
|
"Stores a backup of `org-capture-templates'.")
|
||||||
|
|
||||||
|
(defun counsel-projectile-org-capture-action-switch-project (_)
|
||||||
|
"Reset `org-capture-templates' from
|
||||||
|
`counsel-projectile--org-capture-templates-backup' and call
|
||||||
|
`counsel-projectile-switch-project'."
|
||||||
|
(setq org-capture-templates counsel-projectile--org-capture-templates-backup)
|
||||||
|
(counsel-projectile-switch-project))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun counsel-projectile-org-capture (&optional from-buffer)
|
(defun counsel-projectile-org-capture (&optional from-buffer)
|
||||||
"Capture into the current project.
|
"Capture into the current project.
|
||||||
|
|
@ -960,7 +983,9 @@ Optional argument FROM-BUFFER specifies the buffer from which to
|
||||||
capture."
|
capture."
|
||||||
(interactive)
|
(interactive)
|
||||||
(require 'org-capture)
|
(require 'org-capture)
|
||||||
(let* ((root (ignore-errors (projectile-project-root)))
|
(setq counsel-projectile--org-capture-templates-backup org-capture-templates)
|
||||||
|
(let* ((ivy--actions-list (copy-sequence ivy--actions-list))
|
||||||
|
(root (ignore-errors (projectile-project-root)))
|
||||||
(name (projectile-project-name))
|
(name (projectile-project-name))
|
||||||
(org-capture-templates-contexts
|
(org-capture-templates-contexts
|
||||||
(append (when root
|
(append (when root
|
||||||
|
|
@ -993,6 +1018,9 @@ capture."
|
||||||
else
|
else
|
||||||
collect item)))
|
collect item)))
|
||||||
org-capture-templates)))
|
org-capture-templates)))
|
||||||
|
(ivy-add-actions
|
||||||
|
'counsel-org-capture
|
||||||
|
counsel-projectile-org-capture-extra-actions)
|
||||||
(with-current-buffer (or from-buffer (current-buffer))
|
(with-current-buffer (or from-buffer (current-buffer))
|
||||||
(counsel-org-capture))))
|
(counsel-org-capture))))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue