11 lines
2.3 KiB
Plaintext
11 lines
2.3 KiB
Plaintext
<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->intern (env, "define-error");
|
||
emacs_value Qxeft_error = env->intern (env, "xeft-error");
|
||
emacs_value Qerror = env->intern (env, "error");
|
||
char **text = "Generic Xeft error";
|
||
emacs_value message = env->make_string (env, text , strlen (text));
|
||
emacs_value args[] = {Qxeft_error, message, Qerror};
|
||
int nargs = 3;
|
||
env->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 can’t say that I’m 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> |