Class Notepad
Notepad++ wrapper.
Provides access to the Notepad++ application. Most of the API messages and notifications have been made available, but more can be made available as needed.
The global instance npp
is used for application access.
Helper Methods
Notepad.SendEditor(sci_const[, wparam=0[, lparam=0]]) | Sends a message to the current editor. |
Notepad.ConstantName(const[, hint]) | Looks up the symbolic name of a constant. |
Notepad.AddEventHandler(event, callback) | Registers a Lua function to handle a given event. |
Notepad.RemoveEventHandler(event, callback) | Removes previously registered Lua function for a given event. |
Notepad.RemoveAllEventHandlers(event) | Removes all registered Lua functions for a given event. |
Notepad.AddShortcut(name, shortcut, callback) | Registers a Lua function for a shortcut key. |
Notepad.WriteError(...) | Writes an error message to the console. |
Notepad.ClearConsole() | Clears the console. |
Notepad.StartTimer(ms, callback) | Continuously calls a function at a set interval. |
Notepad.StopTimer(timer) | Stops a previously created timer. |
Methods
Notepad:ActivateDoc(view, index2Activate) | Activates the specified document. |
Notepad:DisableAutoUpdate() | Disable checking for auto updates. |
Notepad:DmmViewOtherTab(name) | View another docked tab. |
Notepad:DoOpen(file) | Opens a document. |
Notepad:DocSwitcherDisableColumn(toShow) | Enable or disable the file extension column in the doc switcher. |
Notepad:GetBufferIDFromPos(position, view) | Gets the BufferID located at the given position. |
Notepad:GetCurrentDirectory() | Gets the current directory of the document. |
Notepad:GetCurrentDocIndex(view) | Gets the current document index within the view. |
Notepad:GetCurrentWord() | Selects and returns the word at the cursor's position |
Notepad:GetExtPart() | Gets the file extension of the current document. |
Notepad:GetFileName() | Gets the file name of the current document. |
Notepad:GetFileNameAtCursor() | Gets the file name at the cursor position. |
Notepad:GetFullCurrentPath() | Gets the full path of the current document. |
Notepad:GetFullPathFromBufferID(BufferID) | Gets the full path of the provided buffer ID. |
Notepad:GetNamePart() | Gets the file name (without extension) of the current document. |
Notepad:GetNbOpenFiles(view) | Gets the number of open documents. |
Notepad:GetNbSessionFiles(session) | Gets the number of files a the session file. |
Notepad:GetNppDirectory() | Gets the directory of the Notepad++ application. |
Notepad:GetPluginsConfigDir() | Gets the plugin configuration directory. |
Notepad:GetPosFromBufferID(BufferID, priorityView) | Gets the position information of the provided buffer ID. |
Notepad:HideMenu(hideOrNot) | Hides or shows the menu. |
Notepad:HideStatusBar(hideOrNot) | Hides or shows the status bar. |
Notepad:HideTabBar(hideOrNot) | Hides or shows the tab bar. |
Notepad:HideToolBar(hideOrNot) | Hides or shows the tool bar. |
Notepad:IsDocSwitcherShown() | Gets whether the doc switcher is hidden or shown. |
Notepad:IsMenuHidden() | Gets whether the menu is hidden or shown. |
Notepad:IsStatusBarHidden() | Gets whether the status bar is hidden or shown. |
Notepad:IsTabBarHidden() | Gets whether the tab bar is hidden or shown. |
Notepad:IsToolBarHidden() | Gets whether the tool bar is hidden or shown. |
Notepad:LaunchFindInFilesDlg(path, filter) | Launch the "Find in Files" dialog. |
Notepad:LoadSession(filename) | Loads a session file. |
Notepad:MakeCurrentBufferDirty() | Makes the current buffer marked as dirty. |
Notepad:MenuCommand(command) | Executes a menu command. |
Notepad:ReloadBufferID(BufferID, alertOrNot) | Reloads the specified buffer ID. |
Notepad:ReloadFile(withAlert, filename) | Reloads the specified file. |
Notepad:SaveAllFiles() | Saves all the opened documents. |
Notepad:SaveCurrentFile() | Saves the current document. |
Notepad:SaveCurrentFileAs(asCopy, filename) | Saves the current document as the specified name. |
Notepad:SaveCurrentSession(session) | Saves a new session file of the currently opened buffers. |
Notepad:SetEditorBorderEdge(useOrNot) | Enable or disable the editor's border edge |
Notepad:SetSmoothFont(useOrNot) | Enable or disable the use of smooth fonts. |
Notepad:ShowDocSwitcher(showOrNot) | Enable or disable the doc switcher panel. |
Notepad:SwitchToFile(filename) | Switch to the specified document. |
Notepad:TriggerTabbarContextMenu(view, index) | Activate the tab bar context menu. |
Properties
Notepad.AppDataPluginsAllowed | Whether plugins are allowed to be loaded from the %APPDATA% directory. |
Notepad.BufferFormat[id] | Gets or sets the buffer's end of line mode (one of the SC_EOL_xxx constants). |
Notepad.BufferLangType[id] | Gets or sets the buffer's language type (one of the L_xxx constants). |
Notepad.CurrentBufferID | Gets the current BufferID. |
Notepad.CurrentColumn | Gets the current column of the cursor. |
Notepad.CurrentLine | Gets the current line number of the cursor. |
Notepad.CurrentView | Gets the currently active view, either MAIN_VIEW or SUB_VIEW . |
Notepad.DefaultBackgroundColor | Gets the default background color used for documents. |
Notepad.DefaultForegroundColor | Gets the default foreground color used for documents. |
Notepad.LanguageDescription[language] | Gets the description of a language. |
Notepad.LanguageName[language] | Gets the language name. |
Notepad.NativeLangEncoding | Gets the encoding of Notepad++'s localization. |
Notepad.StatusBar[field] | Sets the status bar's text. |
Notepad.Version | Gets the Notepad++ version. |
Notepad.WindowsVersion | Gets the version of the Windows operating system (one of the WV_xxx constants). |
Helper Methods
- Notepad.SendEditor(sci_const[, wparam=0[, lparam=0]])
-
Sends a message to the current editor.
This duplicates the functionality of the editor object, providing access to this through an interface that is more familiar to Scintilla C++ developers.
Parameters:
- sci_const int A SCI_xxx message constant
- wparam optional parameter dependent on the specific message (default 0)
- lparam optional parameter dependent on the specific message (default 0)
Returns:
-
optional return value dependent on the specific message
- Notepad.ConstantName(const[, hint])
-
Looks up the symbolic name of a constant.
Parameters:
- const int number
- hint string the prefix of the constant to attempt to find (optional)
Returns:
-
string
The symbolic name of a Scintilla / Notepad++ constant. Raises error if not found.
- Notepad.AddEventHandler(event, callback)
-
Registers a Lua function to handle a given event.
See the topic on Callbacks
Parameters:
- event string name of the desired event (can also be an array of strings)
- callback function function to call when the event(s) is triggered
Returns:
-
bool
always returns
true
currently - Notepad.RemoveEventHandler(event, callback)
-
Removes previously registered Lua function for a given event.
Parameters:
- event string name of the desired event
- callback function a previously registered function
Returns:
-
bool
true
if the function had been previously registered, elsefalse
See also:
- Notepad.RemoveAllEventHandlers(event)
-
Removes all registered Lua functions for a given event.
Parameters:
- event string name of the desired event
See also:
- Notepad.AddShortcut(name, shortcut, callback)
-
Registers a Lua function for a shortcut key.
The callback is not passed any parameters.
Note: This can only be called during startup.
Parameters:
- name string the user-friendly name of the shortcut (this is displayed in the menu)
- shortcut
string
the modifier and key (e.g. "
Ctrl+Alt+Shift+D
"). The key must be one of:A
-Z
,0
-9
,F1
-F12
,;
,/
,~
,[
,\
,]
,\
,,
,-
,.
,=
,up
,down
,left
,right
,space
,pageup
,pagedown
,backspace
,delete
,escape
- callback function function to call when the shortcut is triggered
- Notepad.WriteError(...)
-
Writes an error message to the console.
Calls
tostring
on each parameter and prints the results in the console in red text.Parameters:
- ... variable number of arguments
- Notepad.ClearConsole()
- Clears the console.
- Notepad.StartTimer(ms, callback)
-
Continuously calls a function at a set interval.
Note: The timer will continue to fire until StopTimer is called. Also, these timers run synchronously in the same thread as Notepad++, meaning that if Notepad++ is busy processing the file (such as doing search/replace) the timer event will get delayed. It is safe to access any of the globally defined LuaScript objects in the callback.
Parameters:
- ms int milliseconds to wait between calls
- callback
function
function to be called. It will be passed a singe parameter, the opaque
timer
object
Returns:
-
the opaque
timer
objectSee also:
Usage:
-- A trivial example...save a copy of the current file every 10 seconds, unless the file is too big npp.StartTimer(10000, function(timer) if editor.Length < 1000 then npp:SaveCurrentFileAs(true, [[C:\path\to\current\file.backup]]) else npp.StopTimer(timer) end end)
- Notepad.StopTimer(timer)
-
Stops a previously created timer.
Parameters:
- timer
the opaque
timer
object returned from StartTimer or passed into the callback
See also:
- timer
the opaque
Methods
- Notepad:ActivateDoc(view, index2Activate)
-
Activates the specified document.
Parameters:
- view
int
either
MAIN_VIEW
orSUB_VIEW
- index2Activate int index of the view to activate
- view
int
either
- Notepad:DisableAutoUpdate()
- Disable checking for auto updates.
- Notepad:DmmViewOtherTab(name)
-
View another docked tab.
Parameters:
- name string name of the docked tab (e.g. "Function List")
- Notepad:DoOpen(file)
-
Opens a document.
Parameters:
- file string name
Returns:
-
bool
true
if successful, elsefalse
- Notepad:DocSwitcherDisableColumn(toShow)
-
Enable or disable the file extension column in the doc switcher.
Parameters:
- toShow bool whether to show or hide the column
- Notepad:GetBufferIDFromPos(position, view)
-
Gets the BufferID located at the given position.
Parameters:
- position int position of document
- view
int
either
MAIN_VIEW
orSUB_VIEW
Returns:
-
int
BufferID or 0 if invalid
- Notepad:GetCurrentDirectory()
-
Gets the current directory of the document.
Returns:
-
string
current directory
- Notepad:GetCurrentDocIndex(view)
-
Gets the current document index within the view.
Parameters:
- view
int
either
MAIN_VIEW
orSUB_VIEW
Returns:
-
int
index of the current document. -1 if the requested view is not visible.
- view
int
either
- Notepad:GetCurrentWord()
-
Selects and returns the word at the cursor's position
Returns:
-
string
word
- Notepad:GetExtPart()
-
Gets the file extension of the current document.
Returns:
-
string
file extension
- Notepad:GetFileName()
-
Gets the file name of the current document.
Returns:
-
string
file name
- Notepad:GetFileNameAtCursor()
-
Gets the file name at the cursor position.
Returns:
-
string
file path
- Notepad:GetFullCurrentPath()
-
Gets the full path of the current document.
Returns:
-
string
full path
- Notepad:GetFullPathFromBufferID(BufferID)
-
Gets the full path of the provided buffer ID.
Parameters:
- BufferID int
Returns:
-
string
full path
- Notepad:GetNamePart()
-
Gets the file name (without extension) of the current document.
Returns:
-
string
- Notepad:GetNbOpenFiles(view)
-
Gets the number of open documents.
Parameters:
- view
int
either
ALL_OPEN_FILES
,PRIMARY_VIEW
, orSECOND_VIEW
Returns:
-
int
- view
int
either
- Notepad:GetNbSessionFiles(session)
-
Gets the number of files a the session file.
Parameters:
- session string full path to the session file
Returns:
-
int
number of files
- Notepad:GetNppDirectory()
-
Gets the directory of the Notepad++ application.
Returns:
-
string
- Notepad:GetPluginsConfigDir()
-
Gets the plugin configuration directory.
Returns:
-
string
- Notepad:GetPosFromBufferID(BufferID, priorityView)
-
Gets the position information of the provided buffer ID.
Parameters:
- BufferID int
- priorityView
int
either
MAIN_VIEW
orSUB_VIEW
. If priorityView set toSUB_VIEW
, then it will be searched first
Returns:
-
int
the two highest bits will either be
MAIN_VIEW
orSUB_VIEW
. The lower 30 bits will be the 0-based index. - Notepad:HideMenu(hideOrNot)
-
Hides or shows the menu.
Parameters:
- hideOrNot bool whether or not to hide the menu
Returns:
-
bool
the previous state
- Notepad:HideStatusBar(hideOrNot)
-
Hides or shows the status bar.
Parameters:
- hideOrNot bool whether or not to hide the status bar
Returns:
-
bool
the previous state
- Notepad:HideTabBar(hideOrNot)
-
Hides or shows the tab bar.
Parameters:
- hideOrNot bool whether or not to hide the tab bar
Returns:
-
bool
the previous state
- Notepad:HideToolBar(hideOrNot)
-
Hides or shows the tool bar.
Parameters:
- hideOrNot bool whether or not to hide the tool bar
Returns:
-
bool
the previous state
- Notepad:IsDocSwitcherShown()
-
Gets whether the doc switcher is hidden or shown.
Returns:
-
bool
- Notepad:IsMenuHidden()
-
Gets whether the menu is hidden or shown.
Returns:
-
bool
- Notepad:IsStatusBarHidden()
-
Gets whether the status bar is hidden or shown.
Returns:
-
bool
- Notepad:IsTabBarHidden()
-
Gets whether the tab bar is hidden or shown.
Returns:
-
bool
- Notepad:IsToolBarHidden()
-
Gets whether the tool bar is hidden or shown.
Returns:
-
bool
- Notepad:LaunchFindInFilesDlg(path, filter)
-
Launch the "Find in Files" dialog.
Parameters:
- path string the directory path to search
- filter string the filter to use (e.g. "*.c *.h")
- Notepad:LoadSession(filename)
-
Loads a session file.
Parameters:
- filename string full path to the session file
- Notepad:MakeCurrentBufferDirty()
- Makes the current buffer marked as dirty.
- Notepad:MenuCommand(command)
-
Executes a menu command.
Parameters:
- command int one of the IDM_xxx constants
- Notepad:ReloadBufferID(BufferID, alertOrNot)
-
Reloads the specified buffer ID.
Parameters:
- BufferID int
- alertOrNot bool whether to show an alert dialog.
Returns:
-
bool
- Notepad:ReloadFile(withAlert, filename)
-
Reloads the specified file.
Parameters:
- withAlert bool use an alert or not
- filename string file name to reload
- Notepad:SaveAllFiles()
-
Saves all the opened documents.
Returns:
-
bool
- Notepad:SaveCurrentFile()
-
Saves the current document.
Returns:
-
bool
- Notepad:SaveCurrentFileAs(asCopy, filename)
-
Saves the current document as the specified name.
Parameters:
- asCopy bool flag to indicate of the file should be saved as a copy
- filename string file name
Returns:
-
bool
- Notepad:SaveCurrentSession(session)
-
Saves a new session file of the currently opened buffers.
Parameters:
- session string full path of the new session file
- Notepad:SetEditorBorderEdge(useOrNot)
-
Enable or disable the editor's border edge
Parameters:
- useOrNot bool
- Notepad:SetSmoothFont(useOrNot)
-
Enable or disable the use of smooth fonts.
Parameters:
- useOrNot bool
- Notepad:ShowDocSwitcher(showOrNot)
-
Enable or disable the doc switcher panel.
Parameters:
- showOrNot bool
- Notepad:SwitchToFile(filename)
-
Switch to the specified document.
Parameters:
- filename string file name
Returns:
-
bool
true
if successful, elsefalse
- Notepad:TriggerTabbarContextMenu(view, index)
-
Activate the tab bar context menu.
Parameters:
- view
int
either
MAIN_VIEW
orSUB_VIEW
- index int 0-based index
- view
int
either
Properties
- Notepad.AppDataPluginsAllowed
-
Whether plugins are allowed to be loaded from the
%APPDATA%
directory.- AppDataPluginsAllowed bool (readonly)
- Notepad.BufferFormat[id]
-
Gets or sets the buffer's end of line mode (one of the
SC_EOL_xxx
constants).- id BufferID
- Notepad.BufferLangType[id]
-
Gets or sets the buffer's language type (one of the
L_xxx
constants).- id BufferID
- Notepad.CurrentBufferID
-
Gets the current BufferID.
- CurrentBufferID BufferID (readonly)
- Notepad.CurrentColumn
-
Gets the current column of the cursor.
- CurrentColumn int (readonly)
- Notepad.CurrentLine
-
Gets the current line number of the cursor.
- CurrentLine int (readonly)
- Notepad.CurrentView
-
Gets the currently active view, either
MAIN_VIEW
orSUB_VIEW
.- CurrentView int (readonly)
- Notepad.DefaultBackgroundColor
-
Gets the default background color used for documents.
- DefaultBackgroundColor colour (readonly)
- Notepad.DefaultForegroundColor
-
Gets the default foreground color used for documents.
- DefaultForegroundColor colour (readonly)
- Notepad.LanguageDescription[language]
-
Gets the description of a language.
- language
int
one of the
L_xxx
constant (readonly)
- language
int
one of the
- Notepad.LanguageName[language]
-
Gets the language name.
- language
int
one of the
L_xxx
constant (readonly)
- language
int
one of the
- Notepad.NativeLangEncoding
-
Gets the encoding of Notepad++'s localization.
- NativeLangEncoding int (readonly)
- Notepad.StatusBar[field]
-
Sets the status bar's text.
field
must be one of the following:STATUSBAR_DOC_TYPE
STATUSBAR_DOC_SIZE
STATUSBAR_CUR_POS
STATUSBAR_EOF_FORMAT
STATUSBAR_UNICODE_TYPE
STATUSBAR_TYPING_MODE
- field int
- Notepad.Version
-
Gets the Notepad++ version.
The high 16 bits contain the major version. The low 16 bits contain the minor version.
- Version int (readonly)
Usage:
print((npp.Version >> 16) .. '.' .. (npp.Version & 0xff))
- Notepad.WindowsVersion
-
Gets the version of the Windows operating system (one of the
WV_xxx
constants).- WindowsVersion int (readonly)