Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use julia-repl in manual & other edits #21866

Merged
merged 11 commits into from
May 25, 2017

Conversation

mortenpi
Copy link
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
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
@@ -152,7 +152,7 @@ we can define dispatch directly on `SubArray{T,N,A,I,true}` without any intermed
Since this computation doesn't depend on runtime values, it can miss some cases in which the stride
happens to be uniform:

```julia
```julia-repl
Copy link
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
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.

@@ -182,7 +182,7 @@ julia> sum(1/n^2 for n=1:1000)
When writing a generator expression with multiple dimensions inside an argument list, parentheses
are needed to separate the generator from subsequent arguments:

```julia
```julia-repl
Copy link
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
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
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
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.

1.0 2.0 3.0
4.0 5.0 6.0
```

Conversion isn't always possible, in which case a no method error is thrown indicating that `convert`
doesn't know how to perform the requested conversion:

```julia
```julia-repl
Copy link
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
Member

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

@@ -106,7 +106,7 @@ that the `Distributions` package should be installed since it is required but no
stated before, you can accomplish the same thing by editing your `~/.julia/v0.6/REQUIRE` file
by hand and then running [`Pkg.resolve()`](@ref) yourself:

```julia
```julia-repl
$ echo UTF16 >> ~/.julia/v0.6/REQUIRE
Copy link
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

@@ -49,7 +49,7 @@ true

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

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

Choose a reason for hiding this comment

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

doctestable?

@@ -808,7 +808,7 @@ The Unicode escape `\u2200` is encoded in UTF-8 as the three bytes 226, 136, 128
resulting byte array does not correspond to a valid UTF-8 string -- if you try to use this as
a regular string literal, you will get a syntax error:

```julia
```julia-repl
Copy link
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

@@ -174,7 +174,7 @@ julia> x
Within soft scopes, the *global* keyword is never necessary, although allowed. The only case
when it would change the semantics is (currently) a syntax error:

```julia
```julia-repl
Copy link
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?

@@ -332,7 +332,7 @@ The reason to allow *modifying local* variables of parent scopes in nested funct
constructing [closures](https://en.wikipedia.org/wiki/Closure_%28computer_programming%29) which
have a private state, for instance the `state` variable in the following example:

```julia
```julia-repl
Copy link
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?

@@ -26,7 +26,7 @@ Base.Test.@test_throws

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

```julia
```julia-repl
Copy link
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
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
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.

@@ -163,7 +163,7 @@ f (generic function with 2 methods)
This output tells us that `f` is a function object with two methods. To find out what the signatures
of those methods are, use the [`methods()`](@ref) function:

```julia
```julia-repl
Copy link
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
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
Member

Great with so many more doctests!

base/regex.jl Outdated
@@ -75,7 +75,7 @@ after the ending quote, to change its behaviour:

For example, this regex has all three flags enabled:

```julia
```julia-repl
Copy link
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
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
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
Member

Barring objections I plan to merge this later today.

@ararslan
Copy link
Member

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

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
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.

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
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