I am writing a function to get the foreground color of the face at point and am thinking that Emacs may already provide a better method than the one I'm composing?
I am going to be using this function about 50 times every redisplay
(i.e., once for every visible horizontal line, going down a column vertically from window-start
to window-end
), so I want it to be as efficient as possible.
With the proposed function get-face
, I would use: (when (eq (car (text-properties-at (point))) 'face) (nth 23 (get-face (nth 1 (text-properties-at (point))))))
.
I'm not certain under what circumstances more than one face will exist, or whether the car
of text-properties-at
will always contain the symbol face
if a face is present?
I still have not dealt with handling an inherit
situation.
(defun get-face (face)
"Doc-string."
(let* (
(attributes (face-all-attributes face (selected-frame)))
(family-car (car (nth 0 attributes)))
(family-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 0 attributes))))
"Courier"
(cdr (nth 0 attributes))))
(foundry-car (car (nth 1 attributes)))
(foundry-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 1 attributes))))
nil
(cdr (nth 1 attributes))))
(width-car (car (nth 2 attributes)))
(width-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 2 attributes))))
'normal
(cdr (nth 2 attributes))))
(height-car (car (nth 3 attributes)))
(height-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 3 attributes))))
180
(cdr (nth 3 attributes))))
(weight-car (car (nth 4 attributes)))
(weight-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 4 attributes))))
'normal
(cdr (nth 4 attributes))))
(slant-car (car (nth 5 attributes)))
(slant-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 5 attributes))))
'normal
(cdr (nth 5 attributes))))
(underline-car (car (nth 6 attributes)))
(underline-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 6 attributes))))
nil
(cdr (nth 6 attributes))))
(overline-car (car (nth 7 attributes)))
(overline-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 7 attributes))))
nil
(cdr (nth 7 attributes))))
(strike-through-car (car (nth 8 attributes)))
(strike-through-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 8 attributes))))
nil
(cdr (nth 8 attributes))))
(box-car (car (nth 9 attributes)))
(box-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 9 attributes))))
nil
(cdr (nth 9 attributes))))
(inverse-video-car (car (nth 10 attributes)))
(inverse-video-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 10 attributes))))
nil
(cdr (nth 10 attributes))))
(foreground-car (car (nth 11 attributes)))
(foreground-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 11 attributes))))
'unspecified
(cdr (nth 11 attributes))))
(background-car (car (nth 12 attributes)))
(background-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 12 attributes))))
'unspecified
(cdr (nth 12 attributes))))
(stipple-car (car (nth 13 attributes)))
(stipple-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 13 attributes))))
nil
(cdr (nth 13 attributes))))
(inherit-car (car (nth 14 attributes)))
(inherit-cdr
(if (equal "unspecified" (format "%s" (cdr (nth 14 attributes))))
nil
(cdr (nth 14 attributes)))))
(list
family-car family-cdr
foundry-car foundry-cdr
width-car width-cdr
height-car height-cdr
weight-car weight-cdr
slant-car slant-cdr
underline-car underline-cdr
overline-car overline-cdr
strike-through-car strike-through-cdr
box-car box-cdr
inverse-video-car inverse-video-cdr
foreground-car foreground-cdr
background-car background-cdr
stipple-car stipple-cdr
inherit-car inherit-cdr)))
fg
(i.e., the name) to be reset and instead becomet
rather than the foreground name:(fg (and fg (not (member fg '("unspecified-fg" "unspecified-bg")))))
This would likely occur with the other similar function too -- i.e.,eyedrop-background-at-point
. – lawlist May 09 '15 at 20:36and
were reversed. – Drew May 09 '15 at 20:47