1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-18 08:51:45 -08:00
Commit graph

160134 commits

Author SHA1 Message Date
Stefan Monnier
7cbeeabc7e Tighten up handling of otick
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-09 19:45:26 -04:00
Stefan Monnier
4f3f7aebc9 itree.c: Use interval_tree_inherit_offset
The insertion code tried to manipulate the offset in its own way,
and apparently there was a bug in it.  Replace that with a call to
`interval_tree_inherit_offset`, making the whole logic a bit simpler,
and fixing a bug along the way (not sure where the bug was, to be honest).

* src/itree.c (interval_tree_insert): Use `interval_tree_inherit_offset`.
Check the tree before insert_fix.
(recurse_check_tree): Don't check RB invariants.
(itree_limits_are_stable): Delete function (subsumed by `check_tree`).
2022-10-09 00:56:24 -04:00
Matt Armstrong
fe14454101 Debug check overlay tree invariants
* src/itree.c (check_tree):
(recurse_check_tree): new functions.
(interval_tree_insert): call them.
(interval_tree_remove): ditto.
(interval_tree_insert_fix): ditto.
2022-10-08 20:37:28 -07:00
Matt Armstrong
92a0bf6ce2 ; * test/src/buffer-tests.el (test-overlay-randomly): new test. 2022-10-08 20:37:28 -07:00
Matt Armstrong
30f5220277 Comment change: explain inheriting "dirty" offsets
; * src/itree.c (interval_generator_next): explain why the code
handles inheriting offsets from dirty nodes.
2022-10-08 20:37:28 -07:00
Stefan Monnier
208de5de59 itree: Try and detect non-local exits during itree iterations
* src/itree.c (itree_busy_p): New function.
* src/eval.c (signal_or_quit): Use it.
* src/itree.h (itree_busy_p): Declare it.
2022-10-07 19:15:07 -04:00
Matt Armstrong
780d3d8df2 ; * src/itree.c: Add comment describing when noverlay is O(N) 2022-10-07 09:38:49 -07:00
Matt Armstrong
c0d5026321 Use a bool instead of a bitfield
* src/itree.c (struct interval_generator): use a bool instead of a
bitfield, since space is not an issue.
2022-10-07 09:38:49 -07:00
Matt Armstrong
cab3b67652 ; * src/itree.c: change comments for clarity. 2022-10-07 09:38:49 -07:00
Matt Armstrong
0fcd6de93b ; * src/itree.h (struct interval_node): document field invariants. 2022-10-07 09:38:49 -07:00
Matt Armstrong
6dff825a99 ; * src/itree.h: include "lisp.h" for Lisp_Object 2022-10-06 13:27:27 -07:00
Stefan Monnier
8bd114b98a itree.c: Get rid of the trick using null->parent
* src/itree.c (interval_tree_remove_fix): Add a `parent` argument.
Change the loop so it always keeps both `node` and `parent` in sync,
thus avoiding the use of `node->parent` on the initial node (since
that one can be null).
(interval_tree_remove): Manually keep track of the `broken` node's
parent to pass it to `interval_tree_remove_fix`.
2022-10-05 23:52:01 -04:00
Stefan Monnier
a1f1fdd291 * src/itree.c (interval_tree_remove_fix): Move before first use 2022-10-05 23:48:47 -04:00
Stefan Monnier
1f31534f51 itree.c: Fix corner case errors in offsets
In some cases, `interval_tree_remove` could cause some nodes to
inherit fewer (or additional) offsets than the should because nodes
were transplanted between two parts of the tree where offsets had not
been propagated "equally".  So we remove/apply all offsets along the
path between the two points of a transplant before doing the transplant.

