diff options
| author | bh <qn+git@excalibur.computer> | 2025-11-13 19:55:39 +0800 |
|---|---|---|
| committer | bh <qn+git@excalibur.computer> | 2025-11-13 19:55:39 +0800 |
| commit | 1afa56764aaddbbc4253c8e61086aedec2340efd (patch) | |
| tree | c66c56f2b66f77031566904e9f93e648b17e61bb /lua | |
| parent | cfaa4eb06d8353288aa19238c6519a29a9df5d75 (diff) | |
LuaSnips Stuff
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/config/luasnip.lua (renamed from lua/config/luasnips.lua) | 1 | ||||
| -rw-r--r-- | lua/plugins/init.lua | 50 | ||||
| -rw-r--r-- | lua/plugins/test.c | 114 |
3 files changed, 151 insertions, 14 deletions
diff --git a/lua/config/luasnips.lua b/lua/config/luasnip.lua index 22fc94f..f3b39b4 100644 --- a/lua/config/luasnips.lua +++ b/lua/config/luasnip.lua @@ -18,4 +18,3 @@ return function() -- Optionally, load snippets here if you have them -- require("luasnip.loaders.from_vscode").lazy_load() end - diff --git a/lua/plugins/init.lua b/lua/plugins/init.lua index 0f8fad0..f66d9c6 100644 --- a/lua/plugins/init.lua +++ b/lua/plugins/init.lua @@ -8,6 +8,49 @@ return { end, }, + -- TreeSitter + {"nvim-treesitter/nvim-treesitter", branch = 'master', lazy = false, build = ":TSUpdate", + config = function() + require("config.treesitter")() + end,}, + {"nvim-treesitter/nvim-treesitter-textobjects", lazy = false, }, + + -- Autopairs + { + 'windwp/nvim-autopairs', + event = "InsertEnter", + config = true + -- use opts = {} for passing setup options + -- this is equivalent to setup({}) function + }, + + { + "kylechui/nvim-surround", + version = "^3.0.0", -- Use for stability; omit to use `main` branch for the latest features + event = "VeryLazy", + config = function() + require("nvim-surround").setup({ + -- Configuration here, or leave empty to use defaults + }) + end + }, + + + -- Autocompletion + { "hrsh7th/nvim-cmp" }, + { "hrsh7th/cmp-nvim-lsp" }, + + -- Snippets + { + "L3MON4D3/LuaSnip", + -- follow latest release. + version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release) + -- install jsregexp (optional!). + build = "make install_jsregexp", + config = function() + require("config.luasnip")() + end, + }, -- File Explorer { "nvim-tree/nvim-tree.lua", config = require("config.tree") }, @@ -33,13 +76,6 @@ return { -- LaTeX { "lervag/vimtex", ft = "tex", config = require("config.vimtex") }, - -- Autocompletion - { "hrsh7th/nvim-cmp" }, - { "hrsh7th/cmp-nvim-lsp" }, - - -- Snippets - { "L3MON4D3/LuaSnip" }, - -- Grammar & Spell Checking { "rhysd/vim-grammarous", ft = "tex" }, diff --git a/lua/plugins/test.c b/lua/plugins/test.c index 57028aa..bdba367 100644 --- a/lua/plugins/test.c +++ b/lua/plugins/test.c @@ -1,12 +1,114 @@ #include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdbool.h> -int main() -{ - int x = 5; - printf("Hello World!\n"); +#define MAX_NAME_LEN 50 +#define ARRAY_SIZE 5 - while(1){ - printf("Hello World!\n"); +typedef enum { + STUDENT, + TEACHER, + STAFF +} Role; + +typedef struct { + char name[MAX_NAME_LEN]; + int age; + Role role; + float grades[ARRAY_SIZE]; +} Person; + +// Function declarations +void print_person(const Person* p); +float average_grade(const Person* p); +Person* create_person(const char* name, int age, Role role); +void fill_random_grades(Person* p); +void print_all(Person** people, int count); +void free_all(Person** people, int count); +int find_oldest(Person** people, int count); + +int main() { + Person* people[ARRAY_SIZE]; + + people[0] = create_person("Alice", 20, STUDENT); + people[1] = create_person("Bob", 35, TEACHER); + people[2] = create_person("Charlie", 28, STAFF); + people[3] = create_person("Diana", 22, STUDENT); + people[4] = create_person("Ethan", 40, TEACHER); + + for (int i = 0; i < ARRAY_SIZE; i++) { + fill_random_grades(people[i]); } + print_all(people, ARRAY_SIZE); + + int oldest_index = find_oldest(people, ARRAY_SIZE); + printf("\nOldest person is: %s, Age: %d\n", people[oldest_index]->name, people[oldest_index]->age); + + free_all(people, ARRAY_SIZE); + + return 0; } + +void print_person(const Person* p) { + const char* role_names[] = {"Student", "Teacher", "Staff"}; + printf("Name: %s\n", p->name); + printf("Age: %d\n", p->age); + printf("Role: %s\n", role_names[p->role]); + printf("Grades: "); + for (int i = 0; i < ARRAY_SIZE; i++) { + printf("%.2f ", p->grades[i]); + } + printf("\nAverage Grade: %.2f\n\n", average_grade(p)); +} + +float average_grade(const Person* p) { + float sum = 0; + for (int i = 0; i < ARRAY_SIZE; i++) { + sum += p->grades[i]; + } + return sum / ARRAY_SIZE; +} + +Person* create_person(const char* name, int age, Role role) { + Person* p = (Person*)malloc(sizeof(Person)); + if (!p) { + fprintf(stderr, "Memory allocation failed\n"); + exit(1); + } + strncpy(p->name, name, MAX_NAME_LEN); + p->age = age; + p->role = role; + memset(p->grades, 0, sizeof(p->grades)); + return p; +} + +void fill_random_grades(Person* p) { + for (int i = 0; i < ARRAY_SIZE; i++) { + p->grades[i] = (float)(rand() % 101); // 0 to 100 + } +} + +void print_all(Person** people, int count) { + for (int i = 0; i < count; i++) { + print_person(people[i]); + } +} + +void free_all(Person** people, int count) { + for (int i = 0; i < count; i++) { + free(people[i]); + } +} + +int find_oldest(Person** people, int count) { + int oldest_index = 0; + for (int i = 1; i < count; i++) { + if (people[i]->age > people[oldest_index]->age) { + oldest_index = i; + } + } + return oldest_index; +} + |
