2

I use the following prompt for my Emacs shell:

PS1='\n\[\e[33m\]\w\033[36m\]$(parse_git_branch)\[\033[00m\]\n$ '

The output looks like this:

Emacs prompt

I tried to use the regexp "(^[^\\(]*)" to match the path and set it in dirtrack-list:

(setq-default dirtrack-list '("(^[^\\(]*)" 1 1))

But due to the colors, the shell never matches (so it can't track my cwd). Is it possible to extend my regexp to include the colors?


Including @tripleee's regexp works:

(setq-default dirtrack-list '("\\s-\\(\033\\[[0-9]+m\\)*\\([^\033\\(]+\\)" 2 1))

But now when I cd I randomly get the following error in a *Warnings* buffer:

Warning (emacs):   
/ does not exist
4

3 回答 3

1

Try something like "^\\(\033\\[[0-9]+m\\)*\\([^\033\\(]+\\)" and grab the second capture group instead of the first.

于 2013-04-28T06:18:56.170 回答
1

There is nothing in tracking.el that throws warnings. I used the following .emacs to try and reproduce the problem and got nothing wrong:

(add-hook 'shell-mode-hook
         (lambda ()
           (shell-dirtrack-mode -1)
           (dirtrack-mode 1)))

(add-hook 'dirtrack-directory-change-hook
          (lambda ()
            (message default-directory)))

(setq-default dirtrack-list '("\\s-\\(\033\\[[0-9]+m\\)*\\([^\033\\(]+\\)" 2 1))

What OS and what version of emacs are you using?

于 2013-04-30T16:44:48.133 回答
1

The problem comes from the rvm part. When you cd in that specific repository, it automatically spits out a line telling you it is using a gemset. The regex is not narrow enough to eliminate this false positive. I believe the following regexp should work: "\\s-\\(\033\\[[0-9]+m\\)\\([^\033\\(]+\\)".

于 2013-05-01T13:15:44.447 回答