emacs-evil / evil

The extensible vi layer for Emacs.
GNU General Public License v3.0
3.29k stars 276 forks source link

`vip` select wrong region in org-mode #1872

Closed pysnow530 closed 3 months ago

pysnow530 commented 3 months ago

Issue type

Environment

Emacs version: GNU Emacs 28.2 (build 1, x86_64-apple-darwin21.6.0, Carbon Version 165 AppKit 2113.6) of 2022-09-15 Operating System: macOS Sonoma 14.2.1 Evil version: Evil version 1.15.0 Evil installation type: MELPA Graphical/Terminal: Graphical Tested in a make emacs session (see CONTRIBUTING.md): Yes

Reproduction steps

* example

| a | b |
| c | d |

#+begin_src emacs-lisp
(+ 2 3)
#+end_src

Expected behavior

select the table

Actual behavior

table was selected, with org header, and begin_src header

Further notes

  1. In vim, it just select the table.
  2. In fundamental-mode, the behavior is expected.
pysnow530 commented 3 months ago
Screenshot 2024-03-22 at 21 30 50
pysnow530 commented 3 months ago

I found the cause of this issue.

Evil's vip depends on forward-paragraph, this function use paragraph-start and paragraph-seperate. When entering org-mode, org.el will change these two variable to new variable that about org element.

workaround in doomemacs:

(after! org
  (defadvice! recover-paragraph-seperate ()
    "Recover org paragraph mark position."
    :after 'org-setup-filling
    (setq-local paragraph-start "[\f\\|[ \t]*$]")
    (setq-local paragraph-separate "[ \t\f]*$")))
axelf4 commented 3 months ago

If Org mode redefines paragraphs there is little that can be done without introducing other surprises, I am afraid. FWIW, I use the following advice so that Evil paragraph motions and text objects always act consistently:

;; Always use blank lines as paragraph delimiters in motions/text objects
(define-advice forward-evil-paragraph (:around (orig-fun &rest args))
  (let ((paragraph-start (default-value 'paragraph-start))
        (paragraph-separate (default-value 'paragraph-separate))
        (paragraph-ignore-fill-prefix t))
    (apply orig-fun args)))