Command that pastes in the same indent level

classic Classic list List threaded Threaded
16 messages Options
Reply | Threaded
Open this post in threaded view
|

Command that pastes in the same indent level

phuibonhoa
I have a command I'm trying to create that pastes multiple lines of code, the problem is sequential lines are not indented properly.  If my command pastes 1, 2, 3 on newlines for example, I'll get something like this:

def foo
   1
2
3
end

since I invoke my command from the proper indenting (2 spaces over), but the following lines are not indented at all.  Is there a recommended way to fix this?

Thanks!


_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

list of all file types for -t

Dr Eberhard W Lisse
Hi,

Is there a list somewhere where I can find all possible file types that
-t understands?

        cat somefile.tex | mate -t text.tex.latex -
        cat somefile.md | mate text.html.markdown -

in particular for bash, perl and sql, but preferably complete?

greetings, el



--
Dr. Eberhard W. Lisse          / Obstetrician & Gynaecologist (Saar)
[hidden email]            / *     |   Telephone: +264 81 124 6733 (cell)
PO Box 8421                  /
Bachbrecht, Namibia     ;____/

_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

Re: list of all file types for -t

Carpii UK
mate -h

On Mon, 22 Apr 2019 at 17:22, Dr Eberhard W Lisse <[hidden email]> wrote:
Hi,

Is there a list somewhere where I can find all possible file types that
-t understands?

        cat somefile.tex | mate -t text.tex.latex -
        cat somefile.md | mate text.html.markdown -

in particular for bash, perl and sql, but preferably complete?

greetings, el



--
Dr. Eberhard W. Lisse          / Obstetrician & Gynaecologist (Saar)
[hidden email]            / *     |   Telephone: +264 81 124 6733 (cell)
PO Box 8421                  /
Bachbrecht, Namibia     ;____/

_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate


_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

Re: list of all file types for -t

Timothy Bates
 nice thing to tweet from @macromates 

On 22 Apr 2019, at 5:44 pm, Carpii UK <[hidden email]> wrote:

mate -h

On Mon, 22 Apr 2019 at 17:22, Dr Eberhard W Lisse <[hidden email]> wrote:
Hi,

Is there a list somewhere where I can find all possible file types that
-t understands?

        cat somefile.tex | mate -t text.tex.latex -
        cat somefile.md | mate text.html.markdown -

in particular for bash, perl and sql, but preferably complete?

greetings, el



_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

Re: list of all file types for -t

Dr Eberhard W Lisse
mate -h does not show any list of <filetypes>

I do not understand the tween reference.

el

Sent from Dr Lisse's iPad mini 4
On 22 Apr 2019, 19:03 +0200, Tim Bates <[hidden email]>, wrote:
 nice thing to tweet from @macromates 

On 22 Apr 2019, at 5:44 pm, Carpii UK <[hidden email]> wrote:

mate -h

On Mon, 22 Apr 2019 at 17:22, Dr Eberhard W Lisse <[hidden email]> wrote:
Hi,

Is there a list somewhere where I can find all possible file types that
-t understands?

        cat somefile.tex | mate -t text.tex.latex -
        cat somefile.md | mate text.html.markdown -

in particular for bash, perl and sql, but preferably complete?

greetings, el


_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate


_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

Re: list of all file types for -t

Carpii UK


On Mon, 22 Apr 2019 at 22:00, Dr Eberhard W Lisse <[hidden email]> wrote:
mate -h does not show any list of <filetypes>

