emacs-pretest-bug
[Top][All Lists]
Advanced

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

Turning off tooltip-mode wipes out echo-area message


From: Drew Adams
Subject: Turning off tooltip-mode wipes out echo-area message
Date: Sun, 6 Aug 2006 16:23:26 -0700

I've pared this down quite a bit, but I haven't isolated the problem completely. The two libraries below give a reproducible test, in any case. Neither library has anything to do with tooltip-mode, BTW.

In GNU Emacs 22.0.50.1 (i386-msvc-nt5.1.2600)
 of 2006-07-19 on BOS-CTHEWLAP2
X server distributor `Microsoft Corp.', version 5.1.2600
configured using `configure --with-msvc (12.00)'

To reproduce:

1. load file hexrgb-for-bug-test.el (second file below).

2. load file bug-tooltip.el (first file below).

3. turn on tooltip-mode: M-x tooltip mode once or twice, until enabled.

4. M-x palette - type a color name, e.g. "thistle", to the prompt for a color.

5. The palette will be displayed, and you'll see these messages in the echo area. Each is followed by a sleep-for of a couple seconds. (The sleep-for is unrelated to the bug; it is just to see better what's going on.)

a. "FFFFFFFFFFFFFFFFFFFFFFFFF"
b. "Color: thistle, RGB: (0.8470588235294118 0.7490196078431373 0.8470588235294118), HSV: (0.0 0.0 0.8470588235294118)"

Notice that the second message stays displayed, as it should. That is the real aim of the code; the FFFF... message and the sleep-for's are just for the bug report.

