From: Philipp Stephani <p.stephani2@gmail.com>
To: 26624@debbugs.gnu.org
Subject: bug#26624: 26.0.50; Generalized variable `buffer-local-value' does't restore local flag
Date: Sat, 17 Jun 2017 13:10:20 +0000 [thread overview]
Message-ID: <CAArVCkSFpW3Sc80XKHuxC7akHPUs14+GX0A3L+eJF7vhfw7zEA@mail.gmail.com> (raw)
In-Reply-To: <m28tmrxd17.fsf@p>
[-- Attachment #1.1: Type: text/plain, Size: 1181 bytes --]
Philipp Stephani <p.stephani2@gmail.com> schrieb am So., 23. Apr. 2017 um
19:14 Uhr:
>
> In *scratch*, evaluate:
>
> (defvar foo-test-var nil)
> (with-temp-buffer
> (list (list (buffer-local-value 'foo-test-var (current-buffer))
> (local-variable-p 'foo-test-var)
> (local-variable-if-set-p 'foo-test-var))
> (cl-letf (((buffer-local-value 'foo-test-var (current-buffer))
> 123))
> (list (buffer-local-value 'foo-test-var (current-buffer))
> (local-variable-p 'foo-test-var)
> (local-variable-if-set-p 'foo-test-var)))
> (list (buffer-local-value 'foo-test-var (current-buffer))
> (local-variable-p 'foo-test-var)
> (local-variable-if-set-p 'foo-test-var))))
>
> The result is:
>
> ((nil nil nil) (123 t t) (nil t t))
>
> But expected is:
>
> ((nil nil nil) (123 t t) (nil nil nil))
>
> i.e. the local flag of the variable should be reset.
>
>
It's possible to fix this (see attached patch), but at the expense of
breaking other valid use cases such as (cl-incf (buffer-local-value ...)).
Not sure whether the bug can be fixed at all without breaking other stuff.
[-- Attachment #1.2: Type: text/html, Size: 1642 bytes --]
[-- Attachment #2: 0001-Have-cl-letf-restore-buffer-local-status-Bug-26624.txt --]
[-- Type: text/plain, Size: 3996 bytes --]
From 3789b7b843ec417ae3be5d0f24409559a46bcc93 Mon Sep 17 00:00:00 2001
From: Philipp Stephani <phst@google.com>
Date: Fri, 16 Jun 2017 22:55:52 +0200
Subject: [PATCH 1/2] Have `cl-letf' restore buffer-local status (Bug#26624)
* lisp/emacs-lisp/gv.el (buffer-local-value): Record and restore
whether the variable was buffer-local; used for `cl-letf'.
* test/lisp/emacs-lisp/gv-tests.el (gv-tests--bug26624): Add unit
test.
---
lisp/emacs-lisp/gv.el | 15 +++++++++---
test/lisp/emacs-lisp/gv-tests.el | 51 ++++++++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+), 3 deletions(-)
create mode 100644 test/lisp/emacs-lisp/gv-tests.el
diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el
index c5c12a6414..a614d675af 100644
--- a/lisp/emacs-lisp/gv.el
+++ b/lisp/emacs-lisp/gv.el
@@ -372,9 +372,18 @@ setf
(gv-define-setter window-point (v &optional w) `(set-window-point ,w ,v))
(gv-define-setter window-start (v &optional w) `(set-window-start ,w ,v))
-(gv-define-setter buffer-local-value (val var buf)
- (macroexp-let2 nil v val
- `(with-current-buffer ,buf (set (make-local-variable ,var) ,v))))
+(gv-define-expander buffer-local-value
+ (lambda (do var buf)
+ (macroexp-let2* nil ((var var) (buf buf))
+ (funcall do
+ `(if (local-variable-p ,var ,buf)
+ (buffer-local-value ,var ,buf)
+ #1='#:unbound)
+ (lambda (val)
+ `(with-current-buffer ,buf
+ (if (eq ,val #1#)
+ (kill-local-variable ,var)
+ (set (make-local-variable ,var) ,val))))))))
(gv-define-expander alist-get
(lambda (do key alist &optional default remove)
diff --git a/test/lisp/emacs-lisp/gv-tests.el b/test/lisp/emacs-lisp/gv-tests.el
new file mode 100644
index 0000000000..b49c12ddf2
--- /dev/null
+++ b/test/lisp/emacs-lisp/gv-tests.el
@@ -0,0 +1,51 @@
+;;; gv-tests.el --- unit tests for gv.el -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for lisp/emacs-lisp/gv.el.
+
+;;; Code:
+
+(defvar gv-tests--var 'default "Test variable.")
+
+(ert-deftest gv-tests--bug26624 ()
+ "Checks that Bug#26624 is fixed."
+ (with-temp-buffer
+ (let ((var-calls 0) (buf-calls 0))
+ (should (equal (buffer-local-value 'gv-tests--var (current-buffer))
+ 'default))
+ (should-not (local-variable-p 'gv-tests--var))
+ (should-not (local-variable-if-set-p 'gv-tests--var))
+ (cl-letf (((buffer-local-value
+ (progn (cl-incf var-calls) 'gv-tests--var)
+ (progn (cl-incf buf-calls) (current-buffer)))
+ 'unbound))
+ (should (equal (buffer-local-value 'gv-tests--var (current-buffer))
+ 'unbound))
+ (should (local-variable-p 'gv-tests--var))
+ (should (local-variable-if-set-p 'gv-tests--var)))
+ (should (equal (buffer-local-value 'gv-tests--var (current-buffer))
+ 'default))
+ (should-not (local-variable-p 'gv-tests--var))
+ (should-not (local-variable-if-set-p 'gv-tests--var))
+ (should (equal var-calls 1))
+ (should (equal buf-calls 1)))))
+
+;;; gv-tests.el ends here
--
2.13.1
next prev parent reply other threads:[~2017-06-17 13:10 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-23 17:13 bug#26624: 26.0.50; Generalized variable `buffer-local-value' does't restore local flag Philipp Stephani
2017-06-17 13:10 ` Philipp Stephani [this message]
2017-06-17 18:48 ` npostavs
2017-06-18 4:17 ` Michael Heerdegen
2017-07-02 16:53 ` Philipp Stephani
2017-09-24 15:19 ` Philipp Stephani
2017-09-24 15:36 ` Michael Heerdegen
2017-09-24 15:44 ` Noam Postavsky
2017-09-24 16:42 ` Philipp Stephani
2017-09-24 17:43 ` Noam Postavsky
2017-09-29 7:50 ` Eli Zaretskii
2017-09-29 20:55 ` Philipp Stephani
2017-09-30 6:46 ` Eli Zaretskii
2017-12-26 22:19 ` Michael Heerdegen
2017-12-27 16:10 ` Eli Zaretskii
2017-12-27 19:54 ` Michael Heerdegen
2017-12-27 20:27 ` Eli Zaretskii
2017-12-29 14:08 ` Michael Heerdegen
2017-12-29 16:14 ` Eli Zaretskii
2017-12-29 16:20 ` Philipp Stephani
2022-08-21 21:38 ` Lars Ingebrigtsen
2022-08-21 22:21 ` Lars Ingebrigtsen
2022-08-22 6:53 ` Michael Heerdegen
2022-08-22 10:10 ` Lars Ingebrigtsen
2022-08-22 21:43 ` Michael Heerdegen
2022-08-23 10:28 ` Lars Ingebrigtsen
2018-01-24 14:33 ` Michael Heerdegen
2018-02-04 19:01 ` Philipp Stephani
2018-02-04 21:02 ` Michael Heerdegen
2018-02-11 17:54 ` Philipp Stephani
2018-02-11 20:56 ` Michael Heerdegen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAArVCkSFpW3Sc80XKHuxC7akHPUs14+GX0A3L+eJF7vhfw7zEA@mail.gmail.com \
--to=p.stephani2@gmail.com \
--cc=26624@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).