all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: Jorge <jorge13515@gmail.com>
Cc: "Pascal J. Bourguignon" <pjb@informatimago.com>, help-gnu-emacs@gnu.org
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)	[thread overview]
Message-ID: <bd25d4be-3f7f-49d9-a973-179eb74ab375@default> (raw)
In-Reply-To: <CAJR3Qncjc3A_=eD-6FkYdN7M25cYT=uuy9uiVh7=wTW+tZN5nQ@mail.gmail.com>

> > 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'.



  parent reply	other threads:[~2016-08-26 20:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-23 20:26 How to customize an option to a dynamic value (computed by lisp form) Jorge
2016-08-24 17:50 ` Pascal J. Bourguignon
2016-08-25 17:55   ` Jorge
2016-08-25 20:54     ` Drew Adams
2016-08-26 12:54       ` Jorge
2016-08-26 13:26         ` Jorge
2016-08-26 14:28         ` Drew Adams
2016-08-26 19:02           ` Jorge
2016-08-26 20:18             ` Jorge
2016-08-26 20:59             ` Drew Adams [this message]
2016-08-27 11:50               ` tomas
2016-08-30 20:42               ` Jorge

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=bd25d4be-3f7f-49d9-a973-179eb74ab375@default \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=jorge13515@gmail.com \
    --cc=pjb@informatimago.com \
    /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.