patches: apply all maintainer review fixes (review pass 2)

All 9 patches now apply cleanly with git am on Linux (git 2.43.0).
Root cause of previous failures: hunk offsets were systematically wrong
by 7-40 lines; macOS git fuzzy-matched them, Linux did not.
Patches regenerated via git format-patch after applying all changes.

Fixes applied:
- P0000: unbind_to on no-candidate fall-through path; hunk regenerated
- P0001: block_input + record_unwind_protect_void in ns_ax_buffer_text
- P0003: [trims release] MRC memory leak; block_input already present
- P0004: mojibake comment (--- not UTF-8 em-dash)
- P0006: texinfo dangling semicolons -> periods in GNUstep paragraph
- P0007: em-dash fixes removed (content was already --- from P0004/P0005)
- P0008: childFrameLastBuffer -> BVAR(b,name) for GC safety;
  BUF_OVERLAY_MODIFF removed from ensureTextCache (hl-line-mode O(N)
  rebuild regression); block_input in ns_ax_buffer_text (P0001 scope);
  voiceoverSetPoint and childFrameLastBuffer explicit init in
  initFrameFromEmacs:; cachedOverlayModiffForText ivar removed
This commit is contained in:
2026-03-02 18:50:45 +01:00
parent 51f59441c1
commit 6176087cfb
9 changed files with 176 additions and 200 deletions

View File

@@ -1,30 +1,43 @@
From 830710de8a7bac560d71ae802dcf7df60517c57b Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 16:01:29 +0100
Subject: [PATCH 8/8] ns: announce child frame completion candidates for
From 3daf00725fe434bfe5e820fd69e390697e9e6373 Mon Sep 17 00:00:00 2001
From: Daneel <daneel@sukany.cz>
Date: Mon, 2 Mar 2026 18:49:13 +0100
Subject: [PATCH 9/9] ns: announce child frame completion candidates for
VoiceOver
Completion frameworks such as Corfu and Company-box render candidates
in a child frame. This extends the overlay announcement support to
handle child frame popups.
Child frame popups (Corfu, Company-mode child frames) render completion
candidates in a separate frame whose buffer is not accessible via the
minibuffer overlay path. This patch scans child frame buffers for
selected candidates and announces them via VoiceOver.
* src/nsterm.m (ns_ax_selected_child_frame_text): New function; scan
a child frame buffer line by line using Fget_char_property to find the
selected candidate; uses record_unwind_current_buffer for safety.
(EmacsView announceChildFrameCompletion): New method.
(EmacsView postAccessibilityUpdates): Detect child frames via
FRAME_PARENT_FRAME; call announceChildFrameCompletion. Post
NSAccessibilityFocusedUIElementChangedNotification on the parent buffer
element when a child frame completion closes.
* src/nsterm.h (EmacsView): Add childFrameLastBuffer, childFrameLastModiff,
childFrameLastCandidate, childFrameCompletionActive, lastEchoCharsModiff
ivars; remove cachedOverlayModiffForText (unused after BUF_OVERLAY_MODIFF
removed from ensureTextCache to prevent hl-line-mode O(N) rebuilds).
Initialize voiceoverSetPoint, childFrameLastBuffer in initFrameFromEmacs:.
(EmacsAXBuffer): Add voiceoverSetPoint ivar.
* src/nsterm.m (ns_ax_buffer_text): Add block_input protection for
Lisp calls; use record_unwind_protect_void to guarantee unblock_input.
(ensureTextCache): Remove BUF_OVERLAY_MODIFF tracking; keep only
BUF_CHARS_MODIFF. BUF_OVERLAY_MODIFF caused O(buffer-size) rebuilds
with hl-line-mode (moves overlay on every post-command-hook).
(announceChildFrameCompletion): New method; scans child frame buffers
for selected completion candidates. Store childFrameLastBuffer as
BVAR(b, name) (buffer name symbol, GC-reachable via obarray) rather
than make_lisp_ptr to avoid dangling pointer after buffer kill.
(postEchoAreaAnnouncementIfNeeded): New method; announces echo area
changes for commands like C-g.
(postAccessibilityNotificationsForFrame:): Drive child frame and echo
area announcements.
* doc/emacs/macos.texi: Fix dangling semicolon in GNUstep paragraph.
---
doc/emacs/macos.texi | 18 +-
doc/emacs/macos.texi | 14 +-
etc/NEWS | 18 +-
src/nsterm.h | 21 ++
src/nsterm.m | 496 +++++++++++++++++++++++++++++++++++++++----
4 files changed, 501 insertions(+), 52 deletions(-)
src/nsterm.h | 20 ++
src/nsterm.m | 537 +++++++++++++++++++++++++++++++++++++++----
4 files changed, 538 insertions(+), 51 deletions(-)
diff --git a/doc/emacs/macos.texi b/doc/emacs/macos.texi
index 6514dfc..bcf74b3 100644
index 8d4a7825d8..03a657f970 100644
--- a/doc/emacs/macos.texi
+++ b/doc/emacs/macos.texi
@@ -278,7 +278,6 @@ restart Emacs to access newly-available services.
@@ -55,22 +68,11 @@ index 6514dfc..bcf74b3 100644
@vindex ns-accessibility-enabled
To disable the accessibility interface entirely (for instance, to
@@ -341,8 +345,8 @@ but @code{accessibilityRangeForPosition} hit-testing assumes
left-to-right glyph layout.
@end itemize
- This support is available only on the Cocoa build; GNUstep has a
-different accessibility model and is not yet supported;
+ This support is available only on the Cocoa build. GNUstep has a
+different accessibility model and is not yet supported.
Block-style cursors are handled
correctly: character navigation announces the character at the cursor
position, not the character before it.
diff --git a/etc/NEWS b/etc/NEWS
index 2b1f9e6..5766428 100644
index 7f917f93b2..d7631fa6c7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -4400,15 +4400,19 @@ allowing Emacs users access to speech recognition utilities.
@@ -4385,16 +4385,20 @@ allowing Emacs users access to speech recognition utilities.
Note: Accepting this permission allows the use of system APIs, which may
send user data to Apple's speech recognition servers.
@@ -99,10 +101,10 @@ index 2b1f9e6..5766428 100644
interface and eliminate the associated overhead.
diff --git a/src/nsterm.h b/src/nsterm.h
index 21a93bc..d435e42 100644
index 21a93bc799..bdd40b8eb7 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -504,9 +504,21 @@ typedef struct ns_ax_visible_run
@@ -504,9 +504,20 @@ typedef struct ns_ax_visible_run
NSUInteger lineCount; /* Entries in lineStartOffsets. */
NSMutableArray *cachedInteractiveSpans;
BOOL interactiveSpansDirty;
@@ -120,11 +122,10 @@ index 21a93bc..d435e42 100644
+/* Overlay modiff at last text cache rebuild. Tracked separately from
+ cachedOverlayModiff (which is used for completion announcements) so
+ that fold/unfold detection is independent of notification dispatch. */
+@property (nonatomic, assign) ptrdiff_t cachedOverlayModiffForText;
@property (nonatomic, assign) ptrdiff_t cachedOverlayModiff;
@property (nonatomic, assign) ptrdiff_t cachedTextStart;
@property (nonatomic, assign) ptrdiff_t cachedModiff;
@@ -596,6 +608,14 @@ typedef NS_ENUM (NSInteger, EmacsAXSpanType)
@@ -596,6 +607,14 @@ typedef NS_ENUM (NSInteger, EmacsAXSpanType)
Lisp_Object lastRootWindow;
BOOL accessibilityTreeValid;
BOOL accessibilityUpdating;
@@ -139,7 +140,7 @@ index 21a93bc..d435e42 100644
#endif
BOOL font_panel_active;
NSFont *font_panel_result;
@@ -665,6 +685,7 @@ typedef NS_ENUM (NSInteger, EmacsAXSpanType)
@@ -665,6 +684,7 @@ typedef NS_ENUM (NSInteger, EmacsAXSpanType)
- (void)rebuildAccessibilityTree;
- (void)invalidateAccessibilityTree;
- (void)postAccessibilityUpdates;
@@ -148,7 +149,7 @@ index 21a93bc..d435e42 100644
@end
diff --git a/src/nsterm.m b/src/nsterm.m
index 8d44b5f..29b646d 100644
index 5e6ab11295..6e0575677e 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1126,24 +1126,19 @@ Uses CFAbsoluteTimeGetCurrent() (~5 ns, a VDSO read) for timing. */
@@ -186,9 +187,9 @@ index 8d44b5f..29b646d 100644
}
/* Scan overlay before-string / after-string properties in the
@@ -1356,6 +1351,12 @@ so the visual offset is (ov_line + 1) * line_h from
UAZoomChangeFocus (&cgRect, &cgRect,
kUAZoomFocusTypeInsertionPoint);
@@ -1464,6 +1459,12 @@ so the visual offset is (ov_line + 1) * line_h from
#endif
gsaved = YES;
}
+ /* Unbind record_unwind_current_buffer for both overlay and child
+ frame paths. The overlay path calls unbind_to before return;
@@ -198,8 +199,8 @@ index 8d44b5f..29b646d 100644
+ unbind_to (count, Qnil);
}
#endif /* MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 */
@@ -7415,6 +7416,112 @@ visual line index for Zoom (skip whitespace-only lines
@@ -7407,6 +7408,112 @@ visual line index for Zoom (skip whitespace-only lines
return nil;
}
@@ -312,15 +313,16 @@ index 8d44b5f..29b646d 100644
/* Build accessibility text for window W, skipping invisible text.
Populates *OUT_START with the buffer start charpos.
Populates *OUT_RUNS with an array of visible runs and *OUT_NRUNS
@@ -8046,6 +8153,7 @@ that remapped bindings (e.g., C-j -> next-line) are recognized.
@implementation EmacsAccessibilityBuffer
@synthesize cachedText;
@synthesize cachedTextModiff;
+@synthesize cachedOverlayModiffForText;
@synthesize cachedOverlayModiff;
@synthesize cachedTextStart;
@synthesize cachedModiff;
@@ -8159,16 +8267,34 @@ - (void)ensureTextCache
@@ -7441,6 +7548,8 @@ visual line index for Zoom (skip whitespace-only lines
specpdl_ref count = SPECPDL_INDEX ();
record_unwind_current_buffer ();
+ record_unwind_protect_void (unblock_input);
+ block_input ();
if (b != current_buffer)
set_buffer_internal_1 (b);
@@ -8147,16 +8256,32 @@ - (void)ensureTextCache
if (!b)
return;
@@ -348,32 +350,29 @@ index 8d44b5f..29b646d 100644
+ Including overlay_modiff would silently update cachedOverlayModiff
+ and prevent the notification dispatch from detecting changes. */
+ ptrdiff_t chars_modiff = BUF_CHARS_MODIFF (b);
+ ptrdiff_t overlay_modiff = BUF_OVERLAY_MODIFF (b);
+ ptrdiff_t pt = BUF_PT (b);
+ NSUInteger textLen = cachedText ? [cachedText length] : 0;
+ /* Cache is valid when neither characters nor fold-state have changed.
+ BUF_CHARS_MODIFF guards against character edits and is not bumped
+ by font-lock (text-property changes), preserving the O(1) hot path.
+ BUF_OVERLAY_MODIFF catches fold/unfold: outline-mode, org-mode, and
+ hideshow all use overlays (via outline-flag-region) in Emacs 28+.
+ Font-lock uses only text properties, so adding BUF_OVERLAY_MODIFF
+ here does not reintroduce the per-redisplay rebuild. */
+ Do NOT add BUF_OVERLAY_MODIFF here: modes like hl-line-mode move
+ overlays on every post-command-hook, bumping BUF_OVERLAY_MODIFF and
+ causing O(buffer-size) text rebuilds per keystroke. Fold/unfold
+ changes visible characters and thereby bumps BUF_CHARS_MODIFF. */
+ if (cachedText && cachedTextModiff == chars_modiff
+ && cachedOverlayModiffForText == overlay_modiff
&& cachedTextStart == BUF_BEGV (b)
&& pt >= cachedTextStart
&& (textLen == 0
@@ -8184,7 +8310,8 @@ included in the cached AX text (it is handled separately via
@@ -8172,7 +8297,7 @@ included in the cached AX text (it is handled separately via
{
[cachedText release];
cachedText = [text retain];
- cachedTextModiff = modiff;
+ cachedTextModiff = chars_modiff;
+ cachedOverlayModiffForText = overlay_modiff;
cachedTextStart = start;
if (visibleRuns)
@@ -8597,6 +8724,11 @@ - (void)setAccessibilitySelectedTextRange:(NSRange)range
@@ -8585,6 +8710,11 @@ - (void)setAccessibilitySelectedTextRange:(NSRange)range
[self ensureTextCache];
@@ -385,7 +384,7 @@ index 8d44b5f..29b646d 100644
specpdl_ref count = SPECPDL_INDEX ();
record_unwind_current_buffer ();
/* Ensure block_input is always matched by unblock_input even if
@@ -9064,14 +9196,22 @@ - (void)postFocusedCursorNotification:(ptrdiff_t)point
@@ -9040,15 +9170,23 @@ - (void)postFocusedCursorNotification:(ptrdiff_t)point
= @(ns_ax_text_state_change_selection_move);
moveInfo[@"AXTextSelectionDirection"] = @(direction);
moveInfo[@"AXTextChangeElement"] = self;
@@ -414,7 +413,8 @@ index 8d44b5f..29b646d 100644
+ self.emacsView,
NSAccessibilitySelectedTextChangedNotification,
moveInfo);
@@ -9111,12 +9254,17 @@ derive its own speech (it would read the wrong character
@@ -9146,12 +9284,17 @@ user expectation ("w" jumps to next word and reads it). */
}
}
@@ -437,7 +437,7 @@ index 8d44b5f..29b646d 100644
if (cachedText
&& granularity == ns_ax_text_selection_granularity_line)
{
@@ -9179,7 +9327,14 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
@@ -9214,7 +9357,14 @@ - (void)postCompletionAnnouncementForBuffer:(struct buffer *)b
ptrdiff_t currentOverlayStart = 0;
ptrdiff_t currentOverlayEnd = 0;
@@ -452,7 +452,7 @@ index 8d44b5f..29b646d 100644
record_unwind_current_buffer ();
if (b != current_buffer)
set_buffer_internal_1 (b);
@@ -9356,12 +9511,29 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
@@ -9390,12 +9540,29 @@ - (void)postAccessibilityNotificationsForFrame:(struct frame *)f
if (!b)
return;
@@ -482,7 +482,7 @@ index 8d44b5f..29b646d 100644
if (modiff != self.cachedModiff)
{
self.cachedModiff = modiff;
@@ -9375,6 +9547,7 @@ Text property changes (e.g. face updates from
@@ -9409,6 +9576,7 @@ Text property changes (e.g. face updates from
{
self.cachedCharsModiff = chars_modiff;
[self postTextChangedNotification:point];
@@ -490,7 +490,7 @@ index 8d44b5f..29b646d 100644
}
}
@@ -9397,8 +9570,15 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
@@ -9431,8 +9599,15 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
displayed in the minibuffer. In normal editing buffers,
font-lock and other modes change BUF_OVERLAY_MODIFF on
every redisplay, triggering O(overlays) work per keystroke.
@@ -508,7 +508,7 @@ index 8d44b5f..29b646d 100644
goto skip_overlay_scan;
int selected_line = -1;
@@ -9444,7 +9624,18 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
@@ -9478,7 +9653,18 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
self.cachedPoint = point;
self.cachedMarkActive = markActive;
@@ -528,7 +528,7 @@ index 8d44b5f..29b646d 100644
NSInteger direction = ns_ax_text_selection_direction_discontiguous;
if (point > oldPoint)
direction = ns_ax_text_selection_direction_next;
@@ -9492,6 +9683,58 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
@@ -9526,6 +9712,58 @@ frameworks like Vertico bump BOTH BUF_MODIFF (via text property
granularity = ns_ax_text_selection_granularity_line;
}
@@ -587,7 +587,7 @@ index 8d44b5f..29b646d 100644
/* Post notifications for focused and non-focused elements. */
if ([self isAccessibilityFocused])
[self postFocusedCursorNotification:point
@@ -9634,6 +9865,17 @@ - (NSRect)accessibilityFrame
@@ -9668,6 +9906,17 @@ - (NSRect)accessibilityFrame
if (vis_start >= vis_end)
return @[];
@@ -605,7 +605,7 @@ index 8d44b5f..29b646d 100644
/* Symbols are interned once at startup via DEFSYM in syms_of_nsterm;
reference them directly here (GC-safe, no repeated obarray lookup). */
@@ -9754,6 +9996,7 @@ than O(chars). Fall back to pos+1 as safety net. */
@@ -9788,6 +10037,7 @@ than O(chars). Fall back to pos+1 as safety net. */
pos = span_end;
}
@@ -613,7 +613,7 @@ index 8d44b5f..29b646d 100644
return [[spans copy] autorelease];
}
@@ -9935,6 +10178,10 @@ - (void)dealloc
@@ -9969,6 +10219,10 @@ - (void)dealloc
#endif
[accessibilityElements release];
@@ -624,17 +624,18 @@ index 8d44b5f..29b646d 100644
[[self menu] release];
[super dealloc];
}
@@ -11384,6 +11631,9 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f
@@ -11418,6 +11672,10 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f
windowClosing = NO;
processingCompose = NO;
+#ifdef NS_IMPL_COCOA
+ childFrameLastBuffer = Qnil;
+ voiceoverSetPoint = NO;
+#endif
scrollbarsNeedingUpdate = 0;
fs_state = FULLSCREEN_NONE;
fs_before_fs = next_maximized = -1;
@@ -12692,6 +12942,154 @@ - (id)accessibilityFocusedUIElement
@@ -12726,6 +12984,154 @@ - (id)accessibilityFocusedUIElement
The existing elements carry cached state (modiff, point) from the
previous redisplay cycle. Rebuilding first would create fresh
elements with current values, making change detection impossible. */
@@ -719,15 +720,15 @@ index 8d44b5f..29b646d 100644
+ if (!BUFFER_LIVE_P (b))
+ return;
+ EMACS_INT modiff = BUF_MODIFF (b);
+ /* Compare buffer identity using the raw pointer, not a Lisp_Object.
+ A killed buffer can be GC'd even if we hold a Lisp_Object for it
+ (EmacsView is not GC-visible). Storing and comparing struct buffer *
+ is safe because we only test identity (not dereference) here, and
+ we guard all actual buffer field reads with BUFFER_LIVE_P below. */
+ if ((struct buffer *) XLP (childFrameLastBuffer) == b
+ /* Compare buffer identity via the buffer name symbol, which is always
+ GC-reachable through the obarray. Storing the name avoids keeping
+ a direct buffer pointer in a non-GC-visible ObjC ivar: if the buffer
+ were killed and GC swept, a stale make_lisp_ptr value could collide
+ with a newly-allocated buffer at the same address. */
+ if (EQ (childFrameLastBuffer, BVAR (b, name))
+ && modiff == childFrameLastModiff)
+ return;
+ childFrameLastBuffer = make_lisp_ptr (b, Lisp_Vectorlike);
+ childFrameLastBuffer = BVAR (b, name);
+ childFrameLastModiff = modiff;
+
+ if (!BUFFER_LIVE_P (b))
@@ -789,7 +790,7 @@ index 8d44b5f..29b646d 100644
- (void)postAccessibilityUpdates
{
NSTRACE ("[EmacsView postAccessibilityUpdates]");
@@ -12702,11 +13098,64 @@ - (void)postAccessibilityUpdates
@@ -12736,11 +13142,64 @@ - (void)postAccessibilityUpdates
/* Re-entrance guard: VoiceOver callbacks during notification posting
can trigger redisplay, which calls ns_update_end, which calls us