1
;; .spacemacs file
(defun my/function (beg end)
     ;; To work with visual selection:
     (interactive "r")

    ;; Displays visual selection in message buffer:
    (message (buffer-substring-no-properties beg end))

    ;; Now I want to toggle off visual selection in buffer
    ;; But I do not know how to do it?
)

Any ideas?

1

I have found a way after exploring all evil- functions:

   (evil-normal-state 1)

My first idea was to use:

   (evil-visual-state -1)

But it leaves the buffer in insert mode with no possibility to go back to normal mode.


Edit: I have come to another way of doing it:

;; .spacemacs file
(defun my/function (beg end)
     ;; To work with visual selection:
     (interactive "r")

    ;; checking:   <-----------  section added
    (unless (evil-visual-state-p) (error "Not in visual mode..."))

    ;; Displays visual selection in message buffer:
    (message (buffer-substring-no-properties beg end))

    ;; Eventually the function I have been looking for:
    (evil-exit-visual-state)
)
| improve this answer | |
0

I think this is what you are looking for evil-magit-maybe-deactivate-mark


evil-magit-maybe-deactivate-mark is an interactive and compiled
function defined in evil-magit.el.

Documentation
Deactivate mark if region is active. Used for ESC binding.

| improve this answer | |
  • I have stumbled upon this one. But I did not consider it as it seems to be useful in magit context only. Have you tested it? – pietrodito Feb 10 at 8:16
  • I am using it already with some hydra-post-hook. It works everywhere and interactive function. – itirazimvar Feb 10 at 9:41
  • What do you think of evil-exit-visual-state? – pietrodito Feb 10 at 10:06
  • I prefer still evil-magit... because it's more simple function if you see the function + Just tested evil-exit visual state does not work if you are emacs-mode in spacemacs. – itirazimvar Feb 10 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.