简体   繁体   中英

How can I load changes of .el file at startup in Emacs?

I have installed Emacs under Windows 7 and want to use it in my everyday work. Unfortunately Emacs world and other text editors world are completely different and I am getting stuck on every third sequence of keys pressed on keyboard - it's doing something that I don't expect it would do.

I want to make a panic command - when I press ESC ESC ESC it stops doing everything, quitting from minibuffer, stops entering command, unhighlight regexps, etc. It already does what I want, except it killing buffers, the layout of my workspace. So I modified keyboard-escape-quit function in simple.el file (found it by Ch k ESC ESC ESC)

(defun keyboard-escape-quit ()
  "Exit the current \"mode\" (in a generalized sense of the word).
   This command can exit an interactive command such as `query-replace',
   can clear out a prefix argument or a region,
   can get out of the minibuffer or other recursive edit,
   cancel the use of the current buffer (for special-purpose buffers),
   or go back to just one window (by deleting all but the selected window)."
  (interactive)
  ; Stop highlighting regexp
  (unhighlight-regexp)
  (cond ((eq last-command 'mode-exited) nil)
    ((region-active-p)
     (deactivate-mark))
    ((> (minibuffer-depth) 0)
     (abort-recursive-edit))
     (current-prefix-arg
     nil)
    ((> (recursion-depth) 0)
     (exit-recursive-edit))
     (buffer-quit-function
     (funcall buffer-quit-function))
   ;((not (one-window-p t))
   ; (delete-other-windows))
    ((string-match "^ \\*" (buffer-name (current-buffer)))
     (bury-buffer))))

I have byte-compiled and loaded this file and it works ok. But I can't figure out why it is not loading at startup.

You cannot modify some special built-in libraries, including simple.el . Emacs never actually loads these special libraries from their source or byte code files. Their byte code is directly included in the Emacs executable at build time, by a process called “dumping”. Emacs loads these libraries from its own binary.

Generally, should not modify any built-in libraries anyway. Your risk breakage, and your customizations are lost when you update Emacs.

Instead, do what you are supposed to do: Add custom functions to your init.el .

Hence, instead of modifying the built-in keyboard-escape-quit , create your own function, eg my-emergency-quit , in your init.el , and bind it to a global key, eg Cc q , with

 (global-set-key (kbd "C-c q") #'my-emergency-quit)

Some final words of advice: I do not think that such a panic command does any good. The first rule of Emacs is: Don't panic. If you are stuck, don't try to quit and kill everything. Rather, try to find out why you are stuck, and how to get “un-stuck” by normal means. You'll learn Emacs better this way, imho.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM