unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Setting custom variable values from elisp
@ 2005-01-04 16:20 Lennart Borgman
  2005-01-05  9:06 ` Per Abrahamsen
  0 siblings, 1 reply; 2+ messages in thread
From: Lennart Borgman @ 2005-01-04 16:20 UTC (permalink / raw)
  Cc: drkm

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

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

* Re: Setting custom variable values from elisp
  2005-01-04 16:20 Setting custom variable values from elisp Lennart Borgman
@ 2005-01-05  9:06 ` Per Abrahamsen
  0 siblings, 0 replies; 2+ messages in thread
From: Per Abrahamsen @ 2005-01-05  9:06 UTC (permalink / raw)


"Lennart Borgman" <lennart.borgman.073@student.lu.se> writes:

> Maybe I have overlooked something but I did not find any easy way to set
> custom variables from elisp. 

setq is good.

Depending on what you want to to do, customize-set-value,
customize-set-variable, customize-save-variable,
customize-mark-as-set, customize-mark-to-save, and customize-save-all
could also be useful.

It is really unclear what you want.  

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

end of thread, other threads:[~2005-01-05  9:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-01-04 16:20 Setting custom variable values from elisp Lennart Borgman
2005-01-05  9:06 ` Per Abrahamsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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