all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Nick Roberts <nickrob@snap.net.nz>
Subject: New primitive buffer-position-at
Date: Wed, 12 Jan 2005 10:54:47 +1300	[thread overview]
Message-ID: <16868.19239.506292.507882@farnswood.snap.net.nz> (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.

             reply	other threads:[~2005-01-11 21:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-11 21:54 Nick Roberts [this message]
2005-01-11 22:48 ` New primitive buffer-position-at 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=16868.19239.506292.507882@farnswood.snap.net.nz \
    --to=nickrob@snap.net.nz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.