unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Open files in a new frames from command line
@ 2004-01-21  1:05 Michael B. Schmidt
  0 siblings, 0 replies; 11+ messages in thread
From: Michael B. Schmidt @ 2004-01-21  1:05 UTC (permalink / raw)


Hello,

I need to open multiple files to work with them. I use the command: 
"emacs foo bar baz". This open the file foo,bar and baz each in a new 
Buffer. Is there away (command line option,script) to open the files in 
frames instead of new Buffers? (I know that I can open one of the files 
and then open each file with c-x 5 f but this is to much work :-)))

Thank you

Michael

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

* Re: Open files in a new frames from command line
       [not found] <mailman.1057.1074645741.928.help-gnu-emacs@gnu.org>
@ 2004-01-21  1:11 ` Kin Cho
  2004-01-21  1:14 ` Christopher J. White
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Kin Cho @ 2004-01-21  1:11 UTC (permalink / raw)


Write a three line shell script emacs-nf:

file=$$
echo "(mapc (lambda (f) (find-file-other-frame (symbol-name f))) \'($*))" > $file
emacs -l $file &

-kin

"Michael B. Schmidt" <MiBSchmidt@gmx.de> writes:

> Hello,
> 
> I need to open multiple files to work with them. I use the
> command: "emacs foo bar baz". This open the file foo,bar and baz
> each in a new Buffer. Is there away (command line option,script)
> to open the files in frames instead of new Buffers? (I know that
> I can open one of the files and then open each file with c-x 5 f
> but this is to much work :-)))
> 
> Thank you
> 
> Michael

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

* Re: Open files in a new frames from command line
       [not found] <mailman.1057.1074645741.928.help-gnu-emacs@gnu.org>
  2004-01-21  1:11 ` Kin Cho
@ 2004-01-21  1:14 ` Christopher J. White
  2004-01-29  8:20 ` Kai Grossjohann
  2004-01-30 23:44 ` Oliver Scholz
  3 siblings, 0 replies; 11+ messages in thread
From: Christopher J. White @ 2004-01-21  1:14 UTC (permalink / raw)


Michael,

Unfortunately you didn't specify what OS you are working on.
You basically need to start a server process from emacs, then
use a command line client that communicates with the server
to open files.  The process is slightly different dependent on
the OS you are using.

Unix/linux:
In emacs: M-x server-start
>From shell: emacsclient <file>
Don't recall if it works to specify mor than one <file> on the line, but
if not you can easily write a shell script to do this.

Win:
Download and install gnuserv
Check out: http://www.gnu.org/software/emacs/windows/faq3.html#assoc

Mac OS:
Also uses gnuserv mechanism...can't be sure, but I think it
came with the SDK.

...cj

-- 
------------------------
-- Christopher J. White                                    
--
-- chris @ (---)
--   grierwhite . com
------------------------

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

* Re: Open files in a new frames from command line
       [not found] <mailman.1057.1074645741.928.help-gnu-emacs@gnu.org>
  2004-01-21  1:11 ` Kin Cho
  2004-01-21  1:14 ` Christopher J. White
