[gnu.emacs] emacs file1 file2 ---> initiates emacs with multiple buffers.

paulr@sequent.UUCP (Paul Reger) (10/03/89)

Awhile back I posted to this group asking if I initiated emacs with
multiple file arguments:

emacs file1 file2 ... filen

How would I go about making emacs come up with 2 buffers or maybe just
the *Buffer List* menu.  I got a few responses and this one seems to
work the best for me.  I am not sure who to give the credit to, but
thank you (whoever you are)!!!!  Thought I would post this since it
works, is very convenient, and small (I have great respect for small
amounts of code that do very nice things....).

Enjoy:

(defun auto-buffer-menu ()
  ;; This code is slightly unclean; it relies on Emacs starting up with
  ;; exactly two buffers present: "*scratch*" and " *Minibuf-0*".
  (let ((list (buffer-list)))
    (cond ((> (length list) 4)
	   (buffer-menu t)
	   (delete-other-windows))
	  ((= (length list) 4)
	   (pop-to-buffer nil)))))

(if (cdr command-line-args)
    (setq command-line-args
	  (nconc command-line-args '("-f" "auto-buffer-menu"))))
-- 
			paulr    (Paul Reger)
	      Sequent Computer Systems, Beaverton Oregon
	     {uunet,ucbvax!rutgers!ogccse}!sequent!paulr

meissner@tiktok.dg.com (Michael Meissner) (10/09/89)

In article <22598@sequent.UUCP> paulr@sequent.UUCP (Paul Reger) writes:
| Awhile back I posted to this group asking if I initiated emacs with
| multiple file arguments:
| 
| emacs file1 file2 ... filen
| 
| How would I go about making emacs come up with 2 buffers or maybe just
| the *Buffer List* menu.  ...

However the auto-buffer-menu code as posted does contain an assumption
about how many buffers emacs starts with.  I tend to do things like
create a *server* buffer in my .emacs file when I automatically start
the server.  Also, the assumption might break when emacs version 19
comes out.  Here is a revised auto-buffer-menu, that actually checks
whether the buffers listed are connected to files (with the elisp
buffer-file-name function):

(defun auto-buffer-menu ()
  (let ((count 0) buffer (buf-list (buffer-list)))
    (while buf-list
      (setq buffer (car buf-list))
      (setq buf-list (cdr buf-list))
      (if (buffer-file-name buffer)
	  (setq count (+ count 1))))
    (cond ((> count 2)
	   (buffer-menu t)
	   (delete-other-windows))
	  ((= count 2)
	   (pop-to-buffer nil)))))

--
Michael Meissner, Data General.
Uucp:		...!mcnc!rti!xyzzy!meissner		If compiles were much
Internet:	meissner@dg-rtp.DG.COM			faster, when would we
Old Internet:	meissner%dg-rtp.DG.COM@relay.cs.net	have time for netnews?

nate@hobbes.intel.com (Nate Hess) (10/09/89)

In article <22598@sequent.UUCP>, paulr@sequent (Paul Reger) writes:
>How would I go about making emacs come up with 2 buffers or maybe just
>the *Buffer List* menu.  I got a few responses and this one seems to
>work the best for me.

You could always give this a whirl:

	emacs -f list-buffers -f delete-window

--woodstock
-- 
	   "What I like is when you're looking and thinking and looking
	   and thinking...and suddenly you wake up."   - Hobbes

woodstock@hobbes.intel.com   ...!{decwrl|hplabs!oliveb}!intelca!mipos3!nate