              hydra-launch/modi/eww-im-feeling-lucky-and-exit
              modi/eww-browse-url-of-file
              hydra-launch/modi/eww-browse-url-of-file-and-exit)
+  :init
+  (progn
+    (bind-to-modi-map "e" #'eww-open-file))
   :config
   (progn
     ;; (setq eww-search-prefix                 "https://duckduckgo.com/html/?q=")

    (bind-keys
     :map eww-link-keymap
      ("w" . modi/eww-copy-url-dwim))))

;; Auto-refreshing *eww* buffer
;; http://emacs.stackexchange.com/a/2566/115
(use-package filenotify
  :commands (modi/eww-open-file-with-auto-reload)
  :config
  (progn
    (defvar modi/eww-file-notify-descriptors-list ()
      "List to store file-notify descriptor for all files that have an
associated auto-reloading eww buffer.")

    (defun modi/eww-open-file-with-auto-reload (file)
      "Open a file in eww and add `file-notify' watch for it."
      (interactive "fFile: ")
      (eww-open-file file)
      (file-notify-add-watch file
                             '(change attribute-change)
                             #'modi/file-notify-callback-eww-reload))

    (defun modi/file-notify-callback-eww-reload (event)
      "On getting triggered, switch to the eww buffer, reload and switch
back to the working buffer. Also save the `file-notify-descriptor' of the
triggering event."
      (let* ((working-buffer (buffer-name)))
        (switch-to-buffer-other-window "eww")
        (eww-reload)
        (switch-to-buffer-other-window working-buffer))
      ;; `(car event)' will return the event descriptor
      (add-to-list 'modi/eww-file-notify-descriptors-list (car event)))

    (defun modi/eww-quit-and-update-fn-descriptors ()
      "When quitting `eww', also remove any saved file-notify descriptors
specific to eww, while updating `modi/eww-file-notify-descriptors-list'."
      (interactive)
      (quit-window :kill)
      (dotimes (index (safe-length modi/eww-file-notify-descriptors-list))
        (file-notify-rm-watch (pop modi/eww-file-notify-descriptors-list))))

    (with-eval-after-load 'eww
      ;; Redefine the `q' binding in `eww-mode-map'
      (bind-keys
       :map eww-mode-map
        ("q" . modi/eww-quit-and-update-fn-descriptors )))))


(provide 'setup-eww)

;; Time-stamp: <2016-02-18 13:10:11 kmodi>

;; Eww - Emacs browser (needs emacs 24.4 or higher)

