Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refresh specific script #36

Open
tnmeesters opened this issue Jun 5, 2024 · 9 comments
Open

refresh specific script #36

tnmeesters opened this issue Jun 5, 2024 · 9 comments

Comments

@tnmeesters
Copy link

Is it possible to refresh a specific script instead of every script in the commands folder?
Refreshing has become slow with to many scripts.

Thanks,

Thomas

@GChristensen
Copy link
Owner

It is theoretically possible, but requires a thorough rewrite of the Enso's scriptotron engine. It was written so that all evaluated symbols of all scripts are cleared before loading update from script files. Unfortunately, this is a task no of the foreseeable future.

@tnmeesters
Copy link
Author

Ok, thanks. I do notice that the Enso editor does update and quite faster. Is there a way to update it like that.
Having a script in ...\Enso.enso\commands\ like 'user' and update it with a command.

@GChristensen
Copy link
Owner

By default, changes in command files are tracked only in the editor commands.
It is possible to track all files by enabling

TRACK_COMMAND_CHANGES = True

in config.py or the configuration editor.

Unfortunately, currently it is impossible to speed up anything because all python symbols used in commands should be recreated.

@tnmeesters
Copy link
Author

Thank you, I will try this.

@tnmeesters
Copy link
Author

tnmeesters commented Jun 12, 2024

I'm running into a problem with updating the commands. I saw in the tutorial that using 'on_quasimode_start()' could solve this problem. But I don't know how to do that. I have the following example:

import os
import json

def displayMessage(msg):
import enso.messages
enso.messages.displayMessage("

%s

" % msg)

clipboard = []
clipboard = json.load(open("files/clipboard.txt"))
validarguments = list(map(lambda x : x['name'], clipboard))

def cmd_add_clipboard(ensoapi, name):
""" Add clip to clipboard """
seldict = ensoapi.get_selection()

if seldict.get('text'):
    text = seldict['text'].strip()
    clipboard.append({"name": name,"clip": text})
    json.dump(clipboard, open("files/clipboard.txt",'w'), indent=2)
    displayMessage("Creating new clip in clipboard...")
else:
    displayMessage("Nothing was file selected")

#on_quasimode_start()

def cmd_clipboard(ensoapi, subject):
""" Paste from clipboard """

indexposition = next((index for (index, d) in enumerate(clipboard) if d["name"] == subject), None)
clip = clipboard[indexposition]['clip']

displayMessage(clip)

#ensoapi.set_selection(paste)

cmd_clipboard.valid_args = validarguments

#With the following in the json file
[
{
"name": "mail",
"clip": "[email protected]"
},
{
"name": "phone",
"clip": "1245"
}
]

How should I use on_quasimode_start()?

Thanks,

Thomas

@GChristensen
Copy link
Owner

GChristensen commented Jun 12, 2024

Hi,

It is possible in the same way as with the valid_args:

def cmd_test(ensoapi):
    ensoapi.display_message("test")
    
def my_func():
    displayMessage("<p>test2</p>")
    
cmd_test.on_quasimode_start = my_func

@tnmeesters
Copy link
Author

tnmeesters commented Jun 18, 2024

Hello,

Sorry, I'm not able to get it to work with the .valid_args to be dynamic. I am able to load a list at starting quasimode but I don not know how to use for the input arguments.

import os
import json


def displayMessage(msg):
    import enso.messages
    enso.messages.displayMessage("%s " % msg)


def load_clips():
    clipboard = []
    clipboard = json.load(open(r"C:\Enso\files\clipboard.txt"))
    validarguments = list(map(lambda x : x['name'], clipboard))
    displayMessage(validarguments)
    return validarguments
    
def cmd_non(ensoapi, subject):
    ensoapi.display_message("test")
    
    
cmd_non.on_quasimode_start = load_clips
#cmd_non.valid_args = load_clips


#With the following in the json file
[
{
"name": "mail",
"clip": "[email protected]"
},
{
"name": "phone",
"clip": "1245"
}
]

Thanks,

Thomas

@GChristensen
Copy link
Owner

GChristensen commented Jun 18, 2024

import os
import json


def displayMessage(msg):
    import enso.messages
    enso.messages.displayMessage("%s " % msg)


def load_clips():
    clipboard = []
    clipboard = json.load(open(r"C:\Enso\files\clipboard.txt")))
    validarguments = list(map(lambda x : x['name'], clipboard))
    displayMessage(validarguments)
    cmd_non.valid_args = validarguments
    return validarguments
    
def cmd_non(ensoapi, subject):
    ensoapi.display_message("test")
    
cmd_non.on_quasimode_start = load_clips
cmd_non.valid_args = load_clips()

@tnmeesters
Copy link
Author

I have everything working. I was able to improve a lot of scripts thanks to this.

Thank you for everything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants