Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

non-numeric arguments in emacs

Tags:

emacs

Is there a way to pass non-numeric argument to functions?

Ex: C-u 5 M-x eshell makes(switches to) a eshell with name *eshell*<5>. But I want to give a name instead of number to eshell buffer.

like image 367
egor7 Avatar asked May 13 '26 01:05

egor7


1 Answers

I don't think there is any general way to pass non-numeric arguments to any command the same way C-u works.

However, different modes can get input using the minibuffer. For example, C-u M-x shell (rather than eshell) lets you name your new shell buffer.

You can easily write your own eshell command that also lets you name the buffer:

(defun eshell-new-buffer (name) 
  (interactive "sBuffer name:")
  (eshell t)
  (rename-buffer name))

Then bind it to some key:

(global-set-key (kbd "C-c e") 'eshell-new-buffer)

Now when you type C-c e, you will be prompted for a buffer name and a new eshell buffer with that name will be created for you.

Edit: Simplified the code as @sanityinc helpfully pointed out.

like image 140
Tikhon Jelvis Avatar answered May 16 '26 12:05

Tikhon Jelvis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!