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: Tue, 7 Dec 2021 12:16:20 -0300	[thread overview]
Message-ID: <CADs++6jpWdJ6YYFMSS+9gG8CgZ0LGNhqoANR3_5WD0WLJHADsA@mail.gmail.com> (raw)
In-Reply-To: <61a37784-cdac-4044-1223-2a8bf45ac8e5@gmail.com>

Hi Ypo!

You may find this useful too. I often use it when I want to put
editing commands in my functions and I'm in a hurry and not in a mood
to find their names - so for example I use (eek "C-l") instead of
(recenter-top-bottom), or (eek "<up> C-a C-SPC <down> M-w C-y") to
duplicate the line above the point...

  Cheers & happy hacking =),
    E.
    http://angg.twu.net/#eev


;; See:
;; http://angg.twu.net/eev-intros/find-eev-quick-intro.html#3
;; (find-eev-quick-intro "3. Elisp hyperlinks")
;;
(defun eek (str)
  "Execute STR as a keyboard macro. See `edmacro-mode' for the exact format.\n
An example: (eek \"C-x 4 C-h\")"
  (interactive "sKeys: ")
  (execute-kbd-macro (read-kbd-macro str)))

On Tue, 7 Dec 2021 at 09:55, Ypo <ypuntot@gmail.com> wrote:
>
> Obrigado, Eduardo!
>
> I didn't know that command: "setq last-kbd-macro" and probably it will be useful with elmacro too.
>
> (outline-next-visible-heading) ;; C-c C-n
>
> I save your instructions to my notes to use them :-)
>
> Saúde!
>
>
> El 07/12/2021 a las 3:11, Eduardo Ochs escribió:
>
> 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


      reply	other threads:[~2021-12-07 15:17 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
2021-12-07 12:55   ` Ypo
2021-12-07 15:16     ` Eduardo Ochs [this message]

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++6jpWdJ6YYFMSS+9gG8CgZ0LGNhqoANR3_5WD0WLJHADsA@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).