all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Possible to hook into Emacs's buffer name generation?
@ 2011-02-18  0:28 Sean McAfee
  2011-02-18  1:37 ` Leo
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Sean McAfee @ 2011-02-18  0:28 UTC (permalink / raw)
  To: help-gnu-emacs

Lately I've been doing a lot of editing inside a large source
repository.  Sometimes I'll have different versions of the same source
file open at the same time, and it's a bit of a hassle to have to keep
in mind whether the older or the newer version is the one with a "<2>"
after its name in the mode line.

I thought it might be cool to have Emacs automatically name buffers that
are visiting files in my repository with a trailing "<component-x.y.z>"
when I open them, where component-x.y.z is simply the closest directory
name above the file that matches that pattern.  I could do this by
adding a hook to find-file-hooks and renaming the buffer according to my
scheme, but it seems cleaner to tell Emacs how to generate the desired
buffer name in the first place.  I've traced the code from find-file all
the way down to generate-new-buffer-name, but I can't find anywhere I
can interpose my buffer-naming logic.

Did I miss something, or am I out of luck?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Possible to hook into Emacs's buffer name generation?
  2011-02-18  0:28 Possible to hook into Emacs's buffer name generation? Sean McAfee
@ 2011-02-18  1:37 ` Leo
  2011-02-18  9:13   ` Tassilo Horn
  2011-02-18  1:37 ` Óscar Fuentes
       [not found] ` <mailman.5.1297993074.2625.help-gnu-emacs@gnu.org>
  2 siblings, 1 reply; 6+ messages in thread
From: Leo @ 2011-02-18  1:37 UTC (permalink / raw)
  To: help-gnu-emacs

On 2011-02-18 08:28 +0800, Sean McAfee wrote:
> Lately I've been doing a lot of editing inside a large source
> repository.  Sometimes I'll have different versions of the same source
> file open at the same time, and it's a bit of a hassle to have to keep
> in mind whether the older or the newer version is the one with a "<2>"
> after its name in the mode line.
>
> I thought it might be cool to have Emacs automatically name buffers that
> are visiting files in my repository with a trailing "<component-x.y.z>"
> when I open them, where component-x.y.z is simply the closest directory
> name above the file that matches that pattern.  I could do this by
> adding a hook to find-file-hooks and renaming the buffer according to my
> scheme, but it seems cleaner to tell Emacs how to generate the desired
> buffer name in the first place.  I've traced the code from find-file all
> the way down to generate-new-buffer-name, but I can't find anywhere I
> can interpose my buffer-naming logic.
>
> Did I miss something, or am I out of luck?

Maybe you can build on top of uniquify.el?

Leo




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Possible to hook into Emacs's buffer name generation?
  2011-02-18  0:28 Possible to hook into Emacs's buffer name generation? Sean McAfee
  2011-02-18  1:37 ` Leo
@ 2011-02-18  1:37 ` Óscar Fuentes
       [not found] ` <mailman.5.1297993074.2625.help-gnu-emacs@gnu.org>
  2 siblings, 0 replies; 6+ messages in thread
From: Óscar Fuentes @ 2011-02-18  1:37 UTC (permalink / raw)
  To: Sean McAfee; +Cc: help-gnu-emacs

Sean McAfee <eefacm@gmail.com> writes:

[snip]

> I thought it might be cool to have Emacs automatically name buffers that
> are visiting files in my repository with a trailing "<component-x.y.z>"
> when I open them, where component-x.y.z is simply the closest directory
> name above the file that matches that pattern.

See if this helps:

C-h v uniquify-buffer-name-style

> I could do this by
> adding a hook to find-file-hooks and renaming the buffer according to my
> scheme, but it seems cleaner to tell Emacs how to generate the desired
> buffer name in the first place.  I've traced the code from find-file all
> the way down to generate-new-buffer-name, but I can't find anywhere I
> can interpose my buffer-naming logic.

