<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[How can I get autocomplete working for Python 3? I'm using the PythonScript plugin.]]></title><description><![CDATA[<p dir="auto">I am looking for a way to get better autocomplete for Python when developing scripts with PythonScript.</p>
<p dir="auto">For instance, I start my document with:</p>
<pre><code>from Npp import *
import re
</code></pre>
<p dir="auto">And then I want to reference the <code>editor</code> object. But when I type <code>editor.</code> (Note the period) there are no autocomplete suggestions.</p>
<p dir="auto">I’m trying to learn more about how Python interfaces with N++ and having auto-completion for built in commands / classes / structures would make this a lot easier.</p>
<p dir="auto">Also, is there documentation anywhere on the NP++ specific Python bindings anywhere?</p>
<p dir="auto">Any help greatly appreciated.</p>
]]></description><link>https://community.notepad-plus-plus.org/topic/24687/how-can-i-get-autocomplete-working-for-python-3-i-m-using-the-pythonscript-plugin</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 00:57:15 GMT</lastBuildDate><atom:link href="https://community.notepad-plus-plus.org/topic/24687.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 10 Jul 2023 12:51:35 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How can I get autocomplete working for Python 3? I'm using the PythonScript plugin. on Sun, 14 Jan 2024 20:58:30 GMT]]></title><description><![CDATA[<p dir="auto">If you’ve used a script in this thread, you might want to double check your copy of it for a bug I’ve discovered.<br />
Look to previous postings in this topic thread where the script has been changed – find the text <code>moderator edit (2024-Jan-14)</code>.<br />
There’s a link there that describes the bug in more detail, and shows what needs to be changed in an old copy (or you can simply grab a copy of the current version).</p>
]]></description><link>https://community.notepad-plus-plus.org/post/92061</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/92061</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Sun, 14 Jan 2024 20:58:30 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete working for Python 3? I'm using the PythonScript plugin. on Tue, 11 Jul 2023 15:12:30 GMT]]></title><description><![CDATA[<p dir="auto">I said earlier,</p>
<blockquote>
<p dir="auto">I might have to update my script to use that rather than manually building the list of methods</p>
</blockquote>
<p dir="auto">My <a href="https://github.com/pryrt/nppStuff/blob/main/pythonScripts/nppCommunity/24xxx/AutoCompletionForPythonScriptMethods.py" rel="nofollow ugc">repo version of my script</a> has been updated to use Alan’s algorithm to populate the methods and elements of PythonScript’s built-in instances and enumerations.</p>
<p dir="auto">(While I understand the “problem” with the auto-complete approach, the technical details of implementing it intrigued me … especially expanding <a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a>’s algorithm to also get the enumerations like <code>NOTIFICATION</code> to have dot-completion for their elements.  <a class="plugin-mentions-user plugin-mentions-a" href="/user/mark-olson" aria-label="Profile: Mark-Olson">@<bdi>Mark-Olson</bdi></a>’s solution is a great idea if you also want extra  )</p>
]]></description><link>https://community.notepad-plus-plus.org/post/87809</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87809</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Tue, 11 Jul 2023 15:12:30 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete working for Python 3? I'm using the PythonScript plugin. on Tue, 11 Jul 2023 05:39:38 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jay-s" aria-label="Profile: Jay-S">@<bdi>Jay-S</bdi></a></p>
<p dir="auto">Depending on how you use the PythonScript plugin, you can add something like <a href="https://pypi.org/project/jedi/" rel="nofollow ugc">jedi</a> to help you write Python code.<br />
There are also two alpha versions of an lsp plugin, <a href="https://sourceforge.net/projects/kered13-notepad-plugins/files" rel="nofollow ugc">kered13</a> and <a href="https://github.com/Ekopalypse/NppLspClient/releases/tag/v0.0.13-alpha" rel="nofollow ugc">mine</a>,<br />
that can be used with lsp servers like <a href="https://pypi.org/project/python-lsp-server/" rel="nofollow ugc">python-lsp-server</a>, <a href="https://github.com/mtshiba/pylyzer" rel="nofollow ugc">pylyzer</a> or  <a href="https://github.com/microsoft/pyright" rel="nofollow ugc">pyright</a> …<br />
What they all have in common is that you need some kind of <a href="https://peps.python.org/pep-0561/" rel="nofollow ugc">stubs file</a>, that you can create using the techniques already mentioned so that they discover the methods that Notepad, Editor and Console offer.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/87799</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87799</guid><dc:creator><![CDATA[Ekopalypse]]></dc:creator><pubDate>Tue, 11 Jul 2023 05:39:38 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete working for Python 3? I'm using the PythonScript plugin. on Mon, 10 Jul 2023 20:35:08 GMT]]></title><description><![CDATA[<p dir="auto">My script in this thread from earlier today is reminiscent of a similar script in this <a href="https://community.notepad-plus-plus.org/topic/23399/">OTHER</a> thread.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/87786</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87786</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 10 Jul 2023 20:35:08 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete working for Python 3? I'm using the PythonScript plugin. on Mon, 10 Jul 2023 16:11:57 GMT]]></title><description><![CDATA[<p dir="auto">My <a href="https://github.com/molsonkiko/dictautocomp" rel="nofollow ugc">dictionary autocompletion tool</a> I made a while back actually has PythonScript autocompletion built in. I mean, there are already some perfectly fine solutions posted here, but the good thing about this one is that it also provides autocompletion for all the enums in PythonScript, like <code>SCINTILLANOTIFICATION</code> and <code>NOTIFICATION</code>.</p>
<p dir="auto">Just add this to <code>settings.json</code>:</p>
<pre><code>"%AppData%\\Roaming\\Notepad++\\plugins\\config\\PythonScript\\scripts\\dictautocomp\\pythonscript_autocompletions.txt": {
        "extensions": "\\.(?:py|foobar)$",
        "ignorecase": false,
        "min_autocomplete_length": 3
    }
</code></pre>
<p dir="auto">Running <code>get_pythonscript_autocompletions.py</code> in <code>dictautocomp</code> will regenerate the list of PythonScript autocompletions for a different version of PythonScript.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/87765</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87765</guid><dc:creator><![CDATA[Mark Olson]]></dc:creator><pubDate>Mon, 10 Jul 2023 16:11:57 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete working for Python 3? I'm using the PythonScript plugin. on Mon, 10 Jul 2023 16:02:51 GMT]]></title><description><![CDATA[<p dir="auto">The “problem” with the auto-complete approach is that you often have to know where you’re “going”, when you don’t know that.  There are A LOT of <code>editor</code> object functions.  A lot of them begin with <code>.get</code>, but sometimes the one you want (when you are trying to “get” something) doesn’t start that way.  That’s why I like the approach I presented; you can search around in the data for a partial string that isn’t necessarily at the start (i.e., right after <code>editor.</code> or <code>notepad.</code>).  Everyone’s mileage varies…</p>
]]></description><link>https://community.notepad-plus-plus.org/post/87764</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87764</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Mon, 10 Jul 2023 16:02:51 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete working for Python 3? I'm using the PythonScript plugin. on Mon, 10 Jul 2023 14:59:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alan-kilborn" aria-label="Profile: Alan-Kilborn">@<bdi>Alan-Kilborn</bdi></a> said in <a href="/post/87757">How can I get autocomplete working for Python 3? I’m using the PythonScript plugin.</a>:</p>
<blockquote>
<p dir="auto"><code>for item in dir(eval(obj_str)):</code></p>
</blockquote>
<p dir="auto">Ooh, I might have to update my script to use that rather than manually building the list of methods!  Thanks for that idea!</p>
]]></description><link>https://community.notepad-plus-plus.org/post/87761</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87761</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 10 Jul 2023 14:59:55 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete working for Python 3? I'm using the PythonScript plugin. on Mon, 10 Jul 2023 14:58:05 GMT]]></title><description><![CDATA[<p dir="auto">Installation Instructions:</p>
<ul>
<li>see <a href="https://community.notepad-plus-plus.org/topic/23039/faq-desk-how-to-install-and-run-a-script-in-pythonscript">FAQ</a> for detailed instructions
<ul>
<li>call it <code>AutoCompletionForPythonScriptMethods.py</code></li>
</ul>
</li>
<li>run it once to turn on the dot-based autocomplete</li>
<li>run it again to turn it back off
<ul>
<li>I like having a shortcut for <strong>Plugins &gt; PythonScript &gt; Run Previous Script</strong> to make such toggle-scripts easy (<strong>Settings &gt; Shortcut Mapper</strong> to assign that key)</li>
<li>or follow instructions in the FAQ to add a shortcut to this specific script</li>
</ul>
</li>
</ul>
<p dir="auto">This is only proof-of-concept; you would have to add the other methods to the list; and you could also add completions for the <code>console.</code> prefix as well as any of the enumeration prefixes, using the same logic as the <code>editor.</code> and <code>notepad.</code> that are currently shown.</p>
<pre><code class="language-py"># encoding=utf-8
"""in response to https://community.notepad-plus-plus.org/topic/24687/

Auto-completion for PythonScript methods (complete-on-dot) when a dot is entered.

Derived from https://github.com/bruderstein/PythonScript/issues/275#issuecomment-1383132656 as starting point

Installation Instructions:
- call it `AutoCompletionForPythonScriptMethods.py`
- see FAQ for instructions: https://community.notepad-plus-plus.org/topic/23039/faq-desk-how-to-install-and-run-a-script-in-pythonscript

"""
from Npp import editor,notepad,console,SCINTILLANOTIFICATION

