all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Wolfgang Jenkner <wjenkner@inode.at>
To: Glenn Morris <rgm@gnu.org>
Cc: 20084@debbugs.gnu.org, Charles Tam <me@charlest.net>
Subject: bug#20084: comint-highlight-prompt overrides ANSI colors in 24.4
Date: Fri, 20 Mar 2015 03:22:37 +0100	[thread overview]
Message-ID: <85d244tmzb.fsf@iznogoud.viz> (raw)
In-Reply-To: <CAKu+9YUBrsz2sQG8Bq+N2oXBw6gRAKT3ZraoKV1HKNiYX5q0xA@mail.gmail.com>

On Thu, Mar 12 2015, Wolfgang Jenkner wrote:

> I've been using something like the following patch for some time:

I've refactored it a bit and added an ert test.  It would be nice if you
(the OP or someone else) could test it (since font-lock.el is pre-loaded
it is necessary to manually load the (compiled) patched file, even after
restarting emacs).  If there are no objections I'd like to push it in,
say, a week.

-- >8 --
Subject: [PATCH] Preserve face text properties in comint prompt.

* lisp/font-lock.el (remove-single-text-property): Uncomment.
Hack it a bit.
* lisp/comint.el (comint-output-filter): Use it to remove
comint-highlight-prompt.
(comint-snapshot-last-prompt, comint-output-filter): Use
font-lock-prepend-text-property for comint-highlight-prompt.
* test/automated/textprop-tests.el: New file.
(textprop-tests-remove-single-text-property): New test.

Thus, the original face text property of a prompt "candidate" (the
last line of an output chunk not ending with a newline) is
preserved.  This amends the fixing of bug#14744.  (Bug#20084)
---
 lisp/comint.el                   | 20 +++++++++------
 lisp/font-lock.el                | 47 +++++++++++++++++++---------------
 test/automated/textprop-tests.el | 55 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 28 deletions(-)
 create mode 100644 test/automated/textprop-tests.el

diff --git a/lisp/comint.el b/lisp/comint.el
index aaa7d59..1d7f81e 100644
--- a/lisp/comint.el
+++ b/lisp/comint.el
@@ -1930,10 +1930,10 @@ the start, the cdr to the end of the last prompt recognized.")
 Freezes the `font-lock-face' text property in place."
   (when comint-last-prompt
     (with-silent-modifications
-      (add-text-properties
+      (font-lock-prepend-text-property
        (car comint-last-prompt)
        (cdr comint-last-prompt)
-       '(font-lock-face comint-highlight-prompt)))
+       'font-lock-face 'comint-highlight-prompt))
     ;; Reset comint-last-prompt so later on comint-output-filter does
     ;; not remove the font-lock-face text property of the previous
     ;; (this) prompt.
@@ -2085,14 +2085,18 @@ Make backspaces delete the previous character."
 		  (add-text-properties prompt-start (point)
 				       '(read-only t front-sticky (read-only)))))
 	      (when comint-last-prompt
-		(remove-text-properties (car comint-last-prompt)
-					(cdr comint-last-prompt)
-					'(font-lock-face)))
+		(with-silent-modifications
+		  (remove-single-text-property (car comint-last-prompt)
+					       (cdr comint-last-prompt)
+					       'font-lock-face
+					       'comint-highlight-prompt)))
 	      (setq comint-last-prompt
 		    (cons (copy-marker prompt-start) (point-marker)))
-	      (add-text-properties prompt-start (point)
-				   '(rear-nonsticky t
-				     font-lock-face comint-highlight-prompt)))
+	      (with-silent-modifications
+		(font-lock-prepend-text-property prompt-start (point)
+						 'font-lock-face
+						 'comint-highlight-prompt)
+		(add-text-properties prompt-start (point) '(rear-nonsticky t))))
 	    (goto-char saved-point)))))))
 
 (defun comint-preinput-scroll-to-bottom ()
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index 6ec6c9f..0c6642c 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -1427,26 +1427,33 @@ Optional argument OBJECT is the string or buffer containing the text."
 
 ;; For consistency: maybe this should be called `remove-single-property' like
 ;; `next-single-property-change' (not `next-single-text-property-change'), etc.
