From 4d4be15415a4f592e67ce6237e493f22adff8ba6 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 21 Feb 2020 00:42:38 -0500 Subject: mode: Retain non-keyword parts of inherited font-lock-defaults snakemake-font-lock-keywords is extended with python-font-lock-keywords, but the non-keyword bits that python.el defines for font-lock-defaults are discarded. Keep those too because python.el sets a value for font-lock-syntactic-face-function. --- snakemake-mode.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/snakemake-mode.el b/snakemake-mode.el index e0299c2..2c15e9e 100644 --- a/snakemake-mode.el +++ b/snakemake-mode.el @@ -462,7 +462,8 @@ embedded R, you need to set mmm-global-mode to a non-nil value such as 'maybe.") #'snakemake-block-or-defun-name) (set (make-local-variable 'font-lock-defaults) - `(,(append snakemake-font-lock-keywords python-font-lock-keywords)))) + (cons (append snakemake-font-lock-keywords python-font-lock-keywords) + (cdr font-lock-defaults)))) ;;;###autoload (add-to-list 'auto-mode-alist '("Snakefile\\'" . snakemake-mode)) -- cgit v1.2.3 From 8e8db653aa3a1ddf0afd19f2eea8656ce6c76c61 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 21 Feb 2020 00:42:38 -0500 Subject: font-lock: Pull python-font-lock-keywords into snakemake's This will make it easier to work around a change to python-font-lock-keywords in Emacs 27. --- snakemake-mode.el | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/snakemake-mode.el b/snakemake-mode.el index 2c15e9e..7987304 100644 --- a/snakemake-mode.el +++ b/snakemake-mode.el @@ -431,20 +431,23 @@ embedded R, you need to set mmm-global-mode to a non-nil value such as 'maybe.") ;;; Mode +(defvar snakemake--font-lock-keywords + `((,snakemake-rule-or-subworkflow-re + (1 font-lock-keyword-face nil 'lax) + (2 font-lock-function-name-face nil 'lax) + (3 font-lock-keyword-face nil 'lax)) + (,(snakemake-rx line-start (one-or-more space) + (group field-key) + (zero-or-more space) ":") + 1 font-lock-type-face) + (,(snakemake-rx line-start (zero-or-more space) + (group sm-command) + (zero-or-more space) ":") + 1 font-lock-keyword-face) + (,(snakemake-rx (group sm-builtin)) 1 font-lock-builtin-face))) + (defvar snakemake-font-lock-keywords - `((,snakemake-rule-or-subworkflow-re - (1 font-lock-keyword-face nil 'lax) - (2 font-lock-function-name-face nil 'lax) - (3 font-lock-keyword-face nil 'lax)) - (,(snakemake-rx line-start (one-or-more space) - (group field-key) - (zero-or-more space) ":") - 1 font-lock-type-face) - (,(snakemake-rx line-start (zero-or-more space) - (group sm-command) - (zero-or-more space) ":") - 1 font-lock-keyword-face) - (,(snakemake-rx (group sm-builtin)) 1 font-lock-builtin-face))) + (append snakemake--font-lock-keywords python-font-lock-keywords)) ;;;###autoload (define-derived-mode snakemake-mode python-mode "Snakemake" @@ -462,8 +465,7 @@ embedded R, you need to set mmm-global-mode to a non-nil value such as 'maybe.") #'snakemake-block-or-defun-name) (set (make-local-variable 'font-lock-defaults) - (cons (append snakemake-font-lock-keywords python-font-lock-keywords) - (cdr font-lock-defaults)))) + (cons snakemake-font-lock-keywords (cdr font-lock-defaults)))) ;;;###autoload (add-to-list 'auto-mode-alist '("Snakefile\\'" . snakemake-mode)) -- cgit v1.2.3 From 5d5bb0109f6a84c0c191559ab71670fae4650e6a Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 21 Feb 2020 00:42:38 -0500 Subject: font-lock: Adjust python-font-lock-keywords handling for Emacs 27 In Emacs 27, specifically 36b64e087e (Add 'font-lock-maximum-decoration' levels for Python, 2018-07-19), python-font-lock-keywords was changed to a list of symbols that define different fontification levels, so we can no longer simply tack snakemake-font-lock-keywords onto it. Instead define a set of levels that mirrors Python mode's. For Snakemake mode, the same decoration is used for all levels, but at least we will honor the level of decoration that the user has set for Python. Reported-by: Nicholas Knoblauch Closes #29. --- NEWS | 3 +++ snakemake-mode.el | 23 +++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index bc2fc12..8b7e817 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,9 @@ NEWS -- history of user-visible changes -*- mode: org; -*- - The 'multiext' built-in (new in Snakemake v5.8.2) is now recognized. +- The font-lock handling has been updated to be compatible with + python.el changes in Emacs 27. + * v1.6.0 - Checkpoints (new in Snakemake v5.4) are now recognized. diff --git a/snakemake-mode.el b/snakemake-mode.el index 7987304..255985c 100644 --- a/snakemake-mode.el +++ b/snakemake-mode.el @@ -446,8 +446,27 @@ embedded R, you need to set mmm-global-mode to a non-nil value such as 'maybe.") 1 font-lock-keyword-face) (,(snakemake-rx (group sm-builtin)) 1 font-lock-builtin-face))) -(defvar snakemake-font-lock-keywords - (append snakemake--font-lock-keywords python-font-lock-keywords)) +(if (bound-and-true-p python-font-lock-keywords-level-1) + (with-no-warnings + ;; In Emacs 27 `python-font-lock-keywords' was split up into + ;; different decoration levels. + (defvar snakemake-font-lock-keywords-level-1 + (append snakemake--font-lock-keywords + python-font-lock-keywords-level-1)) + (defvar snakemake-font-lock-keywords-level-2 + (append snakemake--font-lock-keywords + python-font-lock-keywords-level-2)) + (defvar snakemake-font-lock-keywords-maximum-decoration + (append snakemake--font-lock-keywords + python-font-lock-keywords-maximum-decoration)) + (defvar snakemake-font-lock-keywords + ;; Mirrors `python-font-lock-keywords'. + '(snakemake-font-lock-keywords-level-1 + snakemake-font-lock-keywords-level-1 + snakemake-font-lock-keywords-level-2 + snakemake-font-lock-keywords-maximum-decoration))) + (defvar snakemake-font-lock-keywords + (append snakemake--font-lock-keywords python-font-lock-keywords))) ;;;###autoload (define-derived-mode snakemake-mode python-mode "Snakemake" -- cgit v1.2.3