@@ -78,7 +78,7 @@ mutable struct Comm{target}
7878 primary:: Bool
7979 on_msg:: Function
8080 on_close:: Function
81- function (:: Type{Comm{target}} )(id, primary, on_msg, on_close; kernel= _default_kernel ) where {target}
81+ function (:: Type{Comm{target}} )(id, primary, on_msg, on_close, kernel) where {target}
8282 comm = new {target} (id, primary, on_msg, on_close)
8383 kernel. comms[id] = comm
8484 return comm
@@ -240,6 +240,10 @@ This consists of log messages printed to the terminal window where
240240or received by the kernel. Used for debugging IJulia.
241241"""
242242function set_verbose (v:: Bool = true , kernel= _default_kernel)
243+ if isnothing (kernel)
244+ error (" Kernel has not been initialized, cannot set its verbosity." )
245+ end
246+
243247 kernel. verbose = v
244248end
245249
@@ -251,7 +255,13 @@ whether you are in an IJulia notebook, therefore, you can check
251255"""
252256inited:: Bool = false
253257
254- set_current_module (m:: Module ; kernel= _default_kernel) = kernel. current_module = m
258+ function set_current_module (m:: Module ; kernel= _default_kernel)
259+ if isnothing (kernel)
260+ error (" Kernel has not been initialized, cannot set the current module." )
261+ end
262+
263+ kernel. current_module = m
264+ end
255265
256266_shutting_down:: Threads.Atomic{Bool} = Threads. Atomic {Bool} (false )
257267
@@ -383,6 +393,15 @@ history
383393# executing an input cell, e.g. to "close" the current plot in Pylab.
384394# Modules should only use these if isdefined(Main, IJulia) is true.
385395
396+ function _pop_hook! (f, hooks)
397+ hook_idx = findlast (isequal (f), hooks)
398+ if isnothing (hook_idx)
399+ error (" Could not find hook: $(f) " )
400+ else
401+ splice! (hooks, hook_idx)
402+ end
403+ end
404+
386405"""
387406 push_postexecute_hook(f::Function)
388407
@@ -396,8 +415,7 @@ push_postexecute_hook(f::Function; kernel=_default_kernel) = push!(kernel.postex
396415Remove a function `f()` from the list of functions to
397416execute after executing any notebook cell.
398417"""
399- pop_postexecute_hook (f:: Function ; kernel= _default_kernel) =
400- splice! (kernel. postexecute_hooks, findlast (isequal (f), kernel. postexecute_hooks))
418+ pop_postexecute_hook (f:: Function ; kernel= _default_kernel) = _pop_hook! (f, kernel. postexecute_hooks)
401419
402420"""
403421 push_preexecute_hook(f::Function)
@@ -412,8 +430,7 @@ push_preexecute_hook(f::Function; kernel=_default_kernel) = push!(kernel.preexec
412430Remove a function `f()` from the list of functions to
413431execute before executing any notebook cell.
414432"""
415- pop_preexecute_hook (f:: Function ; kernel= _default_kernel) =
416- splice! (kernel. preexecute_hooks, findlast (isequal (f), kernel. preexecute_hooks))
433+ pop_preexecute_hook (f:: Function ; kernel= _default_kernel) = _pop_hook! (f, kernel. preexecute_hooks)
417434
418435# similar, but called after an error (e.g. to reset plotting state)
419436"""
@@ -429,8 +446,7 @@ push_posterror_hook(f::Function; kernel=_default_kernel) = push!(kernel.posterro
429446Remove a function `f()` from the list of functions to
430447execute after an error occurs when a notebook cell is evaluated.
431448"""
432- pop_posterror_hook (f:: Function ; kernel= _default_kernel) =
433- splice! (kernel. posterror_hooks, findlast (isequal (f), kernel. posterror_hooks))
449+ pop_posterror_hook (f:: Function ; kernel= _default_kernel) = _pop_hook! (f, kernel. posterror_hooks)
434450
435451# ######################################################################
436452
0 commit comments