How to restore default function in Emacs?

I changed the beep (defun beep () ..., can I return it without restarting Emacs?

+4
source share
3 answers

Just visit the original definition and evaluate it.

If you need to, you can run a second instance of Emacs to find the code: C-h f beep RETand follow the link to the source code.

(I usually say find-function, but in this case, beep is an alias, and after the link you get to the string defalias, while the find function goes to the source definition.)

+2
source

, (symbol-function 'ding). , ( fset). , , ding (aka beep) C, Lisp.

Lisp, , @phils.

+1

It may be an accident, but I can do it now using

(defun restore-redefined-function (name)
  (interactive (find-function-read))
  (save-window-excursion
    (find-function name)
    (eval-defun nil)))
  • In *scratch*:

    (defun beep () "foo")
    ;; beep
    
    (symbol-function 'beep)
    ;; (lambda nil "foo")
    
  • M-x restore-redefined-functionand enter beep.

  • in *scratch*:

    (symbol-function 'beep)
    ;; ding
    
0
source

Source: https://habr.com/ru/post/1528824/


All Articles