Notepad++ Object¶
-
class
Notepad
¶
-
notepad.
activateBufferID
(bufferID)¶ -
Activates the given bufferID:
bufferID = notepad.getCurrentBufferID() ... notepad.activateBufferID(bufferID)
-
notepad.
activateFile
(filename)¶ -
Activates the document with the given filename
-
notepad.
activateIndex
(view, index)¶ -
Activates the document with the given view and index. view is 0 or 1.
-
notepad.
allocateCmdID
(numberRequested) → int¶ -
Allocates a range of Command ID for use in WM_COMMAND. Mainly used internally by plugins.
Returns the start number of the requested range
-
notepad.
allocateMarker
(numberRequested) → bool¶ -
Allocates a range of marker number for Scintilla. Use this to stop marker number collisions with other plugins / scripts.
Returns the start number of the requested range
-
notepad.
allocateSupported
() → bool¶ -
Returns
True
if the Command ID allocation API is supported in this version of Notepad++
-
notepad.
callback
(function, notifications)¶ -
Registers a callback function for a notification. notifications is a list of messages to call the function for.:
def my_callback(args): console.write("Buffer Activated %d\n" % args["bufferID"] notepad.callback(my_callback, [NOTIFICATION.BUFFERACTIVATED])
The
NOTIFICATION
enum corresponds to the NPPN_* plugin notifications. The function arguments is a map, and the contents vary dependant on the notification.Note that the callback will live on past the life of the script, so you can use this to perform operations whenever a document is opened, saved, changed etc.
Also note that it is good practice to put the function in another module (file), and then import that module in the script that calls
notepad.callback()
. This way you can unregister the callback easily.For Scintilla notifications, see
editor.callback()
-> boolReturns
True
if the registration was successful
-
notepad.
clearCallbacks
()¶ -
Unregisters all callbacks
-
notepad.
clearCallbacks
(function) -
Unregisters all callbacks for the given function. Note that this uses the actual function object, so if the function has been redefined since it was registered, this will fail. If this has happened, use one of the other
clearCallbacks()
functions.
-
notepad.
clearCallbacks
(eventsList) -
Unregisters all callbacks for the given list of events.:
notepad.clearCallbacks([NOTIFICATION.BUFFERACTIVATED, NOTIFICATION.FILESAVED])
See
NOTIFICATION
-
notepad.
clearCallbacks
(function, eventsList) -
Unregisters the callback for the given callback function for the list of events.
-
notepad.
close
()¶ -
Closes the currently active document
-
notepad.
closeAll
()¶ -
Closes all open documents
-
notepad.
closeAllButCurrent
()¶ -
Closes all but the currently active document
-
notepad.
createScintilla
() → editor¶ -
Create a new Scintilla handle.
Returns an Editor Object
-
notepad.
decodeSci
(view) → int¶ -
View is either 0 or 1
Returns the old unicode mode
-
notepad.
destroyScintilla
(editor)¶ -
Destroy a Scintilla handle created with createScintilla
-
notepad.
disableAutoUpdate
()¶ -
Disables notepad++ auto update functionality
-
notepad.
docSwitcherDisableColumn
(boolean)¶ -
True
if it should be hidden,False
if it should be shown
-
notepad.
encodeSci
(view) → int¶ -
View is either 0 or 1
Returns the new unicode mode
-
notepad.
flashWindow
(count, milliseconds)¶ -
Flashes notepad++ for the given count and milliseconds
-
notepad.
getAppdataPluginsAllowed
() → bool¶ -
Returns
True
if loading plugins from %APPDATA%\Notepad++\plugins is allowed,False
otherwise
-
notepad.
getBufferFilename
(bufferID)¶ -
Gets the filename of the given buffer ID
-
notepad.
getCommandLine
()¶ -
Gets the command line used to start Notepad++
-
notepad.
getCurrentBufferID
()¶ -
Gets the bufferID of the currently active buffer
-
notepad.
getCurrentDocIndex
(view)¶ -
Gets the current active index for the given view (0 or 1)
-
notepad.
getCurrentFilename
()¶ -
Gets the filename of the active document
-
notepad.
getCurrentNativeLangEncoding
() → int¶ -
Returns the current native language encoding
-
notepad.
getCurrentView
()¶ -
Get the currently active view (0 or 1)
-
notepad.
getEditorDefaultBackgroundColor
() → tuple¶ -
Returns the default background color as tuple
-
notepad.
getEditorDefaultForegroundColor
() → tuple¶ -
Returns the default foreground color as tuple
-
notepad.
getEnableThemeTextureFunc
() → bool¶ -
Returns
True
if a dialog window supports background texturing,False
otherwise.
-
notepad.
getEncoding
([bufferID]) → BUFFERENCODING¶ -
Gets the encoding of the given bufferID. If no bufferID is given, then the encoding of the currently active buffer is returned.
Returns
BUFFERENCODING
-
notepad.
getFiles
() → list¶ -
Gets a list of the open filenames.
Returns A list of tuples containing
(filename, bufferID, index, view)
-
notepad.
getFormatType
([bufferID]) → FORMATTYPE¶ -
Gets the format type (i.e. Windows, Unix or Mac) of the given bufferID. If no bufferID is given, then the format of the currently active buffer is returned.
Returns
FORMATTYPE
-
notepad.
getLanguageDesc
(langType) → LANGTYPE¶ -
Returns the programming language short description from the given
LANGTYPE
-
notepad.
getLanguageName
(langType) → LANGTYPE¶ -
Returns the programming language name from the given
LANGTYPE
-
notepad.
getLangType
([bufferID]) → LANGTYPE¶ -
Gets the language type of the given bufferID. If no bufferID is given, then the language of the currently active buffer is returned.
Returns
LANGTYPE
-
notepad.
getNppDir
() → str¶ -
Gets the directory Notepad++ is running in (i.e. the location of notepad++.exe)
-
notepad.
getMenuHandle
(menu)¶ -
Menu is either 0(main) or 1(plugin) -> int
Returns the handle for the main or plugins menu.
-
notepad.
getNbUserLang
() → int¶ -
Returns the number of user defined languages
-
notepad.
getPluginConfigDir
() → str¶ -
Gets the plugin config directory.
-
notepad.
getPluginMenuHandle
() → int¶ -
Gets the handle for the Plugins menu.
-
notepad.
getPluginVersion
() → str¶ -
Gets the PythonScript plugin version as a string. There is always four parts to it. e.g. ‘0.9.2.0’
-
notepad.
getSessionFiles
(sessionFileName) → list¶ -
Returns a list of files from given session file
-
notepad.
getVersion
() → tuple¶ -
Gets the Notepad++ version as a tuple - e.g. 5.6.8 becomes
(5,6,8)
-
notepad.
hideMenu
(boolean)¶ -
True
if it should be hidden,False
if it should be shown
-
notepad.
hideStatusBar
(boolean)¶ -
True
if it should be hidden,False
if it should be shown
-
notepad.
hideTabBar
()¶ -
Hides the Tab bar
-
notepad.
hideToolBar
(boolean)¶ -
True
if it should be hidden,False
if it should be shown
-
notepad.
isDocSwitcherShown
() → bool¶ -
Returns
True
if document switcher is shown elseFalse
-
notepad.
isMenuHidden
() → bool¶ -
Returns
True
if menu is hidden elseFalse
-
notepad.
isSingleView
()¶ -
True
if only one view is used,False
otherwise
-
notepad.
isStatusBarHidden
() → bool¶ -
Returns
True
if statusbar is hidden elseFalse
-
notepad.
isTabBarHidden
() → bool¶ -
Returns
True
if tabbar is hidden elseFalse
-
notepad.
isToolBarHidden
() → bool¶ -
Returns
True
if toolbar is hidden elseFalse
-
notepad.
launchFindInFilesDlg
(dir2Search, filter)¶ -
Launches the find in files dialog for given directory and filter arguments
-
notepad.
loadSession
(sessionFileName)¶ -
Loads a session from a session file
-
notepad.
makeCurrentBufferDirty
()¶ -
Makes current document dirty
-
Runs a Notepad++ menu command. Use the
MENUCOMMAND
enum, or integers directly from the nativeLang.xml file.
-
notepad.
messageBox
("message: Hello World!", "title: Hello!" , 0) → MessageBoxFlags¶ -
Displays a message box with the given message, title (optional), and message flag (optional)
Flags is 0 by default, where 0 is for a standard ‘OK’ message box, or a combination of
MESSAGEBOXFLAGS
.
is “Python Script for Notepad++” by default.
title -
Returns a RESULTxxxx member of
MESSAGEBOXFLAGS
as to which button was pressed.
-
notepad.
new
()¶ -
Create a new document.
-
notepad.
open
(filename)¶ -
Opens the given file.
-
notepad.
prompt
(prompt, title[, defaultText]) → str¶ -
Prompts the user for some text. Optionally provide the default text to initialise the entry field.
Returns the string entered.
None
if cancel was pressed (note that is different to an empty string, which means that no input was given)
-
notepad.
reloadBuffer
(bufferID)¶ -
Reloads the given bufferID
-
notepad.
reloadCurrentDocument
()¶ -
Reloads the current document
-
notepad.
reloadFile
(filename)¶ -
Reloads a filename.
-
notepad.
runMenuCommand
(menuName, menuOption[, refreshCache]) → bool¶ -
Runs a command from the menus. For built-in menus use notepad.menuCommand(), for non built-in menus (e.g. TextFX and macros you’ve defined), use
notepad.runMenuCommand(menuName, menuOption)
. For other plugin commands (in the plugin menu), usenotepad.runPluginCommand(pluginName, menuOption)_
Menus are searched for the text, and when found, the internal ID of the menu command is cached. When
runMenuCommand
is called, the cache is first checked if it holds the internal ID for the givenmenuName
andmenuOption
. If it does, it simply uses the value from the cache. If the ID could have been updated (for example, you’re calling the name of macro that has been removed and added again), set refreshCache toTrue
. This isFalse
by default.Returns
True
if the menu command was found, otherwiseFalse
e.g.:
notepad.runMenuCommand('TextFX Edit', 'Delete Blank Lines')
-
notepad.
runPluginCommand
(pluginName, menuOption[, refreshCache])¶ -
Runs a command from the plugin menu. Use to run direct commands from the Plugins menu. To call TextFX or other menu functions, either use
notepad.menuCommand(menuCommand)_
(for Notepad++ menu commands), ornotepad.runMenuCommand(menuName, menuOption)_
for TextFX or non standard menus (such as macro names).Note that menuOption can be a submenu in a plugin’s menu. So:
notepad.runPluginCommand('Python Script', 'demo script')
Could run a script called “demo script” from the Scripts submenu of Python Script.
Menus are searched for the text, and when found, the internal ID of the menu command is cached. When
runPluginCommand
is called, the cache is first checked if it holds the internal ID for the givenmenuName
andmenuOption
. If it does, it simply uses the value from the cache. If the ID could have been updated (for example, you’re calling the name of macro that has been removed and added again), set refreshCache toTrue
. This isFalse
by default.- e.g.::
- notepad.runPluginCommand(‘XML Tools’, ‘Pretty Print (XML only)’)
-
notepad.
save
()¶ -
Save the current file
-
notepad.
saveAllFiles
()¶ -
Saves all currently unsaved files
-
notepad.
saveAs
(filename)¶ -
Save the current file as the specified filename
Only works in Notepad++ 5.7 onwards
-
notepad.
saveAsCopy
(filename)¶ -
Save the current file as the specified filename, but don’t change the filename for the buffer in Notepad++
Only works in Notepad++ 5.7 onwards
-
notepad.
saveFile
(filename)¶ -
Saves the provided file - must not be the active one
-
notepad.
saveCurrentSession
(filename)¶ -
Save the current session (list of open files) to a file.
-
notepad.
saveSession
(filename, filesList)¶ -
Saves a session file with the list of filenames.
-
notepad.
setCurrentLang
(langType)¶ -
Set the language type of the currently active buffer (see
LANGTYPE
)
-
notepad.
setEditorBorderEdge
(boolean)¶ -
True
if editor should use border edge,False
otherwise
-
notepad.
setEncoding
(encoding)¶ -
Sets the encoding of the current buffer. Use the
BUFFERENCODING
constants
-
notepad.
setEncoding
(encoding, bufferID) -
Sets the encoding of the given bufferID. Use the
BUFFERENCODING
constants
-
notepad.
setFormatType
(formatType[, bufferID])¶ -
Sets the format type (i.e. Windows, Unix or Mac) of the specified buffer ID. If not bufferID is passed, then the format type of the currently active buffer is set.
-
notepad.
setLangType
(langType[, bufferID])¶ -
Sets the language type of the given bufferID. If not bufferID is given, sets the language for the currently active buffer.
-
notepad.
setSmoothFont
(boolean)¶ -
True
if smooth font should be set,False
otherwise
-
notepad.
setStatusBar
(statusBarSection, text)¶ -
Sets the status bar text. For statusBarSection, use one of the
STATUSBARSECTION
constants.
-
notepad.
showDocSwitcher
(boolean)¶ -
True
if it should be hidden,False
if it should be shown
-
notepad.
showTabBar
()¶ -
Shows the Tab bar
-
notepad.
triggerTabbarContextMenu
(view, index2Activate)¶ -
Activates the context menu for given view and tab index