emacs-devel
[Top][All Lists]
Advanced

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

New primitive buffer-position-at


From: Nick Roberts
Subject: New primitive buffer-position-at
Date: Wed, 12 Jan 2005 10:54:47 +1300

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.




reply via email to

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