radian-software/el-patch

How to patch vector literal given with backticks

legendre6891 opened this issue · 2 comments

Thanks for the great package, Radon!

I'm having a bit of trouble figuring out how to patch the following defconst found in flycheck.

(defconst flycheck-error-list-format
  `[("File" 6)
    ("Line" 5 flycheck-error-list-entry-< :right-align t)
    ("Col" 3 nil :right-align t)
    ("Level" 8 flycheck-error-list-entry-level-<)
    ("ID" 6 t)
    (,(flycheck-error-list-make-last-column "Message" 'Checker) 0 t)]
  "Table format for the error list.")

Here is a reproducible example

(use-package el-patch
  :demand t
  :straight t)

(use-package flycheck
  :straight t)

(el-patch-feature flycheck)
(with-eval-after-load 'flycheck
  (el-patch-defconst flycheck-error-list-format
    `[("File" 6)
      ("Line" 5 flycheck-error-list-entry-< :right-align t)
      ("Col" 3 nil :right-align t)
      ("Level" 8 flycheck-error-list-entry-level-<)
      ("ID" (el-patch-swap 6 20) t)
      (,(flycheck-error-list-make-last-column "Message" 'Checker) 0 t)]
    "Table format for the error list."))

Unfortunately, I just can't figure out the right combination of backticks to use to make the patch validate. I believe there is an incompatibility with nested backticks? For example,

(with-eval-after-load 'flycheck
  (el-patch-defconst flycheck-error-list-format
    `[("File" 6)
      ("Line" 5 flycheck-error-list-entry-< :right-align t)
      ("Col" 3 nil :right-align t)
      ("Level" 8 flycheck-error-list-entry-level-<)
      ("ID" ,(el-patch-swap 6 20) t)
      (,(flycheck-error-list-make-last-column "Message" 'Checker) 0 t)]
    "Table format for the error list."))

throws an error Debugger entered--Lisp error: (error "Can’t use ‘el-patch-swap’ outside of an ‘el-patch’"). Is there an actual bug or am I misunderstanding?

Thanks for the report. This should be fixed now. (The problem was the vector literal, not the backticks.)

Thanks for the fix — works beautifully! (Thanks for the pointer also; I’m learning a lot about Elisp and general software development guidance from reading your code.)