[gnus git] branch master updated: m0-7-141-gf03aee0 =8= (eww-tag-textarea): Implement <textarea>. ; (eww-toggle-checkbox): Implement radio/checkboxes. ; (eww-change-select): Implement changing the select value. ; (eww-select-display): Display the correct selected item. ; (eww-submit): Rewrite to use the new-style form methods. ; Allow editing text input fields again ; (eww-self-insert): Implement entering commands in text fields. ; Don't use widgets in eww
Lars Magne Ingebrigtsen <[email protected]>
| Newsgroups | gmane.emacs.gnus.cvs |
|---|---|
| Message-ID | <[email protected]> |
via f03aee0974ddab2895c85647ca516fad9cffe6be (commit)
via f4c8b1aff0fbfe2624cdf4236ecfccc682425935 (commit)
via 8778a4242ec83d017dcbfb4ebf6f1353104d9664 (commit)
via 0cf2f1a7667a1e1db8fef585272be0e3dae7c448 (commit)
via fadfad2034f6f6543f2e446b23798fe65d3fa7b2 (commit)
via 052856dcfdd2b83ba4c1f6f27fb236c1e27b6d4f (commit)
via ac910f70b3eab14b9341e9214cb0a5a5f3c218b6 (commit)
via 61fad87dc471e10644b4d193cf0638506040cbb8 (commit)
from a6f1723bb4f9df9521d8c42a8cf4f9ba0c9dee11 (commit)
- Log -----------------------------------------------------------------
commit f03aee0974ddab2895c85647ca516fad9cffe6be
Author: Lars Magne Ingebrigtsen <[email protected]>
Date: Wed Jun 19 21:11:51 2013 +0200
(eww-tag-textarea): Implement <textarea>.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index eb5fb7f..2a27f19 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -10,6 +10,8 @@
(eww-select-display): Display the correct selected item.
(eww-change-select): Implement changing the select value.
(eww-toggle-checkbox): Implement radio/checkboxes.
+ (eww-update-field): Fix compilation error.
+ (eww-tag-textarea): Implement <textarea>.
* shr.el (shr-urlify): Use `keymap' instead of `local-map' so that we
don't shadow mode-specific bindings.
diff --git a/lisp/eww.el b/lisp/eww.el
index 2c11218..7e5e2c5 100644
--- a/lisp/eww.el
+++ b/lisp/eww.el
@@ -385,6 +385,19 @@ or <a> tag."
(define-key map [backtab] 'shr-previous-link)
map))
+(defvar eww-textarea-map
+ (let ((map (make-keymap)))
+ (set-keymap-parent map text-mode-map)
+ (define-key map "\r" 'forward-line)
+ (define-key map [tab] 'shr-next-link)
+ (define-key map [backtab] 'shr-previous-link)
+ map))
+
+(defvar eww-select-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map "\r" 'eww-change-select)
+ map))
+
(defun eww-beginning-of-text ()
"Move to the start of the input field."
(interactive)
@@ -416,16 +429,6 @@ or <a> tag."
(1- (next-single-property-change
(point) 'eww-form nil (point-max))))
-(defvar eww-textarea-map
- (let ((map (make-sparse-keymap)))
- (set-keymap-parent map text-mode-map)
- map))
-
-(defvar eww-select-map
- (let ((map (make-sparse-keymap)))
- (define-key map "\r" 'eww-change-select)
- map))
-
(defun eww-tag-form (cont)
(let ((eww-form
(list (assq :method cont)
@@ -494,15 +497,19 @@ or <a> tag."
(insert " ")))
(defun eww-process-text-input (beg end length)
- (let ((form (get-text-property end 'eww-form))
- (properties (text-properties-at end)))
+ (let* ((form (get-text-property end 'eww-form))
+ (properties (text-properties-at end))
+ (type (plist-get form :type)))
(when (and form
- (member (plist-get form :type) '("text" "password" "textarea")))
+ (member type '("text" "password" "textarea")))
(cond
((zerop length)
;; Delete some text
(save-excursion
- (goto-char (eww-end-of-field))
+ (goto-char
+ (if (equal type "textarea")
+ (1- (line-end-position))
+ (eww-end-of-field)))
(let ((new (- end beg)))
(while (and (> new 0)
(eql (following-char) ? ))
@@ -512,7 +519,10 @@ or <a> tag."
((> length 0)
;; Add padding.
(save-excursion
- (goto-char (1+ (eww-end-of-field)))
+ (goto-char
+ (if (equal type "textarea")
+ (1- (line-end-position))
+ (eww-end-of-field)))
(let ((start (point)))
(insert (make-string length ? ))
(set-text-properties start (point) properties)))))
@@ -520,7 +530,7 @@ or <a> tag."
(eww-beginning-of-field)
(eww-end-of-field))))))
-(defun eww-form-textarea (cont)
+(defun eww-tag-textarea (cont)
(let ((start (point))
(value (or (cdr (assq :value cont)) ""))
(lines (string-to-number
@@ -536,7 +546,7 @@ or <a> tag."
(when (< (count-lines start (point)) lines)
(dotimes (i (- lines (count-lines start (point))))
(insert "\n")))
- (setq end (point))
+ (setq end (point-marker))
(goto-char start)
(while (< (point) end)
(end-of-line)
@@ -546,16 +556,18 @@ or <a> tag."
(add-face-text-property (line-beginning-position)
(point) 'eww-form-text)
(put-text-property (line-beginning-position) (point)
- 'keymap eww-text-map)))
+ 'local-map eww-textarea-map)
+ (forward-line 1))
(put-text-property start (point) 'eww-form
(list :eww-form eww-form
:value value
- :type (downcase (cdr (assq :type cont)))
- :name (cdr (assq :name cont)))))
+ :type "textarea"
+ :name (cdr (assq :name cont))))))
(defun eww-tag-input (cont)
(let ((type (downcase (or (cdr (assq :type cont))
- "text"))))
+ "text")))
+ (start (point)))
(cond
((or (equal type "checkbox")
(equal type "radio"))
@@ -578,10 +590,9 @@ or <a> tag."
:name name
:value (cdr (assq :value cont))))))))
(t
- (eww-form-text cont)))))
-
-(defun eww-tag-textarea (cont)
- (eww-form-textarea cont))
+ (eww-form-text cont)))
+ (unless (= start (point))
+ (put-text-property start (1+ start) 'help-echo "Input field"))))
(defun eww-tag-select (cont)
(shr-ensure-paragraph)
@@ -643,17 +654,16 @@ or <a> tag."
(completing-read "Change value: " options nil 'require-match))
(inhibit-read-only t))
(plist-put input :value (cdr (assoc-string display options t)))
- (goto-chat
- (eww-update-field
- (concat display
- (make-string (- (- end start) (length display)) ? ))))))
+ (goto-char
+ (eww-update-field display))))
(defun eww-update-field (string)
(let ((properties (text-properties-at (point)))
(start (eww-beginning-of-field))
(end (1+ (eww-end-of-field))))
(delete-region start end)
- (insert string)
+ (insert string
+ (make-string (- (- end start) (length string)) ? ))
(set-text-properties start end properties)
start))
@@ -700,11 +710,20 @@ or <a> tag."
(nreverse inputs)))
(defun eww-input-value (input)
- (let ((type (plist-get input :type)))
- (let ((value (plist-get input :value)))
- (if (string-match " +" value)
+ (let ((type (plist-get input :type))
+ (value (plist-get input :value)))
+ (cond
+ ((equal type "textarea")
+ (with-temp-buffer
+ (insert value)
+ (goto-char (point-min))
+ (while (re-search-forward "^ +\n\\| +$" nil t)
+ (replace-match "" t t))
+ (buffer-string)))
+ (t
+ (if (string-match " +\\'" value)
(substring value 0 (match-beginning 0))
- value))))
+ value)))))
(defun eww-submit ()
"Submit the current form."
commit f4c8b1aff0fbfe2624cdf4236ecfccc682425935
Author: Lars Magne Ingebrigtsen <[email protected]>
Date: Wed Jun 19 20:49:43 2013 +0200
(eww-toggle-checkbox): Implement radio/checkboxes.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index da52605..eb5fb7f 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -9,6 +9,7 @@
(eww-submit): Rewrite to use the new-style form methods.
(eww-select-display): Display the correct selected item.
(eww-change-select): Implement changing the select value.
+ (eww-toggle-checkbox): Implement radio/checkboxes.
* shr.el (shr-urlify): Use `keymap' instead of `local-map' so that we
don't shadow mode-specific bindings.
diff --git a/lisp/eww.el b/lisp/eww.el
index 300f09b..2c11218 100644
--- a/lisp/eww.el
+++ b/lisp/eww.el
@@ -467,6 +467,7 @@ or <a> tag."
(list :eww-form eww-form
:value (cdr (assq :value cont))
:type (downcase (cdr (assq :type cont)))
+ :checked (cdr (assq :checked cont))
:name (cdr (assq :name cont))))
(put-text-property start (point) 'keymap eww-checkbox-map)
(insert " ")))
@@ -489,7 +490,8 @@ or <a> tag."
(list :eww-form eww-form
:value value
:type type
- :name (cdr (assq :name cont))))))
+ :name (cdr (assq :name cont))))
+ (insert " ")))
(defun eww-process-text-input (beg end length)
(let ((form (get-text-property end 'eww-form))
@@ -627,8 +629,6 @@ or <a> tag."
"Change the value of the select drop-down menu under point."
(interactive)
(let* ((input (get-text-property (point) 'eww-form))
- (start (eww-beginning-of-field))
- (end (1+ (eww-end-of-field)))
(properties (text-properties-at (point)))
(completion-ignore-case t)
(options
@@ -643,25 +643,47 @@ or <a> tag."
(completing-read "Change value: " options nil 'require-match))
(inhibit-read-only t))
(plist-put input :value (cdr (assoc-string display options t)))
+ (goto-chat
+ (eww-update-field
+ (concat display
+ (make-string (- (- end start) (length display)) ? ))))))
+
+(defun eww-update-field (string)
+ (let ((properties (text-properties-at (point)))
+ (start (eww-beginning-of-field))
+ (end (1+ (eww-end-of-field))))
(delete-region start end)
- (insert display (make-string (- (- end start) (length display)) ? ))
+ (insert string)
(set-text-properties start end properties)
- (goto-char start)))
-
-(defun eww-click-radio (widget &rest ignore)
- (let ((form (plist-get (cdr widget) :eww-form))
- (name (plist-get (cdr widget) :name)))
- (when (equal (plist-get (cdr widget) :type) "radio")
- (if (widget-value widget)
- ;; Switch all the other radio buttons off.
- (dolist (overlay (overlays-in (point-min) (point-max)))
- (let ((field (plist-get (overlay-properties overlay) 'button)))
- (when (and (eq (plist-get (cdr field) :eww-form) form)
- (equal name (plist-get (cdr field) :name)))
- (unless (eq field widget)
- (widget-value-set field nil)))))
- (widget-value-set widget t)))
- (eww-fix-widget-keymap)))
+ start))
+
+(defun eww-toggle-checkbox ()
+ "Toggle the value of the checkbox under point."
+ (interactive)
+ (let* ((input (get-text-property (point) 'eww-form))
+ (type (plist-get input :type)))
+ (if (equal type "checkbox")
+ (goto-char
+ (1+
+ (if (plist-get input :checked)
+ (progn
+ (plist-put input :checked nil)
+ (eww-update-field "[ ]"))
+ (plist-put input :checked t)
+ (eww-update-field "[X]"))))
+ ;; Radio button. Switch all other buttons off.
+ (let ((name (plist-get input :name)))
+ (save-excursion
+ (dolist (elem (eww-inputs (plist-get input :eww-form)))
+ (when (equal (plist-get (cdr elem) :name) name)
+ (goto-char (car elem))
+ (if (not (eq (cdr elem) input))
+ (progn
+ (plist-put input :checked nil)
+ (eww-update-field "[ ]"))
+ (plist-put input :checked t)
+ (eww-update-field "[X]")))))
+ (forward-char 1)))))
(defun eww-inputs (form)
(let ((start (point-min))
@@ -679,12 +701,10 @@ or <a> tag."
(defun eww-input-value (input)
(let ((type (plist-get input :type)))
- (cond
- (t
(let ((value (plist-get input :value)))
(if (string-match " +" value)
(substring value 0 (match-beginning 0))
- value))))))
+ value))))
(defun eww-submit ()
"Submit the current form."
@@ -700,7 +720,7 @@ or <a> tag."
(name (plist-get input :name)))
(when name
(cond
- ((equal (plist-get input :type) "checkbox")
+ ((member (plist-get input :type) '("checkbox" "radio"))
(when (plist-get input :checked)
(push (cons name (plist-get input :value))
values)))
commit 8778a4242ec83d017dcbfb4ebf6f1353104d9664
Author: Lars Magne Ingebrigtsen <[email protected]>
Date: Wed Jun 19 20:27:25 2013 +0200
(eww-change-select): Implement changing the select value.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7c5e5eb..da52605 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -8,6 +8,7 @@
work.
(eww-submit): Rewrite to use the new-style form methods.
(eww-select-display): Display the correct selected item.
+ (eww-change-select): Implement changing the select value.
* shr.el (shr-urlify): Use `keymap' instead of `local-map' so that we
don't shadow mode-specific bindings.
diff --git a/lisp/eww.el b/lisp/eww.el
index bec2b0d..300f09b 100644
--- a/lisp/eww.el
+++ b/lisp/eww.el
@@ -402,8 +402,15 @@ or <a> tag."
(forward-char 1))))
(defun eww-beginning-of-field ()
+ (cond
+ ((bobp)
+ (point))
+ ((not (eq (get-text-property (point) 'eww-form)
+ (get-text-property (1- (point)) 'eww-form)))
+ (point))
+ (t
(previous-single-property-change
- (point) 'eww-form nil (point-min)))
+ (point) 'eww-form nil (point-min)))))
(defun eww-end-of-field ()
(1- (next-single-property-change
@@ -487,7 +494,8 @@ or <a> tag."
(defun eww-process-text-input (beg end length)
(let ((form (get-text-property end 'eww-form))
(properties (text-properties-at end)))
- (when form
+ (when (and form
+ (member (plist-get form :type) '("text" "password" "textarea")))
(cond
((zerop length)
;; Delete some text
@@ -615,6 +623,31 @@ or <a> tag."
(setq display (plist-get (cdr elem) :display))))
display))
+(defun eww-change-select ()
+ "Change the value of the select drop-down menu under point."
+ (interactive)
+ (let* ((input (get-text-property (point) 'eww-form))
+ (start (eww-beginning-of-field))
+ (end (1+ (eww-end-of-field)))
+ (properties (text-properties-at (point)))
+ (completion-ignore-case t)
+ (options
+ (delq nil
+ (mapcar (lambda (elem)
+ (and (consp elem)
+ (eq (car elem) 'item)
+ (cons (plist-get (cdr elem) :display)
+ (plist-get (cdr elem) :value))))
+ input)))
+ (display
+ (completing-read "Change value: " options nil 'require-match))
+ (inhibit-read-only t))
+ (plist-put input :value (cdr (assoc-string display options t)))
+ (delete-region start end)
+ (insert display (make-string (- (- end start) (length display)) ? ))
+ (set-text-properties start end properties)
+ (goto-char start)))
+
(defun eww-click-radio (widget &rest ignore)
(let ((form (plist-get (cdr widget) :eww-form))
(name (plist-get (cdr widget) :name)))
commit 0cf2f1a7667a1e1db8fef585272be0e3dae7c448
Author: Lars Magne Ingebrigtsen <[email protected]>
Date: Wed Jun 19 19:34:59 2013 +0200
(eww-select-display): Display the correct selected item.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 8b07fb1..7c5e5eb 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -7,6 +7,7 @@
(eww-process-text-input): New function to make text input field editing
work.
(eww-submit): Rewrite to use the new-style form methods.
+ (eww-select-display): Display the correct selected item.
* shr.el (shr-urlify): Use `keymap' instead of `local-map' so that we
don't shadow mode-specific bindings.
diff --git a/lisp/eww.el b/lisp/eww.el
index 91f0a40..bec2b0d 100644
--- a/lisp/eww.el
+++ b/lisp/eww.el
@@ -445,6 +445,7 @@ or <a> tag."
(put-text-property start (point) 'eww-form
(list :eww-form eww-form
:value value
+ :type "submit"
:name (cdr (assq :name cont))))
(put-text-property start (point) 'keymap eww-submit-map)
(insert " ")))
@@ -585,17 +586,18 @@ or <a> tag."
(nconc menu (list :value
(cdr (assq :value (cdr elem))))))
(let ((display (or (cdr (assq 'text (cdr elem))) "")))
- (setq max (max max (length display))))
+ (setq max (max max (length display)))
(push (list 'item
:value (cdr (assq :value (cdr elem)))
:display display)
- options)))
+ options))))
(when options
+ (setq options (nreverse options))
;; If we have no selected values, default to the first value.
(unless (plist-get menu :value)
(nconc menu (list :value (nth 2 (car options)))))
(nconc menu options)
- (let ((selected (eww-element-value menu)))
+ (let ((selected (eww-select-display menu)))
(insert selected
(make-string (- max (length selected)) ? )))
(put-text-property start (point) 'eww-form menu)
@@ -603,6 +605,16 @@ or <a> tag."
(put-text-property start (point) 'keymap eww-select-map)
(shr-ensure-paragraph))))
+(defun eww-select-display (select)
+ (let ((value (plist-get select :value))
+ display)
+ (dolist (elem select)
+ (when (and (consp elem)
+ (eq (car elem) 'item)
+ (equal value (plist-get (cdr elem) :value)))
+ (setq display (plist-get (cdr elem) :display))))
+ display))
+
(defun eww-click-radio (widget &rest ignore)
(let ((form (plist-get (cdr widget) :eww-form))
(name (plist-get (cdr widget) :name)))
@@ -635,8 +647,6 @@ or <a> tag."
(defun eww-input-value (input)
(let ((type (plist-get input :type)))
(cond
- ((equal type "select")
- )
(t
(let ((value (plist-get input :value)))
(if (string-match " +" value)
@@ -669,6 +679,7 @@ or <a> tag."
(and (not (eq input this-input))
(null next-submit)
(> input-start (point))))
+ (setq next-submit t)
(push (cons name (plist-get input :value))
values)))
(t
commit fadfad2034f6f6543f2e446b23798fe65d3fa7b2
Author: Lars Magne Ingebrigtsen <[email protected]>
Date: Wed Jun 19 19:09:13 2013 +0200
(eww-submit): Rewrite to use the new-style form methods.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index b96d414..8b07fb1 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -6,6 +6,7 @@
(eww-self-insert): Implement entering commands in text fields.
(eww-process-text-input): New function to make text input field editing
work.
+ (eww-submit): Rewrite to use the new-style form methods.
* shr.el (shr-urlify): Use `keymap' instead of `local-map' so that we
don't shadow mode-specific bindings.
diff --git a/lisp/eww.el b/lisp/eww.el
index e245927..91f0a40 100644
--- a/lisp/eww.el
+++ b/lisp/eww.el
@@ -388,33 +388,27 @@ or <a> tag."
(defun eww-beginning-of-text ()
"Move to the start of the input field."
(interactive)
- (goto-char (previous-single-property-change
- (point) 'eww-form nil (point-min))))
+ (goto-char (eww-beginning-of-field)))
(defun eww-end-of-text ()
"Move to the end of the text in the input field."
(interactive)
(goto-char (eww-end-of-field))
- (let ((start (previous-single-property-change
- (point) 'eww-form nil (point-min))))
+ (let ((start (eww-beginning-of-field)))
(while (and (equal (following-char) ? )
(> (point) start))
(forward-char -1))
(when (> (point) start)
(forward-char 1))))
+(defun eww-beginning-of-field ()
+ (previous-single-property-change
+ (point) 'eww-form nil (point-min)))
+
(defun eww-end-of-field ()
(1- (next-single-property-change
(point) 'eww-form nil (point-max))))
-(defun eww-self-insert ()
- "Insert the character you type."
- (interactive)
- (let ((inhibit-read-only t)
- (end (next-single-property-change
- (point) 'eww-form nil (point-max))))
- (insert last-command-event)))
-
(defvar eww-textarea-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map text-mode-map)
@@ -510,7 +504,10 @@ or <a> tag."
(goto-char (1+ (eww-end-of-field)))
(let ((start (point)))
(insert (make-string length ? ))
- (set-text-properties start (point) properties))))))))
+ (set-text-properties start (point) properties)))))
+ (plist-put form :value (buffer-substring-no-properties
+ (eww-beginning-of-field)
+ (eww-end-of-field))))))
(defun eww-form-textarea (cont)
(let ((start (point))
@@ -555,9 +552,20 @@ or <a> tag."
((equal type "submit")
(eww-form-submit cont))
((equal type "hidden")
- (nconc eww-form (list 'hidden
- :name (cdr (assq :name cont))
- :value (cdr (assq :value cont)))))
+ (let ((form eww-form)
+ (name (cdr (assq :name cont))))
+ ;; Don't add <input type=hidden> elements repeatedly.
+ (while (and form
+ (or (not (consp (car form)))
+ (not (eq (caar form) 'hidden))
+ (not (equal (plist-get (cdr (car form)) :name)
+ name))))
+ (setq form (cdr form)))
+ (unless form
+ (nconc eww-form (list
+ (list 'hidden
+ :name name
+ :value (cdr (assq :value cont))))))))
(t
(eww-form-text cont)))))
@@ -610,57 +618,68 @@ or <a> tag."
(widget-value-set widget t)))
(eww-fix-widget-keymap)))
-(defun eww-submit (widget &rest ignore)
- (let ((form (plist-get (cdr widget) :eww-form))
- values)
- (dolist (overlay (sort (overlays-in (point-min) (point-max))
+(defun eww-inputs (form)
+ (let ((start (point-min))
+ (inputs nil))
+ (while (and start
+ (< start (point-max)))
+ (when (or (get-text-property start 'eww-form)
+ (setq start (next-single-property-change start 'eww-form)))
+ (when (eq (plist-get (get-text-property start 'eww-form) :eww-form)
+ form)
+ (push (cons start (get-text-property start 'eww-form))
+ inputs))
+ (setq start (next-single-property-change start 'eww-form))))
+ (nreverse inputs)))
+
+(defun eww-input-value (input)
+ (let ((type (plist-get input :type)))
+ (cond
+ ((equal type "select")
+ )
+ (t
+ (let ((value (plist-get input :value)))
+ (if (string-match " +" value)
+ (substring value 0 (match-beginning 0))
+ value))))))
+
+(defun eww-submit ()
+ "Submit the current form."
+ (interactive)
+ (let* ((this-input (get-text-property (point) 'eww-form))
+ (form (plist-get this-input :eww-form))
+ values next-submit)
+ (dolist (elem (sort (eww-inputs form)
(lambda (o1 o2)
- (< (overlay-start o1) (overlay-start o2)))))
- (let ((field (or (plist-get (overlay-properties overlay) 'field)
- (plist-get (overlay-properties overlay) 'button))))
- (when (eq (plist-get (cdr field) :eww-form) form)
- (let ((name (plist-get (cdr field) :name)))
+ (< (car o1) (car o2)))))
+ (let* ((input (cdr elem))
+ (input-start (car elem))
+ (name (plist-get input :name)))
(when name
(cond
- ((eq (car field) 'checkbox)
- (when (widget-value field)
- (push (cons name (plist-get (cdr field) :checkbox-value))
+ ((equal (plist-get input :type) "checkbox")
+ (when (plist-get input :checked)
+ (push (cons name (plist-get input :value))
values)))
- ((eq (car field) 'push-button)
- ;; We want the values from buttons if we hit a button,
- ;; if it's the first button in the DOM after the field
- ;; hit ENTER on.
- (when (and (eq (car widget) 'push-button)
- (eq widget field))
- (push (cons name (widget-value field))
+ ((equal (plist-get input :type) "submit")
+ ;; We want the values from buttons if we hit a button if
+ ;; we hit enter on it, or if it's the first button after
+ ;; the field we did hit return on.
+ (when (or (eq input this-input)
+ (and (not (eq input this-input))
+ (null next-submit)
+ (> input-start (point))))
+ (push (cons name (plist-get input :value))
values)))
(t
- (push (cons name (widget-value field))
- values))))))))
+ (push (cons name (eww-input-value input))
+ values))))))
(dolist (elem form)
(when (and (consp elem)
(eq (car elem) 'hidden))
(push (cons (plist-get (cdr elem) :name)
(plist-get (cdr elem) :value))
values)))
- ;; If we hit ENTER in a non-button field, include the value of the
- ;; first submit button after it.
- (unless (eq (car widget) 'push-button)
- (let ((rest form)
- (name (plist-get (cdr widget) :name)))
- (when rest
- (while (and rest
- (or (not (consp (car rest)))
- (not (equal name (plist-get (cdar rest) :name)))))
- (pop rest)))
- (while rest
- (let ((elem (pop rest)))
- (when (and (consp (car rest))
- (eq (car elem) 'push-button))
- (push (cons (plist-get (cdr elem) :name)
- (plist-get (cdr elem) :value))
- values)
- (setq rest nil))))))
(if (and (stringp (cdr (assq :method form)))
(equal (downcase (cdr (assq :method form))) "post"))
(let ((url-request-method "POST")
commit 052856dcfdd2b83ba4c1f6f27fb236c1e27b6d4f
Author: Lars Magne Ingebrigtsen <[email protected]>
Date: Wed Jun 19 18:31:54 2013 +0200
Allow editing text input fields again
(eww-process-text-input): New function to make text input field editing
work.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 7a64828..b96d414 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -4,6 +4,8 @@
relying in widget.el. Using widget.el leads to too many
user interface inconsistencies.
(eww-self-insert): Implement entering commands in text fields.
+ (eww-process-text-input): New function to make text input field editing
+ work.
* shr.el (shr-urlify): Use `keymap' instead of `local-map' so that we
don't shadow mode-specific bindings.
diff --git a/lisp/eww.el b/lisp/eww.el
index 1756198..e245927 100644
--- a/lisp/eww.el
+++ b/lisp/eww.el
@@ -178,6 +178,7 @@
(setq eww-current-url url)
(eww-update-header-line-format)
(let ((inhibit-read-only t)
+ (after-change-functions nil)
(shr-width nil)
(shr-external-rendering-functions
'((title . eww-tag-title)
@@ -292,7 +293,9 @@
\\{eww-mode-map}"
(set (make-local-variable 'eww-current-url) 'author)
(set (make-local-variable 'browse-url-browser-function) 'eww-browse-url)
- (setq buffer-read-only t))
+ (set (make-local-variable 'after-change-functions) 'eww-process-text-input)
+ ;;(setq buffer-read-only t)
+ )
(defun eww-browse-url (url &optional new-window)
(when (and (equal major-mode 'eww-mode)
@@ -374,13 +377,12 @@ or <a> tag."
(defvar eww-text-map
(let ((map (make-keymap)))
- (suppress-keymap map)
(set-keymap-parent map text-mode-map)
- (substitute-key-definition
- 'undefined 'eww-self-insert map)
(define-key map "\r" 'eww-submit)
(define-key map [(control a)] 'eww-beginning-of-text)
(define-key map [(control e)] 'eww-end-of-text)
+ (define-key map [tab] 'shr-next-link)
+ (define-key map [backtab] 'shr-previous-link)
map))
(defun eww-beginning-of-text ()
@@ -392,13 +394,18 @@ or <a> tag."
(defun eww-end-of-text ()
"Move to the end of the text in the input field."
(interactive)
- (goto-char (1- (next-single-property-change
- (point) 'eww-form nil (point-max))))
+ (goto-char (eww-end-of-field))
(let ((start (previous-single-property-change
(point) 'eww-form nil (point-min))))
(while (and (equal (following-char) ? )
(> (point) start))
- (forward-char -1))))
+ (forward-char -1))
+ (when (> (point) start)
+ (forward-char 1))))
+
+(defun eww-end-of-field ()
+ (1- (next-single-property-change
+ (point) 'eww-form nil (point-max))))
(defun eww-self-insert ()
"Insert the character you type."
@@ -475,12 +482,36 @@ or <a> tag."
(insert (make-string (- width (length value)) ? )))
(put-text-property start (point) 'face 'eww-form-text)
(put-text-property start (point) 'local-map eww-text-map)
+ (put-text-property start (point) 'inhibit-read-only t)
(put-text-property start (point) 'eww-form
(list :eww-form eww-form
:value value
:type type
:name (cdr (assq :name cont))))))
+(defun eww-process-text-input (beg end length)
+ (let ((form (get-text-property end 'eww-form))
+ (properties (text-properties-at end)))
+ (when form
+ (cond
+ ((zerop length)
+ ;; Delete some text
+ (save-excursion
+ (goto-char (eww-end-of-field))
+ (let ((new (- end beg)))
+ (while (and (> new 0)
+ (eql (following-char) ? ))
+ (delete-region (point) (1+ (point)))
+ (setq new (1- new))))
+ (set-text-properties beg end properties)))
+ ((> length 0)
+ ;; Add padding.
+ (save-excursion
+ (goto-char (1+ (eww-end-of-field)))
+ (let ((start (point)))
+ (insert (make-string length ? ))
+ (set-text-properties start (point) properties))))))))
+
(defun eww-form-textarea (cont)
(let ((start (point))
(value (or (cdr (assq :value cont)) ""))
commit ac910f70b3eab14b9341e9214cb0a5a5f3c218b6
Author: Lars Magne Ingebrigtsen <[email protected]>
Date: Wed Jun 19 17:38:24 2013 +0200
(eww-self-insert): Implement entering commands in text fields.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index b2cfdfd..7a64828 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -3,6 +3,7 @@
* eww.el: Rewrite to implement form elements "by hand" instead of
relying in widget.el. Using widget.el leads to too many
user interface inconsistencies.
+ (eww-self-insert): Implement entering commands in text fields.
* shr.el (shr-urlify): Use `keymap' instead of `local-map' so that we
don't shadow mode-specific bindings.
diff --git a/lisp/eww.el b/lisp/eww.el
index 5a55500..1756198 100644
--- a/lisp/eww.el
+++ b/lisp/eww.el
@@ -46,7 +46,7 @@
(defface eww-form-submit
'((((type x w32 ns) (class color)) ; Like default mode line
:box (:line-width 2 :style released-button)
- :background "lightgrey" :foreground "black"))
+ :background "#808080" :foreground "black"))
"Face for eww buffer buttons."
:version "24.4"
:group 'eww)
@@ -68,7 +68,9 @@
:group 'eww)
(defface eww-form-text
- '((t (:background "red" :foreground "white")))
+ '((t (:background "#505050"
+ :foreground "white"
+ :box (:line-width 1))))
"Face for eww text inputs."
:version "24.4"
:group 'eww)
@@ -239,10 +241,12 @@
(when new-colors
(when fg
(add-face-text-property start end
- (list :foreground (cadr new-colors))))
+ (list :foreground (cadr new-colors))
+ t))
(when bg
(add-face-text-property start end
- (list :background (car new-colors))))))))
+ (list :background (car new-colors))
+ t))))))
(defun eww-display-raw (charset)
(let ((data (buffer-substring (point) (point-max))))
@@ -369,13 +373,41 @@ or <a> tag."
map))
(defvar eww-text-map
- (let ((map (make-sparse-keymap)))
+ (let ((map (make-keymap)))
+ (suppress-keymap map)
(set-keymap-parent map text-mode-map)
+ (substitute-key-definition
+ 'undefined 'eww-self-insert map)
(define-key map "\r" 'eww-submit)
(define-key map [(control a)] 'eww-beginning-of-text)
(define-key map [(control e)] 'eww-end-of-text)
map))
+(defun eww-beginning-of-text ()
+ "Move to the start of the input field."
+ (interactive)
+ (goto-char (previous-single-property-change
+ (point) 'eww-form nil (point-min))))
+
+(defun eww-end-of-text ()
+ "Move to the end of the text in the input field."
+ (interactive)
+ (goto-char (1- (next-single-property-change
+ (point) 'eww-form nil (point-max))))
+ (let ((start (previous-single-property-change
+ (point) 'eww-form nil (point-min))))
+ (while (and (equal (following-char) ? )
+ (> (point) start))
+ (forward-char -1))))
+
+(defun eww-self-insert ()
+ "Insert the character you type."
+ (interactive)
+ (let ((inhibit-read-only t)
+ (end (next-single-property-change
+ (point) 'eww-form nil (point-max))))
+ (insert last-command-event)))
+
(defvar eww-textarea-map
(let ((map (make-sparse-keymap)))
(set-keymap-parent map text-mode-map)
@@ -442,7 +474,7 @@ or <a> tag."
(when (< (length value) width)
(insert (make-string (- width (length value)) ? )))
(put-text-property start (point) 'face 'eww-form-text)
- (put-text-property start (point) 'keymap eww-text-map)
+ (put-text-property start (point) 'local-map eww-text-map)
(put-text-property start (point) 'eww-form
(list :eww-form eww-form
:value value
commit 61fad87dc471e10644b4d193cf0638506040cbb8
Author: Lars Magne Ingebrigtsen <[email protected]>
Date: Wed Jun 19 17:12:16 2013 +0200
Don't use widgets in eww
* eww.el: Rewrite to implement form elements "by hand" instead of
relying in widget.el. Using widget.el leads to too many
user interface inconsistencies.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 3bd4cb4..b2cfdfd 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,9 @@
2013-06-19 Lars Magne Ingebrigtsen <[email protected]>
+ * eww.el: Rewrite to implement form elements "by hand" instead of
+ relying in widget.el. Using widget.el leads to too many
+ user interface inconsistencies.
+
* shr.el (shr-urlify): Use `keymap' instead of `local-map' so that we
don't shadow mode-specific bindings.
diff --git a/lisp/eww.el b/lisp/eww.el
index a76cd16..5a55500 100644
--- a/lisp/eww.el
+++ b/lisp/eww.el
@@ -43,7 +43,7 @@
:group 'eww
:type 'string)
-(defface eww-button
+(defface eww-form-submit
'((((type x w32 ns) (class color)) ; Like default mode line
:box (:line-width 2 :style released-button)
:background "lightgrey" :foreground "black"))
@@ -51,6 +51,28 @@
:version "24.4"
:group 'eww)
+(defface eww-form-checkbox
+ '((((type x w32 ns) (class color)) ; Like default mode line
+ :box (:line-width 2 :style released-button)
+ :background "lightgrey" :foreground "black"))
+ "Face for eww buffer buttons."
+ :version "24.4"
+ :group 'eww)
+
+(defface eww-form-select
+ '((((type x w32 ns) (class color)) ; Like default mode line
+ :box (:line-width 2 :style released-button)
+ :background "lightgrey" :foreground "black"))
+ "Face for eww buffer buttons."
+ :version "24.4"
+ :group 'eww)
+
+(defface eww-form-text
+ '((t (:background "red" :foreground "white")))
+ "Face for eww text inputs."
+ :version "24.4"
+ :group 'eww)
+
(defvar eww-current-url nil)
(defvar eww-current-title ""
"Title of current page.")
@@ -164,8 +186,7 @@
(select . eww-tag-select)
(link . eww-tag-link)
(a . eww-tag-a))))
- (shr-insert-document document)
- (eww-convert-widgets))
+ (shr-insert-document document))
(goto-char (point-min))))
(defun eww-handle-link (cont)
@@ -240,7 +261,6 @@
(defun eww-setup-buffer ()
(pop-to-buffer (get-buffer-create "*eww*"))
(remove-overlays)
- (setq widget-field-list nil)
(let ((inhibit-read-only t))
(erase-buffer))
(eww-mode))
@@ -267,7 +287,8 @@
\\{eww-mode-map}"
(set (make-local-variable 'eww-current-url) 'author)
- (set (make-local-variable 'browse-url-browser-function) 'eww-browse-url))
+ (set (make-local-variable 'browse-url-browser-function) 'eww-browse-url)
+ (setq buffer-read-only t))
(defun eww-browse-url (url &optional new-window)
(when (and (equal major-mode 'eww-mode)
@@ -336,6 +357,35 @@ or <a> tag."
(defvar eww-form nil)
+(defvar eww-submit-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map "\r" 'eww-submit)
+ map))
+
+(defvar eww-checkbox-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map [space] 'eww-toggle-checkbox)
+ (define-key map "\r" 'eww-toggle-checkbox)
+ map))
+
+(defvar eww-text-map
+ (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map text-mode-map)
+ (define-key map "\r" 'eww-submit)
+ (define-key map [(control a)] 'eww-beginning-of-text)
+ (define-key map [(control e)] 'eww-end-of-text)
+ map))
+
+(defvar eww-textarea-map
+ (let ((map (make-sparse-keymap)))
+ (set-keymap-parent map text-mode-map)
+ map))
+
+(defvar eww-select-map
+ (let ((map (make-sparse-keymap)))
+ (define-key map "\r" 'eww-change-select)
+ map))
+
(defun eww-tag-form (cont)
(let ((eww-form
(list (assq :method cont)
@@ -350,92 +400,136 @@ or <a> tag."
(put-text-property start (1+ start)
'eww-form eww-form))))
-(defun eww-tag-input (cont)
- (let* ((start (point))
+(defun eww-form-submit (cont)
+ (let ((start (point))
+ (value (cdr (assq :value cont))))
+ (setq value
+ (if (zerop (length value))
+ "Submit"
+ value))
+ (insert value)
+ (add-face-text-property start (point) 'eww-form-submit)
+ (put-text-property start (point) 'eww-form
+ (list :eww-form eww-form
+ :value value
+ :name (cdr (assq :name cont))))
+ (put-text-property start (point) 'keymap eww-submit-map)
+ (insert " ")))
+
+(defun eww-form-checkbox (cont)
+ (let ((start (point)))
+ (if (cdr (assq :checked cont))
+ (insert "[X]")
+ (insert "[ ]"))
+ (add-face-text-property start (point) 'eww-form-checkbox)
+ (put-text-property start (point) 'eww-form
+ (list :eww-form eww-form
+ :value (cdr (assq :value cont))
+ :type (downcase (cdr (assq :type cont)))
+ :name (cdr (assq :name cont))))
+ (put-text-property start (point) 'keymap eww-checkbox-map)
+ (insert " ")))
+
+(defun eww-form-text (cont)
+ (let ((start (point))
(type (downcase (or (cdr (assq :type cont))
"text")))
- (value (cdr (assq :value cont)))
- (widget
+ (value (or (cdr (assq :value cont)) ""))
+ (width (string-to-number
+ (or (cdr (assq :size cont))
+ "40"))))
+ (insert value)
+ (when (< (length value) width)
+ (insert (make-string (- width (length value)) ? )))
+ (put-text-property start (point) 'face 'eww-form-text)
+ (put-text-property start (point) 'keymap eww-text-map)
+ (put-text-property start (point) 'eww-form
+ (list :eww-form eww-form
+ :value value
+ :type type
+ :name (cdr (assq :name cont))))))
+
+(defun eww-form-textarea (cont)
+ (let ((start (point))
+ (value (or (cdr (assq :value cont)) ""))
+ (lines (string-to-number
+ (or (cdr (assq :rows cont))
+ "10")))
+ (width (string-to-number
+ (or (cdr (assq :cols cont))
+ "10")))
+ end)
+ (shr-ensure-newline)
+ (insert value)
+ (shr-ensure-newline)
+ (when (< (count-lines start (point)) lines)
+ (dotimes (i (- lines (count-lines start (point))))
+ (insert "\n")))
+ (setq end (point))
+ (goto-char start)
+ (while (< (point) end)
+ (end-of-line)
+ (let ((pad (- width (- (point) (line-beginning-position)))))
+ (when (> pad 0)
+ (insert (make-string pad ? ))))
+ (add-face-text-property (line-beginning-position)
+ (point) 'eww-form-text)
+ (put-text-property (line-beginning-position) (point)
+ 'keymap eww-text-map)))
+ (put-text-property start (point) 'eww-form
+ (list :eww-form eww-form
+ :value value
+ :type (downcase (cdr (assq :type cont)))
+ :name (cdr (assq :name cont)))))
+
+(defun eww-tag-input (cont)
+ (let ((type (downcase (or (cdr (assq :type cont))
+ "text"))))
(cond
- ((or (equal type "submit")
- (equal type "image"))
- (list 'push-button
- :notify 'eww-submit
- :name (cdr (assq :name cont))
- :value (if (zerop (length value))
- "Submit"
- value)
- :eww-form eww-form
- (or (if (zerop (length value))
- "Submit"
- value))))
- ((or (equal type "radio")
- (equal type "checkbox"))
- (list 'checkbox
- :notify 'eww-click-radio
- :name (cdr (assq :name cont))
- :checkbox-value value
- :checkbox-type type
- :eww-form eww-form
- (cdr (assq :checked cont))))
+ ((or (equal type "checkbox")
+ (equal type "radio"))
+ (eww-form-checkbox cont))
+ ((equal type "submit")
+ (eww-form-submit cont))
((equal type "hidden")
- (list 'hidden
+ (nconc eww-form (list 'hidden
:name (cdr (assq :name cont))
- :value value))
+ :value (cdr (assq :value cont)))))
(t
- (list 'editable-field
- :size (string-to-number
- (or (cdr (assq :size cont))
- "40"))
- :value (or value "")
- :secret (and (equal type "password") ?*)
- :action 'eww-submit
- :name (cdr (assq :name cont))
- :eww-form eww-form)))))
- (nconc eww-form (list widget))
- (unless (eq (car widget) 'hidden)
- (apply 'widget-create widget)
- (put-text-property start (point) 'eww-widget widget)
- (insert " "))))
+ (eww-form-text cont)))))
(defun eww-tag-textarea (cont)
- (let* ((start (point))
- (widget
- (list 'text
- :size (string-to-number
- (or (cdr (assq :cols cont))
- "40"))
- :value (or (cdr (assq 'text cont)) "")
- :action 'eww-submit
- :name (cdr (assq :name cont))
- :eww-form eww-form)))
- (nconc eww-form (list widget))
- (apply 'widget-create widget)
- (put-text-property start (point) 'eww-widget widget)))
+ (eww-form-textarea cont))
(defun eww-tag-select (cont)
(shr-ensure-paragraph)
- (let ((menu (list 'menu-choice
- :name (cdr (assq :name cont))
+ (let ((menu (list :name (cdr (assq :name cont))
:eww-form eww-form))
(options nil)
- (start (point)))
+ (start (point))
+ (max 0))
(dolist (elem cont)
(when (eq (car elem) 'option)
(when (cdr (assq :selected (cdr elem)))
(nconc menu (list :value
(cdr (assq :value (cdr elem))))))
+ (let ((display (or (cdr (assq 'text (cdr elem))) "")))
+ (setq max (max max (length display))))
(push (list 'item
:value (cdr (assq :value (cdr elem)))
- :tag (cdr (assq 'text (cdr elem))))
+ :display display)
options)))
(when options
;; If we have no selected values, default to the first value.
- (unless (plist-get (cdr menu) :value)
+ (unless (plist-get menu :value)
(nconc menu (list :value (nth 2 (car options)))))
(nconc menu options)
- (apply 'widget-create menu)
- (put-text-property start (point) 'eww-widget menu)
+ (let ((selected (eww-element-value menu)))
+ (insert selected
+ (make-string (- max (length selected)) ? )))
+ (put-text-property start (point) 'eww-form menu)
+ (add-face-text-property start (point) 'eww-form-select)
+ (put-text-property start (point) 'keymap eww-select-map)
(shr-ensure-paragraph))))
(defun eww-click-radio (widget &rest ignore)
@@ -521,41 +615,6 @@ or <a> tag."
"?"
(mm-url-encode-www-form-urlencoded values))))))
-(defun eww-convert-widgets ()
- (let ((start (point-min))
- widget)
- ;; Some widgets come from different buffers (rendered for tables),
- ;; so we need to nix out the list of widgets and recreate them.
- (setq widget-field-list nil
- widget-field-new nil)
- (while (setq start (if (get-text-property start 'eww-widget)
- start
- (next-single-property-change start 'eww-widget)))
- (setq widget (get-text-property start 'eww-widget))
- (goto-char start)
- (let ((end (next-single-property-change start 'eww-widget)))
- (dolist (overlay (overlays-in start end))
- (when (or (plist-get (overlay-properties overlay) 'button)
- (plist-get (overlay-properties overlay) 'field))
- (delete-overlay overlay)))
- (delete-region start end))
- (when (and widget
- (not (eq (car widget) 'hidden)))
- (apply 'widget-create widget)
- (put-text-property start (point) 'help-echo
- (if (memq (car widget) '(text editable-field))
- "Input field"
- "Button"))
- (when (eq (car widget) 'push-button)
- (add-face-text-property start (point) 'eww-button t))))
- (widget-setup)
- (eww-fix-widget-keymap)))
-
-(defun eww-fix-widget-keymap ()
- (dolist (overlay (overlays-in (point-min) (point-max)))
- (when (plist-get (overlay-properties overlay) 'button)
- (overlay-put overlay 'local-map widget-keymap))))
-
(provide 'eww)
;;; eww.el ends here
-----------------------------------------------------------------------
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 | 13 ++
lisp/eww.el | 568 +++++++++++++++++++++++++++++++++++++++-----------------
2 files changed, 409 insertions(+), 172 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