Permalink
Browse files

Initialize file both in interactive and non interactive mode.

  • Loading branch information...
1 parent e4df396 commit 3873b31e707f09d4226c38b956fabf3ca8d1f708 @rejeep committed Apr 18, 2010
Showing with 14 additions and 10 deletions.
  1. +1 −0 keats-interactive.el
  2. +13 −10 keats.el
View
@@ -254,6 +254,7 @@ nil."
;;;###autoload
(defun keats-interactive-mode (title)
"Major mode to interactively manage Keats."
+ (keats-file-init)
(switch-to-buffer (get-buffer-create keats-interactive-temp-buffer))
(delete-region (point-min) (point-max))
(kill-all-local-variables)
View
@@ -83,6 +83,8 @@
;;; Code:
+(add-hook 'kill-emacs-hook 'keats-write)
+
(defconst keats-temp-buffer "*Keats*"
"Temp buffer.")
@@ -284,22 +286,23 @@ there has been enough changes. But only if `keats-save-at' is non nil."
(if (>= keats-save-count keats-save-at)
(keats-write))))
+(defun keats-file-init ()
+ "Initialization for keats file."
+ (if (keats-file-exists-p)
+ (if (keats-file-valid-p)
+ (keats-read)
+ (error "Keats file is invalid!"))
+ (with-temp-buffer
+ (erase-buffer)
+ (write-file keats-file))))
+
;;;###autoload
(define-minor-mode keats-mode
"Simple interface to Emacs keybinding cheats."
:init-value nil
:keymap keats-mode-map
(when keats-mode
- (unless (keats-file-exists-p)
- (switch-to-buffer (get-buffer-create keats-temp-buffer))
- (delete-region (point-min) (point-max))
- (write-file keats-file nil)
- (kill-this-buffer))
- (when (keats-file-valid-p)
- (keats-read))
- (add-hook 'kill-emacs-hook 'keats-write))
- (unless (keats-file-valid-p)
- (error "No valid keats file")))
+ (keats-file-init)))
(provide 'keats)

0 comments on commit 3873b31

Please sign in to comment.