Type `q' to kill the palette buffers and delete the palette frame. Now, turn off tooltip-mode and then repeat step 5. The second message is never seen. (Or, you might see it momentarily, but it is quickly blanked out.)

The correct behavior is what you see when tooltip-mode is enabled. It is incorrect that the second message is not displayed and left displayed.

My guess is that some tooltip that is not even seen is somehow being displayed in the echo area, and that is wiping out the message. I don't know.
 
Tooltips should not be displayed at all if you don't move the mouse (I don't touch the mouse during this testing), and they should go away after a few seconds. And, after a tooltip does go away, whatever message might have been in the echo area before the tooltip was displayed should be restored, as if the tooltip were never displayed. IOW, a tooltip in the echo area should be only temporary, and it should not affect the state of the echo area after it is gone.

BTW, sometimes the bug doesn't appear, and I'm not sure why.
I think I noticed, a couple of times, that doing something like C-x C-b C-x 1 made it work again (no bug) for a while. Or putting the mouse over the frame title bar. Or moving the main frame, so the palette frame overlapped or didn't overlap it, or so the palette frame was displayed under the mouse or not. I couldn't track any of this down to anything systematic. My hunch is that in some situations (?) the invisible tooltip is simply not displayed, so the "Color:" message appears and is left displayed. So, if you don't see the bug right away, try moving a few things and turning tooltip-mode off and on. Once the bug appears, it does so regularly, and you can make it manifest or not, just by toggling tooltip-mode.
 
Thanks.

-----------8<----------- file bug-tooltip.el -----------------------

(require 'hexrgb)

(defcustom palette-font
    (or (car (x-list-fonts "-*-Courier-*-*-*-*-5-*-*-*-*-*-iso8859-1" nil nil 1))
        (car (x-list-fonts "-*-fixed-*-*-*-*-5-*-*-*-*-*-iso8859-1" nil nil 1))
        (car (x-list-fonts "-*-Terminal-*-*-*-*-5-*-*-*-*-*-iso8859-1" nil nil 1))
        (car (x-list-fonts "-*-*-*-*-*-*-5-*-*-*-*-*-iso8859-1" nil nil 1)))
  "$$$" :type 'string)

(defvar palette-current-color "#000000000000" "$$")
(defvar palette-old-color "#000000000000" "$$")
(defvar palette-mode-map nil "$$")
(unless palette-mode-map
  (let ((map (make-sparse-keymap "Color Palette"))
        (popup-map (make-sparse-keymap "Color Palette Menu")))
    (define-key map "q"    'palette-quit)                ; q = quit
    (define-key-after popup-map [quit]
      '(menu-item "Quit (Cancel)" palette-quit
        :help "Quit the color palette without any exit action."))
    (setq palette-mode-map map)))

(define-derived-mode palette-mode nil "$$" "$$"
    (setq mode-line-format nil)
    (set (make-local-variable 'auto-hscroll-mode) nil)
    (set (make-local-variable 'auto-window-vscroll) nil)
    (set (make-local-variable 'transient-mark-mode) nil)
    (set (make-local-variable 'truncate-lines) t)
    (setq show-trailing-whitespace nil)
    (setq cursor-in-non-selected-windows t)
    (when (fboundp 'blink-cursor-mode) (blink-cursor-mode 1)))

(defun palette-face-at-point () "$$"
  (let* ((faceprop (or (get-char-property (point) 'read-face-name)
                       (get-char-property (point) 'face)
                       'default))
         (face (cond ((symbolp faceprop) faceprop)
                     ((and (consp faceprop) (not (keywordp (car faceprop)))
                           (not (memq (car faceprop) '(foreground-color background-color))))
                      (car faceprop))
                     (t nil))))
    (if (facep face) face nil)))

(defun palette-background-at-point () "$$"
  (interactive)
  (let* ((face (or (and (not (eq major-mode 'palette-mode))
                        (palette-face-at-point))
                   (get-char-property (point) 'read-face-name)
                   (get-char-property (point) 'face)
                   'default))
         (bg (cond ((and face (symbolp face))
                    (condition-case nil
                        (face-background face nil 'default) ; Emacs 22.
                      (error (or (face-background face) ; Emacs 20
                                 (cdr (assq 'background-color (frame-parameters)))))))
                   ((consp face)
                    (cond ((memq 'background-color face) (cdr (memq 'background-color face)))
                          ((memq ':background face) (cadr (memq ':background face)))))
                   (t nil))))
    (when (interactive-p)
      (if bg (palette-color-message bg t) (message "No background color here")))
    bg))

(defun palette-pick-background-at-point (&optional show-p) "$$"
  (interactive "P")
  (save-selected-window
    (setq palette-current-color (palette-background-at-point))
    (unless (stringp palette-current-color) (error "No background color here to pick"))
    (when (interactive-p) (palette-color-message palette-current-color))
    (cond ((get-buffer-window "Palette (Hue x Saturation)" 'visible)
           (palette-brightness-scale)
           (palette-swatch))
          (show-p (palette palette-current-color))))
  palette-current-color)

(defun palette-quit () "$$$$$$$"
  (interactive)
  (let ((win (get-buffer-window "Palette (Hue x Saturation)" 'visible)))
    (when win (select-window win) (delete-frame)))
  (when (get-buffer "Palette (Hue x Saturation)") (kill-buffer "Palette (Hue x Saturation)"))
  (when (get-buffer "Brightness") (kill-buffer "Brightness"))
  (when (get-buffer "Current/Original") (kill-buffer "Current/Original"))
  palette-current-color)

(defun palette-where-is-color (color &optional cursor-color) "$$"
  (interactive (list (hexrgb-read-color t)))
  (setq color (hexrgb-color-name-to-hex color))
  (let ((target-hue (hexrgb-hue color))
        (target-sat (hexrgb-saturation color))
        (next-line-add-newlines nil)
        (hue-sat-win (get-buffer-window "Palette (Hue x Saturation)" 'visible))
        bg hue sat)
    (unless hue-sat-win (error "No Palette displayed - use command `palette'"))
    (select-window hue-sat-win)
    (if (< target-sat 0.049)
        (goto-char (- (point-max) 50))
      (while (and (not (eobp)) (setq bg (palette-background-at-point))
                  (setq sat (hexrgb-saturation bg)) (< target-sat sat))
        (condition-case nil (next-line 1) (goto-char (point-max))))
      (while (and (not (bobp)) (setq bg (palette-background-at-point))
                  (setq sat (hexrgb-saturation bg)) (> target-sat sat))
        (condition-case nil (previous-line 1) (goto-char (point-min))))
      (while (and (not (eolp)) (setq bg (palette-background-at-point))
                  (setq hue (hexrgb-hue bg)) (< target-hue hue))
        (forward-char))
      (while (and (not (bolp)) (setq bg (palette-background-at-point))
                  (setq hue (hexrgb-hue bg)) (> target-hue hue))
        (backward-char)))))

