                                      name
                                      tags
                                      edit-mode)
-       (setq evernote-note-guid (evernote-eval-command-result)
-             evernote-note-name name
-             evernote-note-tags tags
-             evernote-note-edit-mode edit-mode)
-       (evernote-mode)
-       (evernote-update-mode-line)
-       (set-buffer-modified-p nil)))))
+       (evernote-change-major-mode-from-note-name name)
+       (evernote-mode (evernote-eval-command-result)
+                      name
+                      tags
+                      edit-mode)
+       (set-buffer-modified-p nil))
+     t)))
 
 
 (defun evernote-write-note ()

   ((eq error-code evernote-error-quota-reached)      "Quota reached")
   ((eq error-code evernote-error-invalid-auth)       "Invalid auth")
   ((eq error-code evernote-error-auth-expired)       "Auth expired")
   ((eq error-code evernote-error-data-conflict)      "Data conflict")
   ((eq error-code evernote-error-enml-validation)    "Enml validation. Tried to save a note of invalid format.")
   ((eq error-code evernote-error-shared-unavailable) "Shared unavailable")))


        (read-string "New Saved search name:"
                     (evernote-assoc-cdr 'name search-attr))
        (read-string "New Query:"
                     (evernote-assoc-cdr 'query search-attr))))
     t)))


;;
;; Helper functions.
;;

;;(defun evernote-command-with-auth (func &rest args)
;;  "Add or remove tags from/to the note"
;;  (let ((error-code (catch 'error (apply func args))))
;;    (if (or (eq error-code evernote-error-invalid-auth)
;;            (eq error-code evernote-error-auth-expired))
;;        (let ((error-code (catch 'error (evernote-command-login))))
;;          (if (eq error-code t)
;;              (apply func args)
;;            (message "%s (%s)"
;;                     (evernote-error-message error-code)
;;                     (evernote-get-first-line
;;                      (evernote-get-command-result)))))
;;      (message "%s (%s)"
;;               (evernote-error-message error-code)
;;               (evernote-get-first-line
;;                (evernote-get-command-result))))))


(defun evernote-command-with-auth (func &rest args)
  "Add or remove tags from/to the note"
  (let ((error-code (catch 'error (apply func args))))
    (cond
     ((eq error-code t)
      t)
     ((or (eq error-code evernote-error-invalid-auth)
          (eq error-code evernote-error-auth-expired))
      (let ((error-code (catch 'error (evernote-command-login))))
        (if (eq error-code t)
            (progn
              (let ((error-code (catch 'error (apply func args))))
                (if (not (eq error-code t))
                    (evernote-output-error-message error-code))))
          (evernote-output-error-message error-code))))
     (t
      (evernote-output-error-message error-code)))))


(defun evernote-output-error-message (error-code)
  (message "%s (%s)"
           (evernote-error-message error-code)
           (evernote-get-first-line
            (evernote-get-command-result))))


(defun evernote-get-tag-alist (tag-command-out)
