paste text to another tab by command

Post Reply
SamC
Posts: 207
Joined: 12.08.2023 00:49

paste text to another tab by command

Post 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!
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Re: paste text to another tab by command

Post 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
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Re: paste text to another tab by command

Post 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
SamC
Posts: 207
Joined: 12.08.2023 00:49

Re: paste text to another tab by command

Post 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?
SamC
Posts: 207
Joined: 12.08.2023 00:49

Re: paste text to another tab by command

Post 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?
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Re: paste text to another tab by command

Post 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.
SamC
Posts: 207
Joined: 12.08.2023 00:49

Re: paste text to another tab by command

Post by SamC »

Thanks! That means JSON5 is used in Cudatext?
main Alexey
Posts: 2245
Joined: 25.08.2021 18:15

Re: paste text to another tab by command

Post by main Alexey »

I did not check that ALL JSON5 specs are supported. comments are supported.
Post Reply