emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eduardo Ochs <eduardoochs@gmail.com>
To: Ypo <ypuntot@gmail.com>
Cc: Org-mode <emacs-orgmode@gnu.org>
Subject: Re: From macros to elisp programming?
Date: Mon, 6 Dec 2021 23:11:40 -0300	[thread overview]
Message-ID: <CADs++6j_4wxW9V5Oxr1hMrWk6-09tqO5ViOGwfC5h0_xSS-TjA@mail.gmail.com> (raw)
In-Reply-To: <5b93e27d-df22-3799-7b35-3078472a5154@gmail.com>

On Mon, 6 Dec 2021 at 10:43, Ypo <ypuntot@gmail.com> wrote:
>
> 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. This 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éndez Balaña" (pp. 95-118)
> **** INTRODUCCIÓN
>
> I get modified the second headline:
>
> *** Sanz Aparicio et al. (2019) "5 Los Motivos Adquiridos, Menéndez Balaña" (pp. 95-118)
> **** Sanz Aparicio et al. (2019) "5 Los Motivos Adquiridos - INTRODUCCIÓN"
>
>
> Are macros near to elisp programming or they are two different worlds?
>
> Ypo


Hi Ypo,

here's a suggestion. If you run this

  (setq last-kbd-macro [?\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 ?\"])

and then type `C-x C-k C-e' (`kmacro-edit-macro-repeat') you will get
a temporary buffer that contains this:

    C-a                     ;; move-beginning-of-line
    M-f                     ;; forward-word
    M-b                     ;; backward-word
    C-SPC                   ;; set-mark-command
    9*M-f                   ;; forward-word
    M-w                     ;; kill-ring-save
    C-c C-n
    C-a                     ;; move-beginning-of-line
    M-f                     ;; forward-word
    M-b                     ;; backward-word
    C-y                     ;; yank
    SPC                     ;; self-insert-command
    -                       ;; self-insert-command
    SPC                     ;; self-insert-command
    C-e                     ;; move-end-of-line
    M-b                     ;; backward-word
    M-f                     ;; forward-word
    "                       ;; self-insert-command

If you convert that by hand - suggestion: use keyboard macros for
that! =) - to a defun like this one,

  (defun SanzTema5 ()
    (interactive)
    (move-beginning-of-line)       ; C-a
    (forward-word)                 ; M-f
    (backward-word)                ; M-b
    (set-mark-command)             ; C-SPC
    (dotimes 9 (forward-word))     ; 9*M-f
    ;; ^ or: (forward-word 9)
    (kill-ring-save)               ; M-w
    ;; What here? I don' have a:   ; C-c C-n
    (move-beginning-of-line)       ; C-a
    (forward-word)                 ; M-f
    (backward-word)                ; M-b
    (yank)                         ; C-y
    (insert " - ")                 ; SPC - SPC
    (move-end-of-line)             ; C-e
    (backward-word)                ; M-b
    (forward-word)                 ; M-f
    (insert "\"")                  ; "
    )

Then you will get a defun that does something that is clearly useful
to you... you can start by creating and debugging a handful of defuns
like that one and then learn what most people consider as "real
Elisp"...

  Cheers =),
    Eduardo Ochs
    http://angg.twu.net/#eev


  parent reply	other threads:[~2021-12-07  2:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 13:42 From macros to elisp programming? Ypo
2021-12-06 18:08 ` András Simonyi
2021-12-06 18:58   ` Ypo
2021-12-06 22:10 ` Tim Cross
2021-12-07  9:30   ` Marcin Borkowski
2021-12-07  2:11 ` Eduardo Ochs [this message]
2021-12-07 12:55   ` Ypo
2021-12-07 15:16     ` Eduardo Ochs

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CADs++6j_4wxW9V5Oxr1hMrWk6-09tqO5ViOGwfC5h0_xSS-TjA@mail.gmail.com \
    --to=eduardoochs@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=ypuntot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).