<?xml version="1.0"?>
<paste-with-annotations>
  <paste>
    <number>
      <integer>10147</integer>
    </number>
    <user>
      <string>bpalmer</string>
    </user>
    <title>
      <string>A good way to avoid multiple ,@body ?</string>
    </title>
    <contents>
      <string>(defmacro with-renamed-buffer (buffer &amp;rest body)
  &quot;Rename a buffer to a unique name&quot;
  `(let* ((b (get-buffer buffer))
	  (name (buffer-name b)))
     (if b
	 (unwind-protect
	     (progn (set-buffer b)
		    (rename-uniquely)
		    ,@body)
	   (set-buffer b)
	   (rename-buffer b t))
       ,@body)))</string>
    </contents>
    <universal-time>
      <integer>3331126734</integer>
    </universal-time>
    <channel>
      <string>#xemacs</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <null/>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </paste>
  <annotation>
    <number>
      <integer>1</integer>
    </number>
    <user>
      <string>bpalmer</string>
    </user>
    <title>
      <string>slightly cleaned</string>
    </title>
    <contents>
      <string>(defmacro with-renamed-buffer (buffer &amp;rest body)
  &quot;Rename a buffer to a unique name temporarily, while BODY executes.
This is useful so that new shell buffers can be created without
running into any issues about an existing *shell* buffer, for example&quot;
  `(let* ((b (get-buffer buffer))
	  (name (buffer-name b)))
     (if b
	 (unwind-protect
	     (progn (with-current-buffer b
		      (rename-uniquely))
		    ,@body)
	   (with-current-buffer b
	     (rename-buffer name t)))
       ,@body)))</string>
    </contents>
    <universal-time>
      <integer>3331127840</integer>
    </universal-time>
    <channel>
      <string>#xemacs</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <null/>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </annotation>
  <annotation>
    <number>
      <integer>2</integer>
    </number>
    <user>
      <string>bpalmer</string>
    </user>
    <title>
      <string>seems to work, ignoring variable capture</string>
    </title>
    <contents>
      <string>(defmacro with-renamed-buffer (buffer &amp;rest body)
  &quot;Rename a buffer to a unique name temporarily, while BODY executes.
This is useful so that new shell buffers can be created without
running into any issues about an existing *shell* buffer, for example&quot;
  `(let* ((b (get-buffer ,buffer))
	  (name (buffer-name b)))
     (unwind-protect
	 (progn (when b (with-current-buffer b
			  (rename-uniquely)))
		,@body)
       (when (and b (buffer-live-p b))
	 (with-current-buffer b
	   (rename-buffer name t))))))
(put 'with-renamed-buffer 'lisp-indent-function 1)

(defun shell-current-directory ()
  &quot;Create a shell pertaining to the current directory.&quot;  
  (interactive)
  (let ((current-shell-buffer (directory-shell-buffer)))
    (if current-shell-buffer
	(pop-to-buffer current-shell-buffer)      
      (with-renamed-buffer &quot;*shell*&quot;
	(shell)
	(rename-buffer (directory-shell-buffer-name) t)))))</string>
    </contents>
    <universal-time>
      <integer>3331129222</integer>
    </universal-time>
    <channel>
      <string>#xemacs</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <null/>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </annotation>
  <annotation>
    <number>
      <integer>3</integer>
    </number>
    <user>
      <string>bpalmer</string>
    </user>
    <title>
      <string>with gensyms</string>
    </title>
    <contents>
      <string>(defmacro with-renamed-buffer (buffer &amp;rest body)
  &quot;Rename a buffer to a unique name temporarily, while BODY executes.
This is useful so that new shell buffers can be created without
running into any issues about an existing *shell* buffer, for example&quot;
  (let ((b (gensym))
	(bufname (gensym)))
  `(let* ((,b (get-buffer ,buffer))
	  (,bufname (buffer-name b)))
     (unwind-protect
	 (progn (when ,b (with-current-buffer ,b
			  (rename-uniquely)))
		,@body)
       (when (and ,b (buffer-live-p ,b))
	 (with-current-buffer ,b
	   (rename-buffer ,bufname t)))))))</string>
    </contents>
    <universal-time>
      <integer>3331129507</integer>
    </universal-time>
    <channel>
      <string>#xemacs</string>
    </channel>
    <colorization-mode>
      <string></string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <null/>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </annotation>
</paste-with-annotations>
