 
 (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))
-         (name (buffer-name buffer))
-         (mode (buffer-local-value 'major-mode buffer)))
-    (catch 'break
-      (dolist (config smartwin-buffers)
-        (let ((pattern (if (consp config) (car config) config))
-              (keywords (if (consp config) (cadr config) nil)))
-          (if (cond ((eq pattern t) (not (buffer-file-name buffer)))
-                    ((and (stringp pattern) (plist-get keywords :regexp))
-                     (string-match pattern name))
-                    ((stringp pattern)
-                     (string= pattern name))
-                    ((symbolp pattern)
-                     (eq pattern mode))
-                    ((functionp pattern)
-                     (funcall pattern buffer))
-                    (t (error "Invalid pattern: %s" pattern)))
-              (throw 'break config)))))))
+  (let ((buffer (if (stringp buffer-or-name)
+                    (get-buffer buffer-or-name)
+                  buffer-or-name)))
+    (if buffer
+        (let ((name (buffer-name buffer))
+              (mode (buffer-local-value 'major-mode buffer)))
+          (catch 'break
+            (dolist (config smartwin-buffers)
+              (let ((pattern (if (consp config) (car config) config))
+                    (keywords (if (consp config) (cadr config) nil)))
+                (if (cond ((eq pattern t) (not (buffer-file-name buffer)))
+                          ((and (stringp pattern) (plist-get keywords :regexp))
+                           (string-match pattern name))
+                          ((stringp pattern)
+                           (string= pattern name))
+                          ((symbolp pattern)
+                           (eq pattern mode))
+                          ((functionp pattern)
+                           (funcall pattern buffer))
+                          (t (error "Invalid pattern: %s" pattern)))
+                    (throw 'break config)))))))))
 
 (defun smartwin-smart-window-p (window)
   "To judge whether WINDOW is smart window or not."

              (ad-activate 'delete-window)
              (ad-activate 'delete-other-windows)
              (ad-activate 'balance-windows)
              (ad-activate 'select-window)
              ;;(ad-activate 'windmove-do-window-select)
              ;;(ad-activate 'evil-window-rotate-upwards)
              ;;(ad-activate 'evil-window-rotate-downwards)
              ;;(ad-activate 'kill-buffer)
              ;;(ad-activate 'quit-window)
              ;;(smartwin-show)
              )
          (setq display-buffer-alist (delete pair display-buffer-alist))
          (ad-deactivate 'switch-to-buffer)

            (smartwin-show))
        ad-do-it)
    (message "Attempt to move smart window")))

(defadvice delete-other-windows (around smartwin-delete-other-windows)
  "If in smart window, just enlarge it instead of `delete-other-windows'."
