Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

wctxactions: make editor parameter expansion more powerful, with regexp

Added a $SEARCH variable for expansion. If you editor supports searches triggered
from the command line, you can make it highlight the phrase you "grepped" for. In
vim, you can quickly step through all the matches with 'n'.

Changeset bb0f4c168277

Parent 4aa1fd6acfc8

by Steve Borho

Changes to 2 files · Browse files at bb0f4c168277 Showing diff from parent 4aa1fd6acfc8 Diff from another changeset...

 
193
194
195
196
 
197
198
199
 
193
194
195
 
196
197
198
199
@@ -193,7 +193,7 @@
  ' Failing that it uses the first applicable tool it finds.')),   (_('Visual Editor'), 'tortoisehg.editor', genEditCombo,   _('Specify the visual editor used to view files. Format:<br>' - 'myeditor -flags [$FILE --num=$LINENUM] -moreflags<br><br>' + 'myeditor -flags [$FILE --num=$LINENUM][--search $SEARCH]<br><br>'   'See <a href="%s">OpenAtLine</a>'   % 'http://bitbucket.org/tortoisehg/thg/wiki/OpenAtLine')),   (_('CLI Editor'), 'ui.editor', genEditCombo,
 
6
7
8
 
9
10
11
 
117
118
119
120
 
121
122
 
123
124
125
126
127
128
129
130
131
132
133
134
135
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
138
139
 
6
7
8
9
10
11
12
 
118
119
120
 
121
122
123
124
125
126
 
 
 
 
 
 
 
 
 
 
 
 
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
@@ -6,6 +6,7 @@
 # GNU General Public License version 2, incorporated herein by reference.    import os +import re  import subprocess    from mercurial import util, error, merge, commands @@ -117,23 +118,35 @@
 def vdiff(parent, ui, repo, files):   visdiff.visualdiff(ui, repo, files, {})   -def edit(parent, ui, repo, files, lineno=None): +def edit(parent, ui, repo, files, lineno=None, search=None):   files = [util.shellquote(util.localpath(f)) for f in files]   editor = ui.config('tortoisehg', 'editor') + assert len(files) == 1 or lineno == None   if editor:   try: - pre, ln = editor.split('[') - ln, post = ln.split(']') - if lineno is not None: - assert len(files) == 1 # lineno implies one file - ln = ln.replace('$LINENUM', str(lineno)) - if '$FILE' in ln: - ln = ln.replace('$FILE', files[0]) - cmdline = ' '.join([pre, ln, post]) - else: - cmdline = ' '.join([pre, ln, post] + files) - else: - cmdline = ' '.join([pre, post] + files) + regexp = re.compile('\[([^\]]*)\]') + expanded = [] + pos = 0 + for m in regexp.finditer(editor): + expanded.append(editor[pos:m.start()-1]) + phrase = editor[m.start()+1:m.end()-1] + pos=m.end()+1 + if '$LINENUM' in phrase: + if lineno is None: + # throw away phrase + continue + phrase = phrase.replace('$LINENUM', str(lineno)) + elif '$SEARCH' in phrase: + if search is None: + # throw away phrase + continue + phrase = phrase.replace('$SEARCH', search) + if '$FILE' in phrase: + phrase = phrase.replace('$FILE', files[0]) + files = [] + expanded.append(phrase) + expanded.append(editor[pos:]) + cmdline = ' '.join(expanded + files)   except ValueError, e:   # '[' or ']' not found   cmdline = ' '.join([editor] + files)