all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* New primitive buffer-position-at
@ 2005-01-11 21:54 Nick Roberts
  2005-01-11 22:48 ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Nick Roberts @ 2005-01-11 21:54 UTC (permalink / raw)



I would like to include the following primitive that returns the buffer
position from the window co-ordinates. Its for use with files like
xt-mouse.el and t-mouse.el which cannot access this information directly.
It is styled on window-at.

Nick


*** /home/nick/emacs/src/dispnew.c.~1.336.~	2004-11-01 12:58:29.000000000 +1300
--- /home/nick/emacs/src/dispnew.c	2005-01-10 12:03:35.000000000 +1300
***************
*** 5809,5814 ****
--- 5809,5840 ----
    return string;
  }
  
+ DEFUN ("buffer-position-at", Fbuffer_position_at, SBuffer_position_at, 2, 3, 0,
+        doc: /* Return the buffer position at coordinates X and Y in WINDOW.
+ If omitted, WINDOW defaults to the currently selected WINDOW. */)
+      (x, y, window)
+      Lisp_Object x, y, window;
+ {
+   struct window *w;
+   struct frame *f;
+   int xcoord, ycoord;
+   struct display_pos pos;
+   Lisp_Object object;
+   int dx, dy;
+   int width, height;
+ 
+   if (NILP (window))
+     window = selected_window;
+   else
+     CHECK_WINDOW (window);
+   w = XWINDOW (window);
+   f = XFRAME (w->frame);
+   xcoord = FRAME_PIXEL_X_FROM_CANON_X (f, x) + FRAME_INTERNAL_BORDER_WIDTH (f);
+   ycoord = FRAME_PIXEL_Y_FROM_CANON_Y (f, y) + FRAME_INTERNAL_BORDER_WIDTH (f);
+   buffer_posn_from_coords (w, &xcoord, &ycoord, &pos,
+ 			   &object, &dx, &dy, &width, &height);
+   return make_number ((pos.pos).charpos);
+ }
  
  /* Value is the string under window-relative coordinates X/Y in the
     mode line or header line (PART says which) of window W, or nil if none.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: New primitive buffer-position-at
  2005-01-11 21:54 New primitive buffer-position-at Nick Roberts
@ 2005-01-11 22:48 ` Stefan Monnier
  2005-01-11 23:16   ` Nick Roberts
  2005-01-12  5:59   ` Eli Zaretskii
  0 siblings, 2 replies; 9+ messages in thread
From: Stefan Monnier @ 2005-01-11 22:48 UTC (permalink / raw)
  Cc: emacs-devel

> +        doc: /* Return the buffer position at coordinates X and Y in WINDOW.
> + If omitted, WINDOW defaults to the currently selected WINDOW. */)

Could you describe more precisely what the coordinates are (in pixels or
chars?  1 or 0 based? relative to the the farme or window? ...).

Also, in what way is it different from (posn-point (posn-at-x-y X Y)) ?


        Stefan "who's wondering what posn-at-x-y does on a tty"

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: New primitive buffer-position-at
  2005-01-11 22:48 ` Stefan Monnier
@ 2005-01-11 23:16   ` Nick Roberts
  2005-01-11 23:32     ` Stefan Monnier
  2005-01-12  6:08     ` Eli Zaretskii
  2005-01-12  5:59   ` Eli Zaretskii
  1 sibling, 2 replies; 9+ messages in thread
From: Nick Roberts @ 2005-01-11 23:16 UTC (permalink / raw)
  Cc: emacs-devel

 > > +        doc: /* Return the buffer position at coordinates X and Y in WINDOW.
 > > + If omitted, WINDOW defaults to the currently selected WINDOW. */)
 > 
 > Could you describe more precisely what the coordinates are (in pixels or
 > chars?  1 or 0 based? relative to the the farme or window? ...).

They are the same co-ordinates as used in window-at i.e in chars and 0 based.
Perhaps I should add:

The top left corner of the frame is considered to be row 0, column 0.

to the documentation.


 > Also, in what way is it different from (posn-point (posn-at-x-y X Y)) ?
 > 
 > 
 >         Stefan "who's wondering what posn-at-x-y does on a tty"

The posn-* family of commands (posn-point, posn-object etc) only work if Emacs
provides the proper click event in the first place which it doesn't currently
do on a text terminal or xterm.  My patches to xt-mouse.el and t-mouse.el
provide them in lisp i.e with these patches the posn-* family of commands will
work on a text terminal or xterm.

Nick

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: New primitive buffer-position-at
  2005-01-11 23:16   ` Nick Roberts
@ 2005-01-11 23:32     ` Stefan Monnier
  2005-01-12  6:11       ` Nick Roberts
  2005-01-12  6:08     ` Eli Zaretskii
  1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2005-01-11 23:32 UTC (permalink / raw)
  Cc: emacs-devel

> They are the same co-ordinates as used in window-at i.e in chars and 0 based.
> Perhaps I should add:

> The top left corner of the frame is considered to be row 0, column 0.

> to the documentation.

Yes, the docstring should make it clear.  It can refer to window-at.

>> Also, in what way is it different from (posn-point (posn-at-x-y X Y)) ?
>> 
>> 
>> Stefan "who's wondering what posn-at-x-y does on a tty"

> The posn-* family of commands (posn-point, posn-object etc) only work if
> Emacs provides the proper click event in the first place which it doesn't
> currently do on a text terminal or xterm.  My patches to xt-mouse.el and
> t-mouse.el provide them in lisp i.e with these patches the posn-* family
> of commands will work on a text terminal or xterm.

Try C-h f posn-at-x-y RET


        Stefan

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: New primitive buffer-position-at
  2005-01-11 22:48 ` Stefan Monnier
  2005-01-11 23:16   ` Nick Roberts
@ 2005-01-12  5:59   ` Eli Zaretskii
  1 sibling, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2005-01-12  5:59 UTC (permalink / raw)
  Cc: nickrob, emacs-devel

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Tue, 11 Jan 2005 17:48:58 -0500
> Cc: emacs-devel@gnu.org
> 
>         Stefan "who's wondering what posn-at-x-y does on a tty"

