all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Decebal <CLDWesterhof@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Making callable function of a macro
Date: Tue, 30 Sep 2008 02:04:28 -0700 (PDT)	[thread overview]
Message-ID: <c11ae530-8c19-4520-be82-72e936315e89@e53g2000hsa.googlegroups.com> (raw)
In-Reply-To: 19cc8ee3-7dbc-47ac-bee9-bf233b42a0eb@j22g2000hsf.googlegroups.com

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.


      parent reply	other threads:[~2008-09-30  9:04 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c11ae530-8c19-4520-be82-72e936315e89@e53g2000hsa.googlegroups.com \
    --to=cldwesterhof@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /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 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.