From aafa0c6045b9d69c7ad0297e414f7008f0127d5d Mon Sep 17 00:00:00 2001 From: amirrezaask Date: Wed, 3 Jan 2024 21:35:31 +0330 Subject: [PATCH] snippet system for eamcs --- .emacs | 33 ++++++++++++++++++++++++++------ emacs.bat | 2 +- nvim/init.lua | 52 +++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 76 insertions(+), 11 deletions(-) diff --git a/.emacs b/.emacs index 3470ca0a..59167503 100644 --- a/.emacs +++ b/.emacs @@ -86,6 +86,8 @@ (unless (theme-exists "4coder-fleury-theme.el") (url-copy-file "https://raw.githubusercontent.com/amirrezaask/themes/main/4coder-fleury-theme.el" (theme-file "4coder-fleury-theme.el") t)) (load-theme 'handmadehero) +(fido-mode +1) + ;; Compiling stuff (defun compile-directory (DIR) "Compile in a directory" @@ -139,7 +141,7 @@ (command (format "grep --exclude-dir=\".git\" --color=auto -nH --null -r -e \"%s\" ." pattern))) (compilation-start command 'grep-mode))) -(defun grep (dir pattern) +(defun grep-dwim (dir pattern) (interactive (list (read-directory-name "[Grep] Directory: ") (read-string "[Grep] Pattern: "))) (cond ((or (executable-find "rg") is-windows) (rg dir pattern)) @@ -164,6 +166,22 @@ (add-hook 'emacs-lisp-mode-hook (lambda () (setq-local amirreza-find-functions-regex "\\(defun")))) +;; Snippets +(setq amirreza-snippets '(("TO" . "TODO(amirreza): ") + ("NO" . "NOTE(amirreza): "))) + +(defun amirreza-expand () + (interactive) + (let* ((word (current-word)) + (expansion (alist-get word amirreza-snippets nil nil 'string-equal))) + (if expansion + ;; expand snippet + (progn + (backward-delete-char (length word)) + (insert expansion)) + (call-interactively 'dabbrev-expand)))) + + ;; Golang (setq amirreza-golang-imenu-generic-expression '((nil "^type *\\([^ ]*\\)" 1) @@ -172,7 +190,9 @@ (defun amirreza-go-hook () (message "Amirreza Go Hook") (setq-local imenu-generic-expression amirreza-golang-imenu-generic-expression) - (setq-local amirreza-find-functions-regex "^func *\\(.*\\) \\{")) + (setq-local amirreza-find-functions-regex "^func *\\(.*\\) \\{") + (setq-local amirreza-snippets (append '( + ("ifer" . "if err != nil {}")) amirreza-snippets))) (with-eval-after-load 'go-mode (add-hook 'go-mode-hook 'amirreza-go-hook)) @@ -197,13 +217,14 @@ (nil "Classes" "^\\s-*\\(?:\\(?:abstract\\|final\\)\\s-+\\)?\\(?:class\\|interface\\|trait\\|enum\\)\\s-+\\(\\(?:\\sw\\|\\\\\\|\\s_\\)+\\)" 0) (nil "^\\s-*\\(?:\\(?:abstract\\|final\\)\\s-+\\)?namespace\\s-+\\(\\(?:\\sw\\|\\\\\\|\\s_\\)+\\)" 1)) - ) - ) + )) + (with-eval-after-load 'php-mode (add-hook 'php-mode-hook 'amirreza-php-hook)) + ;; Keymaps (global-set-key (kbd "C-.") 'isearch-forward-thing-at-point) -(global-set-key (kbd "C-/") 'grep) ;; Magical search +(global-set-key (kbd "C-/") 'grep-dwim) ;; Magical search (global-set-key (kbd "") 'compile-dwim) ;; |> little green button of my IDE (global-set-key (kbd "M-m") 'compile-dwim) ;; |> button (global-set-key (kbd "C-z") 'undo) ;; Sane undo key @@ -212,7 +233,7 @@ (global-set-key (kbd "M-]") 'kmacro-end-or-call-macro-repeat) ;; end recording keyboard macro. (global-set-key (kbd "C-3") 'split-window-horizontally) (global-set-key (kbd "C-2") 'split-window-vertically) -(global-set-key (kbd "C-q") 'dabbrev-expand) ;; expand current word with suggestions from all buffers. +(global-set-key (kbd "C-q") 'amirreza-expand) ;; Try snippets and then expand with emacs dabbrev (global-set-key (kbd "C-x C-c") 'delete-frame) ;; rebind exit key to just kill frame if possible (global-set-key (kbd "M-p") 'jump-up) (global-set-key (kbd "M-n") 'jump-down) diff --git a/emacs.bat b/emacs.bat index 95f18f36..17490037 100644 --- a/emacs.bat +++ b/emacs.bat @@ -1,3 +1,3 @@ @echo off -"C:\Program Files\Emacs\emacs-29.1\bin\runemacs.exe" -l W:\dotfiles\.emacs +"C:\Program Files\Emacs\emacs-29.1\bin\runemacs.exe" -l W:\dotfiles\.emacs %* diff --git a/nvim/init.lua b/nvim/init.lua index 3462cf0a..d48504ed 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -6,6 +6,49 @@ -- AmirrezaAsk neovim configuration -- Color theme +local function hl(name, bg, fg, link) + local cmd = "" + if bg == nil and fg == nil and link == nil then return end + if bg ~= nil then cmd = string.format("guibg=%s", bg) end + if fg ~= nil then cmd = string.format("%s guifg=%s", cmd, fg) end + if link == nil then + vim.cmd(string.format("hi! %s %s", name, cmd)) + else + vim.cmd(string.format("hi! link %s %s", name, link)) + end +end +local function handmadehero() + local colors = {} + colors.Normal = { bg = "#161616", guifg = "#cdaa7d" } + colors.NonText = colors.Normal + colors.Visual = { bg = "#191970" } + colors.CursorLine = { bg = "#171616" } + colors.Comment = { fg = "#7f7f7f" } + colors.Keyword = { fg = "#cd950c" } + colors.String = { fg = "#6b8e23" } + colors.Character = { fg = "#6b8e23" } + colors.Boolean = { fg = "#6b8e23" } + -- colors.LineNr = { bg = "#101010", fg = "#404040" } + colors.Identifier = { fg = "#cdaa7d" } + colors["@variable"] = { link = "Identifier" } + colors.Macro = { fg = "#8cde94" } + colors.Include = { link = "Macro" } + colors.Type = { fg = "#cdaa7d" } + colors.Constant = { fg = "#6b8e23" } + colors.Function = { fg = "#cdaa7d" } + colors.Punctuation = { fg = "#cdaa7d" } + colors.SignColumn = { bg = "#020202", fg = "#b99468" } + colors.DiffText = { link = "SignColumn" } + colors.DiffAdd = { link = "SignColumn" } + colors.DiffChange = { link = "SignColumn" } + colors.DiffDelete = { link = "SignColumn" } + colors.Pmenu = { bg = "#303040"} + colors.PmenuSel = { bg = "#020202"} + for k,v in pairs(colors) do + hl(k, v.bg, v.fg, v.link) + end +end + local function _4coder_fluery_theme() vim.cmd("hi! Normal guibg=#020202 guifg=#b99468") vim.cmd("hi! NonText guibg=#020202 guifg=#b99468") @@ -39,7 +82,8 @@ local function _4coder_fluery_theme() vim.cmd("hi PmenuSel guibg=#020202") end -_4coder_fluery_theme() +-- _4coder_fluery_theme() +handmadehero() -- Options vim.opt.errorbells = false @@ -198,7 +242,7 @@ require "lazy".setup({ end vim.diagnostic.config({ virtual_text = true }) - -- Hover and signature help windows have rounded borders + -- Hover and signature help windows have rounded borders vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) vim.lsp.handlers["textDocument/signatureHelp"] = @@ -352,7 +396,8 @@ vim.keymap.set("n", "", function() telescope_builtin.git_files(telescope_no vim.keymap.set("n", "b", function() telescope_builtin.buffers(telescope_no_preview) end) vim.keymap.set("n", "", function() telescope_builtin.find_files(telescope_no_preview) end) vim.keymap.set("n", "ff", function() telescope_builtin.find_files(telescope_no_preview) end) -vim.keymap.set("n", ".", function() telescope_builtin.grep_string({ layout_config = { height = 0.7, width = 0.9 } }) end) +vim.keymap.set("n", ".", + function() telescope_builtin.grep_string({ layout_config = { height = 0.7, width = 0.9 } }) end) vim.keymap.set("n", "o", function() telescope_builtin.treesitter(telescope_no_preview) end) vim.keymap.set("n", "??", function() telescope_builtin.live_grep({ layout_config = { height = 0.9, width = 0.9 } }) end) vim.keymap.set("n", "w", function() telescope_builtin.lsp_workspace_symbols(telescope_no_preview) end) @@ -380,4 +425,3 @@ vim.api.nvim_create_autocmd("LspAttach", { vim.keymap.set("i", "", vim.lsp.buf.signature_help, buffer("Signature Help")) end, }) -