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: Wed, 13 Aug 2008 20:04:33 -0600
User-agent: Thunderbird 2.0.0.16 (Macintosh/20080707)

Lennart Borgman (gmail) wrote:
Nikolaj Schumacher wrote:
Nikolaj Schumacher <address@hidden> wrote:

"Rustom Mody" <address@hidden> wrote:

Bind the character '%' to
(file-name-nondirectory (buffer-file-name))
Also, note that you'll need to make an interactive function out of the
form to bind it to a key.

Oups, that's not all...
It won't work, because `buffer-file-name' will of course return the
minibuffer's file name (i.e. none).  I'm currently not aware of an easy
way to get the originating buffer from the minibuffer.  Sorry.


Maybe minibuffer-selected-window + window-buffer?

Brilliant!

(defvar minibuffer-insert-buffer-directory nil)

(defun minibuffer-insert-buffer-file-name ()
  (interactive)
  (unless (minibuffer-window-active-p (selected-window))
    (error "Minibuffer window is not active"))
  (let ((minibuffer-selected-buffer-file-name
         (buffer-file-name (window-buffer (minibuffer-selected-window)))))
    (insert (if minibuffer-insert-buffer-directory
                minibuffer-selected-buffer-file-name
              (file-name-nondirectory minibuffer-selected-buffer-file-name)))))

(define-key minibuffer-local-map "%" 'minibuffer-insert-buffer-file-name)
(define-key minibuffer-local-completion-map "%" nil)

--
Kevin Rodgers
Denver, Colorado, USA





reply via email to

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