From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: How to save custom variable programmatically? Date: Tue, 10 Nov 2020 16:55:23 +0300 Message-ID: References: <87blg5e9re.fsf@web.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39690"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.0 (3d08634) (2020-11-07) Cc: help-gnu-emacs@gnu.org To: Michael Heerdegen Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 10 15:24:38 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kcUZa-000ABN-2E for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 10 Nov 2020 15:24:38 +0100 Original-Received: from localhost ([::1]:51454 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kcUZY-0002bw-VR for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 10 Nov 2020 09:24:36 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34350) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcUZA-0002bm-Sg for help-gnu-emacs@gnu.org; Tue, 10 Nov 2020 09:24:12 -0500 Original-Received: from static.rcdrun.com ([95.85.24.50]:41343) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kcUZ8-0003Ip-QU for help-gnu-emacs@gnu.org; Tue, 10 Nov 2020 09:24:12 -0500 Original-Received: from localhost ([::ffff:197.157.34.177]) (AUTH: PLAIN admin, TLS: TLS1.2,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by static.rcdrun.com with ESMTPSA id 00000000002C0003.000000005FAAA288.00004E9A; Tue, 10 Nov 2020 14:24:07 +0000 Content-Disposition: inline In-Reply-To: <87blg5e9re.fsf@web.de> Received-SPF: pass client-ip=95.85.24.50; envelope-from=bugs@gnu.support; helo=static.rcdrun.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/10 08:40:04 X-ACL-Warn: Detected OS = Linux 3.11 and newer [fuzzy] X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:125187 Archived-At: * 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 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.