Force Current Macro Execution while in Edit Mode. Possible?

Hello, I am a pretty heavy user of macros and custom commands and, since “Inline Properties”, I started to make quite heavy use of inline properties, too (I auto-fill those also from custom commands since {{p priority, }} is a lot to write when you want to jot down some text as quick as possible as to not forget your idea.

But, I even find myself needing to use macros inside other macros :see_no_evil: or inside markdown links (i’ll go with this one cause it’s -maybe- easier to understand). So I have this Custom Command that adds a date + timestamp:

:commands [
[ ">>"," [→](.# \" {{today}} {{current-time}}\" " ]
]

and I am using macros to be able to use “dynamic variables” inside Custom Commands.

As you can see, I am adding a right arrow which is a markdown link that has in it a date and a timestamp as the markdown link’s title and I have to leave the syntax incomplete so that the macros inside can execute when I do an Escape to exit Edit Mode, then go back in edit mode (Enter) and add the closing parenthesis (“)”) and go on with adding text. Next time I exit I have the Right Arrow symbol as a Markdown Link, with an embedded Date and Timestamp which I can see while hovering the Link.

This exiting Edit Mode and re-entering Edit Mode is very annoying and I am wondering if there is any possibility to have some javascript that would execute a macro when still in Edit Mode, on demand. The TAB key is not doing anything inside Edit Mode so I was wondering if we can have it do this just like it does some auto-completion in some IDEs or CLIs.

NOTE: I don’t want to simulate exiting the Edit Mode and Re-Entering Edit mode as that would attempt to execute all macros inside the text and bring unexpected results, but only the latest macro relative to the cursor (the cursor might be inside the macro or immediately after the last curly bracket that closes the macro call).

I see these options:

  • Create macros that treat some of their arguments as nested macros.
    • easiest approach to implement in this list
      • easiest doesn’t mean easy
  • Write code that executes macros in a temporary block, then brings the results to the current block.
    • necessary for deeper nesting and one-time scenarios
    • basically a hack for not leaving Edit mode
  • Write your notes in Synthesis, for true nesting of unlimited complexity.
    • most maintainable option
      • probably the only option that other users may find attractive
  • Develop a custom parser that operates in Edit mode.
    • only option to cover your increasing appetite for full-custom edge requirements long-term

I also thought about some sort of embedded temp block (execution block) that can be opened from the existing Edit Mode session so when I press Escape on that one, it executes and pipes its result in the current block while still in Edit Mode. It should also be recursive, so that one can open subsequent temp blocks from inside that one:) . But I just can’t imagine how that can be implemented in my current poition of non-developer.

Synthesis is mentioned a lot in your answers and looks very potent to even replace the other kits and I would be willing and eager to try it but there is little info on how to use it. Since “Inline Properties” became a reality, even in its limited capability (so no complex values unless quoted, no way to call macros inside it, etc) I have just found it to be a “feature” I could hardly live without (besides the Logseq Text Expander - the custom commands- and the macros functionality for dynamic variables).

So now my Data Entry workflow is via:

  1. Text Expander for Custom Block Templates, which right from the start use both macros (to get the current date, current time for example) and the inline properties functionality to both place relevant data in the block’s Title/Body and also in the values of the properties and set stage (prepares the text of the body of the block) so that I can
  2. use Macros (including Inline Properties Macro) to manually fill some of the properties, either at the time of writing or after I finish the data entry, by selecting the text, pressing {{ to enclose the text in macro brackets, then type the name of the macro and the property to add that text to (also done via custom command);

I don’t think this workflow is “edge requirement” as both “Custom Commands”-based Block Templates and Macros and Inline Properties -lately- are quite useful features for any user that wants to make notes quickly and also prepare the note for queries by using relevant properties. But well, I can leave with that designation too :slight_smile:

So far similar workflows have been mentioned by 0.03% of the userbase. That is considered edge.

That’s because it is the answer.

  • But you use kits that:
    • has even less info
      • apart from the javascript part
    • is lower level
  • You even use GPT which is clueless.
  • The above would not work for you without special help from the forum anyway.
  • Not long ago, the above was off-limit to you, along with anything beyond shell.

I don’t see you escaping the next step forward. In Synthesis:

  • the multitude of macros are replaced by very few ones that expect a single argument of arbitrary complexity
  • definitions live inside Logseq pages, instead of in file config.edn
    • Already the case with kits, but additionally supporting context-specific definitions.
      • If you still prefer the simplicity of a single place, just put them all inside page Synthesis/Custom
  • variables can optionally outlive a single macro or a single block
    • To use a variable:
      • instead of typing {{p name}}
      • type something similar to {{s ?name}}
    • To set a variable:
      • instead of typing {{p name value}}
        • here value has to be a limited raw value
          • a dynamic variable at best
      • type something similar to {{s set name value}}
        • here value can be a complicated expression, e.g. {{s set name (...)}}
          • including recursive execution of other code

Anyway, this is the only one of the above approaches that I would consider worthy helping you with. But you should begin with simpler scenarios.

1 Like