help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: How to temporarily show an image in an Emacs buffer?


From: Marcin Borkowski
Subject: Re: How to temporarily show an image in an Emacs buffer?
Date: Wed, 08 Mar 2023 17:01:34 +0100
User-agent: mu4e 1.1.0; emacs 30.0.50

On 2023-03-08, at 07:19, Ruijie Yu <ruijie@netyu.xyz> wrote:

> Marcin Borkowski <mbork@mbork.pl> writes:
>
>> On 2023-03-08, at 05:53, Marcin Borkowski <mbork@mbork.pl> wrote:
>>
>>> Alternatively, it _may_ change the buffer contents but in a way that is
>>> not recorded in `buffer-undo-list'.  Is that possible?
>>
>> I did some experimenting, and this
>>
>> (defvar no-undo-marker (make-marker))
>> (defun no-undo-insert ()
>>   "Test undo."
>>   (save-excursion
>>     (let ((buffer-undo-list))
>>       (set-marker no-undo-marker (point))
>>       (insert "this can't be undone\n"))))
>>
>> (defun no-undo-uninsert ()
>>   (save-excursion
>>     (goto-char no-undo-marker)
>>     (let ((buffer-undo-list))
>>       (when (looking-at-p "this can't be undone\n")
>>   (delete-char 21)))))
>>
>> seems to do the trick, but depending on the order of typing and calling
>> these functions, the undo list becomes corrupted (I get "primitive-undo:
>> Changes to be undone are outside visible portion of buffer").
>>
>> Any hints?
>
> Maybe you can make use of overlays [1]?  That sounds like a great fit
> according to the description of your need.
>
> [1]: (info "(elisp) Managing Overlays")

As I said in my reply to Eli, you were right.  (I knew about overlays,
but I didn't know that apparently you can use an overlay with
a `before-string' property /and/ put another display property on the
/string/ being the value of `before-string', which is kind of cool!)

Thanks,

-- 
Marcin Borkowski
http://mbork.pl



reply via email to

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