[comp.emacs] switch-to-buffer NORECORD

eliot@phoenix.Princeton.EDU (Eliot Handelman) (02/12/89)

If I'm bapping around between two files that I'm editing and a lisp
process, I want the default value sent to switch-to-buffer to be
the last file visited, not the *lisp* buffer. It turns out that
switch to buffer has a second optional value, called NORECORD, which
should do what I want. Now if only I could figure out how to use it.

There has got to be some variable bound to the default buffer (the
last one visited), but what's it called? How do I prevent buffers
like *lisp* from getting bound to it? How do I make sure that it only
records buffers whose name ends in .lisp?

In case it's not clear what I'm looking for, here's an example:

1. I'm editing dog.lisp.
2. Now I go into the lisp process, called *lisp* -- the default buffer
   is now dog.lisp.
3. I now leave *lisp* and edit mazurka.lisp. the default buffer is now *lisp*.
   This is what I'm trying to prevent -- I want the default buffer to still
   be dog.lisp. I want whoever records the name of the last visted buffer
   (or however it works) to ignore everything that doesn't end in .lisp.

Help, anyone?

-Eliot
   

jr@bbn.com (John Robinson) (02/14/89)

In article <6314@phoenix.Princeton.EDU>, eliot@phoenix (Eliot Handelman) writes:
>If I'm bapping around between two files that I'm editing and a lisp
>process, I want the default value sent to switch-to-buffer to be
>the last file visited, not the *lisp* buffer. It turns out that
>switch to buffer has a second optional value, called NORECORD, which
>should do what I want. Now if only I could figure out how to use it.

I don't know how to do this interactively, but you could define a new
function:

  (defun bury-and-switch-to-buffer (to-buffer)
    "Select buffer BUFFER in the current window, burying window's
previoius buffer."
    (interactive "BBury current buffer and switch to buffer: ")
    (bury-buffer (current-buffer))
    (switch-to-buffer to-buffer nil))

And then do something like:

 (global-set-key "B" 'bury-and-switch-to-buffer)

Now, when you want to leave the *lisp* window and not come back to it,
use ^XB to pick its replacement.

One could get more fancy and make the burying behavior conditional on
whether a prefix argumenbt was provided, and then get it all on ^Xb
(normal switch-to-buffer), but hey, it's Monday.

(By the way, I found that the optional NORECORD argument to
switch-to-buffer seemed not to work.)
--
/jr
jr@bbn.com or bbn!jr

jr@bbn.com (John Robinson) (02/14/89)

In article <35945@bbn.COM>, jr@bbn (John Robinson) [that's me!] writes:
> (global-set-key "B" 'bury-and-switch-to-buffer)
>
>Now, when you want to leave the *lisp* window and not come back to it,
>use ^XB to pick its replacement.

Oops - the literal control-X in there disappeared in the mail.  Make that

  (global-set-key "^XB" 'bury-and-switch-to-buffer)

--
/jr
jr@bbn.com or bbn!jr

jr@bbn.com (John Robinson) (02/14/89)

In article <35945@bbn.COM>, jr@bbn (John Robinson) [that's me!] writes:
>In article <6314@phoenix.Princeton.EDU>, eliot@phoenix (Eliot Handelman) writes:
>>If I'm bapping around between two files that I'm editing and a lisp
>>process, I want the default value sent to switch-to-buffer to be
>>the last file visited, not the *lisp* buffer. It turns out that
>>switch to buffer has a second optional value, called NORECORD, which
>>should do what I want. Now if only I could figure out how to use it.

Stephen Gildea (gildea@bbn.com) wrote this function to replicate some
zwei (Symbolics lisp machine Zmacs edition of emacs) functionality:

(defun switch-to-previous-buffer (n)
  "Switch to Nth previously selected buffer.  N defaults to 2,
which switches to the most recently selected buffer.
If N is 1, repeated calls will cycle through all buffers, otherwise
the first N buffers on the buffer list are rotated."
  (interactive "P")
  (if (not n)
      (setq n 2)
    (setq n (prefix-numeric-value n)))
  (if (= n 1)
      (progn
	(bury-buffer (current-buffer))
	(setq n 2)))
  (let ((buffer-list (buffer-list)))
    (while (and (> n 1) buffer-list)
      (setq n (1- n))
      (setq buffer-list (cdr buffer-list))
      (while (eq (elt (buffer-name (car buffer-list)) 0) ? )
	(setq buffer-list (cdr buffer-list))))
    (if buffer-list
	(switch-to-buffer (car buffer-list))
      (error "There aren't that many buffers"))))

Suggested binding:

(global-set-key "\e\C-l" 'switch-to-previous-buffer)

Then, saying M-1 M-C-l at your *lisp* will have the desired effect.
--
/jr
jr@bbn.com or bbn!jr