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

[Feat. Req.] Consider adding notepad.getNppConfigDir() #268

Open
alankilborn opened this issue Jan 2, 2023 · 4 comments
Open

[Feat. Req.] Consider adding notepad.getNppConfigDir() #268

alankilborn opened this issue Jan 2, 2023 · 4 comments
Labels
Feature N++ extension needed First a N++ modification is needed to work on this

Comments

@alankilborn
Copy link

Recently I had a need to open (for reading) the default session file (session.xml) from a PythonScript.

Locating the file was tedious as I first had to figure out where it was.

PS currently has notepad.getNppDir() and notepad.getPluginConfigDir() functions, and it would be nice to see the addition of notepad.getNppConfigDir().

Comments based on functionality from PS 2.0 and 3.10.4.


Here's my workaround script code:

# -*- coding: utf-8 -*-
from __future__ import print_function

from Npp import *

def notepad_getNppConfigDir():
    npp_dir = notepad.getNppDir()
    plugin_cfg_dir = notepad.getPluginConfigDir()
    if plugin_cfg_dir.startswith(npp_dir):
        npp_config_dir = npp_dir  # portable version of N++
    else:
        # installed (%APPDATA%) version of N++
        npp_config_dir = os.path.join(plugin_cfg_dir, '..', '..')
        npp_config_dir = os.path.abspath(npp_config_dir)
    return npp_config_dir

npp_cfg_dir = notepad_getNppConfigDir()
print('npp_cfg_dir:', npp_cfg_dir)
@alankilborn
Copy link
Author

Note: Sample code doesn't consider settings stored in the "cloud", but it, and the suggested new function, should.

@chcg chcg added the Feature label Jan 2, 2023
@Ekopalypse
Copy link
Contributor

Isn't it always os.path.abspath(os.path.join(notepad.getPluginConfigDir(), r'..\..'))?
No matter if it is local, appdata or cloud?

@alankilborn
Copy link
Author

The original request here mentioned session.xml location retrieval as an example, and that file isn't put in the cloud location when configured for cloud.

My original request, 2 years old exactly today, perhaps isn't as important to me as it was then.

If no one else thinks it has value, perhaps it should be closed.

@Ekopalypse
Copy link
Contributor

@chcg - requires the Notepad++ extension needed label.
Of course, PS can read the config.xml file to find out if a cloud setting has been made, but since the configuration file format is not part of the public API, PS should not need to rely on it, I guess.

@chcg chcg added the N++ extension needed First a N++ modification is needed to work on this label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature N++ extension needed First a N++ modification is needed to work on this
Projects
None yet
Development

No branches or pull requests

3 participants