unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#47083: 28.0.50; [PATCH] Use color.el on pulse.el
@ 2021-03-12  1:43 Gabriel
  2021-03-18  7:11 ` Lars Ingebrigtsen
  0 siblings, 1 reply; 2+ messages in thread
From: Gabriel @ 2021-03-12  1:43 UTC (permalink / raw)
  To: 47083

[-- Attachment #1: Type: text/plain, Size: 111 bytes --]


Replace custom color calculation in pulse.el with color-gradient from
color.el and some other minor changes.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-cedet-pulse.el-Use-color.el.patch --]
[-- Type: text/x-diff, Size: 6581 bytes --]

From c9e6614c01941243752e590e486788d029ecd3e8 Mon Sep 17 00:00:00 2001
From: Gabriel do Nascimento Ribeiro <gabriel.nascimento@nubank.com.br>
Date: Thu, 11 Mar 2021 22:37:12 -0300
Subject: [PATCH] lisp/cedet/pulse.el: Use color.el

(pulse-int-to-hex): remove function
(pulse-color-values-to-hex): remove function
(pulse-lighten-highlight): remove function
(pulse-momentary-iteration): add variable
(pulse-momentary-highlight-overlay): use color-gradient from color.el
(pulse-tick): receive colors and update overlay background
based on iteration
---
 lisp/cedet/pulse.el | 102 +++++++++++++-------------------------------
 1 file changed, 30 insertions(+), 72 deletions(-)

diff --git a/lisp/cedet/pulse.el b/lisp/cedet/pulse.el
index 3257feb1fe..ca4f7f48c2 100644
--- a/lisp/cedet/pulse.el
+++ b/lisp/cedet/pulse.el
@@ -30,10 +30,9 @@
 ;;
 ;; The following are useful entry points:
 ;;
-;; `pulse' - Cause `pulse-highlight-face' to shift toward background color.
+;; `pulse-tick' - Cause `pulse-highlight-face' to shift toward background color.
 ;;      Assumes you are using a version of Emacs that supports pulsing.
 ;;
