[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: |
Tue, 7 Dec 2021 12:16:20 -0300 |
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