From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: August Karlstrom Newsgroups: gmane.emacs.help Subject: Re: Finding Unused Identifiers Date: Sat, 04 Mar 2006 19:19:46 GMT Organization: Telia Internet Message-ID: References: <4406fc36$0$11610$3b214f66@tunews.univie.ac.at> <1YDNf.5345$F56.2416@newsread3.news.atl.earthlink.net> <1kwdawrs69lxs$.1nqpbp8apcebt.dlg@40tude.net> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1141686657 9618 80.91.229.2 (6 Mar 2006 23:10:57 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 6 Mar 2006 23:10:57 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 07 00:10:56 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FGOqo-00070d-3r for geh-help-gnu-emacs@m.gmane.org; Tue, 07 Mar 2006 00:10:50 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FGOqn-0002jp-EB for geh-help-gnu-emacs@m.gmane.org; Mon, 06 Mar 2006 18:10:49 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!bloom-beacon.mit.edu!npeer.de.kpn-eurorings.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newspeer2.se.telia.net!se.telia.net!masternews.telia.net.!newsb.telia.net.POSTED!not-for-mail User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051013) X-Accept-Language: en-us, en Original-Newsgroups: gnu.emacs.help In-Reply-To: <1kwdawrs69lxs$.1nqpbp8apcebt.dlg@40tude.net> Original-Lines: 67 Original-NNTP-Posting-Host: 83.250.237.84 Original-X-Complaints-To: abuse@telia.com Original-X-Trace: newsb.telia.net 1141499986 83.250.237.84 (Sat, 04 Mar 2006 20:19:46 CET) Original-NNTP-Posting-Date: Sat, 04 Mar 2006 20:19:46 CET Original-Xref: shelby.stanford.edu gnu.emacs.help:137926 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:33569 Archived-At: Peter Tury wrote: > As the first easiest(?) step it might help if you generate a list of all > words what has only one instance in that file (and that instance is in an > outermost defvar...)? If the list would have a form what is usable in > compilation mode, then one could go throught it easily and check what > should really be removed... I wrote the following, which basically does what I want: (defconst my-elisp-global-decl-re (concat "^[ \t]*(" (regexp-opt '("defconst" "defimage" "defmacro" "defsubst" "defun" "defvar")) "[ \t]+\\<\\(\\w+\\)\\>")) (defun my-elisp-unused-globals () "Return a list of unused global identifiers. Returns a list of global identifiers in the current buffer declared with defconst, defimage, defmacro, defsubst, defun or defvar that are never accessed in the same buffer. Requires that no local identifier uses the same name as a global identifier." (let ((pos nil) (res nil) (id nil)) (save-excursion (beginning-of-buffer) (setq pos (re-search-forward my-elisp-global-decl-re nil t)) (while (not (null pos)) (save-excursion (setq id (match-string-no-properties 1)) (setq pos (re-search-forward (concat "\\<" id "\\>") nil t)) (when (null pos) (setq pos (re-search-backward (concat "\\<" id "\\>") nil t 2))) (when (null pos) (setq res (cons id res)))) (setq pos (re-search-forward my-elisp-global-decl-re nil t)))) res)) (defun my-elisp-list-unused-globals () "Display the list returned by `my-elisp-unused-globals'. Output is written to a separate buffer." (interactive) (let ((unused-globals (my-elisp-unused-globals)) (buffer nil)) (setq buffer (get-buffer-create "*Elisp Unused Globals*")) (when (= (count-windows) 1) (split-window)) (other-window 1) (switch-to-buffer buffer) (erase-buffer) (if (null unused-globals) (insert "No unused global identifiers found.") (insert "Found unused global identifier(s):\n\n") (mapc '(lambda (x) (insert x) (newline)) unused-globals) (switch-to-buffer buffer)))) August -- I am the "ILOVEGNU" signature virus. Just copy me to your signature. This email was infected under the terms of the GNU General Public License.