-;;
 ;; `pulse-momentary-highlight-one-line' - Pulse a single line at POINT.
 ;; `pulse-momentary-highlight-region' - Pulse a region.
 ;; `pulse-momentary-highlight-overlay' - Pulse an overlay.
@@ -50,7 +49,9 @@
 ;;
 ;; Pulse is a part of CEDET.  http://cedet.sf.net
 
-(defun  pulse-available-p ()
+(require 'color)
+
+(defun pulse-available-p ()
   "Return non-nil if pulsing is available on the current frame."
   (condition-case nil
       (let ((v (color-values (face-background 'default))))
@@ -90,69 +91,27 @@ pulse-highlight-face
   :group 'pulse)
 
 ;;; Code:
-;;
-(defun pulse-int-to-hex (int &optional nb-digits)
-  "Convert integer argument INT to a #XXXXXXXXXXXX format hex string.
-Each X in the output string is a hexadecimal digit.
-NB-DIGITS is the number of hex digits.  If INT is too large to be
-represented with NB-DIGITS, then the result is truncated from the
-left.  So, for example, INT=256 and NB-DIGITS=2 returns \"00\", since
-the hex equivalent of 256 decimal is 100, which is more than 2 digits.
-
-This function was blindly copied from hexrgb.el by Drew Adams.
-https://www.emacswiki.org/emacs/hexrgb.el"
-  (setq nb-digits (or nb-digits 4))
-  (substring (format (concat "%0" (int-to-string nb-digits) "X") int) (- nb-digits)))
-
-(defun pulse-color-values-to-hex (values)
-  "Convert list of rgb color VALUES to a hex string, #XXXXXXXXXXXX.
-Each X in the string is a hexadecimal digit.
-Input VALUES is as for the output of `x-color-values'.
-
-This function was blindly copied from hexrgb.el by Drew Adams.
-https://www.emacswiki.org/emacs/hexrgb.el"
-  (concat "#"
-          (pulse-int-to-hex (nth 0 values) 4) ; red
-          (pulse-int-to-hex (nth 1 values) 4) ; green
-          (pulse-int-to-hex (nth 2 values) 4))) ; blue
 
 (defcustom pulse-iterations 10
   "Number of iterations in a pulse operation."
   :group 'pulse
   :type 'number)
+
 (defcustom pulse-delay .03
   "Delay between face lightening iterations."
   :group 'pulse
   :type 'number)
 
-(defun pulse-lighten-highlight ()
-  "Lighten the face by 1/`pulse-iterations' toward the background color.
-Return t if there is more drift to do, nil if completed."
-  (if (>= (get 'pulse-highlight-face :iteration) pulse-iterations)
-      nil
-    (let* ((frame (color-values (face-background 'default)))
-	   (pulse-background (face-background
-			      (get 'pulse-highlight-face
-				   :startface)
-                              nil t)));; can be nil
-      (when pulse-background
-	(let* ((start (color-values pulse-background))
-	       (frac  (list (/ (- (nth 0 frame) (nth 0 start)) pulse-iterations)
-			    (/ (- (nth 1 frame) (nth 1 start)) pulse-iterations)
-			    (/ (- (nth 2 frame) (nth 2 start)) pulse-iterations)))
-	       (it (get 'pulse-highlight-face :iteration))
-	       )
-	  (set-face-background 'pulse-highlight-face
-			       (pulse-color-values-to-hex
-				(list
-				 (+ (nth 0 start) (* (nth 0 frac) it))
-				 (+ (nth 1 start) (* (nth 1 frac) it))
-				 (+ (nth 2 start) (* (nth 2 frac) it)))))
-	  (put 'pulse-highlight-face :iteration (1+ it))
-	  (if (>= (1+ it) pulse-iterations)
-	      nil
-	    t)))
-      )))
+;;; Convenience Functions
+;;
+(defvar pulse-momentary-overlay nil
+  "The current pulsing overlay.")
+
+(defvar pulse-momentary-timer nil
+  "The current pulsing timer.")
+
+(defvar pulse-momentary-iteration 0
+  "The current pulsing iteration.")
 
 (defun pulse-reset-face (&optional face)
   "Reset the pulse highlighting FACE."
@@ -166,15 +125,7 @@ pulse-reset-face
                         (face-extend-p face nil t)))
   (put 'pulse-highlight-face :startface (or face
 					    'pulse-highlight-start-face))
-  (put 'pulse-highlight-face :iteration 0))
-
-;;; Convenience Functions
-;;
-(defvar pulse-momentary-overlay nil
-  "The current pulsing overlay.")
-
-(defvar pulse-momentary-timer nil
-  "The current pulsing timer.")
+  (setq pulse-momentary-iteration 0))
 
 (defun pulse-momentary-highlight-overlay (o &optional face)
   "Pulse the overlay O, unhighlighting before next command.
@@ -201,14 +152,21 @@ pulse-momentary-highlight-overlay
       ;; Thus above we put our face on the overlay, but pulse
       ;; with a reference face needed for the color.
       (pulse-reset-face face)
-      (setq pulse-momentary-timer
-            (run-with-timer 0 pulse-delay #'pulse-tick
-                            (time-add nil
-                                      (* pulse-delay pulse-iterations)))))))
-
-(defun pulse-tick (stop-time)
+      (let* ((start (color-name-to-rgb (face-background 'pulse-highlight-start-face)))
+             (stop (color-name-to-rgb (face-background 'default)))
+             (colors (mapcar (apply-partially 'apply 'color-rgb-to-hex)
+                             (color-gradient start stop pulse-iterations))))
+        (setq pulse-momentary-timer
+              (run-with-timer 0 pulse-delay #'pulse-tick
+                              colors
+                              (time-add nil
+                                        (* pulse-delay pulse-iterations))))))))
+
+(defun pulse-tick (colors stop-time)
   (if (time-less-p nil stop-time)
-      (pulse-lighten-highlight)
+      (when-let (color (elt colors pulse-momentary-iteration))
+        (set-face-background 'pulse-highlight-face color)
+        (setq pulse-momentary-iteration (1+ pulse-momentary-iteration)))
     (pulse-momentary-unhighlight)))
 
 (defun pulse-momentary-unhighlight ()
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#47083: 28.0.50; [PATCH] Use color.el on pulse.el
  2021-03-12  1:43 bug#47083: 28.0.50; [PATCH] Use color.el on pulse.el Gabriel
@ 2021-03-18  7:11 ` Lars Ingebrigtsen
  0 siblings, 0 replies; 2+ messages in thread
From: Lars Ingebrigtsen @ 2021-03-18  7:11 UTC (permalink / raw)
  To: Gabriel; +Cc: 47083

Gabriel <gabriel376@hotmail.com> writes:

> Replace custom color calculation in pulse.el with color-gradient from
> color.el and some other minor changes.

Looks reasonable to me; applied to Emacs 28.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-18  7:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12  1:43 bug#47083: 28.0.50; [PATCH] Use color.el on pulse.el Gabriel
2021-03-18  7:11 ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).