PythonScript icon indicating copy to clipboard operation
PythonScript copied to clipboard

permanent setting

Open DomOBU opened this issue 10 months ago • 4 comments

Hello,

I'm a new PythonScript user. I'm not a geek and I don't know Python.

On the Notepad++ forum I was recommended to install PythonScript to solve a CSS problem with Lexilla. A command was provided. I tested it in the console; it's operational but temporary. I haven't found a way to make it permanent when I launch Notepad++. How would this be possible?

Thank you for your reply.

DomOBU avatar Apr 17 '24 19:04 DomOBU

I do not know what "command" you are referring to but to make something permanent you usually create a script and name it startup.py. It must be called startup.py and it shouldn't be the one that comes with the plugin itself. Change to configuration from LAZY to ATSTARTUP and then this script will run every time Npp starts.

Ekopalypse avatar Apr 20 '24 05:04 Ekopalypse

Thank you for your reply.

I have created a file containing :

  • from Npp import editor
  • editor.setProperty('lexer.css.scss.language', 1) This last command line works in the PythonScript console.

I've :

  • renamed the startup.py file to oldstartup.py
  • renamed my file to startup.py and copied it to the scripts directory.

Without success.

DomOBU avatar Apr 20 '24 12:04 DomOBU

No, the startup.py that is supplied with the plugin must remain. The "user" startup.py must be created in addition. the setProperty function must be called for both editor instances

editor1.setProperty...
editor2.setProperty...

the editor refers to the currently active instance and would only be set for this instance.

Do you have changed the Python Script Configuration from LAZY to ATSTARTUP?

Ekopalypse avatar Apr 20 '24 12:04 Ekopalypse

No, this is a Lexer property that you want to set. This must be done differently. You need to register a callback for bufferactivated and then set the property. This should still be done in the user startup.py.

def on_buffer_activated(args):
    # check if the file needs to have the setting and then
    # call editor.setProperty('lexer.css.scss.language', 1)
    # something like
    # if editor.getLexer() == whatever_number:
    #     editor.setProperty('lexer.css.scss.language', 1)

notepad.callback(on_buffer_activated, [NOTIFICATION.BUFFERACTIVATED])

Ekopalypse avatar Apr 20 '24 12:04 Ekopalypse