From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Lennart Borgman" Newsgroups: gmane.emacs.devel Subject: Setting custom variable values from elisp Date: Tue, 4 Jan 2005 17:20:50 +0100 Message-ID: <001601c4f279$63b753a0$0200a8c0@sedrcw11488> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1104855790 15217 80.91.229.6 (4 Jan 2005 16:23:10 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 4 Jan 2005 16:23:10 +0000 (UTC) Cc: drkm Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jan 04 17:23:00 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1ClrSU-0007MB-00 for ; Tue, 04 Jan 2005 17:22:59 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Clrdh-0006DX-QC for ged-emacs-devel@m.gmane.org; Tue, 04 Jan 2005 11:34:33 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1Clrda-0006By-Ov for emacs-devel@gnu.org; Tue, 04 Jan 2005 11:34:26 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1ClrdZ-0006B9-J4 for emacs-devel@gnu.org; Tue, 04 Jan 2005 11:34:25 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1ClrdZ-0006B6-GE for emacs-devel@gnu.org; Tue, 04 Jan 2005 11:34:25 -0500 Original-Received: from [81.228.9.108] (helo=av2-2-sn3.vrr.skanova.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1ClrQy-0003Cv-9n for emacs-devel@gnu.org; Tue, 04 Jan 2005 11:21:24 -0500 Original-Received: by av2-2-sn3.vrr.skanova.net (Postfix, from userid 502) id 8E0C237ED1; Tue, 4 Jan 2005 17:21:23 +0100 (CET) Original-Received: from smtp1-1-sn3.vrr.skanova.net (smtp1-1-sn3.vrr.skanova.net [81.228.9.177]) by av2-2-sn3.vrr.skanova.net (Postfix) with ESMTP id 80EAC37EA8; Tue, 4 Jan 2005 17:21:23 +0100 (CET) Original-Received: from sedrcw11488 (t1o58p52.telia.com [62.20.164.52]) by smtp1-1-sn3.vrr.skanova.net (Postfix) with SMTP id E0CEF38019; Tue, 4 Jan 2005 17:21:21 +0100 (CET) Original-To: "Emacs Devel" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1409 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:31829 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:31829 Maybe I have overlooked something but I did not find any easy way to set custom variables from elisp. I therefore wrote the three functions below which I believe can be used for that. Do they seem correct? Is this the way to divide it? Could they be part of the custom package? I use these functions in the setup for w32 to make it possible to 1) Set a bunch of values from a customize like page 2) Fetch values into Emacs - Lennart (defun setup-helper-set-as-custom(symbol) "Set SYMBOL the same way `custom-set-variables' should do." (let* ((value (car (get symbol 'saved-value))) (now (get symbol 'force-value)) (requests (get symbol 'custom-requests)) (comment (get symbol 'comment)) (cuslist (list value symbol))) (when (or now requests comment) (setq cuslist (cons now cuslist))) (when (or requests comment) (setq cuslist (cons requests cuslist))) (when comment (setq cuslist (cons comment cuslist))) (setq cuslist (reverse cuslist)) (custom-set-variables cuslist) ;;(message "%s" cuslist) )) (defun setup-helper-add-custom(symbol value &optional now requests comment) "Sets the custom properties of SYMBOL. For an explanation of VALUE, NOW, REQUESTS and COMMENT see `custom-set-variables'. If COMMENT is nil a comment is added by this function. The current value of SYMBOL is not set. To set the value use `setup-helper-set-as-custom'. If you call `custom-save-all' SYMBOL will be saved to the `custom-set-variables' entry." (put symbol 'saved-value (list value)) (put symbol 'custom-requests (list requests)) (put symbol 'force-value now) (unless comment (setq comment "Added by setup-helper")) (put symbol 'saved-variable-comment comment)) ;; Use these lines to test: ;;(setup-helper-add-custom 'aaa "test" nil) ;;(setup-helper-set-as-custom 'aaa) ;;(defvar aaa nil) ;;(setup-helper-set-as-custom 'aaa) ;; This is riped from cus-edit.el customize-option, Emacs 21.3.1 (defun setup-helper-customizeable (symbol) "Return t if SYMBOL can be customized, nil otherwise." (interactive (custom-variable-prompt)) ;; If we don't have SYMBOL's real definition loaded, ;; try to load it. (unless (get symbol 'custom-type) (let ((loaddefs-file (locate-library "loaddefs.el" t)) file) ;; See if it is autoloaded from some library. (when loaddefs-file (with-temp-buffer (insert-file-contents loaddefs-file) (when (re-search-forward (concat "^(defvar " (symbol-name symbol)) nil t) (search-backward "\n;;; Generated autoloads from ") (goto-char (match-end 0)) (setq file (buffer-substring (point) (progn (end-of-line) (point))))))) ;; If it is, load that library. (when file (when (string-match "\\.el\\'" file) (setq file (substring file 0 (match-beginning 0)))) (load file)))) (if (get symbol 'custom-type) t nil))