Skip to content

Latest commit

 

History

History
1349 lines (1243 loc) · 39.8 KB

config.org

File metadata and controls

1349 lines (1243 loc) · 39.8 KB

Emacs Configuration

Configuration

Startup

Keep your ~/.emacs.d clean.

(when load-file-name
  (setq user-emacs-directory (file-name-directory load-file-name)))

Read flx.

(setq gc-cons-threshold 20000000)

Stop annoying things.

(when (display-graphic-p)
  (menu-bar-mode -1)
  (tool-bar-mode -1)
  (scroll-bar-mode -1)
  (horizontal-scroll-bar-mode -1)
  (tooltip-mode -1))

(setq initial-scratch-message nil
      initial-major-mode #'fundamental-mode
      inhibit-startup-screen t)

(blink-cursor-mode -1)

(defalias #'yes-or-no-p #'y-or-n-p)

Switch some keys by using yamy to avoid “Emacs Pinky”.

BeforeAfter
CapsLockCtrl_L
EnterCtrl_R(Enter)
Shift_LAlt_L
Shift_RAlt_R
SpaceShift_L(Space)
(keyboard-translate ?\C-h ?\C-?)
(keyboard-translate ?\C-z ?\C-h)

Read a character in hexadecimal by pressing C-q.

(setq read-quoted-char-radix 16)

Package Management

Package Repository

Add emacs-lisp package repositories.

(require 'package)
(setq package-enable-at-startup nil)
(setq package-archives
      '(("gnu" . "https://elpa.gnu.org/packages/")
        ("melpa" . "https://melpa.org/packages/")
        ("org" . "https://orgmode.org/elpa/")))
(package-initialize)

use-package

Read use-package.

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

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

paradox

(use-package paradox :ensure t :defer t)

File Management

Cache File

Store all temporary files in cache directory.

(defconst hyonhyoro|cache-dir
  (expand-file-name "cache/" user-emacs-directory))

(unless (file-exists-p hyonhyoro|cache-dir)
  (make-directory hyonhyoro|cache-dir))

Custom file.

(setq custom-file (expand-file-name "custom.el" hyonhyoro|cache-dir))
(load custom-file t)

Backup files. Create *~ files in cache/backup directory.

(setq make-backup-files t)
(setq version-control t)
(setq kept-new-vi 5
      kept-old-versions 0)
(setq backup-by-copying nil)
(setq delete-old-versions t)
(let ((backup-dir (expand-file-name "backup/" hyonhyoro|cache-dir)))
  (setq backup-directory-alist `((".*" . ,backup-dir))))

Auto-save files. Create #*# files in cache/auto-save directory.

(setq auto-save-default t)
(setq delete-auto-save-files t)
(setq auto-save-interval 150
      auto-save-timeout 15)

(let ((auto-save-dir (expand-file-name "auto-save/" hyonhyoro|cache-dir)))
  (setq auto-save-list-file-prefix (expand-file-name ".saves-" auto-save-dir))
  (setq auto-save-file-name-transforms
        `(("\\`/[^/]*:\\([^/]*/\\)*\\([^/]*\\)\\'" "/tmp/\\2" t)
          (".*" ,auto-save-dir t))))

Lock files. Stop creating .#* files.

(setq create-lockfiles nil)

Recentf file.

(eval-when-compile
  (require 'recentf))

(with-eval-after-load 'recentf
  (setq recentf-save-file (expand-file-name "recentf" hyonhyoro|cache-dir)
        recentf-max-menu-items 10
        recentf-max-saved-items 1000))

And its blacklist.

(with-eval-after-load 'recentf
  (setq recentf-exclude '("/recentf"
                          "COMMIT_EDITMSG"
                          "/.?TAGS"
                          "^/sudo:"
                          "/\\.emacs\\.d/elpa/.*"
                          "/\\.emacs\\.d/cache/.*"
                          "/usr/share/emacs/.*")))

Executable File

Store all executable files in bin directory.

(defconst hyonhyoro|bin-dir
  (expand-file-name "bin/" user-emacs-directory))

(unless (file-exists-p hyonhyoro|bin-dir)
  (make-directory hyonhyoro|bin-dir))

Save

(add-hook 'before-save-hook #'time-stamp)
(add-hook 'after-save-hook #'executable-make-buffer-file-executable-if-script-p)
(setq-default require-final-newline t)

Auto Revert

(global-auto-revert-mode 1)

Uniquify

Like config.org<snug> and config.org<.emacs.d>.

(setq uniquify-buffer-name-style 'post-forward-angle-brackets)

Ignore *scratch*, *Messages*, *Compile-Log*, *Help* and so on.

(setq uniquify-ignore-buffers-re "*[^*]+*")

Locale

(set-locale-environment nil)
(set-language-environment "Japanese")

(let ((coding-system 'utf-8))
  (setq locale-coding-system coding-system)
  (prefer-coding-system coding-system)
  (set-file-name-coding-system coding-system)
  (set-keyboard-coding-system coding-system)
  (set-terminal-coding-system coding-system)
  (set-selection-coding-system coding-system))

East Asian ambiguous width.

(defun set-east-asian-ambiguous-width (width)
  "Integrate some glyphs' width into WIDTH."
  (while (char-table-parent char-width-table)
    (setq char-width-table (char-table-parent char-width-table)))
  (let ((table (make-char-table nil)))
    (dolist (range
             '(#x00A1 #x00A4 (#x00A7 . #x00A8) #x00AA (#x00AD . #x00AE)
                      (#x00B0 . #x00B4) (#x00B6 . #x00BA) (#x00BC . #x00BF)
                      #x00C6 #x00D0 (#x00D7 . #x00D8) (#x00DE . #x00E1) #x00E6
                      (#x00E8 . #x00EA) (#x00EC . #x00ED) #x00F0
                      (#x00F2 . #x00F3) (#x00F7 . #x00FA) #x00FC #x00FE
                      #x0101 #x0111 #x0113 #x011B (#x0126 . #x0127) #x012B
                      (#x0131 . #x0133) #x0138 (#x013F . #x0142) #x0144
                      (#x0148 . #x014B) #x014D (#x0152 . #x0153)
                      (#x0166 . #x0167) #x016B #x01CE #x01D0 #x01D2 #x01D4
                      #x01D6 #x01D8 #x01DA #x01DC #x0251 #x0261 #x02C4 #x02C7
                      (#x02C9 . #x02CB) #x02CD #x02D0 (#x02D8 . #x02DB) #x02DD
                      #x02DF (#x0300 . #x036F) (#x0391 . #x03A9)
                      (#x03B1 . #x03C1) (#x03C3 . #x03C9) #x0401
                      (#x0410 . #x044F) #x0451 #x2010 (#x2013 . #x2016)
                      (#x2018 . #x2019) (#x201C . #x201D) (#x2020 . #x2022)
                      (#x2024 . #x2027) #x2030 (#x2032 . #x2033) #x2035 #x203B
                      #x203E #x2074 #x207F (#x2081 . #x2084) #x20AC #x2103
                      #x2105 #x2109 #x2113 #x2116 (#x2121 . #x2122) #x2126
                      #x212B (#x2153 . #x2154) (#x215B . #x215E)
                      (#x2160 . #x216B) (#x2170 . #x2179) (#x2190 . #x2199)
                      (#x21B8 . #x21B9) #x21D2 #x21D4 #x21E7 #x2200
                      (#x2202 . #x2203) (#x2207 . #x2208) #x220B #x220F #x2211
                      #x2215 #x221A (#x221D . #x2220) #x2223 #x2225
                      (#x2227 . #x222C) #x222E (#x2234 . #x2237)
                      (#x223C . #x223D) #x2248 #x224C #x2252 (#x2260 . #x2261)
                      (#x2264 . #x2267) (#x226A . #x226B) (#x226E . #x226F)
                      (#x2282 . #x2283) (#x2286 . #x2287) #x2295 #x2299 #x22A5
                      #x22BF #x2312 (#x2460 . #x24E9) (#x24EB . #x254B)
                      (#x2550 . #x2573) (#x2580 . #x258F) (#x2592 . #x2595)
                      (#x25A0 . #x25A1) (#x25A3 . #x25A9) (#x25B2 . #x25B3)
                      (#x25B6 . #x25B7) (#x25BC . #x25BD) (#x25C0 . #x25C1)
                      (#x25C6 . #x25C8) #x25CB (#x25CE . #x25D1)
                      (#x25E2 . #x25E5) #x25EF (#x2605 . #x2606) #x2609
                      (#x260E . #x260F) (#x2614 . #x2615) #x261C #x261E #x2640
                      #x2642 (#x2660 . #x2661) (#x2663 . #x2665)
                      (#x2667 . #x266A) (#x266C . #x266D) #x266F #x273D
                      (#x2776 . #x277F) (#xE000 . #xF8FF) (#xFE00 . #xFE0F)
                      #xFFFD))
      (set-char-table-range table range width))
    (optimize-char-table table)
    (set-char-table-parent table char-width-table)
    (setq char-width-table table)))

(set-east-asian-ambiguous-width 2)

Font

English and Japanese fonts.

(let* ((en-font "Hack")
       (jp-font "Migu 1M")
       (size 16)
       (fontset (format "fontset-%s" en-font)))
  (create-fontset-from-ascii-font
   (format "%s:size=%d:weight=normal:slant=normal" en-font size) nil en-font)
  (set-fontset-font fontset 'unicode jp-font nil 'append)
  (add-to-list 'default-frame-alist `(font . ,fontset))
  (add-to-list 'face-font-rescale-alist `(,(format ".*%s.*" jp-font) . 1.1)))

Window Arrangement

Mode Line

Display line number and column number in the mode line.

(line-number-mode 1)
(setq line-number-display-limit-width 10000)

(column-number-mode 1)

Display the date and time in the mode line.

(setq system-time-locale "C")
(setq display-time-format "%a %m/%d %H:%M")

(display-time-mode 1)

Theme

Zerodark Emacs theme.

(use-package zerodark-theme :ensure t :defer t
  :init
  (load-theme 'zerodark t)
  :config
  (zerodark-setup-modeline-format))

all-the-icons

(use-package all-the-icons :ensure t :defer t)

delight

(use-package delight :ensure t :defer t)

neotree

(use-package neotree :ensure t :after all-the-icons
  :bind
  ("C-x t" . neotree-toggle)
  :config
  (setq neo-theme
        (if (display-graphic-p)
            'icons
          'arrow)))

nlinum

(use-package nlinum :ensure t
  :hook (prog-mode . nlinum-mode)
  :config
  (setq nlinum-format "%4d "
        nlinum-highlight-current-line t))

Moving Around

Smooth Scroll

(setq auto-window-vscroll nil
      scroll-step 0
      scroll-margin 5
      scroll-conservatively most-positive-fixnum
      scroll-up-aggressively nil
      scroll-down-aggressively nil
      scroll-preserve-screen-position 'always)

avy

(use-package avy :ensure t
  :bind
  ("C-'" . avy-goto-subword-1)
  ("M-g g" . avy-goto-line))

avy-migemo

(use-package avy-migemo :ensure t :after migemo
  :commands avy-migemo-mode
  :config
  (avy-migemo-mode 1)
  (use-package avy-migemo-e.g.ivy :after ivy)
  (use-package avy-migemo-e.g.swiper :after swiper)
  (use-package avy-migemo-e.g.counsel :after counsel
    :bind
    ("C-x j" . counsel-rg-migemo)))

beacon

(use-package beacon :ensure t :delight
  :commands beacon-mode
  :init
  (beacon-mode 1)
  :config
  (setq beacon-push-mark 35))

dumb-jump

Jump to the definition.

(use-package dumb-jump :ensure t :after (hydra ivy)
  :commands (dumb-jump-go
             dumb-jump-go-other-window
             dumb-jump-go-prefer-external
             dumb-jump-go-prefer-external-other-window
             dumb-jump-go-prompt
             dumb-jump-quick-look
             dumb-jump-back)
  :bind
  ("C-c d" . hyonhyoro|hydra-dumb-jump/body)
  :config
  ;; Restrict the scope of searching.
  (setq dumb-jump-default-project "")
  (setq dumb-jump-selector 'ivy)
  (defhydra hyonhyoro|hydra-dumb-jump (:hint nil)
    "
    ^Go^      ^External^     ^Misc^
--------------------------------------
[_j_] Jump   [_e_] Jump   [_i_] Prompt
[_o_] Other  [_x_] Other  [_l_] Look
[_b_] Back   ^ ^          [_q_] Quit
"
    ("j" dumb-jump-go)
    ("o" dumb-jump-go-other-window)
    ("e" dumb-jump-go-prefer-external)
    ("x" dumb-jump-go-prefer-external-other-window)
    ("i" dumb-jump-go-prompt)
    ("l" dumb-jump-quick-look)
    ("b" dumb-jump-back)
    ("q" nil)))

eyebrowse

(use-package eyebrowse :ensure t :defer t
  :config
  (eyebrowse-mode 1))

win-switch

(use-package win-switch :ensure t
  :commands win-switch-set-keys
  :bind
  ("C-x o" . win-switch-dispatch)
  :config
  (setq win-switch-window-threshold 1
        win-switch-idle-time 1.2
        win-switch-provide-visual-feedback nil
        win-switch-other-window-first  t)
  (win-switch-set-keys '("h") 'left)
  (win-switch-set-keys '("j") 'down)
  (win-switch-set-keys '("k") 'up)
  (win-switch-set-keys '("l") 'right)
  (win-switch-set-keys '("o") 'next-window)
  (win-switch-set-keys '("p") 'previous-window)
  (win-switch-set-keys '("H") 'shrink-horizontally)
  (win-switch-set-keys '("J") 'shrink-vertically)
  (win-switch-set-keys '("K") 'enlarge-vertically)
  (win-switch-set-keys '("L") 'enlarge-horizontally)
  (win-switch-set-keys '("2") 'split-vertically)
  (win-switch-set-keys '("3") 'split-horizontally)
  (win-switch-set-keys '("q") 'exit))

Text Arrangement

Truncate Lines

Truncate lines in all buffers

(setq-default truncate-lines nil)

(when (fboundp 'delight)
  (delight '((visual-line-mode nil simple))))

(global-visual-line-mode 1)

Whitespace

(require 'whitespace)
(add-hook 'before-save-hook #'delete-trailing-whitespace)

(when (fboundp 'delight)
  (delight '((global-whitespace-mode nil whitespace))))

(setq whitespace-line-column 80)
(setq whitespace-style '(face trailing tabs spaces space-mark tab-mark))
(setq whitespace-space-regexp "\\(\u3000+\\)"
      whitespace-display-mappings '((space-mark ?\u3000 [?\u25a1] [?_ ?_])
                                    (tab-mark ?\t [?\u00bb ?\t] [?\\ ?\t])))
(set-face-attribute 'whitespace-trailing nil
                    :foreground "pale green"
                    :background 'unspecified
                    :underline t)
(set-face-attribute 'whitespace-tab nil
                    :foreground "sky blue"
                    :background 'unspecified
                    :underline t)
(set-face-attribute 'whitespace-space nil
                    :foreground "tomato"
                    :background 'unspecified
                    :underline nil)

(global-whitespace-mode 1)

rainbow-delimiters

The reason why doesn’t exist global-rainbow-delimiters-mode.

(use-package rainbow-delimiters :ensure t
  :hook (emacs-lisp-mode . rainbow-delimiters-mode))

volatile-highlights

(use-package volatile-highlights :ensure t :defer t
  :config
  (volatile-highlights-mode 1))

Text Manipulation

Delete Word

Don’t kill. Delete!

(defun hyonhyoro|delete-word (arg)
  "Delete characters forward until encountering the end of a word.
With ARG, do this that many times."
  (interactive "p")
  (if (use-region-p)
      (delete-region (region-beginning) (region-end))
    (delete-region (point)
                   (progn
                     (forward-word arg)
                     (point)))))

(defun hyonhyoro|backward-delete-word (arg)
  "Delete characters backward until encountering the end of a word.
With ARG, do this that many times."
  (interactive "p")
  (hyonhyoro|delete-word (- arg)))

(global-set-key (kbd "M-d") #'hyonhyoro|delete-word)
(global-set-key (kbd "M-h") #'hyonhyoro|backward-delete-word)

Overwrite the selected region.

(delete-selection-mode 1)

Open Line

Add two commands like vi’s o and O.

(defun hyonhyoro|open-next-line (arg)
  "Move to the next line and then open a new one.
See also `newline-and-indent'."
  (interactive "p")
  (end-of-line)
  (open-line arg)
  (forward-line 1)
  (indent-according-to-mode))

(defun hyonhyoro|open-previous-line (arg)
  "Open a new line before the current one.
See also `newline-and-indent'."
  (interactive "p")
  (beginning-of-line)
  (open-line arg)
  (indent-according-to-mode))

(global-set-key (kbd "C-o") #'hyonhyoro|open-next-line)
(global-set-key (kbd "M-o") #'hyonhyoro|open-previous-line)

aggressive-indent

(use-package aggressive-indent :ensure t :delight
  :hook (emacs-lisp-mode . aggressive-indent-mode))

anzu

(use-package anzu :ensure t
  :bind
  (("M-q" . anzu-query-replace)
   ("M-Q" . anzu-query-replace-regexp))
  :config
  (setq anzu-deactivate-region t
        anzu-search-threshold 1000)
  (setq anzu-use-migemo t))

comment-dwim-2

(use-package comment-dwim-2 :ensure t
  :bind
  ("M-;" . comment-dwim-2))

cua-mode

Start CUA rectangle mode by C-x SPC.

(cua-mode 1)

(setq cua-enable-cua-keys nil)

(let ((map cua-global-keymap))
  (define-key map (kbd "C-x SPC") #'cua-set-rectangle-mark)
  (define-key map (kbd "C-<return>") nil))

ediff

(use-package ediff
  :commands ediff-setup-windows-plain
  :config
  (setq ediff-window-setup-function #'ediff-setup-windows-plain
        ediff-split-window-function #'split-window-right))

expand-region

(use-package expand-region :ensure t
  :bind
  ("C-;" . er/expand-region))

move-text

(use-package move-text :ensure t
  :bind
  (("M-n" . move-text-down)
   ("M-p" . move-text-up)))

multiple-cursors

(use-package multiple-cursors :ensure t :after hydra
  :bind
  ("C-t" . hyonhyoro|hydra-multiple-cursors/body)
  :config
  (defhydra hyonhyoro|hydra-multiple-cursors (:hint nil)
    "
     ^Up^            ^Down^        ^Other^
----------------------------------------------
[_p_]   Next    [_n_]   Next    [_l_] Edit lines
[_P_]   Skip    [_N_]   Skip    [_a_] Mark all
[_M-p_] Unmark  [_M-n_] Unmark  [_r_] Mark by regexp
^ ^             ^ ^             [_q_] Quit
"
    ("n" mc/mark-next-like-this)
    ("p" mc/mark-previous-like-this)
    ("N" mc/skip-to-next-like-this)
    ("P" mc/skip-to-previous-like-this)
    ("M-n" mc/unmark-next-like-this)
    ("M-p" mc/unmark-previous-like-this)
    ("l" mc/edit-lines :exit t)
    ("a" mc/mark-all-like-this :exit t)
    ("r" mc/mark-all-in-region-regexp :exit t)
    ("q" nil)))

smartparens

Use sp-pair for global pair properties and sp-local-pair for local ones. Read Pair management and Premissions for details on adding pair rules.

(use-package smartparens :ensure t :delight
  :commands sp-local-pair
  :hook (((emacs-lisp-mode org-mode c-mode c++-mode rust-mode) . smartparens-mode)
         ((emacs-lisp-mode org-mode c-mode c++-mode rust-mode) . show-smartparens-mode))
  :bind
  (:map smartparens-mode-map
        ("C-M-f" . sp-forward-sexp)
        ("C-M-b" . sp-backward-sexp)
        ("C-M-d" . sp-down-sexp)
        ("C-M-a" . sp-backward-down-sexp)
        ("C-M-u" . sp-backward-up-sexp)
        ("C-M-e" . sp-up-sexp)
        ("C-S-d" . sp-beginning-of-sexp)
        ("C-S-a" . sp-end-of-sexp)
        ("C-M-n" . sp-next-sexp)
        ("C-M-p" . sp-previous-sexp)
        ("M-F" . sp-forward-symbol)
        ("M-B" . sp-backward-symbol)
        ("C-M-k" . sp-kill-sexp)
        ("M-k" . sp-backward-kill-sexp)
        ("C-k" . sp-kill-hybrid-sexp)
        ("C-M-w" . sp-copy-sexp)
        ("C-<right>" . sp-forward-slurp-sexp)
        ("C-<left>" . sp-forward-barf-sexp)
        ("C-M-<left>" . sp-backward-slurp-sexp)
        ("C-M-<right>" . sp-backward-barf-sexp)
        ("M-s" . sp-splice-sexp)
        ("C-M-<delete>" . sp-splice-sexp-killing-forward)
        ("C-M-<backspace>" . sp-splice-sexp-killing-backward)
        ("C-S-<backspace>" . sp-splice-sexp-killing-around)
        ("C-M-t" . sp-transpose-sexp)
        ("C-x C-t" . sp-transpose-hybrid-sexp)
        ("C-M-SPC" . sp-mark-sexp))
  :config
  (require 'smartparens-config)
  (electric-pair-mode -1)
  (show-paren-mode -1)
  (sp-with-modes '(c-mode c++-mode)
    (sp-local-pair "{" nil
                   :post-handlers '(("||\n[i]" "RET")))
    (sp-local-pair "/*" "*/"
                   :post-handlers '(("| " "SPC")
                                    ("* |[i]\n[i]" "RET"))))
  (sp-with-modes 'rust-mode
    (sp-local-pair "{" nil
                   :post-handlers '(("||\n[i]" "RET")))))

undo-tree

(use-package undo-tree :ensure t :delight
  :commands global-undo-tree-mode
  :init
  (global-undo-tree-mode 1))

wgrep

(use-package wgrep :ensure t :defer t)

zop-to-char

(use-package zop-to-char :ensure t
  :bind
  ("M-z" . zop-up-to-char))

Framework

hydra

(use-package hydra :ensure t :demand t
  :commands (hydra-default-pre
             hydra-keyboard-quit
             hydra--call-interactively-remap-maybe
             hydra-show-hint
             hydra-set-transient-map))

ivy

(use-package ivy :ensure t :after flx :delight
  :commands (ivy-mode
             ivy--format-function-generic
             ivy--add-face)
  :init
  (ivy-mode 1)
  :bind
  (("M-r" . ivy-resume)
   ("C-M-r" . ivy-resume)
   :map ivy-occur-grep-mode-map
   ("C-c C-e" . ivy-wgrep-change-to-wgrep-mode))
  :config
  (setq ivy-height 8
        ivy-count-format "(%d/%d) "
        ivy-use-virtual-buffers nil)
  (setq ivy-re-builders-alist
        '((ivy-switch-buffer . ivy--regex-plus)
          (swiper . ivy--regex-plus)
          (swiper-all . ivy--regex-plus)
          (counsel-find-file . ivy--regex-plus)
          (t . ivy--regex-fuzzy)))
  (defun hyonhyoro|ivy-format-function-arrow (cands)
    "Transform CANDS into a string for minibuffer."
    (ivy--format-function-generic
     (lambda (str)
       (concat "-> " (ivy--add-face str 'ivy-current-match)))
     (lambda (str)
       (concat "   " str))
     cands
     "\n"))
  (setq ivy-format-function #'hyonhyoro|ivy-format-function-arrow))

Completion

flx

Fuzzy matching engine. You should decrease frequency of garbage collection to speed up future matching. The author encourages you to keep gc-cons-threshold 20000000 or over.

(use-package flx :ensure t)

swiper

(use-package swiper :ensure t :after ivy
  :bind
  (("C-M-s" . swiper-all)
   :map swiper-map
   ("M-q" . swiper-query-replace)
   ("C-'" . swiper-avy)
   ("C-t" . swiper-mc)))

counsel

(use-package counsel :ensure t :after ivy
  :commands counsel-esh-history
  :init
  (setq enable-recursive-minibuffers t)
  (eval-when-compile
    (require 'eshell))
  (add-hook 'eshell-mode-hook
            #'(lambda ()
                (bind-key "M-r" #'counsel-esh-history eshell-mode-map)))
  :bind
  (("C-s" . counsel-grep-or-swiper)
   ("C-x C-f" . counsel-find-file)
   ("C-x C-b" . counsel-imenu)
   ("C-x C-r" . counsel-recentf)
   ("M-x" . counsel-M-x)
   ("M-y" . counsel-yank-pop)
   ("C-c j" . counsel-rg)
   ("C-c g f" . counsel-git)
   ("C-c g j" . counsel-git-grep)
   :map help-map
   ("b" . counsel-descbinds)
   ("f" . counsel-describe-function)
   ("v" . counsel-describe-variable)
   ("l" . counsel-find-library)
   ("i" . counsel-info-lookup-symbol)
   ("u" . counsel-unicode-char)
   :map read-expression-map
   ("C-r" . counsel-minibuffer-history)
   :map minibuffer-local-shell-command-map
   ("C-r" . counsel-minibuffer-history))
  :config
  (setq counsel-find-file-at-point t))

company

(use-package company :ensure t :delight
  :hook ((emacs-lisp-mode racer-mode) . company-mode)
  :bind
  (:map company-active-map
   ("C-s" . company-filter-candidates)
   ("C-n" . company-select-next)
   ("C-p" . company-select-previous)
   ("M-n" . nil)
   ("M-p" . nil)
   ("C-h" . nil)
   :map company-search-map
   ("C-n" . company-select-next)
   ("C-p" . company-select-previous))
  :config
  (setq company-idle-delay 0
        company-minimum-prefix-length 4
        company-selection-wrap-around t
        company-tooltip-limit 7
        company-tooltip-minimum 5
        company-tooltip-align-annotations t
        company-tooltip-flip-when-above t)
  (setq company-frontends '(company-pseudo-tooltip-unless-just-one-frontend-with-delay
                            company-preview-common-frontend
                            company-echo-metadata-frontend))
  (setq company-transformers '(company-sort-by-backend-importance
                               company-sort-by-occurrence)))

migemo

(use-package migemo :ensure t
  :if (executable-find "cmigemo")
  :commands migemo-init
  :config
  (setq migemo-command "cmigemo"
        migemo-options '("-q" "--emacs")
        migemo-dictionary "/usr/share/cmigemo/utf-8/migemo-dict"
        migemo-coding-system 'utf-8
        migemo-user-dictionary nil
        migemo-regex-dictionary nil)
  (migemo-init))

yasnippet

(use-package yasnippet :ensure t :delight yas-minor-mode
  :commands yas-global-mode
  :init
  (yas-global-mode 1)
  :bind
  (:map yas-minor-mode-map
        ("C-c s n" . yas-new-snippet)
        ("C-c s i" . yas-insert-snippet)
        ("C-c s v" . yas-visit-snippet-file))
  :config
  (setq yas-snippet-dirs
        (expand-file-name "snippets" user-emacs-directory)))

which-key

(use-package which-key :ensure t :delight
  :commands (which-key-mode which-key-setup-side-window-right-bottom)
  :init
  (which-key-mode 1)
  :config
  (which-key-setup-side-window-right-bottom)
  (setq which-key-idle-delay 0.8))

Checker

ispell

(use-package ispell :defer t
  :if (executable-find "aspell")
  :config
  (setq ispell-dictionary "english"
        ispell-program-name "aspell")
  (add-to-list 'ispell-skip-region-alist '("[^\000-\377]+")))

flyspell

Fix the conflict with er/expand-region.

(use-package flyspell :delight
  :hook ((org-mode markdown-mode) . flyspell-mode)
  :bind
  (:map flyspell-mode-map
        ("C-;" . nil)))

flycheck

(use-package flycheck :ensure t :after hydra
  :commands (flycheck-list-errors
             flycheck-next-error
             flycheck-previous-error
             flycheck-first-error
             flycheck-error-list-set-filter)
  :hook ((c-mode c++-mode python-mode rust-mode) . flycheck-mode)
  :bind
  (:map flycheck-mode-map
        ("C-c f" . hyonhyoro|hydra-flycheck/body))
  :config
  (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.2)))
  (defhydra hyonhyoro|hydra-flycheck
    (:pre
     (progn (setq hydra-hint-display-type 'lv) (flycheck-list-errors))
     :post
     (progn (setq hydra-hint-display-type nil) (quit-windows-on "*Flycheck errors*"))
     :hint nil)
    "
   ^Up^       ^Down^      ^Other^
------------------------------
[_p_] Next  [_n_] Next  [_f_] Filter
[_P_] End   [_N_] End   [_q_] Quit
"
    ("n" flycheck-next-error)
    ("p" flycheck-previous-error)
    ("N" (progn (goto-char (point-max)) (flycheck-previous-error)))
    ("P" flycheck-first-error)
    ("f" flycheck-error-list-set-filter)
    ("q" nil)))

Dired

dired

(use-package dired
  :bind
  (:map dired-mode-map
        ("r" . wdired-change-to-wdired-mode))
  :config
  (require 'dired-x)
  (setq dired-auto-revert-buffer t)
  (put 'dired-find-alternate-file 'disabled nil)
  (setq dired-dwim-target t)
  (setq dired-recursive-copies 'always
        dired-recursive-deletes 'top)
  (setq dired-listing-switches
        "-AFGhl --group-directories-first --time-style=long-iso")
  (require 'dired-aux)
  (require 'dired-async)
  (setq dired-compress-file-suffixes
        '(("\\.tar\\.bz2\\'" "" "tar xjf %i")
          ("\\.tar\\.gz\\'"  "" "tar xzf %i")
          ("\\.bz2\\'"       "" "bunzip2 %i")
          ("\\.gz\\'"        "" "gunzip %i")
          ("\\.xz\\'"        "" "unxz %i")
          ("\\.tar\\'"       "" "tar xf %i")
          ("\\.tbz2\\'"      "" "tar xjf %i")
          ("\\.tgz\\'"       "" "tar xzf %i")
          ("\\.zip\\'"       "" "unzip %i")
          ("\\.rar\\'"       "" "unrar x %i")
          ("\\.Z\\'"         "" "uncompress %i")
          ("\\.7z\\'"        "" "7z x %i"))))

dired-collapse

(use-package dired-collapse :ensure t :after dired
  :bind
  (:map dired-mode-map
        ("K" . dired-collapse-mode)))

dired-filter

(use-package dired-filter :ensure t :after dired)

dired-k

(use-package dired-k :ensure t :after dired
  :init
  (add-hook 'dired-initial-position-hook #'dired-k)
  (add-hook 'dired-after-readin-hook #'dired-k-no-revert)
  :bind
  (:map dired-mode-map
        ("g" . dired-k))
  :config
  (setq dired-k-human-readable t))

dired-narrow

(use-package dired-narrow :ensure t :after dired
  :bind
  (:map dired-mode-map
        ("C-s" . dired-narrow)))

dired-subtree

(use-package dired-subtree :ensure t :after dired
  :bind
  (:map dired-mode-map
        ("i" . dired-subtree-insert)
        (";" . dired-subtree-remove)))

Eshell

(eval-when-compile
  (require 'eshell))

(global-set-key (kbd "C-c m") #'eshell)

(with-eval-after-load 'eshell
  (setq eshell-glob-case-insensitive t
        eshell-error-if-no-glob nil))

(autoload #'eshell-smart-initialize "em-smart" nil t)
(add-hook 'eshell-mode-hook #'eshell-smart-initialize)

(eval-when-compile
  (require 'em-smart))

(with-eval-after-load 'em-smart
  (setq eshell-scroll-to-bottom-on-input nil
        eshell-where-to-jump 'begin
        eshell-review-quick-commands nil
        eshell-smart-space-goes-to-end t))

Git

magit

(use-package magit :ensure t :after ivy
  :bind
  (("C-c g s" . magit-status)
   ("C-c g b" . magit-blame-addition))
  :config
  (magit-auto-revert-mode -1)
  (setq magit-diff-refine-hunk 'all)
  (setq magit-completing-read-function 'ivy-completing-read))

git-gutter-fringe+

(use-package git-gutter-fringe+ :ensure t
  :if (display-graphic-p)
  :bind
  (("C-c g g" . git-gutter+-mode)
   :map git-gutter+-mode-map
   ("C-c g d" . git-gutter+-show-hunk-inline-at-point)))

gitconfig-mode

(use-package gitconfig-mode :ensure t :defer t)

gitignore-mode

(use-package gitignore-mode :ensure t :defer t)

IME

(use-package mozc :ensure t
  :commands mozc-session-sendkey
  :if (executable-find "mozc_emacs_helper.sh")
  :bind
  (("C-x j" . toggle-input-method)
   :map isearch-mode-map
   ("C-x j" . toggle-input-method))
  :config
  (setq mozc-helper-program-name "mozc_emacs_helper.sh")
  (advice-add 'mozc-session-execute-command
              :after #'(lambda (&rest args)
                         (when (eq (nth 0 args) 'CreateSession)
                           (mozc-session-sendkey '(Ctrl Space))))))

(use-package mozc-im :ensure t :after mozc
  :init
  (setq default-input-method "japanese-mozc-im")
  (make-variable-buffer-local 'mozc-im-mode)
  (add-hook 'mozc-im-activate-hook #'(lambda () (setq mozc-im-mode t)))
  (add-hook 'mozc-im-deactivate-hook #'(lambda () (setq mozc-im-mode nil))))

(use-package mozc-popup :ensure t :after mozc
  :config
  (setq mozc-candidate-style 'popup))

(use-package mozc-cursor-color :after mozc
  :load-path "site-lisp/"
  :config
  (setq mozc-cursor-color-alist
        '((read-only . "royal blue")
          (hiragana . "pink")
          (full-katakana . "green")
          (half-ascii . "gray")
          (full-ascii . "gold")
          (half-katakana . "thistle")))
  (advice-add 'mozc-cursor-color-update
              :around #'(lambda (orig-fun &rest args)
                          (let ((mozc-mode mozc-im-mode))
                            (apply orig-fun args)))))

Org

org-mode

(add-to-list 'auto-mode-alist '("\\.\\(org\\|org_archive\\)\\'" . org-mode))

(global-set-key (kbd "C-c l") #'org-store-link)
(global-set-key (kbd "C-c a") #'org-agenda)
(global-set-key (kbd "C-c b") #'org-switchb)
(global-set-key (kbd "C-c c") #'org-capture)

(setq org-directory "~/org"
      org-default-notes-file (expand-file-name "refile.org" org-directory)
      org-startup-folded t
      org-startup-indented t
      org-startup-truncated t
      org-ellipsis ""
      org-cycle-separator-lines 0
      org-blank-before-new-entry '((heading)
                                   (plain-list-item . auto))
      org-return-follows-link t)

Fix the conflict with avy-goto-subword-1.

(eval-when-compile
  (require 'org))

(with-eval-after-load 'org
  (define-key org-mode-map (kbd "C-'") nil))

Org-TODO.

(setq org-todo-keywords '((sequence "❢ TODO(t)" "☛ NEXT(n)" "|" "✔ DONE(d)")
                          (sequence "⚑ WAITING(w@/!)" "┅ INACTIVE(i@/!)" "|" "✘ CANCELED(c@/!)"))
      org-use-fast-todo-selection t
      org-treat-S-cursor-todo-selection-as-state-change nil
      org-enable-priority-commands nil)

Org-indent.

(when (fboundp 'delight)
  (delight '((org-indent-mode nil org-indent))))

Org-list.

(setq org-list-demote-modify-bullet '(("+" . "-")
                                      ("*" . "-")
                                      ("1." . "-")
                                      ("1)" . "a)")))

Org-agenda.

(setq org-agenda-files `(,org-directory))

Org-archive.

(setq org-archive-mark-done nil
      org-archive-location "%s_archive::* Archived Tasks")

Org-babel.

(setq org-src-window-setup 'current-window
      org-src-fontify-natively t
      org-src-tab-acts-natively t
      org-src-strip-leading-and-trailing-blank-lines t
      org-src-preserve-indentation nil
      org-edit-src-content-indentation 0)

org-bullets

(use-package org-bullets :ensure t
  :hook (org-mode . org-bullets-mode)
  :config
  (setq org-bullets-bullet-list '("" "" "" "")))

C/C++

c/c++-mode

(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))

(defconst hyonhyoro|c-style
  '((indent-tabs-mode . nil)
    (c-basic-offset . 4)
    (c-tab-always-indent . t)
    (c-comment-only-line-offset . 0)
    (comment-column . 40)
    ;; (c-echo-syntatic-information-p . t)
    (c-hanging-braces-alist . ((block-close . c-snug-do-while)
                               (statement-case-open after)
                               (substatement-open after)
                               ;; (brace-list-open after)
                               ;; (brace-list-close before after)
                               ))
    (c-hanging-colons-alist . ((case-label after)
                               (label after)
                               (access-label after)
                               (member-init-intro before)
                               (inher-intro)))
    (c-hanging-semi&comma-criteria . (c-semi&comma-inside-parenlist
                                      c-semi&comma-no-newlines-for-oneline-inliners
                                      c-semi&comma-no-newlines-before-nonblanks))
    (c-cleanup-list . (brace-else-brace
                       brace-elseif-brace
                       brace-catch-brace
                       empty-defun-braces
                       defun-close-semi
                       list-close-comma
                       scope-operator))
    (c-offset-alist . ((arglist-intro . ++)
                       (arglist-close . c-lineup-arglist)
                       (func-decl-cont . ++)
                       (inher-intro . ++)
                       (inline-open . 0)
                       (substatement-open . 0)
                       (innamespace . 0)))))

(autoload #'c-toggle-auto-newline "cc-mode" nil t)

(defun hyonhyoro|c-mode-init ()
  (c-add-style "hyonhyoro|c-style" hyonhyoro|c-style t)
  (c-toggle-auto-newline 1))

(dolist (hook '(c-mode-hook c++-mode-hook))
  (add-hook hook #'hyonhyoro|c-mode-init))

Emacs Lisp

(define-key emacs-lisp-mode-map (kbd "C-c k") #'checkdoc-minor-mode)

LaTeX

ox-latex

(eval-when-compile
  (require 'ox-latex))

(with-eval-after-load 'ox-latex
  (setq org-latex-default-class "bxjsarticle"
        org-latex-pdf-process
        '("latexmk -gg -pdfdvi %f"))
  (add-to-list 'org-latex-classes
               '("bxjsarticle"
                 "\\documentclass[autodetect-engine,dvipdfmx-if-dvi,11pt,a4paper,ja=standard]{bxjsarticle}
[NO-DEFAULT-PACKAGES]
\\usepackage{newtxtext,newtxmath}
\\usepackage{amsmath}
\\usepackage{ascmac}
\\usepackage{graphicx}
\\usepackage{hyperref}
\\ifdefined\\kanjiskip
  \\usepackage{pxjahyper}
  \\hypersetup{colorlinks=true}
\\else
  \\ifdefined\\XeTeXversion
    \\hypersetup{colorlinks=true}
  \\else
    \\ifdefined\\directlua
      \\hypersetup{pdfencoding=auto,colorlinks=true}
    \\else
      \\hypersetup{unicode,colorlinks=true}
    \\fi
  \\fi
\\fi"
                 ("\\section{%s}" . "\\section*{%s}")
                 ("\\subsection{%s}" . "\\subsection*{%s}")
                 ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
                 ("\\paragraph{%s}" . "\\paragraph*{%s}")
                 ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))
  (add-to-list 'org-latex-classes
               '("beamer"
                 "\\documentclass[dvipdfmx,11pt,presentation]{beamer}
[NO-DEFAULT-PACKAGES]
\\usepackage[T1]{fontenc}
\\usepackage{newtxtext,newtxmath}
\\usepackage{amsmath}
\\usepackage{ascmac}
\\usepackage{graphicx}
\\usepackage{hyperref}
\\usepackage{bxdpx-beamer}
\\usepackage{pxjahyper}
\\renewcommand{\\kanjifamilydefault}{\\gtdefault}"
                 ("\\section{%s}" . "\\section*{%s}")
                 ("\\subsection{%s}" . "\\subsection*{%S}")
                 ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))))

yatex

(use-package yatex :ensure t
  :mode ("\\.tex\\'" . yatex-mode)
  :init
  (setq YaTeX-inhibit-prefix-letter t)
  :config
  (setq YaTeX-kanji-code nil
        YaTeX-use-LaTeX2e t
        YaTeX-use-AMS-LaTeX t
        tex-command "latexmk -gg -pdfdvi"
        bibtex-command "latexmk -gg -pdfdvi"
        makeindex-command "latexmk -gg -pdfdvi"))

Markdown

markdown-mode

(use-package markdown-mode :ensure t
  :mode (("README\\.md\\'" . gfm-mode)
         ("\\.md\\'" . markdown-mode)
         ("\\.markdown\\'" . markdown-mode))
  :config
  (setq markdown-command "multimarkdown"))

Rust

rust-mode

(use-package rust-mode :ensure t :defer t
  :config
  (setq rust-format-on-save t))

racer

(use-package racer :ensure t
  :hook (rust-mode . racer-mode)
  :init
  (add-hook 'racer-mode-hook #'eldoc-mode))

flycheck-rust

(use-package flycheck-rust :ensure t :after (flycheck rust-mode)
  :commands flycheck-rust-setup
  :init
  (add-hook 'flycheck-mode-hook #'flycheck-rust-setup))

Footer