Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 127079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:25:11+00:00 2026-05-11T05:25:11+00:00

I use shell-command a lots (default binded to M-!), but often I’m doing stuff

  • 0

I use shell-command a lots (default binded to M-!), but often I’m doing stuff to the buffer I’m currently editing. Instead of typing the buffer name (and no filename completion is available in shell-command, alas!), it’d be nice to have a shortcut key, say f3, to insert that name for me whenever I press the key.

The problem is I don’t want to bind the key globally (I use f3 for other things in other context), only in minibuffer when shell-command is prompting. It’s easy to write a lisp function to insert the current buffer name, but what mode’s keymap should I modify to bind a key to that function?

Alternatively, is there any lisp code/package that provide filename completion in shell-command, similar to how bash does it? I know the normal M-x shell does completion, but the convenience of entering a command in minibuffer is hard to give up 😉

Edit:

here is what I wanted, taken from huaiyuan‘s answer with some fixes inspired by / stolen from http://osdir.com/ml/emacs.sources/2002-04/msg00022.html

(define-key minibuffer-local-map   [f3] (lambda () (interactive)         (insert (buffer-name (current-buffer-not-mini)))))  (defun current-buffer-not-mini ()   'Return current-buffer if current buffer is not the *mini-buffer*   else return buffer before minibuf is activated.'   (if (not (window-minibuffer-p)) (current-buffer)       (if (eq (get-lru-window) (next-window))           (window-buffer (previous-window)) (window-buffer (next-window))))) 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T05:25:11+00:00Added an answer on May 11, 2026 at 5:25 am
    (define-key minibuffer-local-map   [f3] (lambda () (interactive) (insert (buffer-name)))) 

    Edit:

    As pointed out in the comment section and elsewhere, the above code snippet doesn’t work. (Sorry, I should have tested it before posting. 🙂 Some fixes have been posted; here is another:

    (define-key minibuffer-local-map [f3]   (lambda () (interactive)       (insert (buffer-name (window-buffer (minibuffer-selected-window)))))) 

    Regarding filename completion while issuing shell-command, perhaps this kludge would work (it works for me on Emacs 23.0.60):

    (require 'shell) (define-key minibuffer-local-map (kbd 'C-i') 'comint-dynamic-complete) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 154k
  • Answers 155k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer That's normal on most (if not all) POSIX systems. Rename… May 12, 2026 at 10:36 am
  • Editorial Team
    Editorial Team added an answer It all depends on the semantics of what you are… May 12, 2026 at 10:36 am
  • Editorial Team
    Editorial Team added an answer Attaching to the service should work, so I'm not sure… May 12, 2026 at 10:36 am

Related Questions

I use shell-command a lots (default binded to M-!), but often I'm doing stuff
First of all: I am not an experienced ClearCase user, but I have lots
I have a strange (don't ask) need to see a few examples of a
I wrote a quick program in python to add a gtk GUI to a
I've created a question about this a few days . My solution is something

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.