From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Ehud Karni" Newsgroups: gmane.emacs.bugs Subject: Re: insert current buffer name anywhere vs. M-p M-n Date: Tue, 16 Apr 2002 13:22:03 +0300 Organization: Mivtach-Simon Insurance agencies Sender: bug-gnu-emacs-admin@gnu.org Message-ID: <200204161022.g3GAM3A03107@unix.simonwiesel.co.il> References: <3CB70635.620302DC@ihs.com> <3CB724F0.FBB19D10@ihs.com> Reply-To: ehud@unix.simonwiesel.co.il NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-8 Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1018952651 2263 127.0.0.1 (16 Apr 2002 10:24:11 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Tue, 16 Apr 2002 10:24:11 +0000 (UTC) Cc: bug-gnu-emacs@gnu.org, gnu-emacs-sources@gnu.org Return-path: Original-Received: from fencepost.gnu.org ([199.232.76.164]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 16xQ8A-0000aO-00 for ; Tue, 16 Apr 2002 12:24:10 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 16xQ8G-0001lY-00; Tue, 16 Apr 2002 06:24:16 -0400 Original-Received: from unix.simonwiesel.co.il ([192.114.178.12] helo=bsw1.) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 16xQ6O-0001dd-00; Tue, 16 Apr 2002 06:22:21 -0400 Original-Received: from unix.simonwiesel.co.il (beta [10.253.0.3]) by bsw1. (8.9.3/8.9.3) with ESMTP id NAA26590 for ; œTue, 16 Apr 2002 13:22:17 +0300 Original-Received: (from ehud@localhost) by unix.simonwiesel.co.il (8.11.6/8.11.4) id g3GAM3A03107; Tue, 16 Apr 2002 13:22:03 +0300 Original-To: jidanni@yam.com.tw In-Reply-To: (message from Dan Jacobson on 16 Apr 2002 12:20:31 +0800) X-Mailer: Emacs 21.1.1 rmail (send-msg 1.106) Errors-To: bug-gnu-emacs-admin@gnu.org X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.0.9 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Bug reports for GNU Emacs, the Swiss army knife of text editors List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.bugs:696 X-Report-Spam: http://spam.gmane.org/gmane.emacs.bugs:696 On 16 Apr 2002 12:20:31 +0800, Dan Jacobson wrote: > > Anyways, all the more argument for a set of keybindings that can > insert the current file, or current file name, or dired file on line name, or > recent-file-excluding-minibuffer-itself name, at point. C-u for full > path. Wouldn't that save hacking all the different places it is > needed? > > It could be integrated with C-x r register stuff, but care should be > taken that the keystrokes don't get too long. Here are some functions that can insert the current word, buffer name, file name or directory name into the minibuf (as a bonus there is a function for selecting from minibuf history). I think, I already posted it to emacs.sources, but anyway here it is. Ehud. ;;needed in insert-word-or-file-name (defun backward-to-non-blank () "go to 1st non blank (after blank) to left" (interactive) (if (re-search-backward "[ \t\n][^ \t\n]" (point-min) t) (forward-char 1) (if (string-match "[^ \t\n]" (buffer-substring 1 2)) (goto-char (point-min))))) ;;needed in insert-buffer/file/dir-name functions (defun buffer-name-not-mini () "Return the name of current buffer, as a string. If current buffer is the *mini-buffer* return name of previous-window." (buffer-name (if (window-minibuffer-p) (if (eq (get-lru-window) (next-window)) (window-buffer (previous-window)) (window-buffer (next-window))) nil))) (defun insert-word-or-file-name () "copy word cursor is on or file name to minibuff input" (interactive) (let* ((bfl (current-buffer)) (str "")) (set-buffer (buffer-name-not-mini)) (cond ((eq major-mode 'dired-mode) (setq str (dired-get-filename t t))) (t (let (bch ech) (forward-char 1) (backward-to-non-blank) (setq bch (point)) (re-search-forward "[^ \t\n][ \t\n]" (point-max) t) (setq ech (1- (point))) (setq str (buffer-substring bch ech))))) (set-buffer bfl) (insert str))) (defun insert-buffer-name () "insert buffer name of current buffer or most recent buffer when in minibuffer" (interactive) (insert (buffer-name-not-mini))) (defun insert-buffer-dir-name () "insert dir name of current buffer or most recent buffer when in minibuffer" (interactive) (let* ((bfn (buffer-file-name (get-buffer (buffer-name-not-mini))))) (if bfn (insert (file-name-directory bfn))))) (defun insert-buffer-file-name () "insert file name of current buffer or most recent buffer when in minibuffer" (interactive) (let* ((bfn (buffer-file-name (get-buffer (buffer-name-not-mini))))) (if bfn (insert (file-name-nondirectory bfn))))) (defun complete-from-minibuffer-history () "Take the history list and make it available as a `completions' buffer" (interactive) (with-output-to-temp-buffer "*Completions*" (display-completion-list (symbol-value minibuffer-history-variable)) (save-excursion (set-buffer standard-output) (setq completion-base-size 0)))) (defun insert-current-date-time-minibuf () "insert the current date and time into mini-buffer." (interactive) (insert (format-time-string "%y%m%d_%H%M%S" (current-time)))) (defun keymap-test (var) ; internal function for keymap checking (and (boundp var) (keymapp (symbol-value var)))) (let ((minimaps (apropos-internal "mini" 'keymap-test)) map op) (while minimaps (setq map (symbol-value (car minimaps))) (setq minimaps (cdr minimaps)) (setq op (lookup-key map [9])) ;tab char (^I) (if op (define-key map '[tab] op)) (define-key map "\C-b" 'insert-buffer-name) (define-key map "\C-d" 'insert-buffer-dir-name) (define-key map "\C-f" 'insert-buffer-file-name) (define-key map "\C-w" 'insert-word-or-file-name) (define-key map "\C-t" 'insert-current-date-time-minibuf) (define-key map "\eh" 'complete-from-minibuffer-history))) -- Ehud Karni Tel: +972-3-7966-561 /"\ Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign Insurance agencies (USA) voice mail and X Against HTML Mail http://www.mvs.co.il FAX: 1-815-5509341 / \ mailto:ehud@unix.simonwiesel.co.il Better Safe Than Sorry