* src/itree.c (interval_tree_subtree_min): Move before first use; delete
the declaration; add an `otick` argument, and use it to update offsets
along the way.
(interval_tree_remove): Update all offsets on the way from `node` to `min`.
Reorder some of the operations so that when we transplant `min` to `node`
those nodes are in the proper state where `interval_tree_transplant`
can do its sanity checks.
(itree_total_offset): New function.
(interval_tree_transplant): Use it to sanity check that improper
offsets aren't accidentally inherited/lost because of the transplant.
(itree_newlimit): New function.
(itree_limit_is_stable, interval_tree_update_limit)
(interval_tree_propagate_limit): Use it.
(null_is_sane): Remove `inline` annotation; it's not needed.
(interval_tree_inherit_offset): Sanity check that `offset` is 0 when
`otick` is uptodate.  Skip the unneeded increments when the offset is 0.
(interval_tree_insert_fix): Add sanity check that we indeed have 2 reds.
2022-10-05 22:55:54 -04:00
Stefan Monnier
5642b4a255 itree.c: Fix incomplete update of limits in corner cases
`interval_tree_remove` called `interval_tree_propagate_limit (subst)`
and `interval_tree_propagate_limit (min_right)` but both of those nodes
are moved without touching their subtrees, so their `limit`s are
"stable" causing `interval_tree_propagate_limit` to do nothing.
Indeed we don't need to update those nodes's `limit`s but we *do*
need to update their parents since those nodes have been moved.
Incidentally, this removes some uses of `null->parent` :-)

There are more uses of `null->parent`, tho, so I added more comments
explaining them (with the help of the matching section of the book
from which the algorithm was taken).

* src/itree.c (interval_tree_update_limit): Remove unused arg `tree`.
(interval_tree_rotate_left, interval_tree_rotate_right): Adjust callers.
(interval_tree_contains): Mark as static.
(itree_limit_is_stable, itree_limits_are_stable): New functions.
(interval_tree_remove): Fix incomplete update of `limit`s in corner
cases.
(interval_generator_next): Add sanity check to make sure the `limit`s
were properly updated.

