tags:

views:

118

answers:

4

As an Emacs beginner, I am working on writing a minor mode. My current (naive) method of programming elisp consists of making a change, closing out Emacs, restarting Emacs, and observing the change. How can I streamline this process? Is there a command to refresh everything?

+1  A: 

M-x eval-buffer should do it.

Greg
Eval-buffer reevaluates the code, but the minor mode's behavior does not seem to be updated, even if I turn it off and on again. Is there a command I can use in combination with this one to reload the minor mode?
dvcolgan
Well, I assumed that minor modes worked similar to .emacs file modifications, but I'm clearly wrong. My next guess was that the .emacs would also have to be refreshed- no dice. Guess we'll both need to wait for someone who knows what they're talking about to swing by. Sorry for the wrong attempt.
Greg
+8  A: 

You might try using M-C-x (eval-defun), which will re-evaluate the top-level form around point. Unlike M-x eval-buffer or C-x C-e (exal-last-sexp), this will reset variables declared with defvar and defcustom to their initial values, which might what's tripping you up.

Sean
+1  A: 

It all depends on what you're writing and how you've written it. Toggling the mode should get you the new behavior. If you're using [define-minor-mode][1], you can add code in the body of the macro that keys off the mode variable:

(define-minor-mode my-minor-mode 
  "doc string"
  nil
  ""
  nil
  (if my-minor-mode
      (progn
         ;; do something when minor mode is on
      )
    ;; do something when minor mode is off
    )

But, another way to check it quickly would be to spawn a new Emacs from your existing one:

M-x shell-command emacs&
Trey Jackson
+2  A: 

Also try out C-u C-M-x which evaluates the definition at point and sets a breakpoint there, so you get dropped into the debugger when you hit that function.

M-x ielm is also very useful as a more fetaure-rich Lisp REPL when developing Emacs code.

Joakim Hårsman