Discussion:
[Matlab-emacs-discuss] annoying path behavior of the *MATLAB* shell buffer who is the culprit
Uwe Brauer
2017-02-24 16:57:23 UTC
Permalink
Hi all

I find the following quite annoying and look desperately for a solution.

I am using the following structure

Dir-Matlab/dir1/test.m
Dir-Matlab/dir2/test2.m

Now I open test.m and run matlab-shell-save-and-go
I see
>> cd(['/home/oub/ALLES/Dir-Matlab/dir1/'])
>> test
y = 64

Which is ok, so I open test2.m in dir2 and do the same, again the shall
does it nicely
>> cd(['/home/oub/ALLES/Dir-Matlab/dir2/'])
>> test2
y = 49

And indeed
>> pwd

tells me

/home/oub/ALLES/Dir-Matlab/dir2

Which is ok.

However when I use find-file, in the *MATLAB* shell, then the buffer of
the matlab shell thinks that I am still in dir1.

Find file: ~/ALLES/Dir-Matlab/dir1/

How can I tell the buffer that I am running that I am in the dir2?

Or in other words
>> cd(['/home/oub/ALLES/Dir-Matlab/dir2/'])

should be reflected in the *MATLAB* buffer

Anybody has an idea how to achieve that?

The only idea which occurred to me is this function

(defun my-matlab-switch-and-save-default-directory ()
(interactive)
(let ((saved-default-directory default-directory))
(switch-to-buffer "*MATLAB*")
(setq default-directory saved-default-directory)))

Which should somehow be included in matlab-shell-save-and-go, any
suggestions?

Regards

Uwe Brauer
Uwe Brauer
2017-02-24 18:26:07 UTC
Permalink
>>> "Eric" == Eric Ludlam <***@mathworks.com> writes:

> Hiya,
> Matlab-shell uses dirtrack, or shell-directory-tracker. It just
> watches the input stream and changes default-directory when it sees:

> cd /some/path/to/directory

> I'll guess MATLAB syntax around (['/path']) is confusing it.

> You could probably replace all the parens etc with just:

> cd '/path'

> which should work fine. I tried this with a DOS shell in Emacs and
> Emacs followed the path even though the actual shell threw and error.

Hi Eric

Thanks for your answer, however at least for this does not work

I know obtain, with the same logic as before

>> cd '/home/oub/ALLES/Dir-Matlab/dir1/'
>> test
y = 64
>> addpath('/home/oub/.emacs.d/elpa/matlab-mode-20160902.459/toolbox','-begin'); rehash; emacsinit('emacsclient -n');
>>
>> pwd

ans =

/home/oub/ALLES/Dir-Matlab/dir1

>> cd '/home/oub/ALLES/Dir-Matlab/dir2/'
>> test2

y = 49

However find-file still thinks it is in dir1 not 2.

Uwe
John Ciolfi
2017-02-24 20:16:11 UTC
Permalink
I wonder if we could update matlab mode to ask what cwd is each time it sees the prompt?

On Feb 24, 2017, at 1:26 PM, Uwe Brauer <***@mat.ucm.es> wrote:

>>>> "Eric" == Eric Ludlam <***@mathworks.com> writes:
>
>> Hiya,
>> Matlab-shell uses dirtrack, or shell-directory-tracker. It just
>> watches the input stream and changes default-directory when it sees:
>
>> cd /some/path/to/directory
>
>> I'll guess MATLAB syntax around (['/path']) is confusing it.
>
>> You could probably replace all the parens etc with just:
>
>> cd '/path'
>
>> which should work fine. I tried this with a DOS shell in Emacs and
>> Emacs followed the path even though the actual shell threw and error.
>
> Hi Eric
>
> Thanks for your answer, however at least for this does not work
>
> I know obtain, with the same logic as before
>
>>> cd '/home/oub/ALLES/Dir-Matlab/dir1/'
>>> test
> y = 64
>>> addpath('/home/oub/.emacs.d/elpa/matlab-mode-20160902.459/toolbox','-begin'); rehash; emacsinit('emacsclient -n');
>>>
>>> pwd
>
> ans =
>
> /home/oub/ALLES/Dir-Matlab/dir1
>
>>> cd '/home/oub/ALLES/Dir-Matlab/dir2/'
>>> test2
>
> y = 49
>
> However find-file still thinks it is in dir1 not 2.
>
> Uwe
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> Matlab-emacs-discuss mailing list
> Matlab-emacs-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matlab-emacs-discuss
Eric Ludlam
2017-03-01 21:47:18 UTC
Permalink
Hmm. I'm not certain what the difference is. As I mentioned, matlab-shell has no directory parsing itself, it just turns on this service. When I looked at how it works, it's just a long conditional trying out different regexp trying to divine what is being CD'd to.

I'm assuming you needed the 'quotes' around the path in case of spaces in the path.

Looking through shell-dirtrack-mode, it looks like there isn't much in the way of options regarding syntax around the string. It was probably an error when I tried it in a dos shell due to how the syntax table was set up.

Perhaps the desired path can be examined for spaces, and then have no special syntax around it if there are no spaces. That will allow it to work in most cases.

Or maybe instead of depending on the cd command, just change the default-directory next to the code that inserts the CD command. That would be pretty robust.

Eric

-----Original Message-----
From: Uwe Brauer [mailto:***@mat.ucm.es]
Sent: Friday, February 24, 2017 1:26 PM
To: Eric Ludlam <***@mathworks.com>
Cc: Uwe Brauer <***@mat.ucm.es>; matlab-emacs-discuss <matlab-emacs-***@lists.sourceforge.net>
Subject: Re: [Matlab-emacs-discuss] annoying path behavior of the *MATLAB* shell buffer who is the culprit

>>> "Eric" == Eric Ludlam <***@mathworks.com> writes:

> Hiya,
> Matlab-shell uses dirtrack, or shell-directory-tracker. It just
> watches the input stream and changes default-directory when it sees:

> cd /some/path/to/directory

> I'll guess MATLAB syntax around (['/path']) is confusing it.

> You could probably replace all the parens etc with just:

> cd '/path'

> which should work fine. I tried this with a DOS shell in Emacs and
> Emacs followed the path even though the actual shell threw and error.

Hi Eric

Thanks for your answer, however at least for this does not work

I know obtain, with the same logic as before

>> cd '/home/oub/ALLES/Dir-Matlab/dir1/'
>> test
y = 64
>> addpath('/home/oub/.emacs.d/elpa/matlab-mode-20160902.459/toolbox','-begin'); rehash; emacsinit('emacsclient -n');
>>
>> pwd

ans =

/home/oub/ALLES/Dir-Matlab/dir1

>> cd '/home/oub/ALLES/Dir-Matlab/dir2/'
>> test2

y = 49

However find-file still thinks it is in dir1 not 2.

Uwe
Loading...