Question

How can I have emacs start and be in the middle of a command input? Particularly, I want emacs to start in the middle of a command input find-file with a message in the small buffer saying:

Find file: ~/

and the cursor at the last character of it so that I can continue typing the remaining path to open the file I want.

Was it helpful?

Solution

I have to admit that my lisp is a bit rusty, but this works for me. Drop it in your ~/.emacs file (or whatever init file you are using):

(add-hook 'emacs-startup-hook
          (lambda ()
            (if (= (length command-line-args) 1)
                  (call-interactively 'find-file))))

If you call emacs with no arguments, like this:

sawa@localhost:~$ emacs

It will invoke find-file for you. If, on the other hand, you invoke emacs with an argument, such as a filename, like this:

sawa@localhost:~$ emacs somefile.txt

It will default to just visiting somefile.txt

OTHER TIPS

You can execute one of the following commands on the command prompt or make a shell script containing it appropriately:

$ emacs -f find-file         # if you want to start Emacs in the current direcoty
$ (cd ~; emacs -f find-file) # if you want to start Emacs in your home diretory

From the emacs(1) man page:

-f function, --funcall function

Excute the lisp function function

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top