[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/htmlize 87d4a43 080/134: Recognize tmp overlays with an ov
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/htmlize 87d4a43 080/134: Recognize tmp overlays with an overlay property. |
Date: |
Sat, 7 Aug 2021 09:17:11 -0400 (EDT) |
branch: elpa/htmlize
commit 87d4a4387195e52a1fd0587613076ea63fec6349
Author: Hrvoje Niksic <hniksic@gmail.com>
Commit: Hrvoje Niksic <hniksic@gmail.com>
Recognize tmp overlays with an overlay property.
That way they can be created anywhere in the code and removed in a
single step.
---
htmlize.el | 60 +++++++++++++++++++++++++++++++++---------------------------
1 file changed, 33 insertions(+), 27 deletions(-)
diff --git a/htmlize.el b/htmlize.el
index 81c12a4..2c55ab5 100644
--- a/htmlize.el
+++ b/htmlize.el
@@ -80,8 +80,8 @@
;; Thanks go to the many people who have sent reports and contributed
;; comments, suggestions, and fixes. They include Ron Gut, Bob
-;; Weiner, Toni Drabik, Peter Breton, Thomas Vogels, Juri Linkov,
-;; Maciek Pasternacki, and many others.
+;; Weiner, Toni Drabik, Peter Breton, Ville Skytta, Thomas Vogels,
+;; Juri Linkov, Maciek Pasternacki, and many others.
;; User quotes: "You sir, are a sick, sick, _sick_ person. :)"
;; -- Bill Perry, author of Emacs/W3
@@ -772,33 +772,38 @@ This is used to protect mailto links without modifying
their meaning."
(setq string (replace-match "%40" nil t string)))
string)
-(defun htmlize-make-link-overlay (beg end uri)
+(defun htmlize-make-tmp-overlay (beg end props)
(let ((overlay (make-overlay beg end)))
- (overlay-put overlay 'htmlize-link (list :uri uri))
+ (overlay-put overlay 'htmlize-tmp-overlay t)
+ (while props
+ (overlay-put overlay (pop props) (pop props)))
overlay))
+(defun htmlize-delete-tmp-overlays ()
+ (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))))
+
(defun htmlize-create-auto-links ()
"Add `htmlize-link' property to all mailto links in the buffer.
Returns the list of created overlays."
- ;; Function originally submitted by Ville Skytta. Rewritten by
- ;; Hrvoje Niksic, then modified by Ville Skytta and Hrvoje Niksic.
- (let ((overlays nil))
- (save-excursion
- (goto-char (point-min))
- (while (re-search-forward
- "<\\(\\(mailto:\\)?\\([-=+_.a-zA-Z0-9]+@[-_.a-zA-Z0-9]+\\)\\)>"
- nil t)
- (let* ((address (match-string 3))
- (beg (match-beginning 0)) (end (match-end 0))
- (uri (concat "mailto:" (htmlize-despam-address address))))
- (push (htmlize-make-link-overlay beg end uri) overlays)))
- (goto-char (point-min))
- (while (re-search-forward "<\\(\\(URL:\\)?\\([a-zA-Z]+://[^;]+\\)\\)>"
- nil t)
- (push (htmlize-make-link-overlay
- (match-beginning 0) (match-end 0) (match-string 3))
- overlays)))
- overlays))
+ (save-excursion
+ (goto-char (point-min))
+ (while (re-search-forward
+ "<\\(\\(mailto:\\)?\\([-=+_.a-zA-Z0-9]+@[-_.a-zA-Z0-9]+\\)\\)>"
+ nil t)
+ (let* ((address (match-string 3))
+ (beg (match-beginning 0)) (end (match-end 0))
+ (uri (concat "mailto:" (htmlize-despam-address address))))
+ (htmlize-make-link-overlay beg end uri)))
+ (goto-char (point-min))
+ (while (re-search-forward "<\\(\\(URL:\\)?\\([a-zA-Z]+://[^;]+\\)\\)>"
+ nil t)
+ (htmlize-make-link-overlay
+ (match-beginning 0) (match-end 0) (match-string 3)))))
;; Tests for htmlize-create-auto-links:
@@ -1575,9 +1580,7 @@ it's called with the same value of KEY. All other times,
the cached
(file-name-nondirectory
(buffer-file-name)))
"*html*")))
- (completed nil)
- (auto-link-overlays (and htmlize-generate-hyperlinks
- (htmlize-create-auto-links))))
+ (completed nil))
(unwind-protect
(let* ((buffer-faces (htmlize-faces-in-buffer))
(face-map (htmlize-make-face-map (adjoin 'default
buffer-faces)))
@@ -1585,6 +1588,9 @@ it's called with the same value of KEY. All other times,
the cached
(title (if (buffer-file-name)
(file-name-nondirectory (buffer-file-name))
(buffer-name))))
+ (when htmlize-generate-hyperlinks
+ (htmlize-create-auto-links))
+
;; Initialize HTMLBUF and insert the HTML prolog.
(with-current-buffer htmlbuf
(buffer-disable-undo)
@@ -1688,7 +1694,7 @@ it's called with the same value of KEY. All other times,
the cached
(when (not completed)
(kill-buffer htmlbuf))
- (mapc #'delete-overlay auto-link-overlays)))))
+ (htmlize-delete-tmp-overlays)))))
;; Utility functions.
- [nongnu] elpa/htmlize 9145b68 128/134: Simplify ensuring of font-lock., (continued)
- [nongnu] elpa/htmlize 9145b68 128/134: Simplify ensuring of font-lock., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 86f22f2 132/134: Add Homepage to the package header, ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 999eef2 032/134: Support searching for any property change., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 7f94aa2 039/134: Conditionalize on color-instance-rgb-components., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 34845c5 042/134: Update comment., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize c847998 057/134: The future has come: switch to lexical scope., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 845329e 060/134: Don't attempt to use lexical binding in emacsen that don't support it., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize a6f9f07 066/134: Decide at each macroexpansion whether to use `lexical-let' or `let'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 58775c8 064/134: Improve introductory text., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize db4b76e 076/134: New file: NEWS, ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 87d4a43 080/134: Recognize tmp overlays with an overlay property.,
ELPA Syncer <=
- [nongnu] elpa/htmlize 67b8bf3 086/134: Implement form feed replacement with <hr/> as a temporary overlay with, ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 9e4c0bc 089/134: Faces that come first take precedence over those that come later., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 5d9be53 093/134: Bumped version., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize ece5b5f 095/134: Bumped version., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 974c169 098/134: Set `lexical-binding' to `t' in the first line of the file., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 8593a5e 111/134: Put style information in <pre> tags., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize a0b55cb 112/134: Introduced option for styling <pre>, "screenshot" function., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 133ac35 115/134: Remove XEmacs support., ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 75c21c7 116/134: Use `font-lock-ensure' where available. (#14), ELPA Syncer, 2021/08/07
- [nongnu] elpa/htmlize 315a8f2 121/134: htmlize-sorted-overlays-at: correctly initialize OVERLAYS. (#18), ELPA Syncer, 2021/08/07