3ad06109fba6 — Steve Fink 3 months ago
[em] add vi support, improve docs
2 files changed, 42 insertions(+), 19 deletions(-)

M README.md
M bin/em
M README.md +31 -17
@@ 10,10 10,11 @@ Tools included:
    revisions.
  - run-taskcluster-job : Run taskcluster jobs in a local Docker container.
  - get-taskcluster-logs : Retrieve groups of log files from a push by scraping taskcluster
+ - em / vs : Open emacs or VSCode on the files touched by a patch, on a relevant
+   line number
  - json : Interactive navigation of a JSON file
  - debug : Start up a debugger within emacs on various types of files
  - rr-exits : List out all rr recordings with their worst exit codes
- - em : Start up emacs on the files touched by a patch, on a relevant line number
  - traverse.py : Gecko-specific, sorta. Utility for traversing a callgraph.
  - wig : Patch harder
 

          
@@ 99,6 100,35 @@ that.)
 
 ----------------------------------------------------------------------
 
+em / vs - Edit files relevant to a patch
+
+Run your $EDITOR (defaulting to emacs) on the given files, or on the files
+touched by the changes described by the given revision.
+
+If $EDITOR is unset, then `em` will default to `emacs` and `vs` will default to
+`vscode` (you will need to create a symlink from `vs` -> `em`).
+
+If you are using vscode remote editing, you will want to install this on the
+remote machine and run it from within a terminal there.
+
+1. `em foo.txt:33` will run `emacs +33 foo.txt`
+   so will `em foo.txt:33:` (easier cut & paste of trailing colon for error messages)
+   and foo.txt will be found anywhere in the current hg tree (if not in cwd)
+2. `em` with no args will run emacs on the files changed in the cwd, or if none, then
+   by the cwd's parent hg rev
+3. `em 01faf51a0acc` will run emacs on the files changed by that hg rev.
+4. `em foo.txt.rej` will run emacs on both foo.txt and foo.txt.rej, but at the lines
+   containing the first patch hunk and the line number of the original that it
+   applies to (ok, so this is probably where this script jumped the shark.)
+
+The fancy line number stuff does not apply to all possible editors. emacs and
+vscode are fully supported, though vscode's behavior is a little erratic. vi
+will only set the position for the first file.
+
+Sorry, no git support.
+
+----------------------------------------------------------------------
+
 get-taskcluster-logs - Retrieve groups of log files from a push by scraping taskcluster
 
 Typical example: copy link location to a taskcluster push (what you get from

          
@@ 185,22 215,6 @@ look for the alias 'ff', and use that co
 
 ----------------------------------------------------------------------
 
-em - Edit files relevant to a patch
-
-1. `em foo.txt:33` will run `emacs +33 foo.txt`
-   so will `em foo.txt:33`: (easier cut & paste of trailing colon for error messages)
-   and foo.txt will be found anywhere in the current hg tree (if not in cwd)
-2. `em` with no args will run emacs on the files changed in the cwd, or if none, then
-   by the cwd's parent rev
-3. `em 01faf51a0acc` will run emacs on the files changed by that rev.
-4. `em foo.txt.rej` will run emacs on both foo.txt and foo.txt.rej, but at the lines
-   containing the first patch hunk and the line number of the original that it
-   applies to (ok, so this is probably where this script jumped the shark.)
-
-If your $EDITOR is not set to emacs, you won't get the fancy line number stuff.
-
-----------------------------------------------------------------------
-
 traverse.py - various traversals over the known portion of a callgraph.
 
 The callgraph is in the format generated by the rooting hazard analysis.

          
M bin/em +11 -2
@@ 10,6 10,9 @@ 
 #    containing the first patch hunk and the line number of the original that it
 #    applies to (ok, so this is probably where this script jumped the shark.)
 
+# TODO: Rewrite in Python, purely to be able to use argparse. (Yeah, I could
+# use Getopt::Long. argparse has better help message output.)
+
 use strict;
 use warnings;
 

          
@@ 169,8 172,14 @@ if ($editor eq 'emacs') {
     $cmd = 'code';
     push @cmd_args, '-r';
     foreach (@to_edit) {
-	my ($file, $lineno) = @$_;
-	push @cmd_args, "-g", join(":", grep { $_ } $file, $lineno);
+        my ($file, $lineno) = @$_;
+        push @cmd_args, "-g", join(":", grep { $_ } $file, $lineno);
+    }
+} else {
+    $cmd = $editor;
+    push @cmd_args, map { $_->[0] } @to_edit;
+    if ($editor =~ /vi/ && $to_edit[0][1]) {
+        unshift @cmd_args, "+$to_edit[0][1]";
     }
 }