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

wctxactions: support an optional line number in edit() function

Only effective when user configures linenumber arguments in tortoisehg.editor.
syntax is: editprog -flags [$FILE --num=$LINENUM] -moreflags

If no line number is passed to edit(), the braces and everything between are removed.
$FILE is optional, if not specified the filename is appended.

Changeset fd8dcce1ddca

Parent 6d9b7510aac8

by Steve Borho

Changes to one file · Browse files at fd8dcce1ddca Showing diff from parent 6d9b7510aac8 Diff from another changeset...

 
117
118
119
120
121
122
123
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
126
127
 
131
132
133
134
135
136
137
138
 
117
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
 
153
154
155
 
 
156
157
158
@@ -117,11 +117,33 @@
 def vdiff(parent, ui, repo, files):   visdiff.visualdiff(ui, repo, files, {})   -def edit(parent, ui, repo, files): - editor = (ui.config('tortoisehg', 'editor') or - os.environ.get('HGEDITOR') or - ui.config('ui', 'editor') or - os.environ.get('EDITOR', 'vi')) +def edit(parent, ui, repo, files, lineno=None): + files = [util.shellquote(util.localpath(f)) for f in files] + editor = ui.config('tortoisehg', 'editor') + 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) + except ValueError, e: + # '[' or ']' not found + cmdline = ' '.join([editor] + files) + except TypeError, e: + # variable expansion failed + cmdline = ' '.join([editor] + files) + else: + editor = os.environ.get('HGEDITOR') or ui.config('ui', 'editor') or \ + os.environ.get('EDITOR', 'vi') + cmdline = ' '.join([editor] + files)   if os.path.basename(editor) in ('vi', 'vim', 'hgeditor'):   res = QtGui.QMessageBox.critical(parent,   _('No visual editor configured'), @@ -131,8 +153,6 @@
  dlg.exec_()   return   - files = [util.shellquote(util.localpath(f)) for f in files] - cmdline = ' '.join([editor] + files)   cmdline = util.quotecommand(cmdline)   try:   subprocess.Popen(cmdline, shell=True, creationflags=visdiff.openflags,