0

When I place the cursor at the start of a line in Evil's normal state and then switch to visual state, the function bolp (which checks if the cursor is at the beginning of a line) returns nil. When checking for point, it has increased by one after entering visual state. Visually the cursor doesn't move.

If I start in visual state when I am not at the beginning of the line and then move to the beginning of the line with 0, bolp correctly returns t. So, this is only a problem when the cursor is at the beginning of the line when entering visual state.

  • How can I reliably check if I'm at the beginning of a line?
  • Am I doing something wrong?
  • Is there maybe variable I can configure to change this behaviour?

Update: I understand the problem now. Without evil-mode setting the mark doesn't mark the first character, one has to move forward one char to do so. Evil automatically marks the first character to copy the behaviour of vim. So it moves forward by one character when switching to visual state.

1
  • I will open an issue on the evil repo.
    – Hubisan
    Feb 27 at 9:47

2 Answers 2

1

The problem is that when the size of the visual region is 1, then point is always located at the end of the region. You can add an advice around bolp to fix it as follows:

(with-eval-after-load 'evil
  (defun evil-bolp-ad (orig-fn)
    (save-excursion
      (when (and (eq evil-state 'visual) (= (- (region-end) (region-beginning)) 1))
        (backward-char))
      (funcall orig-fn)))

  
  (advice-add 'bolp :around #'evil-bolp-ad))
1
  • 1
    Thanks for the patch. Will use this. If I get an answer on the issue on the repo I will post the link here.
    – Hubisan
    Feb 28 at 8:18
0

Opened an issue and got an answer. Was able to improve the function slightly:

(defun my-feat-evil/bolp-fix (orig-fn)
  "Fix `bolp' not returning `t' if in Evil visual state.
This occurs when only the first character is marked."
  (save-excursion
    (when (eq evil-state 'visual)
      (goto-char evil-visual-point))
    (funcall orig-fn)))

(advice-add 'bolp :around #'my-feat-evil/bolp-fix)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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