all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Lennart Borgman" <lennart.borgman.073@student.lu.se>
Cc: drkm <darkman_spam@yahoo.fr>
Subject: Setting custom variable values from elisp
Date: Tue, 4 Jan 2005 17:20:50 +0100	[thread overview]
Message-ID: <001601c4f279$63b753a0$0200a8c0@sedrcw11488> (raw)

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

             reply	other threads:[~2005-01-04 16:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-04 16:20 Lennart Borgman [this message]
2005-01-05  9:06 ` Setting custom variable values from elisp Per Abrahamsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='001601c4f279$63b753a0$0200a8c0@sedrcw11488' \
    --to=lennart.borgman.073@student.lu.se \
    --cc=darkman_spam@yahoo.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.