From: Lars Ingebrigtsen Date: Thu, 12 May 2022 00:16:38 +0000 (+0200) Subject: Adjust restore-buffer-modified-p autosaved logic X-Git-Tag: emacs-29.0.90~1910^2~782 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1642a5ffcdf734c629e5aec963a0b190997704d6;p=emacs.git 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". --- diff --git a/doc/lispref/buffers.texi b/doc/lispref/buffers.texi index 2e5771f3474..9f3808a45b1 100644 --- a/doc/lispref/buffers.texi +++ b/doc/lispref/buffers.texi @@ -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 diff --git a/src/buffer.c b/src/buffer.c index 0af14a10609..89b04a42801 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -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; } diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el index 10dac68f9fe..f6a18acaa64 100644 --- a/test/src/buffer-tests.el +++ b/test/src/buffer-tests.el @@ -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