📜 ⬆️ ⬇️

Tuning mooedit, work on the bugs

In the first part, syntax check and formatting of Perl sources in mooedit were added . If there were no problems with the first one, then when formatting I had to refuse to display errors in the notification area. But since then a new version has appeared in the unstable-1.1.9x branch . Nothing particularly unstable in version 1.1.97-devel did not notice, except that the workpiece for the long-awaited code folding. But at least one nice change appeared in the internal API.


Previously, it was impossible to choose where to display the result of the utilities: in the editor window (formatted source code) or in the notification area (error messages). Now you can get an object for output, the code for Lua and Python scripts is exactly the same:

obj = window.get_output() obj.clear() obj.set_filter_by_id("default") obj.write_with_filter("-,   ") window.present_output() 

')
First of all, we change the ~ / bin / perlsyntax script a bit , add the return of the exit code to it:

 #!/usr/bin/perl use strict; die "Usage: $0 file\n" unless $ARGV[0]; my $out = `/usr/bin/perl -c $ARGV[0] 2>&1`; my $rc = ($out =~ s|^(.*) at (($ARGV[0]) line (\d+))(.*)$|$3:$4 $1$5|gm); print $out; exit $rc; # 0 -   


And modify the script to format the source:

 filename = doc.get_filename() codefile = os.tmpname() rc = os.execute(string.format("/home/klopp/bin/perlsyntax \"%s\" > \"%s\" 2>&1",filename,codefile)) if rc == 0 then tidyfile = os.tmpname() os.execute(string.format("/usr/bin/perltidy -nsak=\"if elsif unless for while\" -pt=0 -i=4 -bl -vt=2 -vtc=2 -boc -st \"%s\" > \"%s\"",filename,tidyfile)) out = io.open(tidyfile,"r") doc.select_all() doc.replace_selected_text(out:read("*a")) doc.save() os.remove(tidyfile) else out = io.open(codefile,"r") err = string.format("Run syntax check!\n\n%s",out:read("*a")) o = window.get_output() o.clear() o.set_filter_by_id("default") o.write_with_filter(err) window.present_output() end os.remove(codefile) 


Now, in case of errors, the source in the editor window will not change, and the output of these errors will appear in the notification area. And clicking on the line with the error will move us to the same line in the editor window.



The utility settings are:



Additionally, create a utility to run the script directly from the editor. You can, of course, as before - just run / usr / bin / perl "$ DOC_PATH" . But in case of errors we will not get clickable output in the notification area. Therefore, we will first check the source, if everything is good, run the script, and output the modified messages in case of errors. To do this, create ~ / bin / perlrun with the following contents:

 #!/bin/sh rc=`/home/klopp/bin/perlsyntax $1` if [ "$?" -eq 0 ] ; then /usr/bin/perl $1 else echo $rc fi 


And we will register its launch in the utility with such settings:



We are waiting for the next version of the editor, maybe something else interesting will appear :)

Source: https://habr.com/ru/post/206152/


All Articles