Jump to content


Photo

PSPad Auto generate syntax


  • Please log in to reply
5 replies to this topic

#1 kidmar

kidmar
  • Members
  • 73 posts

Posted 14 March 2012 - 06:08 PM

I've made a little script (collecting scripts I found in this forum) that automates the process of defining autohotkey's syntax highlightning for PSPad.

; Generates Syntax file for PSPad
; Last Edited: 14/03/2012
; Tested with: Autohotkey_L v1.1.07.01 (Win 7 x64)
; Author: Kidmar, Scott Greenberg (Gen PSPad)
; ============================================================================
; PLACE THIS SCRIPT IN PSPAD FOLDER
; FILL THE AHK_Folder variable (ex: "C:\Program Files (x86)\AutoHotkey")
; ============================================================================

SetWorkingDir, %A_ScriptDir%
SetBatchLines, -1     ; Speeds up file operations.
IniKey := ""
PSPadINI = PSPad.ini
PSPadEXE = PSPad.exe
TargetFile = AutoHotkey.ini
TargetProfileName = AutoHotkey

AHK_Folder := "C:\Program Files (x86)\AutoHotkey"   ; Fill me up

CheckAllOk()
GetAHKSyntaxFiles()
GenPSPad()
WriteIniFile()
ClearFiles()

ClearFiles()
{
  Global TargetFile
  FileMove, %TargetFile%, Syntax\%TargetFile%, 1
  FileDelete CommandNames.txt
  FileDelete Functions.txt
  FileDelete Keywords.txt
  FileDelete Variables.txt
  FileDelete Keys.txt
}


WriteIniFile()
{
  Global PSPadINI
  Global IniKey
  Global TargetProfileName
  Global AHK_Folder
  
  IniDelete, %PSPadINI%, %TargetProfileName% 
  IniWrite, %TargetProfileName%, %PSPadINI%, Config, %IniKey%
  IniWrite, AutoHotkey (*.ahk)|*.ahk, %PSPadINI%, %TargetProfileName%, Filter
  IniWrite, 0, %PSPadINI%, %TargetProfileName%, HLTabWidth
  IniWrite, % "" , %PSPadINI%, %TargetProfileName%, IndentChar
  IniWrite, % "" , %PSPadINI%, %TargetProfileName%, UnIndentChar
  IniWrite, 00FF00001FFFFFFF010, %PSPadINI%, %TargetProfileName%, Comment
  IniWrite, 1FFFFFFF1FFFFFFF000, %PSPadINI%, %TargetProfileName%, Identifier
  IniWrite, 1FFFFFFF1FFFFFFF100, %PSPadINI%, %TargetProfileName%, Key
  IniWrite, 1FFFFFFF1FFFFFFF100, %PSPadINI%, %TargetProfileName%, Key words 2
  IniWrite, 1FFFFFFF1FFFFFFF100, %PSPadINI%, %TargetProfileName%, Key words 3
  IniWrite, 000000FF1FFFFFFF000, %PSPadINI%, %TargetProfileName%, Label
  IniWrite, 008000001FFFFFFF000, %PSPadINI%, %TargetProfileName%, Number
  IniWrite, 008080001FFFFFFF010, %PSPadINI%, %TargetProfileName%, Preprocessor
  IniWrite, 000000801FFFFFFF100, %PSPadINI%, %TargetProfileName%, Reserved Word
  IniWrite, 008080001FFFFFFF000, %PSPadINI%, %TargetProfileName%, Space
  IniWrite, 000080001FFFFFFF000, %PSPadINI%, %TargetProfileName%, String
  IniWrite, 1FFFFFFF1FFFFFFF000, %PSPadINI%, %TargetProfileName%, Symbol
  IniWrite, %AHK_Folder%\Compiler\Ahk2Exe.exe, %PSPadINI%, %TargetProfileName%, Compilator File
  IniWrite, /in `"`%File`%`", %PSPadINI%, %TargetProfileName%, Compilator Param
  IniWrite, % "", %PSPadINI%, %TargetProfileName%, Compilator LOG
  IniWrite, % "", %PSPadINI%, %TargetProfileName%, Compilator Run
  IniWrite, %AHK_Folder%\AutoHotkey.chm, %PSPadINI%, %TargetProfileName%, Compilator Help
  IniWrite, 0, %PSPadINI%, %TargetProfileName%, Compilator SaveAll
  IniWrite, % "", %PSPadINI%, %TargetProfileName%, Compilator ParsLog
  IniWrite, 0, %PSPadINI%, %TargetProfileName%, Compilator Capture
  IniWrite, 0, %PSPadINI%, %TargetProfileName%, Compilator HideOutput
  IniWrite, % "", %PSPadINI%, %TargetProfileName%, Compilator DefaultDir
  IniWrite, 0, %PSPadINI%, %TargetProfileName%, Compilator LogType
  IniWrite, % "AutoHotkey,|" AHK_Folder "\AutoHotkey.exe| |%File%|", %PSPadINI%, %TargetProfileName%, Prog0
}

