Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hidekiyatomi/706cb4fd1b4bac688ac337f4447c088a to your computer and use it in GitHub Desktop.
Save hidekiyatomi/706cb4fd1b4bac688ac337f4447c088a to your computer and use it in GitHub Desktop.
;;; init.el --- -*- coding: utf-8; lexical-binding: t; -*-
;;; commentary:
;;; code:
;;============================================================
;; native compilation
;;============================================================
(setq native-comp-speed 3) ;; native-compilation 最適化レベル
;;============================================================
;; package.el
;;============================================================
;; built-in パッケージもパッケージサイトからugprade可能にする。
;; デフォルトでは、builtinパッケージよりも新しいバージョンがパッケージサイトに
;; 存在してもアップグレードしない。
(setq package-install-upgrade-built-in t)
;; パッケージサイト追加。
(setq package-archives
'(("MELPA" . "https://melpa.org/packages/")
("GNU" . "https://elpa.gnu.org/packages/")
;; ("NonGNU" . "https://elpa.nongnu.org/nongnu/")
)
package-archive-priorities
'(("MELPA" . 8)
("GNU" . 4)
("NonGNU" . 10)))
;;============================================================
;; leaf.el
;;============================================================
(unless (package-installed-p 'leaf)
(package-refresh-contents)
(package-install 'leaf))
;;============================================================
;; default setting
;;============================================================
;; 警告ベル効果無効化。
(setq visible-bell nil)
(setq ring-bell-function 'ignore)
;; emacsが勝手にファイルを作る系機能を無効化。
(setq auto-save-default nil)
(setq auto-save-interval 0)
(setq make-backup-files nil)
(setq create-lockfiles nil)
(setq version-control 'never)
(setq-default tab-width 4)
(setq-default indent-tabs-mode nil) ;; TABコードではなくスペースでインデントする。
(global-display-line-numbers-mode) ;; 行番号を表示。
(setq-default fill-column 120) ;; 1行の最大カラム。
;; バッファの空行を可視化。
(setq-default indicate-empty-lines t)
(setq-default indicate-buffer-boundaries t)
;; 対応するカッコ類を強調表示。
(setq show-paren-style 'parenthesis)
(setq show-paren-context-when-offscreen t)
;; 検索時のケース判定を無効化。
(setq case-fold-search t)
(setq isearch-case-fold-search nil)
(setq read-buffer-completion-ignore-case t)
(setq read-file-name-completion-ignore-case t)
;; 検索時のケース判定を有効化。
(setq case-replace t)
(setq-default dabbrev-case-replace nil)
;; GUIデコレーション表示設定
(tool-bar-mode 0)
(menu-bar-mode 0)
(scroll-bar-mode 0)
;; スタートアップ表示無効化。
(setq inhibit-startup-message t)
(setq inhibit-splash-screen t)
(setq initial-scratch-message nil)
;; 強制的に表示バッファを切り替えるレベルをerror以上に。デフォルトwarningでは頻繁にバッファが切り替わる。
(setq warning-minimum-level :error)
(setq split-width-threshold nil) ;; フレーム横サイズが大きい場合も、縦方向にウィンドウ分割。
;; undo history用バッファを増加。
(setq undo-limit 16777216) ; 16mb.
(setq undo-strong-limit 33554432) ; 32mb.
(setq undo-outer-limit 33554432) ; 32mb.
;; major-modeが判別できない場合の初期モードをlispからtextに変更。
(setq initial-major-mode 'text-mode)
(setq-default default-major-mode 'text-mode)
(global-hl-line-mode t) ;; 現在行を強調表示。
;; (defun my-hl-line-range-function ()
;; "行の最終文字以降に indicator を表示する。."
;; (cons
;; (line-end-position)
;; (line-beginning-position 2)))
;; (setq hl-line-range-function #'my-hl-line-range-function)
(size-indication-mode t) ;; mode-lineにファイルサイズを表示。
(setq grep-command "rg --no-heading -i ")
(global-auto-revert-mode) ;; emacs外でファイルが変更された際に、自動でバッファを更新。
(savehist-mode) ;; mini-bufferの履歴を保存。
;; emacs起動時に前回の作業状態を復元。
(setq desktop-path '("./" "~/.emacs.d/" "~"))
(desktop-save-mode)
;; eldoc を mini buffer に1行で表示する。
(setq eldoc-echo-area-use-multiline-p nil)
;; custom 設定を init.el とは別ファイルに保存。
(leaf cus-edit
:custom
`(custom-file . ,(locate-user-emacs-file "custom.el"))
:config
(load-file (expand-file-name custom-file)))
;; Mac Commandキーを SUPER から META に変更。
(when (eq system-type 'darwin)
(setq mac-command-modifier 'meta)
(setq mac-option-modifier 'super))
;;============================================================
;; key binding
;;============================================================
(unbind-key "C-x C-c")
(bind-key "C-x C-M-c" 'save-buffers-kill-terminal)
(bind-key "C-h" 'delete-backward-char)
(bind-key "M-k" 'kill-whole-line)
(bind-key "C-x C-y" 'duplicate-dwim)
;; use smartparens sp-delete-symbol.
;; (defun my-kill-thing-at-point (thing)
;; "Kill the `thing-at-point' for the specified kind of THING."
;; (let ((bounds (bounds-of-thing-at-point thing)))
;; (if bounds
;; (delete-region (car bounds) (cdr bounds))
;; (error "No %s at point" thing))))
;; (defun my-kill-word-at-point ()
;; "Kill the word at point."
;; (interactive)
;; (my-kill-thing-at-point 'word))
;; (bind-key "M-d" 'my-kill-word-at-point)
(bind-key "C-S-d" 'delete-horizontal-space)
(bind-key "M-r" 'query-replace)
(bind-key "C-M-i" 'indent-region)
(bind-key "M-q" 'quoted-insert)
(bind-key "C-M-/" 'undo-redo)
(bind-key "C-t" 'scroll-down)
(bind-key "M-a" 'beginning-of-buffer)
(bind-key "M-e" 'end-of-buffer)
(bind-key "C-M-v" 'scroll-other-window)
(bind-key "C-M-t" 'scroll-other-window-down)
(bind-key "C-x C-t" 'mark-whole-buffer)
(defun my-copy-whole-buffer-no-move ()
"Copy the whole buffer without changing cursor position."
(interactive)
(save-excursion
(copy-region-as-kill (point-min) (point-max)))
(message "Whole buffer coped."))
(bind-key "C-x C-a" 'my-copy-whole-buffer-no-move)
(bind-key "C-M-g" 'pop-to-mark-command)
(bind-key "C-z" 'execute-extended-command)
(defun my-newline-at-end-of-parens()
"Local func."
(interactive)
(newline)
(indent-for-tab-command)
(forward-line 0)
(open-line 1)
(indent-for-tab-command))
(bind-key "C-j" 'my-newline-at-end-of-parens)
(defun my-open-previous-line()
"Local func."
(interactive)
(beginning-of-line)
(open-line 1)
(indent-for-tab-command))
(bind-key "M-o" 'my-open-previous-line)
(defun my-newline-with-blankline()
"Local func."
(interactive)
(end-of-line)
(open-line 2)
(forward-line 2)
(indent-for-tab-command))
(bind-key "C-M-j" 'my-newline-with-blankline)
(bind-key "M-u" 'upcase-dwim)
(bind-key "M-l" 'downcase-dwim)
(bind-key "C-u" 'dabbrev-expand)
(bind-key "C-'" 'switch-to-buffer)
;; (bind-key "" 'switch-to-next-buffer)
(bind-key "C-;" 'other-window)
(bind-key "C-," 'split-window-vertically)
(bind-key "M-." 'delete-window)
(bind-key "C-." 'delete-other-windows)
(bind-key "M-/" 'shell)
(bind-key "C-x C-e" 'eval-region)
;; argument ショートカットである "C-[0-9]" を他コマンドに割り当てる
;; [0-9]argument の代替ショートカットとして、数値入力方式の argument を有効化する。
;; デフォルトでは、 "C--" にはマイナスの数値を入力する argument ショートカットが割り当てられている。
(bind-key "C--" 'universal-argument)
(bind-key "M-9" 'grep)
(bind-key "C-1" 'find-file)
(bind-key "C-2" 'save-buffer)
(bind-key "C-3" (lambda () (interactive) (kill-buffer (current-buffer))))
(defun my-kill-buffer-and-window ()
"Comment. `kill-window and `delete-window."
(interactive)
(kill-buffer (current-buffer))
(delete-window))
(bind-key "C-M-3" 'my-kill-buffer-and-window)
(bind-key "C-x C-n" 'rename-file)
(defun my-revert-file (&optional force-reverting)
"Revert file.
If FORCE-REVERTING is non nil, revert file regardless file is modified."
(interactive "p")
(if (or force-reverting (not (buffer-modified-p)))
(revert-buffer :ignore-auto :noconfirm)
(error "The buffer has been modified")))
(bind-key "C-x C-r" 'my-revert-file)
;; "c-x k ret" kill-buffer のミスタイプ回避
(unbind-key "C-x C-k RET")
(bind-key "C-h" 'isearch-delete-char isearch-mode-map)
(bind-key "C-x s" 'scratch-buffer)
(bind-key "C-S-f" 'forward-word)
(bind-key "C-S-b" 'backward-word)
(bind-key "C-S-a" 'beginning-of-buffer)
(bind-key "C-S-e" 'end-of-buffer)
(bind-key "C-M-=" 'quick-calc)
;;============================================================
;; theme
;;============================================================
(leaf doom-themes :ensure t)
(load-theme 'doom-bluloco-light)
(custom-set-faces '(default ((t (:foreground "dark slate gray" :background "floral white")))))
(custom-set-faces '(cursor ((t (:background "dodger blue")))))
(custom-set-faces '(region ((t (:background "light sky blue")))))
(custom-set-faces '(hl-line ((t (:background "azure")))))
;;============================================================
;; japanese settings
;;============================================================
(set-language-environment "Japanese")
(set-default-coding-systems 'utf-8-unix)
(when (eq system-type 'gnu/linux)
(if (/= (length (getenv "WSL_DISTRO_NAME")) 0) ; WSL
(leaf mozc
:ensure t
:custom
(default-input-method . "japanese-mozc")
:bind
("<XF86TouchpadOff>" . 'toggle-input-method)
)
)
)
;;============================================================
;; garbage collection
;;============================================================
;; Increase threshold to fire garbage collection
;; (setq gc-cons-threshold 536870912)
;; (setq garbage-collection-messages t)
;; Run GC every designated seconds if emacs is idle.
;; (run-with-idle-timer 5.0 t #'garbage-collect)
(leaf gcmh
:ensure t
:global-minor-mode t
:custom
(gcmh-low-cons-threshold . 104857600)
(gcmh-high-cons-threshold . 536870912)
(gcmh-idle-delay . 60))
;;============================================================
;; Windows shell mode.
;;============================================================
(when (eq system-type 'windows-nt)
;; use git bash
;; (setq shell-file-name "c:/Users/yashichi/scoop/apps/git/current/bin/bash.exe")
(setq shell-file-name "bash.exe"))
;;============================================================
;; packages
;;============================================================
(leaf avy
:ensure t
:custom
(avy-timeout-seconds . 0.2)
:bind
("C-r" . avy-goto-char-timer)
:custom-face
(avy-lead-face . '((t (:background "deeppink" :box nil))))
(avy-goto-char-timer-face . '((t (:background "deeppink" :box nil))))
)
(leaf easy-kill
:ensure t
:bind
("C-q" . easy-kill)
:custom-face
(easy-kill-selection . '((t (:background "light sky blue" :box nil)))))
;; (leaf smart-hungry-delete
;; :ensure t
;; :bind
;; ("" . smart-hungry-delete-forward-char)
;; ("" . smart-hungry-delete-backward-char))
(leaf fix-word
:ensure t
:bind
("M-u" . fix-word-upcase)
("M-l" . fix-word-downcase)
("M-c" . fix-word-capitalize))
(leaf string-inflection
:ensure t
:bind
("C-M-c" . string-inflection-all-cycle))
(leaf hideshow
:ensure t
:hook
(prog-mode-hook . hs-minor-mode)
:bind
("M-]" . hs-toggle-hiding))
;; (leaf beacon
;; :ensure t
;; :custom
;; (beabcon-color . 0.1)
;; (beacon-size . 10)
;; (beacon-blink-delay . 0.1)
;; (beacon-blink-duration . 0.1)
;; (beacon-blink-when-window-scrolls . nil)
;; :global-minor-mode t)
(leaf pulsar
:ensure t
:if (display-graphic-p)
:global-minor-mode pulsar-global-mode
:custom
(pulsar-face . 'pulsar-blue))
(leaf fill-column-indicator
:ensure t
:custom
(fci-always-use-textual-rule . t) ;; Windows では、indicator にグラフィックを使用すると height が変化する。
:hook
(prog-mode-hook . fci-mode))
;; (leaf ispell
;; :if (executable-find "aspell")
;; :ensure t
;; :config
;; (setq-default ispell-program-name "aspell")
;; (setq-default ispell-local-dictionary "en_US")
;; (add-to-list 'ispell-skip-region-alist '("[^\000-\377]+")))
;; (leaf flyspell
;; :if (executable-find "aspell")
;; :ensure t
;; :hook
;; ((yaml-mode-hook markdown-mode-hook git-commit-mode-hoook) . flyspell-mode)
;; (prog-mode-hook . flyspell-prog-mode)
;; :config
;; ((lambda ()
;; (dolist (key '("C-;" "C-," "C-."))
;; (unbind-key key flyspell-mode-map)))))
(leaf expand-region
:ensure t
:bind
("C-M-SPC" . 'er/expand-region))
(leaf recentf
:ensure t
:custom
(recentf-max-saved-items . 4096)
:global-minor-mode t)
(leaf which-key
:ensure t
:global-minor-mode t
:custom
(which-key-popup-type . 'side-window)
(which-key-side-window-location . 'bottom))
(leaf mwim
:ensure t
:bind
("C-a" . 'mwim-beginning)
("C-e" . 'mwim-end))
(leaf move-dup
:ensure t
:bind
("M-<up>" . 'move-dup-move-lines-up)
("M-<down>" . 'move-dup-move-lines-down))
(leaf whitespace
:hook
(after-init-hook . global-whitespace-mode)
:custom
((whitespace-line-column . 72)
(whitespace-style . '(face trailing empty missing-newline-at-eof))
(whitespace-display-mappings . '((space-mark ?\u3000 [?\□])
(tab-mark ?\t [?\u00BB ?\t] [?\\ ?\t])))
(whitespace-space-regexp . "\\(\u3000+\\)")
(whitespace-global-modes . '(not eww-mode
term-mode
eshell-mode
org-agenda-mode
calendar-mode)))
:custom-face
(whitespace-trailing . '((t (:background "tomato"))))
(whitespace-empty . '((t (:background "bisque")))))
(leaf highlight-indent-guides
:ensure t
:custom
(highlight-indent-guides-method . 'fill)
(highlight-indent-guides-character . 124) ;; '|'
(highlight-indent-guides-auto-even-face-perc . 4)
(highlight-indent-guides-auto-odd-face-perc . 8)
:hook
(prog-mode-hook . highlight-indent-guides-mode))
(leaf volatile-highlights
:ensure t
:global-minor-mode t
:custom-face
(vhl/default-face . '((t (:background "light sky blue")))))
(leaf rainbow-delimiters
:ensure t
:hook
(prog-mode-hook . rainbow-delimiters-mode))
(leaf smartparens
:ensure t
:init
(require 'smartparens-config)
:config
:hook
(prog-mode-hook . smartparens-mode)
:bind
("M-d" . 'sp-delete-symbol)
;; ("" . 'sp-splice-sexp)
;; ("" . 'sp-forward-sexp)
;; ("" . 'sp-backward-sexp)
)
;; (leaf elec-pair
;; :ensure t
;; :global-minor-mode electric-pair-mode
;; :config
;; ;; C-h -> DEL=BACKSPACEキーに変換。
;; ;; electric-pair-mode 内で BACKSPACEキーに直接 electric-pair-delete-char がマップされていて、その関数を呼び出すため。
;; (define-key key-translation-map (kbd "C-h") (kbd "<DEL>"))
;; )
(leaf comment-dwim-2
:ensure t
:bind
("M-;" . comment-dwim-2))
;; (leaf tab-bar
;; :ensure t
;; :global-minor-mode tab-bar-mode
;; :custom-face
;; (tab-bar-tab . '((t (:foreground "steel blue" :background "honeydew1" :weight bold :box "honeydew3"))))
;; (tab-bar-tab-inactive . '((t (:foreground "sky blue" :background "honeydew1" :weight bold :box nil))))
;; (tab-bar . '((t (:foreground "white" :background "honeydew1"))))
;; :bind
;; ("C-4" . tab-bar-switch-to-next-tab)
;; ("C-$" . tab-bar-switch-to-prev-tab)
;; ("M-4" . tab-bar-new-tab)
;; ("C-M-4" . tab-bar-close-tab))
(leaf posframe
:ensure t
:if (display-graphic-p)
:custom
(posframe-inhibit-double-buffering . t)
)
(leaf projectile
:ensure t
:config
(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)
:hook
(prog-mode-hook . projectile-mode))
(leaf magit
:ensure t)
(leaf git-timemachine
:ensure t
:bind
("C-x h" . git-timemachine-toggle))
(leaf git-gutter
:ensure t
:global-minor-mode global-git-gutter-mode)
(leaf mode-icons
:ensure t
:if (display-graphic-p)
:config
(mode-icons-mode))
;; required for doom-modeline.
;; run nerd-icons-install-fonts after installed once.
(leaf nerd-icons
:ensure t
:if (display-graphic-p))
(leaf doom-modeline
:ensure t
:global-minor-mode t
:custom
(doom-modeline-height . 20)
(doom-modeline-buffer-file-name-style . 'auto)
(doom-modeline-total-line-number . t)
(doom-modeline-icon . t)
(doom-modeline-major-mode-icon . t)
(doom-modeline-minor-mode . t)
(doom-modeline-minor-mode-icon . t)
:custom-face
(mode-line-active . '((t (:background "LightSteelBlue1" :box nil))))
(mode-line-inactive . '((t (:background "LightSteelBlue3" : box nil)))))
(leaf minions
:ensure t
:custom
;;(minions-mode-line-delimiters . nil)
;; (minions-mode-line-delimiters . '("" . ""))
;; (minions-mode-line-face . '((:inherit font-lock-comment-face :slant normal :foreground "yellow")))
;; (minions-mode-line-lighter . "")
:config
(minions-mode))
(leaf nyan-mode
:ensure t
:custom
(nyan-animate-nyancat . t)
:global-minor-mode t)
(leaf yasnippet
:ensure t
:global-minor-mode yas-global-mode
:config
(leaf yasnippet-snippets :ensure t))
(leaf vertico
:ensure t
:custom
(vertico-count . 20)
(vertico-cycle . t)
:bind
(:vertico-map
("TAB" . 'minibuffer-complete) ;; 一致文字列まで補完する、標準補完をTABで使う。
("M-TAB" . 'vertico-insert) ;; vertico のデフォルト補完 vertico-insert では、補完第一候補をすべて補完してしまう。
("C-v" . 'scroll-up-command)
("C-t" . 'scroll-down-command))
:global-minor-mode t
:config
(leaf vertico-posframe
:ensure t
:require posframe
:global-minor-mode t
:custom
(vertico-posframe-border-width . 1)
(vertico-posframe-poshandler . 'posframe-poshandler-window-bottom-right-corner)))
(leaf orderless
:ensure t
:custom
(completion-styles . '(substring orderless basic)))
(leaf marginalia
:ensure t
:hook
:global-minor-mode t)
(leaf migemo
:if (executable-find "cmigemo")
:ensure t
:config
(setq migemo-dictionary (cond ((eq system-type 'windows-nt) "/home/yashichi/.emacs.d/cmigemo/dict/utf-8/migemo-dict")
((eq system-type 'gnu/linux) "/usr/share/cmigemo/utf-8/migemo-dict")
((eq system-type 'darwin) "/opt/homebrew/opt/cmigemo/share/migemo/utf-8/migemo-dict")))
:custom
(migemo-command . "cmigemo")
(migemo-options . '("-q" "-e"))
(migemo-coding-system . 'utf-8-unix)
(migemo-use-default-isearch-keybinding . nil)
:hook
(emacs-startup-hook . migemo-init))
(leaf company
:ensure t
:custom
(company-idle-delay . 0.2)
(company-tooltip-idle-delay . 0.1)
(company-minimum-prefix-length . 2)
(company-show-numbers . t)
(company-selection-wrap-around . t)
(company-require-match . 'never)
(company-tooltip-width-grow-only . t)
(company-quick-access-modifier . 'control)
(company-show-quick-access . t)
(company-backends . `((company-capf)
(company-dabbrev
company-dabbrev-code
company-semantic
company-files)
(company-gtags company-etags company-keywords)))
:bind
(:company-active-map
("C-h" . 'delete-backward-char)
("RET" . 'newline)
("C-SPC" . 'company-complete-selection))
;; ("" . 'company-capf)
:hook
(prog-mode-hook . company-mode)
:config
;; (leaf company-posframe
;; :ensure t
;; :hook
;; (company-mode-hook . company-posframe-mode))
(leaf company-statistics
:ensure t
:global-minor-mode t)
(leaf company-dict
:ensure t
:config
(add-to-list 'company-backends #'company-dict t)))
(leaf dumb-jump
:ensure t
:hook
(xref-backend-functions . dumb-jump-xref-activate)
)
(leaf eldoc-box :ensure t)
(leaf flycheck
:ensure t
:hook
(prog-mode-hook . flycheck-mode)
:custom
(flycheck-display-errors-delay . 0.1)
(flycheck-checker-error-threshold . 4096)
:bind
("M-n" . 'flycheck-next-error)
("M-p" . 'flycheck-previous-error)
:config
(leaf flycheck-eglot
:ensure t
:hook
(eglot-managed-mode-hook . flycheck-eglot-mode)
:custom
;; eglot checker が有効の場合、eglot以外のchecker(flycheckにデフォルトでインストールされているcheckerを含む)
;; からの出力を flycheck の表示から除外する。
;; (flycheck-eglot-exclusive . nil)
;; (flycheck-eglot-enable-diagnostic-tags . nil)
)
;; (leaf flycheck-posframe
;; フォーカスに問題あり。ALT+TABで他のウィンドウ切り替えたあとに、emacsが再びフォーカスを取って全面に出てくる挙動あり。
;; :ensure t
;; :require posframe
;; :custom
;; (flycheck-posframe-position . 'window-top-right-corner)
;; (flycheck-posframe-border-width . 1)
;; (flycheck-posframe-border-use-error-face . t)
;; :hook
;; (flycheck-mode-hook . flycheck-posframe-mode))
;; (leaf flycheck-pos-tip
;; 他ウィンドウに切り替えてもポップアップが残り続ける。
;; :ensure t
;; :custom
;; (flycheck-pos-tip-timeout . 60)
;; :hook
;; (flycheck-mode-hook . flycheck-pos-tip-mode))
;; (leaf flycheck-inline
;; :ensure t
;; :hook
;; (flycheck-mode-hook . flycheck-inline-mode))
)
;; (leaf sideline
;; :ensure t
;; :hook
;; (flycheck-mode-hook . sideline-mode)
;; :custom
;; (sideline-delay . 0.1)
;; :config
;; (leaf sideline-flycheck
;; :ensure t
;; :hook
;; (flycheck-mode-hook . sideline-flycheck-setup)
;; :init
;; (setq sideline-backends-right '(sideline-flycheck))))
(leaf editorconfig
:ensure t
:config
(editorconfig-mode t))
(leaf google-translate
:ensure t
:custom
(google-translate-default-source-language . "en")
(google-translate-default-target-language . "ja")
:bind
("C-c t t" . 'google-translate-query-translate)
("C-c t r" . 'google-translate-query-translate-reverse))
(leaf google-this :ensure t)
(leaf consult
:ensure t
:custom
(consult-async-min-input . 1) ;; 入力がこの文字数を超えると補完開始(default:3)
:bind
;;("" . 'consult-history)
;;("" . 'consult-kmacro)
("C-'" . 'consult-buffer)
;;("" . 'consult-bookmark)
;;("" . 'consult-project-buffer)
("M-y" . 'consult-yank-from-kill-ring)
("M-g" . 'consult-goto-line)
;;("" . 'consult-mark)
;;("" . 'consult-global-mark)
;; ("" . 'consult-locate)
;; デフォルトではプロジェクトルートディレクトリを検索する。バッファカレントディレクトリ以下を検索するように変更。
("M-9" . (lambda () (interactive) (consult-find default-directory)))
;; ("" . 'consult-find)
;; デフォルトではプロジェクトルートディレクトリを検索する。バッファカレントディレクトリ以下を検索するように変更。
("C-9" . (lambda () (interactive) (consult-ripgrep default-directory)))
;; ("" . 'consult-ripgrep)
("C-0" . 'consult-line)
("M-0" . 'consult-line-multi)
("C-M-0" . 'consult-focus-lines)
("C-S-s" . 'consult-isearch-history)
("C-x C-h" . 'consult-recent-file)
:config
(add-to-list 'consult-buffer-filter
"\\`\\*.*\\'") ;; 先頭が "*" のバッファを除外する。
;; "\\`\\*Completions\\*\\'")
(leaf consult-company :ensure t)
(leaf consult-projectile
:ensure t
:require projectile
:bind ("M-1" . 'consult-projectile-find-file))
(leaf consult-flycheck
:ensure t
:require flycheck
:bind
("C-5" . 'consult-flycheck)
)
;; (leaf consult-flyspell
;; :ensure t
;; :bind
;; ("C-M-5" . 'consult-flyspell)
;; )
)
(leaf embark
:ensure t
:config
(leaf embark-consult :ensure t))
(leaf edit-list :ensure t)
(leaf treesit-auto
:ensure t
:global-minor-mode global-treesit-auto-mode
:config
(setq treesit-auto-install t))
;; (use-package treesit
;; :config
;; (setq treesit-font-lock-level 4))
(leaf treemacs
:ensure t
:bind
("C-x m" . 'treemacs)
:config
(leaf treemacs-nerd-icons :ensure t)
(leaf treemacs-projectile :ensure t)
(leaf treemacs-tab-bar :ensure t))
;;============================================================
;; eglot
;;============================================================
(leaf eglot
:ensure t
:custom
(eglot-connect-timeout . 120)
(eglot-report-progress . nil) ;; mini bufferへの eglot メッセージ出力量を抑制する。デフォルトではスパム状態。
(eglot-send-changes-idle-time . 0.5) ;; テキスト変更イベントをlspサーバーに送るまでのインターバル秒。
(eglot-sync-connect . nil)
(eglot-events-buffer-config . '(:size 0))
:bind
(:eglot-mode-map
("M-5" . 'eglot-code-actions)
("C-M-5" . 'eglot-rename)
("C-6" . 'eglot-format-buffer)
;; ("" . 'xref-go-forward)
;; ("" . 'xref-go-back)
("C-7" . 'xref-find-definitions)
("M-7" . 'xref-find-references)
;; ("" . 'eldoc)
;; ("" . 'eldoc-box-help-at-point)
("C-M-7" . 'consult-eglot-symbols)
("M-6" . 'delete-trailing-whitespace)
)
:config
(leaf consult-eglot
:ensure t
:require consult
:bind
("" . 'consult-eglot-symbols))
(setq read-process-output-max (* 16 1024 1024))
;; eglot初期化時にユーザー側で設定した company-backends を上書きする動作を無効化する。
;; (add-to-list 'eglot-stay-out-of 'company)
:hook
(eglot-managed-mode-hook . (lambda() (eglot-inlay-hints-mode -1)))
)
;;============================================================
;; Web
;;============================================================
(leaf web-mode
:ensure t
:custom
(web-mode-markup-indent-offset . 2)
(web-mode-css-indent-offset . 2)
(web-mode-code-indent-offset . 2)
(web-mode-block-padding . 0)
(web-mode-script-padding . 0)
(web-mode-style-padding . 0)
(web-mode-enable-auto-indentation . nil)
(web-mode-enable-current-element-highlight . t)
(web-mode-enable-auto-pairing . nil) ;; use smartparens for auto paring.
(web-mode-engines-alist .
'(("php" . "\\.phtml\\'")
("blade" . "\\.blade\\.'")
("django" . "\\.html\\'")
))
:mode
"\\.phtml\\'"
"\\.tpl\\.php\\'"
"\\.[gj]sp\\'"
"\\.erb\\'"
"\\.html?\\'"
"\\.css?\\'"
"\\.js[x]?\\'"
"\\.ts[x]?\\'"
:custom-face
(web-mode-current-element-highlight-face . '((t (:background "pale green"))))
;; :hook
;; (web-mode-hook . turn-off-smartparens-mode)
:config
(leaf company-web
:ensure t
:config
:hook
(web-mode-hook . (lambda ()
(add-to-list 'company-backends 'company-web-html))))
(leaf auto-rename-tag
:ensure t
:hook
(web-mode-hook . auto-rename-tag-mode))
(leaf rainbow-mode
:ensure t
:hook
(web-mode-hook . rainbow-mode))
;; editorconfig にて以下のインデント設定が上書きされてしまうので、さらに再設定。
(when (package-installed-p 'editorconfig)
(add-hook 'editorconfig-after-apply-functions
(lambda (props)
(setq web-mode-block-padding 0)
(setq web-mode-script-padding 0)
(setq web-mode-style-padding 0))
)))
(leaf css-mode
:custom
(css-indent-offset . 2))
;;============================================================
;; javascript, typescript
;;============================================================
;; (leaf js2-mode :ensure t
;; :custom
;; (js-indent-level . 2)
;; )
;; major-mode は web-modeを使用する。
;; (leaf typescript-mode
;; :ensure t
;; :init
;; (define-derived-mode typescript-tsx-mode typescript-mode "tsx")
;; :custom
;; (web-mode-markup-indent-offset . 2)
;; (web-mode-css-indent-offset . 2)
;; (web-mode-code-indent-offset . 2)
;; :config
;; (add-to-list 'auto-mode-alist '("\\.tsx?\\'" . typescript-tsx-mode))
;; )
(require 'eglot)
(define-derived-mode my-typescript-mode web-mode "ts"
"A typescript major mode derived from web-mode.")
(add-to-list 'auto-mode-alist '("\\.[cm]?ts[x]?\\'" . my-typescript-mode))
(add-to-list 'auto-mode-alist '("\\.[cm]?js[x]?\\'" . my-typescript-mode))
(add-hook 'my-typescript-mode-hook 'eglot-ensure)
(add-hook 'my-typescript-mode-hook (lambda () (add-hook 'before-save-hook 'eglot-format-buffer)))
(add-to-list 'eglot-server-programs '(my-typescript-mode "typescript-language-server" "--stdio"))
;; (add-hook 'my-typescript-mode-hook 'turn-on-smartparens-mode) ;; web-mode でoffにしたモードを on に。
;;============================================================
;; vue
;;============================================================
;; 派生モードの名前を 'vue-mode' 以外にすると、language server との通信がうまくいかない。
(define-derived-mode vue-mode web-mode "vue"
"A vue major mode derived from web-mode.")
(add-to-list 'auto-mode-alist '("\\.vue\\'" . vue-mode))
(defun vue-eglot-init-options ()
"Initialize vue eglot."
;; tsdk-path の設定。環境によって typescript/lib フォルダの取得方法を切り替える。
(let
;; npm global.
;; ((tsdk-path (expand-file-name
;; "lib"
;; (string-trim-right (shell-command-to-string "npm list --global --parseable typescript | head -n1")))))
;; volta.
;; ((tsdk-path
;; (if (equal system-type 'windows-nt)
;; (expand-file-name
;; "node_modules/typescript/lib"
;; (string-trim-right (shell-command-to-string "dirname `volta which tsc`")))
;; (expand-file-name
;; "lib/node_modules/typescript/lib"
;; (string-trim-right (shell-command-to-string "dirname `dirname \\`volta which tsc\\``"))))))
;; direct path.
((tsdk-path "/Users/yatomi/.volta/tools/image/packages/typescript/lib/node_modules/typescript/lib/"))
`(:typescript (:tsdk ,tsdk-path
:languageFeatures (:completion
(:defaultTagNameCase "both"
:defaultAttrNameCase "kebabCase"
:getDocumentNameCasesRequest nil
:getDocumentSelectionRequest nil)
:diagnostics
(:getDocumentVersionRequest nil))
:documentFeatures (:documentFormatting
(:defaultPrintWidth 100
:getDocumentPrintWidthRequest nil)
:documentSymbol t
:documentColor t)))))
(add-to-list 'eglot-server-programs `(vue-mode . ("vue-language-server" "--stdio" :initializationOptions ,(vue-eglot-init-options))))
(add-hook 'vue-mode-hook 'eglot-ensure)
(add-hook 'vue-mode-hook (lambda () (add-hook 'before-save-hook 'eglot-format-buffer)))
;;(add-hook 'vue-mode-hook (lambda () (company-mode 0))) ;; completion無効
;; ============================================================
;; java
;; ============================================================
(leaf eglot-java
:ensure t
:hook
((java-mode-hook java-ts-mode-hook) . eglot-java-mode))
;;============================================================
;; python
;; install 'pip install python-lsp-server[all]' manually.
;;============================================================
(leaf python-mode
:ensure t
:hook
((python-mode-hook python-ts-mode-hook) . eglot-ensure)
((python-mode-hook python-ts-mode-hook) . (lambda () (add-hook 'before-save-hook 'eglot-format-buffer))))
(leaf blacken :ensure t)
;;============================================================
;; dart
;;============================================================
(leaf dart-mode
:ensure t
:config
;; dart-mode によって t にセットされるが、自動インデントの挙動が直感的ではないので無効化する。
(setq electric-indent-inhibit nil)
;; (setq-default electric-indent-chars nil)
:bind
(:dart-mode-map
("TAB" . 'indent-according-to-mode) ;; 標準のtabキーにsmartではないindentコマンドが割り当てられている。
)
:hook
((dart-mode-hook dart-ts-mode-hook) . (lambda () (setq fill-column 120))) ;; dart.el にハードコーディングされている。
((dart-mode-hook dart-ts-mode-hook) . eglot-ensure)
)
;;============================================================
;; misc prog modes.
;;============================================================
(leaf json-mode
:ensure t
:custom
(js-indent-level . 2)
)
(leaf format-all :ensure t)
(leaf markdown-mode :ensure t)
(leaf yaml-mode :ensure t)
(leaf logview :ensure t)
;;; init.el ends here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment