I was working on ox-gemini, a gemini exporter for org-mode documents. In the
latest versions of emacs, string-replace is a function which replaces a word
in a string. It doesn’t exist in emacs 27.2 and earlier, so I added a simple
shim.
;; backport for older emacs verisons
(if (not (fboundp 'string-replace))
(defun string-replace (from to in)
(replace-regexp-in-string (regexp-quote from) to in nil 'literal)))
The shim says “If you don’t see a string-replace function, use this one). Unfortunately, this left me with this compilation error:
In toplevel form:
ox-gemini.el:286:1:Error: the function ‘string-replace’ is not known to be defined.
Makefile:5: recipe for target 'compile' failed
The solution to this is to use declare-function to say where emacs should be
able to find the function. This is effectively a way to say “Emacs.. trust me..
it’s around here somewhere” and squelches the error.
Here’s the final code snippet.
;; backport for older emacs verisons
(if (not (fboundp 'string-replace))
(progn
(defun string-replace (from to in)
(replace-regexp-in-string (regexp-quote from) to in nil 'literal))
(declare-function string-replace "ox-gemini")
))