GNU bug report logs - #63818
27.1; unbound local variables break python-util-clone-local-variables

Previous Next

Package: emacs;

Reported by: Ernesto Alfonso <erjoalgo <at> gmail.com>

Date: Wed, 31 May 2023 21:48:02 UTC

Severity: normal

Found in version 27.1

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: kobarity <kobarity <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Ernesto Alfonso <erjoalgo <at> gmail.com>, Stefan Monnier <monnier <at> iro.umontreal.ca>, 63818 <at> debbugs.gnu.org
Subject: bug#63818: 27.1; unbound local variables break python-util-clone-local-variables
Date: Thu, 01 Jun 2023 23:36:24 +0900
Eli Zaretskii wrote:
> > From: Ernesto Alfonso <erjoalgo <at> gmail.com>
> > Date: Wed, 31 May 2023 17:47:16 -0400
> >   SCRIPT=$(cat <<EOF
> >   (progn
> >     (require 'python)
> >     (defvar-local my-local-var 0)
> >     (makunbound 'my-local-var)
> >     (python-util-clone-local-variables (current-buffer)))
> >   EOF
> >   )
> >   emacs -Q --eval "${SCRIPT}"
> >   
> > 
> > Suggested patch to '#python-util-clone-local-variables in python.el
> > 
> > 
> > 5205c5205,5206
> > <      (and (symbolp (car pair))
> > ---
> > >      (and (listp pair)
> > >           (symbolp (car pair))
> > 
> 
> Stefan and kobarity, any comments?

I'm not familiar with this area, but I looked at the Orgmode code.  It
was changed to use pcase.

(defun org-clone-local-variables (from-buffer &optional regexp)
  "Clone local variables from FROM-BUFFER.
Optional argument REGEXP selects variables to clone."
  (dolist (pair (buffer-local-variables from-buffer))
    (pcase pair
      (`(,name . ,value)		;ignore unbound variables
       (when (and (not (memq name org-unique-local-variables))
		  (or (null regexp) (string-match-p regexp (symbol-name name))))
	 (ignore-errors (set (make-local-variable name) value)))))))

This change seems to be based on the following discussion.

https://lists.gnu.org/archive/html/emacs-orgmode/2017-06/msg00037.html

Maybe we can adopt the same approach?




This bug report was last modified 2 years and 48 days ago.

Previous Next


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