Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions M2/Macaulay2/d/actors5.d
Original file line number Diff line number Diff line change
Expand Up @@ -1773,12 +1773,8 @@ changeDirectory(dir:string):Expr := (
changeDirectory(e:Expr):Expr := (
when e
is filename:stringCell do changeDirectory(filename.v)
is a:Sequence do (
if length(a) == 0
then changeDirectory("~")
else WrongArg("a string or ()"))
else WrongArg("a string or ()"));
setupfun("changeDirectory",changeDirectory);
else WrongArgString());
setupfun("changeDirectory0",changeDirectory);

export debuggerHook := nullE;

Expand Down
6 changes: 6 additions & 0 deletions M2/Macaulay2/m2/files.m2
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,12 @@ scanLines(Function,String) := (p,inf) -> ( -- the function p can use "break
ret)
scanLines(Function,List) := (p,infs) -> scan(infs,inf->scanLines(p,inf))

changeDirectory = method()
changeDirectory String := newdir -> (
path = apply(path, dir -> minimizeFilename relativizeFilename(newdir, dir));
changeDirectory0 newdir)
changeDirectory () := () -> changeDirectory "~"

-- Local Variables:
-- compile-command: "make -C $M2BUILDDIR/Macaulay2/m2 "
-- End:
13 changes: 10 additions & 3 deletions M2/Macaulay2/packages/Macaulay2Doc/ov_system.m2
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,9 @@ document {

doc ///
Key
changeDirectory
changeDirectory
(changeDirectory, String)
1:changeDirectory
Headline
change the current working directory
Usage
Expand All @@ -702,15 +704,20 @@ doc ///
:String -- the new working directory
Description
Text
Change the current working directory to @VAR "dir"@.
Change the current working directory to @VAR "dir"@. Any relatives paths
in @TO "path"@ are updated accordingly.
Example
dir = temporaryFileName()
makeDirectory dir
changeDirectory dir
currentDirectory()
Text
If @VAR "dir"@ is omitted, then the current working directory
is changed to the user's home directory.
is changed to the user's home directory
Caveat
Calling this function in Emacs will break the "jump to source" feature when
clicking on the output of @TO locate@ unless you also update Emacs's working
directory with @KBD "M-x cd"@..
SeeAlso
currentDirectory
///
Expand Down
16 changes: 14 additions & 2 deletions M2/Macaulay2/tests/normal/files.m2
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,23 @@
dir = temporaryFileName()
assert(changeDirectory makeDirectory dir == realpath dir)
assert(currentDirectory() == realpath dir)

-- #4389
dir | "/hello.m2" << "hello = () -> \"Hello, world!\"" << endl << close
oldpath = path
path = {"."}
changeDirectory "/"
load "hello.m2"
assert Equation(hello(), "Hello, world!")
path = oldpath

removeFile(dir | "/hello.m2")
removeDirectory dir
assert not isDirectory dir

if fileExists homeDirectory then (
assert(changeDirectory() == homeDirectory);
assert(currentDirectory() == homeDirectory))
removeDirectory dir
assert not isDirectory dir

assert(baseFilename "/foo/bar/baz" == "baz")
assert(baseFilename "/foo/bar/baz/" == "baz")
Expand Down