[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: insert-file-contents and format-decode
From: |
martin rudalics |
Subject: |
Re: insert-file-contents and format-decode |
Date: |
Tue, 03 Jul 2007 08:47:05 +0200 |
User-agent: |
Mozilla Thunderbird 1.0 (Windows/20041206) |
> ! (let (value size old-undo)
> ! ;; Record only one undo entry for the insertion. Inhibit
point-motion and
> ! ;; modification hooks as with `insert-file-contents'.
> ! (let ((inhibit-point-motion-hooks t)
> ! (inhibit-modification-hooks t))
> ! ;; Don't bind `buffer-undo-list' to t here to assert that
> ! ;; `insert-file-contents' may record whether the buffer was
unmodified
> ! ;; before.
> ! (let ((format-alist nil))
> ! (setq value (insert-file-contents filename nil beg end))
> ! (setq size (nth 1 value)))
> ! (when (consp buffer-undo-list)
> ! (let ((head (car buffer-undo-list)))
> ! (when (and (consp head)
> ! (equal (car head) (point))
> ! (equal (cdr head) (+ (point) size)))
> ! ;; Remove first entry from `buffer-undo-list', we shall insert
> ! ;; another one below.
> ! (setq old-undo (cdr buffer-undo-list)))))
>
> That pateh is basically good, but it could be simpler. Instead of
> letting insert-file-contents produce an undo entry and taking it off
> and taking it apart, it would be better to inhibit undo around
> insert-file-contents and generate the undo entry from scratch in all
> cases. When no format decoding is done, VALUE has the size you need.
It's complicated because I may have to create the (t HIGH . LOW) entry
to indicate that the buffer previously had "unmodified" status. With my
solution I let `insert-file-contents' take care of that automatically.
With your solution I would have to create it manually and care about the
modification time myself. Is it worth the trouble?