A macro for Jesse Grosjean's Bike Outliner.
Material that I paste into Bike sometimes comes with more empty lines than I want.
This macro prunes out lines that are both empty and childless (i.e. have no material indented under them).
If the selection is extended in the Bike front document, this macro affects only selected lines.
Otherwise, if the selection is collapsed, childless gaps are pruned from all visible rows in the document.
BIKE – Remove childless empty rows from outline.kmmacros (26 KB)
Expand disclosure triangle to view JS source
(() => {
"use strict";
// Delete childless empty rows in the visible part of
// the front document.
//
// If the selection is extended,
// then only childless gaps in *selected* rows
// are removed.
//
// Otherwise, *all* childless empty rows in any visible
// part of the document are pruned out.
// Reversible with ⌘Z
// Rob Trew @2022
// Ver 0.04
// const main :: IO ()
const main = () => {
const
bike = Application("Bike"),
doc = bike.documents.at(0);
return doc.exists() ? (() => {
const
selectionExtended = Boolean(
doc.selectedText()
),
childlessEmptyRows = doc.rows.where((
selectionExtended ? (
inSelection
) : (x => x)
)({
_and: [
{visible: true},
{name: ""},
{containsRows: false}
]
})),
n = childlessEmptyRows.length;
return (
// Effect
bike.delete(childlessEmptyRows),
// Value (message string)
[
[`Deleted ${n} empty rows in`],
selectionExtended ? (
["extended selection of "]
) : [],
[`document: "${doc.name()}"`],
0 < n ? ["(⌘Z to undo)"] : []
]
.flat()
.join("\n")
);
})() : "No documents open in Bike";
};
// inSelecton :: Dict -> Dict
const inSelection = match =>
// JXA Where/Whose condition for Bike Rows
// further restricted to selected rows only.
({
_and: [
{selected: true},
match
]
});
// MAIN ---
return main();
})();