From 26cd00853d03b7e3dacf037eea53360fe73bde69 Mon Sep 17 00:00:00 2001 From: Endre Bakken Stovner Date: Mon, 18 Apr 2016 19:22:52 +0200 Subject: Syntax-highlight embedded R code --- snakemake-mode.el | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) 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: @@ -324,6 +327,53 @@ label." index)) (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 -- cgit v1.2.3