Change the coding style to GNU

This commit is contained in:
Sameer Rahmani 2022-08-07 11:06:50 +01:00
parent 5d108d7f95
commit 61764bc1f5
3 changed files with 77 additions and 18 deletions

20
.clang-format Normal file
View File

@ -0,0 +1,20 @@
---
# Global Options Go Here
IndentWidth: 2
ColumnLimit: 100
---
Language: Cpp
BasedOnStyle: GNU
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlignConsecutiveMacros: true
ForEachMacros: []
IndentWidth: 2
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveBitFields: Consecutive
AlignEscapedNewlines: Left
AlwaysBreakTemplateDeclarations: Yes
IncludeBlocks: Regroup
SortIncludes: true
SortUsingDeclarations: true
...

31
.pre-commit-config.yaml Normal file
View File

@ -0,0 +1,31 @@
# Apply to all files without commiting:
# pre-commit run --all-files
# Update this file:
# pre-commit autoupdate
fail_fast: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
hooks:
- id: check-added-large-files
- id: check-symlinks
- id: check-byte-order-marker
- id: check-case-conflict
- id: check-docstring-first
- id: check-executables-have-shebangs
- id: forbid-new-submodules
- id: end-of-file-fixer
- id: trailing-whitespace
- id: mixed-line-ending
- repo: https://github.com/pocc/pre-commit-hooks
rev: v1.3.5
hooks:
- id: clang-format
- id: cppcheck
args: ['--project=compile_commands.json']
- repo: https://github.com/detailyang/pre-commit-shell
rev: 1.0.5
hooks:
- id: shell-lint
args: ['-x']

View File

@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "export.h"
#include <emacs-module.h>
/* Declare mandatory GPL symbol. */
@ -23,45 +24,52 @@ 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) {
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);
return env->make_integer (env, 42);
}
/* Bind NAME to FUN. */
static void bind_function(emacs_env *env, const char *name, emacs_value Sfun) {
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);
emacs_value Qfset = env->intern (env, "fset");
emacs_value Qsym = env->intern (env, name);
/* Prepare the arguments array */
emacs_value args[] = {Qsym, Sfun};
emacs_value args[] = { Qsym, Sfun };
/* Make the call (2 == nb of arguments) */
env->funcall(env, Qfset, 2, args);
env->funcall (env, Qfset, 2, args);
}
/* Provide FEATURE to Emacs. */
static void provide(emacs_env *env, const char *feature) {
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};
emacs_value Qfeat = env->intern (env, feature);
emacs_value Qprovide = env->intern (env, "provide");
emacs_value args[] = { Qfeat };
env->funcall(env, Qprovide, 1, args);
env->funcall (env, Qprovide, 1, args);
}
FEYNMAN_EXPORT int emacs_module_init(struct emacs_runtime *ert) {
emacs_env *env = ert->get_environment(ert);
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(
emacs_value fun = env->make_function (
env, 0, /* min. number of arguments */
0, /* max. number of arguments */
feynman_init, /* actual function pointer */
@ -69,7 +77,7 @@ FEYNMAN_EXPORT int emacs_module_init(struct emacs_runtime *ert) {
NULL /* user pointer of your choice (data param in feynman_init) */
);
bind_function(env, "feynman/init", fun);
provide(env, "feynman");
bind_function (env, "feynman/init", fun);
provide (env, "feynman");
return 0;
}