feat(emacs): Basic emacs setup

This commit is contained in:
js0ny 2025-01-28 14:27:46 +00:00
parent 2346c13564
commit 6edb5d9e90
7 changed files with 134 additions and 0 deletions

17
tools/emacs.d/.gitignore vendored Normal file
View file

@ -0,0 +1,17 @@
# 自动生成的目录
/auto-save-list/
/elpa/
/eshell/
/server/
/url/
# 临时文件
tutorial
*~
\#*\#
.#*
*.elc
# 自动保存的文件
auto-save-list
tramp

12
tools/emacs.d/custom.el Normal file
View file

@ -0,0 +1,12 @@
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(package-selected-packages '(use-package evil company)))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)

31
tools/emacs.d/init.el Normal file
View file

@ -0,0 +1,31 @@
;;; init.el --- Entry point of GNU/Emacs configuration
;;; First edit date 2025/01/27
;;; Organised by such directory structure
;;; init.el -- This file, entry point
;;; lisp/
;;; init-basic.el
;;; init-keymaps.el
;;; init-package.el
;;; init-evil.el
;;; custom.el -- Auto Generated
;; All elisp files under emacs.d/lisp will be loaded
(add-to-list 'load-path (expand-file-name "lisp" user-emacs-directory))
;; Store the auto-generated custom config to `custom.el`
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
;; Load each modules
(require 'init-basic)
(require 'init-keymaps)
(require 'init-package)
(require 'init-evil)
;; Load `custom` file
(when (file-exists-p custom-file)
(load custom-file))
;;; init.el end

View file

@ -0,0 +1,15 @@
;;; init-basic.el
;; Disable startup message
(setq inhibit-startup-message t)
;; Use line number by default
(global-display-line-numbers-mode 1)
;; Vim-like relativenumber
(setq display-line-numbers-type 'relative)
;; https://book.emacs-china.org/#orgcfd105e Open with Emacs
(server-mode 1)
;; Export module
(provide 'init-basic)

View file

@ -0,0 +1,26 @@
;;; init-evil.el
;; Evil - Extensible VI Layer
(defvar evil-colemak-state-map (make-sparse-keymap))
(use-package evil
:ensure t
:config
(evil-mode 1)
; Colemak Vim Arrow
(evil-define-key '(normal visual operator) 'global
"n" 'evil-next-line
"e" 'evil-previous-line
"i" 'evil-forward-char
"l" 'evil-insert
"L" 'evil-insert-0-line
"k" 'evil-search-next
"K" 'evil-search-previous
"j" 'evil-forward-word-end
"J" 'evil-forward-WORD-end
"N" '(lambda () (interactive) (evil-next-line 5)) ; 5n
"E" '(lambda () (interactive) (evil-previous-line 5)) ; 5e
))
(provide 'init-evil)

View file

@ -0,0 +1,11 @@
;;; init-keymaps.el
;; Once this is defined, `M-x open-init-file` will open this file
(defun open-init-file()
(interactive) ;; Mark function as `interactive` that allows user to access by M-x open-init-file RET
(find-file "~/.emacs.d/init.el"))
(defun reload-init()
(interactive)
(load-file "~/.emacs.d/init.el"))
(provide 'init-keymaps)

View file

@ -0,0 +1,22 @@
;;; init-package.el
;; Manual Install Packages (plugins): Options > Manage Emacs Packages (Don't use this)
(global-company-mode 1) ; Enable company
;; Ensure use-package is installed (use-package: lazy load plugin manager)
(unless (package-install 'use-package)
(package-refresh-contents)
(package-install 'use-package))
;; Plugins Here
;; Company - Complete Anything
(use-package company
:ensure t
:config
(global-company-mode 1)
(define-key company-active-map (kbd "C-n") 'company-select-next)
(define-key company-active-map (kbd "C-p") 'company-select-previous))
(provide 'init-package)