dir-grep improved; ignore_suffix improved

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-06-09 02:12:07 -04:00
parent 1120424255
commit 4f52a89a22
4 changed files with 27 additions and 3 deletions

8
BUGS
View File

@ -1,5 +1,13 @@
=== OUSTANDING BUGS ===
2009/06/09:
1. many of the dir-mode methods need better names, to make it clear they
aren't general purpose.
2. need a "refresh-screen" command.
3. headers work poorly with some indenting schemes.
2009/06/04:
change the mode-detection order--using the "in-file" override should be
able to override a positive match on file extension, filename, etc.

View File

@ -197,7 +197,8 @@ class Application(object):
curses.def_prog_mode()
def _load_config_defaults(self):
self.config['ignore_suffix'] = ['~', '-']
self.config['ignore_suffix'] = ['~', '-', 'CVS', '.svn', '.git', '.hg']
self.config['error_timeout'] = -1
self.config['max_error_len'] = 192
self.config['max_num_kills'] = 64

View File

@ -1,4 +1,5 @@
import commands, dirutil, grp, method, mode, os.path, pwd, re
import util
import buffer, buffer.fs
from window import Window
from lex import Grammar, PatternRule, RegionRule, PatternMatchRule
@ -72,9 +73,16 @@ class OpenPath(Method):
class DirGrep(Method):
args = [Argument('pattern', datatype="str", prompt="Pattern: ")]
def _execute(self, w, **vargs):
cmd = 'grep -rEl %r %r' % (vargs['pattern'], w.buffer.path)
cmd = 'grep -rEl "%s" %r' % (vargs['pattern'], w.buffer.path)
(status, output) = commands.getstatusoutput(cmd)
paths = [x for x in output.split('\n') if x]
paths = []
suffixes = w.application.config['ignore_suffix']
for path in output.split('\n'):
if not path or util.should_ignore_path(path, suffixes):
continue
paths.append(path)
bufname = '*%s*' % self.name.title()
b = buffer.fs.PathListBuffer(bufname, paths)
b.modename = 'dir'

View File

@ -14,6 +14,13 @@ def flatzip(a, b):
l.append(y)
return l
def should_ignore_path(path, suffixes):
for name in path.split('/'):
for suffix in suffixes:
if name.endswith(suffix):
return True
return False
def normal_path(path):
#path = os.path.realpath(path)
path = os.path.normpath(path)