aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.h (unfollow)
Commit message (Collapse)AuthorFilesLines
2025-07-21insert-file-contents st_size cleanupPaul Eggert1-5/+6
* src/fileio.c (Finsert_file_contents): Store st_size, not file_size_hint, into current_buffer->modtime_size, since modtime_size is compared to a later st_size, not to the actual file size. Simplify buffer overflow detection from file size, since this occurred only on regular files.
2025-05-03Add line-column tracking for tree-sitterYuan Fu1-0/+72
Add line-column tracking for tree-sitter parsers. Copied from comments in treesit.c: Technically we had to send tree-sitter the line and column position of each edit. But in practice we just send it dummy values, because tree-sitter doesn't use it for parsing and mostly just carries the line and column positions around and return it when e.g. reporting node positions[1]. This has been working fine until we encountered grammars that actually utilizes the line and column information for parsing (Haskell)[2]. [1] https://github.com/tree-sitter/tree-sitter/issues/445 [2] https://github.com/tree-sitter/tree-sitter/issues/4001 So now we have to keep track of line and column positions and pass valid values to tree-sitter. (It adds quite some complexity, but only linearly; one can ignore all the linecol stuff when trying to understand treesit code and then come back to it later.) Eli convinced me to disable tracking by default, and only enable it for languages that needs it. So the buffer starts out not tracking linecol. And when a parser is created, if the language is in treesit-languages-require-line-column-tracking, we enable tracking in the buffer, and enable tracking for the parser. To simplify things, once a buffer starts tracking linecol, it never disables tracking, even if parsers that need tracking are all deleted; and for parsers, tracking is determined at creation time, if it starts out tracking/non-tracking, it stays that way, regardless of later changes to treesit-languages-require-line-column-tracking. To make calculating line/column positons fast, we store linecol caches for begv, point, and zv in the buffer (buf->ts_linecol_cache_xxx); and in the parser object, we store linecol cache for visible beg/end of that parser. In buffer editing functions, we need the linecol for start/old_end/new_end, those can be calculated by scanning newlines (treesit_linecol_of_pos) from the buffer point cache, which should be always near the point. And we usually set the calculated linecol of new_end back to the buffer point cache. We also need to calculate linecol for the visible_beg/end for each parser, and linecol for the buffer's begv/zv, these positions are usually far from point, so we have caches for all of them (in either the parser object or the buffer). These positions are far from point, so it's inefficient to scan newlines from point to there to get up-to-date linecol for them; but in the same time, because they're far and outside the changed region, we can calculate their change in line and column number by simply counting how much newlines are added/removed in the changed region (compute_new_linecol_by_change). * doc/lispref/parsing.texi (Using Parser): Mention line-column tracking in manual. * etc/NEWS: Add news. * lisp/treesit.el: (treesit-languages-need-line-column-tracking): New variable. * src/buffer.c: Include treesit.h (for TREESIT_EMPTY_LINECOL). (Fget_buffer_create): (Fmake_indirect_buffer): Initialize new buffer fields. (Fbuffer_swap_text): Add new buffer fields. * src/buffer.h (ts_linecol): New struct. (buffer): New buffer fields. (BUF_TS_LINECOL_BEGV): (BUF_TS_LINECOL_POINT): (BUF_TS_LINECOL_ZV): (SET_BUF_TS_LINECOL_BEGV): (SET_BUF_TS_LINECOL_POINT): (SET_BUF_TS_LINECOL_ZV): New inline functions. * src/casefiddle.c (casify_region): Record linecol info. * src/editfns.c (Fsubst_char_in_region): (Ftranslate_region_internal): (Ftranspose_regions): Record linecol info. * src/insdel.c (insert_1_both): (insert_from_string_1): (insert_from_gap_1): (insert_from_buffer): (replace_range): (del_range_2): Record linecol info. * src/treesit.c (TREESIT_BOB_LINECOL): (TREESIT_EMPTY_LINECOL): (TREESIT_TS_POINT_1_0): New constants. (treesit_debug_print_linecol): (treesit_buf_tracks_linecol_p): (restore_restriction_and_selective_display): (treesit_count_lines): (treesit_debug_validate_linecol): (treesit_linecol_of_pos): (treesit_make_ts_point): (Ftreesit_tracking_line_column_p): (Ftreesit_parser_tracking_line_column_p): New functions. (treesit_tree_edit_1): Accept real TSPoint and pass to tree-sitter. (compute_new_linecol_by_change): New function. (treesit_record_change_1): Rename from treesit_record_change, handle linecol if tracking is enabled. (treesit_linecol_maybe): New function. (treesit_record_change): New wrapper around treesit_record_change_1 that handles some boilerplate and sets buffer state. (treesit_sync_visible_region): Handle linecol if tracking is enabled. (make_treesit_parser): Setup parser's linecol cache if tracking is enabled. (Ftreesit_parser_create): Enable tracking if the parser's language requires it. (Ftreesit__linecol_at): (Ftreesit__linecol_cache_set): (Ftreesit__linecol_cache): New functions for debugging and testing. (syms_of_treesit): New variable Vtreesit_languages_require_line_column_tracking. * src/treesit.h (Lisp_TS_Parser): New fields. (TREESIT_BOB_LINECOL): (TREESIT_EMPTY_LINECOL): New constants. * test/src/treesit-tests.el (treesit-linecol-basic): (treesit-linecol-search-back-across-newline): (treesit-linecol-col-same-line): (treesit-linecol-enable-disable): New tests. * src/lisp.h: Declare display_count_lines. * src/xdisp.c (display_count_lines): Remove static keyword.
2025-03-28Miscellaneous correctionsPo Lu1-2/+2
* src/buffer.h (BUF_PTR_BYTE_POS): Fix comment. * src/profiler.c (add_sample): Use BASE_EQ.
2025-01-02Update copyright year to 2025Stefan Kangas1-1/+1
Run "TZ=UTC0 admin/update-copyright".
2025-01-01Update copyright year to 2025Paul Eggert1-1/+1
Run "TZ=UTC0 admin/update-copyright".
2024-03-15Further adjustments for restoring killed buffer windows (Bug#68235)Martin Rudalics1-0/+3
* etc/NEWS: Announce 'window-restore-killed-buffer-windows'. * src/buffer.h (struct buffer) : New field last_name_. * src/buffer.c (Fbuffer_last_name): New function to return last name of buffer before it was killed or renamed. (bset_last_name, Fget_buffer_create, Fmake_indirect_buffer) (Frename_buffer, Fkill_buffer, init_buffer_once): Set buffer's last_name_ field accordingly. * src/window.c (window_restore_killed_buffer_windows): New variable replacing Vwindow_kept_windows_functions. (Fset_window_configuration): Use window_restore_killed_buffer_windows instead of Vwindow_kept_windows_functions. * lisp/window.el (window--state-put-2, window-state-put): Use 'window-restore-killed-buffer-windows' instead of 'window-kept-windows-functions'. * doc/lispref/windows.texi (Window Configurations): Describe 'window-restore-killed-buffer-windows' which replaces 'window-kept-windows-functions'.
2024-02-05Prefer `ITREE_FOREACH` over `overlays_in`Stefan Monnier1-2/+0
Use `ITREE_FOREACH` instead of `overlays_in` if that can save us from allocating an array. * src/buffer.c (overlays_in): Mark as static. (mouse_face_overlay_overlaps): Use `ITREE_FOREACH` instead of `overlays_in`. (disable_line_numbers_overlay_at_eob): Same, and also change return value to a boolean. * src/buffer.h (overlays_in): Don't declare. * src/editfns.c (overlays_around): Delete function. (Fget_pos_property): Use `ITREE_FOREACH` and keep the "best so far" instead of using `overlays_in` and sorting the elements. * src/lisp.h (disable_line_numbers_overlay_at_eob): Change return type to a boolean. * src/xdisp.c (should_produce_line_number): Adjust accordingly.
2024-01-20Be more systematic about parens in C source codePaul Eggert1-1/+1
Be more systematic about putting space before paren in calls, and in avoiding unnecessary parentheses in macros. This was partly inspired by my wading through gcc -E output while debugging something else, and seeing too many parens. This patch does not change the generated .o files on my platform.
2024-01-02; Add 2024 to copyright yearsPo Lu1-1/+1
2023-12-30Improve performance let-binding `case-fold-search' (bug#66117)Ihor Radchenko1-1/+0
* src/buffer.h: Remove case_fold_search_ buffer object slot. * src/buffer.c (bset_case_fold_search): Remove - no longer needed. (init_buffer_once): Remove removed buffer slot init. (syms_of_buffer): Use DEFVAR_LISP to define `case-fold-search' and declare it buffer-local. * src/minibuf.c (syms_of_minibuf): Remove DEFSYM call for `case-fold-search' symbol. It now lives in `syms_of_buffer'. * src/editfns.c (Fcompare_buffer_substrings): (Fchar_equal): * src/search.c (looking_at_1): (string_match_1): (search_command): (Fre__describe_compiled): Adjust C queries to `case-fold-search' value to use C globals instead of BVAR macro. * doc/lispref/internals.texi (Buffer Internals): Do not list `case_fold_search' slot. See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=66117#259 When used as buffer slot, let-binding `case-fold-search' would scale with the number of live buffers and can be slow. This change makes let-binding much faster at the cost of slightly slower `set-buffer'.
2023-09-02Doc fixes for obsolete functions and variablesStefan Kangas1-3/+3
* admin/notes/multi-tty: * doc/emacs/building.texi (Debugger Operation): * doc/misc/efaq-w32.texi (Line ends by file system): * doc/misc/gnus.texi (Hashcash): * lisp/emacs-lisp/eieio.el (eieio-class-parents) (eieio-class-children): * lisp/progmodes/perl-mode.el: * lisp/textmodes/ispell.el (ispell-lookup-words): * src/buffer.h: Update or delete references to variables and functions made obsolete in Emacs 24.4.
2023-02-15Update Android portPo Lu1-0/+11
* doc/emacs/input.texi (On-Screen Keyboards): * doc/lispref/commands.texi (Misc Events): Improve documentation of text conversion stuff. * java/org/gnu/emacs/EmacsInputConnection.java (beginBatchEdit) (endBatchEdit, commitCompletion, commitText, deleteSurroundingText) (finishComposingText, getSelectedText, getTextAfterCursor) (EmacsInputConnection, setComposingRegion, performEditorAction) (getExtractedText): Condition debug code on DEBUG_IC. * java/org/gnu/emacs/EmacsService.java (EmacsService, updateIC): Likewise. * lisp/bindings.el (global-map): * lisp/electric.el (global-map): Make `text-conversion' `analyze-text-conversion'. * lisp/progmodes/prog-mode.el (prog-mode): Enable text conversion in input methods. * lisp/simple.el (analyze-text-conversion): New function. * lisp/textmodes/text-mode.el (text-conversion-style) (text-mode): Likewise. * src/androidterm.c (android_handle_ime_event): Handle set_point_and_mark. (android_sync_edit): Give Emacs 100 ms instead. (android_perform_conversion_query): Skip the active region, not the conversion region. (getSelectedText): Implement properly. (android_update_selection): Expose mark to input methods. (android_reset_conversion): Handle `text-conversion-style'. * src/buffer.c (init_buffer_once, syms_of_buffer): Add buffer local variable `text-conversion-style'. * src/buffer.h (struct buffer, bset_text_conversion_style): New fields. * src/emacs.c (android_emacs_init): Call syms_of_textconv. * src/frame.h (enum text_conversion_operation): Rename TEXTCONV_SET_POINT. * src/lisp.h: Export syms_of_textconv. * src/marker.c (set_marker_internal): Force redisplay when the mark is set and the buffer is visible on builds that use text conversion. Explain why. * src/textconv.c (copy_buffer): Fix copying past gap. (get_mark): New function. (textconv_query): Implement new flag. (sync_overlay): New function. Display conversion text in an overlay. (record_buffer_change, really_commit_text) (really_set_composing_text, really_set_composing_region) (really_delete_surrounding_text, really_set_point) (handle_pending_conversion_events_1, decrement_inside) (handle_pending_conversion_events, textconv_set_point) (get_extracted_text, register_textconv_interface): Various fixes and improvements. * src/textconv.h (struct textconv_interface): Update documentation. * src/window.h (GCALIGNED_STRUCT): New field `prev_mark'. * src/xdisp.c (mark_window_display_accurate_1): Handle prev_mark.
2023-02-12; Fix typo in buffer.hDaniel Martín1-1/+1
2023-01-01; Add 2023 to copyright years.Eli Zaretskii1-1/+1
2022-12-11Actually improve detection of long linesGregory Heytings1-11/+0
* src/xdisp.c (redisplay_window): Update condition. * src/xdisp.c (mark_window_display_accurate_1): * src/pdumper.c (dump_buffer): * src/buffer.h (BUF_CHARS_UNCHANGED_MODIFIED): (struct buffer_text): * src/buffer.c (Fget_buffer_create): Revert 1c837c42c2, which was misguided.
2022-11-30Add itree_empty_p for clarity and reduced couplingMatt Armstrong1-2/+1
* src/itree.h (itree_empty_p): New predicate. * src/buffer.h (buffer_has_overlays): * src/pdumper.c (dump_buffer): * src/alloc.c (mark_buffer): Call it. (Bug#59137)
2022-11-05buffer.c: evaporate overlays in all indirect buffersStefan Monnier1-1/+0
This fixes bug#58928. The patch works by moving the `evaporate_overlays` check closer to `itree_delete_gap`. * src/buffer.c (adjust_overlays_for_delete_in_buffer): New function, integrating the functionality of `evaporate_overlays`. (adjust_overlays_for_delete): Use it. (evaporate_overlays): Delete function. * src/buffer.h (evaporate_overlays): Delete declaration. * src/insdel.c (adjust_markers_for_replace): Minor optimization. (adjust_after_replace, replace_range, replace_range_2, del_range_2): Don't call `evaporate_overlays`. * test/src/buffer-tests.el (buffer-tests--overlays-indirect-evaporate): Remove the `:expected-result :failed` attribute.
2022-10-21Fix a narrow-to-region vs. overlays-at bugMatt Armstrong1-1/+1
See bug#58703. * src/buffer.c (overlays_in): Add a new TRAILING arg expressing the behavior wanted by `overlays-at', namely to include all overlays beginning at the POS passed to `overlays-at', even if POS is the end of the narrowed region. Pass true and the search range is extended to ZV+1 if END is greater than ZV, just as is done for EMPTY. (overlays_at): Pass 'true' for the new trailing arg. At present this is the only caller passing 'true'. (mouse_face_overlay_overlaps): Pass 'false' for the new trailing arg. (disable_line_numbers_overlay_at_eob): ditto. (Foverlays_in): ditto. * src/editfns.c (overlays_around): ditto. * test/src/buffer-tests.el (sorted-overlays): Add a spot test for this.
2022-10-19Rename all exported itree.h functions with the itree_ prefixMatt Armstrong1-2/+2
For the most part, I replaced the interval_tree_ prefix with itree_, interval_node_ with itree_node_, etc. * src/alloc.c: Rename everywhere as appropriate. * src/alloc.c: ditto. * src/buffer.c: ditto. * src/buffer.h: ditto. * src/itree.c: ditto. * src/itree.h: ditto.
2022-10-19Prefix all itree.h type names with itree_Matt Armstrong1-1/+1
Rename interval_node -> itree_node, interval_tree -> itree_tree, interval_tree_order -> itree_order. * src/alloc.c: Renames. * src/buffer.c: ditto. * src/itree.c: ditto. * src/itree.h: ditto. * src/lisp.h: ditto. * src/pdumper.h: ditto. * src/textprop.h: ditto. * src/xdisp.h: ditto.
2022-10-19Remove the ITREE_NULL macro and use NULL everywhere.Matt Armstrong1-1/+1
* src/itree.h: Delete the ITREE_NULL macro. * src/itree.c (check_subtree): Use NULL everywhere. * src/pdumper.c (dump_buffer): ditto.
2022-10-14src/textprop.c (get_char_property_and_overlay): Fix bug#58479Stefan Monnier1-1/+1
Correct `get-char-property` which failed to ignore empty overlays. * src/textprop.c (get_char_property_and_overlay): Make sure the overlay covers the character. * test/src/buffer-tests.el (buffer-tests--overlay-bug58479): New test. * src/buffer.h (buffer_has_overlays): Avoid `interval_tree_size`.
2022-10-09Tighten up handling of `otick`Stefan Monnier1-34/+1
Move args between `build_overlay` and `add_buffer_overlay`, to try and keep buffer positions together with their buffer. Be more strict in the `otick` values passed to `interval_tree_insert`. Move a few things around to try and reduce dependencies through `.h` files. Fix a thinko bug in `check_tree`. * src/alloc.c (build_overlay): Remove `begin` and `end` args. * src/buffer.c (add_buffer_overlay): Move from `buffer.h`. Add `begin` and `end` args. (copy_overlays): Adjust accordingly. (Fmake_overlay): Use BUF_BEG and BUF_Z; adjust call to `build_overlay` and `add_buffer_overlay`. (Fmove_overlay): Use BUF_BEG and BUF_Z; Use the new `begin` and `end` args of `add_buffer_overlay` so we don't need to use `interval_node_set_region` when moving to a new buffer. (remove_buffer_overlay, set_overlay_region): Move from `buffer.h`. * src/buffer.h (set_overlay_region, add_buffer_overlay) (remove_buffer_overlay): Move to `buffer.c`. (build_overlay): Move from `lisp.h`. (maybe_alloc_buffer_overlays): Delete function (inline into its only caller). * src/itree.c (interval_tree_insert): Move declaration `from buffer.h`. (check_tree): Fix initial offset in call to `recurse_check_tree`. Remove redundant check of the `limit` value. (interval_node_init): Remove `begin` and `end` args. (interval_tree_insert): Mark it as static. Assert that the new node's `otick` should already be uptodate and its new parent as well. (itree_insert_node): New function. (interval_tree_insert_gap): Assert the otick of the removed+added nodes were uptodate and mark them as uptodate again after adjusting their positions. (interval_tree_inherit_offset): Check that the parent is at least as uptodate as the child. * src/lisp.h (build_overlay): Move to `buffer.h`. * src/itree.h (interval_node_init): Adjust accordingly. (interval_tree_insert): Remove declaration. (itree_insert_node): New declaration.
2022-10-02New ITREE_FOREACH macroStefan Monnier1-33/+0
* src/itree.h (interval_tree_iter_start): Adjust type. (interval_tree_nodes): Delete declaration. (ITREE_FOREACH, ITREE_FOREACH_ABORT, ITREE_FOREACH_NARROW): New macros. * src/itree.c (interval_tree_contains, interval_tree_insert_gap): Use the new ITREE_FOREACH macro. (interval_tree_nodes): Delete function. (interval_tree_iter_start): Return the iterator. (interval_generator_next, interval_tree_destroy): Don't accept a NULL arg any more. * src/xdisp.c (load_overlay_strings, strings_with_newlines): * src/textprop.c (get_char_property_and_overlay): * src/buffer.c (copy_overlays, delete_all_overlays) (set_overlays_multibyte, swap_buffer_overlays, overlays_in) (next_overlay_change, previous_overlay_change, overlay_touches_p) (overlay_strings, Foverlay_lists, report_overlay_modification) (evaporate_overlays): Use the new ITREE_FOREACH macro. * src/buffer.h (buffer_overlay_iter_start1) (buffer_overlay_iter_start, buffer_overlay_iter_next) (buffer_overlay_iter_finish, buffer_overlay_iter_narrow): Delete declarations.
2022-09-30itree.c: Improve division between tree and iteratorStefan Monnier1-3/+3
* src/buffer.c (delete_all_overlays): Add comment. * src/itree.c (struct interval_generator): New fields `running`, `file`, and `line` moved from `interval_tree`. (interval_stack_push_flagged): Adjust comment to resolve a FIXME. (interval_tree_clear): Replace assignment with an a (interval_tree_iter_next): Delete function. (interval_tree_clear): Don't set `iter_running` here any more. (interval_generator_create): Set it here instead. (interval_tree_iter_start): Fetch `iter` once and for all. (interval_generator_narrow): Mark it as non-static. (interval_tree_iter_next, interval_tree_iter_narrow): Delete functions. Inline their old bodies in the callers. (interval_tree_iter_finish): Take the iter rather than the whole tree. Adjust all callers. (interval_generator_next): Move `running `assertion here from `interval_tree_iter_next`. * src/buffer.h: Adjust accordingly. * src/itree.h (struct interval_tree): Remove fields `iter_running`, `file`, and `line`, moved to `interval_generator`. (interval_generator_narrow): Replace `interval_tree_iter_narrow`.
2022-09-29free_buffer_overlays: Move nearer to its sole callerStefan Monnier1-14/+0
* src/buffer.c (free_buffer_overlays): Move from `buffer.h`. * src/buffer.h (free_buffer_overlays): Move to `buffer.c`. * src/itree.c (interval_tree_iter_narrow, interval_tree_iter_finish) (interval_tree_iter_next): Prefer `eassert`.
2022-09-28Add debugging help for nested iterators (nug#58144)Gerd Möllmann1-3/+6
When starting an iteration, store __FILE__ and __LINE__ where this happens in the interval_tree structure. * src/buffer.h (buffer_overlay_iter_start): New macro adding __FILE and __LINE__. (buffer_overlay_iter_start1): Renamed from ..._start. * src/itree.h (struct interval_tree): Add file and line info. * src/itree.c: (interval_tree_contains, interval_tree_nodes, interval_tree_insert_gap): Pass __FILE__ and __LINE__ to iter_start. (interval_tree_iter_start): Record file and line info in tree.
2022-08-23; * src/buffer.h (struct buffer_text): Improve commentary.Eli Zaretskii1-1/+3
2022-08-23Improve detection of long lines.Gregory Heytings1-0/+9
* src/buffer.h (struct buffer_text): New field. (BUF_CHARS_UNCHANGED_MODIFIED, CHARS_UNCHANGED_MODIFIED): New macros. * src/buffer.c (Fget_buffer_create): Initialize the new field. * src/xdisp.c (mark_window_display_accurate_1): Set the new field. (redisplay_window): Use it, together with CHARS_MODIFF, instead of MODIFF and UNCHANGED_MODIFIED to decide whether to check for long lines. * src/pdumper.c (dump_buffer): Dump the new field.
2022-07-20Further tweaks to long lines handling.Gregory Heytings1-3/+4
* src/xdisp.c (redisplay_window): Increase the threshold above which long lines detection is performed in the buffer. This should avoid triggering that detection for most simple editing operations. * src/lisp.h (modiff_incr): Explain why the counter is incremented logarithmically. * src/buffer.h (struct buffer_text): Adapt the comment about the 'modiff' field accordingly. * src/buffer.c (modify_overlay): Increase the counter by 1 instead of the size of the buffer section on which the overlay is placed. * etc/NEWS: Small improvement.
2022-07-19Revert commits 1ff69cc744 and 9a894206f6.Gregory Heytings1-6/+0
2022-07-18Improve the heuristic for long lines detection.Gregory Heytings1-0/+6
* src/buffer.h (struct buffer_text): New 'unchanged_size' field. (BUF_UNCHANGED_SIZE): New macro to access the field. * src/buffer.c (Fget_buffer_create): Initialize the field. (Fbuffer_swap_text): Handle it. * src/xdisp.c (mark_window_display_accurate_1): Set the field. (redisplay_window): Use the field for long lines detection.
2022-07-16Improvements to long lines handling.Gregory Heytings1-0/+4
* src/buffer.h (struct buffer): New field 'long_line_optimizations_p'. * src/buffer.c (syms_of_buffer): New variable 'long-line-threshold'. (reset_buffer): Initialize the 'long_line_optimizations_p' field. (Fbuffer_swap_text): Handle it. * src/xdisp.c (redisplay_window): Set 'long_line_optimizations_p' when a buffer contains long lines. (init_iterator): Use 'long_line_optimizations_p'. (get_narrowed_begv): Update. (SET_WITH_NARROWED_BEGV): New macro. (unwind_narrowed_begv): New internal function used by the new macro. (back_to_previous_line_start, get_visually_first_element, move_it_vertically_backward): Use the new macro. * src/search.c (find_newline1): Make it externally visible. * src/lisp.h: Make 'find_newline1' externally visible. * src/dispextern.h (struct it): Update comment. Remove the 'WITH_NARROWED_BEGV' macro. * etc/NEWS: Mention the 'long-line-threshold' variable.
2022-07-08Revert commit 38b3780f6e.Gregory Heytings1-14/+0
2022-07-08Revert commits 9ea9533f17, c0c4600ece, 7b19ce51fc, 051d2a1e36 and eb6d2fb58d.Gregory Heytings1-16/+0
2022-07-06Various improvements to auto-narrow mode.Gregory Heytings1-0/+16
* lisp/files.el (auto-narrow-display-length): Improve docstring. (auto-narrow-widen-automatically): Add 'undo' to the command list. (auto-narrow-hook): New defcustom. (auto-narrow-pre-command-function, auto-narrow-post-command-function): Move initialization code. (auto-narrow-mode): Do not make the 'auto-narrow-mode' permanent local anymore. * lisp/font-lock.el (turn-off-font-lock-mode): New convenience function. * src/xdisp.c (set_vertical_scroll_bar): Fix typo. (redisplay_window): Use the new convenience function. * src/buffer.h (BUFFER_NEEDS_AUTO_NARROWING_P, BUFFER_AUTO_NARROWED_NON_NARROWED_P): Two new convenience functions. * src/window.c (Frecenter): Do not recenter auto-narrowed buffers that are not actually narrowed. * etc/NEWS: Improvement. * doc/emacs/display.texi (Auto-Narrowing): Improvement.
2022-07-06Actually fix the long lines display bug (bug#56393).Gregory Heytings1-0/+14
* lisp/files.el (auto-narrow-mode): New minor mode. (auto-narrow-pre-command-function, auto-narrow-post-command-function): New auxiliary functions for the minor mode. (auto-narrow-display-length, auto-narrow-widen-automatically): New defcustoms for the minor mode. (auto-narrow--widen-automatically, auto-narrow--isearch-widen-automatically, auto-narrow--initialized): New internal variables for the minor mode. * src/buffer.h (struct buffer): New internal variable for the minor mode. (bset_auto_narrow__narrowing_state, BUFFER_AUTO_NARROWED_P): New auxiliary functions. * src/buffer.c (init_buffer_once, syms_of_buffer): New internal variable for the minor mode. Update the docstring of mode-line-format. * src/fileio.c (Finsert_file_contents): Detect whether the minor mode should be entered when the buffer is displayed. (syms_of_fileio): New defcustom for the minor mode. * src/keyboard.c (syms_of_keyboard): New hook functions for the minor mode. (command_loop_1): Execute the hook functions. * src/xdisp.c (redisplay_window): Enter the minor mode when the buffer is displayed. (decode_mode_spec): Indicate when the minor mode is active in the modeline. Indicate the buffer position relative to the whole buffer. (set_vertical_scroll_bar): Indicate the buffer position relative to the whole buffer. (syms_of_xdisp): Two new symbols. * lisp/isearch.el (isearch-widen-automatically): New defcustom. (isearch-search): Use the new defcustom. * lisp/bindings.el (mode-line-modes): Do not propertize the indication in the modeline when the new minor mode is active. * etc/NEWS: Announce the new minor mode, and remove the unobsoletion indication for 'longlines-mode'. * lisp/longlines.el: Reobsolete longlines-mode. * doc/emacs/display.texi (Auto-Narrowing): New section, describing the new minor mode. (Display): Entry for the new section. * doc/emacs/trouble.texi (Long Lines): Remove the section. (Lossage): Remove the entry for the Long Lines section. * doc/emacs/emacs.texi (Top): Remove the entry for the Long Lines section.
2022-06-16Change treesit-parser-list from variable to functionYuan Fu1-0/+4
Effectively making the list internal. Now Emacs user cannot shoot themselves in the foot by removing a parser from the list, make chaanges to buffer and add that parser back to the list. * doc/lispref/parsing.texi (Language Definitions, Using Parser) (Retrieving Node, Multiple Languages): Change variable to function. * lisp/treesit.el (treesit-language-at, treesit-node-on) (treesit-buffer-root-node, treesit-indent, treesit-check-indent) (treesit-search-forward, treesit-search-beginning) (treesit-end-of-defun, treesit-inspect-mode): Change variable to function. * src/buffer.c (bset_ts_parser_list, reset_buffer, init_buffer_once): Add ts_parser_list. * src/buffer.h (struct buffer): Add ts_parser_list. * src/treesit.c (ts_record_change, Ftreesit_parser_create): Use the buffer field instead of the old buffer local variable. (Ftreesit_parser_delete, Ftreesit_parser_list): New functions. (syms_of_treesit): Remove treesit-parser-list. * test/src/treesit-tests.el (treesit-basic-parsing): Use the new function.
2022-01-01; Add 2022 to copyright years.Eli Zaretskii1-1/+1
2021-09-22Update comments warning about GC-resistant C programmingEli Zaretskii1-0/+11
* src/eval.c: Remove an outdated comment about protection from GC. * src/buffer.h: * src/lisp.h: Add warnings about using 'char *' pointers to text of Lisp strings and buffer text in code that could GC. Reported by Po Lu <luangruo@yahoo.com>
2021-02-15Rename minor-modes to local-minor-modesLars Ingebrigtsen1-1/+1
* doc/lispref/modes.texi (Minor Modes): Update documentation. * lisp/simple.el (completion-with-modes-p): Change usage. * lisp/emacs-lisp/easy-mmode.el (define-minor-mode): Change usage. * src/buffer.c: Rename from minor_modes to local_minor_modes throughout. (syms_of_buffer): Rename minor-modes to local-minor-modes. * src/buffer.h (struct buffer): Rename minor_modes_. * src/pdumper.c (dump_buffer): Update hash and usage.
2021-02-14Add a new buffer-local variable `minor-modes'Lars Ingebrigtsen1-0/+3
* lisp/emacs-lisp/easy-mmode.el (define-minor-mode): Keep `minor-modes' updated. * src/buffer.c (bset_minor_modes, Fmake_indirect_buffer) (reset_buffer, init_buffer_once): Initialise `minor-modes'. (syms_of_buffer): Add `minor-modes' as a new permanently-local variable. * src/buffer.h (struct buffer): Add minor_modes_.
2021-01-01Update copyright year to 2021Paul Eggert1-1/+1
Run "TZ=UTC0 admin/update-copyright".
2021-01-01Update copyright year to 2021Paul Eggert1-1/+1
Run "TZ=UTC0 admin/update-copyright $(git ls-files)".
2020-12-20Inhibit buffer hooks in temporary buffersBasil L. Contovounesios1-5/+5
Give get-buffer-create an optional argument to inhibit buffer hooks in internal or temporary buffers for efficiency (bug#34765). * etc/NEWS: Announce new parameter of get-buffer-create and generate-new-buffer, and that with-temp-buffer and with-temp-file now inhibit buffer hooks. * doc/lispref/buffers.texi (Buffer Names): Fix typo. (Creating Buffers): Document new parameter of get-buffer-create and generate-new-buffer. (Buffer List, Killing Buffers): Document when buffer hooks are inhibited. (Current Buffer): * doc/lispref/files.texi (Writing to Files): Document that with-temp-buffer and with-temp-file inhibit buffer hooks. * doc/lispref/internals.texi (Buffer Internals): Document inhibit_buffer_hooks flag. Remove stale comment. * doc/misc/gnus-faq.texi (FAQ 5-8): * lisp/simple.el (shell-command-on-region): Fix indentation. * lisp/files.el (kill-buffer-hook): Document when hook is inhibited. (create-file-buffer): * lisp/gnus/gnus-uu.el (gnus-uu-unshar-article): * lisp/international/mule.el (load-with-code-conversion): * lisp/mh-e/mh-xface.el (mh-x-image-url-fetch-image): * lisp/net/imap.el (imap-open): * lisp/net/mailcap.el (mailcap-maybe-eval): * lisp/progmodes/flymake-proc.el (flymake-proc--read-file-to-temp-buffer) (flymake-proc--copy-buffer-to-temp-buffer): Simplify. * lisp/subr.el (generate-new-buffer): Forward new optional argument to inhibit buffer hooks to get-buffer-create. (with-temp-file, with-temp-buffer, with-output-to-string): * lisp/json.el (json-encode-string): Inhibit buffer hooks in buffer used. * src/buffer.c (run_buffer_list_update_hook): New helper function. (Fget_buffer_create): Use it. Add optional argument to set inhibit_buffer_hooks flag instead of comparing the buffer name to Vcode_conversion_workbuf_name. All callers changed. (Fmake_indirect_buffer, Frename_buffer, Fbury_buffer_internal) (record_buffer): Use run_buffer_list_update_hook. (Fkill_buffer): Document when buffer hooks are inhibited. Use run_buffer_list_update_hook. (init_buffer_once): Inhibit buffer hooks in Vprin1_to_string_buffer. (Vkill_buffer_query_functions, Vbuffer_list_update_hook): Document when hooks are inhibited. * src/buffer.h (struct buffer): Update inhibit_buffer_hooks commentary. * src/coding.h (Vcode_conversion_workbuf_name): * src/coding.c (Vcode_conversion_workbuf_name): Make static again since it is no longer needed in src/buffer.c. (code_conversion_restore, code_conversion_save, syms_of_coding): Prefer boolean over integer constants. * src/fileio.c (Finsert_file_contents): Inhibit buffer hooks in " *code-converting-work*" buffer. * src/window.c (Fselect_window): Fix grammar. Mention window-selection-change-functions alongside buffer-list-update-hook. * test/src/buffer-tests.el: Fix requires. (buffer-tests-inhibit-buffer-hooks): New test.
2020-11-19* src/buffer.h (struct buffer): Remove unused field `minor_modes`Stefan Monnier1-3/+0
* src/buffer.c (bset_minor_modes): Remove function. (reset_buffer_local_variables, init_buffer_once): Don't set `minor_modes`.
2020-04-17Prefer more inline functions in character.hPaul Eggert1-0/+101
* src/buffer.h (fetch_char_advance, fetch_char_advance_no_check) (buf_next_char_len, next_char_len, buf_prev_char_len) (prev_char_len, inc_both, dec_both): New inline functions, replacing the old character.h macros FETCH_CHAR_ADVANCE, FETCH_CHAR_ADVANCE_NO_CHECK, BUF_INC_POS, INC_POS, BUF_DEC_POS, DEC_POS, INC_BOTH, DEC_BOTH respectively. All callers changed. These new functions all assume buffer primitives and so need to be here rather than in character.h. * src/casefiddle.c (make_char_unibyte): New static function, replacing the old MAKE_CHAR_UNIBYTE macro. All callers changed. (do_casify_unibyte_string): Use SINGLE_BYTE_CHAR_P instead of open-coding it. * src/ccl.c (GET_TRANSLATION_TABLE): New static function, replacing the old macro of the same name. * src/character.c (string_char): Omit 2nd arg. 3rd arg can no longer be NULL. All callers changed. * src/character.h (SINGLE_BYTE_CHAR_P): Move up. (MAKE_CHAR_UNIBYTE, MAKE_CHAR_MULTIBYTE, PREV_CHAR_BOUNDARY) (STRING_CHAR_AND_LENGTH, STRING_CHAR_ADVANCE) (FETCH_STRING_CHAR_ADVANCE) (FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE) (FETCH_STRING_CHAR_ADVANCE_NO_CHECK, FETCH_CHAR_ADVANCE) (FETCH_CHAR_ADVANCE_NO_CHECK, INC_POS, DEC_POS, INC_BOTH) (DEC_BOTH, BUF_INC_POS, BUF_DEC_POS): Remove. (make_char_multibyte): New static function, replacing the old macro MAKE_CHAR_MULTIBYTE. All callers changed. (CHAR_STRING_ADVANCE): Remove; all callers changed to use CHAR_STRING. (NEXT_CHAR_BOUNDARY): Remove; it was unused. (raw_prev_char_len): New inline function, replacing the old PREV_CHAR_BOUNDARY macro. All callers changed. (string_char_and_length): New inline function, replacing the old STRING_CHAR_AND_LENGTH macro. All callers changed. (STRING_CHAR): Rewrite in terms of string_char_and_length. (string_char_advance): New inline function, replacing the old STRING_CHAR_ADVANCE macro. All callers changed. (fetch_string_char_advance): New inline function, replacing the old FETCH_STRING_CHAR_ADVANCE macro. All callers changed. (fetch_string_char_as_multibyte_advance): New inline function, replacing the old FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE macro. All callers changed. (fetch_string_char_advance_no_check): New inline function, replacing the old FETCH_STRING_CHAR_ADVANCE_NO_CHECK macro. All callers changed. * src/regex-emacs.c (HEAD_ADDR_VSTRING): Remove; no longer used. * src/syntax.c (scan_lists): Use dec_bytepos instead of open-coding it. * src/xdisp.c (string_char_and_length): Rename from string_char_and_length to avoid name conflict with new function in character.h. All callers changed.
2020-04-17Prefer inline functions in character.hPaul Eggert1-0/+39
In character.h, replace macros with inline functions or enums when this is easy. This improves maintainability and on my platform (Fedora 31 x86-64, gcc -O2) improved CPU performance very slightly (0.3%) on ‘make compile-always’. * src/buffer.h (SANE_TAB_WIDTH, CHARACTER_WIDTH): Move here from character.h, and make them inline functions. Tune CHARACTER_WIDTH so that ASCII_CHAR_WIDTH is no longer needed. (sanitize_tab_width, sanitize_char_width): Move here from character.h. * src/character.h (MAX_CHAR, MAX_UNICODE_CHAR, MAX_1_BYTE_CHAR) (MAX_2_BYTE_CHAR, MAX_3_BYTE_CHAR, MAX_4_BYTE_CHAR) (MAX_5_BYTE_CHAR, MIN_MULTIBYTE_LEADING_CODE) (MAX_MULTIBYTE_LEADING_CODE, MAX_MULTIBYTE_LENGTH): Now enum constants instead of macros. * src/character.h (CHAR_BYTES): Redo to avoid conditional branches. (CHAR_BYTE8_P, BYTE8_TO_CHAR, UNIBYTE_TO_CHAR, CHAR_TO_BYTE8) (CHAR_TO_BYTE_SAFE, CHAR_BYTE8_HEAD_P, CHARACTERP) (CHECK_CHARACTER, CHECK_CHARACTER_CAR, CHECK_CHARACTER_CDR) (CHAR_PRINTABLE_P, CHAR_BYTES, CHAR_LEADING_CODE, BYTE8_STRING) (LEADING_CODE_P, TRAILING_CODE_P, CHAR_HEAD_P) (BYTES_BY_CHAR_HEAD): Now inline functions instead of macros. (ASCII_CHAR_WIDTH): Remove; no longer used. * src/conf_post.h (ATTRIBUTE_PURE): New macro. * src/lisp.h (char_table_ref): Use it, for better inlining. * src/fns.c (base64_decode_1): Add now-necessary casts.
2020-03-31Remove `all_buffers` and the associated `next` field of buffersStefan Monnier1-12/+0
* src/alloc.c (enum mem_type): Remove MEM_TYPE_BUFFER. (allocate_buffer): Allocate like any other pseudovector. Don't register on `all_buffers` any more. (live_buffer_holding, live_buffer_p): Delete functions. (mark_maybe_object, valid_lisp_object_p): Don't pay attention to MEM_TYPE_BUFFER any more. (garbage_collect): Only compact the live buffers. (mark_buffer): Mark the undo_list of dead buffers here. (mark_object): Buffers are normal pseudovectors now. (sweep_buffers): Don't do the actual sweep here, just cleanup the markers and only for live buffers. * src/buffer.c (all_buffers): Remove variable. (Fkill_buffer): Don't check indirect dead buffers. Set the undo_list before we remove ourselves from the list of live buffers. (Fbuffer_swap_text, Fset_buffer_multibyte): Don't check indirect dead buffers. (init_buffer_once): Don't set `all_buffers`. (init_buffer): Don't map new memory for dead buffers. * src/buffer.h (struct buffer): Remove `next` field. (FOR_EACH_BUFFER): Remove macro. * src/pdumper.c (dump_buffer): Don't dump the `next` field.
2020-03-27Treat out-of-range positions consistentlyPaul Eggert1-0/+2
If a position argument to get-byte etc. is an out-of-range integer, treat it the same regardless of whether it is a fixnum or a bignum. * src/buffer.c (fix_position): New function. * src/buffer.c (validate_region): * src/character.c (Fget_byte): * src/coding.c (Ffind_coding_systems_region_internal) (Fcheck_coding_systems_region): * src/composite.c (Ffind_composition_internal): * src/editfns.c (Fposition_bytes, Fchar_after, Fchar_before) (Finsert_buffer_substring, Fcompare_buffer_substrings) (Fnarrow_to_region): * src/fns.c (Fsecure_hash_algorithms): * src/font.c (Finternal_char_font, Ffont_at): * src/fringe.c (Ffringe_bitmaps_at_pos): * src/search.c (search_command): * src/textprop.c (get_char_property_and_overlay): * src/window.c (Fpos_visible_in_window_p): * src/xdisp.c (Fwindow_text_pixel_size): Use it instead of CHECK_FIXNUM_COERCE_MARKER, so that the code is simpler and treats bignums consistently with fixnums. * src/buffer.h (CHECK_FIXNUM_COERCE_MARKER): Define here rather than in lisp.h, and reimplement in terms of fix_position so that it treats bignums consistently with fixnums. * src/lisp.h (CHECK_FIXNUM_COERCE_MARKER): Move to buffer.h. * src/textprop.c (validate_interval_range): Signal with original bounds rather than modified ones.