* How to save custom variable programmatically?
@ 2020-11-10 7:51 Jean Louis
2020-11-10 10:43 ` Robert Pluim
` (2 more replies)
0 siblings, 3 replies; 24+ messages in thread
From: Jean Louis @ 2020-11-10 7:51 UTC (permalink / raw)
To: GNU Emacs Help
I would like to use custom variables in such way to ask user
pragmatically, not through customize interface, to change a
variable. This could be for example user's location.
Upon changing it, I would like programatically to save it for future.
Should I use below function? Or maybe something else is recommended?
(defun customize-save-variable (variable value &optional comment)
This way it is not working:
(require 'cus-edit)
(customize-save hyperscope-default-server "localhost")
Any good way?
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
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 16:24 ` Drew Adams
2 siblings, 1 reply; 24+ messages in thread
From: Robert Pluim @ 2020-11-10 10:43 UTC (permalink / raw)
To: Jean Louis; +Cc: GNU Emacs Help
Jean Louis <bugs@gnu.support> writes:
> I would like to use custom variables in such way to ask user
> pragmatically, not through customize interface, to change a
> variable. This could be for example user's location.
>
> Upon changing it, I would like programatically to save it for future.
>
> Should I use below function? Or maybe something else is recommended?
>
> (defun customize-save-variable (variable value &optional comment)
>
Thatʼs what lots of code in Emacs uses.
> This way it is not working:
>
> (require 'cus-edit)
> (customize-save hyperscope-default-server "localhost")
What's not working apart from the fact that customize-save doesnʼt
exist? Or did you mean
(customize-save-variable 'hyperscope-default-server "localhost")
Robert
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 7:51 How to save custom variable programmatically? Jean Louis
2020-11-10 10:43 ` Robert Pluim
@ 2020-11-10 11:23 ` Michael Heerdegen
2020-11-10 13:55 ` Jean Louis
2020-11-10 16:24 ` Drew Adams
2 siblings, 1 reply; 24+ messages in thread
From: Michael Heerdegen @ 2020-11-10 11:23 UTC (permalink / raw)
To: help-gnu-emacs
Jean Louis <bugs@gnu.support> writes:
> I would like to use custom variables in such way to ask user
> pragmatically, not through customize interface, to change a
> variable. This could be for example user's location.
>
> Upon changing it, I would like programatically to save it for future.
>
> Should I use below function? Or maybe something else is recommended?
>
> (defun customize-save-variable (variable value &optional comment)
>
> This way it is not working:
>
> (require 'cus-edit)
> (customize-save hyperscope-default-server "localhost")
(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?
Michael.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 10:43 ` Robert Pluim
@ 2020-11-10 13:42 ` Jean Louis
0 siblings, 0 replies; 24+ messages in thread
From: Jean Louis @ 2020-11-10 13:42 UTC (permalink / raw)
To: Robert Pluim; +Cc: GNU Emacs Help
* Robert Pluim <rpluim@gmail.com> [2020-11-10 13:44]:
> Jean Louis <bugs@gnu.support> writes:
>
> > I would like to use custom variables in such way to ask user
> > pragmatically, not through customize interface, to change a
> > variable. This could be for example user's location.
> >
> > Upon changing it, I would like programatically to save it for future.
> >
> > Should I use below function? Or maybe something else is recommended?
> >
> > (defun customize-save-variable (variable value &optional comment)
> >
>
> Thatʼs what lots of code in Emacs uses.
>
> > This way it is not working:
> >
> > (require 'cus-edit)
> > (customize-save hyperscope-default-server "localhost")
>
> What's not working apart from the fact that customize-save doesnʼt
> exist? Or did you mean
>
> (customize-save-variable 'hyperscope-default-server "localhost")
Oh that works! Thank you.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 11:23 ` Michael Heerdegen
@ 2020-11-10 13:55 ` Jean Louis
2020-11-10 14:36 ` Michael Heerdegen
0 siblings, 1 reply; 24+ messages in thread
From: Jean Louis @ 2020-11-10 13:55 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
* 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.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 13:55 ` Jean Louis
@ 2020-11-10 14:36 ` Michael Heerdegen
2020-11-10 19:19 ` Jean Louis
0 siblings, 1 reply; 24+ messages in thread
From: Michael Heerdegen @ 2020-11-10 14:36 UTC (permalink / raw)
To: help-gnu-emacs
Jean Louis <bugs@gnu.support> writes:
> If there is anyway of storing data from Emacs that is standard I do
> not know about it. Welcoming tips.
The eieio-persistent class is made for that purpose.
You make your data/database/whatever an object of a class you define as
you like, and make that class inherit from eieio-persistent. Then your
data is savable out of the box.
(info "(eieio) eieio-persistent")
Do you need an example?
Michael.
^ permalink raw reply [flat|nested] 24+ messages in thread
* RE: How to save custom variable programmatically?
2020-11-10 7:51 How to save custom variable programmatically? Jean Louis
2020-11-10 10:43 ` Robert Pluim
2020-11-10 11:23 ` Michael Heerdegen
@ 2020-11-10 16:24 ` Drew Adams
2020-11-10 19:23 ` Jean Louis
2 siblings, 1 reply; 24+ messages in thread
From: Drew Adams @ 2020-11-10 16:24 UTC (permalink / raw)
To: Jean Louis, GNU Emacs Help
> I would like to use custom variables in such way to ask user
> pragmatically, not through customize interface, to change a
> variable. This could be for example user's location.
>
> Upon changing it, I would like programatically to save it for future.
>
> Should I use below function? Or maybe something else is recommended?
>
> (defun customize-save-variable (variable value &optional comment)
>
> This way it is not working:
>
> (require 'cus-edit)
> (customize-save hyperscope-default-server "localhost")
>
> Any good way?
Michael has given the answer: `customize-save-variable'.
___
This page has more on the topic of Customize and saving,
if you're interested. (Just one opinion.)
https://www.emacswiki.org/emacs/CustomizingAndSaving
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 14:36 ` Michael Heerdegen
@ 2020-11-10 19:19 ` Jean Louis
2020-11-10 20:42 ` Marcin Borkowski
` (2 more replies)
0 siblings, 3 replies; 24+ messages in thread
From: Jean Louis @ 2020-11-10 19:19 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
* Michael Heerdegen <michael_heerdegen@web.de> [2020-11-10 17:36]:
> Jean Louis <bugs@gnu.support> writes:
>
> > If there is anyway of storing data from Emacs that is standard I do
> > not know about it. Welcoming tips.
>
> The eieio-persistent class is made for that purpose.
>
> You make your data/database/whatever an object of a class you define as
> you like, and make that class inherit from eieio-persistent. Then your
> data is savable out of the box.
>
> (info "(eieio) eieio-persistent")
>
> Do you need an example?
Thank you. If you have ready simplest example it may be useful for
review.
My strategy is to minimize number of packages used as dependencies so
I try to use what is built in or to re-use what is inside of Emacs.
For simplest database with hundreds of entries file locking and Lisp
data can be enough.
For larger database I would prefer GDBM bindings built-in, but life is
not a dream.
Personally I am using PostgreSQL. Then I just define the table
definition and that may be similar to eieio.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 16:24 ` Drew Adams
@ 2020-11-10 19:23 ` Jean Louis
0 siblings, 0 replies; 24+ messages in thread
From: Jean Louis @ 2020-11-10 19:23 UTC (permalink / raw)
To: Drew Adams; +Cc: GNU Emacs Help
* Drew Adams <drew.adams@oracle.com> [2020-11-10 19:25]:
> > I would like to use custom variables in such way to ask user
> > pragmatically, not through customize interface, to change a
> > variable. This could be for example user's location.
> >
> > Upon changing it, I would like programatically to save it for future.
> >
> > Should I use below function? Or maybe something else is recommended?
> >
> > (defun customize-save-variable (variable value &optional comment)
> >
> > This way it is not working:
> >
> > (require 'cus-edit)
> > (customize-save hyperscope-default-server "localhost")
> >
> > Any good way?
>
> Michael has given the answer: `customize-save-variable'.
> ___
>
> This page has more on the topic of Customize and saving,
> if you're interested. (Just one opinion.)
>
> https://www.emacswiki.org/emacs/CustomizingAndSaving
Thank you for reference. I was looking into it for reason to enable
those functions to save to other files. Instead customization of Emacs
to use it to save any variables like a simple database in different
files.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 19:19 ` Jean Louis
@ 2020-11-10 20:42 ` Marcin Borkowski
2020-11-10 21:46 ` Jean Louis
2020-11-10 20:43 ` Michael Heerdegen
2020-11-10 21:15 ` Michael Heerdegen
2 siblings, 1 reply; 24+ messages in thread
From: Marcin Borkowski @ 2020-11-10 20:42 UTC (permalink / raw)
To: Jean Louis; +Cc: Michael Heerdegen, help-gnu-emacs
On 2020-11-10, at 20:19, Jean Louis <bugs@gnu.support> wrote:
> * Michael Heerdegen <michael_heerdegen@web.de> [2020-11-10 17:36]:
>> Jean Louis <bugs@gnu.support> writes:
>>
>> > If there is anyway of storing data from Emacs that is standard I do
>> > not know about it. Welcoming tips.
>>
>> The eieio-persistent class is made for that purpose.
>>
>> You make your data/database/whatever an object of a class you define as
>> you like, and make that class inherit from eieio-persistent. Then your
>> data is savable out of the box.
>>
>> (info "(eieio) eieio-persistent")
>>
>> Do you need an example?
>
> Thank you. If you have ready simplest example it may be useful for
> review.
>
> My strategy is to minimize number of packages used as dependencies so
> I try to use what is built in or to re-use what is inside of Emacs.
You might get inspired by an old post of mine here:
http://mbork.pl/2018-09-10_Persisting_Emacs_variables
Best,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 19:19 ` Jean Louis
2020-11-10 20:42 ` Marcin Borkowski
@ 2020-11-10 20:43 ` Michael Heerdegen
2020-11-10 21:52 ` Jean Louis
2020-11-10 21:15 ` Michael Heerdegen
2 siblings, 1 reply; 24+ messages in thread
From: Michael Heerdegen @ 2020-11-10 20:43 UTC (permalink / raw)
To: help-gnu-emacs
Jean Louis <bugs@gnu.support> writes:
> My strategy is to minimize number of packages used as dependencies so
> I try to use what is built in or to re-use what is inside of Emacs.
Eieio is part of Emacs. The Gnus registry is saved using
eieio-persistent.
This class is relatively new and was a bit buggy in the past, though.
In new Emacs versions it works reliably AFAICT.
> Personally I am using PostgreSQL. Then I just define the table
> definition and that may be similar to eieio.
Might also be interesting.
The Eieio approach has the advantage that (an) Emacs Lisp (object) is
saved as (an) Emacs Lisp (expression). It is slow, however.
Michael.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 19:19 ` Jean Louis
2020-11-10 20:42 ` Marcin Borkowski
2020-11-10 20:43 ` Michael Heerdegen
@ 2020-11-10 21:15 ` Michael Heerdegen
2020-11-10 21:55 ` Jean Louis
2020-11-17 15:44 ` Jean Louis
2 siblings, 2 replies; 24+ messages in thread
From: Michael Heerdegen @ 2020-11-10 21:15 UTC (permalink / raw)
To: help-gnu-emacs
Jean Louis <bugs@gnu.support> writes:
> Thank you. If you have ready simplest example it may be useful for
> review.
Simplest? Ok, that might be possible. Let's make a wrapper holding a
single value that is savable:
#+begin_src emacs-lisp
(defclass my-persistent (eieio-persistent)
((data :initarg :data)))
(defun my-save-in-location (thing file)
(let ((obj (my-persistent :data thing)))
(setf (oref obj file) file)
(eieio-persistent-save obj)))
;; save a value to a file:
(my-save-in-location (list 'x [] "Hello")
(expand-file-name "~/test"))
;; get it back:
(oref (eieio-persistent-read
(expand-file-name "~/test")
'my-persistent)
:data)
;; ==> (x [] "Hello")
#+end_src
This is not only a nice abstraction. eieio-persistent has some
(programmable) knowledge about how to print and "restore" objects where
a normal print+read cycle would not work.
Michael.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 20:42 ` Marcin Borkowski
@ 2020-11-10 21:46 ` Jean Louis
2020-11-11 21:20 ` Marcin Borkowski
0 siblings, 1 reply; 24+ messages in thread
From: Jean Louis @ 2020-11-10 21:46 UTC (permalink / raw)
To: Marcin Borkowski; +Cc: Michael Heerdegen, help-gnu-emacs
* Marcin Borkowski <mbork@mbork.pl> [2020-11-10 23:42]:
>
> On 2020-11-10, at 20:19, Jean Louis <bugs@gnu.support> wrote:
>
> > * Michael Heerdegen <michael_heerdegen@web.de> [2020-11-10 17:36]:
> >> Jean Louis <bugs@gnu.support> writes:
> >>
> >> > If there is anyway of storing data from Emacs that is standard I do
> >> > not know about it. Welcoming tips.
> >>
> >> The eieio-persistent class is made for that purpose.
> >>
> >> You make your data/database/whatever an object of a class you define as
> >> you like, and make that class inherit from eieio-persistent. Then your
> >> data is savable out of the box.
> >>
> >> (info "(eieio) eieio-persistent")
> >>
> >> Do you need an example?
> >
> > Thank you. If you have ready simplest example it may be useful for
> > review.
> >
> > My strategy is to minimize number of packages used as dependencies so
> > I try to use what is built in or to re-use what is inside of Emacs.
>
> You might get inspired by an old post of mine here:
> http://mbork.pl/2018-09-10_Persisting_Emacs_variables
Nice post and Wiki. Reference taken. I can read the flow somehow. You
watching in the file by trying to read ^(setq if variable exists, if I
get it well. It relies on personal use case and common usage of
setq. What if variable is b that is set with:
(set (quote b) 1)
or
(setq a 1 b 2)
or
(setq a 1
b 2
c 3)
or
(setf b 1)
For me personally I save major information in the database. But to
make simpler package for users to do one thing do well I like to find
solutions that is preferrably built-in and well proven.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 20:43 ` Michael Heerdegen
@ 2020-11-10 21:52 ` Jean Louis
2020-11-11 18:00 ` Michael Heerdegen
2020-11-17 12:24 ` Michael Heerdegen
0 siblings, 2 replies; 24+ messages in thread
From: Jean Louis @ 2020-11-10 21:52 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
* Michael Heerdegen <michael_heerdegen@web.de> [2020-11-10 23:44]:
> Jean Louis <bugs@gnu.support> writes:
>
> > My strategy is to minimize number of packages used as dependencies so
> > I try to use what is built in or to re-use what is inside of
> > Emacs.
Thank you, I see it now. It is similar to CLOS. Which I never well
understood, maybe in future.
> The Eieio approach has the advantage that (an) Emacs Lisp (object) is
> saved as (an) Emacs Lisp (expression). It is slow, however.
Do you have example for:
- client's name (to be key for below)
- address line 1
- address line 2
- address line 3
- postal code
- city
- country
- phone
- fax
- mobile
- email
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
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
1 sibling, 1 reply; 24+ messages in thread
From: Jean Louis @ 2020-11-10 21:55 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
* Michael Heerdegen <michael_heerdegen@web.de> [2020-11-11 00:17]:
> Jean Louis <bugs@gnu.support> writes:
>
> > Thank you. If you have ready simplest example it may be useful for
> > review.
>
> Simplest? Ok, that might be possible. Let's make a wrapper holding a
> single value that is savable:
>
#+begin_src emacs-lisp
(defclass my-persistent (eieio-persistent)
((data :initarg :data)))
I got:
eieio-defclass-internal: Given parent class eieio-persistent is not a
classInvalid face reference: mail-double-quoted-text-face (this last
one is maybe not related)
I understand it works on your side, not yet on mine, I wish to
understand it.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 21:55 ` Jean Louis
@ 2020-11-11 10:55 ` Michael Heerdegen
0 siblings, 0 replies; 24+ messages in thread
From: Michael Heerdegen @ 2020-11-11 10:55 UTC (permalink / raw)
To: help-gnu-emacs
Jean Louis <bugs@gnu.support> writes:
> #+begin_src emacs-lisp
> (defclass my-persistent (eieio-persistent)
> ((data :initarg :data)))
>
> I got:
>
> eieio-defclass-internal: Given parent class eieio-persistent is not a
> class
Sorry, I didn't check what you should `require'. I also didn't check
now, but with the following the definition works for me in emacs -Q:
(require 'eieio)
(require 'eieio-base)
Michael.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
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
1 sibling, 1 reply; 24+ messages in thread
From: Michael Heerdegen @ 2020-11-11 18:00 UTC (permalink / raw)
To: help-gnu-emacs
Jean Louis <bugs@gnu.support> writes:
> Do you have example for:
>
> - client's name (to be key for below)
> - address line 1
> - address line 2
> - address line 3
> - postal code
> - city
> - country
> - phone
> - fax
> - mobile
> - email
Hey! - I finally recognize fishing emails when I see them!
Ok, jokes aside, but isn't
(info "(eieio) Quick Start")
giving an example just like that?
Then all you have to do is to collect your records (your objects) in a
data structure, e.g. a hash table (with names as the keys), which is an
object of a class similar to what I had posted, simply inheriting from
eieio-persistent, and that's it.
HTH,
Michael.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-11 18:00 ` Michael Heerdegen
@ 2020-11-11 18:05 ` Jean Louis
0 siblings, 0 replies; 24+ messages in thread
From: Jean Louis @ 2020-11-11 18:05 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
* Michael Heerdegen <michael_heerdegen@web.de> [2020-11-11 21:01]:
> Jean Louis <bugs@gnu.support> writes:
>
> > Do you have example for:
> >
> > - client's name (to be key for below)
> > - address line 1
> > - address line 2
> > - address line 3
> > - postal code
> > - city
> > - country
> > - phone
> > - fax
> > - mobile
> > - email
>
> Hey! - I finally recognize fishing emails when I see them!
>
> Ok, jokes aside, but isn't
>
> (info "(eieio) Quick Start")
>
> giving an example just like that?
>
> Then all you have to do is to collect your records (your objects) in a
> data structure, e.g. a hash table (with names as the keys), which is an
> object of a class similar to what I had posted, simply inheriting from
> eieio-persistent, and that's it.
Thank you for reference, I will come to that.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 21:46 ` Jean Louis
@ 2020-11-11 21:20 ` Marcin Borkowski
0 siblings, 0 replies; 24+ messages in thread
From: Marcin Borkowski @ 2020-11-11 21:20 UTC (permalink / raw)
To: Jean Louis; +Cc: Michael Heerdegen, help-gnu-emacs
On 2020-11-10, at 22:46, Jean Louis <bugs@gnu.support> wrote:
> * Marcin Borkowski <mbork@mbork.pl> [2020-11-10 23:42]:
>>
>> On 2020-11-10, at 20:19, Jean Louis <bugs@gnu.support> wrote:
>>
>> > * Michael Heerdegen <michael_heerdegen@web.de> [2020-11-10 17:36]:
>> >> Jean Louis <bugs@gnu.support> writes:
>> >>
>> >> > If there is anyway of storing data from Emacs that is standard I do
>> >> > not know about it. Welcoming tips.
>> >>
>> >> The eieio-persistent class is made for that purpose.
>> >>
>> >> You make your data/database/whatever an object of a class you define as
>> >> you like, and make that class inherit from eieio-persistent. Then your
>> >> data is savable out of the box.
>> >>
>> >> (info "(eieio) eieio-persistent")
>> >>
>> >> Do you need an example?
>> >
>> > Thank you. If you have ready simplest example it may be useful for
>> > review.
>> >
>> > My strategy is to minimize number of packages used as dependencies so
>> > I try to use what is built in or to re-use what is inside of Emacs.
>>
>> You might get inspired by an old post of mine here:
>> http://mbork.pl/2018-09-10_Persisting_Emacs_variables
>
> Nice post and Wiki. Reference taken. I can read the flow somehow. You
> watching in the file by trying to read ^(setq if variable exists, if I
> get it well. It relies on personal use case and common usage of
> setq. What if variable is b that is set with:
>
> (set (quote b) 1)
>
> or
>
> (setq a 1 b 2)
>
> or
>
> (setq a 1
> b 2
> c 3)
>
> or
>
> (setf b 1)
Well, it won't work;-). The idea is, though, that this line is put in
init.el automatically and not tampered manually.
Best,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 21:52 ` Jean Louis
2020-11-11 18:00 ` Michael Heerdegen
@ 2020-11-17 12:24 ` Michael Heerdegen
2020-11-17 15:07 ` Jean Louis
1 sibling, 1 reply; 24+ messages in thread
From: Michael Heerdegen @ 2020-11-17 12:24 UTC (permalink / raw)
To: Jean Louis; +Cc: help-gnu-emacs
Jean Louis <bugs@gnu.support> writes:
> Do you have example for:
>
> - client's name (to be key for below)
> - address line 1
> - address line 2
> - address line 3
> - postal code
> - city
> - country
> - phone
> - fax
> - mobile
> - email
BTW, if you actually happen to want to have a database of contacts, I
have to add that there are special solutions for that task of course:
BBDB, its successor EDBD, and org-contacts (I currently use the first
one; there may be more).
Michael.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-17 12:24 ` Michael Heerdegen
@ 2020-11-17 15:07 ` Jean Louis
0 siblings, 0 replies; 24+ messages in thread
From: Jean Louis @ 2020-11-17 15:07 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
* Michael Heerdegen <michael_heerdegen@web.de> [2020-11-17 15:24]:
> Jean Louis <bugs@gnu.support> writes:
>
> > Do you have example for:
> >
> > - client's name (to be key for below)
> > - address line 1
> > - address line 2
> > - address line 3
> > - postal code
> > - city
> > - country
> > - phone
> > - fax
> > - mobile
> > - email
>
> BTW, if you actually happen to want to have a database of contacts, I
> have to add that there are special solutions for that task of course:
> BBDB, its successor EDBD, and org-contacts (I currently use the first
> one; there may be more).
Question for the structure is meant for packages that produce invoices
and quotations for customers where user does not need any outside
package or anything more sophisticated. Just entering few tables, few
items or articles or goods, pricing and creating invoice.
For contacts management I will have new package for GNU ELPA, it will
come. I am using it since quite some time for me and it comes from CRM
or Customer Relationship Management database and different web GUI.
GeDaFe - PostgreSQL Generic Database Interface
==============================================
Hyperlink: http://gedafe.github.io/doc/gedafe-sql.en.html
Gedafe is a generic web front-end to PostgreSQL. Generic means in this
context that Gedafe does not know anything about the structure or
contents of the database it is presenting.
Over many years using Gedafe interface I have developed many various
PostgreSQL tables for various use cases. Let us say for mapping lands
and generation of maps or for planning, invoices, etc.
Contacts are of course included together with various accounts and
integrations that is way complex than BBDB. For me personally I have
contacts management that satisfied all personal needs (not public
need).
For a package to create invoices and to be very simple as Emacs is
simple for the user, I am looking how to structure data and save it
for the user.
I think that packages should support various databases:
1. Emacs based databases should be simplest
2. GDBM database, I hope to sponsor dynamic module for GDBM soon,
3. PostgreSQL, dynamic module already exists
For the option 3. I have the solution and `emacs-libpq` will come soon
to GNU ELPA: https://github.com/anse1/emacs-libpq.git
For option 1. I look for solution to make it simple for those users
who do not have many clients and do not need sophisticated database in
background.
Option 3. with GDBM will come in future and I hope it will enhance
Emacs as programming interface to databases.
So structure with EIEIO will serve for option 1.
Jean
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-10 21:15 ` Michael Heerdegen
2020-11-10 21:55 ` Jean Louis
@ 2020-11-17 15:44 ` Jean Louis
2020-11-17 16:38 ` Michael Heerdegen
1 sibling, 1 reply; 24+ messages in thread
From: Jean Louis @ 2020-11-17 15:44 UTC (permalink / raw)
To: Michael Heerdegen; +Cc: help-gnu-emacs
* Michael Heerdegen <michael_heerdegen@web.de> [2020-11-11 00:17]:
> Jean Louis <bugs@gnu.support> writes:
>
> > Thank you. If you have ready simplest example it may be useful for
> > review.
>
> Simplest? Ok, that might be possible. Let's make a wrapper holding a
> single value that is savable:
>
> #+begin_src emacs-lisp
> (defclass my-persistent (eieio-persistent)
> ((data :initarg :data)))
>
> (defun my-save-in-location (thing file)
> (let ((obj (my-persistent :data thing)))
> (setf (oref obj file) file)
> (eieio-persistent-save obj)))
> This is not only a nice abstraction. eieio-persistent has some
> (programmable) knowledge about how to print and "restore" objects where
> a normal print+read cycle would not work.
>
> Michael.
I remember from Common Lisp about `defstruc' and more than that I did
not use. But I remember `defstruct' preparing various methods
(probably methods) automatically. From there I understand this and
keep it as note until I come to implement it.
As it is built-in, it offers straight solution, good to know!
Jean
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-17 15:44 ` Jean Louis
@ 2020-11-17 16:38 ` Michael Heerdegen
2020-11-17 21:30 ` Stefan Monnier
0 siblings, 1 reply; 24+ messages in thread
From: Michael Heerdegen @ 2020-11-17 16:38 UTC (permalink / raw)
To: Jean Louis; +Cc: help-gnu-emacs
Jean Louis <bugs@gnu.support> writes:
> I remember from Common Lisp about `defstruc' and more than that I did
> not use. But I remember `defstruct' preparing various methods
> (probably methods) automatically.
For the sake of completeness: In Emacs Lisp we also have structs via
`cl-defstruct'. These are not part of EIEIO (though EIEIO knows how to
handle them). Accessors, constructors etc are ordinary functions and
macros.
Independent of EIEIO and structs Emacs Lisp has also generic functions
and methods.
Michael.
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: How to save custom variable programmatically?
2020-11-17 16:38 ` Michael Heerdegen
@ 2020-11-17 21:30 ` Stefan Monnier
0 siblings, 0 replies; 24+ messages in thread
From: Stefan Monnier @ 2020-11-17 21:30 UTC (permalink / raw)
To: help-gnu-emacs
>> I remember from Common Lisp about `defstruc' and more than that I did
>> not use. But I remember `defstruct' preparing various methods
>> (probably methods) automatically.
> For the sake of completeness: In Emacs Lisp we also have structs via
> `cl-defstruct'. These are not part of EIEIO (though EIEIO knows how to
> handle them).
I think you mean Emacs's generic functions know how to handle them.
EIEIO's old generic functions didn't, and the rest of EIEIO is specific
to `defclass`.
Stefan
^ permalink raw reply [flat|nested] 24+ messages in thread
end of thread, other threads:[~2020-11-17 21:30 UTC | newest]
Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
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).