@ 2004-01-29  8:20 ` Kai Grossjohann
  2004-02-04 22:25   ` Joe Casadonte
  2004-01-30 23:44 ` Oliver Scholz
  3 siblings, 1 reply; 11+ messages in thread
From: Kai Grossjohann @ 2004-01-29  8:20 UTC (permalink / raw)


"Michael B. Schmidt" <MiBSchmidt@gmx.de> writes:

> I need to open multiple files to work with them. I use the command:
> "emacs foo bar baz". This open the file foo,bar and baz each in a new
> Buffer. Is there away (command line option,script) to open the files
> in frames instead of new Buffers? (I know that I can open one of the
> files and then open each file with c-x 5 f but this is to much work
> :-)))

Normally, people start Emacs once and then leave it running for the
whole session.  With that usage pattern, using C-x 5 f does not seem
to be so terrible.

Kai

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

* RE: Open files in a new frames from command line
@ 2004-01-29 16:46 Bingham, Jay
  0 siblings, 0 replies; 11+ messages in thread
From: Bingham, Jay @ 2004-01-29 16:46 UTC (permalink / raw)


"Michael B. Schmidt" <MiBSchmidt@gmx.de> wrote:

> I need to open multiple files to work with them. I use the command:
> "emacs foo bar baz". This open the file foo,bar and baz each in a new
> Buffer. Is there away (command line option,script) to open the files
> in frames instead of new Buffers? (I know that I can open one of the
> files and then open each file with c-x 5 f but this is to much work
> :-)))

I have been watching this thread for several days and like others who
have responded I do not know of a command line option that will do what
you want.  Finally today it occurred to me that a function which I just
wrote (because I found doing multiple c-x 5 2's each time I started
emacs to be tedious) should be fairly simple to modify to do what you
describe.

The function that I wrote opens a number of frames based on the contents
of a list and positions the frames at specific locations on the screen.
It should not be difficult to adapt this function use a list of the
buffers associated with files that were opened with the command line as
the basis for the number of frames to create and to map the buffers in
list to the frames as they are opened.  Making it transparent would then
just be a matter of running the function from your .emacs file.  I do
not have the time right now to do those modifications but if you are
interested in doing it your self I will be glad to send the code to you.

-_
J_)
C_)ingham
.    HP - NonStop Austin Software & Services - Software Quality
Assurance
.    Austin, TX
. "Language is the apparel in which your thoughts parade in public.
.  Never clothe them in vulgar and shoddy attire."     -Dr. George W.
Crane-

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

* Re: Open files in a new frames from command line
       [not found] <mailman.1057.1074645741.928.help-gnu-emacs@gnu.org>
                   ` (2 preceding siblings ...)
  2004-01-29  8:20 ` Kai Grossjohann
@ 2004-01-30 23:44 ` Oliver Scholz
  2004-02-02 22:17   ` Kevin Rodgers
  3 siblings, 1 reply; 11+ messages in thread
From: Oliver Scholz @ 2004-01-30 23:44 UTC (permalink / raw)


"Michael B. Schmidt" <MiBSchmidt@gmx.de> writes:

> Hello,
>
> I need to open multiple files to work with them. I use the command:
> "emacs foo bar baz". This open the file foo,bar and baz each in a new
> Buffer. Is there away (command line option,script) to open the files
> in frames instead of new Buffers? (I know that I can open one of the
> files and then open each file with c-x 5 f but this is to much work
> :-)))

There is no such command line option, but you could make your own
command line option, if you put something like this (only slightly
tested) into your .emacs:

(defun my-is-option-p (str)
  "Return non-nil if STR is an command line option."
  (string-match "^--?"
		str))

(defun my-command-line-make-new-frames ()
  "Process open each files in a new frame.
This function is supposed to be an element of
`command-line-functions' (q.v.). Its functionality is triggered
if ARGI is \"--as-frames\" and opens each element in
COMMAND-LINE-ARGS-LEFT not starting with a slash as a file in a
separate frame."
  (when (string= argi "--as-frames")
    (unless (my-is-option-p (car command-line-args-left))
      (find-file (pop command-line-args-left)))
    (while (and command-line-args-left
		(not (my-is-option-p
		      (car command-line-args-left))))
      (find-file-other-frame
       (pop command-line-args-left))
      t)))

(push 'my-command-line-make-new-frames
      command-line-functions)


Use as 

emacs --as-frames lirum.txt larum.txt

    Oliver
-- 
12 Pluviôse an 212 de la Révolution
Liberté, Egalité, Fraternité!

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

* Re: Open files in a new frames from command line
  2004-01-30 23:44 ` Oliver Scholz
@ 2004-02-02 22:17   ` Kevin Rodgers
  2004-02-03  4:38     ` Oliver Scholz
  0 siblings, 1 reply; 11+ messages in thread
From: Kevin Rodgers @ 2004-02-02 22:17 UTC (permalink / raw)


Oliver Scholz wrote:

> There is no such command line option, but you could make your own
> command line option, if you put something like this (only slightly
> tested) into your .emacs:
> 
> (defun my-is-option-p (str)
>   "Return non-nil if STR is an command line option."
>   (string-match "^--?"
> 		str))
> 
> (defun my-command-line-make-new-frames ()
>   "Process open each files in a new frame.
> This function is supposed to be an element of
> `command-line-functions' (q.v.). Its functionality is triggered
> if ARGI is \"--as-frames\" and opens each element in
> COMMAND-LINE-ARGS-LEFT not starting with a slash as a file in a
> separate frame."
>   (when (string= argi "--as-frames")
>     (unless (my-is-option-p (car command-line-args-left))
>       (find-file (pop command-line-args-left)))
>     (while (and command-line-args-left
> 		(not (my-is-option-p
> 		      (car command-line-args-left))))
>       (find-file-other-frame
>        (pop command-line-args-left))
>       t)))
> 
> (push 'my-command-line-make-new-frames
>       command-line-functions)

It's a lot easier to use command-switch-alist:

(setq command-switch-alist
       (cons '("--other-frame" . find-file-other-frame-command-line-arg) ; -R
	    command-switch-alist))

(defun find-file-other-frame-command-line-arg (switch)
   "Visit next command line argument (after SWITCH) in a new frame."
   ;; (prog1 (car x) (setq x (cdr x))) == (pop x):
   (find-file-other-frame (prog1 (car command-line-args-left)
			   (setq command-line-args-left
				 (cdr command-line-args-left)))))

 > Use as
 >
 > emacs --as-frames lirum.txt larum.txt

Invoke as emacs --other-frame FILE ...

-- 
Kevin Rodgers

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

* RE: Open files in a new frames from command line
@ 2004-02-02 23:12 Bingham, Jay
  0 siblings, 0 replies; 11+ messages in thread
From: Bingham, Jay @ 2004-02-02 23:12 UTC (permalink / raw)


On Monday, February 02, 2004 at 4:18 PM Kevin Rodgers wrote

