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