class ACFPSM(object):
    sci_methods = ';'.join("""
        addRefDocument
        addSelection
        addStyledText
        addTabStop
        addText
        addUndoAction
        """.split())

    npp_methods = ';'.join("""
        activateBufferID
        activateFile
        activateIndex
        """.split())

    def __init__(self):
        console.write("Registered AutoCompletionForPythonScriptMethods.py callbacks\n")
        editor.callback(self.on_charadded, [SCINTILLANOTIFICATION.CHARADDED])
        self.active = True
        self.bufferIDs = []

    def toggle(self):
        self.active = not self.active
        console.write("AutoCompletionForPythonScriptMethods.py callbacks are {}\n".format('active' if self.active else 'inactive'))

    def get_current_dotted_words(self, p):
        end_p = p
        while p &gt; 0:
            p -= 1
            c = editor.getCharAt(p)
            # . or _ is valid
            if c == ord('.') or c == ord('_'):
                continue
            # digit is valid
            if ord('0') &lt;= c and c &lt;= ord('9'):
                continue
            # uppercase is valid
            if ord('A') &lt;= c and c &lt;= ord('Z'):
                continue
            # lowercase is valid
            if ord('a') &lt;= c and c &lt;= ord('z'):
                continue

            # otherwise, not valid, so do not include this character in the string
            p+=1
            break

        return editor.getTextRange(p, end_p)


    def on_charadded(self, args):
        if not self.active:
            return

        if args['ch'] == ord('.'):
            word = self.get_current_dotted_words(editor.getCurrentPos())
            clist = None
            if word in ['editor.', 'editor1.', 'editor2.']:
                clist = self.sci_methods
            elif word == 'notepad.':
                clist = self.npp_methods

            if clist is not None:
                editor.autoCSetSeparator(ord(';'))
                editor.autoCShow(0, clist)