(defun palette (&optional color) "$$"
  (interactive (list (hexrgb-read-color nil t)))
  (message "Loading palette...")
  (when (string= "" color)
    (let ((rand (random (length hexrgb-defined-colors))))
      (setq color (elt hexrgb-defined-colors rand))))
  (let ((xcolor (hexrgb-color-name-to-hex color)))
    (setq palette-current-color (or (hexrgb-color-name-to-hex xcolor) "#FFFF00000000")
          palette-old-color palette-current-color)
    (unless palette-font
      (error "You must define `palette-font'.  `C-h v' for more information"))
    (palette-quit)
    (let* ((pop-up-frames t)
           (window-min-width 5)
           (temp-buffer-setup-hook nil)
           (temp-buffer-show-functions nil)
           (width 100)
           (height 100)
           (stringlen (* width height)))
      (set-buffer (get-buffer-create "Palette (Hue x Saturation)"))
      (make-frame
       `((menu-bar-lines . 0) (tool-bar-lines . 0) (left-fringe . 0) (right-fringe . 0)
         (fringe . 0) (height . 100) (width . 115) (minibuffer) (vertical-scroll-bars)
         (cursor-type . box) (background-color . "Black") (mouse-color . "Black")
         (cursor-color . "Black") ,(cons 'font palette-font)))
      (with-output-to-temp-buffer "Palette (Hue x Saturation)"
        (let* ((cells (make-string stringlen ?\s- ))
               (hue 0.999999)
               (sat 1.0)
               (index 0)
               (col "#000000000000")
               (hhh 0)
               (sss 0))
          (while (< index stringlen)
            (setq sss 0)
            (while (< sss height)
              (setq hhh 0)
              (setq hue 1.0)
              (while (< hhh width)
                (put-text-property index (1+ index)
                                   'face (cons 'background-color
                                               (setq col (hexrgb-hsv-to-hex hue sat 1.0)))
                                   cells)
                (put-text-property index (1+ index) 'pointer 'hand cells)
                (setq hue (* (- hue 0.01) 0.999) hhh (1+ hhh) index (1+ index)))
              (setq sat (* sat 0.97) sss (1+ sss))))
          (set-buffer "Palette (Hue x Saturation)")
          (setq sss 0 index 0)
          (while (< sss height)
            (insert (substring cells index (+ index width)) ?\n)
            (setq sss (1+ sss) index (+ index width)))))
      (select-window (get-buffer-window "Palette (Hue x Saturation)" 'visible))
      (setq window-size-fixed t)
      (palette-mode)
      (setq buffer-read-only t)
      (split-window (selected-window) width t)
      (palette-swatch)
      (palette-swatch t)
      (split-window (selected-window) 10 t)
      (palette-brightness-scale)
      (select-window (get-buffer-window "Palette (Hue x Saturation)" 'visible)))
    (when (interactive-p)
      ;;(let ((redisplay-dont-pause t)) (sit-for 0))
      ;;(force-mode-line-update t)
      ;;(redraw-display)
      (message "FFFFFFFFFFFFFFFFFFFFFFFFF")
      (sleep-for 3)
      (palette-color-message color)
      (sleep-for 2))
    palette-current-color))

(defun palette-brightness-scale (&optional color) "$$"
  (interactive (list (hexrgb-read-color)))
  (setq color (or color palette-current-color))
  (setq color (hexrgb-color-name-to-hex color))
  (let* ((width 5)
         (height 100)
         (hue-sat-win (get-buffer-window "Palette (Hue x Saturation)" 'visible))
         (pop-up-frames (not hue-sat-win))
         (stringlen (* width height))
         (target-val (hexrgb-value color))
         (val 1.0))
    (with-output-to-temp-buffer "Brightness"
      (let* ((cells (make-string stringlen ?\s- ))
             (hue (hexrgb-hue color))
             (sat (hexrgb-saturation color))
             (index 0)
             (col "#FFFFFFFFFFFF")
             (hhh 0)
             (sss 0))
        (while (< index stringlen)
          (setq sss 0)
          (while (< sss height)
            (setq hhh 0)
            (setq col (hexrgb-hsv-to-hex hue sat val))
            (while (< hhh width)
              (put-text-property index (1+ index) 'face (cons 'background-color col)
                                 cells)
              (put-text-property index (1+ index) 'pointer 'hand cells)
              (setq hhh (1+ hhh) index (1+ index)))
            (setq val (* val 0.97) sss (1+ sss))))
        (set-buffer "Brightness")
        (setq sss 0 index 0)
        (while (< sss height)
          (insert (substring cells index (+ index width)) ?\n)
          (setq sss (1+ sss) index (+ index width)))))
    (select-window (get-buffer-window "Brightness" 'visible))

    (while (and (not (eobp))
                (setq val (hexrgb-value (palette-background-at-point)))
                (< target-val val))
      (condition-case nil (next-line 1) (goto-char (point-max))))
    (while (and (not (bobp))
                (setq val (hexrgb-value (palette-background-at-point)))
                (> target-val val))
      (condition-case nil (previous-line 1) (goto-char (point-min))))
    (save-excursion
      (let ((buffer-read-only nil)
            (cells (make-string 5 ?e))
            (bg (get-text-property (point) 'face)))
        (delete-char 5)
        (put-text-property 0 5 'face bg cells)
        (insert cells)))
    (palette-mode)
    (setq buffer-read-only t)
    (let ((complement-color (palette-complement-or-alternative color)))
      (if (not hue-sat-win)
          (modify-frame-parameters
           (selected-frame)
           `((menu-bar-lines . 0) (tool-bar-lines . 0) (cursor-type . box)
             (left-fringe . 0) (right-fringe . 0) (fringe . 0) (minibuffer) (height . 101)
             (vertical-scroll-bars) (background-color . "White") ,(cons 'width (1+ width))
             ,(cons 'foreground-color complement-color) ,(cons 'mouse-color complement-color)
             ,(cons 'font palette-font) ,(cons 'cursor-color complement-color)))
        (select-window hue-sat-win)
        (palette-where-is-color color complement-color)))))

