Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selecting two lines and folding folds 3 lines #22

Open
aaronjensen opened this issue May 16, 2021 · 1 comment
Open

Selecting two lines and folding folds 3 lines #22

aaronjensen opened this issue May 16, 2021 · 1 comment

Comments

@aaronjensen
Copy link

If I use V, then hit j to select two lines, followed by zf, it folds 3 lines. This differs from vim, which will only fold 2. I'm guessing this happens because as far as the range is concerned, I think emacs considers the point to be at the beginning of the next line and, in emacs mode, vimish-fold assumes you want to fold the line that includes the point. This seems perhaps wrong, but I wanted to check in here first to see if that's known, I've got some configuration issue, or something else.

Thanks!

@9ziggy9
Copy link

9ziggy9 commented Apr 18, 2024

This is really old but I racked my brain trying to get a fix. I think this has something to do with certain evil-mode configurations which lend to visual mode consuming the final newline character of a region during line-selection.

You may have noticed that standard visual selection leads to no issues.

A way to fix this is to wrap your calls to vimish-fold with a condition which decrements the endpoint if the region happens to end in a newline character. Here is my use-package config, just take the zig/vimish-fold-region function and adapt it as you need.

(use-package vimish-fold
  :ensure t
  :after evil
  :preface
  (defun zig/vimish-fold-region ()
    (interactive)
    (when (region-active-p)
      (let ((beg (region-beginning)) (end (region-end)))
        (if (= (char-before end) ?\n) (setq end (1- end)))
        (vimish-fold beg end)
        (evil-normal-state))))
  :bind (:map evil-visual-state-map
         ("<tab>"   . zig/vimish-fold-region)
         :map evil-normal-state-map
         ("<tab>"   . 'vimish-fold-toggle)
         ("M-<tab>" . 'vimish-fold-delete))
  :config
  (vimish-fold-global-mode 1)
  (setq vimish-fold-persist-on-saving t))

I also found this in the evil-mode documentation, although this did not work in my case and I believe that this is because it again does not account for the newline character consumption in LINE selection mode.

evil-v$-excludes-newline
If non-nil, evil-end-of-line does not move as far as to include the `` `` char at eol. This makes v$ consistent with $ used as a motion (e.g. v$y is consistent with y$ in normal state).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants