TransWikia.com

Move point inside of image overlay

Emacs Asked by Cardano on November 10, 2021

I’m trying to create a realtime/WYSIWYG editor for LaTeX fragments — the general idea is that at each move of point / edit of the fragment, the overlay should update to reflect the newly changed fragment, including a cursor symbol indicating where point is now.

However, it’s impossible to move point into an image overlay — any command that would end up inside the overlaid region is preempted so that point ends up at the end of the overlay.

Is there any way to override this behavior so that point can be inside of the overlaid region? I know I can do this XWidgets but I would prefer that the solution be compatible with the built-in fragment preview mechanism that org offers, which uses overlays.

An example of the behavior that I’m talking about: Run the following function with some image, with point at 1:

(defun image-overlay-minimal-repro ()
  (interactive)
  (let ((ov (make-overlay (point) (+ (point) 10))))
    (overlay-put ov
                 'display
                 (list 'image :type 'png :file "~/Downloads/dog-png-dog-png-image-267.png"))))

; 1234567890 test test

The image overlay will occlude all the digits, and it only takes one motion of point to cross the entire overlay. I want it to take 10 movements of point.

2 Answers

I believe you are looking for the variable disable-point-adjustment. You will want to read its docstring to better understand how you want to use it (i.e. you'll have to reset it every time point "enters" one of those overlays).

Answered by Stefan on November 10, 2021

No, this isn't possible. To quote the manual ("Replacing Specs"):

Some kinds of display specifications specify something to display instead of the text that has the property. These are called “replacing” display specifications. Emacs does not allow the user to interactively move point into the middle of buffer text that is replaced in this way.

You'd instead have to track attempts at the user moving point inside the overlay and at which point of the text they'd be at, then update the image accordingly. Overlays have a keymap attribute that can be used for that purpose.

Answered by wasamasa on November 10, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP