@@ -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
@@ -243,6 +243,10 @@ This consists of log messages printed to the terminal window where
243243or received by the kernel. Used for debugging IJulia.
244244"""
245245function set_verbose (v:: Bool = true , kernel= _default_kernel)
246+ if isnothing (kernel)
247+ error (" Kernel has not been initialized, cannot set its verbosity." )
248+ end
249+
246250 kernel. verbose = v
247251end
248252
@@ -254,7 +258,13 @@ whether you are in an IJulia notebook, therefore, you can check
254258"""
255259inited:: Bool = false
256260
257- set_current_module (m:: Module ; kernel= _default_kernel) = kernel. current_module = m
261+ function set_current_module (m:: Module ; kernel= _default_kernel)
262+ if isnothing (kernel)
263+ error (" Kernel has not been initialized, cannot set the current module." )
264+ end
265+
266+ kernel. current_module = m
267+ end
258268
259269_shutting_down:: Threads.Atomic{Bool} = Threads. Atomic {Bool} (false )
260270
@@ -386,6 +396,15 @@ history
386396# executing an input cell, e.g. to "close" the current plot in Pylab.
387397# Modules should only use these if isdefined(Main, IJulia) is true.
388398
399+ function _pop_hook! (f, hooks)
400+ hook_idx = findlast (isequal (f), hooks)
401+ if isnothing (hook_idx)
402+ error (" Could not find hook: $(f) " )
403+ else
404+ splice! (hooks, hook_idx)
405+ end
406+ end
407+
389408"""
390409 push_postexecute_hook(f::Function)
391410
@@ -399,8 +418,7 @@ push_postexecute_hook(f::Function; kernel=_default_kernel) = push!(kernel.postex
399418Remove a function `f()` from the list of functions to
400419execute after executing any notebook cell.
401420"""
402- pop_postexecute_hook (f:: Function ; kernel= _default_kernel) =
403- splice! (kernel. postexecute_hooks, findlast (isequal (f), kernel. postexecute_hooks))
421+ pop_postexecute_hook (f:: Function ; kernel= _default_kernel) = _pop_hook! (f, kernel. postexecute_hooks)
404422
405423"""
406424 push_preexecute_hook(f::Function)
@@ -415,8 +433,7 @@ push_preexecute_hook(f::Function; kernel=_default_kernel) = push!(kernel.preexec
415433Remove a function `f()` from the list of functions to
416434execute before executing any notebook cell.
417435"""
418- pop_preexecute_hook (f:: Function ; kernel= _default_kernel) =
419- splice! (kernel. preexecute_hooks, findlast (isequal (f), kernel. preexecute_hooks))
436+ pop_preexecute_hook (f:: Function ; kernel= _default_kernel) = _pop_hook! (f, kernel. preexecute_hooks)
420437
421438# similar, but called after an error (e.g. to reset plotting state)
422439"""
@@ -432,8 +449,7 @@ push_posterror_hook(f::Function; kernel=_default_kernel) = push!(kernel.posterro
432449Remove a function `f()` from the list of functions to
433450execute after an error occurs when a notebook cell is evaluated.
434451"""
435- pop_posterror_hook (f:: Function ; kernel= _default_kernel) =
436- splice! (kernel. posterror_hooks, findlast (isequal (f), kernel. posterror_hooks))
452+ pop_posterror_hook (f:: Function ; kernel= _default_kernel) = _pop_hook! (f, kernel. posterror_hooks)
437453
438454# ######################################################################
439455
0 commit comments