diff options
-rw-r--r-- | snakemake-test.el | 20 | ||||
-rw-r--r-- | snakemake.el | 26 |
2 files changed, 45 insertions, 1 deletions
diff --git a/snakemake-test.el b/snakemake-test.el index 8ebb3ff..6374b0d 100644 --- a/snakemake-test.el +++ b/snakemake-test.el @@ -693,6 +693,26 @@ rule abc: (forward-line -1) (snakemake-org-link-file-targets))))) +(ert-deftest snakemake-test-region-file-targets () + (let ((files '("/path/to/fname" "fname2" "CAP"))) + (should (equal (mapcar #'expand-file-name files) + (with-temp-buffer + (insert (mapconcat #'identity files "\n")) + (snakemake-region-file-targets + (point-min) (point-max))))) + (should (equal (mapcar #'expand-file-name files) + (with-temp-buffer + (insert (mapconcat #'identity files ",")) + (snakemake-region-file-targets + (point-min) (point-max))))) + (should (equal (mapcar #'expand-file-name files) + (with-temp-buffer + (insert (car files)) + (insert ?\n) + (insert (mapconcat #'identity (cdr files) " ")) + (snakemake-region-file-targets + (point-min) (point-max))))))) + (ert-deftest snakemake-test-file-targets-at-point () (should (equal '("aa.out") diff --git a/snakemake.el b/snakemake.el index 663f336..c3f5ec4 100644 --- a/snakemake.el +++ b/snakemake.el @@ -110,7 +110,8 @@ Snakefiles in the current directory will be detected." :package-version '(snakemake-mode . "0.4.0")) (defcustom snakemake-file-targets-hook - '(snakemake-dired-file-targets + '(snakemake-region-file-targets + snakemake-dired-file-targets snakemake-org-link-file-targets snakemake-thingatpt-file-targets) "Functions to return file targets at point. @@ -120,6 +121,13 @@ value should be a list of absolute paths." :type 'hook :package-version '(snakemake-mode . "0.4.0")) +(defcustom snakemake-region-files-strip-re + (concat (regexp-opt '("[" "]" "'" "\"" ";" ",")) "+") + "Regexp matching text to be discarded when collecting region files. +Used by `snakemake-region-file-targets'." + :type 'regexp + :package-version '(snakemake-mode . "0.4.0")) + ;;; Utilities @@ -237,6 +245,22 @@ currently limited to a single-item list." (and (derived-mode-p 'dired-mode) (dired-get-marked-files))) +(defun snakemake-region-file-targets (&optional beg end) + "Return file targets in region. + +Before generating the list, characters that match +`snakemake-region-files-strip-re' are discarded. + +If BEG or END is non-nil, use them in place of `region-beginning' +or `region-end', respectively." + (when (or (use-region-p) (and beg end)) + (mapcar #'expand-file-name + (split-string + (replace-regexp-in-string + snakemake-region-files-strip-re " " + (buffer-substring-no-properties (or beg (region-beginning)) + (or end (region-end)))))))) + (defun snakemake-thingatpt-file-targets () "Return file at point accordinng `thing-at-point'. This function returns a list for consistency with other |