From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Anders Lindgren Newsgroups: gmane.emacs.bugs Subject: bug#16576: Binding `standard-output' to a function doesn't work -- function sometimes called with garbage Date: Tue, 28 Jan 2014 20:39:57 +0100 Message-ID: References: <83ob2w85d3.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c30a043b368204f10cfd75 X-Trace: ger.gmane.org 1390938073 23558 80.91.229.3 (28 Jan 2014 19:41:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 28 Jan 2014 19:41:13 +0000 (UTC) Cc: 16576@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jan 28 20:41:19 2014 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1W8EX8-0001Bo-7d for geb-bug-gnu-emacs@m.gmane.org; Tue, 28 Jan 2014 20:41:18 +0100 Original-Received: from localhost ([::1]:39159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8EX7-0005yJ-9j for geb-bug-gnu-emacs@m.gmane.org; Tue, 28 Jan 2014 14:41:17 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47898) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8EWy-0005y6-Qd for bug-gnu-emacs@gnu.org; Tue, 28 Jan 2014 14:41:13 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W8EWt-0007HC-6b for bug-gnu-emacs@gnu.org; Tue, 28 Jan 2014 14:41:08 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:53782) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W8EWt-0007H8-2R for bug-gnu-emacs@gnu.org; Tue, 28 Jan 2014 14:41:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1W8EWs-0001yR-DN for bug-gnu-emacs@gnu.org; Tue, 28 Jan 2014 14:41:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Anders Lindgren Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 28 Jan 2014 19:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 16576 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 16576-submit@debbugs.gnu.org id=B16576.13909380107523 (code B ref 16576); Tue, 28 Jan 2014 19:41:02 +0000 Original-Received: (at 16576) by debbugs.gnu.org; 28 Jan 2014 19:40:10 +0000 Original-Received: from localhost ([127.0.0.1]:39568 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W8EW0-0001xG-LH for submit@debbugs.gnu.org; Tue, 28 Jan 2014 14:40:09 -0500 Original-Received: from mail-oa0-f42.google.com ([209.85.219.42]:46971) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1W8EVs-0001we-Vr for 16576@debbugs.gnu.org; Tue, 28 Jan 2014 14:40:02 -0500 Original-Received: by mail-oa0-f42.google.com with SMTP id i7so954161oag.15 for <16576@debbugs.gnu.org>; Tue, 28 Jan 2014 11:39:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=kz9BnItxi6xb8cdHZ0AH6k6sAvMBenRMz5FwMnSz8LY=; b=duBLgpB7iosGIvN28J05hOBl2gY+u+bj+UoT72j+Vbrpsqlm+coLB08CjFDi0++ku0 VjFaJYnJ7/aLb5gsKJInJe2B+tg/h4s9vfWVmdZJjxolPC4om8AV7EqJg+9r6Efxk4k/ d1viULcaDa0z97Q0A0PhZgizNLfFKKrlv/ZqUFXc9gh8UVVVYx4wqMwC2SrQ/azq75sq b7X0Q394ik1IHMk5zw6+NOezdqZ72FYCGXCvUxZXPKaT33l7TfFAFmes/m4XogFZl71z iLDuloFOV5BKI+AU0rv2e/C5u/gEeChlw5S7a/M3q5UTV92hS7em7BgfRQEBepDKE7AJ suxQ== X-Received: by 10.60.44.42 with SMTP id b10mr1199534oem.70.1390937997258; Tue, 28 Jan 2014 11:39:57 -0800 (PST) Original-Received: by 10.182.114.199 with HTTP; Tue, 28 Jan 2014 11:39:57 -0800 (PST) In-Reply-To: <83ob2w85d3.fsf@gnu.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:84187 Archived-At: --001a11c30a043b368204f10cfd75 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi! I got the same result with your version. After running it 24 times, I got the following output (on Emacs 22) -- please note the extra text and control characters towards the end of the string (which I have changed to the \xNN syntax, in order not to confuse the mail program). "\"(\\\\(co\\\\(?:mbine-after-change-calls\\\\|nd\\\\(?:ition-case\\\\(?:-u= nless-debug\\\\)?\\\\)?\\\\)\\\\|eval-\\\\(?:a\\\\(?:fter-load\\\\|nd-compi= le\\\\)\\\\|next-after-load\\\\|when\\\\(?:-compile\\\\)?\\\\)\\\\\\\\|p\\\= \(?:case\\\\(?:-let\\\\*?\\\\)?\\\\|rog[*12nv]?\\\\)\\\\|save-\\\\(?:curren= t-buffer\\\\|excursion\\\\|match-data\\\\|restriction\\\\|selected-window\\= \\|window-excursion\\\\)\\\\|track-mouse\\\\|unwind-protect\\\\|w\\\\(?:hil= e\\\\(?:-no-input\\\\)?\\\\|ith-\\\\(?:c\\\\(?:a\\\\(?:\\\\(?:se\\\\|tegory= \\\\)-table\\\\)\\\\|urrent-buffer\\\\)\\\\|demoted-errors\\\\|electric-hel= p\\\\|local-quit\\\\|no-warnings\\\\|output-to-\\\\(?:string\\\\|temp-buffe= r\\\\)\\\\|s\\\\(?:elected-\\\\(?:frame\\\\|window\\\\)\\\\|ilent-modificat= ions\\\\|yntax-table\\\\)\\\\|t\\\\(?:emp-\\\\(?:buffer\\\\|\\\\(?:fil\\\\|= messag\\\\)e\\\\)\\\\|imeout\\\\(?:-handler\\\\)?\\\\)\\\\|wrapper-hook\\\\= )\\\\)\\\\)\\\\>\x00cs/ \xdc\xac=06\\\"(\\\\\\\\(co\\\\\\\\(?:mbine-after-change-calls\\\\\\\\|n\"" When it comes to the original program, I believe that it's correct. The function bound to `standard-output' is called from within `prin1', which is called from inside the scope of `let'. Hence, it will work on the local version of the variable. (If it wouldn't have been correct -- why would it return the correct value *most* of the time?) -- Anders On Tue, Jan 28, 2014 at 4:59 PM, Eli Zaretskii wrote: > > Date: Tue, 28 Jan 2014 10:09:08 +0100 > > From: Anders Lindgren > > > > emacs -Q > > Eval the following: > > > > (defvar bug-bind-output-str nil) > > > > (defun bug-bind-output-function (char) > > (setq bug-bind-output-str > > (concat bug-bind-output-str (list char)))) > > > > (defun bug-bind-output-test () > > (interactive) > > (let ((bug-bind-output-str "") > > (standard-output 'bug-bind-output-function) > > (s > > > "(\\(co\\(?:mbine-after-change-calls\\|nd\\(?:ition-case\\(?:-unless-debu= g\\)?\\)?\\)\\|eval-\\(?:a\\(?:fter-load\\|nd-compile\\)\\|next-after-load\= \|when\\(?:-compile\\)?\\)\\|i\\(?:f\\|nline\\)\\|l\\(?:ambda\\|et\\(?:\\*\= \|rec\\)?\\)\\|p\\(?:case\\(?:-let\\*?\\)?\\|rog[*12nv]?\\)\\|save-\\(?:cur= rent-buffer\\|excursion\\|match-data\\|restriction\\|selected-window\\|wind= ow-excursion\\)\\|track-mouse\\|unwind-protect\\|w\\(?:hile\\(?:-no-input\\= )?\\|ith-\\(?:c\\(?:a\\(?:\\(?:se\\|tegory\\)-table\\)\\|urrent-buffer\\)\\= |demoted-errors\\|electric-help\\|local-quit\\|no-warnings\\|output-to-\\(?= :string\\|temp-buffer\\)\\|s\\(?:elected-\\(?:frame\\|window\\)\\|ilent-mod= ifications\\|yntax-table\\)\\|t\\(?:emp-\\(?:buffer\\|\\(?:fil\\|messag\\)e= \\)\\|imeout\\(?:-handler\\)?\\)\\|wrapper-hook\\)\\)\\)\\>") > > s0) > > (prin1 s) > > bug-bind-output-str)) > > > > Type this a number of times: > > > > M-x (bug-bind-output-test) RET > > I think there's a bug in your test program. You let-bind > bug-bind-output-str, and print that local binding after you call > prin1. But your print function concatenates each character onto the > _global_ binding of bug-bind-output-str, so the result is not in your > local binding, it's in the global one. > > If you change your program like this: > > (defun bug-bind-output-test () > (interactive) > (setq bug-bind-output-str "") > (let ((standard-output 'bug-bind-output-function) > (s > > "(\\(co\\(?:mbine-after-change-calls\\|nd\\(?:ition-case\\(?:-unless-debu= g\\)?\\)?\\)\\|eval-\\(?:a\\(?:fter-load\\|nd-compile\\)\\|next-after-load\= \|when\\(?:-compile\\)?\\)\\|i\\(?:f\\|nline\\)\\|l\\(?:ambda\\|et\\(?:\\*\= \|rec\\)?\\)\\|p\\(?:case\\(?:-let\\*?\\)?\\|rog[*12nv]?\\)\\|save-\\(?:cur= rent-buffer\\|excursion\\|match-data\\|restriction\\|selected-window\\|wind= ow-excursion\\)\\|track-mouse\\|unwind-protect\\|w\\(?:hile\\(?:-no-input\\= )?\\|ith-\\(?:c\\(?:a\\(?:\\(?:se\\|tegory\\)-table\\)\\|urrent-buffer\\)\\= |demoted-errors\\|electric-help\\|local-quit\\|no-warnings\\|output-to-\\(?= :string\\|temp-buffer\\)\\|s\\(?:elected-\\(?:frame\\|window\\)\\|ilent-mod= ifications\\|yntax-table\\)\\|t\\(?:emp-\\(?:buffer\\|\\(?:fil\\|messag\\)e= \\)\\|imeout\\(?:-handler\\)?\\)\\|wrapper-hook\\)\\)\\)\\>") > s0) > (prin1 s) > bug-bind-output-str)) > > i.e., work with the global binding, then the program works as > expected, AFAICS. > --001a11c30a043b368204f10cfd75 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi!

