Configurations for GNU Emacs

Table of Contents

1 はじめに

1.1 基本情報

2 Initialize

2.1 leaf

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

(eval-and-compile
  (customize-set-variable
   'package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
                       ("melpa" . "https://melpa.org/packages/")
                       ("org" . "https://orgmode.org/elpa/")))
  (package-initialize)
  (unless (package-installed-p 'leaf)
    (package-refresh-contents)
    (package-install 'leaf))

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

    :config
    ;; initialize leaf-keywords.el
    (leaf-keywords-init)))

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")
    (progn
      (menu-bar-mode -1)
      (tool-bar-mode -1)
      (toggle-scroll-bar -1)))

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

(setq inhibit-startup-message t)

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

特定のmode以外末尾のスペースを可視化するようにした。

(setq-default show-trailing-whitespace t)

(dolist
    (mode '(comint-mode
            eshell-mode
            eww-mode
            term-mode
            twittering-mode
            minibuffer-inactive-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-?)

(general-define-key
 "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)

3.14 ビープ音を消す

(setq ring-bell-function 'ignore)

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

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

3.16 coding system

(set-coding-system-priority 'utf-8)
(set-terminal-coding-system 'utf-8-unix)
(set-keyboard-coding-system 'utf-8-unix)
(setq-default buffer-file-coding-system 'utf-8-unix)
(setq-default default-process-coding-system '(utf-8 . utf-8))

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)

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 dhall-mode

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

4.9 docker-compose-mode

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

4.10 dockerfile-mode

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

4.11 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.12 fish-mode

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

4.13 gitignore-mode

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

4.14 glsl-mode

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

4.15 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.16 gradle-mode

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

4.17 haskell-mode

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

4.18 js2-mode

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

4.19 json-mode

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

4.20 lisp-mode

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

4.21 markdown-mode

(leaf markdown-mode
  :ensure t
  :mode ("\\.md$" "\\.markdown$")
  :bind (("C-j" . electric-newline-and-maybe-indent)))

4.22 mmm-mode

(leaf mmm-mode
  :ensure t
  :after (emmet-mode typescript-mode)
  :hook (mmm-mode-hook . emmet-mode)
  :setq
  (mmm-global-mode . 'maybe)
  (mmm-submode-decoration-level . 0)
  :hook (after-save-hook . (lambda ()
                             (when (string-match-p "\\.tsx?" buffer-file-name)
                               (mmm-mode-off)
                               (mmm-mode-on))))
  :config
  (require 'mmm-mode)
  (mmm-add-classes
   '((tsx-embed-web-mode
      :submode web-mode
      :front "\\(return\s\\|n\s\\|(\n\s*\\)<"
      :front-offset -1
      :back ">\n?\s*)\n}\n"
      :back-offset 1)))
  (mmm-add-mode-ext-class 'typescript-mode nil 'tsx-embed-web-mode))

4.23 nginx-mode

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

4.24 php-mode

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

4.25 plantuml-mode

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

4.26 processing-mode

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

4.27 python-mode

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

4.28 ruby-mode

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

4.29 rust-mode

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

4.30 scala-mode

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

4.31 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.32 slim-mode

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

4.33 ssh-config-mode

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

4.34 sql-mode

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

4.35 swift-mode

(leaf swift-mode
  :ensure t)

4.36 terraform-mode

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

4.37 toml-mode

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

4.38 typescript-mode

(leaf typescript-mode
  :ensure t
  :mode ("\\.ts$" "\\.tsx$")
  :hook
  (typescript-mode-hook . lsp))

4.39 vue-mode

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

4.40 vimrc-mode

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

4.41 web-mode

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

4.42 yaml-mode

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

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))
  :bind
  ("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))

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"
                             symbol-name)))))

  (defun common-lisp-hyperspec-lookup-reader-macro (macro)
    (interactive
     (list
      (let ((completion-ignore-case t))
        (completing-read "Look up reader-macro: "
                         common-lisp-hyperspec--reader-macros nil t
                         (common-lisp-hyperspec-reader-macro-at-point)))))
    (eww-open-file
     (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
                             common-lisp-hyperspec--format-characters)
                    (error "The symbol `%s' is not defined in Common Lisp"
                           character-name))))

  (defadvice common-lisp-hyperspec (around common-lisp-hyperspec-around activate)
    (let ((buf (current-buffer)))
      ad-do-it
      (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)))
      ad-do-it
      (switch-to-buffer buf)
      (pop-to-buffer "*eww*")))

  (defadvice common-lisp-hyperspec-format (around common-lisp-hyperspec-format activate)
    (let ((buf (current-buffer)))
      ad-do-it
      (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 ()
  (interactive)
  (insert
   (completing-read
    "choice history: "
    (-distinct (read (f-read-text "~/.slime-history.eld"))))))

(general-define-key
 :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 ()
    (interactive)
    (insert
     (completing-read
      "choice history: "
      (progn
        (let ((history nil)
              (comint-input-ring nil))
          (dotimes (index (ring-length comint-input-ring))
            (push (ring-ref comint-input-ring index) history))
          history)))))

  (defun takeokunn/ielm-write-history-on-exit (process event)
    (interactive)
    (comint-write-input-ring)
    (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)
        (comint-read-input-ring)
        (add-hook 'kill-buffer-hook #'comint-write-input-ring)
        (general-define-key
         :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
  :ensure t)

6.1.2 all-the-icons-dired

(leaf all-the-icons-dired
  :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
  :ensure t
  :after all-the-icons
  :config
  (all-the-icons-ivy-setup))

6.1.4 dashboard

(leaf dashboard
  :ensure t
  :config
  (dashboard-setup-startup-hook))

6.1.5 doom-theme

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

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))
  :config
  (line-number-mode 0)
  (column-number-mode 0))

