1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00

; * lisp/completion.el (load-completions-from-file): Simplify

Use a condition-case :success clause instead flags for control.
This commit is contained in:
Mattias Engdegård 2021-07-27 20:29:40 +02:00
parent 35610b870e
commit b4173443fb

View file

@ -1917,68 +1917,64 @@ If file is not specified, then use `save-completions-file-name'."
(clear-visited-file-modtime) (clear-visited-file-modtime)
(erase-buffer) (erase-buffer)
(let ((insert-okay-p nil) (let ((buffer (current-buffer))
(buffer (current-buffer))
string entry last-use-time string entry last-use-time
cmpl-entry cmpl-last-use-time cmpl-entry cmpl-last-use-time
(current-completion-source cmpl-source-init-file) (current-completion-source cmpl-source-init-file)
(total-in-file 0) (total-perm 0)) (total-in-file 0) (total-perm 0))
;; insert the file into a buffer ;; insert the file into a buffer
(condition-case nil (condition-case nil
(progn (insert-file-contents filename t) (insert-file-contents filename t)
(setq insert-okay-p t))
(file-error (file-error
(message "File error trying to load completion file %s." (message "File error trying to load completion file %s."
filename))) filename))
;; parse it (:success
(if insert-okay-p ;; parse it
(progn (goto-char (point-min))
(goto-char (point-min))
(condition-case nil (condition-case nil
(while t (while t
(setq entry (read buffer)) (setq entry (read buffer))
(setq total-in-file (1+ total-in-file)) (setq total-in-file (1+ total-in-file))
(cond (cond
((and (consp entry) ((and (consp entry)
(stringp (setq string (car entry))) (stringp (setq string (car entry)))
(cond (cond
((eq (setq last-use-time (cdr entry)) 'T) ((eq (setq last-use-time (cdr entry)) 'T)
;; handle case sensitivity ;; handle case sensitivity
(setq total-perm (1+ total-perm)) (setq total-perm (1+ total-perm))
(setq last-use-time t)) (setq last-use-time t))
((eq last-use-time t) ((eq last-use-time t)
(setq total-perm (1+ total-perm))) (setq total-perm (1+ total-perm)))
((integerp last-use-time)))) ((integerp last-use-time))))
;; Valid entry ;; Valid entry
;; add it in ;; add it in
(setq cmpl-last-use-time (setq cmpl-last-use-time
(completion-last-use-time (completion-last-use-time
(setq cmpl-entry (setq cmpl-entry
(add-completion-to-tail-if-new string)))) (add-completion-to-tail-if-new string))))
(if (or (eq last-use-time t) (if (or (eq last-use-time t)
(and (> last-use-time 1000);;backcompatibility (and (> last-use-time 1000);;backcompatibility
(not (eq cmpl-last-use-time t)) (not (eq cmpl-last-use-time t))
(or (not cmpl-last-use-time) (or (not cmpl-last-use-time)
;; more recent ;; more recent
(> last-use-time cmpl-last-use-time)))) (> last-use-time cmpl-last-use-time))))
;; update last-use-time ;; update last-use-time
(set-completion-last-use-time cmpl-entry last-use-time))) (set-completion-last-use-time cmpl-entry last-use-time)))
(t (t
;; Bad format ;; Bad format
(message "Error: invalid saved completion - %s" (message "Error: invalid saved completion - %s"
(prin1-to-string entry)) (prin1-to-string entry))
;; try to get back in sync ;; try to get back in sync
(search-forward "\n(")))) (search-forward "\n("))))
(search-failed (search-failed
(message "End of file while reading completions.")) (message "End of file while reading completions."))
(end-of-file (end-of-file
(if (= (point) (point-max)) (if (= (point) (point-max))
(if (not no-message-p) (if (not no-message-p)
(message "Loading completions from file %s . . . Done." (message "Loading completions from file %s . . . Done."
filename)) filename))
(message "End of file while reading completions.")))))) (message "End of file while reading completions."))))))
)))))) ))))))
(defun completion-initialize () (defun completion-initialize ()