Subject: Re: bug#39134: 28.0.50; forward-sexp fails on curved singlequotes

From: "Michalis V." <[email-masked]>
Date: Tue, 17 Aug 2021 12:58:46 +0300

Andreas Röhler <[email-masked]> writes:

> Andreas Röhler <[email-masked]> writes:
>
> Hi Michalis,
>
> don't have any idea WRT importance of this.
>
> Just thought it may work  - modifying the help-mode syntax-table should do it.
>
> Best,
>
> Andreas

hi Andreas,

Looking at the help-mode.el it wasn't very clear to me how the help-mode
syntax-table variable was actually created - there wasn't any defvar
defined but rather the syntax-table was applied inside two
defuns. Despite that "C-h v help-mode-syntax-table" would redirect 
to this line in help-mode.el

(define-derived-mode help-mode special-mode "Help"

for some cryptic reason. Anyway attached is a patch that introduces
properly the help-mode-syntax-table var which derives from the elisp one
and sets ‘’ as parens. Now forward-sexp jumps over the definitions in
the *Help* buffer as it should despite any punctuation they may contain. 

cheers,
Michalis

diff --git a/lisp/help-mode.el b/lisp/help-mode.el
index 2f82d83ceb..6280fad1c1 100644
--- a/lisp/help-mode.el
+++ b/lisp/help-mode.el
@@ -111,6 +111,15 @@ help-xref-stack-forward-item
 (setq-default help-xref-stack nil help-xref-stack-item nil)
 (setq-default help-xref-forward-stack nil help-xref-forward-stack-item nil)
 
+(defvar help-mode-syntax-table
+  (let ((table (make-syntax-table emacs-lisp-mode-syntax-table)))
+    ;; treat single quotes as parens so that forward-sexp does not
+    ;; break when quoted string contains punctuation
+    (modify-syntax-entry ?‘ "(’  " table)
+    (modify-syntax-entry ?’ ")‘  " table)
+    table)
+  "Syntax table used in `help-mode'.")
+
 (defcustom help-mode-hook nil
   "Hook run by `help-mode'."
   :type 'hook
@@ -490,7 +499,7 @@ help-make-xrefs
         (let ((stab (syntax-table))
               (case-fold-search t)
               (inhibit-read-only t))
-          (set-syntax-table emacs-lisp-mode-syntax-table)
+          (set-syntax-table help-mode-syntax-table)
           ;; The following should probably be abstracted out.
           (unwind-protect
               (progn
@@ -643,7 +652,7 @@ help-insert-xref-button
 (defun help-xref-on-pp (from to)
   "Add xrefs for symbols in `pp's output between FROM and TO."
   (if (> (- to from) 5000) nil
-    (with-syntax-table emacs-lisp-mode-syntax-table
+    (with-syntax-table help-mode-syntax-table
       (save-excursion
 	(save-restriction
 	  (narrow-to-region from to)