From cc56e2e47c5f6f2015208e05d5fb145205d21a35 Mon Sep 17 00:00:00 2001 From: Martin Sukany Date: Wed, 4 Mar 2026 15:23:54 +0100 Subject: [PATCH 3/9] ns: implement buffer accessibility element MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implement the NSAccessibility text protocol for Emacs buffer windows. * src/nsterm.m (ns_ax_find_completion_overlay_range): New function. (ns_ax_event_is_line_nav_key, ns_ax_completion_text_for_span): New functions. (EmacsAccessibilityBuffer): Implement core NSAccessibility protocol. (ensureTextCache): Cache validity tracked via BUF_MODIFF so that fold/unfold commands (which change text properties but not characters) correctly invalidate the AX text cache. Add explanatory comment on why lineRangeForRange: in the lineStartOffsets loop is safe. (accessibilityIndexForCharpos:): O(1) fast path for pure-ASCII runs (ax_length == length); fall back to sequence walk for multi-byte runs. (charposForAccessibilityIndex:): Symmetric O(1) fast path. (accessibilityRole, accessibilityLabel, accessibilityValue) (accessibilityNumberOfCharacters, accessibilitySelectedText) (accessibilitySelectedTextRange, accessibilityInsertionPointLineNumber) (accessibilityLineForIndex:): New method; return the line number for an AX character index; defined here so patches 0003+ can call it without forward reference. (accessibilityRangeForLine:, accessibilityRangeForIndex:) (accessibilityStyleRangeForIndex:, accessibilityFrameForRange:) (accessibilityRangeForPosition:, accessibilityVisibleCharacterRange) (accessibilityFrame, setAccessibilitySelectedTextRange:) (setAccessibilityFocused:): Implement NSAccessibility protocol methods. ns: add accessibility base classes and text extraction Add the foundation for macOS VoiceOver accessibility in the NS (Cocoa) port. No existing code paths are modified. * src/nsterm.h (ns_ax_visible_run): New struct. (EmacsAccessibilityElement): New base Objective-C class. (EmacsAccessibilityBuffer, EmacsAccessibilityModeLine) (EmacsAccessibilityInteractiveSpan): Forward-declare new classes. (EmacsAXSpanType): New enum for interactive span types. (EmacsView): New ivars for accessibility element tree. * src/nsterm.m: Include intervals.h for TEXT_PROP_MEANS_INVISIBLE. (ns_ax_buffer_text): New function; build visible-text string and run array for a window, skipping invisible character regions. (ns_ax_mode_line_text): New function; extract mode-line text. (ns_ax_frame_for_range): New function; map charpos range to screen rect via glyph matrix. (ns_ax_completion_string_from_prop) (ns_ax_window_buffer_object, ns_ax_window_end_charpos) (ns_ax_text_prop_at, ns_ax_next_prop_change) (ns_ax_get_span_label, ns_ax_post_notification) (ns_ax_post_notification_with_info): New helper functions. (EmacsAccessibilityElement): Implement base class. (syms_of_nsterm): Register accessibility DEFSYMs. Add DEFVAR_BOOL ns-accessibility-enabled with corrected doc: initial value is nil, set non-nil automatically when an AT is detected at startup. ns: integrate with macOS Zoom for cursor tracking Inform macOS Zoom of the text cursor position so the zoomed viewport follows keyboard focus in Emacs. Also track completion candidates so Zoom follows the selected item (Vertico, Corfu, etc.) during completion. * etc/NEWS: Document Zoom integration. * src/nsterm.h (EmacsView): Add lastCursorRect, zoomCursorUpdated. * src/nsterm.m: Include ApplicationServices for UAZoomEnabled and UAZoomChangeFocus (UniversalAccess sub-framework). [NS_IMPL_COCOA]: Define NS_AX_MAX_COMPLETION_BUFFER_CHARS. (ns_zoom_enabled_p): New static function; caches UAZoomEnabled with 1-second TTL to avoid per-frame Mach IPC overhead. (ns_zoom_face_is_selected): New static predicate; matches 'current', 'selected', 'selection' in face symbol names. (ns_zoom_find_overlay_candidate_line): New static function; scans minibuffer overlays for the selected completion candidate line. (ns_zoom_find_child_frame_candidate): New static function; scans child frame buffers for a selected candidate; guards against partially initialized frames with WINDOWP and BUFFERP checks. (ns_zoom_track_completion): New static function; overrides Zoom focus to the selected completion candidate after normal cursor tracking. (ns_update_end): Call ns_zoom_track_completion. (ns_draw_window_cursor): Store cursor rect; call UAZoomChangeFocus. Fix `diary-rrule' recurrence rule calculation (Bug#80460) Thanks to TAKAHASHI Yoshio for reporting and for fixing one of the typos. In addition to the reported bug involving :include/:exclude, testing revealed that the provided RRULE COUNT clause was also not being handled correctly; this change also fixes that. * lisp/calendar/diary-icalendar.el (diary-rrule): Handle recurrence rules with a COUNT clause. * lisp/calendar/icalendar-recur.el (icalendar-recur-recurrences-in-interval): Fix a couple of typos that caused RDATE/EXDATE calculations to fail. * test/lisp/calendar/diary-icalendar-tests.el (diary-icalendar-test-rrule-bug-80460): New test for this bug. ; Avoid byte-compilation warning in c-ts-common.el * lisp/progmodes/c-ts-common.el (c-ts-common-comment-start-skip): Move up to avoid byte-compiler warning. Upgrade 'equal' from side-effect-free to error-free * lisp/emacs-lisp/byte-opt.el (side-effect-free-fns) (side-effect-and-error-free-fns): 'equal' and 'equal-including-properties' no longer signal 'circular-list'; while they do error on very deep structures, that is more of a resource limit so let's overlook that. Simplify peephole optimisation rule * lisp/emacs-lisp/byte-opt.el (byte-optimize-lapcode): Remove some obsolete dynamic variable optimisations that no longer improve any code. Fix broken logging (thanks Pip). ; Fix doc-string of 'window-combination-resize' * src/window.c (syms_of_window): Fix doc-string of 'window-combination-resize'. ; * lisp/skeleton.el (skeleton-insert): Doc fix. (Bug#80492) ; Fix esh-proc-tests on MS-Windows * test/lisp/eshell/esh-proc-tests.el (esh-proc-test/kill/process-id) (esh-proc-test/kill/process-object): Fix these tests on MS-Windows. Make c-ts-common-comment-start-skip public * lisp/progmodes/c-ts-common.el: (c-ts-common-comment-start-skip): Change to public. (c-ts-common-comment-2nd-line-anchor): (c-ts-common-comment-setup): Use it. c-ts-mode: Don't assume comment-start-skip is set This patch makes it easier to use the existing C and C++ language support in other languages. Without this patch, if the outer mode sets some specific and more accurate comment-start-skip value, or perhaps leaves it unset, indentation will break. * lisp/progmodes/c-ts-common.el (c-ts-common--comment-start-skip): Declare to the value c-ts-common-comment-setup used to set as comment-start-skip. (c-ts-common-comment-setup): Use it, rather than hardcoding. (c-ts-common-comment-2nd-line-anchor): Use it, rather than comment-start-skip. This makes it easier to reuse C/++ indentation rules in other TS modes for embedding C/++ segments in other languages. Copyright-paperwork-exempt: yes Repair another test bollixed by aggressive optimization. Repair ab ecal test by making a variable kexical, Complete the test set for floatfns,c. Tesrts for the portable primitives in fileio.c. Tests for primitives in coding.c and charset.c. Tests for primitives from the character.c module. lisp/vc/smerge-mode.el (smerge-refine-shadow-cursor): Make it thinner OTOH a thickness of 1 pixel is a bit too thin on my HiDPI displays, but 2 is too thick on non-HiDPI displays, at least with my default smallish font. I originally favored the HiDPI displays and large fonts, thinking it's a more common situation nowadays, but I changed my mind because the "too thick" problem seems actually more severe because it's occasionally bad enough that it's unclear which cursor is the real one. Tests for the lreaf.c amd print.c primitives. Tests for remaining functions iun eval.c. Completing test coverage for dataa.c orimitives. More correctness tesrs for orinitives from fns.c. More tests for edit functions, buffers, and markers. Added more buffer/marker/editing test coverage. Category/charset/coding + char-table tests. More test coverage improvements. Repair serious breakage in the batch tests. There were a bunch of tests that were breaking make check and should never be run in batch mode, because they do things like assuming there is a controlling tty or assuming we can access network services when we can't (e/g. in a CI/CD environment). I have shotgunned this problem by tagging all the failing tests with :nobatch and then changing the default and expensive selectors so make check won't barf all over its shoes. As many of these :nobatch should be individually removed as possible, after upgrading the test harness to mock the environmental stuff they need. Investigate these failures with "make check-nobatch". More test coverage improvements. Bignum corner-case tests in data-tests.el. More buffer-primitive tests in editfns-test.el Some condition-case tesrs in eval-tests.el. And another marker-primitive test in marker-tests.el. More test coverage improvements for ERT. In marker-tests.el, editfbs-tests.el, and data-tests.el. ; Fix emacs-module-tests on MS-Windows * test/src/emacs-module-resources/mod-test.c [WINDOWSNT]: Undef fprintf to prevent link error. Crrections to tedt coverrage extensuion after bootstrap build. Files: data-tests.el, editfns-tests.el. Improve test coverage of builtin predicates. New function multiple-command-partition-arguments * lisp/subr.el (command-line-max-length): New variable. (multiple-command-partition-arguments): New function. * doc/lispref/processes.texi (Shell Arguments): * etc/NEWS: Document them. * test/lisp/subr-tests.el (subr-multiple-command-partition-arguments): New test. (define-treesit-generic-mode): Improve autoloading support (bug#80480) * lisp/treesit-x.el (define-treesit-generic-mode): Mark it as `(autoload-macro expand)`. Don't autoload the `treesit-language-source-alist` setting. Generate simpler code for the common case where AUTO-MODE is a string. Tests for 2 marker primitives previously not covered. - insertion-type - last-position-after-kill Tests for 7 editor primitives previously not covered. - byte-to-position - byte-to-string - insert-byte - insert-buffer-substring - insert-before-markers-and-inherit - field-string-and-delete - constrain-to-field calendar-check-holidays: Call calendar-increment-month * lisp/calendar/holidays.el (calendar-check-holidays): Call calendar-increment-month (bug#80476). ; Revise short descriptions of EDE. Make ert more robust * lisp/emacs-lisp/ert.el (ert-run-test): Check, that `begin-marker' is still valid. The *Messages* buffer could have been deleted during test run. Fix eglot-tests on MacOS (bug#80479) * test/lisp/progmodes/eglot-tests.el (eglot--call-with-fixture): Normalise 'temporary-file-directory' to stave off problems that occur when it contains symlinks, which is common on MacOS. Speed up 'equal'-comparison of vectorlike objects * src/fns.c (internal_equal_1): Switch on the vectorlike type instead of using a sequence of type predicates. Compare circular lists in 'equal' without error (bug#80456) * src/lisp.h (FOR_EACH_TAIL_INTERNAL): Divvy up the code into... (FOR_EACH_TAIL_BASIC, FOR_EACH_TAIL_STEP_CYCLEP): ...these macros, so that they can be used in more flexible ways. * src/fns.c (internal_equal_1): Detect circular lists and call... (internal_equal_cycle): ...this function that keeps comparing but now detecting cycles in the other argument. * lisp/emacs-lisp/testcover.el (testcover-after): Remove unnecessary error handling. * test/src/fns-tests.el (test-cycle-equal): Adapt and extend. * test/lisp/emacs-lisp/testcover-resources/testcases.el (testcover-testcase-cyc1): Remove case that no longer applies. * doc/lispref/objects.texi (Equality Predicates): Update. * etc/NEWS: Announce. Fix "End" key in PuTTY and older GNU screen * lisp/term/xterm.el (xterm-alternatives-map): Map