Yes sorry, I realised as soon as I'd sent it, that I'd misread your question :(

But list of supported filetypes, isn't that just going to be determined by what bundles you have installed?






 
I do not understand the tween reference.

el

Sent from Dr Lisse's iPad mini 4
On 22 Apr 2019, 19:03 +0200, Tim Bates <[hidden email]>, wrote:
 nice thing to tweet from @macromates 

On 22 Apr 2019, at 5:44 pm, Carpii UK <[hidden email]> wrote:

mate -h

On Mon, 22 Apr 2019 at 17:22, Dr Eberhard W Lisse <[hidden email]> wrote:
Hi,

Is there a list somewhere where I can find all possible file types that
-t understands?

        cat somefile.tex | mate -t text.tex.latex -
        cat somefile.md | mate text.html.markdown -

in particular for bash, perl and sql, but preferably complete?

greetings, el


_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate

_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate


_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

Re: list of all file types for -t

Dr Eberhard W Lisse
Yes, and no.

I would like to know which (common) ones are possible, or how I can find
that (which ones are installed/available) out, so that if I use "mate -"
in a pipe I can "load" the required bundle and make use of its
facilities without having to resort to selecting filetype with the
mouse.

Probably something of use to others as well.

greetings, el

On 2019-04-22 23:02 , Carpii UK wrote:

> On Mon, 22 Apr 2019 at 22:00, Dr Eberhard W Lisse <[hidden email]> wrote:
>
>> mate -h does not show any list of <filetypes>
>>
>
> Yes sorry, I realised as soon as I'd sent it, that I'd misread your
> question :(
>
> But list of supported filetypes, isn't that just going to be
> determined by what bundles you have installed?
[...]

--
Dr. Eberhard W. Lisse          / Obstetrician & Gynaecologist (Saar)
[hidden email]            / *     |   Telephone: +264 81 124 6733 (cell)
PO Box 8421                  /
Bachbrecht, Namibia     ;____/

_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

Re: list of all file types for -t

Carpii UK
Ok, I think I understand the problem, but I don't know a solution, sorry. 

My understanding is 'mate' is simply a wrapper which passes the parameters to TextMate, which then loads all of its bundles, and only at this point would it know what filetypes it has bundle handling for. 
Maybe Allan will chip in with some workaround

Is there no way you could just identify the filetype before you start piping it, and then pass that to textmate (and just assume it has handling for it, otherwise it will default to text)?






On Mon, 22 Apr 2019 at 23:02, Dr Eberhard W Lisse <[hidden email]> wrote:
Yes, and no.

I would like to know which (common) ones are possible, or how I can find
that (which ones are installed/available) out, so that if I use "mate -"
in a pipe I can "load" the required bundle and make use of its
facilities without having to resort to selecting filetype with the
mouse.

Probably something of use to others as well.

greetings, el

On 2019-04-22 23:02 , Carpii UK wrote:
> On Mon, 22 Apr 2019 at 22:00, Dr Eberhard W Lisse <[hidden email]> wrote:
>
>> mate -h does not show any list of <filetypes>
>>
>
> Yes sorry, I realised as soon as I'd sent it, that I'd misread your
> question :(
>
> But list of supported filetypes, isn't that just going to be
> determined by what bundles you have installed?
[...]

--
Dr. Eberhard W. Lisse          / Obstetrician & Gynaecologist (Saar)
[hidden email]            / *     |   Telephone: +264 81 124 6733 (cell)
PO Box 8421                  /
Bachbrecht, Namibia     ;____/

_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate


_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

Re: list of all file types for -t

Christian Rosentreter
In reply to this post by Dr Eberhard W Lisse

Hi there,

> On 23 Apr 2019, at 12:01 AM, Dr Eberhard W Lisse <[hidden email]> wrote:
>
> Yes, and no.
>
> I would like to know which (common) ones are possible, or how I can find
> that (which ones are installed/available) out, so that if I use "mate -"
> in a pipe I can "load" the required bundle and make use of its
> facilities without having to resort to selecting filetype with the
> mouse.
>
> Probably something of use to others as well.

Maybe use something like this insane one-liner:

find ~/Library/Application\ Support/TextMate/Managed/Bundles -depth 1 -name '*.tmbundle' -exec bash -c 'tput bold; echo -n "$(defaults read "{}/info.plist" name): "; tput sgr0; echo $(if cd "{}/Syntaxes" 2>/dev/null; then for syntax in *.plist *.tmLanguage; do if [ -f "${syntax}" ]; then /usr/libexec/PlistBuddy -c "Print :fileTypes" "${syntax}" 2>/dev/null | grep -v "[\{\}]"; fi; done; fi)' \;


Actually, please don't try that. You've been warned! :-) But probably something like this could be done properly in a shell script. Just scan the available bundles and extract the required information directly. I'm not sure what "filetype" the mate command actually wants (maybe using the scopeName from the syntax file would be the right choice?).

Just providing some wild ideas…




_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate

smime.p7s (7K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: list of all file types for -t

じょいすじょん

This should be somewhat rare, but what would be valuable to know is, does it accept UTIs? or file extensions? or some list of names?


> On Apr 23, 2019, at 8:04, Christian Rosentreter <[hidden email]> wrote:
>
>
> Hi there,
>
>> On 23 Apr 2019, at 12:01 AM, Dr Eberhard W Lisse <[hidden email]> wrote:
>>
>> Yes, and no.
>>
>> I would like to know which (common) ones are possible, or how I can find
>> that (which ones are installed/available) out, so that if I use "mate -"
>> in a pipe I can "load" the required bundle and make use of its
>> facilities without having to resort to selecting filetype with the
>> mouse.
>>
>> Probably something of use to others as well.
>
>
> Maybe use something like this insane one-liner:
>
> find ~/Library/Application\ Support/TextMate/Managed/Bundles -depth 1 -name '*.tmbundle' -exec bash -c 'tput bold; echo -n "$(defaults read "{}/info.plist" name): "; tput sgr0; echo $(if cd "{}/Syntaxes" 2>/dev/null; then for syntax in *.plist *.tmLanguage; do if [ -f "${syntax}" ]; then /usr/libexec/PlistBuddy -c "Print :fileTypes" "${syntax}" 2>/dev/null | grep -v "[\{\}]"; fi; done; fi)' \;
>
>
> Actually, please don't try that. You've been warned! :-) But probably something like this could be done properly in a shell script. Just scan the available bundles and extract the required information directly. I'm not sure what "filetype" the mate command actually wants (maybe using the scopeName from the syntax file would be the right choice?).
>
> Just providing some wild ideas…
>
>
>
> _______________________________________________
> textmate mailing list
> [hidden email]
> https://lists.macromates.com/listinfo/textmate


_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

Re: list of all file types for -t

Dr Eberhard W Lisse
Thanks,

the find command (for which one needs a concealed carry permit :-)-O)
works but it returns the extensions (or filenames) by which TextMate
recognizes the type.

Grepping around in plist files showed stuff like

        <string>source.r</string>
        <string>source.ruby</string>

so

        mate -t source.r -
        mate -t source.makefile -
        mate -t source.perl -

and after a little experimenting

        mate -t text.tabular.csv -


work (even if source.perl did not come up in the grep) if the
corresponding bundle is installed.

And TextMate evaluates the shebang which also works in a pipe.

So that solves my problem, but I am still wondering if a complete list,
or the logic used should not be published somewhere...

el



On 23/04/2019 3:35 am, じょいすじょん wrote:

>
> This should be somewhat rare, but what would be valuable to know is,
> does it accept UTIs?  or file extensions?  or some list of names?
>
>
>> On Apr 23, 2019, at 8:04, Christian Rosentreter <[hidden email]> wrote:
>>
>>
>> Hi there,
>>
>>> On 23 Apr 2019, at 12:01 AM, Dr Eberhard W Lisse <[hidden email]> wrote:
>>>
>>> Yes, and no.
>>>
>>> I would like to know which (common) ones are possible, or how I can find
>>> that (which ones are installed/available) out, so that if I use "mate -"
>>> in a pipe I can "load" the required bundle and make use of its
>>> facilities without having to resort to selecting filetype with the
>>> mouse.
>>>
>>> Probably something of use to others as well.
>>
>>
>> Maybe use something like this insane one-liner:
>>
>> find ~/Library/Application\ Support/TextMate/Managed/Bundles -depth 1
>> -name '*.tmbundle' -exec bash -c 'tput bold; echo -n "$(defaults read
>> "{}/info.plist" name): "; tput sgr0; echo $(if cd "{}/Syntaxes"
>> 2>/dev/null; then for syntax in *.plist *.tmLanguage; do if [ -f
>> "${syntax}" ]; then /usr/libexec/PlistBuddy -c "Print :fileTypes"
>> "${syntax}" 2>/dev/null | grep -v "[\{\}]"; fi; done; fi)' \;
>>
>>
>> Actually, please don't try that.  You've been warned!  :-) But
>> probably something like this could be done properly in a shell
>> script.  Just scan the available bundles and extract the required
>> information directly.  I'm not sure what "filetype" the mate command
>> actually wants (maybe using the scopeName from the syntax file would
>> be the right choice?).
>>
>> Just providing some wild ideas…

--
Dr. Eberhard W. Lisse          / Obstetrician & Gynaecologist (Saar)
[hidden email]            / *     |   Telephone: +264 81 124 6733 (cell)
PO Box 8421                  /
Bachbrecht, Namibia     ;____/

_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

Re: list of all file types for -t

Christian Rosentreter

Hi there,

Just change the "Print :fileTypes" to "Print :scopeName" in my command line. This will
print out what you need. Even "source.perl" and "source.perl.6".

After that just unwrap that proof-of-concept on-liner, clean it up into a nice shell
script, better protect things against error cases, so it won't run wild on you in a
worst case scenario, and you should be all set. :-)


> On 23 Apr 2019, at 10:13 AM, Dr Eberhard W Lisse <[hidden email]> wrote:
>
> Thanks,
>
> the find command (for which one needs a concealed carry permit :-)-O)
> works but it returns the extensions (or filenames) by which TextMate
> recognizes the type.
>
> Grepping around in plist files showed stuff like
>
> <string>source.r</string>
> <string>source.ruby</string>
>
> so
>
> mate -t source.r -
> mate -t source.makefile -
> mate -t source.perl -
>
> and after a little experimenting
>
> mate -t text.tabular.csv -
>
>
> work (even if source.perl did not come up in the grep) if the
> corresponding bundle is installed.
>
> And TextMate evaluates the shebang which also works in a pipe.
>
> So that solves my problem, but I am still wondering if a complete list,
> or the logic used should not be published somewhere...
>
> el
>
>
>
> On 23/04/2019 3:35 am, じょいすじょん wrote:
>>
>> This should be somewhat rare, but what would be valuable to know is,
>> does it accept UTIs?  or file extensions?  or some list of names?
>>
>>
>>> On Apr 23, 2019, at 8:04, Christian Rosentreter <[hidden email]> wrote:
>>>
>>>
>>> Hi there,
>>>
>>>> On 23 Apr 2019, at 12:01 AM, Dr Eberhard W Lisse <[hidden email]> wrote:
>>>>
>>>> Yes, and no.
>>>>
>>>> I would like to know which (common) ones are possible, or how I can find
>>>> that (which ones are installed/available) out, so that if I use "mate -"
>>>> in a pipe I can "load" the required bundle and make use of its
>>>> facilities without having to resort to selecting filetype with the
>>>> mouse.
>>>>
>>>> Probably something of use to others as well.
>>>
>>>
>>> Maybe use something like this insane one-liner:
>>>
>>> find ~/Library/Application\ Support/TextMate/Managed/Bundles -depth 1
>>> -name '*.tmbundle' -exec bash -c 'tput bold; echo -n "$(defaults read
>>> "{}/info.plist" name): "; tput sgr0; echo $(if cd "{}/Syntaxes"
>>> 2>/dev/null; then for syntax in *.plist *.tmLanguage; do if [ -f
>>> "${syntax}" ]; then /usr/libexec/PlistBuddy -c "Print :fileTypes"
>>> "${syntax}" 2>/dev/null | grep -v "[\{\}]"; fi; done; fi)' \;
>>>
>>>
>>> Actually, please don't try that.  You've been warned!  :-) But
>>> probably something like this could be done properly in a shell
>>> script.  Just scan the available bundles and extract the required
>>> information directly.  I'm not sure what "filetype" the mate command
>>> actually wants (maybe using the scopeName from the syntax file would
>>> be the right choice?).
>>>
>>> Just providing some wild ideas…
>
> --
> Dr. Eberhard W. Lisse          / Obstetrician & Gynaecologist (Saar)
> [hidden email]            / *     |   Telephone: +264 81 124 6733 (cell)
> PO Box 8421                  /
> Bachbrecht, Namibia     ;____/
>
> _______________________________________________
> textmate mailing list
> [hidden email]
> https://lists.macromates.com/listinfo/textmate


