emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r109585: * lisp/color.el (color-xyz-t


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r109585: * lisp/color.el (color-xyz-to-lab, color-lab-to-xyz, color-cie-de2000):
Date: Mon, 13 Aug 2012 15:10:35 -0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 109585
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Mon 2012-08-13 15:10:35 -0400
message:
  * lisp/color.el (color-xyz-to-lab, color-lab-to-xyz, color-cie-de2000):
  Prefer pcase-let over destructuring-bind.
  * lisp/vc/diff-mode.el (diff-remove-trailing-whitespace): Same.
  Also, remove whitespace as we go, rather than after accumulating the
  various places.
modified:
  lisp/ChangeLog
  lisp/color.el
  lisp/vc/diff-mode.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2012-08-13 14:12:47 +0000
+++ b/lisp/ChangeLog    2012-08-13 19:10:35 +0000
@@ -1,5 +1,11 @@
 2012-08-13  Stefan Monnier  <address@hidden>
 
+       * color.el (color-xyz-to-lab, color-lab-to-xyz, color-cie-de2000):
+       Prefer pcase-let over destructuring-bind.
+       * vc/diff-mode.el (diff-remove-trailing-whitespace): Same.
+       Also, remove whitespace as we go, rather than after accumulating the
+       various places.
+
        * subr.el (internal--before-with-selected-window)
        (internal--after-with-selected-window): Fix typo seleted->selected.
        (with-selected-window): Adjust callers.

=== modified file 'lisp/color.el'
--- a/lisp/color.el     2012-04-05 07:29:19 +0000
+++ b/lisp/color.el     2012-08-13 19:10:35 +0000
@@ -1,4 +1,4 @@
-;;; color.el --- Color manipulation library -*- coding: utf-8; -*-
+;;; color.el --- Color manipulation library -*- coding: utf-8; 
lexical-binding:t -*-
 
 ;; Copyright (C) 2010-2012 Free Software Foundation, Inc.
 
@@ -85,7 +85,7 @@
         (g-step (/ (- (nth 1 stop) g) (1+ step-number)))
         (b-step (/ (- (nth 2 stop) b) (1+ step-number)))
         result)
