Skip to content

Instantly share code, notes, and snippets.

@dgutov
Last active April 6, 2021 07:20
Show Gist options
  • Save dgutov/5042865 to your computer and use it in GitHub Desktop.
Save dgutov/5042865 to your computer and use it in GitHub Desktop.
Find unused definitions in Emacs Lisp
(defun check-next-def ()
(push-mark nil t)
(when (re-search-forward
(concat "(def\\(?:un\\|macro\\|subst\\|var\\|const\\) "
"\\(\\(?:\\sw\\|\\s_\\)+\\)")
nil 'move)
(save-excursion
(let ((name (match-string 1)))
(goto-char (point-min))
(unless (re-search-forward (concat "\\_<" name "\\_>") nil t 2)
name)))))
(defun find-unused-def ()
(interactive)
(let (name)
(while (and (not (eobp))
(not (setq name (check-next-def)))))
(message "Found! %s" name)))
(global-set-key [f7] 'find-unused-def)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment