* insert-file-name-into-minibuffer
@ 2019-02-09 14:39 Alexander Klimov
2019-02-09 14:50 ` insert-file-name-into-minibuffer Eli Zaretskii
2019-02-17 7:09 ` insert-file-name-into-minibuffer Marcin Borkowski
0 siblings, 2 replies; 9+ messages in thread
From: Alexander Klimov @ 2019-02-09 14:39 UTC (permalink / raw)
To: emacs-devel
It is quite common to insert the name of the current file into the
argument of shell-command or compile command (both use
read-shell-command). I wonder what it the preferred way to do it?
I currently use the following to allow M-. or C-u M-. to be used to
insert the file name or its full path:
(defun insert-file-name-into-minibuffer (full-path)
(interactive "P")
(let ((path (buffer-file-name (window-buffer (minibuffer-selected-window)))))
(insert (if full-path
path
(file-name-nondirectory path)))))
(define-key minibuffer-local-map (kbd "M-.") 'insert-file-name-into-minibuffer)
--
Regards,
ASK
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: insert-file-name-into-minibuffer
2019-02-09 14:39 insert-file-name-into-minibuffer Alexander Klimov
@ 2019-02-09 14:50 ` Eli Zaretskii
2019-02-09 21:30 ` insert-file-name-into-minibuffer Alexander Klimov
2019-02-17 7:09 ` insert-file-name-into-minibuffer Marcin Borkowski
1 sibling, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2019-02-09 14:50 UTC (permalink / raw)
To: Alexander Klimov; +Cc: emacs-devel
> Date: Sat, 9 Feb 2019 14:39:36 +0000
> From: Alexander Klimov <alserkli@inbox.ru>
>
> It is quite common to insert the name of the current file into the
> argument of shell-command or compile command (both use
> read-shell-command). I wonder what it the preferred way to do it?
Doesn't M-n in the minibuffer already do that?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: insert-file-name-into-minibuffer
2019-02-09 14:50 ` insert-file-name-into-minibuffer Eli Zaretskii
@ 2019-02-09 21:30 ` Alexander Klimov
2019-02-09 21:38 ` insert-file-name-into-minibuffer Marcin Borkowski
0 siblings, 1 reply; 9+ messages in thread
From: Alexander Klimov @ 2019-02-09 21:30 UTC (permalink / raw)
To: emacs-devel
On Sat, 9 Feb 2019, Eli Zaretskii wrote:
> > It is quite common to insert the name of the current file into the
> > argument of shell-command or compile command (both use
> > read-shell-command). I wonder what it the preferred way to do it?
>
> Doesn't M-n in the minibuffer already do that?
Thanks, never knew it works in read-shell-command this way!
OTOH, next-history-element replaces the whole line even if one
already typed `gcc ...' and does not allow to insert the file name
with full path.
Speaking of buffer file names, probably there should also be a more
direct way to copy the full path of the current file than C-x C-f M-n
C-S-backspace.
--
Regards,
ASK
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: insert-file-name-into-minibuffer
2019-02-09 21:30 ` insert-file-name-into-minibuffer Alexander Klimov
@ 2019-02-09 21:38 ` Marcin Borkowski
2019-02-09 21:50 ` insert-file-name-into-minibuffer Alexander Klimov
0 siblings, 1 reply; 9+ messages in thread
From: Marcin Borkowski @ 2019-02-09 21:38 UTC (permalink / raw)
To: Alexander Klimov; +Cc: emacs-devel
On 2019-02-09, at 22:30, Alexander Klimov <alserkli@inbox.ru> wrote:
> On Sat, 9 Feb 2019, Eli Zaretskii wrote:
>> > It is quite common to insert the name of the current file into the
>> > argument of shell-command or compile command (both use
>> > read-shell-command). I wonder what it the preferred way to do it?
>>
>> Doesn't M-n in the minibuffer already do that?
>
> Thanks, never knew it works in read-shell-command this way!
>
> OTOH, next-history-element replaces the whole line even if one
> already typed `gcc ...' and does not allow to insert the file name
> with full path.
>
> Speaking of buffer file names, probably there should also be a more
> direct way to copy the full path of the current file than C-x C-f M-n
> C-S-backspace.
Not entirely what you're looking for, but are you aware of `w', `C-u w'
and `C-u 0 w' in Dired?
Hth,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: insert-file-name-into-minibuffer
2019-02-09 21:38 ` insert-file-name-into-minibuffer Marcin Borkowski
@ 2019-02-09 21:50 ` Alexander Klimov
2019-02-09 21:59 ` insert-file-name-into-minibuffer Marcin Borkowski
0 siblings, 1 reply; 9+ messages in thread
From: Alexander Klimov @ 2019-02-09 21:50 UTC (permalink / raw)
To: emacs-devel
On Sat, 9 Feb 2019, Marcin Borkowski wrote:
> > Speaking of buffer file names, probably there should also be a more
> > direct way to copy the full path of the current file than C-x C-f M-n
> > C-S-backspace.
>
> Not entirely what you're looking for, but are you aware of `w', `C-u w'
> and `C-u 0 w' in Dired?
Yes (M-0 w), but opening Dired (BTW, dired-jump is not bound to C-x
C-j in `emacs -Q') is likely even less direct.
--
Regards,
ASK
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: insert-file-name-into-minibuffer
2019-02-09 21:50 ` insert-file-name-into-minibuffer Alexander Klimov
@ 2019-02-09 21:59 ` Marcin Borkowski
2019-02-09 22:19 ` insert-file-name-into-minibuffer Alexander Klimov
0 siblings, 1 reply; 9+ messages in thread
From: Marcin Borkowski @ 2019-02-09 21:59 UTC (permalink / raw)
To: Alexander Klimov; +Cc: emacs-devel
On 2019-02-09, at 22:50, Alexander Klimov <alserkli@inbox.ru> wrote:
> On Sat, 9 Feb 2019, Marcin Borkowski wrote:
>> > Speaking of buffer file names, probably there should also be a more
>> > direct way to copy the full path of the current file than C-x C-f M-n
>> > C-S-backspace.
>>
>> Not entirely what you're looking for, but are you aware of `w', `C-u w'
>> and `C-u 0 w' in Dired?
>
> Yes (M-0 w), but opening Dired (BTW, dired-jump is not bound to C-x
> C-j in `emacs -Q') is likely even less direct.
Of course, but I thought it might be useful for others reading this.
(And BTW, I fully agree that your use case is legitimate and not covered
by M-n. Otoh, I often run shell commands from Dired, so it's not that
indirect for me.)
Best,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: insert-file-name-into-minibuffer
2019-02-09 21:59 ` insert-file-name-into-minibuffer Marcin Borkowski
@ 2019-02-09 22:19 ` Alexander Klimov
2019-02-13 18:49 ` insert-file-name-into-minibuffer Marcin Borkowski
0 siblings, 1 reply; 9+ messages in thread
From: Alexander Klimov @ 2019-02-09 22:19 UTC (permalink / raw)
To: emacs-devel
On Sat, 9 Feb 2019, Marcin Borkowski wrote:
> > Yes (M-0 w), but opening Dired (BTW, dired-jump is not bound to C-x
> > C-j in `emacs -Q') is likely even less direct.
>
> Of course, but I thought it might be useful for others reading this.
I use
(defun copy-buffer-file-name-as-kill (&optional nondirectory)
(interactive "P")
(let ((f (buffer-file-name)))
(when nondirectory
(setq f (file-name-nondirectory f)))
(kill-new f)
(message "%s" f)))
IMO it would be nice to have something like this bound to some key in
`emacs -Q'; as well as something like insert-file-name-into-minibuffer
because it is common to recall that you need the buffer file name only
once you already started typing the compilation command. Furthermore,
M-n does not insert buffer file name in M-x compile.
--
Regards,
ASK
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: insert-file-name-into-minibuffer
2019-02-09 22:19 ` insert-file-name-into-minibuffer Alexander Klimov
@ 2019-02-13 18:49 ` Marcin Borkowski
0 siblings, 0 replies; 9+ messages in thread
From: Marcin Borkowski @ 2019-02-13 18:49 UTC (permalink / raw)
To: Alexander Klimov; +Cc: emacs-devel
On 2019-02-09, at 23:19, Alexander Klimov <alserkli@inbox.ru> wrote:
> On Sat, 9 Feb 2019, Marcin Borkowski wrote:
>> > Yes (M-0 w), but opening Dired (BTW, dired-jump is not bound to C-x
>> > C-j in `emacs -Q') is likely even less direct.
>>
>> Of course, but I thought it might be useful for others reading this.
>
> I use
>
> (defun copy-buffer-file-name-as-kill (&optional nondirectory)
> (interactive "P")
> (let ((f (buffer-file-name)))
> (when nondirectory
> (setq f (file-name-nondirectory f)))
> (kill-new f)
> (message "%s" f)))
Nice, and really useful! I'm going to put it in my init.el, thanks.
> IMO it would be nice to have something like this bound to some key in
> `emacs -Q'; as well as something like insert-file-name-into-minibuffer
> because it is common to recall that you need the buffer file name only
> once you already started typing the compilation command. Furthermore,
> M-n does not insert buffer file name in M-x compile.
+1
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: insert-file-name-into-minibuffer
2019-02-09 14:39 insert-file-name-into-minibuffer Alexander Klimov
2019-02-09 14:50 ` insert-file-name-into-minibuffer Eli Zaretskii
@ 2019-02-17 7:09 ` Marcin Borkowski
1 sibling, 0 replies; 9+ messages in thread
From: Marcin Borkowski @ 2019-02-17 7:09 UTC (permalink / raw)
To: Alexander Klimov; +Cc: emacs-devel
On 2019-02-09, at 15:39, Alexander Klimov <alserkli@inbox.ru> wrote:
> It is quite common to insert the name of the current file into the
> argument of shell-command or compile command (both use
> read-shell-command). I wonder what it the preferred way to do it?
>
> I currently use the following to allow M-. or C-u M-. to be used to
> insert the file name or its full path:
>
> (defun insert-file-name-into-minibuffer (full-path)
> (interactive "P")
> (let ((path (buffer-file-name (window-buffer (minibuffer-selected-window)))))
> (insert (if full-path
> path
> (file-name-nondirectory path)))))
> (define-key minibuffer-local-map (kbd "M-.") 'insert-file-name-into-minibuffer)
Hi, it seems I reinvented your code and written about it on my blog:
http://mbork.pl/2019-02-17_Inserting_the_current_file_name_at_point
(don't worry, you get the credit). Thanks again!
Best,
--
Marcin Borkowski
http://mbork.pl
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2019-02-17 7:09 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-02-09 14:39 insert-file-name-into-minibuffer Alexander Klimov
2019-02-09 14:50 ` insert-file-name-into-minibuffer Eli Zaretskii
2019-02-09 21:30 ` insert-file-name-into-minibuffer Alexander Klimov
2019-02-09 21:38 ` insert-file-name-into-minibuffer Marcin Borkowski
2019-02-09 21:50 ` insert-file-name-into-minibuffer Alexander Klimov
2019-02-09 21:59 ` insert-file-name-into-minibuffer Marcin Borkowski
2019-02-09 22:19 ` insert-file-name-into-minibuffer Alexander Klimov
2019-02-13 18:49 ` insert-file-name-into-minibuffer Marcin Borkowski
2019-02-17 7:09 ` insert-file-name-into-minibuffer Marcin Borkowski
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.