Skip to content

Commit

Permalink
snakemake-rx: Use rx-let instead of obsolete rx-constituents
Browse files Browse the repository at this point in the history
rx-constituents has been declared as obsolete in the upcoming Emacs
30.1.  Follow the change to python-rx [*] (on which snakemake-rx is
based) and switch to using rx-let.

Bump the minimum Emacs requirement from 26.1 to 27.1 because rx-let
isn't available until 27.1 (released in 2020).

[*] 2aed0430c7c (Use new-style rx extensions in python.el, 2019-10-28)
  • Loading branch information
kyleam committed Feb 4, 2025
1 parent 8f34adf commit 715f162
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 91 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ jobs:
strategy:
matrix:
emacs_version:
- 26.1
- 27.2
- 28.2
- 29.4
Expand Down
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ NEWS -- history of user-visible changes -*- mode: org; -*-

* master (unreleased)

- The minimum required Emacs is now 27.1.

- The 'localrule' keyword (new in Snakemake v7.25.0) is now
recognized.

Expand Down
170 changes: 80 additions & 90 deletions snakemake-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
;; URL: https://git.kyleam.com/snakemake-mode/about
;; Keywords: tools
;; Version: 2.0.0
;; Package-Requires: ((emacs "26.1") (transient "0.3.0"))
;; Package-Requires: ((emacs "27.1") (transient "0.3.0"))

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -73,95 +73,85 @@

;;; Regexp

(eval-and-compile
(defconst snakemake-rx-constituents
`((named-rule . ,(rx (and (group
symbol-start
(or "checkpoint" "module" "rule" "subworkflow"))
" "
(group (one-or-more
(or (syntax word) (syntax symbol)))))))
(anon-rule . ,(rx symbol-start "rule"))
(field-key . ,(rx symbol-start
(or "benchmark"
"cache"
"conda"
"container"
"cwl"
"default_target"
"envmodules"
"group"
"handover"
"input"
"localrule"
"log"
"message"
"name"
"notebook"
"output"
"params"
"priority"
"resources"
"run"
"script"
"shadow"
"shell"
"singularity"
"threads"
"version"
"wildcard_constraints"
"wrapper"
;; Keys for subworkflow blocks
"configfile"
"snakefile"
"workdir")
symbol-end))
(sm-command . ,(rx symbol-start
(or "configfile"
"container"
"containerized"
"envvars"
"include"
"localrules"
"onerror"
"onsuccess"
"report"
"ruleorder"
"singularity"
"wildcard_constraints"
"workdir")
symbol-end))
(sm-builtin . ,(rx symbol-start
(or "ancient"
"checkpoints"
"directory"
"dynamic"
"expand"
"input"
"multiext"
"output"
"params"
"pipe"
"protected"
"report"
"shell"
"temp"
"touch"
"unpack"
"wildcards")
symbol-end)))
"Snakemake-specific sexps for `snakemake-rx'.")

(defmacro snakemake-rx (&rest regexps)
"Specialized `rx' for Snakemake mode."
;; Modified from `python-rx'.
(let ((rx-constituents (append snakemake-rx-constituents rx-constituents)))
(cond ((null regexps)
(error "No regexp"))
((cdr regexps)
(rx-to-string `(and ,@regexps) t))
(t
(rx-to-string (car regexps) t))))))
(defmacro snakemake-rx (&rest regexps)
"Specialized `rx' for Snakemake mode."
;; Modified from `python-rx'.
`(rx-let ((named-rule (and (group
symbol-start
(or "checkpoint" "module" "rule" "subworkflow"))
" "
(group (one-or-more
(or (syntax word) (syntax symbol))))))
(anon-rule (and symbol-start "rule"))
(field-key (and symbol-start
(or "benchmark"
"cache"
"conda"
"container"
"cwl"
"default_target"
"envmodules"
"group"
"handover"
"input"
"localrule"
"log"
"message"
"name"
"notebook"
"output"
"params"
"priority"
"resources"
"run"
"script"
"shadow"
"shell"
"singularity"
"threads"
"version"
"wildcard_constraints"
"wrapper"
;; Keys for subworkflow blocks
"configfile"
"snakefile"
"workdir")
symbol-end))
(sm-command (and symbol-start
(or "configfile"
"container"
"containerized"
"envvars"
"include"
"localrules"
"onerror"
"onsuccess"
"report"
"ruleorder"
"singularity"
"wildcard_constraints"
"workdir")
symbol-end))
(sm-builtin (and symbol-start
(or "ancient"
"checkpoints"
"directory"
"dynamic"
"expand"
"input"
"multiext"
"output"
"params"
"pipe"
"protected"
"report"
"shell"
"temp"
"touch"
"unpack"
"wildcards")
symbol-end)))
(rx ,@regexps)))

(defconst snakemake-rule-or-subworkflow-re
(snakemake-rx line-start (zero-or-more space)
Expand Down

0 comments on commit 715f162

Please sign in to comment.