From 66f0d242fa063277713e723d83d051402ff12e1d Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 15 Apr 2016 12:42:22 -0400 Subject: mode: Unset indent-region-function Don't use python-indent-region for indent-region-function. At first glance, setting indent-region-function to nil (that is, running indent-according-to-mode on each line) seems to indent rule blocks fine, though it will probably fail on more complex "run" values. However, this does mean that python-indent-region is no longer used when indent-region is called with a region that doesn't include a rule block, so it's probably worth adding a snakemake-indent-region function that calls python-indent-region in this case. Re: #8 --- snakemake-mode.el | 1 + snakemake-test.el | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/snakemake-mode.el b/snakemake-mode.el index dc9fbf8..319a0d8 100644 --- a/snakemake-mode.el +++ b/snakemake-mode.el @@ -338,6 +338,7 @@ label." (set (make-local-variable 'imenu-create-index-function) #'snakemake-imenu-create-index) (set (make-local-variable 'indent-line-function) 'snakemake-indent-line) + (set (make-local-variable 'indent-region-function) nil) (set (make-local-variable 'font-lock-defaults) `(,(append snakemake-font-lock-keywords python-font-lock-keywords)))) diff --git a/snakemake-test.el b/snakemake-test.el index 6374b0d..eeb2e5f 100644 --- a/snakemake-test.el +++ b/snakemake-test.el @@ -469,6 +469,57 @@ rule abc: (snakemake-indent-line) (buffer-string))))) +(ert-deftest snakemake-test/indent-region () + (should + (string= + " +rule abc: + input: 'infile' + output:" + (snakemake-with-temp-text + " +rule abc: +input: 'infile' +output:" + (indent-region (point) (point-max)) + (buffer-string)))) + (should + (string= + " +rule abc: + input: + one='one', two='two' + output: 'out' + run: + with open(input.one) as ifh: + with open(output.out, 'w') as ofh: + ofh.write(ifh.read())" + (snakemake-with-temp-text + " +rule abc: +input: +one='one', two='two' +output: 'out' +run: +with open(input.one) as ifh: +with open(output.out, 'w') as ofh: +ofh.write(ifh.read())" + (indent-region (point) (point-max)) + (buffer-string)))) + (should + (string= + " +x = [1, + 2, + 3,]" + (snakemake-with-temp-text + " +x = [1, +2, +3,]" + (indent-region (point) (point-max)) + (buffer-string))))) + ;;;; Other (ert-deftest snakemake-test-in-rule-or-subworkflow-block-p () -- cgit v1.2.3