_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate

smime.p7s (7K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: list of all file types for -t

Dr Eberhard W Lisse
Christian,

danke aus dem Süden :-)-O

I added a '|sort -f' to the end

greetings, el

On 2019-04-23 11:08 , Christian Rosentreter wrote:>

> Hi there,
>
> Just change the "Print :fileTypes" to "Print :scopeName" in my command
> line.  This will print out what you need.  Even "source.perl" and
> "source.perl.6".
>
> After that just unwrap that proof-of-concept on-liner, clean it up
> into a nice shell script, better protect things against error cases,
> so it won't run wild on you in a worst case scenario, and you should
> be all set.  :-)

_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

Re: list of all file types for -t

Allan Odgaard-4
In reply to this post by Dr Eberhard W Lisse

On 23 Apr 2019, at 10:13, Dr Eberhard W Lisse wrote:

[…] so

mate -t source.r -
mate -t source.makefile -
mate -t source.perl -

and after a little experimenting

mate -t text.tabular.csv -

work (even if source.perl did not come up in the grep) if the
corresponding bundle is installed.

And TextMate evaluates the shebang which also works in a pipe.

So that solves my problem, but I am still wondering if a complete list,
or the logic used should not be published somewhere...

The type <filetype> argument for mate -t is indeed the grammar’s root scope that you find by grepping the property lists.