-    (dotimes (n step-number)
+    (dotimes (_ step-number)
       (push (list (setq r (+ r r-step))
                  (setq g (+ g g-step))
                  (setq b (+ b b-step)))
@@ -226,44 +226,44 @@
   "Convert CIE XYZ to CIE L*a*b*.
 WHITE-POINT specifies the (X Y Z) white point for the
 conversion. If omitted or nil, use `color-d65-xyz'."
-  (destructuring-bind (Xr Yr Zr) (or white-point color-d65-xyz)
-      (let* ((xr (/ X Xr))
-             (yr (/ Y Yr))
-             (zr (/ Z Zr))
-             (fx (if (> xr color-cie-ε)
-                     (expt xr (/ 1 3.0))
-                   (/ (+ (* color-cie-κ xr) 16) 116.0)))
-             (fy (if (> yr color-cie-ε)
-                     (expt yr (/ 1 3.0))
-                   (/ (+ (* color-cie-κ yr) 16) 116.0)))
-             (fz (if (> zr color-cie-ε)
-                     (expt zr (/ 1 3.0))
-                   (/ (+ (* color-cie-κ zr) 16) 116.0))))
-        (list
-         (- (* 116 fy) 16)                  ; L
-         (* 500 (- fx fy))                  ; a
-         (* 200 (- fy fz))))))              ; b
+  (pcase-let* ((`(,Xr ,Yr ,Zr) (or white-point color-d65-xyz))
+               (xr (/ X Xr))
+               (yr (/ Y Yr))
+               (zr (/ Z Zr))
+               (fx (if (> xr color-cie-ε)
+                       (expt xr (/ 1 3.0))
+                     (/ (+ (* color-cie-κ xr) 16) 116.0)))
+               (fy (if (> yr color-cie-ε)
+                       (expt yr (/ 1 3.0))
+                     (/ (+ (* color-cie-κ yr) 16) 116.0)))
+               (fz (if (> zr color-cie-ε)
+                       (expt zr (/ 1 3.0))
+                     (/ (+ (* color-cie-κ zr) 16) 116.0))))
+    (list
+     (- (* 116 fy) 16)                ; L
+     (* 500 (- fx fy))                ; a
+     (* 200 (- fy fz)))))             ; b
 
 (defun color-lab-to-xyz (L a b &optional white-point)
   "Convert CIE L*a*b* to CIE XYZ.
 WHITE-POINT specifies the (X Y Z) white point for the
 conversion. If omitted or nil, use `color-d65-xyz'."
-  (destructuring-bind (Xr Yr Zr) (or white-point color-d65-xyz)
-      (let* ((fy (/ (+ L 16) 116.0))
-             (fz (- fy (/ b 200.0)))
-             (fx (+ (/ a 500.0) fy))
-             (xr (if (> (expt fx 3.0) color-cie-ε)
-                     (expt fx 3.0)
-               (/ (- (* fx 116) 16) color-cie-κ)))
-             (yr (if (> L (* color-cie-κ color-cie-ε))
-                     (expt (/ (+ L 16) 116.0) 3.0)
-                   (/ L color-cie-κ)))
-             (zr (if (> (expt fz 3) color-cie-ε)
-                     (expt fz 3.0)
-                   (/ (- (* 116 fz) 16) color-cie-κ))))
-        (list (* xr Xr)                 ; X
-              (* yr Yr)                 ; Y
-              (* zr Zr)))))             ; Z
+  (pcase-let* ((`(,Xr ,Yr ,Zr) (or white-point color-d65-xyz))
+               (fy (/ (+ L 16) 116.0))
+               (fz (- fy (/ b 200.0)))
+               (fx (+ (/ a 500.0) fy))
+               (xr (if (> (expt fx 3.0) color-cie-ε)
+                       (expt fx 3.0)
+                     (/ (- (* fx 116) 16) color-cie-κ)))
+               (yr (if (> L (* color-cie-κ color-cie-ε))
+                       (expt (/ (+ L 16) 116.0) 3.0)
+                     (/ L color-cie-κ)))
+               (zr (if (> (expt fz 3) color-cie-ε)
+                       (expt fz 3.0)
+                     (/ (- (* 116 fz) 16) color-cie-κ))))
+    (list (* xr Xr)                   ; X
+          (* yr Yr)                   ; Y
+          (* zr Zr))))                ; Z
 
 (defun color-srgb-to-lab (red green blue)
   "Convert RGB to CIE L*a*b*."
@@ -277,67 +277,72 @@
   "Return the CIEDE2000 color distance between COLOR1 and COLOR2.
 Both COLOR1 and COLOR2 should be in CIE L*a*b* format, as
 returned by `color-srgb-to-lab' or `color-xyz-to-lab'."
-  (destructuring-bind (L₁ a₁ b₁) color1
-    (destructuring-bind (L₂ a₂ b₂) color2
-      (let* ((kL (or kL 1))
-             (kC (or kC 1))
-             (kH (or kH 1))
-             (C₁ (sqrt (+ (expt a₁ 2.0) (expt b₁ 2.0))))
-             (C₂ (sqrt (+ (expt a₂ 2.0) (expt b₂ 2.0))))
-             (C̄ (/ (+ C₁ C₂) 2.0))
-             (G (* 0.5 (- 1 (sqrt (/ (expt C̄ 7.0) (+ (expt C̄ 7.0) (expt 25 
7.0)))))))
-             (a′₁ (* (+ 1 G) a₁))
-             (a′₂ (* (+ 1 G) a₂))
-             (C′₁ (sqrt (+ (expt a′₁ 2.0) (expt b₁ 2.0))))
-             (C′₂ (sqrt (+ (expt a′₂ 2.0) (expt b₂ 2.0))))
-             (h′₁ (if (and (= b₁ 0) (= a′₁ 0))
-                      0
-                    (let ((v (atan b₁ a′₁)))
-                      (if (< v 0)
-                          (+ v (* 2 float-pi))
-                        v))))
-             (h′₂ (if (and (= b₂ 0) (= a′₂ 0))
-                      0
-                    (let ((v (atan b₂ a′₂)))
-                      (if (< v 0)
-                          (+ v (* 2 float-pi))
-                        v))))
-             (ΔL′ (- L₂ L₁))
-             (ΔC′ (- C′₂ C′₁))
-             (Δh′ (cond ((= (* C′₁ C′₂) 0)
-                         0)
-                        ((<= (abs (- h′₂ h′₁)) float-pi)
-                         (- h′₂ h′₁))
-                        ((> (- h′₂ h′₁) float-pi)
-                         (- (- h′₂ h′₁) (* 2 float-pi)))
-                        ((< (- h′₂ h′₁) (- float-pi))
-                         (+ (- h′₂ h′₁) (* 2 float-pi)))))
-             (ΔH′ (* 2 (sqrt (* C′₁ C′₂)) (sin (/ Δh′ 2.0))))
-             (L̄′ (/ (+ L₁ L₂) 2.0))
-             (C̄′ (/ (+ C′₁ C′₂) 2.0))
-             (h̄′ (cond ((= (* C′₁ C′₂) 0)
-                        (+ h′₁ h′₂))
-                       ((<= (abs (- h′₁ h′₂)) float-pi)
-                        (/ (+ h′₁ h′₂) 2.0))
-                       ((< (+ h′₁ h′₂) (* 2 float-pi))
-                        (/ (+ h′₁ h′₂ (* 2 float-pi)) 2.0))
-                       ((>= (+ h′₁ h′₂) (* 2 float-pi))
-                        (/ (+ h′₁ h′₂ (* -2 float-pi)) 2.0))))
-             (T (+ 1
-                   (- (* 0.17 (cos (- h̄′ (degrees-to-radians 30)))))
-                   (* 0.24 (cos (* h̄′ 2)))
-                   (* 0.32 (cos (+ (* h̄′ 3) (degrees-to-radians 6))))
-                   (- (* 0.20 (cos (- (* h̄′ 4) (degrees-to-radians 63)))))))
-             (Δθ (* (degrees-to-radians 30) (exp (- (expt (/ (- h̄′ 
(degrees-to-radians 275)) (degrees-to-radians 25)) 2.0)))))
-             (Rc (* 2 (sqrt (/ (expt C̄′ 7.0) (+ (expt C̄′ 7.0) (expt 25.0 
7.0))))))
-             (Sl (+ 1 (/ (* 0.015 (expt (- L̄′ 50) 2.0)) (sqrt (+ 20 (expt (- 
L̄′ 50) 2.0))))))
-             (Sc (+ 1 (* C̄′ 0.045)))
-             (Sh (+ 1 (* 0.015 C̄′ T)))
-             (Rt (- (* (sin (* Δθ 2)) Rc))))
+  (pcase-let*
+      ((`(,L₁ ,a₁ ,b₁) color1)
+       (`(,L₂ ,a₂ ,b₂) color2)
+       (kL (or kL 1))
+       (kC (or kC 1))
+       (kH (or kH 1))
+       (C₁ (sqrt (+ (expt a₁ 2.0) (expt b₁ 2.0))))
+       (C₂ (sqrt (+ (expt a₂ 2.0) (expt b₂ 2.0))))
+       (C̄ (/ (+ C₁ C₂) 2.0))
+       (G (* 0.5 (- 1 (sqrt (/ (expt C̄ 7.0)
+                               (+ (expt C̄ 7.0) (expt 25 7.0)))))))
+       (a′₁ (* (+ 1 G) a₁))
+       (a′₂ (* (+ 1 G) a₂))
+       (C′₁ (sqrt (+ (expt a′₁ 2.0) (expt b₁ 2.0))))
+       (C′₂ (sqrt (+ (expt a′₂ 2.0) (expt b₂ 2.0))))
+       (h′₁ (if (and (= b₁ 0) (= a′₁ 0))
+                0
+              (let ((v (atan b₁ a′₁)))
+                (if (< v 0)
+                    (+ v (* 2 float-pi))
+                  v))))
+       (h′₂ (if (and (= b₂ 0) (= a′₂ 0))
+                0
+              (let ((v (atan b₂ a′₂)))
+                (if (< v 0)
+                    (+ v (* 2 float-pi))
+                  v))))
+       (ΔL′ (- L₂ L₁))
+       (ΔC′ (- C′₂ C′₁))
+       (Δh′ (cond ((= (* C′₁ C′₂) 0)
+                   0)
+                  ((<= (abs (- h′₂ h′₁)) float-pi)
+                   (- h′₂ h′₁))
+                  ((> (- h′₂ h′₁) float-pi)
+                   (- (- h′₂ h′₁) (* 2 float-pi)))
+                  ((< (- h′₂ h′₁) (- float-pi))
+                   (+ (- h′₂ h′₁) (* 2 float-pi)))))
+       (ΔH′ (* 2 (sqrt (* C′₁ C′₂)) (sin (/ Δh′ 2.0))))
+       (L̄′ (/ (+ L₁ L₂) 2.0))
+       (C̄′ (/ (+ C′₁ C′₂) 2.0))
+       (h̄′ (cond ((= (* C′₁ C′₂) 0)
+                  (+ h′₁ h′₂))
+                 ((<= (abs (- h′₁ h′₂)) float-pi)
+                  (/ (+ h′₁ h′₂) 2.0))
+                 ((< (+ h′₁ h′₂) (* 2 float-pi))
+                  (/ (+ h′₁ h′₂ (* 2 float-pi)) 2.0))
+                 ((>= (+ h′₁ h′₂) (* 2 float-pi))
+                  (/ (+ h′₁ h′₂ (* -2 float-pi)) 2.0))))
+       (T (+ 1
+             (- (* 0.17 (cos (- h̄′ (degrees-to-radians 30)))))
+             (* 0.24 (cos (* h̄′ 2)))
+             (* 0.32 (cos (+ (* h̄′ 3) (degrees-to-radians 6))))
+             (- (* 0.20 (cos (- (* h̄′ 4) (degrees-to-radians 63)))))))
+       (Δθ (* (degrees-to-radians 30)
+              (exp (- (expt (/ (- h̄′ (degrees-to-radians 275))
+                               (degrees-to-radians 25)) 2.0)))))
+       (Rc (* 2 (sqrt (/ (expt C̄′ 7.0) (+ (expt C̄′ 7.0) (expt 25.0 7.0))))))
+       (Sl (+ 1 (/ (* 0.015 (expt (- L̄′ 50) 2.0))
+                   (sqrt (+ 20 (expt (- L̄′ 50) 2.0))))))
+       (Sc (+ 1 (* C̄′ 0.045)))
+       (Sh (+ 1 (* 0.015 C̄′ T)))
+       (Rt (- (* (sin (* Δθ 2)) Rc))))
         (sqrt (+ (expt (/ ΔL′ (* Sl kL)) 2.0)
                  (expt (/ ΔC′ (* Sc kC)) 2.0)
                  (expt (/ ΔH′ (* Sh kH)) 2.0)
-                 (* Rt (/ ΔC′ (* Sc kC)) (/ ΔH′ (* Sh kH)))))))))
+                 (* Rt (/ ΔC′ (* Sc kC)) (/ ΔH′ (* Sh kH)))))))
 
 (defun color-clamp (value)
   "Make sure VALUE is a number between 0.0 and 1.0 inclusive."

=== modified file 'lisp/vc/diff-mode.el'
--- a/lisp/vc/diff-mode.el      2012-08-08 04:41:35 +0000
+++ b/lisp/vc/diff-mode.el      2012-08-13 19:10:35 +0000
@@ -2024,37 +2024,26 @@
 file referenced on the diff has no buffer and needs to be fixed,
 a buffer visiting that file is created."
   (interactive)
-  (goto-char (point-min))
-  (let
-      ;; We assume that the diff header has no trailing whitespace.
-      ((modified-buffers nil)
-       (white-positions nil))
-    (while (re-search-forward "^[+!>].*[ \t]+$" (point-max) t)
-      (save-excursion
-       (cl-destructuring-bind (buf line-offset pos src _dst &optional 
_switched)
-           (diff-find-source-location t t)
-         (when line-offset
-           (set-buffer buf)
-           (save-excursion
-             (goto-char (+ (car pos) (cdr src)))
-             (beginning-of-line)
-             (when (re-search-forward "\\([ \t]+\\)$" (line-end-position) t)
-               (when (not (member buf modified-buffers))
-                 (push buf modified-buffers))
-               (goto-char (match-end 0))
-               (push (point-marker) white-positions)
-               (goto-char (match-beginning 0))
-               (push (point-marker) white-positions)
-               (push buf white-positions)))))))
-    (while white-positions
-      (save-excursion
-       (set-buffer (pop white-positions))
-       (delete-region (pop white-positions) (pop white-positions))))
+  ;; We assume that the diff header has no trailing whitespace.
+  (let ((modified-buffers nil))
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward "^[+!>].*[ \t]+$" (point-max) t)
+        (pcase-let ((`(,buf ,line-offset ,pos ,src ,_dst ,_switched)
+                     (diff-find-source-location t t)))
+          (when line-offset
+            (with-current-buffer buf
+              (save-excursion
+                (goto-char (+ (car pos) (cdr src)))
+                (beginning-of-line)
+                (when (re-search-forward "\\([ \t]+\\)$" (line-end-position) t)
+                  (unless (memq buf modified-buffers)
+                    (push buf modified-buffers))
+                  (replace-match ""))))))))
     (if modified-buffers
-       (let ((msg "Deleted new trailing whitespace from:"))
-         (dolist (f modified-buffers)
-           (setq msg (concat msg " `" (buffer-name f) "'")))
-         (message "%s" msg))
+        (message "Deleted new trailing whitespace from: %s"
+                 (mapconcat (lambda (buf) (concat "`" (buffer-name buf) "'"))
+                            modified-buffers " "))
       (message "No trailing whitespace fixes needed."))))
 
 ;; provide the package


reply via email to

[Prev in Thread] Current Thread [Next in Thread]