PrettyTables.jl: @ptconf tf argument not able to find custom tf

Hi, I’m currently using PrettyTables, and I’m not sure what’s going on with my codes below. I defined a custom tf as follows:

using JuliaDB
using PrettyTables

tf_compact2 = TextFormat(up_right_corner = '─',
                   up_left_corner      = '─',
                   bottom_left_corner  = '─',
                   bottom_right_corner = '─',
                   up_intersection     = '─',
                   left_intersection   = '─',
                   right_intersection  = '─',
                   middle_intersection = '─',
                   bottom_intersection = '─',
                   column              = ' ',
                   row                 = '─',
                   hlines              = [:begin,:header,:end],
                   vlines              = :all);

pretty_table works fine:

a = table((x=collect(1:10), y=collect(11:20)));
pretty_table(a, tf=tf_compact2)
─────────────────
      x       y 
  Int64   Int64 
─────────────────
      1      11
      2      12
      3      13
      4      14
      5      15
      6      16
      7      17
      8      18
      9      19
     10      20
─────────────────

But I wanted to declare this custom tf globally, so this is can be done using @ptconf:

@ptconf tf=tf_compact2
@pt a

which gives me the following error,

UndefVarError: tf_compact2 not defined

Stacktrace:
 [1] top-level scope at In[150]:1
 [2] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091

Built-in tf_compact works though,

@ptconf tf=tf_compact
@pt a
------- -------
      x       y 
  Int64   Int64 
 ------- -------
      1      11
      2      12
      3      13
      4      14
      5      15
      6      16
      7      17
      8      18
      9      19
     10      20
 ------- -------

However, redefining this to new variable, won’t work

tf2 = tf_compact
@ptconf tf=tf2
@pt a
UndefVarError: tf2 not defined

Stacktrace:
 [1] top-level scope at In[153]:1
 [2] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091

I’m beginner on macros.

Hi @alasaadstat,

This is a bug in @ptconf. The macro is being expanded to:

julia> @macroexpand @ptconf tf = tf_compact2
:(PrettyTables.set_pt_conf!(PrettyTables._pt_conf, tf = PrettyTables.tf_compact2))

That’s why you can’t use custom formats. In fact, even custom highlighters will not work. I will try to fix it.

It should be working in master now. Can you please test?

All working now! Thanks!