How can I reload .emacs after changing it?

前端 未结 18 854
余生分开走
余生分开走 2020-12-12 08:51

How can I get Emacs to reload all my definitions that I have updated in .emacs without restarting Emacs?

相关标签:
18条回答
  • 2020-12-12 09:40

    If you've got your .emacs file open in the currently active buffer:

    M-x eval-buffer
    0 讨论(0)
  • 2020-12-12 09:42

    I'm currently on Ubuntu 15.04; I like to define a key for this.
    [M-insert] translates to alt-insert on my keyboard.
    Put this in your .emacs file:

    (global-set-key [M-insert] '(lambda() (interactive) (load-file "~/.emacs")))
    
    0 讨论(0)
  • 2020-12-12 09:43

    Very strange that the very convenient

    M-x eval-buffer

    is not mentioned here.

    It immediately evaluates all code in the buffer, its the quickest method, if your .emacs is idempotent.

    0 讨论(0)
  • 2020-12-12 09:44

    Keyboard shortcut:

    (defun reload-init-file ()
      (interactive)
      (load-file user-init-file))
    
    (global-set-key (kbd "C-c C-l") 'reload-init-file)    ; Reload .emacs file
    
    0 讨论(0)
  • 2020-12-12 09:44

    If you happen to have a shell opened inside Emacs, you can also do:

    . ~/.emacs
    

    May save a few key strokes.

    0 讨论(0)
  • 2020-12-12 09:45

    solution

    M-: (load user-init-file)


    notes

    • you type it in Eval: prompt (including the parentheses)
    • user-init-file is a variable holding the ~/.emacs value (pointing to the configuration file path) by default
    • (load) is shorter, older, and non-interactive version of (load-file); it is not an emacs command (to be typed in M-x) but a mere elisp function

    conclusion

    M-: > M-x

    0 讨论(0)
提交回复
热议问题