On a tty, 1 pixel = 1 character (for the text area only, of course).
This is how all the pixel-related macros are defined on a tty, so if
you see any other behavior, that's a bug.  The mouse on a tty, if
supported, also works in character units.

In particular, posn-at-x-y on a tty assumes that its 2 arguments are
window-relative coordinates in character units.  I just tried that,
and it seems to do what I'd expect.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: New primitive buffer-position-at
  2005-01-11 23:16   ` Nick Roberts
  2005-01-11 23:32     ` Stefan Monnier
@ 2005-01-12  6:08     ` Eli Zaretskii
  2005-01-12  6:58       ` Nick Roberts
  1 sibling, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2005-01-12  6:08 UTC (permalink / raw)
  Cc: monnier, emacs-devel

> From: Nick Roberts <nickrob@snap.net.nz>
> Date: Wed, 12 Jan 2005 12:16:06 +1300
> Cc: emacs-devel@gnu.org
> 
>  > Also, in what way is it different from (posn-point (posn-at-x-y X Y)) ?
>  > 
>  > 
>  >         Stefan "who's wondering what posn-at-x-y does on a tty"
> 
> The posn-* family of commands (posn-point, posn-object etc) only work if Emacs
> provides the proper click event in the first place which it doesn't currently
> do on a text terminal or xterm.

??? Are you saying that posn-point would throw an error or otherwise
behave incorrectly if invoked on a tty without a mouse?  I tried that,
and it seemed to work fine for me.

I think whether a mouse is connected or not is not an issue, since a
click event object can be created manually even if there's no mouse.
And posn-at-x-y does precisely that, doesn't it?

> My patches to xt-mouse.el and t-mouse.el
> provide them in lisp i.e with these patches the posn-* family of commands will
> work on a text terminal or xterm.

I'm puzzled why did you need to patch xt-mouse.el, since these 2
functions seem to work for me on a tty, even a tty that lacks the
mouse.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: New primitive buffer-position-at
  2005-01-11 23:32     ` Stefan Monnier
@ 2005-01-12  6:11       ` Nick Roberts
  2005-01-12 18:40         ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Nick Roberts @ 2005-01-12  6:11 UTC (permalink / raw)
  Cc: emacs-devel


 > Try C-h f posn-at-x-y RET

Hmm! I don't know how I missed that one. I can't even use my usual excuse of
it not being in the manual.

On the one hand that makes my function useless, but on the other it makes what
I'm ultimately trying to do much simpler.


Nick

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: New primitive buffer-position-at
  2005-01-12  6:08     ` Eli Zaretskii
@ 2005-01-12  6:58       ` Nick Roberts
  0 siblings, 0 replies; 9+ messages in thread
From: Nick Roberts @ 2005-01-12  6:58 UTC (permalink / raw)
  Cc: monnier, emacs-devel

 > > The posn-* family of commands (posn-point, posn-object etc) only work if
 > > Emacs provides the proper click event in the first place which it doesn't
 > > currently do on a text terminal or xterm.
 > 
 > ??? Are you saying that posn-point would throw an error or otherwise
 > behave incorrectly if invoked on a tty without a mouse?  I tried that,
 > and it seemed to work fine for me.

I'm trying to say that posn-point etc doesn't work if invoked on a tty *with*
a mouse. 

For example, calling the function below in an xterm, xt-mouse.el doesn't
provide the full click event and so (posn-point posn) is not a number.

(defun gdb-mouse-toggle-breakpoint (event)
  "Toggle breakpoint in left fringe/margin with mouse click."
  (interactive "e")
  (mouse-minibuffer-check event)
  (let ((posn (event-end event)))
    (if (numberp (posn-point posn))
	(with-selected-window (posn-window posn)
	  (save-excursion
	    (goto-char (posn-point posn))
	    (if (or (posn-object posn)
            ...

 > I'm puzzled why did you need to patch xt-mouse.el, since these 2
 > functions seem to work for me on a tty, even a tty that lacks the
 > mouse.

I've just committed my changes to xt-mouse.el. With these, if you start Emacs
in an xterm, you should now be able to select another buffer etc by clicking
on the mode-line, navigate info from the header line, set breakpoints with the
mouse...

I have done the same for a text-terminal with t-mouse.el, but FSF doesn't have
an assignment yet to let me install this file.


Nick

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: New primitive buffer-position-at
  2005-01-12  6:11       ` Nick Roberts
@ 2005-01-12 18:40         ` Stefan Monnier
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2005-01-12 18:40 UTC (permalink / raw)
  Cc: emacs-devel

>> Try C-h f posn-at-x-y RET
> Hmm! I don't know how I missed that one. I can't even use my usual excuse of
> it not being in the manual.

You're excused: it's a recent addition.


        Stefan

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-01-12 18:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-11 21:54 New primitive buffer-position-at Nick Roberts
2005-01-11 22:48 ` Stefan Monnier
2005-01-11 23:16   ` Nick Roberts
2005-01-11 23:32     ` Stefan Monnier
2005-01-12  6:11       ` Nick Roberts
2005-01-12 18:40         ` Stefan Monnier
2005-01-12  6:08     ` Eli Zaretskii
2005-01-12  6:58       ` Nick Roberts
2005-01-12  5:59   ` Eli Zaretskii

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.