diff options
| author | Lars Ingebrigtsen | 2022-05-10 03:38:01 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2022-05-10 03:46:43 +0200 |
| commit | 0bee4cda881f7db4113cba541b684c334e828c4a (patch) | |
| tree | 4873dc599fb34e07c5e967ea5d91cb867c151c1b /src/buffer.c | |
| parent | 0b2f550e3229c7a1b001fb1a09e7a5b4e3ecfb3e (diff) | |
| download | emacs-0bee4cda881f7db4113cba541b684c334e828c4a.tar.gz emacs-0bee4cda881f7db4113cba541b684c334e828c4a.zip | |
Reimplement recent with-silent-modifications auto-save changes
* doc/lispref/buffers.texi (Buffer Modification): Document
buffer-modified-p returning `autosaved'.
* lisp/subr.el (with-silent-modifications): Use
restore-buffer-modified-p instead of altering the buffer modiff
(since this has other side effects like not updating after async
`display' changes.
* src/buffer.c (Fbuffer_modified_p): Allow returning whether the
buffer has been autosaved after changes.
(Frestore_buffer_modified_p): Allow adjusting whether the buffer
has been autosaved after changes.
* src/fileio.c (Fdo_auto_save): Refill the doc string.
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 47 |
1 files changed, 34 insertions, 13 deletions
diff --git a/src/buffer.c b/src/buffer.c index 6334e197f0e..f54714675e2 100644 --- a/src/buffer.c +++ b/src/buffer.c | |||
| @@ -1376,12 +1376,23 @@ No argument or nil as argument means use current buffer as BUFFER. */) | |||
| 1376 | 1376 | ||
| 1377 | DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p, | 1377 | DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p, |
| 1378 | 0, 1, 0, | 1378 | 0, 1, 0, |
| 1379 | doc: /* Return t if BUFFER was modified since its file was last read or saved. | 1379 | doc: /* Return non-nil if BUFFER was modified since its file was last read or saved. |
| 1380 | No argument or nil as argument means use current buffer as BUFFER. */) | 1380 | No argument or nil as argument means use current buffer as BUFFER. |
| 1381 | |||
| 1382 | If BUFFER has been autosaved after BUFFER was last modified, the | ||
| 1383 | symbol `autosaved' is returned. */) | ||
| 1381 | (Lisp_Object buffer) | 1384 | (Lisp_Object buffer) |
| 1382 | { | 1385 | { |
| 1383 | struct buffer *buf = decode_buffer (buffer); | 1386 | struct buffer *buf = decode_buffer (buffer); |
| 1384 | return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil; | 1387 | if (BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf)) |
| 1388 | { | ||
| 1389 | if (BUF_AUTOSAVE_MODIFF (buf) == BUF_MODIFF (buf)) | ||
| 1390 | return Qautosaved; | ||
| 1391 | else | ||
| 1392 | return Qt; | ||
| 1393 | } | ||
| 1394 | else | ||
| 1395 | return Qnil; | ||
| 1385 | } | 1396 | } |
| 1386 | 1397 | ||
| 1387 | DEFUN ("force-mode-line-update", Fforce_mode_line_update, | 1398 | DEFUN ("force-mode-line-update", Fforce_mode_line_update, |
| @@ -1436,6 +1447,11 @@ and `buffer-file-truename' are non-nil. */) | |||
| 1436 | DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p, | 1447 | DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p, |
| 1437 | Srestore_buffer_modified_p, 1, 1, 0, | 1448 | Srestore_buffer_modified_p, 1, 1, 0, |
| 1438 | doc: /* Like `set-buffer-modified-p', but doesn't redisplay buffer's mode line. | 1449 | doc: /* Like `set-buffer-modified-p', but doesn't redisplay buffer's mode line. |
| 1450 | A nil FLAG means to mark the buffer as unmodified. A non-nil FLAG | ||
| 1451 | means mark the buffer as modified, except the special value | ||
| 1452 | `autosaved', which will instead mark the buffer as having been | ||
| 1453 | autosaved. | ||
| 1454 | |||
| 1439 | This function also locks or unlocks the file visited by the buffer, | 1455 | This function also locks or unlocks the file visited by the buffer, |
| 1440 | if both `buffer-file-truename' and `buffer-file-name' are non-nil. | 1456 | if both `buffer-file-truename' and `buffer-file-name' are non-nil. |
| 1441 | 1457 | ||
| @@ -1475,16 +1491,19 @@ state of the current buffer. Use with care. */) | |||
| 1475 | recent-auto-save-p from t to nil. | 1491 | recent-auto-save-p from t to nil. |
| 1476 | Vice versa, if FLAG is non-nil and SAVE_MODIFF>=auto_save_modified | 1492 | Vice versa, if FLAG is non-nil and SAVE_MODIFF>=auto_save_modified |
| 1477 | we risk changing recent-auto-save-p from nil to t. */ | 1493 | we risk changing recent-auto-save-p from nil to t. */ |
| 1478 | SAVE_MODIFF = (NILP (flag) | 1494 | if (NILP (flag)) |
| 1479 | /* FIXME: This unavoidably sets recent-auto-save-p to nil. */ | 1495 | /* This unavoidably sets recent-auto-save-p to nil. */ |
| 1480 | ? MODIFF | 1496 | SAVE_MODIFF = MODIFF; |
| 1481 | /* Let's try to preserve recent-auto-save-p. */ | 1497 | else |
| 1482 | : SAVE_MODIFF < MODIFF ? SAVE_MODIFF | 1498 | { |
| 1483 | /* If SAVE_MODIFF == auto_save_modified == MODIFF, | 1499 | if (EQ (flag, Qautosaved)) |
| 1484 | we can either decrease SAVE_MODIFF and auto_save_modified | 1500 | BUF_AUTOSAVE_MODIFF (b) = MODIFF; |
| 1485 | or increase MODIFF. */ | 1501 | /* If SAVE_MODIFF == auto_save_modified == MODIFF, we can either |
| 1486 | : modiff_incr (&MODIFF)); | 1502 | decrease SAVE_MODIFF and auto_save_modified or increase |
| 1487 | 1503 | MODIFF. */ | |
| 1504 | else if (SAVE_MODIFF >= MODIFF) | ||
| 1505 | SAVE_MODIFF = modiff_incr (&MODIFF); | ||
| 1506 | } | ||
| 1488 | return flag; | 1507 | return flag; |
| 1489 | } | 1508 | } |
| 1490 | 1509 | ||
| @@ -6465,5 +6484,7 @@ will run for `clone-indirect-buffer' calls as well. */); | |||
| 6465 | defsubr (&Soverlay_put); | 6484 | defsubr (&Soverlay_put); |
| 6466 | defsubr (&Srestore_buffer_modified_p); | 6485 | defsubr (&Srestore_buffer_modified_p); |
| 6467 | 6486 | ||
| 6487 | DEFSYM (Qautosaved, "autosaved"); | ||
| 6488 | |||
| 6468 | Fput (intern_c_string ("erase-buffer"), Qdisabled, Qt); | 6489 | Fput (intern_c_string ("erase-buffer"), Qdisabled, Qt); |
| 6469 | } | 6490 | } |