[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Making callable function of a macro
From: |
Decebal |
Subject: |
Re: Making callable function of a macro |
Date: |
Tue, 30 Sep 2008 02:04:28 -0700 (PDT) |
User-agent: |
G2/1.0 |
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.
Re: Making callable function of a macro, Joost Kremers, 2008/09/25
Re: Making callable function of a macro, harven, 2008/09/25
Re: Making callable function of a macro,
Decebal <=