diff jde-hax.el @ 31:129123962e51

trying to merge lib/emacs and xemacs
author Henry S Thompson <ht@inf.ed.ac.uk>
date Sat, 07 Oct 2023 12:43:14 +0100
parents 5f3a215f12eb
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jde-hax.el	Sat Oct 07 12:43:14 2023 +0100
@@ -0,0 +1,27 @@
+(defun jde-cursor-posn-as-event(&optional forceText)
+  "Returns the text cursor position as an EVENT on Emacs and the mouse
+cursor position on XEmacs."
+  (if (and jde-xemacsp (not forceText))
+      (let* ((mouse-pos (mouse-pixel-position))
+             (x (car (cdr mouse-pos)))
+             (y (cdr (cdr mouse-pos))))
+	(if x
+	    (make-event 'button-press `(button 1 modifiers nil x ,x y ,y))
+	  (let ((fake (jde-cursor-posn-as-event t)))
+	    (make-event 'button-press `(button 1 modifiers nil
+					       x ,(caar fake)
+					       y ,(cadar fake))))))
+    (let ((x (* (if jde-xemacsp (/(window-pixel-width)(window-width))
+		  (frame-char-width))
+                (if (and
+                     (boundp 'hscroll-mode)
+                     (fboundp 'hscroll-window-column))
+                    (hscroll-window-column)
+                  (mod (current-column) (window-width)))))
+          (y  (* (if jde-xemacsp (/ (window-pixel-height)
+				    (window-height))
+		   (frame-char-height)) 
+                 (- (count-lines (point-min) (point))
+                    (count-lines (point-min) (window-start)))))
+          (window (get-buffer-window (current-buffer))))
+      (list (list x y) window))))