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