PSPad editor script interface description

Note!
Don’t place any non script files direct into script language subdirectories !
All files e.g. in VBScript subrirectory are consider as script and non script file causes compilation error.

modules library

You can write own library and share function from library in other scripts. Unique module_name is identifier.
To call function from other module, place module name before function name:
myLibrary.someFunction()

global functions/subroutines

addMenuItem(caption: string; submenu: string; procedure: string)
creates menu item in PSPad main menu. if you don't want submenu, send empty string as parameter
Its contained in script Init subroutine and works only during Init phase. All other calling is ignored.

echo(text: string)
information box with text and button OK
sleep(ms: integer)
stops script execution for number of miliseconds
setWaitCursor([boolean])
sets screen cursor to HourGlass (true parameter) and Default one (false parameter)
inputText(label [, default_value [, cancel_value]]: string): string
input text dialog. Cancel_value is returned after press Cancel button.

setClipboardText(text: string)
stores text into clipboard
getClipboardText(): string
returns text from clipboad

runPSPadAction(ActionName: string)
allows to run any PSPad editor action. List of actions follows.
getVarValue(name: string)
returns value of variable passed as parameter. You can use PSPad or system variable as well. 
reloadClips
reloads all code clip files

logClear
clears whole LOG window content
logAddLine(test: string)
adds new line into LOG
logGetLine(index: integer): string
returns line from LOG, identified by index parameter (numbered from 0)
logSetLine(index: integer, test: string)
sets log line, identified by index
logLinesCount(): Integer
returns current number of LOG window lines
logLineIndex([index: integer]): Integer
sets or returns (if no parameter) current line index of LOG window
logSetTypeMemo
sets LOG window type to memo style - you are able to make free selection, byt without error marks
logSetTypeList
sets LOG window type to list style - only line by line selection, but with error marks
logIsVisible(): Boolean
returns if LOG window is visible or not
logSetParser(expression: string): string
sets LOG parser expression

pspadVersion(): string
returns PSPad version
moduleExists(name: string):boolean
returns True if script module exists
moduleVersion(name: string):string
returns version of module, if module doesn't exists, returns empty string
moduleFileName(name: string):string
returns file name of module, if module doesn't exists, returns empty string.
modulePath():string
returns module file path include last backslash
mainWindowHandle():HWND
returns main PSpad window handle (HWND)

closeEditorByTitle(file_name: string): boolean
closes editor by filename
closeEditorByIndex(index: integer): boolean
closes editor by index
closeAllEditors
closes all editor windows
editorsCount: integer
returns number of open editors
pspadClosing(): boolean
returns if PSPad is in closing state
reloadUserHighlighter(name: string)
if user highlighter name (of definition file name) sent as parameter is loaded, PSPad will reload user highlighter definition

projectFilesCount: integer
returns number of files (not folders) in project. Use cycle from 0 to projectFilesCount-1
projectFiles(index: integer): string
returns file name for index. If file doesn't exists, returns empty string
projectItemsCount: integer
returns number of all items (files and folders) in project. Use cycle from 0 to projectItemsCount-1
projectItems(index: integer): string
returns item name for index. If item doesn't exists, returns empty string
projectItemType(index: integer): integer
returns project item type. 1: folder, 2: file, -1: item doesn't exists
projectFileName: string
returns project file name
projectSave
saves project

ftpConnect(connection_name: string): boolean
connect to in PSPad defined FTP connection
ftpDisconnect
disconnect FTP server
ftpCommand(command: string): string
send command to FTP server, e.g. "CWD \public\www". Function returns FTP server return stringserveru
ftpDownloadFile(ftp_filename, local_filename): boolean
download file from ftp and stored it as local file
ftpUploadFile(local_filename, ftp_filename, [refresh]): boolean
uploads local file to current FTP directory, when refresh parameters is send, FTP folder will be refreshed after uload
ftpRefresh
refresh current ftp folder

newEditor(): object
creates new object for editor handling

editor object function

