How do I start emacs with a command and its option, for example, I want emacs start with entering gdb mi mode, otherwise it does not go to the gdb mode during startup.

The following works:

emacs gdb

Or using evaluate:

emacs gdb -e gdb

But I want to enter the mi mode and this does not work:

emacs gdb -i=mi

Or this:

emacs -e gdb -i=mi

Unfortunately I just want to enter mi mode directly during startup.

  • Use a .emacs file or init.el file and customize it, or learn how to pass arguments from the command line that include elisp. If you do a bit of Googling, you will find a zillion hits. E.g., Evaluate emacs lisp expession on command line stackoverflow.com/questions/11474774/… – lawlist Nov 10 '16 at 6:24
  • I want to enter gdb mi mode on startup not after startup to enter gdb mi manually – phonycollectibles Nov 10 '16 at 6:26
  • @lawlist But how can I also include -i=mi, evaluate does not work on that but I really need to enter the text gui mode during startup. – phonycollectibles Nov 10 '16 at 6:55
  • 1
    The following link has an example that you can work with and modify as needed: stackoverflow.com/questions/35577536/gdb-in-emacs-24-messed-up You should be using Emacs 25 at this point unless there is a good reason for using an earlier version. – lawlist Nov 10 '16 at 7:03

The following works:

emacs --eval "(gdb \"gdb -i=mi\")"
  • 2
    Using simple quotes removes the need for backslash escapes. Also, you can include executable name in that command emacs --eval '(gdb "gdb -i=mi ./myexecutable")' & . You might be interested also in -x option of gdb that starts a specific script. Or include source localgdbscript in your ~/.gdbinit so that a localgdbscript in your local directory is automatically run. – Stéphane Gourichon Mar 10 '17 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.