;; gc.
(setq gc-cons-threshold 402653184)
(add-hook 'after-emacs-hook '(lambda ()
;; restore after startup
(setq gc-cons-threshold 16777216)))
;; Prevent the glimpse of un-styled Emacs by disabling these UI elements early.
(push '(menu-bar-lines . 0) default-frame-alist)
(push '(tool-bar-lines . 0) default-frame-alist)
(push '(vertical-scroll-bars) default-frame-alist)
;; Resizing the Emacs frame can be a terribly expensive part of changing the
;; font. By inhibiting this, we easily halve startup times with fonts that are
;; larger than the system default.
(setq frame-inhibit-implied-resize t)
;; In Emacs 27+, package initialization occurs before `user-init-file' is
;; loaded, but after `early-init-file'. We must prevent Emacs from doing
;; it early!
(setq package-enable-at-startup nil)
;; Prevent unwanted runtime builds in gccemacs (native-comp); packages are
;; compiled ahead-of-time when they are installed and site files are compiled
;; when gccemacs is installed.
(setq comp-deferred-compilation nil)
;; Profile emacs startup
(add-hook 'emacs-startup-hook
(lambda ()
(message "*** Emacs loaded in %s with %d garbage collections."
(format "%.2f seconds"
(float-time
(time-subtract after-init-time before-init-time)))
gcs-done)))
(let (file-name-handler-alist)
;; Ensure Emacs is running out of this file's directory
(setq user-emacs-directory (file-name-directory load-file-name)))
(defvar salt-dir-private (expand-file-name "private" user-emacs-directory)
"All files you create under the private folder are yours for personalization.")
;;; .local folder
(defvar salt-dir-local (expand-file-name ".local" user-emacs-directory)
"Folder of configure files, backup files, template files and so on.")
;;; Cache folder
(defvar salt-dir-cache (expand-file-name "cache" salt-dir-local))
;;; Template folder
(defvar salt-dir-template (expand-file-name "template" salt-dir-local)
"Folder path of template files.")
;; the load-path of core settings
(add-to-list 'load-path (expand-file-name "elisp/" user-emacs-directory))
;;; Create folders
(dolist (dir (list salt-dir-private
salt-dir-local
salt-dir-cache
salt-dir-template))
(when (not (file-directory-p dir))
(make-directory dir)))
;;; Font and frame size
;; frame size
(setq initial-frame-alist
(quote ((fullscreen . maximized))))
;;; Remove menu-bar, scroll-bar and tool-bar.
(menu-bar-mode -1)
(toggle-scroll-bar -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(setq visible-bell t)
(set-face-attribute 'default nil :family "M+ 1mn Light" :height 180)
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
;;; install use-package
(straight-use-package 'use-package)
(eval-and-compile
(setq use-package-always-ensure nil) ;; ESSENTIAL for `straight.el'
(setq use-package-always-defer nil)
(setq use-package-always-demand nil)
(setq use-package-expand-minimally nil)
(setq use-package-enable-imenu-support t)
(setq use-package-compute-statistics nil))
;;; provides `straight-x-clean-unused-repos' (part of `straight.el')
(use-package straight-x
:defer t)
;;; modus themes
(use-package modus-themes
:straight t
:init
(setq modus-themes-italic-constructs t
modus-themes-bold-constructs nil
modus-themes-mixed-fonts nil
modus-themes-subtle-line-numbers nil
modus-themes-deuteranopia t
modus-themes-tabs-accented t
modus-themes-variable-pitch-ui nil
modus-themes-inhibit-reload t ; only applies to `customize-set-variable' and related
modus-themes-fringes nil ; {nil,'subtle,'intense}
;; Options for `modus-themes-lang-checkers' are either nil (the
;; default), or a list of properties that may include any of those
;; symbols: `straight-underline', `text-also', `background',
;; `intense' OR `faint'.
modus-themes-lang-checkers nil
;; Options for `modus-themes-mode-line' are either nil, or a list
;; that can combine any of `3d' OR `moody', `borderless',
;; `accented', and a natural number for extra padding
modus-themes-mode-line '(3d accented borderless)
;; Options for `modus-themes-markup' are either nil, or a list
;; that can combine any of `bold', `italic', `background',
;; `intense'.
modus-themes-markup '(background italic)
;; Options for `modus-themes-syntax' are either nil (the default),
;; or a list of properties that may include any of those symbols:
;; `faint', `yellow-comments', `green-strings', `alt-syntax'
modus-themes-syntax nil
;; Options for `modus-themes-hl-line' are either nil (the default),
;; or a list of properties that may include any of those symbols:
;; `accented', `underline', `intense'
modus-themes-hl-line '(underline accented)
;; Options for `modus-themes-paren-match' are either nil (the
;; default), or a list of properties that may include any of those
;; symbols: `bold', `intense', `underline'
modus-themes-paren-match '(bold intense)
;; Options for `modus-themes-links' are either nil (the default),
;; or a list of properties that may include any of those symbols:
;; `neutral-underline' OR `no-underline', `faint' OR `no-color',
;; `bold', `italic', `background'
modus-themes-links '(neutral-underline background)
;; Options for `modus-themes-prompts' are either nil (the
;; default), or a list of properties that may include any of those
;; symbols: `background', `bold', `gray', `intense', `italic'
modus-themes-prompts '(intense bold)
modus-themes-completions 'moderate ; {nil,'moderate,'opinionated}
modus-themes-mail-citations nil ; {nil,'intense,'faint,'monochrome}
;; Options for `modus-themes-region' are either nil (the default),
;; or a list of properties that may include any of those symbols:
;; `no-extend', `bg-only', `accented'
modus-themes-region '(bg-only no-extend)
;; Options for `modus-themes-diffs': nil, 'desaturated, 'bg-only
modus-themes-diffs 'desaturated
modus-themes-org-blocks 'gray-background ; {nil,'gray-background,'tinted-background}
modus-themes-org-agenda ; this is an alist: read the manual or its doc string
'((header-block . (variable-pitch 1.3))
(header-date . (grayscale workaholic bold-today 1.1))
(event . (accented varied))
(scheduled . uniform)
(habit . traffic-light))
modus-themes-headings ; this is an alist: read the manual or its doc string
'((1 . (overline background variable-pitch 1.5))
(2 . (rainbow overline 1.3))
(3 . (overline 1.1))
(t . (monochrome))))
;;(set-face-attribute 'default nil :family "M+ 1mn Light" :height 120)
;;(set-face-attribute 'variable-pitch nil :family "M+ 1mn Light" :height 120)
;;(set-face-attribute 'fixed-pitch nil :family "M+ 1mn Light" :height 120)
;; Load the theme files before enabling a theme (else you get an error).
(modus-themes-load-themes)
:config
;; Load the theme of your choice:
(modus-themes-load-vivendi) ;; OR (modus-themes-load-vivendi)
)
;;; display line number
(use-package display-line-numbers
:hook (prog-mode . display-line-numbers-mode)
:hook (text-mode . display-line-numbers-mode))
;;; TODO: deal with word-wrap issue of language-mixed style.
;;; visual-fill-column
(use-package visual-fill-column
:straight t
:init
(setq visual-fill-column-inhibit-sensible-window-split t
visual-fill-column-width 120)
:hook
(text-mode . visual-line-mode)
(prog-mode . visual-line-mode)
(visual-line-mode . visual-fill-column-mode)
:config
(add-hook 'visual-line-mode-hook #'(lambda ()
(setq-local word-wrap nil)))
(advice-add 'text-scale-adjust :after #'visual-fill-column-adjust))
;; Enable vertico
(use-package vertico
:straight t
:init
(vertico-mode)
;; Grow and shrink the Vertico minibuffer
;; (setq vertico-resize t)
;; Optionally enable cycling for `vertico-next' and `vertico-previous'.
(setq vertico-cycle t))
(use-package orderless
:straight t
:custom (completion-styles '(orderless)))
;;; consult
(use-package consult
:straight t
:init
(defun consult-fd (&optional dir)
"Search for regexp with fd in DIR."
(interactive "P")
(let ((consult-fd-cmd '("fd" "--color=never" "--full-path")))
(pcase-let ((`(,prompt . ,default-directory) (consult--directory-prompt "fd" dir)))
(consult--find prompt consult-fd-cmd))))
:config
(fset 'multi-occur #'consult-multi-occur))
;;; Enable richer annotations using the Marginalia package
(use-package marginalia
:straight t
:defer t
;; Either bind `marginalia-cycle` globally or only in the minibuffer
:bind (("M-A" . marginalia-cycle)
:map minibuffer-local-map
("M-A" . marginalia-cycle))
;; The :init configuration is always executed (Not lazy!)
:init
;; Must be in the :init section of use-package such that the mode gets
;; enabled right away. Note that this forces loading the package.
(marginalia-mode))
;;; embark
(use-package embark
:straight t
:defer t
:bind
(("C-." . embark-act) ;; pick some comfortable binding
("M-." . embark-dwim) ;; good alternative: M-.
("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'
:init
;; Optionally replace the key help with a completing-read interface
(setq prefix-help-command #'embark-prefix-help-command)
:config
;; 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)))))
(use-package embark-consult
:straight t
:defer t
:after (embark consult)
:demand t ; only necessary if you have the hook below
;; if you want to have consult previews as you move around an
;; auto-updating embark collect buffer
:hook
(embark-collect-mode . consult-preview-at-point-mode))
以下這些設定,是為了 vertico 這個套件所做的設定。
;; Persist history over Emacs restarts. Vertico sorts by history position.
(use-package savehist
:straight (:type built-in)
:init
(savehist-mode))
;; A few more useful configurations for vertico ...
(use-package emacs
:straight (:type built-in)
:init
;; Add prompt indicator to `completing-read-multiple'.
;; Alternatively try `consult-completing-read-multiple'.
(defun crm-indicator (args)
(cons (concat "[CRM] " (car args)) (cdr args)))
(advice-add #'completing-read-multiple :filter-args #'crm-indicator)
;; Do not allow the cursor in the minibuffer prompt
(setq minibuffer-prompt-properties
'(read-only t cursor-intangible t face minibuffer-prompt))
(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode)
;; Emacs 28: Hide commands in M-x which do not work in the current mode.
;; Vertico commands are hidden in normal buffers.
;; (setq read-extended-command-predicate
;; #'command-completion-default-include-p)
;; Enable recursive minibuffers
(setq enable-recursive-minibuffers t))
(use-package undo-tree
:straight t
:defer t)
(use-package ibuffer-projectile
:straight t
:defer t
:after projectile
)
(use-package helpful
:straight t
:defer t
:init
(global-set-key (kbd "C-h f") #'helpful-callable)
(global-set-key (kbd "C-h v") #'helpful-variable)
(global-set-key (kbd "C-h k") #'helpful-key)
;; Lookup the current symbol at point. C-c C-d is a common keybinding
;; for this in lisp modes.
(global-set-key (kbd "C-c C-d") #'helpful-at-point)
;; Look up *F*unctions (excludes macros).
;;
;; By default, C-h F is bound to `Info-goto-emacs-command-node'. Helpful
;; already links to the manual, if a function is referenced there.
(global-set-key (kbd "C-h F") #'helpful-function)
;; Look up *C*ommands.
;;
;; By default, C-h C is bound to describe `describe-coding-system'. I
;; don't find this very useful, but it's frequently useful to only
;; look at interactive functions.
(global-set-key (kbd "C-h C") #'helpful-command))
(use-package projectile
:straight t
:hook (after-init . projectile-mode)
:config
(setq projectile-completion-system 'default
projectile-enable-caching t
projectile-indexing-method 'hybrid
projectile-known-projects-file (expand-file-name "projectile.projects" salt-dir-cache)
projectile-cache-file (expand-file-name "projectile.cache" salt-dir-cache)
projectile-ignored-projects '("~/" "/tmp")))
(use-package org
:straight (:host github
:repo "emacs-straight/org-mode")
:defer t)
(use-package org-contrib
:straight (:host github
:repo "emacsmirror/org-contrib")
:defer t)
(use-package evil
:straight t
:init
(setq evil-want-keybinding nil))
(use-package evil-collection
:straight t
:after evil)
(use-package eshell ;built-in
:defer t
:commands (eshell/pushd eshell/pwd)
:init
(setq eshell-directory-name (concat user-emacs-directory ".local/eshell/")))
(use-package eshell-z
:straight t
:defer t
:hook ((eshell-mode . (lambda () (require 'eshell-z)))
(eshell-z-change-dir . (lambda () (eshell/pushd (eshell/pwd))))))
(use-package esh-help
:straight t
:defer t
:config
(setup-esh-help-eldoc))
(use-package eshell-syntax-highlighting
:straight t
:after eshell
:defer t
:hook
(eshell-mode . eshell-syntax-highlighting-mode))
(use-package ruby-mode
:straight t)
(use-package inf-ruby
:straight t)
(use-package rainbow-mode
:straight t
:defer t)
(use-package kurecolor
:straight t
:defer t)
;;; magit
(use-package magit
:straight t
:defer t
:init
(setq transient-levels-file (expand-file-name "transient/levels" salt-dir-local)
transient-values-file (expand-file-name "transient/values" salt-dir-local)
transient-history-file (expand-file-name "transient/history" salt-dir-local))
:defer t)
(use-package gist
:straight t
:defer t)
(use-package hydra
:straight t
:defer t
:init
)
(defhydra salt (:color blue :columns 5)
"Launch!"
("b" salt-buffers/body "+buffers")
("f" salt-files/body "+files")
("h" salt-help/body "+help & info")
("p" salt-project/body "+projects")
("s" salt-search/body "+search")
("t" salt-toggles/body "+toggles")
("q" nil "cancel")
("SPC" execute-extended-command "M-x")
("<escape>" enter-salt-cmd-mode "Exit")
)
(use-package smartparens
:straight t
:defer t
)
(use-package emmet-mode
:straight t
:defer t)
(use-package web-mode
:straight t
:defer t)
(use-package rjsx-mode
:straight t
:defer t)
(use-package xref-js2
:straight t
:defer t)