Nasy Emacs 配置

zenodo.7790390.svg

1. 新配置文件尙在加工中

此處留些許文字以方便諸君使用

2. 安裝 Install

克隆到 .emacs.d

git clone https://github.com/nasyxx/emacs.d ~/nasy-emacs --recursive
ln -s ~/nasy-emacs ~/.emacs.d

2.1. 生成 el 文件 Generate el files

make generate -j

2.2. 生成 elc 與 eln 文件 Generate elc & eln files (可選 optional)

make config -j

3. 更新 Update

簡而言之兩步

3.1. 更新倉庫 Update repo

make update

3.2. 更新 Update straight (可選 optional)

同時更新 elc 與 eln

make update-all

4. 自定義

自定義文件全位于~芄蘭~有~芄蘭.el~與~custom.el~

雖有 custom.el 但未在配置中加載苟欲用之加載于 芄蘭/芄蘭.el

5. 頟外

5.1. Python isort

;;; python-isort.el --- Utility to sort Python imports -*- lexical-binding: t; -*-

(require 'reformatter)

(defcustom python-isort-command "isort"
  "Name of the `isort` executable."
  :group 'nasy
  :type 'string)

(defvar python-isort--base-args '("--quiet" "--atomic")
  "Base arguments to pass to isort.")

(defcustom python-isort-extra-args nil
  "Extra arguments to pass to isort."
  :group 'nasy
  :type '(repeat string))

;;;###autoload (autoload 'python-isort-buffer "python-isort" nil t)
;;;###autoload (autoload 'python-isort-region "python-isort" nil t)
;;;###autoload (autoload 'python-isort-on-save-mode "python-isort" nil t)
(reformatter-define python-isort
  :program python-isort-command
  :args (python-isort--make-args beg end)
  :lighter " isort"
  :group 'python-isort)

(defun python-isort--make-args (beg end)
  "Helper to build the argument list for isort for span BEG to END."
  (append python-isort--base-args
          python-isort-extra-args
          '("-")))

(provide 'python-isort)
;;; python-isort.el ends here

5.2. 外皃 Theme

外皃

Nasy's Emacs Theme

5.2.1. Colors

;;; 彩.el --- Nasy's Emacs theme colors.  -*- lexical-binding: t; -*-

;;; Commentary:

;;; Code:

;;; 正色
(defconst n-青       "􀝦#00ffff")
(defconst n-赤       "􀝦#c3272b")
(defconst n-白       "􀝦#ffffff")  ;; 精白
(defconst n-黑       "􀝦#000000")
(defconst n-黄       "􀝦#fff143")  ;; 不知其法而用鵝黃


;;; 間色
(defconst n-紺青     "􀝦#3f4470")
(defconst n-鴉青     "􀝦#424c50")
(defconst n-靛藍     "􀝦#065279")
(defconst n-羣青     "􀝦#2e59a7")
(defconst n-深竹月   "􀝦#2e62cd")
(defconst n-寶藍     "􀝦#4b5cc4")
(defconst n-青冥     "􀝦#3271ae")
(defconst n-靛青     "􀝦#177CB0")
(defconst n-湖藍     "􀝦#30DFF3")
(defconst n--青      "􀝦#00ffff")

(defconst n-松绿     "􀝦#057748")
(defconst n-官緑     "􀝦#2a6e3f")
(defconst n-青青     "􀝦#4f6f46")
(defconst n-蒼翠     "􀝦#519a73")
(defconst n-菉竹     "􀝦#698e6a")
(defconst n-竹靑     "􀝦#789262")
(defconst n-春辰     "􀝦#a9be7b")
(defconst n-松花     "􀝦#bce672")
(defconst n-歐碧     "􀝦#c0d695")
(defconst n-龍泉靑瓷 "􀝦#c8e6c6")
(defconst n-水緑     "􀝦#d4f2e7")
(defconst n-水黄     "􀝦#ddeec4")
(defconst n-春緑     "􀝦#e3efd1")
(defconst n-蔥青     "􀝦#edfebb")
(defconst n-断肠     "􀝦#ecebc2")

(defconst n-絳       "􀝦#510312")
(defconst n-胭脂     "􀝦#960018")
(defconst n-綪       "􀝦#b13546")
(defconst n-品红     "􀝦#F00056")
(defconst n-朱       "􀝦#ff0000")
(defconst n-火红     "􀝦#FF2D51")
(defconst n-丹       "􀝦#ff4c00")
(defconst n-妃       "􀝦#ed5736")
(defconst n-海棠     "􀝦#DB5A6B")
(defconst n-桃红     "􀝦#f47983")
(defconst n-鳳仙粉   "􀝦#FF9393")
(defconst n-粉红     "􀝦#ffb3a7")
(defconst n-露玫瑰   "􀝦#ffe4e1")


(defconst n-墨       "􀝦#50616D")
(defconst n-蒼青     "􀝦#7397ab")
(defconst n-墨灰     "􀝦#758A99")

(defconst n-养生主   "􀝦#b49b7f")

(defconst n-茶       "􀝦#B35C44")
(defconst n-鱼肚     "􀝦#FCEFE8")
(defconst n-珈琲椶   "􀝦#705438")
(defconst n-紙棕     "􀝦#D2B38C")
(defconst n-向日黃   "􀝦#FFC34D")
(defconst n-缟       "􀝦#F2ECDE")
(defconst n-牙       "􀝦#EEDEB0")
(defconst n-米灰     "􀝦#D3CBAF")
(defconst n-芽灰     "􀝦#E3DBBF")
(defconst n-胡粉     "􀝦#FFFAE8")
(defconst n-蠟白     "􀝦#FEF8DE")
(defconst n-富春紡   "􀝦#FEF4B4")
(defconst n-鹅黄     "􀝦#FFF143")
(defconst n-嬭油     "􀝦#fffdd0")
(defconst n-鸭黄     "􀝦#FAFF72")
(defconst n-蛤粉     "􀝦#fdfff4")
(defconst n-荼       "􀝦#F3F9F1")
(defconst n-素       "􀝦#E0F0E9")
(defconst n-霜       "􀝦#E9F1F6")
(defconst n-漆       "􀝦#161823")
(defconst n-黛       "􀝦#4A4266")
(defconst n-丁香     "􀝦#CCA4E3")
(defconst n-青莲     "􀝦#801DAE")
(defconst n-淡紫丁香 "􀝦#e6cfe6")
(defconst n-水紅     "􀝦#f3d3e7")
(defconst n-長萅蕐   "􀝦#FF47D1")
(defconst n-紫扇貝   "􀝦#923A60")

(provide ')
;;; 彩.el ends here

5.2.2. Definition

(defgroup nasy-theme nil
  "Options of Nasy's theme."
  :group 'faces)

(defcustom nasy-theme-light/dark 'light
  "Nasy theme uses light theme or dark theme?"
  :group 'nasy-theme
  :type 'symbol)

(defcustom nasy-theme-org-scale t
  "Nasy theme uses scale up in `org-mode' or not."
  :group 'nasy-theme
  :type 'boolean)

(defcustom nasy-theme-outline-scale t
  "Nasy theme uses scale up in `outline' or not."
  :group 'nasy-theme
  :type 'boolean)

(defcustom nasy-theme-underlines-list '(comment constant dash-string hl-line)
  "Nasy theme uses underline on list.

 Should be one or more in `comment', `hl-line', `constant', `dash-string', `keyword'."
  :group 'nasy-theme
  :type '(list symbol))

(defcustom nasy-theme-fixed-pitch-font "Recursive Mono Casual Static"
  "Nasy theme fixed pitch font."
  :group 'nasy-theme
  :type 'string)

(defcustom nasy-theme-variable-pitch-font "Cardo"
  "Nasy theme variable pitch font."
  :group 'nasy-theme
  :type 'string)

(defcustom nasy-theme-variable-pitch-font-weight 'regular
  "Nasy theme variable pitch font weight."
  :group 'nasy-theme
  :type 'symbol)

(defcustom nasy-theme-fixed-pitch-font-scale 1.0
  "Nasy theme fixed pitch font scale."
  :group 'nasy-theme
  :type 'float)

(defcustom nasy-theme-variable-pitch-font-scale 1.3
  "Nasy theme variable pitch font scale."
  :group 'nasy-theme
  :type 'float)

(defcustom nasy-theme-rescale-f/v-pitch-font t
  "Nasy theme rescale f/v-pitch-font or not."
  :group 'nasy-theme
  :type 'boolean)

(defun nasy-theme--light?dark (light dark)
  "Determine using the LIGHT or the DARK color of nasy-theme."
  (if (eq nasy-theme-light/dark 'light)
      light
    dark))
(defalias '--l?d #'nasy-theme--light?dark)

(defun nasy-theme--scale? (scale)
  "Determine using `org-mode' SCALE or not."
  (if nasy-theme-org-scale
      scale
    1))
(defun nasy-theme--outline-scale? (scale)
  "Determine using `outline' SCALE or not."
  (if nasy-theme-outline-scale
      scale
    1))
(defalias '--s? #'nasy-theme--scale?)
(defalias '--os? #'nasy-theme--outline-scale?)

(defun nasy-theme--check-underline-list (sym)
  "Check if SYM in `nasy-theme-underlines-list' or not."
  (when (memq sym nasy-theme-underlines-list)
    t))
(defalias '--u? #'nasy-theme--check-underline-list)

(defun nasy-theme--rescale-font ()
  "Nasy theme rescale font."
  (when nasy-theme-rescale-f/v-pitch-font
    (setf (alist-get
           nasy-theme-fixed-pitch-font
           face-font-rescale-alist
           nasy-theme-fixed-pitch-font-scale nil 'string=)
          nasy-theme-fixed-pitch-font-scale)
    (setf (alist-get
           nasy-theme-variable-pitch-font
           face-font-rescale-alist
           nasy-theme-variable-pitch-font-scale nil 'string=)
          nasy-theme-variable-pitch-font-scale)))

(nasy-theme--rescale-font)

5.2.3. Theme

(deftheme nasy)

(let* ((class  '((class color) (min-colors 88) (background light)))
       (classd '((class color) (min-colors 88) (background dark)))
       (n/淺背景    "􀝦#f4daefb6e3b6")  ;; (color-lighten-name n-缟 1.45)
       (n/深背景    "􀝦#F109ea21da05")  ;; (color-darken-name n-缟 1.45)
       (n/深深背景  "􀝦#ef20e757d52d")  ;; (color-darken-name n-缟 2.9)
       (nd/淺背景   "􀝦#1667187123a5")  ;; (color-lighten-name n-漆 1.45)
       (nd/淺淺背景 "􀝦#16b918ca2427")  ;; (color-lighten-name n-漆 2.9)
       (n/丁香青莲  (--l?d n-青莲 n-青莲))
       (n/墨墨灰    (--l?d n-墨 n-墨灰))
       (n/墨灰墨    (--l?d n-墨灰 n-墨))
       (n/墨灰素    (--l?d n-墨灰 n-素))
       (n/墨缟      (--l?d n-墨 n-缟))
       (n/湖藍靛青  (--l?d n-湖藍 n-靛青))
       (n/漆缟      (--l?d n-漆 n-缟))
       (n/牙墨      (--l?d n-牙 n-墨))
       (n/牙黛      (--l?d n-牙 n-黛))
       (n/素墨      (--l?d n-素 n-墨))
       (n/素墨灰    (--l?d n-素 n-墨灰))
       (n/缟墨      (--l?d n-缟 n-墨))
       (n/缟漆      (--l?d n-缟 n-漆))
       (n/缟黛      (--l?d n-缟 n-黛))
       (n/霜黛      (--l?d n-霜 n-黛))
       (n/青莲丁香  (--l?d n-青莲 n-丁香))
       (n/青莲牙    (--l?d n-青莲 n-牙))
       (n/靛青湖藍  (--l?d n-靛青 n-湖藍))
       (n/黛缟      (--l?d n-黛 n-缟))
       (n/黛霜      (--l?d n-黛 n-霜)))
  (custom-theme-set-faces
   'nasy
   ;;; essential styles
   `(default ((,class (:foreground ,n/墨缟 :background ,n/缟漆))))

   ;;; Basic
   `(bold ((,class (:weight bold))))
   `(button          ((,class (:box (:line-width 1) :underline t :weight bold))))
   `(cursor          ((,class (:background ,n/黛霜 :foreground ,n/霜黛))))
   `(error           ((,class (:background ,n-鳳仙粉 :foreground ,n-紫扇貝 :weight bold))))
   `(escape-glyph    ((,class (:foreground ,n-茶))))
   `(fixed-pitch
     ((,class (:family ,nasy-theme-fixed-pitch-font))))
   `(fixed-pitch-serif ((t (:inherit fixed-pitch))))
   `(fringe          ((,class (:background ,n/缟漆 :foreground ,n/墨缟))))
   `(header-line     ((,class (:background ,n-荼
                                           :box (:line-width 2 :style released-button)
                                           :extend t
                                           :foreground ,n/靛青湖藍))))
   `(highlight    ((,class (:background ,n-米灰
                                        :distant-foreground ,n/霜黛))))
   `(internal-border ((,class (:background ,n/缟漆))))
   `(link         ((,class (:foreground ,n-靛青 :underline t))))
   `(link-visited ((,class (:foreground ,n-青莲 :underline t))))
   `(region       ((,class (:background ,n-蠟白 :distant-foreground ,n/墨缟 :extend t))))
   `(secondary-selection ((,class (:background ,n-芽灰))))
   `(success      ((,class (:background ,n-鱼肚 :foreground ,n-靛青 :weight bold))))
   `(variable-pitch
     ((,class (:family ,nasy-theme-variable-pitch-font
                       :weight ,nasy-theme-variable-pitch-font-weight))))
   `(warning      ((,class (:background ,n-富春紡 :foreground ,n-珈琲椶 :weight bold))))


   ;;; centaur-tabs
   `(centaur-tabs-default
     ((,class (:background ,n-米灰
                           :foreground ,n-墨))))
   `(centaur-tabs-selected
     ((,class (:background ,n-富春紡
                           :foreground ,n-墨))))
   `(centaur-tabs-selected-modified
     ((,class (:background ,n-富春紡
                           :foreground ,n-墨
                           :slant italic))))
   `(centaur-tabs-unselected
     ((,class (:background ,n-春緑
                           :foreground ,n-墨灰))))
   `(centaur-tabs-unselected-modified
     ((,class (:background ,n-水黄
                           :foreground ,n-墨灰
                           :slant italic))))
   `(centaur-tabs-active-bar-face
     ((,class (:background ,n-墨))))



   ;;; company
   `(company-box-scrollbar
     ((,class (:background ,n/黛缟
                           :box (:line-width 2 :style released-button)
                           :extend t
                           :foreground ,n/缟黛))))
   `(company-box-selection
     ((,class (:inherit company-box-scrollbar))))
   `(company-echo-common
     ((,class (:background ,n-茶 :foreground ,n-缟))))
   `(company-preview-common
     ((,class (:background ,n-荼 :foreground ,n-墨 :slant italic :weight bold))))
   `(company-scrollbar-bg
     ((,class (:background ,n-牙))))
   `(company-scrollbar-fg
     ((,class (:background ,n-茶 :foreground ,n-缟))))
   `(company-tooltip
     ((,class (:background ,n/霜黛 :foreground ,n/黛霜))))
   `(company-tooltip-common
     ((,class (:background ,n-素 :foreground ,n-松绿 :weight bold))))
   `(company-tooltip-common-selection
     ((,class (:background ,n/黛缟 :foreground ,n-松花 :inherit company-tooltip-common))))
   `(company-tooltip-selection
     ((,class (:background ,n/黛缟
                           :box (:style released-button)
                           :extend t
                           :foreground ,n/缟黛))))

   ;;; counsel & ivy
   `(all-the-icons-ivy-rich-icon-face
     ((t (:box (:line-width 2 :style released-button)
               :inherit default))))
   `(ivy-current-match
     ((,class (:background ,n/黛缟
                           :extend t
                           :foreground ,n/缟墨
                           :weight bold))))
   `(ivy-highlight-face
     ((,class (:inherit counsel-active-mode))))
   `(ivy-minibuffer-match-face-1
     ((,class (:background ,n-松花
                           :foreground ,n-墨
                           :weight bold))))
   `(ivy-minibuffer-match-face-2
     ((,class (:background ,n-鹅黄
                           :foreground ,n-墨
                           :weight bold))))
   `(ivy-minibuffer-match-face-3
     ((,class (:background ,n-丁香
                           :foreground ,n-墨
                           :weight bold))))
   `(ivy-minibuffer-match-face-4
     ((,class (:background ,n-火红
                           :foreground ,n-墨
                           :weight bold))))

   ;;; customize faces
   `(custom-button
     ((,class (:box (:line-width 2 :style released-button)
                    :foreground ,n/霜黛
                    :background ,n/黛霜))))
   `(custom-button-mouse
     ((,class (:box (:line-width 2 :style released-button)
                    :background ,n/霜黛
                    :foreground ,n/黛霜))))
   `(custom-button-pressed
     ((,class (:box (:line-width 2 :style pressed-button)
                    :inherit custom-button))))
   `(custom-button-pressed-unraised
     ((,class (:foreground ,n-青莲 :inherit custom-button-unraised))))
   `(custom-button-unraised
     ((,class (:underline t))))
   `(custom-comment
     ((,class (:background ,n/霜黛 :foreground ,n/黛霜))))
   `(custom-group-tag
     ((,class (:foreground ,n-靛青
                           :height 1.4
                           :slant normal
                           :weight bold
                           :inherit variable-pitch))))
   `(custom-group-subtitle
     ((,class (:foreground ,n/墨缟
                           :height 1.2
                           :underline t
                           :weight bold))))
   `(custom-variable-obsolete
     ((,class (:foreground ,n/黛霜
                           :strike-through t))))
   `(custom-variable-tag
     ((,class (:foreground ,n-靛青
                           :slant normal
                           :weight bold))))

   ;;; dashboard
   `(dashboard-heading
     ((,class (:inherit font-lock-string-face :underline ,(--u? 'dash-string)))))
   `(widget-button
     ((,class (:weight unspecified))))

   ;;; display-fill-column-indicator-mode
   `(fill-column-indicator ((,class (:background ,n-湖藍 :foreground ,n-靛青))))


   ;;; flycheck
   `(flycheck-warning ((,class (:background ,n-牙
                                            :underline (:style wave :color ,n-丁香)))))

   ;;; font-lock faces
   `(font-lock-bracket-face
     ((,class (:foreground ,n-茶))))
   `(font-lock-builtin-face
     ((,class (:foreground ,n-黛 :weight bold))))
   `(font-lock-comment-delimiter-face
     ((,class (:foreground ,n-墨 :weight bold
                           :underline ,(--u? 'comment)))))
   `(font-lock-comment-face
     ((,class (:foreground ,n-墨 :weight light
                           :slant italic
                           :underline ,(--u? 'comment)))))
   `(font-lock-constant-face
     ((,class (:foreground ,n-黛
                           :underline ,(--u? 'constant)
                           :weight bold))))
   `(font-lock-delimiter-face
     ((,class (:foreground ,n-蒼翠
                           :background ,n/深深背景))))
   `(font-lock-doc-face
     ((,class (:background ,n-春緑 :foreground ,n-墨 :weight light :extend t))))
   `(font-lock-doc-markup-face
     ((,class (:inherit font-lock-constant-face))))
   `(font-lock-escape-face
     ((,class (:foreground ,n-丁香))))
   `(font-lock-function-name-face
     ((,class (:background ,n/深背景 :foreground ,n-墨 :weight bold))))
   `(font-lock-keyword-face
     ((,class (:foreground ,n-黛
                           :weight bold
                           :underline ,(--u? 'keyword)
                           :background ,n-断肠))
      (,classd (:foreground ,n-缟
                            :weight bold
                            :underline ,(--u? 'keyword)))))
   `(font-lock-misc-punctuation-face
     ((,class (:inherit font-lock-punctuation-face))))
   `(font-lock-negation-char-face
     ((,class (:foreground ,n-珈琲椶))))
   `(font-lock-number-face
     ((,class (:foreground ,n-深竹月))))
   `(font-lock-operator-face
     ((,class (:foreground ,n-羣青
                           :background ,n-露玫瑰))))
   `(font-lock-preprocessor-face
     ((,class (:foreground ,n-紙棕 :slant italic))))
   `(font-lock-property-face
     ((,class (:foreground ,n-靛藍 :slant italic))))
   `(font-lock-punctuation-face
     ((,class (:foreground ,n-春辰))))
   `(font-lock-regexp-grouping-backslash
     ((,class (:background ,n-淡紫丁香))))
   `(font-lock-regexp-grouping-construct
     ((,class (:background ,n-淡紫丁香))))
   `(font-lock-string-face
     ((,class (:background ,n/淺背景 :foreground ,n-青青))))
   `(font-lock-type-face
     ((,class (:background ,n/深深背景
                          :foreground ,n-墨
                          :slant italic
                          :weight bold))))
   `(font-lock-variable-name-face
     ((,class (:foreground ,n-墨 :slant italic))))
   `(font-lock-warning-face
     ((,class (:background ,n-鸭黄 :foreground ,n-墨 :weight bold))))

   ;;; highlight
   ;; highlight-indents-guide
   `(highlight-indent-guides-even-face
     ((,class (:background ,n-水黄))))
   `(highlight-indent-guides-odd-face
     ((,class (:background ,n-春緑))))
   ;; hl-line
   `(hl-line ((,class (:underline ,(--u? 'hl-line)
                                  ;; :background ,n-芽灰
                                  ;; :distant-foreground ,n-墨
                                  :extend t
                                  :weight bold))))

   ;;; minibuffer
   `(minibuffer-prompt ((,class (:foreground ,n-松绿 :weight bold
                                             :underline t))))

   ;;; mode line
   `(doom-modeline-battery-charging
     ((,class (:foreground ,n-寶藍))))
   `(doom-modeline-battery-full
     ((,class (:foreground ,n-松绿))))
   `(doom-modeline-buffer-file
     ((,class (:foreground ,n-墨
                           :weight light))))
   `(doom-modeline-buffer-minor-mode
     ((,class (:inherit mode-line))))
   `(doom-modeline-buffer-modified
     ((,class (:foreground ,n-火红
                           :inherit mode-line
                           :weight bold))))
   `(doom-modeline-buffer-major-mode
     ((,class (:foreground ,n-火红 :weight light))))
   `(doom-modeline-buffer-path
     ((,class (:foreground ,n-墨
                           :weight light))))
   `(doom-modeline-debug
     ((,class (:foreground ,n-墨 :weight light))))
   `(doom-modeline-info
     ((,class (:foreground ,n-靛青
                           :inherit mode-line
                           :weight light))))
   `(doom-modeline-lsp-error
     ((,class (:inherit doom-modeline-urgent))))
   `(doom-modeline-lsp-running
     ((,class (:inherit doom-modeline-warning))))
   `(doom-modeline-lsp-warning
     ((,class (:inherit doom-modeline-warning))))
   `(doom-modeline-buffer-minor-mode
     ((,class (:inherit mode-line :background nil))))
   `(doom-modeline-project-dir
     ((,class (:foreground ,n-青青 :weight bold))))
   `(doom-modeline-urgent
     ((,class (:foreground ,n-品红
                           :inherit mode-line
                           :weight bold))))
   `(doom-modeline-warning
     ((,class (:foreground ,n-松花
                           :inherit mode-line
                           :weight bold))))
   `(mode-line          ((,class (:background ,n-胡粉 :weight light))))
   `(mode-line-inactive ((,class (:background ,n-素 :weight light))))

   ;;; orderless
   `(orderless-match-face-0
     ((,class (:background ,n-富春紡   :foreground ,n-蒼翠 :weight bold))))
   `(orderless-match-face-1
     ((,class (:background ,n-鳳仙粉   :foreground ,n-珈琲椶 :weight bold))))
   `(orderless-match-face-2
     ((,class (:background ,n-龍泉靑瓷 :foreground ,n-靛青   :weight bold))))
   `(orderless-match-face-3
     ((,class (:background ,n-紙棕     :foreground ,n-松绿   :weight bold))))

   ;;; org mode
   `(org-block
     ((,class (:background ,n/淺背景 :foreground ,n-墨 :extend t))
      (,classd (:background ,nd/淺背景 :foreground ,n-缟 :extend t))))
   `(org-block-begin-line
     ((,class (:background ,n-嬭油
                           :box (:line-width 1 :style released-button)
                           :extend t
                           :foreground ,n/墨缟
                           :weight bold
                           :slant italic))))
   `(org-cite-key
     ((,class (:foreground ,n-松绿))
      (,classd (:foreground ,n-蔥青))))
   `(org-code ((,class (:background ,n-米灰
                                    :foreground ,n-墨
                                    :inheit fixed-pitch))))
   `(org-document-title
     ((,class (:background ,n-富春紡
                           :extend t
                           :foreground ,n/墨缟
                           :height ,(--s? 1.7)
                           :weight bold))))
   `(org-document-info
     ((,class (:extend nil
                           :foreground ,n/墨缟
                           :height ,(--s? 1.2)
                           :slant italic))))
   `(org-document-info-keyword
     ((,class (:background ,n/素墨
                           :foreground ,n/墨缟
                           :height ,(--s? 1.2)
                           :slant italic))))
   `(org-done
     ((,class (:box (:line-width 2 :style released-button)
                    :foreground ,n/墨缟))))
   `(org-ellipsis
     ((,class (:foreground ,n-米灰
                           :underline nil))))
   `(org-headline-done
     ((,class (:underline (:color ,n-松花)))))
   `(org-list-dt ((,class (:height ,(--s? 1.1) :weight bold))))
   `(org-meta-line
     ((,class (:inherit font-lock-comment-face
                        :underline nil))))
   `(org-property-value ((,class (:foreground ,n-松绿))))
   `(org-roam-link
     ((,class (:inherit org-link
                        :overline  t
                        :underline t))))
   `(org-special-keyword ((,class (:foreground ,n-深竹月))))
   `(org-superstar-header-bullet ((,class (:background ,n-富春紡))))
   `(org-superstar-item ((,class (:foreground ,n-靛青))))
   `(org-tag
     ((,class (;; :background ,n/牙黛
               :box nil
                    :foreground ,n/墨缟
                    :slant normal
                    :underline nil
                    :weight bold))))
   `(org-verbatim ((,class (:background ,n-春緑
                                        :foreground ,n-墨
                                        :inheit fixed-pitch))))

   ;;; Outline
   ;; Also the org-levels
   `(outline-1
     ((,class (:extend nil
                       ;; :background ,n-霜
                       :foreground ,n-靛青
                       :height ,(--os? 1.4)
                       :overline nil
                       :underline nil
                       :weight bold))))
   `(outline-2
     ((,class (:extend nil
                       ;; :background ,n-露玫瑰
                       :foreground ,n-紫扇貝
                       :height ,(--os? 1.2)
                       :overline nil
                       :underline nil
                       :weight bold))))
   `(outline-3
     ((,class (:extend nil
                       ;; :background ,n-春緑
                       :foreground ,n-松绿
                       :height ,(--os? 1.1)
                       :overline nil
                       :underline nil
                       :weight bold))))
   `(outline-4
     ((,class (:extend nil
                       ;; :background ,n-淡紫丁香
                       :foreground ,n/青莲丁香
                       :height ,(--os? 1.1)
                       :overline nil
                       :underline nil
                       :weight bold))))
   `(outline-5
     ((,class (:extend nil
                       :foreground ,n-靛青
                       :height ,(--os? 1.1)
                       :slant italic
                       :weight normal))))
   `(outline-6
     ((,class (:extend nil
                       :foreground ,n-茶
                       :height ,(--os? 1.1)
                       :slant italic
                       :weight normal))))
   `(outline-7
     ((,class (:extend nil
                       :foreground ,n-松绿
                       :height ,(--os? 1.1)
                       :slant italic
                       :weight normal))))
   `(outline-8
     ((,class (:extend nil
                       :foreground ,n/青莲丁香
                       :height ,(--os? 1.1)
                       :slant italic
                       :weight normal))))

   ;;; page break lines
   `(page-break-lines
     ((,class (:inherit font-lock-comment-face :slant normal :underline nil))))


   ;;; Show parens
   `(show-paren-match    ((,class (:background ,n-丁香))))
   `(show-paren-mismatch ((,class (:background ,n-鳳仙粉))))

   ;;; tab-line and tab-bar
   `(tab-line                               ((t (:inherit mode-line))))
   `(tab-line-tab                           ((t (:inherit mode-line))))
   `(tab-line-tab-inactive                  ((t (:inherit mode-line-inactive))))
   `(tab-line-tab-face-inactive-alternating ((t (:inherit mode-line-inactive))))
   `(tab-line-tab-current                   ((t (:inherit mode-line :foreground ,n-富春紡))))
   `(tab-line-highlight                     ((t (:inherit tab-line-tab))))

   `(tab-bar                ((t (:inherit tab-line))))
   `(tab-bar-tab            ((t (:inherit tab-line-tab))))
   `(tab-bar-tab-inactive   ((t (:inherit tab-line-tab-inactive))))

   ;;; term
   `(term-color-􀝦black   ((,class (:background ,n-墨     :foreground ,n-墨))))
   `(term-color-􀝦blue    ((,class (:background ,n-靛青   :foreground ,n-靛青))))
   `(term-color-􀝦cyan    ((,class (:background ,n-湖藍   :foreground ,n-湖藍))))
   `(term-color-􀝦green   ((,class (:background ,n-松绿   :foreground ,n-松绿))))
   `(term-color-􀝦magenta ((,class (:background ,n-長萅蕐 :foreground ,n-長萅蕐))))
   `(term-color-􀝦red     ((,class (:background ,n-火红   :foreground ,n-火红))))
   `(term-color-􀝦white   ((,class (:background ,n-缟     :foreground ,n-缟))))
   `(term-color-􀝦yellow  ((,class (:background ,n-紙棕   :foreground ,n-紙棕))))
   `(vterm-color-inverse-video
     ((,class (:background ,n-墨))))

   ;;; vertico
   `(vertico-mouse  ((,class (:background ,n-紙棕
                                          :inherit highlight))))

   ;;; which-func
   `(which-func  ((,class (:foreground ,n-青青 :weight light))))))

;;;###autoload
(and load-file-name
     (boundp 'custom-theme-load-path)
     (add-to-list 'custom-theme-load-path
                  (file-name-as-directory
                   (file-name-directory load-file-name))))

(provide-theme 'nasy)

5.3.

5.3.1. Single Function to Center Emacs Window on Screen

;;;###autoload
(defun nasy/frame-recenter (&optional frame)
  "Center FRAME on the screen.
FRAME can be a frame name, a terminal name, or a frame.
If FRAME is omitted or nil, use currently selected frame."
  (interactive)
  (unless (eq 'maximised (frame-parameter nil 'fullscreen))
    (let* ((frame (or (and (boundp 'frame) frame) (selected-frame)))
           (frame-w (frame-pixel-width frame))
           (frame-h (frame-pixel-height frame))
            ;; frame-monitor-workarea returns (x y width height) for the monitor
           (monitor-w (nth 2 (frame-monitor-workarea frame)))
           (monitor-h (nth 3 (frame-monitor-workarea frame)))
           (center (list (/ (- monitor-w frame-w) 2)
                         (/ (- monitor-h frame-h) 2))))
      (apply 'set-frame-position (flatten-list (list frame center))))))

6. 配置

國風・鄭風・蔓艸

埜有蔓艸、霝露漙兮
有美一人、淸揚婉兮
邂逅相遇、冟我願兮

埜有蔓艸、霝路瀼瀼
有美一人、婉如淸揚
邂逅相遇、與子偕臧

6.1.

吾學埶不精所述設定必有遺屚朢恕

篇者聚章而成試以詩之名名設定之篇不求其意但求其魂

設定之初也擊鼔而启

6.2.

譯 el 至 elc 與 eln

;;; 譯.el ---  -*- lexical-binding: t; -*-

;;; Commentary:
;; 譯 el 至 elc 與 eln

;;; Code:

(require 'comp)
(require 'comp-run)

(setq load-prefer-newer t
      native-comp-deferred-compilation nil
      org-roam-v2-ack t
      nasy--require nil)

(message "\n\n---------------- 下載與加載  ----------------\n\n")

(add-to-list 'load-path (locate-user-emacs-file "桃夭/擊鼓"))

(load (locate-user-emacs-file "桃夭/擊鼓/擊鼓.el"))

;; (when (and (eq system-type 'darwin) (executable-find "cargo"))
;;   (shell-command (concat "make " (straight--build-dir "tsc") "tsc-dyn.dylib")))

(message "\n\n---------------- Run hooks ----------------\n\n")

(run-hooks
 'after-init-hook
 'emacs-startup-hook
 'nasy/config-before-hook
 'nasy/config-after-hook
 'nasy-first-key-hook
 'org-mode-hook
 'org-first-key-hook
 'prog-mode-hook
 'pre-command-hook)

(message "\n\n---------------- Wait straight.el ----------------\n\n")

(when (native-comp-available-p)
  (while (or comp-files-queue
             (> (comp--async-runnings) 0))
    (sleep-for 2)))

(unless (and (boundp 'nasy-first-p)
             nasy-first-p)

  (message "\n\n---------------- Build elc in 桃夭 ----------------\n\n")
  (byte-recompile-directory (locate-user-emacs-file "桃夭/") 0 t)

  (when (native-comp-available-p)
    (message "\n\n---------------- Build eln in 桃夭 ----------------")
    (dolist (folder '("擊鼓" "風雨" "緑衣"
                      "月出" "庭燎" "日月"
                      "麐之趾" "小曐"))

      (message "\n\n---------------- Build eln of %s ----------------" folder)
      (dolist (elf (directory-files-recursively
                    (locate-user-emacs-file (concat "桃夭/" folder)) "\\.el$"))
        (native-compile elf)
        (while (or comp-files-queue
                  (> (comp--async-runnings) 0))
           (sleep-for 2))))

    (while (or comp-files-queue
               (> (comp--async-runnings) 0))
      (sleep-for 2))))

(provide ')
;;; 譯.el ends here

6.3.early-init

(unless (boundp '*nasy*)
  (load (locate-user-emacs-file"early-init.el") nil t))

開始之歬 加載之初 所用

;;; early-init.el --- Nasy's early-init.el  -*- coding: utf-8; lexical-binding: t; -*-

;;; Commentary:
;; Nasy's early-init.el

;;; Code:

(setq
 ad-redefinition-action            'accept
 fast-but-imprecise-scrolling      t
 ffap-machine-p-known              'reject
 gc-cons-percentage                1.0
 gc-cons-threshold                 most-positive-fixnum
 idle-update-delay                 1
 inhibit-compacting-font-caches    t
 inhibit-default-init              t
 inhibit-startup-message           t
 inhibit-startup-screen            t
 initial-major-mode                'fundamental-mode
 load-prefer-newer                 t
 native-comp-async-jobs-number     10
 package-enable-at-startup         nil
 read-process-output-max           #x10000
 redisplay-skip-fontification-on-input    t
 native-comp-async-report-warnings-errors 'silent)

(setq initial-scratch-message
      (concat ";; Happy hacking, "
              user-login-name " - Emacs ♥ you!\n\n"))


(let ((old-file-name-handler-alist file-name-handler-alist))

  (setq-default file-name-handler-alist nil)

  (defun nasy/restore-default ()
    "Restore gc setting to default."
    (setq file-name-handler-alist
          (delete-dups
           (append file-name-handler-alist
                   old-file-name-handler-alist))
          inhibit-trace nil))

  (add-hook 'emacs-startup-hook #'nasy/restore-default))


(set-language-environment "UTF-8")
(setq selection-coding-system 'utf-8)

(setenv "LSP_USE_PLISTS" "true")


(defconst *nasy* "20221109")

(defconst *is-a-mac* (eq system-type 'darwin))

(defconst *nasy-custom* (concat (expand-file-name user-emacs-directory) "芄蘭/"))
(defconst *nasy-site*   (concat (expand-file-name user-emacs-directory) "木瓜/"))
(defconst *nasy-dir*    (concat (expand-file-name user-emacs-directory) "萚兮/"))
(defconst *nasy-etc*    (concat *nasy-dir* "恆/"))
(defconst *nasy-var*    (concat *nasy-dir* "時/"))


(when (boundp 'native-comp-eln-load-path)
  (add-to-list 'native-comp-eln-load-path (concat *nasy-var* "eln/")))

(when (fboundp 'startup-redirect-eln-cache)
  (startup-redirect-eln-cache
   (convert-standard-filename
    (concat *nasy-var* "eln/"))))


(defvar *debug* (or (getenv-internal "DEBUG") init-file-debug))
(setq inhibit-trace (not *debug*))

(defvar native-comp-deferred-compilation-deny-list nil)

(defvar nasy--require nil
  "Require all packages.")

(defvar nasy-pdump nil
  "Use pdump.")

(setq async-byte-compile-log-file (concat *nasy-var* "async-bytecomp.log")
      debug-on-error    *debug*
      jka-compr-verbose *debug*)

(defvar nasy-first-key-hook nil
  "The hook to run functions before press first key.")

(provide 'early-init)
;;; early-init.el ends here

6.4. 擊鼓

(add-to-list 'load-path (locate-user-emacs-file  "桃夭/擊鼓"))
(require '擊鼓)

國風・邶風・擊鼓

擊鼓其鏜、踊躍用兵
土國城漕、我獨南行

從孫子仲、平陳與宋
不我以歸、憂心有忡

爰居爰處、爰喪其馬
于以求之、于林之下

死生契闊、與子成說
執子之手、與子偕老

于嗟闊兮、不我活兮
于嗟洵兮、不我信兮

啓勭組件

6.4.1.

以 raxod502 之 straight.el 載入包以 setup.el.

6.4.2. 整置文件   convenience

(with-no-warnings
  (customize-set-variable
   'abbrev-file-name
   (concat *nasy-etc* "abbrev.el") "Customized by Nasy.")
  (customize-set-variable
   'auto-save-list-file-prefix
   (concat *nasy-var* "auto-save/sessions/") "Customized by Nasy.")
  (customize-set-variable
   'auto-save-file-name-transforms
   `((".*" ,(concat *nasy-var* "auto-save/") t))
    "Customized by Nasy.")
  (customize-set-variable
   'bookmark-default-file
   (concat *nasy-var* "bookmarks.el") "Customized by Nasy.")
  (customize-set-variable
   'dirvish-cache-dir
   (concat *nasy-var* "dirvish/") "Customized by Nasy.")
  (customize-set-variable
   'eshell-aliases-file
   (concat *nasy-etc* "eshell/aliases") "Customized by Nasy.")
  (customize-set-variable
   'eshell-directory-name
   (concat *nasy-var* "eshell/") "Customized by Nasy.")
  (customize-set-variable
   'save-place-file
   (concat *nasy-var* "save-place.el") "Customized by Nasy.")
  (customize-set-variable
   'svg-lib-icons-dir
   (concat *nasy-var* "svg-lib/") "Customized by Nasy.")
  (customize-set-variable
   'tramp-auto-save-directory
   (concat *nasy-var* "tramp/auto-save/") "Customized by Nasy.")
  (customize-set-variable
   'tramp-persistency-file-name
   (concat *nasy-var* "tramp/persistency.el") "Customized by Nasy.")
  (customize-set-variable
   'url-cache-directory
   (concat *nasy-var* "url/cache/") "Customized by Nasy.")
  (customize-set-variable
   'url-configuration-directory
   (concat *nasy-var* "url/configuration/") "Customized by Nasy."))

6.4.3. straight

(setq-default straight-vc-git-default-clone-depth     1
              straight-repository-branch              "develop"
              straight-enable-use-package-integration nil
              straight-enable-package-integration     nil
              straight-check-for-modifications        nil
              straight-fix-flycheck                   t)

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 6))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))


(defun nasy/-s-u-p (package)
  "Handle special PACKAGE var."
  (if (boundp package)
      (when (eval package)
        (straight-use-package (eval package)))
    (straight-use-package package)))

(defun nasy/sup (&rest packages-sets)
  "Straight use multiple PACKAGES-SETS."
  (cl-loop for packages-set in packages-sets
           when (not (null packages-set))
           do
           (cl-loop for package in packages-set
                    do
                    (cond ((symbolp package)
                           (nasy/-s-u-p package))
                          ((listp package)
                           (dolist (p package)
                             (nasy/-s-u-p p)))
                          (t (error "???"))))))

(defmacro sup (package &optional req)
  "Straight use PACKAGE and or require it if REQ."
  (when (and (listp package) (or (eq '\` (car package))
                                 (eq 'quote (car package))))
      (setq package (eval package)))
  (let ((pkg (if (symbolp package) package (car package)))
        bs)
    (push `(straight-use-package ',package) bs)
    (when (eval req)
      (if (eq (eval req) t)
          (push `(require ',pkg) bs)
        (push `(require ,req) bs)))
    (macroexp-progn (nreverse bs))))

6.4.4. Elpaca

https://github.com/progfolio/elpaca

Elpaca is an elisp package manager. It allows users to find, install, update, and remove third-party packages for Emacs. It is a replacement for the built-in Emacs package manager, package.el.

;; (eval-and-compile
;;   (declare-function elpaca-generate-autoloads "elpaca")
;;   (defvar elpaca-directory (expand-file-name "elpaca/" user-emacs-directory))
;;   (defvar elpaca-builds-directory (expand-file-name "builds/" elpaca-directory))
;;   (when-let* ((elpaca-repo (expand-file-name "repos/elpaca/" elpaca-directory))
;;               (elpaca-build (expand-file-name "elpaca/" elpaca-builds-directory))
;;               (elpaca-target (if (file-exists-p elpaca-build) elpaca-build elpaca-repo))
;;               (elpaca-url  "https://www.github.com/progfolio/elpaca.git")
;;               ((add-to-list 'load-path elpaca-target))
;;               ((not (file-exists-p elpaca-repo)))
;;               (buffer (get-buffer-create "*elpaca-bootstrap*")))
;;     (condition-case-unless-debug err
;;         (progn
;;           (unless (zerop (call-process "git" nil buffer t "clone" elpaca-url elpaca-repo))
;;             (error "%s" (list (with-current-buffer buffer (buffer-string)))))
;;           (byte-recompile-directory elpaca-repo 0 'force)
;;           (require 'elpaca)
;;           (elpaca-generate-autoloads "elpaca" elpaca-repo)
;;           (kill-buffer buffer))
;;       ((error)
;;        (delete-directory elpaca-directory 'recursive)
;;        (with-current-buffer buffer
;;          (goto-char (point-max))
;;          (insert (format "\n%S" err))
;;          (display-buffer buffer)))))
;;   (require 'elpaca-autoloads)
;;   (add-hook 'after-init-hook #'elpaca-process-queues)
;;   (elpaca (elpaca :host github :repo "progfolio/elpaca")))

6.4.5.

(defun nasy/-package-filter (name &rest _)
  "Ignore package NAME if *no-packages* is t."
  (let ((sym (intern (format "*no-%s*" name))))
    (if (and (boundp sym) sym)
        (progn
          (message "Ignore package: %s" name)
          nil)
      t)))

6.4.6. Leaf

;; (eval-and-compile
;;   (setq leaf-defaults '(:leaf-autoload nil :leaf-defun nil :leaf-defer t))
;;   (leaf-keywords-init))

;; (advice-add 'leaf :before-while #'nasy/-package-filter)

6.4.7. use-package

;; (eval-when-compile
;;   (require 'use-package)
;;   (require 'bind-key)

;;   (defalias 'use-package-normalize/:doc 'use-package-normalize-test)
;;   (defun use-package-handler/:doc (name keyword _ rest state)
;;     (use-package-process-keywords name rest state))
;;   (defalias 'use-package-normalize/:tag #'(lambda (&rest _) nil))
;;   (defalias 'use-package-handler/:tag 'use-package-handler/:doc)
;;   (defalias 'use-package-normalize/:url 'use-package-normalize-test)
;;   (defalias 'use-package-handler/:url 'use-package-handler/:doc)
;;   (add-to-list 'use-package-keywords :doc)
;;   (add-to-list 'use-package-keywords :tag)
;;   (add-to-list 'use-package-keywords :url)

;;   (unintern "use-package-autoloads/:hook" nil)
;;   (unintern "use-package-autoloads/:bind" nil)
;;   (advice-add 'use-package :before-while #'nasy/-package-filter))

;; (customize-set-variable 'use-package-always-defer t "Customized by Nasy.")

6.4.8. Setup EL

setup.el provides a macro to ease repetitive configuration patterns in Emacs. This is done by providing context sensitive local macros, that expand to regular, pure EmacsLisp.

The package is available on GnuELPA and is currently maintained by PhilipKaludercic on SourceHut: https://git.sr.ht/~pkal/setup.

Documentation is available at https://www.emacswiki.org/emacs/SetupEl

(sup 'setup)
(require 'setup)
(setup-define :doc
  (lambda (&rest _) nil)
  :documentation "The one line doc for the setup package.")
(setup-define :tag
  (lambda (&rest _) nil)
  :documentation "The one line doc for the setup package.")
(setup-define :url
  (lambda (&rest _) nil)
  :documentation "The one line doc for the setup package.")

(setup-define :sup
  (lambda (name) `(sup ',name))
  :documentation "Customize variables."
  :debug '(sexp)
  :repeatable t)

(setup-define :opt
  (lambda (name val) `(customize-set-variable ',name ,val "Customized by Nasy."))
  :documentation "Customize variables."
  :after-loaded t
  :repeatable t)

(setup-define :opt*
  (lambda (name val) `(customize-set-variable ',name ,val "Customized by Nasy."))
  :documentation "Customize variables."
  :debug '(sexp form)
  :repeatable t)

(setup-define :opts
  (lambda (nsv)
    (let ((names (car nsv))
          (val (cdr nsv))
          bs)
      (dolist (name (if (listp names) names (list names)))
        (push `(customize-set-variable ',name ,val "Customized by Nasy.") bs))
      (macroexp-progn (nreverse bs))))
  :documentation "Customize variables."
  :after-loaded t
  :repeatable t)

(setup-define :opts*
  (lambda (nsv)
    (let ((names (car nsv))
          (val (cdr nsv))
          bs)
      (dolist (name (if (listp names) names (list names)))
        (push `(customize-set-variable ',name ,val "Customized by Nasy.") bs))
      (macroexp-progn (nreverse bs))))
  :documentation "Customize variables."
  :repeatable t)

(setup-define :custom
  (lambda (name val) `(customize-set-variable ',name ,val "Customized by Nasy."))
  :documentation "Customize variables."
  :debug '(sexp form)
  :after-loaded t
  :repeatable t)

(setup-define :customs
  (lambda (nsv)
    (let ((names (car nsv))
          (val (cdr nsv))
          bs)
      (dolist (name (if (listp names) names (list names)))
        (push `(customize-set-variable ',name ,val "Customized by Nasy.") bs))
      (macroexp-progn (nreverse bs))))
  :documentation "Customize variables."
  :repeatable t)

(setup-define :customs*
  (lambda (names val)
    (let (bs)
      (dolist (name names)
        (push `(customize-set-variable ',name ,val "Customized by Nasy.") bs))
      (macroexp-progn (nreverse bs))))
  :documentation "Customize variables."
  :repeatable t)

(setup-define :hooks
  (lambda (hook func)
    `(add-hook ',hook #',func))
  :documentation "Add pairs of hooks."
  :repeatable t)

(setup-define :init
  (lambda (&rest body) (macroexp-progn body))
  :documentation "Init keywords like use-package and leaf.")

(setup-define :load-after
  (lambda (&rest features)
    (let ((body `(require ',(setup-get 'feature))))
      (dolist (feature (nreverse features))
        (setq body `(with-eval-after-load ',feature ,body)))
      body))
  :documentation "Load the current feature after FEATURES.")

(setup-define :load-first
  (lambda (&rest features)
    `(:first-key*
      (:load-after ,@features))))

(setup-define :after
  (lambda (feature &rest body)
    `(with-eval-after-load ',feature ,@body))
  :documentation "Eval BODY after FEATURE."
  :after-loaded t
  :indent 1)

(setup-define :after*
  (lambda (feature &rest body)
    `(with-eval-after-load ',feature ,@body))
  :documentation "Eval BODY after FEATURE."
  :indent 1)

(setup-define :quit
 #'setup-quit
 :documentation "Unconditionally abort the evaluation of the current body.")

(setup-define :first-key
  (lambda (name) `(add-hook 'nasy-first-key-hook #',name))
  :documentation "Add to `nasy-first-key-hook'."
  :repeatable t)

(setup-define :first-key*
  (lambda (&rest body) `(add-hook 'nasy-first-key-hook #'(lambda () (progn ,@body))))
  :documentation "Add to `nasy-first-key-hook'.")

(setup-define :first-org
  (lambda (name) `(add-hook 'nasy-org-first-key-hook #',name))
  :documentation "Add to `nasy-first-key-hook'."
  :repeatable t)

(setup-define :first-org*
  (lambda (&rest body) `(add-hook 'nasy-org-first-key-hook #'(lambda () (progn ,@body))))
  :documentation "Add to `nasy-first-key-hook'.")

(setup-define :advice
  (lambda (symbol where function)
    `(advice-add ',symbol ,where ,function))
  :documentation "Add a piece of advice on a function.
 See `advice-add' for more details."
  :after-loaded t
  :debug '(sexp sexp function-form)
  :ensure '(nil nil func)
  :repeatable t)

(setup-define :mode-hook
  (lambda (&rest body)
    `(add-hook ',(setup-get 'hook) #'(lambda () (progn ,@body))))
  :documentation "Add to the mode hook.")

(setup-define :autoload
  (lambda (func)
    (let ((fn (if (memq (car-safe func) '(quote function))
                  (cadr func)
                func)))
      `(unless (fboundp (quote ,fn))
         (autoload (function ,fn) ,(symbol-name (setup-get 'feature)) nil t))))
  :documentation "Autoload COMMAND if not already bound."
  :repeatable t
  :signature '(FUNC ...))

(setup-define :bindm
  (lambda (map &rest rest)
    `(:with-map ,map (:bind ,@rest)))
  :documentation "Bind keys in MAP."
  :debug '(sexp &rest form sexp)
  :ensure '(nil &rest kbd func)
  :indent 1)


(advice-add 'setup :before-while #'nasy/-package-filter)

6.4.9. 包之墬阯 load-path

straight 載入本墬包即可。

;; (defmacro nasy/local-repo (repo &rest body)
;;   "Nasy load local REPO."
;;   (let ((n-repo (symbol-name repo)))
;;     `(sup
;;       '(,(intern n-repo)
;;         ,@body
;;         :build nil
;;         :local-repo ,(expand-file-name
;;                       (format "桃夭/%s" (symbol-name repo))
;;                       user-emacs-directory)))))

(defmacro nasy/config-path (config)
  "Nasy CONFIG path."
  (locate-user-emacs-file
   (format "桃夭/%s" (symbol-name config))))


(defmacro nasy/extra-repo (repo &optional path &rest body)
  "Nasy extra local site-lisp REPO."
  (let ((path (or path (symbol-name repo))))
    `(sup
      '(,repo
        ,@body
        :local-repo ,(locate-user-emacs-file
                      (format "木瓜/%s" path))))))


(defmacro nasy/-repo (repo &rest body)
  "Nasy extra local site-lisp REPO."
  (let ((path (symbol-name repo)))
    `(sup
      '(,repo
        ,@body
        :local-repo ,(locate-user-emacs-file
                      (format "木瓜/nasy/%s" path))))))

6.4.10. melpa/elpa 之外

(straight-register-package
 '(keytar :type git
          :host github
          :repo "emacs-grammarly/keytar"))

(straight-register-package
 '(point-history :type git
                 :host github
                 :repo "blue0513/point-history"))

(straight-register-package
 '(vundo :type git
         :host github
         :repo "casouri/vundo"))

6.4.11. 載入

(sup '(org :type git
           :repo "https://git.tecosaur.net/tec/org-mode.git"
           :branch "dev"))
(sup 'org)
(sup 'org-contrib)
(sup 'gcmh)
6.4.11.1. 自定義

例子~芄蘭之例~、个人配置~芄蘭~與自定義~custom-file~

肰定義 custom-file 于此並無載入之意苟欲載入置 (load custom-file) 于个人配置 芄蘭 之內。

(add-to-list 'load-path *nasy-custom*)

(require '芄蘭)
6.4.11.2. 自定義例
;; (leaf custom-settings
;;   :custom
;;   ;; (calendar-latitude         . 24.8801)
;;   ;; (calendar-longitude        . 102.8329)
;;   ;; (user-mail-address         . "[email protected]")
;;   ;; (initial-buffer-choice     . #'(lambda () (get-buffer "*dashboard*")))
;;   ;; (diary-file                . ~/dairy/emacs-dairy)
;;   (*debug*                   . nil)
;;   (*theme*                   . 'nasy))

;; (leaf disabled-packages
;;   :custom
;;   ((*no-eldoc-overlay*
;;     *no-highlight-indent-guides*
;;     *no-indent-tools*
;;     *no-point-history*
;;     *no-tree-sitter-indent*)
;;    . t))

(setup custom-settings
  (:opt* *debug* nil
         *theme* 'nasy))

(setup disabled-packages
  (:opts*
   ((*no-eldoc-overlay*
     *no-highlight-indent-guides*
     *no-indent-tools*
     *no-point-history*
     *no-tree-sitter-indent*)
    . t)))

(provide '芄蘭之例)
6.4.11.3.
(eval-and-compile
  (message "載包: %s" (if nasy--require
                          "是"
                        "否"))
  (sup 'org nasy--require)
  (sup '(org :type git
             :repo "https://git.tecosaur.net/tec/org-mode.git"
             :branch "dev"))
  (sup 'org-contrib nasy--require)
  (sup 'gcmh nasy--require)
  (sup 'setup nasy--require)

  ;; 風雨
  (sup 'beacon nasy--require)
  (sup 'expand-region nasy--require)
  (sup 'flycheck nasy--require)
  (sup 'treemacs nasy--require)
  (sup 'avy nasy--require)
  (sup 'beacon nasy--require)
  (sup 'dashboard nasy--require)
  (sup 'doom-modeline nasy--require)
  (sup 'flycheck nasy--require)
  (sup 'ibuffer nasy--require)
  (sup 'projectile nasy--require)
  (sup 'smartparens nasy--require)
  (sup `(:local-repo ,(concat *nasy-site* "nasy/nasy-theme")
            :files ("彩.el"))
       nasy--require)

  ;; 緑衣
  (sup 'alert nasy--require)
  (sup 'anzu nasy--require)
  (sup 'avy nasy--require)
  (sup 'beginend nasy--require)
  (sup 'cape nasy--require)
  (sup 'company nasy--require)
  (sup 'consult nasy--require)
  (sup 'consult-dir nasy--require)
  (sup 'consult-flycheck nasy--require)
  (sup '(copilot :host github :repo "zerolfx/copilot.el"
                 :files ("dist" "*.el"))
       nasy--require)
  (sup '(copilot-chat :host github :repo "chep/copilot-chat.el"
                      :files ("*.el"))
       nasy--require)
  (sup 'corfu nasy--require)
  (sup `(corfu-extensions
         :local-repo ,(concat (straight--repos-dir "corfu") "extensions"))
       nasy--require)
  (sup 'easy-kill nasy--require)
  (sup 'elisp-demos nasy--require)
  (sup 'embark-consult nasy--require)
  (sup 'embark nasy--require)
  (sup 'flycheck nasy--require)
  (sup '(flx-rs :files (:defaults "bin")) nasy--require)
  ;; (sup '(flx-rs :repo "jcs-elpa/flx-rs"
  ;;        :host github
  ;;        :files (:defaults "bin"))
  ;;      nasy--require)
  (sup 'fussy nasy--require)
  (sup 'helpful nasy--require)
  (sup 'keyfreq nasy--require)
  (sup 'marginalia nasy--require)
  (sup 'orderless nasy--require)
  (sup 'page-break-lines nasy--require)
  (sup 'projectile nasy--require)
  (sup '(emacs-session
         :repo "https://git.sr.ht/~nasy/emacs-session"
         :type git
         :host nil)
       nasy--require)
  (sup 'savehist nasy--require)
  (sup 'spatial-navigate nasy--require)
  (sup 'sudo-edit nasy--require)
  (sup 'switch-window nasy--require)
  (sup 'transient nasy--require)
  (sup 'treesit-auto nasy--require)
  (sup 'unfill nasy--require)
  (sup 'valign nasy--require)
  (sup '(vertico :files (:defaults "extensions/*")) nasy--require)
  (sup 'vlf nasy--require)
  (sup 'wgrep nasy--require)
  (sup 'which-key nasy--require)
  (sup 'whitespace-cleanup-mode nasy--require)

  ;; 月出
  (sup 'abridge-diff nasy--require)
  (sup 'ansi-color nasy--require)
  (sup 'async nasy--require)
  (sup 'beacon nasy--require)
  (sup 'beacon nasy--require)
  (sup 'color-identifiers-mode nasy--require)
  (sup '(colorful-mode
         :repo "DevelopmentCool2449/colorful-mode"
         :host github)
       nasy--require)
  (sup 'corfu nasy--require)
  (sup 'default-text-scale nasy--require)
  (sup 'diff-hl nasy--require)
  (sup 'dired-collapse nasy--require)
  (sup 'dired-filter nasy--require)
  (sup 'dired-hacks nasy--require)
  (sup 'dired-narrow nasy--require)
  (sup 'dired-rainbow nasy--require)
  (sup 'dirvish nasy--require)
  (sup 'eldoc-box nasy--require)
  (sup 'eldoc-box nasy--require)
  (sup 'eldoc-overlay nasy--require)
  (sup 'expand-region nasy--require)
  (sup 'f nasy--require)
  (sup 'find-file-in-project nasy--require)
  (sup 'ftable nasy--require)
  (sup 'git-gutter nasy--require)
  (sup 'highlight-indent-guides nasy--require)
  (sup 'highlight-tail nasy--require)
  (sup 'imenu-list nasy--require)
  (sup 'kind-icon nasy--require)
  (sup 'license-snippets nasy--require)
  (sup 'mixed-pitch nasy--require)
  (sup 'mmm-mode nasy--require)
  (sup 'multiple-cursors nasy--require)
  (sup 'pcre2el nasy--require)
  (sup 'persistent-scratch nasy--require)
  (sup 'point-history nasy--require)
  (sup 'rainbow-delimiters nasy--require)
  (sup 'rainbow-mode nasy--require)
  (sup 'shellcop nasy--require)
  (sup 'smartparens nasy--require)
  (sup 'symbol-overlay nasy--require)

  (sup 'treemacs nasy--require)
  ;; (sup 'treemacs-icons-dired nasy--require)
  (sup 'treemacs-magit nasy--require)
  (sup 'treemacs-projectile nasy--require)
  (sup 'undo-propose nasy--require)
  (sup 'visual-fill-column nasy--require)
  (sup 'vundo nasy--require)
  (sup 'which-key nasy--require)
  (sup 'winum nasy--require)
  (sup 'writeroom-mode nasy--require)
  (sup 'yasnippet nasy--require)
  (sup 'yasnippet-snippets nasy--require)

  ;; (sup 'tsc nasy--require)
  ;; (sup 'tree-sitter nasy--require)
  ;; (sup 'tree-sitter-indent nasy--require)
  ;; (sup 'tree-sitter-langs nasy--require)
  ;; (sup '(ts-fold :type git :host github :repo "jcs090218/ts-fold") nasy--require)

  ;; 庭燎
  (sup 'nerd-icons nasy--require)
  (sup 'nerd-icons-completion nasy--require)
  (sup 'nerd-icons-ibuffer nasy--require)
  (sup 'treemacs-nerd-icons nasy--require)
  (sup 'consult nasy--require)
  (sup 'dash nasy--require)
  (sup 'projectile nasy--require)
  (sup 'cal-china-x nasy--require)
  (sup 'centaur-tabs nasy--require)
  (sup 'dashboard nasy--require)
  (sup 'doom-themes nasy--require)
  (sup 'pretty-mode nasy--require)
  (sup 'ligature nasy--require)
  (sup 'nyan-mode nasy--require)
  (sup 'minions nasy--require)
  (sup 'doom-modeline nasy--require)
  (sup `(nasy-theme :local-repo ,(concat *nasy-site* "nasy/nasy-theme")) nasy--require)

  ;; 日月
  (sup 'alert nasy--require)
  (sup 'carbon-now-sh nasy--require)
  (sup 'cheat-sh nasy--require)
  (sup 'rime nasy--require)
  (sup 'esup nasy--require)
  (sup 'explain-pause-mode nasy--require)
  (sup 'gptel nasy--require)
  (sup 'grab-mac-link nasy--require)
  (sup 'htmlize nasy--require)
  (sup 'indent-tools nasy--require)
  (sup 'list-unicode-display nasy--require)
  (sup 'magit nasy--require)
  (sup 'forge nasy--require)
  (sup 'magit-delta nasy--require)
  (sup 'magit-org-todos nasy--require)
  (sup 'magit-todos nasy--require)
  ;; (sup
  ;;  '(mind-wave :type git :host github :repo "manateelazycat/mind-wave"
  ;;              :files ("*.el" "*.py"))
  ;;  nasy--require)
  (sup '(openai :type git :host github :repo "emacs-openai/openai"))
  (sup '(nasy-emacs-ai :type git :host github :repo "nasyxx/nasy-emacs-ai")
       nasy--require)
  (sup 'pdf-tools nasy--require)
  (sup 'prettier nasy--require)
  (sup 'request nasy--require)
  (sup 'svg-clock nasy--require)
  (with-no-warnings
    (setq vterm-always-compile-module t))
  (sup 'vterm nasy--require)
  (sup '(vterm-toggle :build (:not native-compile)) nasy--require)
  (sup 'wakatime-mode nasy--require)

  ;; 麐之趾
  (sup 'apheleia nasy--require)
  (sup 'cdlatex nasy--require)
  (sup 'reformatter nasy--require)
  (sup `(bibtex-tidy :local-repo ,(concat *nasy-site* "nasy/bibtex-tidy-mode"))
       nasy--require)
  (sup 'lsp-mode nasy--require)
  (sup 'lsp-ui nasy--require)
  (sup 'lsp-treemacs nasy--require)
  (sup `(flex-mode :local-repo ,(concat *nasy-site* "villadora")) nasy--require)
  (sup 'haskell-mode nasy--require)
  (sup 'lsp-haskell nasy--require)
  (sup 'dap-mode nasy--require)
  (sup 'elisp-def nasy--require)
  (sup 'highlight-quoted nasy--require)
  (sup '(ipretty :type git :repo "https://framagit.org/steckerhalter/ipretty.git")
       nasy--require)
  (sup 'macrostep nasy--require)
  (with-no-warnings
    (setq parinfer-rust-auto-download nil
     parinfer-rust-library
     (concat *nasy-var* "parinfer-rust/parinfer-rust-darwin.so")))
  (sup 'parinfer-rust-mode nasy--require)
  (sup 'auctex nasy--require)
  (sup 'markdown-mode nasy--require)
  (sup 'nix-mode nasy--require)
  (sup '(nushell-mode :type git :host github :repo "azzamsa/emacs-nushell"))
  (sup 'citeproc nasy--require)
  (sup
   '(org-ai :type git :host github :repo "rksm/org-ai"
            :local-repo "org-ai"
            :files ("*.el" "README.md" "snippets"))
   nasy--require)
  (sup 'org-appear nasy--require)
  (sup 'org-fragtog nasy--require)
  (sup 'org-latex-impatient nasy--require)
  (sup '(org-margin :host github :repo "rougier/org-margin") nasy--require)
  (sup 'org-modern nasy--require)
  (sup '(org-rainbow-tags :host github :repo "KaratasFurkan/org-rainbow-tags")
       nasy--require)
  (sup 'org-roam nasy--require)
  (sup 'elpy nasy--require)
  (sup 'python-􀝦black nasy--require)
  (sup 'lsp-pyright nasy--require)
  (sup `(lsp-basedpyright :local-repo ,(concat *nasy-site* "nasy/lsp-basedpyright")))
  (sup `(lsp-pylance :local-repo ,(concat *nasy-site* "nasy/lsp-pylance")))
  (sup `(python-isort :local-repo ,(concat *nasy-site* "nasy/python-isort"))
       nasy--require)
  (sup 'restclient nasy--require)
  (sup 'company-restclient nasy--require)
  (sup 'ob-restclient nasy--require)
  (sup 'yaml-mode nasy--require)
  (sup 'ob-elvish nasy--require)
  (sup 'elvish-mode nasy--require)
  (sup '(typst-ts-mode :host sourcehut :type git :repo "meow_king/typst-ts-mode")
       nasy--require)
  (sup '(typst-preview :host github :repo "havarddj/typst-preview.el") nasy--require)
  ;; (sup 'toml-mode nasy--require)

  ;; 小曐
  (sup 'git-blamed nasy--require)
  (sup 'git-messenger nasy--require)
  (sup 'git-modes nasy--require)
  (sup 'git-timemachine nasy--require)
  (sup 'wgrep nasy--require)
  (sup 'rg nasy--require)
  (sup 'company-dict nasy--require)
  (sup 'company-math nasy--require)
  (sup 'flycheck-package nasy--require)
  (sup 'ibuffer-vc nasy--require)
  ;; (sup 'all-the-icons-ibuffer nasy--require)
  (sup 'nix-buffer nasy--require)
  (sup 'nix-update nasy--require)
  (sup 'nixpkgs-fmt nasy--require)
  (sup 'thingopt nasy--require)
  (sup 'haskell-snippets nasy--require))

6.5. 風雨

(add-to-list 'load-path (locate-user-emacs-file  "桃夭/風雨"))
(require '風雨)
(add-hook 'nasy-first-key-hook #'(lambda () (require '風雨時用)))

風雨淒淒、雞鳴喈喈
既見君子、云胡不夷

風雨瀟瀟、雞鳴膠膠
既見君子、云胡不瘳

風雨如晦、雞鳴不已
既見君子、云胡不喜

函數與宏定製其文宜其用之

6.5.1. 恆用之

6.5.1.1.
(defvar nasy/config-before-hook nil
  "Hook to run config functions before load custom.el.")

(defvar nasy/config-after-hook nil
  "Hook to run config functions after load custom.el.")

(add-hook 'nasy/config-after-hook
          #'(lambda () (message "Hi~ Hope you have fun with this config.")))

(defvar nasy--defer-loads nil
  "Nasy defer load packages.")

(defvar nasy--defer-load-hook nil
  "Nasy defer load hook.")
6.5.1.2. 函數
(defun nasy/change-char-width (char width)
  "Change CHAR width to WIDTH."
  (let ((table (make-char-table nil)))
    (set-char-table-parent table char-width-table)
    (set-char-table-range table char width)
    (setq char-width-table table)))


;;;###autoload
(defun nasy/enlist (exp)
 "Return EXP wrapped in a list, or as-is if already a list."
 (declare (pure t) (side-effect-free t))
 (if (listp exp) exp (list exp)))


(defun nasy/run-hook-once-on (hook on-hook)
  "Run HOOK on ON-HOOK once."
  (let ((fn (intern (format "nasy-once-hook--%s-on-%s" hook on-hook)))
        (hook* hook))
    (fset
     fn
     (lambda (&rest _)
       (run-hooks hook*)
       (set hook* nil)))
    (add-hook on-hook fn)))

(defun nasy/defer-load ()
  (nasy/sup nasy--defer-loads)
  (run-hooks 'nasy--defer-load-hook))

(add-hook 'nasy-first-key-hook #'nasy/defer-load -1)


;;;###autoload
(defun stop-minimizing-window ()
  "Stop minimizing window under macOS."
  (interactive)
  (unless (and *is-a-mac*
               window-system)
    (suspend-frame)))


;;;###autoload
(defun transparency (value)
  "Sets the transparency of the frame window. 0=transparent/100=opaque"
  (interactive "nTransparency Value 0 - 100 opaque:")
  (set-frame-parameter (selected-frame) 'alpha-background value))


;;;###autolaod
(defun toggle-transparency ()
  "Toggle transparency."
  (interactive)
  (let ((alpha-background (frame-parameter nil 'alpha-background)))
     (set-frame-parameter
      nil 'alpha-background
      (if (eql (cond ((numberp alpha-background) alpha-background)
                     ((numberp (cdr alpha-background)) (cdr alpha-background))
                     ;; Also handle undocumented (<active> <inactive>) form.
                     ((numberp (cadr alpha-background)) (cadr alpha-background)))
               100)
          70
        100))))
6.5.1.3.
(cl-eval-when (compile eval load)
  (if (fboundp 'with-eval-after-load)
      (defalias 'after-x 'with-eval-after-load)
    (defmacro after-x (feature &rest body)
      "Eval BODY afetr FEATURE have loaded."
      (declare (indent defun))
      `(eval-after-load ,feature
         '(progn ,@body)))))
6.5.1.4. 字軆
(defvar nasy/font-change-hook nil
  "Hooks to run after font changed.")

(defvar nasy--cus-font nil)
(defvar nasy--set-font nil)

(defun nasy/-set-font (&rest _)
  "Font."
  (setq nasy--set-font t)
  (setup nasy-font
    (:doc "字軆初值")
    (:opt*
     *font-main-family*   "MonoLisa Nasy"  ;; "Monaspace Radon Var"
     *font-symbol-family* "SF Pro"
     *font-nerd-family*   "Symbols Nerd Font Mono"
     *font-cjk-family*    "STFLGQKJF"
     *font-cjk-2-family*  "FZLiuGongQuanKaiShuJF"
     ;; I.Ngaan' font from `http://founder.acgvlyric.org/iu/doku.php/造字:開源字型_i.顏體'.
     *font-cjk-3-family*  "I.Ngaan"
     *font-cjk-4-family*  "Kaiti SC"
     *font-cjk-5-family*  "Kaiti TC"
     *font-math-family*   "Euler Math")
    (:opts*
     ((*font-mode-line-family*
       *font-header-line-family*
       *font-tab-line-family*)
      . "Recursive Mono Casual Static"))
    (:opt*
     *font-main-size*        14
     *font-mode-line-size*   14
     *font-tab-line-size*    13
     *font-symbol-size*      17
     *font-header-line-size* 12

     *font-main-weight* 'medium)
    (:opts*
     ((*font-cjk-size*
       *font-cjk-2-size*
       *font-cjk-3-size*
       *font-cjk-4-size*
       *font-cjk-5-size*)
      . nil)
     ((*font-cjk-scale*
       *font-cjk-2-scale*
       *font-cjk-3-scale*
       *font-cjk-4-scale*
       *font-cjk-5-scale*)
      . 1.3)
     ((*font-symbol-weight*
       ;; *font-cjk-4-weight*
       ;; *font-cjk-5-weight*
       *font-mode-line-weight*
       *font-tab-line-weight*
       *font-header-line-weight*

       *font-cjk-weight*
       *font-cjk-2-weight*
       *font-cjk-3-weight*)
      . 'normal)

     ((*font-cjk-4-weight*
       *font-cjk-5-weight*)
      . 'bold)))
  (require '芄蘭 nil t))


(cl-eval-when (compile eval load)
  (defun nasy/-font-doc (cname ftype)
    "Generate font custome variable doc with CNAME and FTYPE."
    (concat "The " cname " font " ftype ".
     After change it, run `M-x nasy/set-font' to see the effect."))


  (defun nasy/-cus-font ()
    "Defcustom some fonts."
    (setq nasy--cus-font t)
    (dolist (cname '("main" "symbol" "cjk" "mode-line" "tab-line" "header-line"))
      (cl-loop for ftype in '("family" "weight" "size" "scale")
               for type = (cond ((string= "family" ftype) 'string)
                              ((string= "weight" ftype) 'symbol)
                              ((string= "size" ftype)   'float)
                              ((string= "scale" ftype)  'float)
                              (t (error "Wrong Font Type")))
               for doc  = (nasy/-font-doc cname ftype)
               for name = (intern (format "*font-%s-%s*" cname ftype))
               do
               (progn
                 (custom-declare-variable name nil doc :group 'nasy-font :type type)
                 (when (string= "cjk" cname)
                   (cl-loop for sfxn in '(2 3 4 5)
                            for cname_ = (format "%s-%d" cname sfxn)
                            for name_  = (intern (format "*font-%s-%s*" cname_ ftype))
                            for doc_   = (nasy/-font-doc cname_ ftype)
                            do
                            (progn
                              (custom-declare-variable name_ nil doc_
                                                       :group 'nasy-font
                                                       :type type)))))))))


(cl-eval-when (compile)
  (nasy/-cus-font)
  (nasy/-set-font))


(defun nasy/check-font (font)
  "Check if FONT avaliable."
  (if (find-font (font-spec :family font))
      t
    (message (format "`%s' font not find" font))))

(defun nasy/set-default-font (charset &optional size frame)
  "Set CHARSET fontset to default *font-main* with SIZE on FRAME."
  (when (and (display-graphic-p)
            (nasy/check-font *font-main-family*))
    (let ((size (or size *font-main-size*)))
      (set-fontset-font t
                        charset
                        (font-spec :family *font-main-family*
                                   :weight *font-main-weight*
                                   :size   size)
                        frame
                        'prepend))))


(defun nasy/set-hanamin (charset &optional size frame)
  "Set CHARSET fontset to HanaMin with SIZE on FRAME.
 https://github.com/cjkvi/HanaMinAFDKO/releases
 Font for char like 𨉚."
  (when (display-graphic-p)
    (let ((size (or size *font-cjk-size*)))
      (when (nasy/check-font "HanaMinB")
        (set-fontset-font (frame-parameter nil 'font)
                          charset
                          (font-spec :family "HanaMinB"
                                     :weight 'normal
                                     :size   size)
                          frame
                          'prepend))
      (when (nasy/check-font "HanaMinA")
        (set-fontset-font (frame-parameter nil 'font)
                          charset
                          (font-spec :family "HanaMinA"
                                     :weight 'normal
                                     :size   size)
                          frame
                          'prepend))
      (setf (alist-get ".*HanaMinA.*" face-font-rescale-alist *font-cjk-scale* nil 'string=)
            *font-cjk-scale*)
      (setf (alist-get ".*HanaMinB.*" face-font-rescale-alist *font-cjk-scale* nil 'string=)
            *font-cjk-scale*)
      (cl-loop for sfx in (reverse '("A" "B" "C" "Ex A1" "Ex A2" "Ex B" "Ex C" "I"))
               for hfont = (concat "Hanazono Mincho " sfx)
               do
               (progn
                 (when (nasy/check-font hfont)
                   (set-fontset-font (frame-parameter nil 'font)
                                     charset
                                     (font-spec :family hfont
                                                :weight 'normal
                                                :size   size)
                                     frame
                                     'prepend))

                (setf (alist-get (format ".*%s.*" hfont)
                                 face-font-rescale-alist
                                 *font-cjk-scale*
                                 nil
                                 'string=)
                      *font-cjk-scale*))))))

(defun nasy/set-symbol (charset &optional size weight frame)
    "Set CHARSET fontset to Symbol with SIZE with WEIGHT on FRAME.

  Font for char like ∷."
    (when (display-graphic-p)
      (let ((size (or size *font-symbol-size*)))
        (when (nasy/check-font *font-symbol-family*)
          (set-fontset-font (frame-parameter nil 'font)
                            charset
                            (font-spec :family *font-symbol-family*
                                       :weight weight
                                       :size   size)
                            frame
                            'prepend)))))


(defun nasy/set-apple-symbol (charset &optional frame)
    "Set CHARSET fontset to Apple Color Emoji with SIZE with WEIGHT on FRAME.

  Font for char like ∷."
    (when (display-graphic-p)
      (when (nasy/check-font "SF Pro")
        (set-fontset-font (frame-parameter nil 'font)
                          charset
                          (font-spec :family "SF Pro")
                          frame
                          'prepend))))


(defun nasy/set-nerd-fonts (&optional font-family frame)
  "Modify nerd font charsets to use FONT-FAMILY for FRAME."
  (when (nasy/check-font (or font-family *font-nerd-family*))
    (let ((font-f (or font-family *font-nerd-family*))
          (charsets '((#xe5fa . #xe631)  ;; Seti-UI + Custom
                      (#xe700 . #xe7c5)  ;; Devicons
                      (#xf000 . #xf2e0)  ;; Font Awesome
                      (#xe200 . #xe2a9)  ;; Font Awesome Extension
                      (#xf500 . #xfd46) (#xf0001 . #xf1af0)  ;; Material Design Icons
                      (#xe300 . #xe3eb)  ;; Weather
                      (#xf400 . #xf4a9) #x2665 #x26A1  ;; Octicons
                      (#xe0a0 . #xe0a2) (#xe0b0 . #xe0b3)  ;; Powerline Symbols
                      #xe0a3 (#xe0b4 . #xe0c8) #xe0ca (#xe0cc . #xe0d4)  ;; Powerline Extra Symbols
                      (#x23fb . #x23fe) #x2b58  ;; IEC Power Symbols
                      (#xf300 . #xf32d)  ;; Font Logos
                      (#xe000 . #xe00a)  ;; Pomicons
                      (#xea60 . #xebeb))))  ;; Codicons
      (cl-loop for charset in charsets do
               (set-fontset-font
                (frame-parameter nil 'font)
                charset
                (font-spec :family font-f
                           :weight nil
                           :size   nil)
                frame
                'prepend)))))


(defun nasy/-set--font (frame)
  "Nasy set font for `FRAME'."
  (unless nasy--cus-font
    (nasy/-cus-font))
  (unless nasy--set-font
    (nasy/-set-font))
  (when (display-graphic-p)
    ;; default
    (when (nasy/check-font *font-main-family*)
      (set-face-attribute
          'default nil
          :font (font-spec :family *font-main-family*
                           :weight *font-main-weight*
                           :size   *font-main-size*)))
    ;; 中文
    (dolist (charset '(kana han cjk-misc bopomofo))
      (progn
        (nasy/set-hanamin charset)
        (cl-loop for fn in (reverse '("" "-2" "-3" "-4" "-5"))
                 for fpf = (format "*font-cjk%s" fn)
                 for ff  = (eval (intern (concat fpf "-family*")))
                 for fw  = (eval (intern (concat fpf "-weight*")))
                 ;; for fs  = (eval (intern (concat fpf "-size*")))
                 for fss = (eval (intern (concat fpf "-scale*")))
                 do
                 (progn
                   (when (nasy/check-font ff)
                     (set-fontset-font (frame-parameter nil 'font)
                                       charset
                                       (font-spec :family ff
                                                  :weight fw)
                                                  ;; :size   fs)
                                       frame
                                       'prepend))
                   (let ((ffn (concat ".*" ff ".*")))
                     (setf (alist-get ffn face-font-rescale-alist fss nil 'string=) fss))))))

   ;; nerd font
   (nasy/set-nerd-fonts nil frame)
   (when (and *is-a-mac*
              (nasy/check-font "SF Pro"))
     ;; For NS/Cocoa
     (set-fontset-font (frame-parameter nil 'font)
                       'symbol
                       (font-spec :family "SF Pro")
                       frame
                       'prepend))

   (when (nasy/check-font *font-symbol-family*)
     (set-fontset-font (frame-parameter nil 'font)
                       'symbol
                       (font-spec :family *font-symbol-family*
                                  :weight *font-symbol-weight*
                                  :size   *font-symbol-size*)
                       frame
                       'append)
     (set-fontset-font (frame-parameter nil 'font)
                       'unicode
                       (font-spec :family *font-symbol-family*
                                  :weight *font-symbol-weight*
                                  :size   *font-symbol-size*)
                       frame
                       'append))

   (when (nasy/check-font "Apple Color Emoji")
     (set-fontset-font (frame-parameter nil 'font)
                       'symbol
                       (font-spec :family "Apple Color Emoji")
                       frame
                       'append)
     (set-fontset-font (frame-parameter nil 'font)
                       'unicode
                       (font-spec :family "Apple Color Emoji")
                       frame
                       'append))

   (when (nasy/check-font *font-math-family*)
     (set-fontset-font (frame-parameter nil 'font)
                       (cons #x1D400 #x1D7FF)
                       (font-spec :family *font-math-family*)
                       frame
                       'prepend)
     (set-fontset-font (frame-parameter nil 'font)
                       (cons #x2100 #x214f)
                       (font-spec :family *font-math-family*)
                       frame
                       'prepend))

   (when (nasy/check-font *font-mode-line-family*)
     (set-face-attribute 'mode-line nil
                         :font (font-spec :family *font-mode-line-family*
                                          :weight *font-mode-line-weight*
                                          :size   *font-mode-line-size*))

     (set-face-attribute 'mode-line-inactive nil
                         :font (font-spec :family *font-mode-line-family*
                                          :weight *font-mode-line-weight*
                                          :size   *font-mode-line-size*)))
   (when (nasy/check-font *font-tab-line-family*)
     (set-face-attribute 'tab-line nil
                         :font (font-spec :family *font-tab-line-family*
                                          :weight *font-tab-line-weight*
                                          :size   *font-tab-line-size*)))
   (when (nasy/check-font *font-header-line-family*)
     (set-face-attribute 'header-line nil
                         :font (font-spec :family *font-header-line-family*
                                          :weight *font-header-line-weight*
                                          :size   *font-header-line-size*))))

    ;; (after-x 'doom-modeline
       ;;     (doom-modeline--set-char-widths doom-modeline-rhs-icons-alist))

  (run-hooks 'nasy/font-change-hook))


(defun nasy/set-font (&rest _)
  "Nasy set font."
  (interactive)
  (message "setting font...")
  (nasy/-set--font nil)
  (message "setting font...done"))

(add-hook 'emacs-startup-hook #'nasy/-set-font 98)
(add-hook 'emacs-startup-hook #'nasy/-cus-font 97)
;; (add-hook 'after-init-hook #'nasy/set-font)
(add-hook 'emacs-startup-hook #'nasy/set-font 99)
;; (add-hook 'nasy-first-key-hook #'nasy/set-font)
;; (add-hook 'after-make-frame-functions #'nasy/set-font)

(when noninteractive
  (nasy/set-font))
6.5.1.5. 光幖
(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)))))


(add-hook 'nasy-first-key-hook
          #'(lambda ()
              (advice-add 'blink-cursor-timer-function :before
                          #'nasy/blink-cursor-timer-function)))
6.5.1.6. 定製
6.5.1.6.1.
(defgroup nasy nil
  "Nasy Emacs Custom Configurations."
  :group 'emacs)

(defgroup nasy-font nil
  "Nasy Emacs Custom Font Configurations."
  :group 'nasy)

(defcustom lisp-modes-hooks '(common-lisp-mode-hook
                              emacs-lisp-mode-hook
                              lisp-mode-hook
                              lisp-interaction-mode-hook
                              racket-mode-hook
                              scheme-mode-hook)
  "List of lisp-related modes hooks."
  :type '(repeat symbol)
  :group 'nasy)

(defmacro lisp-modes-hooks-add (func)
  "Add FUNC to all lisp-related modes hooks."
  (let ((bs))
    (dolist (hook lisp-modes-hooks)
      (push `(add-hook ',hook #',func) bs))
    (macroexp-progn bs)))

(defcustom *theme* 'nasy-theme
  "The Theme."
  :group 'nasy
  :type 'symbol)

(defun nasy/-cus-emacs ()
  "Nasy customize emacs misc variable."
  (customize-set-variable 'colon-double-space    nil "Customized by Nasy.")
  (customize-set-variable 'cursor-type           'box "Customized by Nasy.")
  (customize-set-variable 'custom-raised-buttons nil "Customized by Nasy.")
  (customize-set-variable 'help-window-select    t "Customized by Nasy.")
  (customize-set-variable 'make-backup-files     nil "Customized by Nasy.")
  (customize-set-variable 'mouse-yank-at-point   t "Customized by Nasy.")
  (customize-set-variable 'mouse-drag-and-drop-region-cross-program
                          t "Customized by Nasy.")
  (customize-set-variable 'resize-mini-windows   t "Customized by Nasy.")
  (customize-set-variable 'scroll-conservatively 5 "Customized by Nasy.")
  (customize-set-variable 'scroll-margin         5 "Customized by Nasy.")
  (customize-set-variable 'tab-always-indent     'complete "Customized by Nasy.")
  (customize-set-variable 'use-dialog-box        nil "Customized by Nasy.")
  (customize-set-variable 'use-file-dialog       nil "Customized by Nasy.")
  (customize-set-variable 'word-wrap-by-category t   "Customized by Nasy.")

  (customize-set-variable 'enable-recursive-minibuffers t "Customized by Nasy.")

  (customize-set-variable 'ediff-split-window-function
                          'split-window-horizontally "Customized by Nasy.")
  (customize-set-variable 'ediff-window-setup-function
                          'ediff-setup-windows-plain "Customized by Nasy.")

  (setq-default indent-tabs-mode nil)

  (fset 'yes-or-no-p 'y-or-n-p)

  (column-number-mode 1)
  (delete-selection-mode 1)
  (display-battery-mode 1)
  (global-auto-revert-mode 1)
  (minibuffer-depth-indicate-mode 1)
  (save-place-mode 1)
  (pixel-scroll-precision-mode 1))


(add-hook 'nasy-first-key-hook #'nasy/-cus-emacs)
6.5.1.6.2.
(defun nasy/-insert-backslash ()
  (interactive)
  (insert-char ?\\))

(defun n/kill-line-0 ()
  (interactive)
  (kill-line 0))

(defun nasy/-cus-mac ()
  "Customize macOS."
  (setup mac
    (:only-if *is-a-mac*)
    (:opt*
     mac-function-modifier      'super
     mac-option-modifier        'meta
     mac-command-modifier       'hyper
     mac-right-command-modifier 'super
     mac-right-option-modifier  'alt
     default-frame-alist '((ns-transparent-titlebar . t)
                           (ns-appearance           . light)
                           (alpha-background        . 70)
                           (vertical-scroll-bars    . nil)
                           (undecorated-round       . t)
                           (border-width            . 5)
                           (internal-border-width   . 24)))
    (:global
     "C-z"   stop-minimizing-window
     "M-¥"   nasy/-insert-backslash
     "A-¥"   nasy/-insert-backslash
     "A-C-¥" toggle-input-method
     [remap list-buffers] ibuffer

     ;; cursor Movement
     "H-<up>"   beginning-of-buffer
     "H-<down>" end-of-buffer
     "H-l"      goto-line

     ;; text Operations
     "H-a"  mark-whole-buffer
     "H-v"  yank
     "H-c"  kill-ring-save
     "H-s"  save-buffer
     "H-z"  undo
     "H-w"  delete-window
     "H-<backspace>" n/kill-line-0

     ;; Tab
     "H-t" dashboard-refresh-buffer)
    (:init
     ;; unset
     (global-unset-key (kbd "<magnify-down>"))
     (global-unset-key (kbd "<magnify-up>")))))

(add-hook 'emacs-startup-hook #'nasy/-cus-mac)

6.5.2. 時用之

主勭使用。

;;; 風雨時用.el --- Nasy's emacs.d core file.  -*- lexical-binding: t; -*-
(cl-eval-when (compile)
  (add-to-list 'load-path (locate-user-emacs-file "桃夭/擊鼓"))
  (add-to-list 'load-path (locate-user-emacs-file "桃夭/風雨"))
  (require '擊鼓)
  (require '風雨)

  (require 'compile)
  (require 'winner)

  (sup 'apheleia t)
  (sup 'avy t)
  (sup 'expand-region t)
  (sup 'flycheck t)
  (sup 'nasy-emacs-ai t)
  (sup 'org t)
  (sup 'projectile t)
  (sup 'smartparens t)
  (sup 'treemacs t)
  (with-no-warnings
    (setq vterm-always-compile-module t))
  (sup 'vterm t)
  (sup '(vterm-toggle :build (:not native-compile)) t)
  (sup `(:local-repo ,(concat *nasy-site* "nasy/nasy-theme")
            :files ("彩.el"))
       t))
6.5.2.1.
(defvar nasy-file-sym-t '((".config/nasy-emacs" . ".emacs.d")))
6.5.2.2. 函數
;;;###autoload
(defun nasy/file-sym-t (file)
  "Trans true file name to symlink file name."
  (cl-loop for (from . to) in nasy-file-sym-t
           do
           (setq file (string-replace from to file))
           return file))


;;;###autoload
(defun nasy/file-truename (file)
  "Get the true name of FILE."
  (if (or (file-remote-p file nil t)
          (not (file-remote-p file)))
      (file-truename file)
    file))


;;;###autoload
(defun nasy/p-ignore-p (truename)
  "Determine whether ignore the `TRUENAME' file or not."
  (or (string-match-p "nix/store" truename)
      nil))


;;;###autoload
(defun nasy/unquote (exp)
  "Return EXP unquoted."
  (declare (pure t) (side-effect-free t))
  (while (memq (car-safe exp) '(quote function))
    (setq exp (cadr exp)))
  exp)


;;;###autoload
(defun posframe-poshandler-frame-top-center (info)
  "Make posframe INFO top center."
  (cons (/ (- (plist-get info :parent-frame-width)
              (plist-get info :posframe-width))
           2)
        (round (* 0.02 (x-display-pixel-height)))))


;;;###autoload
(defun nasy/wfw1 (&rest _)
  "Widget forward 1."
  (interactive)
  (widget-forward 1))


;;;###autoload
(defun nasy/fw2 (&rest _)
  "Forward 2 chars."
  (interactive "p")
  (forward-char 2))


;;;###autoload
(defun nasy/閒置 ()
  "閒置 Emacs."
  (interactive)
  (dashboard-refresh-buffer)
  (delete-other-windows))


;;;###autoload
(defun nasy/-open-custom ()
  "Open custom 芄蘭.el."
  (interactive)
  (find-file (concat *nasy-custom* "芄蘭.el")))


;;;###autoload
(defun nasy/-open-source-page ()
  "Open source page."
  (interactive)
  (browse-url "https://github.com/nasyxx/emacs.d/"))


;;;###autoload
(defun nasy/-open-document ()
  "Open document."
  (interactive)
  (browse-url "https://emacs.nasy.moe/"))


;;;###autoload
(defun nasy/clear-text-overlay ()
  "Clear text overlay."
  (interactive)
  (let ((inhibit-read-only t))
    (set-text-properties (point-min) (point-max) nil)))


;;;###autoload
(defun nasy/up-directory (arg)
  "Move up a directory ARGth times."
  (interactive "p")
  (if minibuffer-completing-file-name
      (if (string-match-p "/." (minibuffer-contents))
          (zap-up-to-char (- arg) ?/)
        (delete-minibuffer-contents))
    (backward-kill-word arg)))
6.5.2.3. 重新加載 user-init-file 文件
;;;###autoload
(defun nasy/reload-init ()
  "Reload init.el."
  (interactive)
  (message "Reloading init.el...")
  (load user-init-file nil 'nomessage)
  (message "Reloading init.el... done."))


;;;###autoload
(defun nasy/eval-buffer-or-region (&optional start end)
  "Evaluate the current region, or the whole buffer if no region is active.
In Lisp code, START and END denote the region to be evaluated;
they default to `point-min' and `point-max' respectively.
If evaluating a buffer visiting this file, then delegate instead
to `nasy/reload-init'."
  (interactive)
  (if (and buffer-file-name
           (member (file-truename buffer-file-name)
                   (list
                    (when (bound-and-true-p early-init-file)
                      (file-truename early-init-file))
                    (file-truename user-init-file)))
           (not (region-active-p)))
      (nasy/reload-init)
    (let ((name nil))
      (if (region-active-p)
          (progn
            (setq start (region-beginning))
            (setq end (region-end))
            (setq name "region"))
        (setq start (point-min))
        (setq end (point-max))
        (setq name (buffer-name)))
      (let ((load-file-name (buffer-file-name)))
        (message "Evaluating %s..." name)
        (eval-region start end)
        (message "Evaluating %s...done" name)))))
6.5.2.4. 臿入時間
;;;###autoload
(defun nasy/insert-current-date ()
  "Insert current date."
  (interactive)
  (insert (shell-command-to-string "echo -n $(date +'%b %d, %Y')")))

;;;###autoload
(defun nasy/insert-current-filename ()
  "Insert current buffer filename."
  (interactive)
  (insert (file-relative-name buffer-file-name)))
6.5.2.5. buffer 相關
;;;###autoload
(defvar nasy/real-buffer-functions
  '(nasy/dired-buffer-p)
  "A list of predicate functions run to determine if a buffer is real, unlike
`nasy/unreal-buffer-functions'. They are passed one argument: the buffer to be
tested.
Should any of its function returns non-nil, the rest of the functions are
ignored and the buffer is considered real.
See `nasy/real-buffer-p' for more information.")

;;;###autoload
(defvar nasy/unreal-buffer-functions
  '(minibufferp nasy/special-buffer-p nasy/non-file-visiting-buffer-p)
  "A list of predicate functions run to determine if a buffer is *not* real,
unlike `nasy/real-buffer-functions'. They are passed one argument: the buffer to
be tested.
Should any of these functions return non-nil, the rest of the functions are
ignored and the buffer is considered unreal.
See `nasy/real-buffer-p' for more information.")

;;;###autoload
(defvar-local nasy/real-buffer-p nil
  "If non-nil, this buffer should be considered real no matter what. See
`nasy/real-buffer-p' for more information.")

;;;###autoload
(defvar nasy/fallback-buffer-name "*scratch*"
  "The name of the buffer to fall back to if no other buffers exist (will create
it if it doesn't exist).")


;;
;; Functions

;;;###autoload
(defun nasy/buffer-frame-predicate (buf)
  "To be used as the default frame buffer-predicate parameter. Returns nil if
BUF should be skipped over by functions like `next-buffer' and `other-buffer'."
  (or (nasy/real-buffer-p buf)
      (eq buf (nasy/fallback-buffer))))

;;;###autoload
(defun nasy/fallback-buffer ()
  "Returns the fallback buffer, creating it if necessary. By default this is the
scratch buffer. See `nasy/fallback-buffer-name' to change this."
  (let (buffer-list-update-hook)
    (get-buffer-create nasy/fallback-buffer-name)))

;;;###autoload
(defalias 'nasy/buffer-list #'buffer-list)


;;;###autoload
(defun nasy/project-root (&optional dir)
  "Return the project root of DIR (defaults to `default-directory').
Returns nil if not in a project."
  (let ((projectile-project-root
         (unless dir (bound-and-true-p projectile-project-root)))
        projectile-require-project-root)
    (projectile-project-root dir)))


;;;###autoload
(defun nasy/project-buffer-list (&optional project)
  "Return a list of buffers belonging to the specified PROJECT.
If PROJECT is nil, default to the current project.
If no project is active, return all buffers."
  (let ((buffers (nasy/buffer-list)))
    (if-let* ((project-root
               (if project (expand-file-name project)
                 (nasy/project-root))))
        (cl-loop for buf in buffers
                 if (projectile-project-buffer-p buf project-root)
                 collect buf)
      buffers)))

;;;###autoload
(defun nasy/open-projects ()
  "Return a list of projects with open buffers."
  (cl-loop with projects = (make-hash-table :test 'equal :size 8)
           for buffer in (nasy/buffer-list)
           if (buffer-live-p buffer)
           if (nasy/real-buffer-p buffer)
           if (with-current-buffer buffer (nasy/project-root))
           do (puthash (abbreviate-file-name it) t projects)
           finally return (hash-table-keys projects)))

;;;###autoload
(defun nasy/dired-buffer-p (buf)
  "Returns non-nil if BUF is a dired buffer."
  (with-current-buffer buf (derived-mode-p 'dired-mode)))

;;;###autoload
(defun nasy/special-buffer-p (buf)
  "Returns non-nil if BUF's name starts and ends with an *."
  (equal (substring (buffer-name buf) 0 1) "*"))

;;;###autoload
(defun nasy/temp-buffer-p (buf)
  "Returns non-nil if BUF is temporary."
  (equal (substring (buffer-name buf) 0 1) " "))

;;;###autoload
(defun nasy/visible-buffer-p (buf)
  "Return non-nil if BUF is visible."
  (get-buffer-window buf))

;;;###autoload
(defun nasy/buried-buffer-p (buf)
  "Return non-nil if BUF is not visible."
  (not (nasy/visible-buffer-p buf)))

;;;###autoload
(defun nasy/non-file-visiting-buffer-p (buf)
  "Returns non-nil if BUF does not have a value for `buffer-file-name'."
  (not (buffer-file-name buf)))

;;;###autoload
(defun nasy/real-buffer-list (&optional buffer-list)
  "Return a list of buffers that satify `nasy/real-buffer-p'."
  (cl-remove-if-not #'nasy/real-buffer-p (or buffer-list (nasy/buffer-list))))

;;;###autoload
(defun nasy/real-buffer-p (buffer-or-name)
  "Returns t if BUFFER-OR-NAME is a =real= buffer.
A real buffer is a useful buffer; a first class citizen in Doom. Real ones
should get special treatment, because we will be spending most of our time in
them. Unreal ones should be low-profile and easy to cast aside, so we can focus
on real ones.
The exact criteria for a real buffer is:
  1. A non-nil value for the buffer-local value of the `nasy/real-buffer-p'
     variable OR
  2. Any function in `nasy/real-buffer-functions' returns non-nil OR
  3. None of the functions in `nasy/unreal-buffer-functions' must return
     non-nil.
If BUFFER-OR-NAME is omitted or nil, the current buffer is tested."
  (or (bufferp buffer-or-name)
      (stringp buffer-or-name)
      (signal 'wrong-type-argument (list '(bufferp stringp) buffer-or-name)))
  (when-let* (buf (get-buffer buffer-or-name))
    (and (buffer-live-p buf)
         (not (nasy/temp-buffer-p buf))
         (or (buffer-local-value 'nasy/real-buffer-p buf)
             (run-hook-with-args-until-success 'nasy/real-buffer-functions buf)
             (not (run-hook-with-args-until-success 'nasy/unreal-buffer-functions buf))))))

;;;###autoload
(defun nasy/unreal-buffer-p (buffer-or-name)
  "Return t if BUFFER-OR-NAME is an =unreal= buffer.
See `nasy/real-buffer-p' for details on what that means."
  (not (nasy/real-buffer-p buffer-or-name)))

;;;###autoload
(defun nasy/buffers-in-mode (modes &optional buffer-list derived-p)
  "Return a list of buffers whose `major-mode' is `eq' to MODE(S).
If DERIVED-P, test with `derived-mode-p', otherwise use `eq'."
  (let ((modes (nasy/enlist modes)))
    (cl-remove-if-not (if derived-p
                          (lambda (buf)
                            (with-current-buffer buf
                              (apply #'derived-mode-p modes)))
                        (lambda (buf)
                          (memq (buffer-local-value 'major-mode buf) modes)))
                      (or buffer-list (nasy/buffer-list)))))

;;;###autoload
(defun nasy/visible-windows (&optional window-list)
  "Return a list of the visible, non-popup (dedicated) windows."
  (cl-loop for window in (or window-list (window-list))
           when (or (window-parameter window 'visible)
                    (not (window-dedicated-p window)))
           collect window))

;;;###autoload
(defun nasy/visible-buffers (&optional buffer-list)
  "Return a list of visible buffers (i.e. not buried)."
  (if buffer-list
      (cl-remove-if-not #'get-buffer-window buffer-list)
    (delete-dups (mapcar #'window-buffer (window-list)))))

;;;###autoload
(defun nasy/buried-buffers (&optional buffer-list)
  "Get a list of buffers that are buried."
  (cl-remove-if #'get-buffer-window (or buffer-list (nasy/buffer-list))))

;;;###autoload
(defun nasy/matching-buffers (pattern &optional buffer-list)
  "Get a list of all buffers that match the regex PATTERN."
  (cl-loop for buf in (or buffer-list (nasy/buffer-list))
           when (string-match-p pattern (buffer-name buf))
           collect buf))

;;;###autoload
(defun nasy/set-buffer-real (buffer flag)
  "Forcibly mark BUFFER as FLAG (non-nil = real)."
  (with-current-buffer buffer
    (setq nasy/real-buffer-p flag)))

;;;###autoload
(defun nasy/kill-buffer-and-windows (buffer)
  "Kill the buffer and delete all the windows it's displayed in."
  (dolist (window (get-buffer-window-list buffer))
    (unless (one-window-p t)
      (delete-window window)))
  (kill-buffer buffer))

;;;###autoload
(defun nasy/fixup-windows (windows)
  "Ensure that each of WINDOWS is showing a real buffer or the fallback buffer."
  (dolist (window windows)
    (with-selected-window window
      (when (nasy/unreal-buffer-p (window-buffer))
        (previous-buffer)
        (when (nasy/unreal-buffer-p (window-buffer))
          (switch-to-buffer (nasy/fallback-buffer)))))))

;;;###autoload
(defun nasy/kill-buffer-fixup-windows (buffer)
  "Kill the BUFFER and ensure all the windows it was displayed in have switched
to a real buffer or the fallback buffer."
  (let ((windows (get-buffer-window-list buffer)))
    (kill-buffer buffer)
    (nasy/fixup-windows (cl-remove-if-not #'window-live-p windows))))

;;;###autoload
(defun nasy/kill-buffers-fixup-windows (buffers)
  "Kill the BUFFERS and ensure all the windows they were displayed in have
switched to a real buffer or the fallback buffer."
  (let ((seen-windows (make-hash-table :test 'eq :size 8)))
    (dolist (buffer buffers)
      (let ((windows (get-buffer-window-list buffer)))
        (kill-buffer buffer)
        (dolist (window (cl-remove-if-not #'window-live-p windows))
          (puthash window t seen-windows))))
    (nasy/fixup-windows (hash-table-keys seen-windows))))

;;;###autoload
(defun nasy/-kill-matching-buffers (pattern &optional buffer-list)
  "Kill all buffers (in current workspace OR in BUFFER-LIST) that match the
regex PATTERN. Returns the number of killed buffers."
  (let ((buffers (nasy/matching-buffers pattern buffer-list)))
    (dolist (buf buffers (length buffers))
      (kill-buffer buf))))


;;
;; Hooks

;;;###autoload
(defun nasy/mark-buffer-as-real-h ()
  "Hook function that marks the current buffer as real."
  (nasy/set-buffer-real (current-buffer) t))


;;
;; Interactive commands

;;;###autoload
(defun nasy/kill-this-buffer-in-all-windows (buffer &optional dont-save)
  "Kill BUFFER globally and ensure all windows previously showing this buffer
have switched to a real buffer or the fallback buffer.
If DONT-SAVE, don't prompt to save modified buffers (discarding their changes)."
  (interactive
   (list (current-buffer) current-prefix-arg))
  (cl-assert (bufferp buffer) t)
  (when (and (buffer-modified-p buffer) dont-save)
    (with-current-buffer buffer
      (set-buffer-modified-p nil)))
  (nasy/kill-buffer-fixup-windows buffer))


(defun nasy/message-or-count (interactive message count)
  (if interactive
      (message message count)
    count))

;;;###autoload
(defun nasy/kill-all-buffers (&optional buffer-list interactive)
  "Kill all buffers and closes their windows.
If the prefix arg is passed, doesn't close windows and only kill buffers that
belong to the current project."
  (interactive
   (list (if current-prefix-arg
             (nasy/project-buffer-list)
           (nasy/buffer-list))
         t))
  (if (null buffer-list)
      (message "No buffers to kill")
    (save-some-buffers)
    (delete-other-windows)
    (when (memq (current-buffer) buffer-list)
      (switch-to-buffer (nasy/fallback-buffer)))
    (mapc #'kill-buffer buffer-list)
    (nasy/message-or-count
     interactive "Killed %d buffers"
     (- (length buffer-list)
        (length (cl-remove-if-not #'buffer-live-p buffer-list))))))

;;;###autoload
(defun nasy/kill-other-buffers (&optional buffer-list interactive)
  "Kill all other buffers (besides the current one).
If the prefix arg is passed, kill only buffers that belong to the current
project."
  (interactive
   (list (delq (current-buffer)
               (if current-prefix-arg
                   (nasy/project-buffer-list)
                 (nasy/buffer-list)))
         t))
  (mapc #'nasy/kill-buffer-and-windows buffer-list)
  (nasy/message-or-count
   interactive "Killed %d other buffers"
   (- (length buffer-list)
      (length (cl-remove-if-not #'buffer-live-p buffer-list)))))

;;;###autoload
(defun nasy/kill-matching-buffers (pattern &optional buffer-list interactive)
  "Kill buffers that match PATTERN in BUFFER-LIST.
If the prefix arg is passed, only kill matching buffers in the current project."
  (interactive
   (list (read-regexp "Buffer pattern: ")
         (if current-prefix-arg
             (nasy/project-buffer-list)
           (nasy/buffer-list))
         t))
  (nasy/-kill-matching-buffers pattern buffer-list)
  (when interactive
    (message "Killed %d buffer(s)"
             (- (length buffer-list)
                (length (cl-remove-if-not #'buffer-live-p buffer-list))))))

;;;###autoload
(defun nasy/kill-buried-buffers (&optional buffer-list interactive)
  "Kill buffers that are buried.
If PROJECT-P (universal argument), only kill buried buffers belonging to the
current project."
  (interactive
   (list (nasy/buried-buffers
          (if current-prefix-arg (nasy/project-buffer-list)))
         t))
  (mapc #'kill-buffer buffer-list)
  (nasy/message-or-count
   interactive "Killed %d buried buffers"
   (- (length buffer-list)
      (length (cl-remove-if-not #'buffer-live-p buffer-list)))))

;;;###autoload
(defun nasy/kill-project-buffers (project &optional interactive)
  "Kill buffers for the specified PROJECT."
  (interactive
   (list (if-let (open-projects (nasy/open-projects))
             (completing-read
              "Kill buffers for project: " open-projects
              nil t nil nil
              (if-let* ((project-root (nasy/project-root))
                        (project-root (abbreviate-file-name project-root))
                        ((member project-root open-projects)))
                  project-root))
           (message "No projects are open!")
           nil)
         t))
  (when project
    (let ((buffer-list (nasy/project-buffer-list project)))
      (nasy/kill-buffers-fixup-windows buffer-list)
      (nasy/message-or-count
       interactive "Killed %d project buffers"
       (- (length buffer-list)
          (length (cl-remove-if-not #'buffer-live-p buffer-list)))))))


;;;###autoload
(defun nasy/kill-buffers-no-company-box ()
  "Kill all buffers except company box buffers."
  (interactive)
  (nasy/kill-all-buffers
   (cl-loop for buffer in (nasy/buffer-list)
          when (not (string-match-p "company-box" (buffer-name buffer)))
          collect buffer)))


;;;###autoload
(defun nasy/scratch ()
  "Switch buffer to scratch."
  (interactive)
  (switch-to-buffer "*scratch*"))
6.5.2.6. 布局相關
;; When splitting window, show (other-buffer) in the new window
(defun split-window-func-with-other-buffer (split-function)
  "Split window with `SPLIT-FUNCTION'."
  (lambda (&optional arg)
    "Split this window and switch to the new window unless ARG is provided."
    (interactive "P")
    (funcall split-function)
    (let ((target-window (next-window)))
      (set-window-buffer target-window (other-buffer))
      (unless arg
        (select-window target-window)))))

(defun split-window--v ()
  "Split window vertically."
  (interactive)
  (split-window-func-with-other-buffer 'split-window-vertically))

(defun split-window--h ()
  "Split window horizontcally."
  (interactive)
  (split-window-func-with-other-buffer 'split-window-horizontally))

(defun toggle-delete-other-windows ()
  "Delete other windows in frame if any, or restore previous window config."
  (interactive)
  (if (and winner-mode
           (equal (selected-window) (next-window)))
      (winner-undo)
    (delete-other-windows)))

(defun split-window-horizontally-instead ()
  "Kill any other windows and re-split such that
      the current window is on the top half of the frame."
  (interactive)
  (let ((other-buffer (and (next-window) (window-buffer (next-window)))))
    (delete-other-windows)
    (split-window-horizontally)
    (when other-buffer
      (set-window-buffer (next-window) other-buffer))))

(defun split-window-vertically-instead ()
  "Kill any other windows and re-split such that
      the current window is on the left half of the frame."
  (interactive)
  (let ((other-buffer (and (next-window) (window-buffer (next-window)))))
    (delete-other-windows)
    (split-window-vertically)
    (when other-buffer
      (set-window-buffer (next-window) other-buffer))))

  ;; Borrowed from http://postmomentum.ch/blog/201304/blog-on-emacs
(defun nasy/split-window()
  "Split the window to see the most recent buffer in the other window.
  Call a second time to restore the original window configuration."
  (interactive)
  (if (eq last-command 'nasy-split-window)
      (progn
        (jump-to-register :nasy-split-window)
        (setq this-command 'nasy-unsplit-window))
    (window-configuration-to-register :nasy/split-window)
    (switch-to-buffer-other-window nil)))
6.5.2.7. 文字處理
;;;###autoload
(defun nasy/delete-backward-word (arg)
  "Like `backward-kill-word', but doesn't affect the kill-ring."
  (interactive "p")
  (let (kill-ring)
    (backward-kill-word arg)))

;;;###autoload
(defun nasy/region-active-p ()
  "Return non-nil if selection is active."
  (declare (side-effect-free t))
  (use-region-p))

;;;###autoload
(defun nasy/region-beginning ()
  "Return beginning position of selection."
  (declare (side-effect-free t))
  (region-beginning))

;;;###autoload
(defun nasy/region-end ()
  "Return end position of selection."
  (declare (side-effect-free t))
  (region-end))

;;;###autoload
(defun nasy/thing-at-point-or-region (&optional thing prompt)
  "Grab the current selection, THING at point, or xref identifier at point.
Returns THING if it is a string. Otherwise, if nothing is found at point and
PROMPT is non-nil, prompt for a string (if PROMPT is a string it'll be used as
the prompting string). Returns nil if all else fails.
NOTE: Don't use THING for grabbing symbol-at-point. The xref fallback is smarter
in some cases."
  (declare (side-effect-free t))
  (cond ((stringp thing)
         thing)
        ((nasy/region-active-p)
         (buffer-substring-no-properties
          (nasy/region-beginning)
          (nasy/region-end)))
        (thing
         (thing-at-point thing t))
        ((require 'xref nil t)
         ;; A little smarter than using `symbol-at-point', though in most cases,
         ;; xref ends up using `symbol-at-point' anyway.
         (xref-backend-identifier-at-point (xref-find-backend)))
        (prompt
         (read-string (if (stringp prompt) prompt "")))))

;;;###autoload
(defalias 'default/newline #'newline)

;;;###autoload
(defun default/newline-above ()
  "Insert an indented new line before the current one."
  (interactive)
  (beginning-of-line)
  (save-excursion (newline))
  (indent-according-to-mode))

;;;###autoload
(defun default/newline-below ()
  "Insert an indented new line after the current one."
  (interactive)
  (end-of-line)
  (newline-and-indent))

;;;###autoload
(defun default/yank-pop ()
  "Interactively select what text to insert from the kill ring."
  (interactive)
  (call-interactively
   (cond ((fboundp 'counsel-yank-pop)    #'counsel-yank-pop)
         ((fboundp 'helm-show-kill-ring) #'helm-show-kill-ring)
         ((error "No kill-ring search backend available. Enable ivy or helm!")))))

;;;###autoload
(defun default/yank-buffer-filename ()
  "Copy the current buffer's path to the kill ring."
  (interactive)
  (if-let* ((filename (or buffer-file-name (bound-and-true-p list-buffers-directory))))
      (message (kill-new (abbreviate-file-name filename)))
    (error "Couldn't find filename in current buffer")))

;;;###autoload
(defun default/insert-file-path (arg)
  "Insert the file name (absolute path if prefix ARG).
If `buffer-file-name' isn't set, uses `default-directory'."
  (interactive "P")
  (let ((path (or buffer-file-name default-directory)))
    (insert
     (if arg
         (abbreviate-file-name path)
       (file-name-nondirectory path)))))

;;;###autoload
(defun default/newline-indent-and-continue-comments-a ()
  "A replacement for `newline-and-indent'.
Continues comments if executed from a commented line, with special support for
languages with weak native comment continuation support (like C-family
languages)."
  (interactive)
  (if (and (sp-point-in-comment)
           comment-line-break-function)
      (funcall comment-line-break-function nil)
    (delete-horizontal-space t)
    (newline nil t)
    (indent-according-to-mode)))


(defun nasy/insert-zero-width-space ()
  "Insert a zero width space \u200b."
  (interactive)
  (insert "\u200b"))
6.5.2.8. 挈壺   benchmark
(defmacro nasy/timer (&rest body)
  "Measure and return the time it takes evaluating BODY."
  `(let ((time (current-time)))
     ,@body
     (float-time (time-since time))))
6.5.2.9. 模式
6.5.2.9.1. 激活區域
(defvar nasy/active-region--on nil)

(defun nasy/on--active-region ()
  (nasy/active-region--mode 1))

(defun nasy/off--active-region ()
  (nasy/active-region--mode -1))

(defvar nasy/active-region-map (make-sparse-keymap))


;;;###autoload
(define-minor-mode nasy/active-region--mode
  "Actized region or not."
  :keymap nasy/active-region-map)


;;;###autoload
(define-minor-mode nasy/active-region-mode
  "Actived region or not."
  :lighter "n/ar"
  (if nasy/active-region-mode
      (progn
        (nasy/off--active-region)
        (add-hook 'activate-mark-hook   #'nasy/on--active-region)
        (add-hook 'deactivate-mark-hook #'nasy/off--active-region))
    (remove-hook 'activate-mark-hook   #'nasy/on--active-region)
    (remove-hook 'deactivate-mark-hook #'nasy/off--active-region)
    (nasy/off--active-region)))
6.5.2.9.2. 快捷鍵
(defun nasy/-set-key-map ()
  "Nasy Set keymap for config."
  (define-key global-map (kbd "s-SPC") #'nasy/insert-zero-width-space))


(defun nasy/-unset-key-map ()
  "Nasy Unet keymap for config."
  (define-key global-map (kbd "s-SPC") nil))


(defun nasy/-keymap ()
  "Define nasy key map."
  (define-keymap :parent mode-specific-map
    "a"     (define-keymap :prefix 'nasy-ai-map
              ;; "r" #'org-ai-talk-capture-in-org
              "Z" #'nasy-ai-tozh-at-point
              "z" #'nasy-ai-tozh)
    "c"     (define-keymap :prefix 'nasy-code-map
              "c" #'compile
              "C" #'recompile
              "t" #'vterm-toggle
              "x" #'flycheck-list-errors
              "f" #'apheleia-format-buffer)
    "e"     (define-keymap :prefix 'nasy-edit-map
              "a"   #'avy-goto-char
              "c"   #'comment-line
              "e"   #'er/expand-region
              "SPC" #'nasy/insert-zero-width-space)
    "t"     (define-keymap :prefix 'nasy-treemacs-map
              "t" #'treemacs
              "1" #'treemacs-delete-other-windows
              "B" #'treemacs-bookmark
              "f" #'treemacs-find-file)
    "o"     (define-keymap :prefix 'nasy-org-map
              "b" #'org-tree-to-indirect-buffer)
    "y"     (define-keymap :prefix 'nasy-yas-map
              "n" #'yas-new-snippet)))


(define-minor-mode nasy-keybinding-mode
  "Nasy Keybinding Mode."
  :init-value nil
  :lighter "n/k"
  (if nasy-keybinding-mode
      (progn
        (let ((keymap (nasy/-keymap)))
          (define-key global-map "\C-c" keymap))

        (nasy/-set-key-map))

    (define-key global-map "\C-c" mode-specific-map)
    (nasy/-unset-key-map)))


(setup nasy-keybinding
  (:hook-into nasy-org-first-key-hook
              prog-mode-hook
              text-mode-hook))
6.5.2.9.3. 光影
(defun beacon--shine-b ()
  "Shine a beacon at point."
  (let ((colors (beacon--color-range)))
    (save-excursion
      ;; (backward-char 1)
      (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
                                backward-char
                                backward-word
                                delete-char
                                delete-backward-char
                                backward-delete-char-untabify
                                move-beginning-of-line
                                org-beginning-of-line
                                org-beginning-of-item
                                org-beginning-of-block
                                org-delete-backward-char
                                org-metaleft))
         (beacon-blink))
        ((member this-command '(right-char
                                forward-char
                                forward-word
                                self-insert-command
                                move-end-of-line
                                org-end-of-line
                                org-end-of-item
                                org-end-of-block
                                org-metaright))
         (nasy/beacon-blink))))

(define-minor-mode nasy-beacon-cursor-mode
  "Nasy beacon on moving cursor."
  :lighter "n/bc"
  :global t
  :group 'nasy
  (if nasy-beacon-cursor-mode
      (add-hook 'pre-command-hook #'nasy/blink)
    (remove-hook 'pre-command-hook #'nasy/blink)))

(nasy-beacon-cursor-mode 1)
6.5.2.10.
(provide '風雨時用)
;;; 風雨時用.el ends here

6.6. 緑衣

(add-to-list 'load-path (locate-user-emacs-file  "桃夭/緑衣"))
(require '緑衣)
(require ')

國風・邶風・緑衣

緑兮衣兮、緑衣黃裹
心之憂矣、曷維其已

緑兮衣兮、緑衣黃裳
心之憂矣、曷維其亡

緑兮絲兮、女所治兮
我恖古人、俾無訧兮

絺兮綌兮、淒其以風
我恖古人、實獲我心

永不弃者載入于初始之時也

Permanent configuration file.

You cannot disable anything here.

6.6.1.

6.6.1.1. Anzu   search tools

anzu.el is an Emacs port of anzu.vim. anzu.el provides a minor mode which displays current match and total matches information in the mode-line in various search modes.

https://github.com/emacsorphanage/anzu

(setup anzu
  (:doc "anzu.el is an Emacs port of anzu.vim.")
  (:url "https://github.com/emacsorphanage/anzu")
  (:tag "search" "tools")
  (:first-key global-anzu-mode)
  (:global
   [remap query-replace]        anzu-query-replace
   [remap query-replace-regexp] anzu-query-replace-regexp))
6.6.1.2. Avy   point location

Jump to things in Emacs tree-style.

https://github.com/abo-abo/avy

(setup avy
  (:doc "Jump to things in Emacs tree-style.")
  (:url "https://github.com/abo-abo/avy")
  (:tag "point" "location")
  (:opt
   avy-keys '(?a ?o ?e ?u ?i ?d ?h ?t ?n ?s)) ;; for dvorak
  (:global
   "C-;"     avy-goto-char
   "C-:"     avy-goto-char-2
   ;; "C-'"     avy-goto-char-2
   ;; "C-`"     avy-goto-char-2
   "M-g e"   avy-goto-word-0
   "M-g w"   avy-goto-word-1
   ;; "C-~"     avy-goto-word-1
   "C-c C-j" avy-resume))
6.6.1.3. Beginend   editing

Emacs package to redefine M-< and M-> for some modes

https://github.com/DamienCassou/beginend

(setup beginend
  (:doc "Emacs package to redefine M-< and M-> for some modes")
  (:url "https://github.com/DamienCassou/beginend")
  (:tag "editing")
  (:first-key beginend-global-mode))
6.6.1.4. Compile   builtin
(defvar nasy/last-compilation-buffer nil
  "The last buffer in which compilation took place.")

(defun nasy/save-compilation-buffer (&rest _)
  "Save the compilation buffer to find it later."
  (setq nasy/last-compilation-buffer next-error-last-buffer))

(defun alert-after-compilation-finish (buf result)
  "Use `alert' to report compilation RESULT if BUF is hidden."
  (when (buffer-live-p buf)
    (unless (catch 'is-visible
              (walk-windows (lambda (w)
                              (when (eq (window-buffer w) buf)
                                (throw 'is-visible t))))
              nil)
      (alert (concat "Compilation " result)
             :buffer buf
             :category 'compilation
             :title "Emacs"))))

(setup compile
  (:tag "builtin")
  (:advice compilation-start :after nasy/save-compilation-buffer)
  (:global [f6] recompile)
  (:with-hook compilation-finish-functions (:hook alert-after-compilation-finish)))
6.6.1.5. Consult   extensions

consult.el - Consulting completing-read.

https://github.com/minad/consult

Include consult & consult-flycheck.

6.6.1.5.1. consult
(defun nasy/consult-line-symbol-at-point ()
  "Consult line with symbol at point."
  (interactive)
  (consult-line (thing-at-point 'symbol)))

(setup consult
  (:doc "consult.el - Consulting completing-read")
  (:url "https://github.com/minad/consult")
  (:tag "extensions")
  (:load-first vertico)
  (:opt
   consult-narrow-key "C-.")
  (:with-hook completion-list-mode-hook
    (:hook consult-preview-at-point-mode))
  (:global
   [remap switch-to-buffer]              consult-buffer
   [remap switch-to-buffer-other-window] consult-buffer-other-window
   [remap switch-to-buffer-other-frame]  consult-buffer-other-frame

   [remap bookmark-jump]      consult-bookmark
   [remap goto-line]          consult-goto-line
   [remap imenu]              consult-imenu
   [remap multi-occur]        consult-line-multi
   [remap recentf-open-files] consult-recent-file
   [remap yank-pop]           consult-yank-replace

    "C-s"   consult-line
    "C-S-s" nasy/consult-line-symbol-at-point)
  (:when-loaded
    (:require consult-xref)
    (consult-customize
     consult-theme
     :preview-key '("M-."
                    :debounce 3 "<up>" "<down>"
                    :debounce 1 any)
     consult-ripgrep consult-git-grep consult-grep
     consult-bookmark consult-recent-file consult-xref
     consult--source-recent-file consult--source-project-recent-file
     consult--source-bookmark consult-buffer
     :preview-key '("M-."
                    :debounce 5 "<up>" "<down>"
                    :debounce 5 any))))
6.6.1.5.2. consult-flycheck
(setup consult-flycheck
  (:doc "consult.el - Consulting completing-read")
  (:url "https://github.com/minad/consult")
  (:tag "extensions")
  (:load-first consult)
  (:with-map  flycheck-command-map
    (:bind
      "!" consult-flycheck)))
6.6.1.5.3. consult-dir   convenience

Consult-dir allows you to easily select and switch between “active” directories.

https://github.com/karthink/consult-dir

(setup consult-dir
  (:doc "consult-dir: switch directories easily in Emacs")
  (:url "https://github.com/karthink/consult-dir")
  (:tag "convenience")
  (:load-first consult)
  (:global
   "C-x C-d" consult-dir)
  (:with-map minibuffer-local-completion-map
    (:bind
      "C-x C-d" consult-dir
      "C-x C-j" consult-dir-jump-file))
  (:after vertico
    (:with-map vertico-map
      (:bind
        "C-x C-d" consult-dir
        "C-x C-j" consult-dir-jump-file))))
6.6.1.6. Dired   files

DiredMode is the mode of a Dired buffer. It shows a directory (folder) listing that you can use to perform various operations on files and subdirectories in the directory. The operations you can perform are numerous, from creating subdirectories to byte-compiling files, searching files, and of course visiting (editing) files.

https://www.emacswiki.org/emacs/DiredMode

(setup dired
  (:doc "DiredMode is the mode of a Dired buffer.")
  (:url "https://www.emacswiki.org/emacs/DiredMode")
  (:tag "files")
  (:bindm dired-mode-map
    [mouse-2] dired-find-file
    "C-c C-p" wdired-change-to-wdired-mode)
  (:opt
   insert-directory-program (or (executable-find "gls")
                                (executable-find "ls"))
   dired-recursive-deletes 'top))
6.6.1.7. Easy Kill   killing convenience

Provide commands easy-kill and easy-mark to let users kill or mark things easily.

https://github.com/leoliu/easy-kill

(setup easy-kill
  (:doc "Kill & Mark Things Easily in Emacs.")
  (:url "https://github.com/leoliu/easy-kill")
  (:tag "killing" "convenience")
  (:global
   [remap kill-ring-save] easy-kill
   [remap mark-sexp]      easy-mark))
6.6.1.8. Eldoc   builtin docs help
(setup eldoc
  (:opt eldoc-documentation-strategy #'eldoc-documentation-compose
        eldoc-echo-area-use-multiline-p t))
6.6.1.9. Emacs Spatial Navigate   editing

Spatial navigation in Emacs.

https://gitlab.com/ideasman42/emacs-spatial-navigate

(setup spatial-navigate
  (:doc "Spatial navigation in Emacs.")
  (:url "https://gitlab.com/ideasman42/emacs-spatial-navigate")
  (:tag "editing")
  (:global "<C-p>" spatial-navigate-backward-vertical-bar
           "<C-n>" spatial-navigate-forward-vertical-bar
           "<M-b>" spatial-navigate-backward-horizontal-bar
           "<M-f>" spatial-navigate-forward-horizontal-bar
           "<M-up>" spatial-navigate-backward-vertical-box
           "<M-down>" spatial-navigate-forward-vertical-box
           "<H-left>" spatial-navigate-backward-horizontal-box
           "<H-right>" spatial-navigate-forward-horizontal-box))
6.6.1.10. embark   convenience

Emacs Mini-Buffer Actions Rooted in Keymaps.

https://github.com/oantolin/embark/

(defun embark-act-noquit ()
  "Run action but don't quit the minibuffer afterwards."
  (interactive)
  (let ((embark-quit-after-action nil))
    (embark-act)))

(defun embark-which-key-indicator ()
  "An embark indicator that displays keymaps using which-key.
 The which-key help message will show the type and value of the
 current target followed by an ellipsis if there are further
 targets."
  (lambda (&optional keymap targets prefix)
    (if (null keymap)
        (which-key--hide-popup-ignore-command)
      (which-key--show-keymap
       (if (eq (plist-get (car targets) :type) 'embark-become)
           "Become"
         (format "Act on %s '%s'%s"
                 (plist-get (car targets) :type)
                 (embark--truncate-target (plist-get (car targets) :target))
                 (if (cdr targets) "…" "")))
       (if prefix
           (pcase (lookup-key keymap prefix 'accept-default)
             ((and (pred keymapp) km) km)
             (_ (key-binding prefix 'accept-default)))
         keymap)
       nil nil t (lambda (binding)
                   (not (string-suffix-p "-argument" (cdr binding))))))))

(defun embark-hide-which-key-indicator (fn &rest args)
  "Hide the which-key indicator immediately
      when using the completing-read prompter."
  (which-key--hide-popup-ignore-command)
  (let ((embark-indicators
         (remq #'embark-which-key-indicator embark-indicators)))
    (apply fn args)))

(defun embark-live-vertico ()
  "Shrink Vertico minibuffer when `embark-live' is active."
  (when-let* (win (and (string-prefix-p "*Embark Live" (buffer-name))
                       (active-minibuffer-window)))
    (with-selected-window win
      (when (and (bound-and-true-p vertico--input)
                 (fboundp 'vertico-multiform-unobtrusive))
        (vertico-multiform-unobtrusive)))))

(setup embark
  (:doc "Emacs Mini-Buffer Actions Rooted in Keymaps.")
  (:url "https://github.com/oantolin/embark")
  (:tag "convenience")
  (:load-first vertico consult embark-consult)
  (:global
   [remap describe-bindings] embark-bindings
   "C-," embark-dwim)
  (:bindm embark-file-map
    "s" sudo-edit)
  (:after vertico
    (:bindm vertico-map
      "M-o" embark-act)
    (add-to-list 'embark-indicators #'embark-which-key-indicator))
  (:after 風雨時用
    (:bindm nasy/active-region-map
      "M-o" embark-act))
  (:with-mode embark-collect-mode
    (:hook embark-live-vertico))
  (:when-loaded
    ;; Hide the mode line of the Embark live/completions buffers
    (add-to-list 'display-buffer-alist
                 '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
                   nil
                   (window-parameters (mode-line-format . none))))))


(setup embark-consult
  (:load-first consult)
  (:with-mode embark-collect-mode
    (:hook consult-preview-at-point-mode)))
6.6.1.11. Flycheck   convenience languages tools

Modern on-the-fly syntax checking extension for GNU Emacs.

flycheck.org

https://github.com/flycheck/flycheck

(setup flycheck
  (:doc "On the fly syntax checking for GNU Emacs.")
  (:url "https://github.com/flycheck/flycheck")
  (:tag "convenience" "languages" "tools")
  (:hook-into prog-mode)
  (:opt
   flycheck-display-errors-function #'flycheck-display-error-messages-unless-error-list
   flycheck-check-syntax-automatically '(save idle-change mode-enabled)
   flycheck-display-errors-delay       0.25)
  (:bindm flycheck-error-list-mode-map
    "C-n" flycheck-error-list-next-error
    "C-p" flycheck-error-list-previous-error
    "RET" flycheck-error-list-goto-error
    [return]  flycheck-error-list-goto-error)
  (:when-loaded
   (add-to-list 'display-buffer-alist
                `(,(rx bos "*Flycheck errors*" eos)
                  (display-buffer-reuse-window
                   display-buffer-in-side-window)
                  (side            . bottom)
                  (reusable-frames . visible)
                  (window-height   . 0.33)))
   (defalias 'show-error-at-point-soon
     'flycheck-show-error-at-point)
   (add-to-list 'flycheck-emacs-lisp-checkdoc-variables 'sentence-end-double-space)))
6.6.1.12. Fussy   completion matching

Emacs completion-style leveraging flx.

This is a package to provide a completion-style to Emacs that is able to leverage flx as well as various other fuzzy matching scoring packages to provide intelligent scoring and sorting.

This package is intended to be used with packages that leverage completion-styles, e.g. completing-read and completion-at-point-functions.

https://github.com/jojojames/fussy

(setup fussy
  (:doc "Emacs completion-style leveraging flx.")
  (:url "https://github.com/jojojames/fussy")
  (:tag "completion" "matching")
  (:first-key*
   (require 'orderless)
   (require 'fussy))
  (:when-loaded (flx-rs-load-dyn))
  (:opt fussy-score-fn 'fussy-flx-rs-score
        fussy-use-cache nil
        fussy-compare-same-score-fn 'fussy-histlen->strlen<
        ;; completion-styles '(fussy initials basic partial-completion emacs22)
        ;; completion-category-defaults nil
        ;; completion-category-overrides nil
        fussy-filter-fn 'fussy-filter-default)
  ;; (:after* corfu (:advice corfu--capf-wrapper :before fussy-wipe-cache))
  (:with-mode corfu-mode
    (:mode-hook
      (setq-local fussy-max-candidate-limit 5000
                  fussy-default-regex-fn 'fussy-pattern-first-letter
                  fussy-prefer-prefix nil))))
6.6.1.13. GCMH   internal

gcmh 管理汙薉

Use GCMH – the Garbage Collector Magic Hack – to adjust garbage collection.

https://gitlab.com/koral/gcmh

(defun nasy/-start-gcmh (&rest _)
  "Start GCMH."
  (when (and (not noninteractive)
             (not (and (boundp '*no-gcmh*)
                     *no-gcmh*)))
    (customize-set-variable
     'gcmh-verbose t
     "Customized with leaf in `gcmh' block")
    (customize-set-variable
     'gcmh-low-cons-threshold #x2000000  ;; 32MB
     "Customized with leaf in `gcmh' block")
    (customize-set-variable
     'gcmh-high-cons-threshold #x8000000 ;; 128MB
     "Customized with leaf in `gcmh' block")
    (customize-set-variable
     'gcmh-idle-delay 360
     "Customized with leaf in `gcmh' block")
    (gcmh-mode 1)))

;; (use-package gcmh
;;   :doc "Use GCMH --  the Garbage Collector Magic Hack -- to adjust garbage collection."
;;   :url "https://gitlab.com/koral/gcmh"
;;   :tag "internal"
;;   :commands gcmh-mode
;;   :hook (nasy-first-key . nasy/-start-gcmh))

(setup gcmh
  (:doc "Use GCMH --  the Garbage Collector Magic Hack -- to adjust garbage collection.")
  (:url "https://gitlab.com/koral/gcmh")
  (:tag "internal")
  (:first-key nasy/-start-gcmh))
6.6.1.14. Grep   builtin
(setup grep
  (:tag "builtin")
  (:opt
   grep-highlight-matches t
   grep-scroll-output     t))
6.6.1.15. Helpful   help lisp

A better Emacs help buffer.

https://github.com/Wilfred/helpful

(setup helpful
  (:doc "A better Emacs *help* buffer.")
  (:url "https://github.com/Wilfred/helpful")
  (:tag "help" "lisp")
  (:global
   "C-c d" helpful-at-point
   [remap describe-function] helpful-callable
   [remap describe-variable] helpful-variable
   [remap describe-key]      helpful-key))
6.6.1.15.1. elisp-demos
(setup elisp-demos
  (:doc "Demonstrate Emacs Lisp APIs.")
  (:url "https://github.com/xuchunyang/elisp-demos")
  (:tag "lisp" "docs")
  (:advice helpful-update :after elisp-demos-advice-helpful-update))
6.6.1.16. Keyfreq   extensions utilities

Track Emacs commands frequency

https://github.com/dacap/keyfreq

(setup keyfreq
  (:doc "Track Emacs commands frequency")
  (:url "https://github.com/dacap/keyfreq")
  (:tag "extensions" "utilities")
  (:opt
   keyfreq-file (concat *nasy-var* "keyfreq")
   keyfreq-excluded-commands
   '(backward-char
     dap-tooltip-mouse-motion
     delete-backward-char
     execute-extended-command
     forward-char
     keyboard-quit
     kill-buffer
     left-char
     minibuffer-keyboard-quit
     mouse-drag-region
     mouse-set-point
     move-beginning-of-line
     move-end-of-line
     next-line
     org-delete-backward-char
     org-end-of-line
     org-return
     org-self-insert-command
     pixel-scroll-precision
     previous-line
     previous-line
     right-char
     right-word
     save-buffer
     selectrum-next-candidate
     selectrum-select-current-candidate
     self-insert-command
     yank))
  (:hook-into nasy-first-key-hook)
  (:mode-hook (keyfreq-autosave-mode 1)))
6.6.1.17. marginalia   extensions

marginalia.el - Marginalia in the minibuffer

https://github.com/minad/marginalia

(setup marginalia
  (:doc "marginalia.el - Marginalia in the minibuffer.")
  (:url "https://github.com/minad/marginalia")
  (:tag "extensions")
  (:load-first vertico)
  (:when-loaded (marginalia-mode 1))
  (:bindm minibuffer-local-map
    "M-a" marginalia-cycle))
;; (setup all-the-icons-completion
;;   (:with-mode marginalia-mode
;;     (:hook all-the-icons-completion-marginalia-setup)))
6.6.1.18. Orderless   extensions

This package provides an orderless completion style that divides the pattern into space-separated components, and matches candidates that match all of the components in any order. Each component can match in any one of several ways: literally, as a regexp, as an initialism, in the flex style, or as multiple word prefixes. By default, regexp and literal matches are enabled.

https://github.com/oantolin/orderless

(defun nasy/-orderless-dispatch (pattern _index _total)
  "Orderless (PATTERN) dispatch.

 Recognizes the following patterns:
 * ~flex flex~
 * =literal literal=
 * `initialism initialism`
 * !without-literal without-literal!
 * .ext (file extension)
 * regexp$ (regexp matching at end)"
  (cond
   ;; Ensure that $ works with Consult commands, which add disambiguation suffixes
   ((string-suffix-p "$" pattern) `(orderless-regexp . ,(concat (substring pattern 0 -1) "[\x100000-\x10FFFD]*$")))
   ;; File extensions
   ((string-match-p "\\`\\.." pattern) `(orderless-regexp . ,(concat "\\." (substring pattern 1) "[\x100000-\x10FFFD]*$")))
   ;; Ignore single !
   ((string= "!" pattern) `(orderless-literal . ""))
   ;; Without literal
   ((string-prefix-p "!" pattern) `(orderless-without-literal . ,(substring pattern 1)))
   ((string-suffix-p "!" pattern) `(orderless-without-literal . ,(substring pattern 0 -1)))
   ;; Initialism matching
   ((string-prefix-p "`" pattern) `(orderless-initialism . ,(substring pattern 1)))
   ((string-suffix-p "`" pattern) `(orderless-initialism . ,(substring pattern 0 -1)))
   ;; Literal matching
   ((string-prefix-p "=" pattern) `(orderless-literal . ,(substring pattern 1)))
   ((string-suffix-p "=" pattern) `(orderless-literal . ,(substring pattern 0 -1)))
   ;; Flex matching
   ((string-prefix-p "~" pattern) `(orderless-flex . ,(substring pattern 1)))
   ((string-suffix-p "~" pattern) `(orderless-flex . ,(substring pattern 0 -1)))))


(setup orderless
  (:doc "Emacs completion style that matches multiple regexps in any order.")
  (:url "https://github.com/oantolin/orderless")
  (:tag "extensions")
  (:first-key* (require 'orderless) (require 'orderless-kwd))
  (:opt
   completion-styles '(orderless initials basic)
   orderless-matching-styles '(orderless-regexp
                               orderless-initialism
                               orderless-literal)
   orderless-style-dispatchers   '(orderless-affix-dispatch
                                   ;; nasy/-orderless-dispatch
                                   orderless-kwd-dispatch)
   orderless-component-separator "[ &·]"
   completion-category-overrides '((file (styles partial-completion)))
   completion-category-defaults  nil))
6.6.1.19. Page Break Lines   convenience faces

This Emacs library provides a global mode which displays ugly form feed characters as tidy horizontal rules.

https://github.com/purcell/page-break-lines

(setup page-break-lines
  (:doc "Emacs: display ugly ^L page breaks as tidy horizontal lines")
  (:url "https://github.com/purcell/page-break-lines")
  (:tag "convenience" "faces")
  (:with-hook nasy/font-change-hook
    (:hook (lambda ()
             (progn
               (after-x 'page-break-lines
                 (nasy/change-char-width page-break-lines-char 2)
                 (nasy/set-symbol ?⊸ 18 nil))))))
  (:opt page-break-lines-char ?⊸))
6.6.1.20. Parens   faces languages parens builtin
(setup paren
  (:tag "builtin")
  (:opt show-paren-context-when-offscreen t)
  (:first-key show-paren-mode))
6.6.1.21. Projectile   convenience project

Projectile is a project interaction library for Emacs. Its goal is to provide a nice set of features operating on a project level without introducing external dependencies (when feasible). For instance - finding project files has a portable implementation written in pure Emacs Lisp without the use of GNU find (but for performance sake an indexing mechanism backed by external commands exists as well).

https://github.com/bbatsov/projectile

(setup projectile
  (:doc "Projectile is a project interaction library for Emacs.")
  (:url "https://github.com/bbatsov/projectile")
  (:tag "project" "convenience")
  (:global [remap find-tag] projectile-find-tag)
  (:opt
   projectile-known-projects-file (concat *nasy-var* "projectile/known-projects.el")
   projectile-indexing-method          'hybrid
   projectile-require-project-root     'prompt
   projectile-ignored-project-function #'nasy/p-ignore-p)
  (:when-loaded
    (setq projectile-project-root-files-top-down-recurring
           (append '("compile_commands.json"
                     ".cquery")
                   projectile-project-root-files-top-down-recurring))))
6.6.1.22. Recentf   files

Recentf is a minor mode that builds a list of recently opened files.

https://www.emacswiki.org/emacs/RecentFiles

(defvar nasy--recentf-cleaned nil)

(setup recentf
  (:doc "Recentf is a minor mode that builds a list of recently opened files.")
  (:url "https://www.emacswiki.org/emacs/RecentFiles")
  (:tag "files")
  (:global "C-c r" recentf-open-files)
  (:first-key*
   (recentf-mode))
  (:mode-hook
   (after-x '風雨時用
     (unless nasy--recentf-cleaned
       (setq nasy--recentf-cleaned t)
       (recentf-cleanup))))
  (:opt*
   recentf-save-file (concat *nasy-var* "recentf-save.el")

   recentf-filename-handlers
   '(;; Text properties inflate the size of recentf's files, and there is
     ;; no purpose in persisting them, so we strip them out.
     substring-no-properties
     ;; Resolve symlinks of local files. Otherwise we get duplicate
     ;; entries opening symlinks.
     nasy/file-truename
     ;; Keep some symlinks
     nasy/file-sym-t
     ;; Replace $HOME with ~, which is more portable, and reduces how much
     ;; horizontal space the recentf listing uses to list recent files.
     abbreviate-file-name)

    recentf-auto-cleanup    'never
    recentf-max-saved-items 1000

    recentf-exclude
    `(,(abbreviate-file-name
        (locate-user-emacs-file *nasy-var*))
      "/tmp/" "/ssh:" "/nix/store" "~/.nix/store" "/private/var/folders"
      ,(locate-user-emacs-file "straight"))))
6.6.1.23. Savehist   history
(setup savehist
  (:hook-into nasy-first-key-hook)
  (:opt
   kill-ring-max              300
   history-length             3000
   history-delete-duplicates  t
   savehist-autosave-interval 3600
   savehist-file (concat *nasy-var* "savehist.el")
   savehist-additional-variables '(mark-ring
                                   global-mark-ring
                                   search-ring
                                   regexp-search-ring
                                   extended-command-history)))
6.6.1.24. Sessions   history
(setup session
  (:autoload session-initialize session-save-session)
  (:with-hook aftre-init-hook
    (:hook session-initialize))
  (:with-hook after-save-hook
    (:hook session-save-session))
  (:opt* session-save-file (concat *nasy-var* "session"))
  (:opt
   session-name-disable-regexp     "\\(?:\\`'/tmp\\|\\.git/[A-Z_]+\\'\\)"
   session-save-file-coding-system 'utf-8
   desktop-globals-to-save
   '((comint-input-ring        . 50)
     (compile-history          . 30)
     desktop-missing-file-warning
     (dired-regexp-history     . 20)
     (extended-command-history . 30)
     (face-name-history        . 20)
     (file-name-history        . 100)
     (grep-find-history        . 30)
     (grep-history             . 30)
     (ivy-history              . 100)
     (magit-revision-history   . 50)
     (minibuffer-history       . 50)
     (org-clock-history        . 50)
     (org-refile-history       . 50)
     (org-tags-history         . 50)
     (query-replace-history    . 60)
     (read-expression-history  . 60)
     (regexp-history           . 60)
     (regexp-search-ring       . 20)
     register-alist
     (search-ring              . 20)
     (shell-command-history    . 50)
     tags-file-name
     tags-table-list
     kill-ring)))
6.6.1.25. Subword   builtin
(setup subword
  (:tag "builtin")
  (:hook-into prog-mode-hook))
6.6.1.26. Sudo Edit   convenience

Utilities for opening files with sudo

https://github.com/nflath/sudo-edit

(setup sudo-edit
  (:doc "Utilities for opening files with sudo.")
  (:url "https://github.com/nflath/sudo-edit")
  (:tag "convenience"))
6.6.1.27. switch-window   convenience

Offer a visual way to choose a window to switch to.

https://github.com/dimitri/switch-window

(setup switch-window
  (:doc "Offer a *visual* way to choose a window to switch to.")
  (:url "https://github.com/dimitri/switch-window")
  (:tag "convenience")
  (:global
   "C-c 1" toggle-delete-other-windows
   "C-c 2" split-window--v
   "C-c 3" split-window--h
   "C-x |" split-window-horizontally-instead
   "C-x _" split-window-vertically-instead
   "C-x o" switch-window
   "C-c x" nasy/split-window
   "M-o"   other-window)
  (:opt
   ;; for dvorak layout
   switch-window-qwerty-shortcuts
   '("a" "o" "e" "u" "h" "t" "n" "s" "i" "d"
     ";" "," "." "p" "y" "f" "g" "c" "l"
     "'" "q" "j" "k" "x" "b" "m")
   switch-window-shortcut-style 'qwerty))
6.6.1.28. Tempo   builtin
(setup tempo
  (:tag "builtin")
  (:autoload tempo-define-template))
6.6.1.29. transient   bindings

Taking inspiration from prefix keys and prefix arguments, Transient implements a similar abstraction involving a prefix command, infix arguments and suffix commands. We could call this abstraction a "transient command", but because it always involves at least two commands (a prefix and a suffix) we prefer to call it just a "transient".

https://magit.vc/manual/transient

https://github.com/magit/transient

(setup transient
  (:doc "Transient commands.")
  (:url "https://github.com/magit/transient")
  (:tag "bindings")
  (:opt
   transient-history-file (concat *nasy-var* "transient/history.el")
   transient-levels-file  (concat *nasy-etc* "transient/levels.el")
   transient-values-file  (concat *nasy-etc* "transient/values.el"))
  (:init (add-to-list 'nasy--defer-loads 'transient)))
6.6.1.30. Treesit   languages
(defun na/treesit-install-language-grammar (lang)
  "Build and install the tree-sitter language grammar library for LANG.

 Interactively, if `treesit-language-source-alist' doesn't already
 have data for building the grammar for LANG, prompt for its
 repository URL and the C/C++ compiler to use.

 This command requires Git, a C compiler and (sometimes) a C++ compiler,
 and the linker to be installed and on PATH.  It also requires that the
 recipe for LANG exists in `treesit-language-source-alist'.

 See `exec-path' for the current path where Emacs looks for
 executable programs, such as the C/C++ compiler and linker."
  (interactive (list (intern
                      (completing-read
                       "Language: "
                       (mapcar #'car treesit-language-source-alist)))))
  (when-let* ((recipe
               (or (assoc lang treesit-language-source-alist)
                   (treesit--install-language-grammar-build-recipe
                    lang))))
    (condition-case err
        (apply #'treesit--install-language-grammar-1
               ;; The nil is OUT-DIR.
               (cons (car treesit-extra-load-path) recipe))
      (error
       (display-warning
        'treesit
        (format "Error encountered when installing language grammar: %s"
                err)))))

  ;; Check that the installed language grammar is loadable.
  (pcase-let ((`(,available . ,err)
               (treesit-language-available-p lang t)))
    (when (not available)
      (display-warning
       'treesit
       (format "The installed language grammar for %s cannot be located or has problems (%s): %s"
               lang (nth 0 err)
               (string-join
                (mapcar (lambda (x) (format "%s" x))
                        (cdr err))
                " "))))))

(setup treesit
  (:opt treesit-font-lock-level 4)
  (:when-loaded
   (add-to-list 'treesit-extra-load-path
                (concat *nasy-var* "treesit")))
  (:advice
   treesit-install-language-grammar :override na/treesit-install-language-grammar))

(setup treesit-auto
  (:opt treesit-auto-install 'prompt)
  (:first-key*
   (require 'treesit-auto)
   (add-to-list 'treesit-auto-fallback-alist '(bash-ts-mode . sh-mode))
   (add-to-list 'treesit-auto-fallback-alist '(toml-ts-mode . conf-toml-mode))
   (add-to-list 'treesit-auto-recipe-list
                (make-treesit-auto-recipe
                 :lang 'typst
                 :ts-mode 'typst-ts-mode
                 :remap '(typst-mode)
                 :url "https://github.com/uben0/tree-sitter-typst"
                 :revision "master"
                 :source-dir "src"
                 :ext ".typ"))
   (global-treesit-auto-mode)))
6.6.1.31. Unfill   convenience

Functions providing the inverse of Emacs' fill-paragraph and fill-region

https://github.com/purcell/unfill

(setup unfill
  (:doc "Functions providing the inverse of Emacs' fill-paragraph and fill-region")
  (:url "https://github.com/purcell/unfill")
  (:tag "convenience")
  (:global "M-q" unfill-toggle))
6.6.1.32. Uniquify   builtin files
(setup uniquify
  (:tag "builtin" "files")
  (:opt
   uniquify-buffer-name-style   'reverse
   uniquify-separator           " • "
   uniquify-after-kill-buffer-p t
   uniquify-ignore-buffers-re   "^\\*"))
6.6.1.33. valign   convenience table text

这个包能对齐 Org Mode、Markdown和table.el 的表格。它能对齐包含不等宽字体、中日韩字符、图片的表格。valign 不会影响 Org Mode(或 Markdown mode)基于等宽字符的对齐。 (注:目歬不在 org-mode 中启用)

This package provides visual alignment for Org Mode, Markdown and table.el tables on GUI Emacs. It can properly align tables containing variable-pitch font, CJK characters and images. Meanwhile, the text-based alignment generated by Org mode (or Markdown mode) is left untouched.

https://github.com/casouri/valign

(setup valign
  (:doc "Pixel-perfect visual alignment for Org and Markdown tables.")
  (:url "https://github.com/casouri/valign")
  (:tag "convenience" "table" "text")
  (:hook-into markdown-mode-hook))
6.6.1.34. vc-mode   vc
(setup vc
  (:first-key vc-mode))
6.6.1.35. Vertico   completion extensions

Vertico provides a performant and minimalistic vertical completion UI based on the default completion system. The main focus of Vertico is to provide a UI which behaves correctly under all circumstances. By reusing the built-in facilities system, Vertico achieves full compatibility with built-in Emacs completion commands and completion tables. Vertico only provides the completion UI but aims to be highly flexible, extensible and modular. Additional enhancements are available as extensions or complementary packages. The code base is small and maintainable. The main vertico.el package is only about 600 lines of code without white space and comments.

https://github.com/minad/vertico

;; Add prompt indicator to `completing-read-multiple'.
;; We display [CRM<separator>], e.g., [CRM,] if the separator is a comma.
(defun crm-indicator (args)
  (cons (format "[CRM%s] %s"
                (replace-regexp-in-string
                 "\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" ""
                 crm-separator)
                (car args))
        (cdr args)))

(setup vertico
  (:doc "Vertico provides a performant and minimalistic vertical completion UI based on the default completion system.")
  (:url "https://github.com/minad/vertico")
  (:tag "completion")
  (:advice completing-read-multiple :filter-args crm-indicator)
  (:bindm vertico-map
    "M-<DEL>" vertico-directory-delete-word)
  (:first-key* (vertico-mode 1))
  (:with-hook minibuffer-setup-hook
    (:hook vertico-repeat-save))
  (:mode-hook
   (vertico-mouse-mode 1)
   (after-x '風雨時用
     (nasy/active-region-mode 1))))
6.6.1.36. View Large File   files largefiles utilities

Emacs minor mode that allows viewing, editing, searching and comparing large files in batches, trading memory for processor time.

https://github.com/m00natic/vlfi

(defun ffap-vlf ()
  "Find file at point with VLF."
  (interactive)
  (let ((file (ffap-file-at-point)))
    (unless (file-exists-p file)
      (error "File does not exist: %s" file))
    (vlf file)))

(setup vlf
  (:doc "View Large Files in Emacs")
  (:url "https://github.com/m00natic/vlfi")
  (:tag "files" "large files" "utilities")
  (:autoload ffap-vlf))
6.6.1.37. wgrep   editing extensions grep

wgrep allows you to edit a grep buffer and apply those changes to the file buffer like sed interactively. No need to learn sed script, just learn Emacs.

https://github.com/mhayashi1120/Emacs-wgrep

(setup wgrep
  (:doc "Writable grep buffer and apply the changes to files.")
  (:url "https://github.com/mhayashi1120/Emacs-wgrep")
  (:tag "editing" "extensions" "grep"))
6.6.1.38. Which Function   builtin
(setup which-func
  (:tag "builtin")
  (:first-key which-function-mode))
6.6.1.39. Whitespace   convenience data wp

Visualize blanks (TAB, (HARD) SPACE and NEWLINE).

https://www.emacswiki.org/emacs/WhiteSpace

In Emacs, intelligently call whitespace-cleanup on save.

https://github.com/purcell/whitespace-cleanup-mode

(defun no-trailing-whitespace ()
  "Turn off display of trailing whitespace in this buffer."
  (setq show-trailing-whitespace nil))

(setup whitespace
  (:tag "data" "wp")
  (:with-function no-trailing-whitespace
    (:hook-into
     ;; But don't show trailing whitespace in SQLi, inf-ruby etc.
     artist-mode-hook
     picture-mode-hook
     special-mode-hook
     Info-mode-hook
     eww-mode-hook
     term-mode-hook
     vterm-mode-hook
     comint-mode-hook
     compilation-mode-hook
     twittering-mode-hook
     minibuffer-setup-hook
     fundamental-mode-hook)))

(setup whitespace-cleanup-mode
  (:doc "In Emacs, intelligently call whitespace-cleanup on save.")
  (:url "https://github.com/purcell/whitespace-cleanup-mode")
  (:tag "convonience")
  (:opt
   whitespace-cleanup-mode-only-if-initially-clean nil
   whitespace-style
   '(face trailing tabs spaces newline
          missing-newline-at-eof empty indentation
          space-after-tab space-before-tab
          space-mark tab-mark newline-mark))
  (:hook-into text-mode-hook prog-mode-hook)
  (:global "<remap> <just-one-space>" cycle-spacing))
6.6.1.40. xref   builtin
(setup xref
  (:opts
   ((xref-show-xrefs-function
     xref-show-definitions-function)
    . #'xref-show-definitions-completing-read)))

6.6.2.

;;;###autoload
(defvar nasy/company-backend-alist
  '((text-mode company-dabbrev company-yasnippet company-ispell company-files)
    (prog-mode company-capf company-yasnippet company-files)
    (conf-mode company-capf company-dabbrev-code company-yasnippet company-files))
  "An alist matching modes to company backends.

 The backends for any mode is built from this.")


;;;###autoload
(defvar nasy-cape/company
  ;; '(company-tabnine company-yasnippet)
  '(company-yasnippet))

6.6.3.

;;;###autoload
(defun nasy/add-company-backend (modes &rest backends)
  "Prepend BACKENDS (in order) to `company-backends' in MODES.

 MODES should be one symbol or a list of them,
 representing major or minor modes.
 This will overwrite backends for MODES on consecutive uses.

 If the car of BACKENDS is nil, unset the backends for MODES.
 Examples:
 (nasy/add-company-backend \\='js2-mode
   \\='company-tide \\='company-yasnippet)
 (nasy/add-company-backend \\='sh-mode
   \\='(company-shell :with company-yasnippet))
 (nasy/add-company-backend \\='(c-mode c++-mode)
   \\='(:separate company-irony-c-headers company-irony))
 (nasy/add-company-backend \\='sh-mode nil)  ; unsets backends for `sh-mode'"
 (declare (indent defun))
 (dolist (mode (nasy/enlist modes))
   (if (null (car backends))
       (setq nasy/company-backend-alist
             (delq (assq mode nasy/company-backend-alist)
                   nasy/company-backend-alist))
     (setf (alist-get mode nasy/company-backend-alist)
           backends))))


;;;###autoload
(defun nasy/company-backends ()
  "Get company backends."
  (let (backends)
    (let ((mode major-mode)
          (modes (list major-mode)))
      (while (setq mode (get mode 'derived-mode-parent))
        (push mode modes))
      (dolist (mode modes)
        (dolist (backend (append (cdr (assq mode nasy/company-backend-alist))
                                 (default-value 'company-backends)))
          (push backend backends)))
      (delete-dups
       (append (cl-loop for (mode . backends) in nasy/company-backend-alist
                        if (or (eq major-mode mode)  ; major modes
                              (and (boundp mode)
                                 (symbol-value mode))) ; minor modes
                        append backends)
               (nreverse backends))))))


;;;###autoload
(defun nasy/company-init-backends-h ()
  "Set `company-backends' for the current buffer."
  (or (memq major-mode '(fundamental-mode special-mode))
     buffer-read-only
     (nasy/temp-buffer-p (or (buffer-base-buffer) (current-buffer)))
     (setq-local company-backends (nasy/company-backends))))


;; (put 'nasy/company-init-backends-h 'permanent-local-hook t)


;;;###autoload
(defun nasy/company-complete ()
  "Bring up the completion popup.  If only one result, complete it."
  (interactive)
  (require 'company)
  (when (ignore-errors
          (/= (point)
              (cdr (bounds-of-thing-at-point 'symbol))))
    (save-excursion (insert " ")))
  (when (and (company-manual-begin)
             (= company-candidates-length 1))
    (company-complete-common)))


;;;###autoload
(defun nasy/company-has-completion-p ()
  "Return non-nil if a completion candidate exists at point."
  (and (company-manual-begin)
       (= company-candidates-length 1)))


;;;###autoload
(defun nasy/company-toggle-auto-completion ()
  "Toggle as-you-type code completion."
  (interactive)
  (require 'company)
  (setq company-idle-delay (unless company-idle-delay 0.2))
  (message "Auto completion %s"
           (if company-idle-delay "enabled" "disabled")))


;;;###autoload
(defun nasy/company-dabbrev ()
  "Invokes `company-dabbrev-code' in `prog-mode' buffers and `company-dabbrev'
      everywhere else."
  (interactive)
  (call-interactively
   (if (derived-mode-p 'prog-mode)
       #'company-dabbrev-code
     #'company-dabbrev)))


;;;###autoload
(defun nasy/company-whole-lines (command &optional arg &rest _)
  "`company-mode' completion backend that completes whole-lines, akin to vim's
      C-x C-l."
  (interactive (list 'interactive))
  (require 'company)
  (pcase command
    (`interactive (company-begin-backend 'nasy/company-whole-lines))
    (`prefix      (company-grab-line "^[\t\s]*\\(.+\\)" 1))
    (`candidates
     (all-completions
      arg
      (delete-dups
       (split-string
        (replace-regexp-in-string
         "^[\t\s]+" ""
         (concat (buffer-substring-no-properties (point-min) (line-beginning-position))
                 (buffer-substring-no-properties (line-end-position) (point-max))))
        "\\(\r\n\\|[\n\r]\\)" t))))))


;;;###autoload
(defun nasy/company-dict-or-keywords ()
  "`company-mode' completion combining `company-dict' and `company-keywords'."
  (interactive)
  (require 'company-dict)
  (require 'company-keywords)
  (let ((company-backends '((company-keywords company-dict))))
    (call-interactively #'company-complete)))


;;;###autoload
(defun nasy/company-dabbrev-code-previous ()
  "TODO."
  (interactive)
  (require 'company-dabbrev)
  (let ((company-selection-wrap-around t))
    (call-interactively #'nasy/company-dabbrev)
    (company-select-previous-or-abort)))


;;;###autoload
(defvar nasy/prev-whitespace-mode nil)
(make-variable-buffer-local 'nasy/prev-whitespace-mode)


;;;###autoload
(defvar nasy/show-trailing-whitespace nil)
(make-variable-buffer-local 'nasy/show-trailing-whitespace)


(defvar my-prev-whitespace-mode nil)

;;;###autoload
(defun nasy/-pre-popup-draw ()
  "Turn off whitespace mode before showing company complete tooltip."
  (if whitespace-mode
      (progn
        (setq my-prev-whitespace-mode t)
        (whitespace-mode -1)))
  (setq nasy/show-trailing-whitespace show-trailing-whitespace)
  (setq show-trailing-whitespace nil))


;;;###autoload
(defun nasy/-post-popup-draw ()
  "Restore previous whitespace mode after showing company tooltip."
  (if nasy/prev-whitespace-mode
      (progn
        (whitespace-mode 1)
        (setq nasy/prev-whitespace-mode nil)))
  (setq show-trailing-whitespace nasy/show-trailing-whitespace))


;;;###autoload
(defun nasy/company-filter-c ()
  (company-search-abort)
  (company-filter-candidates))



;;;###autoload
(defun nasy/company-box-icons--elisp-fn (candidate)
  (when (derived-mode-p 'emacs-lisp-mode)
    (let ((sym (intern candidate)))
      (cond ((fboundp  sym) 'ElispFunction)
            ((boundp   sym) 'ElispVariable)
            ((featurep sym) 'ElispFeature)
            ((facep    sym) 'ElispFace)))))


;;;###autoload
(defun nasy/company-remove-scrollbar-a (orig-fn &rest args)
  "This disables the company-box scrollbar, because:
  https://github.com/sebastiencs/company-box/issues/44"
  (cl-letf (((symbol-function #'display-buffer-in-side-window)
             (symbol-function #'ignore)))
    (apply orig-fn args)))


;;;###autoload
(defun nasy/merge-capf (c)
  "Merge c into completion-at-point-functions."
  (remove-hook 'completion-at-point-functions t t)
  (add-hook 'completion-at-point-functions c 1 'local))
  ;; (setq completion-at-point-functions
  ;;       (cape-capf-buster (apply #'cape-super-capf completion-at-point-functions))))

;;;###autoload
(defun nasy/-merge-capf ()
  "Merge nasy capy."
  (require 'cape)
  (let ((nasy-capfs (cape-capf-buster (cape-company-to-capf
                                       (apply-partially
                                        #'company--multi-backend-adapter
                                        nasy-cape/company)))))
    (nasy/merge-capf nasy-capfs)))


;;;###autoload
(defun nasy/orderless-dispatch-flex-first (_pattern index _total)
  "orderless-flex for corfu."
  (and (eq index 0) 'orderless-flex))


;;;###autoload
(defun nasy/setup-corfu ()
  "Setup corfu."
  (corfu-mode 1)
  (setq-local orderless-matching-styles '(orderless-flex)
              orderless-style-dispatchers nil)
  (add-hook 'orderless-style-dispatchers (function nasy/orderless-dispatch-flex-first) nil
            'local))

6.6.4.

6.6.4.1. cape   editing extensions

Cape provides a bunch of Completion At Point Extensions which can be used in combination with my Corfu completion UI or the default completion UI. The completion backends used by completion-at-point are so called completion-at-point-functions (Capfs). In principle, the Capfs provided by Cape can also be used by Company.

https://github.com/minad/cape

(setup cape
  (:doc "Completion At Point Extensions.")
  (:url "https://github.com/minad/cape")
  (:tag "editing" "extensions")
  (:load-first corfu company)
  (:with-map mode-specific-map
    (:bind
      "p p"   completion-at-point ;; capf
      "p t"   complete-tag        ;; etags
      "p d"   cape-dabbrev        ;; or dabbrev-completion
      "p f"   cape-file
      "p k"   cape-keyword
      "p s"   cape-elisp-symbol
      "p a"   cape-abbrev
      "p l"   cape-line
      "p w"   cape-dict
      "p \\"  cape-tex
      "p A-¥" cape-tex
      "p &"   cape-sgml
      "p r"   cape-rfc1345))
  (:with-hook corfu-mode-hook
    (:hook nasy/-merge-capf))
  (:when-loaded
    (setq completion-at-point-functions
          (cape-capf-buster (cape-company-to-capf
                             (apply-partially
                              #'company--multi-backend-adapter
                              nasy-cape/company))))))
6.6.4.2. company
6.6.4.2.1. company
(setup company
  (:autoload company--multi-backend-adapter))
  ;; ;; (:global
  ;; ;;  "C-;"      nasy/company-complete
  ;; ;;  "M-/"      company-files
  ;; ;;  "C-<tab>"  nasy/company-complete
  ;; ;;  [remap indent-for-tab-command] company-indent-or-complete-common)
  ;; (:company-mode-map
  ;;  ([remap indent-for-tab-command]
  ;;   . company-indent-or-complete-common)
  ;;  ("M-/" . company-files))
  ;; (:company-active-map
  ;;  ("C-o"        . company-search-kill-others)
  ;;  ("C-n"        . company-select-next)
  ;;  ("C-p"        . company-select-previous)
  ;;  ("C-h"        . company-quickhelp-manual-begin)
  ;;  ("C-S-h"      . company-show-doc-buffer)
  ;;  ("C-s"        . company-search-candidates)
  ;;  ("M-s"        . company-filter-candidates)
  ;;  ([C-tab]      . nasy/company-complete)
  ;;  ([tab]        . company-complete-common-or-cycle)
  ;;  ([backtab]    . company-select-previous))
  ;; (:company-search-map
  ;;  ("C-n"        . company-search-repeat-forward)
  ;;  ("C-p"        . company-search-repeat-backward)
  ;;  ("C-s"        . nasy/company-filter-c))
  ;; :custom
  ;; ((company-tooltip-limit       . 10)
  ;;  (company-dabbrev-downcase    . nil)
  ;;  (company-dabbrev-ignore-case . t)
  ;;  (company-global-modes
  ;;   . '(not erc-mode message-mode help-mode gud-mode eshell-mode))
  ;;  ;; `(company-frontends
  ;;  ;;   . ,(if *c-box*
  ;;  ;;          '(company-box-frontend)
  ;;  ;;        '(company-pseudo-tooltip-frontend company-echo-metadata-frontend)))
  ;;  (company-dabbrev-other-buffers     . 'all)
  ;;  (company-tooltip-align-annotations . t)
  ;;  (company-minimum-prefix-length     . 2)
  ;;  (company-idle-delay                . 1)
  ;;  (company-tooltip-idle-delay        . .2)
  ;;  (company-require-match             . 'never)
  ;;  (company-format-margin-function    . #'company-vscode-dark-icons-margin))
  ;; :hook (nasy--defer-load-hook . (lambda () (require 'company)))
  ;; :config
  ;; ;; (add-hook 'after-change-major-mode-hook #'nasy/company-init-backends-h 'append)
  ;; :defer-config
  ;; ;; (add-to-list 'completion-styles 'initials t)
  ;; (setq company-backends '(company-capf))
  ;; :advice
  ;; (:before company-pseudo-tooltip-unhide nasy/-pre-popup-draw)
  ;; (:after  company-pseudo-tooltip-hide   nasy/-post-popup-draw))
6.6.4.2.2. Company Quickhelp
;; (leaf company-quickhelp
;;   :after company
;;   :bind
;;   (:company-active-map
;;    ("C-c h" . company-quickhelp-manual-begin))
;;   :hook company-mode-hook
;;   :custom
;;   (pos-tip-use-relative-coordinates . t))
6.6.4.2.3. Company Tabnine
;; (leaf company-tabnine
;;   :disabled t
;;   :after company
;;   :custom
;;   `(company-tabnine-binaries-folder . ,(concat *nasy-var* "company/tabnine-binaries"))
;;   `(company-tabnine-log-file-path
;;     . ,(concat *nasy-var* "company/tabnine-binaries/log")))
6.6.4.2.4. Company Flx
;; (leaf company-flx
;;   :after company
;;   :disabled t
;;   :hook company-mode-hook)
6.6.4.2.5. Company Box
;; (leaf company-box
;;   :after company
;;   :hook company-mode-hook
;;   :custom
;;   (company-box-show-single-candidate . t)
;;   (company-box-max-candidates        . 25)
;;   (company-box-icons-alist           . 'company-box-icons-all-the-icons)
;;   :config
;;   (setq
;;    company-box-icons-functions
;;    (cons #'nasy/company-box-icons--elisp-fn
;;          (delq 'company-box-icons--elisp
;;                company-box-icons-functions)))

;;   (after-x 'all-the-icons
;;     (setq
;;      company-box-icons-all-the-icons
;;      (let ((all-the-icons-scale-factor 0.8))
;;        `((Unknown       . ,(all-the-icons-material "find_in_page"             :face 'all-the-icons-􀝦purple))
;;          (Text          . ,(all-the-icons-material "text_fields"              :face 'all-the-icons-􀝦green))
;;          (Method        . ,(all-the-icons-material "functions"                :face 'all-the-icons-􀝦yellow))
;;          (Function      . ,(all-the-icons-material "functions"                :face 'all-the-icons-􀝦yellow))
;;          (Constructor   . ,(all-the-icons-material "functions"                :face 'all-the-icons-􀝦yellow))
;;          (Field         . ,(all-the-icons-material "functions"                :face 'all-the-icons-􀝦yellow))
;;          (Variable      . ,(all-the-icons-material "adjust"                   :face 'all-the-icons-􀝦blue))
;;          (Class         . ,(all-the-icons-material "class"                    :face 'all-the-icons-􀝦cyan))
;;          (Interface     . ,(all-the-icons-material "settings_input_component" :face 'all-the-icons-􀝦cyan))
;;          (Module        . ,(all-the-icons-material "view_module"              :face 'all-the-icons-􀝦cyan))
;;          (Property      . ,(all-the-icons-material "settings"                 :face 'all-the-icons-lorange))
;;          (Unit          . ,(all-the-icons-material "straighten"               :face 'all-the-icons-􀝦red))
;;          (Value         . ,(all-the-icons-material "filter_1"                 :face 'all-the-icons-􀝦red))
;;          (Enum          . ,(all-the-icons-material "plus_one"                 :face 'all-the-icons-lorange))
;;          (Keyword       . ,(all-the-icons-material "filter_center_focus"      :face 'all-the-icons-lgreen))
;;          (Snippet       . ,(all-the-icons-material "short_text"               :face 'all-the-icons-lblue))
;;          (Color         . ,(all-the-icons-material "color_lens"               :face 'all-the-icons-􀝦green))
;;          (File          . ,(all-the-icons-material "insert_drive_file"        :face 'all-the-icons-􀝦green))
;;          (Reference     . ,(all-the-icons-material "collections_bookmark"     :face 'all-the-icons-silver))
;;          (Folder        . ,(all-the-icons-material "folder"                   :face 'all-the-icons-􀝦green))
;;          (EnumMember    . ,(all-the-icons-material "people"                   :face 'all-the-icons-lorange))
;;          (Constant      . ,(all-the-icons-material "pause_circle_filled"      :face 'all-the-icons-􀝦blue))
;;          (Struct        . ,(all-the-icons-material "streetview"               :face 'all-the-icons-􀝦blue))
;;          (Event         . ,(all-the-icons-material "event"                    :face 'all-the-icons-􀝦yellow))
;;          (Operator      . ,(all-the-icons-material "control_point"            :face 'all-the-icons-􀝦red))
;;          (TypeParameter . ,(all-the-icons-material "class"                    :face 'all-the-icons-􀝦red))
;;          (Template      . ,(all-the-icons-material "short_text"               :face 'all-the-icons-􀝦green))
;;          (ElispFunction . ,(all-the-icons-material "functions"                :face 'all-the-icons-􀝦red))
;;          (ElispVariable . ,(all-the-icons-material "check_circle"             :face 'all-the-icons-􀝦blue))
;;          (ElispFeature  . ,(all-the-icons-material "stars"                    :face 'all-the-icons-􀝦orange))
;;          (ElispFace     . ,(all-the-icons-material "format_paint"             :face 'all-the-icons-􀝦pink))))))

;;   :advice (:around
;;            company-box--update-scrollbar
;;            nasy/company-remove-scrollbar-a))
6.6.4.3. copilot.el   editing extensions

Copilot.el is an Emacs plugin for GitHub Copilot.

https://github.com/zerolfx/copilot.el

(defun nasy/copilot-complete ()
  "Copilot complete."
  (interactive)
  (copilot-clear-overlay)
  (copilot-complete))

(defun nasy/copilot-disable-p ()
  "Disable copilot when at the end of the file and not changed."
  (and (= (point-max) (point))
       (not (buffer-modified-p))))

(setup copilot
  (:doc "An unofficial Copilot plugin for Emacs.")
  (:url "https://github.com/zerolfx/copilot.el")
  (:tag "editing" "extensions")
  (:advice keyboard-quit :after copilot-clear-overlay)
  (:bindm copilot-mode-map
    "C-<tab>" copilot-accept-completion
    "H-SPC"   nasy/copilot-complete)
  (:opt* copilot-install-dir (concat *nasy-var* "copilot"))
  (:opt copilot-idle-delay 0.8
        copilot-indent-warning-suppress t)
  (:when-loaded
    (add-to-list 'copilot-disable-predicates #'nasy/copilot-disable-p)
    (add-to-list 'warning-suppress-types '(copilot copilot-no-mode-indent)))
  (:hook-into prog-mode-hook text-mode org-mode-hook emacs-lisp-mode-hook))
6.6.4.4. copilot chat   convenience tools

Chat with Github copilot in Emacs!

https://github.com/chep/copilot-chat.el

(setup copilot-chat
  (:doc "Chat with Github copilot in Emacs!")
  (:url "https://github.com/chep/copilot-chat.el")
  (:tag "convenience" "tools")
  (:opt copilot-chat-frontend 'shell-maker)
  (:when-loaded
    (require 'copilot-chat-shell-maker)
    (push '(shell-maker . copilot-chat-shell-maker-init) copilot-chat-frontend-list)
    (copilot-chat-shell-maker-init)))
6.6.4.5. corfu   editing extensions

Corfu enhances the default completion in region function with a completion overlay.

https://github.com/minad/corfu

(defun nasy/corfu-commit-predicate ()
  "Auto-commit candidates if:
  1. A '.' is typed, except after a SPACE or text/org mode.
  2. A selection was made, aside from entering SPACE.
  3. Just one candidate exists, and we continue to non-symbol info.
  4. The 1st match is exact."
  (cond
   ((seq-contains-p (this-command-keys-vector) ?.)
    (or (string-empty-p (car corfu--input))
        (not
         (or (string= (substring (car corfu--input) -1) " ")
             (eq major-mode 'org-mode)
             (eq major-mode 'text-mode)))))

   ((/= corfu--index corfu--preselect) ; a selection was made
    (not (seq-contains-p (this-command-keys-vector) ?\s)))

   ((eq corfu--total 1) ;just one candidate
    (seq-intersection (this-command-keys-vector) [?: ?, ?\) ?\] ?\( ?\s]))

   ((and corfu--input ; exact 1st match
         (string-equal (substring (car corfu--input) corfu--base)
                       (car corfu--candidates)))
    (seq-intersection (this-command-keys-vector) [?: ?\. ?, ?\) ?\] ?\" ?' ?\s]))))

(setup corfu
  (:doc "Completion Overlay Region FUnction.")
  (:url "https://github.com/minad/corfu")
  (:tag "editing" "extensions")
  (:bindm corfu-map
    "C-g"       corfu-quit
    "<backtab>" corfu-last)
  (:opts
   ((corfu-cycle
     corfu-auto)
    . t)
   ((corfu-preselect-first
     corfu-preview-current)
    . nil))
  (:opt
   corfu-quit-no-match      'separator
   corfu-separator          #x00b7
   corfu-auto-delay         0.4
   corfu-auto-prefix        2
   corfu-echo-documentation 1
   corfu-commit-predicate   #'nasy/corfu-commit-predicate)
  (:with-function nasy/setup-corfu
    (:hook-into
     prog-mode-hook
     org-mode-hook
     shell-mode-hook
     eshell-mode-hook
     text-mode-hook
     typst-mode-hook
     typst-ts-mode-hook
     eval-expression-minibuffer-setup-hook))
  ;; Extensions
  (:mode-hook
   (corfu-history-mode)
   (corfu-indexed-mode)
   (:after savehist
     (add-to-list 'savehist-additional-variables 'corfu-history))))
6.6.4.6. corfu-popupinfo   convenience corfu documentation popup

Display a documentation popup for completion candidate when using Corfu. It can be re regarded as company-quickhelp for Corfu.

https://github.com/minad/corfu/blob/main/extensions/corfu-popupinfo.el

(setup corfu-popupinfo
  (:doc "Documentation popup for Corfu.")
  (:url "https://github.com/minad/corfu/blob/main/extensions/corfu-popupinfo.el")
  (:tag "convenience" "corfu" "documentation" "popup")
  (:hook-into corfu-mode-hook))
6.6.4.7. citre

Citre

6.7. 月出

(add-to-list 'load-path (locate-user-emacs-file  "桃夭/月出"))
(require '月出)

月出皎兮、佼人嫽兮
舒窈糾兮、勞心悄兮

月出晧兮、佼人懰兮
舒憂受兮、勞心慅兮

月出照兮、佼人尞兮
舒夭綤兮、勞心憯兮

非恆用者以 *no-xxx*t 弃用之

Selective packages. Disabled the package by setting no-package in the custom file.

6.7.1.

6.7.1.1. abridge-diff   diffs tools magit

A simple Emacs package for abridging refined diff hunks (for example in magit). Why abridge a diff hunk? Most diffs are line based. If you are working on files with very long lines, for example LaTeX files, or text files with full paragraphs per line (often using visual-line-mode), line-based diffs can be very challenging to read, even with "hunk refining" enabled (highlighting the words which changed).

https://github.com/jdtsmith/abridge-diff

(setup abridge-diff
  (:doc "Emacs package for refining diff hunks with very long lines (as in LaTeX files).")
  (:url "https://github.com/jdtsmith/abridge-diff")
  (:tag "diffs" "magit" "tools")
  (:load-first magit)
  (:when-loaded
    (abridge-diff-mode 1)))
6.7.1.2. Ansi-Color   comm processes terminals services

ansi-color.el translates ANSI SGR (Select Graphic Rendition) escape sequences like "Esc[30m" into EmacsOverlays, TextProperties, or XEmacsExtents with face colours, bold, etc.

https://www.emacswiki.org/emacs/AnsiColor

(defun colourise-compilation-buffer ()
  (when (eq major-mode 'compilation-mode)
    (ansi-color-apply-on-region compilation-filter-start
                                (point-max))))

(setup ansi-color
  (:doc "ansi-color.el translates ANSI SGR (Select Graphic Rendition) escape sequences with face colours, bold, etc.")
  (:url "https://www.emacswiki.org/emacs/AnsiColor")
  (:tag "comm" "processes" "terminals" "services")
  (:autoload colourise-compilation-buffer)
  (:load-first compile)
  (:with-hook compilation-filter-hook
    (:hook colourise-compilation-buffer)))
6.7.1.3. beacon   convenience

A light that follows your cursor around so you don't lose it!

https://github.com/Malabarba/beacon

(setup beacon
  (:doc "Never lose your cursor again.")
  (:url "https://github.com/Malabarba/beacon")
  (:tag "convenience")
  (:custom
   beacon-size 8
   beacon-blink-delay 0.1
   beacon-dont-blink-commands nil)
  (:customs
   ((beacon-blink-when-point-moves-vertically
     beacon-blink-when-point-moves-horizontally
     blink-cursor-interval)
    . 1))
  (:with-hook nasy-first-key-hook
    (:hook (lambda () (require 'beacon)))))
6.7.1.4. Color Identifiers Mode   faces languages

Emacs minor mode to highlight each source code identifier uniquely based on its name.

https://github.com/ankurdave/color-identifiers-mode

(setup color-identifiers-mode
  (:doc "Emacs minor mode to highlight each source code identifier uniquely based on its name.")
  (:url "https://github.com/ankurdave/color-identifiers-mode")
  (:tag "faces" "languages")
  (:autoload color-identifiers-mode-maybe)
  (:load-first helpful)
  (:with-hook python-base-mode-hook
    (:hook color-identifiers-mode-maybe)))
6.7.1.5. Colorful-Mode   faces matching tools

Colorful-mode is a minor mode that allow you preview any color format such as color hex and color names, in your current buffer in real time and in a user friendly way based on 🌈rainbow-mode.el.

https://github.com/DevelopmentCool2449/colorful-mode

(setup colorful-mode
  (:doc "Preview any color in your buffer.")
  (:url "https://github.com/DevelopmentCool2449/colorful-mode")
  (:tag "faces" "tools" "matching")
  (:opt colorful-use-prefix t
        colorful-prefix-string "􀝦")
  (:hook-into
   nasy-first-key-hook
   text-mode-hook
   org-mode-hook
   css-mode-hook
   html-mode-hook
   prog-mode-hook))
6.7.1.6. Default Text Scale   text
(setup default-text-scale
  (:autoload default-text-scale-mode)
  (:hook-into nasy-first-key-hook))
6.7.1.7. Diff-hl (only for dired)   vc diffs

Emacs package for highlighting uncommitted changes

https://github.com/dgutov/diff-hl

(setup diff-hl
  (:doc "Emacs package for highlighting uncommitted changes")
  (:url "https://github.com/dgutov/diff-hl")
  (:tag "vc" "diffs")
  (:hooks
   dired-mode-hook         diff-hl-dired-mode
   magit-pre-refresh-hook  diff-hl-magit-pre-refresh
   magit-post-refresh-hook diff-hl-magit-post-refresh
   nasy-first-key-hook     global-diff-hl-mode
   nasy-first-key-hook     global-diff-hl-show-hunk-mouse-mode
   nasy-first-key-hook     diff-hl-margin-mode))
6.7.1.8. dired-async   dired async network

Simple library for asynchronous processing in Emacs.

https://github.com/jwiegley/emacs-async

(setup dired-async
  (:doc "Simple library for asynchronous processing in Emacs.")
  (:url "https://github.com/jwiegley/emacs-async")
  (:tag "dired" "async" "network")
  (:autoload dired-async-mode)
  (:hook-into dired-mode-hook))
6.7.1.9. Dired Hack   files

Collection of useful dired additions

https://github.com/Fuco1/dired-hacks

(setup dired-hacks
  (:doc "Collection of useful dired additions")
  (:url "https://github.com/Fuco1/dired-hacks")
  (:tag "files"))
6.7.1.9.1. Dired Filter
(setup dired-filter
  (:autoload dired-filter-group-mode)
  (:bindm dired-filter-map
     "p" dired-filter-pop-all)
  (:with-hook dired-mode-hook
    (:hook dired-filter-mode dired-filter-group-mode))
  (:opt
   dired-filter-revert 'never
   dired-filter-group-saved-groups
   '(("default"
      ("Git"
       (directory . ".git")
       (file . ".gitignore"))
      ("Directory"
       (directory))
      ("PDF"
       (extension . "pdf"))
      ("LaTeX"
       (extension "tex" "bib"))
      ("Source"
       (extension "c" "cpp" "hs" "rb" "py" "r" "cs" "el" "lisp" "html" "js" "css"))
      ("Doc"
       (extension "md" "rst" "txt"))
      ("Org"
       (extension . "org"))
      ("Archives"
       (extension "zip" "rar" "gz" "bz2" "tar"))
      ("Images"
       (extension "jpg" "JPG" "webp" "png" "PNG" "jpeg" "JPEG" "bmp" "BMP" "TIFF" "tiff" "gif" "GIF")))))
  (:when-loaded
    (define-key dired-filter-map (kbd "/") dired-filter-mark-map)))
6.7.1.9.2. Dired Rainbow
(defun nasy/-init-dired-rainbow ()
  "Nasy init dired-rainbow."
  (require 'dired-rainbow)
  (with-no-warnings
    (dired-rainbow-define
     html "􀝦#eb5286"
     ("css" "less" "sass" "scss" "htm" "html" "jhtm" "mht" "eml" "mustache" "xhtml"))
    (dired-rainbow-define
      xml "􀝦#f2d024"
      ("xml" "xsd" "xsl" "xslt" "wsdl" "bib" "json" "msg" "pgn" "rss" "yaml" "yml" "rdata"))
    (dired-rainbow-define
      document "􀝦#9561e2"
      ("docm" "doc" "docx" "odb" "odt" "pdb" "pdf" "ps" "rtf" "djvu" "epub" "odp" "ppt" "pptx"))
    (dired-rainbow-define
      markdown "􀝦#705438"
      ("org" "etx" "info" "markdown" "md" "mkd" "nfo" "pod" "rst" "tex" "textfile" "txt"))
    (dired-rainbow-define
      database "􀝦#6574cd"
      ("xlsx" "xls" "csv" "accdb" "db" "mdb" "sqlite" "nc"))
    (dired-rainbow-define
      media "􀝦#de751f"
      ("mp3" "mp4" "MP3" "MP4" "avi" "mpeg" "mpg" "flv" "ogg" "mov" "mid" "midi" "wav" "aiff" "flac"))
    (dired-rainbow-define
      image "􀝦#f66d9b"
      ("tiff" "tif" "cdr" "gif" "ico" "jpeg" "jpg" "png" "psd" "eps" "svg"))
    (dired-rainbow-define
      log "􀝦#c17d11"
      ("log"))
    (dired-rainbow-define
      shell "􀝦#f6993f"
      ("awk" "bash" "bat" "sed" "sh" "zsh" "vim"))
    (dired-rainbow-define
      interpreted "􀝦#38c172"
      ("py" "ipynb" "rb" "pl" "t" "msql" "mysql" "pgsql" "sql" "r" "clj" "cljs" "scala" "js"))
    (dired-rainbow-define
      compiled "􀝦#4dc0b5"
      ("asm" "cl" "lisp" "el" "c" "h" "c++" "h++" "hpp" "hxx" "m" "cc" "cs" "cp" "cpp" "go" "f" "for" "ftn" "f90" "f95" "f03" "f08" "s" "rs" "hi" "h
        s" "pyc" ".java"))
    (dired-rainbow-define
      executable "􀝦#8cc4ff"
      ("exe" "msi"))
    (dired-rainbow-define
      compressed "􀝦#51d88a"
      ("7z" "zip" "bz2" "tgz" "txz" "gz" "xz" "z" "Z" "jar" "war" "ear" "rar" "sar" "xpi" "apk" "xz" "tar"))
    (dired-rainbow-define
      packaged "􀝦#faad63"
      ("deb" "rpm" "apk" "jad" "jar" "cab" "pak" "pk3" "vdf" "vpk" "bsp"))
    (dired-rainbow-define
      encrypted "􀝦#ffed4a"
      ("gpg" "pgp" "asc" "bfe" "enc" "signature" "sig" "p12" "pem"))
    (dired-rainbow-define
     fonts "􀝦#6cb2eb"
     ("afm" "fon" "fnt" "pfb" "pfm" "ttf" "otf"))
    (dired-rainbow-define
     partition "􀝦#e3342f"
     ("dmg" "iso" "bin" "nrg" "qcow" "toast" "vcd" "vmdk" "bak"))
    (dired-rainbow-define
     vc "􀝦#0074d9"
     ("git" "gitignore" "gitattributes" "gitmodules"))
    (dired-rainbow-define-chmod
     directory "􀝦#6cb2eb"
     "d.*")
    (dired-rainbow-define-chmod
     executable-unix
     "􀝦#38c172" "-.*x.*"))
  (font-lock-flush)
  (font-lock-ensure))

(setup dired-rainbow
  (:autoload nasy/-init-dired-rainbow dired-rainbow-define dired-rainbow-define-chmod)
  (:load-first dired)
  (:with-hook dired-mode-hook
    (:hook nasy/-init-dired-rainbow)))
6.7.1.9.3. Dired Narrow
(setup dired-narrow
  (:load-first dired))
6.7.1.9.4. Dired Collapse
(setup dired-collapse
  (:load-first dired)
  (:hook-into dired-mode-hook))
6.7.1.10. Dirvish   convenience files

Dirvish is an improved version of the Emacs inbuilt package Dired. It not only gives Dired an appealing and highly customizable user interface, but also comes together with almost all possible parts required for full usability as a modern file manager.

https://github.com/alexluigit/dirvish

(setup dirvish
  (:doc "A polished Dired with batteries included.")
  (:url "https://github.com/alexluigit/dirvish")
  (:tag "files" "convenience")
  (:first-key*
   (dirvish-override-dired-mode))
  (:opt delete-by-moving-to-trash t
        dirvish-default-layout    '(0 0.3 0.7)
        dirvish-reuse-session     nil
        dirvish-attributes
        '(vc-state subtree-state collapse file-time file-size)
        dirvish-preview-dispatchers nil)  ;; never preview
  (:global "C-c f" dirvish-fd)
  (:bindm dirvish-mode-map ; Dirvish inherits `dired-mode-map'
    "a"   dirvish-quick-access
    "f"   dirvish-file-info-menu
    "y"   dirvish-yank-menu
    "N"   dirvish-narrow
    "^"   dirvish-history-last
    "h"   dirvish-history-jump ; remapped `describe-mode'
    "s"   dirvish-quicksort    ; remapped `dired-sort-toggle-or-edit'
    "v"   dirvish-vc-menu      ; remapped `dired-view-file'
    "TAB" dirvish-subtree-toggle
    "M-f" dirvish-history-go-forward
    "M-b" dirvish-history-go-backward
    "M-l" dirvish-ls-switches-menu
    "M-m" dirvish-mark-menu
    "M-t" dirvish-layout-toggle
    "M-s" dirvish-setup-menu
    "M-e" dirvish-emerge-menu
    "M-j" dirvish-fd-jump))
6.7.1.11. eldoc box   docs extensions help

This package displays ElDoc documentations in a childframe.

https://github.com/casouri/eldoc-box

(setup eldoc-box
  (:doc "This package displays ElDoc documentations in a childframe.")
  (:url "https://github.com/casouri/eldoc-box")
  (:tag "docs" "extensions" "help")
  (:opt eldoc-box-only-multi-line t)
  (:with-hook eldoc-mode-hook
    (:hook eldoc-box-hover-at-point-mode)))
6.7.1.12. eldoc-overlay   extensions

Display eldoc doc with contextual documentation overlay for easy to look.

https://github.com/stardiviner/eldoc-overlay

(setup eldoc-overlay
  (:doc "Display eldoc doc with contextual documentation overlay for easy to look.")
  (:url "https://github.com/stardiviner/eldoc-overlay")
  (:tag "extensions")
  (:hook-into eldoc-mode-hook))
6.7.1.13. Expand Region   marking region

Emacs extension to increase selected region by semantic units.

https://github.com/magnars/expand-region.el

(setup expand-region
  (:doc "Emacs extension to increase selected region by semantic units.")
  (:url "https://github.com/magnars/expand-region.el")
  (:tag "marking" "region")
  (:global "C-=" er/expand-region))
6.7.1.14. Find File in Project   project convenience

Find file/directory and review Diff/Patch/Commit quickly everywhere.

https://github.com/technomancy/find-file-in-project

(setup find-file-in-project
  (:doc "Find file/directory and review Diff/Patch/Commit quickly everywhere.")
  (:url "https://github.com/technomancy/find-file-in-project")
  (:tag "project" "convenience")
  (:custom ffip-use-rust-fd t))
6.7.1.15. ftables   convenience table text

This package provides some convenient commands for filling a table, i.e., adjusting the layout of the table so it can fit in n columns.

https://github.com/casouri/ftable

(setup ftable
  (:doc "Fill (auto-layout) tables.")
  (:url "https://github.com/casouri/ftable")
  (:tag "convenience" "table" "text"))
6.7.1.16. Git Gutter   vc git

Disabled. Now use diff-hl

Emacs port of GitGutter which is Sublime Text Plugin GitGutter.

https://github.com/emacsorphanage/git-gutter

(setup git-gutter
  (:doc "Emacs port of GitGutter which is Sublime Text Plugin.")
  (:url "https://github.com/emacsorphanage/git-gutter")
  (:tag "vc" "git"))
6.7.1.17. Highlight Indent Guides   faces

Disabled.

Emacs minor mode to highlight indentation.

https://github.com/DarthFennec/highlight-indent-guides

(setup highlight-indent-guides
  (:doc "Emacs minor mode to highlight indentation.")
  (:url "https://github.com/DarthFennec/highlight-indent-guides")
  (:tag "faces")
  (:custom highlight-indent-guides-delay 0.5))
6.7.1.18. Highlight Tail   color effect highlight visual

This minor-mode draws a tail in real time, when you write.

https://www.emacswiki.org/emacs/highlight-tail.el

(setup highlight-tail
  (:doc "This minor-mode draws a tail in real time, when you write.")
  (:url "https://www.emacswiki.org/emacs/highlight-tail.el")
  (:tag "color" "effect" "highlight" "visual"))
6.7.1.19. hl-line   faces frame emulations

Highlight the current line of characters.

https://www.emacswiki.org/emacs/HighlightCurrentLine

(setup hl-line
  (:doc "Highlight the current line of characters.")
  (:url "https://www.emacswiki.org/emacs/HighlightCurrentLine")
  (:tag "faces" "frames" "emulations")
  (:hook-into prog-mode text-mode org-mode))
6.7.1.20. imenu list   tools convenience

Emacs plugin to show the current buffer's imenu entries in a seperate buffer.

https://github.com/bmag/imenu-list

(setup imenu-list
  (:doc "Emacs plugin to show the current buffer's imenu entries in a seperate buffer")
  (:url "https://github.com/bmag/imenu-list")
  (:tag "tools" "convenience")
  (:global "C-." imenu-list-smart-toggle)
  (:custom imenu-list-auto-resize t))
6.7.1.21. kind-icon   completion

kind-icon — colorful icons for completion in Emacs

This emacs package adds configurable icon or text-based completion prefixes based on the :company-kind property that many completion backends (such as lsp-mode and Emacs 28's elisp-mode) provide.

https://github.com/jdtsmith/kind-icon

(setup kind-icon
  (:doc "Completion kind text/icon prefix labelling for emacs in-region completion.")
  (:url "https://github.com/jdtsmith/kind-icon")
  (:tag "completion")
  (:load-first corfu)
  ;; (:custom kind-icon-default-face 'corfu-default)
  (:when-loaded (add-to-list 'corfu-margin-formatters #'kind-icon-margin-formatter)))
6.7.1.22. mixed-pitch   faces

Mixed pitch is a minor mode that enables mixing fixed-pitch (also known as fixed-width or monospace) and variable-pitch (AKA “proportional”) fonts. It tries to be smart about which fonts get which face. Fonts that look like code, org-tables, and such remain fixed-pitch and everything else becomes variable-pitch.

https://gitlab.com/jabranham/mixed-pitch

(eval-and-compile
  (defvar nasy--hl-line-bold nil))

(setup mixed-pitch
  (:doc "Mix fixed-pitch and variable-pitch fonts in Emacs.")
  (:url "https://gitlab.com/jabranham/mixed-pitch")
  (:tag "faces")
  (:custom mixed-pitch-variable-pitch-cursor '(hbar . 3))
  (:hook-into org-mode-hook)
  (:mode-hook
   (after-x 'hl-line
     (unless (boundp 'nasy--hl-line-bold)
       (setq nasy--hl-line-bold (face-attribute 'hl-line :weight)))
     (if mixed-pitch-mode
         (set-face-attribute 'hl-line nil :weight 'unspecified)
       (set-face-attribute 'hl-line nil :weight nasy--hl-line-bold))))
  (:after org
    (setq mixed-pitch-fixed-pitch-faces
          (append mixed-pitch-fixed-pitch-faces
                  org-level-faces
                  '(whitespace-hspace whitespace-space)
                  '(fixed-pitch fixed-pitch-serif)
                  '(org-date
                    org-footnote
                    org-special-keyword
                    org-property-value
                    org-ref-cite-face
                    org-tag
                    org-todo-keyword-todo
                    org-todo-keyword-habt
                    org-todo-keyword-done
                    org-todo-keyword-wait
                    org-todo-keyword-kill
                    org-todo-keyword-outd
                    org-todo
                    org-done
                    font-lock-comment-face)))))
6.7.1.23. mmm-mode   convenience faces languages tools

MMM Mode is a minor mode for Emacs that allows Multiple Major Modes to coexist in one buffer.

https://github.com/purcell/mmm-mode

(setup mmm-auto
  (:doc "MMM Mode is a minor mode for Emacs that allows Multiple Major Modes to coexist in one buffer.")
  (:url "https://github.com/purcell/mmm-mode")
  (:tag "convenience" "faces" "languages" "tools")
  (:custom
   mmm-global-mode              'maybe
   mmm-submode-decoration-level 2)
  (:first-key (lambda () (require 'mmm-mode))))
6.7.1.24. Multiple Cursors   cursors editing

Multiple cursors for Emacs.

https://github.com/magnars/multiple-cursors.el

(setup multiple-cursors
  (:doc "Multiple cursors for Emacs.")
  (:url "https://github.com/magnars/multiple-cursors.el")
  (:tag "editing" "cursors")
  (:global
   "C-<"     mc/mark-previous-like-this
   "C->"     mc/mark-next-like-this
   "C-+"     mc/mark-next-like-this
   "C-c C-<" mc/mark-all-like-this
   "C-c m r" set-rectangular-region-anchor
   "C-c m c" mc/edit-lines
   "C-c m e" mc/edit-ends-of-lines
   "C-c m a" mc/edit-beginnings-of-lines)
  (:opt*
   mc/list-file (concat *nasy-var* "mc-list.el")))
6.7.1.25. Persistent Scratch   convenience history

persistent-scratch is an Emacs package that preserves the state of scratch buffers accross Emacs sessions by saving the state to and restoring it from a file.

https://github.com/Fanael/persistent-scratch

(setup persistent-scratch
  (:doc "Preserve the scratch buffer across Emacs sessions.")
  (:url "https://github.com/Fanael/persistent-scratch")
  (:tag "convenience" "history")
  (:advice persistent-scratch-restore :after nasy/scratch)
  (:custom
   persistent-scratch-save-file (concat *nasy-var* "persistent-scratch.el")
   persistent-scratch-backup-directory (concat *nasy-var* "persistent-scratch/")))
6.7.1.26. Point History   editing history

Show the history of points you visited before.

https://github.com/blue0513/point-history

(setup point-history
  (:doc "Show the history of points you visited before.")
  (:url "https://github.com/blue0513/point-history")
  (:tag "editing")
  (:hook nasy-first-key-hook)
  (:global
   "C-c C-/" point-history-show)
  (:custom
   point-history-ignore-buffer "^ \\*Minibuf\\|^ \\*point-history-show*"))
6.7.1.27. Rainbow-Mode   faces

This minor mode sets background color to strings that match color names, e.g. #0000ff is displayed in white with a blue background.

https://elpa.gnu.org/packages/rainbow-mode.html

(defun nasy/rainbow-colorize-match (color &optional match)
  "Return a matched string propertized with a face whose background is COLOR.

 The foreground is computed using `rainbow-color-luminance',
 and is either 􀝦white or 􀝦black."
  (let ((match (or match 0)))
   (put-text-property
    (match-beginning match) (match-end match)
    'face `((:foreground ,(if (> 0.5 (rainbow-x-color-luminance color))
                              "􀝦white" "􀝦black"))
            (:background ,color)
            (:family ,*font-main-family*)))))

(setup rainbow-mode
  (:quit)
  (:doc "Colorize color names in buffers.")
  (:url "https://elpa.gnu.org/packages/rainbow-mode.html")
  (:tag "faces")
  (:autoload nasy/rainbow-colorize-match)
  (:advice rainbow-colorize-match :override nasy/rainbow-colorize-match)
  (:hook-into
   nasy-first-key-hook
   text-mode-hook
   org-mode-hook
   css-mode-hook
   html-mode-hook
   prog-mode-hook)
  (:when-loaded
    (eval-when-compile
      (defvar *font-main-family*))
    (when (fboundp 'diminish)
      (diminish 'rainbow-mode))))
6.7.1.28. Rainbow Delimiters   convenience faces lisp tools parens

rainbow-delimiters is a "rainbow parentheses"-like mode which highlights delimiters such as parentheses, brackets or braces according to their depth. Each successive level is highlighted in a different color. This makes it easy to spot matching delimiters, orient yourself in the code, and tell which statements are at a given depth.

https://github.com/Fanael/rainbow-delimiters

(setup rainbow-delimiters
  (:doc "Emacs rainbow delimiters mode")
  (:url "https://github.com/Fanael/rainbow-delimiters")
  (:tag "convenience" "faces" "lisp" "tools")
  (:hook-into prog-mode-hook org-src-mode-hook))
6.7.1.29. Shellcop   tools unix

Analyze errors reported in Emacs builtin shell

https://github.com/redguardtoo/shellcop

(setup shellcop
  (:quit)
  (:doc "Analyze errors reported in Emacs builtin shell.")
  (:url "https://github.com/redguardtoo/shellcop")
  (:tag "unix" "tools")
  (:with-hook shell-mode-hook
    (:hook shellcop-start)))
6.7.1.30. Smartparens   abbrev convenience editing parens

Minor mode for Emacs that deals with parens pairs and tries to be smart about it.

https://github.com/Fuco1/smartparens

(setup smartparens
  (:doc "Minor mode for Emacs that deals with parens pairs and tries to be smart about it.")
  (:url "https://github.com/Fuco1/smartparens")
  (:tag "abbrev" "convenience" "editing")
  (:first-key smartparens-global-mode)
  (:custom sp-hybrid-kill-entire-symbol nil))
6.7.1.31. Symbol Overlay   faces matching

Highlight symbols with overlays while providing a keymap for various operations about highlighted symbols. It was originally inspired by the package highlight-symbol. The fundamental difference is that in symbol-overlay every symbol is highlighted by the Emacs built-in function overlay-put rather than the font-lock mechanism used in highlight-symbol.

https://github.com/wolray/symbol-overlay

(setup symbol-overlay
  (:doc "Highlight symbols with keymap-enabled overlays.")
  (:url "https://github.com/wolray/symbol-overlay")
  (:tag "faces" "matching")
  (:global
   "M-i"  symbol-overlay-put
   "M-n"  symbol-overlay-switch-forward
   "M-p"  symbol-overlay-switch-backward
   "<f8>" symbol-overlay-remove-all
   "<f7>" symbol-overlay-mode))
6.7.1.32. Treemacs   convenience files

Treemacs is a file and project explorer similar to NeoTree or vim’s NerdTree, but largely inspired by the Project Explorer in Eclipse. It shows the file system outlines of your projects in a simple tree layout allowing quick navigation and exploration, while also possessing basic file management utilities.

https://github.com/Alexander-Miller/treemacs

(setup treemacs
  (:doc "A tree layout file explorer for Emacs")
  (:url "https://github.com/Alexander-Miller/treemacs")
  (:tag "convenience" "files")
  (:after winum
    (define-key winum-keymap (kbd "M-0") #'treemacs-select-window))
  (:when-loaded
    (progn
      (setq treemacs-collapse-dirs                   (if treemacs-python-executable 3 0)                treemacs-deferred-git-apply-delay      0.5
            treemacs-directory-name-transformer      #'identity
            treemacs-display-in-side-window          t
            treemacs-eldoc-display                   'detailed
            treemacs-file-event-delay                5000
            treemacs-file-extension-regex            treemacs-last-period-regex-value
            treemacs-file-follow-delay               0.2
            treemacs-file-name-transformer           #'identity
            treemacs-follow-after-init               t
            treemacs-expand-after-init               t
            treemacs-find-workspace-method           'find-for-file-or-pick-first
            treemacs-git-command-pipe                ""
            treemacs-goto-tag-strategy               'refetch-index
            treemacs-header-scroll-indicators        '(nil . "^^^^^^")
            treemacs-hide-dot-git-directory          t
            treemacs-indentation                     2
            treemacs-indentation-string              " "
            treemacs-is-never-other-window           nil
            treemacs-max-git-entries                 5000
            treemacs-missing-project-action          'ask
            treemacs-move-forward-on-expand          t
            treemacs-no-png-images                   nil
            treemacs-no-delete-other-windows         t
            treemacs-project-follow-cleanup          nil
            treemacs-persist-file                    (concat *nasy-var* "treemacs-persist")
            treemacs-position                        'left
            treemacs-recenter-distance               0.1
            treemacs-recenter-after-file-follow      nil
            treemacs-recenter-after-tag-follow       nil
            treemacs-recenter-after-project-jump     'always
            treemacs-recenter-after-project-expand   'on-distance
            treemacs-litter-directories              '("/node_modules" "/.venv" "/.cask")
            treemacs-show-cursor                     nil
            treemacs-show-hidden-files               t
            treemacs-silent-filewatch                nil
            treemacs-silent-refresh                  nil
            treemacs-sorting                         'alphabetic-asc
            treemacs-select-when-already-in-treemacs 'move-back
            treemacs-space-between-root-nodes        t
            treemacs-tag-follow-cleanup              t
            treemacs-tag-follow-delay                1.5
            treemacs-text-scale                      nil
            treemacs-user-mode-line-format           nil
            treemacs-user-header-line-format         nil
            treemacs-wide-toggle-width               70
            treemacs-width                           35
            treemacs-width-increment                 1
            treemacs-width-is-initially-locked       t
            treemacs-workspace-switch-cleanup        nil)
     ;; The default width and height of the icons is 22 pixels. If you are
     ;; using a Hi-DPI display, uncomment this to double the icon size.
     ;; (treemacs-resize-icons 44)
     (treemacs-follow-mode 1)
     (treemacs-filewatch-mode 1)
     (treemacs-fringe-indicator-mode 'always)
     (when treemacs-python-executable
       (treemacs-git-commit-diff-mode t))

     (pcase (cons (not (null (executable-find "git")))
                  (not (null treemacs-python-executable)))
        (`(t . t)
          (treemacs-git-mode 'deferred))
        (`(t . _)
          (treemacs-git-mode 'simple))))))


;; (setup treemacs-icons-dired
;;   (:load-first treemacs dired)
;;   (:when-loaded (treemacs-icons-dired-mode)))

(setup treemacs-magit
  (:load-first treemacs magit))

(setup treemacs-projectile
  (:load-first treemacs projectile))
6.7.1.33. Tree Sitter   languages parsers tools

emacs-tree-sitter is an Emacs binding for tree-sitter, an incremental parsing system.

https://ubolonton.github.io/emacs-tree-sitter/

;; (setup tree-sitter
;;   (:doc "emacs-tree-sitter is an Emacs binding for tree-sitter, an incremental parsing system.")
;;   (:url "https://github.com/ubolonton/emacs-tree-sitter")
;;   (:tag "languagues" "parsers" "tools")
;;   (:hook-into
;;    agda-mode-hook
;;    c-mode-hook
;;    c++-mode-hook
;;    css-mode-hook
;;    emacs-lisp-mode-hook
;;    html-mode-hook
;;    js-mode-hook
;;    js2-mode-hook
;;    son-mode-hook
;;    python-mode-hook
;;    ruby-mode-hook
;;    rust-mode-hook
;;    typescript-mode-hook)
;;   (:when-loaded
;;     (require 'tree-sitter-langs)
;;     (add-to-list 'tree-sitter-major-mode-language-alist '(mhtml-mode . html))
;;     (add-to-list 'tree-sitter-major-mode-language-alist '(emacs-lisp-mode . elisp))))


;; (setup tree-sitter-hl
;;   (:load-first tree-sitter tree-sitter-langs)
;;   (:hook-into css-mode-hook python-mode-hook))
6.7.1.34. Tree Sitter Indent   convenience internal

https://codeberg.org/FelipeLema/tree-sitter-indent.el.git

;; (setup tree-sitter-indent
;;   (:doc "Use Tree-sitter as backend to source code indentation.")
;;   (:url "https://codeberg.org/FelipeLema/tree-sitter-indent.el")
;;   (:tag "convenience" "internal")
;;   (:hook-into tree-sitter-mode-hook))

;; (setup tree-sitter-indent
;;   (:load-first tree-sitter-indent)
;;   (:custom c-indent-offset tree-sitter-indent-offset))
6.7.1.35. Tree Sitter Fold (ts-fold)   convenience folding

ts-fold builds on top of elisp-tree-sitter to provide code folding base on the tree-sitter syntax tree.

https://github.com/jcs090218/ts-fold

;; (setup ts-fold
;;   (:doc "Code-folding using tree-sitter.")
;;   (:url "https://github.com/jcs090218/ts-fold")
;;   (:tag "folding" "convenience")
;;   (:global "C-c @" ts-fold-toggle))
6.7.1.36. Undo Propose   convenience files undo redo history

Navigate the emacs undo history by staging undo's in a temporary buffer.

https://github.com/jackkamm/undo-propose-el

(setup undo-propose
  (:doc "Navigate the emacs undo history by staging undo's in a temporary buffer.")
  (:url "https://github.com/jackkamm/undo-propose-el")
  (:tag "convenience" "files" "undo" "redo" "history")
  (:global "C-c u" undo-propose))
6.7.1.37. Visual-fill-column   convenience

Emacs mode for wrapping visual-line-mode buffers at fill-column.

https://github.com/joostkremers/visual-fill-column

(setup visual-fill-column
  (:doc "Emacs mode for wrapping visual-line-mode buffers at fill-column.")
  (:url "https://github.com/joostkremers/visual-fill-column")
  (:tag "convenience")
  (:advice text-scale-adjust :after visual-fill-column-adjust)
  (:custom
   visual-fill-column-width 100)
  (:hook-into
   tex-mode-hook
   TeX-mode-hook
   latex-mode-hook
   LaTeX-mode-hook)
  (:mode-hook
   (if visual-fill-column-mode
       (setq split-window-preferred-function #'visual-fill-column-split-window-sensibly)
     (setq split-window-preferred-function #'split-window-sensibly))))
6.7.1.38. vundo   undo redo

Visual undo tree.

https://archive.casouri.cat/note/2021/visual-undo-tree/index.html

https://github.com/casouri/vundo

(setup vundo
  (:doc "Visual undo tree.")
  (:url "https://github.com/casouri/vundo")
  (:tag "undo" "redo")
  (:opt
   vundo-window-side        'bottom
   vundo-window-max-height  5
   vundo-glyph-alist        vundo-unicode-symbols)
  (:global
   "s-/" vundo))
6.7.1.39. Which Key   help

Emacs package that displays available keybindings in popup.

https://github.com/justbur/emacs-which-key

(setup which-key
  (:doc "Emacs package that displays available keybindings in popup.")
  (:url "https://github.com/justbur/emacs-which-key")
  (:tag "help")
  (:custom which-key-allow-imprecise-window-fit nil)
  (:hook-into nasy-first-key-hook))
6.7.1.40. Writeroom   text

writeroom-mode is a minor mode for Emacs that implements a distraction-free writing mode similar to the famous Writeroom editor for macOS.

https://github.com/joostkremers/writeroom-mode

(setup writeroom-mode
  (:doc "Writeroom-mode: distraction-free writing for Emacs.")
  (:url "https://github.com/joostkremers/writeroom-mode")
  (:tag "text")
  (:custom
   writeroom-global-effects
   '(;; writeroom effects
     ;; writeroom-set-fullscreen
     writeroom-set-alpha
     writeroom-set-menu-bar-lines
     ;; writeroom-set-tool-bar-lines
     writeroom-set-vertical-scroll-bars
     writeroom-set-bottom-divider-width)
   writeroom-fullscreen-effect 'maximized
   writeroom-maximize-window   nil
   writeroom-width             1.0))
6.7.1.41. yank-pulse   text
;; From https://christiantietze.de/posts/2020/12/emacs-pulse-highlight-yanked-text/
(defun nasy/-yank-pulse-advice (orig-fn &rest args)
  ;; Define the variables first
  (let (begin end)
    ;; Initialize `begin` to the current point before pasting
    (setq begin (point))
    ;; Forward to the decorated function (i.e. `yank`)
    (apply orig-fn args)
    ;; Initialize `end` to the current point after pasting
    (setq end (point))
    ;; Pulse to highlight!
    (pulse-momentary-highlight-region begin end)))

(setup pulse
  (:advice yank :around nasy/-yank-pulse-advice))
6.7.1.42. Yasnipeet   convenience emulation

YASnippet is a template system for Emacs. It allows you to type an abbreviation and automatically expand it into function templates. Bundled language templates include: C, C++, C#, Perl, Python, Ruby, SQL, LaTeX, HTML, CSS and more. The snippet syntax is inspired from TextMate's syntax, you can even import most TextMate templates to YASnippet. Watch a demo on YouTube.

https://github.com/joaotavora/yasnippet

https://github.com/sei40kr/license-snippets

https://github.com/AndreaCrotti/yasnippet-snippets

(defvar nasy-yas-new-snippet (concat *nasy-etc* "yas-new")
  "Yasnippet prompt.")


(defun nasy/yas-new-snippet-with-example ()
  "https://mjdiloreto.github.io/posts/yasnippet-helpful-buffer/"
  (interactive)
  (funcall-interactively 'yas-new-snippet)
  (erase-buffer)
  (insert-file-contents nasy-yas-new-snippet))


(setup yasnippet
  (:doc "A template system for Emacs")
  (:url "https://github.com/joaotavora/yasnippet")
  (:tag "convenience" "enmulation")
  (:load-first company corfu)
  (:autoload yas-minor-mode
             yas-reload-all)
  (:custom
   yas-snippet-dirs `(,(concat *nasy-etc* "yasnippet/snippets/")))
  (:with-mode yas-minor-mode
    (:hook-into prog-mode-hook text-mode-hook)
    (:bind
     [remap yas-new-snippet] nasy/yas-new-snippet-with-example))
  (:when-loaded
    (license-snippets-init)
    (yas-reload-all)))

6.8. 庭燎

(add-to-list 'load-path (locate-user-emacs-file  "桃夭/庭燎"))
(require '庭燎)

小雅・彤弓之什・庭燎

夜如何其、夜未央、庭燎之光
君子至止、鸞聲將將

夜如何其、夜未艾、庭燎皙皙
君子至止、鸞聲噦噦

夜如何其、夜郷晨、庭燎有煇
君子至止、言觀其旂

容皃也

UI

6.8.1.

6.8.1.1. Calendar

Also cal-china-x

This extension mainly adds the following extra features:

  • Chinese localizations
  • Display holiday, lunar(农历), horoscope(星座), zodiac(属相、十二生肖), solar term(节气) info on mode line
  • Define holidays using holiday-lunar, holiday-solar-term
  • Highlight holidays based on different priorities
  • Add cal-china-x-chinese-holidays, cal-china-x-japanese-holidays.
  • Custom week diary (like weeks in school)

https://github.com/xwl/cal-china-x

(defun nasy/chinese-date-string (date)
  "Nasy version calendar string of DATE."
  (let* ((cn-date (calendar-chinese-from-absolute
                   (calendar-absolute-from-gregorian date)))
         (cn-year  (cadr   cn-date))
         (cn-month (cl-caddr  cn-date))
         (cn-day   (cl-cadddr cn-date)))
    (format "黃帝%s%s%s%s%s%s(%s)"
            (+ 2698 (calendar-extract-year date))
            (calendar-chinese-sexagesimal-name cn-year)
            ;; (aref cal-china-x-zodiac-name (% (1- cn-year) 12))
            (aref cal-china-x-month-name (1-  (floor cn-month)))
            (if (integerp cn-month) "" "(闰月)")
            (aref cal-china-x-day-name (1- cn-day))
            (cal-china-x-get-solar-term date)
            (cal-china-x-get-horoscope (car date) (cadr date)))))


(defun nasy/init-chinese-calendar ()
  "Initial Chinese calendar."
  (setq calendar-date-display-form
        '((cal-china-x-calendar-display-form
           (mapcar (lambda (el) (string-to-number el))
                   (list month day year)))))

  (setq diary-date-forms chinese-date-diary-pattern)

  (setq calendar-chinese-celestial-stem cal-china-x-celestial-stem
        calendar-chinese-terrestrial-branch cal-china-x-terrestrial-branch)

  ;; (setq calendar-month-header '(propertize (format "%d年%2d月" year month)
  ;;                                          'font-lock-face
  ;;                                          'calendar-month-header))

  (when cal-china-x-force-chinese-week-day
    (setq calendar-day-header-array cal-china-x-days))

  (setq calendar-mode-line-format
        (list
         (calendar-mode-line-entry 'calendar-scroll-right "previous month" "<")
         ;; "日曆"

         '(cal-china-x-get-holiday date)

         '(concat " " (calendar-date-string date t)
                  (format " 第%d周"
                          (funcall (if cal-china-x-custom-week-start-date
                                       'cal-china-x-custom-week-of-date
                                     'cal-china-x-week-of-date)
                                   date)))

         '(nasy/chinese-date-string date)

         ;; " "

         ;; (concat
         ;;  (calendar-mode-line-entry 'calendar-goto-info-node "read Info on Calendar"
         ;;                            nil "info")
         ;;  " / "
         ;;  (calendar-mode-line-entry 'calendar-other-month "choose another month"
         ;;                            nil "other")
         ;;  " / "
         ;;  (calendar-mode-line-entry 'calendar-goto-today "go to today's date"
         ;;                            nil "today"))

         (calendar-mode-line-entry 'calendar-scroll-left "next month" ">")))

  (add-hook 'calendar-move-hook 'calendar-update-mode-line)
  (add-hook 'calendar-initial-window-hook 'calendar-update-mode-line)

  (add-hook 'calendar-mode-hook
            (lambda ()
              (set (make-local-variable 'font-lock-defaults)
                   ;; chinese month and year
                   '((("[0-9]+年\\ *[0-9]+月" . font-lock-function-name-face)) t))))


  (advice-add 'calendar-mark-holidays :around 'cal-china-x-mark-holidays)
  (advice-add 'mouse-set-point :after 'cal-china-x-mouse-set-point))


(setup calendar
  (:customs
   ;; 爾雅 月名
   ((calendar-chinese-month-name-array cal-china-x-month-name)
    . ["陬月" "如月" "寎月" "余月" "皋月" "且月"
       "相月" "壯月" "玄月" "陽月" "辜月" "涂月"])))


(setup cal-china-x
  (:doc "chinese localization, prioritized holiday highlight, lunar, horoscope, zodiac, etc.")
  (:url "https://github.com/xwl/cal-china-x")
  (:tag "calendar" "date")
  (:opt
   cal-china-x-force-chinese-week-day t
   cal-china-x-always-show-jieqi      t)
  (:first-key
   (lambda ()
     (progn
       (require 'calendar)
       (require 'cal-china-x)
       (nasy/init-chinese-calendar)))))

6.8.1.2. Centaur Tab

This projects aims to become an aesthetic, functional and efficient tabs plugin for Emacs with a lot of customization options.

https://github.com/ema2159/centaur-tabs

(setup centaur-tabs
  (:advice centaur-tabs-buffer-groups :override nasy/-centaur-tabs-buffer-groups)
  (:opt
   centaur-tabs-style "wave")
  (:with-hook nasy/font-change-hook
    (:hook (lambda () (nasy/set-symbol ?⏺ 14)))))


(defun nasy/-enable-centaur-tabs-local-mode ()
  (unless centaur-tabs-mode
    (centaur-tabs-mode 1))
  (centaur-tabs-local-mode 1))

(defun nasy/-disable-centaur-tabs-local-mode ()
  (unless centaur-tabs-mode
    (centaur-tabs-mode 1))
  (centaur-tabs-local-mode -1))


(defvar nasy--centaur-text-modes
  '(org-mode org-agenda-mode org-agenda-clockreport-mode
             org-agenda-log-mode org-beamer-mode
             org-bullets-mode org-cdlatex-mode
             org-indent-mode org-src-mode diary-mode
             text-mode markdown-mode))

(defvar nasy--centaur-vc-modes
  '(magit-blame-mode magit-blob-mode magit-diff-mode
                     magit-file-mode magit-log-mode
                     magit-process-mode magit-status-mode))


(defun nasy/-centaur-tabs-buffer-groups ()
  "Nasy's centaur tabs groups."
  (let ((bn (buffer-name)))
    (list
     (cond
      ;; org, markdown & text
      ((or (memq major-mode nasy--centaur-text-modes)
           (string-prefix-p "*Org Src" bn)
           (string-prefix-p "*Org Export" bn))
       "書寫")

      ;; VC
      ((memq major-mode nasy--centaur-vc-modes)
       "Magit")

      ;; Shell
      ((memq major-mode '(eshell-mode shell-mode vterm-mode))
       "Shell")

      ;; Info & Help
      ((memq major-mode '(help-mode info-mode helpful-mode))
       "注")

      ;; programming
      ((derived-mode-p 'prog-mode)
       "編程")

      ;; Web Page
      ((or (memq major-mode '(eww-mode xwidget-webkit-mode))
           (string-prefix-p "*xwidget webkit" bn))
       "網頁")

      ;; Emacs
      ((string-prefix-p "*" bn)
       "虛")

      ;; 
      (t (centaur-tabs-get-group-name (current-buffer)))))))


(setup centaur-tabs
  (:quit)
  (:opt
   centaur-tabs-set-modified-marker t
   centaur-tabs-height     28
   centaur-tabs-bar-height 30
   centaur-tabs-set-close-button      nil
   centaur-tabs-enable-ido-completion nil)
  (:first-key nasy/-disable-centaur-tabs-local-mode)
  (:mode-hook
   ;; (centaur-tabs-headline-match)

   (customize-set-variable 'centaur-tabs-set-icons t
                           "Customized by Nasy in `centaur-tabs' block")
   (customize-set-variable 'centaur-tabs-show-navigation-buttons t
                           "Customized by Nasy in `centaur-tabs' block")
   (setq centaur-tabs-active-bar
         (centaur-tabs--make-xpm 'centaur-tabs-active-bar-face
                                4
                                centaur-tabs-bar-height))))

6.8.1.3. Dashboard
(setup dashboard
  (:autoload dashboard-refresh-buffer
             dashboard-setup-startup-hook))


(defun nasy/-set-dashboard-init-info (&rest _)
  (setq dashboard-init-info
        (let ((package-count 0) (time (emacs-init-time)))
          (setq package-count (+ (hash-table-size straight--profile-cache) package-count))
          (if (zerop package-count)
              (format "Emacs started in %s" time)
            (format "%d packages loaded in %s" package-count time)))))


(defun nasy/-dashboard-items (_)
  (insert "\n       ")
  (widget-create 'item
                 :tag "近期 (r)"
                 :action #'consult-recent-file
                 :mouse-face 'highlight
                 :button-face 'dashboard-heading
                 :button-prefix "􀯛 "
                 :button-suffix ""
                 :format "%[%t%]"
                 :help-echo "open recent files")
  (insert "\t")
  (widget-create 'item
                 :tag "書籤 (b)"
                 :action #'consult-bookmark
                 :mouse-face 'highlight
                 :button-face 'dashboard-heading
                 :button-prefix "􀉚 "
                 :button-suffix ""
                 :format "%[%t%]"
                 :help-echo "open bookmarks")
  (insert "\t")
  (widget-create 'item
                 :tag "項目 (p)"
                 :action #'projectile-switch-project
                 :mouse-face 'highlight
                 :button-face 'dashboard-heading
                 :button-prefix "􀉹  "
                 :button-suffix ""
                 :format "%[%t%]"
                 :help-echo "open projects")
  (insert "\n\n       ")
  (widget-create 'item
                 :tag "草稿 (c)"
                 :action #'persistent-scratch-restore
                 :mouse-face 'highlight
                 :button-face 'dashboard-heading
                 :button-prefix "􀤑 "
                 :button-suffix ""
                 :format "%[%t%]"
                 :help-echo "restore scratch buffer")
  (insert "\t")
  (widget-create 'item
                 :tag "議程 (a)"
                 :action #'org-agenda
                 :mouse-face 'highlight
                 :button-face 'dashboard-heading
                 :button-prefix "􀮝 "
                 :button-suffix ""
                 :format "%[%t%]"
                 :help-echo "Org Agenda")
  (insert "\t")
  (widget-create 'item
                 :tag "日曆 (d)"
                 :action #'calendar
                 :mouse-face 'highlight
                 :button-face 'dashboard-heading
                 :button-prefix "􀉉 "
                 :button-suffix ""
                 :format "%[%t%]"
                 :help-echo "open calendar")
  (insert "\n\n       ")
  (widget-create 'item
                 :tag "芄蘭 (C)"
                 :action #'nasy/-open-custom
                 :mouse-face 'highlight
                 :button-face 'dashboard-heading
                 :button-prefix "􀍟 "
                 :button-suffix ""
                 :format "%[%t%]"
                 :help-echo "open custom file")
  (insert "\t")
  (widget-create 'item
                 :tag "源碼 (s)"
                 :action #'nasy/-open-source-page
                 :mouse-face 'highlight
                 :button-face 'dashboard-heading
                 :button-prefix "􀧎 "
                 :button-suffix ""
                 :format "%[%t%]"
                 :help-echo "open https://github.com/nasyxx/emacs.d/")
  (insert "\t")
  (widget-create 'item
                 :tag "文檔 (D)"
                 :action #'nasy/-open-document
                 :mouse-face 'highlight
                 :button-face 'dashboard-heading
                 :button-prefix "􀉅  "
                 :button-suffix ""
                 :format "%[%t%]"
                 :help-echo "open https://emacs.nasy.moe")
  (insert "\n\n"))


(defun nasy/dashboard-refresh ()
  "Refresh dashboard buffer."
  (interactive)
  (unless (get-buffer dashboard-buffer-name)
    (generate-new-buffer "*dashboard*"))
  (dashboard-refresh-buffer))


(declare-function persistent-scratch-restore "persistent-scratch")


(setup dashboard
  (:global
   "<f5>" dashboard-refresh-buffer)
  (:bindm dashboard-mode-map
   "r"              consult-recent-file
   "b"              consult-bookmark
   "p"              projectile-switch-project
   "c"              persistent-scratch-restore
   "a"              org-agenda
   "d"              calendar
   "C"              nasy/-open-custom
   "s"              nasy/-open-source-page
   "D"              nasy/-open-document
   "g"              dashboard-refresh-buffer
   "<down-mouse-1>" nil
   "H-p"            dashboard-previous-line
   "H-n"            dashboard-next-line
   "H-b"            widget-backward
   "H-f"            widget-forward
   "<mouse-1>"      widget-button-click
   "<mouse-2>"      widget-button-click
   "<up>"           widget-backward
   "<down>"         nasy/wfw1
   [remap previous-line] widget-backward
   [remap next-line]     nasy/wfw1)
  (:hooks
   dashboard-mode-hook (lambda () (setq-local tab-width 1 mode-line-format nil))
   after-init-hook     dashboard-setup-startup-hook
   after-init-hook     dashboard-refresh-buffer)
   ;; nasy/font-change-hook (lambda ()
   ;;                         (progn
   ;;                           (nasy/set-apple-symbol ?🌓)
   ;;                           (nasy/set-apple-symbol ?🔖)
   ;;                           (nasy/set-apple-symbol ?🚀)
   ;;                           (nasy/set-apple-symbol ?📝)
   ;;                           (nasy/set-apple-symbol ?🗓)
   ;;                           (nasy/set-apple-symbol ?📅)
   ;;                           (nasy/set-apple-symbol ?⚙)
   ;;                           (nasy/set-apple-symbol ?🍭)
   ;;                           (nasy/set-apple-symbol ?📖))))
  (:opt*
   dashboard-items '((n-items . t))
                     ;; (bookmarks . t)
                     ;; (registers . 5)
                     ;; (agenda    . 5)
                     ;; (projects  . 7))))
   dashboard-item-generators '((n-items . nasy/-dashboard-items))
   dashboard-startup-banner  (concat *nasy-etc* "n_icon.png"))
  (:opts*
   ((dashboard-center-content
     dashboard-set-heading-icons
     dashboard-set-init-info)
    . t))
  (:advice dashboard-refresh-buffer :before nasy/-set-dashboard-init-info))
6.8.1.4. doom Theme
(setup doom-themes
  (:first-key* (require 'doom-themes))
  (:opt
   doom-dracula-brighter-comments t
   doom-dracula-colorful-headers  t
   doom-dracula-comment-bg        t
   ;; doom-themes-treemacs-theme "doom-colors"
   doom-themes-org-fontify-special-tags nil)
  (:when-loaded
   ;; (after-x 'treemacs
   ;;   (doom-themes-treemacs-config))
   ;; (doom-themes-visual-bell-config)
   (after-x 'org
     (doom-themes-org-config))))
6.8.1.5. Icons   icons

以 nerd font 显眎圖幖

(setup nerd-icons
  (:after kind-icon
    (:opt
     kind-icon-use-icons nil
     kind-icon-mapping
     `((array          ,(nerd-icons-codicon "nf-cod-symbol_array")       :face font-lock-type-face)
       (boolean        ,(nerd-icons-codicon "nf-cod-symbol_boolean")     :face font-lock-builtin-face)
       (class          ,(nerd-icons-codicon "nf-cod-symbol_class")       :face font-lock-type-face)
       (color          ,(nerd-icons-codicon "nf-cod-symbol_color")       :face success)
       (command        ,(nerd-icons-codicon "nf-cod-terminal")           :face default)
       (constant       ,(nerd-icons-codicon "nf-cod-symbol_constant")    :face font-lock-constant-face)
       (constructor    ,(nerd-icons-codicon "nf-cod-triangle_right")     :face font-lock-function-name-face)
       (enummember     ,(nerd-icons-codicon "nf-cod-symbol_enum_member") :face font-lock-builtin-face)
       (enum-member    ,(nerd-icons-codicon "nf-cod-symbol_enum_member") :face font-lock-builtin-face)
       (enum           ,(nerd-icons-codicon "nf-cod-symbol_enum")        :face font-lock-builtin-face)
       (event          ,(nerd-icons-codicon "nf-cod-symbol_event")       :face font-lock-warning-face)
       (field          ,(nerd-icons-codicon "nf-cod-symbol_field")       :face font-lock-variable-name-face)
       (file           ,(nerd-icons-codicon "nf-cod-symbol_file")        :face font-lock-string-face)
       (folder         ,(nerd-icons-codicon "nf-cod-folder")             :face font-lock-doc-face)
       (interface      ,(nerd-icons-codicon "nf-cod-symbol_interface")   :face font-lock-type-face)
       (keyword        ,(nerd-icons-codicon "nf-cod-symbol_keyword")     :face font-lock-keyword-face)
       (macro          ,(nerd-icons-codicon "nf-cod-symbol_misc")        :face font-lock-keyword-face)
       (magic          ,(nerd-icons-codicon "nf-cod-wand")               :face font-lock-builtin-face)
       (method         ,(nerd-icons-codicon "nf-cod-symbol_method")      :face font-lock-function-name-face)
       (function       ,(nerd-icons-codicon "nf-cod-symbol_method")      :face font-lock-function-name-face)
       (module         ,(nerd-icons-codicon "nf-cod-file_submodule")     :face font-lock-preprocessor-face)
       (numeric        ,(nerd-icons-codicon "nf-cod-symbol_numeric")     :face font-lock-builtin-face)
       (operator       ,(nerd-icons-codicon "nf-cod-symbol_operator")    :face font-lock-comment-delimiter-face)
       (param          ,(nerd-icons-codicon "nf-cod-symbol_parameter")   :face default)
       (property       ,(nerd-icons-codicon "nf-cod-symbol_property")    :face font-lock-variable-name-face)
       (reference      ,(nerd-icons-codicon "nf-cod-references")         :face font-lock-variable-name-face)
       (snippet        ,(nerd-icons-codicon "nf-cod-symbol_snippet")     :face font-lock-string-face)
       (string         ,(nerd-icons-codicon "nf-cod-symbol_string")      :face font-lock-string-face)
       (struct         ,(nerd-icons-codicon "nf-cod-symbol_structure")   :face font-lock-variable-name-face)
       (text           ,(nerd-icons-codicon "nf-cod-text_size")          :face font-lock-doc-face)
       (typeparameter  ,(nerd-icons-codicon "nf-cod-list_unordered")     :face font-lock-type-face)
       (type-parameter ,(nerd-icons-codicon "nf-cod-list_unordered")     :face font-lock-type-face)
       (unit           ,(nerd-icons-codicon "nf-cod-symbol_ruler")       :face font-lock-constant-face)
       (value          ,(nerd-icons-codicon "nf-cod-symbol_field")       :face font-lock-builtin-face)
       (variable       ,(nerd-icons-codicon "nf-cod-symbol_variable")    :face font-lock-variable-name-face)
       (t              ,(nerd-icons-codicon "nf-cod-code")               :face font-lock-warning-face)))))

(setup nerd-icons-ibuffer
  (:hook-into ibuffer-mode-hook))

(setup nerd-icons-completion
  (:first-key nerd-icons-completion-mode))

(setup treemacs-nerd-icons
  (:after* treemacs
    (:require treemacs-nerd-icons)
    (treemacs-load-theme "nerd-icons")))
6.8.1.6. Ligature

This package maps ordinary graphemes (characters) to fancy ligatures, if both your version of Emacs and the font supports it.

With this package you can control where Emacs must display ligatures. That is useful if you only want a subset of the ligatures in certain major modes, for instance, or if you want to ensure that some modes have no ligatures at all.

https://github.com/mickeynp/ligature.el

(setup ligature
  (:after ligature
   (ligature-set-ligatures
    't
    '("|||>" "<|||" "<==>" "<!--" "####" "~~>" "***" "||=" "||>"
      ":::" "::=" "=:=" "===" "==>" "=!=" "=>>" "=<<" "=/=" "!=="
      "!!." ">=>" ">>=" ">>>" ">>-" ">->" "->>" "-->" "---" "-<<"
      "<~~" "<~>" "<*>" "<||" "<|>" "<$>" "<==" "<=>" "<=<" "<->"
      "<--" "<-<" "<<=" "<<-" "<<<" "<+>" "</>" "###" "#_(" "..<"
      "..." "+++" "/==" "///" "_|_" "www" "&&" "^=" "~~" "~@" "~="
      "~>" "~-" "**" "*>" "*/" "||" "|}" "|]" "|=" "|>" "|-" "{|"
      "[|" "]#" "::" ":=" ":>" ":<" "$>" "==" "=>" "!=" "!!" ">:"
      ">=" ">>" ">-" "-~" "-|" "->" "--" "-<" "<~" "<*" "<|" "<:"
      "<$" "<=" "<>" "<-" "<<" "<+" "</" "#{" "#[" "#:" "#=" "#!"
      "##" "#(" "#?" "#_" "%%" ".=" ".-" ".." ".?" "+>" "++" "?:"
      "?=" "?." "??" ";;" "/*" "/=" "/>" "//" "__" "~~" "(*" "*)"
      "\\\\" "://" "ff" "fi" "ffi")))
  (:first-key global-ligature-mode))
(defvar nasy-prog-mode-first-key-hook nil)
(defvar nasy--prog-mode-first-key-hook nil)

(defun nasy/-load-prog-mode ()
  (setq nasy--prog-mode-first-key-hook nasy-prog-mode-first-key-hook)
  (nasy/run-hook-once-on 'nasy--prog-mode-first-key-hook 'pre-command-hook))

(add-hook 'prog-mode-hook #'nasy/-load-prog-mode)

(add-hook 'nasy-prog-mode-first-key-hook #'(lambda () (global-ligature-mode 1)))
6.8.1.7. Mode Line
(defun nasy/-start-display-time ()
  "Nasy start display time mode."
  (customize-set-variable 'display-time-24hr-format          t "Customized by Nasy.")
  (customize-set-variable 'display-time-day-and-date         t "Customized by Nasy.")
  (customize-set-variable 'display-time-load-average         nil "Customized by Nasy.")
  (customize-set-variable 'display-time-default-load-average nil "Customized by Nasy.")
  (display-time-mode 1))

(add-hook 'nasy-first-key-hook #'nasy/-start-display-time)
(setup nyan-mode
  (:opt
   nyan-animate-nyancat t
   nyan-bar-length      16
   nyan-wavy-trail      t)
  (:hook-into nasy-first-key-hook))
(setup minions
  (:opt
   minions-mode-line-lighter "✬")
  (:hook-into nasy-first-key-hook))
(setup doom-modeline
  (:hook-into emacs-startup-hook))

(setup doom-modeline
  (:opt
   inhibit-compacting-font-caches   t
   doom-modeline-bar-width          5
   doom-modeline-window-width-limit fill-column
   doom-modeline-project-detection  'ffip  ;; changed
   doom-modeline-continuous-word-count-modes
   '(markdown-mode gfm-mode org-mode text-mode))
  (:opts
   ((doom-modeline-icon             ;; changed
     doom-modeline-unicode-fallback ;; changed
     doom-modeline-minor-modes)      ;; changed
     ;; doom-modeline-hud)             ;; changed
    . t))
  (:opt
   doom-modeline-buffer-encoding       nil  ;; changed
   doom-modeline-checker-simple-format nil  ;; changed
   doom-modeline-persp-name            nil))  ;; changed
6.8.1.8. Nasy Theme
(setup nasy-theme)
6.8.1.9. Main Theme
(defun nasy/load-theme ()
  "Nasy load theme function"
  (when *theme*
    (require 'nasy-theme)
    (load-theme *theme* t)))

(add-hook 'after-init-hook #'nasy/load-theme)
6.8.1.10. Tool Bar
(setup tool-bar
  (:tag "builtin")
  (:bindm tool-bar-map
    [copy]            nil
    [cut]             nil
    [dired]           nil
    [isearch-forward] nil
    [new-file]        nil
    [open-file]       nil
    [paste]           nil
    [save-buffer]     nil
    [undo]            nil
    [yank]            nil)
  (:init (tool-bar-mode -1)))
6.8.1.11. Tab Line
;; (add-hook 'after-init-hook #'global-tab-line-mode)
;; (setq tab-line-close-tab-function #'kill-buffer)

6.9. 日月

(add-to-list 'load-path (locate-user-emacs-file  "桃夭/日月"))
(require '日月)

國風・邶風・日月

日居月諸、照臨下土
乃如之人兮、逝不古處
胡能有定、寧不我顧

日居月諸、下土是冒
乃如之人兮、逝不相好
胡能有定、寧不我報

日居月諸、出自東方
乃如之人兮、徝音無良
胡能有定、俾也可忘

日居月諸、東方自出
父兮母兮、畜我不卒
胡能有定、報我不述

無關 Emacs 也用之亦可弃置亦可

Applications.

6.9.1.

6.9.1.1. alert   emacs message notification

A Growl-like alerts notifier for Emacs

https://github.com/jwiegley/alert

(setup alert
  (:doc "A Growl-like alerts notifier for Emacs.")
  (:url "https://github.com/jwiegley/alert")
  (:tag "notification" "emacs" "message")
  (:custom
   alert-default-style 'osx-notifier))
6.9.1.2. Carbon Now sh   convenience

Emacs to carbon.now.sh integration.

https://github.com/veelenga/carbon-now-sh.el

Try: M-x carbon-now-sh RET

(setup carbon-now-sh
  (:doc "Emacs to carbon.now.sh integration.")
  (:url "https://github.com/veelenga/carbon-now-sh.el")
  (:tag "convenience"))
6.9.1.3. Cheat Sh   docs help

Simple Emacs interface for cheat.sh.

https://github.com/davep/cheat-sh.el

(setup cheat-sh
  (:doc "Simple Emacs interface for cheat.sh")
  (:url "https://github.com/davep/cheat-sh.el")
  (:tag "docs" "help"))
6.9.1.4. Emacs Rime   convenience inputmethod

RIME ㄓ in Emacs

https://github.com/DogLooksGood/emacs-rime

(setup rime
  (:doc "RIME ㄓ in Emacs")
  (:url "https://github.com/DogLooksGood/emacs-rime")
  (:tag "convenience" "input-method")
  (:custom default-input-method "rime")
  (:first-key (lambda () (require 'rime))))

(setup rime
  (:global
   "C-M-¥" toggle-input-method
   "C-$"   toggle-input-method)
  (:bindm rime-mode-map
   "C-`"   rime-send-keybinding
   "C-S-`" rime-send-keybinding
   "C-,"   rime-send-keybinding)
  (:bindm rime-active-mode-map
   "C-;"   rime-send-keybinding
   "C-SPC" rime-send-keybinding)
  (:custom
   rime-librime-root  (expand-file-name "~/.macports")
   rime-user-data-dir (expand-file-name "~/.config/rime")
   rime-cursor         "˰"
   rime-show-candidate 'posframe
   rime-posframe-style 'vertical
   rime-show-preedit   't
   ;; rime-show-candidate           'sidewindow
   ;; rime-sidewindow-keep-window   t
   ;; rime-sidewindow-style         'horizontal
   ;; rime-sidewindow-side          'top
   rime-translate-keybindings
   '("C-f"
     "C-b"
     "C-n"
     "C-p"
     "C-g"
     "C-`"
     "C-;"
     "C-SPC"
     "<left>"
     "<right>"
     "<up>"
     "<down>"
     "<prior>"
     "<next>"
     "<delete>")))
6.9.1.5. ESUP – Emacs Start Up Profiler   benchmark convenience processes

Benchmark Emacs Startup time without ever leaving your Emacs.

https://github.com/jschaf/esup

(setup esup
  (:doc "Benchmark Emacs Startup time without ever leaving your Emacs.")
  (:url "https://github.com/jschaf/esup")
  (:tag "benchmark" "convenience" "processes")
  (:opt esup-depth 1))
6.9.1.6. explain-pause-mode   performance config speed

top, but for Emacs.

https://github.com/lastquestion/explain-pause-mode

(setup explain-pause-mode
  (:doc "top, but for Emacs.")
  (:url "https://github.com/lastquestion/explain-pause-mode")
  (:tag "performance" "speed" "config"))
6.9.1.7. GPTEL

Openai GPT.

https://github.com/karthink/gptel

(setup gptel
  (:doc "A no-frills ChatGPT client for Emacs.")
  (:url "https://github.com/karthink/gptel")
  (:tag "convenience")
  (:opt gptel-default-mode 'org-mode
        gptel-prompt-string "[Nasy]: "))
6.9.1.9. Htmlize   hypermedia extensions

Convert buffer text and decorations to HTML.

https://github.com/hniksic/emacs-htmlize

(setup htmlize
  (:doc "Convert buffer text and decorations to HTML.")
  (:url "https://github.com/hniksic/emacs-htmlize")
  (:tag "hypermedia" "extensions")
  (:custom htmlize-pre-style t))
6.9.1.10. indent-tools   indentation navigation

Emacs mode to indent, navigate around and act on indentation units: perfect for yaml, python and the like.

https://gitlab.com/emacs-stuff/indent-tools

(setup indent-tools
  (:doc "Emacs mode to indent, navigate around and act on indentation units: perfect for yaml, python and the like.")
  (:url "https://gitlab.com/emacs-stuff/indent-tools")
  (:tag "indentation" "navigation")
  (:global "C-c TAB" indent-tools-hydra/body))
6.9.1.11. List Unicode Display   convenience

Provides a command which searches for unicode characters by name, and displays a list of matching characters with their names in a buffer.

https://github.com/purcell/list-unicode-display

(setup list-unicode-display
  (:doc "Search for and list unicode characters in Emacs.

`list-unicode-display'")
  (:url "https://github.com/purcell/list-unicode-display")
  (:tag "convenience"))
6.9.1.12. Magit   git tools vc

Magit is an interface to the version control system Git, implemented as an Emacs package. Magit aspires to be a complete Git porcelain. While we cannot (yet) claim that Magit wraps and improves upon each and every Git command, it is complete enough to allow even experienced Git users to perform almost all of their daily version control tasks directly from within Emacs. While many fine Git clients exist, only Magit and Git itself deserve to be called porcelains.

https://github.com/magit/magit

(defvar nasy-magit-first-key-hook nil)
(defvar nasy--magit-first-key-hook nil)


(defun nasy/load-magit ()
  (setq nasy--magit-first-key-hook nasy-magit-first-key-hook)
  (nasy/run-hook-once-on 'nasy--magit-first-key-hook 'pre-command-hook))

(setup magit
  (:doc "It's Magit! A Git porcelain inside Emacs.")
  (:url "https://github.com/magit/magit")
  (:tag "git" "tools" "vc")
  (:autoload magit-status)
  (:with-hook magit-popup-mode-hook
    (:hook no-trailing-whitespace))
  (:mode-hook (nasy/load-magit))
  (:global
   [(meta f12)] magit-status  ;; Hint: customize `magit-repository-directories' so that you can use C-u M-F12 to
   "C-x g"      magit-status
   "C-x M-g"    magit-dispatch
   "C-c M-g"    magit-file-dispatch)
  (:bindm magit-mode-map
    "s" magit-stage)
  (:bindm magit-status-mode-map
    "C-M-<up>" magit-section-up)
  (:bindm vc-prefix-map
    "f" vc-git-grep))
6.9.1.12.1. Forge   git tools vc

Work with Git forges from the comfort of Magit.

https://github.com/magit/forge

(setup forge
  (:doc "Work with Git forges from the comfort of Magit.")
  (:url "https://github.com/magit/forge")
  (:tag "git" "tools" "vc")
  (:load-first magit)
  (:custom
   forge-database-file  (concat *nasy-var* "forge/database.sqlite")
   forge-post-directory (concat *nasy-var* "forge/posts/")))
6.9.1.12.2. Magit Delta   git tools vc

https://github.com/dandavison/magit-delta

(setup magit-delta
  (:doc "Use delta (dandavison/delta) when viewing diffs in Magit.")
  (:url "https://github.com/dandavison/magit-delta")
  (:tag "git" "tools" "vc")
  (:only-if (executable-find "delta"))
  (:load-first magit)
  (:custom
   magit-delta-default-light-theme "Solarized (light)"
   magit-delta-delta-args '("--max-line-distance"
                            "0.6" "--24-bit-color"
                            "always" "--color-only"))
  (:hook-into magit-mode-hook))
6.9.1.12.3. Magit Org Todos   magit orgmode tools

Get `todo.org` into your magit status.

https://github.com/danielma/magit-org-todos.el

(setup magit-org-todos
  (:doc "Get `todo.org` into your magit status")
  (:url "https://github.com/danielma/magit-org-todos.el")
  (:tag "magit" "orgmode" "tools")
  (:load-first magit)
  (:when-loaded (magit-org-todos-autoinsert)))
6.9.1.12.4. Magit Todos   magit vc

Show source files' TODOs (and FIXMEs, etc) in Magit status buffer.

https://github.com/alphapapa/magit-todos

(setup magit-todos
  (:doc "Show source files' TODOs (and FIXMEs, etc) in Magit status buffer.")
  (:url "https://github.com/alphapapa/magit-todos")
  (:tag "magit" "vc")
  (:load-first magit)
  (:custom magit-todos-exclude-globs '("*.map")))
6.9.1.13. Mind Wave   ai openai

The mind-wave is an Emacs AI plugin developed using ChatGPT API, which can be deeply integrated into Emacs to improve its efficiency in various aspects.

https://github.com/manateelazycat/mind-wave.git

;; (setup mind-wave
;;   (:doc "Emacs AI plugin based on ChatGPT API")
;;   (:url "https://github.com/manateelazycat/mind-wave.git")
;;   (:tag "ai")
;;   (:opt mind-wave-python-command "python"
;;         mind-wave-api-key-path (concat *nasy-var* "openai.key")))
6.9.1.14. OpenAI   ai comm openai

The OpenAI Elisp library provides convenient access to the OpenAI API from applications written in the Elips language.

https://github.com/emacs-openai/openai.git

(setup openai
  (:doc "Elisp library for the OpenAI API.")
  (:url "https://github.com/emacs-openai/openai.git")
  (:tag "comm" "ai" "openai")
  (:opt openai-key (nasy/api-key-from-auth-source)
        openai-chat-max-tokens 8000
        nasy-ai-model "gpt-4"))


(defun nasy/api-key-from-auth-source (&optional host user)
  "Lookup api key in the auth source.
 By default, \"openai.com\" is used as HOST and \"apikey\" as USER."
 (if-let* ((secret (plist-get (car (auth-source-search
                                    :host (or host "openai.com")
                                    :user (or user "apikey")))
                              :secret)))
     (if (functionp secret) (funcall secret) secret)
   (user-error "No `gptel-api-key' found in the auth source")))
6.9.1.15. PDF Tools   files multimedia

PDF Tools is, among other things, a replacement of DocView for PDF files.

https://github.com/politza/pdf-tools

(setup pdf-tools
  (:doc "Emacs support library for PDF files.")
  (:url "https://github.com/politza/pdf-tools")
  (:tag "files" "multimedia")
  (:custom pdf-view-display-size 'fit-page)
  (:bindm pdf-view-mode-map
    "<wheel-up>"    pdf-view-previous-line-or-previous-page
    "<wheel-down>"  pdf-view-next-line-or-next-page
    "<wheel-left>"  image-backward-hscroll
    "<wheel-right>" image-forward-hscroll)
  (:first-key*
   (pdf-tools-install t t t)))
6.9.1.16. Prettier   convenience files languages

The prettier Emacs package reformats your code by running Prettier with minimal overhead, by request or transparently on file save.

https://github.com/jscheid/prettier.el

(setup prettier
  (:doc "Prettier code formatting for Emacs.")
  (:url "https://github.com/jscheid/prettier.el")
  (:tag "convenience" "files" "languages"))
6.9.1.17. Request

Request.el – Easy HTTP request for Emacs Lisp

https://github.com/tkf/emacs-request.git

(setup request
  (:doc "Request.el -- Easy HTTP request for Emacs Lisp")
  (:url "https://github.com/tkf/emacs-request.git")
  (:tag "http" "tool")
  (:opt request-storage-directory (concat *nasy-var* "request/storage")))
6.9.1.18. vterm   terminals

Emacs libvterm integration.

https://github.com/akermu/emacs-libvterm

(eval-and-compile
  (with-no-warnings
    (setq vterm-always-compile-module t)))
(setup vterm
  (:doc "Emacs libvterm integration.")
  (:url "https://github.com/akermu/emacs-libvterm")
  (:tag "terminals")
  (:custom vterm-always-compile-module t))
6.9.1.19. vterm-toggle   terminals

Toggles between the vterm buffer and whatever buffer you are editing.

https://github.com/jixiuf/vterm-toggle

(setup vterm-toggle
  (:doc "Toggles between the vterm buffer and whatever buffer you are editing.")
  (:url "https://github.com/jixiuf/vterm-toggle")
  (:tag "terminals")
  (:global
   "C-<f2>" vterm-toggle)
  (:bindm vterm-mode-map
   "s-n" vterm-toggle-forward
   "s-p" vterm-toggle-backward)
  (:custom vterm-toggle-fullscreen-p nil)
  (:when-loaded
    (add-to-list
     'display-buffer-alist
     '((lambda(bufname _) (with-current-buffer bufname (equal major-mode 'vterm-mode)))
       (display-buffer-reuse-window display-buffer-in-side-window)
       (side . bottom)
       (dedicated . t) ;dedicated is supported in emacs27
       (reusable-frames . visible)
       (window-height . 0.3)))))
6.9.1.20. Wakatime-mode   calendar comm

wakatime-mode is an automatic time tracking extension for Emacs using WakaTime.

https://github.com/wakatime/wakatime-mode

(setup wakatime-mode
  (:doc "Emacs plugin for automatic time tracking and metrics generated from your programming activity.")
  (:url "https://github.com/wakatime/wakatime-mode")
  (:tag "calendar" "comm")
  (:first-key global-wakatime-mode))

6.10. 麐之趾

(add-to-list 'load-path (locate-user-emacs-file  "桃夭/麐之趾"))
(require '麐之趾)
(setup 麐之趾
  (:first-key*
   (require ')
   (:after python
     (nasy/tempo-python))
   (:after haskell
     (nasy/tempo-haskell))))

國風・周南・麐之趾

麐之趾、振振公子
于嗟麐兮

麐之定、振振公姓
于嗟麐兮

麐之角、振振公族
于嗟麐兮

程序之言也

Programming Languages

6.10.1.

6.10.1.1. Apheleia
(setup apheleia
  (:doc "Run code formatter on buffer contents without moving point, using RCS patches and dynamic programming.")
  (:url "https://github.com/radian-software/apheleia")
  (:tag "languages" "tools")
  (:first-key*
    (require 'apheleia)))
6.10.1.2. Bibtex
6.10.1.2.1. bibtex-tidy
(setup bibtex-tidy
  (:with-function bibtex-tidy-on-save-mode
    (:hook-into bibtex-mode)))
6.10.1.3. Language Server Protocol & Debug Adapter Protocol   languages

Emacs client/library for the Language Server Protocol

6.10.1.3.1. lsp-mode   languages
(setup lsp-mode
  (:doc "Language Server Protocol Support for Emacs.")
  (:url "https://github.com/emacs-lsp/lsp-mode")
  (:tag "languages"))


(defun nasy/lsp-setup-completion ()
  "Nasy lsp mode completion."
  (setf (alist-get 'styles (alist-get 'lsp-capf completion-category-defaults))
        '(orderless))
  (nasy/-merge-capf))


(defun lsp-booster--advice-json-parse (old-fn &rest args)
  "Try to parse bytecode instead of json."
  (or
   (when (equal (following-char) ?#)
     (let ((bytecode (read (current-buffer))))
       (when (byte-code-function-p bytecode)
         (funcall bytecode))))
   (apply old-fn args)))

(defun lsp-booster--advice-final-command (old-fn cmd &optional test?)
  "Prepend emacs-lsp-booster command to lsp CMD."
  (let ((orig-result (funcall old-fn cmd test?)))
    (if (and (not test?)                             ;; for check lsp-server-present?
             (not (file-remote-p default-directory)) ;; see lsp-resolve-final-command, it would add extra shell wrapper
             lsp-use-plists
             (not (functionp 'json-rpc-connection))  ;; native json-rpc
             (executable-find "emacs-lsp-booster"))
        (progn
          (message "Using emacs-lsp-booster for %s!" orig-result)
          (cons "emacs-lsp-booster" orig-result))
      orig-result)))


(setup lsp-mode
  (:when-loaded
    (advice-add (if (progn (require 'json)
                           (fboundp 'json-parse-buffer))
                    'json-parse-buffer
                  'json-read)
                :around
                #'lsp-booster--advice-json-parse)
    (advice-add 'lsp-resolve-final-command :around #'lsp-booster--advice-final-command)))


(setup lsp-mode
  (:opt
   lsp-eslint-library-choices-file (concat *nasy-var* "lsp/eslint-library-choices.el")
   lsp-python-ms-dir               (concat *nasy-var* "lsp/lsp-python-ms/")
   lsp-server-install-dir          (concat *nasy-var* "lsp/server/")
   lsp-session-file                (concat *nasy-var* "lsp/session.el")
   lsp-log-io *debug*
   lsp-headerline-breadcrumb-icons-enable nil)
  (:hooks
   kill-emacs-hook (lambda () (setq lsp-restart 'ignore))
   lsp-completion-mode-hook nasy/lsp-setup-completion)
  (:mode-hook
   (lsp-enable-which-key-integration t))
  (:opts
   ((
     ;; lsp-auto-configure
     ;; lsp-before-save-edits
     ;; lsp-completion-enable
     ;; lsp-eldoc-enable-hover
     lsp-eldoc-render-all
     ;; lsp-enable-folding
     ;; lsp-enable-imenu
     ;; lsp-enable-indentation
     ;; lsp-enable-links
     ;; lsp-enable-on-type-formatting
     ;; lsp-enable-snippet
     ;; lsp-enable-symbol-highlighting
     ;; lsp-enable-text-document-color
     ;; lsp-enable-xref
     ;; lsp-headerline-breadcrumb-enable
     ;; lsp-imenu-show-container-name
     ;; lsp-signature-render-documentation
     lsp-semantic-tokens-enable)
    . t)
   ((
     lsp-keep-workspace-alive
     ;; lsp-auto-guess-root
     lsp-document-sync-method
     lsp-auto-execute-action
     lsp-enable-file-watchers
     ;; lsp-server-trace
     lsp-modeline-diagnostics-enable)
    . nil))
  (:opt*
   lsp-restart 'interactive

   lsp-completion-provider  :none
   lsp-diagnostics-provider :auto
   lsp-response-timeout 10))
6.10.1.3.2. lsp-ui   languages tools
(defun nasy/toggle-lsp-ui-imenu ()
  "Nasy toggle lsp ui imenu."
  (interactive)
  (if (get-buffer "*lsp-ui-imenu*")
      (kill-buffer "*lsp-ui-imenu*")
    (lsp-ui-imenu)))

(setup lsp-ui
  (:doc "UI integrations for lsp-mode.")
  (:url "https://github.com/emacs-lsp/lsp-ui")
  (:tag "languages" "tools")
  (:global
   [remap imenu] nasy/toggle-lsp-ui-imenu)
  (:opt
   lsp-ui-doc-enable nil)
  (:opts
   ((lsp-ui-doc-include-signature
     lsp-ui-sideline-show-hover
     lsp-ui-sideline-show-symbol
     lsp-ui-sideline-show-diagnostics
     lsp-ui-sideline-show-code-actions
     lsp-ui-sideline-ignore-duplicate)
    . t))
  (:opt
   lsp-ui-doc-position         'at-point
   lsp-ui-sideline-update-mode 'point)
  (:hook-into lsp-mode-hook)
  (:mode-hook
   (lsp-ui-sideline-mode 1))
  ;; (flycheck-inline-mode -1)
  (:when-loaded
    (require 'lsp-ui-peek)))
6.10.1.3.3. lsp-treemacs   languages
(setup lsp-treemacs
  (:doc "lsp-mode ❤ treemacs.")
  (:url "https://github.com/emacs-lsp/lsp-treemacs")
  (:tag "languages")
  (:with-hook lsp-mode-hook
    (:hook (lambda () (require 'lsp-treemacs))))
  (:opt
   lsp-metals-treeview-show-when-views-received t
   lsp-treemacs-theme "doom-colors")
  (:when-loaded
    (lsp-treemacs-sync-mode t)))
6.10.1.4. dap-mode   languages
(setup dap-mode
  (:custom dap-breakpoints-file (concat *nasy-var* "dap/breakpoints.el")))
6.10.1.5. Flex
(setup flex-mode
  (add-to-list 'auto-mode-alist
               '("\\.l\\'" . flex-mode)))
6.10.1.6. Haskell   haskell languages
6.10.1.6.1. haskell-mode   haskell
(define-minor-mode stack-exec-path-mode
  "If this is a stack project, set `exec-path' to the path \"stack exec\" would use."
  :init-value nil
  :lighter ""
  :global nil
  (if stack-exec-path-mode
      (when (and (executable-find "stack")
                 (locate-dominating-file default-directory "stack.yaml"))
        (setq-local
         exec-path
         (seq-uniq
          (append (list (concat (string-trim-right
                                 (shell-command-to-string "stack path --local-install-root")
                                 "/bin")))
                  (parse-colon-path
                   (replace-regexp-in-string "[\r\n]+\\'" ""
                                             (shell-command-to-string "stack path --bin-path"))))
          'string-equal)))
    (kill-local-variable 'exec-path)))


(defun haskell-mode-generate-tags (&optional and-then-find-this-tag)
  "Generate tags using Hasktags.  This is synchronous function.

  If optional AND-THEN-FIND-THIS-TAG argument is present it is used
  with function `xref-find-definitions' after new table was
  generated."
  (interactive)
  (let* ((dir (haskell-cabal--find-tags-dir))
         (command (haskell-cabal--compose-hasktags-command dir)))
    (if (not command)
        (error "Unable to compose hasktags command")
      ;; I disabled the noisy shell command output.
      ;; The original is (shell-command command)
      (call-process-shell-command command nil "*Shell Command Output*" t)
      (haskell-mode-message-line "Tags generated.")
      (when and-then-find-this-tag
        (let ((tags-file-name dir))
          (xref-find-definitions and-then-find-this-tag))))))

(setup haskell-mode
  (:opts
   ((haskell-tags-on-save
     haskell-process-auto-import-loaded-modules
     haskell-process-log
     haskell-process-suggest-haskell-docs-imports
     haskell-process-suggest-hoogle-imports
     haskell-process-suggest-remove-import-lines
     haskell-svg-render-images
     haskell-doc-show-global-types)
    . t))
  (:opt
   haskell-mode-stylish-haskell-path "stylish-haskell"
   haskell-indentation-layout-offset 4
   haskell-indentation-left-offset   2
   haskell-doc-chop-off-context      nil))


(setup haskell-mode
  (:bindm haskell-mode-map
   "C-x a a" align
   "C-c h"   hoogle
   "C-o"     open-line)
  (:mode-hook
   (subword-mode 1)
   (haskell-auto-insert-module-template)
   (haskell-collapse-mode)
   (interactive-haskell-mode)
   (setq tab-width 4)
   (nasy/tempo-haskell)
   ;; (stack-exec-path-mode 1)
   (progn
     (require 'align)
     (add-to-list 'align-rules-list
                  '(haskell-types
                    (regexp . "\\(\\s-+\\)\\(::\\|\\)\\s-+")
                    (modes quote (haskell-mode literate-haskell-mode))))
     (add-to-list 'align-rules-list
                  '(haskell-assignment
                    (regexp . "\\(\\s-+\\)=\\s-+")
                    (modes quote (haskell-mode literate-haskell-mode))))
     (add-to-list 'align-rules-list
                  '(haskell-arrows
                    (regexp . "\\(\\s-+\\)\\(->\\|\\)\\s-+")
                    (modes quote (haskell-mode literate-haskell-mode))))
     (add-to-list 'align-rules-list
                  '(haskell-left-arrows
                    (regexp . "\\(\\s-+\\)\\(<-\\|\\)\\s-+")
                    (modes quote (haskell-mode literate-haskell-mode))))))
  (:after page-break-lines
    (add-to-list 'page-break-lines-modes 'haskell-mode)))
6.10.1.6.2. lsp-haskell   haskell
(defun start-lsp-haskell ()
  (require 'lsp)
  (require 'lsp-haskell)
  (lsp))

(setup lsp-haskell
  (:custom lsp-haskell-formatting-provider "brittany")
  (:with-hook haskell-mode-hook
    (:hook start-lsp-haskell))
  (:after company
    (nasy/add-company-backend 'haskell-mode
      '(company-capf
        company-files
        :with company-yasnippet))))
6.10.1.7. HTML   html languages
(setup lsp-html
  (:with-function lsp
    (:hook-into html-mode-hook mhtml-mode-hook sgml-mode-hook web-mode-hook)))
6.10.1.8. JavaScript & TypeScript   javascript typescript languages
(setup lsp-javascript
  (:with-function lsp
    (:hook-into javascript-mode-hook js-mode-hook)))
6.10.1.9. Lisp   lisp languages
6.10.1.9.1. elisp-def   lisp
(setup elisp-def
  (:with-function elisp-def-mode
    (:hook-into emacs-lisp-mode-hook ielm-mode-hook)))
6.10.1.9.2. Highlight-quoted   lisp
(setup highlight-quoted
  (:hook-into emacs-lisp-mode-hook))
6.10.1.9.3. ipretty   lisp

Interactive Emacs Lisp pretty-printing.

ipretty.el provides interactive functions to pretty-print the result of an expression and a global mode ipretty-mode that advices eval-print-last-sexp to pretty print.

https://framagit.org/steckerhalter/ipretty

;; (leaf ipretty
;;   :doc "Interactive Emacs Lisp pretty-printing"
;;   :url "https://framagit.org/steckerhalter/ipretty"
;;   :tag "buffer" "emacslisp" "pprint"
;;   :disabled t
;;   :bind (("C-h C-j" . ipretty-last-sexp)
;;          ("C-h C-k" . ipretty-last-sexp-other-buffer))
;;   :hook emacs-lisp-mode-hook)
6.10.1.9.4. lisp-mode   lisp
(defun eval-last-sexp-or-region (prefix)
  "Eval region from BEG to END if active, otherwise the last sexp."
  (interactive "P")
  (if (and (mark) (use-region-p))
      (eval-region (min (point) (mark)) (max (point) (mark)))
    (pp-eval-last-sexp prefix)))

(setup lisp-mode
  (:bindm emacs-lisp-mode-map
   [remap eval-expression] pp-eval-expression
   "C-x C-e"               eval-last-sexp-or-region))
6.10.1.9.5. macrostep   lisp
(setup macrostep
  (:bindm emacs-lisp-mode-map
    "C-c e m" macrostep-expand))
6.10.1.9.6. parinfer-rust-mode   lisp
(setup parinfer-rust-mode
  (:custom
   parinfer-rust-auto-download nil
   parinfer-rust-library (concat *nasy-var* "parinfer-rust/parinfer-rust-darwin.so"))
  (:init
   (lisp-modes-hooks-add (lambda () (indent-tabs-mode -1)))
   (lisp-modes-hooks-add parinfer-rust-mode))
  (:when-loaded
    ;; https://github.com/justinbarclay/parinfer-rust-mode/issues/53
    (add-to-list 'parinfer-rust-treat-command-as
                 '(quoted-insert . "paren"))))
6.10.1.10. TeX   tex

TeX related works.

6.10.1.10.1. TeX
(setup tex
  (:with-function visual-line-mode
    (:hook-into
     tex-mode-hook
     TeX-mode-hook
     latex-mode-hook
     LaTeX-mode-hook)))
6.10.1.10.2. auctex
(setup auctex
  (:init
   (setq TeX-data-directory (straight--repos-dir "auctex")
         TeX-lisp-directory TeX-data-directory)

   ;; Or set the following variable via custom-set-variables in the opened buffer by the following command.
   ;; M-x describe-variable RET preview-TeX-style-dir RET
   ;;`(preview-TeX-style-dir ,(concat ".:" (straight--repos-dir "auctex") "latex:"))
   (setq preview-TeX-style-dir (concat ".:" (straight--repos-dir "auctex") "latex:"))

   (setq TeX-auto-save t)
   (setq TeX-parse-self t)
   (setq-default TeX-master nil)))
6.10.1.10.3. cdlatex
(setup cdlatex
  (:custom cdlatex-use-dollar-to-ensure-math nil))
6.10.1.11. Markdown   markdown languages
(setup markdown-mode
  (:init
   (progn
    (add-to-list 'auto-mode-alist
                 '("INSTALL\\'" . markdown-mode))
    (add-to-list 'auto-mode-alist
                 '("CONTRIBUTORS\\'" . markdown-mode))
    (add-to-list 'auto-mode-alist
                 '("LICENSE\\'" . markdown-mode))
    (add-to-list 'auto-mode-alist
                 '("\\.markdown\\'" . markdown-mode))
    (add-to-list 'auto-mode-alist
                 '("\\.md\\'" . markdown-mode))
    (add-to-list 'nasy--defer-loads 'markdown-mode))))

6.10.1.12. Nix   nix languages
(defun start-nix-lsp ()
  (after-x 'lsp-mode
    (add-to-list 'lsp-language-id-configuration '(nix-mode . "nix"))
    (lsp-register-client
     (make-lsp-client :new-connection (lsp-stdio-connection '("rnix-lsp"))
                      :major-modes '(nix-mode)
                      :server-id 'nix))
    (lsp)))

(setup nix-mode
  (:with-hook nix-mode-hook
    (:hook start-nix-lsp)))
6.10.1.13. Org Mode   org languages
(add-hook 'nasy-first-key-hook #'(lambda () (require 'org)))
(add-to-list 'auto-mode-alist
             '("README\\'" . org-mode))
6.10.1.13.1. 自定義   org
6.10.1.13.1.1. org
(defvar nasy-org-first-key-hook nil)
(defvar nasy--org-first-key-hook nil)

(setup org
  (:opt
   org-export-backends      '(ascii beamer html latex md org)
   org-support-shift-select 'always
   org-safe-remote-resources '("\\`https://raw\\.githubusercontent\\.com\\(?:/\\|\\'\\)")
   org-modules nil)
  (:init
   (with-no-warnings
     (setq org-emphasis-regexp-components
           '(" \t('\"{[:nonascii:]"
             "- \t.,:!?)));'\")}\\[[:nonascii:]"
             " \t\r\n,\"'"
             "."
             1))))
  (:when-loaded
    (add-to-list 'safe-local-variable-values
               '(org-src-fontify-natively))
    (add-to-list 'safe-local-variable-values
               '(org-startup-indented))))
(setup org
  (:opt
   org-ellipsis          " 略"
   org-startup-folded    'content
   org-startup-truncated nil))
6.10.1.13.1.2. org agenda
(setup org-agenda
  (:opt
   org-agenda-compact-blocks   t
   org-agenda-files            (list (concat *nasy-etc* "standard-agenda.org"))
   org-agenda-start-on-weekday nil
   org-agenda-prefix-format '((agenda . " %i %+15c\t%?-15t% s")
                              (todo   . " %i %+15c\t")
                              (tags   . " %i %+15c\t")
                              (search . " %i %+15c\t"))
   org-agenda-sorting-strategy
   '((agenda habit-down time-up user-defined-up effort-up category-keep)
     (todo category-up effort-up)
     (tags category-up effort-up)
     (search category-up))

   org-agenda-time-grid
   '((daily today weekly require-timed remove-match)
     (0 600 900 1200 1300 1600 1800 2000 2200 2400 2600)
     "......"
     "-----------------------------------------------------")

   org-agenda-clockreport-parameter-plist '(:link t :maxlevel 3)
   org-agenda-window-setup 'current-window))
6.10.1.13.1.3. org appear
(setup org-appear
  (:opts
   ((org-appear-autoemphasis
     org-appear-autoentities
     org-appear-autolinks
     org-appear-autosubmarkers)
    . t)))
6.10.1.13.1.4. org appearance
(setup org
  (:opts
   ((org-allow-promoting-top-level-subtree
     org-fontify-todo-headline
     ;; org-fontify-whole-heading-line
     org-hide-emphasis-markers
     org-hide-leading-stars)
    . t)
   ((org-image-actual-width
     org-pretty-entities)
    . nil)))
6.10.1.13.1.5. org babel
(setup ob-latex
  (:after org
    (:custom
     org-babel-latex-preamble
     (lambda (_) "\\documentclass[preview]{standalone}\n"))))

(setup ob-core
  (:opt org-confirm-babel-evaluate nil))

(setup org
  (:opt org-babel-load-languages '((emacs-lisp . t)
                                   (dot        . t)
                                   (python     . t)
                                   (gnuplot    . t))))
6.10.1.13.1.6. org capture
(setup org
  (:opt org-default-notes-file "~/notes/default.org"))
6.10.1.13.1.7. org export
(setup org
  (:opt
   ;; general
   org-export-coding-system         'utf-8
   org-export-with-broken-links     'mark
   org-export-with-sub-superscripts '{}
   org-use-sub-superscripts         '{}
   org-html-checkbox-type           'unicode)
  (:opt
   ;; html
   org-html-doctype              "html5"
   org-html-head-include-scripts t
   org-html-klipsify-src         t
   org-html-html5-fancy          t
   org-html-mathjax-options
   '((path          "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js")
     (scale         1.0)
     (align         "center")
     (font          "mathjax-euler")
     (overflow      "overflow")
     (linebreaks    "false")
     (tags          "ams")
     (indent        "0em")
     (multlinewidth "85%")
     (tagindent     ".8em")
     (tagside       "right"))
    org-html-with-latex     'mathjax
    org-html-wrap-src-lines t)
  (:opt
   ;; Latex
   org-latex-compiler "xelatex"
   org-latex-default-packages-alist
   '(("AUTO" "inputenc"  t   ("pdflatex"))
     ("T1"   "fontenc"   t   ("pdflatex"))
     (""     "graphicx"  t   nil)
     (""     "grffile"   nil nil)
     (""     "longtable" nil nil)
     (""     "booktabs"  nil nil)
     (""     "wrapfig"   nil nil)
     (""     "rotating"  nil nil)
     ("normalem" "ulem"  nil nil)
     (""     "amsmath"   t   nil)
     (""     "textcomp"  t   nil)
     (""     "amssymb"   t   nil)
     (""     "capt-of"   nil nil)
     (""     "nicefrac"  t   nil)
     ("dvipsnames" "xcolor" nil nil)
     ("colorlinks,unicode,linkcolor=􀝦violet,anchorcolor=􀝦BlueViolet,citecolor=YellowOrange,filecolor=􀝦black,urlcolor=􀝦Aquamarine"
      "hyperref" nil nil)
     (""            "luatexja-fontspec" t ("lualatex")))
    ;; (""            "listings"          t nil)))
    ;; (""            "algorithm"         t nil)
    ;; (""            "algpseudocode"     t nil)
    ;; ("cache=false" "minted"            t nil)))
    org-latex-default-table-environment "longtable"
    org-latex-listings                  'minted
    org-latex-pdf-process
    '("latexmk -f -pdf -%latex -interaction=nonstopmode -shell-escape -output-directory=%o %f")
    org-latex-tables-booktabs t)
  (:opts
   ;; Pandoc
   ((org-pandoc-options-for-context
     org-pandoc-options-for-context-pdf)
    . `((template . ,(concat *nasy-etc* "nasy-context.tex"))))))
(setup ox
  (:when-loaded
    (nasy/sup '(ox-rst ox-pandoc))
    (require 'ox-rst)
    (require 'ox-pandoc)))
6.10.1.13.1.8. org id
(setup org-id
  (:opt org-id-link-to-org-use-id t))
6.10.1.13.1.9. org indent
(setup org-indent
  (:opt org-indent-mode-turns-on-hiding-stars nil))

org keywords

(setup org
  (:opt
   org-todo-keywords
   '((sequence
      "TODO(t)"
      "WIP(w/!)"
      "WAIT(W@/!)"
      "HOLD(h)"
      "|"
      "CANCELLED(c@/!)"
      "DONE(d!/!)"))))

org latex

;; LaTeX
(setup org
  (:opt
   org-preview-latex-default-process 'xesvg
   org-highlight-latex-and-related   '(native latex script entities))
  (:when-loaded
    (defvar
      nasy-luamagick
      '(luamagick
        :programs ("lualatex" "convert")
        :description "pdf > png"
        :message "you need to install lualatex and imagemagick."
        :use-xcolor t
        :image-input-type "pdf"
        :image-output-type "png"
        :image-size-adjust (1.0 . 1.0)
        :latex-compiler ("lualatex -interaction nonstopmode -output-directory %o %f")
        :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O")))
    (add-to-list 'org-preview-latex-process-alist nasy-luamagick)

    (defvar
      nasy-luamsvg
      '(luamsvg
        :programs ("lualatex" "convert")
        :description "pdf > svg"
        :message "you need to install lualatex and imagemagick."
        :use-xcolor t
        :image-input-type "pdf"
        :image-output-type "svg"
        :image-size-adjust (1.0 . 1.0)
        :latex-compiler ("lualatex -interaction nonstopmode -output-directory %o %f")
        :image-converter ("convert -density %D -trim -antialias %f -quality 100 %O")))
    (add-to-list 'org-preview-latex-process-alist nasy-luamsvg)

    (defvar
      nasy-luasvg
      '(luasvg
        :programs ("lualatex" "dvisvgm")
        :description "dvi > svg"
        :message "you need to install lualatex and dvisvgm."
        :use-xcolor t
        :image-input-type "dvi"
        :image-output-type "svg"
        :image-size-adjust (1.0 . 1.0)
        :latex-compiler ("lualatex -interaction nonstopmode --output-format dvi -output-directory %o %f")
        :image-converter ("dvisvgm %f -n -b min -Z 2 -o %O")))
            ;; :image-converter ("inkscape --pdf-poppler %f -T -l -o %O")))
    (add-to-list 'org-preview-latex-process-alist nasy-luasvg)

    (defvar
     nasy-xesvg
     '(xesvg
       :programs ("xelatex" "dvisvgm")
       :description "xdv > svg"
       :message "you need to install xelatex and dvisvgm."
       :use-xcolor t
       :image-input-type "xdv"
       :image-output-type "svg"
       :image-size-adjust (1.7 . 1.5)
       :latex-compiler ("xelatex -interaction nonstopmode -no-pdf -output-directory %o %f")
       :image-converter ("dvisvgm %f -n -b min -Z 2 -c %S -o %O")))
      ;; :image-converter ("inkscape --pdf-poppler %f -T -l -o %O")))
    (add-to-list 'org-preview-latex-process-alist nasy-xesvg)))
6.10.1.13.1.10. org refile
(setup org-refile
  (:opts
   (org-outline-path-complete-in-steps . nil)
   (org-refile-allow-creating-parent-nodes . 'confirm)
   ((org-refile-use-outline-path
     org-refile-use-cache)
    . t)))
(setup org-roam
  (:opt org-roam-directory "~/orgmode"))
(setup org
  (:after org
    (:customs
     (org-startup-indented      . nil)
     (org-archive-location      . "%s_archive::* Archive")
     (org-catch-invisible-edits . 'smart))))
(setup org
  (:opts
   (org-fast-tag-selection-single-key . 'expert)
   (org-tags-column                   . -62)
   (org-tags-sort-function            . 'org-string-collate-lessp)))
(setup org
  (:after org
    (:customs
     ((org-display-custom-times
       org-edit-timestamp-down-means-later
       org-log-into-drawer
       org-clock-in-resume
       org-clock-out-remove-zero-time-clocks
       org-clock-persist)
      . t)
     (org-log-done . 'time)
     (org-time-stamp-custom-formats    . '("<%a, %b %d, %Y>" . "<%a, %b %d, %Y at %H:%M>"))
     (org-export-date-timestamp-format . "%b %d, %Y"))))
(setup org
  (:opt org-todo-repeat-to-state "NEXT"))
(setup oc
  (:after org
    (:custom org-cite-global-bibliography
             `(,(concat *nasy-var* "refs/ref.bib")))))

(setup oc-biblatex
  (:after oc
    (:when-loaded
       (add-to-list 'org-cite-biblatex-styles
                    '("foot" "full" "footfullcite" nil nil))
       (add-to-list 'org-cite-biblatex-styles
                    '("foot" nil "footcite" nil nil))
       (add-to-list 'org-cite-biblatex-styles
                    '(nil "full" "fullcite" nil nil))
       (add-to-list 'org-cite-biblatex-style-shortcuts
                    '("ft" . "foot")))))

(setup oc-csl
  (:after oc
    (:custom org-cite-csl-styles-dir "~/Zotero/styles")))
6.10.1.13.1.11. org src
(setup org-src
  (:when-loaded
    (push '("python" . python-ts) org-src-lang-modes)))
6.10.1.13.2. Basic & Functions   org
;; Exclude DONE state tasks from refile targets
;;;###autoload
(defun nasy/verify-refile-target ()
  "Exclude todo keywords with a done state from refile targets."
  (not (member (nth 2 (org-heading-components)) org-done-keywords)))

(setq org-refile-target-verify-function 'nasy/verify-refile-target)

  ;;;###autoload
(defun nasy/org-refile-anywhere (&optional goto default-buffer rfloc msg)
  "A version of `org-refile' which allows refiling to any subtree."
  (interactive "P")
  (let ((org-refile-target-verify-function))
    (org-refile goto default-buffer rfloc msg)))

  ;;;###autoload
(defun nasy/org-agenda-refile-anywhere (&optional goto rfloc no-update)
  "A version of `org-agenda-refile' which allows refiling to any subtree."
  (interactive "P")
  (let ((org-refile-target-verify-function))
    (org-agenda-refile goto rfloc no-update)))

  ;;;###autoload
(defun nasy/org-html-paragraph-advice (orig paragraph contents &rest args)
  "Join consecutive Chinese lines into a single long line without
  unwanted space when exporting org-mode to html."
  (let* ((fix-regexp "[[:multibyte:]]")
         (fixed-contents
          (replace-regexp-in-string
           (concat
            "\\(" fix-regexp "\\) *\n *\\(" fix-regexp "\\)") "\\1\\2" contents)))
    (apply orig paragraph fixed-contents args)))

  ;;;###autoload
(defun nasy/org-fix-saveplace ()
  "Fix a problem with saveplace.el putting you back in a folded position"
  (when (outline-invisible-p)
    (save-excursion
      (outline-previous-visible-heading 1)
      (org-fold-show-subtree))))

  ;;;###autoload
(defun nasy/org-agenda-log-mode-colorize-block ()
  "Set different line spacing based on clock time duration."
  (save-excursion
    (let* ((colors (cl-case (alist-get 'background-mode (frame-parameters))
                     (light
                      (list "􀝦#a7e9af" "􀝦#75b79e" "􀝦#6a8caf" "􀝦#eef9bf"))
                     (dark
                      (list "􀝦#a7e9af" "􀝦#75b79e" "􀝦#6a8caf" "􀝦#eef9bf"))))
           pos
           duration)
      (nconc colors colors)
      (goto-char (point-min))
      (while (setq pos (next-single-property-change (point) 'duration))
        (goto-char pos)
        (when (and (not (equal pos (pos-eol)))
                  (setq duration (org-get-at-bol 'duration)))
          ;; larger duration bar height
          (let ((line-height (if (< duration 15) 1.0 (+ 0.5 (/ duration 30))))
                (ov (make-overlay (pos-bol) (1+ (pos-eol)))))
            (overlay-put ov 'face `(:background ,(car colors) :foreground "􀝦black"))
            (setq colors (cdr colors))
            (overlay-put ov 'line-height line-height)
            (overlay-put ov 'line-spacing (1- line-height))))))))

  ;;;###autoload
(defun nasy/show-org-clock-in-header-line ()
  "Show the clocked-in task in header line"
  (setq-default header-line-format '((" " org-mode-line-string ""))))

  ;;;###autoload
(defun nasy/hide-org-clock-from-header-line ()
  "Hide the clocked-in task from header line"
  (setq-default header-line-format nil))

(setup org
  (:bindm org-src-mode-map
    "C-c _" org-edit-src-exit)
  (:first-org*
   ;; (auto-fill-mode 1)
   (visual-line-mode)
   (eldoc-mode 1))
  (:after company
    (nasy/add-company-backend 'org-mode
      '(;; company-tabnine
        company-files
        :with company-yasnippet)))
  (:when-loaded
    (require 'org-tempo nil t)
    (progn
     (require 'org-eldoc)
     (org-eldoc-load)))
  (:advice
   org-refile :after
   (lambda (&rest _) (org-save-all-org-buffers))

   org-html-paragraph :around
   nasy/org-html-paragraph-advice))
6.10.1.13.3. Org AI   ai org
(setup org-ai
  (:doc "ChatGPT and DALL-E in org-mode using the OpenAI APIs.")
  (:url "https://github.com/rksm/org-ai")
  (:tag "org")
  (:autoload org-ai-explain-code org-ai-refactor-code org-ai-summarize)
  (:first-org org-ai-mode org-ai-install-yasnippets)
  (:first-key* (require 'org-ai))
  (:unbind "C-c r"))
6.10.1.13.4. Org Agenda   org
(setup org-agenda
  (:bindm org-mode-map
    "C-," nil)
  (:with-hook org-agenda-finalize-hook
    (:hook nasy/org-agenda-log-mode-colorize-block))
  (:after nerd-icons
    (setq
     org-agenda-category-icon-alist
     `(("Tasks"
        ,(list (nerd-icons-faicon "nf-fa-tasks"))
        nil nil :ascent center)
       ("Calendar"
        ,(list (nerd-icons-faicon "nf-fa-calendar"))
        nil nil :ascent center)
       ("Appointments"
        ,(list (nerd-icons-faicon "nf-fa-calendar_o"))
        nil nil :ascent center)))))

  ;; (:after all-the-icons
  ;;   (setq
  ;;    org-agenda-category-icon-alist
  ;;    `(("Tasks"
  ;;       ,(list (all-the-icons-faicon "tasks" :height 0.8 :v-adjust 0))
  ;;       nil nil :ascent center)
  ;;      ("Calendar"
  ;;       ,(list (all-the-icons-octicon "calendar" :height 0.8 :v-adjust 0))
  ;;       nil nil :ascent center)
  ;;      ("Appointments"
  ;;       ,(list (all-the-icons-faicon "calendar-check-o" :height 0.8 :v-adjust 0))
  ;;       nil nil :ascent center)))))
6.10.1.13.5. Org Appear   convenience org

Toggle visibility of hidden Org mode element parts upon entering and leaving an element

https://github.com/awth13/org-appear

(setup org-appear
  (:doc "Make invisible parts of Org elements appear visible.")
  (:url "https://github.com/awth13/org-appear")
  (:tag "convenience")
  (:hook-into nasy-org-first-key-hook))
6.10.1.13.6. Org Capture   org
(setup org-capture
  (:when-loaded
   (add-to-list 'org-capture-templates '("t" "Tasks"))

   (add-to-list 'org-capture-templates
                '("tr" "Book Reading Task" entry
                  (file+olp "~/notes/task.org" "Reading" "Book")
                  "* TODO %^{book name}\n%u\n%a\n" :clock-in t :clock-resume t))

   (add-to-list 'org-capture-templates
                '("tw" "Work Task" entry
                  (file+headline "~/notes/task.org" "Work")
                  "* TODO %^{task name}\n%u\n%a\n" :clock-in t :clock-resume t))

   (add-to-list 'org-capture-templates
                '("T" "Thoughts" entry
                  (file "~/notes/thoughts.org")
                  "* %t - %^{heading}\n\n%?"))

   (add-to-list 'org-capture-templates
                '("j" "Journal" entry
                  (file "~/notes/journal.org")
                  "* %U - %^{heading}\n  %?"))

   (add-to-list 'org-capture-templates
                '("i" "Inbox" entry
                  (file "~/notes/inbox.org")
                  "* %U - %^{heading} %^g\n %?\n"))

   (add-to-list 'org-capture-templates
                '("n" "Notes" entry
                  (file "~/notes/notes.org")
                  "* %^{heading} %t %^g\n  %?\n"))))
6.10.1.13.7. Org CDLatex   org tex

https://orgmode.org/manual/CDLaTeX-mode.html

(setup org-cdlatex
  (:hook-into nasy-org-first-key-hook))
6.10.1.13.8. Org Clock   org
(setup org-clock
  (:with-hook org-clock-in-hook
    (:hook nasy/show-org-clock-in-header-line))
  (:with-function nasy/hide-org-clock-from-header-line
    (:hook-into org-clock-out-hook org-clock-cancel))
  (:bindm org-clock-mode-line-map
   [header-line mouse-2] org-clock-goto
   [header-line mouse-1] org-clock-menu)
  (:when-loaded
    (when (and *is-a-mac* (file-directory-p "/Applications/org-clock-statusbar.app"))
      (add-hook 'org-clock-in-hook
                (lambda () (call-process "/usr/bin/osascript" nil 0 nil "-e"
                                    (concat "tell application \"org-clock-statusbar\" to clock in \""
                                            org-clock-current-task "\""))))
      (add-hook 'org-clock-out-hook
                (lambda () (call-process "/usr/bin/osascript" nil 0 nil "-e"
                                    "tell application \"org-clock-statusbar\" to clock out"))))))
6.10.1.13.9. Org Fragtag   org tex

Automatically toggle Org mode LaTeX fragment previews as the cursor enters and exits them.

https://github.com/io12/org-fragtog

(setup org-fragtog
  (:doc "Automatically toggle Org mode LaTeX fragment previews as the cursor enters and exits them.")
  (:url "https://github.com/io12/org-fragtog")
  (:tag "org" "tex")
  (:hook-into nasy-org-first-key-hook))
6.10.1.13.10. Org Latex Impatient   org tex tools

org-latex-impatient provides instant preview of LaTeX snippets via MathJax outputed SVG.

https://github.com/yangsheng6810/org-latex-impatient

(setup org-latex-impatient
  (:doc "Instant Previews LaTeX snippets in Org-mode.")
  (:url "https://github.com/yangsheng6810/org-latex-impatient")
  (:tag "org" "tex" "tool")
  (:custom
   org-latex-impatient-tex2svg-bin (executable-find "tex2svg")
   org-latex-impatient-user-latex-definitions
   '("\\newcommand{\\ensuremath}[1]{#1}"
     "\\renewcommand{\\usepackage}[2][]{}"
     "\\renewcommand{\\useoutertheme}[1]{}"
     "\\renewcommand{\\setbeamertemplate}[2]{}"
     "\\renewcommand{\\setbeamercolor}[2]{}"
     "\\renewcommand{\\setbeamerfont}[2]{}"
     "\\renewcommand{\\input}[1]{}"))
  (:hook-into nasy-org-first-key-hook))
6.10.1.13.11. Org Margin   org

Outdent headlines in emacs org-mode.

https://github.com/rougier/org-margin/tree/master

(setup org-margin
  (:doc "Outdent headlines in emacs org-mode")
  (:tag "org")
  (:url "https://github.com/rougier/org-margin"))
6.10.1.13.12. Org Modern   org

This package implements a “modern” style for your Org buffers using font locking and text properties. The package styles headlines, keywords, tables and source blocks. The styling is configurable, you can enable, disable or modify the style of each syntax element individually via the org-modern customization group.

"https://github.com/minad/org-modern"

(setup org-modern
  (:doc "Modern Org Style")
  (:url "https://github.com/minad/org-modern")
  (:tag "org")
  (:opts
   (org-modern--timestamp . '(" %a, %b %d, %Y " . " %H:%M "))
   (org-modern-star . ["􁝯" "􀥲" "􁖎" "􁝰" "􁂂" "􀥳" "􁖏" "􀬚"])
   ;; (org-modern-star . ["✿" "❀" "✭" "✫" "✦" "✧" "◈" "◇"])
   ;; (org-modern-star . ["⚀" "⚁" "⚂" "⚃" "⚄" "⚅"])
   ;; (org-modern-star . ["☰" "☱" "☲" "☳" "☴" "☵" "☶" "☷"])
   ;; (org-modern-hide-stars . 'leading)
   (org-modern-hide-stars . t)
   (org-modern-table . nil)
   ;; (org-modern-list . '((?+ . "⊕")
   ;;                      (?- . "⊖")
   ;;                      (?* . "⊛")))
   ;; (org-modern-list . '((?+ . "✨")
   ;;                      (?- . "💫")
   ;;                      (?* . "💥"))))
   (org-modern-list . '((?+ . "􀵵")
                        (?- . "􀷎")
                        (?* . "􁜷"))))
  (:hook-into nasy-org-first-key-hook))
6.10.1.13.13. Org Prettify Source Block   org
;; (leaf org-prettify-source-block
;;   :disabled t
;;   :load-path* "桃夭/麐之趾"
;;   :leaf-autoload t
;;   :leaf-defun t
;;   :hook nasy-org-first-key-hook)
;;; org-prettify-source-block.el --- Org Prettify Source Block -*- lexical-binding: t; -*-

;;; Commentary:

;;; Code:

(require 'org-macs)

(defgroup org-prettify-source-block nil
  "Prettify org-mode source block markers."
  :group 'org-mode
  :prefix "org-prettify-source-block"
  :version "0.1")

(defvar-local opsb-org-at-src-begin -1
  "Variable that holds whether last position was a ")

(defvar opsb-ob-header-symbol ?☰
  "Symbol used for babel headers")

(defvar opsb-block-alist `(("#+begin_src"     . ?λ) ;; ╦ ➤ 🖝 ➟ ➤ ✎ ✎
                           ("#+end_src"       . ?⌞) ;; ╩ □
                           ("#+header:"       . ,opsb-ob-header-symbol)
                           ("#+begin_comment" . ?✎)
                           ("#+end_comment"   . ?⌞)
                           ("#+begin_verse" . ?☾)
                           ("#+end_verse"   . ?⌞)
                           ("#+begin_notes"   . ?➤)
                           ("#+end_notes"     . ?⌞)
                           ("#+begin_quote"   . ?»)
                           ("#+end_quote"     . ?⌞)))

(defun opsb-org-prettify-src--update ()
  (let ((case-fold-search t)
        (re "^[ \t]*#\\+begin_src[ \t]+[^ \f\t\n\r\v]+[ \t]*")
        found)
    (save-excursion
      (goto-char (point-min))
      (while (re-search-forward re nil t)
        (goto-char (match-end 0))
        (let ((args (org-trim
                     (buffer-substring-no-properties (point)
                                                     (line-end-position)))))
          (when (org-string-nw-p args)
            (let ((new-cell (cons args opsb-ob-header-symbol)))
              (cl-pushnew new-cell prettify-symbols-alist :test #'equal)
              (cl-pushnew new-cell found :test #'equal)))))

      (setq prettify-symbols-alist
            (cl-set-difference prettify-symbols-alist
                               (cl-set-difference
                                (cl-remove-if-not
                                 (lambda (elm)
                                   (eq (cdr elm) opsb-ob-header-symbol))
                                 prettify-symbols-alist)
                                found :test #'equal)))

      ;; Clean up old font-lock-keywords.
      (font-lock-remove-keywords nil prettify-symbols--keywords)
      (setq prettify-symbols--keywords (prettify-symbols--make-keywords))
      (font-lock-add-keywords nil prettify-symbols--keywords)
      (while (re-search-forward re nil t)
        (font-lock-flush (line-beginning-position) (line-end-position))))))

(defun opsb-org-prettify-src ()
  "Hide src options via `prettify-symbols-mode'.
    `prettify-symbols-mode' is used because it has
    uncollapsing. It may not be efficient."
  (let* ((case-fold-search t)
         (at-src-block
          (save-excursion
            (beginning-of-line)
            (looking-at "^[ \t]*#\\+begin_src[ \t]+[^ \f\t\n\r\v]+[ \t]*"))))
    ;; Test if we moved out of a block.
    (when (or (and opsb-org-at-src-begin
                   (not at-src-block))
              ;; File was just opened.
              (eq opsb-org-at-src-begin -1))
      (opsb-org-prettify-src--update))
    (setq opsb-org-at-src-begin at-src-block)))

(defsubst opsb-append-upcase (the-list)
    "Duplicate THE-LIST with upcased cars."
  (cl-reduce 'append
             (mapcar (lambda (x) (list x (cons (upcase (car x)) (cdr x))))
                     the-list)))

(defun opsb-append-org-prettify-symbols ()
  (setq prettify-symbols-alist
          (cl-union prettify-symbols-alist
                    (opsb-append-upcase opsb-block-alist))))

(defun opsb-delete-org-prettify-symbols ()
  (setq prettify-symbols-alist
        (cl-set-difference prettify-symbols-alist
                           (opsb-append-upcase opsb-block-alist))))


;;;###autoload
(define-minor-mode org-prettify-source-block-mode
  "Toggle prettification of org source blocks."
  :lighter ""
  (if org-prettify-source-block-mode
      (progn
        (turn-on-prettify-symbols-mode)
        (add-hook 'post-command-hook 'opsb-org-prettify-src t t)
        (opsb-append-org-prettify-symbols))
    (remove-hook 'post-command-hook 'opsb-org-prettify-src t)
    (opsb-delete-org-prettify-symbols)))


(provide 'org-prettify-source-block)
;;; org-prettify-source-block.el ends here
6.10.1.13.14. org rainbow tags

This package adds random colors to your org tags. In order to make colors random but consistent between same tags, colors are generated from the hash of the tag names.

Since it’s random, results may not make you happy, but there are some custom fields that you can use as seed to generate different colors. If you are really picky, there is already a built-in solution for you, please see org-tag-faces. This package aims to get rid of setting and updating org-tag-faces manually for each tag you use.

https://github.com/KaratasFurkan/org-rainbow-tags

(setup org-rainbow-tags
  (:doc "Colorize org tags automatically to make them visually distinguishable.")
  (:url "https://github.com/KaratasFurkan/org-rainbow-tags")
  (:tag "org" "faces" "outlines")
  (:hook-into nasy-org-first-key-hook))
6.10.1.13.15. org roam   convenience roam org

Org-roam is a plain-text knowledge management system. It brings some of Roam's more powerful features into the org-mode ecosystem.

Rudimentary Roam replica with org-mode.

https://www.orgroam.com/

https://github.com/org-roam/org-roam

(setup org-roam
  (:doc "Rudimentary Roam replica with org-mode.")
  (:url "https://github.com/org-roam/org-roam")
  (:tag "convenience" "roam")
  (:bind
   "C-c n c" org-roam-capture
   "C-c n f" org-roam-node-find
   "C-c n g" org-roam-graph
   "C-c n i" org-roam-node-insert
   "C-c n l" org-roam-buffer-toggle
   ;; Dailies
   "C-c n j" org-roam-dailies-capture-today)
  (:custom
   org-roam-db-location (concat *nasy-var* "org/org-roam.db"))
  ;; :hook (nasy-first-key-hook . org-roam-setup)
  (:when-loaded
    (setq org-roam-node-display-template
          (concat "${title:*} " (propertize "${tags:10}" 'face 'org-tag)))
    (org-roam-db-autosync-mode)
    (add-to-list 'safe-local-variable-values
                 '(org-roam-directory))
    (add-to-list 'safe-local-variable-values
                 '(eval setq-local org-roam-directory
                        (locate-dominating-file default-directory ".dir-locals.el")))))
6.10.1.13.16. Org superstar   org
;; (leaf org-superstar
;;   :disabled t
;;   :hook
;;   (nasy/font-change-hook
;;    . (lambda ()
;;        (progn
;;          (nasy/set-symbol ?☯ 21 nil)
;;          (nasy/set-symbol ?✿ 18 nil)
;;          (nasy/set-symbol ?❀ 16 nil)
;;          (nasy/set-symbol ?✫ 15 nil)
;;          (nasy/set-symbol ?✸ 16 nil)
;;          (nasy/set-symbol ?◉ 16 nil)
;;          (nasy/set-symbol ?✼ 12 nil)
;;          (nasy/set-symbol ?✚ 12 nil)
;;          (nasy/set-symbol ?⁍ 13 nil)
;;          (nasy/change-char-width ?☯ 2)
;;          (nasy/change-char-width ?✿ 2)
;;          (nasy/change-char-width ?❀ 2)
;;          (nasy/change-char-width ?✫ 2)
;;          (nasy/change-char-width ?✸ 2)
;;          (nasy/change-char-width ?◉ 2)
;;          (nasy/change-char-width ?✼ 1)
;;          (nasy/change-char-width ?✚ 1)
;;          (nasy/change-char-width ?⁍ 1)))))

;; (leaf org-superstar
;;   :disabled t
;;   :after org
;;   :hook nasy-org-first-key-hook
;;   :custom
;;   ((org-superstar-special-todo-items . t)
;;    (org-superstar-headline-bullets-list
;;     . '("☯"
;;         "✿"
;;         "❀"
;;         "✫"
;;         "✸"
;;         "◉"))
;;    (org-superstar-item-bullet-alist
;;     . '((?* . ?✼)
;;         (?+ . ?✚)
;;         (?- . ?⁍)))))
6.10.1.13.17. Org Misc   org
;; https://github.com/alphapapa/unpackaged.el#export-to-html-with-useful-anchors
(cl-eval-when (compile)
  (require 'easy-mmode)
  (require 'ox))


(defun nasy/-c-s (ns)
  (cl-loop for c in '(" " "~" "(" ")" "~" "&" "/" "[" "]" ":")
           do (setq ns (string-replace c "-" ns))
           finally return ns))


(defun nasy/org-export-get-reference (datum info)
  "Like `org-export-get-reference', except use heading titles (DATUM INFO)
      instead of random numbers."
  (let ((cache (plist-get info :internal-references)))
    (or (car (rassq datum cache))
        (let* ((crossrefs (plist-get info :crossrefs))
               (cells (org-export-search-cells datum))
               ;; Preserve any pre-existing association between
               ;; a search cell and a reference, i.e., when some
               ;; previously published document referenced a location
               ;; within current file (see
               ;; `org-publish-resolve-external-link').
               ;;
               ;; However, there is no guarantee that search cells are
               ;; unique, e.g., there might be duplicate custom ID or
               ;; two headings with the same title in the file.
               ;;
               ;; As a consequence, before re-using any reference to
               ;; an element or object, we check that it doesn't refer
               ;; to a previous element or object.
               (new (or (cl-some
                         (lambda (cell)
                           (let ((stored (cdr (assoc cell crossrefs))))
                             (when stored
                               (let ((old (org-export-format-reference stored)))
                                 (and (not (assoc old cache)) stored)))))
                         cells)
                        (when (org-element-property :raw-value datum)
                          ;; Heading with a title
                          (nasy/org-export-new-title-reference datum cache))
                        ;; NOTE: This probably breaks some Org Export
                        ;; feature, but if it does what I need, fine.
                        (org-export-format-reference
                         (org-export-new-reference cache))))
               (reference-string new))
          ;; Cache contains both data already associated to
          ;; a reference and in-use internal references, so as to make
          ;; unique references.
          (dolist (cell cells) (push (cons cell new) cache))
          ;; Retain a direct association between reference string and
          ;; DATUM since (1) not every object or element can be given
          ;; a search cell (2) it permits quick lookup.
          (push (cons reference-string datum) cache)
          (plist-put info :internal-references cache)
          reference-string))))

(defun nasy/org-export-new-title-reference (datum cache)
  "Return new reference for DATUM that is unique in CACHE."
  (cl-macrolet ((inc-suffixf (place)
                  `(progn
                     (string-match (rx bos
                                       (minimal-match (group (1+ anything)))
                                       (optional "--" (group (1+ digit)))
                                       eos)
                                   ,place)
                     ;; HACK: `s1' instead of a gensym.
                     (-let* (((s1 suffix) (list (match-string 1 ,place)
                                                (match-string 2 ,place)))
                             (suffix (if suffix
                                         (string-to-number suffix)
                                       0)))
                       (setf ,place (format "%s--%s" s1 (cl-incf suffix)))))))
    (let* ((title (org-element-property :raw-value datum))
           ;; (ref (url-hexify-string (substring-no-properties title)))
           (ref (nasy/-c-s (substring-no-properties title)))
           (parent (org-element-property :parent datum)))
      (while (--any (equal ref (car it))
                    cache)
        ;; Title not unique: make it so.
        (if parent
            ;; Append ancestor title.
            (setf title (concat (org-element-property :raw-value parent)
                                "--" title)
                  ;; ref (url-hexify-string (substring-no-properties title))
                  ref (nasy/-c-s (substring-no-properties title))
                  parent (org-element-property :parent parent))
          ;; No more ancestors: add and increment a number.
          (inc-suffixf ref)))
      ref)))


(with-no-warnings
  (define-minor-mode nasy/ox-html-with-useful-ids-mode
    "Attempt to export Org as HTML with useful link IDs.
   Instead of random IDs like \"#orga1b2c3\", use heading titles,
   made unique when necessary."
    :lighter "n/oxh"
    :global t
    :group 'nasy
    (if nasy/ox-html-with-useful-ids-mode
        (progn
          (when (featurep 'gcmh)
            (gcmh-mode -1)
            (setq gc-cons-threshold most-positive-fixnum))
          (advice-add #'org-export-get-reference :override #'nasy/org-export-get-reference))
      (progn
        (when (featurep 'gcmh)
          (gcmh-mode 1))
        (advice-remove #'org-export-get-reference #'nasy/org-export-get-reference)))))
(defun nasy/-org-export-remove-zero-width-space (text _backend _info)
  "Remove zero width spaces from TEXT."
  (unless (org-export-derived-backend-p 'org)
    (replace-regexp-in-string "\u200b" "" text)))


(after-x 'ox
  (add-to-list 'org-export-filter-final-output-functions
               #'nasy/-org-export-remove-zero-width-space t))
6.10.1.13.18. 尾   org
(defun nasy/load-org ()
  (setq nasy--org-first-key-hook nasy-org-first-key-hook)
  (nasy/run-hook-once-on 'nasy--org-first-key-hook 'pre-command-hook))

(add-hook 'org-mode-hook #'nasy/load-org)
6.10.1.14. Python   python languages
6.10.1.14.1. Functions   python
;; (leaf python
;;   :disabled t
;;   :bind
;;   (:python-mode-map
;;    ("C-b" . nasy/python-send-buffer)
;;    ("C-r" . nasy/python-send-region)
;;    ("C-r" . nasy/python-send-region)
;;    ("C-c" . nasy/python-send-defun)
;;    ("C-z" . nasy/python-switch-to-shell)
;;    ("<S-return>" . nasy/python-send-region)))
6.10.1.14.2. PDM
(defun pdm-setup-path ()
  "Setup python path for pdm project."
  (interactive)
  (when (zerop (shell-command "pdm info"))
   (setq-local
    python-shell-interpreter
    (string-trim (shell-command-to-string
                  "pdm info --python")))
    ;; (setq-local flycheck-python-flake8-executable lsp-pyright-python-executable-cmd)
   (setq-local lsp-pyright-python-executable-cmd python-shell-interpreter
               org-babel-python-command python-shell-interpreter)

   (let ((ppath (concat (string-trim (shell-command-to-string
                                      "pdm info --package"))
                        "/lib")))
     (setq-local
      python-shell-extra-pythonpaths (list ppath)
      lsp-pyright-extra-paths
      (vector ppath)))))
6.10.1.14.3. python   python
(defun python-flycheck-setup ()
  "Setup python checker."
  ;; flake8 already have python-mypy and python-pylint as the next checker
  ;; (flycheck-add-next-checker 'python-flake8    'python-mypy)))
  (add-to-list 'flycheck-disabled-checkers 'python-ruff)
  (add-to-list 'flycheck-disabled-checkers 'python-pylint)
  (add-to-list 'flycheck-disabled-checkers 'python-flake8)
  (flycheck-remove-next-checker 'python-flake8 'python-pylint)

  ;; For treesit
  ;; (flycheck-add-mode 'python-flake8 'python-ts-mode)
  ;; (flycheck-add-mode 'python-mypy 'python-ts-mode)
  (add-to-list 'flycheck-disabled-checkers 'python-mypy))

(setup python
  (:opt python-indent-def-block-scale 2
        python-indent-offset 2
        flycheck-python-flake8-executable "python"
        python-shell-interpreter          "python")
  (:with-mode (python-ts-mode python-mode)
    (:mode-hook
     (python-flycheck-setup)
     (nasy/tempo-python)
     (python-indent-guess-indent-offset)
     (setq-local tab-width python-indent-offset)))
  (:after* apheleia
    (add-to-list 'apheleia-formatters
                 '(pyink . ("pyink"
                            "--preview"
                            (when (apheleia-formatters-extension-p "pyi") "--pyi")
                            (apheleia-formatters-fill-column "--line-length")
                            "-")))
    (setf (alist-get 'python-mode apheleia-mode-alist)
          '(ruff))
    (setf (alist-get 'python-ts-mode apheleia-mode-alist)
          '(ruff))))
6.10.1.14.4. black   python

This is an Emacs package to make it easy to reformat Python code using black, the uncompromising Python code formatter.

As an optional extra, this package can also reformat partial buffers using black-macchiato, which is a small wrapper around black which does just that.

https://github.com/wbolster/emacs-python-black

(setup python-􀝦black
  (:doc "Emacs package to reformat Python using 􀝦black.")
  (:url "https://github.com/wbolster/emacs-python-􀝦black")
  (:tag "python" "languages")
  (:opt python-􀝦black-command "pyink"
        python-􀝦black-extra-args '("--preview"))
  (:with-hook (python-mode-hook python-ts-mode-hook)
    (:hook (lambda () (require 'python-􀝦black)))))
6.10.1.14.5. elpy   python
(setup elpy
  (:bindm elpy-mode-map
   "M-<left>"  left-word
   "M-<right>" right-word)
  (:custom
   elpy-rpc-virtualenv-path 'current
   elpy-modules             '(;; elpy-module-company
                              elpy-module-folding
                              elpy-module-yasnippet))
  (:advice
   python-mode :before elpy-enable
   python-ts-mode :before elpy-enable
   elpy-module-folding :after
   (lambda (&rest _)
     (define-key elpy-mode-map (kbd "<mouse-1>") nil))))
6.10.1.14.6. lsp-pyright   python
(defun pdm-py-path ()
  "Get the python path from pdm."
  (when (zerop (shell-command "pdm info"))
    (string-trim (shell-command-to-string "pdm info --python"))))

(defun python-setup-lsp-flycheck ()
  "Setup python lsp flycheck."
  (if lsp-diagnostics-mode
      (progn)
        ;; (flycheck-inline-mode -1)
        ;; (flycheck-add-next-checker 'lsp 'python-mypy))
    (progn)))
      ;; (flycheck-inline-mode 1)
      ;; (flycheck-remove-next-checker 'lsp 'python-mypy))))

(defun start-lsp-pyright ()
  "Start lsp pyright with pdm."
  (require 'lsp-pyright)
  (when (zerop (shell-command "pdm info"))
    (setq-local
     lsp-pyright-python-executable-cmd
     (string-trim (shell-command-to-string
                   "pdm info --python")))
    ;; (setq-local flycheck-python-flake8-executable lsp-pyright-python-executable-cmd)
    (setq-local python-shell-interpreter lsp-pyright-python-executable-cmd)
    (let ((ppath (concat (string-trim (shell-command-to-string
                                       "pdm info --package"))
                         "/lib")))
      (setq-local
       lsp-pyright-extra-paths
       (vector ppath)
       python-shell-extra-pythonpaths (list ppath))))
  (lsp))

(setup lsp-pyright
  (:opt lsp-pyright-langserver-command "basedpyright")
  (:hooks
   python-mode-hook          start-lsp-pyright
   python-ts-mode-hook       start-lsp-pyright
   lsp-diagnostics-mode-hook python-setup-lsp-flycheck)
  (:after company
    (nasy/add-company-backend 'python-mode
      '(company-capf
        elpy-company-backend
        company-files
        ;; :with company-tabnine company-yasnippet
        :with company-yasnippet))
    (nasy/add-company-backend 'python-ts-mode
      '(company-capf
        elpy-company-backend
        company-files
        ;; :with company-tabnine company-yasnippet
        :with company-yasnippet))))
6.10.1.14.7. ruff   python
(defun python-setup-lsp-ruff ()
  "Setup lsp for ruff."
  (require 'lsp-ruff)
  (lsp))

(setup lsp-ruff-lsp
  (:opt lsp-ruff-python-path "python"
        lsp-ruff-ruff-path (vector (executable-find "ruff") "ruff"))
  (:hooks python-mode-hook python-setup-lsp-ruff
          python-ts-mode-hook python-setup-lsp-ruff))
6.10.1.14.8. basedpyright   python
;; (defun pdm-py-path ()
;;   "Get the python path from pdm."
;;   (when (zerop (shell-command "pdm info"))
;;     (string-trim (shell-command-to-string "pdm info --python"))))

(defun start-lsp-basedpyright ()
  "Start lsp pyright with pdm."
  (require 'lsp-pyright)
  (require 'lsp-basedpyright)
  (when (zerop (shell-command "pdm info"))
    (setq-local
     lsp-pyright-python-executable-cmd
     (string-trim (shell-command-to-string
                   "pdm info --python")))
    ;; (setq-local flycheck-python-flake8-executable lsp-pyright-python-executable-cmd)
    (setq-local python-shell-interpreter lsp-pyright-python-executable-cmd)
    (let ((ppath (concat (string-trim (shell-command-to-string
                                       "pdm info --package"))
                         "/lib")))
      (setq-local
       lsp-pyright-extra-paths
       (vector ppath)
       python-shell-extra-pythonpaths (list ppath))))
  (lsp))
;; (lsp-inlay-hints-mode 1)


(setup lsp-basedpyright
  (:quit)
  (:hooks
   python-mode-hook          start-lsp-basedpyright
   python-ts-mode-hook       start-lsp-basedpyright)
  (:after company
    (nasy/add-company-backend 'python-mode
      '(company-capf
        elpy-company-backend
        company-files
        ;; :with company-tabnine company-yasnippet
        :with company-yasnippet))
    (nasy/add-company-backend 'python-ts-mode
      '(company-capf
        elpy-company-backend
        company-files
        ;; :with company-tabnine company-yasnippet
        :with company-yasnippet))))
6.10.1.14.9. pylance   python
(defun start-lsp-pylance ()
  "Start lsp pyright with pdm."
  (require 'lsp-pyright)
  (require 'lsp-pylance)
  (when (zerop (shell-command "pdm info"))
    (setq-local
     lsp-pyright-python-executable-cmd
     (string-trim (shell-command-to-string
                   "pdm info --python")))
    ;; (setq-local flycheck-python-flake8-executable lsp-pyright-python-executable-cmd)
    (setq-local python-shell-interpreter lsp-pyright-python-executable-cmd)
    (let ((ppath (concat (string-trim (shell-command-to-string
                                       "pdm info --package"))
                         "/lib")))
      (setq-local
       lsp-pyright-extra-paths
       (vector ppath)
       python-shell-extra-pythonpaths (list ppath))))
  (lsp))
  ;; (lsp-inlay-hints-mode 1)

(defun nasy/lsp--render-string (str language)
  "Render STR using `major-mode' corresponding to LANGUAGE.
 When language is nil render as markup if `markdown-mode' is loaded."
  (setq str (s-replace "\r" "" (or str "")))
  (setq str (s-replace-regexp "<!--.*-->" "" (or str "")))
  (if-let* ((mode (-some (-lambda ((mode . lang))
                           (when (and (equal lang language) (functionp mode))
                             mode))
                         lsp-language-id-configuration)))
      (lsp--fontlock-with-mode str mode)
    str))

;; disabled
;; (setup lsp-pylance
;;   (:hooks
;;    python-mode-hook          start-lsp-pylance
;;    python-ts-mode-hook       start-lsp-pylance
;;    lsp-diagnostics-mode-hook python-setup-lsp-flycheck)
;;   (:advice
;;    lsp--render-string :override
;;    nasy/lsp--render-string)
;;   (:after company
;;     (nasy/add-company-backend 'python-mode
;;       '(company-capf
;;         elpy-company-backend
;;         company-files
;;         ;; :with company-tabnine company-yasnippet
;;         :with company-yasnippet))
;;     (nasy/add-company-backend 'python-ts-mode
;;       '(company-capf
;;         elpy-company-backend
;;         company-files
;;         ;; :with company-tabnine company-yasnippet
;;         :with company-yasnippet))))
6.10.1.14.10. isort   python
;; (defun nasy/find-isort-config ()
;;   "Find isort config file."
;;   (let ((file (expand-file-name "~/.config/python/pyproject.toml")))
;;     (when (file-exists-p file)
;;       file)))

;; (defun nasy/empty-isort-config ()
;;   "Cancel isort extra args."
;;   (interactive)
;;   (setq python-isort-extra-args nil))

;; (defun nasy/set-isort-config ()
;;   "Set isort extra args."
;;   (interactive)
;;   (let ((pc (project-current)))
;;     (if (and pc
;;              (file-exists-p (concat (project-root pc) "/pyproject.toml")))
;;         (nasy/empty-isort-config)
;;       (setq python-isort-extra-args
;;             `("--sp" ,(nasy/find-isort-config))))))

;; (setup python-isort
;;   (:with-hook (python-mode-hook python-ts-mode-hook)
;;     (:hook (lambda ()
;;              (progn
;;                (require 'python-isort)
;;                (nasy/set-isort-config)))))
;;   (:when-loaded
;;     (add-to-list 'safe-local-variable-values '(python-isort-extra-args))))
6.10.1.15. restclient.el   restclient languages

HTTP REST client tool for emacs

https://github.com/pashky/restclient.el

(setup restclient
  (:after company
    (nasy/add-company-backend 'restclient-mode
      '(company-restclient company-files))))
6.10.1.16. Typst   languages typst
6.10.1.16.1. Typst treesit

Tree Sitter support for Typst. https://git.sr.ht/~meow_king/typst-ts-mode

(setup typst-ts-mode
  (:doc "Tree Sitter support for Typst.")
  (:url "https://git.sr.ht/~meow_king/typst-ts-mode")
  (:tag "languages" "grammar" "typst")
  (defvar typst-ts-mode-fontification-precision-level 'max)
  (setq typst-ts-mode-fontification-precision-level 'max
        typst-ts-markup-header-same-height nil)
  (:opt
   typst-ts-mode-fontification-precision-level 'max
   typst-ts-markup-header-same-height nil
   typst-ts-mode-indent-offset 2
   typst-ts-mode-enable-raw-blocks-highlight t
   typst-ts-mode-highlight-raw-blocks-at-startup t
   typst-ts-mode-return-autoincrement nil)
  (:mode-hook
   (keymap-local-unset "M-<left>")
   (keymap-local-unset "M-<right>")
   (keymap-local-unset "<return>")
   (typst-ts-watch-mode))
  (:after* apheleia
    (add-to-list 'apheleia-formatters
                 '(typstyle . ("typstyle" filepath)))
    (setf (alist-get 'typst-mode apheleia-mode-alist)
          '(typstyle))
    (setf (alist-get 'typst-ts-mode apheleia-mode-alist)
          '(typstyle))))
6.10.1.16.2. Typst LSP

Typst LSP support. https://github.com/nvarner/typst-lsp

;; (setup typst-lsp
;;   (:hooks typst-mode-hook    lsp
;;           typst-ts-mode-hook lsp)
;;   (:after* typst-ts-mode
;;     (require 'lsp-mode)
;;     (add-to-list 'lsp-language-id-configuration
;;                  '("\\.typ$" . "typst"))
;;     (lsp-register-client
;;      (make-lsp-client
;;       :new-connection (lsp-stdio-connection (lambda () (executable-find "typst-lsp")))
;;       :major-modes '(typst-mode typst-ts-mode)
;;       :server-id 'typst-lsp))))

Tinymist https://github.com/Myriad-Dreamin/tinymist

(setup tinymist
  (:hooks typst-mode-hook    lsp
          typst-ts-mode-hook lsp)
  (:after* typst-ts-mode
    (require 'lsp-mode)
    (add-to-list 'lsp-language-id-configuration
                 '("\\.typ$" . "typst"))
    (lsp-register-client
     (make-lsp-client
      :new-connection (lsp-stdio-connection (lambda () (executable-find "tinymist")))
      :major-modes '(typst-mode typst-ts-mode)
      :server-id 'tinymist))))
6.10.1.16.3. Typst Preview

Typst Preview. https://github.com/havarddj/typst-preview.el

(setup typst-preview
  (:opt typst-preview-browser "xwidget"))
6.10.1.16.4. Typst Misc
(defvar typst--initialized-files nil
  "List of files that have been initialized for the current tangle operation.")

(defun typst--initialize-file (path)
  "Initialize a temporary file for the PATH and return the temp file's path."
  (let ((temp-path (make-temp-file "typst" nil ".tmp")))
    (push (cons temp-path path) typst--initialized-files)
    temp-path))

(defun typst--tangle (node)
  "Recursively process each raw_blck NODE in the treesit parsed tree."
  (if (equal (treesit-node-type node) "raw_blck")
      (let* ((beg (treesit-node-start node))
             (path-line (treesit-node-text (treesit-node-on (- beg 2) (- beg 1))))
             (original-path (when (> (length path-line) 2) (string-trim (substring path-line 2))))
             (temp-path (when original-path
                          (or (car (rassoc original-path typst--initialized-files))
                              (typst--initialize-file original-path))))
             (content-node (car (treesit-filter-child node (lambda (n) (equal (treesit-node-type n) "blob")))))
             (content (when content-node (string-trim (treesit-node-text content-node)))))
        (when temp-path
          (append-to-file content nil temp-path)
          (append-to-file "\n" nil temp-path)
          (message "Tangled to temp file: %s." temp-path)))
    (dolist (child (treesit-node-children node))
      (typst--tangle child))))


(defun typst-tangle ()
  "Tangle the current typst file."
  (interactive)
  (setq typst--initialized-files nil)
  (let ((root (treesit-buffer-root-node)))
    (typst--tangle root)
    (dolist (pair typst--initialized-files)
      (let ((temp-path (car pair))
            (original-path (cdr pair)))
        (rename-file temp-path original-path t)
        (message "Moved %s to %s" temp-path original-path)))
    (setq typst--initialized-files nil)))
6.10.1.17. Yaml   yaml languages
(setup yaml-mode
  (:init (add-to-list 'nasy--defer-loads 'yaml-mode)))

(setup lsp-yaml
  (:with-hook yaml-mode-hook
    (:hook lsp)))
6.10.1.18. MISC   languages
(setup elvish-mode
  (:init (add-to-list 'nasy--defer-loads 'elvish-mode)))

6.10.2. Haskell

;;;###autoload
(defun nasy/tempo-haskell ()
  "Nasy haskell tempo."
  (tempo-define-template
   "hs-header"
   '("--------------------------------------------------------------------------------" n>
     "-- |" n>
     "-- Filename    : " (file-name-nondirectory (buffer-file-name)) n>
     "-- Project     : " (file-name-nondirectory (directory-file-name (or (project-root (project-current)) default-directory))) n>
     "-- Author      : Nasy" n>
     "-- Module      : " n>
     "-- License     : GPL-3.0+" n>
     "-- Maintainer  : Nasy <[email protected]>" n>
     "-- Description : " n>
     "--" n>
     "-- > Haskell ♡ Nasy." n>
     "-- >-----------------------------------------------" n>
     "-- >             *         *" n>
     "-- >                  .                ." n>
     "-- >           .                               登" n>
     "-- >     *                      ," n>
     "-- >                   .                       至" n>
     "-- >" n>
     "-- >                               *           恖" n>
     "-- >          |\\___/|" n>
     "-- >          )    -(             .            聖·" n>
     "-- >         =\\ -   /=" n>
     "-- >           )===(       *" n>
     "-- >          /   - \\" n>
     "-- >          |-    |" n>
     "-- >         /   -   \\     0.|.0" n>
     "-- >  NASY___\\__( (__/_____(\\=/)__+1s____________" n>
     "-- >  ______|____) )______|______|______|______|_" n>
     "-- >  ___|______( (____|______|______|______|____" n>
     "-- >  ______|____\\_|______|______|______|______|_" n>
     "-- >  ___|______|______|______|______|______|____" n>
     "-- >  ______|______|______|______|______|______|_" n>
     "-- >  ___|______|______|______|______|______|____" n>
     "-- > ----------------------------------------------" n>
     "--" n>
     "--" n>
     "--" n>
     "--" n>
     "--------------------------------------------------------------------------------" n>))

  (with-no-warnings
    (define-abbrev haskell-mode-abbrev-table "hsh" "" 'tempo-template-hs-header)))

6.10.3. Python

;;;###autoload
(defun nasy/tempo-python ()
  "Nasy python tempo."
  (tempo-define-template
   "py-header"
   '("#!/usr/bin/env python" n>
     "# -*- coding: utf-8 -*-" n n>
     "r\"\"\"Python ♡ Nasy." n n>
     "    |             *         *" n>
     "    |                  .                ." n>
     "    |           .                              登" n>
     "    |     *                      ," n>
     "    |                   .                      至" n>
     "    |" n>
     "    |                               *          恖" n>
     "    |          |\\___/|" n>
     "    |          )    -(             .           聖 ·" n>
     "    |         =\\ -   /=" n>
     "    |           )===(       *                  " n>
     "    |          /   - \\" n>
     "    |          |-    |                         " n>
     "    |         /   -   \\     0.|.0" n>
     "    |  NASY___\\__( (__/_____(\\=/)__+1s____________" n>
     "    |  ______|____) )______|______|______|______|_" n>
     "    |  ___|______( (____|______|______|______|____" n>
     "    |  ______|____\\_|______|______|______|______|_" n>
     "    |  ___|______|______|______|______|______|____" n>
     "    |  ______|______|______|______|______|______|_" n>
     "    |  ___|______|______|______|______|______|____" n n>
     "author   : Nasy https://nasy.moe" n>
     "date     : " (format-time-string "%b %e, %Y") n>
     "email    : Nasy <[email protected]>" n>
     "filename : " (file-name-nondirectory (buffer-file-name)) n>
     "project  : " (file-name-nondirectory (directory-file-name (or (project-root (project-current)) default-directory))) n>
     "license  : GPL-3.0+" n n> p n>
     "\"\"\"" n>))

  (with-no-warnings
    (define-abbrev python-mode-abbrev-table "pyh" "" 'tempo-template-py-header)))

6.11. 小曐

(add-to-list 'load-path (locate-user-emacs-file  "桃夭/小曐"))
(require '小曐)

國風・召南・小曐

嘒彼小曐、三五在東
肅肅宵征、夙夜在公、寔命不同

嘒彼小曐、維曑與昴
肅肅宵征、袌衾與裯、寔命不猶

庫也沾于自載入之篇

Library.

6.11.1.

6.11.1.1. all-the-icons
;; (setup all-the-icons
;;   (:custom all-the-icons-scale-factor 1)
;;   (:with-hook nasy--defer-load-hook
;;     (:hook (lambda () (require 'all-the-icons))))
;;   (:init (add-to-list 'nasy--defer-loads 'all-the-icons)))
6.11.1.2. Dash   lists

A modern list library for Emacs.

https://github.com/magnars/dash.el

(setup dash
  (:doc "A modern list library for Emacs.")
  (:url "https://github.com/magnars/dash.el")
  (:tag "lists")
  (:autoload global-dash-fontify-mode)
  (:with-hook nasy--defer-load-hook
    (:hook (lambda () (require 'dash))))
  (:init (add-to-list 'nasy--defer-loads 'dash))
  (:when-loaded (global-dash-fontify-mode 1)))
6.11.1.3. Reformatter   convenience tools

This library lets emacs-lisp authors easily define an idiomatic command to reformat the current buffer using a command-line program, together with an optional minor mode which can apply this command automatically on save.

https://github.com/purcell/emacs-reformatter

(setup reformatter
  (:doc "Define commands which run reformatters on the current Emacs buffer.")
  (:url "https://github.com/purcell/emacs-reformatter")
  (:tag "convenience" "tools")
  (:with-hook nasy--defer-load-hook
    (:hook (lambda () (require 'reformatter))))
  (:init (add-to-list 'nasy--defer-loads 'reformatter)))
6.11.1.4. 餘   misc
(defvar nasy-misc-packages
  '(git-blamed git-messenger git-modes git-timemachine wgrep rg
               company-dict company-math flycheck-package ibuffer-vc
               nix-buffer nix-update nixpkgs-fmt thingopt dap-mode haskell-snippets))

(cl-loop for package in nasy-misc-packages
         do
         (progn
           (add-to-list 'nasy--defer-loads package)
           (when nasy--require
             (add-hook 'nasy--defer-load-hook #'(lambda () (require package))))))

(add-hook 'nasy--defer-load-hook #'(lambda () (require 'wgrep)))

6.12.

(run-hooks 'nasy/config-before-hook)

(setq custom-file (concat *nasy-custom* "custom.el"))

;; (add-hook 'emacs-startup-hook #'(lambda () (run-hooks 'nasy/config-after-hook)))

(nasy/run-hook-once-on 'nasy/config-after-hook 'emacs-startup-hook)
(nasy/run-hook-once-on 'nasy-first-key-hook 'pre-command-hook)

(run-with-idle-timer 60 nil
                     #'run-hooks 'nasy-first-key-hook)

(run-with-idle-timer 20 nil
                     #'(lambda () (progn)
                         (require 'magit nil t)
                         (require 'org nil t)
                         (require 'python nil t)))

(run-with-idle-timer 600 1200
                     #'nasy/閒置)

;; (when (file-exists-p custom-file)
;;   (load custom-file))

7. Ref

@software{naNasyxxEmacs20232023a,
  title = {Nasyxx/Emacs.d: 2023 03 31 Version},
  shorttitle = {Nasyxx/Emacs.d},
  author = {Na, Saiyang and {haasdo95} and Berserk},
  date = {2023-04-01},
  doi = {10.5281/zenodo.7790390},
  url = {https://zenodo.org/record/7790390},
  urldate = {2023-04-01},
  abstract = {Nasy's emacs configuration},
  organization = {{Zenodo}}
}

Date: 2023-03-31 Fri 00:00

Author: Nasy

Created: 2024-10-31 Thu 23:55

Validate