[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/adaptive-wrap 01e7d1f 14/15: adaptive-wrap: Fontify wra
From: |
Stefan Monnier |
Subject: |
[elpa] externals/adaptive-wrap 01e7d1f 14/15: adaptive-wrap: Fontify wrap-prefix |
Date: |
Sun, 29 Nov 2020 19:09:10 -0500 (EST) |
branch: externals/adaptive-wrap
commit 01e7d1fe2153aca295fd7859eccbaa491fe34ffd
Author: Kévin Le Gouguec <kevin.legouguec@gmail.com>
Commit: Lars Ingebrigtsen <larsi@gnus.org>
adaptive-wrap: Fontify wrap-prefix
* packages/adaptive-wrap/adaptive-wrap.el
(adaptive-wrap--face-extends): Compatibility shim for Emacs < 27.
(adaptive-wrap--prefix-face): New function to determine what face to
apply to the wrap-prefix.
(adaptive-wrap--prefix): New function to compute the full wrap-prefix,
extracted verbatim from adaptive-wrap-fill-context-prefix.
(adaptive-wrap-fill-context-prefix): Call the new functions.
* packages/adaptive-wrap/adaptive-wrap.el (adaptive-wrap--prefix): Use
spaces; ignore the string returned by fill-context-prefix.
---
adaptive-wrap.el | 58 +++++++++++++++++++++++++++++++++++++++-----------------
1 file changed, 41 insertions(+), 17 deletions(-)
diff --git a/adaptive-wrap.el b/adaptive-wrap.el
index f8d89ac..b075b3b 100644
--- a/adaptive-wrap.el
+++ b/adaptive-wrap.el
@@ -59,6 +59,41 @@ 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)
+ (cond ((get-text-property 0 'face fcp))
+ ;; 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.
+ ;; NB: the face might not actually span the whole line: see for
+ ;; example removed lines in diff-mode, where the first character
+ ;; has the diff-indicator-removed face, while the rest of the
+ ;; 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)))))
+
+(defun adaptive-wrap--prefix (fcp)
+ (let ((fcp-len (string-width fcp)))
+ (cond
+ ((= 0 adaptive-wrap-extra-indent)
+ fcp)
+ ((< 0 adaptive-wrap-extra-indent)
+ (concat fcp (make-string adaptive-wrap-extra-indent ?\s)))
+ ((< 0 (+ adaptive-wrap-extra-indent fcp-len))
+ (substring fcp
+ 0
+ (+ adaptive-wrap-extra-indent fcp-len)))
+ (t
+ ""))))
+
(defun adaptive-wrap-fill-context-prefix (beg end)
"Like `fill-context-prefix', but with length adjusted by
`adaptive-wrap-extra-indent'."
(let* ((fcp
@@ -72,23 +107,12 @@ extra indent = 2
(fill-context-prefix beg end))
;; Note: fill-context-prefix may return nil; See:
;; http://article.gmane.org/gmane.emacs.devel/156285
- ""))
- (fcp-len (string-width fcp))
- (fill-char (if (< 0 fcp-len)
- (string-to-char (substring fcp -1))
- ?\ )))
- (cond
- ((= 0 adaptive-wrap-extra-indent)
- fcp)
- ((< 0 adaptive-wrap-extra-indent)
- (concat fcp
- (make-string adaptive-wrap-extra-indent fill-char)))
- ((< 0 (+ adaptive-wrap-extra-indent fcp-len))
- (substring fcp
- 0
- (+ adaptive-wrap-extra-indent fcp-len)))
- (t
- ""))))
+ ""))
+ (prefix (adaptive-wrap--prefix fcp))
+ (face (adaptive-wrap--prefix-face fcp beg end)))
+ (if face
+ (propertize prefix 'face face)
+ prefix)))
(defun adaptive-wrap-prefix-function (beg end)
"Indent the region between BEG and END with adaptive filling."
- [elpa] branch externals/adaptive-wrap created (now 603648e), Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap db52f0b 01/15: Rename adaptive-wrap-prefix to adaptive-wrap., Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap f78efba 02/15: Add adaptive-wrap-extra-indent., Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap 77979be 04/15: * adaptive-wrap.el (adaptive-wrap-extra-indent): Fix buffer-localness., Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap fb4aa4e 06/15: * adaptive-wrap.el (menu-bar-options-menu): Add checkbox for Adaptive Wrap, Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap 7db060b 07/15: * adaptive-wrap.el: Require easymenu (bug#14974)., Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap 07e03a8 08/15: * adaptive-wrap.el: Fix bug#14974 by using define-key-after, Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap ef01f42 09/15: * adaptive-wrap.el (adaptive-wrap-mode): Move after font-lock (bug#15155)., Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap b17b789 10/15: Mark adaptive-wrap-extra-indent as safe if integerp (Bug#23816), Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap 710d484 05/15: Fix error during redisplay: (wrong-type-argument stringp nil), Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap 01e7d1f 14/15: adaptive-wrap: Fontify wrap-prefix,
Stefan Monnier <=
- [elpa] externals/adaptive-wrap 603648e 15/15: * .gitignore: New file, Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap 5888dc0 03/15: Clean up copyright notices., Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap a1cd968 11/15: * adaptive-wrap/adaptive-wrap.el: Fix use without font-lock, Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap dd32f62 12/15: * adaptive-wrap/adaptive-wrap.el: Fix interaction with visual-fill, Stefan Monnier, 2020/11/29
- [elpa] externals/adaptive-wrap 1289272 13/15: * adaptive-wrap.el (adaptive-wrap-fill-context-prefix): Ignore paragraph-start, Stefan Monnier, 2020/11/29