emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/htmlize 3551c6b 063/134: Respect `before-string' and `afte


From: ELPA Syncer
Subject: [nongnu] elpa/htmlize 3551c6b 063/134: Respect `before-string' and `after-string' overlay properties.
Date: Sat, 7 Aug 2021 09:17:07 -0400 (EDT)

branch: elpa/htmlize
commit 3551c6bd63be9e2d90b8033ee359da5de0721416
Author: Hrvoje Niksic <hniksic@gmail.com>
Commit: Hrvoje Niksic <hniksic@gmail.com>

    Respect `before-string' and `after-string' overlay properties.
---
 htmlize.el | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/htmlize.el b/htmlize.el
index 6c0aa87..5b731c7 100644
--- a/htmlize.el
+++ b/htmlize.el
@@ -488,6 +488,35 @@ next-single-char-property-change")))
             ((cdr-safe (car match)) 'ellipsis)
             (t nil)))))
 
+(defun htmlize-add-before-after-strings (beg end text)
+  ;; Find overlays specifying before-string and after-string in [beg,
+  ;; pos).  If any are found, splice them into TEXT and return the new
+  ;; text.
+  (let (additions)
+    (dolist (overlay (overlays-in beg end))
+      (let ((before (overlay-get overlay 'before-string))
+            (after (overlay-get overlay 'after-string)))
+        (when after
+          (push (cons (- (overlay-end overlay) beg)
+                      after)
+                additions))
+        (when before
+          (push (cons (- (overlay-start overlay) beg)
+                      before)
+                additions))))
+    (if additions
+        (let ((textlist nil)
+              (strpos 0))
+          (dolist (add (sort* additions #'< :key #'car))
+            (let ((addpos (car add))
+                  (addtext (cdr add)))
+              (push (substring text strpos addpos) textlist)
+              (push addtext textlist)
+              (setq strpos addpos)))
+          (push (substring text strpos) textlist)
+          (apply #'concat (nreverse textlist)))
+      text)))
+
 (defun htmlize-get-text-with-display (beg end)
   ;; Like buffer-substring-no-properties, except it copies the
   ;; `display' property from the buffer, if found.  We cannot rely on
@@ -504,6 +533,8 @@ next-single-char-property-change")))
         (put-text-property (- pos beg) (- next-change beg)
                            'display display text))
       (setq pos next-change))
+    (unless running-xemacs
+      (setq text (htmlize-add-before-after-strings beg end text)))
     text))
 
 (defun htmlize-buffer-substring-no-invisible (beg end)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]