> Oliver Scholz wrote:
> 
>> There is no such command line option, but you could make your own
>> command line option, if you put something like this (only slightly
>> tested) into your .emacs:
>> 
>> (defun my-is-option-p (str)
>>   "Return non-nil if STR is an command line option."
>>   (string-match "^--?"
>> 		str))
>> 
>> (defun my-command-line-make-new-frames ()
>>   "Process open each files in a new frame.
>> This function is supposed to be an element of
>> `command-line-functions' (q.v.). Its functionality is triggered
>> if ARGI is \"--as-frames\" and opens each element in
>> COMMAND-LINE-ARGS-LEFT not starting with a slash as a file in a
>> separate frame."
>>   (when (string= argi "--as-frames")
>>     (unless (my-is-option-p (car command-line-args-left))
>>       (find-file (pop command-line-args-left)))
>>     (while (and command-line-args-left
>> 		(not (my-is-option-p
>> 		      (car command-line-args-left))))
>>       (find-file-other-frame
>>        (pop command-line-args-left))
>>       t)))
>> 
>> (push 'my-command-line-make-new-frames
>>       command-line-functions)
> 
> It's a lot easier to use command-switch-alist:
> 
> (setq command-switch-alist
>    (cons '("--other-frame" . find-file-other-frame-command-line-arg) ;
-R
>     command-switch-alist))

I agree it is a lot easier to use command-switch-alist, especially when
I found that the original suggestion does not work in emacs 21.1 or
20.4.
However I have a question about your implementation since my reading of
the documentation on command-switch-alist indicates that the hyphen is
not included in the CAR of the alist.  I don't know how that plays with
double hyphen options.

> (defun find-file-other-frame-command-line-arg (switch)
>    "Visit next command line argument (after SWITCH) in a new frame."
>    ;; (prog1 (car x) (setq x (cdr x))) == (pop x):
>    (find-file-other-frame (prog1 (car command-line-args-left)
> 			   (setq command-line-args-left
> 				 (cdr command-line-args-left)))))

If you are looking for easy, why would you want to type that big long
option before every file name?  Here is what I did to Oliver's function
to make it work with only one option that affects all the remaining file
names on the command line.

(setq
 command-switch-alist
 (append
  '(("fpf" . jcb-frame-per-file))))

 (defun jcb-frame-per-file (arg)
  "Open each file on the command line in a new frame.
This function is triggered by the '-fpf' command line option.
Each file on the command line that follows it is opened in its own
frame."
  (while (and command-line-args-left
             (not ((string-match "^--?" str)
                   (car command-line-args-left))))
    (find-file-other-frame
     (pop command-line-args-left) t)
    t))

>> Use as
>>
>> emacs --as-frames lirum.txt larum.txt
> 
> Invoke as emacs --other-frame FILE ...

Invoke as:
 emacs first-file -fpf second-file ...

if the -fpf option is before the first file name then n+1 frames are
opened and *scratch* is in the first frame.

-_
J_)
C_)ingham
.    HP - NonStop Austin Software & Services - Software Quality
Assurance
.    Austin, TX
. "Language is the apparel in which your thoughts parade in public.
.  Never clothe them in vulgar and shoddy attire."     -Dr. George W.
Crane-

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

* Re: Open files in a new frames from command line
  2004-02-02 22:17   ` Kevin Rodgers
@ 2004-02-03  4:38     ` Oliver Scholz
  0 siblings, 0 replies; 11+ messages in thread
From: Oliver Scholz @ 2004-02-03  4:38 UTC (permalink / raw)


Kevin Rodgers <ihs_4664@yahoo.com> writes:

> Oliver Scholz wrote:

[command-line-functions]


> It's a lot easier to use command-switch-alist:

[code]

Indeed. Nice! Thanks a lot.

    Oliver
-- 
15 Pluviôse an 212 de la Révolution
Liberté, Egalité, Fraternité!

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

* Re: Open files in a new frames from command line
       [not found] <mailman.1752.1075763607.928.help-gnu-emacs@gnu.org>
@ 2004-02-03 17:46 ` Kevin Rodgers
  0 siblings, 0 replies; 11+ messages in thread
From: Kevin Rodgers @ 2004-02-03 17:46 UTC (permalink / raw)


Bingham, Jay wrote:
 > On Monday, February 02, 2004 at 4:18 PM Kevin Rodgers wrote
 >>It's a lot easier to use command-switch-alist:
 >>
 >>(setq command-switch-alist
 >>      (cons '("--other-frame" . find-file-other-frame-command-line-arg)
 >>            command-switch-alist))
 >
 > I agree it is a lot easier to use command-switch-alist, especially
 > when I found that the original suggestion does not work in emacs 21.1
 > or 20.4.
 >
 > However I have a question about your implementation since my reading
 > of the documentation on command-switch-alist indicates that the hyphen
 > is not included in the CAR of the alist.  I don't know how that plays
 > with double hyphen options.

I assume you're alluding to its doc string:

| command-switch-alist's value is nil
|
| Documentation:
| Alist of command-line switches.
| Elements look like (SWITCH-STRING . HANDLER-FUNCTION).
| HANDLER-FUNCTION receives switch name as sole arg;
| remaining command-line args are in the variable `command-line-args-left'.
|
| Defined in `startup'.

I read that to mean whatever SWITCH-STRING you want to define, whether
"-foo", "--foo", or "---foo", etc. is what should be specified in
command-switch-alist.  It does say that HANDLER-FUNCTION receives the
switch name (vs. switch string), which could be interpreted to mean
"foo" in all those cases.  But a simple test proves otherwise, that
switch name means the same thing as switch string:

(defun foo-switch-handler (switch)
   (message "%s" switch))

(setq command-switch-alist
       (cons '("--foo" . foo-switch-handler) command-switch-alist))

The number of hyphens is irrelevant -- it can even be zero!  I just try
to follow the GNU convention that multicharacter (long) options should
be preceded by 2 hyphens.

 >>(defun find-file-other-frame-command-line-arg (switch)
 >>   "Visit next command line argument (after SWITCH) in a new frame."
 >>   ;; (prog1 (car x) (setq x (cdr x))) == (pop x):
 >>   (find-file-other-frame (prog1 (car command-line-args-left)
 >> 
		   (setq command-line-args-left
 >> 
			 (cdr command-line-args-left)))))
 >
 > If you are looking for easy, why would you want to type that big long
 > option before every file name?

Because I was looking for an easier implementation, and I think clarity
and readability are more important for ease of use.  If you want to
minimize typing at the command line, use a shell alias or function.

 > Here is what I did to Oliver's function to make it work with only one
 > option that affects all the remaining file names on the command line.
 >
 > (setq
 >  command-switch-alist
 >  (append
 >   '(("fpf" . jcb-frame-per-file))))
 >
 >  (defun jcb-frame-per-file (arg)
 >   "Open each file on the command line in a new frame.
 > This function is triggered by the '-fpf' command line option.
 > Each file on the command line that follows it is opened in its own
 > frame."
 >   (while (and command-line-args-left
 >              (not ((string-match "^--?" str)
 >                    (car command-line-args-left))))

That doesn't look syntactically correct.

 >     (find-file-other-frame
 >      (pop command-line-args-left) t)
 >     t))

Since command line switches don't necessarily begin with a hyphen, you
might want to test each remaining arg like this:

	(and command-line-args-left
	     (not (string-match "\\`-" (car command-line-args-left)))
	     (not (assoc (car command-line-args-left) command-switch-alist)))

 >>Invoke as emacs --other-frame FILE ...
 >
 > Invoke as:
 >  emacs first-file -fpf second-file ...
 >
 > if the -fpf option is before the first file name then n+1 frames are
 > opened and *scratch* is in the first frame.

Very nice.  Here's another way, but it's not quite as nice since it also
pops up a *Buffer List* window:

emacs --eval '(setq pop-up-frames t)' FILE ... \
       --eval '(setq pop-up-frames nil)'

That works best with something like this:

(add-hook 'find-file-hooks
	  (lambda ()
	    (set-window-dedicated-p (selected-window) t))
(add-hook 'find-file-not-found-hooks
	  (lambda ()
	    (set-window-dedicated-p (selected-window) t)
	    nil)

-- 
Kevin

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

* Re: Open files in a new frames from command line
  2004-01-29  8:20 ` Kai Grossjohann
@ 2004-02-04 22:25   ` Joe Casadonte
  0 siblings, 0 replies; 11+ messages in thread
From: Joe Casadonte @ 2004-02-04 22:25 UTC (permalink / raw)


"Michael B. Schmidt" <MiBSchmidt@gmx.de> writes:

> I need to open multiple files to work with them. I use the command:
> "emacs foo bar baz". This open the file foo,bar and baz each in a
> new Buffer. Is there away (command line option,script) to open the
> files in frames instead of new Buffers? (I know that I can open one
> of the files and then open each file with c-x 5 f but this is to
> much work :-)))

How about:

   gnudoit -q (find-file-other-frame \"c:/temp/foo\")

Works for me under Win2k.  Replace filename with a shell variable and
you're done.

--
Regards,

joe
Joe Casadonte
jcasadonte@northbound-train.com

------------------------------------------------------------------------------
         Llama Fresh Farms => http://www.northbound-train.com
   Gay Media Resource List => http://www.northbound-train.com/gaymedia.html
            Perl for Win32 => http://www.northbound-train.com/perlwin32.html
               Emacs Stuff => http://www.northbound-train.com/emacs.html
          Music CD Trading => http://www.northbound-train.com/cdr.html
------------------------------------------------------------------------------
                       Live Free, that's the message!
------------------------------------------------------------------------------

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

end of thread, other threads:[~2004-02-04 22:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-29 16:46 Open files in a new frames from command line Bingham, Jay
     [not found] <mailman.1752.1075763607.928.help-gnu-emacs@gnu.org>
2004-02-03 17:46 ` Kevin Rodgers
  -- strict thread matches above, loose matches on Subject: below --
2004-02-02 23:12 Bingham, Jay
     [not found] <mailman.1057.1074645741.928.help-gnu-emacs@gnu.org>
2004-01-21  1:11 ` Kin Cho
2004-01-21  1:14 ` Christopher J. White
2004-01-29  8:20 ` Kai Grossjohann
2004-02-04 22:25   ` Joe Casadonte
2004-01-30 23:44 ` Oliver Scholz
2004-02-02 22:17   ` Kevin Rodgers
2004-02-03  4:38     ` Oliver Scholz
2004-01-21  1:05 Michael B. Schmidt

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).