jesterKing / literate

Literate Programming extension for VS Code
https://jesterking.github.io/literate
MIT License
8 stars 4 forks source link

Handling of output code files #34

Closed RossBoylan closed 10 months ago

RossBoylan commented 10 months ago

As I type in the name of an output file in the code fence, files are created as I go, including spelling errors that I later correct. Here's one example of the result:

   Directory: J:\source\repos\mccli\bin

Mode                LastWriteTime         Length Name                                                                                                        
----                -------------         ------ ----                                                                                                        
d-----        12/5/2023   4:20 PM                js                                                                                                          
d-----       11/27/2023   1:46 PM                python                                                                                                      
-a----        6/29/2023   1:15 PM           2542 input_data.json                                                                                             
-a----        12/5/2023   4:20 PM            135 jsv4-csvconfig.js                                                                                           
-a----       11/14/2022  11:34 PM           1817 mc.js                                                                                                       
-a----         2/2/2022   3:31 PM           1113 t1a.js                                                                                                      
-a----        7/14/2022   2:22 PM           2409 t1b.js                                                                                                      
-a----        12/5/2023   3:38 PM              0 v                                                                                                           
-a----        12/5/2023   3:38 PM              0 v4                                                                                                          
-a----        12/5/2023   3:38 PM              0 v4-                                                                                                         
-a----        12/5/2023   3:38 PM              0 v4-c                                                                                                        
-a----        12/5/2023   3:38 PM              0 v4-cs                                                                                                       
-a----        12/5/2023   3:38 PM              0 v4-csv                                                                                                      
-a----        12/5/2023   3:38 PM              0 v4-csvcon                                                                                                   
-a----        12/5/2023   3:38 PM              0 v4-csvconf                                                                                                  
-a----        12/5/2023   3:38 PM              0 v4-csvconfi                                                                                                 
-a----        12/5/2023   3:38 PM              0 v4-csvconfig                                                                                                
-a----        12/5/2023   3:38 PM              0 v4-csvconfig.                                                                                               
-a----        12/5/2023   4:04 PM            135 v4-csvconfig.js                                                                                             
-a----        12/5/2023   3:38 PM              0 v4-csvconn                                                                                                  
-a----        12/5/2023   3:38 PM              0 v4-csvconnfi                                                                                                
-a----        12/5/2023   3:38 PM              0 v4-csvconnfig 

The file starting with jsv4 and all the ones starting with v are from typing in the code fence. By the way, that was all from before I realized I was using the wrong directory, and so none of the files "should" be there, in the sense that given my current input file they would not be created.

It's not obvious to me how to fix this. Some possibilities:

  1. Don't generate anything until the code block has some real content. Works at the start, but not after.
  2. Require some period (5s?) of keyboard inactivity before considering the entry complete. Maybe one of the solutions here. Like 1, seems likely to reduce the clutter without completely eliminating it.
  3. Track previous file names generated for a fragment and clean them up if the name changes.
  4. Use a manual-only update scheme.

I think a user work-around would be to avoid typing the : until the rest of the line is done. Even if it works, it's awkward.

jesterKing commented 10 months ago

Perhaps we can introduce a filename terminating token. As long as that token doesn't exist the filename isn't created yet.

I propose whitespace followed by dollar sign

```py : <<snippet.*>>= ./filename.py $
# code here