Emacs: Inconsistency of Search Features

By Xah Lee. Date: . Last updated: .

This page discuss inconsistency of the many emacs features related to text search (grep).

Emacs has many commands related to searching text. For example: {list-matching-lines, grep, rgrep, lgrep, grep-find, find-dired, dired-do-search, …}. However, their interface are inconsistent. Their implementation is also inconsistent.

Interface Inconsistency

The interface isn't consistent. For example: grep and grep-find (with alias find-grep) both directly prompt you to enter unix command in one shot. But {find-dired, rgrep, lgrep} do several prompts asking for: {search string, file extension, directory}. (though, they still require user to be familiar with the unix commands. For example: When find-dired prompts “Run find (with args):”, you have to give -name "*html" or -type f etc.)

People who are not unix sys admin or unix programer won't be able to search a folder. The unix find/grep parameters are quite complex, and emacs documentation doesn't try to explain them.

Implementation Inconsistency

list-matching-lines (alias of occur) is implemented with elisp, while the others rely on unix utilities {grep, find}.

Calling external util has lots problems under Microsoft Windows. On Windows, external utilities may not be installed. Searching text is a critical feature of emacs. Then, there's Cygwin, MinGW and other variety issues. Emacs has to go thru several layers to interface with them.

On unix/linux including Mac OS X, BSD, there's also complex issues of identifying the version of grep/find used, which differ in options and behavior. I recall that rgrep didn't work on Mac OS X around year 2007.

Then, emacs has to process the output to make syntax coloring. Also, if your search string contains Unicode, then there's complex problem about locale/encoding setup, environment variable setup and inheritance issues among shell/OS/emacs.

[see Problems of Calling Unix grep in Emacs]

Suggestion: Unified Interface and Implemented in Emacs Lisp

It seems to me, they could all use elisp, with a single code engine, and with the same interface. The files to be searched can be from buffer list or dired marked files, or entered from prompt with emacs regex. The output can be a output like occur or can be dired list or buffer list. For example, you could have a command list-matching-lines, and then “list-matching-lines-directory” with options to do nested dirs, and options to use a pattern to filter files to search for, or options to get marked files in dired, and also options to show result as file list in dired.

These text searching task is what emacs lisp is designed to do, and is trivial to implement. It would eliminate the whole external program problems.

The core are already in emacs. occur, dired-do-query-replace-regexp, dired-do-search, and probably something in eshell too. They are just scattered and not unified.

Emacs Lisp Speed Issues?

Doing it inside elisp is not that slow. Slower than those written in C, but remember that emacs has to parse their output and the communication overhead might just make it up. I've written a grep command in elisp [see Elisp: Write grep]. Just tested now, calling it on a dir with subdir with total of 1592 files. Using a search word that returns over a thousand files. Both my script and unix util are close to 3 seconds. (For example, Alt+x shell in emacs, then give grep -c */*html) Calling grep -c */*html by shell-command is less than 1 second. Calling grep -c */*html by emacs's grep is about 3 seconds too.

(this article was originally posted to 《comp.emacs》 At http://groups.google.com/group/comp.emacs/browse_frm/thread/9458d26644fde3e4)

This report applies to GNU Emacs

Emacs Modernization

  1. Simple Changes Emacs Should Adopt
  2. Why Emacs Keys are Painful
  3. Problems of the Scratch Buffer
  4. M-key Notation vs Alt+key Notation
  5. Menu Problem
  6. Mode Line Problem
  7. cua-mode Problems
  8. kill-buffer Induces Buffer Accumulation
  9. Emacs Form Feed ^L
  10. Inconsistency of Search Features
  11. Single Key to Delete Whole Line
  12. Emacs HTML Mode Sucks
  13. Emacs Does Not Support Viewing Images Files In Windows
  14. Emacs Spell Checker Problems
  15. Adopt HTML as Texinfo Replacement
  16. Support HTML Mail
  17. Problems of “man” Command
  18. Emacs Lisp Mode Syntax Coloring Problem
  19. Emacs Ahk Mode Problems
  20. Problems of Emacs's Manual
  21. Problems of Emacs's Manual; Examples
  22. Emacs: Have You Read Emacs Manual?
  23. Elisp: Ban Syntax Table
  24. Emacs: Make elisp-index-search use Current Symbol
  25. Emacs: Usability Problems of Mode Documentation
  26. Problems of Emacswiki
  27. Emacs GNU Texinfo Problems; Invalid HTML
  28. A Record of Frustration in IT Industry; Disappearing FSF URLs, 2006
  29. Emacs Manual Node Persistency Issues
  30. Emacs: dired-do-query-replace-regex Replace ALL (fixed)
  31. Problems of Emacs Supporting Obsolete Systems
  32. Elisp: Function to Copy/Delete a Dir Recursively (fixed)
  33. Thoughts on Common Lisp Scheme Lisp Based Emacs
  34. Text Editors Popularity and Market Research
  35. Text Editor's Cursor Movement Behavior (emacs, vi, Notepad++)
  36. GNU Emacs Development Inefficiency
  37. Emacs Dev Inefficiency and Emacs Web 2.0?
  38. Letter-Case Commands Usability Problems
  39. Emacs: Select Line, between Quotes, Extend Selection
  40. Emacs: isearch Current Word
  41. Suggestions on Line Wrap Commands
  42. Emacs: Single Key to Delete Whole Line
  43. Emacs Cult Problem: Emacs vs Windows Notepad
  44. Emacs Undo and Emacs Cult Problem

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp