From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Drew Adams Newsgroups: gmane.emacs.help Subject: RE: How to customize an option to a dynamic value (computed by lisp form) Date: Fri, 26 Aug 2016 13:59:00 -0700 (PDT) Message-ID: References: <87k2f69hvb.fsf@kuiper.lan.informatimago.com> <83832586-765e-4df4-917a-98458247d829@default> <86785f1e-022c-4946-8a28-39c72eb26d5d@default> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1472245186 31542 195.159.176.226 (26 Aug 2016 20:59:46 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 26 Aug 2016 20:59:46 +0000 (UTC) Cc: "Pascal J. Bourguignon" , help-gnu-emacs@gnu.org To: Jorge Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Aug 26 22:59:42 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bdOE1-0007hI-2Y for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Aug 2016 22:59:41 +0200 Original-Received: from localhost ([::1]:33806 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bdODy-0005Tg-HV for geh-help-gnu-emacs@m.gmane.org; Fri, 26 Aug 2016 16:59:38 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50110) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bdODZ-0005JA-KY for help-gnu-emacs@gnu.org; Fri, 26 Aug 2016 16:59:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bdODV-0000QH-EC for help-gnu-emacs@gnu.org; Fri, 26 Aug 2016 16:59:12 -0400 Original-Received: from aserp1040.oracle.com ([141.146.126.69]:20902) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bdODV-0000Pw-5c for help-gnu-emacs@gnu.org; Fri, 26 Aug 2016 16:59:09 -0400 Original-Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u7QKx4Dm022504 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 26 Aug 2016 20:59:04 GMT Original-Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u7QKx3MF032570 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 26 Aug 2016 20:59:03 GMT Original-Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u7QKx2K9013334; Fri, 26 Aug 2016 20:59:02 GMT In-Reply-To: X-Priority: 3 X-Mailer: Oracle Beehive Extensions for Outlook 2.0.1.9 (901082) [OL 12.0.6753.5000 (x86)] X-Source-IP: userv0022.oracle.com [156.151.31.74] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 141.146.126.69 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:111211 Archived-At: > > What does that mean? A variable has a single, static, literal value at > > any time. > https://en.wikipedia.org/wiki/Literal_(computer_programming) Which says: "In computer science, a literal is a _notation_ for _representing_ a fixed value in source code." Whereas here we are not talking about a notation. We are not talking about a source-code representation of a value. We are talking about a real, live, runtime value. We are talking about the value of a variable, and a value is not something particularly "dynamic". A _variable_ could be considered dynamic, in that it can change its value over time. > const int answer =3D 42; // the answer to life the universe and everythi= ng > const int answer_sq =3D answer*answer; > const int age =3D read_int(); >=20 > All three variables defined above are constants. However, only the first > two have values which can be known at compile time, and only the first > one is initialized to a literal (42). The context of what you requested has nothing to do with compile time, and it has nothing to do with whether the source code defining the option value uses a literal (self-evaluating Lisp thingy) or is computed. "the new value will be added to the custom-set-variables form with static values. This has two problems: 1. It will have static values. 2. Since org-init.el is called after the custom-set-variables form, the values set in the form will be overwritten." When a variable is assigned a value, regardless of when or how, the value is a value: essentially static. (A value can be a mutable object, such as a cons, but I don't think that's what you intended by something "dynamic".) > I want to be able to customize the options mentioned in the original emai= l > to values computed from other options, but I cannot. I can only initiali= ze > them to literals. Going back to your original message: "I set three options to a dynamic value, using the value of the option `org-directory'." And you show code that, in effect, calls `customize-set-variable' with this as the value argument: =20 (list (concat org-directory "/agenda/") "~/Dropbox/wanessa_e_jorge/administra=C3=A7=C3=A3o_cl=C3=ADnica/derma= -prime.org") The value that is assigned is a list of two strings. It is not especially "dynamic". You did _not_ assign the variable to "a dynamic value". And your plaint was that Customize then shows you the value as that "static" list of two strings, being oblivious to the fact that you constructed the list and the first string, let alone how you constructed them. You say that after customizing the value "it will be written to init.el as a string literal, no longer respecting org-directory." You said: "The problem is that when I try to customize one of these three options, the customize buffer does not know that the value was computed dynamically." And that's exactly right. No matter how you set a variable value, the value does not tell you how it was constructed. Customize knows the allowed types for the value, and it knows the current value and the initial value. It does not know or care how the initial or the current value was computed. It sounds like what you want to use as value is not a list of strings but a _function_ that, when called, returns a list of strings, and you want that function to construct the first string of the list using `org-directory'. Here is a command that does that. (defun foo (subdir file) (interactive (list (read-directory-name "Agenda subdir: " org-directory nil t) (read-file-name "Org file: " nil nil t))) (customize-set-variable 'org-agenda-files (list (expand-file-name subdir org-directory) file))) But that won't help you use the Customize UI to set it. The defcustom defining `org-agenda-files' does not have a :type that allows a function value. The value must be either a list of files and directories or a file name. (If you really wanted to, you could redefine that defcustom to accept a function value also, and then redefine the Org code that uses the option, so that if the value is a function it invokes it to get the required list of strings.) What you can do (others might have other suggestions): M-x foo RET agenda RET=20 /Dropbox/wanessa_e_jorge/administra=C3=A7=C3=A3o_cl=C3=ADnica/derma-prime.o= rg RET IOW, use a command to set the value, and have that command respect `org-directory'.