From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: [emacs-lisp newbie] print-something() -> clipboard? Date: Mon, 21 May 2012 06:24:17 -0700 Message-ID: <6784456F5E1247D387CCC7C99DA86748@us.oracle.com> References: <4FB74988.9000404@easy-emacs.de> <87r4uhxof8.fsf@pobox.com> <87boli1ttd.fsf@pobox.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1337606705 4135 80.91.229.3 (21 May 2012 13:25:05 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 21 May 2012 13:25:05 +0000 (UTC) To: , "'Tom Roche'" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon May 21 15:25:04 2012 Return-path: Envelope-to: geh-help-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 1SWSbY-0007IS-QO for geh-help-gnu-emacs@m.gmane.org; Mon, 21 May 2012 15:24:56 +0200 Original-Received: from localhost ([::1]:33928 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWSbX-0001Ic-Ve for geh-help-gnu-emacs@m.gmane.org; Mon, 21 May 2012 09:24:55 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:37135) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWSbS-0001IK-EQ for help-gnu-emacs@gnu.org; Mon, 21 May 2012 09:24:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SWSbE-0003yg-3b for help-gnu-emacs@gnu.org; Mon, 21 May 2012 09:24:49 -0400 Original-Received: from acsinet15.oracle.com ([141.146.126.227]:19616) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SWSbD-0003yQ-UU for help-gnu-emacs@gnu.org; Mon, 21 May 2012 09:24:36 -0400 Original-Received: from acsinet22.oracle.com (acsinet22.oracle.com [141.146.126.238]) by acsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q4LDOV7X020302 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 21 May 2012 13:24:31 GMT Original-Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q4LDOUt1007541 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 21 May 2012 13:24:31 GMT Original-Received: from abhmt106.oracle.com (abhmt106.oracle.com [141.146.116.58]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q4LDOUrL013774; Mon, 21 May 2012 08:24:30 -0500 Original-Received: from dradamslap1 (/10.159.189.196) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 21 May 2012 06:24:30 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <87boli1ttd.fsf@pobox.com> Thread-Index: Ac02xjS/mLU2pROWTaOksqiEtmBhrQAjiA6Q X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-Source-IP: acsinet22.oracle.com [141.146.126.238] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 141.146.126.227 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:84915 Archived-At: > > (defun foo (&optional arg) > > "..." > > (interactive "P") > > (let ((bn ...)) > > (if arg > > (insert bn) > > (kill-new bn)))) > > Thanks! I probably should `let`, Yes, you should. > but this works: > > (defun print-buffer-name (&optional arg) > "..." > (interactive "P") > (setq bn ...) > (if arg > (kill-new bn) > (insert bn))) `bn' is a free variable here - by default a global, dynamically scoped variable. If you or some code that you use defines another variable named `bn' then your code will suffer from variable capture: You could end up changing the other variable. There is NO reason to use `setq' here, and NO reason not to use `let'. When you suffer from variable capture you don't necessarily realize it, and debugging the problem (with perhaps farflung symptoms) can be a headache. A self-imposed headache in this case, for no benefit.