Skip to content

Use julia-repl in manual & other edits#21866

Merged
KristofferC merged 11 commits intoJuliaLang:masterfrom
mortenpi:mp/julia-repl
May 25, 2017
Merged

Use julia-repl in manual & other edits#21866
KristofferC merged 11 commits intoJuliaLang:masterfrom
mortenpi:mp/julia-repl

Conversation

@mortenpi
Copy link
Copy Markdown
Contributor

Use julia-repl to highlight REPL blocks in the manual, which makes them consistent with doctest blocks. Requires Documenter v0.10.1, which is why it's currently based on #21846.

I also came across a number of REPL blocks that seemed like they could be turned into doctests as well, and a few other small things. However, I guess there might have been a good reason why some of them were not enabled, so I'd be happy to drop some or all of those commits if need be.

I think it would be good to get this backported to 0.6 as well, at least the first commit. It seems that there's only one tiny conflict, so it shouldn't be a big problem.

Example build: http://mortenpi.eu/julia/julia-repl/index.html

LIBM: libopenlibm
LLVM: libLLVM-3.3
```@repl
versioninfo()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change would also require a small bugfix in Documenter (JuliaDocs/Documenter.jl#484).

@ararslan ararslan added the docsystem The documentation building system label May 14, 2017
happens to be uniform:

```julia
```julia-repl
Copy link
Copy Markdown
Contributor

@tkelman tkelman May 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doctest candidate?
(also the next one in this file)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd doctest a lot more in this file, but we'd need a way to run ordinary code within doctests. A named @example block sharing scope with doctests could be a way maybe, but Documenter doesn't support that at the moment afaict.

are needed to separate the generator from subsequent arguments:

```julia
```julia-repl
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doctest candidate? in case the error message changes I suppose

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documenter can't handle syntax errors as far as I can tell (at the moment, should probably be fixed).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah my mistake then. Is there a tracking issue?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is now: JuliaDocs/Documenter.jl#487 Also, the same applies to the invalid UTF-8 example in manual/strings.md.

doesn't know how to perform the requested conversion:

```julia
```julia-repl
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doctest too for the error message?

@KristofferC
Copy link
Copy Markdown
Member

I'm not sure I understand why both julia and julia-repl need to exist? What is the difference?


```julia
```julia-repl
$ echo UTF16 >> ~/.julia/v0.6/REQUIRE
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may want to change this example to a non-deprecated package

More generally, you can use [`open()`](@ref) to read from or write to an external command.

```julia
```julia-repl
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doctestable?

a regular string literal, you will get a syntax error:

```julia
```julia-repl
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could doctest the error

when it would change the semantics is (currently) a syntax error:

```julia
```julia-repl
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doctest for the error?

have a private state, for instance the `state` variable in the following example:

```julia
```julia-repl
Copy link
Copy Markdown
Contributor

@tkelman tkelman May 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this, and the next in this file's diff, should also be testable?

For example, suppose we want to check our new function `foo(x)` works as expected:

```julia
```julia-repl
Copy link
Copy Markdown
Contributor

@tkelman tkelman May 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we put the series in this file in a common named doctest set?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle this should be doable, but it's a bit more work. I'd leave this for another day.

@ararslan
Copy link
Copy Markdown
Member

@KristofferC The julia definition highlights code blocks as programs. That is, every keyword is highlighted. When used as we do throughout the docs, to simulate a REPL session, the output is also highlighted as though it were code. The difference with julia-repl is that it highlights the julia> prompt and all code that's part of the input, but applies no highlighting to the output. Basically it better simulates what a REPL session looks like.

of those methods are, use the [`methods()`](@ref) function:

```julia
```julia-repl
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can't be a doctest at the moment since Documenter thinks that the first line of output is a comment that should be ignored (JuliaDocs/Documenter.jl#483).

@mortenpi
Copy link
Copy Markdown
Contributor Author

Rebased and all the doctests seem to be passing now. I can squash some of the commits (e.g. all the "Enable doctests in ..." ones) if need be, but I was trying to keep distinct changes in separate commits.

@KristofferC
Copy link
Copy Markdown
Member

Great with so many more doctests!

base/regex.jl Outdated
For example, this regex has all three flags enabled:

```julia
```julia-repl
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did I comment on this one or miss it, seems doctestable?

@StefanKarpinski
Copy link
Copy Markdown
Member

We could probably add some smarts to a single julia highlight mode so that it understands when a code block looks like a REPL interaction and does the right thing, but I think having these be different modes is ok too – it provides useful semantic information and it's not all that onerous to mark the two kinds of blocks differently.

@mortenpi
Copy link
Copy Markdown
Contributor Author

We could probably add some smarts to a single julia highlight mode

Someone has to implement that in highlight.js though. As you point out, there are pros and cons to both approaches, so I'm actually neutral on the matter. For some data: other languages in highlight.js seem to have separate lang-repl modes, and both Atom's language-julia and Pygments have a separate grammar/lexer for Julia's REPL syntax -- although that might be just because it's easier to implement it this way.

However, in any case, switching back to a single julia mode would be simple and non-breaking, so we could easily go with julia-repl for now and change back later if we want, I think.

@KristofferC
Copy link
Copy Markdown
Member

Barring objections I plan to merge this later today.

@ararslan
Copy link
Copy Markdown
Member

It would be good to squash some of the commits first; 23 is a lot of separate commits for this.

mortenpi added 5 commits May 25, 2017 16:35
With the highlighting updates in Documenter v0.10.1 it is now possible
to have specialized highlighting for REPL blocks via the julia-repl
attribute on code blocks. Doctests already use this, so this makes the
highlighting for non-doctest REPL blocks consistent.
A couple of code examples were not highlighted for some reason.
These blocks are not Julia code, but special REQUIRE file syntax
instead.
Also add a newline to the end of the file.
UTF16.jl has been deprecated for a while. Use SHA.jl instead as the
example.
@mortenpi
Copy link
Copy Markdown
Contributor Author

Done, down to 11 now. I squashed the similar ones. I left the doctest ones under base/ separate, so it would be a bit easier with any potential merge conflicts, should they get backported.

mortenpi added 5 commits May 25, 2017 16:49
The REPL example is basically exactly as above, and does not add
anything to the latter bit about the actual convert methods.
Switching to julia-repl revealed several code blocks that could
trivially be turned into doctests.
@KristofferC KristofferC merged commit eaace3b into JuliaLang:master May 25, 2017
@ararslan
Copy link
Copy Markdown
Member

Perfect. Thanks, @mortenpi!

@mortenpi mortenpi deleted the mp/julia-repl branch May 25, 2017 22:25
tkelman pushed a commit that referenced this pull request Jun 3, 2017
With the highlighting updates in Documenter v0.10.1 it is now possible
to have specialized highlighting for REPL blocks via the julia-repl
attribute on code blocks. Doctests already use this, so this makes the
highlighting for non-doctest REPL blocks consistent.

(cherry picked from commit 014c5d5)
ref #21866

Use at-repl for versioninfo() output

(cherry picked from commit f67d4fd)

Enable highlighting in the manual

A couple of code examples were not highlighted for some reason.

(cherry picked from commit b710de9)

Remove highlighting from REQUIRE code

These blocks are not Julia code, but special REQUIRE file syntax
instead.

(cherry picked from commit c90c17f)

Enable bash highlighting

Also add a newline to the end of the file.

(cherry picked from commit 6e08c18)

Use a non-deprecated package in an example

UTF16.jl has been deprecated for a while. Use SHA.jl instead as the
example.

(cherry picked from commit 6e5c55d)

Edit manual/conversion-and-promotion.md

The REPL example is basically exactly as above, and does not add
anything to the latter bit about the actual convert methods.

(cherry picked from commit 96b65f1)

Fix line numbers in doctests

(cherry picked from commit 814a8a1)

Enable a doctest in base/regex.jl

(cherry picked from commit d9063cb)

Enable doctests the the manual

Switching to julia-repl revealed several code blocks that could
trivially be turned into doctests.

(cherry picked from commit 1d20519)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docsystem The documentation building system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants