>From d2ad575e8935981c23846bd54a3eac29b9290f45 Mon Sep 17 00:00:00 2001 From: "F. Jason Park" Date: Sat, 9 Mar 2024 07:12:16 -0800 Subject: [PATCH 0/3] *** NOT A PATCH *** F. Jason Park (2): [5.6] Leverage inverse-video for erc-inverse-face . Add new foreground and background face for color code 99 . Don't apply hover props for ^C99,99 because, by definition, the fg and bg map to different, contrasting colors. . Use `:inverse-video' face attribute for `erc-inverse-face' to mimic effect prescribed by https://modern.ircdocs.horse/formatting#reverse-color. [5.6] Make important text props more resilient in ERC F. Moukayed (1): [5.6] Redefine erc-spoiler-face to indicate revealed text . Have `erc-spoiler-face' inherit from `default' instead of `erc-inverse-face'. lisp/erc/erc-button.el | 3 +- lisp/erc/erc-goodies.el | 39 +++++--- lisp/erc/erc.el | 34 +++++++ test/lisp/erc/erc-goodies-tests.el | 153 ++++++++++++++++++++--------- test/lisp/erc/erc-tests.el | 52 ++++++++++ 5 files changed, 223 insertions(+), 58 deletions(-) Interdiff: diff --git a/lisp/erc/erc-goodies.el b/lisp/erc/erc-goodies.el index 212cdbfa9ef..6e9e48e1b81 100644 --- a/lisp/erc/erc-goodies.el +++ b/lisp/erc/erc-goodies.el @@ -661,11 +661,13 @@ erc-italic-face :group 'erc-faces) (defface erc-inverse-face - '((t :foreground "White" :background "Black")) + '((((supports :inverse-video t)) + :inverse-video t) + (t :foreground "White" :background "Black")) "ERC inverse face." :group 'erc-faces) -(defface erc-spoiler-face '((t :inherit erc-inverse-face)) +(defface erc-spoiler-face '((t :inherit default)) "ERC spoiler face." :group 'erc-faces) @@ -673,6 +675,16 @@ erc-underline-face "ERC underline face." :group 'erc-faces) +(defface erc-control-default-fg '((t :inherit default)) + "ERC foreground face for the \"default\" color code." + :group 'erc-faces) + +(defface erc-control-default-bg '((t :inherit default)) + "ERC background face for the \"default\" color code." + :group 'erc-faces) + +;; FIXME rename these to something like `erc-control-color-N-fg', +;; and deprecate the old names via `define-obsolete-face-alias'. (defface fg:erc-color-face0 '((t :foreground "White")) "ERC face." :group 'erc-faces) @@ -802,7 +814,7 @@ erc-get-bg-color-face (intern (concat "bg:erc-color-face" (number-to-string n)))) ((< 15 n 99) (list :background (aref erc--controls-additional-colors (- n 16)))) - (t (erc-log (format " Wrong color: %s" n)) '(default))))) + (t (erc-log (format " Wrong color: %s" n)) 'erc-control-default-fg)))) (defun erc-get-fg-color-face (n) "Fetches the right face for foreground color N (0-15)." @@ -818,7 +830,7 @@ erc-get-fg-color-face (intern (concat "fg:erc-color-face" (number-to-string n)))) ((< 15 n 99) (list :foreground (aref erc--controls-additional-colors (- n 16)))) - (t (erc-log (format " Wrong color: %s" n)) '(default))))) + (t (erc-log (format " Wrong color: %s" n)) 'erc-control-default-bg)))) ;;;###autoload(autoload 'erc-irccontrols-mode "erc-goodies" nil t) (define-erc-module irccontrols nil @@ -966,7 +978,7 @@ erc-controls-propertize "Prepend properties from IRC control characters between FROM and TO. If optional argument STR is provided, apply to STR, otherwise prepend properties to a region in the current buffer." - (when (and fg bg (equal fg bg)) + (when (and fg bg (equal fg bg) (not (equal fg "99"))) (add-text-properties from to '( mouse-face erc-spoiler-face cursor-face erc-spoiler-face) str) diff --git a/test/lisp/erc/erc-goodies-tests.el b/test/lisp/erc/erc-goodies-tests.el index 0ab40808a4a..c8fb0544a72 100644 --- a/test/lisp/erc/erc-goodies-tests.el +++ b/test/lisp/erc/erc-goodies-tests.el @@ -29,19 +29,23 @@ (defun erc-goodies-tests--assert-face (beg end-str present &optional absent) (setq beg (+ beg (point-min))) (let ((end (+ beg (1- (length end-str))))) - (while (and beg (< beg end)) - (let* ((val (get-text-property beg 'font-lock-face)) - (ft (flatten-tree (ensure-list val)))) - (dolist (p (ensure-list present)) - (if (consp p) - (should (member p val)) - (should (memq p ft)))) - (dolist (a (ensure-list absent)) - (if (consp a) - (should-not (member a val)) - (should-not (memq a ft)))) - (setq beg (text-property-not-all beg (point-max) - 'font-lock-face val)))))) + (ert-info ((format "beg: %S, end-str: %S" beg end-str)) + (while (and beg (< beg end)) + (let* ((val (get-text-property beg 'font-lock-face)) + (ft (flatten-tree (ensure-list val)))) + (ert-info ((format "looking-at: %S, val: %S" + (buffer-substring-no-properties beg end) + val)) + (dolist (p (ensure-list present)) + (if (consp p) + (should (member p val)) + (should (memq p ft)))) + (dolist (a (ensure-list absent)) + (if (consp a) + (should-not (member a val)) + (should-not (memq a ft))))) + (setq beg (text-property-not-all beg (point-max) + 'font-lock-face val))))))) ;; These are from the "Examples" section of ;; https://modern.ircdocs.horse/formatting.html @@ -134,30 +138,93 @@ erc-controls-highlight--spoilers (erc-tests-common-make-server-buf) (with-current-buffer (erc--open-target "#chan") (setq-local erc-interpret-mirc-color t) - (let* ((m "Spoiler: \C-c0,0Hello\C-c1,1World!") - (msg (erc-format-privmessage "bob" m nil t))) + (let* ((raw (concat "BEGIN " + "\C-c0,0 WhiteOnWhite " + "\C-c1,1 BlackOnBlack " + "\C-c99,99 Default " + "\C-o END")) + (msg (erc-format-privmessage "bob" raw nil t))) (erc-display-message nil nil (current-buffer) msg)) (forward-line -1) (should (search-forward " " nil t)) (save-restriction ;; Narrow to EOL or start of right-side stamp. (narrow-to-region (point) (line-end-position)) - (should (eq (get-text-property (+ 9 (point)) 'mouse-face) - 'erc-spoiler-face)) - (should (eq (get-text-property (1- (pos-eol)) 'mouse-face) - 'erc-spoiler-face)) - ;; "Spoiler" appears in ERC default face. + (save-excursion + (search-forward "WhiteOn") + (should (eq (get-text-property (point) 'mouse-face) + 'erc-spoiler-face)) + (search-forward "BlackOn") + (should (eq (get-text-property (point) 'mouse-face) + 'erc-spoiler-face))) + ;; Start wtih ERC default face. (erc-goodies-tests--assert-face - 0 "Spoiler: " 'erc-default-face + 0 "BEGIN " 'erc-default-face '(fg:erc-color-face0 bg:erc-color-face0)) - ;; "Hello" is masked in all white. + ;; Masked in all white. (erc-goodies-tests--assert-face - 9 "Hello" '(fg:erc-color-face0 bg:erc-color-face0) + 6 "WhiteOnWhite" '(fg:erc-color-face0 bg:erc-color-face0) '(fg:erc-color-face1 bg:erc-color-face1)) - ;; "World" is masked in all black. + ;; Masked in all black. (erc-goodies-tests--assert-face - 18 " World" '(fg:erc-color-face1 bg:erc-color-face1 ) - '(fg:erc-color-face0 bg:erc-color-face0)))) + 20 "BlackOnBlack" '(fg:erc-color-face1 bg:erc-color-face1) + '(erc-control-default-fg erc-control-default-bg)) + ;; Explicit "default" code ignoerd. + (erc-goodies-tests--assert-face + 34 "Default" '(erc-control-default-fg erc-control-default-bg) + '(fg:erc-color-face1 bg:erc-color-face1)) + (erc-goodies-tests--assert-face + 43 "END" 'erc-default-face + '(erc-control-default-bg erc-control-default-fg)))) + (when noninteractive + (erc-tests-common-kill-buffers))) + +(ert-deftest erc-controls-highlight--inverse () + (should (eq t erc-interpret-controls-p)) + (erc-tests-common-make-server-buf) + (with-current-buffer (erc--open-target "#chan") + (setq-local erc-interpret-mirc-color t) + (defvar erc-fill-column) + (let* ((erc-fill-column 90) + (raw (concat "BEGIN " + "\C-c3,13 GreenOnPink " + "\C-v PinkOnGreen " + "\C-c99,99 ReversedDefault " + "\C-v NormalDefault " + "\C-o END")) + (msg (erc-format-privmessage "bob" raw nil t))) + (erc-display-message nil nil (current-buffer) msg)) + (forward-line -1) + (should (search-forward " " nil t)) + (save-restriction + ;; Narrow to EOL or start of right-side stamp. + (narrow-to-region (point) (line-end-position)) + ;; Baseline. + (erc-goodies-tests--assert-face + 0 "BEGIN " 'erc-default-face + '(fg:erc-color-face0 bg:erc-color-face0)) + ;; Normal fg/bg combo. + (erc-goodies-tests--assert-face + 6 "GreenOnPink" '(fg:erc-color-face3 bg:erc-color-face13) + '(erc-inverse-face)) + ;; Reverse of previous, so former-bg on former-fg. + (erc-goodies-tests--assert-face + 19 "PinkOnGreen" + '(erc-inverse-face fg:erc-color-face3 bg:erc-color-face13) + nil) + ;; The inverse of `default' because reverse still in effect. + (erc-goodies-tests--assert-face + 32 "ReversedDefault" '(erc-inverse-face erc-control-default-fg + erc-control-default-bg) + '(fg:erc-color-face3 bg:erc-color-face13)) + (erc-goodies-tests--assert-face + 49 "NormalDefault" '(erc-control-default-fg + erc-control-default-bg) + '(erc-inverse-face fg:erc-color-face1 bg:erc-color-face1)) + (erc-goodies-tests--assert-face + 64 "END" 'erc-default-face + '( erc-control-default-fg erc-control-default-bg + fg:erc-color-face0 bg:erc-color-face0)))) (when noninteractive (erc-tests-common-kill-buffers))) -- 2.44.0