Skip to content

Commit

Permalink
snippet system for eamcs
Browse files Browse the repository at this point in the history
  • Loading branch information
amirrezaask committed Jan 3, 2024
1 parent faf8207 commit aafa0c6
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 11 deletions.
33 changes: 27 additions & 6 deletions .emacs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand All @@ -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)
Expand All @@ -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))

Expand All @@ -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 "<f5>") '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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion emacs.bat
Original file line number Diff line number Diff line change
@@ -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 %*
52 changes: 48 additions & 4 deletions nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"] =
Expand Down Expand Up @@ -352,7 +396,8 @@ vim.keymap.set("n", "<C-p>", function() telescope_builtin.git_files(telescope_no
vim.keymap.set("n", "<leader>b", function() telescope_builtin.buffers(telescope_no_preview) end)
vim.keymap.set("n", "<leader><leader>", function() telescope_builtin.find_files(telescope_no_preview) end)
vim.keymap.set("n", "<leader>ff", function() telescope_builtin.find_files(telescope_no_preview) end)
vim.keymap.set("n", "<leader>.", function() telescope_builtin.grep_string({ layout_config = { height = 0.7, width = 0.9 } }) end)
vim.keymap.set("n", "<leader>.",
function() telescope_builtin.grep_string({ layout_config = { height = 0.7, width = 0.9 } }) end)
vim.keymap.set("n", "<leader>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", "<leader>w", function() telescope_builtin.lsp_workspace_symbols(telescope_no_preview) end)
Expand Down Expand Up @@ -380,4 +425,3 @@ vim.api.nvim_create_autocmd("LspAttach", {
vim.keymap.set("i", "<C-s>", vim.lsp.buf.signature_help, buffer("Signature Help"))
end,
})

0 comments on commit aafa0c6

Please sign in to comment.