-;;(defun remove-single-text-property (start end prop value &optional object)
-;;  "Remove a specific property value from text from START to END.
-;;Arguments PROP and VALUE specify the property and value to remove.  The
-;;resulting property values are not equal to VALUE nor lists containing VALUE.
-;;Optional argument OBJECT is the string or buffer containing the text."
-;;  (let ((start (text-property-not-all start end prop nil object)) next prev)
-;;    (while start
-;;      (setq next (next-single-property-change start prop object end)
-;;	    prev (get-text-property start prop object))
-;;      (cond ((and (symbolp prev) (eq value prev))
-;;	     (remove-text-property start next prop object))
-;;	    ((and (listp prev) (memq value prev))
-;;	     (let ((new (delq value prev)))
-;;	       (cond ((null new)
-;;		      (remove-text-property start next prop object))
-;;		     ((= (length new) 1)
-;;		      (put-text-property start next prop (car new) object))
-;;		     (t
-;;		      (put-text-property start next prop new object))))))
-;;      (setq start (text-property-not-all next end prop nil object)))))
+(defun remove-single-text-property (start end prop value &optional object)
+  "Remove a specific property value from text from START to END.
+Arguments PROP and VALUE specify the property and value to remove.  The
+resulting property values are not `eq' to VALUE nor lists containing VALUE.
+Optional argument OBJECT is the string or buffer containing the text."
+  (let ((start (text-property-not-all start end prop nil object)) next prev)
+    (while start
+      (setq next (next-single-property-change start prop object end)
+	    prev (get-text-property start prop object))
+      (cond ((or (symbolp prev)
+		 (and (consp prev)
+		      (or (keywordp (car prev))
+			  (eq (car prev) 'foreground-color)
+			  (eq (car prev) 'background-color))))
+	     (when (eq value prev)
+	       (remove-list-of-text-properties start next (list prop) object)))
+	    ((and (listp prev)
+		  (memq value prev))
+	     (let ((new (remq value prev)))
+	       (cond ((null new)
+		      (remove-list-of-text-properties start next (list prop)
+						      object))
+		     ((= (length new) 1)
+		      (put-text-property start next prop (car new) object))
+		     (t
+		      (put-text-property start next prop new object))))))
+      (setq start (text-property-not-all next end prop nil object)))))
 
 ;;; End of Additional text property functions.
 \f
diff --git a/test/automated/textprop-tests.el b/test/automated/textprop-tests.el
new file mode 100644
index 0000000..6fda65d
--- /dev/null
+++ b/test/automated/textprop-tests.el
@@ -0,0 +1,55 @@
+;;; textprop-tests.el --- Test suite for text properties.
+
+;; Copyright (C) 2015 Free Software Foundation, Inc.
+
+;; Author: Wolfgang Jenkner <wjenkner@inode.at>
+;; Keywords: internal
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(require 'ert)
+
+(ert-deftest textprop-tests-remove-single-text-property ()
+  "Test `remove-single-text-property'."
+  (let* ((string "foobar")
+	 (stack (list string))
+	 (faces '(bold (:foreground "red") underline)))
+    ;; Build each string in `stack' by adding a face to the previous
+    ;; string.
+    (let ((faces (reverse faces)))
+      (push (copy-sequence (car stack)) stack)
+      (put-text-property 0 3 'font-lock-face (pop faces) (car stack))
+      (push (copy-sequence (car stack)) stack)
+      (put-text-property 3 6 'font-lock-face (pop faces) (car stack))
+      (push (copy-sequence (car stack)) stack)
+      (font-lock-prepend-text-property 2 5
+				       'font-lock-face (pop faces) (car stack)))
+    ;; Check that removing the corresponding face from each string
+    ;; yields the previous string in `stack'.
+    (while faces
+      ;; (message "%S" (car stack))
+      (should (equal-including-properties
+	       (progn
+		 (remove-single-text-property 0 6 'font-lock-face (pop faces)
+					      (car stack))
+		 (pop stack))
+	       (car stack))))
+    ;; Sanity check.
+    ;; (message "%S" (car stack))
+    (should (and (equal-including-properties (pop stack) string)
+		 (null stack)))))
-- 
2.3.3






  reply	other threads:[~2015-03-20  2:22 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-11 16:01 bug#20084: comint-highlight-prompt overrides ANSI colors in 24.4 Charles Tam
2015-03-11 19:00 ` Glenn Morris
2015-03-12  2:00   ` Wolfgang Jenkner
2015-03-20  2:22     ` Wolfgang Jenkner [this message]
2015-03-20 14:24       ` Stefan Monnier
2015-03-22 16:29         ` Wolfgang Jenkner
2015-03-22 16:36           ` Wolfgang Jenkner
2015-03-23  2:10           ` Stefan Monnier
2015-03-23 19:06             ` Wolfgang Jenkner
2015-03-23 20:50               ` Stefan Monnier
2015-03-20  2:31     ` Wolfgang Jenkner
2015-03-25  0:53       ` Glenn Morris
2015-03-27  3:27         ` Wolfgang Jenkner
2015-03-30 15:54         ` Wolfgang Jenkner
2015-03-31 15:01           ` Wolfgang Jenkner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=85d244tmzb.fsf@iznogoud.viz \
    --to=wjenkner@inode.at \
    --cc=20084@debbugs.gnu.org \
    --cc=me@charlest.net \
    --cc=rgm@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.