Configurations for GNU Emacs

Table of Contents

1 はじめに

1.1 基本情報

2 Initialize

2.1 leaf

  (when (or load-file-name byte-compile-current-file)
    (setq user-emacs-directory
           (file-name-directory (or load-file-name byte-compile-current-file))))))

   'package-archives '(("gnu" . "")
                       ("melpa" . "")
                       ("org" . "")))
  (unless (package-installed-p 'leaf)
    (package-install 'leaf))

  (leaf leaf-keywords
    :ensure t
    ;; optional packages if you want to use :hydra, :el-get, :blackout,,,
    (leaf hydra :ensure t)
    (leaf el-get :ensure t)
    ;; (leaf blackout :ensure t)

    ;; initialize leaf-keywords.el

2.2 utility

(leaf dash :ensure t)
(leaf dash-functional :ensure t)
(leaf s :ensure t)
(leaf f :ensure t)
(leaf ht :ensure t)
(leaf general :ensure t)

3 Basic

3.1 early-init

(if (version< emacs-version "27")
      (menu-bar-mode -1)
      (tool-bar-mode -1)
      (toggle-scroll-bar -1)))

3.2 スタートアップメッセージを非表示

(setq inhibit-startup-message t)

3.3 末尾のスペースを可視化する


(setq-default show-trailing-whitespace t)

    (mode '(comint-mode
  (add-hook (intern (concat (symbol-name mode) "-hook"))
            '(lambda () (setq show-trailing-whitespace nil))))

3.4 行番号を表示する

(global-linum-mode t)

3.5 自動生成ファイルを無効にする

(setq make-backup-files nil)
(setq auto-save-default nil)
(setq auto-save-list-file-prefix nil)
(setq create-lockfiles nil)

3.6 C-kで行削除

(setq kill-whole-line t)

3.7 カッコの中をハイライトする

(show-paren-mode t)
(setq-default show-paren-style 'mixed)

3.8 カッコが自動的に作られるようにする

(electric-pair-mode 1)

3.9 time locale

(setq system-time-locale "C")

3.10 Font

(set-fontset-font t 'japanese-jisx0208 "TakaoPGothic")
(add-to-list 'face-font-rescale-alist '(".*Takao P.*" . 0.85))

3.11 GC/Memory

;;; gcc
(setq gc-cons-threshold (* 128 1024 1024))
(setq garbage-collection-messages t)

;;; memory
(setq read-process-output-max (* 4 1024 1024))

3.12 indent

(setq-default indent-tabs-mode nil)

3.13 keybind

(keyboard-translate ?\C-h ?\C-?)

 "M-¥" (lambda () (interactive) (insert "\\"))
 "C-h" 'backward-delete-char
 "C-z" 'undo
 "C-?" 'help-command
 "C-m" 'set-mark-command
 "C-a" 'back-to-indentation
 "C-c i" 'find-function
 "C-x C-o" 'other-window
 "C-x C-k" nil
 "C-x C-c" nil)

3.14 ビープ音を消す

(setq ring-bell-function 'ignore)

3.15 デフォルトのpathをかえる

(setq default-directory "~/")
(setq command-line-default-directory "~/")

3.16 coding system

;; language and locale
(set-language-environment "Japanese")
(setq system-time-locale "C")

;; coding system
(set-default-coding-systems 'utf-8-unix)
(prefer-coding-system 'utf-8-unix)
(set-selection-coding-system 'utf-8-unix)

;; prefer-coding-system take effect equally to follows
(set-buffer-file-coding-system 'utf-8-unix)
(set-file-name-coding-system 'utf-8-unix)
(set-terminal-coding-system 'utf-8-unix)
(set-keyboard-coding-system 'utf-8-unix)
(setq locale-coding-system 'utf-8-unix)

3.17 global-auto-revert-mode

(global-auto-revert-mode t)

3.18 yes/no to y/n

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

3.19 killできないようにする

(with-current-buffer "*scratch*"
  (emacs-lock-mode 'kill))
(with-current-buffer "*Messages*"
  (emacs-lock-mode 'kill))

4 Major/Minor Mode

4.1 c++-mode

(leaf c++-mode
  :hook (c++-mode-hook . lsp))

4.2 c-mode

(leaf c-mode
  :hook (c-mode-hook . lsp))

4.3 clojure-mode

(leaf clojure-mode
  :ensure t
  :mode ("\\.clj$" "\\.cljs$"))

4.4 cmake-mode

(leaf cmake-mode
  :ensure t
  :mode ("\\.cmake$"))

4.5 coffee-mode

(leaf coffee-mode
  :ensure t
  :mode ("\\.coffee$"))

4.6 csharp-mode

(leaf csharp-mode
  :ensure t
  :mode ("\\.cs$"))

4.7 csv-mode

(leaf csv-mode :ensure t)

4.8 dart-mode

(leaf dart-mode
  :ensure t
  :after reformatter
  (dart-mode-hook . lsp)
   ("C-c C-o" . dart-format-buffer))
  (reformatter-define dart-format
    :program "dart"
    :args '("format")))

4.9 dhall-mode

(leaf dhall-mode
  :ensure t
  :mode ("\\dhall$"))

4.10 docker-compose-mode

(leaf docker-compose-mode
  :ensure t
  :mode ("\\docker-compose*"))

4.11 dockerfile-mode

(leaf dockerfile-mode
  :ensure t
  :mode ("Dockerfile\\'"))

4.12 emmet-mode

(leaf emmet-mode
  :ensure t
  :after web-mode
  :hook (web-mode-hook . emmet-mode)
  ;; :config
  ;; (define-key emmet-mode-keymap (kbd "C-j") nil)
  ;; (define-key emmet-mode-keymap (kbd "M-j") 'emmet-expand-line)

4.13 fish-mode

(leaf fish-mode
  :ensure t
  :mode ("\\.fish$")
  :defvar fish-enable-auto-indent
  (setq fish-enable-auto-indent t))

4.14 git-modes

(leaf git-modes
  :ensure t
  :mode ("\\.dockerignore$"))

4.15 glsl-mode

(leaf glsl-mode
  :ensure t
  :mode ("\\.vsh$" "\\.fsh$"))

4.16 go-mode

(leaf go-mode
  :ensure t
  :hook ((go-mode-hook . lsp)
         (before-save-hook . gofmt-before-save))
  :mode ("\\.go$")
  :custom (gofmt-command . "goimports"))

4.17 gradle-mode

(leaf gradle-mode
  :ensure t
  :mode (("\\.gradle$" . java-mode)))

4.18 graphql-mode

(leaf graphql-mode
  :ensure t)

4.19 haskell-mode

(leaf haskell-mode
  :ensure t
  :mode ("\\.hs$" "\\.cable$"))

4.20 js2-mode

(leaf js2-mode
  :ensure t
  (js2-strict-missing-semi-warning . nil)
  :mode ("\\.js$")
  :hook ((js2-mode-hook . js2-refactor-mode)
         (js2-mode-hook . lsp)))

4.21 json-mode

(leaf json-mode
  :ensure t
  :mode ("\\.json$"))

4.22 lisp-mode

(leaf lisp-mode
  :mode ("Cask" "\\.lemrc?$"))

4.23 markdown-mode

(leaf markdown-mode
  :ensure t
  :mode ("\\.md$" "\\.markdown$")
  :bind (:markdown-mode-map
         ("C-m" . nil)))

4.24 nginx-mode

(leaf nginx-mode
  :ensure t
  :mode ("/nginx/sites-\\(?:available\\|enabled\\)/"))

4.25 php-mode

(leaf php-mode
  :ensure t
  :hook (php-mode-hook . lsp)
  :mode ("\\.php$"))

4.26 phpt-mode

(leaf phpt-mode
  :ensure t
  :mode ("\\.phpt$"))

4.27 plantuml-mode

(leaf plantuml-mode
  :ensure t
  :mode ("\\.pu$"))

4.28 prisma-mode

(leaf prisma-mode
  :el-get (prisma-mode
           :url ""
           :features prisma-mode))

4.29 processing-mode

(leaf processing-mode
  :ensure t
  :mode ("\\.pde$")
  (with-eval-after-load 'processing-mode
    (setq-default processing-location "/opt/processing/processing-java")
    (setq-default processing-output-dir "/tmp")))

4.30 python-mode

(leaf python-mode
  :ensure t
  :mode ("\\.py$")
  :interpreter ("python"))

4.31 ruby-mode

(leaf ruby-mode
  :ensure t
  :mode ("\\.rb$" "Capfile" "Gemfile" "Schemafile" ".pryrc" "Fastfile" "Matchfile")
  ;; :hook ((ruby-mode-hook . lsp))
  (with-eval-after-load 'ruby-mode
    (setq-default ruby-insert-encoding-magic-comment nil)))

4.32 rust-mode

(leaf rust-mode
  :ensure t
  :mode ("\\.rs$"))

4.33 scala-mode

(leaf scala-mode
  :ensure t
  :mode ("\\.scala$"))

4.34 TODO scheme-mode

;; (setq-default gosh-program-name "/usr/local/bin/gosh -i")

;; (general-def inferior-scheme-mode-map
;;   "C-p" 'comint-previous-input
;;   "C-n" 'comint-next-input)

4.35 slim-mode

(leaf slim-mode
  :ensure t
  :mode ("\\.slim$"))

4.36 solidity-mode

(leaf solidity-mode
  :ensure t)

4.37 ssh-config-mode

(leaf ssh-config-mode
  :ensure t
  :mode ("/path-to-your-ssh/config\\$"))

4.38 sql-mode

(leaf sql
  :ensure t
  (sql-indent-offset . t))

4.39 swift-mode

(leaf swift-mode
  :ensure t)

4.40 terraform-mode

(leaf terraform-mode
  :ensure t)

4.41 toml-mode

(leaf toml-mode
  :ensure t
  :mode ("\\.toml$"))

4.42 typescript-mode

(leaf typescript-mode
  :ensure t
  (define-derived-mode typescript-tsx-mode typescript-mode "tsx")
  (add-to-list 'auto-mode-alist (cons (rx ".tsx" string-end) #'typescript-tsx-mode))
  ((typescript-mode-hook . lsp)
   (typescript-tsx-mode-hook . lsp))

4.43 vue-mode

(leaf vue-mode
  :ensure t
  :mode ("\\.vue$"))

4.44 vimrc-mode

(leaf vimrc-mode
  :ensure t
  :mode ("\\.vim\\(rc\\)?\\'")
  :hook (vimrc-mode-hook . lsp))

4.45 web-mode

(leaf web-mode
  :ensure t
  (web-mode-engines-alist . '(("blade" . "\\.blade\\.php\\.")))
  :mode ("\\.html?\\'" "\\.erb\\'" "\\.gsp\\'"))

4.46 yaml-mode

(leaf yaml-mode
  :ensure t
  :mode ("\\.ya?ml$" "phpstan.neon"))

5 Lisp

5.1 Basic

5.1.1 paredit

(leaf paredit
  :ensure t
  :commands enable-paredit-mode
  :hook ((emacs-lisp-mode-hook . enable-paredit-mode)
         (lisp-mode-hook . enable-paredit-mode)
         (lisp-interacton-mode-hook . enable-paredit-mode)
         (scheme-mode-hook . enable-paredit-mode)
         (slime-mode-hook . enable-paredit-mode))
  ("C-<right>" . paredit-forward-slurp-sexp)
  ("C-c f" . paredit-forward-slurp-sexp)
  ("C-<left>" . paredit-forward-barf-sexp)
  ("C-c b" . paredit-forward-barf-sexp)
  ("M-s" . paredit-split-sexp))

5.1.2 rainbow-delimiters

(leaf rainbow-delimiters
  :ensure t
  :hook (prog-mode-hook))

5.2 CommonLisp

5.2.1 HyperSpec

(with-eval-after-load 'hyperspec
  (general-define-key "C-c h" 'hyperspec-lookup)
  (defvar common-lisp-hyperspec-root "~/.roswell/HyperSpec/")
  (defvar common-lisp-hyperspec--reader-macros nil)
  (defvar common-lisp-hyperspec--format-characters nil)

  (defun common-lisp-hyperspec (symbol-name)
    (interactive (list (common-lisp-hyperspec-read-symbol-name)))
    (let ((name (common-lisp-hyperspec--strip-cl-package
                 (downcase symbol-name))))
      (cl-maplist (lambda (entry)
                    (eww-open-file (concat common-lisp-hyperspec-root "Body/"
                                           (car entry)))
                    (when (cdr entry)
                      (sleep-for 1.5)))
                  (or (common-lisp-hyperspec--find name)
                      (error "The symbol `%s' is not defined in Common Lisp"

  (defun common-lisp-hyperspec-lookup-reader-macro (macro)
      (let ((completion-ignore-case t))
        (completing-read "Look up reader-macro: "
                         common-lisp-hyperspec--reader-macros nil t
     (concat common-lisp-hyperspec-root "Body/"
             (gethash macro common-lisp-hyperspec--reader-macros))))

  (defun common-lisp-hyperspec-format (character-name)
    (interactive (list (common-lisp-hyperspec--read-format-character)))
    (cl-maplist (lambda (entry)
                  (eww-open-file (common-lisp-hyperspec-section (car entry))))
                (or (gethash character-name
                    (error "The symbol `%s' is not defined in Common Lisp"

  (defadvice common-lisp-hyperspec (around common-lisp-hyperspec-around activate)
    (let ((buf (current-buffer)))
      (switch-to-buffer buf)
      (pop-to-buffer "*eww*")))

  (defadvice common-lisp-hyperspec-lookup-reader-macro (around common-lisp-hyperspec-lookup-reader-macro-around activate)
    (let ((buf (current-buffer)))
      (switch-to-buffer buf)
      (pop-to-buffer "*eww*")))

  (defadvice common-lisp-hyperspec-format (around common-lisp-hyperspec-format activate)
    (let ((buf (current-buffer)))
      (switch-to-buffer buf)
      (pop-to-buffer "*eww*"))))

5.2.2 slime

(with-eval-after-load 'slime
  (load (expand-file-name "~/.roswell/helper.el"))
  (defvar slime-net-coding-system 'utf-8-unix))

5.2.3 takeokunn/slime-history

(defun takeokunn/slime-history ()
    "choice history: "
    (-distinct (read (f-read-text "~/.slime-history.eld"))))))

 :keymaps 'slime-repl-mode-map
 "C-c C-r" 'takeokunn/slime-history)

5.3 EmacsLisp

5.3.1 elisp-slime-nav

(leaf elisp-slime-nav :ensure t)

5.3.2 nameless

(leaf nameless
  :ensure t
  :hook (emacs-lisp-mode-hook))

5.3.3 takeokunn/ielm-history

(with-eval-after-load 'ielm
  (defun takeokunn/ielm-history ()
      "choice history: "
        (let ((history nil)
              (comint-input-ring nil))
          (dotimes (index (ring-length comint-input-ring))
            (push (ring-ref comint-input-ring index) history))

  (defun takeokunn/ielm-write-history-on-exit (process event)
    (let ((buf (process-buffer process)))
      (when (buffer-live-p buf)
        (with-current-buffer buf
          (insert (format "\nProcess %s %s" process event))))))

  (defun takeokunn/ielm-turn-on-history ()
    (let ((process (get-buffer-process (current-buffer))))
      (when process
        (defvar comint-input-ring nil)
        (defvar comint-input-ring-file-name (concat (file-remote-p default-directory) "~/.ielm-history"))
        (defvar comint-input-ring-size 100000)
        (defvar comint-input-ignoredups t)
        (add-hook 'kill-buffer-hook #'comint-write-input-ring)
         :keymaps 'ielm-map
         "C-c C-r" 'takeokunn/ielm-history)

        (set-process-sentinel process #'takeokunn/ielm-write-history-on-exit))))

  (add-hook 'ielm-mode-hook 'takeokunn/ielm-turn-on-history))

5.4 Clojure

5.4.1 cider

(leaf cider
  :ensure t)

6 Awesome Package

6.1 Theme

6.1.1 all-the-icons

(leaf all-the-icons
  :if window-system
  :ensure t)

6.1.2 all-the-icons-dired

(leaf all-the-icons-dired
  :if window-system
  :after (all-the-icons)
  :ensure t
  :hook (dired-mode-hook . all-the-icons-dired-mode))

6.1.3 all-the-icons-ivy

(leaf all-the-icons-ivy
  :if window-system
  :ensure t
  :after all-the-icons

6.1.4 dashboard

(leaf dashboard
  :ensure t
  (dashboard-after-initialize-hook . (lambda ()
                                       (with-current-buffer "*dashboard*"
                                         (emacs-lock-mode 'kill))))

6.1.5 doom-theme

(leaf doom-themes
  :ensure t
  :after neotree
  :custom-face ((doom-modeline-bar quote ((t (:background "#6272a4")))))
  (load-theme 'tango-dark t)

6.1.6 doom-modeline

(leaf doom-modeline
  :ensure t
  :hook (after-init-hook)
  :custom ((doom-modeline-buffer-file-name-style . 'truncate-with-project)
           (doom-modeline-icon . t)
           (doom-modeline-major-mode-icon . nil)
           (doom-modeline-minor-modes . nil))
  (line-number-mode 0)
  (column-number-mode 0))

6.1.7 hl-line

(leaf hl-line
  :ensure t
  (set-face-background 'hl-line "#444642")
  (set-face-attribute 'hl-line nil :inherit nil))

6.1.8 neotree

(leaf neotree
  :ensure t
  :after all-the-icons
  :custom (neo-theme quote nerd2)
  :setq-default ((neo-show-hidden-files . t)
  (defun takeokunn/neotree-toggle ()
    (let ((default-directory (locate-dominating-file default-directory ".git")))
  (if window-system
      (defun neo-buffer--insert-fold-symbol (name &optional file-name)
          (equal name 'open)
           (all-the-icons-icon-for-dir file-name "down")))
          (equal name 'close)
           (all-the-icons-icon-for-dir file-name "right")))
          (equal name 'leaf)
           (format "                    %s      "
                   (all-the-icons-icon-for-file file-name)))))))
  :bind ("C-q" . takeokunn/neotree-toggle))

6.1.9 nyan-mode

(leaf nyan-mode
  :ensure t
  :after doom-modeline
  :hook (doom-modeline-mode-hook)
  :custom ((nyan-cat-face-number . 4)
           (nyan-animate-nyancat . t)))

6.1.10 tab-mode

(leaf tab-bar-mode
  :after ivy
  (("C-x t n" . tab-next)
   ("C-x t b" . tab-bar-switch-to-tab))
  (tab-bar-mode 1)
  ;; ivy integration
  (defun advice-completing-read-to-ivy (orig-func &rest args)
     (let* ((recent-tabs (mapcar (lambda (tab)
                                   (alist-get 'name tab))
       (list (ivy-completing-read "Switch to tab by name (default recent): "
                                  recent-tabs nil nil nil nil recent-tabs))))
    (apply orig-func args))
  (advice-add #'tab-bar-switch-to-tab :around #'advice-completing-read-to-ivy))

6.2 Refactor

6.2.1 emr

(leaf emr
  :ensure t
  :bind ("M-RET" . emr-show-refactor-menu))

6.3 Completion

6.3.1 company

(leaf company
  :ensure t
  :defvar company-backends
  (add-to-list 'company-backends 'company-yasnippet)
   ("C-n" . company-select-next)
   ("C-p" . company-select-previous)))

6.3.2 company-box

(leaf company-box
  :ensure t
  :after company
  :hook (company-mode . company-box-mode))

6.3.3 company-dockerfile

(leaf company-dockerfile
  :el-get (company-dockerfile
           :url ""
           :features company-dockerfile)
  (push 'company-dockerfile company-backends))

6.3.4 company-glsl

(leaf company-glsl
  :ensure t
  :after company
  (add-to-list 'company-backends 'company-glsl))

6.3.5 company-go

(leaf company-go
  :ensure t
  :after (company go-mode)
  (push 'company-go company-backends))

6.3.6 company-php

(leaf company-php
  :ensure t
  :disabled t
  :after (company php-mode)
  (push 'company-ac-php-backend company-backends))

6.3.7 company-phpactor

(leaf company-phpactor
  :ensure t
  :disabled t
  :after (company phpactor))

6.3.8 company-slime

(leaf slime-company
  :ensure t
  :after (company slime)
  :custom ((slime-company-completion . 'fuzzy)
           (slime-company-after-completion . 'slime-company-just-one-space))
  :config (slime-setup '(slime-fancy slime-banner slime-company)))

6.3.9 company-c-headers

(leaf company-c-headers
  :ensure t
  :after company
  :defvar company-backends
  (push 'company-c-headers company-backends))

6.3.10 company-shell

(leaf company-shell
  :el-get (company-shell
           :url ""
           :features company-shell)
  (push 'company-shell company-backends)
  (push 'company-shell-env company-backends)
  (push 'company-fish-shell company-backends))

6.3.11 company-solidity

(leaf company-solidity
  :ensure t
  :disabled t
  :after company
  (add-to-list 'company-backends 'company-solidity))

6.3.12 company-terraform

(leaf company-terraform
  :ensure t
  :after company
  (add-to-list 'company-backends 'company-terraform))

6.4 Snippet

6.4.1 yasnippet


(leaf yasnippet
  :ensure t
  :init (yas-global-mode 1)
  (yas-snippet-dirs . '("~/.emacs.d/yasnippets")))

6.4.2 ivy-yasnippet

(leaf ivy-yasnippet
  :ensure t
  :after (yasnippet ivy)
  :bind (("C-c y" . ivy-yasnippet)
         ("C-c C-y" . ivy-yasnippet)))

6.5 LSP

6.5.1 lsp-mode

(leaf lsp-mode
  :ensure t
  :after company
  ((lsp-keymap-prefix . "C-c l")
   (lsp-prefer-capf . t))
  (push 'company-capf company-backends))

6.5.2 lsp-ui

(leaf lsp-ui
  :ensure t
  :after lsp
  :bind (("M-." . lsp-ui-peek-find-definitions)
         ("M-?" . lsp-ui-peek-find-implementation))
  :hook (lsp-mode-hook . lsp-ui)
  ((lsp-ui-doc-enable . t)
   (lsp-ui-doc-max-height . 15)
   (lsp-ui-sideline-enable . nil)
   (lsp-ui-imenu-enable . nil)
   (lsp-ui-sideline-enable . nil)))

6.5.3 lsp-dart

(leaf lsp-dart
  :ensure t
  :after lsp)

6.5.4 lsp-ivy

(leaf lsp-ivy
  :ensure t
  :after (lsp-mode counsel))

6.6 DAP

6.6.1 dap-mode

(leaf dap-mode
  :ensure t
  :after lsp-mode
   ("C-c d" . dap-breakpoint-toggle))
  ;; :hook (dap-stopped-hook . (lambda (arg) (call-interactively #'dap-hydra))
  (add-hook 'dap-stopped-hook
            (lambda (arg) (call-interactively #'dap-hydra)))
  (with-eval-after-load 'dap-mode
    (dap-mode 1)
    (dap-ui-mode 1)
    (dap-auto-configure-mode 1)
    (require 'dap-go)))

6.7 Git

6.7.1 magit

(leaf magit
  :ensure t
  :setq (magit-refresh-status-buffer . nil)
  :custom (magit-display-buffer-function . #'magit-display-buffer-fullframe-status-v1))

6.7.2 magit-forge

;; (leaf forge
;;   :disabled t
;;   :ensure t
;;   :after magit
;;   :setq
;;   (browse-url-browser-function . 'browse-url-default-browser))

6.7.3 git-gutter-fringe

(leaf git-gutter-fringe
  :disabled t
  :ensure t
  (global-git-gutter-mode 1))

6.8 Search

6.8.1 swiper

(leaf ivy
  :ensure t
  :custom (ivy-use-virtual-buffers . t)
  (ivy-mode 1)
  (ivy-configure 'counsel-M-x :sort-fn 'ivy--sort-by-length))

(leaf counsel
  :ensure t
    (defun takeokunn/counsel-rg ()
      (let ((symbol (thing-at-point 'symbol 'no-properties))
            (default-directory (locate-dominating-file default-directory ".git")))
        (counsel-rg symbol)))
    (defun takeokunn/counsel-fzf ()
      (let ((default-directory (locate-dominating-file default-directory ".git")))
  (("C-x m" . counsel-compile)
   ("C-c k" . takeokunn/counsel-rg)
   ("M-p" . takeokunn/counsel-fzf))
  (counsel-mode 1))

(leaf swiper
  :ensure t
    (defun takeokunn/swiper ()
      (let ((word (thing-at-point 'symbol 'no-properties)))
        (swiper word))))
  :bind (("C-o" . takeokunn/swiper)))

6.8.2 ivy-ghq

(leaf ivy-ghq
  :el-get (ivy-ghq
           :url ""
           :features ivy-ghq)
  (defun takeokunn/ivy-ghq-open-and-fzf ()
  :after counsel
  :custom ((ivy-ghq-short-list . t))
  :defun ivy-ghq-open takeokunn/ivy-ghq-open-and-fzf)

 "M-o" 'takeokunn/ivy-ghq-open-and-fzf)

6.8.3 ivy-rich

(leaf ivy-rich
  :ensure t
  :after counsel
  (ivy-rich-mode 1))

6.9 Shell

6.9.1 exec-path-from-shell

(leaf exec-path-from-shell
  :ensure t
  :defun (exec-path-from-shell-initialize)
  :hook ((after-init-hook . exec-path-from-shell-initialize))
  (exec-path-from-shell-variables . '("PATH"

6.10 Rust

6.10.1 racer

(leaf racer
  :ensure t
  :after rust-mode
  :hook (rust-mode-hook
         (racer-mode-hook . eldoc-mode)))

6.10.2 TODO rustic

;; (leaf rustic
;;   :ensure t
;;   :after (rust-mode))

6.11 Cpp

6.11.1 clang-format

(leaf clang-format
  :ensure t
  :hook (before-save-hook . (lambda ()
                              (when (member major-mode '(c-mode c++-mode))

6.11.2 inferior-cling

(leaf inferior-cling
  :el-get (inferior-cling
           :url ""
           :features cling))

6.12 C#

6.12.1 TODO omnisharp

;; (leaf omnisharp
;;   :ensure t
;;   :after company flycheck
;;   :hook (csharp-mode-hook . flycheck-mode)
;;   :config
;;   (add-to-list 'company-backends 'company-omnisharp))

6.13 JavaScript/TypeScript

6.13.1 js2-refactor

(leaf js2-refactor
  :ensure t
  :after typescript-mode js2-mode
  :hook (js2-mode-hook typescript-mode-hook))

6.13.2 tree-sitter

(leaf tree-sitter
  :ensure (t tree-sitter-langs)
  :after typescript-mode
  :require tree-sitter-langs
  :hook (typescript-tsx-mode-hook . tree-sitter-hl-mode)

  ;; for tsx
  (add-to-list 'tree-sitter-major-mode-language-alist '(typescript-tsx-mode . tsx))
  (tree-sitter-hl-add-patterns 'tsx
      ;; styled.div``
      function: (member_expression
                 object: (identifier)
                 (.eq? "styled"))
      arguments: ((template_string) @property.definition
                  (.offset! @property.definition 0 1 0 -1)))
      ;; styled(Component)``
      function: (call_expression
                 function: (identifier)
                 (.eq? "styled"))
      arguments: ((template_string) @property.definition
                  (.offset! @property.definition 0 1 0 -1)))]))

6.13.3 TODO styled-components

;; (leaf fence-edit
;;   ;; :ensure t
;;   :after (css-mode rx ov)
;;   :el-get (fence-edit
;;            :url ""
;;            :features fence-edit)
;;   :setq
;;   ((styled-component-start . (rx-to-string '(: (1+ (and (+ word) (0+ "\.") (0+ "(" (+ alpha) ")"))) "`" eol)))
;;    (styled-component-end . (rx-to-string '(: "`;" eol)))
;;    (styled-component-region . (rx-to-string '(: (minimal-match
;;                                                  (seq
;;                                                   (and (1+ (and (+ word) (0+ "\.") (0+ "(" (+ alpha) ")"))) "`")
;;                                                   (or "\n" "\r")
;;                                                   (0+ (+ any) (or "\n" "\r"))
;;                                                   (and "`;" eol))))))
;;    (fence-edit-blocks . `((,styled-component-start ,styled-component-end)))
;;    (fence-edit-default-mode . 'css-mode))
;;   :config
;;   (defun takeokunn/get-component ()
;;     "Get current buffer styled components."
;;     (interactive)
;;     (let (matches match beg end)
;;       (save-match-data
;;         (save-excursion
;;           (goto-char (point-min))
;;           (while (search-forward-regexp styled-component-region nil t 1)
;;             (setq match (match-string-no-properties 0))
;;             (setq beg (match-beginning 0))
;;             (setq end (match-end 0))
;;             (push (list beg end match) matches))))
;;       (reverse matches))))

6.14 Haskell

6.14.1 hindent

(leaf hindent
  :ensure t
  :after haskell-mode
  :hook (haskell-mode-hook))

6.15 Ruby

6.15.1 robe

(leaf robe
  :ensure t
  :after ruby-mode company
  :hook (ruby-mode-hook)
  (push 'company-robe company-backends))

6.15.2 rubocop

(leaf rubocop
  :ensure t
  :after ruby-mode
  :hook (ruby-mode-hook))

6.15.3 ruby-refactor

(leaf ruby-refactor
  :ensure t
  :hook ((ruby-mode-hook . ruby-refactor-mode-launch)))

6.15.4 inf-ruby

(leaf inf-ruby
  (defun takeokunn/irb-history ()
      "choose history: "
      (mapcar #'list (-distinct (s-lines (f-read-text "~/.irb_history")))))))
   ("C-c C-r" . takeokunn/irb-history)))

6.16 SQL

6.16.1 sql-indent

(leaf sql-indent
  :ensure t
  :after sql-mode
  :hook (sql-mode-hook . sqlind-minor-mode))

6.17 php

6.17.1 phpactor

(leaf phpactor
  :ensure t
  :disabled t
  :after (f php-mode smart-jump)
   ("M-." . phpactor-goto-definition)
   ("M-?" . phpactor-find-references))
  ((eldoc-documentation-function . 'phpactor-hover)
   (phpactor-history-size . 100000))

6.17.2 psysh

(leaf psysh
  :ensure t
  :after (php-mode))

6.18 Markdown

6.18.1 poly-markdown

(leaf poly-markdown
  :ensure t
  (add-to-list 'auto-mode-alist '("\\.md" . poly-markdown-mode)))

6.19 Fish

6.19.1 fish-repl

(leaf fish-repl
  :el-get (fish-repl.el
           :url ""))

6.20 File

6.20.1 recentf

(leaf recentf
  :ensure t
  :setq-default ((recentf-max-saved-items . 10000)
                 (recentf-auto-cleanup quote never)
                 (recentf-save-file . "~/.emacs.d/.recentf")
                 (recentf-exclude quote
  (recentf-mode 1))

6.20.2 open-junk-file

(leaf open-junk-file
  :ensure t
  ("C-x j" . open-junk-file)
  :custom (open-junk-file-format . `,(locate-user-emacs-file ".junk/%Y-%m%d-%H%M%S.")))

6.21 Check

6.21.1 flycheck

(leaf flycheck
  :ensure t
  :after ruby-mode
  :hook ((ruby-mode-hook . flycheck-mode)
         (org-mode-hook . flycheck-mode)))

6.21.2 flycheck-textlint

(leaf flycheck-textlint
  :after flycheck
  (flycheck-define-checker textlint
    "A linter for Markdown."
    :command ("textlint" "--format" "unix" source)
    ((warning line-start (file-name) ":" line ":" column ": "
              (id (one-or-more (not (any " "))))
              (message (one-or-more not-newline)
                       (zero-or-more "\n" (any " ") (one-or-more not-newline)))
    :modes (text-mode markdown-mode))
  (add-to-list 'flycheck-checkers 'textlint))

6.21.3 flycheck-solidity

(leaf solidity-flycheck
  :ensure t
  :after (solidity-mode flycheck)
  (solidity-mode-hook . flycheck-mode)
  (solidity-flycheck-solc-checker-active . t))

6.22 Cursor

6.22.1 smartrep/multiple-cursors

(leaf smartrep :ensure t)

(leaf multiple-cursors
  :ensure t
  :defun (smartrep-define-key . smartrep)
  :after smartrep
  (global-unset-key (kbd "C-t"))
  (smartrep-define-key global-map "C-t"
    '(("C-t" quote mc/mark-next-like-this)
      ("n" quote mc/mark-next-like-this)
      ("p" quote mc/mark-previous-like-this)
      ("m" quote mc/mark-more-like-this-extended)
      ("u" quote mc/unmark-next-like-this)
      ("U" quote mc/unmark-previous-like-this)
      ("s" quote mc/skip-to-next-like-this)
      ("S" quote mc/skip-to-previous-like-this)
      ("*" quote mc/mark-all-like-this)
      ("d" quote mc/mark-all-like-this-dwim)
      ("i" quote mc/insert-numbers)
      ("o" quote mc/sort-regions)
      ("O" quote mc/reverse-regions))))

6.22.2 smooth-scroll

(leaf smooth-scroll
  :ensure t
  :commands smooth-scroll-mode
  (smooth-scroll-mode 1))

6.23 Other

6.23.1 ace-window

(leaf ace-window
  :ensure t
  :custom ((aw-keys '(97 115 100 102 103 104 106 107 108)))
  :bind ("C-x C-q" . ace-window))

6.23.2 auto-save-buffers-enhanced

(leaf auto-save-buffers-enhanced
  :ensure t
  (auto-save-buffers-enhanced-interval . 10)
  (auto-save-buffers-enhanced t))

6.23.3 amx

(leaf amx :ensure t)

6.23.4 avy

(leaf avy
  :ensure t
  :bind (("C-:" . avy-goto-char-timer)))

(leaf avy-zap
  :ensure t
  :after avy
  :bind (("M-z" . avy-zap-up-to-char-dwim)))

6.23.5 define-word

(leaf define-word
  :ensure t
  (define-word-default-service . 'wordnik)
    '((wordnik . takeokunn/define-word--display-in-buffer)
      (openthesaurus . takeokunn/define-word--display-in-buffer)
      (webster . takeokunn/define-word--display-in-buffer)
      (weblio . takeokunn/define-word--display-in-buffer)))
  (defun takeokunn/define-word--display-in-buffer (definition)
    (let* ((buf-name "*DEFINE WORD*")
           (buffer (get-buffer-create buf-name))
      (with-current-buffer buffer
        (read-only-mode -1)
        (insert definition)
        (goto-char (point-min))
        (save-excursion (xml-parse-string))
        (read-only-mode 1)
        (buffer-face-set 'woman-buffer))
      (display-buffer buffer)))
  (defun takeokunn/define-word ()
    (if (use-region-p)
        (call-interactively #'define-word-at-point)
      (call-interactively #'define-word))))

6.23.6 ddskk

(leaf ddskk
  :ensure t
  ("C-x C-j" . skk-mode)
  (skk-byte-compile-init-file . t)
  (skk-isearch-mode-enable . 'always)
  (skk-preload . t)
  (default-input-method . "japanese-skk"))

6.23.7 editorconfig

(leaf editorconfig
  :ensure t
  (editorconfig-mode 1))

6.23.8 esup

(leaf esup :ensure t)

6.23.9 elfeed

(leaf elfeed
  :ensure t
  ("C-x w" . elfeed)
  :defvar elfeed-search-filter
  (elfeed-search-filter . "@3-days-ago +unread")
  (browse-url-browser-function . 'eww-browse-url))

(leaf elfeed-org
  :ensure t
  :after elfeed
  (rmh-elfeed-org-files . '("~/.emacs.d/"))

6.23.10 font-lock-studio

(leaf font-lock-studio :ensure t)

6.23.11 google-this

(leaf google-this
  :ensure t
  ("M-g" . google-this))

6.23.12 grugru

(leaf grugru
  :ensure t
  :disabled t
  ("C-;" . grugru)

6.23.13 goto-addr

(leaf goto-addr
  :ensure t
  :commands goto-address-prog-mode goto-address-mode
  :hook ((prog-mode-hook . goto-address-prog-mode)
         (text-mode-hook . goto-address-mode)))

6.23.14 helpful

(leaf helpful
  :ensure t
  :after counsel
  (("C-? f" . helpful-callable)
   ("C-? v" . helpful-variable)
   ("C-? k" . helpful-key)
   ("C-? C-d" . helpful-at-point)
   ("C-? F" . helpful-function)
   ("C-? C" . helpful-command))
  :custom ((counsel-describe-function-function function helpful-callable)
           (counsel-describe-variable-function function helpful-variable)))

6.23.15 htmlize

(leaf htmlize :ensure t)

6.23.16 keyfreq

(leaf keyfreq
  :ensure t
  (keyfreq-mode 1)
  (keyfreq-autosave-mode 1))

6.23.17 lorem ipsum

(leaf lorem-ipsum
  :ensure t
  (("C-c C-l s" . lorem-ipsum-insert-sentences)
   ("C-c C-l p" . lorem-ipsum-insert-paragraphs)
   ("C-c C-l l" . lorem-ipsum-insert-list)))

6.23.18 origami

(leaf origami
  :ensure t
  :hook (prog-mode-hook . origami-mode)
  :bind (("C-c C-t" . origami-recursively-toggle-node)
         ("C-c t" . origami-recursively-toggle-node))

6.23.19 popwin

(leaf popwin
  :ensure t
  (popwin-mode 1))

6.23.20 smartparens

(leaf smartparens :ensure t)

6.23.21 smart-jump

(leaf smart-jump
  :ensure t)

6.23.22 subword

(leaf subword
  (defun takeokunn/delete-forward-block ()
    (if (eobp)
        (message "End of buffer")
      (let* ((syntax-move-point
                (skip-syntax-forward (string (char-syntax (char-after))))
        (kill-region (point) (min syntax-move-point subword-move-point)))))
  :bind (("M-d" . takeokunn/delete-forward-block)))

6.23.23 undo

(leaf undo-tree
  :ensure t
  :config (global-undo-tree-mode))

6.23.24 uuid

(leaf uuid
  :ensure t
  :el-get (emacs-uuid
           :url ""
           :features uuid)
  (defun takeokunn/uuid ()
    (insert (uuid-string))))

6.23.25 which-key

(leaf which-key
  :ensure t
  :hook (after-init . which-key-mode))

6.23.26 whitespace

(leaf whitespace
  :ensure t
  ((whitespace-style '(face tabs tab-mark spaces space-mark))
   (whitespace-display-mappings '((space-mark ?\u3000 [?\u25a1])
                                  (tab-mark ?\t [?\xBB ?\t] [?\\ ?\t]))))
  (global-whitespace-mode 1))

6.23.27 wanderlust

(leaf wanderlust
  :ensure t
  ;; :setq
  ;; (ssl-certificate-verification-policy . 1)

6.23.28 xah-lookup

(leaf xah-lookup
  :ensure t
  :disabled t
  :after (eww define-word)
  (xah-lookup-browser-function . 'eww)
  (xah-lookup-dictionary-browser-function . 'eww)
  (xah-lookup-dictionary-list . [""])
  (put 'xah-lookup-google 'xah-lookup-browser-function 'eww)
  (put 'xah-lookup-wikipedia 'xah-lookup-url "")
  (put 'xah-lookup-wikipedia 'xah-lookup-browser-function 'eww))

7 Eshell

7.1 basic

(leaf eshell
  (with-eval-after-load 'eshell
    ;; function
    (defun eshell/ff (&rest args)
      (find-file (car args)))

    ;; config
    (defvar eshell-cmpl-ignore-case t)
    (defvar eshell-glob-include-dot-dot nil)
    (defvar eshell-ask-to-save-history (quote always))
    (defvar eshell-history-size 100000)
    (defvar eshell-hist-ignoredups t)

    ;; alias
    (defvar *shell-alias* '(("ll" "ls -la")
                            ("cdd" "cd ~/Desktop")))
    (defvar eshell-command-aliases-list (append *shell-alias*))))

7.2 aweshell

(leaf aweshell
  :after eshell
  (defun takeokunn/aweshell-setup ()
    (shell-command-to-string "ghq get"))

  (when (file-directory-p "~/.ghq/")
    (add-to-list 'load-path (expand-file-name "~/.ghq/"))
    (require 'esh-mode)
    (require 'aweshell)
    (with-eval-after-load 'aweshell
      (defun takeokunn/counsel-aweshell-history ()
        (insert (ivy-read "Aweshell history: " (aweshell-parse-shell-history))))

      (defvar eshell-mode-map nil)
      (defvar aweshell-auto-suggestion-p nil)
      (defvar eshell-highlight-prompt t)
      (setq eshell-prompt-function 'epe-theme-lambda)
      (add-hook 'eshell-mode-hook
                (lambda () (define-key eshell-mode-map (kbd "C-c C-r") 'takeokunn/counsel-aweshell-history))))))

7.3 eshell-z

(leaf eshell-z
  :ensure t
  :after eshell
  :bind ("C-c C-q" . eshell-z))

8 Org Mode

8.1 basic

(leaf org
  ((org-use-speed-commands . t)
   (org-agenda-todo-ignore-with-date . t)
   (org-directory . "~/org")
   (org-agenda-files . '("~/org/agenda"))
   (org-todo-keywords . '((sequence "TODO(t)" "TODAY" "WAIT(w)" "|" "DONE(d)")))
   (org-capture-templates . '(("t" "Todo" entry (file+datetree "~/org/")
                               "* %?")
                              ("m" "Memo" entry (file "~/org/")
                               "* %?"))))
  ((org-startup-folded . 'fold)
   (org-archive-location . `,(format "~/org/archive/"
                                     (format-time-string "%Y" (current-time)))))
  (org-link '(t (:foreground "#ebe087" :underline t)))
  (("C-c a" . org-agenda)
   ("C-c b" . counsel-bookmark)
   ("C-c c" . org-capture)
   (:org-mode-map ("C-m" . nil))))

8.2 org-journal

(leaf org-journal
  :ensure t
  (org-journal-dir . "~/org/journal")
  (org-journal-file-type . 'weekly)
  (org-journal-prefix-key . "C-c j"))

8.3 org-ql

(leaf org-ql
  :ensure t
  (org-agenda-custom-commands . `(("i" "Today's agenda"
                                   ((org-ql-block '(and (todo "TODAY"))
                                                  ((org-ql-block-header "TODAY's agenda"))))))))

8.4 org-babel

(leaf ob-core
  (org-confirm-babel-evaluate . nil))

(leaf ob-fish
  :el-get (ob-fish
           :url ""))

(leaf ob-go :ensure t)
(leaf ob-rust :ensure t)
(leaf ob-typescript :ensure t)

(leaf ob-babel
  :after (ob-fish
  (org-babel-do-load-languages 'org-babel-load-languages
                               '((shell . t)
                                 (emacs-lisp . t)
                                 (lisp . t)
                                 (ruby . t)
                                 (fish . t)
                                 (go . t)
                                 (rust . t)
                                 (typescript . t))))

8.5 org-superstar

(leaf org-superstar
  :ensure t
  :hook (org-mode-hook . org-superstar-mode)
  ((org-superstar-headline-bullets-list . '("◉" "○" "✸" "✿"))
   (org-superstar-leading-bullet . " ")))

8.6 org-generate

(leaf org-generate
  :ensure t
  (org-generate-file . `,(locate-user-emacs-file ""))
  (org-generate-root . "yasnippets"))

8.7 org-roam

(leaf org-roam
  :disabled t
  :ensure t
  :hook (after-init-hook . org-roam-mode)
  :custom ((org-roam-db-update-method . 'immediate)
           (org-roam-db-location . "~/org/roam/org-roam.db")
           (org-roam-directory . "~/org/roam")
           (org-roam-index-file . "~/org/roam/"))
  (org-roam-graph-viewer . #'eww-open-file)
  ((org-roam-v2-ack . nil))
  (("C-c n l" . org-roam)
   ("C-c n f" . org-roam-find-file)
   ("C-c n g" . org-roam-graph)
    (("C-c n i" . org-roam-insert)
     ("C-c n I" . org-roam-insert-immediate)))))

8.8 org-tree-slide

(leaf org-tree-slide
  :ensure t
  (("<f8>" . org-tree-slide-mode)
   ("S-<f8>" . org-tree-slide-skip-done-toggle)))

8.9 org-pomodoro

(leaf org-pomodoro
  :ensure t)

9 MyFunc

9.1 takeokun/beginning-of-intendation

(defun takeokunn/beginning-of-intendation ()
  "move to beginning of line, or indentation"

9.2 takeokunn/before-set-auto-mode

(defun takeokunn/before-set-auto-mode ()
  (when (or (and buffer-file-name
                 (> (or (file-attribute-size (file-attributes buffer-file-name)) 0) 1000000))
            (> (line-number-at-pos (point-max)) 100000))
    (prog1 t
;; (advice-add 'set-auto-mode :before-until 'takeokunn/before-set-auto-mode)

9.3 takeokunn/reload-major-mode

(defun takeokunn/reload-major-mode ()
  "Reload current major mode."
  (let ((current-mode major-mode))
    (funcall current-mode)

9.4 takeokunn/move-line

(defun takeokunn/move-line (arg)
  (let ((col (current-column)))
    (unless (eq col 0)
      (move-to-column 0))
      (transpose-lines arg))
    (forward-line arg)))

(defun takeokunn/move-line-down ()
  (takeokunn/move-line 1))

(defun takeokunn/move-line-up ()
  (takeokunn/move-line -1))

 "M-N" 'takeokunn/move-line-down
 "M-P" 'takeokunn/move-line-up)

9.5 takeokunn/toggle-read-only-mode

(defun takeokunn/toggle-read-only-mode ()

 "C-x C-q" 'takeokunn/toggle-read-only-mode)

9.6 takeokunn/ghq-get

(defun takeokunn/ghq-get ()
  (let ((url (read-string "url > ")))
      (mapconcat #'shell-quote-argument
                 (list "ghq" "get" url)
                 " ")))))

(defalias 'ghq-get 'takeokunn/ghq-get)

Author: takeokunn

Created: 2022-01-27 Thu 14:42