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

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

pathreg.el v. 0.0dev --- search an entire path for regexps.


From: D Goel
Subject: pathreg.el v. 0.0dev --- search an entire path for regexps.
Date: Wed, 31 Aug 2005 18:03:44 -0400
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

 pathreg.el --- search an entire path for regexps.



INTRODUCTION:
============
M-x pathreg to search your loadpath (or any other path) for a
regex.   M-, to continue search. A few customizations are provided.



Aside: Remember seeing errors like this? -- 
   Error in process: Not enough arguments for format string

See M-x pathreg-example-bugs-message to see how pervasive the
(message filename) bug is.  Keep in mind that your running emacs
probably does not have access to all the .el files (and may only see
.elc files), else you may find lots more matches. 


This error is so pervasive that I wish that elisp provided a function
'msg' which simply calls (message "%s" arg). A lot of times, an
author accidentally writes code with msg in mind rather than
message. (At least, I often do.)

(If you want to follow up on this discussion, the recent post
 from me on g.e.d titled (message (format "File %s" file))
 might be more appropriate rather than g.e.s.
-----------------------------------------------------
The latest version can be had from
http://gnufans.net/~deego/emacspub/lisp-mine/pathreg .
;;;---------------- CUT HERE -------------------------------

;;; pathreg.el --- search an entire path for regexps.
;; Time-stamp: <2005-08-31 18:01:35 deego>
;; Copyright (C) 2005 D. Goel
;; Emacs Lisp Archive entry
;; Filename: pathreg.el
;; Package: pathreg
;; Author: D. Goel <address@hidden>
;; Keywords:
;; Version:  0.0DEV
;; URL: http://gnufans.net/~deego
;; For latest version:

(defconst pathreg-home-page
  "http://gnufans.net/~deego/emacspub/lisp-mine/pathreg";)


 
;; This file is NOT (yet) part of GNU Emacs.
 
;; This is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
 
;; This is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.
 

;; See also:


(defconst pathreg-version "0.0dev")

;;; Commentary:
(defconst pathreg-introduction
  "M-x pathreg to search your loadpath (or any other path) for a
regex.   M-, to continue search. A few customizations are provided.



Aside: Remember seeing errors like this? -- 
   Error in process: Not enough arguments for format string

See M-x pathreg-example-bugs-message to see how pervasive the
\(message filename) bug is.  Keep in mind that your running emacs
probably does not have access to all the .el files (and may only see
.elc files), else you may find lots more matches. 


This error is so pervasive that I wish that elisp provided a function
'msg' which simply calls (message \"%s\" arg). A lot of times, an
author accidentally writes code with msg in mind rather than
message. (At least, I often do.)

\(If you want to follow up on this discussion, the recent post
 from me on g.e.d titled \(message (format \"File %s\" file))
 might be more appropriate rather than g.e.s."
)
;;;###autoload
(defun pathreg-introduction ()
  "Provides electric help from variable `pathreg-introduction'."
  (interactive)
  (with-electric-help
   '(lambda () (insert pathreg-introduction) nil) "*doc*"))




;;; New features:
(defconst pathreg-new-features
  "Help..."
)

(defun pathreg-new-features ()
  "Provides electric help from variable `pathreg-new-features'."
  (interactive)
  (with-electric-help
   '(lambda () (insert pathreg-new-features) nil) "*doc*"))


;;==========================================
;;; Requires:
(eval-when-compile (require 'cl))

;;; Code:

(defgroup pathreg nil
  "The group pathreg."
  :group 'applications)
(defcustom pathreg-before-load-hook nil
  "Hook to run before loading pathreg."
  :group 'pathreg)
(defcustom pathreg-after-load-hook nil
  "Hook to run after loading pathreg."
  :group 'pathreg)
(run-hooks 'pathreg-before-load-hook)

(defcustom pathreg-verbosity 0
  "How verbose to be.
Once you are experienced with this lib, 0 is the recommended
value.  Values between -90 to +90 are recommended for general use and
the rest for debugging."
  :type 'integer
  :group 'pathreg)
(defcustom pathreg-interactivity 0
  "How interactive to be.
Once you are experienced with this lib, 0 is the recommended
value.  Values between -90 and +90 are recommended for general use and
the rest for debugging."
  :type 'integer
  :group 'pathreg)
(defcustom pathreg-y-or-n-p-function 'pathreg-y-or-n-p
  "Function to use for interactivity-dependent  `y-or-n-p'.
Format same as that of `pathreg-y-or-n-p'."
  :type 'function
  :group 'pathreg)
(defcustom pathreg-n-or-y-p-function 'pathreg-n-or-y-p
  "Function to use for interactivity-dependent `n-or-y-p'.
Format same as that of `pathreg-n-or-y-p'."
  :type 'function
  :group 'pathreg)
(defun pathreg-message (points &rest args)
  "Signal message, depending on POINTS andpathreg-verbosity.
ARGS are passed to `message'."
  (unless (minusp (+ points pathreg-verbosity))
    (apply #'message args)))
(defun pathreg-y-or-n-p (add prompt)
  "Query or assume t, based on `pathreg-interactivity'.
ADD is added to `pathreg-interactivity' to decide whether
to query using PROMPT, or just return t."
  (if (minusp (+ add pathreg-interactivity))
        t
      (funcall 'y-or-n-p prompt)))
(defun pathreg-n-or-y-p (add prompt)
  "Query or assume t, based on `pathreg-interactivity'.
ADD is added to `pathreg-interactivity' to decide whether
to query using PROMPT, or just return t."
  (if (minusp (+ add pathreg-interactivity))
        nil
      (funcall 'y-or-n-p prompt)))




;;; Real Code:

(defcustom pathreg-file-regexp "\\.el$"
  "" :group 'pathreg)

(defcustom pathreg-path-regexp ""
  "" :group 'pathreg)

(defcustom pathreg-path-regexp-not nil
  "" :group 'pathreg)


(defcustom pathreg-path ""
  "When this is not a list, we shall use the loadpath." 
:group 'pathreg)



;;;###autoload
(defun pathreg (reg)
  (interactive "sRegexp to search for: ")
  (tags-search reg 
               (list 'quote (pathreg-get-files))))



(defun pathreg-get-files ()
  (require 'cl)
  (remove-if-not
   (lambda (arg)
     (and
      (or 
       (not pathreg-path-regexp)
       (string-match pathreg-path-regexp 
                     arg))
      (or 
       (not pathreg-path-regexp-not)
       (not 
        (string-match pathreg-path-regexp-not
                      arg)))
      
      (file-regular-p arg)
      (file-readable-p arg)))
   
   (pathreg-get-files1)))


(defun pathreg-get-files1 ()
  (require 'cl)
  (apply 
   #'append 
   (mapcar 
    (lambda (dir)
      (ignore-errors
        (mapcar 
         (lambda (f)
           (expand-file-name f dir))
         (remove-if-not 
          (lambda (f)
            (string-match pathreg-file-regexp f))
          (directory-files dir)))))
    (if (consp pathreg-path)
        pathreg-path
      load-path))))
  



(defun pathreg-example-bug-message ()
  "Try to locate buggy calls to `message'.  These calls usually
involve funcalling `message' directly on a string, which can yield bad
results if the string happens to contain % characters, etc.  

M-, to continue on to the next buggy call."
  
  
  
  (interactive "")
  (let 
      ((pathreg-path-regexp-not nil)
       ;;(pathreg-path-regexp "22.0.50")
       ;;(pathreg-path-regexp "lisp-mine")
       (pathreg-path-regexp "")
       )
    (pathreg
     ;; a call to message whose first arg is neither a direct string,
     ;; nor is nil.  of course, this is a heuristic in a lot of places.
     ;; And some will invariably be false matches, like (message
     ;; message-spec str1 str2) .. in other words, cases where the
     ;; author actually intended the variableto be a format-spec.
     
     
     "(message[ \n\t]+\\([^ \n\t\"n]\\|n[^i]\\|ni[^l]\\)")))
     




(provide 'pathreg)
(run-hooks 'pathreg-after-load-hook)



;;; pathreg.el ends here





reply via email to

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