CheckAllOk()
{
  Global PSPadINI
  Global PSPadEXE
  Global IniKey
  Global TargetProfileName
  Global AHK_Folder
  
  ; Check for script in right folder
  If NOT (FileExist(PSPadEXE) AND FileExist(PSPadINI))
  {
    MsgBox, Can't generate Syntax file.`nPlease place this script in PSPad folder!
    ExitApp
  }
  
  ; Search a free UserHighliter's slot
  Loop, 5
  {
    UserKey = UserHighLighterName
    If A_INDEX > 1
      UserKey := UserKey . (A_INDEX -1)
    IniRead, User, %PSPadINI%, Config, %UserKey%, 
    If (User = "" OR User = TargetProfileName)
    {
      IniKey := UserKey
      Break
    }
  }
  If (IniKey = "")
  {
    MsgBox, No user slot available in PSPad.ini
    ExitApp
  }
  
  ; Check for AHK Installation Path
  If NOT FIleExist(AHK_Folder . "\Autohotkey.exe")
  {
    msgbox, Wrong AHK folder.Correct the script
    Exitapp
  }
}

GenPSPad()
  ;;; ============================================================================
  ;;;   FILENAME: Generate PSPad.ahk
  ;;; ============================================================================
  ;;;   PSPad Syntax Generator Script
  ;;; ============================================================================
  ;;;   AUTHOR:  Scott Greenberg
  ;;;   COMPANY: SG Technology
  ;;;   VERSION: 1.0.0, 02/08/2005 - 02/08/2005
  ;;;   WEBSITE: http://gogogadgetscott.info/
  ;;;
  ;;; ============================================================================
  ;;;   NOTE:
  ;;;    Derived from Rajat's PSPad Syntax Generator Script
  ;;; ============================================================================

  {
    Global TargetFile
    FileDelete, %TargetFile%
    
    FileAppend, `; PSPad keyword syntax file for AutoHotkey`n, %TargetFile%
    FileAppend, `; Auto generated by GoGoGadgetScott's PSPad Syntax Generator Script`n`n, %TargetFile%
    
    FileAppend, [Settings] `n, %TargetFile%
    FileAppend, Name=AutoHotkey `n, %TargetFile%
    FileAppend, HTMLGroup=0 `n, %TargetFile%
    FileAppend, FileType=*.ahk `n, %TargetFile%
    FileAppend, CommentString=; `n, %TargetFile%
    FileAppend, CComment=1 `n, %TargetFile%
    FileAppend, BasComment=1 `n, %TargetFile%
    FileAppend, SingleQuote=1 `n, %TargetFile%
    FileAppend, DoubleQuote=1 `n, %TargetFile%
    FileAppend, Preprocessors=1 `n, %TargetFile%
    FileAppend, KeyWordChars=-_# `n, %TargetFile%
    FileAppend, [KeyWords]`n, %TargetFile%
        
    ;this doesn't require fancy cmd names for human reading,
    ;it just requires names to be highlighted. so getting first name only
    
    Loop, Read, CommandNames.txt, %TargetFile%
    {
    	CurrCmd =
    	FullCmd = %a_loopreadline%
    	
    	;directives don't have first comma but a first space
    	;so whichever is first, take it as end of cmd name
    	StringGetPos, cPos, a_loopreadline, `,
    	StringGetPos, sPos, a_loopreadline, %A_Space%
    	
    	IfLess, sPos, %cPos%
    		IfGreater, sPos, 0
    			StringLeft, CurrCmd, a_loopreadline, %sPos%
    	
    	IfLess, cPos, %sPos%
    		IfGreater, cPos, 0
    			StringLeft, CurrCmd, a_loopreadline, %cPos%
    
    	IfLess, cPos, %sPos%
    		IfLess, cPos, 0
    			StringLeft, CurrCmd, a_loopreadline, %sPos%
    
    	IfLess, sPos, %cPos%
    		IfLess, sPos, 0
    			StringLeft, CurrCmd, a_loopreadline, %cPos%
    			
    	StringReplace, FullCmd, FullCmd, ``n, `n, a
    	StringReplace, FullCmd, FullCmd, ``t, `t, a
    
    	StringReplace, CurrCmd, CurrCmd, [,, a
    	StringReplace, CurrCmd, CurrCmd, %a_space%,, a
    	
    	;For a directive that has no parameters
    	IfEqual, CurrCmd,
    		CurrCmd = %a_loopreadline%
    	
    	
    	;this check removes duplicates for loop and if
    	IfNotEqual, CurrCmd, %LastCmd%
    		FileAppend, %CurrCmd%=`n
    	
    	LastCmd = %CurrCmd%
    }
    
    
    FileAppend, `n[ReservedWords]`n, %TargetFile%
    
    ;Adding keywords including the blank lines and comments
    Loop, Read, Keywords.txt, %TargetFile%
    	FileAppend, %A_LoopReadLine%=`n
    
    FileAppend, `n`n, %TargetFile%
    
    FileAppend, `n[KeyWords2]`n, %TargetFile%
    
    ;same with variables
    Loop, Read, Variables.txt, %TargetFile%
    	FileAppend, %A_LoopReadLine%=`n
    
    
    FileAppend, `n[KeyWords3]`n, %TargetFile%
    
    ;keys are added with and without {}
    Loop, Read, Keys.txt, %TargetFile%
    {
    	FileAppend, %A_LoopReadLine%=`n
    	IfEqual, A_LoopReadLine,, Continue
    	
    	;comment check
    	StringReplace, check, A_LoopReadLine, %A_Space%,, A
    	StringReplace, check, check, %A_Tab%,, A
    	StringLeft, check, check, 1
    	IfEqual, check, `;, Continue
    	
    	FileAppend, {%A_LoopReadLine%}=`n
    }
  }

