From 584020c40a4e35baeac0f6a5a3f8267ff43cd376 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 4 Mar 2016 00:56:29 -0500 Subject: popup: Consider file targets in region --- snakemake.el | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'snakemake.el') 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 -- cgit v1.2.3