unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Re: How to insert buffer name into buffer
  2005-11-06 15:40 How to insert buffer name into buffer bturnip
@ 2005-11-06 15:34 ` Bastien
  2005-11-06 15:45   ` bturnip
  2005-11-06 15:47 ` ken
  1 sibling, 1 reply; 6+ messages in thread
From: Bastien @ 2005-11-06 15:34 UTC (permalink / raw)


bturnip@i.hate.spam writes:

> So if I open a new buffer called world_domination.c and then call my
> function, the result looks something like this:

Is (insert (buffer-name)) enough ?

-- 
Bastien

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

* How to insert buffer name into buffer
@ 2005-11-06 15:40 bturnip
  2005-11-06 15:34 ` Bastien
  2005-11-06 15:47 ` ken
  0 siblings, 2 replies; 6+ messages in thread
From: bturnip @ 2005-11-06 15:40 UTC (permalink / raw)


I am writing a little function that fills out some of my code
documentation for me.  What I want to do is take the buffer name and
insert it into the comment block.  So if I open a new buffer called
world_domination.c and then call my function, the result looks something like
this:

/* * * * * * * * * * * * * * * * * * * * *
 * File name: world_domination.c
 * Author: bturnip
 * File date: 11/11/2011
.
.
.
etc

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

* Re: How to insert buffer name into buffer
  2005-11-06 15:34 ` Bastien
@ 2005-11-06 15:45   ` bturnip
  2005-11-06 16:05     ` Harald Hanche-Olsen
  0 siblings, 1 reply; 6+ messages in thread
From: bturnip @ 2005-11-06 15:45 UTC (permalink / raw)


That was 100% exactly what I was wanted.  Thanks!

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

* Re: How to insert buffer name into buffer
  2005-11-06 15:40 How to insert buffer name into buffer bturnip
  2005-11-06 15:34 ` Bastien
@ 2005-11-06 15:47 ` ken
  1 sibling, 0 replies; 6+ messages in thread
From: ken @ 2005-11-06 15:47 UTC (permalink / raw)



This function should get you part of the way there:

(defun file-name-into-kill-buffer ()
"Put path/filename of current buffer onto kill-ring so to paste
into an X application."
(interactive)
     (let ((str (buffer-file-name)))
       (and str
            (kill-new str)
            (message "Copied %s to kill ring" str)))
)



On Sun, 06 Nov 2005 09:40:08 -0600
bturnip <bturnip@i.hate.spam> wrote:

> I am writing a little function that fills out some of my code
> documentation for me.  What I want to do is take the buffer name and
> insert it into the comment block.  So if I open a new buffer called
> world_domination.c and then call my function, the result looks
> something like this:
> 
> /* * * * * * * * * * * * * * * * * * * * *
>  * File name: world_domination.c
>  * Author: bturnip
>  * File date: 11/11/2011
> .
> .
> .
> etc
> _______________________________________________
> Help-gnu-emacs mailing list
> Help-gnu-emacs@gnu.org
> http://lists.gnu.org/mailman/listinfo/help-gnu-emacs


-- 
A lot of us are working harder than we want, at things we don't like to
do.  Why? ...In order to afford the sort of existence we don't care to
live.
	-- Bradford Angier

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

* Re: How to insert buffer name into buffer
  2005-11-06 15:45   ` bturnip
@ 2005-11-06 16:05     ` Harald Hanche-Olsen
  2005-11-06 16:43       ` François Fleuret
  0 siblings, 1 reply; 6+ messages in thread
From: Harald Hanche-Olsen @ 2005-11-06 16:05 UTC (permalink / raw)


+ "bturnip" <bturnip@gmail.com>:

| That was 100% exactly what I was wanted.  Thanks!

Well, you should be aware that (insert (buffer-name)) just might
insert something like "world_domination.c<3>", if you really are into
this world domination stuff.

Here is an alternative solution:

(defun insert-buffer-file-name ()
  "Insert the current buffer's file name, or the buffer name if the buffer
is not visiting a file."
  (interactive)
  (insert
   (let ((fn (buffer-file-name)))
     (if (and fn (string-match "^.*/\\([^/]+\\)$" fn))
	 (substring fn (match-beginning 1) (match-end 1))
       (buffer-name)))))

-- 
* Harald Hanche-Olsen     <URL:http://www.math.ntnu.no/~hanche/>
- Debating gives most of us much more psychological satisfaction
  than thinking does: but it deprives us of whatever chance there is
  of getting closer to the truth.  -- C.P. Snow

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

* Re: How to insert buffer name into buffer
  2005-11-06 16:05     ` Harald Hanche-Olsen
@ 2005-11-06 16:43       ` François Fleuret
  0 siblings, 0 replies; 6+ messages in thread
From: François Fleuret @ 2005-11-06 16:43 UTC (permalink / raw)



<Harald Hanche-Olsen> wrote on 06 Nov 2005 17:05:57 MET:

> Well, you should be aware that (insert (buffer-name)) just might
> insert something like "world_domination.c<3>", if you really are into
> this world domination stuff.

You're right. He was probably more looking for

 (insert (buffer-file-name))

,------------------
| buffer-file-name is a built-in function.
| (buffer-file-name &optional BUFFER)
| 
| Return name of file BUFFER is visiting, or nil if none.
| No argument or nil as argument means use the current buffer.
`------------------

Cheers,

-- 
François Fleuret                          http://cvlab.epfl.ch/~fleuret

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

end of thread, other threads:[~2005-11-06 16:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-06 15:40 How to insert buffer name into buffer bturnip
2005-11-06 15:34 ` Bastien
2005-11-06 15:45   ` bturnip
2005-11-06 16:05     ` Harald Hanche-Olsen
2005-11-06 16:43       ` François Fleuret
2005-11-06 15:47 ` ken

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).