@@ -355,152 +355,6 @@ export number_of_variables
355
355
@alias nrows number_of_rows
356
356
@alias nvars number_of_variables
357
357
358
- # ##############################################################################
359
- # Macros for fancy printing. to use, enable attribute storage for your struct,
360
- # i.e.m change
361
- #
362
- # mutable struct bla..
363
- # ...
364
- # end
365
- #
366
- # to
367
- #
368
- # @attributes mutable struct bla ..
369
- # ...
370
- # end
371
- #
372
- # Then, in the `show` method, start with
373
- # @show_name(io, obj)
374
- # If the user assigned a name to the object (in the REPL mainly) by doing
375
- # A = bla...
376
- # then, in the compact printing only the name "A" is printed
377
- # also adding
378
- # @show_special(io, obj)
379
- # allows, if present to call a different printing function for this instance
380
- # See FreeModule for an example
381
- #
382
- # ##############################################################################
383
-
384
- function set_name! (G:: Any , name:: String )
385
- set_attribute! (G, :name => name)
386
- end
387
-
388
- function set_name! (G)
389
- s = get_attribute (G, :name )
390
- s === nothing || return
391
- sy = find_name (G)
392
- sy === nothing && return
393
- set_name! (G, string (sy))
394
- end
395
-
396
- extra_name (G) = nothing
397
-
398
- macro show_name (io, O)
399
- return :( begin
400
- local i = $ (esc (io))
401
- local o = $ (esc (O))
402
- s = get_attribute (o, :name )
403
- if s === nothing
404
- sy = find_name (o)
405
- if sy === nothing
406
- sy = extra_name (o)
407
- end
408
- if sy != = nothing
409
- s = string (sy)
410
- set_name! (o, s)
411
- end
412
- end
413
- if s != = nothing && (get (i, :supercompact , false ) || get (i, :compact , false ))
414
- if AbstractAlgebra. PrettyPrinting. _supports_io_custom (i)
415
- print (i, LowercaseOff ())
416
- end
417
- print (i, s)
418
- return
419
- end
420
- end )
421
- end
422
-
423
- const CurrentModule = Ref (Main)
424
-
425
- function set_current_module (m)
426
- CurrentModule[] = m
427
- end
428
-
429
- function get_current_module ()
430
- return CurrentModule[]
431
- end
432
-
433
- function find_name (A, M = Main; all:: Bool = false )
434
- # in Documenter, the examples are not run in the REPL.
435
- # in the REPL: A = ... adds A to the global name space (Main....)
436
- # in Documenter (doctests) all examples are run in their own module
437
- # which is stored in CurrentModule, hence we need to search there as well
438
- # furthermore, they are not exported, hence the "all" option
439
- if M === Main && AbstractAlgebra. get_current_module () != Main
440
- a = find_name (A, AbstractAlgebra. get_current_module (), all = true )
441
- if a != = nothing
442
- return a
443
- end
444
- end
445
- for a = names (M, all = all)
446
- a === :ans && continue
447
- if isdefined (M, a) && getfield (M, a) === A
448
- return a
449
- end
450
- end
451
- end
452
-
453
- macro show_special (io, O)
454
- return :( begin
455
- local i = $ (esc (io))
456
- local o = $ (esc (O))
457
- s = get_attribute (o, :show )
458
- if s != = nothing
459
- s (i, o)
460
- return
461
- end
462
- end )
463
- end
464
-
465
- macro show_special (io, mime, O)
466
- return :( begin
467
- local i = $ (esc (io))
468
- local m = $ (esc (mime))
469
- local o = $ (esc (O))
470
- s = get_attribute (o, :show )
471
- if s != = nothing
472
- s (i, m, o)
473
- return
474
- end
475
- end )
476
- end
477
-
478
- macro show_special_elem (io, e)
479
- return :( begin
480
- local i = $ (esc (io))
481
- local a = $ (esc (e))
482
- local o = parent (a)
483
- s = get_attribute (o, :show_elem )
484
- if s != = nothing
485
- s (i, a)
486
- return
487
- end
488
- end )
489
- end
490
-
491
- macro show_special_elem (io, mime, e)
492
- return :( begin
493
- local i = $ (esc (io))
494
- local m = $ (esc (mime))
495
- local a = $ (esc (e))
496
- local o = parent (a)
497
- s = get_attribute (o, :show_elem )
498
- if s != = nothing
499
- s (i, m, a)
500
- return
501
- end
502
- end )
503
- end
504
358
505
359
# ##############################################################################
506
360
# generic fall back if no immediate coercion is possible
@@ -607,11 +461,16 @@ include("fundamental_interface.jl")
607
461
include (" PrettyPrinting.jl" )
608
462
609
463
import . PrettyPrinting: @enable_all_show_via_expressify
464
+ import . PrettyPrinting: @show_name
465
+ import . PrettyPrinting: @show_special
466
+ import . PrettyPrinting: @show_special_elem
610
467
import . PrettyPrinting: allow_unicode
611
468
import . PrettyPrinting: canonicalize
612
469
import . PrettyPrinting: expr_to_latex_string
613
470
import . PrettyPrinting: expr_to_string
614
471
import . PrettyPrinting: expressify
472
+ import . PrettyPrinting: extra_name
473
+ import . PrettyPrinting: get_current_module
615
474
import . PrettyPrinting: get_html_as_latex
616
475
import . PrettyPrinting: get_syntactic_sign_abs
617
476
import . PrettyPrinting: is_syntactic_one
@@ -623,6 +482,7 @@ import .PrettyPrinting: obj_to_string_wrt_times
623
482
import . PrettyPrinting: print_integer_string
624
483
import . PrettyPrinting: print_obj
625
484
import . PrettyPrinting: printer
485
+ import . PrettyPrinting: set_current_module
626
486
import . PrettyPrinting: set_html_as_latex
627
487
import . PrettyPrinting: show_obj
628
488
import . PrettyPrinting: show_via_expressify
0 commit comments