From 0725fba61833e724e121657bdff2513e51b34f80 Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Thu, 9 Sep 2021 20:25:43 +0200 Subject: [PATCH 1/3] simplify/fix regexes for font locking etc --- talonscript-mode.el | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/talonscript-mode.el b/talonscript-mode.el index 0f2742f..d945077 100644 --- a/talonscript-mode.el +++ b/talonscript-mode.el @@ -30,14 +30,14 @@ (defconst talonscript-font-lock-definitions (list - ;; Matches speech commands at the start of a line, but NOT actions. - ;; Excludes actions by disallowing parens next to letters. - ;; - ;; It's difficult to stop this highlighting left-hand expressions before the - ;; divider (-). It's easier to let it highlight those with the same format, - ;; so we tolerate variable syntax too. - (cons "^\\(\\^?[(]?\\([]a-z-A-Z0-9[<>{} ._|)]\\|\\([^-a-zA-Z0-9_](\\)\\)*\\)[$]?[ \t]*:" - '(1 font-lock-function-name-face)) + ;; To find speech commands, we look for unindented lines, and match the part + ;; before the first colon. However, we exclude action/settings/tag blocks by + ;; disallowing parens next to alphanumerics. It's difficult to stop this from + ;; also highlighting left-hand expressions before the divider (-), so we + ;; don't bother. + (cons + "^\\([^[:space:]]\\(?:[^(\n]\\|[^-a-zA-Z0-9_.\n](\\)*\\):" + '(1 font-lock-function-name-face)) ;; Matches the start & end anchors (^ and $) ;; @@ -54,7 +54,7 @@ ;; Matches keys that are function calls, e.g will match "action" in: ;; action(edit.zoom_in): key(ctrl-+) - (cons "^\\([a-zA-Z0-9_-.]*\\)(" '(1 font-lock-type-face t)) + (cons "^\\([-a-zA-Z0-9_.]*\\)(" '(1 font-lock-type-face t)) ;; Matches function references ;; (cons "\\(\\([-a-zA-Z0-9_](\\)\\|:\\)[ \t]*\\([-a-zA-Z0-9_.]+\\)" @@ -93,7 +93,7 @@ recognition." (modify-syntax-entry ?# "<" talonscript-mode-syntax-table) (modify-syntax-entry ?\n ">" talonscript-mode-syntax-table) (setq-local comment-start "# ") - (setq-local comment-start-skip "#+[\t ]*") + (setq-local comment-start-skip "#+[[:blank:]]*") ;; TODO: Convenient indentation ;; (setq-local indent-line-function 'talonscript-toggle-indent) ) From f0fd7ebbfd1c34ba455cc31062d0191c1ee1ce32 Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Fri, 10 Sep 2021 15:36:40 +0200 Subject: [PATCH 2/3] allow ^( at beginning of voice command --- talonscript-mode.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/talonscript-mode.el b/talonscript-mode.el index d945077..9578c07 100644 --- a/talonscript-mode.el +++ b/talonscript-mode.el @@ -36,7 +36,7 @@ ;; also highlighting left-hand expressions before the divider (-), so we ;; don't bother. (cons - "^\\([^[:space:]]\\(?:[^(\n]\\|[^-a-zA-Z0-9_.\n](\\)*\\):" + "^\\(\\(?:\\^(\\|[^[:blank:]]\\)\\(?:[^(\n]\\|[^-a-zA-Z0-9_.\n](\\)*?\\):" '(1 font-lock-function-name-face)) ;; Matches the start & end anchors (^ and $) From 5296f9f60bbd84d855120e7a05d3978ef477a1bb Mon Sep 17 00:00:00 2001 From: Michael Arntzenius Date: Wed, 7 Sep 2022 14:14:21 +0100 Subject: [PATCH 3/3] rx notation --- talonscript-mode.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/talonscript-mode.el b/talonscript-mode.el index 9578c07..5c0f51a 100644 --- a/talonscript-mode.el +++ b/talonscript-mode.el @@ -36,7 +36,11 @@ ;; also highlighting left-hand expressions before the divider (-), so we ;; don't bother. (cons - "^\\(\\(?:\\^(\\|[^[:blank:]]\\)\\(?:[^(\n]\\|[^-a-zA-Z0-9_.\n](\\)*?\\):" + (rx line-start + (group (or (not blank) "^(") + (*? (or (not (in "(\n")) + (seq (not (any alnum "-_.\n")) "(")))) + ":") '(1 font-lock-function-name-face)) ;; Matches the start & end anchors (^ and $)