emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Searching for line beginning


From: Stefan Monnier
Subject: Re: Searching for line beginning
Date: Sun, 14 Aug 2022 13:24:31 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Eli Zaretskii [2022-08-14 18:36:52] wrote:
>> From: "Basil L. Contovounesios" <contovob@tcd.ie>
>> Cc: emacs-devel@gnu.org
>> Date: Sun, 14 Aug 2022 18:33:00 +0300
>> 
>> Eli Zaretskii [2022-08-13 18:43 +0300] wrote:
>> 
>> > C-a (move-beginning-of-line) does this to find the line's beginning:
>> >
>> >     ;; Move to beginning-of-line, ignoring fields and invisible text.
>> >     (skip-chars-backward "^\n")
>> >     (while (and (not (bobp)) (invisible-p (1- (point))))
>> >       (goto-char (previous-char-property-change (point)))
>> >       (skip-chars-backward "^\n"))
>> >
>> > Apart of the fields part (which can be handled by binding
>> > inhibit-field-text-motion), can anyone see a reason why not use
>> > line-beginning-position instead?  The latter is much faster,
>> > especially when lines are very long.
>> 
>> FWIW, one could also say (beginning-of-line) or (beginning-of-line 1)
>> instead of (goto-char (line-beginning-position)).
>
> As a matter of principle, I don't like calling commands from Lisp if I
> can avoid that, because commands frequently have extensive checks of
> the arguments that are redundant in non-interactive calls.

I also like to avoid moving point when it's possible/easy (my original
motivation was to avoid the extra tricky semantics of moving point in
the presence of things like `point-entered` and `intangible` properties,
but even with `inhibit-point-motion-hooks` permanently set to t I think
it's preferable not to move point when given the choice).

In the above loop, it seems it's easy not to move point.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]