From e8488bcc9cbbeafe6307a73b2386ced986327618 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 7 May 2022 12:05:48 +0200 Subject: Avoid having font locking triggering unnecessary auto-saving * lisp/subr.el (with-silent-modifications): Use it to restore the ticks (bug#11303). * src/buffer.c (Finternal__set_buffer_modified_tick): New function. --- src/buffer.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/buffer.c') diff --git a/src/buffer.c b/src/buffer.c index f8a7a4f5109..6334e197f0e 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1499,6 +1499,18 @@ use current buffer as BUFFER. */) return modiff_to_integer (BUF_MODIFF (decode_buffer (buffer))); } +DEFUN ("internal--set-buffer-modified-tick", + Finternal__set_buffer_modified_tick, Sinternal__set_buffer_modified_tick, + 1, 2, 0, + doc: /* Set BUFFER's tick counter to TICK. +No argument or nil as argument means use current buffer as BUFFER. */) + (Lisp_Object tick, Lisp_Object buffer) +{ + CHECK_FIXNUM (tick); + BUF_MODIFF (decode_buffer (buffer)) = XFIXNUM (tick); + return Qnil; +} + DEFUN ("buffer-chars-modified-tick", Fbuffer_chars_modified_tick, Sbuffer_chars_modified_tick, 0, 1, 0, doc: /* Return BUFFER's character-change tick counter. @@ -6418,6 +6430,7 @@ will run for `clone-indirect-buffer' calls as well. */); defsubr (&Sforce_mode_line_update); defsubr (&Sset_buffer_modified_p); defsubr (&Sbuffer_modified_tick); + defsubr (&Sinternal__set_buffer_modified_tick); defsubr (&Sbuffer_chars_modified_tick); defsubr (&Srename_buffer); defsubr (&Sother_buffer); -- cgit v1.2.1 From 0bee4cda881f7db4113cba541b684c334e828c4a Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Tue, 10 May 2022 03:38:01 +0200 Subject: 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. --- src/buffer.c | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'src/buffer.c') 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. */) DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p, 0, 1, 0, - doc: /* Return t if BUFFER was modified since its file was last read or saved. -No argument or nil as argument means use current buffer as BUFFER. */) + doc: /* Return non-nil if BUFFER was modified since its file was last read or saved. +No argument or nil as argument means use current buffer as BUFFER. + +If BUFFER has been autosaved after BUFFER was last modified, the +symbol `autosaved' is returned. */) (Lisp_Object buffer) { struct buffer *buf = decode_buffer (buffer); - return BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf) ? Qt : Qnil; + if (BUF_SAVE_MODIFF (buf) < BUF_MODIFF (buf)) + { + if (BUF_AUTOSAVE_MODIFF (buf) == BUF_MODIFF (buf)) + return Qautosaved; + else + return Qt; + } + else + return Qnil; } DEFUN ("force-mode-line-update", Fforce_mode_line_update, @@ -1436,6 +1447,11 @@ and `buffer-file-truename' are non-nil. */) 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, except the special value +`autosaved', which will instead mark the buffer as having been +autosaved. + This function also locks or unlocks the file visited by the buffer, if both `buffer-file-truename' and `buffer-file-name' are non-nil. @@ -1475,16 +1491,19 @@ state of the current buffer. Use with care. */) recent-auto-save-p from t to nil. Vice versa, if FLAG is non-nil and SAVE_MODIFF>=auto_save_modified we risk changing recent-auto-save-p from nil to t. */ - SAVE_MODIFF = (NILP (flag) - /* FIXME: This unavoidably sets recent-auto-save-p to nil. */ - ? MODIFF - /* Let's try to preserve recent-auto-save-p. */ - : SAVE_MODIFF < MODIFF ? SAVE_MODIFF - /* If SAVE_MODIFF == auto_save_modified == MODIFF, - we can either decrease SAVE_MODIFF and auto_save_modified - or increase MODIFF. */ - : modiff_incr (&MODIFF)); - + if (NILP (flag)) + /* This unavoidably sets recent-auto-save-p to nil. */ + 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) + SAVE_MODIFF = modiff_incr (&MODIFF); + } return flag; } @@ -6465,5 +6484,7 @@ will run for `clone-indirect-buffer' calls as well. */); defsubr (&Soverlay_put); defsubr (&Srestore_buffer_modified_p); + DEFSYM (Qautosaved, "autosaved"); + Fput (intern_c_string ("erase-buffer"), Qdisabled, Qt); } -- cgit v1.2.1 From 054062060e9f57fd037578378c23ad9ec294edac Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 5 May 2022 13:03:06 -0700 Subject: Factor out *scratch* initialization * lisp/simple.el (get-scratch-buffer-create): New function, factored out of scratch-buffer, and additionally clearing the modification flag and calling substitute-command-keys (bug#55257). (scratch-buffer): * lisp/server.el (server-execute): * lisp/startup.el (normal-no-mouse-startup-screen, command-line-1): * lisp/window.el (last-buffer, window-normalize-buffer-to-switch-to): * src/buffer.c (Fother_buffer, other_buffer_safely): Use it. (syms_of_buffer): Add Qget_scratch_buffer_create. * lisp/startup.el (startup--get-buffer-create-scratch): Delete now-unused function. * doc/lispref/os.texi (Summary: Sequence of Actions at Startup): * NEWS (Incompatible changes in Emacs 29.1): Document the change. --- src/buffer.c | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'src/buffer.c') diff --git a/src/buffer.c b/src/buffer.c index f54714675e2..0f3061b4973 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1665,16 +1665,7 @@ exists, return the buffer `*scratch*' (creating it if necessary). */) if (!NILP (notsogood)) return notsogood; else - { - AUTO_STRING (scratch, "*scratch*"); - buf = Fget_buffer (scratch); - if (NILP (buf)) - { - buf = Fget_buffer_create (scratch, Qnil); - Fset_buffer_major_mode (buf); - } - return buf; - } + return safe_call (1, Qget_scratch_buffer_create); } /* The following function is a safe variant of Fother_buffer: It doesn't @@ -1690,15 +1681,7 @@ other_buffer_safely (Lisp_Object buffer) if (candidate_buffer (buf, buffer)) return buf; - AUTO_STRING (scratch, "*scratch*"); - buf = Fget_buffer (scratch); - if (NILP (buf)) - { - buf = Fget_buffer_create (scratch, Qnil); - Fset_buffer_major_mode (buf); - } - - return buf; + return safe_call (1, Qget_scratch_buffer_create); } DEFUN ("buffer-enable-undo", Fbuffer_enable_undo, Sbuffer_enable_undo, @@ -5583,6 +5566,7 @@ syms_of_buffer (void) DEFSYM (Qbefore_change_functions, "before-change-functions"); DEFSYM (Qafter_change_functions, "after-change-functions"); DEFSYM (Qkill_buffer_query_functions, "kill-buffer-query-functions"); + DEFSYM (Qget_scratch_buffer_create, "get-scratch-buffer-create"); DEFSYM (Qvertical_scroll_bar, "vertical-scroll-bar"); Fput (Qvertical_scroll_bar, Qchoice, list4 (Qnil, Qt, Qleft, Qright)); -- cgit v1.2.1 From 68dd94448f0b46cced59c7fe33f77f74ddf656ad Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 10 May 2022 16:06:10 +0300 Subject: ; Fix recent documentation changes * src/fileio.c (Fdo_auto_save): * src/buffer.c (Fbuffer_modified_p, Frestore_buffer_modified_p): * doc/lispref/buffers.texi (Buffer Modification): Improve documentation of 'do-auto-save', 'buffer-modified-p' and 'restore-buffer-modified-p'. --- src/buffer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/buffer.c') diff --git a/src/buffer.c b/src/buffer.c index 0f3061b4973..0af14a10609 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1379,8 +1379,8 @@ DEFUN ("buffer-modified-p", Fbuffer_modified_p, Sbuffer_modified_p, doc: /* Return non-nil if BUFFER was modified since its file was last read or saved. No argument or nil as argument means use current buffer as BUFFER. -If BUFFER has been autosaved after BUFFER was last modified, the -symbol `autosaved' is returned. */) +If BUFFER was autosaved since it was last modified, this function +returns the symbol `autosaved'. */) (Lisp_Object buffer) { struct buffer *buf = decode_buffer (buffer); @@ -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, except the special value -`autosaved', which will instead mark the buffer as having been -autosaved. +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. This function also locks or unlocks the file visited by the buffer, if both `buffer-file-truename' and `buffer-file-name' are non-nil. -- cgit v1.2.1 From 1642a5ffcdf734c629e5aec963a0b190997704d6 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Thu, 12 May 2022 02:16:38 +0200 Subject: 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". --- src/buffer.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/buffer.c') 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; } -- cgit v1.2.1 From 7d0d87ec51f066aaa27cd3d2d995d56f1f41c67c Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 12 May 2022 09:47:25 +0300 Subject: ; Improve documentation of 'restore-buffer-modified-p' * src/buffer.c (Frestore_buffer_modified_p): * doc/lispref/buffers.texi (Buffer Modification): Fix doc wording. --- src/buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/buffer.c') diff --git a/src/buffer.c b/src/buffer.c index 89b04a42801..57137b2a067 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1449,8 +1449,8 @@ DEFUN ("restore-buffer-modified-p", Frestore_buffer_modified_p, 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. A special value of `autosaved' -will mark the buffer modified, and also as having been autosaved since -it was last modified. +will mark the buffer as modified and also as 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. -- cgit v1.2.1 From dea41d4c24d0d33e359cbfe34054d9048761adfd Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Fri, 13 May 2022 21:24:12 +0200 Subject: Add new minor mode `header-line-indent-mode' This is mostly factored out from tabulated-list.el (with bugs fixed). * doc/lispref/modes.texi (Header Lines): Document it. * lisp/display-line-numbers.el (header-line-indent): New variable. (header-line-indent--line-number-width) (header-line-indent--watch-line-number-width) (header-line-indent--window-scroll-function): New helper functions. (header-line-indent-mode): New minor mode. * lisp/display-line-numbers.el (header-line-indent-width): New variable. * lisp/emacs-lisp/tabulated-list.el (tabulated-list-line-number-width) (tabulated-list-watch-line-number-width) (tabulated-list-window-scroll-function): Make into obsolete aliases. (tabulated-list-mode): Use 'header-line-indent-mode'. * lisp/emacs-lisp/tabulated-list.el (tabulated-list-init-header): Adjust the header line format and computation. * src/buffer.c (syms_of_buffer): Mention header-line-indent-mode. --- src/buffer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/buffer.c') diff --git a/src/buffer.c b/src/buffer.c index 57137b2a067..548d7b1c65c 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -5598,8 +5598,11 @@ the mode line appears at the bottom. */); &BVAR (current_buffer, header_line_format), Qnil, doc: /* Analogous to `mode-line-format', but controls the header line. -The header line appears, optionally, at the top of a window; -the mode line appears at the bottom. */); +The header line appears, optionally, at the top of a window; the mode +line appears at the bottom. + +Also see `header-line-indent-mode' if `display-line-number-mode' is +used. */); DEFVAR_PER_BUFFER ("mode-line-format", &BVAR (current_buffer, mode_line_format), Qnil, -- cgit v1.2.1 From c4da5db04ba611b9a646c325e0e6eee165834f7a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 31 May 2022 01:19:32 -0700 Subject: Pacify GCC 12 in Fmove_overlay * src/buffer.c (Fmove_overlay): Use BASE_EQ, not EQ. This pacifies GCC 12 -Wanalyzer-null-dereference. --- src/buffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/buffer.c') diff --git a/src/buffer.c b/src/buffer.c index 548d7b1c65c..d2b2f255756 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -4107,7 +4107,7 @@ buffer. */) n_end = marker_position (OVERLAY_END (overlay)); /* If the overlay has changed buffers, do a thorough redisplay. */ - if (!EQ (buffer, obuffer)) + if (!BASE_EQ (buffer, obuffer)) { /* Redisplay where the overlay was. */ if (ob) -- cgit v1.2.1 From bab1d412801eead715f1465131aa3734558f35ab Mon Sep 17 00:00:00 2001 From: Mattias EngdegÄrd Date: Sun, 12 Jun 2022 12:05:03 +0200 Subject: Use BASE_EQ when comparing with Qunbound Qunbound is uninterned and can therefore never be EQ to any symbol with position. * src/buffer.c (Fbuffer_local_value, buffer_lisp_local_variables) (buffer_local_variables_1): * src/bytecode.c (exec_byte_code): * src/comp.c (compile_function, Fcomp__compile_ctxt_to_file): * src/composite.c (composition_gstring_cache_clear_font): * src/data.c (Fboundp, Fsymbol_value, set_internal) (Fdefault_boundp, Fdefault_value, Fmake_variable_buffer_local): * src/emacs-module.c (module_global_reference_p): * src/eval.c (Fdefault_toplevel_value, defvar) (run_hook_with_args): * src/fns.c (hash_put, Fmaphash): * src/font.c (font_put_extra): * src/frame.c (gui_set_frame_parameters) (gui_frame_get_and_record_arg, gui_default_parameter) (gui_figure_window_size): * src/haikufns.c (get_geometry_from_preferences) (haiku_create_frame, haiku_create_tip_frame): * src/haikuterm.c (haiku_draw_text_decoration) (haiku_default_font_parameter): * src/json.c (lisp_to_json_nonscalar_1): * src/keymap.c (access_keymap_1, access_keymap, current_minor_maps): * src/lread.c (readevalloop, define_symbol): * src/minibuf.c (read_minibuf, Ftry_completion): (Fall_completions, Ftest_completion): * src/pgtkfns.c (pgtk_default_font_parameter, Fx_create_frame) (x_create_tip_frame): * src/pgtkselect.c (Fpgtk_own_selection_internal): * src/print.c (print): * src/profiler.c (evict_lower_half, record_backtrace): * src/terminal.c (create_terminal): * src/textprop.c (set_properties): * src/w32fns.c (my_create_window, w32_icon) (w32_default_font_parameter, Fx_create_frame) (w32_create_tip_frame): * src/w32term.c (w32_draw_glyph_string): * src/xdisp.c (handle_single_display_spec) (cursor_row_fully_visible_p, calc_pixel_width_or_height): * src/xfns.c (x_default_scroll_bar_color_parameter, x_icon_verify) (x_icon, x_default_font_parameter, Fx_create_frame) (x_create_tip_frame): * src/xselect.c (x_handle_selection_request): * src/xterm.c (x_draw_glyph_string, x_term_init): Use BASE_EQ instead of EQ when comparing with Qunbound. --- src/buffer.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/buffer.c') diff --git a/src/buffer.c b/src/buffer.c index d2b2f255756..a0761f5b59a 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1218,7 +1218,7 @@ is the default binding of the variable. */) { register Lisp_Object result = buffer_local_value (variable, buffer); - if (EQ (result, Qunbound)) + if (BASE_EQ (result, Qunbound)) xsignal1 (Qvoid_variable, variable); return result; @@ -1313,7 +1313,7 @@ buffer_lisp_local_variables (struct buffer *buf, bool clone) if (buf != current_buffer) val = XCDR (elt); - result = Fcons (!clone && EQ (val, Qunbound) + result = Fcons (!clone && BASE_EQ (val, Qunbound) ? XCAR (elt) : Fcons (XCAR (elt), val), result); @@ -1336,7 +1336,7 @@ buffer_local_variables_1 (struct buffer *buf, int offset, Lisp_Object sym) { sym = NILP (sym) ? PER_BUFFER_SYMBOL (offset) : sym; Lisp_Object val = per_buffer_value (buf, offset); - return EQ (val, Qunbound) ? sym : Fcons (sym, val); + return BASE_EQ (val, Qunbound) ? sym : Fcons (sym, val); } return Qnil; } -- cgit v1.2.1