1. Frank Fischer
  2. evil
  3. Issues
Issue #126 wontfix

`evil-visual-state-p' returns nil when it shouldn't

York Zhao
created an issue

I have the following in my .emacs file:

{{{ (define-key evil-normal-state-map [remap evil-change-line] 'evil-change-line-dwim)

(evil-define-operator evil-change-line-dwim (beg end type register yank-handler) "Change to end of line." :motion evil-end-of-line (interactive "<R><x><y>") (cond ((evil-visual-state-p) (evil-change-line beg end type register yank-handler))


(t ...))) }}}

I then set the break point to the line "(evil-visual-state-p)", go somewhere in any file and press "vwww", then press "C", the execution stops at the break point, press SPC to step over and the edebugger shows the return value of "(evil-visual-state-p)" to be nil when it should be t.

Comments (2)

  1. Vegard Øye

    By default, operator commands exit Visual state the moment they are invoked. You can override this by adding the :keep-visual command property:

    (evil-define-operator evil-change-line-dwim (...)
      "Change to end of line."
      :motion evil-end-of-line
      :keep-visual t
      (interactive ...)
        ;; do Visual stuff

    You now have to exit Visual state manually with (evil-exit-visual-state).

  2. York Zhao reporter

    Thank you very much for this Vegard, I'm sorry I should have noticed the difference in `evil-delete-line' where the `:keep-visual' has been set and learnt from there.

  3. Log in to comment