From 2adb64ce5794b535af5b5c1a390a348a12d9f898 Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Tue, 13 Nov 2018 12:35:32 +0100 Subject: [PATCH] update htmlize. Signed-off-by: Andreas Gerler --- elpa/htmlize-20130207.1202/htmlize-pkg.el | 1 - .../htmlize-autoloads.el | 13 +- elpa/htmlize-20180923.1829/htmlize-pkg.el | 2 + .../htmlize.el | 536 ++++++++---------- 4 files changed, 249 insertions(+), 303 deletions(-) delete mode 100644 elpa/htmlize-20130207.1202/htmlize-pkg.el rename elpa/{htmlize-20130207.1202 => htmlize-20180923.1829}/htmlize-autoloads.el (90%) create mode 100644 elpa/htmlize-20180923.1829/htmlize-pkg.el rename elpa/{htmlize-20130207.1202 => htmlize-20180923.1829}/htmlize.el (83%) diff --git a/elpa/htmlize-20130207.1202/htmlize-pkg.el b/elpa/htmlize-20130207.1202/htmlize-pkg.el deleted file mode 100644 index e7624a64..00000000 --- a/elpa/htmlize-20130207.1202/htmlize-pkg.el +++ /dev/null @@ -1 +0,0 @@ -(define-package "htmlize" "20130207.1202" "Convert buffer text and decorations to HTML." (quote nil)) diff --git a/elpa/htmlize-20130207.1202/htmlize-autoloads.el b/elpa/htmlize-20180923.1829/htmlize-autoloads.el similarity index 90% rename from elpa/htmlize-20130207.1202/htmlize-autoloads.el rename to elpa/htmlize-20180923.1829/htmlize-autoloads.el index e59a4a39..2de24ed5 100644 --- a/elpa/htmlize-20130207.1202/htmlize-autoloads.el +++ b/elpa/htmlize-20180923.1829/htmlize-autoloads.el @@ -2,10 +2,11 @@ ;; ;;; Code: +(add-to-list 'load-path (directory-file-name + (or (file-name-directory #$) (car load-path)))) + -;;;### (autoloads (htmlize-many-files-dired htmlize-many-files htmlize-file -;;;;;; htmlize-region htmlize-buffer) "htmlize" "htmlize.el" (21595 -;;;;;; 16733 0 0)) +;;;### (autoloads nil "htmlize" "htmlize.el" (0 0 0 0)) ;;; Generated autoloads from htmlize.el (autoload 'htmlize-buffer "htmlize" "\ @@ -68,14 +69,10 @@ HTMLize dired-marked files. \(fn ARG &optional TARGET-DIRECTORY)" t nil) -;;;*** - -;;;### (autoloads nil nil ("htmlize-pkg.el") (21595 16733 247946 -;;;;;; 0)) +(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "htmlize" '("htmlize-"))) ;;;*** -(provide 'htmlize-autoloads) ;; Local Variables: ;; version-control: never ;; no-byte-compile: t diff --git a/elpa/htmlize-20180923.1829/htmlize-pkg.el b/elpa/htmlize-20180923.1829/htmlize-pkg.el new file mode 100644 index 00000000..84c4c328 --- /dev/null +++ b/elpa/htmlize-20180923.1829/htmlize-pkg.el @@ -0,0 +1,2 @@ +;;; -*- no-byte-compile: t -*- +(define-package "htmlize" "20180923.1829" "Convert buffer text and decorations to HTML." 'nil :commit "8db0aa6aab77475a732b7363f0d57bd3933c18fd" :keywords '("hypermedia" "extensions") :authors '(("Hrvoje Niksic" . "hniksic@gmail.com")) :maintainer '("Hrvoje Niksic" . "hniksic@gmail.com")) diff --git a/elpa/htmlize-20130207.1202/htmlize.el b/elpa/htmlize-20180923.1829/htmlize.el similarity index 83% rename from elpa/htmlize-20130207.1202/htmlize.el rename to elpa/htmlize-20180923.1829/htmlize.el index 6a0eef73..60478ecf 100644 --- a/elpa/htmlize-20130207.1202/htmlize.el +++ b/elpa/htmlize-20180923.1829/htmlize.el @@ -1,11 +1,11 @@ -;;; htmlize.el --- Convert buffer text and decorations to HTML. +;;; htmlize.el --- Convert buffer text and decorations to HTML. -*- lexical-binding: t -*- -;; Copyright (C) 1997-2003,2005,2006,2009,2011,2012 Hrvoje Niksic +;; Copyright (C) 1997-2003,2005,2006,2009,2011,2012,2014,2017,2018 Hrvoje Niksic -;; Author: Hrvoje Niksic +;; Author: Hrvoje Niksic ;; Keywords: hypermedia, extensions -;; Version: 20130207.1202 -;; X-Original-Version: 1.47 +;; Package-Version: 20180923.1829 +;; Version: 1.55 ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ ;;; Commentary: ;; This package converts the buffer text and the associated -;; decorations to HTML. Mail to to discuss +;; decorations to HTML. Mail to to discuss ;; features and additions. All suggestions are more than welcome. ;; To use it, just switch to the buffer you want HTML-ized and type @@ -58,26 +58,17 @@ ;; non-windowing Emacs sessions but the result will be limited to ;; colors supported by the terminal. -;; htmlize aims for compatibility with Emacsen version 21 and later. -;; Please let me know if it doesn't work on the version of XEmacs or -;; GNU Emacs that you are using. The package relies on the presence -;; of CL extensions, especially for cross-emacs compatibility; please -;; don't try to remove that dependency. I see no practical problems -;; with using the full power of the CL extensions, except that one -;; might learn to like them too much. +;; htmlize aims for compatibility with older Emacs versions. Please +;; let me know if it doesn't work on the version of GNU Emacs that you +;; are using. The package relies on the presence of CL extensions; +;; please don't try to remove that dependency. I see no practical +;; problems with using the full power of the CL extensions, except +;; that one might learn to like them too much. -;; The latest version is available as a git repository at: +;; The latest version is available at: ;; -;; +;; ;; -;; The snapshot of the latest release can be obtained at: -;; -;; -;; -;; You can find a sample of htmlize's output (possibly generated with -;; an older version) at: -;; -;; ;; Thanks go to the many people who have sent reports and contributed ;; comments, suggestions, and fixes. They include Ron Gut, Bob @@ -92,15 +83,11 @@ (require 'cl) (eval-when-compile - (defvar unresolved) - (if (string-match "XEmacs" emacs-version) - (byte-compiler-options - (warnings (- unresolved)))) (defvar font-lock-auto-fontify) (defvar font-lock-support-mode) (defvar global-font-lock-mode)) -(defconst htmlize-version "1.47") +(defconst htmlize-version "1.55") (defgroup htmlize nil "Convert buffer text and faces to HTML." @@ -152,7 +139,9 @@ embedded in the HTML as data URIs." Normally when htmlize encounters text covered by the `display' property that specifies an image, it generates an `alt' attribute containing the original text. If the text is larger than `htmlize-max-alt-text' characters, -this will not be done.") +this will not be done." + :type 'integer + :group 'htmlize) (defcustom htmlize-transform-image 'htmlize-default-transform-image "Function called to modify the image descriptor. @@ -296,6 +285,28 @@ running Emacs on non-X11 systems), this option is ignored." :type 'boolean :group 'htmlize) +(defvar htmlize-face-overrides nil + "Overrides for face definitions. + +Normally face definitions are taken from Emacs settings for fonts +in the current frame. For faces present in this plist, the +definitions will be used instead. Keys in the plist are symbols +naming the face and values are the overriding definitions. For +example: + + (setq htmlize-face-overrides + '(font-lock-warning-face \"black\" + font-lock-function-name-face \"red\" + font-lock-comment-face \"blue\" + default (:foreground \"dark-green\" :background \"yellow\"))) + +This variable can be also be `let' bound when running `htmlize-buffer'.") + +(defcustom htmlize-untabify t + "Non-nil means untabify buffer contents during htmlization." + :type 'boolean + :group 'htmlize) + (defcustom htmlize-html-major-mode nil "The mode the newly created HTML buffer will be put in. Set this to nil if you prefer the default (fundamental) mode." @@ -304,6 +315,13 @@ Set this to nil if you prefer the default (fundamental) mode." (function :tag "User-defined major mode")) :group 'htmlize) +(defcustom htmlize-pre-style nil + "When non-nil, `
' tags will be decorated with style
+information in `font' and `inline-css' modes. This allows a
+consistent background for captures of regions."
+  :type 'boolean
+  :group 'htmlize)
+
 (defvar htmlize-before-hook nil
   "Hook run before htmlizing a buffer.
 The hook functions are run in the source buffer (not the resulting HTML
@@ -322,50 +340,36 @@ output.")
 
 ;;; Some cross-Emacs compatibility.
 
-;; I try to conditionalize on features rather than Emacs version, but
-;; in some cases checking against the version *is* necessary.
-(defconst htmlize-running-xemacs (string-match "XEmacs" emacs-version))
-
 ;; We need a function that efficiently finds the next change of a
 ;; property regardless of whether the change occurred because of a
 ;; text property or an extent/overlay.
-(cond
- (htmlize-running-xemacs
-  (defun htmlize-next-change (pos prop &optional limit)
-    (if prop
-        (next-single-char-property-change pos prop nil (or limit (point-max)))
-      (next-property-change pos nil (or limit (point-max)))))
-  (defun htmlize-next-face-change (pos &optional limit)
-    (htmlize-next-change pos 'face limit)))
- (t
-  (defun htmlize-next-change (pos prop &optional limit)
-    (if prop
-        (next-single-char-property-change pos prop nil limit)
-      (next-char-property-change pos limit)))
-  (defun htmlize-overlay-faces-at (pos)
-    (delq nil (mapcar (lambda (o) (overlay-get o 'face)) (overlays-at pos))))
-  (defun htmlize-next-face-change (pos &optional limit)
-    ;; (htmlize-next-change pos 'face limit) would skip over entire
-    ;; overlays that specify the `face' property, even when they
-    ;; contain smaller text properties that also specify `face'.
-    ;; Emacs display engine merges those faces, and so must we.
-    (or limit
-        (setq limit (point-max)))
-    (let ((next-prop (next-single-property-change pos 'face nil limit))
-          (overlay-faces (htmlize-overlay-faces-at pos)))
-      (while (progn
-               (setq pos (next-overlay-change pos))
-               (and (< pos next-prop)
-                    (equal overlay-faces (htmlize-overlay-faces-at pos)))))
-      (setq pos (min pos next-prop))
-      ;; Additionally, we include the entire region that specifies the
-      ;; `display' property.
-      (when (get-char-property pos 'display)
-        (setq pos (next-single-char-property-change pos 'display nil limit)))
-      pos)))
- (t
-  (error "htmlize requires next-single-property-change or \
-next-single-char-property-change")))
+(defun htmlize-next-change (pos prop &optional limit)
+  (if prop
+      (next-single-char-property-change pos prop nil limit)
+    (next-char-property-change pos limit)))
+
+(defun htmlize-overlay-faces-at (pos)
+  (delq nil (mapcar (lambda (o) (overlay-get o 'face)) (overlays-at pos))))
+
+(defun htmlize-next-face-change (pos &optional limit)
+  ;; (htmlize-next-change pos 'face limit) would skip over entire
+  ;; overlays that specify the `face' property, even when they
+  ;; contain smaller text properties that also specify `face'.
+  ;; Emacs display engine merges those faces, and so must we.
+  (or limit
+      (setq limit (point-max)))
+  (let ((next-prop (next-single-property-change pos 'face nil limit))
+        (overlay-faces (htmlize-overlay-faces-at pos)))
+    (while (progn
+             (setq pos (next-overlay-change pos))
+             (and (< pos next-prop)
+                  (equal overlay-faces (htmlize-overlay-faces-at pos)))))
+    (setq pos (min pos next-prop))
+    ;; Additionally, we include the entire region that specifies the
+    ;; `display' property.
+    (when (get-char-property pos 'display)
+      (setq pos (next-single-char-property-change pos 'display nil limit)))
+    pos))
 
 (defmacro htmlize-lexlet (&rest letforms)
   (declare (indent 1) (debug let))
@@ -375,22 +379,6 @@ next-single-char-property-change")))
     ;; cl extensions have a macro implementing lexical let
     `(lexical-let ,@letforms)))
 
-;; Simple overlay emulation for XEmacs
-
-(cond
- (htmlize-running-xemacs
-  (defalias 'htmlize-make-overlay 'make-extent)
-  (defalias 'htmlize-overlay-put 'set-extent-property)
-  (defalias 'htmlize-overlay-get 'extent-property)
-  (defun htmlize-overlays-in (beg end) (extent-list nil beg end))
-  (defalias 'htmlize-delete-overlay 'detach-extent))
- (t
-  (defalias 'htmlize-make-overlay 'make-overlay)
-  (defalias 'htmlize-overlay-put 'overlay-put)
-  (defalias 'htmlize-overlay-get 'overlay-get)
-  (defalias 'htmlize-overlays-in 'overlays-in)
-  (defalias 'htmlize-delete-overlay 'delete-overlay)))
-
 
 ;;; Transformation of buffer text: HTML escapes, untabification, etc.
 
@@ -684,8 +672,7 @@ list."
   (let ((text (buffer-substring-no-properties beg end)))
     (htmlize-copy-prop 'display beg end text)
     (htmlize-copy-prop 'htmlize-link beg end text)
-    (unless htmlize-running-xemacs
-      (setq text (htmlize-add-before-after-strings beg end text)))
+    (setq text (htmlize-add-before-after-strings beg end text))
     text))
 
 (defun htmlize-buffer-substring-no-invisible (beg end)
@@ -728,7 +715,7 @@ list."
       (setf (aref v i) (make-string i ?\ )))
     v))
 
-(defun htmlize-untabify (text start-column)
+(defun htmlize-untabify-string (text start-column)
   "Untabify TEXT, assuming it starts at START-COLUMN."
   (let ((column start-column)
 	(last-match 0)
@@ -780,7 +767,8 @@ list."
       (setq trailing-ellipsis
             (get-text-property (1- (length text))
                                'htmlize-ellipsis text)))
-    (setq text (htmlize-untabify text (current-column)))
+    (when htmlize-untabify
+      (setq text (htmlize-untabify-string text (current-column))))
     (setq text (htmlize-string-to-html text))
     (values text trailing-ellipsis)))
 
@@ -793,16 +781,16 @@ This is used to protect mailto links without modifying their meaning."
   string)
 
 (defun htmlize-make-tmp-overlay (beg end props)
-  (let ((overlay (htmlize-make-overlay beg end)))
-    (htmlize-overlay-put overlay 'htmlize-tmp-overlay t)
+  (let ((overlay (make-overlay beg end)))
+    (overlay-put overlay 'htmlize-tmp-overlay t)
     (while props
-      (htmlize-overlay-put overlay (pop props) (pop props)))
+      (overlay-put overlay (pop props) (pop props)))
     overlay))
 
 (defun htmlize-delete-tmp-overlays ()
-  (dolist (overlay (htmlize-overlays-in (point-min) (point-max)))
-    (when (htmlize-overlay-get overlay 'htmlize-tmp-overlay)
-      (htmlize-delete-overlay overlay))))
+  (dolist (overlay (overlays-in (point-min) (point-max)))
+    (when (overlay-get overlay 'htmlize-tmp-overlay)
+      (delete-overlay overlay))))
 
 (defun htmlize-make-link-overlay (beg end uri)
   (htmlize-make-tmp-overlay beg end `(htmlize-link (:uri ,uri))))
@@ -838,7 +826,15 @@ This is used to protect mailto links without modifying their meaning."
     (put-text-property 0 (length s) 'htmlize-literal t s)
     (let ((disp `(display ,s)))
       (while (re-search-forward "\n\^L" nil t)
-        (htmlize-make-tmp-overlay (match-beginning 0) (match-end 0) disp)))))
+        (let* ((beg (match-beginning 0))
+               (end (match-end 0))
+               (form-feed-pos (1+ beg))
+               ;; don't process ^L if invisible or covered by `display'
+               (show (and (htmlize-decode-invisibility-spec
+                           (get-char-property form-feed-pos 'invisible))
+                          (not (get-char-property form-feed-pos 'display)))))
+          (when show
+            (htmlize-make-tmp-overlay beg end disp)))))))
 
 (defun htmlize-defang-local-variables ()
   ;; Juri Linkov reports that an HTML-ized "Local variables" can lead
@@ -921,17 +917,6 @@ If no rgb.txt file is found, return nil."
 
 ;;; Face handling.
 
-(defun htmlize-face-specifies-property (face prop)
-  ;; Return t if face specifies PROP, as opposed to it being inherited
-  ;; from the default face.  The problem with e.g.
-  ;; `face-foreground-instance' is that it returns an instance for
-  ;; EVERY face because every face inherits from the default face.
-  ;; However, we'd like htmlize-face-{fore,back}ground to return nil
-  ;; when called with a face that doesn't specify its own foreground
-  ;; or background.
-  (or (eq face 'default)
-      (assq 'global (specifier-spec-list (face-property face prop)))))
-
 (defun htmlize-face-color-internal (face fg)
   ;; Used only under GNU Emacs.  Return the color of FACE, but don't
   ;; return "unspecified-fg" or "unspecified-bg".  If the face is
@@ -956,24 +941,13 @@ If no rgb.txt file is found, return nil."
 (defun htmlize-face-foreground (face)
   ;; Return the name of the foreground color of FACE.  If FACE does
   ;; not specify a foreground color, return nil.
-  (cond (htmlize-running-xemacs
-	 ;; XEmacs.
-	 (and (htmlize-face-specifies-property face 'foreground)
-	      (color-instance-name (face-foreground-instance face))))
-	(t
-	 ;; GNU Emacs.
-	 (htmlize-face-color-internal face t))))
+  (htmlize-face-color-internal face t))
 
 (defun htmlize-face-background (face)
   ;; Return the name of the background color of FACE.  If FACE does
   ;; not specify a background color, return nil.
-  (cond (htmlize-running-xemacs
-	 ;; XEmacs.
-	 (and (htmlize-face-specifies-property face 'background)
-	      (color-instance-name (face-background-instance face))))
-	(t
-	 ;; GNU Emacs.
-	 (htmlize-face-color-internal face nil))))
+  ;; GNU Emacs.
+  (htmlize-face-color-internal face nil))
 
 ;; Convert COLOR to the #RRGGBB string.  If COLOR is already in that
 ;; format, it's left unchanged.
@@ -995,15 +969,9 @@ If no rgb.txt file is found, return nil."
 	   (setq rgb-string (gethash (downcase color) htmlize-color-rgb-hash)))
 	  (t
 	   ;; We're getting the RGB components from Emacs.
-	   (let ((rgb
-		  (if (fboundp 'color-instance-rgb-components)
-		      (mapcar (lambda (arg)
-				(/ arg 256))
-			      (color-instance-rgb-components
-			       (make-color-instance color)))
-		    (mapcar (lambda (arg)
-			      (/ arg 256))
-			    (color-values color)))))
+	   (let ((rgb (mapcar (lambda (arg)
+                                (/ arg 256))
+                              (color-values color))))
 	     (when rgb
 	       (setq rgb-string (apply #'format "#%02x%02x%02x" rgb))))))
     ;; If RGB-STRING is still nil, it means the color cannot be found,
@@ -1105,38 +1073,39 @@ If no rgb.txt file is found, return nil."
     ;; Apply the prefix.
     (concat htmlize-css-name-prefix name)))
 
-(defun htmlize-face-to-fstruct (face)
-  "Convert Emacs face FACE to fstruct."
+(defun htmlize-face-to-fstruct-1 (face)
+  "Convert Emacs face FACE to fstruct, internal."
   (let ((fstruct (make-htmlize-fstruct
 		  :foreground (htmlize-color-to-rgb
 			       (htmlize-face-foreground face))
 		  :background (htmlize-color-to-rgb
 			       (htmlize-face-background face)))))
-    (if htmlize-running-xemacs
-        ;; XEmacs doesn't provide a way to detect whether a face is
-        ;; bold or italic, so we need to examine the font instance.
-        (let* ((font-instance (face-font-instance face))
-               (props (font-instance-properties font-instance)))
-          (when (equalp (cdr (assq 'WEIGHT_NAME props)) "bold")
-            (setf (htmlize-fstruct-boldp fstruct) t))
-          (when (or (equalp (cdr (assq 'SLANT props)) "i")
-                    (equalp (cdr (assq 'SLANT props)) "o"))
-            (setf (htmlize-fstruct-italicp fstruct) t))
-          (setf (htmlize-fstruct-strikep fstruct)
-                (face-strikethru-p face))
-          (setf (htmlize-fstruct-underlinep fstruct)
-                (face-underline-p face)))
-      ;; GNU Emacs
-      (dolist (attr '(:weight :slant :underline :overline :strike-through))
-        (let ((value (face-attribute face attr nil t)))
-          (when (and value (not (eq value 'unspecified)))
-            (htmlize-face-set-from-keyword-attr fstruct attr value))))
-      (let ((size (htmlize-face-size face)))
-        (unless (eql size 1.0) 	; ignore non-spec
-          (setf (htmlize-fstruct-size fstruct) size))))
+    ;; GNU Emacs
+    (dolist (attr '(:weight :slant :underline :overline :strike-through))
+      (let ((value (face-attribute face attr nil t)))
+        (when (and value (not (eq value 'unspecified)))
+          (htmlize-face-set-from-keyword-attr fstruct attr value))))
+    (let ((size (htmlize-face-size face)))
+      (unless (eql size 1.0)            ; ignore non-spec
+        (setf (htmlize-fstruct-size fstruct) size)))
     (setf (htmlize-fstruct-css-name fstruct) (htmlize-face-css-name face))
     fstruct))
 
+(defun htmlize-face-to-fstruct (face)
+  (let* ((face-list (or (and (symbolp face)
+                             (cdr (assq face face-remapping-alist)))
+                        (list face)))
+         (fstruct (htmlize-merge-faces
+                   (mapcar (lambda (face)
+                             (if (symbolp face)
+                                 (or (htmlize-get-override-fstruct face)
+                                     (htmlize-face-to-fstruct-1 face))
+                               (htmlize-attrlist-to-fstruct face)))
+                           (nreverse face-list)))))
+    (when (symbolp face)
+      (setf (htmlize-fstruct-css-name fstruct) (htmlize-face-css-name face)))
+    fstruct))
+
 (defmacro htmlize-copy-attr-if-set (attr-list dest source)
   ;; Generate code with the following pattern:
   ;; (progn
@@ -1187,7 +1156,7 @@ If no rgb.txt file is found, return nil."
 ;; htmlize supports attrlist by converting them to fstructs, the same
 ;; as with regular faces.
 
-(defun htmlize-attrlist-to-fstruct (attrlist)
+(defun htmlize-attrlist-to-fstruct (attrlist &optional name)
   ;; Like htmlize-face-to-fstruct, but accepts an ATTRLIST as input.
   (let ((fstruct (make-htmlize-fstruct)))
     (cond ((eq (car attrlist) 'foreground-color)
@@ -1205,7 +1174,7 @@ If no rgb.txt file is found, return nil."
 		   (value (pop attrlist)))
 	       (when (and value (not (eq value 'unspecified)))
 		 (htmlize-face-set-from-keyword-attr fstruct attr value))))))
-    (setf (htmlize-fstruct-css-name fstruct) "ATTRLIST")
+    (setf (htmlize-fstruct-css-name fstruct) (or name "custom"))
     fstruct))
 
 (defun htmlize-decode-face-prop (prop)
@@ -1242,6 +1211,17 @@ If no rgb.txt file is found, return nil."
         (t
          (apply #'nconc (mapcar #'htmlize-decode-face-prop prop)))))
 
+(defun htmlize-get-override-fstruct (face)
+  (let* ((raw-def (plist-get htmlize-face-overrides face))
+         (def (cond ((stringp raw-def) (list :foreground raw-def))
+                    ((listp raw-def) raw-def)
+                    (t
+                     (error (format (concat "face override must be an "
+                                            "attribute list or string, got %s")
+                                    raw-def))))))
+    (and def
+         (htmlize-attrlist-to-fstruct def (symbol-name face)))))
+
 (defun htmlize-make-face-map (faces)
   ;; Return a hash table mapping Emacs faces to htmlize's fstructs.
   ;; The keys are either face symbols or attrlists, so the test
@@ -1252,9 +1232,7 @@ If no rgb.txt file is found, return nil."
       (unless (gethash face face-map)
 	;; Haven't seen FACE yet; convert it to an fstruct and cache
 	;; it.
-	(let ((fstruct (if (symbolp face)
-			   (htmlize-face-to-fstruct face)
-			 (htmlize-attrlist-to-fstruct face))))
+	(let ((fstruct (htmlize-face-to-fstruct face)))
 	  (setf (gethash face face-map) fstruct)
 	  (let* ((css-name (htmlize-fstruct-css-name fstruct))
 		 (new-name css-name)
@@ -1276,120 +1254,78 @@ If no rgb.txt file is found, return nil."
 
 (defun htmlize-faces-in-buffer ()
   "Return a list of faces used in the current buffer.
-Under XEmacs, this returns the set of faces specified by the extents
-with the `face' property.  (This covers text properties as well.)  Under
-GNU Emacs, it returns the set of faces specified by the `face' text
-property and by buffer overlays that specify `face'."
+This is the set of faces specified by the `face' text property and by buffer
+overlays that specify `face'."
   (let (faces)
-    ;; Testing for (fboundp 'map-extents) doesn't work because W3
-    ;; defines `map-extents' under FSF.
-    (if htmlize-running-xemacs
-	(let (face-prop)
-	  (map-extents (lambda (extent ignored)
-			 (setq face-prop (extent-face extent)
-			       ;; FACE-PROP can be a face or a list of
-			       ;; faces.
-			       faces (if (listp face-prop)
-					 (union face-prop faces)
-				       (adjoin face-prop faces)))
-			 nil)
-		       nil
-		       ;; Specify endpoints explicitly to respect
-		       ;; narrowing.
-		       (point-min) (point-max) nil nil 'face))
-      ;; FSF Emacs code.
-      ;; Faces used by text properties.
-      (let ((pos (point-min)) face-prop next)
-	(while (< pos (point-max))
-	  (setq face-prop (get-text-property pos 'face)
-		next (or (next-single-property-change pos 'face) (point-max)))
-          (setq faces (nunion (htmlize-decode-face-prop face-prop)
-                              faces :test 'equal))
-	  (setq pos next)))
-      ;; Faces used by overlays.
-      (dolist (overlay (overlays-in (point-min) (point-max)))
-	(let ((face-prop (overlay-get overlay 'face)))
-          (setq faces (nunion (htmlize-decode-face-prop face-prop)
-                              faces :test 'equal)))))
+    ;; Faces used by text properties.
+    (let ((pos (point-min)) face-prop next)
+      (while (< pos (point-max))
+        (setq face-prop (get-text-property pos 'face)
+              next (or (next-single-property-change pos 'face) (point-max)))
+        (setq faces (nunion (htmlize-decode-face-prop face-prop)
+                            faces :test 'equal))
+        (setq pos next)))
+    ;; Faces used by overlays.
+    (dolist (overlay (overlays-in (point-min) (point-max)))
+      (let ((face-prop (overlay-get overlay 'face)))
+        (setq faces (nunion (htmlize-decode-face-prop face-prop)
+                            faces :test 'equal))))
     faces))
 
+(if (>= emacs-major-version 25)
+    (defun htmlize-sorted-overlays-at (pos)
+      (overlays-at pos t))
+
+  (defun htmlize-sorted-overlays-at (pos)
+    ;; Like OVERLAYS-AT with the SORTED argument, for older Emacsen.
+    (let ((overlays (overlays-at pos)))
+      (setq overlays (sort* overlays #'<
+                            :key (lambda (o)
+                                   (- (overlay-end o) (overlay-start o)))))
+      (setq overlays
+            (stable-sort overlays #'<
+                         :key (lambda (o)
+                                (let ((prio (overlay-get o 'priority)))
+                                  (if (numberp prio) prio 0)))))
+      (nreverse overlays))))
+
+
 ;; htmlize-faces-at-point returns the faces in use at point.  The
 ;; faces are sorted by increasing priority, i.e. the last face takes
 ;; precedence.
 ;;
-;; Under XEmacs, this returns all the faces in all the extents at
-;; point.  Under GNU Emacs, this returns all the faces in the `face'
-;; property and all the faces in the overlays at point.
-
-(cond (htmlize-running-xemacs
-       (defun htmlize-faces-at-point ()
-	 (let (extent extent-list face-list face-prop)
-	   (while (setq extent (extent-at (point) nil 'face extent))
-	     (push extent extent-list))
-	   ;; extent-list is in reverse display order, meaning that
-	   ;; smallest ones come last.  That is the order we want,
-	   ;; except it can be overridden by the `priority' property.
-	   (setq extent-list (stable-sort extent-list #'<
-					  :key #'extent-priority))
-	   (dolist (extent extent-list)
-	     (setq face-prop (extent-face extent))
-	     ;; extent's face-list is in reverse order from what we
-	     ;; want, but the `nreverse' below will take care of it.
-	     (setq face-list (if (listp face-prop)
-				 (append face-prop face-list)
-			       (cons face-prop face-list))))
-	   (nreverse face-list))))
-      (t
-       (defun htmlize-faces-at-point ()
-	 (let (all-faces)
-	   ;; Faces from text properties.
-	   (let ((face-prop (get-text-property (point) 'face)))
-             ;; we need to reverse the `face' prop because we want
-             ;; more specific faces to come later
-	     (setq all-faces (nreverse (htmlize-decode-face-prop face-prop))))
-	   ;; Faces from overlays.
-	   (let ((overlays
-		  ;; Collect overlays at point that specify `face'.
-		  (delete-if-not (lambda (o)
-				   (overlay-get o 'face))
-				 (overlays-at (point))))
-		 list face-prop)
-	     ;; Sort the overlays so the smaller (more specific) ones
-	     ;; come later.  The number of overlays at each one
-	     ;; position should be very small, so the sort shouldn't
-	     ;; slow things down.
-	     (setq overlays (sort* overlays
-				   ;; Sort by ascending...
-				   #'<
-				   ;; ...overlay size.
-				   :key (lambda (o)
-					  (- (overlay-end o)
-					     (overlay-start o)))))
-	     ;; Overlay priorities, if present, override the above
-	     ;; established order.  Larger overlay priority takes
-	     ;; precedence and therefore comes later in the list.
-	     (setq overlays (stable-sort
-			     overlays
-			     ;; Reorder (stably) by acending...
-			     #'<
-			     ;; ...overlay priority.
-			     :key (lambda (o)
-				    (or (overlay-get o 'priority) 0))))
-	     (dolist (overlay overlays)
-	       (setq face-prop (overlay-get overlay 'face)
-                     list (nconc (htmlize-decode-face-prop face-prop) list)))
-	     ;; Under "Merging Faces" the manual explicitly states
-	     ;; that faces specified by overlays take precedence over
-	     ;; faces specified by text properties.
-	     (setq all-faces (nconc all-faces list)))
-	   all-faces))))
+;; This returns all the faces in the `face' property and all the faces
+;; in the overlays at point.
+
+(defun htmlize-faces-at-point ()
+  (let (all-faces)
+    ;; Faces from text properties.
+    (let ((face-prop (get-text-property (point) 'face)))
+      ;; we need to reverse the `face' prop because we want
+      ;; more specific faces to come later
+      (setq all-faces (nreverse (htmlize-decode-face-prop face-prop))))
+    ;; Faces from overlays.
+    (let ((overlays
+           ;; Collect overlays at point that specify `face'.
+           (delete-if-not (lambda (o)
+                            (overlay-get o 'face))
+                          (nreverse (htmlize-sorted-overlays-at (point)))))
+          list face-prop)
+      (dolist (overlay overlays)
+        (setq face-prop (overlay-get overlay 'face)
+              list (nconc (htmlize-decode-face-prop face-prop) list)))
+      ;; Under "Merging Faces" the manual explicitly states
+      ;; that faces specified by overlays take precedence over
+      ;; faces specified by text properties.
+      (setq all-faces (nconc all-faces list)))
+    all-faces))
 
 ;; htmlize supports generating HTML in several flavors, some of which
 ;; use CSS, and others the  element.  We take an OO approach and
 ;; define "methods" that indirect to the functions that depend on
 ;; `htmlize-output-type'.  The currently used methods are `doctype',
-;; `insert-head', `body-tag', and `text-markup'.  Not all output types
-;; define all methods.
+;; `insert-head', `body-tag', `pre-tag', and `text-markup'.  Not all
+;; output types define all methods.
 ;;
 ;; Methods are called either with (htmlize-method METHOD ARGS...) 
 ;; special form, or by accessing the function with
@@ -1441,6 +1377,12 @@ it's called with the same value of KEY.  All other times, the cached
   nil					; no doc-string
   face-map ; shut up the byte-compiler
   "")
+
+(defun htmlize-default-pre-tag (face-map)
+  nil					; no doc-string
+  face-map ; shut up the byte-compiler
+  "
")
+
 
 ;;; CSS based output support.
 
@@ -1528,6 +1470,13 @@ it's called with the same value of KEY.  All other times, the cached
 	  (mapconcat #'identity (htmlize-css-specs (gethash 'default face-map))
 		     " ")))
 
+(defun htmlize-inline-css-pre-tag (face-map)
+  (if htmlize-pre-style
+      (format "
"
+              (mapconcat #'identity (htmlize-css-specs (gethash 'default face-map))
+                         " "))
+    (format "
")))
+
 (defun htmlize-inline-css-text-markup (fstruct-list buffer)
   (let* ((merged (htmlize-merge-faces fstruct-list))
 	 (style (htmlize-memoize
@@ -1551,6 +1500,14 @@ it's called with the same value of KEY.  All other times, the cached
     (format ""
 	    (htmlize-fstruct-foreground fstruct)
 	    (htmlize-fstruct-background fstruct))))
+
+(defun htmlize-font-pre-tag (face-map)
+  (if htmlize-pre-style
+      (let ((fstruct (gethash 'default face-map)))
+        (format "
"
+                (htmlize-fstruct-foreground fstruct)
+                (htmlize-fstruct-background fstruct)))
+    (format "
")))
        
 (defun htmlize-font-text-markup (fstruct-list buffer)
   ;; In `font' mode, we use the traditional HTML means of altering
@@ -1635,7 +1592,7 @@ it's called with the same value of KEY.  All other times, the cached
               (insert (htmlize-method body-tag face-map)
                       "\n    ")
               (put places 'content-start (point-marker))
-              (insert "
\n"))
+              (insert (htmlize-method pre-tag face-map) "\n"))
             (let ((text-markup
                    ;; Get the inserter method, so we can funcall it inside
                    ;; the loop.  Not calling `htmlize-method' in the loop
@@ -1724,28 +1681,19 @@ it's called with the same value of KEY.  All other times, the cached
   ;; actually fontify the buffer.  If font-lock is not in use, we
   ;; don't care because, except in htmlize-file, we don't force
   ;; font-lock on the user.
-  (when (and (boundp 'font-lock-mode)
-	     font-lock-mode)
+  (when font-lock-mode
     ;; In part taken from ps-print-ensure-fontified in GNU Emacs 21.
-    (cond
-     ((and (boundp 'jit-lock-mode)
-	   (symbol-value 'jit-lock-mode))
+    (when (and (boundp 'jit-lock-mode)
+               (symbol-value 'jit-lock-mode))
       (htmlize-with-fontify-message
        (jit-lock-fontify-now (point-min) (point-max))))
-     ((and (boundp 'lazy-lock-mode)
-	   (symbol-value 'lazy-lock-mode))
-      (htmlize-with-fontify-message
-       (lazy-lock-fontify-region (point-min) (point-max))))
-     ((and (boundp 'lazy-shot-mode)
-	   (symbol-value 'lazy-shot-mode))
-      (htmlize-with-fontify-message
-       ;; lazy-shot is amazing in that it must *refontify* the region,
-       ;; even if the whole buffer has already been fontified.  
-       (lazy-shot-fontify-region (point-min) (point-max))))
-     ;; There's also fast-lock, but we don't need to handle specially,
-     ;; I think.  fast-lock doesn't really defer fontification, it
-     ;; just saves it to an external cache so it's not done twice.
-     )))
+
+    (if (fboundp 'font-lock-ensure)
+        (font-lock-ensure)
+      ;; Emacs prior to 25.1
+      (with-no-warnings
+        (font-lock-mode 1)
+        (font-lock-fontify-buffer)))))
 
 
 ;;;###autoload
@@ -1797,6 +1745,16 @@ the text to another HTML buffer."
 			    (plist-get htmlize-buffer-places 'content-end)))
       (kill-buffer htmlbuf))))
 
+(defun htmlize-region-save-screenshot (beg end)
+  "Save the htmlized (see `htmlize-region-for-paste') region in
+the kill ring. Uses `inline-css', with style information in
+`
' tags, so that the rendering of the marked up text
+approximates the buffer as closely as possible."
+  (interactive "r")
+  (let ((htmlize-pre-style t))
+    (kill-new (htmlize-region-for-paste beg end)))
+  (deactivate-mark))
+
 (defun htmlize-make-file-name (file)
   "Make an HTML file name from FILE.
 
@@ -1853,11 +1811,7 @@ does not name a directory, it will be used as output file name."
 	(font-lock-auto-fontify nil)
 	(global-font-lock-mode nil)
 	;; Ignore the size limit for the purposes of htmlization.
-	(font-lock-maximum-size nil)
-	;; Disable font-lock support modes.  This will only work in
-	;; more recent Emacs versions, so htmlize-buffer-1 still needs
-	;; to call htmlize-ensure-fontified.
-	(font-lock-support-mode nil))
+	(font-lock-maximum-size nil))
     (with-temp-buffer
       ;; Insert FILE into the temporary buffer.
       (insert-file-contents file)
@@ -1867,11 +1821,6 @@ does not name a directory, it will be used as output file name."
       (let ((buffer-file-name file))
 	;; Set the major mode for the sake of font-lock.
 	(normal-mode)
-	(font-lock-mode 1)
-	(unless font-lock-mode
-	  ;; In GNU Emacs (font-lock-mode 1) doesn't force font-lock,
-	  ;; contrary to the documentation.  This seems to work.
-	  (font-lock-fontify-buffer))
 	;; htmlize the buffer and save the HTML.
 	(with-current-buffer (htmlize-buffer-1)
 	  (unwind-protect
@@ -1926,8 +1875,7 @@ corresponding source file."
 (provide 'htmlize)
 
 ;; Local Variables:
-;; byte-compile-warnings: (not cl-functions lexical unresolved obsolete)
-;; lexical-binding: t
+;; byte-compile-warnings: (not cl-functions unresolved obsolete)
 ;; End:
 
 ;;; htmlize.el ends here
-- 
2.47.3