GNU bug report logs - #16160
[PATCH] define-derived-mode clobbers syntax tables

Previous Next

Package: emacs;

Reported by: Daniel Colascione <dancol <at> dancol.org>

Date: Mon, 16 Dec 2013 11:14:02 UTC

Severity: normal

Tags: confirmed

Fixed in version 26.1

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Glenn Morris <rgm <at> gnu.org>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#16160: closed ([PATCH] define-derived-mode clobbers syntax
 tables)
Date: Tue, 13 Dec 2016 01:05:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Mon, 12 Dec 2016 20:04:52 -0500
with message-id <58eg1cbpvv.fsf <at> fencepost.gnu.org>
and subject line Re: bug#16160: [PATCH] define-derived-mode clobbers syntax tables
has caused the debbugs.gnu.org bug report #16160,
regarding [PATCH] define-derived-mode clobbers syntax tables
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
16160: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16160
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Daniel Colascione <dancol <at> dancol.org>
To: bug-emacs <bug-gnu-emacs <at> gnu.org>
Subject: [PATCH] define-derived-mode clobbers syntax tables
Date: Mon, 16 Dec 2013 03:12:43 -0800
Repro:

1) Visit shell script with comments. See comments fontified properly.
2) M-x find-library sh-script RET
3) M-x eval-buffer
4) Return to shell script buffer
5) C-x C-v RET
6) Observe that comments are no longer fontified as comments.

The define-derived-mode macro in sh-script.el emits code that clobbers 
sh-mode-syntax-table because we don't have a :syntax-table argument. I 
think the following patch changes the code to the expected behavior.

~/edev/trunk
$ bzr diff
=== modified file 'lisp/emacs-lisp/derived.el'
--- lisp/emacs-lisp/derived.el	2013-05-27 16:12:52 +0000
+++ lisp/emacs-lisp/derived.el	2013-12-16 11:09:41 +0000
@@ -206,11 +206,11 @@
        ,(if declare-syntax
 	    `(progn
 	       (unless (boundp ',syntax)
-		 (put ',syntax 'definition-name ',child))
-	       (defvar ,syntax (make-syntax-table))
-	       (unless (get ',syntax 'variable-documentation)
-		 (put ',syntax 'variable-documentation
-		      (purecopy ,(format "Syntax table for `%s'." child))))))
+		 (put ',syntax 'definition-name ',child)
+                 (defvar ,syntax (make-syntax-table))
+                 (unless (get ',syntax 'variable-documentation)
+                   (put ',syntax 'variable-documentation
+                        (purecopy ,(format "Syntax table for `%s'." 
child)))))))
        ,(if declare-abbrev
 	    `(progn
 	       (put ',abbrev 'definition-name ',child)


That is, we shouldn't touch the syntax table variable at all unless the 
variable is unbound.


[Message part 3 (message/rfc822, inline)]
From: Glenn Morris <rgm <at> gnu.org>
To: 16160-done <at> debbugs.gnu.org
Subject: Re: bug#16160: [PATCH] define-derived-mode clobbers syntax tables
Date: Mon, 12 Dec 2016 20:04:52 -0500
Version: 26.1

>> The repro steps are incorrect. Try these:
>>
>> 1) emacs -Q
>> 2) visit a shell script
>> 3) M-x find-library sh-script RET
>> 4) C-s define-derived-mode RET
>> 5) C-M-x
>> 6) switch to your shell script buffer
>> 7) C-x C-v
>> 8) Observe that the shell script is fontified incorrectly; the syntax
>> table is now clobbered.

Fixed in 8db7b65 along the suggested lines.

So AIUI the issue is that define-derived-mode expands to 

(defvar ,syntax (make-syntax-table))

Normally this has no effect if ,syntax is already bound.
But M-x eval-defun resets defvars to their default settings...
Hence if you selectively re-evaluate only the mode definition from
sh-script.el, you get the reported problem.

So I changed it to explicitly check if ,syntax is bound.

This will however now make things go wrong in the opposite way for
someone who has been playing around with customizing a syntax table that
was actually defined by define-derived-mode and wants to reset it by
re-evaluating the derived mode definition. But AFAICS there's no way to
fix both scenarios, and the second seems less likely (?) to me than the
one reported here.


This bug report was last modified 8 years and 166 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.