Simple VBA Macro for Syntax Highlight

Machine-specific discussion
Unix, Linux, OS X, OS/2, Windows, ..?
Locked
PapoAnaya
Posts: 16
Joined: Mon Oct 24, 2005 6:55 pm

Simple VBA Macro for Syntax Highlight

Post by PapoAnaya »

Hi:

I wrote the following small macro for syntax highlight. It's very basic, but demonstrates how newLISP can be used when you are not in the mood of coding a lot of VBA code for mundane things like that. (I guess I could've used VBA string search routines, but I wanted to try it out anyway. :)

Papo

Code: Select all

' newlisp preable
Public Declare Function dllEvalNewLISP Lib "c:\program files\newlisp\newlisp.dll" Alias "newlispEvalStr" (ByVal LExpr As String) As Long
Private Declare Function lstrLen Lib "kernel32" Alias "lstrlenA" (lpString As Any) As Long
Private Declare Function lstrCpy Lib "kernel32" Alias "lstrcpyA" (lpString1 As Any, lpString2 As Any) As Long
Private Declare Function LoadLibraryA Lib "kernel32" (ByVal s As String) As Long
Private Declare Sub FreeLibrary Lib "kernel32" (ByVal h As Long)
Dim NewLISPhandle As Long

Function EvalNewLISP(LispExpression As String) As String
Dim resHandle As Long
Dim result As String
resHandle = dllEvalNewLISP(LispExpression)
result = Space$(lstrLen(ByVal resHandle))
lstrCpy ByVal result, ByVal resHandle
EvalNewLISP = result
End Function

'Gets a keyword from a list, returns "member" value
Function GetKeyword(inkey As String)
    Dim statement As String
    Dim keywords As String
    keywords = "(setq kw '(expr strsub executesqlsimple strcat puts set mktime unixtime while for incr dbapi loaddriver if else elsif ))"
    statement = "(member ' " + inkey + " kw)"
    output = EvalNewLISP(keywords)
    output = EvalNewLISP(statement)
    GetKeyword = output
End Function

' goes to a selection, if the keyword exists, then boldify, otherwise, leave
' alone

Sub syntax_highlight()
   Dim CurrentString As String 
   For i = 1 To Selection.Words.Count
      CurrentString = Selection.Words(i).Text
      If GetKeyword(CurrentString) <> "nil" Then
         Selection.Words(i).Bold = True
      End If
   Next i
End Sub


Locked