Page 1 of 1
paste text to another tab by command
Posted: 01.09.2023 09:02
by SamC
Hello!
When I do several jobs at same time, many tabs open in CudaText, and when I select some text, I want to make a command to paste it to a certain log file(logfile.log). I want to make a plugin to do this:
1.Get the text by
txt = ed.get_text_sel()
2.Paste the text by
edlog.set_text_line(index, text)
As the ed = Editor(0) (0 means the active tab?), How to assign another Editor for edlog by name, like edlog = Editor('logfile.log")? Or other method can do the samething.
I need some guidance for the API about this, thanks a lot!
Re: paste text to another tab by command
Posted: 01.09.2023 12:03
by main Alexey
API ed_handles() is needed here. example in the wiki:
https://wiki.freepascal.org/CudaText_API#ed_handles
To compare filenames:
Code: Select all
def find_editor_by_filename(fn):
""" gets None if editor not found, or gets Editor() object """
for h in ed_handles():
e = Editor(h)
if e.get_filename() == fn:
return e
Re: paste text to another tab by command
Posted: 01.09.2023 12:15
by main Alexey
corrected the example above. note: on Windows, better compare filenames ignoring case:
Code: Select all
import os
IS_WIN = os.name=='nt'
def equal_filenames(s1, s2):
if IS_WIN:
return s1.lower()==s2.lower()
else:
return s1==s2
Re: paste text to another tab by command
Posted: 02.09.2023 23:45
by SamC
Thanks,the plugin is made following your guidance.
I used Editor.insert:insert(x, y, text) to add text. In wiki page it says:
If y is too big, appends block to the end (even to final line without line-ending).
Is it a value for the maximum y can be used?
As I always want to add new line on the end to the log file(\n is added in the code), does that means this limitation is OK for my case?
Re: paste text to another tab by command
Posted: 03.09.2023 01:34
by SamC
How to make comments on ini file and json file in CudaText? I've Google it,
//for json comments (in line comments)
; for ini file comments (block comments and inline comments )
is it right for Cuda?
Re: paste text to another tab by command
Posted: 03.09.2023 06:20
by main Alexey
Is it a value for the maximum y can be used?
wiki means that 'too big y' is 'y after the actual line count'.
which you can read by ed.get_line_count().
//for json comments (in line comments)
; for ini file comments (block comments and inline comments )
correct. but many apps do not understand JSON comments. JSON 4 standart prohibites comments. JSON 5 allows it for some degree.
Re: paste text to another tab by command
Posted: 03.09.2023 07:58
by SamC
Thanks! That means JSON5 is used in Cudatext?
Re: paste text to another tab by command
Posted: 03.09.2023 08:06
by main Alexey
I did not check that ALL JSON5 specs are supported. comments are supported.