@@ -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
@@ -241,6 +241,10 @@ This consists of log messages printed to the terminal window where
241241or received by the kernel. Used for debugging IJulia.
242242"""
243243function set_verbose (v:: Bool = true , kernel= _default_kernel)
244+ if isnothing (kernel)
245+ error (" Kernel has not been initialized, cannot set its verbosity." )
246+ end
247+
244248 kernel. verbose = v
245249end
246250
@@ -252,7 +256,13 @@ whether you are in an IJulia notebook, therefore, you can check
252256"""
253257inited:: Bool = false
254258
255- set_current_module (m:: Module ; kernel= _default_kernel) = kernel. current_module = m
259+ function set_current_module (m:: Module ; kernel= _default_kernel)
260+ if isnothing (kernel)
261+ error (" Kernel has not been initialized, cannot set the current module." )
262+ end
263+
264+ kernel. current_module = m
265+ end
256266
257267_shutting_down:: Threads.Atomic{Bool} = Threads. Atomic {Bool} (false )
258268
@@ -384,6 +394,15 @@ history
384394# executing an input cell, e.g. to "close" the current plot in Pylab.
385395# Modules should only use these if isdefined(Main, IJulia) is true.
386396
397+ function _pop_hook! (f, hooks)
398+ hook_idx = findlast (isequal (f), hooks)
399+ if isnothing (hook_idx)
400+ error (" Could not find hook: $(f) " )
401+ else
402+ splice! (hooks, hook_idx)
403+ end
404+ end
405+
387406"""
388407 push_postexecute_hook(f::Function)
389408
@@ -397,8 +416,7 @@ push_postexecute_hook(f::Function; kernel=_default_kernel) = push!(kernel.postex
397416Remove a function `f()` from the list of functions to
398417execute after executing any notebook cell.
399418"""
400- pop_postexecute_hook (f:: Function ; kernel= _default_kernel) =
401- splice! (kernel. postexecute_hooks, findlast (isequal (f), kernel. postexecute_hooks))
419+ pop_postexecute_hook (f:: Function ; kernel= _default_kernel) = _pop_hook! (f, kernel. postexecute_hooks)
402420
403421"""
404422 push_preexecute_hook(f::Function)
@@ -413,8 +431,7 @@ push_preexecute_hook(f::Function; kernel=_default_kernel) = push!(kernel.preexec
413431Remove a function `f()` from the list of functions to
414432execute before executing any notebook cell.
415433"""
416- pop_preexecute_hook (f:: Function ; kernel= _default_kernel) =
417- splice! (kernel. preexecute_hooks, findlast (isequal (f), kernel. preexecute_hooks))
434+ pop_preexecute_hook (f:: Function ; kernel= _default_kernel) = _pop_hook! (f, kernel. preexecute_hooks)
418435
419436# similar, but called after an error (e.g. to reset plotting state)
420437"""
@@ -430,8 +447,7 @@ push_posterror_hook(f::Function; kernel=_default_kernel) = push!(kernel.posterro
430447Remove a function `f()` from the list of functions to
431448execute after an error occurs when a notebook cell is evaluated.
432449"""
433- pop_posterror_hook (f:: Function ; kernel= _default_kernel) =
434- splice! (kernel. posterror_hooks, findlast (isequal (f), kernel. posterror_hooks))
450+ pop_posterror_hook (f:: Function ; kernel= _default_kernel) = _pop_hook! (f, kernel. posterror_hooks)
435451
436452# ######################################################################
437453
0 commit comments