all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Generate a new buffer name
@ 2006-11-22  8:00 mopi
  2006-11-22 10:33 ` Mathias Dahl
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: mopi @ 2006-11-22  8:00 UTC (permalink / raw)


Hello friends

I use a lot of different buffers during a normal day. Often I don't
care what their names are, actually I feel that being forced to name
them interrupts me. I'm perfectly happy with the default naming that
other text editors use (Untitled-1, Untitled-2 etc).

I'm trying to replicate this behaviour in emacs. So far I have placed
this in my .emacs:

(global-set-key [(control n)]
		(lambda() (interactive)(switch-to-buffer(get-buffer-create
"Untitled1"))))

This gives me a new buffer named Untitled1. How can I make a variable
that increments so when I press C-n again I get a buffer named
Untitled2 and so on?

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

* Re: Generate a new buffer name
  2006-11-22  8:00 Generate a new buffer name mopi
@ 2006-11-22 10:33 ` Mathias Dahl
  2006-11-22 12:30   ` mopi
  2006-11-22 14:26 ` Perry Smith
  2006-11-22 16:40 ` Kevin Rodgers
  2 siblings, 1 reply; 5+ messages in thread
From: Mathias Dahl @ 2006-11-22 10:33 UTC (permalink / raw)


"mopi" <52hands@gmail.com> writes:

> Hello friends
>
> I use a lot of different buffers during a normal day. Often I don't
> care what their names are, actually I feel that being forced to name
> them interrupts me. I'm perfectly happy with the default naming that
> other text editors use (Untitled-1, Untitled-2 etc).
>
> I'm trying to replicate this behaviour in emacs. So far I have placed
> this in my .emacs:
>
> (global-set-key [(control n)]
> 		(lambda() (interactive)(switch-to-buffer(get-buffer-create
> "Untitled1"))))
>
> This gives me a new buffer named Untitled1. How can I make a variable
> that increments so when I press C-n again I get a buffer named
> Untitled2 and so on?

Maybe you could use `make-temp-name'?

Example:

 (make-temp-name "Untitled-")

  => "Untitled-3744WiN"

It is certainly possible to write a more advanced function that looks
for old "Untitled" buffers and increases the suffix with 1, but the
above might work for you.

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

* Re: Generate a new buffer name
  2006-11-22 10:33 ` Mathias Dahl
@ 2006-11-22 12:30   ` mopi
  0 siblings, 0 replies; 5+ messages in thread
From: mopi @ 2006-11-22 12:30 UTC (permalink / raw)


Thanks. That works great!

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

* Re: Generate a new buffer name
  2006-11-22  8:00 Generate a new buffer name mopi
  2006-11-22 10:33 ` Mathias Dahl
@ 2006-11-22 14:26 ` Perry Smith
  2006-11-22 16:40 ` Kevin Rodgers
  2 siblings, 0 replies; 5+ messages in thread
From: Perry Smith @ 2006-11-22 14:26 UTC (permalink / raw)
  Cc: help-gnu-emacs


[-- Attachment #1.1: Type: text/plain, Size: 1155 bytes --]

On Nov 22, 2006, at 2:00 AM, mopi wrote:

> Hello friends
>
> I use a lot of different buffers during a normal day. Often I don't
> care what their names are, actually I feel that being forced to name
> them interrupts me. I'm perfectly happy with the default naming that
> other text editors use (Untitled-1, Untitled-2 etc).
>
> I'm trying to replicate this behaviour in emacs. So far I have placed
> this in my .emacs:
>
> (global-set-key [(control n)]
> 		(lambda() (interactive)(switch-to-buffer(get-buffer-create
> "Untitled1"))))
>
> This gives me a new buffer named Untitled1. How can I make a variable
> that increments so when I press C-n again I get a buffer named
> Untitled2 and so on?

(defvar next-untitled-buffer-number 0
   "document variable here")

(global-set-key [(control n)]
		(lambda()
		  (interactive)
		  (switch-to-buffer
		   (get-buffer-create
		    (format "Untitled-%d"
			    (setq next-untitled-buffer-number
				  (1+ next-untitled-buffer-number)))))))

Perry Smith ( pedz@easesoftware.com )
Ease Software, Inc. ( http://www.easesoftware.com )

Low cost SATA Disk Systems for IBMs p5, pSeries, and RS/6000 AIX systems



[-- Attachment #1.2: Type: text/html, Size: 7272 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
help-gnu-emacs mailing list
help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Generate a new buffer name
  2006-11-22  8:00 Generate a new buffer name mopi
  2006-11-22 10:33 ` Mathias Dahl
  2006-11-22 14:26 ` Perry Smith
@ 2006-11-22 16:40 ` Kevin Rodgers
  2 siblings, 0 replies; 5+ messages in thread
From: Kevin Rodgers @ 2006-11-22 16:40 UTC (permalink / raw)


mopi wrote:
> Hello friends
> 
> I use a lot of different buffers during a normal day. Often I don't
> care what their names are, actually I feel that being forced to name
> them interrupts me. I'm perfectly happy with the default naming that
> other text editors use (Untitled-1, Untitled-2 etc).
> 
> I'm trying to replicate this behaviour in emacs. So far I have placed
> this in my .emacs:
> 
> (global-set-key [(control n)]
> 		(lambda() (interactive)(switch-to-buffer(get-buffer-create
> "Untitled1"))))
> 
> This gives me a new buffer named Untitled1. How can I make a variable
> that increments so when I press C-n again I get a buffer named
> Untitled2 and so on?

(switch-to-buffer (generate-new-buffer "Untitled"))

-- 
Kevin

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

end of thread, other threads:[~2006-11-22 16:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-11-22  8:00 Generate a new buffer name mopi
2006-11-22 10:33 ` Mathias Dahl
2006-11-22 12:30   ` mopi
2006-11-22 14:26 ` Perry Smith
2006-11-22 16:40 ` Kevin Rodgers

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.