aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEndre Bakken Stovner <endrebak@idi.ntnu.no>2016-04-18 19:22:52 +0200
committerEndre Bakken Stovner <endrebak@idi.ntnu.no>2016-04-22 20:09:29 +0200
commit26cd00853d03b7e3dacf037eea53360fe73bde69 (patch)
treefa160800f89a859dffcd1ce0a91d82c5d6c8d331
parent98bec6d3f6b8b9a4ef3ef830cdd1d8af95e21f80 (diff)
downloadsnakemake-mode-26cd00853d03b7e3dacf037eea53360fe73bde69.tar.gz
Syntax-highlight embedded R code
-rw-r--r--snakemake-mode.el50
1 files changed, 50 insertions, 0 deletions
diff --git a/snakemake-mode.el b/snakemake-mode.el
index 587d577..71787d8 100644
--- a/snakemake-mode.el
+++ b/snakemake-mode.el
@@ -40,6 +40,9 @@
;;
;; to your initialization file.
;;
+;; snakemake-mode.el also includes support for highlighting embedded R
+;; code. See the snakemake-mode-setup-mmm function documentation for how.
+;;
;; [1] https://bitbucket.org/snakemake/snakemake/wiki/browse/
;;; Code:
@@ -325,6 +328,53 @@ label."
(nreverse index)))
+;;; Embedded language syntax-highlighting
+
+(defun snakemake-mode-setup-mmm ()
+ "Set up MMM mode to highlight embedded R code.
+
+You must have the R-strings either within a R(''' ''') function call or a code
+block delimited with '''#r and ''' (triple double-quotes also accepted).
+
+For automatic highlighting of embedded regions, you need to set
+`mmm-global-mode` to 'maybe in your setup file."
+ (unless (require 'mmm-mode nil t)
+ (user-error "You need to install mmm-mode"))
+
+ (when (unless mmm-global-mode)
+ (display-warning 'snakemake-mode "To get automatic syntax highlighting of
+embedded R, you need to set mmm-global-mode to a non-nil value such as 'maybe."))
+
+ (mmm-add-classes
+ '((snakemake-R-call-double
+ :submode R-mode
+ :front ".*R\(\"\"\""
+ :back ".*\"\"\"\)")))
+
+ (mmm-add-classes
+ '((snakemake-R-call-regular
+ :submode R-mode
+ :front ".*R\('''"
+ :back ".*'''\)")))
+
+ (mmm-add-classes
+ '((snakemake-R-string-double
+ :submode R-mode
+ :front ".*\"\"\" *# *[rR]"
+ :back ".*\"\"\"")))
+
+ (mmm-add-classes
+ '((snakemake-R-string-regular
+ :submode R-mode
+ :front ".*''' *# *[rR]"
+ :back ".*'''")))
+
+ (mmm-add-mode-ext-class 'snakemake-mode nil 'snakemake-R-call-double)
+ (mmm-add-mode-ext-class 'snakemake-mode nil 'snakemake-R-call-regular)
+ (mmm-add-mode-ext-class 'snakemake-mode nil 'snakemake-R-string-double)
+ (mmm-add-mode-ext-class 'snakemake-mode nil 'snakemake-R-string-regular))
+
+
;;; Mode
(defvar snakemake-font-lock-keywords