Adjust restore-buffer-modified-p autosaved logic

* doc/lispref/buffers.texi (Buffer Modification): Adjust
documentation.

* src/buffer.c (Frestore_buffer_modified_p): Fix up the logic
around `autosaved': It means "the buffer is modified, and also
autosaved".
This commit is contained in:
Lars Ingebrigtsen 2022-05-12 02:16:38 +02:00
parent dce85743b6
commit 1642a5ffcd
3 changed files with 19 additions and 9 deletions

View file

@ -565,9 +565,9 @@ function @code{force-mode-line-update} works by doing this:
@end defun
@defun restore-buffer-modified-p flag
Like @code{set-buffer-modified-p}, but does not force redisplay
of mode lines. This function also allows a @var{flag} value of
@code{autosaved}, which marks the buffer as having been autosaved
Like @code{set-buffer-modified-p}, but does not force redisplay of
mode lines. This function also allows a @var{flag} value of
@code{autosaved}, which also marks the buffer as having been autosaved
after the last modification.
@end defun

View file

@ -1448,9 +1448,9 @@ DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p,
Srestore_buffer_modified_p, 1, 1, 0,
doc: /* Like `set-buffer-modified-p', but doesn't redisplay buffer's mode line.
A nil FLAG means to mark the buffer as unmodified. A non-nil FLAG
means mark the buffer as modified, but the special value
`autosaved' will instead mark the buffer as having been
autosaved since it was last modified.
means mark the buffer as modified. A special value of `autosaved'
will mark the buffer modified, and also as having been autosaved since
it was last modified.
This function also locks or unlocks the file visited by the buffer,
if both `buffer-file-truename' and `buffer-file-name' are non-nil.
@ -1496,13 +1496,13 @@ state of the current buffer. Use with care. */)
SAVE_MODIFF = MODIFF;
else
{
if (EQ (flag, Qautosaved))
BUF_AUTOSAVE_MODIFF (b) = MODIFF;
/* If SAVE_MODIFF == auto_save_modified == MODIFF, we can either
decrease SAVE_MODIFF and auto_save_modified or increase
MODIFF. */
else if (SAVE_MODIFF >= MODIFF)
if (SAVE_MODIFF >= MODIFF)
SAVE_MODIFF = modiff_incr (&MODIFF);
if (EQ (flag, Qautosaved))
BUF_AUTOSAVE_MODIFF (b) = MODIFF;
}
return flag;
}

View file

@ -1515,6 +1515,16 @@ with parameters from the *Messages* buffer modification."
(should (eq (buffer-modified-p) 'autosaved))
(insert "zot")
(restore-buffer-modified-p 'autosaved)
(should (eq (buffer-modified-p) 'autosaved))))
(ert-with-temp-file file
(with-current-buffer (find-file file)
(auto-save-mode 1)
(should-not (buffer-modified-p))
(insert "foo")
(should (buffer-modified-p))
(should-not (eq (buffer-modified-p) 'autosaved))
(restore-buffer-modified-p 'autosaved)
(should (eq (buffer-modified-p) 'autosaved)))))
;;; buffer-tests.el ends here