feynman/src/feynman.c

84 lines
2.5 KiB
C

/*
* Feynman -- Wayland compositor for GNU Emacs
*
* Copyright (c) 2022 Sameer Rahmani <lxsameer@gnu.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 2.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "export.h"
#include <emacs-module.h>
/* Declare mandatory GPL symbol. */
FEYNMAN_EXPORT int plugin_is_GPL_compatible = 0;
/* New emacs lisp function. All function exposed to Emacs must have this
* prototype. */
static emacs_value
feynman_init (emacs_env *env, ptrdiff_t nargs, emacs_value args[], void *data)
{
(void)nargs;
(void)args;
(void)data;
return env->make_integer (env, 42);
}
/* Bind NAME to FUN. */
static void
bind_function (emacs_env *env, const char *name, emacs_value Sfun)
{
/* Set the function cell of the symbol named NAME to SFUN using
the 'fset' function. */
/* Convert the strings to symbols by interning them */
emacs_value Qfset = env->intern (env, "fset");
emacs_value Qsym = env->intern (env, name);
/* Prepare the arguments array */
emacs_value args[] = { Qsym, Sfun };
/* Make the call (2 == nb of arguments) */
env->funcall (env, Qfset, 2, args);
}
/* Provide FEATURE to Emacs. */
static void
provide (emacs_env *env, const char *feature)
{
/* call 'provide' with FEATURE converted to a symbol */
emacs_value Qfeat = env->intern (env, feature);
emacs_value Qprovide = env->intern (env, "provide");
emacs_value args[] = { Qfeat };
env->funcall (env, Qprovide, 1, args);
}
FEYNMAN_EXPORT int
emacs_module_init (struct emacs_runtime *ert)
{
emacs_env *env = ert->get_environment (ert);
/* create a lambda (returns an emacs_value) */
emacs_value fun = env->make_function (
env, 0, /* min. number of arguments */
0, /* max. number of arguments */
feynman_init, /* actual function pointer */
"Initialize the compositor", /* docstring */
NULL /* user pointer of your choice (data param in feynman_init) */
);
bind_function (env, "feynman/init", fun);
provide (env, "feynman");
return 0;
}