Skip to content

Commit

Permalink
Ignore empty smex-save-files; raise an error on invalid data
Browse files Browse the repository at this point in the history
  • Loading branch information
nonsequitur committed Sep 15, 2012
1 parent 4e60ffd commit 5a2403c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions smex.el
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,19 @@ This function provides temporary means to aid the transition."
(if (file-readable-p save-file)
(with-temp-buffer
(insert-file-contents save-file)
(setq smex-history (read (current-buffer))
smex-data (read (current-buffer))))
(condition-case nil
(setq smex-history (read (current-buffer))
smex-data (read (current-buffer)))
(error (if (save-file-not-empty-p)
(error "Invalid data in smex-save-file (%s). Can't restore history."
smex-save-file)
(if (not (boundp 'smex-history)) (setq smex-history))
(if (not (boundp 'smex-data)) (setq smex-data))))))
(setq smex-history nil smex-data nil))))

(defsubst save-file-not-empty-p ()
(string-match-p "\[^[:space:]\]" (buffer-string)))

(defun smex-save-history ()
"Updates `smex-history'"
(setq smex-history nil)
Expand Down

0 comments on commit 5a2403c

Please sign in to comment.