Function: comint-get-source

comint-get-source is a byte-compiled function defined in comint.el.gz.

Signature

(comint-get-source PROMPT PREV-DIR/FILE SOURCE-MODES MUSTMATCH-P)

Documentation

Prompt for filenames in commands that process source files, e.g. loading or compiling a file. Provides a default, if there is one, and returns the result filename.

See comint-source-default for more on determining defaults.

PROMPT is the prompt string. PREV-DIR/FILE is the (DIRECTORY . FILE) pair from the last source processing command. SOURCE-MODES is a list of major modes used to determine what file buffers contain source files. (These
two arguments are used for determining defaults.) If MUSTMATCH-P is true,
then the filename reader will only accept a file that exists.

A typical use:
 (interactive (comint-get-source "Compile file" prev-lisp-dir/file
                                 '(lisp-mode) t))

Source Code

;; Defined in /usr/src/emacs/lisp/comint.el.gz
(defun comint-get-source (prompt prev-dir/file source-modes mustmatch-p)
  "Prompt for filenames in commands that process source files,
e.g. loading or compiling a file.
Provides a default, if there is one, and returns the result filename.

See `comint-source-default' for more on determining defaults.

PROMPT is the prompt string.  PREV-DIR/FILE is the (DIRECTORY . FILE) pair
from the last source processing command.  SOURCE-MODES is a list of major
modes used to determine what file buffers contain source files.  (These
two arguments are used for determining defaults.)  If MUSTMATCH-P is true,
then the filename reader will only accept a file that exists.

A typical use:
 (interactive (comint-get-source \"Compile file\" prev-lisp-dir/file
                                 \\='(lisp-mode) t))"
  (let* ((def (comint-source-default prev-dir/file source-modes))
	 (stringfile (comint-extract-string))
	 (sfile-p (and stringfile
		       (condition-case ()
			   (file-exists-p stringfile)
			 (error nil))
		       (not (file-directory-p stringfile))))
	 (defdir  (if sfile-p (file-name-directory stringfile)
                    (car def)))
	 (deffile (if sfile-p (file-name-nondirectory stringfile)
                    (cdr def)))
	 (ans (read-file-name (format-prompt prompt deffile)
			      defdir
			      (concat defdir deffile)
			      mustmatch-p)))
    (list (expand-file-name (substitute-in-file-name ans)))))