make-local-variable scrambles default value [lookup-syntax-properties garbled]

Ilya N. Golubev gin
Wed Oct 25 01:50:52 EDT 2006


xemacs branch: 21.4.

The code below does use `save-excursion' within `let' as adviced in
<(elisp) Intro to Buffer-Local>.  Still the assignment that one
expects to be temporary permanently breaks default
`parse-sexp-lookup-properties' value, and in a way that is hard to
detect.  It does not manifest right after the assignment, only after
`make-local-variable' is called.  That is, the following code

;; sdv.el
;; visit `0.sh' in `sh-mode'
(set-buffer (get-buffer-create "0.sh"))
(set (make-local-variable 'parse-sexp-lookup-properties) t)
(print (default-value 'parse-sexp-lookup-properties))
;; visit `0.c' in `c-mode'
(set-buffer (get-buffer-create "0.c"))
(print parse-sexp-lookup-properties)
;; evaluate initial `c-emacs-features' value in `cc-defs.el'
(let ((buf (generate-new-buffer " test"))
      parse-sexp-lookup-properties)
  (save-excursion
    (set-buffer buf)
    (setq parse-sexp-lookup-properties t))
  (kill-buffer buf))
(print parse-sexp-lookup-properties)
(print (default-value 'parse-sexp-lookup-properties))
(make-local-variable 'parse-sexp-lookup-properties)
(print parse-sexp-lookup-properties)
(print (default-value 'parse-sexp-lookup-properties))

when evaluated like this

xemacs -batch -q -l sdv.el

prints:

nil

nil

nil

nil

t

t

Emacs 21.4a invoked the same way prints exactly what one expects.

nil

nil

nil

nil

nil

nil

The call sequence is by no means artificial.  It actually occurs in
interactive session like this.

. Visit file in `sh-mode'.

. Visit other file in `cc-mode'.

. . Load `cc-mode' code, which also loads `cc-defs' with its
`c-emacs-features' initial value evaluation.

. The `parse-sexp-lookup-properties' / `lookup-syntax-properties'
default value is now incorrectly set to `t', which triggers other bug
of `update_syntax_cache' <- `string-match'.  (Will post
`update_syntax_cache' patch on request.)

The elisp primitive is fairly generic, so the bug affects potentially
unlimited number of packages.  In particular, `gnus' depends on
`lookup-syntax-properties' to be `nil' for `string-match' <-
`gnus-extract-address-components' to work around this bug.  This call
sequence occurs inside `gnus-group-select-group' interactive command.

Not every `cc-mode' version works this way, but one that does is
current in xemacs packages cvs.  Will post patch for it on request.

And this patch would be unnecessary for emacs - or if xemacs behaved
the same way as emacs wrt `parse-sexp-lookup-properties'.


The `update_syntax_cache' bug was introduced in 21.4 branch (in
`syntax.c' revision 1.7.2.18 of 2001/02/09 16:00:37 +0).  So 21.5 is
not affected by it, even though in it initial value of
`parse-sexp-lookup-properties' / `lookup-syntax-properties' is `t'.
However, when `t' values in the code abover reversed to `nil', the
code above still shows the same undesired and unexpected change of
default value.



More information about the XEmacs-Beta mailing list