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

Feature Request: Option to format all open documents #152

Open
MikoMMM opened this issue Oct 17, 2022 · 1 comment
Open

Feature Request: Option to format all open documents #152

MikoMMM opened this issue Oct 17, 2022 · 1 comment

Comments

@MikoMMM
Copy link

MikoMMM commented Oct 17, 2022

Like the title says; an option to format all open txt\json files (which I'm trying to do at the moment), instead of doing them all one by one. Think of the (CTRL + ALT +SHIFT + M) shortcut, but expanded to all open files in the notepad++ app.

@molsonkiko
Copy link

I know this is a very old issue and you've probably already solved it, but I just wanted to share a good solution for posterity.

This kind of issue is best solved by a scripting plugin like PythonScript. The below script below is only tested with JsonTools, but I expect it would work just as well with this plugin.

# requires PythonScript: https://github.com/bruderstein/PythonScript
from Npp import notepad

# attempt to pretty-print only files with these extensions
EXTS_TO_PRETTY_PRINT = ['json']

for x in notepad.getFiles():
    fname = x[0]
    # check if the file has an extension to be pretty-printed
    if any(fname.endswith('.' + ext) for ext in EXTS_TO_PRETTY_PRINT):
        # open the file
        notepad.activateFile(fname)
        # run the pretty-print command
        notepad.runPluginCommand('JsonTools', # or Json-Viewer
            'Pretty-print current JSON file') # or Json-Viewer's pretty-print command name
        # save the file
        notepad.save()

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