emacsemacs23

emacs: I need and explanation on dirtrack-list variable


In emacs' shell I am using dirtrack-mode (M-x dirtrack-mode). I get errors in the *Directory Tracking Log* buffer:

Input `user@machine:~/modules/mydir> ' failed to match `dirtrack-list'

In order to solve it I am trying to set the dirtrack-list variable to tell emacs the form of my prompt with no luck. This is mainly because I don't understand this variable's documentation:

dirtrack-list's value is ("^emacs ^.\\{1,\\}@.\\{1,\\}:.+> " nil)

Automatically becomes buffer-local when set in any fashion.

Documentation: List for directory tracking. First item is a regexp that describes where to find the path in a prompt. Second is a number, the regexp group to match. Optional third item is whether the prompt is multi-line. If nil or omitted, prompt is assumed to be on a single line.

Can anyone explain to me which is the first, the second and the third item? How can I tell emacs which part of the prompt is the path?


Solution

  • The value of your dirtrack-list variable is a list:

    ("^emacs ^.\\{1,\\}@.\\{1,\\}:.+> " nil)
    

    This list consists of two items: a string and the symbol nil. The first item, as per the documentation, is a regular expression that is matched against your prompt to extract the path.

    So, let's say your shell prompt looked like this:

    toni@host [/home/toni/stuff] >
    

    then you want the regular expression to match the part of the prompt that contains /home/toni/stuff. Obviously, the default regular expression for dirtrack-list does not do that, so you have to replace it. For the example above, something like this should do:

    "^[^@]*@[^ ]* \\[\\([^]]*\\)\\] > "
    

    In that regexp, the part that is the actual path is captured by the "\\(...\\)" group. Since it is the first (and only) group in your regexp, you want to put the number 1 as the second item of your dirtrack-list variable.

    In order to use your own regexp like the one from the example, type M-x customize-variable RET dirtrack-list RET. Then edit the value to:

    ("^[^@]*@[^ ]* \\[\\([^]]*\\)\\] > " 1)
    

    and set it for the current session. Of course, you will have to use a regular expression that matches your actual prompt, not the one from my example.