all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: sbaugh@catern.com
To: emacs-devel@gnu.org
Subject: Re: Managing environments (Python venv, guix environment, etc.)
Date: Wed, 20 Jul 2016 20:32:02 -0400	[thread overview]
Message-ID: <874m7jygot.fsf@earth.catern.com> (raw)
In-Reply-To: jwvzipf2ewv.fsf-monnier+gmane.emacs.devel@gnu.org

[-- Attachment #1: Type: text/plain, Size: 476 bytes --]

>> Does this approach (putting project root directories into
>> file-name-handler-alist) sound like something that could be accepted
>> into core Emacs? If so I'll get started.

OK, I implemented a very rough prototype of this. It is
attached. environment.el is the API that would go into Emacs,
guix-environment.el provides a command to use an guix-provided
environment, and test-environment.el is just a sequence of expressions
to evaluate to demonstrate them. (Not tests)


[-- Attachment #2: environment.el --]
[-- Type: application/emacs-lisp, Size: 4302 bytes --]

[-- Attachment #3: guix-environment.el --]
[-- Type: application/emacs-lisp, Size: 2365 bytes --]

[-- Attachment #4: test-environment.el --]
[-- Type: application/emacs-lisp, Size: 720 bytes --]

[-- Attachment #5: Type: text/plain, Size: 3141 bytes --]


I have run into a problem though with the file-name-handler-alist
approach. I don't think it will work in the long run. To recap, I am
using file-name-handler-alist to make sure that all operations on files
that are descendants in the filesystem tree of some project directories,
are specially handled by my environment code.

The problem is that paths passed to find-file-name-handler, such as
default-directory, are not necessarily canonical paths. But
file-name-handler-alist is an list of (REGEX . HANDLER), so I am only
able to textually match against the input path. So if a path passed to
find-file-name-handler contains ~ or .. or ., it might be that it is in
fact a descendant of a project directory, but it won't be matched by the
regex, and so it won't get specially handled.

I don't think path resolution can be done with regular expressions,
so this approach will never really work.

>My impression is that this will have to be fixed case-by-case.  There is
>a precedent for that, which is the handling of buffer-local settings.
>E.g. vc-diff is expected to obey the vc-diff-switches settings of the
>"original buffer" rather than those of the buffer where the process
>runs.  So we sometimes go through the trouble to read some variables
>before switching to the destination buffer.  Environments would "simply"
>fall into this case.  But yes, those issues will have to fixed
>one-by-one.

That treatment of vc-diff-switches does look very similar to the correct
treatment of environments. Since there are other variables that need to
be treated in this way, beyond just environments, maybe a generic
solution is possible? Perhaps the "new kind of dynamic buffer-local
variable" I mentioned earlier:

>- Make exec-path and process-environment a different kind of
>  buffer-local dynamic variable
>
>  The behavior of this variable would be that when it is defined locally
>  in the current buffer, it behaves like a normal dynamic variable. And
>  when it is not defined locally in the current buffer, looking up the
>  variable will look up the variable dynamically instead of looking for
>  a global value set with setq-default.
>  This would mean that when M-x compile is invoked from some buffer, if
>  exec-path and process-environment are not buffer-local in the compile
>  buffer, those variables will be looked up dynamically, and found in
>  the buffer-locals of the buffer that was current at the time of the
>  M-x compile invocation.
>  I don't know if this is possible given the implementation of dynamic
>  variables in Emacs Lisp.

This could be used for vc-diff-switches too, and other variables like
it. Having now read more about how dynamic variables are implemented in
Emacs, I guess this would require a fair bit of work though.

If a generic solution like this isn't possible, I can start working on
fixing things case-by-case as soon as a good design is worked out.

>I'm not maintainer any more so I don't need to make those decisions.
>But if I were maintainer, I'd need to see the code before I could make
>a decision.

OK, I'll wait until John expresses his thoughts. (Possibly after the
release?)

  parent reply	other threads:[~2016-07-21  0:32 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-14 21:36 Managing environments (Python venv, guix environment, etc.) sbaugh
2016-07-15 16:26 ` Stefan Monnier
2016-07-17 22:41   ` sbaugh
2016-07-18 10:15     ` Andreas Röhler
2016-07-18 14:46     ` Stefan Monnier
2016-07-18 19:13       ` sbaugh
2016-07-19 13:39         ` Stefan Monnier
2016-07-24  3:35         ` Dmitry Gutov
2016-07-24  8:25           ` sbaugh
2016-07-24 23:08             ` Dmitry Gutov
2016-07-21  0:32       ` sbaugh [this message]
2016-07-22 20:19         ` Stefan Monnier
2016-07-23  7:10           ` Eli Zaretskii
2016-07-24  3:26             ` Dmitry Gutov
2016-07-24  8:25               ` sbaugh
2016-07-24 14:28                 ` Eli Zaretskii
2016-07-24 17:45                   ` sbaugh
2016-07-24 17:58                     ` Eli Zaretskii
2016-07-24 19:05                       ` Spencer Baugh
2016-07-24 19:36                         ` Eli Zaretskii
2016-07-25  4:50                           ` sbaugh
2016-07-25 17:04                             ` Eli Zaretskii
2016-07-28  0:47                               ` sbaugh
2016-07-24 23:04                 ` Dmitry Gutov
2016-07-25  2:37                   ` Eli Zaretskii
2016-07-25  5:01                     ` sbaugh
2016-07-25 17:06                       ` Eli Zaretskii
2016-07-25  7:07                   ` Michael Albinus
2016-07-25 12:49                     ` Dmitry Gutov
2016-07-25 13:03                       ` Michael Albinus
2016-07-25 13:06                         ` Dmitry Gutov
2016-07-25 13:41                         ` Stefan Monnier
2016-07-28  0:02                         ` sbaugh
2016-07-28  9:34                           ` Michael Albinus
2016-07-28 14:42                           ` Eli Zaretskii
2016-07-29 17:59                             ` sbaugh
2016-07-29 18:59                               ` Eli Zaretskii
2016-07-29 19:20                                 ` Stefan Monnier
2016-07-30  6:57                                   ` Eli Zaretskii
2016-07-30 14:42                                     ` Stefan Monnier
2016-07-30 15:56                                       ` Eli Zaretskii
2016-07-29 20:57                                 ` sbaugh
2016-07-30  7:34                                   ` Eli Zaretskii
2016-07-30 13:30                                     ` sbaugh
2016-07-30 16:17                                       ` Eli Zaretskii
2016-07-30 11:24                                   ` Michael Albinus
2016-07-29 18:42                           ` Stefan Monnier
2016-07-29 19:03                             ` Eli Zaretskii
2016-07-26  2:36                   ` Stefan Monnier
2016-07-24 14:24               ` Eli Zaretskii
2016-07-25  0:05                 ` Dmitry Gutov
2016-07-25 17:00                   ` Eli Zaretskii
2016-07-26  2:08                     ` Dmitry Gutov
2016-07-26  3:06                       ` Stefan Monnier
2016-07-26 10:45                         ` Michael Albinus
2016-07-26 12:46                           ` Stefan Monnier
2016-07-26 14:49                       ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2016-07-28 10:01 Spencer Baugh
     [not found] <87shuuvzz6.fsf@totally-fudged-out-message-id>
2016-07-28 10:08 ` Michael Albinus

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=874m7jygot.fsf@earth.catern.com \
    --to=sbaugh@catern.com \
    --cc=emacs-devel@gnu.org \
    /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.