I got the same result with your ver= sion. After running it 24 times, I got the following output (on Emacs 22) -= - please note the extra text and control characters towards the end of the = string (which I have changed to the \xNN syntax, in order not to confuse th= e mail program).

"\"(\\\\(co\\\\(?:mbine-after-change-calls\\\= \|nd\\\\(?:ition-case\\\\(?:-unless-debug\\\\)?\\\\)?\\\\)\\\\|eval-\\\\(?:= a\\\\(?:fter-load\\\\|nd-compile\\\\)\\\\|next-after-load\\\\|when\\\\(?:-c= ompile\\\\)?\\\\)\\\\\\\\|p\\\\(?:case\\\\(?:-let\\\\*?\\\\)?\\\\|rog[*12nv= ]?\\\\)\\\\|save-\\\\(?:current-buffer\\\\|excursion\\\\|match-data\\\\|res= triction\\\\|selected-window\\\\|window-excursion\\\\)\\\\|track-mouse\\\\|= unwind-protect\\\\|w\\\\(?:hile\\\\(?:-no-input\\\\)?\\\\|ith-\\\\(?:c\\\\(= ?:a\\\\(?:\\\\(?:se\\\\|tegory\\\\)-table\\\\)\\\\|urrent-buffer\\\\)\\\\|d= emoted-errors\\\\|electric-help\\\\|local-quit\\\\|no-warnings\\\\|output-t= o-\\\\(?:string\\\\|temp-buffer\\\\)\\\\|s\\\\(?:elected-\\\\(?:frame\\\\|w= indow\\\\)\\\\|ilent-modifications\\\\|yntax-table\\\\)\\\\|t\\\\(?:emp-\\\= \(?:buffer\\\\|\\\\(?:fil\\\\|messag\\\\)e\\\\)\\\\|imeout\\\\(?:-handler\\= \\)?\\\\)\\\\|wrapper-hook\\\\)\\\\)\\\\)\\\\>\x00cs/ \xdc\xac=06\\\&quo= t;(\\\\\\\\(co\\\\\\\\(?:mbine-after-change-calls\\\\\\\\|n\""

