Skip to main content
Tweeted twitter.com/#!/StackMma/status/455710967620718592
added 354 characters in body
Source Link
Stefan
  • 648
  • 3
  • 12

I'm developing a larger package which includes several subpackages. My problem is, that I can't introduce the symbols in the subpackages to the autocompletion by loading the main package, but by calling a subpackage.

Let's explain this with an example: I have a main package, called main which loads the subpackages sub1, sub2 and sub3. The directory should look like

main
├── Kernel
│   └── init.m
├── main.m
├── sub1.m
├── sub2.m
└── sub3.m

The package main loads all three subpackages in its BeginPackage statement, while the package sub1 loads sub2 and sub3. The respective init.m looks like:

Get["main`sub3`"]
Get["main`sub2`"]
Get["main`sub1`"]
Get["main`main`"]

The big problem I have is, that by calling

Needs["main`"]

I can see all symbols in main, but not those in the subpackages (though, they are usable).

By calling

Needs["main`sub1`"]

I can see all symbols in the subpackages without any problems but can't load main anymore, because then some definitions are redone, which leads to error messages about protected symbols. The most interesting thing is, that the $ContextPath includes the subpackages in both cases.

Is there a nice possibility to get the symbols of the subpackages into the autocompletion?


Update: By prepending the path of a subpackage to the $ContextPath, I can load the corresponding symbols of that package into the autocompletion.

$ContextPath = Prepend[$ContextPath, "main`sub1`"]

Unfortunately, this is not very nice and yields duplicates in the $ContextPath.

Is there a better, automatic way to achieve this?

I'm developing a larger package which includes several subpackages. My problem is, that I can't introduce the symbols in the subpackages to the autocompletion by loading the main package, but by calling a subpackage.

Let's explain this with an example: I have a main package, called main which loads the subpackages sub1, sub2 and sub3. The directory should look like

main
├── Kernel
│   └── init.m
├── main.m
├── sub1.m
├── sub2.m
└── sub3.m

The package main loads all three subpackages in its BeginPackage statement, while the package sub1 loads sub2 and sub3. The respective init.m looks like:

Get["main`sub3`"]
Get["main`sub2`"]
Get["main`sub1`"]
Get["main`main`"]

The big problem I have is, that by calling

Needs["main`"]

I can see all symbols in main, but not those in the subpackages (though, they are usable).

By calling

Needs["main`sub1`"]

I can see all symbols in the subpackages without any problems but can't load main anymore, because then some definitions are redone, which leads to error messages about protected symbols. The most interesting thing is, that the $ContextPath includes the subpackages in both cases.

Is there a nice possibility to get the symbols of the subpackages into the autocompletion?

I'm developing a larger package which includes several subpackages. My problem is, that I can't introduce the symbols in the subpackages to the autocompletion by loading the main package, but by calling a subpackage.

Let's explain this with an example: I have a main package, called main which loads the subpackages sub1, sub2 and sub3. The directory should look like

main
├── Kernel
│   └── init.m
├── main.m
├── sub1.m
├── sub2.m
└── sub3.m

The package main loads all three subpackages in its BeginPackage statement, while the package sub1 loads sub2 and sub3. The respective init.m looks like:

Get["main`sub3`"]
Get["main`sub2`"]
Get["main`sub1`"]
Get["main`main`"]

The big problem I have is, that by calling

Needs["main`"]

I can see all symbols in main, but not those in the subpackages (though, they are usable).

By calling

Needs["main`sub1`"]

I can see all symbols in the subpackages without any problems but can't load main anymore, because then some definitions are redone, which leads to error messages about protected symbols. The most interesting thing is, that the $ContextPath includes the subpackages in both cases.

Is there a nice possibility to get the symbols of the subpackages into the autocompletion?


Update: By prepending the path of a subpackage to the $ContextPath, I can load the corresponding symbols of that package into the autocompletion.

$ContextPath = Prepend[$ContextPath, "main`sub1`"]

Unfortunately, this is not very nice and yields duplicates in the $ContextPath.

Is there a better, automatic way to achieve this?

Source Link
Stefan
  • 648
  • 3
  • 12

ContextPath and autocompletion with subpackages

I'm developing a larger package which includes several subpackages. My problem is, that I can't introduce the symbols in the subpackages to the autocompletion by loading the main package, but by calling a subpackage.

Let's explain this with an example: I have a main package, called main which loads the subpackages sub1, sub2 and sub3. The directory should look like

main
├── Kernel
│   └── init.m
├── main.m
├── sub1.m
├── sub2.m
└── sub3.m

The package main loads all three subpackages in its BeginPackage statement, while the package sub1 loads sub2 and sub3. The respective init.m looks like:

Get["main`sub3`"]
Get["main`sub2`"]
Get["main`sub1`"]
Get["main`main`"]

The big problem I have is, that by calling

Needs["main`"]

I can see all symbols in main, but not those in the subpackages (though, they are usable).

By calling

Needs["main`sub1`"]

I can see all symbols in the subpackages without any problems but can't load main anymore, because then some definitions are redone, which leads to error messages about protected symbols. The most interesting thing is, that the $ContextPath includes the subpackages in both cases.

Is there a nice possibility to get the symbols of the subpackages into the autocompletion?