Skip to content

Instantly share code, notes, and snippets.

@queertypes
Created December 8, 2017 03:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save queertypes/5c68eb85185edd1a26926cd37c00bd97 to your computer and use it in GitHub Desktop.
Save queertypes/5c68eb85185edd1a26926cd37c00bd97 to your computer and use it in GitHub Desktop.
emacs minor-mode (syntax highlighting) for Path of Exile item filter files
;;; poe-filter-mode --- a path of exile filter file mode
;;; Commentary:
;;; not much to say
;;; Code:
;; forward declare some vars
(defvar poe-filter-font-lock nil "Font faces for filter files")
(defvar poe-filter-mode-syntax-table nil "Syntax for filter files")
;; create the list for font-lock.
;; each category of keyword is given a particular face
(setq poe-filter-font-lock
(let* (
;; filter language matchable properties
(x-keywords '("ItemLevel"
"DropLevel"
"Quality"
"Rarity"
"Class"
"BaseType"
"Sockets"
"LinkedSockets"
"SocketGroup"
"Height"
"Width"
"Corrupted"))
;; filter language actions to run on match
(x-functions '("SetBorderColor"
"SetTextColor"
"SetBackgroundColor"
"PlayAlertSound"
"SetFontSize"))
;; some constants that can be matched against
(x-constants '("Magic"
"Rare"
"Unique"
"Normal"
"True"
"False"
"RGB"
"WWW"))
;; the two core actions
(x-builtins '("Show" "Hide"))
;; generate regex string for each category of keywords
(x-constants-regexp (regexp-opt x-constants 'words))
(x-builtins-regexp (regexp-opt x-builtins 'words))
(x-functions-regexp (regexp-opt x-functions 'words))
(x-keywords-regexp (regexp-opt x-keywords 'words)))
`(
(,x-constants-regexp . font-lock-constant-face)
(,x-builtins-regexp . font-lock-builtin-face)
(,x-functions-regexp . font-lock-function-name-face)
(,x-keywords-regexp . font-lock-keyword-face)
)))
;; handle comments
(setq poe-filter-mode-syntax-table
(let ((synTable (make-syntax-table)))
(modify-syntax-entry ?# "<" synTable)
(modify-syntax-entry ?\n ">" synTable)
synTable))
;;;###autoload
(define-derived-mode poe-filter-mode c-mode "poe-filter mode"
"Major mode for editing Path of Exile filter files."
;; code for syntax highlighting
(set-syntax-table poe-filter-mode-syntax-table)
(setq font-lock-defaults '((poe-filter-font-lock)))
)
;; add the mode to the `features' list
(provide 'poe-filter-mode)
;;; poe-filter-mode ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment