unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Marcin Borkowski <mbork@mbork.pl>
To: Ruijie Yu <ruijie@netyu.xyz>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to temporarily show an image in an Emacs buffer?
Date: Wed, 08 Mar 2023 17:01:34 +0100	[thread overview]
Message-ID: <875ybbdyg1.fsf@mbork.pl> (raw)
In-Reply-To: <sdvedpzkbky.fsf@fw.net.yu>


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	other threads:[~2023-03-08 16:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-08  4:53 How to temporarily show an image in an Emacs buffer? Marcin Borkowski
2023-03-08  5:23 ` Marcin Borkowski
2023-03-08  6:19   ` Ruijie Yu via Users list for the GNU Emacs text editor
2023-03-08 16:01     ` Marcin Borkowski [this message]
2023-03-08 16:41   ` Michael Heerdegen
2023-03-11  8:14     ` Marcin Borkowski
2023-03-12  3:37       ` Michael Heerdegen
2023-03-12  7:46         ` Marcin Borkowski
2023-03-08 13:38 ` Eli Zaretskii
2023-03-08 16:00   ` Marcin Borkowski
2023-03-13  8:29     ` Jean Louis
2023-03-13  9:27       ` Marcin Borkowski
2023-04-01 15:57       ` Marcin Borkowski
2023-03-10 16:26 ` Stefan Monnier via Users list for the GNU Emacs text editor
2023-03-11  8:15   ` Marcin Borkowski

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=875ybbdyg1.fsf@mbork.pl \
    --to=mbork@mbork.pl \
    --cc=help-gnu-emacs@gnu.org \
    --cc=ruijie@netyu.xyz \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).