mark-naylor-1701

elisp undef

Feb 7th, 2026 (edited)
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.04 KB | None | 0 0
  1. (defun undef--verify (msg sym)
  2.   "Make sure the symbol should be unbound."
  3.   (when (symbolp sym)
  4.     (intern-soft (read-string (concat msg " ") (symbol-name sym)))))
  5.  
  6. (defun undef-variable (&optional sym)
  7.   "Unbind the variable of the supllied symbol or the symbol at the point."
  8.   (interactive (list (undef--verify "Unbind variable:" (symbol-at-point))))
  9.   (when (symbolp sym)
  10.     (makunbound sym)))
  11.  
  12. (defun undef-function (&optional sym)
  13.   "Unbind the function of the supllied symbol or the symbol at the point."
  14.   (interactive (list (undef--verify "Unbind variable:" (symbol-at-point))))
  15.   (when (symbolp sym)
  16.     (fmakunbound sym)))
  17.  
  18. (defun undef-symbol (&optional sym)
  19.   "Unintern the supllied symbol or the symbol at the point."
  20.   (interactive (list (undef--verify "Unbind variable:" (symbol-at-point))))
  21.   (when (symbolp sym)
  22.     (unintern sym obarray)))
  23.  
  24. ;; Suggested key bindings.
  25. (global-set-key (kbd "C-c u v") #'undef-variable)
  26. (global-set-key (kbd "C-c u f") #'undef-function)
  27. (global-set-key (kbd "C-c u s") #'undef-symbol)
  28.  
Advertisement
Add Comment
Please, Sign In to add comment