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

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

Re: How to insert buffer name into buffer


From: Harald Hanche-Olsen
Subject: Re: How to insert buffer name into buffer
Date: Sun, 06 Nov 2005 17:05:57 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/23.0.0 (berkeley-unix)

+ "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


reply via email to

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