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)

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)
  (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
  (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)
  (mmm-global-mode . 'maybe)
  (mmm-submode-decoration-level . 0)
  :hook (after-save-hook . (lambda ()
                             (when (string-match-p "\\.tsx?" buffer-file-name)
  (require 'mmm-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$")
  (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))
  (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
  (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$")
  (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))
  ("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"

  (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
  :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

6.1.4 dashboard

(leaf dashboard
  :ensure t

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")))
  (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.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-glsl

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

6.3.4 company-go

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

6.3.5 company-php

(leaf company-php
  :ensure t
  :after (company php-mode)
  (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
  (push 'company-c-headers company-backends))

6.4 Snippet

6.4.1 yasnippet

snippetはこちら [](

(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)
  :custom (lsp-prefer-capf . t)
  (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)
  ((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
   ("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
  :custom (magit-display-buffer-function . #'magit-display-buffer-fullframe-status-v1))

6.7.2 magit-forge

(leaf forge
  :ensure t
  :after magit
  (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

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
    (defun takeokunn/setup-tide-mode ()
      (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)
  (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 ()
    "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
  (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-mode 1))

6.19.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.20 Syntax

6.20.1 aspell

(leaf ispell
  (ispell-program-name . "aspell")
  (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")
  (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
  (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
  (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
  (auto-save-buffers-enhanced-interval . 10)
  (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
  (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.22.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.22.7 editorconfig

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

6.22.8 esup

(leaf esup :ensure t)

6.22.9 elfeed

(leaf elfeed
  :ensure t
  ("C-x w" . elfeed)
  (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.22.10 font-lock-studio

(leaf font-lock-studio :ensure t)

6.22.11 google-this

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

6.22.12 grugru

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

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
  (("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
  (keyfreq-mode 1)
  (keyfreq-autosave-mode 1))

6.22.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.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))

6.22.19 popwin

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

6.22.20 smartparens

(leaf smartparens :ensure t)

6.22.21 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.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 ""
           :features uuid)
  (defun takeokunn/uuid ()
    (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
  ((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.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)
  (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
  :after (counsel)
  (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 ()
  (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
  :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-archive-location . `,(format "~/org/archive/"
                                  (format-time-string "%Y" (current-time))))
  (org-clock-out-remove-zero-time-clocks . t)
  ((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-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.3 org-babel

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

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

(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-php
  (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))
  ((org-superstar-headline-bullets-list . '("◉" "○" "✸" "✿"))
   (org-superstar-leading-bullet . " ")))

8.5 org-generate

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

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/"))
  (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.7 org-tree-slide

(leaf org-tree-slide
  :ensure t
  (("<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"

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)

Author: takeounn

Created: 2021-09-14 Tue 09:24