Search syntax question: showing child items only if it's not folded


#1

This may not actually be possible, but hope springs eternal. Right now I use this search parameter to show me anything tagged with @today

@today/descendant-or-self::* and not @done

Is there a way to phrase that search parameter so anything that’s folded stays folded? As it is, anything that I’ve folded to hide (usually URLs that are ugly and I don’t want to see) unfolds when I do this search. But if I just search @today, I have to unfold anything I actually want to see.

If it’s not possible, no big deal at all — I’m not hiding URLs all that frequently, and re-folding an item is hardly an arduous task — but I wanted to ask in case there is some search syntax I don’t know that will do exactly this.

Thanks!


#2

There’s no way to incorporate folded state into search logic. Search rules at a lower level and doesn’t have access to that state. And generally a big part of search IS to dig into folded item and find what’s there… and then when you cancel the search to restore all those folds.

But for this particular case I think you might be able to get the effect you want by just removing everything that looks like a URL from your results. Maybe something like this?

(@today///* and not @done) except "http://"

If you format your urls regularly (maybe always as notes, or always include some standard tag) then you could make false positives less likely. Also in my example I used ///* as a shortcut for /descendant-or-self::*.


#3

That solution works perfectly for me. Thanks!

ETA: Well, it worked perfectly until I tried to incorporate it into my script so I can have that search linked to a keyboard shortcut. I’m getting this error:

Error on line 16: SyntaxError: Unexpected identifier ‘http’. Expected ‘)’ to end a argument list.

This is the script:

``
(function (strQuery) {
‘use strict’;

function fnSetSearch(editor, options) {
    return editor.itemPathFilter = options.query;
}

var ds = Application("TaskPaper").documents;
return ds.length ? ds[0].evaluate({
    script: fnSetSearch.toString(),
    withOptions: {
        query: strQuery
    }
}) : false;

})("(@today///* and not @done) except “http:”");
``

No matter what I replace “http” with, I kick up that same error. I’m guessing that it has something to do with the quotation marks within quotation marks, but I don’t know how to fix it.


#4

JavaScript allows you to use either pairs of “double quotes” or pairs of ‘single quotes’

“This ‘can’ be ‘very useful’ when you need to ‘nest’”

"(@today///* and not @done) except 'http:'"

#5

Thanks! While putting the single quotes around “http:” didn’t work (it got rid of the error message, but didn’t actually filter out the URLs), putting single quotes around the entire line and putting double quotes around the http did.

'(@tomorrow///* and not @done) except "https:"'


#6

This is because TaskPaper’s search syntax only does " for strings. So many syntaxes :smile:


#7

So many syntaxes :smile:

Which is why I’m so glad this forum exists. Though I am trying to parse things out on my own with the user’s guide, it’s really great to get answers from knowledgable people. :whale:


#8

Also for anyone who (like me) uses URLs, file paths, and email URLs (I’m sure there’s an actual term for that, this search string will filter them all out:

(@today///* and not @done) except "://"