From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: how to save a face in Lisp? Date: Wed, 3 Oct 2007 00:41:13 -0700 Message-ID: References: <47031962.7000307@earthlink.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1191397307 28655 80.91.229.12 (3 Oct 2007 07:41:47 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 3 Oct 2007 07:41:47 +0000 (UTC) To: Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Oct 03 09:41:44 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IcyrX-0002v4-Ky for geh-help-gnu-emacs@m.gmane.org; Wed, 03 Oct 2007 09:41:44 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IcyrT-000757-AV for geh-help-gnu-emacs@m.gmane.org; Wed, 03 Oct 2007 03:41:39 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IcyrE-00074w-6B for help-gnu-emacs@gnu.org; Wed, 03 Oct 2007 03:41:24 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IcyrD-00074d-Kw for help-gnu-emacs@gnu.org; Wed, 03 Oct 2007 03:41:23 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IcyrD-00074a-Bi for help-gnu-emacs@gnu.org; Wed, 03 Oct 2007 03:41:23 -0400 Original-Received: from rgminet01.oracle.com ([148.87.113.118]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1IcyrC-0001nr-Rk for help-gnu-emacs@gnu.org; Wed, 03 Oct 2007 03:41:23 -0400 Original-Received: from agmgw1.us.oracle.com (agmgw1.us.oracle.com [152.68.180.212]) by rgminet01.oracle.com (Switch-3.2.4/Switch-3.1.6) with ESMTP id l937fJLC019400 for ; Wed, 3 Oct 2007 01:41:19 -0600 Original-Received: from acsmt350.oracle.com (acsmt350.oracle.com [141.146.40.150]) by agmgw1.us.oracle.com (Switch-3.2.0/Switch-3.2.0) with ESMTP id l92F7Ge6003390 for ; Wed, 3 Oct 2007 01:41:19 -0600 Original-Received: from dhcp-amer-csvpn-gw2-141-144-73-128.vpn.oracle.com by acsmt351.oracle.com with ESMTP id 3263176321191397265; Wed, 03 Oct 2007 00:41:05 -0700 X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) In-Reply-To: <47031962.7000307@earthlink.net> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138 X-Brightmail-Tracker: AAAAAQAAAAI= X-Brightmail-Tracker: AAAAAQAAAAI= X-Whitelist: TRUE X-Whitelist: TRUE X-Detected-Kernel: Linux 2.4-2.6 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:48064 Archived-At: > >>> In Lisp, how can I save a face to the user's custom-file after > >>> it has been changed (or to cause it to be saved when Emacs is quit)? > >> > >> The function custom-set-faces works for me. > > > > It requires the face's SPEC also as input: > > > > "The arguments should be a list where each entry has the form: > > (FACE SPEC [NOW [COMMENT]]) > > SPEC is stored as the saved value for FACE..." > > > > I'm looking for something that takes just the face as arg and > > saves it. IOW, I don't want to define the face; I just want to save it. I could have added that, anyway, `custom-set-face' does not write to the custom-file and save it; `custom-set-face' is just the form that needs to be written to (or updated in) the file. > You don't have to define the face manually. But you have to write Elisp > code to find the current values of the attributes of an existing face, > and write those values to a custom-file which can be read back the next > time you start Emacs. > > Example: If you execute the following in a Lisp-Interaction buffer: > (describe-face 'default) > you will see all the default face's attributes whose *current* values > you have to save to a file: :family, :width, :height, :slant, > :foreground, :background, etc. > > A function to inspect each attribute in turn is called 'face-attribute > So again, for the default face, you can get each value: > (face-attribute 'default :family) > (face-attribute 'default :height) > (face-attribute 'default :background) > > And so on. Get the value of each attribute of the face you're > interested in, and then write those values to a file and you can read > them back in at any time. I want to save an _arbitrary_ existing face with a Lisp function: (defun save-face (face) "Update user's `custom-file' with current definition of FACE." ...) Is there an existing function to do that? If not, how to go about it? What you suggest would save the current attributes of the face. That would be like writing `custom-set-face' with this spec: (list (list t (custom-face-attributes-get face nil))). What I want is to save the face spec as customized by the user (or as defined by defface if never customized), but updated to reflect the face's current attributes (what `custom-face-attributes-get' provides). IOW, just what would be written in the `custom-set-faces' sexp if the face had been modified by the user in Customize and saved by the user in Customize. The function I'm looking for would do what `custom-save-all' does with `custom-save-faces', but for only one face. It would of course update any existing `custom-set-faces' in the custom-file, not add another one (there should be only one). And it would write out the face regardless of whether Customize thought the face had been customized - for example, even if it were changed by `modify-face'. There is function `custom-face-save', but it takes a widget as arg, not a face, and it operates strictly in the context of Customize. Based on its code, I guess I could just put nil as the face's `customized-face' property, put its current definition as its `saved-face' property, and then call `custom-save-all'. IIUC, that is also (analogous to) how `customize-save-variable' works. But how can I get that complete current definition (spec) to use for property `saved-face'? Using `face-user-default-spec' I can get the user's saved definition of the face (or the defface definition if there is no custom definition). And using `face-attr-construct' I can get the face's current global definition (which is only part of a spec, not a complete spec). But how do I merge those two to get a complete defface-style spec that reflects the current attribute values? That is what needs to be written into the `custom-set-faces' sexp, AFAIK. For example, suppose this is the definition of face `foo': (defface foo '((((background dark)) (:foreground "DarkGreen")) (t (:foreground "Red"))) "...") And suppose this has been evaluated, temporarily "customizing" the face outside of Customize: (set-face-attribute 'foo nil :foreground "Yellow") And suppose that the background mode is not `dark'. Then the spec that needs to be written if this face is saved is this: '((((background dark)) (:foreground "DarkGreen")) (t (:foreground "Yellow"))) Getting that updated spec seems to be the stumbling block. (Is there a function that gives that?) The Customize code has that ready to hand, because of its code that handles the face change by the user. (Also, I'd want to add some code to only save the face if it had actually changed. And ideally I'd like something that works also with Emacs 20, which doesn't have function `face-user-default-spec'.) The custom code is difficult for me to follow (widgetry leaves me numb), and this all seems terribly complicated. For a user variable, it's simple: just call `customize-save-variable'. Why is there no `customize-save-face'? Of course, for `customize-save-variable' too you need to pass the variable's value to save, and the hard part for the face seems to be getting a complete updated spec for it.