 ;;                                  (cdr (assoc 'updated attr))
 ;;                                  (cdr (assoc 'name attr)))))
 ;;                  note-list))
-;;    (setq evernote-note-completion-prompt "Note:")
-;;    (cdr (assoc (read-from-minibuffer evernote-note-completion-prompt
-;;                                      nil evernote-read-note-name-map)
+;;    (setq evernote-minibuffer-note-completion-prompt "Note:")
+;;    (cdr (assoc (read-from-minibuffer evernote-minibuffer-note-completion-prompt
+;;                                      nil evernote-minibuffer-read-note-name-map)
 ;;                evernote-note-cands))))
 
 
-(defun evernote-note-completion ()
+(defun evernote-minibuffer-note-completion ()
   "Complete note name and display completion list"
   (interactive)
   (let (word result start)
-    (setq start (+ (string-width evernote-note-completion-prompt) 1))
+    (setq start (+ 1 (minibuffer-prompt-width)))
     (setq word (buffer-substring start (point)))
-                                        ;(evernote-tmp-message (concat "[" word "]"))
-    (setq result (try-completion word evernote-note-cands))
+    (setq result (try-completion word evernote-note-cands)) ;; from here.
+    ;(evernote-tmp-message (concat "[" word "]"))
     (cond
      ((eq result t) (evernote-tmp-message "[Sole Completion]"))
      ((eq result nil) (ding) (evernote-tmp-message "[No Match]"))
      ((string= result word)
-      (let (formatted-name-list)
-        (setq formatted-name-list
+      (let (displayed-name-and-name-map completion-buf)
+        (setq displayed-name-and-name-map
               (mapcar (lambda (name)
-                        (cdr (assoc name evernote-note-display-map)))
+                        (cons
+                         (cdr (assoc name evernote-note-display-map))
+                         name))
                       (all-completions word evernote-note-display-map)))
-        (with-output-to-temp-buffer "*Completions*"
-          (display-completion-list formatted-name-list))))
+        (setq completion-buf (get-buffer-create "*Evernote-Completions*"))
+        (save-excursion
+          (set-buffer completion-buf)
+          (evernote-display-completion-list displayed-name-and-name-map)
+          (setq evernote-search-mode-displayed-name-and-name-map displayed-name-and-name-map)
+          (evernote-search-mode))
+        (display-buffer completion-buf)))
      (t (delete-region start (point))
         (insert result)
         (if (eq t (try-completion result evernote-note-cands))
             nil
           (evernote-tmp-message "[Complete, but not unique]"))))))
+
+
+(defun evernote-minibuffer-note-input-finish ()
+  "Finish input note name"
+  (interactive)
+  (if (assoc
+       (buffer-substring
+        (progn
+          (goto-char (+ 1 (minibuffer-prompt-width)))
+          (point))
+        (progn
+          (end-of-line)
+          (point)))
+       evernote-note-cands)
+      (exit-minibuffer)
+    (evernote-tmp-message "[No Match]")))
 
 
 (defun evernote-tmp-message (msg)

         (lambda ()
           (evernote-open-note-common
            (evernote-command-get-note-list-from-tags
             (evernote-completing-read-multiple "Tags used for search (comma separated form. default search all tags):"
                                                (evernote-get-tag-cands (evernote-command-get-tag-list))
                                                nil t))))))
    (evernote-command-with-auth open-note-func)))



(define-key evernote-mode-map "\C-cer"   'evernote-rename-note)
(define-key evernote-mode-map "\C-ced"   'evernote-delete-note)

(defvar evernote-minibuffer-read-note-name-map
  (copy-keymap minibuffer-local-completion-map))

(define-key evernote-minibuffer-read-note-name-map [tab] 'evernote-minibuffer-note-completion)
(define-key evernote-minibuffer-read-note-name-map "\C-i" 'evernote-minibuffer-note-completion)
(define-key evernote-minibuffer-read-note-name-map "\C-m" 'evernote-minibuffer-note-input-finish)


(defvar evernote-search-mode-map (copy-keymap global-map)
  "Keymap used in evernote search mode.")
(define-key evernote-search-mode-map "\C-m" 'evernote-select-note-in-search-mode)

(defvar evernote-search-mode-displayed-name-and-name-map nil
  "Formatted name list variable used only in evernote-search-mode buffer")
(make-variable-buffer-local 'evernote-search-mode-displayed-name-and-name-map)


;;(defvar evernote-browsing-mode-map (copy-keymap global-map)