The mechanism proposed above advises `create-file-buffer':

(defadvice create-file-buffer (after create-file-buffer-uniquify activate)
  "Uniquify buffer names with parts of directory name."
...

That is in the last lines of lisp/uniquify.el



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Possible to hook into Emacs's buffer name generation?
  2011-02-18  1:37 ` Leo
@ 2011-02-18  9:13   ` Tassilo Horn
  0 siblings, 0 replies; 6+ messages in thread
From: Tassilo Horn @ 2011-02-18  9:13 UTC (permalink / raw)
  To: help-gnu-emacs

Leo <sdl.web@gmail.com> writes:

> Maybe you can build on top of uniquify.el?

I'm using that, which does the trick.

  (require 'uniquify)
  (setq uniquify-buffer-name-style 'post-forward-angle-brackets)

,----[ C-h v uniquify-buffer-name-style RET ]
| uniquify-buffer-name-style is a variable defined in `uniquify.el'.
| Its value is post-forward-angle-brackets
| Original value was nil
| 
| Documentation:
| If non-nil, buffer names are uniquified with parts of directory name.
| The value determines the buffer name style and is one of `forward',
| `reverse', `post-forward', or `post-forward-angle-brackets'.
| For example, files `/foo/bar/mumble/name' and `/baz/quux/mumble/name'
| would have the following buffer names in the various styles:
|   forward        bar/mumble/name  quux/mumble/name
|   reverse        name\mumble\bar  name\mumble\quux
|   post-forward   name|bar/mumble  name|quux/mumble
|   post-forward-angle-brackets   name<bar/mumble>  name<quux/mumble>
|   nil            name  name<2>
| Of course, the "mumble" part may be stripped as well, depending on the setting
| of `uniquify-strip-common-suffix'.
`----

Bye,
Tassilo




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Possible to hook into Emacs's buffer name generation?
       [not found] ` <mailman.5.1297993074.2625.help-gnu-emacs@gnu.org>
@ 2011-02-20 23:37   ` Sean McAfee
  2011-02-21  1:32     ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Sean McAfee @ 2011-02-20 23:37 UTC (permalink / raw)
  To: help-gnu-emacs

Leo <sdl.web@gmail.com> writes:

> On 2011-02-18 08:28 +0800, Sean McAfee wrote:
>> I thought it might be cool to have Emacs automatically name buffers that
>> are visiting files in my repository with a trailing "<component-x.y.z>"
>> when I open them, where component-x.y.z is simply the closest directory
>> name above the file that matches that pattern.

> Maybe you can build on top of uniquify.el?

I hadn't known of uniquify, but after some experimentation it seems not
to offer everything I'd like.  In particular, I want a trailing
component-x.y.z on the buffer name even when I'm not already visiting
the same file in a different directory.  uniquify only steps in when
there's a name conflict.

I wrote a short find-file hook to fix the buffer name, so it's not that
big a deal.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Possible to hook into Emacs's buffer name generation?
  2011-02-20 23:37   ` Sean McAfee
@ 2011-02-21  1:32     ` Stefan Monnier
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2011-02-21  1:32 UTC (permalink / raw)
  To: help-gnu-emacs

> I hadn't known of uniquify, but after some experimentation it seems not
> to offer everything I'd like.  In particular, I want a trailing
> component-x.y.z on the buffer name even when I'm not already visiting
> the same file in a different directory.  uniquify only steps in when
> there's a name conflict.

Depending on your needs, uniquify-min-dir-content might do the trick.


        Stefan


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-02-21  1:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-18  0:28 Possible to hook into Emacs's buffer name generation? Sean McAfee
2011-02-18  1:37 ` Leo
2011-02-18  9:13   ` Tassilo Horn
2011-02-18  1:37 ` Óscar Fuentes
     [not found] ` <mailman.5.1297993074.2625.help-gnu-emacs@gnu.org>
2011-02-20 23:37   ` Sean McAfee
2011-02-21  1:32     ` Stefan Monnier

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.