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

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

Re: Rename Shell buffer with current directory


From: Sebastien Vauban
Subject: Re: Rename Shell buffer with current directory
Date: Sun, 08 Dec 2013 21:36:38 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (windows-nt)

Hello Michael,

Michael Heerdegen wrote:
> "Sebastien Vauban" <sva-news@mygooglest.com> writes:
>>
>> In order to rename the Shell buffer with the information of the current
>> directory, I've come up with the following:
>>
>> (defun my-rename-to-curdir ()
>>   (message "%s" default-directory)      ; does work
>>   (rename-buffer (concat "*shell " default-directory "*")) ; DOESN'T WORK
>>   )
>>
>> (add-hook 'comint-output-filter-functions 'my-rename-to-curdir nil t)
>>
>> Depending on where you first launch Shell, the name is correctly created, so
>> it mostly works.
>>
>> But, when changing of directory, in the shell session, does not update the
>> name of the buffer -- while the variable `default-directory' is correctly
>> updated...
>
> Without knowing if renaming the buffer all the time breaks anything:
> `comint-output-filter-functions' is an abnormal hook (that's why it is called
> ""...-functions"" and not "...-hook""). In contrast to normal hooks,
> functions in abnormal hooks take arguments.

Interesting concept. Thanks for the explanations...

> The doc of the hook says how many and what they mean.
> `comint-output-filter-functions' functions need to accept one argument. Just
> don't use it in the function body if you don't need it.

OK, I've "cloned" what's done for `comint-postoutput-scroll-to-bottom' and
`comint-watch-for-password-prompt', present in my
`comint-output-filter-functions', by adding an optional `_string' argument:

--8<---------------cut here---------------start------------->8---
  (defun my-rename-buffer-to-curdir (&optional _string)
    "Change Shell buffer's name to current directory."
    (message "%s" default-directory)
    (rename-buffer (concat "*shell " default-directory "*")))

  (add-hook 'shell-mode-hook 'my-rename-buffer-to-curdir)

  (add-hook 'comint-output-filter-functions 'my-rename-buffer-to-curdir nil t)
--8<---------------cut here---------------end--------------->8---

However, that does not change the end result: the name of the buffer is
unchanged.

Should I report this as an Emacs bug?

Best regards,
  Seb

-- 
Sebastien Vauban


reply via email to

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