Hi Stephen,

yasnippet allows you to insert modifiable yaml templates. You can define 
'fields' that you want to modify, along with straight text that will be 
inserted verbatim. 

In my case, I enter the string 'yaml', hit the tab key, and the template is 
inserted. The cursor starts in the title field ($1), and I tab through category 
($2), excerpt ($3), tags ($4, $5), slug ($6), and finally ends in the body of 
the document ($0). 

I keep it simple, but you can use default values for fields, or define a list 
of options to pick from. In my case, I just enter the values by hand. You can 
also call elisp functions to enter computed values. I use the function 
`tws-today` to enter today's date.

The definition for this, stored in a file, is pasted below.

You can use options in the template to switch between different headers, or you 
could define different templates. For example, you could define a yamlblog 
template, a yamlmanuscript template, etc, with the defaults set to your various 
outputs.

There's a tutorial here: 
  https://github.com/joaotavora/yasnippet/blob/master/README.mdown 

and a short video here: 
  https://youtu.be/W-bRZlseNm0?si=wM-mq-HkO2wgS0or

But making a 'quick start' post specifically for ESS users would be a good 
idea. I will add it to my list, but the list is growing faster than I'm making 
posts lately!

- ty

```
# -*- mode: snippet; require-final-newline: nil -*-
# name: yamlpost
# key: yaml
# expand-env: ((yas-indent-line 'fixed))
# binding: direct-keybinding
# --
---
layout: post
title: "$1"
categories: 
  - $2
excerpt: "$3"
date: `(tws-today)`
tags:
  - $4
  - $5
slug: $6
bibliography: ../../plantarum.bib
csl: ../../american-journal-of-botany.csl
link-citations: true
---

\`\`\`{R init, echo = FALSE}
library(utils) 
library(graphics)
library(grDevices)
library(stats)
\`\`\`

$0

```
-- 
plantarum.ca

On Thu, Oct 12, 2023, at 10:35 AM, Stephen Bond wrote:
> Tyler,
>
> Happy you are lending a hand. I alternate between notebook and plain
> htmil output. this is my typical:
>
> ---
> title: "Title"
> author: "Author"
> date: "2023-10-08"
> output:
>   # html_document:
>   #   df_print: kable
>   #   mathjax: C:/emacs/MathJax.js
>   html_notebook:
>     df_print: kable
>     mathjax: C:/emacs/MathJax.js
> editor_options:
>   chunk_output_type: inline
> ---
>
> I am not familiar with yasnippet. Maybe that is the missing piece.
> Cheers
> Stephen
>
> On Tue, 2023-10-10 at 09:32 -0400, Tyler Smith wrote:
>> Hi Stephen,
>> 
>> Like Manuel, I also do my Rmd editing in Emacs, with ESS and polymode
>> to handle most things, and a yasnippet to insert my YAML section.
>> This covers my needs, but I'm not a very sophisticated user of YAML. 
>> 
>> What support would you like to see? Perhaps there are features you
>> aren't aware of, or if not, we might be able to come up with some
>> workable solutions. Whether or not that's an ESS issue, an polymode
>> issue, or a markdown-mode issue, remains to be seen.
>> 
>> Best,
>> 
>> Tyler
>> 
>> > On Fri, Oct 6, 2023, 10:13 Stephen Bond via ESS-help
>> > <ess-help@r-project.org>
>> > wrote:
>> > 
>> > > Currently there is zero support for the meta/yaml section at the
>> > > beginning, which makes it inconvenient to the point I am using
>> > > Rstudio
>> > > to output my Rmd files.
>> > > 
>> 
>> On Fri, Oct 6, 2023, at 8:16 AM, Manuel Teodoro via ESS-help wrote:
>> > 
>> > I am not part of ESS team but I'm wondering what kind of problems
>> > you have
>> > with Rmd files, maybe we can give you some advices.
>> > 
>> > I do all my Rmd and Qmd files in Emacs without any problem.

______________________________________________
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help

Reply via email to