unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* intern and faces
@ 2009-12-02 11:48 harven
  2009-12-02 16:51 ` Drew Adams
       [not found] ` <mailman.12034.1259772781.2239.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 3+ messages in thread
From: harven @ 2009-12-02 11:48 UTC (permalink / raw)
  To: help-gnu-emacs

I have built a small command to colorize a region

(defun put-color (start end color-name)
   (interactive "r\nsColor ? ")
     (let ((my-color (concat "color-" color-name)))
       (unless (facep my-color)
          (set-face-foreground (make-face (intern my-color)) color-name))
       (facemenu-set-face my-color start end)))

But I encounter a problem when trying to spool the result.

Starting with emacs -Q and executing the code above, I switch to another 
buffer, type some text and colorize it with M-x put-color RET brown RET
The result looks fine in the buffer, but when I try to execute
M-x ps-spool-buffer-with-faces, I get the error 

Wrong type argument: listp, "color-brown"

The message was issued by ps-face-attribute-list and the *Postscript* buffer
is empty. I think that the problem comes from my command. If I execute 
(set-face-foreground (make-face 'color-brown) "brown")
instead of my command, everything works.

Where does the error come from ?



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

* RE: intern and faces
  2009-12-02 11:48 intern and faces harven
@ 2009-12-02 16:51 ` Drew Adams
       [not found] ` <mailman.12034.1259772781.2239.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 3+ messages in thread
From: Drew Adams @ 2009-12-02 16:51 UTC (permalink / raw)
  To: 'harven', help-gnu-emacs

> I have built a small command to colorize a region
> 
> (defun put-color (start end color-name)
>    (interactive "r\nsColor ? ")
>      (let ((my-color (concat "color-" color-name)))
>        (unless (facep my-color)
>           (set-face-foreground
>              (make-face (intern my-color)) 
>              color-name))
>        (facemenu-set-face my-color start end)))
> 
> But I encounter a problem when trying to spool the result.
> 
> Starting with emacs -Q and executing the code above, I switch 
> to another buffer, type some text and colorize it with
> M-x put-color RET brown RET The result looks fine in the
> buffer, but when I try to execute
> M-x ps-spool-buffer-with-faces, I get the error 
> 
> Wrong type argument: listp, "color-brown"
> 
> The message was issued by ps-face-attribute-list and the 
> *Postscript* buffer
> is empty. I think that the problem comes from my command. If 
> I execute 
> (set-face-foreground (make-face 'color-brown) "brown")
> instead of my command, everything works.
> 
> Where does the error come from ?

I think the problem is (facemenu-set-face my-color start end). Use `intern' here
also, so that you pass the symbol, not the string.

Emacs used to always require (an internal face structure or) a symbol for its
face operations. Now, some operations let you use the name of that symbol (a
string) instead. Both `facep' and `facemenu-set-face' now respect a string, but
`ps-*' apparently does not. In general, I'd advise using a symbol.

You can see the difference by using `C-u C-x =' with the cursor on your colored
text. It will tell you that the face is "color-brown", not `color-brown'
(symbol). If you use instead (facemenu-set-face (intern my-color) start end), it
will show you the symbol. And I'm guessing that `ps-*' will act OK if it's a
symbol.

You might want to file a bug for `ps-print' for this, but I'm not sure it will
be considered a bug. I just filed doc-string bugs for `facep' and
`facemenu-set-face' - they should explicitly say that the FACE arg can be a
string or symbol.





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

* Re: intern and faces
       [not found] ` <mailman.12034.1259772781.2239.help-gnu-emacs@gnu.org>
@ 2009-12-02 20:22   ` harven
  0 siblings, 0 replies; 3+ messages in thread
From: harven @ 2009-12-02 20:22 UTC (permalink / raw)
  To: help-gnu-emacs

"Drew Adams" <drew.adams@oracle.com> writes:

>> I have built a small command to colorize a region
>> 
>> (defun put-color (start end color-name)
>>    (interactive "r\nsColor ? ")
>>      (let ((my-color (concat "color-" color-name)))
>>        (unless (facep my-color)
>>           (set-face-foreground
>>              (make-face (intern my-color)) 
>>              color-name))
>>        (facemenu-set-face my-color start end)))
>> 
>> But I encounter a problem when trying to spool the result.
>> 
>> Starting with emacs -Q and executing the code above, I switch 
>> to another buffer, type some text and colorize it with
>> M-x put-color RET brown RET The result looks fine in the
>> buffer, but when I try to execute
>> M-x ps-spool-buffer-with-faces, I get the error 
>> 
>> Wrong type argument: listp, "color-brown"
>
> I think the problem is (facemenu-set-face my-color start end). Use `intern' here
> also, so that you pass the symbol, not the string.
>
> Emacs used to always require (an internal face structure or) a symbol for its
> face operations. Now, some operations let you use the name of that symbol (a
> string) instead. Both `facep' and `facemenu-set-face' now respect a string, but
> `ps-*' apparently does not. In general, I'd advise using a symbol.
>
> You can see the difference by using `C-u C-x =' with the cursor on your colored
> text. It will tell you that the face is "color-brown", not `color-brown'
> (symbol). If you use instead (facemenu-set-face (intern my-color) start end), it
> will show you the symbol. And I'm guessing that `ps-*' will act OK if it's a
> symbol.

Yes, you guessed right, that works if I replace my-color by (intern my-color)
in the function facemenu-set-face. I will report it.
Thanks a lot.


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

end of thread, other threads:[~2009-12-02 20:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-02 11:48 intern and faces harven
2009-12-02 16:51 ` Drew Adams
     [not found] ` <mailman.12034.1259772781.2239.help-gnu-emacs@gnu.org>
2009-12-02 20:22   ` harven

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).