all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Making callable function of a macro
@ 2008-09-25  7:07 Decebal
  2008-09-25  7:39 ` Pascal J. Bourguignon
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Decebal @ 2008-09-25  7:07 UTC (permalink / raw)
  To: help-gnu-emacs

I made the following macro to process some files:
#####
Macro:

ESC <			;; beginning-of-buffer
C-SPC			;; set-mark-command
ESC C-s			;; isearch-forward-regexp
^ =			;; self-insert-command * 2
RET			;; newline
C-a			;; beginning-of-line
2*C-n			;; next-line
C-w			;; kill-region
ESC >			;; end-of-buffer
C-SPC			;; set-mark-command
ESC <			;; beginning-of-buffer
ESC C-s			;; isearch-forward-regexp
^ =			;; self-insert-command * 2
RET			;; newline
C-a			;; beginning-of-line
C-w			;; kill-region
ESC <			;; beginning-of-buffer
ESC C-%			;; query-replace-regexp
C-q			;; quoted-insert
LFD			;; newline-and-indent
ESC 5			;; digit-argument
SPC			;; self-insert-command
RET			;; newline
C-q			;; quoted-insert
TAB			;; indent-relative
RET			;; newline
!			;; self-insert-command
ESC <			;; beginning-of-buffer
RET			;; newline
C-p			;; previous-line
Probleem		;; self-insert-command * 8
C-q			;; quoted-insert
TAB			;; indent-relative
Referentie		;; self-insert-command * 10
C-q			;; quoted-insert
TAB			;; indent-relative
Oplossing		;; self-insert-command * 9
C-a			;; beginning-of-line
#####

Now other people like the functionality that I made. ;-}
But they do not use Emacs. So I would like to change the macro to a
function. In this way the script that is used to generate the input
files, could call Emacs and process them directly. Is this possible?
If so: how would I do this?
I have worked with Emacs, but not really with the Lisp capabilities.
More as an editor.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Making callable function of a macro
  2008-09-25  7:07 Making callable function of a macro Decebal
@ 2008-09-25  7:39 ` Pascal J. Bourguignon
  2008-09-25  8:40   ` Decebal
  2008-09-25  7:54 ` Joost Kremers
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Pascal J. Bourguignon @ 2008-09-25  7:39 UTC (permalink / raw)
  To: help-gnu-emacs

Decebal <CLDWesterhof@gmail.com> writes:
> I have worked with Emacs, but not really with the Lisp capabilities.

Type:

(info "(eintr)") C-x C-e

to get "An Introduction to Programming in Emacs Lisp".


It will be rather trivial to translate the sequence of commands of the
macro into an emacs lisp command.  Sorry I don't have the time right
now to explain more.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

"Remember, Information is not knowledge; Knowledge is not Wisdom;
Wisdom is not truth; Truth is not beauty; Beauty is not love;
Love is not music; Music is the best." -- Frank Zappa


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Making callable function of a macro
  2008-09-25  7:07 Making callable function of a macro Decebal
  2008-09-25  7:39 ` Pascal J. Bourguignon
@ 2008-09-25  7:54 ` Joost Kremers
  2008-09-25  8:33   ` Andreas Politz
  2008-09-25  8:45   ` Decebal
  2008-09-25  9:24 ` harven
  2008-09-30  9:04 ` Decebal
  3 siblings, 2 replies; 11+ messages in thread
From: Joost Kremers @ 2008-09-25  7:54 UTC (permalink / raw)
  To: help-gnu-emacs

Decebal wrote:
[...]
>  So I would like to change the macro to a
> function.

i think the following info section explains how this can be done:

(info "(emacs) Save Keyboard Macro")

it even claims you don't need to know any elisp to do it...

HTH