if __name__ == '__main__':
    try:
        _ACFPSM.toggle()
    except NameError:
        _ACFPSM = ACFPSM()
</code></pre>
<p dir="auto">Any bugfixes/improvements that I make will be in <a href="https://github.com/pryrt/nppStuff/blob/main/pythonScripts/nppCommunity/24xxx/AutoCompletionForPythonScriptMethods.py" rel="nofollow ugc">my github scripts repo</a>.  Over the next few days, I will try to find the time to add more methods and enums to its logic.</p>
]]></description><link>https://community.notepad-plus-plus.org/post/87760</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87760</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 10 Jul 2023 14:58:05 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete working for Python 3? I'm using the PythonScript plugin. on Sun, 14 Jan 2024 18:33:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jay-s" aria-label="Profile: Jay-S">@<bdi>Jay-S</bdi></a></p>
<p dir="auto">Consider this script (quickly-written, I’m sure there are better ways to do it):</p>
<pre><code class="language-py"># -*- coding: utf-8 -*-
from __future__ import print_function

# references:
#  https://community.notepad-plus-plus.org/topic/24687

from Npp import *

output_line_list = []
for obj_str in [ 'editor', 'notepad' ]:
    for item in dir(eval(obj_str)):
        obj_plus_item_str = obj_str + '.' + item
        if not item.startswith('_') and 'bound method' in str(eval(obj_plus_item_str)):
            output_line_list.append(obj_plus_item_str)
