[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to save custom variable programmatically?

From: Jean Louis
Subject: Re: How to save custom variable programmatically?
Date: Tue, 10 Nov 2020 16:55:23 +0300
User-agent: Mutt/2.0 (3d08634) (2020-11-07)

* Michael Heerdegen <> [2020-11-10 14:33]:
> (you wanted to typw `customize-save-variable' I guess)
> Note that `customize-save-variable' is a function.  Above you pass the
> value of a variable instead of a variable: When a function call is
> interpreted all arguments are evaluated first.  So you need to quote the
> variable name to pass the symbol itself to the function.
> Apart from that I think you could use that function.  But do you also
> want a prompt for a value?

That is right, now it works. Yes, I get it with symbols.

I am researching database handling for Emacs and I find it is good to
have those functions. But functions are not written so much in
functional style. It is more in some mixed style.

For example it would be good to have customize-like options to save
any kind of variables in any file, not just into init.el or .emacs as
such are meant more for configuration.

I am now saving into files and reading from files by using these

(defun string-to-file-force (string file)
  "Prints string into file, matters not if file exists. Returns FILE as file 
    (with-temp-file file
      (insert string))

(defun file-to-string (file)
  "File to string function"
    (insert-file-contents file)

(defun data-to-file (data file)
  "PRIN1 Emacs Lisp DATA to FILE"
    (string-to-file-force (prin1-to-string data) file))

(defun data-from-file (file)
  "Reads and returns Emacs Lisp data from FILE"
    (file-to-string file))))

The above can be used as rudimentary database of entries for various

Let us say for invoicing package I am thinking to use various ways of
storing information:

- storing it in ~/.emacs or ~/.emacs/init.el

- storing it in some other files like ~/.emacs.d/data.el

- storing in real databases, such as GDBM, SQL, etc. This complicates
  it. I am thinking that straight GDBM bindings would be best but is
  not in Emacs.
If there is anyway of storing data from Emacs that is standard I do
not know about it. Welcoming tips.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]