JSON-Viewer icon indicating copy to clipboard operation
JSON-Viewer copied to clipboard

Feature Request: Option to format all open documents

Open MikoMMM opened this issue 3 years ago • 1 comments
trafficstars

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.

MikoMMM avatar Oct 17 '22 22:10 MikoMMM

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()

molsonkiko avatar Feb 18 '24 18:02 molsonkiko