2

I can bind the listing-insert command to create a program listing (a.k.a a code-formatted block) inset in LyX, but that will make it a display style program listing. If I want an inline style program listing, I need to manually open the settings, tick the Inline listing checkbox, and click OK.

Is there a way to automate this with a keymap, so I can quickly write inline code fragments? I tried looking at the LyX function list, but all I could see is inset-settings that opens the dialog (so I still need to manually tick the checkbox and hit OK)

Update: I just noticed inset-apply and inset-modify which I think may help, but I can't figure out how to use them and can't find info in Google...

3

1 Answer 1

1

I followed @scottkosty's answer in tha other question, and found that when I do it manually LyX is first opening the dialog with inset-settings and then sets it to inline with inset-apply listings true 1 "". So I tried this command:

command-sequence listing-insert; inset-settings; inset-apply listings true 1

And it indeed opened the settings dialog and converted the program listings' style to inline - but it did not close the dialog... And if I removed inset-settings the inset-apply wouldn't work.

Luckily, I found in the function list help file inset-modify which apparently works like inset-apply but does not need the settings panel open. So this worked:

command-sequence listing-insert; inset-modify listings true 1 ""

I also noticed that it only needs the first argument, so my final command is:

command-sequence listing-insert; inset-modify listings true
3
  • Does not work any more with LyX 2.3 but I found the following fix, command-sequence listing-insert; char-left; char-left; inset-modify listings true 1 "" - the "char-left" are necessary because the cursor is not within the inset, so "inset-modify" is disabled.
    – winitzki
    Apr 12, 2019 at 3:41
  • 2
    What works best is the inset-modify twice; first before moving the cursor, then after. command-sequence listing-insert; inset-modify listings true 1 ""; char-left; char-left; inset-modify listings true 1 "" In this way, the inset is created correctly even when you first select some text and then use the keyboard shortcut.
    – winitzki
    Apr 12, 2019 at 6:08
  • Better yet, add two char-right at the end to support adding empty listing as well: command-sequence listing-insert; inset-modify listings true 1 ""; char-left; char-left; inset-modify listings true 1 ""; char-right; char-right;
    – Gur Telem
    Apr 26, 2021 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.