create repo

This commit is contained in:
Hmtsai 2024-05-18 23:29:43 +08:00
commit 5d46b4a928
4 changed files with 248 additions and 0 deletions

39
init.el Normal file
View File

@ -0,0 +1,39 @@
(let ((minver "25.1"))
(when (version< emacs-version minver)
(error "Your Emacs is too old -- this config requires v%s or higher" minver)))
(when (version< emacs-version "26.1")
(message "Your Emacs is old, and some functionality in this config will be disabled. Please upgrade if possible."))
(add-to-list 'load-path (expand-file-name "lisp" user-emacs-directory)) ; 设定源码加载路径
;; (require 'init-benchmarking) ;; Measure startup time
(defconst *spell-check-support-enabled* nil) ;; Enable with t if you prefer
(defconst *is-a-mac* (eq system-type 'darwin))
;; Adjust garbage collection thresholds during startup, and thereafter
(let ((normal-gc-cons-threshold (* 20 1024 1024))
(init-gc-cons-threshold (* 128 1024 1024)))
(setq gc-cons-threshold init-gc-cons-threshold)
(add-hook 'emacs-startup-hook
(lambda () (setq gc-cons-threshold normal-gc-cons-threshold))))
(require 'settings)
(require 'packages)
(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.
'(custom-enabled-themes '(catppuccin))
'(custom-safe-themes
'("d77d6ba33442dd3121b44e20af28f1fae8eeda413b2c3d3b9f1315fbda021992" default))
'(package-selected-packages
'(markdown-preview-mode catppuccin-theme lsp-treemacs treemacs-projectile treemacs magit lsp-ivy lsp-ui lsp-mode flycheck yasnippet-snippets yasnippet company counsel)))
(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.
)

179
lisp/packages.el Normal file
View File

@ -0,0 +1,179 @@
(setq package-archives '(("gnu" . "https://mirrors.ustc.edu.cn/elpa/gnu/")
("melpa" . "https://mirrors.ustc.edu.cn/elpa/melpa/")
("nongnu" . "https://mirrors.ustc.edu.cn/elpa/nongnu/")))
(use-package counsel
:ensure t)
(use-package ivy
:ensure t
:init
(ivy-mode 1)
(counsel-mode 1)
:config
(setq ivy-use-virtual-buffers t)
(setq search-default-mode #'char-fold-to-regexp)
(setq ivy-count-format "(%d/%d) ")
:bind
(("C-s" . 'swiper)
("C-x b" . 'ivy-switch-buffer)
("C-c v" . 'ivy-push-view)
("C-c s" . 'ivy-switch-view)
("C-c V" . 'ivy-pop-view)
("C-x C-@" . 'counsel-mark-ring); 在某些终端上 C-x C-SPC 会被映射为 C-x C-@,比如在 macOS 上,所以要手动设置
("C-x C-SPC" . 'counsel-mark-ring)
:map minibuffer-local-map
("C-r" . counsel-minibuffer-history)))
(use-package ace-window
:ensure t
:bind (("C-x o" . 'ace-window)))
(use-package undo-tree
:ensure t
:init (global-undo-tree-mode)
:custom
(undo-tree-auto-save-history nil))
(use-package which-key
:ensure t
:init (which-key-mode))
(use-package marginalia
:ensure t
:init (marginalia-mode)
:bind (:map minibuffer-local-map
("M-A" . marginalia-cycle)))
(use-package multiple-cursors
:bind
("C-S-<mouse-1>" . mc/toggle-cursor-on-click))
(use-package dashboard
:ensure t
:config
(setq dashboard-banner-logo-title "Welcome to Emacs!") ;; 个性签名,随读者喜好设置
;; (setq dashboard-projects-backend 'projectile) ;; 读者可以暂时注释掉这一行,等安装了 projectile 后再使用
(setq dashboard-startup-banner 'official) ;; 也可以自定义图片
(setq dashboard-items '((recents . 5) ;; 显示多少个最近文件
(bookmarks . 5) ;; 显示多少个最近书签
(projects . 10))) ;; 显示多少个最近项目
(dashboard-setup-startup-hook))
(use-package highlight-symbol
:ensure t
:init (highlight-symbol-mode)
:bind ("<f3>" . highlight-symbol))
(use-package rainbow-delimiters
:ensure t
:hook (prog-mode . rainbow-delimiters-mode))
(use-package company
:ensure t
:init (global-company-mode)
:config
(setq company-minimum-prefix-length 1) ; 只需敲 1 个字母就开始进行自动补全
(setq company-tooltip-align-annotations t)
(setq company-idle-delay 0.0)
(setq company-show-numbers t) ;; 给选项编号 (按快捷键 M-1、M-2 等等来进行选择).
(setq company-selection-wrap-around t)
(setq company-transformers '(company-sort-by-occurrence))) ; 根据选择的频率进行排序,读者如果不喜欢可以去掉
(use-package yasnippet
:ensure t
:hook
(prog-mode . yas-minor-mode)
:config
(yas-reload-all)
;; add company-yasnippet to company-backends
(defun company-mode/backend-with-yas (backend)
(if (and (listp backend) (member 'company-yasnippet backend))
backend
(append (if (consp backend) backend (list backend))
'(:with company-yasnippet))))
(setq company-backends (mapcar #'company-mode/backend-with-yas company-backends))
;; unbind <TAB> completion
(define-key yas-minor-mode-map [(tab)] nil)
(define-key yas-minor-mode-map (kbd "TAB") nil)
(define-key yas-minor-mode-map (kbd "<tab>") nil)
:bind
(:map yas-minor-mode-map ("S-<tab>" . yas-expand)))
(use-package yasnippet-snippets
:ensure t
:after yasnippet)
(use-package flycheck
:ensure t
:config
(setq truncate-lines nil) ; 如果单行信息很长会自动换行
:hook
(prog-mode . flycheck-mode))
(use-package lsp-mode
:ensure t
:init
;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
(setq lsp-keymap-prefix "C-c l"
lsp-file-watch-threshold 500)
:hook
(lsp-mode . lsp-enable-which-key-integration) ; which-key integration
:commands (lsp lsp-deferred)
:config
(setq lsp-completion-provider :none) ;; 阻止 lsp 重新设置 company-backend 而覆盖我们 yasnippet 的设置
(setq lsp-headerline-breadcrumb-enable t)
:bind
("C-c l s" . lsp-ivy-workspace-symbol)) ;; 可快速搜索工作区内的符号(类名、函数名、变量名等)
(use-package lsp-ui
:ensure t
:config
(define-key lsp-ui-mode-map [remap xref-find-definitions] #'lsp-ui-peek-find-definitions)
(define-key lsp-ui-mode-map [remap xref-find-references] #'lsp-ui-peek-find-references)
(setq lsp-ui-doc-position 'top))
(use-package lsp-ivy
:ensure t
:after (lsp-mode))
(use-package lsp-ivy
:ensure t
:after (lsp-mode))
(use-package magit
:ensure t)
(use-package c++-mode
:functions ; suppress warnings
c-toggle-hungry-state
:hook
(c-mode . lsp-deferred)
(c++-mode . lsp-deferred)
(c++-mode . c-toggle-hungry-state))
(use-package treemacs
:ensure t
:defer t
:config
(treemacs-tag-follow-mode)
:bind
(:map global-map
("M-0" . treemacs-select-window)
("C-x t 1" . treemacs-delete-other-windows)
("C-x t t" . treemacs)
("C-x t B" . treemacs-bookmark)
;; ("C-x t C-t" . treemacs-find-file)
("C-x t M-t" . treemacs-find-tag))
(:map treemacs-mode-map
("/" . treemacs-advanced-helpful-hydra)))
(use-package treemacs-projectile
:ensure t
:after (treemacs projectile))
(use-package lsp-treemacs
:ensure t
:after (treemacs lsp))
(provide 'packages)

16
lisp/settings.el Normal file
View File

@ -0,0 +1,16 @@
(setq confirm-kill-emacs #'yes-or-no-p) ; 在关闭 Emacs 前询问是否确认关闭,防止误触
(electric-pair-mode t) ; 自动补全括号
(add-hook 'prog-mode-hook #'show-paren-mode) ; 编程模式下,光标在括号上时高亮另一个括号
(column-number-mode t) ; 在 Mode line 上显示列号
(global-auto-revert-mode t) ; 当另一程序修改了文件时,让 Emacs 及时刷新 Buffer
(delete-selection-mode t) ; 选中文本后输入文本会替换文本(更符合我们习惯了的其它编辑器的逻辑)
(setq inhibit-startup-message t) ; 关闭启动 Emacs 时的欢迎界面
(setq make-backup-files nil) ; 关闭文件自动备份
(add-hook 'prog-mode-hook #'hs-minor-mode) ; 编程模式下,可以折叠代码块
(global-display-line-numbers-mode 1) ; 在 Window 显示行号
(when (display-graphic-p) (toggle-scroll-bar -1)) ; 图形界面时关闭滚动条
(savehist-mode 1) ; (可选)打开 Buffer 历史记录保存
(provide 'settings)

14
recentf Normal file
View File

@ -0,0 +1,14 @@
;;; Automatically generated by recentf on Sat May 18 20:02:13 2024.
(setq recentf-list
'(
"~/.emacs.d/.cache/treemacs-persist"
"~/Projects/study-area-cn/src/learn_computer_basic/storage_device.md"
))
(setq recentf-filter-changer-current 'nil)
;; Local Variables:
;; coding: utf-8-emacs
;; End: