emacs/var/elfeed/db/data/7a/7a0ed32ac551ea6c5ba5e8ce6e525c8675d1d59a
2022-01-03 12:49:32 -06:00

11 lines
2.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>When writing <a class="footref-anchor obviously-a-link" href="https://archive.casouri.cat/note/emacs-feed.xml#footdef%3Axeft" id="footref:xeft">an Emacs dynamic module for Xapian<span class="inline-footref">1</span></a>, I found that calling Lisp functions in dynamic module is painfully verbose. For example, the equivalent of</p><pre class="code-block">(define-error 'xeft-error "Generic Xeft error" 'error)</pre><p>is</p><pre class="code-block">emacs_value Qdefine_error = env-&gt;intern (env, "define-error");
emacs_value Qxeft_error = env-&gt;intern (env, "xeft-error");
emacs_value Qerror = env-&gt;intern (env, "error");
char **text = "Generic Xeft error";
emacs_value message = env-&gt;make_string (env, text , strlen (text));
emacs_value args[] = {Qxeft_error, message, Qerror};
int nargs = 3;
env-&gt;funcall (env, Qdefine_error, nargs, args);</pre><p>Even though we usually only write a little Lisp for defining the exposed functions and errors in a dynamic module, this is too much boilerplate. Naturally I wrote some wrappers. With my wrappers, I can write the following instead:</p><pre class="code-block">emp_funcall (env, "define-error", 3,
emp_intern (env, "xeft-error"),
emp_build_string (env, "Generic Xeft error"),
emp_intern (env, "error"));</pre><p>I put these wrappers together into <code>emacs-module-prelude</code>. Currently it provides these functions:</p><ul><li><code>emp_define_function</code></li><li><code>emp_funcall</code></li><li><code>emp_intern</code></li><li><code>emp_provide</code></li><li><code>emp_signal_message1</code></li><li><code>emp_define_error</code></li><li><code>emp_nilp</code></li><li><code>emp_copy_string_contents</code></li><li><code>emp_build_string</code></li></ul><p>You can find it at <a href="https://archive.casouri.cat/note/2021/emacs-module-prelude/https:/github.com/casouri/emacs-module-prelude"><em>emacs-module-prelude</em></a>. I cant say that Im a seasoned C programmer, corrections are very welcome.</p><div class="footdef" id="footdef:xeft"><div class="def-footref obviously-a-link"><a href="https://archive.casouri.cat/note/emacs-feed.xml#footref%3Axeft">1</a></div><div class="def-footdef">For my note-searching package: <a href="https://archive.casouri.cat/note/2021/emacs-module-prelude/https:/github.com/casouri/xeft">Xeft</a>.</div></div>