unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Emacs as a command line tool
@ 2004-02-17 10:54 David Rasmussen
  2004-02-17 10:57 ` Billy O'Connor
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: David Rasmussen @ 2004-02-17 10:54 UTC (permalink / raw)


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?

/David

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

* Re: Emacs as a command line tool
  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 11:14 ` Roodwriter
  2004-02-17 13:35 ` Floyd Davidson
  2 siblings, 1 reply; 15+ messages in thread
From: Billy O'Connor @ 2004-02-17 10:57 UTC (permalink / raw)


David Rasmussen <david.rasmussen@gmx.net> writes:

> Is it possible to use the many emacs tools from the command line?
>
You bet, check this out:

http://mail.gnu.org/archive/html/bug-gnu-emacs/2002-08/msg00229.html

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

* Re: Emacs as a command line tool
  2004-02-17 10:57 ` Billy O'Connor
@ 2004-02-17 11:08   ` David Rasmussen
  2004-02-17 15:16     ` Pascal Bourguignon
  0 siblings, 1 reply; 15+ messages in thread
From: David Rasmussen @ 2004-02-17 11:08 UTC (permalink / raw)


Billy O'Connor wrote:
> David Rasmussen <david.rasmussen@gmx.net> writes:
> 
> 
>>Is it possible to use the many emacs tools from the command line?
>>
> 
> You bet, check this out:
> 
> http://mail.gnu.org/archive/html/bug-gnu-emacs/2002-08/msg00229.html
> 

Looks interesting, but I know next to nothing about Emacs Lisp, so I 
would like to just be able to call the functions I already know 
(untabify) without having to write lisp functions etc.

/David

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

* Re: Emacs as a command line tool
  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:14 ` Roodwriter
  2004-02-17 11:19   ` David Rasmussen
  2004-02-17 13:35 ` Floyd Davidson
  2 siblings, 1 reply; 15+ messages in thread
From: Roodwriter @ 2004-02-17 11:14 UTC (permalink / raw)


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?
> 
> /David


Assuming you're on Linux or unix, why not try expand on the command line? 
That converts tabs to spaces. To convert spaces to tabs use unexpand. 

--Rod

__________

Author of "Linux for Non-Geeks--Clear-eyed Answered for Practical Consumers" 
and "Boring Stories from Uncle Rod." Both are available at 
http://www.rodwriterpublishing.com/index.html

To reply by e-mail, take the extra "o" out of the name.

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

* Re: Emacs as a command line tool
  2004-02-17 11:14 ` Roodwriter
@ 2004-02-17 11:19   ` David Rasmussen
  2004-02-17 11:46     ` Joakim Hove
  0 siblings, 1 reply; 15+ messages in thread
From: David Rasmussen @ 2004-02-17 11:19 UTC (permalink / raw)


Roodwriter@core.com wrote:
> 
> Assuming you're on Linux or unix, why not try expand on the command line? 
> That converts tabs to spaces. To convert spaces to tabs use unexpand. 
> 

I considered that, but it just outputs the results to stdout, which 
makes it hard to use in batch runs. Or am I missing something?

/David

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

* Re: Emacs as a command line tool
  2004-02-17 11:19   ` David Rasmussen
@ 2004-02-17 11:46     ` Joakim Hove
  2004-02-17 12:06       ` David Rasmussen
  0 siblings, 1 reply; 15+ messages in thread
From: Joakim Hove @ 2004-02-17 11:46 UTC (permalink / raw)



David Rasmussen <david.rasmussen@gmx.net> writes:

> I considered that, but it just outputs the results to stdout, which
> makes it hard to use in batch runs. Or am I missing something?

Well, 

how about redirection:  

expand file > tmp_file ; mv tmp_file file


Here is an e-lisp solution:


(defun untabify-file (file)
  (find-file file)
  (untabify (point-min) (point-max))
  (save-buffer)
  (kill-buffer (current-buffer)))
  
(defun untabify-script ()
  (interactive)
  (dolist (file command-line-args-left)
    (untabify-file file)))


which can be invoked as follows:

bash% emacs -f untabify-script file1 file2 file3 ....


But, as you can see the use of emacs from the command-line will
typically require some lisp programming to write wrappers around the
emacs functions, like e.g. the function (untabify)

HTH - Joakim


-- 
  /--------------------------------------------------------------------\
 / Joakim Hove  / hove@bccs.no  /  (55 5) 84076       |                 \
 | Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 |
 | CMU                                                | 5231 Paradis    |
 \ Thormøhlensgt.55, 5020 Bergen.                     | 55 91 28 18     /
  \--------------------------------------------------------------------/

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

* Re: Emacs as a command line tool
  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-19  7:01         ` Emacs as a command line tool Roodwriter
  0 siblings, 2 replies; 15+ messages in thread
