1 ;;; eww.el --- Emacs Web Wowser
3 ;; Copyright (C) 2013 Free Software Foundation, Inc.
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 (eval-when-compile (require 'cl
))
28 (require 'format-spec
)
39 (defcustom eww-header-line-format
"%t: %u"
41 - %t is replaced by the title.
42 - %u is replaced by the URL."
47 (defcustom eww-search-prefix
"https://duckduckgo.com/html/?q="
48 "Prefix URL to search engine"
53 (defface eww-form-submit
54 '((((type x w32 ns
) (class color
)) ; Like default mode line
55 :box
(:line-width
2 :style released-button
)
56 :background
"#808080" :foreground
"black"))
57 "Face for eww buffer buttons."
61 (defface eww-form-checkbox
62 '((((type x w32 ns
) (class color
)) ; Like default mode line
63 :box
(:line-width
2 :style released-button
)
64 :background
"lightgrey" :foreground
"black"))
65 "Face for eww buffer buttons."
69 (defface eww-form-select
70 '((((type x w32 ns
) (class color
)) ; Like default mode line
71 :box
(:line-width
2 :style released-button
)
72 :background
"lightgrey" :foreground
"black"))
73 "Face for eww buffer buttons."
77 (defface eww-form-text
78 '((t (:background
"#505050"
80 :box
(:line-width
1))))
81 "Face for eww text inputs."
85 (defvar eww-current-url nil
)
86 (defvar eww-current-title
""
87 "Title of current page.")
88 (defvar eww-history nil
)
89 (defvar eww-history-position
0)
91 (defvar eww-next-url nil
)
92 (defvar eww-previous-url nil
)
93 (defvar eww-up-url nil
)
94 (defvar eww-home-url nil
)
95 (defvar eww-start-url nil
)
96 (defvar eww-contents-url nil
)
100 "Fetch URL and render the page.
101 If the input doesn't look like an URL or a domain name, the
102 word(s) will be searched for via `eww-search-prefix'."
103 (interactive "sEnter URL or keywords: ")
104 (if (and (= (length (split-string url
)) 1)
105 (> (length (split-string url
"\\.")) 1))
107 (unless (string-match-p "\\`[a-zA-Z][-a-zA-Z0-9+.]*://" url
)
108 (setq url
(concat "http://" url
)))
109 ;; some site don't redirect final /
110 (when (string= (url-filename (url-generic-parse-url url
)) "")
111 (setq url
(concat url
"/"))))
112 (unless (string-match-p "\\'file:" url
)
113 (setq url
(concat eww-search-prefix
114 (replace-regexp-in-string " " "+" url
)))))
115 (url-retrieve url
'eww-render
(list url
)))
118 (defun eww-open-file (file)
119 "Render a file using EWW."
120 (interactive "fFile: ")
121 (eww (concat "file://" (expand-file-name file
))))
123 (defun eww-render (status url
&optional point
)
124 (let ((redirect (plist-get status
:redirect
)))
126 (setq url redirect
)))
127 (set (make-local-variable 'eww-next-url
) nil
)
128 (set (make-local-variable 'eww-previous-url
) nil
)
129 (set (make-local-variable 'eww-up-url
) nil
)
130 (set (make-local-variable 'eww-home-url
) nil
)
131 (set (make-local-variable 'eww-start-url
) nil
)
132 (set (make-local-variable 'eww-contents-url
) nil
)
133 (let* ((headers (eww-parse-headers))
135 (and (string-match "#\\(.*\\)" url
)
136 (match-string 1 url
)))
138 (mail-header-parse-content-type
139 (or (cdr (assoc "content-type" headers
))
143 (or (cdr (assq 'charset
(cdr content-type
)))
144 (eww-detect-charset (equal (car content-type
)
147 (data-buffer (current-buffer)))
151 ((equal (car content-type
) "text/html")
152 (eww-display-html charset url
))
153 ((string-match "^image/" (car content-type
))
156 (eww-display-raw charset
)))
161 (let ((point (next-single-property-change
162 (point-min) 'shr-target-id
)))
164 (goto-char (1+ point
)))))))
165 (kill-buffer data-buffer
))))
167 (defun eww-parse-headers ()
169 (goto-char (point-min))
170 (while (and (not (eobp))
172 (when (looking-at "\\([^:]+\\): *\\(.*\\)")
173 (push (cons (downcase (match-string 1))
181 (defun eww-detect-charset (html-p)
182 (let ((case-fold-search t
)
186 "<meta[\t\n\r ]+[^>]*charset=\"?\\([^\t\n\r \"/>]+\\)[\\\"'.*]" nil t
)
190 "[\t\n\r ]*<\\?xml[\t\n\r ]+[^>]*encoding=\"\\([^\"]+\\)")
193 (defun eww-display-html (charset url
)
194 (unless (eq charset
'utf8
)
195 (decode-coding-region (point) (point-max) charset
))
198 'base
(list (cons 'href url
))
199 (libxml-parse-html-region (point) (point-max)))))
201 (setq eww-current-url url
)
202 (eww-update-header-line-format)
203 (let ((inhibit-read-only t
)
204 (after-change-functions nil
)
206 (shr-external-rendering-functions
207 '((title . eww-tag-title
)
208 (form . eww-tag-form
)
209 (input . eww-tag-input
)
210 (textarea . eww-tag-textarea
)
211 (body . eww-tag-body
)
212 (select . eww-tag-select
)
213 (link . eww-tag-link
)
215 (shr-insert-document document
))
216 (goto-char (point-min))))
218 (defun eww-handle-link (cont)
219 (let* ((rel (assq :rel cont
))
220 (href (assq :href cont
))
222 ;; The text associated with :rel is case-insensitive.
223 (if rel
(downcase (cdr rel
)))
224 '(("next" . eww-next-url
)
225 ;; Texinfo uses "previous", but HTML specifies
226 ;; "prev", so recognize both.
227 ("previous" . eww-previous-url
)
228 ("prev" . eww-previous-url
)
229 ;; HTML specifies "start" but also "contents",
230 ;; and Gtk seems to use "home". Recognize
231 ;; them all; but store them in different
232 ;; variables so that we can readily choose the
234 ("start" . eww-start-url
)
235 ("home" . eww-home-url
)
236 ("contents" . eww-contents-url
)
237 ("up" . eww-up-url
)))))
240 (set (cdr where
) (cdr href
)))))
242 (defun eww-tag-link (cont)
243 (eww-handle-link cont
)
246 (defun eww-tag-a (cont)
247 (eww-handle-link cont
)
250 (defun eww-update-header-line-format ()
251 (if eww-header-line-format
252 (setq header-line-format
253 (replace-regexp-in-string
255 (format-spec eww-header-line-format
256 `((?u .
,eww-current-url
)
257 (?t .
,eww-current-title
)))))
258 (setq header-line-format nil
)))
260 (defun eww-tag-title (cont)
261 (setq eww-current-title
"")
263 (when (eq (car sub
) 'text
)
264 (setq eww-current-title
(concat eww-current-title
(cdr sub
)))))
265 (eww-update-header-line-format))
267 (defun eww-tag-body (cont)
268 (let* ((start (point))
269 (fgcolor (cdr (or (assq :fgcolor cont
)
271 (bgcolor (cdr (assq :bgcolor cont
)))
272 (shr-stylesheet (list (cons 'color fgcolor
)
273 (cons 'background-color bgcolor
))))
275 (eww-colorize-region start
(point) fgcolor bgcolor
)))
277 (defun eww-colorize-region (start end fg
&optional bg
)
279 (let ((new-colors (shr-color-check fg bg
)))
282 (add-face-text-property start end
283 (list :foreground
(cadr new-colors
))
286 (add-face-text-property start end
287 (list :background
(car new-colors
))
290 (defun eww-display-raw (charset)
291 (let ((data (buffer-substring (point) (point-max))))
293 (let ((inhibit-read-only t
))
295 (goto-char (point-min))))
297 (defun eww-display-image ()
298 (let ((data (buffer-substring (point) (point-max))))
300 (let ((inhibit-read-only t
))
301 (shr-put-image data nil
))
302 (goto-char (point-min))))
304 (defun eww-setup-buffer ()
305 (pop-to-buffer (get-buffer-create "*eww*"))
307 (let ((inhibit-read-only t
))
312 (let ((map (make-sparse-keymap)))
313 (suppress-keymap map
)
314 (define-key map
"q" 'eww-quit
)
315 (define-key map
"g" 'eww-reload
)
316 (define-key map
[tab] 'shr-next-link)
317 (define-key map [backtab] 'shr-previous-link)
318 (define-key map [delete] 'scroll-down-command)
319 (define-key map "\177" 'scroll-down-command)
320 (define-key map " " 'scroll-up-command)
321 (define-key map "l" 'eww-back-url)
322 (define-key map "f" 'eww-forward-url)
323 (define-key map "n" 'eww-next-url)
324 (define-key map "p" 'eww-previous-url)
325 (define-key map "u" 'eww-up-url)
326 (define-key map "t" 'eww-top-url)
327 (define-key map "w" 'eww-browse-with-external-browser)
328 (define-key map "y" 'eww-yank-page-url)
331 (define-derived-mode eww-mode nil "eww"
332 "Mode for browsing the web.
335 (set (make-local-variable 'eww-current-url) 'author)
336 (set (make-local-variable 'browse-url-browser-function) 'eww-browse-url)
337 (set (make-local-variable 'after-change-functions) 'eww-process-text-input)
338 ;;(setq buffer-read-only t)
341 (defun eww-save-history ()
342 (let ((elem (list :url eww-current-url
344 :text (buffer-string))))
345 (if (or (zerop eww-history-position)
346 (= eww-history-position (length eww-history)))
347 (push elem eww-history)
348 (setcdr (nthcdr eww-history-position eww-history)
349 (cons elem (nthcdr eww-history-position eww-history))))))
351 (defun eww-browse-url (url &optional new-window)
352 (when (and (equal major-mode 'eww-mode)
358 "Exit the Emacs Web Wowser."
360 (setq eww-history nil)
361 (kill-buffer (current-buffer)))
363 (defun eww-back-url ()
364 "Go to the previously displayed page."
366 (when (>= eww-history-position (length eww-history))
367 (error "No previous page"))
369 (if (not (zerop eww-history-position))
370 (elt eww-history eww-history-position)
372 (elt eww-history (1+ eww-history-position))))
373 (setq eww-history-position (1+ eww-history-position)))
375 (defun eww-forward-url ()
376 "Go to the next displayed page."
378 (when (zerop eww-history-position)
379 (error "No next page"))
380 (eww-restore-history (elt eww-history (1- eww-history-position)))
381 (setq eww-history-position (1- eww-history-position)))
383 (defun eww-restore-history (elem)
384 (let ((inhibit-read-only t))
386 (insert (plist-get elem :text))
387 (goto-char (plist-get elem :point))
388 (setq eww-current-url (plist-get elem :url))))
390 (defun eww-next-url ()
391 "Go to the page marked `next'.
392 A page is marked `next' if rel=\"next\" appears in a <link>
396 (eww-browse-url (shr-expand-url eww-next-url eww-current-url))
397 (error "No `next' on this page")))
399 (defun eww-previous-url ()
400 "Go to the page marked `previous'.
401 A page is marked `previous' if rel=\"previous\" appears in a <link>
405 (eww-browse-url (shr-expand-url eww-previous-url eww-current-url))
406 (error "No `previous' on this page")))
409 "Go to the page marked `up'.
410 A page is marked `up' if rel=\"up\" appears in a <link>
414 (eww-browse-url (shr-expand-url eww-up-url eww-current-url))
415 (error "No `up' on this page")))
417 (defun eww-top-url ()
418 "Go to the page marked `top'.
419 A page is marked `top' if rel=\"start\", rel=\"home\", or rel=\"contents\"
420 appears in a <link> or <a> tag."
422 (let ((best-url (or eww-start-url
426 (eww-browse-url (shr-expand-url best-url eww-current-url))
427 (error "No `top' for this page"))))
430 "Reload the current page."
432 (url-retrieve eww-current-url 'eww-render
433 (list eww-current-url (point))))
437 (defvar eww-form nil)
439 (defvar eww-submit-map
440 (let ((map (make-sparse-keymap)))
441 (define-key map "\r" 'eww-submit)
442 (define-key map [(control c) (control c)] 'eww-submit)
445 (defvar eww-checkbox-map
446 (let ((map (make-sparse-keymap)))
447 (define-key map [space] 'eww-toggle-checkbox)
448 (define-key map "\r" 'eww-toggle-checkbox)
449 (define-key map [(control c) (control c)] 'eww-submit)
453 (let ((map (make-keymap)))
454 (set-keymap-parent map text-mode-map)
455 (define-key map "\r" 'eww-submit)
456 (define-key map [(control a)] 'eww-beginning-of-text)
457 (define-key map [(control c) (control c)] 'eww-submit)
458 (define-key map [(control e)] 'eww-end-of-text)
459 (define-key map [tab] 'shr-next-link
)
460 (define-key map
[backtab] 'shr-previous-link)
463 (defvar eww-textarea-map
464 (let ((map (make-keymap)))
465 (set-keymap-parent map text-mode-map)
466 (define-key map "\r" 'forward-line)
467 (define-key map [(control c) (control c)] 'eww-submit)
468 (define-key map [tab] 'shr-next-link)
469 (define-key map [backtab] 'shr-previous-link
)
472 (defvar eww-select-map
473 (let ((map (make-sparse-keymap)))
474 (define-key map
"\r" 'eww-change-select
)
475 (define-key map
[(control c
) (control c
)] 'eww-submit
)
478 (defun eww-beginning-of-text ()
479 "Move to the start of the input field."
481 (goto-char (eww-beginning-of-field)))
483 (defun eww-end-of-text ()
484 "Move to the end of the text in the input field."
486 (goto-char (eww-end-of-field))
487 (let ((start (eww-beginning-of-field)))
488 (while (and (equal (following-char) ?
)
491 (when (> (point) start
)
494 (defun eww-beginning-of-field ()
498 ((not (eq (get-text-property (point) 'eww-form
)
499 (get-text-property (1- (point)) 'eww-form
)))
502 (previous-single-property-change
503 (point) 'eww-form nil
(point-min)))))
505 (defun eww-end-of-field ()
506 (1- (next-single-property-change
507 (point) 'eww-form nil
(point-max))))
509 (defun eww-tag-form (cont)
511 (list (assq :method cont
)
512 (assq :action cont
)))
514 (shr-ensure-paragraph)
519 (when (> (point) start
)
520 (put-text-property start
(1+ start
)
521 'eww-form eww-form
))))
523 (defun eww-form-submit (cont)
524 (let ((start (point))
525 (value (cdr (assq :value cont
))))
527 (if (zerop (length value
))
531 (add-face-text-property start
(point) 'eww-form-submit
)
532 (put-text-property start
(point) 'eww-form
533 (list :eww-form eww-form
536 :name
(cdr (assq :name cont
))))
537 (put-text-property start
(point) 'keymap eww-submit-map
)
540 (defun eww-form-checkbox (cont)
541 (let ((start (point)))
542 (if (cdr (assq :checked cont
))
545 (add-face-text-property start
(point) 'eww-form-checkbox
)
546 (put-text-property start
(point) 'eww-form
547 (list :eww-form eww-form
548 :value
(cdr (assq :value cont
))
549 :type
(downcase (cdr (assq :type cont
)))
550 :checked
(cdr (assq :checked cont
))
551 :name
(cdr (assq :name cont
))))
552 (put-text-property start
(point) 'keymap eww-checkbox-map
)
555 (defun eww-form-text (cont)
556 (let ((start (point))
557 (type (downcase (or (cdr (assq :type cont
))
559 (value (or (cdr (assq :value cont
)) ""))
560 (width (string-to-number
561 (or (cdr (assq :size cont
))
564 (when (< (length value
) width
)
565 (insert (make-string (- width
(length value
)) ?
)))
566 (put-text-property start
(point) 'face
'eww-form-text
)
567 (put-text-property start
(point) 'local-map eww-text-map
)
568 (put-text-property start
(point) 'inhibit-read-only t
)
569 (put-text-property start
(point) 'eww-form
570 (list :eww-form eww-form
573 :name
(cdr (assq :name cont
))))
576 (defun eww-process-text-input (beg end length
)
577 (let* ((form (get-text-property end
'eww-form
))
578 (properties (text-properties-at end
))
579 (type (plist-get form
:type
)))
581 (member type
'("text" "password" "textarea")))
584 ;; Delete some space at the end.
587 (if (equal type
"textarea")
588 (1- (line-end-position))
590 (let ((new (- end beg
)))
591 (while (and (> new
0)
592 (eql (following-char) ?
))
593 (delete-region (point) (1+ (point)))
594 (setq new
(1- new
))))
595 (set-text-properties beg end properties
)))
600 (if (equal type
"textarea")
601 (1- (line-end-position))
603 (let ((start (point)))
604 (insert (make-string length ?
))
605 (set-text-properties start
(point) properties
)))))
606 (let ((value (buffer-substring-no-properties
607 (eww-beginning-of-field)
608 (eww-end-of-field))))
609 (when (string-match " +\\'" value
)
610 (setq value
(substring value
0 (match-beginning 0))))
611 (plist-put form
:value value
)
612 (when (equal type
"password")
613 ;; Display passwords as asterisks.
614 (let ((start (eww-beginning-of-field)))
615 (put-text-property start
(+ start
(length value
))
616 'display
(make-string (length value
) ?
*))))))))
618 (defun eww-tag-textarea (cont)
619 (let ((start (point))
620 (value (or (cdr (assq :value cont
)) ""))
621 (lines (string-to-number
622 (or (cdr (assq :rows cont
))
624 (width (string-to-number
625 (or (cdr (assq :cols cont
))
631 (when (< (count-lines start
(point)) lines
)
632 (dotimes (i (- lines
(count-lines start
(point))))
634 (setq end
(point-marker))
636 (while (< (point) end
)
638 (let ((pad (- width
(- (point) (line-beginning-position)))))
640 (insert (make-string pad ?
))))
641 (add-face-text-property (line-beginning-position)
642 (point) 'eww-form-text
)
643 (put-text-property (line-beginning-position) (point)
644 'local-map eww-textarea-map
)
646 (put-text-property start
(point) 'eww-form
647 (list :eww-form eww-form
650 :name
(cdr (assq :name cont
))))))
652 (defun eww-tag-input (cont)
653 (let ((type (downcase (or (cdr (assq :type cont
))
657 ((or (equal type
"checkbox")
658 (equal type
"radio"))
659 (eww-form-checkbox cont
))
660 ((equal type
"submit")
661 (eww-form-submit cont
))
662 ((equal type
"hidden")
663 (let ((form eww-form
)
664 (name (cdr (assq :name cont
))))
665 ;; Don't add <input type=hidden> elements repeatedly.
667 (or (not (consp (car form
)))
668 (not (eq (caar form
) 'hidden
))
669 (not (equal (plist-get (cdr (car form
)) :name
)
671 (setq form
(cdr form
)))
673 (nconc eww-form
(list
676 :value
(cdr (assq :value cont
))))))))
678 (eww-form-text cont
)))
679 (unless (= start
(point))
680 (put-text-property start
(1+ start
) 'help-echo
"Input field"))))
682 (defun eww-tag-select (cont)
683 (shr-ensure-paragraph)
684 (let ((menu (list :name
(cdr (assq :name cont
))
690 (when (eq (car elem
) 'option
)
691 (when (cdr (assq :selected
(cdr elem
)))
692 (nconc menu
(list :value
693 (cdr (assq :value
(cdr elem
))))))
694 (let ((display (or (cdr (assq 'text
(cdr elem
))) "")))
695 (setq max
(max max
(length display
)))
697 :value
(cdr (assq :value
(cdr elem
)))
701 (setq options
(nreverse options
))
702 ;; If we have no selected values, default to the first value.
703 (unless (plist-get menu
:value
)
704 (nconc menu
(list :value
(nth 2 (car options
)))))
706 (let ((selected (eww-select-display menu
)))
708 (make-string (- max
(length selected
)) ?
)))
709 (put-text-property start
(point) 'eww-form menu
)
710 (add-face-text-property start
(point) 'eww-form-select
)
711 (put-text-property start
(point) 'keymap eww-select-map
)
712 (shr-ensure-paragraph))))
714 (defun eww-select-display (select)
715 (let ((value (plist-get select
:value
))
717 (dolist (elem select
)
718 (when (and (consp elem
)
719 (eq (car elem
) 'item
)
720 (equal value
(plist-get (cdr elem
) :value
)))
721 (setq display
(plist-get (cdr elem
) :display
))))
724 (defun eww-change-select ()
725 "Change the value of the select drop-down menu under point."
727 (let* ((input (get-text-property (point) 'eww-form
))
728 (properties (text-properties-at (point)))
729 (completion-ignore-case t
)
732 (mapcar (lambda (elem)
734 (eq (car elem
) 'item
)
735 (cons (plist-get (cdr elem
) :display
)
736 (plist-get (cdr elem
) :value
))))
739 (completing-read "Change value: " options nil
'require-match
))
740 (inhibit-read-only t
))
741 (plist-put input
:value
(cdr (assoc-string display options t
)))
743 (eww-update-field display
))))
745 (defun eww-update-field (string)
746 (let ((properties (text-properties-at (point)))
747 (start (eww-beginning-of-field))
748 (end (1+ (eww-end-of-field))))
749 (delete-region start end
)
751 (make-string (- (- end start
) (length string
)) ?
))
752 (set-text-properties start end properties
)
755 (defun eww-toggle-checkbox ()
756 "Toggle the value of the checkbox under point."
758 (let* ((input (get-text-property (point) 'eww-form
))
759 (type (plist-get input
:type
)))
760 (if (equal type
"checkbox")
763 (if (plist-get input
:checked
)
765 (plist-put input
:checked nil
)
766 (eww-update-field "[ ]"))
767 (plist-put input
:checked t
)
768 (eww-update-field "[X]"))))
769 ;; Radio button. Switch all other buttons off.
770 (let ((name (plist-get input
:name
)))
772 (dolist (elem (eww-inputs (plist-get input
:eww-form
)))
773 (when (equal (plist-get (cdr elem
) :name
) name
)
774 (goto-char (car elem
))
775 (if (not (eq (cdr elem
) input
))
777 (plist-put input
:checked nil
)
778 (eww-update-field "[ ]"))
779 (plist-put input
:checked t
)
780 (eww-update-field "[X]")))))
783 (defun eww-inputs (form)
784 (let ((start (point-min))
787 (< start
(point-max)))
788 (when (or (get-text-property start
'eww-form
)
789 (setq start
(next-single-property-change start
'eww-form
)))
790 (when (eq (plist-get (get-text-property start
'eww-form
) :eww-form
)
792 (push (cons start
(get-text-property start
'eww-form
))
794 (setq start
(next-single-property-change start
'eww-form
))))
797 (defun eww-input-value (input)
798 (let ((type (plist-get input
:type
))
799 (value (plist-get input
:value
)))
801 ((equal type
"textarea")
804 (goto-char (point-min))
805 (while (re-search-forward "^ +\n\\| +$" nil t
)
806 (replace-match "" t t
))
809 (if (string-match " +\\'" value
)
810 (substring value
0 (match-beginning 0))
814 "Submit the current form."
816 (let* ((this-input (get-text-property (point) 'eww-form
))
817 (form (plist-get this-input
:eww-form
))
819 (dolist (elem (sort (eww-inputs form
)
821 (< (car o1
) (car o2
)))))
822 (let* ((input (cdr elem
))
823 (input-start (car elem
))
824 (name (plist-get input
:name
)))
827 ((member (plist-get input
:type
) '("checkbox" "radio"))
828 (when (plist-get input
:checked
)
829 (push (cons name
(plist-get input
:value
))
831 ((equal (plist-get input
:type
) "submit")
832 ;; We want the values from buttons if we hit a button if
833 ;; we hit enter on it, or if it's the first button after
834 ;; the field we did hit return on.
835 (when (or (eq input this-input
)
836 (and (not (eq input this-input
))
838 (> input-start
(point))))
840 (push (cons name
(plist-get input
:value
))
843 (push (cons name
(eww-input-value input
))
846 (when (and (consp elem
)
847 (eq (car elem
) 'hidden
))
848 (push (cons (plist-get (cdr elem
) :name
)
849 (plist-get (cdr elem
) :value
))
851 (if (and (stringp (cdr (assq :method form
)))
852 (equal (downcase (cdr (assq :method form
))) "post"))
853 (let ((url-request-method "POST")
854 (url-request-extra-headers
855 '(("Content-Type" .
"application/x-www-form-urlencoded")))
856 (url-request-data (mm-url-encode-www-form-urlencoded values
)))
857 (eww-browse-url (shr-expand-url (cdr (assq :action form
))
861 (if (cdr (assq :action form
))
862 (shr-expand-url (cdr (assq :action form
))
866 (mm-url-encode-www-form-urlencoded values
))))))
868 (defun eww-browse-with-external-browser ()
869 "Browse the current URL with an external browser.
870 The browser to used is specified by the `shr-external-browser' variable."
872 (funcall shr-external-browser eww-current-url
))
874 (defun eww-yank-page-url ()
876 (message eww-current-url
)
877 (kill-new eww-current-url
))