assignEditorByName(file_name: string): boolean
assign editor window to object by file name
assignEditorByIndex(index: integer): boolean
assign editor window to object by editor index
assignActiveEditor(): boolean
assign active editor window into object and show it
assignLog(): boolean
this function is obsolete now. Is replaced with logXXXXX() functions. Now returns always 0, in the past returns always 1
newFile([file_name: string]): boolean
creates new file in PSPad. File name is optional
openFile(file_name: string): boolean
opens existing file in new editor window
saveFile(): boolean
saves file
saveFileAs(file_name: string): boolean
saves file as
reloadFile(): boolean
reload file
closeFile(): boolean
closes file
activate(): boolean
brings editor to front
editorWindowHandle():HWND
returns assigned editor window handle (HWND)
printFile(boolean): boolean
if parameters is 1 then PrintDialog appears before print
readOnly([boolean]): boolean
returns if no param or sets editor ReadOnly state
modified([boolean]): boolean
returns if no param or sets editor Modified state
splitWindow([integer]): integer
set/get editor split type. 0 - isn't split, 1 - vertical split, 2 - horizontal split
text(string):string
replaces/returns all editor text
selText(string): string
replaces/returns selected text from editor
lineText(string): string
replaces/returns content of active line
linesCount(): integer
returns editor lines count
topLineIndex([integer]): integer
sets or returns returns index of the first line in editor window
linesInWindow(): integer
returns number of lines in editor window
appendText(string): boolean
appends text to editor end
fileName(string): string
sets/returns editor file name
command(editor_command: string): boolean
runs editor command processor command
setCaretPos(x: integer; y: integer): boolean
sets editor caret position. -1 in  parameter mean no change coordinate
caretX(integer): integer
sets/returns editor CaretX position
caretY(integer): integer
sets/returns editor CaretY position
markEditorLine(integer)
marks line in editor - same as you click on the line in LOG window
setBlockBegin(x: integer; y: integer): boolean
sets start of the block
setBlockEnd(x: integer; y: integer): boolean
sets end of the block
selectionMode([s: string]): string
sets selection mode. C: column, N: normal, L: line selection
if no parameter is sent, function returns C for column, N for normal and L for line selection mode of current editor
blockBeginX: integer
returns block start column
blockBeginY: integer
returns block start line
blockEndX: integer
returns block end column
blockEndY: integer
returns block end line
selStart(integer): integer
returns/sets block start
selLength(integer): integer
returns/sets block length
highlighter([s: string]): string
returns/set highlighter for editor
textDiffWithFileName(string)
calls TextDiff of the current editor with filename given by parameter
textDiffWithEditorIndex(integer)
calls TextDiff of the current editor with editor index given by parameter
tabColor(string): string
returns/sets current file tab color. Color is in RGB format as string: "RRGGBB"

editor commands list

ecLeft            move cursor left one char
ecRight           move cursor right one char
ecUp              move cursor up one line
ecDown            move cursor down one line
ecWordLeft        move cursor left one word
ecWordRight       move cursor right one word
ecLineStart       move cursor to beginning of line
ecLineEnd         move cursor to end of line
ecPageUp          move cursor up one page
ecPageDown        move cursor down one page
ecPageLeft        move cursor right one page
ecPageRight       move cursor left one page
ecPageTop         move cursor to top of page
ecPageBottom      move cursor to bottom of page
ecEditorTop       move cursor to absolute beginning
ecEditorBottom    move cursor to absolute end
ecNextLineStart   move cursor to next line begining
                   
ecSelLeft         ecLeft + ecSelection;
ecSelRight        ecRight + ecSelection;
ecSelUp           ecUp + ecSelection;
ecSelDown         ecDown + ecSelection;
ecSelWord     	selects word under cursor
ecSelWordLeft     ecWordLeft + ecSelection;
ecSelWordRight    ecWordRight + ecSelection;
ecSelLineStart    ecLineStart + ecSelection;
ecSelLineEnd      ecLineEnd + ecSelection;
ecSelPageUp       ecPageUp + ecSelection;
ecSelPageDown     ecPageDown + ecSelection;
ecSelPageLeft     ecPageLeft + ecSelection;
ecSelPageRight    ecPageRight + ecSelection;
ecSelPageTop      ecPageTop + ecSelection;
ecSelPageBottom   ecPageBottom + ecSelection;
ecSelEditorTop    ecEditorTop + ecSelection;
ecSelEditorBottom ecEditorBottom + ecSelection;
                    
ecScrollUp        scroll up one line leaving cursor position unchanged.
ecScrollDown      scroll down one line leaving cursor position unchanged.
ecScrollLeft      scroll left one char leaving cursor position unchanged.
ecScrollRight     scroll right one char leaving cursor position unchanged.
                    
ecInsertMode      set insert mode
ecOverwriteMode   set overwrite mode
ecToggleMode      toggle ins/ovr mode
                    
ecNormalSelect    normal selection mode
ecColumnSelect    column selection mode
ecLineSelect      line selection mode
                    
ecMatchBracket    go to matching bracket
                    
ecGotoMarker0     goto marker
...
ecGotoMarker9     goto marker
ecSetMarker0      set marker
...
ecSetMarker9      set marker
                    
ecDeleteLastChar  delete last char (i.e. backspace key)
ecDeleteChar      delete char at cursor (i.e. delete key)
ecDeleteWord      delete from cursor to end of word
ecDeleteLastWord  delete from cursor to start of word
ecDeleteBOL       delete from cursor to beginning of line
ecDeleteEOL       delete from cursor to end of line
ecDeleteLine      delete current line
ecClearAll        delete everything
ecLineBreak       break line at current position, move caret to new line
ecInsertLine      break line at current position, leave caret
                    
ecUndo            perform undo if available
ecRedo            perform redo if available
ecCut             cut selection to clipboard
ecPaste           paste clipboard to current position
ecSelectAll       select entire content of editor, cursor to end
ecCopy            copy selection to clipboard
                    
ecBlockIndent     indent selection
ecBlockUnindent   unindent selection
ecTab             tab key
ecShiftTab        shift+Tab key
                    
ecUpperCase       apply to the current or previous word
ecLowerCase         
ecToggleCase        
ecTitleCase         
ecUpperCaseBlock  apply to current selection, or current char if no selection
ecLowerCaseBlock    
ecToggleCaseBlock   

PSPad actions list

aAddDiacritic	Add accent marks (dictionary is required)
aAddFile	Add current file to project
aAddFilesToFolder	Add Files to project - dialog
aAddFolder	New folder to project
aAllToASCII	Remove Accent from chars
aANSIToBase64	Encode all text/selected text to Base64
aANSIToQuotedPrint	Encode all text/selected text to Quoted printable
aANSIToURL	Encode all text/selected text to URL adress form
aAutoCompl	Auto completion
aAutoRefresh	Set Autorefresh flag for window
aBase64ToANSI	Decode all text/selected text from Base64
aBlockAlign	Align selection to block
aBlockCenter	Justify block to the center
aBlockLeft	Justify block to the left
aBlockRight	Justify block to the right
aCapitalize	Capitalize block
aClose	Close window
aCloseAll	Close All
aCodeExplorer	Code Explorer window
aCodeFormat	Code Case Change dialog
aColorSelect	Color Selector window
aComment	Add/Remove Comment
aCompile	Compile
aCopy	Copy
aCopyLine	Copy Line
aCSSToInLine	Reformat into Inline CSS
aCSSToStructure	Reformat into Structured CSS
aCSVImport	Import from CSV dialog
aCut	Cut
aDateTime	Insert Date Time
aDateTimeDialog	Date Time Dialog
aDecToHex	Decimal to Hexadecimal selection
aDelete	Delete
aDelFolder	Remove Folder from project
aDelMark	Delete Bookmark
aDelMarks	Delete all Bookmarks
aDiffSame	Text Diff with File Contents on Disk
aDosFormat	Change line ends to DOS (CR+LF)
aExit	Exit
aExpClipHTML	Export to Clipboard as HTML
aExpClipRTF	Export to Clipboard as RTF
aExpClipTeX	Export to Clipboard as &TeX
aExpClipXHTML	Export to clipboard as XHTML
aExport	Export dialog
aFilesSearch	Search / Replace in Files dialog
aFind	Find dialog
aFindNext	Find Next
aFindPrev	Find Previous
aFindPrevWord	Previous Occurrence of Current Word
aFindWord	Next Occurrence of Current Word
aFont	Font dialog
aFullScreen	Full Screen mode
aGoogleSearch	Google Search dialog
aGotoLine	Goto Line dialog
aGUID	Insert GUID
aHexToDec	Hexadecimal to Decimal selection
aHTMLCompress	Compress HTML code
aHtmlCheck	Check HTML code
aHTMLPrev	HTML Page Preview
aHTMLReformat	Reformat HTML code
aHTMLSelTag	Select TAG
aIndent	Indent Block
aInfo	File Info
aInserFile	Insert From File...
aInsertText	Insert Text into Lines...
aInvertCase	Invert Case
aJoinLine	Join Lines
aLangHelp	Help for Language
aLastUserConvertor	Run Last used convertor
aLineNum	Line Numbers
aLogWindow	Show / Hide LOG window
aLoremIpsum	Lorem Ipsum generator
aLowerCase	To Lower Case
aMacFormat	Change line ends to MAC (CR)
aMacroMgr	Macro Manager
aMacroPlay	Play Macro
aMacroRecord	Start / Stop Recording
aMailContents	As e-mail Contents
aMailFile	As e-mail Attachment
aMarkDown	Next Bookmark
aMarkSelection	Sets bookmarks to selection begin and end
aMarkList	Bookmark List
aMarkUp	Previous Bookmark
aMatchBracket	Matching Bracket
aMD5Gen	Hash generator dialog
aMoveAs	Move as dialog
aNew	New file dialog
aOpen	Open file dialog
aOpenCopy	Open Active File with New Name dialog
aOpenHex	Open in HEX Editor dialog
aOpenSame	Open R/O copy of Active File
aOpenSelected	Open file appointed by selection
aOpenWWWFile	Open File from Internet dialog
aPageSetup	Page Setup dialog
aPaste	Paste
aPasteHTML	Paste as HTML
aPasteNoMove	Paste Without Cursor Change
aPrint	Print file
aPrintPrev	Print Preview
aPrintSetup	Printer Settings dialog
aProjAddOpen	Add all open files to project
aProjFolderClose	Close files of current project folder
aProjFolderOpen	Open files of current project folder
aProjFromDir	Create Project from Directory dialog
aProjInfo	Project Information dialog
aProjMainFile	Set File as Main for Compiler
aProjNew	New Project (closes all)
aProjOpen	Open Project dialog
aProjSave	Save Project
aProjSaveas	Save Project as dialog
aProjSettings	Project Settings dialog
aProjShow	Show/hide left Panel
aQuotedPrintToANSI	Decode all text/selected text from Quoted printable
aReadOnly	Read Only on/off for file
aRedo	Redo
aReformat	Reformat block (paragraph=blank line)
aReformat2	Reformat block (paragraph=short line)
aRemoveBlankLines	Remove Blank Lines
aRemoveFile	Remove File from Project
aRemoveRedundantBlank	Remove Redundant Blank Lines
aRemoveSpaces	Remove Redundant Spaces dialog
aRemoveTags	Remove HTML tags - it opens result in new window
aReOpen	Reopen Active File
aRepeatLastAction	Repeat last command
aReplace	Replace dialog
aRollBar	Ruler on/off
aRTFImport	Import text from RTF
aSave	Save current file
aSaveAll	Save All files
aSaveAs	Save As dialog
aSaveBlock	Save Block As dialog
aSaveSameTime	Save Without changing File Date
aSaveToFTP	Save to FTP
aScriptsRecompile	Recompile scripts
aSelectAll	Select All
aSelectNext	Next Window
aSelectPrew	Previous Window
aSelInsideMarks	Select text inside nearest Bookmarks
aSelMatchBracket	Select Inside Brackets
aSelString	Select String
aSendToDisk	Save to Drive A:
aSentensize	Sentensize selection
aSetMain	Set as Main File for Compiler
aSetMark	Set Bookmark
aShellOpen	Open with associated application
aShowControlBar	Show/hide all toolbars
aShowSpecChar	Show/hide nonprinted characters
aSort	Sort dialog
aSpell	Online Spell Check on/off
aSpellCheck	Spell Check with dialog
aSpellSett	Spell Settings dialog
aStayOnTop	Stay on Top on/off
aSwapLineAbove	Swap line with line above (applicable to block)
aSwapLineBellow	Swap line with line bellow (applicable to block)
aSwapBlock	Swap lines in selected block
aSwitchLog	Jump to Editor / LOG
aSyntax	Syntax on/off
aSyntaxChange	Change Syntax dialog
aSysEdit	Open System Files (Autoexc, Config, ...)
aTabToSpaces	Convert Tabs to Spaces dialog
aTagToLowercase	Tags to Lowercase
aTagToUpperCase	Tags to Uppercase
aTextToHTML	Text to HTML
aToJScript	Selection to JavaScript
aToPHP	Selection to PHP variable
aUndo	Undo
aUnIndent	UnIndent Block
aUnixFormat	Change line ends to UNIX (LF)
aUnQuote	Remove Email Quoting
aUpperCase	To Upper Case
aURLToANSI	Decode all text/selected text from URL adress form
aUserConvertors	User Convertors dialog
aWindCascade	Cascade windows
aWindSplitHoriz	Horizontal Split current file
aWindSplitVert	Vertical Split current file
aWindTile	Arrange windows
aWindTileHoriz	Tile windows Horizontal
aWindTileVert	Tile windows Vertical
aWordWrap	Word Wrap Lines on/off

