Skip to content
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

Export changeDirectory #3269

Merged
merged 6 commits into from
Jun 5, 2024
Merged

Conversation

d-torrance
Copy link
Member

I've often wanted the option to change the current working directory inside M2 (e.g, if without realizing I run M-x M2 inside Emacs when the active buffer is visiting some file in some strange directory).

It turns out that a changeDirectory function already exists, but it just wasn't exported!

We update it slightly (allowing the expansion of ~ to the user's home directory and changing to the home directory when there's no input), document it, and add unit tests.

i1 : currentDirectory()

o1 = /home/profzoom/tmp/

i2 : makeDirectory "foo"

i3 : changeDirectory "foo"

i4 : currentDirectory()

o4 = /home/profzoom/tmp/foo/

changeDirectory(dir:string):Expr := (
if chdir(expandFileName(dir)) == -1
then buildErrorPacket(syscallErrorMessage("changing directory"))
else nullE);
Copy link
Member

@mahrud mahrud May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to have it return whatever currentDirectory() returns. This is useful to know the exact new address (e.g. if symlink resolutions happened) without running another command.

On that note, it would be good if makeDirectory() also returned the address so you could do changeDirectory makeDirectory "~/foo".

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great ideas!

@DanGrayson DanGrayson merged commit 77ac190 into Macaulay2:development Jun 5, 2024
6 checks passed
@d-torrance d-torrance deleted the change-directory branch June 6, 2024 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants