eww bookmark window restoration
[bpt/emacs.git] / lisp / net / eww.el
1 ;;; eww.el --- Emacs Web Wowser
2
3 ;; Copyright (C) 2013 Free Software Foundation, Inc.
4
5 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
6 ;; Keywords: html
7
8 ;; This file is part of GNU Emacs.
9
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.
14
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.
19
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/>.
22
23 ;;; Commentary:
24
25 ;;; Code:
26
27 (eval-when-compile (require 'cl))
28 (require 'format-spec)
29 (require 'shr)
30 (require 'url)
31 (require 'mm-url)
32
33 (defgroup eww nil
34 "Emacs Web Wowser"
35 :version "24.4"
36 :group 'hypermedia
37 :prefix "eww-")
38
39 (defcustom eww-header-line-format "%t: %u"
40 "Header line format.
41 - %t is replaced by the title.
42 - %u is replaced by the URL."
43 :version "24.4"
44 :group 'eww
45 :type 'string)
46
47 (defcustom eww-search-prefix "https://duckduckgo.com/html/?q="
48 "Prefix URL to search engine"
49 :version "24.4"
50 :group 'eww
51 :type 'string)
52
53 (defcustom eww-download-path "~/Downloads/"
54 "Path where files will downloaded."
55 :version "24.4"
56 :group 'eww
57 :type 'string)
58
59 (defcustom eww-use-external-browser-for-content-type
60 "\\`\\(video/\\|audio/\\|application/ogg\\)"
61 "Always use external browser for specified content-type."
62 :version "24.4"
63 :group 'eww
64 :type '(choice (const :tag "Never" nil)
65 regexp))
66
67 (defcustom eww-form-checkbox-selected-symbol "[X]"
68 "Symbol used to represent a selected checkbox.
69 See also `eww-form-checkbox-symbol'."
70 :version "24.4"
71 :group 'eww
72 :type '(choice (const "[X]")
73 (const "☒") ; Unicode BALLOT BOX WITH X
74 (const "☑") ; Unicode BALLOT BOX WITH CHECK
75 string))
76
77 (defcustom eww-form-checkbox-symbol "[ ]"
78 "Symbol used to represent a checkbox.
79 See also `eww-form-checkbox-selected-symbol'."
80 :version "24.4"
81 :group 'eww
82 :type '(choice (const "[ ]")
83 (const "☐") ; Unicode BALLOT BOX
84 string))
85
86 (defface eww-form-submit
87 '((((type x w32 ns) (class color)) ; Like default mode line
88 :box (:line-width 2 :style released-button)
89 :background "#808080" :foreground "black"))
90 "Face for eww buffer buttons."
91 :version "24.4"
92 :group 'eww)
93
94 (defface eww-form-checkbox
95 '((((type x w32 ns) (class color)) ; Like default mode line
96 :box (:line-width 2 :style released-button)
97 :background "lightgrey" :foreground "black"))
98 "Face for eww buffer buttons."
99 :version "24.4"
100 :group 'eww)
101
102 (defface eww-form-select
103 '((((type x w32 ns) (class color)) ; Like default mode line
104 :box (:line-width 2 :style released-button)
105 :background "lightgrey" :foreground "black"))
106 "Face for eww buffer buttons."
107 :version "24.4"
108 :group 'eww)
109
110 (defface eww-form-text
111 '((t (:background "#505050"
112 :foreground "white"
113 :box (:line-width 1))))
114 "Face for eww text inputs."
115 :version "24.4"
116 :group 'eww)
117
118 (defvar eww-current-url nil)
119 (defvar eww-current-dom nil)
120 (defvar eww-current-source nil)
121 (defvar eww-current-title ""
122 "Title of current page.")
123 (defvar eww-history nil)
124 (defvar eww-history-position 0)
125
126 (defvar eww-next-url nil)
127 (defvar eww-previous-url nil)
128 (defvar eww-up-url nil)
129 (defvar eww-home-url nil)
130 (defvar eww-start-url nil)
131 (defvar eww-contents-url nil)
132
133 (defvar eww-local-regex "localhost"
134 "When this regex is found in the URL, it's not a keyword but an address.")
135
136 (defvar eww-link-keymap
137 (let ((map (copy-keymap shr-map)))
138 (define-key map "\r" 'eww-follow-link)
139 map))
140
141 ;;;###autoload
142 (defun eww (url)
143 "Fetch URL and render the page.
144 If the input doesn't look like an URL or a domain name, the
145 word(s) will be searched for via `eww-search-prefix'."
146 (interactive "sEnter URL or keywords: ")
147 (cond ((string-match-p "\\`file://" url))
148 ((string-match-p "\\`ftp://" url)
149 (user-error "FTP is not supported."))
150 (t
151 (if (and (= (length (split-string url)) 1)
152 (or (> (length (split-string url "\\.")) 1)
153 (string-match eww-local-regex url)))
154 (progn
155 (unless (string-match-p "\\`[a-zA-Z][-a-zA-Z0-9+.]*://" url)
156 (setq url (concat "http://" url)))
157 ;; some site don't redirect final /
158 (when (string= (url-filename (url-generic-parse-url url)) "")
159 (setq url (concat url "/"))))
160 (setq url (concat eww-search-prefix
161 (replace-regexp-in-string " " "+" url))))))
162 (url-retrieve url 'eww-render (list url)))
163
164 ;;;###autoload (defalias 'browse-web 'eww)
165
166 ;;;###autoload
167 (defun eww-open-file (file)
168 "Render a file using EWW."
169 (interactive "fFile: ")
170 (eww (concat "file://"
171 (and (memq system-type '(windows-nt ms-dos))
172 "/")
173 (expand-file-name file))))
174
175 (defun eww-render (status url &optional point)
176 (let ((redirect (plist-get status :redirect)))
177 (when redirect
178 (setq url redirect)))
179 (setq-local eww-next-url nil)
180 (setq-local eww-previous-url nil)
181 (setq-local eww-up-url nil)
182 (setq-local eww-home-url nil)
183 (setq-local eww-start-url nil)
184 (setq-local eww-contents-url nil)
185 (let* ((headers (eww-parse-headers))
186 (content-type
187 (mail-header-parse-content-type
188 (or (cdr (assoc "content-type" headers))
189 "text/plain")))
190 (charset (intern
191 (downcase
192 (or (cdr (assq 'charset (cdr content-type)))
193 (eww-detect-charset (equal (car content-type)
194 "text/html"))
195 "utf8"))))
196 (data-buffer (current-buffer)))
197 (unwind-protect
198 (progn
199 (setq eww-current-title "")
200 (cond
201 ((and eww-use-external-browser-for-content-type
202 (string-match-p eww-use-external-browser-for-content-type
203 (car content-type)))
204 (eww-browse-with-external-browser url))
205 ((equal (car content-type) "text/html")
206 (eww-display-html charset url nil point))
207 ((string-match-p "\\`image/" (car content-type))
208 (eww-display-image)
209 (eww-update-header-line-format))
210 (t
211 (eww-display-raw)
212 (eww-update-header-line-format)))
213 (setq eww-current-url url
214 eww-history-position 0))
215 (kill-buffer data-buffer))))
216
217 (defun eww-parse-headers ()
218 (let ((headers nil))
219 (goto-char (point-min))
220 (while (and (not (eobp))
221 (not (eolp)))
222 (when (looking-at "\\([^:]+\\): *\\(.*\\)")
223 (push (cons (downcase (match-string 1))
224 (match-string 2))
225 headers))
226 (forward-line 1))
227 (unless (eobp)
228 (forward-line 1))
229 headers))
230
231 (defun eww-detect-charset (html-p)
232 (let ((case-fold-search t)
233 (pt (point)))
234 (or (and html-p
235 (re-search-forward
236 "<meta[\t\n\r ]+[^>]*charset=\"?\\([^\t\n\r \"/>]+\\)[\\\"'.*]" nil t)
237 (goto-char pt)
238 (match-string 1))
239 (and (looking-at
240 "[\t\n\r ]*<\\?xml[\t\n\r ]+[^>]*encoding=\"\\([^\"]+\\)")
241 (match-string 1)))))
242
243 (declare-function libxml-parse-html-region "xml.c"
244 (start end &optional base-url))
245
246 (defun eww-display-html (charset url &optional document point)
247 (or (fboundp 'libxml-parse-html-region)
248 (error "This function requires Emacs to be compiled with libxml2"))
249 (unless (eq charset 'utf8)
250 (condition-case nil
251 (decode-coding-region (point) (point-max) charset)
252 (coding-system-error nil)))
253 (let ((document
254 (or document
255 (list
256 'base (list (cons 'href url))
257 (libxml-parse-html-region (point) (point-max))))))
258 (setq eww-current-source (buffer-substring (point) (point-max)))
259 (eww-setup-buffer)
260 (setq eww-current-dom document)
261 (let ((inhibit-read-only t)
262 (after-change-functions nil)
263 (shr-width nil)
264 (shr-target-id (url-target (url-generic-parse-url url)))
265 (shr-external-rendering-functions
266 '((title . eww-tag-title)
267 (form . eww-tag-form)
268 (input . eww-tag-input)
269 (textarea . eww-tag-textarea)
270 (body . eww-tag-body)
271 (select . eww-tag-select)
272 (link . eww-tag-link)
273 (a . eww-tag-a))))
274 (shr-insert-document document)
275 (cond
276 (point
277 (goto-char point))
278 (shr-target-id
279 (goto-char (point-min))
280 (let ((point (next-single-property-change
281 (point-min) 'shr-target-id)))
282 (when point
283 (goto-char point))))
284 (t
285 (goto-char (point-min)))))
286 (setq eww-current-url url
287 eww-history-position 0)
288 (eww-update-header-line-format)))
289
290 (defun eww-handle-link (cont)
291 (let* ((rel (assq :rel cont))
292 (href (assq :href cont))
293 (where (assoc
294 ;; The text associated with :rel is case-insensitive.
295 (if rel (downcase (cdr rel)))
296 '(("next" . eww-next-url)
297 ;; Texinfo uses "previous", but HTML specifies
298 ;; "prev", so recognize both.
299 ("previous" . eww-previous-url)
300 ("prev" . eww-previous-url)
301 ;; HTML specifies "start" but also "contents",
302 ;; and Gtk seems to use "home". Recognize
303 ;; them all; but store them in different
304 ;; variables so that we can readily choose the
305 ;; "best" one.
306 ("start" . eww-start-url)
307 ("home" . eww-home-url)
308 ("contents" . eww-contents-url)
309 ("up" . eww-up-url)))))
310 (and href
311 where
312 (set (cdr where) (cdr href)))))
313
314 (defun eww-tag-link (cont)
315 (eww-handle-link cont)
316 (shr-generic cont))
317
318 (defun eww-tag-a (cont)
319 (eww-handle-link cont)
320 (let ((start (point)))
321 (shr-tag-a cont)
322 (put-text-property start (point) 'keymap eww-link-keymap)))
323
324 (defun eww-update-header-line-format ()
325 (if eww-header-line-format
326 (setq header-line-format
327 (replace-regexp-in-string
328 "%" "%%"
329 ;; FIXME? Title can be blank. Default to, eg, last component
330 ;; of url?
331 (format-spec eww-header-line-format
332 `((?u . ,eww-current-url)
333 (?t . ,eww-current-title)))))
334 (setq header-line-format nil)))
335
336 (defun eww-tag-title (cont)
337 (setq eww-current-title "")
338 (dolist (sub cont)
339 (when (eq (car sub) 'text)
340 (setq eww-current-title (concat eww-current-title (cdr sub)))))
341 (eww-update-header-line-format))
342
343 (defun eww-tag-body (cont)
344 (let* ((start (point))
345 (fgcolor (cdr (or (assq :fgcolor cont)
346 (assq :text cont))))
347 (bgcolor (cdr (assq :bgcolor cont)))
348 (shr-stylesheet (list (cons 'color fgcolor)
349 (cons 'background-color bgcolor))))
350 (shr-generic cont)
351 (eww-colorize-region start (point) fgcolor bgcolor)))
352
353 (defun eww-colorize-region (start end fg &optional bg)
354 (when (or fg bg)
355 (let ((new-colors (shr-color-check fg bg)))
356 (when new-colors
357 (when fg
358 (add-face-text-property start end
359 (list :foreground (cadr new-colors))
360 t))
361 (when bg
362 (add-face-text-property start end
363 (list :background (car new-colors))
364 t))))))
365
366 (defun eww-display-raw ()
367 (let ((data (buffer-substring (point) (point-max))))
368 (eww-setup-buffer)
369 (let ((inhibit-read-only t))
370 (insert data))
371 (goto-char (point-min))))
372
373 (defun eww-display-image ()
374 (let ((data (shr-parse-image-data)))
375 (eww-setup-buffer)
376 (let ((inhibit-read-only t))
377 (shr-put-image data nil))
378 (goto-char (point-min))))
379
380 (defun eww-setup-buffer ()
381 (switch-to-buffer (get-buffer-create "*eww*"))
382 (let ((inhibit-read-only t))
383 (remove-overlays)
384 (erase-buffer))
385 (unless (eq major-mode 'eww-mode)
386 (eww-mode)))
387
388 (defun eww-view-source ()
389 (interactive)
390 (let ((buf (get-buffer-create "*eww-source*"))
391 (source eww-current-source))
392 (with-current-buffer buf
393 (delete-region (point-min) (point-max))
394 (insert (or eww-current-source "no source"))
395 (goto-char (point-min))
396 (when (fboundp 'html-mode)
397 (html-mode)))
398 (view-buffer buf)))
399
400 (defvar eww-mode-map
401 (let ((map (make-sparse-keymap)))
402 (suppress-keymap map)
403 (define-key map "q" 'quit-window)
404 (define-key map "g" 'eww-reload)
405 (define-key map [tab] 'shr-next-link)
406 (define-key map [backtab] 'shr-previous-link)
407 (define-key map [delete] 'scroll-down-command)
408 (define-key map [?\S-\ ] 'scroll-down-command)
409 (define-key map "\177" 'scroll-down-command)
410 (define-key map " " 'scroll-up-command)
411 (define-key map "l" 'eww-back-url)
412 (define-key map "r" 'eww-forward-url)
413 (define-key map "n" 'eww-next-url)
414 (define-key map "p" 'eww-previous-url)
415 (define-key map "u" 'eww-up-url)
416 (define-key map "t" 'eww-top-url)
417 (define-key map "&" 'eww-browse-with-external-browser)
418 (define-key map "d" 'eww-download)
419 (define-key map "w" 'eww-copy-page-url)
420 (define-key map "C" 'url-cookie-list)
421 (define-key map "v" 'eww-view-source)
422 (define-key map "H" 'eww-list-histories)
423
424 (define-key map "b" 'eww-add-bookmark)
425 (define-key map "B" 'eww-list-bookmarks)
426 (define-key map [(meta n)] 'eww-next-bookmark)
427 (define-key map [(meta p)] 'eww-previous-bookmark)
428
429 (easy-menu-define nil map ""
430 '("Eww"
431 ["Exit" eww-quit t]
432 ["Close browser" quit-window t]
433 ["Reload" eww-reload t]
434 ["Back to previous page" eww-back-url
435 :active (not (zerop (length eww-history)))]
436 ["Forward to next page" eww-forward-url
437 :active (not (zerop eww-history-position))]
438 ["Browse with external browser" eww-browse-with-external-browser t]
439 ["Download" eww-download t]
440 ["View page source" eww-view-source]
441 ["Copy page URL" eww-copy-page-url t]
442 ["List histories" eww-list-histories t]
443 ["Add bookmark" eww-add-bookmark t]
444 ["List bookmarks" eww-list-bookmarks t]
445 ["List cookies" url-cookie-list t]))
446 map))
447
448 (defvar eww-tool-bar-map
449 (let ((map (make-sparse-keymap)))
450 (dolist (tool-bar-item
451 '((eww-quit . "close")
452 (eww-reload . "refresh")
453 (eww-back-url . "left-arrow")
454 (eww-forward-url . "right-arrow")
455 (eww-view-source . "show")
456 (eww-copy-page-url . "copy")
457 (eww-add-bookmark . "bookmark_add"))) ;; ...
458 (tool-bar-local-item-from-menu
459 (car tool-bar-item) (cdr tool-bar-item) map eww-mode-map))
460 map)
461 "Tool bar for `eww-mode'.")
462
463 (define-derived-mode eww-mode nil "eww"
464 "Mode for browsing the web.
465
466 \\{eww-mode-map}"
467 ;; FIXME? This seems a strange default.
468 (setq-local eww-current-url 'author)
469 (setq-local eww-current-dom nil)
470 (setq-local eww-current-source nil)
471 (setq-local browse-url-browser-function 'eww-browse-url)
472 (setq-local after-change-functions 'eww-process-text-input)
473 (setq-local eww-history nil)
474 (setq-local eww-history-position 0)
475 (when (boundp 'tool-bar-map)
476 (setq-local tool-bar-map eww-tool-bar-map))
477 (buffer-disable-undo)
478 ;;(setq buffer-read-only t)
479 )
480
481 ;;;###autoload
482 (defun eww-browse-url (url &optional _new-window)
483 (when (and (equal major-mode 'eww-mode)
484 eww-current-url)
485 (eww-save-history))
486 (eww url))
487
488 (defun eww-back-url ()
489 "Go to the previously displayed page."
490 (interactive)
491 (when (>= eww-history-position (length eww-history))
492 (user-error "No previous page"))
493 (eww-save-history)
494 (setq eww-history-position (+ eww-history-position 2))
495 (eww-restore-history (elt eww-history (1- eww-history-position))))
496
497 (defun eww-forward-url ()
498 "Go to the next displayed page."
499 (interactive)
500 (when (zerop eww-history-position)
501 (user-error "No next page"))
502 (eww-save-history)
503 (eww-restore-history (elt eww-history (1- eww-history-position))))
504
505 (defun eww-restore-history (elem)
506 (let ((inhibit-read-only t))
507 (erase-buffer)
508 (insert (plist-get elem :text))
509 (setq eww-current-source (plist-get elem :source))
510 (setq eww-current-dom (plist-get elem :dom))
511 (goto-char (plist-get elem :point))
512 (setq eww-current-url (plist-get elem :url)
513 eww-current-title (plist-get elem :title))
514 (eww-update-header-line-format)))
515
516 (defun eww-next-url ()
517 "Go to the page marked `next'.
518 A page is marked `next' if rel=\"next\" appears in a <link>
519 or <a> tag."
520 (interactive)
521 (if eww-next-url
522 (eww-browse-url (shr-expand-url eww-next-url eww-current-url))
523 (user-error "No `next' on this page")))
524
525 (defun eww-previous-url ()
526 "Go to the page marked `previous'.
527 A page is marked `previous' if rel=\"previous\" appears in a <link>
528 or <a> tag."
529 (interactive)
530 (if eww-previous-url
531 (eww-browse-url (shr-expand-url eww-previous-url eww-current-url))
532 (user-error "No `previous' on this page")))
533
534 (defun eww-up-url ()
535 "Go to the page marked `up'.
536 A page is marked `up' if rel=\"up\" appears in a <link>
537 or <a> tag."
538 (interactive)
539 (if eww-up-url
540 (eww-browse-url (shr-expand-url eww-up-url eww-current-url))
541 (user-error "No `up' on this page")))
542
543 (defun eww-top-url ()
544 "Go to the page marked `top'.
545 A page is marked `top' if rel=\"start\", rel=\"home\", or rel=\"contents\"
546 appears in a <link> or <a> tag."
547 (interactive)
548 (let ((best-url (or eww-start-url
549 eww-contents-url
550 eww-home-url)))
551 (if best-url
552 (eww-browse-url (shr-expand-url best-url eww-current-url))
553 (user-error "No `top' for this page"))))
554
555 (defun eww-reload ()
556 "Reload the current page."
557 (interactive)
558 (url-retrieve eww-current-url 'eww-render
559 (list eww-current-url (point))))
560
561 ;; Form support.
562
563 (defvar eww-form nil)
564
565 (defvar eww-submit-map
566 (let ((map (make-sparse-keymap)))
567 (define-key map "\r" 'eww-submit)
568 (define-key map [(control c) (control c)] 'eww-submit)
569 map))
570
571 (defvar eww-checkbox-map
572 (let ((map (make-sparse-keymap)))
573 (define-key map " " 'eww-toggle-checkbox)
574 (define-key map "\r" 'eww-toggle-checkbox)
575 (define-key map [(control c) (control c)] 'eww-submit)
576 map))
577
578 (defvar eww-text-map
579 (let ((map (make-keymap)))
580 (set-keymap-parent map text-mode-map)
581 (define-key map "\r" 'eww-submit)
582 (define-key map [(control a)] 'eww-beginning-of-text)
583 (define-key map [(control c) (control c)] 'eww-submit)
584 (define-key map [(control e)] 'eww-end-of-text)
585 (define-key map [tab] 'shr-next-link)
586 (define-key map [backtab] 'shr-previous-link)
587 map))
588
589 (defvar eww-textarea-map
590 (let ((map (make-keymap)))
591 (set-keymap-parent map text-mode-map)
592 (define-key map "\r" 'forward-line)
593 (define-key map [(control c) (control c)] 'eww-submit)
594 (define-key map [tab] 'shr-next-link)
595 (define-key map [backtab] 'shr-previous-link)
596 map))
597
598 (defvar eww-select-map
599 (let ((map (make-sparse-keymap)))
600 (define-key map "\r" 'eww-change-select)
601 (define-key map [(control c) (control c)] 'eww-submit)
602 map))
603
604 (defun eww-beginning-of-text ()
605 "Move to the start of the input field."
606 (interactive)
607 (goto-char (eww-beginning-of-field)))
608
609 (defun eww-end-of-text ()
610 "Move to the end of the text in the input field."
611 (interactive)
612 (goto-char (eww-end-of-field))
613 (let ((start (eww-beginning-of-field)))
614 (while (and (equal (following-char) ? )
615 (> (point) start))
616 (forward-char -1))
617 (when (> (point) start)
618 (forward-char 1))))
619
620 (defun eww-beginning-of-field ()
621 (cond
622 ((bobp)
623 (point))
624 ((not (eq (get-text-property (point) 'eww-form)
625 (get-text-property (1- (point)) 'eww-form)))
626 (point))
627 (t
628 (previous-single-property-change
629 (point) 'eww-form nil (point-min)))))
630
631 (defun eww-end-of-field ()
632 (1- (next-single-property-change
633 (point) 'eww-form nil (point-max))))
634
635 (defun eww-tag-form (cont)
636 (let ((eww-form
637 (list (assq :method cont)
638 (assq :action cont)))
639 (start (point)))
640 (shr-ensure-paragraph)
641 (shr-generic cont)
642 (unless (bolp)
643 (insert "\n"))
644 (insert "\n")
645 (when (> (point) start)
646 (put-text-property start (1+ start)
647 'eww-form eww-form))))
648
649 (defun eww-form-submit (cont)
650 (let ((start (point))
651 (value (cdr (assq :value cont))))
652 (setq value
653 (if (zerop (length value))
654 "Submit"
655 value))
656 (insert value)
657 (add-face-text-property start (point) 'eww-form-submit)
658 (put-text-property start (point) 'eww-form
659 (list :eww-form eww-form
660 :value value
661 :type "submit"
662 :name (cdr (assq :name cont))))
663 (put-text-property start (point) 'keymap eww-submit-map)
664 (insert " ")))
665
666 (defun eww-form-checkbox (cont)
667 (let ((start (point)))
668 (if (cdr (assq :checked cont))
669 (insert eww-form-checkbox-selected-symbol)
670 (insert eww-form-checkbox-symbol))
671 (add-face-text-property start (point) 'eww-form-checkbox)
672 (put-text-property start (point) 'eww-form
673 (list :eww-form eww-form
674 :value (cdr (assq :value cont))
675 :type (downcase (cdr (assq :type cont)))
676 :checked (cdr (assq :checked cont))
677 :name (cdr (assq :name cont))))
678 (put-text-property start (point) 'keymap eww-checkbox-map)
679 (insert " ")))
680
681 (defun eww-form-text (cont)
682 (let ((start (point))
683 (type (downcase (or (cdr (assq :type cont))
684 "text")))
685 (value (or (cdr (assq :value cont)) ""))
686 (width (string-to-number
687 (or (cdr (assq :size cont))
688 "40")))
689 (readonly-property (if (or (cdr (assq :disabled cont))
690 (cdr (assq :readonly cont)))
691 'read-only
692 'inhibit-read-only)))
693 (insert value)
694 (when (< (length value) width)
695 (insert (make-string (- width (length value)) ? )))
696 (put-text-property start (point) 'face 'eww-form-text)
697 (put-text-property start (point) 'local-map eww-text-map)
698 (put-text-property start (point) readonly-property t)
699 (put-text-property start (point) 'eww-form
700 (list :eww-form eww-form
701 :value value
702 :type type
703 :name (cdr (assq :name cont))))
704 (insert " ")))
705
706 (defconst eww-text-input-types '("text" "password" "textarea"
707 "color" "date" "datetime" "datetime-local"
708 "email" "month" "number" "search" "tel"
709 "time" "url" "week")
710 "List of input types which represent a text input.
711 See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.")
712
713 (defun eww-process-text-input (beg end length)
714 (let* ((form (get-text-property (min (1+ end) (point-max)) 'eww-form))
715 (properties (text-properties-at end))
716 (type (plist-get form :type)))
717 (when (and form
718 (member type eww-text-input-types))
719 (cond
720 ((zerop length)
721 ;; Delete some space at the end.
722 (save-excursion
723 (goto-char
724 (if (equal type "textarea")
725 (1- (line-end-position))
726 (eww-end-of-field)))
727 (let ((new (- end beg)))
728 (while (and (> new 0)
729 (eql (following-char) ? ))
730 (delete-region (point) (1+ (point)))
731 (setq new (1- new))))
732 (set-text-properties beg end properties)))
733 ((> length 0)
734 ;; Add padding.
735 (save-excursion
736 (goto-char
737 (if (equal type "textarea")
738 (1- (line-end-position))
739 (eww-end-of-field)))
740 (let ((start (point)))
741 (insert (make-string length ? ))
742 (set-text-properties start (point) properties)))))
743 (let ((value (buffer-substring-no-properties
744 (eww-beginning-of-field)
745 (eww-end-of-field))))
746 (when (string-match " +\\'" value)
747 (setq value (substring value 0 (match-beginning 0))))
748 (plist-put form :value value)
749 (when (equal type "password")
750 ;; Display passwords as asterisks.
751 (let ((start (eww-beginning-of-field)))
752 (put-text-property start (+ start (length value))
753 'display (make-string (length value) ?*))))))))
754
755 (defun eww-tag-textarea (cont)
756 (let ((start (point))
757 (value (or (cdr (assq :value cont)) ""))
758 (lines (string-to-number
759 (or (cdr (assq :rows cont))
760 "10")))
761 (width (string-to-number
762 (or (cdr (assq :cols cont))
763 "10")))
764 end)
765 (shr-ensure-newline)
766 (insert value)
767 (shr-ensure-newline)
768 (when (< (count-lines start (point)) lines)
769 (dotimes (i (- lines (count-lines start (point))))
770 (insert "\n")))
771 (setq end (point-marker))
772 (goto-char start)
773 (while (< (point) end)
774 (end-of-line)
775 (let ((pad (- width (- (point) (line-beginning-position)))))
776 (when (> pad 0)
777 (insert (make-string pad ? ))))
778 (add-face-text-property (line-beginning-position)
779 (point) 'eww-form-text)
780 (put-text-property (line-beginning-position) (point)
781 'local-map eww-textarea-map)
782 (forward-line 1))
783 (put-text-property start (point) 'eww-form
784 (list :eww-form eww-form
785 :value value
786 :type "textarea"
787 :name (cdr (assq :name cont))))))
788
789 (defun eww-tag-input (cont)
790 (let ((type (downcase (or (cdr (assq :type cont))
791 "text")))
792 (start (point)))
793 (cond
794 ((or (equal type "checkbox")
795 (equal type "radio"))
796 (eww-form-checkbox cont))
797 ((equal type "submit")
798 (eww-form-submit cont))
799 ((equal type "hidden")
800 (let ((form eww-form)
801 (name (cdr (assq :name cont))))
802 ;; Don't add <input type=hidden> elements repeatedly.
803 (while (and form
804 (or (not (consp (car form)))
805 (not (eq (caar form) 'hidden))
806 (not (equal (plist-get (cdr (car form)) :name)
807 name))))
808 (setq form (cdr form)))
809 (unless form
810 (nconc eww-form (list
811 (list 'hidden
812 :name name
813 :value (cdr (assq :value cont))))))))
814 (t
815 (eww-form-text cont)))
816 (unless (= start (point))
817 (put-text-property start (1+ start) 'help-echo "Input field"))))
818
819 (defun eww-tag-select (cont)
820 (shr-ensure-paragraph)
821 (let ((menu (list :name (cdr (assq :name cont))
822 :eww-form eww-form))
823 (options nil)
824 (start (point))
825 (max 0)
826 opelem)
827 (if (eq (car (car cont)) 'optgroup)
828 (dolist (groupelem cont)
829 (unless (cdr (assq :disabled (cdr groupelem)))
830 (setq opelem (append opelem (cdr (cdr groupelem))))))
831 (setq opelem cont))
832 (dolist (elem opelem)
833 (when (eq (car elem) 'option)
834 (when (cdr (assq :selected (cdr elem)))
835 (nconc menu (list :value
836 (cdr (assq :value (cdr elem))))))
837 (let ((display (or (cdr (assq 'text (cdr elem))) "")))
838 (setq max (max max (length display)))
839 (push (list 'item
840 :value (cdr (assq :value (cdr elem)))
841 :display display)
842 options))))
843 (when options
844 (setq options (nreverse options))
845 ;; If we have no selected values, default to the first value.
846 (unless (plist-get menu :value)
847 (nconc menu (list :value (nth 2 (car options)))))
848 (nconc menu options)
849 (let ((selected (eww-select-display menu)))
850 (insert selected
851 (make-string (- max (length selected)) ? )))
852 (put-text-property start (point) 'eww-form menu)
853 (add-face-text-property start (point) 'eww-form-select)
854 (put-text-property start (point) 'keymap eww-select-map)
855 (unless (= start (point))
856 (put-text-property start (1+ start) 'help-echo "select field"))
857 (shr-ensure-paragraph))))
858
859 (defun eww-select-display (select)
860 (let ((value (plist-get select :value))
861 display)
862 (dolist (elem select)
863 (when (and (consp elem)
864 (eq (car elem) 'item)
865 (equal value (plist-get (cdr elem) :value)))
866 (setq display (plist-get (cdr elem) :display))))
867 display))
868
869 (defun eww-change-select ()
870 "Change the value of the select drop-down menu under point."
871 (interactive)
872 (let* ((input (get-text-property (point) 'eww-form))
873 (completion-ignore-case t)
874 (options
875 (delq nil
876 (mapcar (lambda (elem)
877 (and (consp elem)
878 (eq (car elem) 'item)
879 (cons (plist-get (cdr elem) :display)
880 (plist-get (cdr elem) :value))))
881 input)))
882 (display
883 (completing-read "Change value: " options nil 'require-match))
884 (inhibit-read-only t))
885 (plist-put input :value (cdr (assoc-string display options t)))
886 (goto-char
887 (eww-update-field display))))
888
889 (defun eww-update-field (string)
890 (let ((properties (text-properties-at (point)))
891 (start (eww-beginning-of-field))
892 (end (1+ (eww-end-of-field))))
893 (delete-region start end)
894 (insert string
895 (make-string (- (- end start) (length string)) ? ))
896 (set-text-properties start end properties)
897 start))
898
899 (defun eww-toggle-checkbox ()
900 "Toggle the value of the checkbox under point."
901 (interactive)
902 (let* ((input (get-text-property (point) 'eww-form))
903 (type (plist-get input :type)))
904 (if (equal type "checkbox")
905 (goto-char
906 (1+
907 (if (plist-get input :checked)
908 (progn
909 (plist-put input :checked nil)
910 (eww-update-field eww-form-checkbox-symbol))
911 (plist-put input :checked t)
912 (eww-update-field eww-form-checkbox-selected-symbol))))
913 ;; Radio button. Switch all other buttons off.
914 (let ((name (plist-get input :name)))
915 (save-excursion
916 (dolist (elem (eww-inputs (plist-get input :eww-form)))
917 (when (equal (plist-get (cdr elem) :name) name)
918 (goto-char (car elem))
919 (if (not (eq (cdr elem) input))
920 (progn
921 (plist-put input :checked nil)
922 (eww-update-field eww-form-checkbox-symbol))
923 (plist-put input :checked t)
924 (eww-update-field eww-form-checkbox-selected-symbol)))))
925 (forward-char 1)))))
926
927 (defun eww-inputs (form)
928 (let ((start (point-min))
929 (inputs nil))
930 (while (and start
931 (< start (point-max)))
932 (when (or (get-text-property start 'eww-form)
933 (setq start (next-single-property-change start 'eww-form)))
934 (when (eq (plist-get (get-text-property start 'eww-form) :eww-form)
935 form)
936 (push (cons start (get-text-property start 'eww-form))
937 inputs))
938 (setq start (next-single-property-change start 'eww-form))))
939 (nreverse inputs)))
940
941 (defun eww-input-value (input)
942 (let ((type (plist-get input :type))
943 (value (plist-get input :value)))
944 (cond
945 ((equal type "textarea")
946 (with-temp-buffer
947 (insert value)
948 (goto-char (point-min))
949 (while (re-search-forward "^ +\n\\| +$" nil t)
950 (replace-match "" t t))
951 (buffer-string)))
952 (t
953 (if (string-match " +\\'" value)
954 (substring value 0 (match-beginning 0))
955 value)))))
956
957 (defun eww-submit ()
958 "Submit the current form."
959 (interactive)
960 (let* ((this-input (get-text-property (point) 'eww-form))
961 (form (plist-get this-input :eww-form))
962 values next-submit)
963 (dolist (elem (sort (eww-inputs form)
964 (lambda (o1 o2)
965 (< (car o1) (car o2)))))
966 (let* ((input (cdr elem))
967 (input-start (car elem))
968 (name (plist-get input :name)))
969 (when name
970 (cond
971 ((member (plist-get input :type) '("checkbox" "radio"))
972 (when (plist-get input :checked)
973 (push (cons name (plist-get input :value))
974 values)))
975 ((equal (plist-get input :type) "submit")
976 ;; We want the values from buttons if we hit a button if
977 ;; we hit enter on it, or if it's the first button after
978 ;; the field we did hit return on.
979 (when (or (eq input this-input)
980 (and (not (eq input this-input))
981 (null next-submit)
982 (> input-start (point))))
983 (setq next-submit t)
984 (push (cons name (plist-get input :value))
985 values)))
986 (t
987 (push (cons name (eww-input-value input))
988 values))))))
989 (dolist (elem form)
990 (when (and (consp elem)
991 (eq (car elem) 'hidden))
992 (push (cons (plist-get (cdr elem) :name)
993 (plist-get (cdr elem) :value))
994 values)))
995 (if (and (stringp (cdr (assq :method form)))
996 (equal (downcase (cdr (assq :method form))) "post"))
997 (let ((url-request-method "POST")
998 (url-request-extra-headers
999 '(("Content-Type" . "application/x-www-form-urlencoded")))
1000 (url-request-data (mm-url-encode-www-form-urlencoded values)))
1001 (eww-browse-url (shr-expand-url (cdr (assq :action form))
1002 eww-current-url)))
1003 (eww-browse-url
1004 (concat
1005 (if (cdr (assq :action form))
1006 (shr-expand-url (cdr (assq :action form))
1007 eww-current-url)
1008 eww-current-url)
1009 "?"
1010 (mm-url-encode-www-form-urlencoded values))))))
1011
1012 (defun eww-browse-with-external-browser (&optional url)
1013 "Browse the current URL with an external browser.
1014 The browser to used is specified by the `shr-external-browser' variable."
1015 (interactive)
1016 (funcall shr-external-browser (or url eww-current-url)))
1017
1018 (defun eww-follow-link (&optional external mouse-event)
1019 "Browse the URL under point.
1020 If EXTERNAL, browse the URL using `shr-external-browser'."
1021 (interactive (list current-prefix-arg last-nonmenu-event))
1022 (mouse-set-point mouse-event)
1023 (let ((url (get-text-property (point) 'shr-url)))
1024 (cond
1025 ((not url)
1026 (message "No link under point"))
1027 ((string-match "^mailto:" url)
1028 (browse-url-mail url))
1029 (external
1030 (funcall shr-external-browser url))
1031 ;; This is a #target url in the same page as the current one.
1032 ((and (url-target (url-generic-parse-url url))
1033 (eww-same-page-p url eww-current-url))
1034 (eww-save-history)
1035 (eww-display-html 'utf8 url eww-current-dom))
1036 (t
1037 (eww-browse-url url)))))
1038
1039 (defun eww-same-page-p (url1 url2)
1040 "Return non-nil if both URLs represent the same page.
1041 Differences in #targets are ignored."
1042 (let ((obj1 (url-generic-parse-url url1))
1043 (obj2 (url-generic-parse-url url2)))
1044 (setf (url-target obj1) nil)
1045 (setf (url-target obj2) nil)
1046 (equal (url-recreate-url obj1) (url-recreate-url obj2))))
1047
1048 (defun eww-copy-page-url ()
1049 (interactive)
1050 (message "%s" eww-current-url)
1051 (kill-new eww-current-url))
1052
1053 (defun eww-download ()
1054 "Download URL under point to `eww-download-directory'."
1055 (interactive)
1056 (let ((url (get-text-property (point) 'shr-url)))
1057 (if (not url)
1058 (message "No URL under point")
1059 (url-retrieve url 'eww-download-callback (list url)))))
1060
1061 (defun eww-download-callback (status url)
1062 (unless (plist-get status :error)
1063 (let* ((obj (url-generic-parse-url url))
1064 (path (car (url-path-and-query obj)))
1065 (file (eww-make-unique-file-name (file-name-nondirectory path)
1066 eww-download-path)))
1067 (write-file file)
1068 (message "Saved %s" file))))
1069
1070 (defun eww-make-unique-file-name (file directory)
1071 (cond
1072 ((zerop (length file))
1073 (setq file "!"))
1074 ((string-match "\\`[.]" file)
1075 (setq file (concat "!" file))))
1076 (let ((count 1))
1077 (while (file-exists-p (expand-file-name file directory))
1078 (setq file
1079 (if (string-match "\\`\\(.*\\)\\([.][^.]+\\)" file)
1080 (format "%s(%d)%s" (match-string 1 file)
1081 count (match-string 2 file))
1082 (format "%s(%d)" file count)))
1083 (setq count (1+ count)))
1084 (expand-file-name file directory)))
1085
1086 ;;; Bookmarks code
1087
1088 (defvar eww-bookmarks nil)
1089
1090 (defun eww-add-bookmark ()
1091 "Add the current page to the bookmarks."
1092 (interactive)
1093 (eww-read-bookmarks)
1094 (dolist (bookmark eww-bookmarks)
1095 (when (equal eww-current-url
1096 (plist-get bookmark :url))
1097 (user-error "Already bookmarked")))
1098 (if (y-or-n-p "bookmark this page? ")
1099 (progn
1100 (let ((title (replace-regexp-in-string "[\n\t\r]" " " eww-current-title)))
1101 (setq title (replace-regexp-in-string "\\` +\\| +\\'" "" title))
1102 (push (list :url eww-current-url
1103 :title title
1104 :time (current-time-string))
1105 eww-bookmarks))
1106 (eww-write-bookmarks)
1107 (message "Bookmarked %s (%s)" eww-current-url eww-current-title))))
1108
1109 (defun eww-write-bookmarks ()
1110 (with-temp-file (expand-file-name "eww-bookmarks" user-emacs-directory)
1111 (insert ";; Auto-generated file; don't edit\n")
1112 (pp eww-bookmarks (current-buffer))))
1113
1114 (defun eww-read-bookmarks ()
1115 (let ((file (expand-file-name "eww-bookmarks" user-emacs-directory)))
1116 (setq eww-bookmarks
1117 (unless (zerop (or (nth 7 (file-attributes file)) 0))
1118 (with-temp-buffer
1119 (insert-file-contents file)
1120 (read (current-buffer)))))))
1121
1122 (defun eww-list-bookmarks ()
1123 "Display the bookmarks."
1124 (interactive)
1125 (eww-bookmark-prepare)
1126 (pop-to-buffer "*eww bookmarks*"))
1127
1128 (defun eww-bookmark-prepare ()
1129 (eww-read-bookmarks)
1130 (unless eww-bookmarks
1131 (user-error "No bookmarks are defined"))
1132 (set-buffer (get-buffer-create "*eww bookmarks*"))
1133 (eww-bookmark-mode)
1134 (let ((format "%-40s %s")
1135 (inhibit-read-only t)
1136 start url)
1137 (erase-buffer)
1138 (setq header-line-format (concat " " (format format "URL" "Title")))
1139 (dolist (bookmark eww-bookmarks)
1140 (setq start (point))
1141 (setq url (plist-get bookmark :url))
1142 (when (> (length url) 40)
1143 (setq url (substring url 0 40)))
1144 (insert (format format url
1145 (plist-get bookmark :title))
1146 "\n")
1147 (put-text-property start (1+ start) 'eww-bookmark bookmark))
1148 (goto-char (point-min))))
1149
1150 (defvar eww-bookmark-kill-ring nil)
1151
1152 (defun eww-bookmark-kill ()
1153 "Kill the current bookmark."
1154 (interactive)
1155 (let* ((start (line-beginning-position))
1156 (bookmark (get-text-property start 'eww-bookmark))
1157 (inhibit-read-only t))
1158 (unless bookmark
1159 (user-error "No bookmark on the current line"))
1160 (forward-line 1)
1161 (push (buffer-substring start (point)) eww-bookmark-kill-ring)
1162 (delete-region start (point))
1163 (setq eww-bookmarks (delq bookmark eww-bookmarks))
1164 (eww-write-bookmarks)))
1165
1166 (defun eww-bookmark-yank ()
1167 "Yank a previously killed bookmark to the current line."
1168 (interactive)
1169 (unless eww-bookmark-kill-ring
1170 (user-error "No previously killed bookmark"))
1171 (beginning-of-line)
1172 (let ((inhibit-read-only t)
1173 (start (point))
1174 bookmark)
1175 (insert (pop eww-bookmark-kill-ring))
1176 (setq bookmark (get-text-property start 'eww-bookmark))
1177 (if (= start (point-min))
1178 (push bookmark eww-bookmarks)
1179 (let ((line (count-lines start (point))))
1180 (setcdr (nthcdr (1- line) eww-bookmarks)
1181 (cons bookmark (nthcdr line eww-bookmarks)))))
1182 (eww-write-bookmarks)))
1183
1184 (defun eww-bookmark-browse ()
1185 "Browse the bookmark under point in eww."
1186 (interactive)
1187 (let ((bookmark (get-text-property (line-beginning-position) 'eww-bookmark)))
1188 (unless bookmark
1189 (user-error "No bookmark on the current line"))
1190 (quit-window)
1191 (eww-browse-url (plist-get bookmark :url))))
1192
1193 (defun eww-next-bookmark ()
1194 "Go to the next bookmark in the list."
1195 (interactive)
1196 (let ((first nil)
1197 bookmark)
1198 (unless (get-buffer "*eww bookmarks*")
1199 (setq first t)
1200 (eww-bookmark-prepare))
1201 (with-current-buffer (get-buffer "*eww bookmarks*")
1202 (when (and (not first)
1203 (not (eobp)))
1204 (forward-line 1))
1205 (setq bookmark (get-text-property (line-beginning-position)
1206 'eww-bookmark))
1207 (unless bookmark
1208 (user-error "No next bookmark")))
1209 (eww-browse-url (plist-get bookmark :url))))
1210
1211 (defun eww-previous-bookmark ()
1212 "Go to the previous bookmark in the list."
1213 (interactive)
1214 (let ((first nil)
1215 bookmark)
1216 (unless (get-buffer "*eww bookmarks*")
1217 (setq first t)
1218 (eww-bookmark-prepare))
1219 (with-current-buffer (get-buffer "*eww bookmarks*")
1220 (if first
1221 (goto-char (point-max))
1222 (beginning-of-line))
1223 ;; On the final line.
1224 (when (eolp)
1225 (forward-line -1))
1226 (if (bobp)
1227 (user-error "No previous bookmark")
1228 (forward-line -1))
1229 (setq bookmark (get-text-property (line-beginning-position)
1230 'eww-bookmark)))
1231 (eww-browse-url (plist-get bookmark :url))))
1232
1233 (defvar eww-bookmark-mode-map
1234 (let ((map (make-sparse-keymap)))
1235 (suppress-keymap map)
1236 (define-key map "q" 'quit-window)
1237 (define-key map [(control k)] 'eww-bookmark-kill)
1238 (define-key map [(control y)] 'eww-bookmark-yank)
1239 (define-key map "\r" 'eww-bookmark-browse)
1240
1241 (easy-menu-define nil map
1242 "Menu for `eww-bookmark-mode-map'."
1243 '("Eww Bookmark"
1244 ["Exit" quit-window t]
1245 ["Browse" eww-bookmark-browse
1246 :active (get-text-property (line-beginning-position) 'eww-bookmark)]
1247 ["Kill" eww-bookmark-kill
1248 :active (get-text-property (line-beginning-position) 'eww-bookmark)]
1249 ["Yank" eww-bookmark-yank
1250 :active eww-bookmark-kill-ring]))
1251 map))
1252
1253 (define-derived-mode eww-bookmark-mode nil "eww bookmarks"
1254 "Mode for listing bookmarks.
1255
1256 \\{eww-bookmark-mode-map}"
1257 (buffer-disable-undo)
1258 (setq buffer-read-only t
1259 truncate-lines t))
1260
1261 ;;; History code
1262
1263 (defun eww-save-history ()
1264 (push (list :url eww-current-url
1265 :title eww-current-title
1266 :point (point)
1267 :dom eww-current-dom
1268 :source eww-current-source
1269 :text (buffer-string))
1270 eww-history))
1271
1272 (defun eww-list-histories ()
1273 "List the eww-histories."
1274 (interactive)
1275 (when (null eww-history)
1276 (error "No eww-histories are defined"))
1277 (set-buffer (get-buffer-create "*eww history*"))
1278 (eww-history-mode)
1279 (let ((inhibit-read-only t)
1280 (domain-length 0)
1281 (title-length 0)
1282 url title format start)
1283 (erase-buffer)
1284 (dolist (history eww-history)
1285 (setq start (point))
1286 (setq domain-length (max domain-length (length (plist-get history :url))))
1287 (setq title-length (max title-length (length (plist-get history :title))))
1288 )
1289 (setq format (format "%%-%ds %%-%ds" title-length domain-length)
1290 header-line-format
1291 (concat " " (format format "Title" "URL")))
1292
1293 (dolist (history eww-history)
1294 (setq url (plist-get history :url))
1295 (setq title (plist-get history :title))
1296 (insert (format format title url))
1297 (insert "\n")
1298 (put-text-property start (point) 'eww-history history)
1299 )
1300 (goto-char (point-min)))
1301 (pop-to-buffer "*eww history*")
1302 )
1303
1304 (defun eww-history-browse ()
1305 "Browse the history under point in eww."
1306 (interactive)
1307 (let ((history (get-text-property (line-beginning-position) 'eww-history)))
1308 (unless history
1309 (error "No history on the current line"))
1310 (eww-history-quit)
1311 (pop-to-buffer "*eww*")
1312 (eww-browse-url (plist-get history :url))))
1313
1314 (defun eww-history-quit ()
1315 "Kill the current buffer."
1316 (interactive)
1317 (kill-buffer (current-buffer)))
1318
1319 (defvar eww-history-kill-ring nil)
1320
1321 (defun eww-history-kill ()
1322 "Kill the current history."
1323 (interactive)
1324 (let* ((start (line-beginning-position))
1325 (history (get-text-property start 'eww-history))
1326 (inhibit-read-only t))
1327 (unless history
1328 (error "No history on the current line"))
1329 (forward-line 1)
1330 (push (buffer-substring start (point)) eww-history-kill-ring)
1331 (delete-region start (point))
1332 (setq eww-history (delq history eww-history))
1333 ))
1334
1335 (defvar eww-history-mode-map
1336 (let ((map (make-sparse-keymap)))
1337 (suppress-keymap map)
1338 (define-key map "q" 'eww-history-quit)
1339 (define-key map [(control k)] 'eww-history-kill)
1340 (define-key map "\r" 'eww-history-browse)
1341 (define-key map "n" 'next-error-no-select)
1342 (define-key map "p" 'previous-error-no-select)
1343 map))
1344
1345 (define-derived-mode eww-history-mode nil "eww history"
1346 "Mode for listing eww-histories.
1347
1348 \\{eww-history-mode-map}"
1349 (buffer-disable-undo)
1350 (setq buffer-read-only t
1351 truncate-lines t))
1352
1353 (provide 'eww)
1354
1355 ;;; eww.el ends here