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

Use visual line when `visual-line-mode` is active #227

Closed
joostkremers opened this Issue Sep 14, 2015 · 9 comments

Comments

Projects
None yet
2 participants
@joostkremers

joostkremers commented Sep 14, 2015

I mostly write text (markdown or LaTeX) with visual-line-mode turned on, which means my paragraphs are actually (very) long lines. As a result, when I use swiper for searching, whole paragraphs are marked and the lines displayed in the minibuffer are so long that they often have to be truncated and the match is not visible.

Would it be possible to use the visual line for matching / displaying when visual-line-mode is turned on in a buffer? visual-line-mode does a pretty good job at presenting visual lines as actual lines, and using swiper in such a buffer is always a bit confusing.

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Sep 15, 2015

Owner

I'll see what I can do. I rarely use visual-line-mode because of the way Emacs handles newlines: certain operations can become very inefficient if newlines are absent, up to the point of Emacs freezing. And this behavior is very rooted into Emacs' buffer model, and is unlikely to change in the future.

On the other hand, all it takes is to rewrite swiper--candidates slightly - a very small function. If I knew how to replace (buffer-substring (line-beginning-position) (line-end-position)) with the visual-line equivalent, I could fix this right now. Unfortunately, I don't yet know how to do it.

Owner

abo-abo commented Sep 15, 2015

I'll see what I can do. I rarely use visual-line-mode because of the way Emacs handles newlines: certain operations can become very inefficient if newlines are absent, up to the point of Emacs freezing. And this behavior is very rooted into Emacs' buffer model, and is unlikely to change in the future.

On the other hand, all it takes is to rewrite swiper--candidates slightly - a very small function. If I knew how to replace (buffer-substring (line-beginning-position) (line-end-position)) with the visual-line equivalent, I could fix this right now. Unfortunately, I don't yet know how to do it.

@joostkremers

This comment has been minimized.

Show comment
Hide comment
@joostkremers

joostkremers Sep 15, 2015

I'll see what I can do. I rarely use visual-line-mode because of the way Emacs handles newlines: certain operations can become very inefficient if newlines are absent, up to the point of Emacs freezing. And this behavior is very rooted into Emacs' buffer model, and is unlikely to change in the future.

I've never noticed any problems... Perhaps I'm just lucky

On the other hand, all it takes is to rewrite swiper--candidates slightly - a very small function. If I knew how to replace (buffer-substring (line-beginning-position) (line-end-position)) with the visual-line equivalent, I could fix this right now. Unfortunately, I don't yet know how to do it.

AFAIK there are no visual-line equivalents for line-beginning-position and line-end-position, so one would have to cobble together something like:

(defun visual-line-beginning-position ()
  "Return point at the beginning of the visual line."
  (save-excursion
    (beginning-of-visual-line)
    (point)))

Though I don't know how inefficient that might be.

joostkremers commented Sep 15, 2015

I'll see what I can do. I rarely use visual-line-mode because of the way Emacs handles newlines: certain operations can become very inefficient if newlines are absent, up to the point of Emacs freezing. And this behavior is very rooted into Emacs' buffer model, and is unlikely to change in the future.

I've never noticed any problems... Perhaps I'm just lucky

On the other hand, all it takes is to rewrite swiper--candidates slightly - a very small function. If I knew how to replace (buffer-substring (line-beginning-position) (line-end-position)) with the visual-line equivalent, I could fix this right now. Unfortunately, I don't yet know how to do it.

AFAIK there are no visual-line equivalents for line-beginning-position and line-end-position, so one would have to cobble together something like:

(defun visual-line-beginning-position ()
  "Return point at the beginning of the visual line."
  (save-excursion
    (beginning-of-visual-line)
    (point)))

Though I don't know how inefficient that might be.

@abo-abo abo-abo closed this in 82a317c Oct 2, 2015

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Oct 2, 2015

Owner

Thanks.

Owner

abo-abo commented Oct 2, 2015

Thanks.

@joostkremers

This comment has been minimized.

Show comment
Hide comment
@joostkremers

joostkremers Oct 4, 2015

Unfortunately, the changes seem to make swiper terribly slow, at least when compiling a list of candidates. It takes a long time (several seconds) for the swiper buffer to appear, during which Emacs is at 100% CPU-usage. Profiling the code shows that most of the processing time is spent in line-move, which is called by end-of-visual-line.

I also tried it with Emacs -Q -L </path/to/latest/swiper>. Same thing.

If you want to try for yourself, you can use this file:

https://github.com/joostkremers/ebib/blob/master/manual/ebib.text

