* Alternative to current-column that counts from visual line beginning
@ 2020-12-29 2:19 Yuan Fu
2020-12-29 2:40 ` Stefan Monnier
0 siblings, 1 reply; 5+ messages in thread
From: Yuan Fu @ 2020-12-29 2:19 UTC (permalink / raw)
To: emacs-devel\@gnu.org
I need to know the column number of the point on the current _visual_ line. current-column measures from logical beginning of line, so it gives rather unintuitive result on wrapped lines. I had to do this:
(save-excursion
(let ((col (current-column)))
;; Go to visual line beginning.
(vertical-motion 0)
(- col (current-column))))
to get the column number counting from the visual line beginning. Is there a function that does what I want? If not, maybe we should add one, or add an argument to current-column.
Yuan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Alternative to current-column that counts from visual line beginning
2020-12-29 2:19 Alternative to current-column that counts from visual line beginning Yuan Fu
@ 2020-12-29 2:40 ` Stefan Monnier
2020-12-29 5:01 ` Yuan Fu
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2020-12-29 2:40 UTC (permalink / raw)
To: Yuan Fu; +Cc: emacs-devel@gnu.org
> to get the column number counting from the visual line beginning. Is
> there a function that does what I want? If not, maybe we should add
> one, or add an argument to current-column.
`posn-at-point`?
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Alternative to current-column that counts from visual line beginning
2020-12-29 2:40 ` Stefan Monnier
@ 2020-12-29 5:01 ` Yuan Fu
2020-12-29 6:21 ` Eli Zaretskii
0 siblings, 1 reply; 5+ messages in thread
From: Yuan Fu @ 2020-12-29 5:01 UTC (permalink / raw)
To: Stefan Monnier; +Cc: emacs-devel@gnu.org
> On Dec 28, 2020, at 9:40 PM, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>
>> to get the column number counting from the visual line beginning. Is
>> there a function that does what I want? If not, maybe we should add
>> one, or add an argument to current-column.
>
> `posn-at-point`?
>
That works, albeit a bit convoluted comparing to current-column and only works when point is visible. Another less legit point is that posn-at-point is a bit far-fetched semantically: for me it is more about GUI pixel positions than text-based column and line positions. All things considered, I still prefer a dedicated function or an additional argument to current-column.
Yuan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Alternative to current-column that counts from visual line beginning
2020-12-29 5:01 ` Yuan Fu
@ 2020-12-29 6:21 ` Eli Zaretskii
2020-12-29 21:05 ` Yuan Fu
0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2020-12-29 6:21 UTC (permalink / raw)
To: emacs-devel, Yuan Fu, Stefan Monnier; +Cc: emacs-devel@gnu.org
On December 29, 2020 7:01:16 AM GMT+02:00, Yuan Fu <casouri@gmail.com> wrote:
>
>
> > On Dec 28, 2020, at 9:40 PM, Stefan Monnier
> <monnier@iro.umontreal.ca> wrote:
> >
> >> to get the column number counting from the visual line beginning.
> Is
> >> there a function that does what I want? If not, maybe we should add
> >> one, or add an argument to current-column.
> >
> > `posn-at-point`?
> >
>
> That works, albeit a bit convoluted comparing to current-column and
> only works when point is visible. Another less legit point is that
> posn-at-point is a bit far-fetched semantically: for me it is more
> about GUI pixel positions than text-based column and line positions.
> All things considered, I still prefer a dedicated function or an
> additional argument to current-column.
>
> Yuan
The concept of "visual line" of some buffer position only makes sense in the context of displaying the buffer in some window. That's because window dimensions and other window-specific aspects, such as faces and overlays, have direct and prominent effect on how physical lines are divided into visual lines.
Therefore, I don't think I understand how can a function exist that reports the "visual column" of a buffer position without telling it the window in which to display that buffer. Could you perhaps outline the algorithm for such a function? Perhaps there is some misunderstanding.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Alternative to current-column that counts from visual line beginning
2020-12-29 6:21 ` Eli Zaretskii
@ 2020-12-29 21:05 ` Yuan Fu
0 siblings, 0 replies; 5+ messages in thread
From: Yuan Fu @ 2020-12-29 21:05 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Stefan Monnier, emacs-devel
> On Dec 29, 2020, at 1:21 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>
> On December 29, 2020 7:01:16 AM GMT+02:00, Yuan Fu <casouri@gmail.com> wrote:
>>
>>
>>> On Dec 28, 2020, at 9:40 PM, Stefan Monnier
>> <monnier@iro.umontreal.ca> wrote:
>>>
>>>> to get the column number counting from the visual line beginning.
>> Is
>>>> there a function that does what I want? If not, maybe we should add
>>>> one, or add an argument to current-column.
>>>
>>> `posn-at-point`?
>>>
>>
>> That works, albeit a bit convoluted comparing to current-column and
>> only works when point is visible. Another less legit point is that
>> posn-at-point is a bit far-fetched semantically: for me it is more
>> about GUI pixel positions than text-based column and line positions.
>> All things considered, I still prefer a dedicated function or an
>> additional argument to current-column.
>>
>> Yuan
>
> The concept of "visual line" of some buffer position only makes sense in the context of displaying the buffer in some window. That's because window dimensions and other window-specific aspects, such as faces and overlays, have direct and prominent effect on how physical lines are divided into visual lines.
>
> Therefore, I don't think I understand how can a function exist that reports the "visual column" of a buffer position without telling it the window in which to display that buffer. Could you perhaps outline the algorithm for such a function? Perhaps there is some misunderstanding.
I see your point. I use vertical-motion, which takes a window as argument (and defaults to the current window).
(save-excursion
(let ((col (current-column)))
;; Go to visual line beginning.
(vertical-motion 0)
(- col (current-column))))
Yuan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-12-29 21:05 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-29 2:19 Alternative to current-column that counts from visual line beginning Yuan Fu
2020-12-29 2:40 ` Stefan Monnier
2020-12-29 5:01 ` Yuan Fu
2020-12-29 6:21 ` Eli Zaretskii
2020-12-29 21:05 ` Yuan Fu
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.