Skip to content

Commit

Permalink
[Refactor] Move file loading code into function 'smex-load-save-file'
Browse files Browse the repository at this point in the history
  • Loading branch information
nonsequitur committed Sep 15, 2012
1 parent 83ebcf6 commit 4e60ffd
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions smex.el
Expand Up @@ -237,23 +237,27 @@ This function provides temporary means to aid the transition."
(defun smex-initialize ()
(interactive)
(unless ido-mode (smex-initialize-ido))
(smex-load-save-file)
(smex-detect-new-commands)
(smex-rebuild-cache)
(add-hook 'kill-emacs-hook 'smex-save-to-file)
(setq smex-initialized-p t))

(defun smex-initialize-ido ()
"Sets up a minimal Ido environment for `ido-completing-read'."
(ido-init-completion-maps)
(add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup))

(defun smex-load-save-file ()
"Loads `smex-history' and `smex-data' from `smex-save-file'"
(smex-detect-legacy-save-file)
(let ((save-file (expand-file-name smex-save-file)))
(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))))
(setq smex-history nil smex-data nil))
(smex-detect-new-commands)
(smex-rebuild-cache)
(add-hook 'kill-emacs-hook 'smex-save-to-file))
(setq smex-initialized-p t))

(defun smex-initialize-ido ()
"Sets up a minimal Ido environment for `ido-completing-read'."
(ido-init-completion-maps)
(add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup))
(setq smex-history nil smex-data nil))))

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

0 comments on commit 4e60ffd

Please sign in to comment.