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

isinteractive() and REPL customizations no longer available from .juliarc.jl #10779

Closed
carlobaldassi opened this issue Apr 9, 2015 · 10 comments · Fixed by #42507
Closed

isinteractive() and REPL customizations no longer available from .juliarc.jl #10779

carlobaldassi opened this issue Apr 9, 2015 · 10 comments · Fixed by #42507
Labels
REPL Julia's REPL (Read Eval Print Loop)

Comments

@carlobaldassi
Copy link
Member

The refactoring in e1b3d85 (cc @JeffBezanson) had the consequence that calling isinteractive() from .juliarc.jl always returns false.

I have some code in there which I only want to load when using the REPL. I'd consider this a regression, but maybe I'm missing something. Any ideas on how to fix this?

@carlobaldassi
Copy link
Member Author

In little more detail: what I wanted (and used to be able) to do is modify Base.active_repl (for customizing the prompt and - more importantly - the key bindings). Since the change, that is also not defined at the time .juliarc.jl is loaded, so now there seems to be no way to achieve that.

@carlobaldassi carlobaldassi changed the title isinteractive() no longer available from .juliarc.jl isinteractive() and REPL customizations no longer available from .juliarc.jl Apr 9, 2015
@carlobaldassi carlobaldassi added the REPL Julia's REPL (Read Eval Print Loop) label Apr 9, 2015
@carlobaldassi
Copy link
Member Author

I updated the title and labels to account for the REPL issue, which is no longer customizable now (i.e. everything is parsed before the REPL is created, and there's no way to hook into it as far as I can tell).

@yuyichao
Copy link
Contributor

Can this issue be closed now given atreplinit() is merged?

@pao pao closed this as completed Apr 20, 2015
@pao
Copy link
Member

pao commented Apr 20, 2015

Reopening per #10782 (comment)

@pao pao reopened this Apr 20, 2015
@pao
Copy link
Member

pao commented Apr 21, 2015

Okay, someone needs to decide if #10782 is enough to close this: @yuyichao @phobon @carlobaldassi & I'll leave it up to @carlobaldassi to declare this closed.

@carlobaldassi
Copy link
Member Author

My own needs are taken care of by atreplinit(), and apparently one could use that as a hack to detect if we're in an interactive session most of the time, but it doesn't seem right to me.

This boils down to this question by @yuyichao:

Is there a interactive shell that doesn't have REPL?

to which I don't know the answer, but I think there may be. Isn't there an emacs mode which uses a bare-bone REPL of some kind? (I don't use emacs so I'm not sure.)
In any case it seems that the two concepts should stay separate, meaning that this issue should be fixed in another way.

Someone more familiar with the nuances of julia initialization could correct me though, in which case feel free to close.

@carlobaldassi
Copy link
Member Author

Upon closer inspection of client.jl, it seems to me that there is one case in which isinteractive() can be true without calling the REPL, and therefore skipping atreplinit(), namely when STDIN is not a TTY, nor a File, nor an IOStream, in which case julia behaves REPL-like, parsing one input line at a time. See this line and this line.
I'm not sure what's the use case for this, but it seems relevant that one could use code from .juliarc.jl in such cases.

mbauman pushed a commit to mbauman/julia that referenced this issue Jun 6, 2015
@ZacCranko
Copy link

Is this currently the best way to implement the isinteractive() && isfile("_init.jl") && require("_init.jl") behaviour from the docs when running 0.3.9 and 0.4 at the same time?

if VERSION == v"0.3.9"
    if isinteractive() && isfile("_init.jl")
        info("Running _init.jl")
        require("_init.jl")
    end
elseif isfile("_init.jl")
    atreplinit() do repl
        info("Running _init.jl")
        require("_init.jl")
    end
end

@goretkin
Copy link
Contributor

I think the current behavior, isinteractive() returns different values within the same invocation of a julia process (see below), is unexpected. I expect isinteractive() == true if a REPL is going to exist, not just after it already exists.

$cat ~/.julia/config/startup.jl
@show isinteractive()

atreplinit() do repl
    println("[debug] invoke `atreplinit` callback\n\t\tisinteractive() = $(isinteractive())")
end
$
$julia --banner=no
isinteractive() = false
[debug] invoke `atreplinit` callback
		isinteractive() = true
julia> exit()
$julia --banner=no -e '1 + 1 '
isinteractive() = false

And for completeness:

$julia --banner=no -i
isinteractive() = true
[debug] invoke `atreplinit` callback
		isinteractive() = true
julia> exit()
$
$julia --banner=no -i -e '1 + 1'
isinteractive() = true
[debug] invoke `atreplinit` callback
		isinteractive() = true
julia> exit()
$

Is isinteractive() effectively "is a REPL running?"? The docstring could clarify. Currently:

help?> isinteractive()
  isinteractive() -> Bool

  Determine whether Julia is running an interactive session.

@goretkin
Copy link
Contributor

goretkin commented Mar 25, 2021

From julia --help:
-i Interactive mode; REPL runs and isinteractive() is true

Is the only difference between julia and julia -i the return value of isinteractive()? (I know the behavior is different if e.g. an expression is passed with -e or it is given a .jl file to run.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
REPL Julia's REPL (Read Eval Print Loop)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants