help-gnu-emacs
[Top][All Lists]
Advanced

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

RE: How to customize an option to a dynamic value (computed by lisp form


From: Drew Adams
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)

> > 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 = 42;  // the answer to life the universe and everything
> const int answer_sq = answer*answer;
> const int age = read_int();
> 
> 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 email
> to values computed from other options, but I cannot.  I can only initialize
> 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:
 
(list (concat org-directory "/agenda/")
      "~/Dropbox/wanessa_e_jorge/administração_clínica/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 
/Dropbox/wanessa_e_jorge/administração_clínica/derma-prime.org RET

IOW, use a command to set the value, and have that command
respect `org-directory'.



reply via email to

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