Function: todo-validate-name

todo-validate-name is a byte-compiled function defined in todo-mode.el.gz.

Signature

(todo-validate-name NAME TYPE)

Documentation

Prompt for new NAME for TYPE until it is valid, then return it.

TYPE can be either of the symbols file or category.

Source Code

;; Defined in /usr/src/emacs/lisp/calendar/todo-mode.el.gz
(defun todo-validate-name (name type)
  "Prompt for new NAME for TYPE until it is valid, then return it.
TYPE can be either of the symbols `file' or `category'."
  (let ((categories todo-categories)
	(files (mapcar #'todo-short-file-name todo-files))
	prompt)
    (while
	(and
	 (cond ((string= "" name)
		(setq prompt
		      (cond ((eq type 'file)
			     (if files
				 "Enter a non-empty file name: "
			       ;; Empty string passed by todo-show to
			       ;; prompt for initial todo file.
			       (concat "Initial file name ["
				       todo-initial-file "]: ")))
			    ((eq type 'category)
			     (if categories
				 "Enter a non-empty category name: "
			       ;; Empty string passed by todo-show to
			       ;; prompt for initial category of a new
			       ;; todo file.
			       (concat "Initial category name ["
				       todo-initial-category "]: "))))))
	       ((string-match "\\`\\s-+\\'" name)
		(setq prompt
		      "Enter a name that does not contain only white space: "))
	       ((and (eq type 'file) (member name files))
		(setq prompt "Enter a non-existing file name: "))
	       ((and (eq type 'category) (assoc name categories))
		(setq prompt "Enter a non-existing category name: ")))
	 (setq name (if (or (and (eq type 'file) files)
			    (and (eq type 'category) categories))
			(completing-read prompt (cond ((eq type 'file)
						       files)
						      ((eq type 'category)
						       categories)))
		      ;; Offer default initial name.
		      (completing-read prompt (if (eq type 'file)
						  files
						categories)
				       nil nil (if (eq type 'file)
						   todo-initial-file
						 todo-initial-category))))))
    name))