From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?Q?Aur=C3=A9lien_Aptel?= Newsgroups: gmane.emacs.help Subject: Re: Meta-code confusion Date: Mon, 13 Aug 2012 18:44:00 +0200 Message-ID: References: <155DEC68569B714B86C2C7075F5EDA98268CCCBB@DAKIYA1.pegasus.local> <155DEC68569B714B86C2C7075F5EDA98268CCDA0@DAKIYA1.pegasus.local> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: dough.gmane.org 1344876254 18073 80.91.229.3 (13 Aug 2012 16:44:14 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 13 Aug 2012 16:44:14 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org" To: Doug Lewan Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 13 18:44:13 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 1T0xkS-00026K-6D for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Aug 2012 18:44:12 +0200 Original-Received: from localhost ([::1]:48845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0xkR-0003aC-94 for geh-help-gnu-emacs@m.gmane.org; Mon, 13 Aug 2012 12:44:11 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:47062) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0xkK-0003ZN-FZ for help-gnu-emacs@gnu.org; Mon, 13 Aug 2012 12:44:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T0xkH-0004XQ-A7 for help-gnu-emacs@gnu.org; Mon, 13 Aug 2012 12:44:04 -0400 Original-Received: from mail-yw0-f41.google.com ([209.85.213.41]:50251) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T0xkH-0004XM-5f for help-gnu-emacs@gnu.org; Mon, 13 Aug 2012 12:44:01 -0400 Original-Received: by yhr47 with SMTP id 47so3699068yhr.0 for ; Mon, 13 Aug 2012 09:44:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=/Cmh5nPt/p/dRbROICPOY7NU/doxP/p52HnQTgdGc2E=; b=fNvhsbEcvTV/ihxqzsQrZtJWaTIdAOnVgQQVT4taU0H+BPI5yn5Mr8dFwJlFQyxixh qPNVhNZqaaL2fnbwo+dV3MSL6DKBnei0O1KBqQ+5mqGa+ZJrC4qNVbBwmsyu6foTELSB IRNiEuvGhIwRnFEy7Jv3x53e3FIFPxV5A/TeOpwbf5BLhZECeFVin0OdPyAns5Of/KIc 2x3MAiwkoENG132VjIu7CO7HHktVa4g/7MkhL/JixAzvL86hbG+y221Gu4e6npLwducf bWuExPAEV58/uHtL1SY7BlmSyULEuPfbwwdiyAFwbuwlouq/XQ6+kzlnT/T/nN4ISu8n HLJQ== Original-Received: by 10.60.29.164 with SMTP id l4mr14176212oeh.4.1344876240555; Mon, 13 Aug 2012 09:44:00 -0700 (PDT) Original-Received: by 10.182.42.1 with HTTP; Mon, 13 Aug 2012 09:44:00 -0700 (PDT) In-Reply-To: <155DEC68569B714B86C2C7075F5EDA98268CCDA0@DAKIYA1.pegasus.local> X-Google-Sender-Auth: YBd2_90CJ59_h1Az-nIh-PFR_E8 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.213.41 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:86331 Archived-At: On Mon, Aug 13, 2012 at 4:04 PM, Doug Lewan wrote: >> But more likely, you probably need to define your own macro rather than >> a function. > > And I do suppose that this would be more correct (and satisfying). I'm not fluent in macros and try to avoid them, but maybe the time has come.... It's really simpler using a macro. Are you familiar with the backquote? This is a backquote form: `(a b c) => (a b c) It's almost the same behaviour as the regular quote *but* if you prefix an element with a comma, it is evaluated. '(1 (+ 1 1) 3) ;; regular quote => (1 (+ 1 1) 3) `(1 (+ 1 1) 3) ;; backquote => (1 (+ 1 1) 3) `(1 ,(+ 1 1) 3) ;; backquote with a comma => (1 2 3) Notice how the expression after the comma is evaluated. Here's a simple macro that does what you want: (defmacro ppm-define-vars (name abbrev) (let ((var (intern (format "*pp-%s-start-re*" abbrev))) (fmt (format "^%s\\s-+" (regexp-quote name)))) `(defvar ,var (concat ,fmt *pp-symbol-re*)))) No nested list call and way more readable, right? When the macro is evaluated, it is first "expanded" and the resulting form is then evaluated. You can see the result (expansion) of the macro *before* it gets evaluated with the macroexpand function. (macroexpand '(ppm-define-vars "douglas" "dug")) => (defvar *pp-dug-start-re* (concat "^douglas\\s-+" *pp-symbol-re*)) There's more in the manual if you're interested. Look at (info "(elisp) Macros") or [1]. Good luck! 1: http://www.gnu.org/software/emacs/manual/html_node/elisp/Macros.html#Macros