From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id ADz6KHKYrmFwvAAAgWs5BA (envelope-from ) for ; Tue, 07 Dec 2021 00:10:42 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id KJqgJHKYrmGMNwAA1q6Kng (envelope-from ) for ; Mon, 06 Dec 2021 23:10:42 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 1AB7ABF68 for ; Tue, 7 Dec 2021 00:10:42 +0100 (CET) Received: from localhost ([::1]:55596 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1muN85-0007vU-8D for larch@yhetil.org; Mon, 06 Dec 2021 18:10:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42376) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1muN7Y-0007vK-EV for emacs-orgmode@gnu.org; Mon, 06 Dec 2021 18:10:09 -0500 Received: from [2607:f8b0:4864:20::42e] (port=36638 helo=mail-pf1-x42e.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1muN7V-0003lA-UU for emacs-orgmode@gnu.org; Mon, 06 Dec 2021 18:10:08 -0500 Received: by mail-pf1-x42e.google.com with SMTP id n26so11581167pff.3 for ; Mon, 06 Dec 2021 15:10:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=references:user-agent:from:to:subject:date:in-reply-to:message-id :mime-version:content-transfer-encoding; bh=lBQhMLcvfWnUyV5SNvbtXP7nznD7rIN08yEru/++nbs=; b=QBStQZuSQXoMeAeNHRnKNjU3ly82xhGIry39hu89qfDcb6lfb6B6AdvyMeV7JWFUDk vqxu3FyENdLT8qQ9mptRPhsKZorSCKiouRl1Aj1thy2U8Z7qGCB7Yx9IQU8fVRgYkVaW kZNa1OqWyf2NSnnXFUOw7o3txaw6QK1vAyR0FiMFuh08ugq2wvcntLmqie27rahlN9NV MXPIqlWyPefL1UxxvN5+m/uAAd68wQomUrDnT1DmQzaRiLcj+zYv1coxAemtWubwAXIR KRhYE73jfFUMqTLd+F+22QLzW18WLfdOwJ0MLufJIbLaoLFNoPdKCggaZYNrnwaf9Iax p7yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:references:user-agent:from:to:subject:date :in-reply-to:message-id:mime-version:content-transfer-encoding; bh=lBQhMLcvfWnUyV5SNvbtXP7nznD7rIN08yEru/++nbs=; b=QlHItKRvdS5K0O75RHluxsFWMNyxhnNp6SG6Sr0YoztT7mj3HRWd6FZgMT2MoUne6z 8XPwWWKYcs2JBmejRSlRiGPBa+YE9LVOn/kac2f3j1aHO7hSEgxu7p2z0z2CpQRITocE 5+/C23AqyO04wrShduTXi1JILG6t1mYyKm5r4RmgeTdltifNQDPjmyUFIRrksRB44cuP Z9Oq1EXdEszwOIosXm9/zi768s0MHsu+zddCHUAXE7r51g9Lmyu/ZDNzTtwnUHRqT1La obYOq8Sry3jHijZmlcILxAwXOtxWBFtPUgh6P4iYQOCxmRLyQhJPIus5yWjRvTKw69DJ IjSA== X-Gm-Message-State: AOAM533Zl0gXwk+NczhPqSKmy3D23hYUn1q5DW7BkXNYBJkc77CcPB4e +hK1dD9iEoajZUJfCQmIGNTKJB3+Pf4= X-Google-Smtp-Source: ABdhPJwH/hXNzsFjxeK1KOslIAmYe9nF3j33/KOdpm8MNaDi+sddLuF3LMV6gzb1WuMBJ4Tt/l7nzQ== X-Received: by 2002:a63:1158:: with SMTP id 24mr20688185pgr.193.1638832200491; Mon, 06 Dec 2021 15:10:00 -0800 (PST) Received: from dingbat (2001-44b8-31f2-bb00-4770-468f-89a4-7506.static.ipv6.internode.on.net. [2001:44b8:31f2:bb00:4770:468f:89a4:7506]) by smtp.gmail.com with ESMTPSA id m18sm14080695pfk.68.2021.12.06.15.09.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Dec 2021 15:10:00 -0800 (PST) References: <5b93e27d-df22-3799-7b35-3078472a5154@gmail.com> User-agent: mu4e 1.7.5; emacs 28.0.90 From: Tim Cross To: emacs-orgmode@gnu.org Subject: Re: From macros to elisp programming? Date: Tue, 07 Dec 2021 09:10:40 +1100 In-reply-to: <5b93e27d-df22-3799-7b35-3078472a5154@gmail.com> Message-ID: <875ys1ba9n.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::42e (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=theophilusx@gmail.com; helo=mail-pf1-x42e.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1638832242; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=lBQhMLcvfWnUyV5SNvbtXP7nznD7rIN08yEru/++nbs=; b=Ic5ZJm+s6CpEHVOMAPAvU2TNWfV2r/yeS5NxJdDv3n0BMBMkJQpzCFZ1xXnHXxaVY1hdpM mhPRkmXVuUDSmZGITgLqWDUoeatJ6hRRZqy8LC7Cx0aHj7pVBhYnNEGqHdYebRBzfAOzY3 we2tl6ozS/LF93IQOOOq71Q6Ruq/1iaRtdlpJgCvZrbYsvxP1+fGP0JYBPoxFfM+kq450y 45o+Hq9oUddx7mC9llqbcfTOB4eD44KgivtHDGwugvcU9oB373bLAdH1udR9AlCqoKcriT 5gspt7tmkefd3jivIpmksKuwhZs9td2O2oSn42+29OJHfkGl4cj5iYwhhqXs5w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1638832242; a=rsa-sha256; cv=none; b=CfxMBdy6DxDp8fjs3QXtGfEWMmd2y7fdWSfeQJdbHEWv9I/LMbsKFQnyRrV6L1c8qBeCTb eiGP25/o1cg+eMkHk2F4M87E7FJLxWY5vpeIhRLjX1meT8yfhWyrvdnaV1eqos/vEbCwvQ 2b3/CyxTRxU0KHuCCVLsfS8byX9ewf+2P5z7YRasc9lzCz0Rn9pefawAZ3/CxW3BT/oriA 0M586rNQJ9pdtr1s/QsHwQKcwEi9r49BY9mb6TPs3Hp7VM4NeIK1BBVPY+xWS6Kt+DREGe +6VLdHzV4zhIqKHpX29bIlztUXKRbZntILCGNpkSqqRLT+tZMltAZ0LQiw+xIQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=QBStQZuS; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.14 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=QBStQZuS; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 1AB7ABF68 X-Spam-Score: -3.14 X-Migadu-Scanner: scn0.migadu.com X-TUID: WEznt/6nczmw Ypo writes: > Hi > > I am able to make macros, but I think I am far away from Lisp programming. > > Is there a path to go from macros to elisp programming? For example, the = last macro I've made is for transforming the name of some > headlines, adding in front of them a part from the previous headline. Thi= s is the elisp code of the macro: > > #+BEGIN_SRC > (fset 'SanzTema5 > (kmacro-lambda-form [?\C-a ?\M-f ?\M-b ?\C- ?\M-f ?\M-f ?\M-f ?\M-f ?= \M-f ?\M-f ?\M-f ?\M-f ?\M-f ?\M-w ?\C-c ?\C-n ?\C-a ?\M-f ?\M-b ?\C-y > ? ?- ? ?\C-e ?\M-b ?\M-f ?\"] 0 "%d")) > #+END_SRC > > Using that code, from these headlines: > > *** Sanz Aparicio et al. (2019) "5 Los Motivos Adquiridos, Men=C3=A9ndez = Bala=C3=B1a" (pp. 95-118) > **** INTRODUCCI=C3=93N > > I get modified the second headline: > > *** Sanz Aparicio et al. (2019) "5 Los Motivos Adquiridos, Men=C3=A9ndez = Bala=C3=B1a" (pp. 95-118) > **** Sanz Aparicio et al. (2019) "5 Los Motivos Adquiridos - INTRODUCCI= =C3=93N" > > Are macros near to elisp programming or they are two different worlds? > Unfortunately, the term 'macro' is somewhat overloaded and can mean different things depending on the language. For example, C has pre-processor 'macros' which are essentially simple string replacement mechanisms and very different from macros as used in lisp languages like elisp, common lisp or clojure. In a similar vain, what you are referring to above is a keyboard macro, which is not an elisp macro. A keyboard macro is essentially a simple 'replay' facility where you can capture a set of keyboard input actions, give them a name and then repeat those actions by running the macro with that name again. This is very different from an elisp macro. An elisp macro (or a common lisp macro, or a clojure macro etc) is a facility which allows you to manipulate source code and can be very useful in defining new low level language constructs which are largely indistinguishable from the built-in constructs of the language. For example, if elisp did not have a 'when' statement, you could define it as a macro and it would operate at the same level as other built in functions. For this reason, macros are often used a lot when defining a 'domain specific language' (DSL-) a type = of language dialect which has operators specific to a specialised domain.=20 While others would likely disagree, I would not consider using keyboard macros as programming in emacs lisp. Keyboard macros are an end user facility which can be used to automate repetitive tasks and which can be used by anyone using Emacs - you don't need to know any emacs lisp to create and use a keyboard macro.=20 Macros as used in lisp languages are a wonderful, extremely powerful facility that allow the programmer to do things which are near impossible in other languages. However, they should be used very judiciously. There is an old adage which states that if you can do it with a function, then use a function, not a macro. A common error made by those new to macros is that they are so amazed at their power, they now think it is the solution to all problems. It is difficult to recommend resources as a lot depends on your own experience, what level you want to dive into and what you want to be able to do. There is a big difference in knowing enough emacs lisp to tweak your Emacs configuration and knowing enough emacs lisp to write the next great package. The good news is that there are some great free resources out there, so the main investment will be in time. If you have not yet read it, a good starting point is Mastering Emacs by Mickey Petersen https://www.masteringemacs.org/ There is also an Introduction to Emacs Lisp, which is part of the GNU Emacs distribution. For getting to understand lisp programming at a much deeper level, there are some excellent resources out there, many of which are free. The trick is to not limit yourself to searching just for Emacs lisp. Emacs lisp is a dialect of lisp - a domain specific language for an editor if you like. Most of the concepts associated with lisp are applicable to emacs lisp. almost any resource teaching lisp will teach you things applicable to emacs lisp. Therefore, if you really want to learn how to program in emacs lisp, search for resources on learning to program in lisp. There is a somewhat famous book called 'The Structure and Interpretation of Computer Programs" (SCIP), which is based on a course in computer science taught at MIT. It is an excellent book. Even better, videos from the course are also available on-line. While the focus is on programming, it uses a lisp dialect to demonstrate the core principals, which it makes very clear. A must watch for anyone really keen to understand programming. Another great book about lisp which is also freely available is Paul Graham's 'On Lisp', which I think gives a pretty good overview of the power and flexibility of lisp and functional programming.=20 A book which I really like and which I think really shows off the power of lisp macros is Doug Hoyte's "Let over Lambda". Not only does this book show the wonderful power and possibilities of macros, it also shows some of the dangers and pitfalls. However, it is pretty hard core computer science focused and can take some effort to really digest.=20 If you really want to learn emacs lisp, there is really only one route you can take - sit down and start using it to write simple programs to solve some basic problems. Maybe you would like to automate some of what you do or maybe you would like to modify how Emacs does something or maybe you want to create a new command to do something. Open a new window and start trying to implement your idea. You will run into road blocks and you will often be frustrated, but eventually the penny will drop. The other big advantage is that when you run into problems, you will have concrete issues which you can take to a forum for help. It is much easier for people to help with something concrete than something more vague or conceptual. The only real way to learn is to do - if you want to learn emacs lisp, you need to use emacs lisp to solve problems.=20