nsis-mode.el
author Oleksandr Gavenko <gavenkoa@gmail.com>
Thu, 30 Mar 2017 00:34:44 +0300
changeset 1521 df20553d4bd2
parent 1250 73c10c73c63f
permissions -rw-r--r--
Fix: Warning: "string-to-int" is an obsolete function (as of 22.1); use "string-to-number" instead.

;;; iar-linker-config-mode.el --- major mode for highlighting NSIS scripts

;; Copyright (C) 2009, 2010 by Oleksandr Gavenko <gavenkoa@gmail.com>

;; You can do anything with this file without any warranty.

;; Author: Oleksandr Gavenko <gavenkoa@gmail.com>
;; Maintainer: Oleksandr Gavenko <gavenkoa@gmail.com>
;; Created: 2009-09-14
;; Version: 0.1
;; Keywords: languages

;;; Commentary:
;;
;; Very pure syntax highlighting.

;;; Code:

(defun nsis-mode-modify-syntax-entry ()
  (modify-syntax-entry ?_ "w")
  (modify-syntax-entry ?. "w")
  (modify-syntax-entry ?$ ".")
  )

(defun nsis-mode-set-comment-style ()
  (set (make-local-variable 'comment-start) "; ")
  (set (make-local-variable 'comment-continue) nil)
  (set (make-local-variable 'comment-end) "")
  (set (make-local-variable 'comment-end-skip) nil)
  (set (make-local-variable 'comment-multi-line) nil)
  (set (make-local-variable 'comment-use-syntax) t)
  )

;;;###autoload
(define-generic-mode nsis-mode
  (list ?\; ?# '("/*" . "*/"))
  '(
    "Section" "SectionEnd" "SectionIn" "SectionGroup" "SectionGroupEnd" "Function" "FunctionEnd" "File"
    "SectionSetFlags" "SectionGetFlags" "SectionSetText" "SectionGetText" "SectionSetInstTypes" "SectionGetInstTypes" "SectionSetSize" "SectionGetSize" "SetCurInstType" "GetCurInstType" "InstTypeSetText" "InstTypeGetText"
    "Name" "ShowInstDetails" "Caption"
    "LicenseText" "LicenseData" "LicenseForceSelection" "ComponentText" "BrandingText" "DetailsButtonText" "CompletedText" "UninstallText"
    "DirText" "DirVar" "DirVerify"
    "Exec" "ExecWait" "ExecShell" "Goto" "goto" "Call" "Return" "Abort" "Quit" "ClearErrors" "SetErrors"
    "Reboot" "SetRebootFlag"
    "IfSilent" "IfAbort" "IfRebootFlag" "IfErrors" "IfFileExists"
    "GetCurrentAddress" "GetFunctionAddress" "GetLabelAddress"
    "Page" "UninstPage" "PageEx" "PageCallbacks" "PageExEnd"
    "Delete" "CopyFiles" "CreateDirectory" "RMDir" "OutFile" "ReserveFile" "CreateShortCut"
    "CallInstDLL" "GetDLLVersion" "GetDLLVersionLocal" "RegDLL" "UnRegDLL"
    "GetFileTime" "GetFileTimeLocal" "GetFullPathName" "GetTempFileName" "SearchPath" "SetFileAttributes"
    "ReadRegStr" "WriteRegStr" "DeleteRegKey" "DeleteRegValue" "EnumRegKey" "EnumRegValue" "WriteRegDWORD" "ReadRegDWORD" "WriteRegDword" "WriteRegBin" "WriteRegDWORD" "WriteRegExpandStr"
    "ExpandEnvStrings" "ReadEnvStr"
    "DeleteINISec" "DeleteINIStr" "FlushINI" "ReadINIStr" "WriteINIStr"
    "Var" "Pop" "Push" "Exch"
    "StrLen" "StrCpy" "StrCmp" "StrCmpS" "IntCmp" "IntCmpU" "IntFmt" "IntOp"
    "FileClose" "FileOpen" "FileRead" "FileReadByte" "FileSeek" "FileWrite" "FileWriteByte" "FindClose" "FindFirst" "FindNext"
    "InitPluginsDir" "addplugindir" "InstallDir" "InstallDirRegKey" "InstType" "Nop" "Sleep"
    "RequestExecutionLevel" "CRCCheck" "XPStyle"
    "ReadIniStr" "WriteIniStr"
    "LogSet" "LogText"
    "Icon" "UninstallIcon"
    "SendMessage" "MessageBox" "GetDlgItem"
    "FindWindow" "EnableWindow" "LockWindow" "ShowWindow" "HideWindow" "IsWindow" "AutoCloseWindow"
    "SetAutoClose" "CreateFont" "SetCtlColors" "SetBrandingImage" "SetDetailsView" "SetDetailsPrint" "SetSilent" "BringToFront" "DetailPrint"
    "LoadLanguageFile" "LangString" "LicenseLangString"
    "SubCaption" "UninstallSubCaption"
    "SetPluginUnload" "DetailPrint" "SetOutPath" "WriteUninstaller"
    "GetErrorLevel" "SetErrorLevel" "GetInstDirError" "SetRegView" "SetShellVarContext"
    "SetDateSave" "SetDatablockOptimize" "BGGradient" "InstallColors" "CheckBitmap" "SilentInstall" "SetOverwrite"
    "SetCompress"
    )
  '(
    ("!\\(insertmacro\\|define\\|ifdef\\|ifndef\\|else\\|endif\\|echo\\|verbose\\|include\\|macroend\\|macro\\|undef\\|packhdr\\|warning\\|error\\)" (1 'font-lock-builtin-face))
    ("$[({]?\\([A-Za-z0-9_]+\\)[)}]?" (1 'font-lock-variable-name-face))
    ("^[[:blank:]]*\\([[:alpha:].][[:alnum:]_.]*:\\)\\([^:]\\|$\\)" (1 'font-lock-function-name-face))
    ("^[[:blank:]]*\\(Function\\|Goto\\|Call\\)[[:blank:]]+\\([[:alnum:]_.]*\\)" (2 'font-lock-function-name-face))
    )
  '("\\.nsi\\'" "\\.nsh\\'")
  '(nsis-mode-modify-syntax-entry nsis-mode-set-comment-style)
  "Generic mode for nsis files.")

(defvar nsis-imenu-generic-expression
      '(
        ("Defines"  "^!define[[:blank:]]+\\([[:word:]]+\\)" 1)
        ("Sections"  "^Section[[:blank:]]+\"?\\(-?[[:word:] ]+\\)\"?" 1)
        ("Functions"  "^Function[[:blank:]]+\\([[:word:]]+\\)" 1)
        ("Macros"  "^!macro[[:blank:]]+\\([[:word:]]+\\)" 1)
        ))

(defun nsis-set-imenu-generic-expression ()
  (setq imenu-generic-expression nsis-imenu-generic-expression)
  )

(add-hook 'nsis-mode-hook 'nsis-set-imenu-generic-expression)

(eval-when-compile
  (defvar which-func-modes))

(eval-after-load 'which-func
  '(add-to-list 'which-func-modes 'nsis-mode))

(provide 'nsis-mode)

;;; nsis-mode.el ends here