-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Making callable function of a macro
  2008-09-25  7:54 ` Joost Kremers
@ 2008-09-25  8:33   ` Andreas Politz
  2008-09-25  8:45   ` Decebal
  1 sibling, 0 replies; 11+ messages in thread
From: Andreas Politz @ 2008-09-25  8:33 UTC (permalink / raw)
  To: help-gnu-emacs

Joost Kremers wrote:
> Decebal wrote:
> [...]
>>  So I would like to change the macro to a
>> function.
> 
> i think the following info section explains how this can be done:
> 
> (info "(emacs) Save Keyboard Macro")
> 
> it even claims you don't need to know any elisp to do it...
> 
> HTH
> 

Yes, name the macro ( C-x C-k n ) and insert it in some file
with insert-kbd-macro . After that it becomes a callable function/command.
-> (NAME)

This requires the emacs instance, in which this is later invoked, to have
the same commands bound to the same keys as the instance where the macro was created.

I am afraid writing a generic macro, which would transform a kbd-macro into a
bindings-agnostic function is no trivial task.

-ap


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Making callable function of a macro
  2008-09-25  7:39 ` Pascal J. Bourguignon
@ 2008-09-25  8:40   ` Decebal
  2008-09-25  8:48     ` Joost Kremers
  0 siblings, 1 reply; 11+ messages in thread
From: Decebal @ 2008-09-25  8:40 UTC (permalink / raw)
  To: help-gnu-emacs

On 25 sep, 09:39, p...@informatimago.com (Pascal J. Bourguignon)
wrote:
> Type:
>
> (info "(eintr)") C-x C-e
>
> to get "An Introduction to Programming in Emacs Lisp".

Does not work in my Emacs. But I allready printed it and am reading
it. But I did not see anything about calling an Emacs function from a
script. Or am I missing something?

What I would like is something like the following:
    emacs-command input output
Input is the file to be processed and output is the file to use for
the processed data. So that in a script the files automatically can be
generated.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Making callable function of a macro
  2008-09-25  7:54 ` Joost Kremers
  2008-09-25  8:33   ` Andreas Politz
@ 2008-09-25  8:45   ` Decebal
  1 sibling, 0 replies; 11+ messages in thread
From: Decebal @ 2008-09-25  8:45 UTC (permalink / raw)
  To: help-gnu-emacs

On 25 sep, 09:54, Joost Kremers <joostkrem...@yahoo.com> wrote:
> i think the following info section explains how this can be done:
>
> (info "(emacs) Save Keyboard Macro")

I allready did this. But that is not what I want. I want to write a
function that I can use to automatically -without user interaction-
convert files. Also the function needs a little bid more knowledge.
For example when there is only one line with starts with a '=',
something els needs to be done. I do not think this can be done with a
macro.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Making callable function of a macro
  2008-09-25  8:40   ` Decebal
@ 2008-09-25  8:48     ` Joost Kremers
  2008-09-25  9:25       ` Decebal
  0 siblings, 1 reply; 11+ messages in thread
From: Joost Kremers @ 2008-09-25  8:48 UTC (permalink / raw)
  To: help-gnu-emacs

Decebal wrote:
> On 25 sep, 09:39, p...@informatimago.com (Pascal J. Bourguignon)
> wrote:
>> Type:
>>
>> (info "(eintr)") C-x C-e
>>
>> to get "An Introduction to Programming in Emacs Lisp".
>
> Does not work in my Emacs. But I allready printed it and am reading
> it. But I did not see anything about calling an Emacs function from a
> script. Or am I missing something?

no, that's probably not in there...

> What I would like is something like the following:
>     emacs-command input output
> Input is the file to be processed and output is the file to use for
> the processed data. So that in a script the files automatically can be
> generated.

emacs has the --script option, which must be followed by the name of a file
containing lisp code, which is then run. see

(info "(emacs) Initial Options")

for details.

i'm not sure if it's possible to pass an input and an output file, though.
at the very least, you'd need to know some elisp to get all the I/O
correct...