; Function
GetAHKSyntaxFiles()
  ; AutoHotkey Version: 1.x
  ; Script Function:
  ; Download a number of pages from the AutoHotkey Wiki to prepare the following files:
  ; 
  ; - CommandNames.txt
  ; - Functions.txt
  ; - Keywords.txt
  ; - Variables.txt
  ; - Keys.txt
  ; 
  ; Which can be used to prepare syntax files for a variety of text editors
  ; see http://www.autohotkey.com/wiki/index.php?title=Syntax_Highlighting
  ; for a complete listing, to discuss this visit the AHK Forum thread.

 {
  FileDelete, tmpfile$$$.htm
  FileList=CommandNames,Functions,Keywords,Variables,Keys
  Loop, parse, FileList, CSV
  {
   URLDownloadToFile, http://www.autohotkey.com/wiki/index.php?title=Syntax_%A_LoopField%, tmpfile$$$.htm
   FileRead, File, tmpfile$$$.htm
   RegExMatch(File,"is)<pre>(.*)</pre>",%A_LoopField%)
   File:=%A_LoopField%1
   File:=RegExReplace(RegExReplace(File, "`nm)^;.+\R" ), "`nm)^\n" ) ; remove empty lines and comments
   FileDelete, %A_LoopField%.txt
   FileAppend,%File%,%A_LoopField%.txt
   FileDelete, tmpfile$$$.htm
   File=
  }
}
I would like to add it to the wiki page too, if it is confirmed to be working for everyone.

Edit 06.04.2012: Added " char in compile options

#2 Ares77

Ares77
  • Members
  • 1 posts

Posted 13 July 2012 - 04:25 PM

There is a problem with the script, as the wiki used to download keywords file is down. The link in the Unofficial Faq is down too. Do you know where could I find a working link? Thanks

#3 kidmar

kidmar
  • Members
  • 73 posts

Posted 13 July 2012 - 05:04 PM

The whole wiki is down atm, hope it will come back soon.
I currently know no other place where to get those files... :(

#4 meochain

meochain
  • Members
  • 12 posts

Posted 14 July 2012 - 03:33 AM

Nice thanks for sharing

#5 marblefoot

marblefoot
  • Members
  • 1 posts

Posted 10 August 2012 - 08:20 PM

I am having problems running this.

Everytime I run it, I get the message "Can't generate Syntax file. Please place this script in PSPad folder!"

I've placed it in "C:\Program Files\PSPad editor" but I;m still getting the same error. What am I doing wrong?

#6 Guests

  • Guests

Posted 10 August 2012 - 09:23 PM

Other files are missing which are no longer available so this will never work. The files used to be on the wiki, but the wiki is gone and so are the files. As the wiki was the only place they could be maintained by "the community" it is the only sensible place to have them, no good in posting them in the forum where they can only be maintained by one person.