-
-
Notifications
You must be signed in to change notification settings - Fork 300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add source command #453
Comments
Is |
Yes, we have x = haha then you should be able to do I will close this issue when this problem with |
FWIW, I stumbled across this issue because I found I needed |
I'm wondering if we really need a |
@krader1961 I really like your idea of being able to specify which symbols to import in the
|
Importing names from modules is not hard to implement, but I doubt its usefulness beyond being able to put your wrapper functions ("aliases") in a module and pouring that into Also, importing names that are not known beforehand ( To start with, Elvish always compiles a chunk of code before evaluating it, and part of the compilation phase is checking variable names. In dynamic languages like Python, use of undefined variables is a runtime error. In Elvish, it is a compilation error and will prevent the whole chunk from executing. For instance, the following code won't do anything (provided that you didn't define echo before
echo $undefined-var
echo after whereas the following Python code will print out print('before')
print(undefined_var)
print('after') Now, to compile code like the following use some-mod [:all]
echo $some-var Elvish has to load If you type something like Now if the module loading is to be moved to the compilation phase, that means that when you type To summarize the challenge in supporting
Code references: On the other hand, there is no problem with So how can the current The way foo = bar The following code won't compile: -source a.elv
echo $foo because However, if you run those two lines as separate commands from the editor, it does work. This is because Elvish creates a new compiler for every new command, and the new compiler knows all names that are defined. This badness of behavior is why I chose to mark Code references: |
@xiaq thank you for the comprehensive explanation. As you say, the only benefit for importing names would be to allow defining "top-level functions". But the usefulness of this can be debated. At the moment, Elvish forces the user to be explicit about top-level functions. For example, to use my
Which makes my configuration more explicit about what is being overriden. This is good for clarity at the expense of verbosity and exposing some more "implementation details" in my top-level configuration. If I think being able to specify the names to import would hit the right balance: abstract away implementation details (such as how to wrap a function) while still making the configuration explicit about what names are being imported:
|
For uniformity, it is better if we can import variables, not just named functions. Named functions are really just variables who names start with Also, I find it clearer to separate the loading of modules (already supported by use dir # loads module "dir"
refer dir ['&cd'] # aliases $dir:&cd as $&cd |
Agreed. But do we really need a new command? I don't see the reason to implement |
@krader1961 We have the same definition for aliasing. There are three reasons for a separate
|
Good points, @xiaq. Your first two points in particular are worth noting since composition is a useful feature in general. I hadn't considered the case of aliasing objects from semi-magic namespaces like The As for your point 3 I recognized that difference from Python behavior but deemed it acceptable given that Elvish is only influenced by Python. So the dual behavior of my proposal being equivalent to Python's |
The namesake of As you pointed out, |
In light of commit ff7c500 that formally deprecates the experimental |
I need this capability, to customize my Elvish shell to configure my PATH, to activate a Python virtual environment, to configure other tools, etc. If Elvish intentionally lacks a source command or equivalent, then how is such shell session configuration supposed to be achieved. Please note that my (and many other's) use case involves putting all the relevant shell configuration into a code repository as part of a project. Therefore, it MUST NOT involve modifying the user's configuration (in XDG directories and files). Can this be done in Elvish, or must I look for another shell? |
@rdw20170120 Instead of |
@hanche, thank you for that insight; I will have to experiment with it. My objectives are primarily two-fold: I must set crucial environment variables to configure this shell session for work on the current project, and I must define important functions to facilitate that project work. However, I wonder whether I actually have to make the functions (modules) "stick" during my activation process. I am starting to think that I may not have to do so. Perhaps it will be enough to set This may also "fix" the issue of module cacheing. If the individual scripts are executed in their own Elvish process (the default), then the modules that they Where this becomes problematic is where I want to use functions directly from the shell, rather than merely in scripts. I could |
@rdw20170120 I think perhaps the best thing for a project like that would be to provide a module to be installed in, say, In short, better not to pollute the user's interactive name space needlessly, without the user's express consent. |
@hanche: I appreciate your comments. A crucial part of my design is to not compromise the user's account and configuration at all. Anything that my project/tool (or any other project/tool) might install within XDG directories could compromise the user, and so is out of the question. My approach is to have the user open a shell, change directory to the root of the project repository that they cloned onto their machine, then invoke an activation script of some kind. Having done that, the user has certainly given their express consent to manipulate the environment. But it is essential that ONLY that shell SESSION has been reconfigured and might be "compromised". As soon as the user invokes Actually, I would never expect to put any code into the users As @krader1961 and others have said elsewhere in these issues, most of us have learned to avoid any tool or project that is rude enough to directly mess with our user configuration such as in I realize that you have only abstract information about my project, and that makes it very difficult to comment. Another crucial part of my "tool" is that an individual user will (ideally) use multiple copies of it, one in each of their project repositories. God willing, someday everybody's project repository might contain a copy of my tool (I can dream, right?). So an individual user's account on their workstation might have a dozen copies of my tool, embedded in a dozen project repository clones, with various versions involved. Each such use of my tool empowers the user to create a custom activation script, suited to the content and tools for that project. Trying to manage such multiple copies and configurations within |
There might be a misunderstanding here. My point was that installing a shell extension should not automatically modify my shell config file(s). There is absolutely nothing wrong with requiring the user to manually add a block of code to their shell config file(s). Having said that, there is nothing wrong with expecting the user to I also don't really understand what you're getting at with respect to namespace collisions since that can happen even with your preferred approach. There is absolutely nothing that keeps the user from defining env vars or shell functions that conflict with those defined by your project. |
@krader1961 has rightly suggested that I open a new issue for my various questions. |
The summarize, the use cases satisfied by
|
Source file.
The text was updated successfully, but these errors were encountered: