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!
paste text to another tab by command
-
- Posts: 2245
- Joined: 25.08.2021 18:15
Re: paste text to another tab by command
API ed_handles() is needed here. example in the wiki:
https://wiki.freepascal.org/CudaText_API#ed_handles
To compare filenames:
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
-
- Posts: 2245
- Joined: 25.08.2021 18:15
Re: paste text to another tab by command
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
Thanks,the plugin is made following your guidance.
I used Editor.insert:insert(x, y, text) to add text. In wiki page it says:
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?
I used Editor.insert:insert(x, y, text) to add text. In wiki page it says:
Is it a value for the maximum y can be used?If y is too big, appends block to the end (even to final line without line-ending).
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
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?
//for json comments (in line comments)
; for ini file comments (block comments and inline comments )
is it right for Cuda?
-
- Posts: 2245
- Joined: 25.08.2021 18:15
Re: paste text to another tab by command
wiki means that 'too big y' is 'y after the actual line count'.Is it a value for the maximum y can be used?
which you can read by ed.get_line_count().
correct. but many apps do not understand JSON comments. JSON 4 standart prohibites comments. JSON 5 allows it for some degree.//for json comments (in line comments)
; for ini file comments (block comments and inline comments )
Re: paste text to another tab by command
Thanks! That means JSON5 is used in Cudatext?
-
- Posts: 2245
- Joined: 25.08.2021 18:15
Re: paste text to another tab by command
I did not check that ALL JSON5 specs are supported. comments are supported.