 (define-key evernote-mode-map "\C-cer"   'evernote-rename-note)
 (define-key evernote-mode-map "\C-ced"   'evernote-delete-note)
 
-(defvar evernote-read-note-name-map
+(defvar evernote-minibuffer-read-note-name-map
   (copy-keymap minibuffer-local-completion-map))
 
-(define-key evernote-read-note-name-map [tab] 'evernote-note-completion)
-(define-key evernote-read-note-name-map "\C-i" 'evernote-note-completion)
+(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)


(provide 'evernote-mode)

;;(setq debug-on-error t)


;;                                  (cdr (assoc 'updated attr))
;;                                  (cdr (assoc 'name attr)))))
;;                  note-list))
;;    (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-minibuffer-note-completion ()
  "Complete note name and display completion list"
  (interactive)
  (let (word result start)
    (setq start (+ 1 (minibuffer-prompt-width)))
    (setq word (buffer-substring start (point)))
    (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 (displayed-name-and-name-map completion-buf)
        (setq displayed-name-and-name-map
              (mapcar (lambda (name)
                        (cons
                         (cdr (assoc name evernote-note-display-map))
                         name))
                      (all-completions word evernote-note-display-map)))
        (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)
