all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Floyd Davidson <floyd@barrow.com>
Subject: Re: Emacs as a command line tool
Date: Tue, 17 Feb 2004 04:35:09 -0900	[thread overview]
Message-ID: <87brnxn81e.fld@barrow.com> (raw)
In-Reply-To: c0sr8r$hel$3@news.net.uni-c.dk

David Rasmussen <david.rasmussen@gmx.net> wrote:
>Is it possible to use the many emacs tools from the command line?
>
>Specifically, I would like to do untabify on several files. I am
>sure that it can be done easily from within emacs. But it would
>still be useful if I could just do something like
>
>emacs -e untabify *.cpp
>
>Is it possible?

Yes.

Note that both /col/ and /expand/ will also fix your tabs, and
probably will be much easier if that is the only thing you might
want to do.  But, to do multiple files, you need to learn a
little shell scripting.

Emacs, on the other hand, can basically do *anything* in batch
mode that it can do as an interactive program; hence, it can do
a great deal more than just change spaces to tabs.  The down
side is, instead of shell scripting, you need to learn a little
eLisp.

Here is a short elisp program that does untabify on a buffer
and then writes it back to disk:

  (untabify (point-min) (point-max))
  (save-buffer)

So if you save that to foo.el, you can untabify file bar.txt
with this command line (and note that the order of arguments
on the command line makes a difference, as the files must
be loaded before the -l option),

  emacs -q -batch bar.txt -l foo.el

However...  to do a number of files, here is a foo.el that will
untabify them all from one command:

 (if (< 1 (count-windows))
     (delete-other-windows (selected-window)))
 (catch 'tag
   (while t
     (untabify (point-min) (point-max))
     (if buffer-file-name  ; nil for *scratch* buffer
         (progn
           (write-file buffer-file-name)
           (kill-buffer (current-buffer)))
       (throw 'tag t))))

Emacs would be invoked with a list of file names,

  emacs -q -batch *.txt bar.* -l foo.el

which will untabify all *.txt and all bar.* files in the current
directory.

That will work with both GNU Emacs and with XEmacs, though there
is a significant incompatibility between them.  GNU Emacs has to
delete-other-windows, even though none are actually being
displayed.  XEmacs not only doesn't have to, but will throw a
segmentation fault and crash if told to!

--
Floyd L. Davidson           <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska)                         floyd@barrow.com

      parent reply	other threads:[~2004-02-17 13:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-17 10:54 Emacs as a command line tool David Rasmussen
2004-02-17 10:57 ` Billy O'Connor
2004-02-17 11:08   ` David Rasmussen
2004-02-17 15:16     ` Pascal Bourguignon
2004-02-17 16:02       ` David Rasmussen
2004-02-17 17:06         ` Pascal Bourguignon
2004-02-19  0:29           ` Kevin Rodgers
2004-02-17 11:14 ` Roodwriter
2004-02-17 11:19   ` David Rasmussen
2004-02-17 11:46     ` Joakim Hove
2004-02-17 12:06       ` David Rasmussen
2004-02-17 13:20         ` expand tabs in a shell Bruce Ingalls
2004-02-17 17:24           ` Bruce Ingalls
2004-02-19  7:01         ` Emacs as a command line tool Roodwriter
2004-02-17 13:35 ` Floyd Davidson [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=87brnxn81e.fld@barrow.com \
    --to=floyd@barrow.com \
    /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.