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

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

Re: emacs equivalent of vi %


From: Kevin Rodgers
Subject: Re: emacs equivalent of vi %
Date: Thu, 14 Aug 2008 19:38:15 -0600
User-agent: Thunderbird 2.0.0.16 (Macintosh/20080707)

Rustom Mody wrote:
Thanks folks!  Heres the code I have:

(define-key minibuffer-local-map "%" 'percentsub)
(defun percentsub ()
  (interactive)
  (insert (file-name-nondirectory
           (buffer-file-name
            (window-buffer (minibuffer-selected-window))))))

Prior to Lennarts suggestion I had hacked together
(cadr (buffer-list))
in place of the last line which was of course quite unacceptable

Any further suggested improvements?  I guess this is going to fail in
some cases when theres no filename...

As it should, no?  You can get a more informative error with

        (insert (or (file-name-nondirectory ...)
                    (error "Selected buffer is not visiting a file")))

or you can get a default value inserted (here ".") with

        (insert (or (file-name-nondirectory ...)
                    "."))

--
Kevin Rodgers
Denver, Colorado, USA





reply via email to

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