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?

1 Answer 1

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))
1
  • 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, 2021 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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