notepad.new()
eol = ['\r\n', '\r', '\n'][editor.getEOLMode()]
editor.appendText(eol.join(output_line_list))
</code></pre>
<p dir="auto">If you run this script, you’ll get output like this in a new tab:</p>
<pre><code class="language-txt">...
editor.wordRightEndExtend
editor.wordRightExtend
editor.wordStartPosition
editor.wrapCount
editor.write
editor.zoomIn
editor.zoomOut
notepad.activateBufferID
notepad.activateFile
notepad.activateIndex
notepad.allocateCmdID
notepad.allocateMarker
...
</code></pre>
<p dir="auto">You can then save that tab to a real file, and reference that when you’re seeking a PS function you just can’t quite remember the exact name of, and you can use Peter’s “context help” hint on its data to get further information about a function.</p>
<p dir="auto">--<br />
<em>Moderator EDIT (2024-Jan-14): The author of the script has found a fairly serious bug with the code published here for those that use Mac-style or Linux-style line-endings in their files.  The logic for Mac and Linux was reversed, and thus if the script was used on one type of file, the line-endings for the opposite type of file could end up in the file after the script is run.  This is insidious, because unless one works with visible line-endings turned on, this is likely not noticed.  Some detail on the problem is <a href="https://community.notepad-plus-plus.org/post/91918">HERE</a>.  The script above has been corrected per that instruction.</em></p>
]]></description><link>https://community.notepad-plus-plus.org/post/87757</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87757</guid><dc:creator><![CDATA[Alan Kilborn]]></dc:creator><pubDate>Sun, 14 Jan 2024 18:33:54 GMT</pubDate></item><item><title><![CDATA[Reply to How can I get autocomplete working for Python 3? I'm using the PythonScript plugin. on Mon, 10 Jul 2023 13:37:28 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jay-s" aria-label="Profile: Jay-S">@<bdi>Jay-S</bdi></a> said,</p>
<blockquote>
<p dir="auto">And then I want to reference the <code>editor</code> object. But when I type <code>editor.</code> (Note the period) there are no autocomplete suggestions.</p>
</blockquote>
<p dir="auto">If you have write permission to <code>C:\Program Files\Notepad++\autoCompletion\python.xml</code>, you can add new keywords to Python’s auto-completion list (see the <a href="https://npp-user-manual.org/docs/auto-completion/#create-auto-completion-definition-files" rel="nofollow ugc">online user manual</a> for more about the structure for the auto-completion defininitions).</p>
<p dir="auto">On second read, I noticed you wanted to have more context-aware auto-completion, only giving you valid values after typing <code>editor.</code> (with the period).</p>
<p dir="auto">Unfortunately, the function auto-completion syntax wasn’t designed in a hierarchical way.  One way you could do it is to use the <code>.</code> in the completion text, such as <code>&lt;KeyWord name="notepad.activateBufferID" /&gt;</code> .  However, as the user manual points out:</p>
<table class="table table-bordered table-striped">
<thead>
<tr></tr>
</thead>
<tbody>
<tr>
<td><img src="/assets/uploads/files/1688994326755-63e644b6-bb5e-44b2-99da-a0e680e17243-image.png" alt="63e644b6-bb5e-44b2-99da-a0e680e17243-image.png" class=" img-fluid img-markdown" /></td>
</tr>
</tbody>
</table>
<p dir="auto">This means you probably shouldn’t use the <code>func="yes"</code> field, nor the <code>&lt;Overload&gt;</code> nor <code>&lt;Param&gt;</code> elements inside the <code>&lt;KeyWord&gt;</code> if you’re going to be including the period in the auto-completion.  Also note: if you started by doing <code>editor.addText</code> and then use backspace over the four character of <code>Text</code>, because you wanted to change to <code>editor.addStyledText</code> instead, it will <em>not</em> do suggestion for the auto-completion because Notepad++'s algorithm for matching on the “current word” stops at the punctuation, so it’s trying to auto-complete on <code>add</code> rather than on <code>editor.add</code> .</p>
<p dir="auto">Because of the limitations of punctuation inside the keyword, you might want to consider not doing the <code>.</code>-notation requirement in your autoCompletion definition, and instead just add all the methods as barewords (or add them as both <code>editor.addText</code> and a separate entry for just <code>addText</code>).  It’s not a perfect solution, but it’s better than no auto-completion.</p>
<p dir="auto">You also might want to put in a feature request for PythonScript 3 plugin to have them automatically add the object-aware auto-completion (though they might have to give it a different activation sequence than normal Notepad++ auto-completion), so that way the individual users don’t have to manually add all that to the builtin python auto-completion definition themselves.  No guarantee that they’d actually implement it, but it wouldn’t hurt to have the request added.</p>
<p dir="auto">(I searched through the existing open and closed <a href="https://github.com/bruderstein/PythonScript/issues" rel="nofollow ugc">PythonScript issues</a> and couldn’t find that suggestion yet.  However, I did find <a href="https://github.com/bruderstein/PythonScript/issues/275" rel="nofollow ugc">this question</a>, in which <a class="plugin-mentions-user plugin-mentions-a" href="/user/ekopalypse" aria-label="Profile: Ekopalypse">@<bdi>Ekopalypse</bdi></a> suggested a script for PythonScript which provides an auto-completion list when period is typed… stay tuned, I may have a proof-of-concept extension of that script in the not-too-distant future.)</p>
<blockquote>
<p dir="auto">Also, is there documentation anywhere on the NP++ specific Python bindings anywhere?</p>
</blockquote>
<p dir="auto">The PythonScript plugin ships with its help files; it will end up in <code>C:\Program Files\Notepad++\Plugins\Doc\PythonScript\</code> or equivalent, which can always be accessed through <strong>Plugins &gt; Python Script &gt; Context-Help</strong> (and if you had your text-editing caret at a PythonScript method name in your source, it will show you the help for that method when it opens)</p>
]]></description><link>https://community.notepad-plus-plus.org/post/87753</link><guid isPermaLink="true">https://community.notepad-plus-plus.org/post/87753</guid><dc:creator><![CDATA[PeterJones]]></dc:creator><pubDate>Mon, 10 Jul 2023 13:37:28 GMT</pubDate></item></channel></rss>