When it comes to the original program, I believe = that it's correct. The function bound to `standard-output' is calle= d from within `prin1', which is called from inside the scope of `let= 9;. Hence, it will work on the local version of the variable. (If it wouldn= 't have been correct -- why would it return the correct value *most* of= the time?)

=A0 =A0 -- Anders


On Tue, Jan 28, 2014 at 4:59 PM, Eli Za= retskii <eliz@gnu.org> wrote:
> Date: Tue, 28 Jan 2014 10:09:08 +0100 > From: Anders Lindgren <andlind= @gmail.com>
>
> =A0 =A0 emacs -Q
> =A0 =A0 Eval the following:
>
> (defvar bug-bind-output-str nil)
>
> (defun bug-bind-output-function (char)
> =A0 (setq bug-bind-output-str
> =A0 =A0 =A0 =A0 (concat bug-bind-output-str (list char))))
>
> (defun bug-bind-output-test ()
> =A0 (interactive)
> =A0 (let ((bug-bind-output-str "")
> =A0 =A0 =A0 =A0 (standard-output 'bug-bind-output-function)
> =A0 =A0 =A0 =A0 (s
> "(\\(co\\(?:mbine-after-change-calls\\|nd\\(?:ition-case\\(?:-unl= ess-debug\\)?\\)?\\)\\|eval-\\(?:a\\(?:fter-load\\|nd-compile\\)\\|next-aft= er-load\\|when\\(?:-compile\\)?\\)\\|i\\(?:f\\|nline\\)\\|l\\(?:ambda\\|et\= \(?:\\*\\|rec\\)?\\)\\|p\\(?:case\\(?:-let\\*?\\)?\\|rog[*12nv]?\\)\\|save-= \\(?:current-buffer\\|excursion\\|match-data\\|restriction\\|selected-windo= w\\|window-excursion\\)\\|track-mouse\\|unwind-protect\\|w\\(?:hile\\(?:-no= -input\\)?\\|ith-\\(?:c\\(?:a\\(?:\\(?:se\\|tegory\\)-table\\)\\|urrent-buf= fer\\)\\|demoted-errors\\|electric-help\\|local-quit\\|no-warnings\\|output= -to-\\(?:string\\|temp-buffer\\)\\|s\\(?:elected-\\(?:frame\\|window\\)\\|i= lent-modifications\\|yntax-table\\)\\|t\\(?:emp-\\(?:buffer\\|\\(?:fil\\|me= ssag\\)e\\)\\|imeout\\(?:-handler\\)?\\)\\|wrapper-hook\\)\\)\\)\\>"= ;)
> =A0 =A0 =A0 =A0 s0)
> =A0 =A0 (prin1 s)
> =A0 =A0 bug-bind-output-str))
>
> Type this a number of times:
>
> =A0 =A0 M-x (bug-bind-output-test) RET

I think there's a bug in your test program. =A0You let-bind
bug-bind-output-str, and print that local binding after you call
prin1. =A0But your print function concatenates each character onto the
_global_ binding of bug-bind-output-str, so the result is not in your
local binding, it's in the global one.

If you change your program like this:

=A0 (defun bug-bind-output-test ()
=A0 =A0 (interactive)
=A0 =A0 (setq bug-bind-output-str "")
=A0 =A0 (let ((standard-output 'bug-bind-output-function)
=A0 =A0 =A0 =A0 =A0 (s
=A0 "(\\(co\\(?:mbine-after-change-calls\\|nd\\(?:ition-case\\(?:-unle= ss-debug\\)?\\)?\\)\\|eval-\\(?:a\\(?:fter-load\\|nd-compile\\)\\|next-afte= r-load\\|when\\(?:-compile\\)?\\)\\|i\\(?:f\\|nline\\)\\|l\\(?:ambda\\|et\\= (?:\\*\\|rec\\)?\\)\\|p\\(?:case\\(?:-let\\*?\\)?\\|rog[*12nv]?\\)\\|save-\= \(?:current-buffer\\|excursion\\|match-data\\|restriction\\|selected-window= \\|window-excursion\\)\\|track-mouse\\|unwind-protect\\|w\\(?:hile\\(?:-no-= input\\)?\\|ith-\\(?:c\\(?:a\\(?:\\(?:se\\|tegory\\)-table\\)\\|urrent-buff= er\\)\\|demoted-errors\\|electric-help\\|local-quit\\|no-warnings\\|output-= to-\\(?:string\\|temp-buffer\\)\\|s\\(?:elected-\\(?:frame\\|window\\)\\|il= ent-modifications\\|yntax-table\\)\\|t\\(?:emp-\\(?:buffer\\|\\(?:fil\\|mes= sag\\)e\\)\\|imeout\\(?:-handler\\)?\\)\\|wrapper-hook\\)\\)\\)\\>"= )
=A0 =A0 =A0 =A0 =A0 s0)
=A0 =A0 =A0 (prin1 s)
=A0 =A0 =A0 bug-bind-output-str))

i.e., work with the global binding, then the program works as
expected, AFAICS.

--001a11c30a043b368204f10cfd75--