Function: defun-cvs-mode

defun-cvs-mode is a macro defined in pcvs.el.gz.

Signature

(defun-cvs-mode FUN ARGS DOCSTRING INTERACT &rest BODY)

Documentation

Define a function to be used in a *cvs* buffer.

This will look for a *cvs* buffer and execute BODY in it. Since the interactive arguments might need to be queried after switching to the *cvs* buffer, the generic code is rather ugly, but luckily we can often use simpler alternatives.

FUN can be either a symbol (i.e. STYLE is nil) or a cons (FUN . STYLE). ARGS and DOCSTRING are the normal argument list. INTERACT is the interactive specification or nil for non-commands.

STYLE can be either SIMPLE, NOARGS or DOUBLE. It's an error for it to have any other value, unless other details of the function make it clear what alternative to use.
- SIMPLE will get all the interactive arguments from the original buffer.
- NOARGS will get all the arguments from the *cvs* buffer and will
  always behave as if called interactively.
- DOUBLE is the generic case.

Source Code

;; Defined in /usr/src/emacs/lisp/vc/pcvs.el.gz
(defmacro defun-cvs-mode (fun args docstring interact &rest body)
  "Define a function to be used in a *cvs* buffer.
This will look for a *cvs* buffer and execute BODY in it.
Since the interactive arguments might need to be queried after
switching to the *cvs* buffer, the generic code is rather ugly,
but luckily we can often use simpler alternatives.

FUN can be either a symbol (i.e. STYLE is nil) or a cons (FUN . STYLE).
ARGS and DOCSTRING are the normal argument list.
INTERACT is the interactive specification or nil for non-commands.

STYLE can be either `SIMPLE', `NOARGS' or `DOUBLE'.  It's an error for it
to have any other value, unless other details of the function make it
clear what alternative to use.
- `SIMPLE' will get all the interactive arguments from the original buffer.
- `NOARGS' will get all the arguments from the *cvs* buffer and will
  always behave as if called interactively.
- `DOUBLE' is the generic case."
  (declare (debug (&define sexp lambda-list stringp
                           ("interactive" interactive) def-body))
	   (doc-string 3))
  (let ((style (cvs-cdr fun))
	(fun (cvs-car fun)))
    (cond
     ;; a trivial interaction, no need to move it
     ((or (eq style 'SIMPLE)
	  (null (nth 1 interact))
	  (stringp (nth 1 interact)))
      `(defun ,fun ,args ,docstring ,interact
	 (cvs-mode! (lambda () ,@body))))

     ;; fun is only called interactively:  move all the args to the inner fun
     ((eq style 'NOARGS)
      `(defun ,fun () ,docstring (interactive)
	 (cvs-mode! (lambda ,args ,interact ,@body))))

     ;; bad case
     ((eq style 'DOUBLE)
      (string-match ".*" docstring)
      (let ((line1 (match-string 0 docstring))
	    (fun-1 (intern (concat (symbol-name fun) "-1"))))
	`(progn
	   (defun ,fun-1 ,args
	     ,(concat docstring "\nThis function only works within a *cvs* buffer.
For interactive use, use `" (symbol-name fun) "' instead.")
	     ,interact
	     ,@body)
	   (put ',fun-1 'definition-name ',fun)
	   (defun ,fun ()
	     ,(concat line1 "\nWrapper function that switches to a *cvs* buffer
before calling the real function `" (symbol-name fun-1) "'.\n")
	     (interactive)
	     (cvs-mode! ',fun-1)))))

     (t (error "Unknown style %s in `defun-cvs-mode'" style)))))