 
 (defun smartwin--match-buffer (buffer-or-name)
   "Judge whether to use smartwin to show BUFFER-OR-NAME."
-  (let ((buffer (if (stringp buffer-or-name)
-                    (get-buffer buffer-or-name)
-                  buffer-or-name)))
+  (let ((buffer (get-buffer buffer-or-name)))
     (if buffer
         (let ((name (buffer-name buffer))
               (mode (buffer-local-value 'major-mode buffer)))

      (if (window-dedicated-p smart-win)
          (set-window-dedicated-p smart-win nil)))))

(defadvice kill-buffer
    (after smartwin-after-kill-buffer)
  "Try to insure smart buffer should not shown in normal window and vice versa."
  (let ((smart-win (smartwin--get-smart-window))
        (window (selected-window)))
    (if (eq smart-win window)
        ;; auto hide smart window if "*scratch*" is the last smart buffer and
        ;; not been modified
        (progn
          (let ((scratch-buffer (get-buffer "*scratch*"))
                (buffer-list (smartwin--make-smart-buffer-list)))
            (if (and (eq scratch-buffer (window-buffer smart-win))
                     (not buffer-list)
                     (not (buffer-modified-p scratch-buffer)))
                (smartwin-hide))))
      ;; to insure smart buffer not shown in normal window
      (let ((buffer (window-buffer window)))
        (if (smartwin--match-buffer buffer)
            (let ((normal-buffer-list (smartwin--make-normal-buffer-list)))
              (if normal-buffer-list
                  (set-window-buffer window (car normal-buffer-list))
                (set-window-buffer window (get-buffer "*scratch*")))
              ))))))

;;; Minor Mode


        (lisp-interaction-mode)
        (current-buffer)))))

(defun clear-scratch-buffer (&optional buffer-or-name)
  "Clear the scratch buffer and keep the scratch message.
If BUFFER-OR-NAME is not nil, treat is as scratch buffer."
  (interactive)
  (let ((buffer (if (not buffer-or-name)
                    (get-buffer "*scratch*")
                  (get-buffer buffer-or-name))))
    (when (eq buffer (current-buffer))
      (delete-region (point-min) (point-max))
      (insert initial-scratch-message)
      (goto-char (point-max)))))


(provide 'smartwin)
