[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Temporarily select-window, without updating mode-line face and curso
From: |
JD Smith |
Subject: |
Re: Temporarily select-window, without updating mode-line face and cursor fill? |
Date: |
Sun, 2 May 2021 22:08:49 -0400 |
For very large file, line-number-at-pos, which uses count-lines, if far too
slow to be used in a modeline :eval. I suspect this is why the “%l” mode line
formatter does not itself use count-lines. Here’s my analysis of that (on top
of some 7yr old complaints about the speed of line-number-at-pos):
https://emacs.stackexchange.com/questions/3821/a-faster-method-to-obtain-line-number-at-pos-in-large-buffers/64656#64656
Summary: format-mode-line is >10x faster on “random” lines, and thousands of
times faster for “nearby lines” (presumably due to caching). The latter is
particular important for rapid scrolling updates.
I managed to get this working quite well on large files (like /usr/dict/words);
see https://github.com/jdtsmith/mlscroll. I indeed use count-lines for
incrementing line count from window-start to window-end, since they are
“close”, and have simplified the fast line count to:
(defun mlscroll-fast-line-number-at-pos (pos &optional win)
(let ((old (window-point win)))
(set-window-point win pos)
(prog1
(string-to-number (format-mode-line "%l" 0 win))
(set-window-point win old))))
If you had any concrete suggestions for calculating window positions (like
window-start and window-end, not just buffer positions) in a non-active window
without selecting it, which is superior to my approach, I’d be happy to hear.
> On May 2, 2021, at 2:55 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: JD Smith <jdtsmith@gmail.com>
>> Date: Sat, 1 May 2021 18:17:46 -0400
>> Cc: emacs-devel@gnu.org
>>
>> (defun mlscroll-fast-line-number-at-pos (pos &optional win)
>> "Line number at position.
>> Compute line number at position POS. Uses fast mode-line
>> formatting. If WIN is non-nil, find line number at position within
>> that window."
>> (string-to-number
>> (if win
>> (let ((old (window-point win)))
>> (set-window-point win pos)
>> (prog1
>> (format-mode-line "%l" 0 win)
>> (set-window-point win old)))
>> (save-excursion
>> (goto-char pos)
>> (format-mode-line "%l" 0)))))
>
> I don't recommend using format-mode-line for counting lines. Why not
> use count-lines instead?
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, (continued)
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, JD Smith, 2021/05/01
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, Eli Zaretskii, 2021/05/02
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, JD Smith, 2021/05/02
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, martin rudalics, 2021/05/03
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, JD Smith, 2021/05/03
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, martin rudalics, 2021/05/03
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, martin rudalics, 2021/05/02
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, JD Smith, 2021/05/02
Re: Temporarily select-window, without updating mode-line face and cursor fill?, JD Smith, 2021/05/01
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, Eli Zaretskii, 2021/05/02
- Re: Temporarily select-window, without updating mode-line face and cursor fill?,
JD Smith <=
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, Stefan Monnier, 2021/05/02
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, JD Smith, 2021/05/02
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, JD Smith, 2021/05/04
- Re: Temporarily select-window, without updating mode-line face and cursor fill?, Stefan Monnier, 2021/05/04
Re: Temporarily select-window, without updating mode-line face and cursor fill?, Stefan Kangas, 2021/05/04
Re: Temporarily select-window, without updating mode-line face and cursor fill?, Eli Zaretskii, 2021/05/05
Re: Temporarily select-window, without updating mode-line face and cursor fill?, Stefan Kangas, 2021/05/05
Re: Temporarily select-window, without updating mode-line face and cursor fill?, Stefan Monnier, 2021/05/05
Re: Temporarily select-window, without updating mode-line face and cursor fill?, JD Smith, 2021/05/05