discussion and development of Emacs Snakemake mode
 help / color / mirror / code / Atom feed
* Support R syntax highlighting in R("""-blocks (#6)
@ 2016-04-13  9:03 Endre Bakken Stovner
  2016-04-13 13:26 ` Endre Bakken Stovner
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Endre Bakken Stovner @ 2016-04-13  9:03 UTC (permalink / raw)
  To: kyleam/snakemake-mode

[-- Attachment #1: Type: text/plain, Size: 1855 bytes --]

Uses purcells robust mmm-library: https://github.com/purcell/mmm-mode

Can be further updated to recognize other strings as embedded R. The template should be easy to follow.

I suggest something like `"""[Rr]` for the case where you need to run R-scripts using shell or write them in a variable to print/debug. But I leave it at your discretion.

Use-cases for suggestion above:

```python
        command = """#r
        library(csaw)
        param = readParam(minq=50, restrict=c({chromosomes_as_string}))"""
        print(command)
        R(command)
```

or 

```python
        run_voom_script = """#R
        library(edgeR)
        normfactors = tail(read.table("{input.normalization_file}", row.names=1, header=F), 18)
        colnames(normfactors) = c("norm.factors") # need this name for voom to accept the normfactors
        df = read.table("{input.infile}")

        x = DGEList(counts=df, norm.factors=as.matrix(normfactors))

        y = voom(x)
        write.table(y$E, "{output.outfile}", sep=" ")
        """.format(**locals())

        print(run_voom_script)

        # Must craete new instance of R-interpreter to avoid clashing library requirements
        with open(output.script, "w+") as script_handle:
            script_handle.write(run_voom_script)

        shell("Rscript {output.script}")
```
You can view, comment on, or merge this pull request online at:

  https://github.com/kyleam/snakemake-mode/pull/6

-- Commit Summary --

  * Support R syntax highlighting in R("""-blocks

-- File Changes --

    M snakemake-mode.el (15)

-- Patch Links --

https://github.com/kyleam/snakemake-mode/pull/6.patch
https://github.com/kyleam/snakemake-mode/pull/6.diff

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kyleam/snakemake-mode/pull/6

[-- Attachment #2: Type: text/html, Size: 4129 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Support R syntax highlighting in R("""-blocks (#6)
  2016-04-13  9:03 Support R syntax highlighting in R("""-blocks (#6) Endre Bakken Stovner
@ 2016-04-13 13:26 ` Endre Bakken Stovner
  2016-04-14  5:51 ` Endre Bakken Stovner
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Endre Bakken Stovner @ 2016-04-13 13:26 UTC (permalink / raw)
  To: kyleam/snakemake-mode

[-- Attachment #1: Type: text/plain, Size: 328 bytes --]

Sorry for this. Long time since I used git collaboratively. Guess the correct way to do this would be to make a new branch for each PR.

---
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/kyleam/snakemake-mode/pull/6#issuecomment-209440519

[-- Attachment #2: Type: text/html, Size: 969 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Support R syntax highlighting in R("""-blocks (#6)
  2016-04-13  9:03 Support R syntax highlighting in R("""-blocks (#6) Endre Bakken Stovner
  2016-04-13 13:26 ` Endre Bakken Stovner
@ 2016-04-14  5:51 ` Endre Bakken Stovner
  2016-04-14  6:09 ` Endre Bakken Stovner
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Endre Bakken Stovner @ 2016-04-14  5:51 UTC (permalink / raw)
  To: kyleam/snakemake-mode; +Cc: Kyle Meyer

[-- Attachment #1: Type: text/plain, Size: 246 bytes --]

Will do, but when is uncertain - doing this when I have analyses waiting.

---
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/kyleam/snakemake-mode/pull/6#issuecomment-209773633

[-- Attachment #2: Type: text/html, Size: 887 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Support R syntax highlighting in R("""-blocks (#6)
  2016-04-13  9:03 Support R syntax highlighting in R("""-blocks (#6) Endre Bakken Stovner
  2016-04-13 13:26 ` Endre Bakken Stovner
  2016-04-14  5:51 ` Endre Bakken Stovner
@ 2016-04-14  6:09 ` Endre Bakken Stovner
  2016-04-17 19:04 ` Endre Bakken Stovner
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Endre Bakken Stovner @ 2016-04-14  6:09 UTC (permalink / raw)
  To: kyleam/snakemake-mode; +Cc: Kyle Meyer

[-- Attachment #1: Type: text/plain, Size: 176 bytes --]

Closed #6.

---
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/kyleam/snakemake-mode/pull/6#event-626833317

[-- Attachment #2: Type: text/html, Size: 1077 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Support R syntax highlighting in R("""-blocks (#6)
  2016-04-13  9:03 Support R syntax highlighting in R("""-blocks (#6) Endre Bakken Stovner
                   ` (2 preceding siblings ...)
  2016-04-14  6:09 ` Endre Bakken Stovner
@ 2016-04-17 19:04 ` Endre Bakken Stovner
  2016-04-18  4:22 ` Endre Bakken Stovner
  2020-04-17  0:01 ` Kyle Meyer
  5 siblings, 0 replies; 7+ messages in thread
From: Endre Bakken Stovner @ 2016-04-17 19:04 UTC (permalink / raw)
  To: kyleam/snakemake-mode; +Cc: Kyle Meyer

[-- Attachment #1: Type: text/plain, Size: 2029 bytes --]

I will open this as a separate PR if you accept the changes:

```elisp
;;;;;;;;;;;;; Will be added to snakemake-mode.el
\f
;;; Embedded language syntax-highlighting

(defun snakemake-mode-setup-mmm ()
  "Call this function in your startup-file to automatically highlight embedded R-code.

You must have the R-strings either within a R(''' ''') function call or a code block delimited with '''#r and '''."

  (if (require 'mmm-mode nil 'noerror)
      (progn (require 'mmm-mode)
             (setq mmm-global-mode '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))
    (error "You need to install mmm-mode")))

(snakemake-mode-setup-mmm)
```

I guess this should be documented, but it would be strange to document this when most of the package is not documented (in any README/FAQ file). Most users probably do not read the code.

---
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/kyleam/snakemake-mode/pull/6#issuecomment-211084302

[-- Attachment #2: Type: text/html, Size: 4085 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Support R syntax highlighting in R("""-blocks (#6)
  2016-04-13  9:03 Support R syntax highlighting in R("""-blocks (#6) Endre Bakken Stovner
                   ` (3 preceding siblings ...)
  2016-04-17 19:04 ` Endre Bakken Stovner
@ 2016-04-18  4:22 ` Endre Bakken Stovner
  2020-04-17  0:01 ` Kyle Meyer
  5 siblings, 0 replies; 7+ messages in thread
From: Endre Bakken Stovner @ 2016-04-18  4:22 UTC (permalink / raw)
  To: kyleam/snakemake-mode; +Cc: Kyle Meyer

[-- Attachment #1: Type: text/plain, Size: 477 bytes --]

You are right about the regex. Will fix the other stuff too.

Agree about the global variable. I guess I could add another unless to the setup-function that warns people that they need to set this variable to `'maybe` in their startup file for automatic parsing of subregions if it is nil. Okay with you?

---
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/kyleam/snakemake-mode/pull/6#issuecomment-211193962

[-- Attachment #2: Type: text/html, Size: 1136 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Support R syntax highlighting in R("""-blocks (#6)
  2016-04-13  9:03 Support R syntax highlighting in R("""-blocks (#6) Endre Bakken Stovner
                   ` (4 preceding siblings ...)
  2016-04-18  4:22 ` Endre Bakken Stovner
@ 2020-04-17  0:01 ` Kyle Meyer
  5 siblings, 0 replies; 7+ messages in thread
From: Kyle Meyer @ 2020-04-17  0:01 UTC (permalink / raw)
  To: snakemake-mode

Some replies are missing, as described at

  https://inbox.kyleam.com/snakemake-mode/874ktmyh4u.fsf@kyleam.com/

Please visit the link in the parent message to see the full discussion.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-04-17  0:01 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-13  9:03 Support R syntax highlighting in R("""-blocks (#6) Endre Bakken Stovner
2016-04-13 13:26 ` Endre Bakken Stovner
2016-04-14  5:51 ` Endre Bakken Stovner
2016-04-14  6:09 ` Endre Bakken Stovner
2016-04-17 19:04 ` Endre Bakken Stovner
2016-04-18  4:22 ` Endre Bakken Stovner
2020-04-17  0:01 ` Kyle Meyer

discussion and development of Emacs Snakemake mode

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.kyleam.com/snakemake-mode/0 snakemake-mode/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 snakemake-mode snakemake-mode/ https://inbox.kyleam.com/snakemake-mode \
		snakemake-mode@inbox.kyleam.com
	public-inbox-index snakemake-mode

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.snakemake-mode


code repositories for project(s) associated with this inbox:

	https://git.kyleam.com/snakemake-mode/

AGPL code for this site: git clone http://ou63pmih66umazou.onion/public-inbox.git