sample vb script

sample n.1 - modify lines of current file using regular expressions

' it will renumber all pictures from 01...
' sample source:
'... <img alt="01" src="../Images/01.jpg"/></p> ...
const module_name  = "Numbering"         'this name must be unique !!!
const module_desc  = "Pictures numbering"  'script description
const module_ver   = "1.00"         'version

sub Main
    ' regular expression initialization, instead of " we use "." (any char):
  Set re = New RegExp
  re.Pattern = "(<img alt=.)(\d+)(. src=.\.\./Images/)(\d+)(\.jpg)"
  re.Global  = False
  re.IgnoreCase = True

  set obj1 = newEditor()	'new editor object
  obj1.assignActiveEditor()	'assign active editor
  dim s
  s = ""
    PictNum = 1
  PictStr = ""
    'go through lines in editor
  for i = 1 to obj1.linesCount()  'go through lines in editor
      obj1.CaretY(i)		'set cursor to line number i
      s = obj1.lineText()	'read line content to variable
      PictStr = Right("00" & PictNum, 2)	'new line number with leading zero
      if re.Test(s) then	'if line match to regular expression then replace
        s = re.Replace(s, "$1" & PictStr & "$3" & PictStr & "$5")
        obj1.lineText(s)	'write modified line back
        PictNum = PictNum + 1	'increase picture number
      end if
  next
end sub

' name "Init" is required, its called automatically during initialization to create menu items
sub Init
  addMenuItem "Sample picture numbering", "", "Main"
end sub

sample n.2 - run user convertor to all open files

const module_name  = "RunAction"         'this name must be unique !!!
const module_ver   = "0.001"             'version

sub Procedure
  set obj = NewEditor()
  for i = 0 to editorsCount - 1
      obj.assignEditorByIndex(i)
      obj.activate
      if i = 0 then  'for first file we call user convertor selector
         runPSPadAction "aUserConvertors"
      else           'for all other files we run last used convertor
         runPSPadAction "aLastUserConvertor"
      end if
  next  
end sub

' name "Init" is required, its called automatically during initialization to create menu items
sub Init
  addMenuItem "Run action demo (convert all open files)","", "Procedure"
end sub