aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
authorYuan Fu2022-06-14 15:59:46 -0700
committerYuan Fu2022-06-14 15:59:46 -0700
commit98bfb240818bae14cd87a1ffeb8fae7cb7846e05 (patch)
tree16e8ab06875ed54e110cf98ccdbd7e78f15905c6 /src/buffer.c
parent184d212042ffa5a4f02c92085d9b6e8346d66e99 (diff)
parent787c4ad8b0776280305a220d6669c956d9ed8a5d (diff)
downloademacs-98bfb240818bae14cd87a1ffeb8fae7cb7846e05.tar.gz
emacs-98bfb240818bae14cd87a1ffeb8fae7cb7846e05.zip
Merge remote-tracking branch 'savannah/master' into feature/tree-sitter
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c97
1 files changed, 59 insertions, 38 deletions
diff --git a/src/buffer.c b/src/buffer.c
index f8a7a4f5109..a0761f5b59a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1218,7 +1218,7 @@ is the default binding of the variable. */)
1218{ 1218{
1219 register Lisp_Object result = buffer_local_value (variable, buffer); 1219 register Lisp_Object result = buffer_local_value (variable, buffer);
1220 1220
1221 if (EQ (result, Qunbound)) 1221 if (BASE_EQ (result, Qunbound))
1222 xsignal1 (Qvoid_variable, variable); 1222 xsignal1 (Qvoid_variable, variable);
1223 1223
1224 return result; 1224 return result;
@@ -1313,7 +1313,7 @@ buffer_lisp_local_variables (struct buffer *buf, bool clone)
1313 if (buf != current_buffer) 1313 if (buf != current_buffer)
1314 val = XCDR (elt); 1314 val = XCDR (elt);
1315 1315
1316 result = Fcons (!clone && EQ (val, Qunbound) 1316 result = Fcons (!clone && BASE_EQ (val, Qunbound)
1317 ? XCAR (elt) 1317 ? XCAR (elt)
1318 : Fcons (XCAR (elt), val), 1318 : Fcons (XCAR (elt), val),
1319 result); 1319 result);
@@ -1336,7 +1336,7 @@ buffer_local_variables_1 (struct buffer *buf, int offset, Lisp_Object sym)
1336 { 1336 {
1337 sym = NILP (sym) ? PER_BUFFER_SYMBOL (offset) : sym; 1337 sym = NILP (sym) ? PER_BUFFER_SYMBOL (offset) : sym;
1338 Lisp_Object val = per_buffer_value (buf, offset); 1338 Lisp_Object val = per_buffer_value (buf, offset);
1339 return EQ (val, Qunbound) ? sym : Fcons (sym, val); 1339 return BASE_EQ (val, Qunbound) ? sym : Fcons (sym, val);
1340 } 1340 }
1341 return Qnil; 1341 return Qnil;
1342} 1342}
@@ -1376,12 +1376,23 @@ No argument or nil as argument means use current buffer as BUFFER. */)
1376 1376
1377DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p, 1377DEFUN ("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.
1380No argument or nil as argument means use current buffer as BUFFER. */) 1380No argument or nil as argument means use current buffer as BUFFER.
1381
1382If BUFFER was autosaved since it was last modified, this function
1383returns the symbol `autosaved'. */)
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
1387DEFUN ("force-mode-line-update", Fforce_mode_line_update, 1398DEFUN ("force-mode-line-update", Fforce_mode_line_update,
@@ -1436,6 +1447,11 @@ and `buffer-file-truename' are non-nil. */)
1436DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p, 1447DEFUN ("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.
1450A nil FLAG means to mark the buffer as unmodified. A non-nil FLAG
1451means mark the buffer as modified. A special value of `autosaved'
1452will mark the buffer as modified and also as autosaved since it was
1453last modified.
1454
1439This function also locks or unlocks the file visited by the buffer, 1455This function also locks or unlocks the file visited by the buffer,
1440if both `buffer-file-truename' and `buffer-file-name' are non-nil. 1456if 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 SAVE_MODIFF == auto_save_modified == MODIFF, we can either
1484 we can either decrease SAVE_MODIFF and auto_save_modified 1500 decrease SAVE_MODIFF and auto_save_modified or increase
1485 or increase MODIFF. */ 1501 MODIFF. */
1486 : modiff_incr (&MODIFF)); 1502 if (SAVE_MODIFF >= MODIFF)
1487 1503 SAVE_MODIFF = modiff_incr (&MODIFF);
1504 if (EQ (flag, Qautosaved))
1505 BUF_AUTOSAVE_MODIFF (b) = MODIFF;
1506 }
1488 return flag; 1507 return flag;
1489} 1508}
1490 1509
@@ -1499,6 +1518,18 @@ use current buffer as BUFFER. */)
1499 return modiff_to_integer (BUF_MODIFF (decode_buffer (buffer))); 1518 return modiff_to_integer (BUF_MODIFF (decode_buffer (buffer)));
1500} 1519}
1501 1520
1521DEFUN ("internal--set-buffer-modified-tick",
1522 Finternal__set_buffer_modified_tick, Sinternal__set_buffer_modified_tick,
1523 1, 2, 0,
1524 doc: /* Set BUFFER's tick counter to TICK.
1525No argument or nil as argument means use current buffer as BUFFER. */)
1526 (Lisp_Object tick, Lisp_Object buffer)
1527{
1528 CHECK_FIXNUM (tick);
1529 BUF_MODIFF (decode_buffer (buffer)) = XFIXNUM (tick);
1530 return Qnil;
1531}
1532
1502DEFUN ("buffer-chars-modified-tick", Fbuffer_chars_modified_tick, 1533DEFUN ("buffer-chars-modified-tick", Fbuffer_chars_modified_tick,
1503 Sbuffer_chars_modified_tick, 0, 1, 0, 1534 Sbuffer_chars_modified_tick, 0, 1, 0,
1504 doc: /* Return BUFFER's character-change tick counter. 1535 doc: /* Return BUFFER's character-change tick counter.
@@ -1634,16 +1665,7 @@ exists, return the buffer `*scratch*' (creating it if necessary). */)
1634 if (!NILP (notsogood)) 1665 if (!NILP (notsogood))
1635 return notsogood; 1666 return notsogood;
1636 else 1667 else
1637 { 1668 return safe_call (1, Qget_scratch_buffer_create);
1638 AUTO_STRING (scratch, "*scratch*");
1639 buf = Fget_buffer (scratch);
1640 if (NILP (buf))
1641 {
1642 buf = Fget_buffer_create (scratch, Qnil);
1643 Fset_buffer_major_mode (buf);
1644 }
1645 return buf;
1646 }
1647} 1669}
1648 1670
1649/* The following function is a safe variant of Fother_buffer: It doesn't 1671/* The following function is a safe variant of Fother_buffer: It doesn't
@@ -1659,15 +1681,7 @@ other_buffer_safely (Lisp_Object buffer)
1659 if (candidate_buffer (buf, buffer)) 1681 if (candidate_buffer (buf, buffer))
1660 return buf; 1682 return buf;
1661 1683
1662 AUTO_STRING (scratch, "*scratch*"); 1684 return safe_call (1, Qget_scratch_buffer_create);
1663 buf = Fget_buffer (scratch);
1664 if (NILP (buf))
1665 {
1666 buf = Fget_buffer_create (scratch, Qnil);
1667 Fset_buffer_major_mode (buf);
1668 }
1669
1670 return buf;
1671} 1685}
1672 1686
1673DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo, 1687DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo,
@@ -4093,7 +4107,7 @@ buffer. */)
4093 n_end = marker_position (OVERLAY_END (overlay)); 4107 n_end = marker_position (OVERLAY_END (overlay));
4094 4108
4095 /* If the overlay has changed buffers, do a thorough redisplay. */ 4109 /* If the overlay has changed buffers, do a thorough redisplay. */
4096 if (!EQ (buffer, obuffer)) 4110 if (!BASE_EQ (buffer, obuffer))
4097 { 4111 {
4098 /* Redisplay where the overlay was. */ 4112 /* Redisplay where the overlay was. */
4099 if (ob) 4113 if (ob)
@@ -5552,6 +5566,7 @@ syms_of_buffer (void)
5552 DEFSYM (Qbefore_change_functions, "before-change-functions"); 5566 DEFSYM (Qbefore_change_functions, "before-change-functions");
5553 DEFSYM (Qafter_change_functions, "after-change-functions"); 5567 DEFSYM (Qafter_change_functions, "after-change-functions");
5554 DEFSYM (Qkill_buffer_query_functions, "kill-buffer-query-functions"); 5568 DEFSYM (Qkill_buffer_query_functions, "kill-buffer-query-functions");
5569 DEFSYM (Qget_scratch_buffer_create, "get-scratch-buffer-create");
5555 5570
5556 DEFSYM (Qvertical_scroll_bar, "vertical-scroll-bar"); 5571 DEFSYM (Qvertical_scroll_bar, "vertical-scroll-bar");
5557 Fput (Qvertical_scroll_bar, Qchoice, list4 (Qnil, Qt, Qleft, Qright)); 5572 Fput (Qvertical_scroll_bar, Qchoice, list4 (Qnil, Qt, Qleft, Qright));
@@ -5583,8 +5598,11 @@ the mode line appears at the bottom. */);
5583 &BVAR (current_buffer, header_line_format), 5598 &BVAR (current_buffer, header_line_format),
5584 Qnil, 5599 Qnil,
5585 doc: /* Analogous to `mode-line-format', but controls the header line. 5600 doc: /* Analogous to `mode-line-format', but controls the header line.
5586The header line appears, optionally, at the top of a window; 5601The header line appears, optionally, at the top of a window; the mode
5587the mode line appears at the bottom. */); 5602line appears at the bottom.
5603
5604Also see `header-line-indent-mode' if `display-line-number-mode' is
5605used. */);
5588 5606
5589 DEFVAR_PER_BUFFER ("mode-line-format", &BVAR (current_buffer, mode_line_format), 5607 DEFVAR_PER_BUFFER ("mode-line-format", &BVAR (current_buffer, mode_line_format),
5590 Qnil, 5608 Qnil,
@@ -6418,6 +6436,7 @@ will run for `clone-indirect-buffer' calls as well. */);
6418 defsubr (&Sforce_mode_line_update); 6436 defsubr (&Sforce_mode_line_update);
6419 defsubr (&Sset_buffer_modified_p); 6437 defsubr (&Sset_buffer_modified_p);
6420 defsubr (&Sbuffer_modified_tick); 6438 defsubr (&Sbuffer_modified_tick);
6439 defsubr (&Sinternal__set_buffer_modified_tick);
6421 defsubr (&Sbuffer_chars_modified_tick); 6440 defsubr (&Sbuffer_chars_modified_tick);
6422 defsubr (&Srename_buffer); 6441 defsubr (&Srename_buffer);
6423 defsubr (&Sother_buffer); 6442 defsubr (&Sother_buffer);
@@ -6452,5 +6471,7 @@ will run for `clone-indirect-buffer' calls as well. */);
6452 defsubr (&Soverlay_put); 6471 defsubr (&Soverlay_put);
6453 defsubr (&Srestore_buffer_modified_p); 6472 defsubr (&Srestore_buffer_modified_p);
6454 6473
6474 DEFSYM (Qautosaved, "autosaved");
6475
6455 Fput (intern_c_string ("erase-buffer"), Qdisabled, Qt); 6476 Fput (intern_c_string ("erase-buffer"), Qdisabled, Qt);
6456} 6477}