emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: "Andrés Saraos Luna" <saraoslunaandres@gmail.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [0] ob-rust, support for rust code blocks
Date: Wed, 20 Dec 2017 00:16:15 +0100	[thread overview]
Message-ID: <877etijolc.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <e6762cad-e681-4ea3-b168-7c37cd69b170@getmailbird.com> ("Andrés Saraos Luna"'s message of "Mon, 18 Dec 2017 14:44:20 +0100")

Hello,

Andrés Saraos Luna <saraoslunaandres@gmail.com> writes:

> As a toy project I've written a simple ob-rust, mainly in order to
> prepare some simple demos using rust.

Thank you.

There is another "ob-rust.el" at
<https://github.com/micanzhang/ob-rust>. Would it make sense to join
efforts with its author?

> Since I'm not completely sure of the submission protocol for new
> features, the new file lives in contrib for now, although it doesn't
> depend on anything outside of `ob' really so maybe it could be added
> to core?

You need to sign FSF papers for that. Even if it doesn't land in master,
I suggest to start the process as it could take some time, depending on
your country. It would be nice to sort out the issue about 

> As far as testing is concerned, since I don't know how to use the
> database used by `org-test-at-id' I hardcoded the name of the testing
> file, I'd be happy to change that if necessary.

You don't need to use `org-test-at-id'. I even suggest to stay away from
it, as it makes debugging harder. Instead, you could make tests
self-sufficient, e.g.:

    (should
     (equal 42
            (org-test-with-temp-text "
    <point>#+name: test-simple
    #+BEGIN_SRC rust :results silent
      fn main() {
          let answer = 42;
          println!("{}", answer);
      }
    #+END_SRC"
          (org-babel-execute-src-block))))

Note that `should' is in the outer part of the test.

> Here's hoping this is useful for others, and since this is my first
> time writing anything functional in elisp I'm gladly open for any
> hints to improve the code.

I have a few suggestion. In particular docstrings should start with one
(or two) sentence(s) filling the first line. Additional sentences need
to start on subsequent lines.

Also, you need to add two spaces at the end of sentences.

> * contrib/lisp/ob-rust.el: Support for limited rust source code in org
>   babel.
>
> * testing/examples/ob-rust-test.org: Test all implemented features of
>   ob-rust in the form of named Org source blocks.
>
> * testing/lisp/test-ob-rust.el: Defines the tests.
>
> TINYCHANGE

This is not a TINYCHANGE :)

> +;; Org-Babel support for evaluating rust code.

Babel support for...

> +;; A currently very limited implementation:
> +;;  - arrays, vecs, lists or tables are not yet supported as header
> +;;  arguments
> +;;  - no error handling
> +;;  - only :results output is supported
> +;;  - cargo is completely ignored
> +
> +(require 'ob)
> +
> +(defvar org-babel-tangle-lang-exts)
> +(add-to-list 'org-babel-tangle-lang-exts '("rust" . "rs"))
> +
> +(defcustom org-babel-rust-command "rustc"
> +  "Name of the rust command."
> +  :group 'org-babel
> +  :type 'string)
> +
> +(defun org-babel-execute:rust (body params)

This function is missing a docstring.

> +  (let* ((full-body (org-babel-expand-body:rust body params))
> +         (cmpflag (or (cdr (assq :cmpflag params)) ""))
> +         (cmdline (or (cdr (assq :cmdline params)) ""))
> +         (default-directory org-babel-temporary-directory)
> +         (src-file (org-babel-temp-file "rust-src-" ".rs"))
> +         (exe-file (org-babel-rust-exe-file src-file cmpflag))
> +         (results))
> +    (with-temp-file src-file
> +      (insert full-body)
> +      (when (require 'rust-mode nil t)
> +        (rust-format-buffer)))
> +    (org-babel-eval
> +     (format "%s %s %s" org-babel-rust-command cmpflag src-file) "")
> +    (setq results (org-babel-eval (format "%s %s" exe-file cmdline) ""))
> +    (org-babel-reassemble-table
> +     (org-babel-result-cond (cdr (assq :result-params params))
> +       (org-babel-read results)
> +       (let ((tmp-file (org-babel-temp-file "rs-")))
> +         (with-temp-file tmp-file (insert results))
> +         (org-babel-import-elisp-from-file tmp-file)))
> +     (org-babel-pick-name
> +      (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
> +     (org-babel-pick-name
> +      (cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))
> +
> +(defun org-babel-expand-body:rust (body params)
> +  "Expand a block of rust code with org-babel according to its
> +header arguments."

The sentence must fit on a single line.

Also "Org Babel"

> +(defun org-babel-prep-session:rust (_session _params)
> +  "This function does nothing as C is a compiled language with no
> +support for sessions"
> +  (error "no support for sessions"))

C -> Rust

> +(defun org-babel-load-session:rust (_session _body _params)
> +  "This function does nothing as C is a compiled language with no
> +support for sessions"
> +  (error "no support for sessions"))

Ditto.
> +  (let* ((var (car var-pairs))
> +         (val (cdr var-pairs))
> +         (value-type (org-babel-rust-val-to-rust-type val))
> +         (var-s (symbol-name var))
> +         (var-regexp "\\(^mut_\\)?\\([[:alnum:]_]+\\)\\(: ?[[:alnum:]]+\\)?[ \t]*$")
> +         (mut
> +          (progn
> +            (string-match var-regexp var-s)
> +            (match-string 1 var-s)))
> +         (var-name
> +          (progn
> +            (string-match var-regexp var-s)
> +            (match-string 2 var-s)))
> +         (var-type
> +          (or
> +           (progn
> +             (string-match var-regexp var-s)
> +             (match-string 3 var-s))

You shouldn't match multiple times. Match once and get match strings.

Regards,

-- 
Nicolas Goaziou

      reply	other threads:[~2017-12-19 23:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-18 13:44 [0] ob-rust, support for rust code blocks Andrés Saraos Luna
2017-12-19 23:16 ` 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=877etijolc.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=saraoslunaandres@gmail.com \
    /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).