From: Lars Ingebrigtsen Date: Fri, 25 Dec 2015 17:50:43 +0000 (+0100) Subject: Allow toggling colors in eww X-Git-Tag: emacs-26.0.90~2868 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=6d124eef1c940b251277b3eed6dd55eb7565d97e;p=emacs.git Allow toggling colors in eww * doc/misc/eww.texi (Basics): Mention "C". * lisp/net/eww.el (eww-toggle-colors): New command and keystroke. * lisp/net/shr.el (shr-use-colors): New variable. (shr-colorize-region): Use it. --- diff --git a/doc/misc/eww.texi b/doc/misc/eww.texi index f1347b7b3bb..15cc867dc7f 100644 --- a/doc/misc/eww.texi +++ b/doc/misc/eww.texi @@ -109,6 +109,12 @@ only display this part. This usually gets rid of menus and the like. The @kbd{F} command (@code{eww-toggle-fonts}) toggles whether to use variable-pitch fonts or not. This sets the @code{shr-use-fonts} variable. +@findex eww-toggle-colors +@findex shr-use-colors +@kindex F + The @kbd{C} command (@code{eww-toggle-colors}) toggles whether to use +HTML-specified colors or not. This sets the @code{shr-use-colors} variable. + @findex eww-download @vindex eww-download-directory @kindex d diff --git a/etc/NEWS b/etc/NEWS index 1ef496c62d0..76fac3e03cd 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -523,6 +523,11 @@ useful when, for example, one needs to distinguish various spaces (e.g. ] [, whether to use variable-pitch fonts or not. The user can also customize the `shr-use-fonts' variable. ++++ +*** A new command `C' (`eww-toggle-colors) can be used to toggle +whether to use the HTML-specified colors or not. The user can also +customize the `shr-use-colors variable. + +++ *** A new command `R' (`eww-readable') will try do identify the main textual parts of a web page and display only that, leaving menus and diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 742e1e4d1c0..0bd60367f65 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -681,6 +681,7 @@ the like." (define-key map "E" 'eww-set-character-encoding) (define-key map "S" 'eww-list-buffers) (define-key map "F" 'eww-toggle-fonts) + (define-key map [(meta C)] 'eww-toggle-fonts) (define-key map "b" 'eww-add-bookmark) (define-key map "B" 'eww-list-bookmarks) @@ -705,6 +706,8 @@ the like." ["Add bookmark" eww-add-bookmark t] ["List bookmarks" eww-list-bookmarks t] ["List cookies" url-cookie-list t] + ["Toggle fonts" eww-toggle-fonts t] + ["Toggle colors" eww-toggle-colors t] ["Character Encoding" eww-set-character-encoding])) map)) @@ -1495,6 +1498,15 @@ If CHARSET is nil then use UTF-8." "off")) (eww-reload)) +(defun eww-toggle-colors () + "Toggle whether to use HTML-specified colors or not." + (interactive) + (message "Colors are now %s" + (if (setq shr-use-colors (not shr-use-colors)) + "on" + "off")) + (eww-reload)) + ;;; Bookmarks code (defvar eww-bookmarks nil) diff --git a/lisp/net/shr.el b/lisp/net/shr.el index a7fdf9e1181..3d5f02c359b 100644 --- a/lisp/net/shr.el +++ b/lisp/net/shr.el @@ -63,6 +63,12 @@ fit these criteria." :group 'shr :type 'boolean) +(defcustom shr-use-colors t + "If non-nil, respect color specifications in the HTML." + :version "25.2" + :group 'shr + :type 'boolean) + (defcustom shr-table-horizontal-line nil "Character used to draw horizontal table lines. If nil, don't draw horizontal table lines." @@ -1082,7 +1088,9 @@ ones, in case fg and bg are nil." (shr-color-visible bg fg))))))) (defun shr-colorize-region (start end fg &optional bg) - (when (and (or fg bg) (>= (display-color-cells) 88)) + (when (and shr-use-colors + (or fg bg) + (>= (display-color-cells) 88)) (let ((new-colors (shr-color-check fg bg))) (when new-colors (when fg