    (let ((note-attrs
           (enh-command-get-note-attrs-from-query
            (enh-read-saved-search-query))))
-     (enh-update-note-attrs-external note-attrs)
+     (enh-set-note-attrs note-attrs)
      (enh-base-open-note-common (enh-base-read-note-attr note-attrs)))))
 
 

(defun evernote-browser ()
  "Open an evernote browser"
  (interactive)
  (let ((buf (get-buffer evernote-browsing-mode-buffer-name)))
    (if buf
        (enutil-move-cursor-to-window buf)
      (switch-to-buffer (generate-new-buffer evernote-browsing-mode-buffer-name))
      (evernote-browsing-mode)
      (evernote-browsing-list-tags))))


(defun evernote-browsing-list-tags ()
  "List tags"
  (interactive)
  (when (eq major-mode 'evernote-browsing-mode)
    (enh-command-with-auth
     (enh-init-tag-info)
     (enh-browsing-push-page
      (enh-browsing-create-page 'tag-list "All Tags")))))


(defun evernote-browsing-list-searches ()
  "List saved searches"
  (interactive)
  (when (eq major-mode 'evernote-browsing-mode)
    (enh-command-with-auth
     (enh-init-search-info)
     (enh-browsing-push-page
      (enh-browsing-create-page 'search-list "All Saved Searches")))))


(defun evernote-browsing-search-notes ()
  "Search notes"
  (interactive)
  (when (eq major-mode 'evernote-browsing-mode)
    (let (note-attrs (query (read-string "Query:")))
      (enh-command-with-auth
       (setq note-attrs
             (enh-command-get-note-attrs-from-query query))
       (enh-set-note-attrs note-attrs)
       (enh-browsing-push-page
        (enh-browsing-create-page 'note-list
                                  (format "Query Result of: %s" query)
                                  note-attrs))))))


(defun evernote-browsing-prev-page ()
  "Move to the prev page"
  (interactive)
  (when (eq major-mode 'evernote-browsing-mode)
    (let ((prev-page (enh-browsing-get-prev-page)))
      (if prev-page
          (progn
            (setq enh-browsing-current-page prev-page)
            (enh-browsing-redraw-current-page))
        (message "[No more previous page]")))))



                    ,guid))))


(defun enh-browsing-setup-search-list-page ()
  "Insert saved search list into the browsing buffer"
  (when enh-browsing-page-widget-root
    (widget-delete enh-browsing-page-widget-root)
    (setq enh-browsing-page-widget-root nil))
  (let ((search-list nil))
    (maphash
     (lambda (guid attr)
       (let ((attr (enh-get-search-attr guid)))
         (enutil-push `(push-button
                        :tag ,(format "%-30s   %s"
                                      (enutil-aget 'name attr)
                                      (enutil-aget 'query attr))
                        :format "%[%t%]\n"
                        :notify enh-browsing-open-search
                        ,guid)
                      search-list)))
     enh-search-info)
    (setq enh-browsing-page-widget-root
          (apply 'widget-create
                 `(group
                   (item ,(format "%s\n\ntotal %d\n%-30s   %s\n\n"
                                  enh-browsing-page-description
                                  (hash-table-count enh-search-info)
                                  "Name"
                                  "Query"))
                   ,@(nreverse search-list)))))
  (widget-setup))


(defun enh-browsing-setup-note-list-page ()
  "Insert note list into the browsing buffer"
  (when enh-browsing-page-widget-root
    (widget-delete enh-browsing-page-widget-root)
    (setq enh-browsing-page-widget-root nil))
  (let ((guid-list enh-browsing-page-data)
        (note-attrs (make-hash-table :test #'equal))
        (note-list nil))
    (mapc
     (lambda (guid)
       (puthash guid (gethash guid enh-note-info) note-attrs))
     guid-list)
    (maphash
     (lambda (guid attr)
       (enutil-push `(push-button
                      :tag ,(format "%-30s   %-15s   %s"
                                    (enutil-aget 'updated attr)
                                    (enh-tag-guids-to-comma-separated-names
                                     (enutil-aget 'tags attr)
                                     15)
                                    (enutil-aget 'name attr))
                      :format "%[%t%]\n"
                      :notify enh-browsing-open-note
                      ,guid)
                    note-list))
     note-attrs)
    (setq enh-browsing-page-widget-root
          (apply 'widget-create
                 `(group
                   (item ,(format "%s\n\ntotal %d\n%-30s   %-15s   %s\n\n"
                                  enh-browsing-page-description
                                  (hash-table-count note-attrs)
                                  "Last Modified"
                                  "Tags"
                                  "Name"))
                   ,@(nreverse note-list)))))
  (widget-setup))


(defun enh-browsing-update-page-list ()
  (setq evernote-browsing-page-list
        (delete nil
                (mapcar (lambda (page)
                          (if (buffer-live-p page) page nil))
                        evernote-browsing-page-list)))
  (unless (memq evernote-browsing-current-page evernote-browsing-page-list)
    (setq evernote-browsing-current-page (car evernote-browsing-page-list))))


(defun enh-browsing-get-prev-page ()
  (cadr
   (memq evernote-browsing-current-page
         evernote-browsing-page-list)))


(defun enh-browsing-get-next-page ()
  (catch 'next-page
    (let (next-page)
      (mapc
       (lambda (page)
         (when (eq page evernote-browsing-current-page)
           (throw 'next-page next-page))
         (setq next-page page))
       evernote-browsing-page-list))))


(defun enh-browsing-get-page-of-type (type)
  "Get a page of the type in the browsing mode"
  (let ((result nil))
    (save-excursion
      (mapc
       (lambda (page)
         (set-buffer page)
         (when (eq enh-browsing-page-type type)
           (setq result page)))
       evernote-browsing-page-list))
    result))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
