all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Michael Heerdegen <michael_heerdegen@web.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: How to save custom variable programmatically?
Date: Tue, 10 Nov 2020 16:55:23 +0300	[thread overview]
Message-ID: <X6qbyyz+DqJ8IGC5@protected.rcdrun.com> (raw)
In-Reply-To: <87blg5e9re.fsf@web.de>

* Michael Heerdegen <michael_heerdegen@web.de> [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
functions:

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

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

(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"
  (car
   (read-from-string
    (file-to-string file))))

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

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	other threads:[~2020-11-10 13:55 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-10  7:51 How to save custom variable programmatically? Jean Louis
2020-11-10 10:43 ` Robert Pluim
2020-11-10 13:42   ` Jean Louis
2020-11-10 11:23 ` Michael Heerdegen
2020-11-10 13:55   ` Jean Louis [this message]
2020-11-10 14:36     ` Michael Heerdegen
2020-11-10 19:19       ` Jean Louis
2020-11-10 20:42         ` Marcin Borkowski
2020-11-10 21:46           ` Jean Louis
2020-11-11 21:20             ` Marcin Borkowski
2020-11-10 20:43         ` Michael Heerdegen
2020-11-10 21:52           ` Jean Louis
2020-11-11 18:00             ` Michael Heerdegen
2020-11-11 18:05               ` Jean Louis
2020-11-17 12:24             ` Michael Heerdegen
2020-11-17 15:07               ` Jean Louis
2020-11-10 21:15         ` Michael Heerdegen
2020-11-10 21:55           ` Jean Louis
2020-11-11 10:55             ` Michael Heerdegen
2020-11-17 15:44           ` Jean Louis
2020-11-17 16:38             ` Michael Heerdegen
2020-11-17 21:30               ` Stefan Monnier
2020-11-10 16:24 ` Drew Adams
2020-11-10 19:23   ` Jean Louis

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=X6qbyyz+DqJ8IGC5@protected.rcdrun.com \
    --to=bugs@gnu.support \
    --cc=help-gnu-emacs@gnu.org \
    --cc=michael_heerdegen@web.de \
    /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.