Article View: gnu.emacs.help
Article #189243Re: Insertion of pathname in minibuffer
From: Piet van Oostrum
Date: Wed, 17 Apr 1991 08:02
Date: Wed, 17 Apr 1991 08:02
45 lines
2805 bytes
2805 bytes
>>>>> halvers@altair.crd.ge.com (Pete Halverson) (PH) writes:
>How can I insert , within a minibuffer command, the pathname of the file
>contained in the current buffer ?
PH> Well, something like the following seems to work:
PH> (defun minibuffer-ins-buffer-file-name ()
PH> "Insert the file name of the current buffer into the minibuffer."
PH> (interactive)
PH> ;; We assume that the second entry in the buffer list is the "real"
PH> ;; current buffer, since "(current-buffer)" just returns the
PH> ;; minibuffer we're in. This is obviously wrong for recursive
PH> ;; minibuffer excursions.
PH> (insert (or (buffer-file-name (car (cdr (buffer-list))))
PH> (beep) "")))
PH> (define-key minibuffer-local-map "\C-c\C-f" 'ins-buffer-file-name)
PH> (define-key minibuffer-local-ns-map "\C-c\C-f" 'ins-buffer-file-name)
PH> (define-key minibuffer-local-must-match-map "\C-c\C-f" 'ins-buffer-file-name)
PH> (define-key minibuffer-local-completion-map "\C-c\C-f" 'ins-buffer-file-name)
1. If you name the function minibuffer-ins-buffer-file-name, you better use
the same name in the define-key's.
2. The problem with recursive minibuffers can easily be circumvented by
searching for the first buffer with a non-nil buffer-file-name:
(defun minibuffer-ins-buffer-file-name ()
"Insert the file name of the current buffer into the minibuffer."
(interactive)
;; We assume that the first entry in the buffer list with a non-nil
;; buffer-file-name is the "real" current buffer, since
;; "(current-buffer)" just returns the minibuffer we're in.
(let ((cbf (cdr (buffer-list))) b-f-name)
(while (and cbf (not (setq b-f-name (buffer-file-name (car cbf)))))
(setq cbf (cdr cbf)))
(if b-f-name
(insert b-f-name)
(beep))))
--
Piet* van Oostrum, Dept of Computer Science, Utrecht University,
Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands.
Telephone: +31 30 531806 Uucp: uunet!mcsun!ruuinf!piet
Telefax: +31 30 513791 Internet: piet@cs.ruu.nl (*`Pete')
Technical Details
Message-ID:
<1991Apr17.080208.17177@cs.ruu.nl>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!hp4nl!alchemy!pietReferences:
<2074@seti.inria.fr> <18561@crdgw1.crd.ge.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103b8b,b1c7cc470582c4dd X-Google-Attributes: gid103b8b,public X-Google-ArrivalTime: 1991-04-17 04:02:33 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!hp4nl!alchemy!piet From: piet@cs.ruu.nl (Piet van Oostrum) Newsgroups: gnu.emacs.help Subject: Re: Insertion of pathname in minibuffer Message-ID: <1991Apr17.080208.17177@cs.ruu.nl> Date: 17 Apr 91 08:02:08 GMT References: <2074@seti.inria.fr> <18561@crdgw1.crd.ge.com> Sender: piet@cs.ruu.nl (Piet van Oostrum) Reply-To: piet@cs.ruu.nl (Piet van Oostrum) Organization: Dept of Computer Science, Utrecht University, The Netherlands Lines: 45 In-Reply-To: halvers@altair.crd.ge.com (Pete Halverson)