Function: cookie-snarf

cookie-snarf is an autoloaded and byte-compiled function defined in cookie1.el.gz.

Signature

(cookie-snarf PHRASE-FILE &optional STARTMSG ENDMSG)

Documentation

Read the PHRASE-FILE, return it as a vector of strings.

Emit STARTMSG and ENDMSG before and after. Cache the result; second and subsequent calls on the same file won't go to disk.

Source Code

;; Defined in /usr/src/emacs/lisp/play/cookie1.el.gz
;;;###autoload
(defun cookie-snarf (phrase-file &optional startmsg endmsg)
  "Read the PHRASE-FILE, return it as a vector of strings.
Emit STARTMSG and ENDMSG before and after.  Cache the result; second
and subsequent calls on the same file won't go to disk."
  (setq phrase-file (cookie-check-file phrase-file))
  (let ((sym (intern-soft phrase-file cookie-cache)))
    (and sym (not (equal (symbol-function sym)
			 (file-attribute-modification-time
                          (file-attributes phrase-file))))
	 (yes-or-no-p (concat phrase-file
			      " has changed.  Read new contents? "))
	 (setq sym nil))
    (if sym
	(symbol-value sym)
      (setq sym (intern phrase-file cookie-cache))
      (if startmsg (message "%s" startmsg))
      (fset sym (file-attribute-modification-time
                 (file-attributes phrase-file)))
      (let (result)
	(with-temp-buffer
	  (insert-file-contents (expand-file-name phrase-file))
	  (re-search-forward cookie-delimiter)
	  (while (progn (skip-chars-forward " \t\n\r\f") (not (eobp)))
	    (let ((beg (point)))
	      (re-search-forward cookie-delimiter)
	      (setq result (cons (buffer-substring beg (match-beginning 0))
				 result)))))
	(if endmsg (message "%s" endmsg))
	(set sym (apply 'vector result))))))