help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding Unused Identifiers


From: August Karlstrom
Subject: Re: Finding Unused Identifiers
Date: Sun, 05 Mar 2006 16:05:00 GMT
User-agent: Mozilla Thunderbird 1.0.7 (X11/20051013)

Markus Triska wrote:
The comment "that are never accessed in the same buffer" is also incorrect:

(defvar falsepositive 0)

(eval `(print ,(intern (concat "false" "positive"))))

==>

Found unused global identifier(s):

falsepositive


Hyphenated identifiers can yield false negatives:

(defvar has-hyphen 0)

(print 'has)

==>

No unused global identifiers found.

Thanks Markus for your remarks. When I tested my functions I had previously changed the syntax class for `-' to "w" (word) and then forgot that, so I never noticed the problem. I wonder why the syntax class of dash is not "word" by default in LISP buffers.

Here is a corrected version:

(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 occur only
once in the same buffer.  Requires that no local identifier uses
the same name as a global identifier."
  (let ((pos nil)
        (res nil)
        (id nil)
        (saved-syntax (char-syntax ?-)))
    (modify-syntax-entry ?- "w")
    (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))))
    (modify-syntax-entry ?- (string saved-syntax))
    res))


Regards,

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.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]