patches: fix all compile errors and review issues

- ZV_S -> BUF_ZV (undefined macro)
- cf->current_buffer -> XWINDOW(cf->selected_window)->contents
  (current_buffer is a thread macro, can't use as field name)
- find_newline: add record_unwind_current_buffer + set_buffer_internal_1
- ns_zoom_track_completion: add specpdl unwind protection
- ns_zoom_face_is_selected: replace with forward decl of ns_ax_face_is_selected
  (eliminates duplicate)
- childFrameLastBuffer: struct buffer * -> Lisp_Object (safe vs kill-buffer)
- EmacsView dealloc: xfree childFrameLastCandidate (memory leak)
- postCompletionAnnouncementForBuffer: add block_input/unblock_input
This commit is contained in:
2026-03-01 03:58:04 +01:00
parent b283068f82
commit 84eb777065
9 changed files with 134 additions and 132 deletions

View File

@@ -1,4 +1,4 @@
From 45076d26a15ae82b489349d481f3c1a1792730a5 Mon Sep 17 00:00:00 2001
From 54cae6f8afe265c12cffaef121bad32bc165a777 Mon Sep 17 00:00:00 2001
From: Martin Sukany <martin@sukany.cz>
Date: Sat, 28 Feb 2026 22:39:35 +0100
Subject: [PATCH 1/9] ns: integrate with macOS Zoom for cursor tracking
@@ -38,8 +38,8 @@ window splits, switches (C-x o), and completion frameworks.
---
etc/NEWS | 11 ++
src/nsterm.h | 6 ++
src/nsterm.m | 285 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 302 insertions(+)
src/nsterm.m | 280 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 297 insertions(+)
diff --git a/etc/NEWS b/etc/NEWS
index ef36df5..80661a9 100644
@@ -81,10 +81,10 @@ index 7c1ee4c..ea6e7ba 100644
}
diff --git a/src/nsterm.m b/src/nsterm.m
index 74e4ad5..05ec3d1 100644
index 74e4ad5..2dd79ca 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1081,6 +1081,217 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
@@ -1081,6 +1081,209 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
}
@@ -93,31 +93,10 @@ index 74e4ad5..05ec3d1 100644
+#if defined (MAC_OS_X_VERSION_MIN_REQUIRED) \
+ && MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
+
+/* Check whether FACE (a Lisp symbol or list) has a name suggesting
+ it marks the currently selected completion candidate. Matches
+ vertico-current, icomplete-selected-match, ivy-current-match,
+ company-tooltip-selection, corfu-current, and similar. */
+static bool
+ns_zoom_face_is_selected (Lisp_Object face)
+{
+ if (SYMBOLP (face) && !NILP (face))
+ {
+ const char *name = SSDATA (SYMBOL_NAME (face));
+ if (strstr (name, "current")
+ || strstr (name, "selected")
+ || strstr (name, "selection"))
+ return true;
+ }
+ /* Handle face list (face1 face2 ...). */
+ if (CONSP (face))
+ {
+ Lisp_Object tail;
+ for (tail = face; CONSP (tail); tail = XCDR (tail))
+ if (ns_zoom_face_is_selected (XCAR (tail)))
+ return true;
+ }
+ return false;
+}
+/* Forward declaration --- defined in the VoiceOver section below.
+ Identifies faces like vertico-current, icomplete-selected-match,
+ ivy-current-match, corfu-current that mark the selected candidate. */
+static bool ns_ax_face_is_selected (Lisp_Object face);
+
+/* Scan overlay before-string / after-string properties in the
+ selected window for a completion candidate with a "selected"
@@ -128,7 +107,7 @@ index 74e4ad5..05ec3d1 100644
+{
+ struct buffer *b = XBUFFER (w->contents);
+ ptrdiff_t beg = marker_position (w->start);
+ ptrdiff_t end = ZV_S (b);
+ ptrdiff_t end = BUF_ZV (b);
+ Lisp_Object overlays = Foverlays_in (make_fixnum (beg),
+ make_fixnum (end));
+ Lisp_Object tail;
@@ -158,7 +137,7 @@ index 74e4ad5..05ec3d1 100644
+ Lisp_Object face
+ = Fget_text_property (make_fixnum (line_start),
+ Qface, str);
+ if (ns_zoom_face_is_selected (face))
+ if (ns_ax_face_is_selected (face))
+ return line;
+ line++;
+ line_start = i + 1;
@@ -190,7 +169,8 @@ index 74e4ad5..05ec3d1 100644
+ if (FRAME_PARENT_FRAME (cf) != f)
+ continue;
+ /* Small buffer = likely completion popup. */
+ struct buffer *b = XBUFFER (cf->current_buffer);
+ struct window *cw = XWINDOW (cf->selected_window);
+ struct buffer *b = XBUFFER (cw->contents);
+ if (BUF_ZV (b) - BUF_BEGV (b) > 10000)
+ continue;
+
@@ -198,14 +178,19 @@ index 74e4ad5..05ec3d1 100644
+ ptrdiff_t zv = BUF_ZV (b);
+ int line = 0;
+
+ specpdl_ref count = SPECPDL_INDEX ();
+ record_unwind_current_buffer ();
+ set_buffer_internal_1 (b);
+
+ ptrdiff_t pos = beg;
+ while (pos < zv)
+ {
+ Lisp_Object face
+ = Fget_char_property (make_fixnum (pos), Qface,
+ cf->current_buffer);
+ if (ns_zoom_face_is_selected (face))
+ cw->contents);
+ if (ns_ax_face_is_selected (face))
+ {
+ unbind_to (count, Qnil);
+ *child_frame = cf;
+ return line;
+ }
@@ -217,6 +202,7 @@ index 74e4ad5..05ec3d1 100644
+ pos = next;
+ line++;
+ }
+ unbind_to (count, Qnil);
+ }
+ return -1;
+}
@@ -230,6 +216,11 @@ index 74e4ad5..05ec3d1 100644
+{
+ if (!UAZoomEnabled ())
+ return;
+ if (!WINDOWP (f->selected_window))
+ return;
+
+ specpdl_ref count = SPECPDL_INDEX ();
+ record_unwind_current_buffer ();
+
+ struct window *w = XWINDOW (f->selected_window);
+ int line_h = FRAME_LINE_HEIGHT (f);
@@ -261,6 +252,7 @@ index 74e4ad5..05ec3d1 100644
+
+ UAZoomChangeFocus (&cgRect, &cgRect,
+ kUAZoomFocusTypeInsertionPoint);
+ unbind_to (count, Qnil);
+ return;
+ }
+ }
@@ -302,7 +294,7 @@ index 74e4ad5..05ec3d1 100644
static void
ns_update_end (struct frame *f)
/* --------------------------------------------------------------------------
@@ -1104,6 +1315,41 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
@@ -1104,6 +1307,41 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
unblock_input ();
ns_updating_frame = NULL;
@@ -344,7 +336,7 @@ index 74e4ad5..05ec3d1 100644
}
static void
@@ -3232,6 +3478,45 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
@@ -3232,6 +3470,45 @@ Note that CURSOR_WIDTH is meaningful only for (h)bar cursors.
/* Prevent the cursor from being drawn outside the text area. */
r = NSIntersectionRect (r, ns_row_rect (w, glyph_row, TEXT_AREA));
@@ -390,6 +382,16 @@ index 74e4ad5..05ec3d1 100644
ns_focus (f, NULL, 0);
NSGraphicsContext *ctx = [NSGraphicsContext currentContext];
@@ -8321,6 +8598,9 @@ - (instancetype) initFrameFromEmacs: (struct frame *)f
windowClosing = NO;
processingCompose = NO;
+#ifdef NS_IMPL_COCOA
+ childFrameLastBuffer = Qnil;
+#endif
scrollbarsNeedingUpdate = 0;
fs_state = FULLSCREEN_NONE;
fs_before_fs = next_maximized = -1;
--
2.43.0