From 0e01d5aa723cd50749f9028f0e8ad85a3afe52aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C5=A0t=C4=9Bp=C3=A1n=20N=C4=9Bmec?= Date: Sun, 12 Apr 2020 00:27:51 +0200 Subject: [PATCH] Preserve setf semantics in 'substring', 'cons', 'logand' expanders * doc/lispref/variables.texi (Adding Generalized Variables): Fix example. * lisp/emacs-lisp/cl-lib.el (substring) * lisp/emacs-lisp/gv.el (cons, logand): Return the value being assigned, as specified for 'setf'. (bug#35546) --- doc/lispref/variables.texi | 7 +++++-- lisp/emacs-lisp/cl-lib.el | 7 +++++-- lisp/emacs-lisp/gv.el | 18 ++++++++++++------ 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi index abcd4bbd0f7..94c8c88796f 100644 --- a/doc/lispref/variables.texi +++ b/doc/lispref/variables.texi @@ -2585,8 +2585,11 @@ implemented this way: (macroexp-let2* nil ((start from) (end to)) (funcall do `(substring ,getter ,start ,end) (lambda (v) - (funcall setter `(cl--set-substring - ,getter ,start ,end ,v)))))))) + (macroexp-let2 nil v v + `(progn + ,(funcall setter `(cl--set-substring + ,getter ,start ,end ,v)) + ,v)))))))) @end example @end defmac diff --git a/lisp/emacs-lisp/cl-lib.el b/lisp/emacs-lisp/cl-lib.el index 7a26d9a90fd..7a4d3c9c3e3 100644 --- a/lisp/emacs-lisp/cl-lib.el +++ b/lisp/emacs-lisp/cl-lib.el @@ -619,8 +619,11 @@ If ALIST is non-nil, the new pairs are prepended to it." (macroexp-let2* nil ((start from) (end to)) (funcall do `(substring ,getter ,start ,end) (lambda (v) - (funcall setter `(cl--set-substring - ,getter ,start ,end ,v)))))))) + (macroexp-let2 nil v v + `(progn + ,(funcall setter `(cl--set-substring + ,getter ,start ,end ,v)) + ,v)))))))) ;;; Miscellaneous. diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index 513bd328899..78d86b9fc31 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el @@ -527,9 +527,12 @@ This macro only makes sense when used in a place." (gv-letplace (dgetter dsetter) d (funcall do `(cons ,agetter ,dgetter) - (lambda (v) `(progn - ,(funcall asetter `(car ,v)) - ,(funcall dsetter `(cdr ,v))))))))) + (lambda (v) + (macroexp-let2 nil v v + `(progn + ,(funcall asetter `(car ,v)) + ,(funcall dsetter `(cdr ,v)) + ,v)))))))) (put 'logand 'gv-expander (lambda (do place &rest masks) @@ -539,9 +542,12 @@ This macro only makes sense when used in a place." (funcall do `(logand ,getter ,mask) (lambda (v) - (funcall setter - `(logior (logand ,v ,mask) - (logand ,getter (lognot ,mask)))))))))) + (macroexp-let2 nil v v + `(progn + ,(funcall setter + `(logior (logand ,v ,mask) + (logand ,getter (lognot ,mask)))) + ,v)))))))) ;;; References -- 2.39.2