Create child node from the selected body text.
\s*def\s+(\w+)
\s*class\s+(\w+)
i.e. the name I want to use for the node, `goTo`, is on the *second*
line. Just glanced and the code and see only the first line of the
selection is passed to the pattern matching....
Looks like (?ms) in a regex will put re into multi-line dot matches all
mode, I guess just (?m) would be sufficient, so I *think* passing the
whole selection to extractDef() and letting people set (?m) in their
patterns would be sufficient and more importantly backwards compatible?
On Sat, Sep 16, 2017 at 3:50 AM, vitalije <vita...@gmail.com> wrote:Many thanks for this work. Rev 449d675 revises the docstring for the extract command. As I write this, I see that the docstring should mention the new @data node.
Hmm, some unforeseen challenges.
In rev:df3d88bb1, I have added one simple method to try each of selected lines in sequence. First line that matches will win. That will cover I believe most cases like nested definitions, python decorators and such. However, it will be broken if the last pattern matches always.
The rev:df3d88bb1 will successfully extract the example code Terry has given.
I hope Edward, you won't consider this solution overly complicated :-)
What remains to be done, is writing some test cases to check and verify expected behavior of this command.
If we bump later on some corner cases those cases should be added to these tests.
Finally, the user can always changed the newly-created node by hand, using all of her natural pattern-matching abilities ;-)What do you think?Edward
I don't know if anyone else was using this command very often. I know that I had written a private plugin whose sole purpose was to patch commander with the new definition of extractDef. It was long time ago before I got commit access to Leo repository, so it was the only way for me to change Leo code.
When importing and analyzing code written in coffeescript, javascript or clojurescript, this command was tremendously helpful (in patched version) and totally useless in its original version. That made me wander if there is anyone else there who uses this command at all. Of course, it was designed to work with python definitions, but surely there are users who use Leo for writing code in other languages as well. My conclusion was that most probably those users haven't been using extract command at all. How else could it be possible that nobody ever complained about its shortcomings before?
This is how I use the extract command when importing foreign code. Usually I open source file with the '@edit` node. It places the whole code in one large body. Then I try to find the largest blocks of code (classes, exports objects,...). Reading from the top of the file, whenever I find the beginning of a block (class definition, or very often comment line that announces a block of correlated classes/functions), I search for the beginning of next such block. When I find the next block (or the end of file if it is the last block), I select all lines from current position up to the beginning of the block and execute extract command (Ctrl+Shift+d). That gives me a few nodes smaller than the original one. In each of them I look for smaller blocks like methods or functions and repeat the process with those blocks. I add '@others' where necessary in parent nodes. And so I repeat this process until I have chunked all code into small enough nodes. The alternative would be to use '@auto' import for a source file, but I was never truly satisfied with the results at least not for coffeescript, javascript and clojurescript files. That is why I find the extract command so useful to me. If you have never heard of extract command or you have tried it before and weren't satisfied with what it did, now is the time to give it a try.
Vitalije
In rev:df3d88bb1, I have added one simple method to try each of selected lines in sequence. First line that matches will win. That will cover I believe most cases like nested definitions, python decorators and such. However, it will be broken if the last pattern matches always.
The rev:df3d88bb1 will successfully extract the example code Terry has given.
Finally, the user can always changed the newly-created node by hand, using all of her natural pattern-matching abilities ;-)
It is more trouble than that. If extractDef doesn't find headline, it strips the first line from the selection and uses it as headline. In effect it deletes the first line of selected code and it can be frustrating for the user. If it however, finds a match even a wrong one, it will keep all selected lines intact and the only a headline can possibly be wrong.
I don't know if anyone else was using this command very often. I know that I had written a private plugin whose sole purpose was to patch commander with the new definition of extractDef. It was long time ago before I got commit access to Leo repository, so it was the only way for me to change Leo code.
When importing and analyzing code written in coffeescript, javascript or clojurescript, this command was tremendously helpful (in patched version) and totally useless in its original version. That made me wander if there is anyone else there who uses this command at all.
Of course, it was designed to work with python definitions, but surely there are users who use Leo for writing code in other languages as well. My conclusion was that most probably those users haven't been using extract command at all. How else could it be possible that nobody ever complained about its shortcomings before?
This is how I use the extract command when importing foreign code. Usually I open source file with the '@edit` node. It places the whole code in one large body. Then I try to find the largest blocks of code (classes, exports objects,...). Reading from the top of the file, whenever I find the beginning of a block (class definition, or very often comment line that announces a block of correlated classes/functions), I search for the beginning of next such block. When I find the next block (or the end of file if it is the last block), I select all lines from current position up to the beginning of the block and execute extract command (Ctrl+Shift+d).
That gives me a few nodes smaller than the original one. In each of them I look for smaller blocks like methods or functions and repeat the process with those blocks. I add '@others' where necessary in parent nodes. And so I repeat this process until I have chunked all code into small enough nodes. The alternative would be to use '@auto' import for a source file, but I was never truly satisfied with the results at least not for coffeescript, javascript and clojurescript files. That is why I find the extract command so useful to me. If you have never heard of extract command or you have tried it before and weren't satisfied with what it did, now is the time to give it a try.
Have you tried parse-body? It uses Leo's importer code for the @language in effect, if one exists. See the node "ic.parse_body & helper". This should save you lots of work for the
Have you tried parse-body? It uses Leo's importer code for the @language in effect, if one exists. See the node "ic.parse_body & helper". This should save you lots of work for theI wasn't aware of this command. I will definitely try it. It is just another example how many cool things there are in Leo which even after 10+ years of using Leo one can easily miss.
Having said that, one editor feature came in to my mind. One of the editors that I used before (not sure which one), had this feature: to show tips on usage on start-up. Every time it starts it would greet a user with a window with something like: "Did you know that you can use ... to achieve ...." along with link to the page in documentation explaining further this feature. I remember discovering some very useful features that way. I suppose it wouldn't be too complicated to make such feature in Leo, but those short tips are to be written and collected first.
--
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 leo-editor+unsubscribe@googlegroups.com.
To post to this group, send email to leo-e...@googlegroups.com.
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.
--
I don't see an importer for clojurescript, but it probably would not be too difficult to create it.