[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/adaptive-wrap a4c49ef: * adaptive-wrap.el: Handle non-s
From: |
Stefan Monnier |
Subject: |
[elpa] externals/adaptive-wrap a4c49ef: * adaptive-wrap.el: Handle non-symbol values of `face` property |
Date: |
Sun, 10 Jan 2021 10:03:29 -0500 (EST) |
branch: externals/adaptive-wrap
commit a4c49ef906b0318485ae053c344fc524c2d8be7c
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
* adaptive-wrap.el: Handle non-symbol values of `face` property
(adaptive-wrap--face-extend-p): Rename from adaptive-wrap--face-extends;
don't signal an error if passed a non-face value, and make it work for
"immediate face plist".
(adaptive-wrap--prefix-face): Make it handle the case where the `face`
property is a list of faces.
---
adaptive-wrap.el | 34 +++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)
diff --git a/adaptive-wrap.el b/adaptive-wrap.el
index b075b3b..3e891af 100644
--- a/adaptive-wrap.el
+++ b/adaptive-wrap.el
@@ -1,6 +1,6 @@
;;; adaptive-wrap.el --- Smart line-wrapping with wrap-prefix
-;; Copyright (C) 2011-2018 Free Software Foundation, Inc.
+;; Copyright (C) 2011-2021 Free Software Foundation, Inc.
;; Author: Stephen Berman <stephen.berman@gmx.net>
;; Stefan Monnier <monnier@iro.umontreal.ca>
@@ -59,16 +59,21 @@ extra indent = 2
:group 'visual-line)
(make-variable-buffer-local 'adaptive-wrap-extra-indent)
-(defun adaptive-wrap--face-extends (face)
- (if (fboundp 'face-extend-p)
- (face-extend-p face nil t)
- ;; Before Emacs 27, faces always extended beyond EOL. Check for a
- ;; non-default background.
- (face-background face nil t)))
-
-(defun adaptive-wrap--prefix-face (fcp beg end)
+(defun adaptive-wrap--face-extend-p (face)
+ ;; Before Emacs 27, faces always extended beyond EOL, so we check for a
+ ;; non-default background instead.
+ (cond
+ ((listp face)
+ (plist-get face (if (fboundp 'face-extend-p) :extend :background)))
+ ((symbolp face)
+ (if (fboundp 'face-extend-p)
+ (face-extend-p face nil t)
+ (face-background face nil t)))))
+
+(defun adaptive-wrap--prefix-face (fcp _beg end)
+ ;; If the fill-context-prefix already specifies a face, just use that.
(cond ((get-text-property 0 'face fcp))
- ;; If the last character is a newline and has a face that
+ ;; Else, if the last character is a newline and has a face that
;; extends beyond EOL, assume that this face spans the whole
;; line and apply it to the prefix to preserve the "block"
;; visual effect.
@@ -78,7 +83,14 @@ extra indent = 2
;; line has the diff-removed face.
((= (char-before end) ?\n)
(let ((eol-face (get-text-property (1- end) 'face)))
- (and eol-face (adaptive-wrap--face-extends eol-face) eol-face)))))
+ ;; `eol-face' can be a face, a "face value"
+ ;; (plist of face properties) or a list of one of those.
+ (if (or (not (consp eol-face)) (keywordp (car eol-face)))
+ ;; A single face.
+ (if (adaptive-wrap--face-extend-p eol-face) eol-face)
+ ;; A list of faces. Keep the ones that extend beyond EOL.
+ (delq nil (mapcar (lambda (f) (if (adaptive-wrap--face-extend-p
f) f))
+ eol-face)))))))
(defun adaptive-wrap--prefix (fcp)
(let ((fcp-len (string-width fcp)))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [elpa] externals/adaptive-wrap a4c49ef: * adaptive-wrap.el: Handle non-symbol values of `face` property,
Stefan Monnier <=