Snippets for external command output?

Plugins for SynWrite and CudaText...
deHavilland
Posts: 5
Joined: 23.05.2022 21:19

Snippets for external command output?

Post by deHavilland »

Hello,

It's been a pleasure to use CudaText so far. I have a question about snippets, as I couldn't find related information in the help documentation.

I have a lot of scripts and programs that output text, which I use in the text editor.

For example a program that outputs a schedule outline in Markdown, starting with the current time. Or a script that brings in text from a given external text file, in a specific format.

Typically I would type the snippet name and press (tab) in my editor to see it replaced by the command output.

Is there a way to do this in CudaText? Thank you.
main Alexey
Posts: 2323
Joined: 25.08.2021 18:15

Post by main Alexey »

I don't get the idea - e.g. you type what? and what command is executed from this snippet name? how command is defined for the snippet?

CudaText "Snippets" plugin
https://wiki.freepascal.org/CudaText_plugins#Snippets
can insert fixed text which is defined in the snippet storage (one snippet name - one fixed text, no command is used)
deHavilland
Posts: 5
Joined: 23.05.2022 21:19

Post by deHavilland »

Here are some examples, I have about 90 of these in the configuration.

Code: Select all

wk=\n{command:cat /home/user/Dropbox/User/Writing/Current\ Writing\ Projects/Weeklies.md}\n\n
ak=\n{command:cat /home/user/Dropbox/Client\ Notes/notes/Active-Client-Projects.md}\n\n
sk=\n{command:/home/user/Dropbox/bin/schedwriter}\n\n
st={command:/home/user/Dropbox/bin/stockprices}
These are placed in the snippets configuration file of my other editor.

Then if I type wk, ak, sk, or st and press the tab key, the corresponding command is executed and the output is placed at my cursor. Usually it is multiple lines of output.

It seems this may not be possible? But I'm curious if there could be any workarounds to get the same result. Thank you.
main Alexey
Posts: 2323
Joined: 25.08.2021 18:15

Post by main Alexey »

'of my editor' - what editor do you use, Sublime? Atom?
it is interesting idea! to support {command:xxxx}. It is worth to support it. I will try that later.
Hobbes
Posts: 43
Joined: 17.05.2022 07:53

Post by Hobbes »

Do you mean support it in something like Vim command mode? a command line (like some CAD Software)? or something different?

In any case, it would be a good idea.
deHavilland
Posts: 5
Joined: 23.05.2022 21:19

Post by deHavilland »

main Alexey wrote:'of my editor' - what editor do you use, Sublime? Atom?
it is interesting idea! to support {command:xxxx}. It is worth to support it. I will try that later.
I'm glad to hear you think so. This editor is Geany.
Do you mean support it in something like Vim command mode? a command line (like some CAD Software)? or something different?
The documentation is here: https://www.geany.org/manual/current/in ... e-snippets

There is no command mode or command line mode, just typing in the document at your cursor. But I wouldn't be angry if those others were also supported. :D
main Alexey
Posts: 2323
Joined: 25.08.2021 18:15

Post by main Alexey »

I changed the Snippets plugin. please test.
"Plugins / Addon Manager / Install from git", enter URL
https://github.com/cudatext-addons/cuda_snippets

The macro ${cmd:xxxxxxxxxx} was added.
I tested it on a new snippet with such body:
result: ${cmd:cat ~/paste.txt}
on Ubuntu.
You can add snippet via "Plugins / snippets / Add-edit snippets".
deHavilland
Posts: 5
Joined: 23.05.2022 21:19

Post by deHavilland »

main Alexey wrote:I changed the Snippets plugin. please test.
"Plugins / Addon Manager / Install from git", enter URL
https://github.com/cudatext-addons/cuda_snippets

The macro ${cmd:xxxxxxxxxx} was added.
I tested it on a new snippet with such body:
That was fast! This works well for me overall; I tested it with some of my scripts already and the results look good.

One issue comes up though, this is a Pascal program and somehow after execution the editor moves my cursor very far to the right (horizontal scrollbar becomes tiny) after execution, without adding actual spaces to the file.

Can I ask if this happens for you too? Version 1.165.0

Code: Select all

${cmd:~/Dropbox/bin/schedwriter}
.pas w/ x64 executable download
main Alexey
Posts: 2323
Joined: 25.08.2021 18:15

Post by main Alexey »

ah, it moves caret to the right when you have MUTLILINE output? it's a issue. plugin doesn't calculate caret pos OK. to fix.
main Alexey
Posts: 2323
Joined: 25.08.2021 18:15

Post by main Alexey »

I updated plugin, fixing the caret pos.
fixed in Git.
to update it: Plugins / Addon Manager / Update, and check item for 'Snippets'.
Post Reply