Function: forms--intuit-from-file

forms--intuit-from-file is a byte-compiled function defined in forms.el.gz.

Signature

(forms--intuit-from-file)

Documentation

Get number of fields and a default form using the data file.

Source Code

;; Defined in /usr/src/emacs/lisp/forms.el.gz
(defun forms--intuit-from-file ()
  "Get number of fields and a default form using the data file."

  ;; If `forms-number-of-fields' is not set, get it from the data file.
  (if (null forms-number-of-fields)

      ;; Need a file to do this.
      (if (not (file-exists-p forms-file))
	  (error "Need existing file or explicit `forms-number-of-fields'")

	;; Visit the file and extract the first record.
	(setq forms--file-buffer (find-file-noselect forms-file))
	(let ((read-file-filter forms-read-file-filter)
	      (the-record))
	  (setq the-record
		(with-current-buffer forms--file-buffer
		  (let ((inhibit-read-only t))
		    (forms--run-functions read-file-filter))
		  (goto-char (point-min))
		  (forms--get-record)))

	  ;; This may be overkill, but try to avoid interference with
	  ;; the normal processing.
	  (kill-buffer forms--file-buffer)

	  ;; Count the number of fields in `the-record'.
	  (let ((start-pos 0)
		found-pos
		(field-sep-length (length forms-field-sep)))
	    (setq forms-number-of-fields 1)
	    (while (setq found-pos
			 (string-match forms-field-sep the-record start-pos))
	      (progn
		(setq forms-number-of-fields (1+ forms-number-of-fields))
		(setq start-pos (+ field-sep-length found-pos))))))))

  ;; Construct default format list.
  (setq forms-format-list (list "Forms file \"" forms-file "\".\n\n"))
  (let ((i 0))
    (while (<= (setq i (1+ i)) forms-number-of-fields)
      (setq forms-format-list
	    (append forms-format-list
		    (list (format "%4d: " i) i "\n"))))))