[gnus git] branch master updated: m0-7-51-g3ceaa18 =1= Make form submission work

Lars Magne Ingebrigtsen <[email protected]>
Newsgroups gmane.emacs.gnus.cvs
Message-ID <[email protected]>
       via  3ceaa1815d15554f4dbcf4ded36686d1cda30c6d (commit)
      from  3534fb65e0efc34efc8f0e8f34ef007012786602 (commit)


- Log -----------------------------------------------------------------
commit 3ceaa1815d15554f4dbcf4ded36686d1cda30c6d
Author: Lars Magne Ingebrigtsen <[email protected]>
Date:   Mon Jun 10 15:43:56 2013 +0200

    Make form submission work
    
    * eww.el (eww-submit): Make form submission work.
    
    (shr-expand-url): Strip query strings from URLs before expanding them.

diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 3bb93f7..693bb92 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,7 +1,10 @@
 2013-06-10  Lars Magne Ingebrigtsen  <[email protected]>
 
+	* 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.
diff --git a/lisp/eww.el b/lisp/eww.el
index badf2a0..f1758a3 100644
--- a/lisp/eww.el
+++ b/lisp/eww.el
@@ -27,6 +27,7 @@
 (eval-when-compile (require 'cl))
 (require 'shr)
 (require 'url)
+(require 'mm-url)
 
 (defvar eww-current-url nil)
 (defvar eww-history nil)
@@ -135,7 +136,7 @@
 	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)
@@ -173,21 +174,38 @@
 		       '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)
diff --git a/lisp/shr.el b/lisp/shr.el
index 1d6a8ca..bf9f5a4 100644
--- a/lisp/shr.el
+++ b/lisp/shr.el
@@ -484,20 +484,23 @@ size, and full-buffer size."
     (not failed)))
 
 (defun shr-expand-url (url)
-  (cond
-   ;; Absolute URL.
-   ((or (not url)
+  (if (or (not url)
 	(string-match "\\`[a-z]*:" url)
 	(not shr-base))
-    url)
+      ;; 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]*:" shr-base))
-    (concat (match-string 0 shr-base) url))
-   ((and (not (string-match "/\\'" shr-base))
+	     (string-match "\\`[a-z]*:" base))
+	(concat (match-string 0 base) url))
+       ((and (not (string-match "/\\'" base))
 	 (not (string-match "\\`/" url)))
-    (concat shr-base "/" url))
+	(concat base "/" url))
    (t
-    (concat shr-base url))))
+	(concat base url))))))
 
 (defun shr-ensure-newline ()
   (unless (zerop (current-column))

-----------------------------------------------------------------------
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we listed those
revisions in full, above.

Summary of changes:
 lisp/ChangeLog |    3 +++
 lisp/eww.el    |   30 ++++++++++++++++++++++++------
 lisp/shr.el    |   31 +++++++++++++++++--------------
 3 files changed, 44 insertions(+), 20 deletions(-)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Gnus Project".

The branch, master has been updated


hooks/post-receive
-- 
Gnus Project
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.