Table of Contents

1. Preview

emacs.png

2. Detect System

detect my all system

(defconst *is-a-mac* (eq system-type 'darwin))
(defconst *is-a-linux* (eq system-type 'gnu/linux))
(package-initialize)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)

3. Base Editor

Basic editor sittings

;; 自动加载外部修改过的文件
(global-auto-revert-mode 1)
;; 关闭自己生产的保存文件
(setq auto-save-default nil)
;; 关闭自己生产的备份文件
(setq make-backup-files nil)
;; 选中某个区域继续编辑可以替换掉该区域
(delete-selection-mode 1)
;; 设置h 文件默认为c++文件
(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))
;; orgmode
(add-hook 'org-mode-hook (lambda () (setq truncate-lines nil)))
;; without lock files
(setq create-lockfiles nil)
;; y-or-n
(fset 'yes-or-no-p 'y-or-n-p)
;; Show welcome message
(setq-default initial-scratch-message
              (concat ";; Happy hacking, " user-login-name " - Emacs ♥ you!\n\n"))
;; org-mode 自动对齐
(setq org-startup-indented t)
;; org-mode 自动折叠
(setq org-startup-folded 'content)

;; macOS change meta key to command
(when *is-a-mac*
  (setq mac-command-modifier 'meta)
  (setq mac-option-modifier 'none))
;;auto pair
(electric-pair-mode +1)
(global-hl-line-mode +1)

4. Terminal

Emacs in terminal usage

(unless window-system
  (xclip-mode 1)
  (xterm-mouse-mode 1))

5. GUI

Emacs GUI Style Stuff

;; display “lambda” as “λ”
(global-prettify-symbols-mode 1)
;; 像素滚动
(pixel-scroll-precision-mode 1)
(when *is-a-linux*
  (setq pixel-scroll-precision-large-scroll-height 10
        pixel-scroll-precision-interpolation-factor 10.0))

5.1. 彩虹括号

(add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
(custom-set-faces
 '(rainbow-delimiters-base-face    ((t (:inherit nil :weight bold))))
 '(rainbow-delimiters-depth-1-face ((t (:inherit rainbow-delimiters-base-face :foreground "dark orange"))))
 '(rainbow-delimiters-depth-2-face ((t (:inherit rainbow-delimiters-base-face :foreground "DeepSkyBlue"))))
 '(rainbow-delimiters-depth-3-face ((t (:inherit rainbow-delimiters-base-face :foreground "YellowGreen"))))
 '(rainbow-delimiters-depth-4-face ((t (:inherit rainbow-delimiters-base-face :foreground "LimeGreen"))))
 '(rainbow-delimiters-depth-5-face ((t (:inherit rainbow-delimiters-base-face :foreground "dodger blue"))))
 '(rainbow-delimiters-depth-6-face ((t (:inherit rainbow-delimiters-base-face :foreground "MediumSlateBlue"))))
 '(rainbow-delimiters-depth-7-face ((t (:inherit rainbow-delimiters-base-face :foreground "blue violet"))))
 '(rainbow-delimiters-depth-8-face ((t (:inherit rainbow-delimiters-base-face :foreground "hot pink"))))
 '(rainbow-delimiters-depth-9-face ((t (:inherit rainbow-delimiters-base-face :foreground "DeepPink")))))

5.2. 行号

(when (fboundp 'display-line-numbers-mode)
  (setq-default display-line-numbers-width 3)
  (add-hook 'prog-mode-hook 'display-line-numbers-mode))
(when (boundp 'display-fill-column-indicator)
  (setq-default indicate-buffer-boundaries 'left)
  ;(setq-default display-fill-column-indicator-character ?\u254e)
  (add-hook 'prog-mode-hook 'display-fill-column-indicator-mode))

5.3. Theme

(when (display-graphic-p)
  (when *is-a-mac*
    (defun my/apply-theme (appearance)
      "Load theme, taking current system APPEARANCE into
      consideration."
      (mapc #'disable-theme custom-enabled-themes)
      (pcase appearance
        ('light (load-theme 'kaolin-light t)  (setq default-frame-alist
                                                              '((ns-appearance . light))))
        ('dark (load-theme 'kaolin-dark t)  (setq default-frame-alist
                                                               '((ns-appearance . dark))))))
    (add-hook 'ns-system-appearance-change-functions #'my/apply-theme))
  (when *is-a-linux*
    (load-theme 'kaolin-light t)))

5.4. ✨ Mode-line

(leaf minions
  :custom (minions-mode-line-lighter . "✬")
  :hook after-init-hook)

(leaf doom-modeline
  :hook emacs-startup-hook)

(leaf doom-modeline
  :after doom-modeline
  :defun doom-modeline-def-modeline doom-modeline-def-segment
  :custom
  (inhibit-compacting-font-caches . t)
  ((doom-modeline-bar-width                   . 5)
   (doom-modeline-window-width-limit          . fill-column)
   (doom-modeline-project-detection           . 'project)  
   ((doom-modeline-icon             
     doom-modeline-unicode-fallback 
     doom-modeline-minor-modes) . t)
   (doom-modeline-continuous-word-count-modes . '(markdown-mode gfm-mode org-mode text-mode))
   (doom-modeline-buffer-encoding             . nil) 
   (doom-modeline-checker-simple-format       . nil)
   (doom-modeline-persp-name                  . nil))
  :defer-config)

5.5. ✨ 光幖

沾加 beacon

(defvar nasy-cursor-colors '("#F00056"
                             "#057748"
                             "#30DFF3"
                             "#FF9393"
                             "#50616D"
                             "#FFC34D"
                             "#801DAE"
                             "#705438"
                             "#FAFF72")
  "Blink cursor colors.")

(defvar nasy--blink-cursor-count 0
  "Blink cursor counter.")


(defun nasy/blink-cursor-timer-function (&rest _)
  (when (not (internal-show-cursor-p))
    (when (>= nasy--blink-cursor-count (length nasy-cursor-colors))
      (setq nasy--blink-cursor-count 0))
    (let ((color (nth nasy--blink-cursor-count nasy-cursor-colors))
          (hl-color (nth nasy--blink-cursor-count (reverse nasy-cursor-colors))))
      (set-cursor-color color)
      (when (featurep 'beacon)
        (setq beacon-color color))
      (setq nasy--blink-cursor-count (1+ nasy--blink-cursor-count)))))


(leaf frame
  :advice
  (:before blink-cursor-timer-function nasy/blink-cursor-timer-function))


;; (defun nasy/blink-cursor-timer-function (orig-fun &rest args)
;;   "Blink and change the color of cursor."
;;   (when (not (internal-show-cursor-p))
;;     (when (>= nasy--blink-cursor-count (length nasy-cursor-colors))
;;       (setq nasy--blink-cursor-count 0))
;;     (let ((c-color (nth nasy--blink-cursor-count nasy-cursor-colors)))
;;       (set-cursor-color c-color)
;;       (when (featurep 'beacon)
;;         (setq beacon-color c-color)))
;;     (setq nasy--blink-cursor-count (1+ nasy--blink-cursor-count))))

5.6. ✨ Beacon

沾加 beacon

(defun beacon--shine-b ()
  "Shine a beacon at point."
  (let ((colors (beacon--color-range)))
    (save-excursion
      (while colors
        (if (looking-at "^")
            (setq colors nil)
          (beacon--colored-overlay (pop colors))
          (backward-char 1))))))


(defun nasy/beacon-blink (&rest _)
  "Blink the beacon at the position of the cursor."
  (interactive)
  (beacon--vanish)
  (run-hooks 'beacon-before-blink-hook)
  (beacon--shine-b)
  (when (timerp beacon--timer)
    (cancel-timer beacon--timer))
  (setq beacon--timer
        (run-at-time beacon-blink-delay
                     (/ beacon-blink-duration 1.0 beacon-size)
                     #'beacon--dec)))


(defun nasy/blink ()
  (cond ((member this-command '(left-char
                                meow-left
                                meow-back-word
                                delete-char
                                backward-delete-char-untabify
                                move-beginning-of-line
                                org-beginning-of-line
                                org-beginning-of-item
                                org-beginning-of-block))
         (beacon-blink))
        ((member this-command '(right-char
                                meow-right
                                meow-next-word
                                self-insert-command
                                move-end-of-line
                                org-end-of-line
                                org-end-of-item
                                org-end-of-block))
         (nasy/beacon-blink))))

(add-hook 'post-command-hook #'nasy/blink)

(leaf beacon
  :doc "Never lose your cursor again."
  :url "https://github.com/Malabarba/beacon"
  :tag "convenience"
  :commands (beacon--vanish beacon--shine-b)
  :custom
  (beacon-size . 8)
  (beacon-blink-delay . 0.1)
  ((beacon-blink-when-point-moves-vertically
    beacon-blink-when-point-moves-horizontally)
   . 1)
  (blink-cursor-interval . 1)
  (beacon-dont-blink-commands . nil)
  :hook (post-command-hook . nasy/blink))

6. ✨ Font

My emacs Font

(when *is-a-linux*
  (set-face-attribute
   'default nil
   :font (font-spec :family "mononoki Nerd Font Mono"
                    :weight 'normal
                    :size  16)))
(when *is-a-mac*
  (set-face-attribute
   'default nil
   :font (font-spec :family "mononoki Nerd Font Mono"
                    :weight 'normal
                    :size  15)))

(set-fontset-font
 t
 '(#x1f300 . #x1fad0)
 (cond
  ((member "Noto Color Emoji" (font-family-list)) "Noto Color Emoji")
  ((member "Apple Color Emoji" (font-family-list)) "Apple Color Emoji")
  ((member "Noto Emoji" (font-family-list)) "Noto Emoji")
  ((member "Segoe UI Emoji" (font-family-list)) "Segoe UI Emoji")
  ((member "Symbola" (font-family-list)) "Symbola"))
 )
(when (member "Unifont" (font-family-list))
  (defvar +font-unicode-family "Unifont")
  (defun +load-ext-font ()
    (when window-system
      (let ((font (frame-parameter nil 'font))
            (font-spec (font-spec :family +font-unicode-family)))
        (dolist (charset '(kana han hangul cjk-misc bopomofo symbol))
          (set-fontset-font font charset font-spec)))))
  (+load-ext-font))

7. MiniBuff

I use Vertico

(add-hook 'after-init-hook 'vertico-mode)

(with-eval-after-load 'vertico
  (require 'orderless)
  (savehist-mode))

(defun sanityinc/use-orderless-in-minibuffer ()
  (setq-local completion-styles '(substring orderless)))
(add-hook 'minibuffer-setup-hook 'sanityinc/use-orderless-in-minibuffer)
(add-hook 'after-init-hook 'marginalia-mode)

8. Org

(setq org-agenda-files (list "~/private/agenda/global.org"
                             "~/private/agenda/daily.org" 
                             "~/private/agenda/week.org"))
(defun org-agenda-show-all-todo (&optional arg)
  "list all my todo"
  (interactive "P")
  (org-agenda arg "t"))

(defun meomacs--org-prettify-symbols ()
  (setq-local prettify-symbols-alist
              '(("#+begin_src" . "»")
                ("#+end_src" . "«")
                ("#+begin_example" . "»")
                ("#+end_example" . "«")
                ("#+begin_quote" . "‟")
                ("#+end_quote" . "‟")
                ("[X]" . "☑")
                ("[ ]" . "☐")))
  (prettify-symbols-mode 1))

(add-hook 'org-mode-hook 'meomacs--org-prettify-symbols)

9. Tools

Misc Tools

9.1. Ctrlf

replace iserch

(ctrlf-mode +1)

9.2. Telega

9.2.1. Install

(leaf telega
  :when *is-a-mac*
  :ensure t)

9.2.2. Font

(with-eval-after-load "telega"
  (when *is-a-mac*
    (defun my-align-with-sarasa-font ()
      (interactive)
      ;; make symbols smaller
      ;; (add-to-list 'face-font-rescale-alist '("-Noto Color Emoji-" . 0.9))
      (add-to-list 'face-font-rescale-alist '("-STIXGeneral-" . 0.4))
      (add-to-list 'face-font-rescale-alist '("-Apple Color Emoji-" . 0.7))
      ;; (add-to-list 'face-font-rescale-alist '("-Noto Sans Symbols-" . 0.9))
      ;; (add-to-list 'face-font-rescale-alist '("-Noto Sans Symbols2-" . 0.9))
      (add-to-list 'face-font-rescale-alist '("-Symbola-" . 0.7)))
    (add-hook 'telega-root-mode-hook (lambda () (my-align-with-sarasa-font)))
    (add-hook 'telega-chat-mode-hook (lambda () (my-align-with-sarasa-font)))))

9.3. Org-static-blog

9.3.1. Blog

;;(when (require-package 'org-static-blog)
;;  (setq org-static-blog-publish-title "NULL")
;;  (setq org-static-blog-publish-url "https://haveagoodtime.gitlab.io/blog")
;;  (setq org-static-blog-publish-directory "~/Repos/blog")
;;  (setq org-static-blog-posts-directory "~/Repos/blog/posts")
;;  (setq org-static-blog-drafts-directory "~/Repos/blog/drafts")
;;  (setq org-static-blog-enable-tags t)
;;  (setq org-static-blog-use-preview t)
;;  (setq org-export-with-toc nil)
;;  (setq org-export-with-section-numbers nil)
;;  (setq org-static-blog-page-header
;;        "
;;<meta name=\"author\" content=\"me\">
;;<meta name=\"referrer\" content=\"no-referrer\">
;;<link href= \"static/blog.css\" rel=\"stylesheet\" type=\"text/css\" />
;;<link rel=\"icon\" href=\"static/favicon.ico\">
;;")
;;  (setq org-static-blog-index-front-matter
;;        "<h1> xx </h1>\n")
;;  (setq org-static-blog-page-preamble
;;        "
;;<div class=\"header\">
;;  <div class=\"sitelinks\">
;;    <a href=\"https://haveagoodtime.gitlab.io/blog\">Home</a> | 
;;    <a href=\"https://haveagoodtime.gitlab.io/blog/archive.html\">All Posts</a> | 
;;    <a href=\"https://haveagoodtime.gitlab.io/blog/tags.html\">Tags</a> | 
;;    <a href=\"https://haveagoodtime.gitlab.io/blog/rss.xml\">RSS</a> | 
;;    <div class=\"dropdown\">
;;      <a class=\"dropbtn\">Configurations</a>
;;      <div class=\"dropdown-content\">
;;        <a href=\"https:\">Emacs</a>
;;        <a href=\"https\">NixOS</a>
;;      </div>
;;    </div>
;;  </div>
;;</div>
;;"))

9.3.2. Htmlize

(setq org-export-with-toc t)

10. Keybind

(global-set-key (kbd "C-x M-p p") 'project-switch-project)
(global-set-key (kbd "C-x M-p f") 'project-find-file)
(global-set-key (kbd "C-x M-p c") 'project-compile)
(global-set-key (kbd "C-x M-p s") 'project-search)
(global-set-key (kbd "C-x M-v v") 'vc-next-action)
(global-set-key (kbd "C-x M-v c") 'vc-dir)
(global-set-key (kbd "C-x M-v d") 'vc-diff)
(global-set-key (kbd "C-x M-w w") 'windmove-up)
(global-set-key (kbd "C-x M-w a") 'windmove-left)
(global-set-key (kbd "C-x M-w s") 'windmove-down)
(global-set-key (kbd "C-x M-w d") 'windmove-right)
(global-set-key (kbd "C-x M-w q") 'delete-window)
(global-set-key (kbd "C-x M-w 1") 'delete-other-windows)
(global-set-key (kbd "C-x M-w 2") 'split-window-below)
(global-set-key (kbd "C-x M-w 3") 'split-window-right)
(global-set-key (kbd "C-x M-b b") 'switch-to-buffer)
(global-set-key (kbd "C-x M-b k") 'kill-buffer)
(global-set-key (kbd "C-x M-t t") 'org-agenda-show-all-todo)

11. 喵喵

(leaf meow
  :require t
  :init
  (defun meow-setup ()
    (setq meow-cheatsheet-layout meow-cheatsheet-layout-qwerty)
    (meow-motion-overwrite-define-key
     '("j" . meow-next)
     '("k" . meow-prev)
     '("<escape>" . ignore))
    (meow-leader-define-key
     ;; SPC j/k will run the original command in MOTION state.
     '("j" . "H-j")
     '("k" . "H-k")
     ;; Use SPC (0-9) for digit arguments.
     '("1" . meow-digit-argument)
     '("2" . meow-digit-argument)
     '("3" . meow-digit-argument)
     '("4" . meow-digit-argument)
     '("5" . meow-digit-argument)
     '("6" . meow-digit-argument)
     '("7" . meow-digit-argument)
     '("8" . meow-digit-argument)
     '("9" . meow-digit-argument)
     '("0" . meow-digit-argument)
     '("p" . "C-x M-p")
     '("v" . "C-x M-v")
     '("w" . "C-x M-w")
     '("b" . "C-x M-b")
     '("t" . "C-x M-t")
     '("/" . meow-keypad-describe-key)
     '("?" . meow-cheatsheet))
    (meow-normal-define-key
     '("0" . meow-expand-0)
     '("9" . meow-expand-9)
     '("8" . meow-expand-8)
     '("7" . meow-expand-7)
     '("6" . meow-expand-6)
     '("5" . meow-expand-5)
     '("4" . meow-expand-4)
     '("3" . meow-expand-3)
     '("2" . meow-expand-2)
     '("1" . meow-expand-1)
     '("-" . negative-argument)
     '(";" . meow-reverse)
     '("," . meow-inner-of-thing)
     '("." . meow-bounds-of-thing)
     '("[" . meow-beginning-of-thing)
     '("]" . meow-end-of-thing)
     '("a" . meow-append)
     '("A" . meow-open-below)
     '("b" . meow-back-word)
     '("B" . meow-back-symbol)
     '("c" . meow-change)
     '("d" . meow-delete)
     '("D" . meow-backward-delete)
     '("e" . meow-next-word)
     '("E" . meow-next-symbol)
     '("f" . meow-find)
     '("g" . meow-cancel-selection)
     '("G" . meow-grab)
     '("h" . meow-left)
     '("H" . meow-left-expand)
     '("i" . meow-insert)
     '("I" . meow-open-above)
     '("j" . meow-next)
     '("J" . meow-next-expand)
     '("k" . meow-prev)
     '("K" . meow-prev-expand)
     '("l" . meow-right)
     '("L" . meow-right-expand)
     '("m" . meow-join)
     '("n" . meow-search)
     '("o" . meow-block)
     '("O" . meow-to-block)
     '("p" . meow-yank)
     '("q" . meow-quit)
     '("Q" . meow-goto-line)
     '("r" . meow-replace)
     '("R" . meow-swap-grab)
     '("s" . meow-kill)
     '("t" . meow-till)
     '("u" . meow-undo)
     '("U" . meow-undo-in-selection)
     '("v" . meow-visit)
     '("w" . meow-mark-word)
     '("W" . meow-mark-symbol)
     '("x" . meow-line)
     '("X" . meow-goto-line)
     '("y" . meow-save)
     '("Y" . meow-sync-grab)
     '("z" . meow-pop-selection)
     '("'" . repeat)
     '("<escape>" . ignore)))
  (unless window-system
    (defun tempuseescape ()
      "xxx"
      (interactive)
      (meow-motion-overwrite-define-key
       '("<escape>" . save-buffers-kill-emacs))))
  :config
  (meow-global-mode 1)
  (setq meow-use-clipboard t)
  (meow-setup))

12. 🌈

(with-eval-after-load 'dired
  (diredfl-global-mode)
  (require 'dired-x))

13. Company

(add-hook 'after-init-hook 'global-company-mode)
(with-eval-after-load 'company
  (define-key company-mode-map (kbd "M-/") 'company-complete)
  (define-key company-mode-map [remap completion-at-point] 'company-complete)
  (define-key company-mode-map [remap indent-for-tab-command] 'company-indent-or-complete-common)
  (define-key company-active-map (kbd "M-/") 'company-other-backend)
  (define-key company-active-map (kbd "C-n") 'company-select-next)
  (define-key company-active-map (kbd "C-p") 'company-select-previous)
  (define-key company-active-map (kbd "C-d") 'company-show-doc-buffer)
  (define-key company-active-map (kbd "M-.") 'company-show-location)
  (setq-default company-dabbrev-other-buffers 'all
                company-tooltip-align-annotations t))
(global-set-key (kbd "M-C-/") 'company-complete)

14. Lang

14.1. LSP


14.2. Rust

(add-hook 'rust-mode-hook #'lsp)
(when *is-a-mac*
  (setenv "LIBRARY_PATH" "/Users/me/.local/share/libiconv"))

14.3. Nix

;;(add-hook 'nix-mode-hook #'lsp)

14.4. Go

(add-hook 'go-mode-hook #'lsp)

14.5. Python

(add-hook 'python-mode-hook #'lsp)

14.6. Clojure

(add-hook 'clojure-mode-hook #'lsp)

14.7. Auctex

(add-hook 'LaTeX-mode-hook
          #'(lambda ()
              (setq-default TeX-engine 'xetex)))

14.7.1. LSP

(add-hook 'LaTeX-mode-hook #'lsp)

14.8. Haskell

(add-hook 'haskell-mode-hook #'lsp)

Author: NULL

Created: 2022-01-15 Sat 20:46

Validate