You can also find this value either in the bundle editor, select a language grammar and it is the “Grammar” field in the drawer, alternatively, if you open a file of the desired type, press ⌃⇧P and a tool tip shows with the full scope of the insertion point, the first line is the grammar’s root scope, and what to use for mate -t.

There is no full list because it would depend on what bundles you have installed/created. But I guess it wouldn’t be bad if there was a way for mate to query the list of installed bundles. I’ve added a note about this, although the effort to implement this is probably not proportional with the benefit.



_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

Re: Command that pastes in the same indent level

Allan Odgaard-4
In reply to this post by phuibonhoa

On 4 Mar 2019, at 11:39, Philippe Huibonhoa wrote:

I have a command I'm trying to create that pastes multiple lines of code,
the problem is sequential lines are not indented properly. […]
Is there a recommended way to
fix this?

In the bundle editor’s sidebar, set Format to Snippet (under Output).

Snippet output is automatically indented to the current indent level.

Be aware though that you should escape any special characters in the output that would otherwise trigger snippet functionality, in ruby that could be done with this function:

def e_sn(str)
  str.gsub(/(?=[$`\\])/, '\\')
end


_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate
Reply | Threaded
Open this post in threaded view
|

Re: Command that pastes in the same indent level

phuibonhoa
That did the trick, thank you Allan! <3

Philippe
On Jun 26, 2019, 11:16 PM -0700, Allan Odgaard <[hidden email]>, wrote:

On 4 Mar 2019, at 11:39, Philippe Huibonhoa wrote:

I have a command I'm trying to create that pastes multiple lines of code,
the problem is sequential lines are not indented properly. […]
Is there a recommended way to
fix this?

In the bundle editor’s sidebar, set Format to Snippet (under Output).

Snippet output is automatically indented to the current indent level.

Be aware though that you should escape any special characters in the output that would otherwise trigger snippet functionality, in ruby that could be done with this function:

def e_sn(str)
  str.gsub(/(?=[$`\\])/, '\\')
end

_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate


_______________________________________________
textmate mailing list
[hidden email]
https://lists.macromates.com/listinfo/textmate