gcv / julia-snail

An Emacs development environment for Julia
GNU General Public License v3.0
236 stars 23 forks source link

Throw error when using `julia-snail-send-region`, in the case of writing Julia package #51

Closed nesteiner closed 3 years ago

nesteiner commented 3 years ago

https://user-images.githubusercontent.com/46296608/124469859-796aab00-ddcd-11eb-9ad8-64987e806964.mp4

this file editing is in the package LinkedList. which confuses me is, when writing this struct in the REPL, it works well. but when using julia-snail-send-region, it will throw the error, what the hell is this??

gcv commented 3 years ago

That works for me when I start with an empty module:

module LinkedList
end

Then add the definition of LinkedList, and then evaluate it:

module LinkedList

mutable struct ListNode{T}
   value::T
   next::Union{Nothing, ListNode{T}}
end

end

I do get an error if I try to change the definition:

module LinkedList

mutable struct ListNode{T}
   value::T
   value2::T
   next::Union{Nothing, ListNode{T}}
end

end

LoadError: invalid redefinition of constant ListNode.

The same thing happens if I try to change the definition at the REPL:

julia> mutable struct ListNode{T}
          value::T
          next::Union{Nothing, ListNode{T}}
       end

julia> mutable struct ListNode{T}
          value::T
          value2::T
          next::Union{Nothing, ListNode{T}}
       end
ERROR: invalid redefinition of constant ListNode4
Stacktrace:
 [1] top-level scope

The REPL operation worked for you because the REPL operates in the Main module, but your definition changed in the LinkedList module.

I'm not sure why you have a different error message. Maybe the error message changed in Julia? I have version 1.6.1 here.

nesteiner commented 3 years ago

I think there is mistake between our communication,

https://user-images.githubusercontent.com/46296608/124486306-0ae31880-dde0-11eb-8467-34bbe0b7edd6.mp4 the problem is, julia-snail-send-region should just send the string from region, it should be not influenced by environment, and we should solve this error

MethodError: no method matching root_module(::Nothing)
Closest candidates are:
  root_module(!Matched::Base.PkgId) at loading.jl:957
  root_module(!Matched::Module, !Matched::Symbol) at loading.jl:958

root_module(where::Module, name::Symbol) at loading.jl:958
eval_in_module(fully_qualified_module_name::Vector{Symbol}, expr::Expr) at JuliaSnail.jl:104
macro expansion at JuliaSnail.jl:356 [inlined]
(::Main.JuliaSnail.var"#32#36"{Sockets.TCPSocket})() at task.jl:411
gcv commented 3 years ago

Oh, now I see. You didn’t define the module, then the evaluation tries to happen in the module context, and fails.

You can make julia-snail-send-region ignore the module context by calling it with a prefix argument (C-u C-c C-r by default).

I recommend loading the file with julia-snail-send-buffer-file (C-c C-k). It’ll define the module, and then julia-snail-send-region will work fine with the module context.

That error message sucks, though. I’ll see what I can do to catch this error and make it more informative.

nesteiner commented 3 years ago

C-u C-c C-r, it's too long :yum: what variable can I modify ?

gcv commented 3 years ago
(define-key julia-snail-mode-map (kbd "C-c C-r")
  (lambda ()
    (interactive)
    (let ((current-prefix-arg t))
      (julia-snail-send-region))))

Or change your use-package invocation accordingly.

gcv commented 3 years ago

Error message improved in commit 7652679.