It's long enough to show the problem. Be sure to activate visual-line-mode, because without it, the swiper buffer appears instantly.

Seems like supporting visual-line-mode isn't really an option after all...

joostkremers commented Oct 4, 2015

Unfortunately, the changes seem to make swiper terribly slow, at least when compiling a list of candidates. It takes a long time (several seconds) for the swiper buffer to appear, during which Emacs is at 100% CPU-usage. Profiling the code shows that most of the processing time is spent in line-move, which is called by end-of-visual-line.

I also tried it with Emacs -Q -L </path/to/latest/swiper>. Same thing.

If you want to try for yourself, you can use this file:

https://github.com/joostkremers/ebib/blob/master/manual/ebib.text

It's long enough to show the problem. Be sure to activate visual-line-mode, because without it, the swiper buffer appears instantly.

Seems like supporting visual-line-mode isn't really an option after all...

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Oct 4, 2015

Owner

I'm aware of the problem. But there's nothing that I can do about it, short of implementing line-move in C. Still, swiper and visual-line-mode is usable in small buffers.

Owner

abo-abo commented Oct 4, 2015

I'm aware of the problem. But there's nothing that I can do about it, short of implementing line-move in C. Still, swiper and visual-line-mode is usable in small buffers.

@joostkremers

This comment has been minimized.

Show comment
Hide comment
@joostkremers

joostkremers Oct 4, 2015

Yes, I was afraid it wouldn't be possible to do something about it...

But would you consider making this an option? Most of the time, the buffers I use visual-line-mode in are rather large, which makes swiper too slow right now.

I know, I'm the one that asked for this in the first place...

joostkremers commented Oct 4, 2015

Yes, I was afraid it wouldn't be possible to do something about it...

But would you consider making this an option? Most of the time, the buffers I use visual-line-mode in are rather large, which makes swiper too slow right now.

I know, I'm the one that asked for this in the first place...

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Oct 4, 2015

Owner

I've enabled line-move only for small buffers.

Owner

abo-abo commented Oct 4, 2015

I've enabled line-move only for small buffers.

@joostkremers

This comment has been minimized.

Show comment
Hide comment
@joostkremers

joostkremers Oct 5, 2015

I'm afraid that makes things even worse... Granted, the delay is much smaller (there's still a slight delay there, but it would be acceptable) but swiper now finds far fewer occurrences of the search string than are actually there. Here, swiper finds 209 occurrences of ebib (the number found depends on the line width, BTW):

screenshot from 2015-10-05 10 41 15

While M-x occur finds 550:

screenshot from 2015-10-05 10 44 02

Moreover, scrolling through them in the swiper buffer highlights (visual) lines that do not match the occurrence:

screenshot from 2015-10-05 10 42 30

Results are similar when using emacs -Q.

joostkremers commented Oct 5, 2015

I'm afraid that makes things even worse... Granted, the delay is much smaller (there's still a slight delay there, but it would be acceptable) but swiper now finds far fewer occurrences of the search string than are actually there. Here, swiper finds 209 occurrences of ebib (the number found depends on the line width, BTW):

screenshot from 2015-10-05 10 41 15

While M-x occur finds 550:

screenshot from 2015-10-05 10 44 02

Moreover, scrolling through them in the swiper buffer highlights (visual) lines that do not match the occurrence:

screenshot from 2015-10-05 10 42 30

Results are similar when using emacs -Q.

abo-abo added a commit that referenced this issue Oct 5, 2015

Fix up visual-line-mode limitation logic
* swiper.el (swiper-use-visual-line): New defvar.
(swiper--candidates):
(swiper--update-input-ivy):
(swiper--action): Update.

Re #227
@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Oct 5, 2015

Owner

OK, I've updated the logic to impose 20000 buffer size limit everywhere. In addition, the visual-line functionality is disabled for org-mode buffers, because something strange happens when using line-move with text hidden in outlines.

Owner

abo-abo commented Oct 5, 2015

OK, I've updated the logic to impose 20000 buffer size limit everywhere. In addition, the visual-line functionality is disabled for org-mode buffers, because something strange happens when using line-move with text hidden in outlines.

abo-abo added a commit that referenced this issue Nov 17, 2015

swiper.el: Modify the behavior with org-mode and visual-line-mode
* swiper.el (swiper--candidates): Set `swiper-use-visual-line' even for
  `org-mode'. In that case, reveal all text to prevent `line-move'
  weirdness.
(swiper--ivy): Use `swiper-use-visual-line'.

Re #291
Re #227
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment