* Rename Shell buffer with current directory
@ 2013-12-07 8:06 Sebastien Vauban
2013-12-07 20:58 ` Michael Heerdegen
[not found] ` <mailman.8479.1386449940.10748.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 11+ messages in thread
From: Sebastien Vauban @ 2013-12-07 8:06 UTC (permalink / raw
To: help-gnu-emacs-mXXj517/zsQ
Hello,
In order to rename the Shell buffer with the information of the current
directory, I've come up with the following:
--8<---------------cut here---------------start------------->8---
(defun my-rename-to-curdir ()
(message "%s" default-directory) ; does work
(rename-buffer (concat "*shell " default-directory "*")) ; DOESN'T WORK
)
(add-hook 'shell-mode-hook 'my-rename-to-curdir)
(add-hook 'comint-output-filter-functions 'my-rename-to-curdir nil t)
--8<---------------cut here---------------end--------------->8---
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...
It's like if `rename-buffer' would fail. But I see no reason for that. Do you?
Best regards,
Seb
--
Sebastien Vauban
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Rename Shell buffer with current directory
2013-12-07 8:06 Rename Shell buffer with current directory Sebastien Vauban
@ 2013-12-07 20:58 ` Michael Heerdegen
[not found] ` <mailman.8479.1386449940.10748.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 11+ messages in thread
From: Michael Heerdegen @ 2013-12-07 20:58 UTC (permalink / raw
To: help-gnu-emacs
"Sebastien Vauban" <sva-news@mygooglest.com>
writes:
> Hello,
>
> 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 'shell-mode-hook 'my-rename-to-curdir)
>
> (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. 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.
Regards,
Michael.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Rename Shell buffer with current directory
[not found] ` <mailman.8479.1386449940.10748.help-gnu-emacs@gnu.org>
@ 2013-12-08 20:36 ` Sebastien Vauban
2013-12-08 21:32 ` Michael Heerdegen
[not found] ` <mailman.8618.1386538352.10748.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 11+ messages in thread
From: Sebastien Vauban @ 2013-12-08 20:36 UTC (permalink / raw
To: help-gnu-emacs-mXXj517/zsQ
Hello Michael,
Michael Heerdegen wrote:
> "Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org> 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
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Rename Shell buffer with current directory
2013-12-08 20:36 ` Sebastien Vauban
@ 2013-12-08 21:32 ` Michael Heerdegen
[not found] ` <mailman.8618.1386538352.10748.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 11+ messages in thread
From: Michael Heerdegen @ 2013-12-08 21:32 UTC (permalink / raw
To: help-gnu-emacs
Hi Sebastien,
> (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)
^
> However, that does not change the end result: the name of the buffer is
> unchanged.
Why do you use a non-nil LOCAL parameter for `add-hook'? Without it,
your code works for me.
> Should I report this as an Emacs bug?
No.
Regards,
Michael.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Rename Shell buffer with current directory
[not found] ` <mailman.8618.1386538352.10748.help-gnu-emacs@gnu.org>
@ 2013-12-09 8:36 ` Sebastien Vauban
2013-12-09 9:36 ` Rainer M Krug
0 siblings, 1 reply; 11+ messages in thread
From: Sebastien Vauban @ 2013-12-09 8:36 UTC (permalink / raw
To: help-gnu-emacs-mXXj517/zsQ
Hi Michael,
Michael Heerdegen wrote:
>> (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)
> ^
>> However, that does not change the end result: the name of the buffer is
>> unchanged.
>
> Why do you use a non-nil LOCAL parameter for `add-hook'? Without it, your
> code works for me.
So does it for me -- thanks for your help!
Though, I still don't understand why making the `my-rename-buffer-to-curdir'
function buffer-local makes the above fail... Remember that that function gets
called (see the message displayed in the echo area), only the function
`rename-buffer' fails...
Best regards,
Seb
--
Sebastien Vauban
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Rename Shell buffer with current directory
2013-12-09 8:36 ` Sebastien Vauban
@ 2013-12-09 9:36 ` Rainer M Krug
[not found] ` <52A58F09.1010409-vfylz/Ys1k4@public.gmane.org>
0 siblings, 1 reply; 11+ messages in thread
From: Rainer M Krug @ 2013-12-09 9:36 UTC (permalink / raw
To: Sebastien Vauban, help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 12/09/13, 09:36 , Sebastien Vauban wrote:
> Hi Michael,
>
> Michael Heerdegen wrote:
>>> (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)
>> ^
>>> However, that does not change the end result: the name of the
>>> buffer is unchanged.
>>
>> Why do you use a non-nil LOCAL parameter for `add-hook'? Without
>> it, your code works for me.
>
> So does it for me -- thanks for your help!
>
> Though, I still don't understand why making the
> `my-rename-buffer-to-curdir' function buffer-local makes the above
> fail... Remember that that function gets called (see the message
> displayed in the echo area), only the function `rename-buffer'
> fails...
Thanks - I am using your code, and it works very nicely - very useful.
Cheers,
Rainer
>
> Best regards, Seb
>
- --
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)
Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa
Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax : +33 - (0)9 58 10 27 44
Fax (D): +49 - (0)3 21 21 25 22 44
email: Rainer@krugs.de
Skype: RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJSpY8JAAoJENvXNx4PUvmCcyMH/iuQ6Bi5o1jfeKBx+2fvs/3y
7MvwdaaUIPD56J5U0/vfQ4J74nmZgceIm7nGf3KkG4iSorOaRHye+IEeQJonwkKo
ozogmFncLw9v7cK8ToUcAawCfFr6iCZo72EPneuOrwdcMI4zvNI+Cyk2iUhHA/nv
L509GMYy36X538yPzbtES0Y1TkSjvCBoUQukj7ZkllTdSzwVFUmQJ0DE22NlQn0W
IM7KFQCe1xTyj5T2oAoZ9C6gIScHQ3NX18lPnFusjpoTzMgyIRfsM4rQlGpeeQh0
0EBufnZvJA5a9O1P8dS8Q9ohgTOWVUNIMAzMixPLKqGCgJm9ee9uIV3uucRCUy0=
=qcQf
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Rename Shell buffer with current directory
[not found] ` <52A58F09.1010409-vfylz/Ys1k4@public.gmane.org>
@ 2013-12-09 12:22 ` Sebastien Vauban
2013-12-09 12:56 ` Rainer M Krug
` (2 more replies)
0 siblings, 3 replies; 11+ messages in thread
From: Sebastien Vauban @ 2013-12-09 12:22 UTC (permalink / raw
To: Rainer M Krug; +Cc: help-gnu-emacs-mXXj517/zsQ
Hi Rainer,
Rainer M Krug wrote:
>> Michael Heerdegen wrote:
>>>> (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)
>>> ^
>>>> However, that does not change the end result: the name of the
>>>> buffer is unchanged.
>>>
>>> Why do you use a non-nil LOCAL parameter for `add-hook'? Without
>>> it, your code works for me.
>>
>> So does it for me -- thanks for your help!
>>
>> Though, I still don't understand why making the
>> `my-rename-buffer-to-curdir' function buffer-local makes the above
>> fail... Remember that that function gets called (see the message
>> displayed in the echo area), only the function `rename-buffer'
>> fails...
>
> Thanks - I am using your code, and it works very nicely - very useful.
You're welcome.
Though, I just realized it also renames R buffers (as it is bound to comint
mode). I'll have to make some exceptions there.
As well, it does not handle (yet) the problem of two Shell buffers in the same
directory, as the name won't be unique. Not sure what's the most
straightforward approach for this one. Maybe looking at `uniquify' or so.
Best regards,
Seb
--
Sebastien Vauban
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Rename Shell buffer with current directory
2013-12-09 12:22 ` Sebastien Vauban
@ 2013-12-09 12:56 ` Rainer M Krug
2013-12-09 18:16 ` Michael Heerdegen
[not found] ` <mailman.8695.1386613044.10748.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 11+ messages in thread
From: Rainer M Krug @ 2013-12-09 12:56 UTC (permalink / raw
To: Sebastien Vauban; +Cc: help-gnu-emacs
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 12/09/13, 13:22 , Sebastien Vauban wrote:
> Hi Rainer,
>
> Rainer M Krug wrote:
>>> Michael Heerdegen wrote:
>>>>> (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)
>>>> ^
>>>>> However, that does not change the end result: the name of
>>>>> the buffer is unchanged.
>>>>
>>>> Why do you use a non-nil LOCAL parameter for `add-hook'?
>>>> Without it, your code works for me.
>>>
>>> So does it for me -- thanks for your help!
>>>
>>> Though, I still don't understand why making the
>>> `my-rename-buffer-to-curdir' function buffer-local makes the
>>> above fail... Remember that that function gets called (see the
>>> message displayed in the echo area), only the function
>>> `rename-buffer' fails...
>>
>> Thanks - I am using your code, and it works very nicely - very
>> useful.
>
> You're welcome.
>
> Though, I just realized it also renames R buffers (as it is bound
> to comint mode). I'll have to make some exceptions there.
I realized the same - that's why I disabled it just now. Please post
your enhancements here, as this is a very useful function.
>
> As well, it does not handle (yet) the problem of two Shell buffers
> in the same directory, as the name won't be unique. Not sure what's
> the most straightforward approach for this one. Maybe looking at
> `uniquify' or so.
True - realised the same with the R buffers...
Cheers,
Rainer
>
> Best regards, Seb
>
- --
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)
Centre of Excellence for Invasion Biology
Stellenbosch University
South Africa
Tel : +33 - (0)9 53 10 27 44
Cell: +33 - (0)6 85 62 59 98
Fax : +33 - (0)9 58 10 27 44
Fax (D): +49 - (0)3 21 21 25 22 44
email: Rainer@krugs.de
Skype: RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.22 (Darwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQEcBAEBAgAGBQJSpb4FAAoJENvXNx4PUvmCK/wIAKDoskc3ItfwfEBuXgeotAcT
RnKav0JkULQDSmldaSuCuH25bmo3/k1+BJRYiffHKCmO5tY1KSLmC3GuBwLC1tpy
YmwA0TZO7kQ7PLAreKgC5nW2Qb3dhyCol4RjeqsHeApCnPCRSV8Rhv/cd9fN3GbI
Mfsx/HPjjM/DuPYq0kL13nX1IIzbINdEBk6gCdCoo6y3lgXWRU0iiOAAdq5XkxHF
9f2m64e58rPI/u3Bo7o14wyOxUtyg1NxM1Qc5d+hdGW3e4bxEc7gPMVOLt2/YX+D
p8vuVqGlHwZP4/akwJn7C7e72wiQhFLcW1rbyjbgm5Wu1rlL1wzK4uzA5hzHMro=
=GHKH
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Rename Shell buffer with current directory
2013-12-09 12:22 ` Sebastien Vauban
2013-12-09 12:56 ` Rainer M Krug
@ 2013-12-09 18:16 ` Michael Heerdegen
[not found] ` <mailman.8695.1386613044.10748.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 11+ messages in thread
From: Michael Heerdegen @ 2013-12-09 18:16 UTC (permalink / raw
To: help-gnu-emacs
"Sebastien Vauban" <sva-news@mygooglest.com>
writes:
> >>> Why do you use a non-nil LOCAL parameter for `add-hook'? Without
> >>> it, your code works for me.
> >>
> Though, I just realized it also renames R buffers (as it is bound to comint
> mode). I'll have to make some exceptions there.
Oh, that's clear, silly me. So, you must indeed use the local
parameter. I think something like this should DTRT:
--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
(lambda ()
(my-rename-buffer-to-curdir)
(add-hook 'comint-output-filter-functions
#'my-rename-buffer-to-curdir nil t)))
--8<---------------cut here---------------end--------------->8---
> As well, it does not handle (yet) the problem of two Shell buffers in
> the same directory, as the name won't be unique. Not sure what's the
> most straightforward approach for this one. Maybe looking at
> `uniquify' or so.
How do you want it to behave?
Regards,
Michael.
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Rename Shell buffer with current directory
[not found] ` <mailman.8695.1386613044.10748.help-gnu-emacs@gnu.org>
@ 2013-12-09 18:44 ` Sebastien Vauban
2013-12-09 19:31 ` Michael Heerdegen
0 siblings, 1 reply; 11+ messages in thread
From: Sebastien Vauban @ 2013-12-09 18:44 UTC (permalink / raw
To: help-gnu-emacs-mXXj517/zsQ
Hello Michael,
Michael Heerdegen wrote:
> "Sebastien Vauban" <sva-news-D0wtAvR13HarG/iDocfnWg@public.gmane.org> writes:
>
>> >>> Why do you use a non-nil LOCAL parameter for `add-hook'? Without
>> >>> it, your code works for me.
>
>> Though, I just realized it also renames R buffers (as it is bound to comint
>> mode). I'll have to make some exceptions there.
>
> Oh, that's clear, silly me. So, you must indeed use the local
> parameter.
Did you understand why `rename-buffer' wasn't working in the local version,
then?
> I think something like this should DTRT:
> (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
> (lambda ()
> (my-rename-buffer-to-curdir)
> (add-hook 'comint-output-filter-functions
> #'my-rename-buffer-to-curdir nil t)))
I'll try it, and come back to you... Thanks for your help.
>> As well, it does not handle (yet) the problem of two Shell buffers in
>> the same directory, as the name won't be unique. Not sure what's the
>> most straightforward approach for this one. Maybe looking at
>> `uniquify' or so.
>
> How do you want it to behave?
I guess the best option would be to work like the default Shell buffer naming;
so, for example:
*shell ~/Public/Repositories/org-mode/lisp*
*shell ~/Public/Repositories/org-mode/lisp <2>*
or something similar.
Best regards,
Seb
--
Sebastien Vauban
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Rename Shell buffer with current directory
2013-12-09 18:44 ` Sebastien Vauban
@ 2013-12-09 19:31 ` Michael Heerdegen
0 siblings, 0 replies; 11+ messages in thread
From: Michael Heerdegen @ 2013-12-09 19:31 UTC (permalink / raw
To: help-gnu-emacs
"Sebastien Vauban" <sva-news@mygooglest.com>
writes:
> Did you understand why `rename-buffer' wasn't working in the local version,
> then?
`add-hook' with the local argument adds functions corresponding to the
hook version locally to the current buffer. If you eval what you had in
scratch, the function was added to the hook variable there, the shell
buffer didn't see it.
Dunno however why you got a message as you said. Hard to reconstruct
that now, since I don't know exactly what you did. If you want to have
that clarified, please send a recipe.
Regards,
Michael.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2013-12-09 19:31 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-07 8:06 Rename Shell buffer with current directory Sebastien Vauban
2013-12-07 20:58 ` Michael Heerdegen
[not found] ` <mailman.8479.1386449940.10748.help-gnu-emacs@gnu.org>
2013-12-08 20:36 ` Sebastien Vauban
2013-12-08 21:32 ` Michael Heerdegen
[not found] ` <mailman.8618.1386538352.10748.help-gnu-emacs@gnu.org>
2013-12-09 8:36 ` Sebastien Vauban
2013-12-09 9:36 ` Rainer M Krug
[not found] ` <52A58F09.1010409-vfylz/Ys1k4@public.gmane.org>
2013-12-09 12:22 ` Sebastien Vauban
2013-12-09 12:56 ` Rainer M Krug
2013-12-09 18:16 ` Michael Heerdegen
[not found] ` <mailman.8695.1386613044.10748.help-gnu-emacs@gnu.org>
2013-12-09 18:44 ` Sebastien Vauban
2013-12-09 19:31 ` Michael Heerdegen
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.