From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Alexander Shukaev Newsgroups: gmane.emacs.help Subject: Re: Macro Expansion Inconsistency Date: Wed, 17 Dec 2014 15:03:53 +0100 Message-ID: References: <87r3vyegmt.fsf@yahoo.fr> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1418825066 24609 80.91.229.3 (17 Dec 2014 14:04:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 17 Dec 2014 14:04:26 +0000 (UTC) Cc: help-gnu-emacs To: Nicolas Richard , John Mastro Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Dec 17 15:04:19 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 1Y1FD8-0005xK-8f for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Dec 2014 15:04:18 +0100 Original-Received: from localhost ([::1]:49694 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1FD2-0006Gz-1Y for geh-help-gnu-emacs@m.gmane.org; Wed, 17 Dec 2014 09:04:12 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36766) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1FCl-0006Gj-Kf for help-gnu-emacs@gnu.org; Wed, 17 Dec 2014 09:04:00 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y1FCk-0003BS-9T for help-gnu-emacs@gnu.org; Wed, 17 Dec 2014 09:03:55 -0500 Original-Received: from mail-lb0-x233.google.com ([2a00:1450:4010:c04::233]:43073) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1FCj-0003Aw-TK for help-gnu-emacs@gnu.org; Wed, 17 Dec 2014 09:03:54 -0500 Original-Received: by mail-lb0-f179.google.com with SMTP id z11so12578118lbi.24 for ; Wed, 17 Dec 2014 06:03:53 -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=h5p2NeuvDRk5/jPLWgLmz7Nc629J9qhL6I66Hnas0hM=; b=nROwboNi7eSf0B/i3R3B9bruJZrOueqP6ksTLE0D0GqD3qY8yit6xbJE7r2t+dADwf BxoAvOKYjWX9cmpQQSzJPqa/QRdx9Bd1N4lkwhhQ6AFM++O3MqerQLa3QFD+fb4QrVYT R+iXc0zFymnNpQ8unf8tfrkY4m+biVFRBfqJhHmmDMAvxopqRQIpEMVTTHoGrG2hJ0z0 6f5H3hBcLddx7E6Of5F+nkrw0hzjQyPTi/Ql5wbCUAA3N5dpIebDAoOg+eOi27I5okhV RXBe8Zu/oBHCItOCEHhUTDaDH0K4JB7lK2x6ouzZyy+J4JkoWOS/LtjgkJ/l9Z6IbCXY Z1/Q== X-Received: by 10.152.37.7 with SMTP id u7mr17628083laj.74.1418825033128; Wed, 17 Dec 2014 06:03:53 -0800 (PST) Original-Received: by 10.112.123.235 with HTTP; Wed, 17 Dec 2014 06:03:53 -0800 (PST) In-Reply-To: <87r3vyegmt.fsf@yahoo.fr> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c04::233 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 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:101632 Archived-At: Thank you very much, John and Nicolas. I think I finally understand how macros expand in Emacs Lisp better now. I'm sure it's not a coincidence that you both came up with almost identical solutions. It suggests that the style of returning forms for evaluation from macro is probably the best way to go in most cases when `let' is involved. So the final tested solution is= : (defmacro bm-define-flag (name index character foreground) (let* ((symbol (intern (format "bm-%s-flag" (symbol-name name)))) (character-symbol (intern (format "%s-character" (symbol-name symbol))))) (put symbol 'index index) (put symbol 'character character-symbol) `(progn (defcustom ,character-symbol ,character "Character for flag." :tag "BM Flag Character" :group 'buffer-manager :type 'character) (defface ,symbol '((t :foreground ,foreground :weight bold)) "Face for flag." :tag "BM Flag Face" :group 'buffer-manager-faces)))) (put 'bm-define-flag 'lisp-indent-function 'defun) As a final exam for myself, considering what I've learned, I've implemented a collective definition macro as well: (defmacro bm-define-flags (name index character foreground &rest ...) (let ((name `,name) (index `,index) (character `,character) (foreground `,foreground) (... `(,@...)) (body '())) (while name (push `(bm-define-flag ,name ,index ,character ,foreground) body) (setq name (pop ...) index (pop ...) character (pop ...) foreground (pop ...))) `(progn ,@body))) (put 'bm-define-flags 'lisp-indent-function 'defun) How do you like this one? Now I simply write: (bm-define-flags delete 0 ?D "#FF0000" open 0 ?O "#00FFFF" previous 0 ?P nil modified 1 ?M "#FFFF00" write 1 ?W "#00FF00" read-only 2 ?=EE=82=A2 "#FF0000") Looks absolutely amazing ;) Kind regards, Alexander