* window-line and window-column
@ 2005-10-07 22:44 rgb
2005-10-07 23:08 ` Neon Absentius
` (4 more replies)
0 siblings, 5 replies; 15+ messages in thread
From: rgb @ 2005-10-07 22:44 UTC (permalink / raw)
How can I tell where, within the current window, I am.
Is there any way to tell what window line I'm currently on? Even if I
use move-to-window-line and it's successful I may not actually be on
that line when it returns. But realistically, I need to know what line
I'm on without moving and I don't see how I can tell.
I can't seem to fine a way to tell what window column I'm in either.
It seems I could probably use (window-width), (current-column) and
truncate-lines to figure it out but comments about popup-ruler on the
wiki make me think such a formula wouldn't be accurate.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: window-line and window-column
2005-10-07 22:44 window-line and window-column rgb
@ 2005-10-07 23:08 ` Neon Absentius
2005-10-07 23:09 ` Lennart Borgman
` (3 subsequent siblings)
4 siblings, 0 replies; 15+ messages in thread
From: Neon Absentius @ 2005-10-07 23:08 UTC (permalink / raw)
On Fri, Oct 07, 2005 at 03:44:23PM -0700, rgb wrote:
> How can I tell where, within the current window, I am.
>
> Is there any way to tell what window line I'm currently on? Even if I
> use move-to-window-line and it's successful I may not actually be on
> that line when it returns. But realistically, I need to know what line
> I'm on without moving and I don't see how I can tell.
>
> I can't seem to fine a way to tell what window column I'm in either.
> It seems I could probably use (window-width), (current-column) and
> truncate-lines to figure it out but comments about popup-ruler on the
> wiki make me think such a formula wouldn't be accurate.
>
These
(setq line-number-mode t)
(setq column-number-mode t)
display the line number and curent column in the modeline.
--
There is no national science just as there is no national
multiplication table; what is national is no longer science.
-- Anton Checov
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: window-line and window-column
2005-10-07 22:44 window-line and window-column rgb
2005-10-07 23:08 ` Neon Absentius
@ 2005-10-07 23:09 ` Lennart Borgman
2005-10-07 23:27 ` Johan Bockgård
` (2 subsequent siblings)
4 siblings, 0 replies; 15+ messages in thread
From: Lennart Borgman @ 2005-10-07 23:09 UTC (permalink / raw)
Cc: help-gnu-emacs
rgb wrote:
>How can I tell where, within the current window, I am.
>
>Is there any way to tell what window line I'm currently on? Even if I
>use move-to-window-line and it's successful I may not actually be on
>that line when it returns. But realistically, I need to know what line
>I'm on without moving and I don't see how I can tell.
>
>I can't seem to fine a way to tell what window column I'm in either.
>It seems I could probably use (window-width), (current-column) and
>truncate-lines to figure it out but comments about popup-ruler on the
>wiki make me think such a formula wouldn't be accurate.
>
>
Can you perhaps use window-start?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: window-line and window-column
2005-10-07 22:44 window-line and window-column rgb
2005-10-07 23:08 ` Neon Absentius
2005-10-07 23:09 ` Lennart Borgman
@ 2005-10-07 23:27 ` Johan Bockgård
2005-10-08 0:49 ` rgb
[not found] ` <mailman.10338.1128726582.20277.help-gnu-emacs@gnu.org>
2005-10-11 1:18 ` Hovav Shacham
4 siblings, 1 reply; 15+ messages in thread
From: Johan Bockgård @ 2005-10-07 23:27 UTC (permalink / raw)
"rgb" <rbielaws@i1.net> writes:
> How can I tell where, within the current window, I am.
See (info "(elisp)Screen Lines")
--
Johan Bockgård
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: window-line and window-column
2005-10-07 23:27 ` Johan Bockgård
@ 2005-10-08 0:49 ` rgb
2005-10-11 4:05 ` Stefan Monnier
0 siblings, 1 reply; 15+ messages in thread
From: rgb @ 2005-10-08 0:49 UTC (permalink / raw)
> > How can I tell where, within the current window, I am.
>
> See (info "(elisp)Screen Lines")
>
I was contemplating what information I need to calculate it
myself and was about to ask if this list was complete:
To calculate (window-column) I need:
truncate-lines (window-width) (current-column) and (window-hscroll)
To get (window-line) I'm thinking I'll need:
truncate-lines (window-width) (current-column) (line-number-at-pos)
and (window-start)
I did re-read the section you suggested and it reminded me that
(line-number-at-pos) and (current-column) may not tell me anything
about (point) in the (selected-window) and so I also need to
compare (current-buffer) with (window-buffer). It also reminded me
that (line-number-at-pos) can be a hog in big files and I may want
to count newline characters between points myself rather than
subtract values it returns.
If your intent was to point to an expedient path to the values
I need I guess I've missed your point.
Perhaps you wanted me to see compute-motion but I don't see how
it helps. It appears to be concerned with "screen coordinates"
which, to me means physical display coordinates, not window
coordinates or frame coordinates which I would expect it to
mention if it were talking about anything useful to my situation.
I'm guessing it's intended for handling mouse events but it's
not clear to me what practical application it's intended for.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: window-line and window-column
2005-10-08 0:49 ` rgb
@ 2005-10-11 4:05 ` Stefan Monnier
2005-10-11 4:38 ` rgb
0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2005-10-11 4:05 UTC (permalink / raw)
> Perhaps you wanted me to see compute-motion but I don't see how it helps.
Check it again. Like most functions it's meant to be meaningful under a tty
as well, so it's very much not pixel-based.
Another useful function would be posn-at-point, but it's only in Emacs-CVS.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: window-line and window-column
2005-10-11 4:05 ` Stefan Monnier
@ 2005-10-11 4:38 ` rgb
2005-10-11 5:02 ` Stefan Monnier
0 siblings, 1 reply; 15+ messages in thread
From: rgb @ 2005-10-11 4:38 UTC (permalink / raw)
Stefan Monnier wrote:
> > Perhaps you wanted me to see compute-motion but I don't see how it helps.
>
> Check it again. Like most functions it's meant to be meaningful under a tty
> as well, so it's very much not pixel-based.
>
> Another useful function would be posn-at-point, but it's only in Emacs-CVS.
>
There it is (nth 6 (posn-at-point))
But I think it might have a problem.
Unlike windmove-coordinates-of-position's value based on
compute-motion, I get a very odd result from posn-at-point
if (point) is off the screen to the left because I've done
(scroll-left). The (car (nth 6 (posn-at-point))) value
doesn't make sense to me under those circumstances.
Could there be a bug?
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: window-line and window-column
2005-10-11 4:38 ` rgb
@ 2005-10-11 5:02 ` Stefan Monnier
2005-10-11 5:09 ` rgb
0 siblings, 1 reply; 15+ messages in thread
From: Stefan Monnier @ 2005-10-11 5:02 UTC (permalink / raw)
> But I think it might have a problem.
> Unlike windmove-coordinates-of-position's value based on
> compute-motion, I get a very odd result from posn-at-point
> if (point) is off the screen to the left because I've done
> (scroll-left). The (car (nth 6 (posn-at-point))) value
> doesn't make sense to me under those circumstances.
> Could there be a bug?
Sounds like it.
If point is not displayed in window (it's out of the window), it should
simply return nil. Try M-x report-emacs-bug.
Stefan
^ permalink raw reply [flat|nested] 15+ messages in thread
[parent not found: <mailman.10338.1128726582.20277.help-gnu-emacs@gnu.org>]
* Re: window-line and window-column
[not found] ` <mailman.10338.1128726582.20277.help-gnu-emacs@gnu.org>
@ 2005-10-08 0:20 ` rgb
2005-10-08 2:29 ` Neon Absentius
0 siblings, 1 reply; 15+ messages in thread
From: rgb @ 2005-10-08 0:20 UTC (permalink / raw)
Neon Absentius wrote:
> On Fri, Oct 07, 2005 at 03:44:23PM -0700, rgb wrote:
> > How can I tell where, within the current window, I am.
> >
> > Is there any way to tell what window line I'm currently on? Even if I
> > use move-to-window-line and it's successful I may not actually be on
> > that line when it returns. But realistically, I need to know what line
> > I'm on without moving and I don't see how I can tell.
> >
> > I can't seem to fine a way to tell what window column I'm in either.
> > It seems I could probably use (window-width), (current-column) and
> > truncate-lines to figure it out but comments about popup-ruler on the
> > wiki make me think such a formula wouldn't be accurate.
> >
>
> These
>
> (setq line-number-mode t)
> (setq column-number-mode t)
>
> display the line number and curent column in the modeline.
>
But
1) I need the values programatically which neither supplies.
2) Niether actually displays the values I'm looking for either.
They simply display (current-column) and (line-number-at-pos)
which are of little use to this situation.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: window-line and window-column
2005-10-08 0:20 ` rgb
@ 2005-10-08 2:29 ` Neon Absentius
0 siblings, 0 replies; 15+ messages in thread
From: Neon Absentius @ 2005-10-08 2:29 UTC (permalink / raw)
On Fri, Oct 07, 2005 at 05:20:47PM -0700, rgb wrote:
> But
> 1) I need the values programatically which neither supplies.
> 2) Niether actually displays the values I'm looking for either.
> They simply display (current-column) and (line-number-at-pos)
> which are of little use to this situation.
Well I missed the word "window" which is inexcusable since it appears
both before "line" and before "column". However you didn't mention
that you needed these values programmatically, although if I had red
more carefully I would probably have figured it out. Anyway, sorry
for the noise.
--
There is no national science just as there is no national
multiplication table; what is national is no longer science.
-- Anton Checov
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: window-line and window-column
2005-10-07 22:44 window-line and window-column rgb
` (3 preceding siblings ...)
[not found] ` <mailman.10338.1128726582.20277.help-gnu-emacs@gnu.org>
@ 2005-10-11 1:18 ` Hovav Shacham
2005-10-11 3:34 ` rgb
4 siblings, 1 reply; 15+ messages in thread
From: Hovav Shacham @ 2005-10-11 1:18 UTC (permalink / raw)
"rgb" <rbielaws@i1.net> writes:
> How can I tell where, within the current window, I am.
Does any of the functions in windmove.el help? In particular,
`windmove-coordinates-of-position'?
--
Hovav Shacham hovav@hovav.net
"Rightly looked at there is no laughable thing under the sun."
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: window-line and window-column
2005-10-11 1:18 ` Hovav Shacham
@ 2005-10-11 3:34 ` rgb
0 siblings, 0 replies; 15+ messages in thread
From: rgb @ 2005-10-11 3:34 UTC (permalink / raw)
Hovav Shacham wrote:
> "rgb" <rbielaws@i1.net> writes:
>
> > How can I tell where, within the current window, I am.
>
> Does any of the functions in windmove.el help? In particular,
> `windmove-coordinates-of-position'?
>
Apparently that's not part of CVS Emacs.
I did find a copy elsewhere and yes it does give me exactly
what I was looking for. Thanks.
Saddly, several hours after finishing my own version :(
Oh well. I've got a better understanding of compute-motion.
I think I'll be suggesting some wording changes to it's
doc string ... as soon as I think of something that might
have helped me <:'
(defun window-position (&optional visible)
"Returns the cons (screen-line . screen-column) of point.
When VISIBLE is non-nil a screen-column of 0 is returned when a
negative
value would otherwise be returned such as after (scroll-left).
nil is returned if current-buffer is not in the current window."
(if (eq (current-buffer) (window-buffer))
(if (or truncate-lines (/= 0 (window-hscroll)))
;; Lines never wrap when horizontal scrolling is in effect.
(let ((window-column (- (current-column)(window-hscroll)))
(window-line (count-lines (window-start)(point))))
(cond
((= 0 (current-column))
(cons window-line (if visible 0 window-column)))
((<= (current-column) (window-hscroll))
(cons (1- window-line) (if visible 0 window-column)))
(t (cons (1- window-line) window-column))))
;; When lines are not being truncated we deal with wrapping
(let ((window-column (% (current-column)(window-width)))
(window-line (count-screen-lines (window-start)(point))))
(if (= 0 window-column)
(cons window-line window-column)
(cons (1- window-line) window-column))))))
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2005-10-14 15:06 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-07 22:44 window-line and window-column rgb
2005-10-07 23:08 ` Neon Absentius
2005-10-07 23:09 ` Lennart Borgman
2005-10-07 23:27 ` Johan Bockgård
2005-10-08 0:49 ` rgb
2005-10-11 4:05 ` Stefan Monnier
2005-10-11 4:38 ` rgb
2005-10-11 5:02 ` Stefan Monnier
2005-10-11 5:09 ` rgb
2005-10-13 18:02 ` rgb
2005-10-14 15:06 ` rgb
[not found] ` <mailman.10338.1128726582.20277.help-gnu-emacs@gnu.org>
2005-10-08 0:20 ` rgb
2005-10-08 2:29 ` Neon Absentius
2005-10-11 1:18 ` Hovav Shacham
2005-10-11 3:34 ` rgb
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).