0

What are best practices for handling long string literals in Emacs Lisp?

E.g.

(... stuff that causes indentation ...
                         (error "`my-config-alist' mapped command `%s' to `%S' instead of a major-mode"
                                command mode))
        10        20        30        40        50        60        70        80

I know several workarounds, all of which are awkward and worse for readability than the long line, e.g.

                         (error (concat "`my-config-alist' mapped command `%s' "
                                        "to `%S' instead of a major-mode")
                                command mode))
                         (error "%s%s%s%S%s" 
                                "`my-config-alist' mapped command `" command 
                                "' to `" mode "' instead of a major-mode"))
        10        20        30        40        50        60        70        80

Such situations happen frequently. If this were python, I could use implied string concatenation, such as

blocks that cause indentation:
                                assert mode, f"`config' object mapped command " \
                                             f"{command!r} to {mode!r} instead " \
                                             f"of a major-mode"
        10        20        30        40        50        60        70        80

Is there any accepted best-practice to do this in Emacs-Lisp or other lisps?

NickD
  • 27,023
  • 3
  • 23
  • 42
kdb
  • 1,561
  • 12
  • 21

1 Answers1

1

I don't know a best-practice recommendation. Personally, I use the concat approach. But I have seen also something like this:

(... stuff that causes indentation ...
                         (error "\
`my-config-alist' mapped command `%s' to `%S' instead of a major-mode"
                                command mode))
Michael Albinus
  • 6,647
  • 14
  • 20
  • The `"\` approach would be workable, if it would allow indenting the string... Messing up indentation like this isn't something I'd like to use as a solution. Inconsistent indentation makes file-processing with external scripts really hard. – kdb Feb 17 '21 at 09:37