[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: From macros to elisp programming?
From: |
Eduardo Ochs |
Subject: |
Re: From macros to elisp programming? |
Date: |
Mon, 6 Dec 2021 23:11:40 -0300 |
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