all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: August Karlstrom <fusionfive@comhem.se>
Subject: Re: Finding Unused Identifiers
Date: Sat, 04 Mar 2006 19:19:46 GMT	[thread overview]
Message-ID: <mLlOf.47072$d5.203079@newsb.telia.net> (raw)
In-Reply-To: <1kwdawrs69lxs$.1nqpbp8apcebt.dlg@40tude.net>

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.

  parent reply	other threads:[~2006-03-04 19:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-02 13:31 Finding Unused Identifiers August Karlstrom
2006-03-02 14:07 ` Markus Triska
2006-03-02 15:13   ` B. T. Raven
2006-03-02 17:18     ` Markus Triska
2006-03-02 22:25     ` August Karlstrom
2006-03-03  8:39       ` Peter Tury
2006-03-03 11:25         ` Pascal Bourguignon
2006-03-03 13:31           ` Markus Triska
2006-03-04  2:21             ` Pascal Bourguignon
2006-03-04 15:20               ` Markus Triska
2006-03-04 19:19         ` August Karlstrom [this message]
2006-03-05  3:15           ` August Karlstrom
2006-03-05 15:13             ` Markus Triska
2006-03-05 16:05               ` August Karlstrom
2006-03-08 18:43                 ` Kevin Rodgers
     [not found]                 ` <mailman.88.1141843635.2832.help-gnu-emacs@gnu.org>
2006-03-09 13:08                   ` August Karlstrom

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='mLlOf.47072$d5.203079@newsb.telia.net' \
    --to=fusionfive@comhem.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.