From: David Rasmussen @ 2004-02-17 12:06 UTC (permalink / raw)


Joakim Hove wrote:
> 
> how about redirection:  
> 
> expand file > tmp_file ; mv tmp_file file
> 

Sure, but that doesn't solve the problem with batch runs. I can't do

expand *.cpp

which would have been very easy.

/David

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

* Re: expand tabs in a shell
  2004-02-17 12:06       ` David Rasmussen
@ 2004-02-17 13:20         ` Bruce Ingalls
  2004-02-17 17:24           ` Bruce Ingalls
  2004-02-19  7:01         ` Emacs as a command line tool Roodwriter
  1 sibling, 1 reply; 15+ messages in thread
From: Bruce Ingalls @ 2004-02-17 13:20 UTC (permalink / raw)


David Rasmussen wrote:
> Joakim Hove wrote:
>> how about redirection: 
>> expand file > tmp_file ; mv tmp_file file
> 
> Sure, but that doesn't solve the problem with batch runs. I can't do
> 
> expand *.cpp
> 
> which would have been very easy.

#!/bin/zsh
#or choose a sufficiently powerful shell, such as bash

for file in *.cpp
do
  expand $file > tmp_file
  mv tmp_file $file
done

#See also nntp://comp.unix.shell

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

* Re: Emacs as a command line tool
  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:14 ` Roodwriter
@ 2004-02-17 13:35 ` Floyd Davidson
  2 siblings, 0 replies; 15+ messages in thread
From: Floyd Davidson @ 2004-02-17 13:35 UTC (permalink / raw)


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

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

* Re: Emacs as a command line tool
  2004-02-17 11:08   ` David Rasmussen
@ 2004-02-17 15:16     ` Pascal Bourguignon
  2004-02-17 16:02       ` David Rasmussen
  0 siblings, 1 reply; 15+ messages in thread
From: Pascal Bourguignon @ 2004-02-17 15:16 UTC (permalink / raw)



David Rasmussen <david.rasmussen@gmx.net> writes:

> Billy O'Connor wrote:
> > David Rasmussen <david.rasmussen@gmx.net> writes:
> >
> >>Is it possible to use the many emacs tools from the command line?
> >>
> > You bet, check this out:
> > http://mail.gnu.org/archive/html/bug-gnu-emacs/2002-08/msg00229.html
> >
> 
> Looks interesting, but I know next to nothing about Emacs Lisp, so I
> would like to just be able to call the functions I already know
> (untabify) without having to write lisp functions etc.

No.  You just  don't use a 25000 Watt power  pick without learning its
features and functions.

-- 
__Pascal_Bourguignon__                     http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/

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

* Re: Emacs as a command line tool
  2004-02-17 15:16     ` Pascal Bourguignon
@ 2004-02-17 16:02       ` David Rasmussen
  2004-02-17 17:06         ` Pascal Bourguignon
  0 siblings, 1 reply; 15+ messages in thread
From: David Rasmussen @ 2004-02-17 16:02 UTC (permalink / raw)


Pascal Bourguignon wrote:
> 
> No.  You just  don't use a 25000 Watt power  pick without learning its
> features and functions.
> 

There would be no problem in emacs having such simple command line 
features. But I guess it hasn't and that's fine too.

/David

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

* Re: Emacs as a command line tool
  2004-02-17 16:02       ` David Rasmussen
@ 2004-02-17 17:06         ` Pascal Bourguignon
  2004-02-19  0:29           ` Kevin Rodgers
  0 siblings, 1 reply; 15+ messages in thread
From: Pascal Bourguignon @ 2004-02-17 17:06 UTC (permalink / raw)



David Rasmussen <david.rasmussen@gmx.net> writes:

> Pascal Bourguignon wrote:
> > No.  You just  don't use a 25000 Watt power  pick without learning
> > its
> > features and functions.
> >
> 
> There would be no problem in emacs having such simple command line
> features. But I guess it hasn't and that's fine too.

Well, it has:

       -f function
               Execute the lisp function function.

to invoke easily a simple function.

But the problem is that  most functions and commands existing in emacs
are designed to  be passed parameters or to  be _interactive_.  If you
program your own batch functions, you can then invoke them easily with
this -f option (and with -batch and -l).


-- 
__Pascal_Bourguignon__                     http://www.informatimago.com/
There is no worse tyranny than to force a man to pay for what he doesn't
want merely because you think it would be good for him.--Robert Heinlein
http://www.theadvocates.org/

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

* Re: expand tabs in a shell
  2004-02-17 13:20         ` expand tabs in a shell Bruce Ingalls
@ 2004-02-17 17:24           ` Bruce Ingalls
  0 siblings, 0 replies; 15+ messages in thread
From: Bruce Ingalls @ 2004-02-17 17:24 UTC (permalink / raw)


>> Sure, but that doesn't solve the problem with batch runs. I can't do
>> expand *.cpp

Try also
	man xargs

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

* Re: Emacs as a command line tool
  2004-02-17 17:06         ` Pascal Bourguignon
@ 2004-02-19  0:29           ` Kevin Rodgers
  0 siblings, 0 replies; 15+ messages in thread
From: Kevin Rodgers @ 2004-02-19  0:29 UTC (permalink / raw)


Pascal Bourguignon wrote:

> Well, it has:
> 
>        -f function
>                Execute the lisp function function.
> 
> to invoke easily a simple function.
> 
> But the problem is that  most functions and commands existing in emacs
> are designed to  be passed parameters or to  be _interactive_.  If you
> program your own batch functions, you can then invoke them easily with
> this -f option (and with -batch and -l).

--eval '(function (quote symbol) "string" 123)'


e.g.


--eval '(ediff-files "file-1" "file-2")'
--eval '(call-interactively (quote find-file))'

-- 
Kevin Rodgers

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

* Re: Emacs as a command line tool
  2004-02-17 12:06       ` David Rasmussen
  2004-02-17 13:20         ` expand tabs in a shell Bruce Ingalls
@ 2004-02-19  7:01         ` Roodwriter
  1 sibling, 0 replies; 15+ messages in thread
From: Roodwriter @ 2004-02-19  7:01 UTC (permalink / raw)


David Rasmussen wrote:

> Joakim Hove wrote:
>> 
>> how about redirection:
>> 
>> expand file > tmp_file ; mv tmp_file file
>> 
> 
> Sure, but that doesn't solve the problem with batch runs. I can't do
> 
> expand *.cpp
> 
> which would have been very easy.
> 
> /David

It just occurred to me (when I was thinking of something else, oddly) an 
easy way to solve your problem--at least for me.

Make a macro.

First, use the dired function to set up the directory with all these files. 
Make sure they're set as whole lines. Then start the macro recording 
function.

Search for the cpp extension, stop the search, hit <return> to call the file 
up, untabify the file, save it, close it, returning to dired. End the 
macro.

Now all you have to do is tell the macro to repeat the required number of 
times.

--Rod

__________

Author of "Linux for Non-Geeks--Clear-eyed Answered for Practical Consumers" 
and "Boring Stories from Uncle Rod." Both are available at 
http://www.rodwriterpublishing.com/index.html

To reply by e-mail, take the extra "o" out of the name.

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

end of thread, other threads:[~2004-02-19  7:01 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).