Macros and Commands - let's share

are you looking for templates ? what are you trying to achieve with macros ?
https://docs.logseq.com/#/page/templates

:editor/input will write the string to the block
:backward-pos is a way to move the caret x characters backwards to wait for user input at the correct location once a macros has been entered, I don’t have links to docs, but you should into the examples in config.edn

Hi Cannibalox, thank you for your answer.
I was thinking about an easier method of writing question-answer LogSeq flashcards.

I was wondering if macros could be used to do something like:

  1. Type the following in a LogSeq block: {{makecard question answer}}

  2. Press enter

  3. Have the macro to expand into the following:
    image

I’m aware of templates but they don’t seem to accept arguments (i.e. I can’t input “quesiton” nor “answer” to a template), if they did they would be perfect for this I think.

Do you think I can somehow use :editor/new-block in a macro to achieve this?

1 Like

afaik, you can’t create flashcards using macros (not sure we can create sub bullet via macros, and I’m not a flashcards user myself).
that said, I would recommend a text expander like Espanso, Autohotkey or fastkeys… although not dedicated to logseq, these tools work great in conjunction with logseq (you can search the discord for scripts or use-cases examples).
alternatively, you can try logseq plugins like : Smart Blocks, Power Blocks or Full House Templates that should theorically achieve what you want.

1 Like

Hi all, thanks for these macros, pretty interesting. Have any of you figured out a way to produce a macro which turns dynamic variables into strings? My goal is to build a template that creates a series of pages based on the page the template is currently built on. Thanks!

You totally can achieve this with 🏛 Full House Templates plugin

Demo

2023-09-06 12.46.23

@jpb Probably your task could be solved with my plugin too. But I need more details to be sure.

1 Like

Hi, you might want to look into this:

If I am not mistaken, you can have exactly what you want → turn dynamic variables into editable strings, stripping the “dynamic” from the Macro with @mentaloid’s code here;

1 Like

RIght on the money, thanks

1 Like

Where did you learn about :editor/input and :backward-pos ?

It really helps with even simpler things like:

:commands [
        ["macro" [[:editor/input "{{}}" {:backward-pos 2}]]]
      
 :macros {
        "t" "<%time%> "
        "ramen" "<%time%> Ate 🍜"}

or just

:commands [
        ["ramen" "{{ramen}}"]]

Hi All,

where can I find documentation to learn how to use commands and macros in the config.edn file?

thanks

1 Like

I use this to emulate missing checkbox support.

:macros {
   "cx" "[:input {:type \"checkbox\" :checked :1}]"
   "c" "[:input {:type \"checkbox\"}]"
 }

There is a section that covers Macros briefly, referenced in the Templates page listed in docs.logseq.com. I have not seen anything on how to build custom commands in the official docs. But I do not fully grasp their usefulness over templates. They cannot have Dynamic variables like %time% can they? And they are limited to one block without properties only.

They differ from Templates in that they are defined in config.edn. As are Macros. Templates are or can be defined in a page.

I imagine that command/macros could have the benefit to be faster to call with few types. instead of /template and then template name.
Do you know any solution to call the template faster?

Try 🏛 Full House Templates plugin.

  1. It allows you to insert templates faster via UI with fuzzy search:
    ⌘T → s → ↩︎ (x3 key presses, but depends on all templates list)
    2023-11-17 03.54.54

  2. And it allows you to render frequently used templates by creating a :command:

     :commands
     [
     	["psy client session                                             [.]"
             [[:editor/input "{{renderer :template, psy → session, :page [[клиент ]], :online}}" {:backward-pos 13}]] ],
     ]
    

    /. → ↩︎ (x3 key presses)
    2023-11-17 03.43.35

2 Likes

@stdword how ti use the full house template plugin?
Currently I have a template for meeting and I would like to have a shortcut to create it. How to do it?
Is there a more exhaustive stent step guide?
Thanks

  1. Assumption: Full House Templates plugin is already installed.
  2. Open Settings (t s shortcut)
  3. Press «Edit config.edn» button
  4. Find line with :commands:

    Note: it is not line #9 by default
  5. Add this code to :commands (between [ and ]):
     ["YOUR-COMMAND-NAME                                             [CHARACTER]"
          [[:editor/input "{{renderer :template, YOUR-TEMPLATE-NAME}}" {:backward-pos 2}]] ],
    
  6. Replace YOUR-COMMAND-NAME, YOUR-TEMPLATE-NAME and CHARACTER with your values. CHARACTER can be any punctuation sign.
  7. If you have only one command in config, it would look like that (example provided for my template):
  8. Reload Logseq. It is necessary step before command usage.
  9. Start editing any block and type in «/» to open «/»-commands menu:
  10. Type in your CHARACTER or YOUR-COMMAND-NAME:
  11. Press Enter on selected command. Then exit editing block (via Esc or Enter or mouse click on another block) to render the template.
  12. PROFIT
1 Like

Thanks. I see that in your example you add also pages and r other “dynamic variable” this to do that?

Templates in Full House Templates can be rendered with arguments. The :page and :online is an arguments for my template. See documentation here.

For simple templates you don’t need arguments.

1 Like

I start to use today. Is crazy cool.
Much easier to input template even only with ctrl T.
Thanks!!!

1 Like

I created a macro like this:

:macros {
“prop” “tags:: CSS property”

      }

But it doesn’t tag the block when I use it.
Am I doing something wrong or macros can’t be used with properties?

Thanks!

1 Like