Function: load-completions-from-file

load-completions-from-file is an interactive and byte-compiled function defined in completion.el.gz.

Signature

(load-completions-from-file &optional FILENAME NO-MESSAGE-P)

Documentation

Load a completion init file FILENAME.

If file is not specified, then use save-completions-file-name.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/completion.el.gz
;;(defun auto-save-completions ()
;;  (if (and save-completions-flag enable-completion cmpl-initialized-p
;;	      *completion-auto-save-period*
;;	      (> cmpl-emacs-idle-time *completion-auto-save-period*)
;;	      cmpl-completions-accepted-p)
;;    (save-completions-to-file)))

;;(add-hook 'cmpl-emacs-idle-time-hooks 'auto-save-completions)

(defun load-completions-from-file (&optional filename no-message-p)
  "Load a completion init file FILENAME.
If file is not specified, then use `save-completions-file-name'."
  (interactive)
  (setq filename (expand-file-name (or filename save-completions-file-name)))
  (let* ((backup-filename (completion-backup-filename filename))
	 (backup-readable-p (file-readable-p backup-filename)))
    (if backup-readable-p (setq filename backup-filename))
    (if (file-readable-p filename)
	(progn
	  (if (not no-message-p)
	      (message "Loading completions from %sfile %s . . ."
		       (if backup-readable-p "backup " "") filename))
	  (with-current-buffer (get-buffer-create " *completion-save-buffer*")
	    (setq buffer-file-name filename)
	    ;; prepare the buffer to be modified
	    (clear-visited-file-modtime)
	    (erase-buffer)

	    (let ((buffer (current-buffer))
		  string entry last-use-time
		  cmpl-entry cmpl-last-use-time
		  (current-completion-source cmpl-source-init-file)
		  (total-in-file 0) (total-perm 0))
	      ;; insert the file into a buffer
	      (condition-case nil
		  (insert-file-contents filename t)
		(file-error
		 (message "File error trying to load completion file %s."
			  filename))
                (:success
                 ;; parse it
		 (goto-char (point-min))

		 (condition-case nil
		     (while t
		       (setq entry (read buffer))
		       (setq total-in-file (1+ total-in-file))
		       (cond
			((and (consp entry)
			      (stringp (setq string (car entry)))
			      (cond
			       ((eq (setq last-use-time (cdr entry)) 'T)
				;; handle case sensitivity
				(setq total-perm (1+ total-perm))
				(setq last-use-time t))
			       ((eq last-use-time t)
				(setq total-perm (1+ total-perm)))
			       ((integerp last-use-time))))
			 ;; Valid entry
			 ;; add it in
			 (setq cmpl-last-use-time
			       (completion-last-use-time
				(setq cmpl-entry
				      (add-completion-to-tail-if-new string))))
			 (if (or (eq last-use-time t)
				 (and (> last-use-time 1000);;backcompatibility
				      (not (eq cmpl-last-use-time t))
				      (or (not cmpl-last-use-time)
					  ;; more recent
					  (> last-use-time  cmpl-last-use-time))))
			     ;; update last-use-time
			     (set-completion-last-use-time cmpl-entry last-use-time)))
			(t
			 ;; Bad format
			 (message "Error: invalid saved completion - %s"
				  (prin1-to-string entry))
			 ;; try to get back in sync
			 (search-forward "\n("))))
		   (search-failed
		    (message "End of file while reading completions."))
		   (end-of-file
		    (if (= (point) (point-max))
			(if (not no-message-p)
			    (message "Loading completions from file %s . . . Done."
				     filename))
		      (message "End of file while reading completions."))))))
))))))