From: "Ehud Karni" <ehud@unix.simonwiesel.co.il>
Cc: bug-gnu-emacs@gnu.org, gnu-emacs-sources@gnu.org
Subject: Re: insert current buffer name anywhere vs. M-p M-n
Date: Tue, 16 Apr 2002 13:22:03 +0300 [thread overview]
Message-ID: <200204161022.g3GAM3A03107@unix.simonwiesel.co.il> (raw)
In-Reply-To: <m2r8lg9svk.fsf_-_@jidanni.org> (message from Dan Jacobson on 16 Apr 2002 12:20:31 +0800)
On 16 Apr 2002 12:20:31 +0800, Dan Jacobson <jidanni@deadspam.com> 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
prev parent reply other threads:[~2002-04-16 10:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-11 17:47 find-alternate-file from dired wildcard dir Dan Jacobson
2002-04-12 16:07 ` Kevin Rodgers
2002-04-12 18:18 ` Kevin Rodgers
2002-04-16 4:20 ` insert current buffer name anywhere vs. M-p M-n Dan Jacobson
2002-04-16 10:22 ` Ehud Karni [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200204161022.g3GAM3A03107@unix.simonwiesel.co.il \
--to=ehud@unix.simonwiesel.co.il \
--cc=bug-gnu-emacs@gnu.org \
--cc=gnu-emacs-sources@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).