Subject: Re: bug#17956: 24.3.92; Calling highlight-regexp non-interactively causes errors from face-name

From: Juri Linkov <[email-masked]>
Date: Mon, 07 Jul 2014 02:38:18 +0300

> M-: (highlight-regexp "1" "hi-green")
> [...]
> The following error is encountered:
> face-name: Wrong type argument: symbolp, "hi-green"

The reason why `highlight-regexp' fails is because
`face-name' rejects non-symbol faces whereas `facep'
accepts them.  This contradiction might cause similar
bugs in other places that naively expect a face always
to be a symbol.  For instance, grepping for `face-name'
shows such code as in `x-resolve-font-name'

  (or (symbolp face)
      (setq face (face-name face)))

that didn't fail only because was never called with
a non-nil non-symbol `face'.

So it would be safer not to assume that a face can be only a symbol:

=== modified file 'lisp/faces.el'
--- lisp/faces.el	2014-04-30 18:01:36 +0000
+++ lisp/faces.el	2014-07-06 23:38:01 +0000
@@ -359,7 +359,10 @@ (defun make-face-x-resource-internal (fa
 
 (defun face-name (face)
   "Return the name of face FACE."
-  (symbol-name (check-face face)))
+  (check-face face)
+  (if (symbolp face)
+      (symbol-name face)
+    face))

 (defun face-all-attributes (face &optional frame)
@@ -2731,8 +2734,8 @@ (defun x-resolve-font-name (pattern &opt
 contains wildcards.
 Given optional arguments FACE and FRAME, return a font which is
 also the same size as FACE on FRAME, or fail."
-  (or (symbolp face)
-      (setq face (face-name face)))
+  (when face
+    (setq face (face-name face)))
   (and (eq frame t)
        (setq frame nil))
   (if pattern