开发者

How can I draw to an XY position in Emacs?

开发者 https://www.devze.com 2023-03-26 22:51 出处:网络
I wanted to allow the Emacs cursor to move around freely outside of actual text (similar to virtualedit=all in Vim).

I wanted to allow the Emacs cursor to move around freely outside of actual text (similar to virtualedit=all in Vim).

"Oh," I thought, "I'll just keep track of a virtual cursor and draw it to the screen myself."

But it turns out the actual开发者_运维问答 native C drawing routines (such as draw_glyphs) seem to refer back to the buffer contents to decide what to draw (I could be wrong though).

My next idea was to make a giant overlay of all spaces so I'd have complete freedom where to put stuff. But an overlay only goes over ranges of actual text, so again, this does not seem to give me what I'm looking for.

Is this a reasonable goal without hacking the C code?


I believe the writeable area of a window is intrinsically limited to the buffer with which it is associated, i.e. you have to draw in an area where buffer content exists.

(One example of this limitation is the impossibility of drawing a vertical guide line in the 80th column to help the user identify long lines; currently the best possible implementation of such a feature is to highlight the "overflow" of each too-long line.)


You can do the same as what artist-mode does without adding spaces to the buffer: when trying to place the cursor after the end of the line, just use an overlay with an after-string property which adds the spaces in the display without modifying the buffer.


Have a look at "artist-mode" (M-xartist-modeRET) - it allows you to draw in Emacs.

From the function documentation: "Artist lets you draw lines, squares, rectangles and poly-lines, ellipses and circles with your mouse and/or keyboard."


You can look at popup.el from the auto-complete package, which can pop up tooltips and menus and such at any position, including positions outside the contents of the buffer. Maybe that will show you how you can do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号