-- 
Joost Kremers                                      joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Making callable function of a macro
  2008-09-25  7:07 Making callable function of a macro Decebal
  2008-09-25  7:39 ` Pascal J. Bourguignon
  2008-09-25  7:54 ` Joost Kremers
@ 2008-09-25  9:24 ` harven
  2008-09-30  9:04 ` Decebal
  3 siblings, 0 replies; 11+ messages in thread
From: harven @ 2008-09-25  9:24 UTC (permalink / raw)
  To: help-gnu-emacs

Decebal <CLDWesterhof@gmail.com> writes:

> Now other people like the functionality that I made. ;-}
> But they do not use Emacs. So I would like to change the macro to a
> function. In this way the script that is used to generate the input
> files, could call Emacs and process them directly. Is this possible?
> If so: how would I do this?
> I have worked with Emacs, but not really with the Lisp capabilities.
> More as an editor.

You better give a name to your macro :  C-x C-k n MY-MACRO
then go to your init file and type   :  M-x insert-kbd-macro RET MY-MACRO RET

This will put under your cursor the definition of a command that
executes the macro. This command can be called interactively the usual
way (M-x MY-MACRO) or put in your script.

I must say that it is not clear what your macro does. I would guess
that you want to keep the text between the two starting = signs and
add a header. But that's not what happens when I run your macro.
Instead it strips everything before the second = sign and add the
header. Also I think the ! insertion is meant to do the replacement
until end of file, but here again that's not what I obtain when I run
the macro.


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Making callable function of a macro
  2008-09-25  8:48     ` Joost Kremers
@ 2008-09-25  9:25       ` Decebal
  2008-09-25  9:45         ` harven
  0 siblings, 1 reply; 11+ messages in thread
From: Decebal @ 2008-09-25  9:25 UTC (permalink / raw)
  To: help-gnu-emacs

On 25 sep, 10:48, Joost Kremers <joostkrem...@yahoo.com> wrote:
> > What I would like is something like the following:
> >     emacs-command input output
> > Input is the file to be processed and output is the file to use for
> > the processed data. So that in a script the files automatically can be
> > generated.
>
> emacs has the --script option, which must be followed by the name of a file
> containing lisp code, which is then run. see
>
> (info "(emacs) Initial Options")
>
> for details.
>
> i'm not sure if it's possible to pass an input and an output file, though.
> at the very least, you'd need to know some elisp to get all the I/O
> correct...

That looks like what I want. I'll start learning elisp then. ;-}


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Making callable function of a macro
  2008-09-25  9:25       ` Decebal
@ 2008-09-25  9:45         ` harven
  0 siblings, 0 replies; 11+ messages in thread
From: harven @ 2008-09-25  9:45 UTC (permalink / raw)
  To: help-gnu-emacs

Decebal <CLDWesterhof@gmail.com> writes:

> On 25 sep, 10:48, Joost Kremers <joostkrem...@yahoo.com> wrote:
>> > What I would like is something like the following:
>> >     emacs-command input output
>> > Input is the file to be processed and output is the file to use for
>> > the processed data. So that in a script the files automatically can be
>> > generated.
>>
>> emacs has the --script option, which must be followed by the name of a file
>> containing lisp code, which is then run. see
>>
>> (info "(emacs) Initial Options")
>>
>> for details.
>>
>> i'm not sure if it's possible to pass an input and an output file, though.
>> at the very least, you'd need to know some elisp to get all the I/O
>> correct...
>
> That looks like what I want. I'll start learning elisp then. ;-}

You may want to look at some example scripts there:
http://www.emacswiki.org/cgi-bin/wiki/CategoryBatchMode


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Making callable function of a macro
  2008-09-25  7:07 Making callable function of a macro Decebal
                   ` (2 preceding siblings ...)
  2008-09-25  9:24 ` harven
@ 2008-09-30  9:04 ` Decebal
  3 siblings, 0 replies; 11+ messages in thread
From: Decebal @ 2008-09-30  9:04 UTC (permalink / raw)
  To: help-gnu-emacs

