[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to determine buffer change
From: |
Thorsten Jolitz |
Subject: |
Re: How to determine buffer change |
Date: |
Sat, 05 Apr 2014 15:23:22 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Thorsten Jolitz <tjolitz@gmail.com> writes:
> Eli Zaretskii <eliz@gnu.org> writes:
>
>>> From: Thorsten Jolitz <tjolitz@gmail.com>
>>> Date: Sat, 05 Apr 2014 13:41:41 +0200
>>>
>>> in a program I insert text in an empty temporary edit-buffer, what of
>>> course modifies the `buffer-undo-list'.
>>> Assume that at this moment (lets call it time T1)
>>>
>>> ,------------------------------
>>> | M-: (length buffer-undo-list)
>>> `------------------------------
>>>
>>> returns 9.
>>>
>>> Now when there are changes to the text in the edit-buffer, these are
>>> copied to the original buffer after quitting. But when nothing has
>>> changed after the insertion of the original text, it would be better to
>>> simply discard the edit-buffer and not touch the original buffer at
>>> all.
>>>
>>> I could remember the length of the buffer-undo-list at time T1 and then
>>> check if it changed when quitting, but this does not seem very robust,
>>> since this length grows and shrinks in both directions.
>>
>> Did you try using buffer-modified-tick?
>
> Thats it probably, thanks.
>
> Still have to figure out when to store the ticks - although I think I
> set them directly after edit-buffer setup and directly before
> edit-buffer quitting, the tick values differ quite a lot although no
> editing took place, e.g.:
>
> ,---------------------
> | tick1: 48 tick2: 97
> | tick1: 76 tick2: 229
> `---------------------
Actually I have this as last expression in the edit-buffer set-up
function:
#+begin_src emacs-lisp
(defun tj/setup-edit-buffer ()
;; [...]
;; store buffer-modified-tick at time T1
(setq edit-buffer-modified-tick-1
(buffer-modified-tick)))
#+end_src
and this as first expression in the edit-buffer quit function:
#+begin_src emacs-lisp
(defun tj/quit-edit-buffer ()
;; store buffer-modified-tick at time T2
(setq edit-buffer-modified-tick-2 (buffer-modified-tick))
(if (eq edit-buffer-modified-tick-1
edit-buffer-modified-tick-2)
(progn
;; [...]
)))
#+end_src
and I did nothing else but calling and quitting the edit-buffer,
however ticks have almost doubled in numbers in between:
,--------------------
| tick1: 48 tick2: 97
`--------------------
Can that be related to buffer fontifying or other stuff that happens
lazily with a bit lag to the initial buffer set-up?
--
cheers,
Thorsten