Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:wq in org-capture-mode should do org-capture-finalize #5320

Closed
mwillsey opened this issue Mar 1, 2016 · 3 comments
Closed

:wq in org-capture-mode should do org-capture-finalize #5320

mwillsey opened this issue Mar 1, 2016 · 3 comments

Comments

@mwillsey
Copy link
Contributor

mwillsey commented Mar 1, 2016

I think org-capture should play nice with the evil-ex commands :q and :wq. Right now, doing :wq will write the captured item, but the capture buffer will remain open and none of the capture hooks are executed.

Right now I do something like this:

    (defun mw/evil-capture ()
      (evil-insert-state)
      (evil-ex-define-cmd-local "q[uit]" 'org-capture-kill)
      (evil-ex-define-cmd-local "wq"     'org-capture-finalize))
    (add-hook 'org-capture-mode-hook 'mw/evil-capture)

This is faciliated by a nice little snippet from stack overflow that allows local ex bindings:

  ;; from http://emacs.stackexchange.com/a/16556
  (defun evil-ex-define-cmd-local
      (cmd function)
    "Locally binds the function FUNCTION to the command CMD."
    (unless (local-variable-p 'evil-ex-commands)
      (setq-local evil-ex-commands (copy-alist evil-ex-commands)))
    (evil-ex-define-cmd cmd function))

I think this behavior is expected by vim users and thus should be the default.

EDIT: I'd be happy to file a PR to fix this, but I'd appreciate some input on where to put the evil-ex-define-cmd-local code, as it's pretty generic. I imagine it'd go somewhere in the spacemacs-base init-evil code, but I wouldn't want putting something in there to prohibit what would otherwise be a simple fix in the org code from going through.

@mwillsey
Copy link
Contributor Author

mwillsey commented Mar 2, 2016

I also think that the Org Notes buffers (those that pop up to log a state change) should have the same behavior. Unfortunately, it looks like a solution similar to the one above does not work for the note buffers:

    (defun mw/evil-log-note ()
      (evil-insert-state)
      (evil-ex-define-cmd-local "q[uit]" 'org-kill-note-or-show-branches)
      (evil-ex-define-cmd-local "wq"     'org-store-log-note))
    (add-hook 'org-log-buffer-setup-hook 'mw/evil-log-note)

With that hook, the :q command works just fine, but the :wq results in unknown command: ':wq'. I'd love to see a solution that gets consistent behavior in both of these modes.

Also, it's worth noting that Magit provides similar behavior, where :wq will complete the commit.

@justbur
Copy link
Contributor

justbur commented Mar 3, 2016

I recently added :wq to magit through these lines

That's the simplest way to do this. For example, for org-capture this should do the trick

(define-key org-capture-mode-map [remap evil-save-and-close]          'org-capture-finalize)
(define-key org-capture-mode-map [remap evil-save-modified-and-close] 'org-capture-finalize)
(define-key org-capture-mode-map [remap evil-quit]                    'org-capture-kill)

Also works for ZZ and ZQ

@TheBB
Copy link
Collaborator

TheBB commented Oct 20, 2016

Should be fixed in master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants