Action

Move done tasks to end

Last update over 6 years ago

MARKDOWN OR TASKPAPER
Move either:
- lines containing a completed markdown task (“- [x]”) , or
- lines containing a @done tag,
to the bottom of the current draft.

Steps

  • script

    // Completed items moved to bottom of draft
    (() => {
    
       // main :: () -> IO Bool
       const main = () => {
    
           // completedItemsToEnd :: Draft -> String
           const completedItemsToEnd = d =>
               concat( // Two lists rejoined,
                   partition( // after partition.
                       d.languageGrammar === 'Taskpaper' ? (
                           x => !x.includes('@done')
                       ) : x => !/^\s*-\s*\[[x\-\*\+]\]/.exec(x),
                       d.content.split('\n')
                   )
               ).join('\n');
    
           draft.content = (
               completedItemsToEnd(draft)
           );
           draft.update();
    
           console.log(true);
           return true;
       };
    
       // General reusable helper functions ------------------
    
       // concat :: [[a]] -> [a]
       // concat :: [String] -> String
       const concat = xs =>
           xs.length > 0 ? (() => {
               const unit = typeof xs[0] === 'string' ? '' : [];
               return unit.concat.apply(unit, xs);
           })() : [];
    
       // partition :: Predicate -> List -> (Matches, nonMatches)
       // partition :: (a -> Bool) -> [a] -> ([a], [a])
       const partition = (p, xs) =>
           xs.reduce(
               (a, x) =>
               p(x) ? (
                   [a[0].concat(x), a[1]]
               ) : [a[0], a[1].concat(x)], [
                   [],
                   []
               ]
           );
    
       // MAIN -----------------------------------------------
       return main();
    })()
    

Options

  • After Success Default
    Notification Error
    Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.