6.1.7 hl-line

(leaf hl-line
  :ensure t
  :init
  (global-hl-line-mode)
  :config
  (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)
                 (neo-window-fixed-size))
  :config
  (defun takeokunn/neotree-toggle ()
    (interactive)
    (let ((default-directory (locate-dominating-file default-directory ".git")))
      (neotree-toggle)))
  (defun neo-buffer--insert-fold-symbol (name &optional file-name)
    (or
     (and
      (equal name 'open)
      (insert
       (all-the-icons-icon-for-dir file-name "down")))
     (and
      (equal name 'close)
      (insert
       (all-the-icons-icon-for-dir file-name "right")))
     (and
      (equal name 'leaf)
      (insert
       (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.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
  :init
  (global-company-mode)
  :config
  (add-to-list 'company-backends 'company-yasnippet)
  :bind
  (:company-active-map
   ("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-glsl

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

6.3.4 company-go

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

6.3.5 company-php

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

6.3.6 company-phpactor

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

6.3.7 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.8 company-c-headers

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

6.4 Snippet

6.4.1 yasnippet

snippetはこちら [https://takeokunn.github.io/.emacs.d/yasnippets.html](https://takeokunn.github.io/.emacs.d/yasnippets.html)

(leaf yasnippet
  :ensure t
  :init (yas-global-mode 1)
  :custom
  (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)
  :custom (lsp-prefer-capf . t)
  :config
  (push 'company-capf company-backends))

6.5.2 lsp-ivy

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

6.5.3 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)
  :setq-default
  ((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.6 DAP

6.6.1 dap-mode

(leaf dap-mode
  :ensure t
  :after lsp-mode
  :bind
  (:dap-mode-map
   ("C-c d" . dap-breakpoint-toggle))
  ;; :hook (dap-stopped-hook . (lambda (arg) (call-interactively #'dap-hydra))
  :config
  (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
  :custom (magit-display-buffer-function . #'magit-display-buffer-fullframe-status-v1))

6.7.2 magit-forge

(leaf forge
  :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
  :config
  (global-git-gutter-mode 1))

6.8 Search

6.8.1 swiper

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

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

(leaf swiper
  :ensure t
  :init
  (eval-and-compile
    (defun takeokunn/swiper ()
      (interactive)
      (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 "https://github.com/analyticd/ivy-ghq.git"
           :features ivy-ghq)
  :preface
  (defun takeokunn/ivy-ghq-open-and-fzf ()
    (interactive)
    (ivy-ghq-open)
    (counsel-fzf))
  :after counsel
  :custom ((ivy-ghq-short-list . t))
  :defun ivy-ghq-open takeokunn/ivy-ghq-open-and-fzf)

(general-define-key
 "M-o" 'takeokunn/ivy-ghq-open-and-fzf)

6.8.3 ivy-rich

(leaf ivy-rich
  :ensure t
  :after counsel
  :config
  (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))
  :custom
  (exec-path-from-shell-variables . '("PATH"
                                      "GEM_HOME"
                                      "GOROOT"
                                      "GOPATH")))

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))
                                (clang-format-buffer)))))

6.11.2 inferior-cling

(leaf inferior-cling
  :el-get (inferior-cling
           :url "https://github.com/brianqq/inferior-cling.git"
           :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

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 tide

(leaf tide
  :ensure t
  :config
  (eval-and-compile
    (defun takeokunn/setup-tide-mode ()
      (interactive)
      (tide-setup)
      (tide-hl-identifier-mode 1)))
  (with-eval-after-load 'typescript-mode
    (add-hook 'typescript-mode-hook #'takeokunn/setup-tide-mode)))

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)
  :config
  (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 takeokunn/irb-history

(defun takeokunn/irb-history ()
  (interactive)
  (insert
   (completing-read
    "choose history: "
    (mapcar #'list (-distinct (s-lines (f-read-text "~/.irb-history")))))))

(general-def inf-ruby-mode-map
  "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)

6.17.2 psysh

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

6.18 Markdown

6.18.1 poly-markdown

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

6.19 File

6.19.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")))
  :config
  (recentf-mode 1))

6.19.2 open-junk-file

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

6.20 Syntax

6.20.1 aspell

(leaf ispell
  :setq-default
  (ispell-program-name . "aspell")
  :config
  (add-to-list 'ispell-skip-region-alist '("[^\000-\377]+")))

6.20.2 flycheck

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

6.20.3 flycheck-aspell

(leaf flycheck-aspell
  :ensure t
  :after (flycheck ispell)
  :defvar (ispell-program-name flycheck-checkers)
  :setq (ispell-program-name . "aspell")
  :config
  (add-to-list 'flycheck-checkers 'tex-aspell-dynamic))

6.21 Cursor

6.21.1 smartrep/multiple-cursors

(leaf smartrep :ensure t)

(leaf multiple-cursors
  :ensure t
  :defun (smartrep-define-key . smartrep)
  :after smartrep
  :config
  (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.21.2 smooth-scroll

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

6.22 Other

6.22.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.22.2 auto-save-buffers-enhanced

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

6.22.3 amx

(leaf smex :ensure t)

6.22.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.22.5 define-word

(leaf define-word
  :ensure t
  :custom
  (define-word-default-service . 'wordnik)
  (define-word-displayfn-alist
    '((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)))
  :config
  (defun takeokunn/define-word--display-in-buffer (definition)
    "docstring"
    (let* ((buf-name "*DEFINE WORD*")
           (buffer (get-buffer-create buf-name))
           (display-buffer-alist
            `((,buf-name
               (display-buffer-same-window)))))
      (with-current-buffer buffer
        (read-only-mode -1)
        (erase-buffer)
        (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 ()
    (interactive)
    (if (use-region-p)
        (call-interactively #'define-word-at-point)
      (call-interactively #'define-word))))

6.22.6 ddskk

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

6.22.7 editorconfig

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

6.22.8 esup

(leaf esup :ensure t)

6.22.9 elfeed

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

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

6.22.10 font-lock-studio

(leaf font-lock-studio :ensure t)

6.22.11 google-this

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

6.22.12 grugru

(leaf grugru
  :ensure t
  :disabled t
  :bind
  ("C-;" . grugru)
  :config
  (grugru-default-setup))

6.22.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.22.14 helpful

(leaf helpful
  :ensure t
  :after counsel
  :bind
  (("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.22.15 htmlize

(leaf htmlize :ensure t)

6.22.16 keyfreq

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

6.22.17 lorem ipsum

(leaf lorem-ipsum
  :ensure t
  :bind
  (("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.22.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))
  :init
  (global-origami-mode))

6.22.19 popwin

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

6.22.20 smartparens

(leaf smartparens :ensure t)

6.22.21 subword

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

6.22.22 undo

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

6.22.23 uuid

(leaf uuid
  :ensure t
  :el-get (emacs-uuid
           :url "https://github.com/nicferrier/emacs-uuid.git"
           :features uuid)
  :config
  (defun takeokunn/uuid ()
    (interactive)
    (insert (uuid-string))))

6.22.24 which-key

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

6.22.25 whitespace

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

6.22.26 wanderlust

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

6.22.27 xah-lookup

(leaf xah-lookup
  :ensure t
  :after (eww define-word)
  :setq
  (xah-lookup-browser-function . 'eww)
  (xah-lookup-dictionary-browser-function . 'eww)
  (xah-lookup-dictionary-list . ["http://www.google.com/search?q=define:+word02051"])
  :config
  (put 'xah-lookup-google 'xah-lookup-browser-function 'eww)
  (put 'xah-lookup-wikipedia 'xah-lookup-url "http://ja.wikipedia.org/wiki/word02051")
  (put 'xah-lookup-wikipedia 'xah-lookup-browser-function 'eww))

7 Eshell

7.1 basic

(leaf eshell
  :after (counsel)
  :config
  (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

(defun takeokunn/aweshell-setup ()
  (interactive)
  (shell-command-to-string "ghq get https://github.com/takeokunn/aweshell.git"))

(when (file-directory-p "~/.ghq/github.com/takeokunn/aweshell")
  (add-to-list 'load-path (expand-file-name "~/.ghq/github.com/takeokunn/aweshell"))
  (require 'esh-mode)
  (require 'aweshell)
  (with-eval-after-load 'aweshell
    (defun takeokunn/counsel-aweshell-history ()
      (interactive)
      (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
  :bind (("C-c C-q" . eshell-z)))

8 Org Mode

8.1 basic

(leaf org
  :setq-default
  ((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/todo.org")
                               "* %?")
                              ("m" "Memo" entry (file "~/org/memo.org")
                               "* %?"))))
  :custom
  (org-archive-location . `,(format "~/org/archive/%s.org"
                                  (format-time-string "%Y" (current-time))))
  (org-clock-out-remove-zero-time-clocks . t)
  :custom-face
  ((org-link '(t (:foreground "#ebe087" :underline t))))
  :bind
  (("C-c a" . org-agenda)
   ("C-c b" . counsel-bookmark)
   ("C-c c" . org-capture)
   (:org-mode-map ("C-m" . nil))))

8.2 org-ql

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

8.3 org-babel

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

(leaf ob-php
  :el-get (ob-php
           :url "https://github.com/stardiviner/ob-php.git"))

(leaf ob-fish
  :el-get (ob-fish
           :url "https://github.com/takeokunn/ob-fish.git"))


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

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

8.4 org-superstar

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

8.5 org-generate

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

8.6 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/index.org"))
  :custom
  (org-roam-graph-viewer . #'eww-open-file)
  :setq
  ((org-roam-v2-ack . nil))
  :bind
  (("C-c n l" . org-roam)
   ("C-c n f" . org-roam-find-file)
   ("C-c n g" . org-roam-graph)
   (:org-mode-map
    (("C-c n i" . org-roam-insert)
     ("C-c n I" . org-roam-insert-immediate)))))

8.7 org-tree-slide

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

8.8 org-pomodoro

(leaf org-pomodoro
  :ensure t)

9 MyFunc

9.1 takeokun/bneginning-of-intendation

(defun takeokunn/beginning-of-intendation ()
  "move to beginning of line, or indentation"
  (interactive)
  (back-to-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
      (prog-mode))))

;; (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."
  (interactive)
  (let ((current-mode major-mode))
    (fundamental-mode)
    (funcall current-mode)
    current-mode))

9.4 takeokunn/move-line

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

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

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

(general-define-key
 "M-N" 'takeokunn/move-line-down
 "M-P" 'takeokunn/move-line-up)

Author: takeounn

Created: 2021-09-14 Tue 09:24

Validate