0

In Evil mode, after I enter visual-state, I can use f to expand the selection by jumping to a character. Now if I've pressed f after entering visual-state, Emacs asks me to input a character to jump to, which I think is implemented using read-key-sequence. What I want to do is to call some external process before I enter the character, so I advise the read-key-sequence function(below is a simplified version):

(defun foo (orig-func &rest args)
  (with-temp-buffer
    (call-process "ls" nil t))
  (apply orig-func args))

(advice-add 'read-key-sequence :around 'foo)

Now I enter the visual-state, press f, enter the character, jump to it, and nothing is shown selected, i.e., the region is not active.

However, if I just change the parameter of call-process by setting the fourth argument(destination) to be nil, i.e., using the following version of foo:

(defun foo (orig-func &rest args)
  (with-temp-buffer
    (call-process "ls"))
  (apply orig-func args))

Everything works fine, exactly like without adding advice to read-key-sequence.

My question is, is there something I did wrong, or something of call-process and Evil implementation will magically change the state of the region?

1 Answer 1

0

It turns out this is a very simple question...Setting the fourth argument of call-process, i.e. destination, to t will insert the output into the buffer, which sets the variable deactivate-mark to t. Therefore, the mark is deactivated afterwards. The solution is to bind deactivate-mark to nil before the call-process:

(defun foo (orig-func &rest args)
  (let (deactivate-mark)
    (with-temp-buffer
      (call-process "ls" nil t)))
  (apply orig-func args))

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.