gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Better dirtrack


From: Dmitri Paduchikh
Subject: Better dirtrack
Date: Thu, 29 Dec 2016 23:51:16 +0500
User-agent: Gnus/5.13 (Gnus v5.13)

A thought came to me that directory tracking in shell-mode can be done
in very simple and robust way. One just needs to call emacsclient from
prompt string in order to set value of default-directory of the shell
buffer. Name of the shell buffer can be transferred to the shell process
using environment. So I have the following solution.

In init.el:

(advice-add 'comint-exec :around
            #'(lambda (f buffer &rest args)
                (let ((process-environment (cons (concat "EMACS_BUFFER=" 
(buffer-name buffer))
                                                 process-environment)))
                  (apply f buffer args)))
            '((name . "envbuf")))

At the end of ~/.bashrc:

if [ -n "$EMACS_BUFFER" ]; then
    set_emacs_dir() {
        >/dev/null 2>&1 emacsclient --eval \
            '(with-current-buffer "'"$EMACS_BUFFER"'" (setq default-directory 
"'"$PWD"'"))'
    }
    PS1='`set_emacs_dir`'"$PS1"
fi

With regards
Dmitri Paduchikh



reply via email to

[Prev in Thread] Current Thread [Next in Thread]