8

I write/modify code in multiple file formats like Python, MySQL, Perl, HTML, CSS, PHP, JavaScript, AutoHotkey, etc.

I often search my personal library of source code for examples of syntax or complex logic for reuse in new code. Sometimes I search for cryptic strings like =~, because I am searching for a particular regular expression in one of my Perl programs.

Sometimes I search existing code using Copernic, but unfortunately it can only search for words and automatically ignores any programming syntax. It also lacks programming language syntax color coding.

My question is: How do you search through your own libraries of source code? What software is good for this? Copernic is imperfect, but still the best tool I have yet found for this purpose.

Grep and grep-like solutions are nice, but I am most interested in programs with a UI and available in Windows.

2
  • I use Total Commander (you could also use Double Commander], which is free) and hit ALT + F7 to search. Of course, I get a lot more features than just search from TC, and never use the Windows Explorer.
    – Mawg
    Dec 6, 2017 at 8:21
  • You can also try Search Monkey although it is more full featured for Linux than Windows
    – Mawg
    Dec 6, 2017 at 8:26

6 Answers 6

4

Semantic Designs' Source Code Search Engine (SCSE) uses language specific scanners to break each source file into its constituent lexemes, indexes everything, and then provides a GUI-based search across the code base in terms of language elements.

This has the advantage of ignoring (language-specific) whitespace and comments in searches except where you want to include them, being able to search for numbers and strings in terms of their actual values in a language-independent way rather than a specific text variant, etc. The indexing allows searches across millions of lines and tens of thousands of files nearly instantly.

In contrast, a grep-like solution, using an extremely fast FSA, will open and read every file under some root directory. Getting grep to ignore all the files that are not text can be hard if there are many extensions or no extensions. Opening tens of thousands of files and reading them with grep takes a long time (tens of seconds). You get many false positives because it scans program code as well as comments. You cannot ignore whitespace (linebreaks or comments) easily in a regexp so they are hard to write.

In short, SCSE searches faster than grep, using queries that are easier to write, with fewer false positive results.

  • Indexes files according to language-specific lexemes
  • Queries can be stated in mixture of language-generic ("identifier") or language-specific entities ("picture-string" in COBOL)
  • Queries skip whitespace and comments
  • Fewer false positives, much faster search than grep
  • Logging ability allows on to record matches
  • Click on hits to see found text in file source
  • Can configure to launch editor on found files in found locations
  • Indexer runs on Windows; results can be shared across multiple users
  • Java-based GUI runs on Windows and Linux

Screen shot of search across Linux code base

Full disclosure: I'm the principal at Semantic Designs

3

I use grep. As I store all my code under the same path on my filesystem I open up my linux shell (but that will work via cygwin on windows as well) and cd to the directory.

Grep is a very sophisticated text search tool that can search for all kinds of text and has no limit to what you want to look for.

Your =~ would be searched like this:

grep -r "=~" .

Whereas the . references the current directory, -r makes the search recursive. So, if you have your programs grouped by language you could cd into your perl directory and search only there.

grep does have downsides, the first would be the speed. It doesn't have an index so each search goes sequentially over all your code until something is hit. Mostly I have a rough idea on where the specific code I look for would be so I only grep over the appropriate directories.

Another downside is complexity. To become good with this approach you will need to spend some time with them.

grep becomes more and more useful the more linux/unix commands you know. You could for example use find to find all the files you want (like all perl files) and then use grep to know if somethings in there. I (as a Java developer) sometimes need to search for a class file inside a jar, but have like gazillions of jars lying around and don't know where it is. So I happen to have a command line that finds jars, lists their contents and outputs only those that have the required file in them. I could use the same technique to also search through the content of the files etc.

So for this specific problem: grep. But in general I recommend the whole toolchain that comes with your unix.

3

I tend to use Agent Ransack for this.

  • Free
  • Microsoft Windows XP (SP3)/2003/Vista/2008/7/2012/8/8.1
  • Supports regular expressions on file name and query text
  • Preview matching line from files within search window
  • Options to export results, and save search criteria

Screenshot

Screenshot of Agent Ransack window

1

You can try CodeSearch since it is made specifically for such purpose. Features include:

  • Cross-platform
  • Open source
  • Indexes your source code files for faster search
  • Supports regular expressions
  • Supports searching for code syntax
  • Has an Emacs package so you can run it from inside your editor
1

Here are few useful tools:

  • ack which is a tool like grep, optimized for programmers,
  • rak is a grep replacement in pure Ruby,
  • grin can help to search directories full of source code (Python based),
  • The Silver Searcher is a tool for searching code (a clone of Ack, but the feature sets have since diverged slightly).
1
  • 1
    It might be worth mentioning that grin supports the full python re and by default skips .git, .svn, etc. directories. Apr 4, 2016 at 6:06
1

I have learned to rely heavily on inforapid search & replace Link

At first I was really sceptical about this because the UI looks really old(2003, working with windows 10),but after using it a few times I realized that the programm was the answer to all my problems and can be used for all kind of purposes.

  • search and or replace
  • in all file types
  • over several subfolders
  • freeware for private license
  • commercial license 25€
  • fast search
  • filepath, file & (multiple)-line declarations
  • save search session
  • start multiple search sessions simultaneous

enter image description here

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.