#!/usr/bin/perl # # Mindy: A Minimalist Development Environment. # # Use this little script as a replacement for `make'. It runs `make', # parses the compiler's output, finds the first error message, # and directs your editor to select the line and character range on # which the error occurs. For more details and the latest version, see: # # http://www.cs.berkeley.edu/~pbg/mindy/ # # USAGE # # You may have to adjust the following configuration parameters. Mindy # works great with nedit, and might work for gvim... $MAKE_COMMAND = 'make'; $EDITOR_TYPE = 'nedit'; # 'nedit' or 'gvim' $NEDIT_EDITOR_CMD = 'nedit-nc'; $GVIM_EDITOR_CMD = 'gvim'; # Now just run this script with parameters the same as those that you # want passed to make, like this: # # $ ./mindy.pl # # To make things as convenient as possible, you might want to put the # script in your binary directory, and rename it to something short # like `m'. # # NOTE ABOUT NEDIT # # Nedit has a normal mode which you get by running `nedit', and a client- # server mode which you get by running `nedit-nc' (at least in my # installation). The latter is what this script uses. If you are not # running in client-server mode, this script will open a new window for you, # and you can just close your old window. # # BUGS / TO DO: # # - gvim not really tested much. # - command line args to make are not properly quoted. It'll mostly work... # # -- Brighten Godfrey # September 27, 2008 # if ($EDITOR_TYPE eq 'nedit') { $EDITOR_CMD = $NEDIT_EDITOR_CMD; } elsif ($EDITOR_TYPE eq 'gvim') { $EDITOR_CMD = $GVIM_EDITOR_CMD; } foreach $arg (@ARGV) { $MAKE_COMMAND .= " $arg"; } open(MAKEOUT, "$MAKE_COMMAND 2>&1 |"); $no_error_yet = 1; foreach $line () { print $line; # OCaml if ($line =~ /^File \"(.+)\", line (\d+), characters (\d+)-(\d+):$/ && $no_error_yet) { #printf "**** File = $1, line=$2, chars $3 - $4\n"; goto_line($1, $2); select_chars($1, $3, $4); $no_error_yet = 0; } # gcc elsif ($line =~ /^(\w+\.\w+)\:(\d+)\: (error|warning)/ && $no_error_yet) { $no_error_yet = 0; print "\n **** Displaying above $3.\n\n"; select_line($1,$2); } # Add rules for other compilers here... } close(MAKEOUT); sub goto_line($$) { (my $file, my $line) = @_; if ($EDITOR_TYPE eq "nedit") { #$cmd = "$EDITOR_CMD -noask -do \"goto_line_number($line)\" \"$file\""; #print "RUNNING \"$cmd\"\n"; system("$EDITOR_CMD -noask -do \"goto_line_number($line)\" \"$file\""); } elsif ($EDITOR_TYPE eq "gvim") { system("$EDITOR_CMD --remote-tab +$line \"$file\""); } else { die($ARGV[0] . ": Unrecognized editor type $EDITOR_TYPE"); } } sub select_chars($$$) { (my $file, my $start, my $end) = @_; $numchars = $end - $start; system("$EDITOR_CMD -do \"set_cursor_pos(\\\$cursor+$start)\" \"$file\""); system("$EDITOR_CMD -do \"select(\\\$cursor,\\\$cursor+$numchars)\" \"$file\""); } sub select_line($) { (my $file, my $line) = @_; goto_line($file, $line); if ($EDITOR_TYPE eq "nedit") { $start = 'search(\"^\", \$cursor, \"regex\", \"backward\")'; $end = 'search(\"\$\", \$cursor, \"regex\")'; $cmd = "select($start, $end)"; system("$EDITOR_CMD -do \"$cmd\" \"$file\""); } }