2013-06-10 Lars Magne Ingebrigtsen <larsi@gnus.org>
+ * eww.el (eww-submit): Make form submission work.
+
* shr.el (shr-descend): Allow other packages to override (or provide)
rendering of elements.
+ (shr-expand-url): Strip query strings from URLs before expanding them.
* eww.el: Don't require cl-lib.
(eww-tag-form): Start form support.
(eval-when-compile (require 'cl))
(require 'shr)
(require 'url)
+(require 'mm-url)
(defvar eww-current-url nil)
(defvar eww-history nil)
mode-name "eww")
(set (make-local-variable 'eww-current-url) 'author)
(set (make-local-variable 'browse-url-browser-function) 'eww-browse-url)
- (setq buffer-read-only t)
+ ;;(setq buffer-read-only t)
(use-local-map eww-mode-map))
(defun eww-browse-url (url &optional new-window)
'eww-form eww-form)))
(defun eww-tag-input (cont)
- (push (cons (cdr (assq :name cont))
- (cdr (assq :value cont)))
- eww-form)
(let ((start (point))
(widget (list
'editable-field
:size (string-to-number
(or (cdr (assq :size cont))
"40"))
- :value (or "____" (cdr (assq :value cont)) "")
- :action 'eww-submit)))
+ :value (or (cdr (assq :value cont)) "")
+ :action 'eww-submit
+ :name (cdr (assq :name cont))
+ :eww-form eww-form)))
(apply 'widget-create widget)
(shr-generic cont)
(put-text-property start (point) 'eww-widget widget)))
+(defun eww-submit (widget dummy)
+ (let ((form (getf (cdr widget) :eww-form))
+ values)
+ (dolist (overlay (overlays-in (point-min) (point-max)))
+ (let ((field (getf (overlay-properties overlay) 'field)))
+ (when (eq (getf (cdr field) :eww-form) form)
+ (let ((name (getf (cdr field) :name)))
+ (when name
+ (push (cons name (widget-value field))
+ values))))))
+ (let ((shr-base eww-current-url))
+ (eww-browse-url
+ (shr-expand-url
+ (concat
+ (getf form :action)
+ "?"
+ (mm-url-encode-www-form-urlencoded values)))))))
+
(defun eww-convert-widgets ()
(let ((start (point-min))
widget)
(not failed)))
(defun shr-expand-url (url)
- (cond
- ;; Absolute URL.
- ((or (not url)
- (string-match "\\`[a-z]*:" url)
- (not shr-base))
- url)
- ((and (string-match "\\`//" url)
- (string-match "\\`[a-z]*:" shr-base))
- (concat (match-string 0 shr-base) url))
- ((and (not (string-match "/\\'" shr-base))
- (not (string-match "\\`/" url)))
- (concat shr-base "/" url))
- (t
- (concat shr-base url))))
+ (if (or (not url)
+ (string-match "\\`[a-z]*:" url)
+ (not shr-base))
+ ;; Absolute URL.
+ url
+ (let ((base shr-base))
+ (when (string-match "^\\([^?]+\\)[?]" base)
+ (setq base (match-string 1 base)))
+ (cond
+ ((and (string-match "\\`//" url)
+ (string-match "\\`[a-z]*:" base))
+ (concat (match-string 0 base) url))
+ ((and (not (string-match "/\\'" base))
+ (not (string-match "\\`/" url)))
+ (concat base "/" url))
+ (t
+ (concat base url))))))
(defun shr-ensure-newline ()
(unless (zerop (current-column))