Hi Edward, As there is no ready Python-Auto-Import solution yet in Leo -- I will try to develop one myself. I am new to Leo, I would appreciate help in choosing the right design and APIs.
But first: Why are automatic imports important for me? For me, editing import statements whenever a new dependency is added to a module is a "deep interruption" of my work flow. I really just want to use a function --- but I have to (1) remember or research where exactly that function was defined. I have to (2) jump to a different location to edit the import statement and I have to (3) jump back to the place where I was working. In the preferred Leo style, step (2) becomes more difficult: I usually will edit cloned nodes and finding the corresponding Declaration nodes is more involved than scrolling up to the top of the file. The bottom line of the interruption --- I lost the momentum of the thought of just using that function. I have used an automatic import feature with PyCharm for a while and it made a real impact on my work. But I don't want to copy the user experience from PyCharm. I want something simpler and more aligned with my work flow. Here is my initial design sketch: (1) All information about importable names must be unambiguously in the titles of the project outline: * Local features (functions and classes defined in this project) are already exposed as nodes below @clear. * Each external dependency (e.g. `from docutils.nodes import field`) must be declared as one node title for the whole project. * There will be a scan of the whole outline to create an `import_dict` mapping symbol names to their import sources. (2) External files with python-auto-import semantics would be explicitly defined (e.g. with @auto-import similar to @others or with @python-src instead of @clear). When saving such a file, we want to: * Expand the body of the file (without any automatic `import` statements). * Extract undefined symbols from this collected source (per file). * Translate these symbols into import statements (using `import_dict` from above) and prepend them to the code. * When loading the external file from disk -- recognize the initial header of import statements and ignore them. (3) There are some special cases (e.g. related to circular imports) that need special attention. I believe the programmer should explicitly resolve these (rare) cases rather than making the automatic import more complex and more fragile by adding automatic special cases. Can you advise about the best way to hook into the creation of external files and into the reading to accomplish these modifications? Yaakov -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/leo-editor/CAHWiE3Ui_URRBZX_bTO34hgJ-fXdqyHwSWBzoT2hUuHTZW8dAA%40mail.gmail.com.