(defun palette-swatch (&optional oldp color)  "$$"
  (interactive (list nil (hexrgb-read-color)))
  (let* ((width 10)
         (height 50)
         (hue-sat-win (get-buffer-window "Palette (Hue x Saturation)" 'visible))
         (swatch-name "Current/Original")
         (pop-up-frames (not hue-sat-win))
         (stringlen (* width height)))
    (setq color (or color (hexrgb-color-name-to-hex
                           (if oldp palette-old-color palette-current-color))))
    (let* ((cells (make-string stringlen ?\s- ))
           (hue (hexrgb-hue color))
           (sat (hexrgb-saturation color))
           (val 1.0)
           (index 0)
           (col "#FFFFFFFFFFFF")
           (hhh 0)
           (sss 0))
      (while (< index stringlen)
        (setq sss 0)
        (while (< sss height)
          (setq hhh 0)
          (while (< hhh width)
            (put-text-property index (1+ index) 'face (cons 'background-color color)
                               cells)
            (put-text-property index (1+ index) 'pointer 'hand cells)
            (setq hhh (1+ hhh) index (1+ index)))
          (setq sss (1+ sss))))
      (set-buffer (get-buffer-create swatch-name))
      (if oldp
          (goto-char (+ stringlen height 1))
        (unless (= (point-min) (point-max))
          (delete-region (point-min) (+ stringlen height 1))
          (goto-char (point-min))))
      (setq sss 0 index 0)
      (while (< sss height)
        (insert (substring cells index (+ index width)) ?\n)
        (setq sss (1+ sss) index (+ index width))))
    (display-buffer swatch-name)
    (select-window (get-buffer-window swatch-name 'visible))
    (palette-mode)
    (goto-char (point-min))
    (unless hue-sat-win
      (let ((complement-color (palette-complement-or-alternative color)))
        (modify-frame-parameters
         (selected-frame)
         `((menu-bar-lines . 0) (tool-bar-lines . 0) (left-fringe . 0) (right-fringe . 0)
           (fringe . 0) (minibuffer) (vertical-scroll-bars) (background-color . "White")
           (cursor-type . box) ,(cons 'foreground-color complement-color)
           ,(cons 'mouse-color complement-color) ,(cons 'height (1+ height))
           ,(cons 'width (1+ width)) ,(cons 'cursor-color complement-color)
           ,(cons 'font palette-font)))))))

(defun palette-complement-or-alternative (color &optional alternative) "$$"
  (let ((hue (hexrgb-hue color)))
    (setq alternative
          (or alternative (if (or (hexrgb-approx-equal hue 1.0 0.2)
                                  (hexrgb-approx-equal hue 0.0 0.0 0.1))
                              "Cyan"
                            "Red")))
    (let ((complement (hexrgb-complement color)))
      (if (or (hexrgb-approx-equal (hexrgb-value complement) (hexrgb-value color) 0.4)
              (< (hexrgb-saturation color) 0.2))
          alternative
        complement))))

(defun palette-color-message (color &optional hint-p) "$$"
  (let* ((rgb (hexrgb-hex-to-rgb color))
         (hsv (apply #'hexrgb-rgb-to-hsv rgb))
         (msg (format "Color: %s, RGB: %s, HSV: %s" color rgb hsv)))
    (if hint-p (message "%s  (pick: mouse-2, RET)" msg) (message "%s" msg)))
  color)

(provide 'palette)
 
 
 


;;--------------8<-------- file hexrgb-for-bug-test.el --------------

(eval-when-compile (require 'cl))
 
(defconst hexrgb-defined-colors
  (eval-when-compile (x-defined-colors)) "$$")
 
(defconst hexrgb-defined-colors-alist
  (eval-when-compile (mapcar #'list (x-defined-colors))) "$$")
 
(defun hexrgb-read-color (&optional convert-to-RGB-p allow-empty-name-p prompt)
  "$$"
  (interactive "p")
  (let* ((completion-ignore-case t)
  (color (completing-read (or prompt "Color (name or #R+G+B+): ")
                                 hexrgb-defined-colors-alist))
         (hex-string (hexrgb-rgb-hex-string-p color t)))
    (if (and allow-empty-name-p (string= "" color))
        ""
      (when (and hex-string (not (eq 0 hex-string)))
        (setq color (concat "#" color)))
      (if (not (or hex-string
                   (if (fboundp 'test-completion)
                       (test-completion color hexrgb-defined-colors-alist)
                     (try-completion color hexrgb-defined-colors-alist))))
          (error "No such color: %S" color)
        (when convert-to-RGB-p (setq color (hexrgb-color-name-to-hex color))))
      (when (interactive-p) (message "Color: `%s'" color))
      color)))
 
(defun hexrgb-rgb-hex-string-p (color &optional laxp) "$$"
  (or (string-match "^#\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color)
      (and laxp (string-match "^\\([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]\\)+$" color) t)))
 
(defun hexrgb-complement (color) "$$"
  (interactive (list (hexrgb-read-color)))
  (setq color (hexrgb-color-name-to-hex color))
  (let ((red (hexrgb-red color))
        (green (hexrgb-green color))
        (blue (hexrgb-blue color)))
    (setq color (hexrgb-rgb-to-hex (- 1.0 red) (- 1.0 green) (- 1.0 blue))))
  (when (interactive-p) (message "Complement: `%s'" color))
  color)
 
(defun hexrgb-hue (color) "$$" 
  (interactive (list (hexrgb-read-color)))
  (setq color (hexrgb-color-name-to-hex color))   
  (car (hexrgb-rgb-to-hsv (hexrgb-red color) (hexrgb-green color) (hexrgb-blue color))))
 
(defun hexrgb-saturation (color) "$$"
  (interactive (list (hexrgb-read-color)))
  (setq color (hexrgb-color-name-to-hex color))
  (cadr (hexrgb-rgb-to-hsv (hexrgb-red color) (hexrgb-green color) (hexrgb-blue color))))
 
(defun hexrgb-value (color) "$$"
  (interactive (list (hexrgb-read-color)))
  (setq color (hexrgb-color-name-to-hex color))
  (caddr (hexrgb-rgb-to-hsv (hexrgb-red color) (hexrgb-green color) (hexrgb-blue color))))
 
(defun hexrgb-red (color) "$$"
  (interactive (list (hexrgb-read-color)))
  (setq color (hexrgb-color-name-to-hex color))
  (/ (hexrgb-hex-to-int (substring color 1 (1+ (/ (1- (length color)) 3))))
     (expt 16.0 (/ (1- (length color)) 3.0))))
   
(defun hexrgb-green (color) "$$"
  (interactive (list (hexrgb-read-color)))
  (setq color (hexrgb-color-name-to-hex color))
  (let* ((len (/ (1- (length color)) 3))
         (start (1+ len)))
    (/ (hexrgb-hex-to-int (substring color start (+ start len)))
       (expt 16.0 (/ (1- (length color)) 3.0)))))
   
(defun hexrgb-blue (color) "$$"
  (interactive (list (hexrgb-read-color)))
  (setq color (hexrgb-color-name-to-hex color))
  (let* ((len (/ (1- (length color)) 3))
         (start (+ 1 len len)))
    (/ (hexrgb-hex-to-int (substring color start (+ start len)))
       (expt 16.0 (/ (1- (length color)) 3.0)))))
 
(defun hexrgb-rgb-to-hsv (red green blue) "$$"
  (let* ((min (min red green blue))
         (max (max red green blue))
         (value max)
         (delta (- max min))
         hue saturation)
    (if (hexrgb-approx-equal 0.0 delta)
        (setq hue 0.0 saturation 0.0)
      (if (and (condition-case nil
                   (setq saturation (/ delta max))
                 (arith-error nil))
               (or (< emacs-major-version 21)
                   (not (equal 0.0e+NaN saturation))))
          (if (hexrgb-approx-equal 0.0 saturation)
              (setq hue 0.0 saturation 0.0)
            (if (hexrgb-approx-equal red max)
                (setq hue (/ (- green blue) delta))
              (if (hexrgb-approx-equal green max)
                  (setq hue (+ 2.0 (/ (- blue red) delta)))
                (setq hue (+ 4.0 (/ (- red green) delta)))))
            (setq hue (/ hue 6.0))
            (when (<= hue 0.0)(setq hue (+ hue 1.0))))
        (setq saturation 0.0 hue 0.0)))
    (list hue saturation value)))
 
(defun hexrgb-hsv-to-rgb (hue saturation value) "$$"
  (let (red green blue int-hue fract pp qq tt ww)
    (if (hexrgb-approx-equal 0.0 saturation)
        (setq red value green value blue value)
      (setq hue (* hue 6.0)
            int-hue (floor hue)
            fract (- hue int-hue)
            pp (* value (- 1 saturation))
            qq (* value (- 1 (* saturation fract)))
            ww (* value (- 1 (* saturation (- 1 (- hue int-hue))))))
      (case int-hue
        ((0 6) (setq red value green ww blue pp))
        (1 (setq red qq green value blue pp))
        (2 (setq red pp green value blue ww))
        (3 (setq red pp green qq blue value))
        (4 (setq red ww green pp blue value))
        (otherwise (setq red value green pp blue qq))))
    (list red green blue)))
 
(defun hexrgb-hsv-to-hex (hue saturation value) "$$"
  (hexrgb-color-values-to-hex
   (mapcar (lambda (x) (floor (* x 65535.0))) (hexrgb-hsv-to-rgb hue saturation value))))
 
(defun hexrgb-rgb-to-hex (red green blue) "$$"
  (hexrgb-color-values-to-hex
   (mapcar (lambda (x) (floor (* x 65535.0))) (list red green blue))))
 
(defun hexrgb-hex-to-rgb (color) "$$"
  (unless (hexrgb-rgb-hex-string-p color) (setq color (hexrgb-color-name-to-hex color)))
  (let ((len (/ (1- (length color)) 3)))
    (list (/ (hexrgb-hex-to-int (substring color 1 (1+ len))) 65535.0)
          (/ (hexrgb-hex-to-int (substring color (1+ len) (+ 1 len len))) 65535.0)
          (/ (hexrgb-hex-to-int (substring color (+ 1 len len))) 65535.0))))
 
(defun hexrgb-color-name-to-hex (color) "$$"
  (let ((components (x-color-values color)))
    (unless components (error "No such color: %S" color))
    (unless (hexrgb-rgb-hex-string-p color)
      (setq color (hexrgb-color-values-to-hex components))))
  color)
 
(defun hexrgb-color-values-to-hex (values) "$$"
  (concat "#"
          (hexrgb-int-to-hex (nth 0 values) 4)
          (hexrgb-int-to-hex (nth 1 values) 4)
          (hexrgb-int-to-hex (nth 2 values) 4)))
 
(defun hexrgb-hex-to-int (hex) "$$"
  (let* ((factor 1)
         (len (length hex))
         (indx (1- len))
         (int 0))
    (while (>= indx 0)
      (setq int (+ int (* factor (hexrgb-hex-char-to-integer (aref hex indx)))))
      (setq indx (1- indx))
      (setq factor (* 16 factor)))
    int))
 
(defun hexrgb-hex-char-to-integer (character) "$$"
  (if (and (>= character ?0) (<= character ?9))
      (- character ?0)
    (let ((ch (logior character 32)))
      (if (and (>= ch ?a) (<= ch ?f))
   (- ch (- ?a 10))
 (error "Invalid hex digit `%c'" ch)))))
 
(defun hexrgb-int-to-hex (int &optional nb-digits) "$$"
  (setq nb-digits (or nb-digits 4))
  (substring (format (concat "%0" (int-to-string nb-digits) "X") int) (- nb-digits)))
 
(defun hexrgb-approx-equal (x y &optional rfuzz afuzz) "$$"
  (setq rfuzz (or rfuzz 1.0e-8) afuzz (or afuzz (/ rfuzz 10)))
  (< (abs (- x y)) (+ afuzz (* rfuzz (+ (abs x) (abs y))))))
 
(provide 'hexrgb)


reply via email to

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