commit cd6148f1240f5f433c447ae8d83d41cc8878cd2a Author: Zedhugh Chen Date: Thu Oct 13 02:18:23 2022 +0800 add magit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..593674f --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +/auto-save-list/ +/transient/ +/elpa/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..45bbc02 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,18 @@ +[submodule "site-lisp/magit"] + path = site-lisp/magit + url = https://github.com/magit/magit.git +[submodule "site-lisp/dash"] + path = site-lisp/dash + url = https://github.com/magnars/dash.el.git +[submodule "site-lisp/transient"] + path = site-lisp/transient + url = https://github.com/magit/transient.git +[submodule "site-lisp/with-editor"] + path = site-lisp/with-editor + url = https://github.com/magit/with-editor.git +[submodule "site-lisp/compat"] + path = site-lisp/compat + url = https://git.sr.ht/~pkal/compat +[submodule "site-lisp/lazy-load"] + path = site-lisp/lazy-load + url = https://github.com/manateelazycat/lazy-load.git diff --git a/early-init.el b/early-init.el new file mode 100644 index 0000000..9dab243 --- /dev/null +++ b/early-init.el @@ -0,0 +1,16 @@ +(setq package-enable-at-startup nil) + +(setq frame-inhibit-implied-resize t) + +;; Initialize frame with alpha +(add-to-list 'default-frame-alist '(alpha-background . 85)) +(add-to-list 'default-frame-alist '(fullscreen . maximized)) + +(when (fboundp 'menu-bar-mode) + (menu-bar-mode -1)) + +(when (fboundp 'tool-bar-mode) + (tool-bar-mode -1)) + +(when (fboundp 'scroll-bar-mode) + (scroll-bar-mode -1)) diff --git a/init.el b/init.el new file mode 100644 index 0000000..1875a8b --- /dev/null +++ b/init.el @@ -0,0 +1,104 @@ +(defvar creature-gc-cons-threshold + (if (display-graphic-p) (* 64 1024 1024) (* 16 1024 1024)) + "The default value to use for `gc-cons-threshold'. +If freezing sometimes, decrease it. If stuttering, increase it.") + +(defvar creature-gc-cons-upper-limit + (if (display-graphic-p) (* 512 1024 1024) (* 128 1024 1024)) + "The temporary value for `gc-cons-threshold' to defer it.") + +(defvar creature-gc-timer (run-with-idle-timer 10 t #'garbage-collect) + "Run garbage collection when idle 10s.") + +(defvar default-file-name-handler-alist file-name-handler-alist + "Temporary `file-name-handler-alist' for restore after startup.") + +;; Speed up startup +(defun creature-enlarge-gc-cons-threshold () + "Enlarge garbage collection threshold." + (setq gc-cons-percentage 0.6 + gc-cons-threshold creature-gc-cons-upper-limit)) + +(defun creature-normalize-gc-cons-threshold () + "Normalize garbage collection threshold." + (setq gc-cons-percentage 0.1 + gc-cons-threshold creature-gc-cons-threshold)) + +(creature-enlarge-gc-cons-threshold) +(setq file-name-handler-alist nil) + +(add-hook 'emacs-startup-hook + (lambda () + (creature-normalize-gc-cons-threshold) + (setq file-name-handler-alist default-file-name-handler-alist) + + (setq read-process-output-max (* 1024 1024)) + + ;; GC automatically when unfocused + (if (boundp 'after-focus-change-function) + (add-function :after after-focus-change-function + (lambda () + (unless (frame-focus-state) (garbage-collect)))) + (add-hook 'focus-out-hook #'garbage-collect)) + + ;; Avoid GC while minibuffer active. + (add-hook 'minibuffer-setup-hook + #'creature-enlarge-gc-cons-threshold) + (add-hook 'minibuffer-exit-hook + #'creature-normalize-gc-cons-threshold))) + +(defconst creature/config-dir + (file-name-directory + (or load-file-name buffer-file-name)) + "Root directory of Creature.") + +(defconst creature/cache-dir + (expand-file-name ".cache" creature/config-dir) + "Cache directory of Creature.") + +(defconst creature/pkg-dir + (expand-file-name "site-lisp" creature/config-dir) + "Package directory.") + +(require 'cl-lib) + +(defun add-subdirs-to-load-path (search-dir) + (interactive) + (let* ((dir (file-name-as-directory search-dir))) + (dolist (subdir + ;; 过滤出不必要的目录,提升Emacs启动速度 + (cl-remove-if + #'(lambda (subdir) + (or + ;; 不是目录的文件都移除 + (not (file-directory-p (concat dir subdir))) + ;; 父目录、 语言相关和版本控制目录都移除 + (member subdir '("." ".." + "dist" "node_modules" "__pycache__" + "RCS" "CVS" "rcs" "cvs" ".git" ".github")))) + (directory-files dir))) + (let ((subdir-path (concat dir (file-name-as-directory subdir)))) + ;; 目录下有 .el .so .dll 文件的路径才添加到 `load-path' 中,提升Emacs启动速度 + (when (cl-some #'(lambda (subdir-file) + (and (file-regular-p (concat subdir-path subdir-file)) + ;; .so .dll 文件指非Elisp语言编写的Emacs动态库 + (member (file-name-extension subdir-file) '("el" "so" "dll")))) + (directory-files subdir-path)) + + ;; 注意:`add-to-list' 函数的第三个参数必须为 t ,表示加到列表末尾 + ;; 这样Emacs会从父目录到子目录的顺序搜索Elisp插件,顺序反过来会导致Emacs无法正常启动 + (add-to-list 'load-path subdir-path t)) + + ;; 继续递归搜索子目录 + (add-subdirs-to-load-path subdir-path))))) + +(add-subdirs-to-load-path creature/pkg-dir) + +(require 'lazy-load) +(lazy-load-global-keys + '(("C-x g" . magit-status)) + "magit") + +(add-hook 'emacs-startup-hook + (lambda () + (message (emacs-init-time)))) diff --git a/site-lisp/compat b/site-lisp/compat new file mode 160000 index 0000000..e827a9f --- /dev/null +++ b/site-lisp/compat @@ -0,0 +1 @@ +Subproject commit e827a9f3e2ba585de8b07cd246534a15ec414a8b diff --git a/site-lisp/dash b/site-lisp/dash new file mode 160000 index 0000000..e926385 --- /dev/null +++ b/site-lisp/dash @@ -0,0 +1 @@ +Subproject commit e926385625bd8cf395770479a4fc6a8290526289 diff --git a/site-lisp/lazy-load b/site-lisp/lazy-load new file mode 160000 index 0000000..cd98190 --- /dev/null +++ b/site-lisp/lazy-load @@ -0,0 +1 @@ +Subproject commit cd9819069c8d25cf34a844ba151c261387aeaa01 diff --git a/site-lisp/magit b/site-lisp/magit new file mode 160000 index 0000000..3e833f3 --- /dev/null +++ b/site-lisp/magit @@ -0,0 +1 @@ +Subproject commit 3e833f369911069eb55e96bc617cb2cfdaa1713f diff --git a/site-lisp/transient b/site-lisp/transient new file mode 160000 index 0000000..097f5be --- /dev/null +++ b/site-lisp/transient @@ -0,0 +1 @@ +Subproject commit 097f5be6e0c228790a6e78ffee5f0c599cb58b20 diff --git a/site-lisp/with-editor b/site-lisp/with-editor new file mode 160000 index 0000000..1d5860c --- /dev/null +++ b/site-lisp/with-editor @@ -0,0 +1 @@ +Subproject commit 1d5860cfd05d6805018bd071b8f9b56493ba11c6