From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Floyd Davidson Newsgroups: gmane.emacs.help Subject: Re: Emacs as a command line tool Date: Tue, 17 Feb 2004 04:35:09 -0900 Organization: __________ Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <87brnxn81e.fld@barrow.com> References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1077025634 18081 80.91.224.253 (17 Feb 2004 13:47:14 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 17 Feb 2004 13:47:14 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Feb 17 14:47:08 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1At5Z6-0002fX-00 for ; Tue, 17 Feb 2004 14:47:08 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1At5Y4-0005HL-LX for geh-help-gnu-emacs@m.gmane.org; Tue, 17 Feb 2004 08:46:04 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!newshosting.com!nx01.iad01.newshosting.com!66.150.105.61.MISMATCH!newsfeed-west.nntpserver.com!hub1.meganetnews.com!nntpserver.com!falcon.america.net!eagle.america.net.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: gnus 5.10.6/XEmacs 21.4.15/Linux 2.6.0 Cancel-Lock: sha1:xZsxR6tgqV+RXrzkigqv4010CbY= Original-Lines: 67 Original-NNTP-Posting-Host: 209.124.156.193 Original-X-Trace: eagle.america.net 1077024953 209.124.156.193 (Tue, 17 Feb 2004 08:35:53 EST) Original-NNTP-Posting-Date: Tue, 17 Feb 2004 08:35:53 EST Original-Xref: shelby.stanford.edu gnu.emacs.help:120989 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:16938 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:16938 David Rasmussen 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 Ukpeagvik (Barrow, Alaska) floyd@barrow.com