summaryrefslogtreecommitdiff
path: root/snakemake.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2016-03-04 00:56:29 -0500
committerKyle Meyer <kyle@kyleam.com>2016-03-04 00:56:29 -0500
commit584020c40a4e35baeac0f6a5a3f8267ff43cd376 (patch)
tree44d0aafbdb9b56f1e91ab84c84c54d30771fd069 /snakemake.el
parente9f6240f36e8123d8eabf7785f64f50e4e0ed50e (diff)
downloadsnakemake-mode-584020c40a4e35baeac0f6a5a3f8267ff43cd376.tar.gz
popup: Consider file targets in region
Diffstat (limited to 'snakemake.el')
-rw-r--r--snakemake.el26
1 files changed, 25 insertions, 1 deletions
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