How to find a bug in “.emacs” or “init.el”?

后端 未结 5 1674
小蘑菇
小蘑菇 2020-12-12 18:38

Sometimes when I open Emacs, Emacs initialization fail.
That is because .emacs or init.el files have a bug. (My bugs often come from just misty

5条回答
  •  旧巷少年郎
    2020-12-12 19:20

    I'll add it's good to anticipate. The function below, coming from oremacs.com allows to check the validity of our init file (or any other file) without starting up emacs:

    (defun ora-test-emacs ()
      (interactive)
      (require 'async)
      (async-start
       (lambda () (shell-command-to-string
              "emacs --batch --eval \"
    (condition-case e
        (progn
          (load \\\"~/.emacs\\\")
          (message \\\"-OK-\\\"))
      (error
       (message \\\"ERROR!\\\")
       (signal (car e) (cdr e))))\""))
       `(lambda (output)
          (if (string-match "-OK-" output)
              (when ,(called-interactively-p 'any)
                (message "All is well"))
            (switch-to-buffer-other-window "*startup error*")
            (delete-region (point-min) (point-max))
            (insert output)
            (search-backward "ERROR!")))))
    

    One can even add a Travis CI test.

    ps: solutions summed up on wikemacs.

提交回复
热议问题