Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop execution of .emacs

Tags:

emacs

elisp

Is there anyway to use a command in .emacs that tells Emacs to ignore anything that comes after it?

I am trying to isolate the source of problem in my .emacs file, and commenting in and out code is quite cumbersome.

like image 749
Amelio Vazquez-Reina Avatar asked Aug 19 '14 21:08

Amelio Vazquez-Reina


People also ask

How do I stop a command in Emacs?

Canceling an Action You can use 'C-g' to cancel any action you have started. For some actions, you may need to repeat this. (If even this doesn't clear things up entirely, then try ` C-] ' or 'M-x top-level' ; that should do the trick.)

How do I exit Emacs buffer?

2) Exiting Files in Emacs To close a particular buffer, hit the keys Ctrl + x, followed by k, and then enter the buffer name. To completely close and exit Emacs, hit the keys Ctrl + x, followed by Ctrl + c.

How do I exit Emacs without saving?

To exit emacs, use C-x C-c . It will ask you whether you want to save the changes. To prevent the question, precede the combination with C-u (but it will save the changes). If you want to kill Emacs without saving any changes, you can use the kill-emacs function ( M-x kill-emacs ).

How do I close Emacs editor on Mac?

To close emacs, type C-x, C-c, which is shorthand for typing the Control and x key, followed by the Control and c key.


2 Answers

Put an (error "Done") in your .emacs file at the point where you're bisecting it. You'll get the error that you signaled upon startup, but it will stop emacs from processing the rest of the .emacs file.

@Tom's suggestion about comment-dwim (and @Drew's comment about comment-region) are good ones, but the (error "Done") option has the advantage that you only need to move one line to various points in your .emacs file without commenting/uncommenting other bits of it -- which could get tedious and error-prone.

like image 118
Dan Avatar answered Sep 30 '22 14:09

Dan


Commenting and uncommenting is pretty easy if you use M-;, aka comment-dwim. Just mark the region and type it -- it will comment or uncomment as appropriate.

Alternatively, sure, you can use the trick of wrapping the remainder of the file by putting (quote at the beginning and ) at the end. This will make the rest of the file appear as a constant, and it will just be discarded.

like image 23
Tom Tromey Avatar answered Sep 30 '22 13:09

Tom Tromey