[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Open files in a new frames from command line
From: |
Bingham, Jay |
Subject: |
RE: Open files in a new frames from command line |
Date: |
Mon, 2 Feb 2004 17:12:41 -0600 |
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-