From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sebastian Wiesner Newsgroups: gmane.emacs.help Subject: Re: run-with-timer does not display message Date: Sat, 19 Jul 2014 17:09:32 +0200 Message-ID: References: <87k37e4tjw.fsf@gmail.com> <87d2d2e4ga.fsf@debian.uxu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.6\)) Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1405782600 3061 80.91.229.3 (19 Jul 2014 15:10:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 19 Jul 2014 15:10:00 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jul 19 17:09:55 2014 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 1X8WGn-0000kY-W1 for geh-help-gnu-emacs@m.gmane.org; Sat, 19 Jul 2014 17:09:54 +0200 Original-Received: from localhost ([::1]:54654 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8WGn-0005xX-8i for geh-help-gnu-emacs@m.gmane.org; Sat, 19 Jul 2014 11:09:53 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53191) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8WGZ-0005xM-LE for help-gnu-emacs@gnu.org; Sat, 19 Jul 2014 11:09:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X8WGV-0006hv-Aj for help-gnu-emacs@gnu.org; Sat, 19 Jul 2014 11:09:39 -0400 Original-Received: from vega.uberspace.de ([95.143.172.245]:36623) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X8WGV-0006hg-18 for help-gnu-emacs@gnu.org; Sat, 19 Jul 2014 11:09:35 -0400 Original-Received: (qmail 6373 invoked from network); 19 Jul 2014 15:09:33 -0000 Original-Received: from localhost (HELO ?192.168.178.22?) (127.0.0.1) by vega.uberspace.de with SMTP; 19 Jul 2014 15:09:33 -0000 In-Reply-To: <87d2d2e4ga.fsf@debian.uxu> X-Mailer: Apple Mail (2.1878.6) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 95.143.172.245 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:98790 Archived-At: Am 18.07.2014 um 23:34 schrieb Emanuel Berg : > Stefan Monnier writes: >=20 >> Please don't quote your lambdas! >=20 > Do you mean in that case or never? >=20 > I have had problems with lambdas and both parameters > and `let' bindings. Enable lexical-binding in your Emacs Lisp files to avoid these. =20 See = https://www.gnu.org/software/emacs/manual/html_node/elisp/Lexical-Binding.= html and = https://www.gnu.org/software/emacs/manual/html_node/elisp/Using-Lexical-Bi= nding.html for details. > For example, this works but not without the > backtick/backquote (and the commas): With lexical binding it does. > (defun shortcut-to-file (key-prefix key file-prefix file) > (global-set-key > (format "%s%s" key-prefix key) > `(lambda () > (interactive) > (do-show-file (format "%s%s" ,file-prefix ,file)) ))) With lexical binding it works without any quoting: (defun shortcut-to-file (key-prefix key file-prefix file) (global-set-key (format "%s%s" key-prefix key) (lambda () (interactive) (do-show-file (format "%s%s" file-prefix file))))) The arguments are captured in a closure, and thus preserved when the = lambda body is evaluated. This is more efficient than your variant. Lexical bindings are = generally more efficient than dynamic ones, because local variables can = be elided entirely, and the byte compiler can now inspect and = byte-compile the lambda form. =20 It=92s also safer, because the byte compiler can now warn you about = unused variables or free variables, which helps you to catch misspelled = variable names.=