This patch applies the syntax table from each source-block's major-mode to the source-block itself. This makes it easier to work with source blocks without editing them in a new buffer:
- s-expression and symbol navigation/selection work as expected. - "<" is not treated as a parentheses within source blocks unless appropriate for the source block's mode, etc. - "C-h f" suggests the correct function at point, even when quoted. >From my testing, this seems to work as expected but I'm happy to put this behind a config variable if there are concerns about it changing default behavior.
>From b24e87beca8701e7edf4e37cf22a5edc7b114c4b Mon Sep 17 00:00:00 2001 From: Steven Allen <[email protected]> Date: Fri, 7 Nov 2025 11:31:39 -0800 Subject: [PATCH] Apply the mode's syntax table when fontifying natively This makes it easier to work with source blocks without editing them in a new buffer: s-expression and symbol navigation/selection work as expected, < is not treated as a parentheses within source blocks unless appropriate for the source block's mode, etc. * lisp/org-src.el (org-src-font-lock-fontify-block): Apply the syntax-table from the source-blocks' mode to the source block text. * lisp/org.el (org-mode): Obey the syntax table text property in commands. This ensures that, e.g., "C-h f" correctly suggests the symbol at point and doesn't, e.g., include any quotes, etc. --- lisp/org-src.el | 1 + lisp/org.el | 3 +++ 2 files changed, 4 insertions(+) diff --git a/lisp/org-src.el b/lisp/org-src.el index 971d6e938..5ad5c2be1 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -737,6 +737,7 @@ defun org-src-font-lock-fontify-block 'org-src-invisible new-prop org-buffer))))))) (setq pos next))) + (put-text-property start end 'syntax-table (syntax-table) org-buffer) (set-buffer-modified-p nil))) (error (message "Native code fontification error in %S at pos%d\n Error: %S" diff --git a/lisp/org.el b/lisp/org.el index ed012d2e6..524741af6 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -5178,6 +5178,9 @@ define-derived-mode org-mode (org-setup-filling) ;; Comments. (org-setup-comments-handling) + ;; Obey the syntax-table text property when navigating text (used in + ;; source blocks). + (setq-local parse-sexp-lookup-properties t) ;; Beginning/end of defun (setq-local beginning-of-defun-function 'org-backward-element) (setq-local end-of-defun-function -- 2.51.2
