Function: cvs-temp-buffer

cvs-temp-buffer is a byte-compiled function defined in pcvs.el.gz.

Signature

(cvs-temp-buffer &optional CMD NORMAL NOSETUP)

Documentation

Create a temporary buffer to run CMD in.

If CMD is a string, use it to lookup cvs-buffer-name-alist to find the buffer name to be used and its major mode.

The selected window will not be changed. The new buffer will not maintain undo information and will be read-only unless NORMAL is non-nil. It will be emptied
(unless NOSETUP is non-nil) and its default-directory will be inherited
from the current buffer.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/pcvs.el.gz
(defun cvs-temp-buffer (&optional cmd normal nosetup)
  "Create a temporary buffer to run CMD in.
If CMD is a string, use it to lookup `cvs-buffer-name-alist' to find
the buffer name to be used and its major mode.

The selected window will not be changed.  The new buffer will not maintain undo
information and will be read-only unless NORMAL is non-nil.  It will be emptied
\(unless NOSETUP is non-nil) and its `default-directory' will be inherited
from the current buffer."
  (let* ((cvs-buf (current-buffer))
	 (info (cdr (assoc cmd cvs-buffer-name-alist)))
	 (name (eval (nth 0 info) `((cmd . ,cmd))))
	 (mode (nth 1 info))
	 (dir default-directory)
	 (buf (cond
	       (name (cvs-get-buffer-create name))
	       ((and (bufferp cvs-temp-buffer) (buffer-live-p cvs-temp-buffer))
		cvs-temp-buffer)
	       (t
                (setq-local cvs-temp-buffer
                            (cvs-get-buffer-create
                             (eval cvs-temp-buffer-name `((dir . ,dir)))
                             'noreuse))))))

    ;; Handle the potential pre-existing process.
    (let ((proc (get-buffer-process buf)))
      (when (and (not normal) (processp proc)
		 (memq (process-status proc) '(run stop)))
	(if cmd
	    ;; When CMD is specified, the buffer is normally shown to the
	    ;; user, so interrupting the process is not harmful.
	    ;; Use `delete-process' rather than `kill-process' otherwise
	    ;; the pending output of the process will still get inserted
	    ;; after we erase the buffer.
	    (delete-process proc)
	  (error "Can not run two cvs processes simultaneously"))))

    (if (not name) (kill-local-variable 'other-window-scroll-buffer)
      ;; Strangely, if no window is created, `display-buffer' ends up
      ;; doing a `switch-to-buffer' which does a `set-buffer', hence
      ;; the need for `save-excursion'.
      (unless nosetup (save-excursion (display-buffer buf)))
      ;; FIXME: this doesn't do the right thing if the user later on
      ;; does a `find-file-other-window' and `scroll-other-window'
      (setq-local other-window-scroll-buffer buf))

    (add-to-list 'cvs-temp-buffers buf)

    (with-current-buffer buf
      (setq buffer-read-only nil)
      (setq default-directory dir)
      (unless nosetup
        ;; Disable undo before calling erase-buffer since it may generate
        ;; a very large and unwanted undo record.
        (buffer-disable-undo)
        (erase-buffer))
      (setq-local cvs-buffer cvs-buf)
      ;;(cvs-minor-mode 1)
      (let ((lbd list-buffers-directory))
	(if (fboundp mode) (funcall mode) (fundamental-mode))
	(when lbd (setq list-buffers-directory lbd)))
      (cvs-minor-mode 1)
      ;;(setq-local cvs-buffer cvs-buf)
      (if normal
          (buffer-enable-undo)
	(setq buffer-read-only t)
	(buffer-disable-undo))
      buf)))