On 25 sep, 09:07, Decebal <CLDWester...@gmail.com> wrote:
> I made the following macro to process some files:
> #####
> Macro:
>
> ESC <                        ;; beginning-of-buffer
> C-SPC                   ;; set-mark-command
> ESC C-s                 ;; isearch-forward-regexp
> ^ =                     ;; self-insert-command * 2
> RET                     ;; newline
> C-a                     ;; beginning-of-line
> 2*C-n                   ;; next-line
> C-w                     ;; kill-region
> ESC >                        ;; end-of-buffer
> C-SPC                   ;; set-mark-command
> ESC <                        ;; beginning-of-buffer
> ESC C-s                 ;; isearch-forward-regexp
> ^ =                     ;; self-insert-command * 2
> RET                     ;; newline
> C-a                     ;; beginning-of-line
> C-w                     ;; kill-region
> ESC <                        ;; beginning-of-buffer
> ESC C-%                 ;; query-replace-regexp
> C-q                     ;; quoted-insert
> LFD                     ;; newline-and-indent
> ESC 5                   ;; digit-argument
> SPC                     ;; self-insert-command
> RET                     ;; newline
> C-q                     ;; quoted-insert
> TAB                     ;; indent-relative
> RET                     ;; newline
> !                       ;; self-insert-command
> ESC <                        ;; beginning-of-buffer
> RET                     ;; newline
> C-p                     ;; previous-line
> Probleem                ;; self-insert-command * 8
> C-q                     ;; quoted-insert
> TAB                     ;; indent-relative
> Referentie              ;; self-insert-command * 10
> C-q                     ;; quoted-insert
> TAB                     ;; indent-relative
> Oplossing               ;; self-insert-command * 9
> C-a                     ;; beginning-of-line
> #####
>
> Now other people like the functionality that I made. ;-}
> But they do not use Emacs. So I would like to change the macro to a
> function. In this way the script that is used to generate the input
> files, could call Emacs and process them directly. Is this possible?

I have done it. I made the following script:
#####
(defun do-make-tab-seperated-file ()
  (re-search-forward "^=" nil nil)
  (forward-line 2)
  (delete-region (point-min) (point))
  (re-search-forward "^=" nil nil)
  (beginning-of-line)
  (delete-region (point) (point-max))
  (goto-char (point-min))
  (insert "Problem\tReferentie\tOplossing\n")
  (while (re-search-forward "\n     " nil t)
    (replace-match "\t")
  )
)

(defun make-tab-seperated-file (input-file output-file)
  (find-file input-file)
  (if (search-forward "No problems detected" nil t)
    (no-problems)
    (do-make-tab-seperated-file)
  )
  (write-file output-file)
)

(defun no-problems ()
  (erase-buffer)
  (insert "Geen problemen gevonden")
)
#####

And I call it with:
    emacs -batch -nw -l ~/bin/makeTabSeperated.el --eval="(make-tab-
seperated-file \"${OUTPUTDIR}/${base}${EXTENSION2}\" \"${base}$
{EXTENSION3}\")" 2>/dev/null

The '2>/dev/null' is needed because emacs sends a lot of output to
stderr. Is there a way to circumvent this? I would prefer to have the
possibility to use stderr in my scripts. If those get drowned in the
output of Emacs itself, it is not going to work.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2008-09-30  9:04 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-09-25  7:07 Making callable function of a macro Decebal
2008-09-25  7:39 ` Pascal J. Bourguignon
2008-09-25  8:40   ` Decebal
2008-09-25  8:48     ` Joost Kremers
2008-09-25  9:25       ` Decebal
2008-09-25  9:45         ` harven
2008-09-25  7:54 ` Joost Kremers
2008-09-25  8:33   ` Andreas Politz
2008-09-25  8:45   ` Decebal
2008-09-25  9:24 ` harven
2008-09-30  9:04 ` Decebal

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.