edmundmiller / nextflow-mode

Emacs major mode for Nextflow
GNU General Public License v3.0
20 stars 7 forks source link

Allow indentation within strings #1

Closed jackkamm closed 4 years ago

jackkamm commented 4 years ago

This PR allows for indentation within strings, so that script blocks can be indented. It also adds \ as an infix character because it's frequently used to continue lines within script blocks.

The approach I took is hacky as hell, it just tricks groovy-indent-line so it doesn't know when it's inside a string. But it seems to work well enough so far...

Here's an example of a script block before/after this PR.

Before:

process alignReads {
    tag { sampleName }

    cpus 4

    input:
    tuple(sampleName, file(reads)) from minimap2_reads_in
    path(ref_fasta)

    output:
    tuple(sampleName, file("${sampleName}.bam")) into minimap2_bam_out

    script:
    """
minimap2 -ax sr \
-R '@RG\\tID:${sampleName}\\tSM:${sampleName}' \
${ref_fasta} ${reads} |
samtools sort -@ 2 -O bam -o ${sampleName}.bam
"""
}

After:

process alignReads {
    tag { sampleName }

    cpus 4

    input:
    tuple(sampleName, file(reads)) from minimap2_reads_in
    path(ref_fasta)

    output:
    tuple(sampleName, file("${sampleName}.bam")) into minimap2_bam_out

    script:
    """
    minimap2 -ax sr \
        -R '@RG\\tID:${sampleName}\\tSM:${sampleName}' \
        ${ref_fasta} ${reads} |
        samtools sort -@ 2 -O bam -o ${sampleName}.bam
    """
}
edmundmiller commented 4 years ago

@jackkamm Works great on my end, thank you! Feel free to open an issue for any other ideas you have for the package, I'd love to see it reach the level of snakemake-mode but I'm new to Nextflow.