Hi,
is there a quick way to transform for instance
[Role, User, UserRole, SourceAddress, BulkMessage, Message, SingleSMSTemplate, Company, Contact]
into
[ Role, User, UserRole, SourceAddress, BulkMessage, Message, SingleSMSTemplate, Company, Contact ],
?
(In this case it's Python but it could be more or less any language.)
I do this so often manually, there must be a better way?
Thanks, Tuk
Hi there Tuk,
I usually just find a delimiter (in your case a comma) and replace them with a newline regexp (\n).
See in the video I’ve quickly put together: https://v.usetapes.com/ZFDCAjpx2i https://v.usetapes.com/ZFDCAjpx2i
There may be quicker methods (that I’m unaware of) but this is admittedly far faster than having to manually go through each line.
— Attila
ATTILA GYÖRFFY I develop software.
attilagyorffy.com http://attilagyorffy.com/ | @attilagyorffy http://www.twitter.com/attilagyorffy | | in/attilagyorffy http://linkedin.com/in/attilagyorffy | github.com/attilagyorffy http://www.github.com/attilagyorffy
Every time you print an email, a tree is marked for death. Trees provide O2. You need that to breathe, remember? 🌳
On 2018. Jan 3., at 10:34, Tuk Bredsdorff tuk@tiktuk.net wrote:
Hi,
is there a quick way to transform for instance
[Role, User, UserRole, SourceAddress, BulkMessage, Message, SingleSMSTemplate, Company, Contact]
into
[ Role, User, UserRole, SourceAddress, BulkMessage, Message, SingleSMSTemplate, Company, Contact ],
?
(In this case it's Python but it could be more or less any language.)
I do this so often manually, there must be a better way?
Thanks, Tuk
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Hi Attila,
I usually just find a delimiter (in your case a comma) and replace them with a newline regexp (\n).
See in the video I’ve quickly put together: https://v.usetapes.com/ZFDCAjpx2i
There may be quicker methods (that I’m unaware of) but this is admittedly far faster than having to manually go through each line.
I was aware of that possibility but thanks anyway ☺️ .
It’s just a lot of keypresses to select, bring up the Find dialog, type in the two strings and so on. I am looking for a shortcut to that. But for many lines it would be worth if of course.
Cheers, Tuk
You can record a macro, save it, and assign a keystroke for it. Check out the record macro feature, very handy for automating things like this! On Wed, Jan 3, 2018 at 1:55 AM Tuk Bredsdorff tuk@tiktuk.net wrote:
Hi Attila,
I usually just find a delimiter (in your case a comma) and replace them
with a newline regexp (\n).
See in the video I’ve quickly put together:
https://v.usetapes.com/ZFDCAjpx2i
There may be quicker methods (that I’m unaware of) but this is
admittedly far faster than having to manually go through each line.
I was aware of that possibility but thanks anyway ☺️ .
It’s just a lot of keypresses to select, bring up the Find dialog, type in the two strings and so on. I am looking for a shortcut to that. But for many lines it would be worth if of course.
Cheers, Tuk
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
You can record a macro, save it, and assign a keystroke for it. Check out the record macro feature, very handy for automating things like this!
Thanks, I just tried that but actually one loses the automatic indentation when do search and replace like that.
So
[Role, User, UserRole, SourceAddress, BulkMessage, Message, SingleSMSTemplate, Company, Contact],
becomes
[Role, User, UserRole, SourceAddress, BulkMessage, Message, SingleSMSTemplate, Company, Contact],
.
I could fix that with multiple carets but it ends up being easier just doing it manually in the first place 😐 .
On 3 Jan 2018, at 4:34, Tuk Bredsdorff wrote:
Hi,
is there a quick way to transform for instance
[Role, User, UserRole, SourceAddress, BulkMessage, Message, SingleSMSTemplate, Company, Contact]
into
[ Role, User, UserRole, SourceAddress, BulkMessage, Message, SingleSMSTemplate, Company, Contact ],
?
(In this case it's Python but it could be more or less any language.)
I do this so often manually, there must be a better way?
I do this a lot in Python as well. If there aren’t that many, I’ll just select the first Space and hit ⌃W repeatedly until I have them all, then hit ↩. This preserves indentation.
If you had string literals that might contain spaces, you could select something more unique, like “, “ or “', “ then hit ⌃W as before, but before hitting return, use the right arrow to deselect, then ⇧← to select just the Space before hitting ↩.
For longer lists, you can select what you want to replace, hit ⌘E to make that the search term, hit ⇧⌘L to select the entire line (to avoid messing with the rest of the file) then hit ⌥⌘F to select all occurrences of the search term on that line. From there, adjust the selection as needed and hit ↩ when ready.
Finally, be sure to go back and add a comma after the last item. Your diff output will thank you.
I do this a lot in Python as well. If there aren’t that many, I’ll just select the first Space and hit ⌃W repeatedly until I have them all, then hit ↩. This preserves indentation.
If you had string literals that might contain spaces, you could select something more unique, like “, “ or “', “ then hit ⌃W as before, but before hitting return, use the right arrow to deselect, then ⇧← to select just the Space before hitting ↩.
For longer lists, you can select what you want to replace, hit ⌘E to make that the search term, hit ⇧⌘L to select the entire line (to avoid messing with the rest of the file) then hit ⌥⌘F to select all occurrences of the search term on that line. From there, adjust the selection as needed and hit ↩ when ready.
Finally, be sure to go back and add a comma after the last item. Your diff output will thank you.
Thanks Rob, that was some really useful tricks I didn’t know! Allan never ceases to surprise me with the capabilities of TextMate ☺️ . Så cool with the repeated usage of ^W, I had know idea it could that. And ⌥⌘F to select all occurrences, I’m gonna remember that as well. That will do until I find or make a bundle command that automates it.
I’m also glad I found out the mailing list is so active.
And happy new year to everybody!
·t
Create a command:
------------------ #!/bin/bash [[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] && . "${TM_SUPPORT_PATH}/lib/bash_init.sh"
INPUT=$(cat /dev/stdin) python -c "import json; print(json.dumps(${INPUT}))" | python -m json.tool ------------------
--- Uğur "vigo" Özyılmazel
https://github.com/vigo https://gitbook.com/@vigo http://ugur.ozyilmazel.com | @vigobronx http://devpod.org | @podcastmaster http://gelistiriciyiz.biz | @gelistiriciyiz
On 3 Jan 2018, at 12:34, Tuk Bredsdorff tuk@tiktuk.net wrote:
Hi,
is there a quick way to transform for instance
[Role, User, UserRole, SourceAddress, BulkMessage, Message, SingleSMSTemplate, Company, Contact]
into
[ Role, User, UserRole, SourceAddress, BulkMessage, Message, SingleSMSTemplate, Company, Contact ],
?
(In this case it's Python but it could be more or less any language.)
I do this so often manually, there must be a better way?
Thanks, Tuk
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Create a command:
#!/bin/bash [[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] && . "${TM_SUPPORT_PATH}/lib/bash_init.sh"
INPUT=$(cat /dev/stdin) python -c "import json; print(json.dumps(${INPUT}))" | python -m json.tool
Good Idea but it doesn’t work for me as my input is not valid json.
I have however cooked up a tiny bundle using YAPF that works and which I will release shortly ☺️ .
·t
I have now put together a bundle that does the job (and more), at least for Python. It’s using the very nice YAPF module.
Hope others will also find it useful ☺️ .
https://github.com/tiktuk/Python-YAPF.tmbundle
·t