* src/itree.h (interval_tree_contains): Remove declaration.
2022-10-05 16:38:50 -04:00
Stefan Monnier
aa5a32ca2c itree.c: Clarify how the sentinel is used
* src/itree.c (null_is_sane): New function.
(interval_tree_iter_start): Use it to make sure we haven't garbled null.
(itree_init): Fully initialize `itree_null` here...
(interval_tree_clear): ...instead of here.
(interval_tree_propagate_limit): Remove special code that read NULL->parent.
(interval_tree_remove): Do it explicitly before the call in those two
places where it can happen.
2022-10-05 12:12:01 -04:00
Stefan Monnier
4f4327c0b0 itree.c: Remove some unnecessary tree arguments
* src/itree.c (interval_tree_propagate_limit)
(interval_tree_subtree_min): Remove `tree` argument.
(interval_node_set_region, interval_tree_remove)
(interval_tree_insert_gap, interval_tree_delete_gap): Adjust callers.
2022-10-04 22:29:27 -04:00
Stefan Monnier
2c4a3910b3 itree: Use a single iterator object
Instead of having one iterator object per buffer, use just a single
global one.  There is virtually no benefit to having per-buffer
iterators anyway: if two iterations can be active at the same time,
then there can be cases where those two iterations happen
to operate on the same buffer :-(

* src/itree.h (struct interval_tree): Remove `iter` field.
* src/itree.c (interval_generator_destroy)
(interval_tree_iter_ensure_space): Delete functions.
(iter): New global variable.
(init_itree_null): Rename to `itree_init` and adjust all callers.
Initialize `iter` as well.
(interval_tree_create, interval_tree_init):
Don't initialize `iter` field any more.
(interval_tree_destroy): Don't destroy `iter` field any more.
(interval_tree_insert): Don't bother growing the iterator (it's grown
in `interval_stack_push_flagged` if needed anyway, and in any case
there's no `iter` here to grow any more).
(interval_tree_remove): Tweak assertion to be more precise and
self-evident.
(interval_tree_iter_start): Use the global `iter`.
(interval_generator_create): Make it work with a NULL argument.
2022-10-02 12:27:37 -04:00
Stefan Monnier
b8fbd42f0a mark_overlays: Use the normal ITREE_FOREACH
This commit basically reverts commit 5b954f8f9.  The problem of nested
iterations hasn't been fixed in the mean time, but since the GC can
run arbitrary ELisp code (via `post-gc-hook`), running the GC from
within an itree iteration is already unsafe anyway :-(

* src/alloc.c (mark_overlays): Delete function.
(mark_buffer): Use ITREE_FOREACH.
2022-10-02 12:21:13 -04:00
Stefan Monnier
ba5fe8e789 itree.c: Remove tree field from iterator
* src/itree.c (interval_generator_ensure_space, interval_generator_reset):
Inline and then delete functions.
(interval_tree_inherit_offset): Only take the tree's `otick` as arg.
Update all callers.
(struct interval_generator): Remove `tree` field, replace with a copy
of the tree's `otick`.
(interval_stack_push_flagged): The arg should be a real node.
(interval_tree_insert_gap): Prefer checking root==NULL rather than size==0.
Skip loop when tree is empty to avoid pushing&processing the NULL node.
(interval_tree_inherit_offset): Prefer parent==NULL rather than
node==root to avoid accessing the tree object.
2022-10-02 11:11:57 -04:00
Stefan Monnier
c3eb6c0563 Merge remote-tracking branch 'origin/feature/noverlay' into noverlay 2022-10-02 01:31:59 -04:00
Stefan Monnier
1303f55161 New ITREE_FOREACH macro
* 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-10-02 01:30:44 -04:00
Gerd Möllmann
c55254dccc Make it compile with ITREE_DEBUG defined
* src/buffer.c (make_lispy_interval_node): Use make_fixnum.
(overlay_tree): Use ITREE_NULL.
2022-10-01 08:32:05 +02:00
Stefan Monnier
ab2926aad3 itree.c: Improve division between tree and iterator
* 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-30 20:37:15 -04:00
Gerd Möllmann
009249e0c6 Remove the per-tree null node
"make check" shows 0 unexpcted.

* src/itree.h (itree_null): Declare extern.
(ITREE_NULL): New macro
(struct interval_tree): Remove null member.
* src/alloc.c (mark_overlays): Use ITREE_NULL.
* src/itree.c: Use ITREE_NULL insteads of a tree's null.
* src/pdumper.c (dump_buffer): Use ITREE_NULL.
2022-09-30 13:25:15 +02:00
Stefan Monnier
a7ad0f806c itree: Remove the visited flag from the tree nodes
These bits really belong in the "workstack" used within
`interval_generator_next`, so move them there.

* src/itree.c (nodeptr_and_flag): New type;
(struct interval_stack): Use it.
(make_nav, nav_nodeptr, nav_flag): New functions.
(interval_tree_insert_gap, interval_tree_delete_gap): Adjust accordingly.
(interval_generator_next): Stash the `visited` bit in the work stack
rather than inside the tree nodes.
(interval_stack_create, interval_stack_destroy, interval_stack_clear)
(interval_stack_ensure_space, interval_stack_push_flagged)
(interval_stack_push, interval_stack_pop): Move before first use.

* src/itree.h (struct interval_node): Remove `visited` field.
* src/pdumper.c (dump_interval_node): Adjust accordingly.
2022-09-29 17:12:21 -04:00
Stefan Monnier
757c116f6b free_buffer_overlays: Move nearer to its sole caller
* 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-29 16:15:01 -04:00
Stefan Monnier
8e61648693 * src/itree.c (interval_tree_iter_start): Improve error message 2022-09-29 14:10:04 -04:00
Stefan Monnier
5b954f8f9d alloc.c: Avoid nested overlay iterations (bug#58158)
* src/alloc.c (mark_overlays): New function.
(mark_buffer): Use it instead of using the overlay iterator.
2022-09-29 09:08:37 -04:00
Stefan Monnier
ea8daec9bb itree.[ch]: Add sanity checks, comments, and minor tweaks
* src/alloc.c (mark_overlay): Add sanity check.

* src/buffer.c (next_overlay_change, previous_overlay_change):
Tweak code to keep the same vars for the bounds.

* src/itree.c (interval_tree_clear, interval_tree_insert)
(interval_tree_remove, interval_tree_insert_fix, interval_tree_remove_fix):
Adjust to the `color` -> `red` change.
(interval_tree_clear): Prefer `true/false` for booleans.
(interval_generator_create): Use an actual `interval_tree_order` value
rather than 0.
(interval_generator_next): Simplify a tiny bit.  Add comment.
(interval_generator_narrow): Add sanity check.

* src/itree.h (struct interval_node): Replace `color` field with
boolean `red` field.
(enum interval_tree_order): Remove unused `ITREE_DEFLT_ORDER` value.

* src/pdumper.c (dump_interval_node): Adjust to the
`color` -> `red` change.
2022-09-28 19:05:16 -04:00
Stefan Monnier
800ecd4767 Merge remote-tracking branch 'origin/scratch/noverlay-wip' into noverlay 2022-09-28 11:57:16 -04:00
Gerd Möllmann
17ba7ac5d9 Avoid nested iteration over intervals (bug#58144)
* src/xdisp.c (strings_with_newlines): Call
buffer_overlay_iter_finish.
2022-09-28 16:38:04 +02:00
Gerd Möllmann
498d331b07 Add debugging help for nested iterators (nug#58144)
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-09-28 16:30:34 +02:00
Gerd Möllmann
8173a292e7 Fix last change 2022-09-28 12:10:30 +02:00
Gerd Möllmann
409327ff68 Fix macOS build (bug#58108)
* src/itree.h (struct interval_tree): Rename member nil to null.
* src/itree.c: Use null instead of nil
* src/pdumper.c (dump_buffer): Use null instead of nil.
* src/itree.c: Fix copyright.
* src/itree.h: Fix copyright.
2022-09-27 12:55:49 +02:00
Stefan Monnier
1a77f09f3c * src/buffer.c (overlays_in): Fix confusion Z-vs-ZV
This fixes test failures in `test-overlays-in-2` and `test-remove-overlays`.
2022-09-25 22:24:35 -04:00
Stefan Monnier
650c20f1ca Merge 'master' into noverlay 2022-09-25 16:15:16 -04:00
Stefan Monnier
4b85ae6a24 Merge remote-tracking branch 'refs/remotes/origin/master' 2022-09-24 11:09:25 -04:00
kobarity
2084f4ada3 hideshow.el: Improve hs-toggle-hiding behavior
* lisp/progmodes/hideshow.el
(hs-find-block-beginning-match): New function to be used in
`hs-already-hidden-p'.
(hs-already-hidden-p): Add check if beginning of line is inside a
block.
(hs-toggle-hiding): Don't change to selected-window's buffer when
event arg is absent.

* test/lisp/progmodes/hideshow-tests.el
(hideshow-tests-with-temp-buffer-selected): New helper macro.
(hideshow-tests-make-event-at): New helper function.
(hideshow-already-hidden-p-1): New test.
(hideshow-toggle-hiding-1): New test.
(hideshow-mouse-toggle-hiding-1): New test (bug#52092).
2022-09-24 11:08:29 -04:00
Lars Ingebrigtsen
0df73dabc1 Regenerated ldefs-boot.el 2022-09-24 16:51:53 +02:00
Lars Ingebrigtsen
b7fb82bc41 Remove "manual" package--builtin-versions updates
* lisp/emacs-lisp/nadvice.el:
* lisp/emacs-lisp/cl-generic.el: Don't push to
package--builtin-versions "manually", because loaddefs-gen does
this correctly now.
2022-09-24 16:51:53 +02:00
Brian Cully
152c7322c1 * lisp/net/tramp-docker.el: New file. 2022-09-24 16:48:01 +02:00
Stefan Monnier
c1cead89f5 (event-start/end): Fix part of bug#52092
When synthesizing a posn for keyboard events, make sure the `posn-point`
i the same as `point`.

* lisp/subr.el (event--posn-at-point): New function.
(event-start, event-end): Use it.
2022-09-24 10:38:09 -04:00
Stefan Monnier
0cc107ac09 Merge branch 'emacs-28' 2022-09-24 10:32:39 -04:00
Stefan Monnier
583ebfa414 * lisp/progmodes/hideshow.el (hs-toggle-hiding): Fix interactive form
This fixes the first part of bug#52092, which is a regression
introduced by commit d0e9113de9.
2022-09-24 10:24:54 -04:00
Lars Ingebrigtsen
2bacd9115f Make dired-do-rename refuse to rename . and ..
* lisp/dired-aux.el (dired-do-rename): Refuse to rename . and ..
(bug#52004).  This used to error out after renaming.
2022-09-24 15:27:50 +02:00
Lars Ingebrigtsen
8dacd8cd91 Add a new command vc-pull-and-push
* lisp/vc/vc-svn.el (vc-exec-after):
* lisp/vc/vc-hg.el (vc-exec-after):
* lisp/vc/vc-git.el (vc-exec-after):
* lisp/vc/vc-cvs.el (vc-exec-after):
* lisp/vc/vc-bzr.el (vc-exec-after):
* lisp/org/org-macro.el (vc-exec-after):
* lisp/obsolete/vc-mtn.el (vc-exec-after):
* lisp/obsolete/vc-arch.el (vc-exec-after): Update declaration.
* lisp/vc/vc-dispatcher.el (vc--process-sentinel): Allow running
code only on success.
(vc-exec-after): Ditto.
(vc--inhibit-change-window-start): New variable.
(vc-do-async-command): Use it to allow chaining commands without
moving window point.  Return the process instead of the buffer,
since the process may have exited already, and then we can't get
at the process.

* lisp/vc/vc-git.el (vc-git--pushpull): Return the process object.
(vc-git-pull-and-push): New function.

* lisp/vc/vc.el (vc-pull-and-push): New command (bug#51964).
2022-09-24 15:19:03 +02:00
Lars Ingebrigtsen
3ce322efef Tweak binding of `+' in vc-dir
* lisp/vc/vc-dir.el (vc-dir-mode-map): Point to the actual
function instead of the alias.  This makes *Help* more helpful.
2022-09-24 15:19:03 +02:00
Alan Mackenzie
e4b1445f43 CC Mode. Make AWK Mode work with electric-pair-mode
Also fix some minor anomalies with other CC Mode modes in electric-pair-mode.
This fixes bug #53446.

* lisp/progmodes/cc-mode.el (c-open-string-opener): New buffer local
variable.
(c-after-change-mark-abnormal-strings): Set c-open-string-opener when an
unbalanced string is detected.
(c-before-change): Initilize c-open-string-opener to nil, each buffer change.
(c-electric-pair-inhibit-predicate): Use the value of c-open-string-opener to
flag an unbalaced string rather than trying to calculate it again.

* lisp/progmodes/cc-awk.el (c-awk-syntax-tablify-string): Set
c-open-string-opener when an unbalanced string is detected.
2022-09-24 12:23:32 +00:00
Visuwesh
1556b43764 docview: Use svg images when using mupdf for conversion
* lisp/doc-view.el (doc-view-mupdf-use-svg, doc-view-svg-background)
(doc-view-svg-foreground): New user options.
(doc-view-insert-image): Add :background and :foreground image
attributes when display svg images.
(doc-view-set-up-single-converter): Produce svg images when using
mupdf (bug#58041).
2022-09-24 14:10:24 +02:00