Getting stdin for formatters, and replacing text

I’m having a devil of a time getting stdin to my perltidy formatter. The dialog notes that the text will be passed via stdin; but I’ve tried various combinations of - as the last argument, redirections (< and friends), and a few others, and it’s always empty. I even tried a wrapper (shell) script.

(I have not tried a macro/userscript that just gets the contents of the current buffer.)

Second, does replacement make any assumptions about vim mode? Should I take extra steps for sending stdout back to the editor buffer if I’m not in insert mode? Or is that back to userscript?

TIA,

I’m having a devil of a time getting stdin to my perltidy formatter.

Could you share what you’re working with in regards to the perltidy formatter? It’s hard to tell from your message exactly what the problem is besides that you’re having trouble with stdin and a script of some sort.

Second, does replacement make any assumptions about vim mode? Should I take extra steps for sending stdout back to the editor buffer if I’m not in insert mode? Or is that back to userscript?

Sorry I’ll need clarification of this also, replacement? Are you talking about the find/replace dialog or something else?

Perltidy uses syntax like this:

perltidy [ options ] file1 -st >outfile (leave off >outfile and it just sends to stdout; replace file1 w/ <infile for stdin on the command line). The problem seems to be that Komodo is doing something like

perltidy [ my arguments here ] <infile which doesn’t seem to work because you generally want the last argument to be your argument to -st, and adding the implicit <in but breaks it somehow.

The second question is, when running a formatter, it doesn’t care about mode eg insert or command mode when you have vi emulation on; it just magically replaces the buffer, right?

I still don’t know where you are running that command though. Are you writing some sort of addon? Can I inspect your code somewhere?

Formatter config:

I’m not having any issue retrieving stdin from formatters using a setup like that, here’s the python executable I created:

#!/usr/bin/python

import sys
file = open("/tmp/stdin", "w")
file.writelines(sys.stdin.readlines())

What does your perltidy.sh file look like?

Presently,

#!/bin/sh
perltidy -bvt=0 -pt=0 -bl -bt=0 -t -nola -i=1 -q <&0 -st

but I’ve tried a couple of other permutations. I’ve also tried it with - as the infile, < - and a couple others. I always get the red ‘component returned failure’.

I can possibly wrap it into a proper Perl script using Perl::Tidy but that feels like giving up.

I tried using your script straight from the command line and it just hangs for me. My guess is it’s waiting for some sort of escape character? Either way the issue appears to be with your script rather than with Komodo.

Works here:

   λ ~ : ~/bin/perltidy.sh < ~/tmp/t.pl
#!/usr/bin/perl -w

use strict;
use warnings;

sub something
{
	return;
}

my $whatever = something();

(where t.pl is a horribly formatted Perl file)

Hmm seems I did something wrong, it does indeed work.

Furthermore though: It also works in Komodo for me. The only difference is I didn’t enter any command line arguments. Try removing your command line arguments.

removed the %F from the arguments field, same thing every time:

[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [koIFormatter.format]"  nsresult: "0x80004005 (NS_ERROR_FAILURE)"  location: "JS frame :: chrome://komodo/content/formatters/formatters.js :: _formatViewWithFormatterAndContext :: line 132"  data: no]
                                         Thu May 19 2016 12:37:21 GMT-0400 (EDT)

Please share Help > About Komodo > copy build info

Komodo IDE, version 10.0.1, build 89160, platform macosx.
Built on Thu May 12 01:55:19 2016.

Odd, I see no reason why it wouldn;t work for you.

Does it work when you restart in safe-mode?

restarting in safe mode makes the formatter go away; adding it doesn’t show it as an option under code->format.

I’m not seeing any of these issues. Could you please try installing the Komodo 10 stable release? Right now you’re on the nightly, it should not make a difference but I’d like to make sure.

Nope, no change.

Here’s a thought, though: I’m using zsh as my shell. In Vim and others, I need to explicitly set my shell for any shelling out as bash (or /bin/bash or in any event something that is sh or bash). Could that matter?

I am using ZSH also so I would think not, but it could definitely be an ENV variable. Still the fact that you cannot even seem to add a formatter under safe-mode is very odd. Could you try doing that again and this time share your error log after going through all the steps?

Restarted in safe mode, added the Perl formatter.

Formatter doesn’t appear. Ok let’s check the log:

Welp

EDIT: In Safe Mode, I went through it AGAIN and banged on ‘Apply’ a few more times than usual, and it took this time!

It didn’t do anything but it didn’t throw the component error.

And you’re sure you were using it on Perl files that would otherwise have visible changes to them?