emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Brad Knotwell <bknotwell@yahoo.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: language support for m4
Date: Thu, 05 Apr 2018 16:58:38 +0200	[thread overview]
Message-ID: <871sft4s4h.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <1363290911.1944832.1522910146358@mail.yahoo.com> (Brad Knotwell's message of "Thu, 5 Apr 2018 06:35:46 +0000 (UTC)")

Hello,

Brad Knotwell <bknotwell@yahoo.com> writes:

> The attached file adds m4 support.  It was tested against org-9.1.7
> and used ob-sed.el and ob-shell.el for inspiration.  Both code
> execution and tangling have been tested with simple inputs as well as
> tables (easiest way to verify correctness is to inspect the tangled
> output).  It was good fun for an evening project (converting the
> tables to m4 list syntax was the trickiest part and required a foray
> into ob-shell.el; pcase is a nifty function).
> When putting it together, I debated between putting the definitions
> representing variables in as -DNAME=value pairs in the command-line or
> putting them in the body of the generate file.  Even though it's a bit
> uglier, I decided to put them in the body of the file as it makes the
> generated file capable of being run by hand.

Thank you. Some comments follow.

First, what is your status wrt FSF papers. If you haven't signed them,
this can go in contrib/ until it is sorted out.

> ;; Copyright (C) 2015-2018 Free Software Foundation, Inc.

The copyright years are probably not accurate.

> ;; build the passed-in macro definitions as a single string to prepend to the body
> ;; the hocus-pocus with :prefix-builtins is necessary for the -P option to work

Could you make two separate sentences? The above is a bit annoying to
grok.

> (defun __org-babel-m4-prefix (params) (if (assq :prefix-builtins params) "m4_"))

The name of the function is not right. It should probably be
`org-babel--m4-prefix'.  Also, it needs a docstring.

Nitpick:

  (and (assq :prefix-builtins params) "m4_")

> (defun org-babel--variable-assignment:m4_generic (params varname values)

Ditto about the missing docstring.

>   (concat (__org-babel-m4-prefix params)
> 	  "define(" (format "%s" varname) "," (format "%s" values) ")"
> 	  (__org-babel-m4-prefix params)
> 	  "dnl\n"))

  (format "define(%s,%s)" varname values)

>
> (defun org-babel--variable-assignment:m4_list (params varname values)

Ditto.

>   (concat (__org-babel-m4-prefix params)
> 	  "define(" (format "%s,[" varname)

Per above:

  (format "define(%s,[%s])"
          varname
          (mapconcat ...))

> 	  (mapconcat (lambda (value)
> 		       (if (= (length value) 1) (format "%s" (car value))

  (and (= (length value) 1) (format "%s" (car values)))

Aren't `values' strings already?

> 		       (concat "["
> 			       (mapconcat (lambda (x) (format "%s" x)) value ",")
> 			       "]"))) values ",")
> 	  "])" (__org-babel-m4-prefix params) "dnl\n"))
>
> (defun org-babel--variable-assignments:m4 (params varnames values)
>   "Represent the parameters as m4 definitions"
>   (pcase values
>     (`(,_ . ,_) (org-babel--variable-assignment:m4_list params varnames values))
>     (_ (org-babel--variable-assignment:m4_generic params varnames values))))
>
> (defun org-babel-variable-assignments:m4 (params)
>   (apply 'concat (mapcar (lambda (pair) (org-babel--variable-assignments:m4
> 					 params (car pair) (cdr pair)))
> 			 (org-babel--get-vars params))))

  (apply #'concat ...)
  
>
> ;; required to make tangling work
> ;; the final "\n" is required to make m4 work as the body doesn't end in a newline

Missing capitals and full stops.

> ;; Test examples below:

These could go into a "test-ob-m4.el" file.

Regards,

-- 
Nicolas Goaziou

      reply	other threads:[~2018-04-06 21:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1363290911.1944832.1522910146358.ref@mail.yahoo.com>
2018-04-05  6:35 ` language support for m4 Brad Knotwell
2018-04-05 14:58   ` Nicolas Goaziou [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871sft4s4h.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=bknotwell@yahoo.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).