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

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.