Skip to content

Instantly share code, notes, and snippets.

@ypsilon-takai
Last active September 29, 2022 06:56
Show Gist options
  • Save ypsilon-takai/1708250 to your computer and use it in GitHub Desktop.
Save ypsilon-takai/1708250 to your computer and use it in GitHub Desktop.
Emacs's init.el
;; emacsserver
(require 'server)
(unless (server-running-p)
(server-start))
;; bobcat setting for >22
(load-library "term/bobcat")
(terminal-init-bobcat)
;; default
(menu-bar-mode 1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(setq visible-bell t)
;; use spaces for tab
(setq-default indent-tabs-mode nil)
(set-default-coding-systems 'utf-8-unix)
;(setq default-file-name-coding-system 'japanese-cp932-dos)
;; font
(when (eq window-system 'x)
(progn
(let* ((fontset-name "Minamoto")
(size 11)
;; (asciifont "Migu 2M")
;; (asciifont "Consolas")
(asciifont "Source Han Code JP")
(jpfont "TakaoGothic")
(font (format "%s-%d:weight=normal:slant=normal" asciifont size))
(fontspec (font-spec :family asciifont))
(jp-fontspec (font-spec :family jpfont))
(fsn (create-fontset-from-ascii-font font nil fontset-name)))
(set-fontset-font fsn 'japanese-jisx0213.2004-1 jp-fontspec)
(set-fontset-font fsn 'japanese-jisx0213-2 jp-fontspec)
(set-fontset-font fsn 'katakana-jisx0201 jp-fontspec)
(set-fontset-font fsn '(#x0080 . #x024F) fontspec)
(set-fontset-font fsn '(#x0370 . #x03FF) fontspec))
;;(set-default-font "Migu 2M")
;;(set-face-font 'variable-pitch "Migu 2M")
;;(set-fontset-font (frame-parameter nil 'font)
;; 'japanese-jisx0208
;; '("TakaoGothic" . "unicode-bmp"))
(add-to-list 'default-frame-alist '(font . "fontset-Minamoto"))
;;(dolist (elt '(("*Takao*" . 0.8)))
;; (add-to-list 'face-font-rescale-alist elt))
(setq face-font-rescale-alist '(("TakaoGothic" . 0.9)))
(set-face-font 'default "fontset-Minamoto")
))
;; theme path
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
;; load path
(add-to-list 'load-path "~/.emacs.d/local")
;; package tool
(require 'package)
(add-to-list 'package-archives
'("melpa-stable" . "http://stable.melpa.org/packages/"))
;;(add-to-list 'package-archives
;; '("melpa" . "http://melpa.org/packages/") t)
;; marmalade はちょっとあるふぁ過ぎる
(add-to-list 'package-archives
'("marmalade" . "https://marmalade-repo.org/packages/"))
(package-initialize)
(when (not package-archive-contents)
(package-refresh-contents))
;;(add-to-list 'package-pinned-packages '(cider . "melpa-stable") t)
;; auto install packages if they don't
(defvar my-packages '(clojure-mode
smartparens
cider
cider-eval-sexp-fu
company
magit
markdown-mode
smex
expand-region
multiple-cursors
smartrep
ido
ido-ubiquitous
))
(dolist (p my-packages)
(when (not (package-installed-p p))
(package-install p)))
;; from new startar kit
(defvar ido-cur-item nil)
(defvar ido-default-item nil)
(defvar ido-cur-list nil)
(ido-mode t)
(ido-ubiquitous-mode)
(setq ido-enable-prefix nil
ido-enable-flex-matching t
ido-auto-merge-work-directories-length nil
ido-create-new-buffer 'always
ido-use-filename-at-point 'guess
ido-use-virtual-buffers t
ido-handle-duplicate-virtual-buffers 2
ido-max-prospects 10)
(require 'uniquify)
(setq uniquify-buffer-name-style 'forward)
(require 'saveplace)
(setq-default save-place t)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(global-set-key (kbd "C-s") 'isearch-forward-regexp)
(global-set-key (kbd "C-r") 'isearch-backward-regexp)
(global-set-key (kbd "C-M-s") 'isearch-forward)
(global-set-key (kbd "C-M-r") 'isearch-backward)
(show-paren-mode t)
(setq x-select-enable-clipboard t
x-select-enable-primary t
save-interprogram-paste-before-kill t
apropos-do-all t
mouse-yank-at-point t
save-place-file (concat user-emacs-directory "places")
backup-directory-alist `(("." . ,(concat user-emacs-directory
"backups"))))
(smex-initialize)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
(electric-indent-mode 1)
;; for wsl
(setq-default sysTypeSpecific system-type)
;; emacs
;; Show Git branch information to mode-line
(let ((cell (or (memq 'mode-line-position mode-line-format)
(memq 'mode-line-buffer-identification mode-line-format)))
(newcdr '(:eval (my/update-git-branch-mode-line))))
(unless (member newcdr mode-line-format)
(setcdr cell (cons newcdr (cdr cell)))))
(defun my/update-git-branch-mode-line ()
(let* ((branch (replace-regexp-in-string
"[\r\n]+\\'" ""
(shell-command-to-string "git symbolic-ref -q HEAD")))
(mode-line-str (if (string-match "^refs/heads/" branch)
(format "[%s]" (substring branch 11))
"[Not Repo]")))
(propertize mode-line-str
'face '((:foreground "Dark green" :weight bold)))))
;; open link with default browser of windows
(cond
((eq sysTypeSpecific 'gnu/linux)
(when (string-match "Linux.*Microsoft.*Linux"
(shell-command-to-string "uname -a"))
(setq-default sysTypeSpecific "ws/linux")
(setq cmdExeBin "/mnt/c/Windows/System32/cmd.exe"
cmdExeArgs '("/c" "start" ""))
(setq browse-url-generic-program cmdExeBin
browse-url-generic-args cmdExeArgs
browse-url-browser-function 'browse-url-generic))))
;; company (auto completion) mode
(add-hook 'after-init-hook 'global-company-mode)
(global-set-key (kbd "M-/") 'company-complete)
(global-set-key (kbd "M-<tab>") 'company-complete)
;; expand-region
(require 'expand-region)
(global-set-key (kbd "C-,") 'er/expand-region)
(global-set-key (kbd "C-M-,") 'er/contract-region) ;; リージョンを狭める
(transient-mark-mode t)
;; multiple-cursor
(require 'multiple-cursors)
(require 'smartrep)
(global-unset-key "\C-t")
(global-set-key (kbd "C-t") 'mc/edit-lines)
;; skk
(require 'skk)
(global-set-key "\C-x\C-j" 'skk-mode)
(declare-function smartrep-define-key "smartrep")
(smartrep-define-key global-map "C-."
'(("C-." . 'mc/mark-next-like-this)
("n" . 'mc/mark-next-like-this)
("p" . 'mc/mark-previous-like-this)
("a" . 'mc/mark-all-in-region)
("m" . 'mc/mark-more-like-this-extended)
("u" . 'mc/unmark-next-like-this)
("U" . 'mc/unmark-previous-like-this)
("s" . 'mc/skip-to-next-like-this)
("S" . 'mc/skip-to-previous-like-this)
("*" . 'mc/mark-all-like-this)
("d" . 'mc/mark-all-like-this-dwim)
("i" . 'mc/insert-numbers)
("o" . 'mc/sort-regions)
("O" . 'mc/reverse-regions)))
;; smartparens
(require 'smartparens-config)
(add-hook 'emacs-lisp-mode 'smartparens-strict-mode)
;; clojur-mode
(defun my-pretty-fn ()
(font-lock-add-keywords nil `(("(\\(\\<fn\\>\\)"
(0 (progn (compose-region (match-beginning 1)
(match-end 1)
"\u0192"
'decompose-region)))))))
(defun my-pretty-lambda ()
(font-lock-add-keywords nil `(("(\\(\\<fn\\>\\)"
(0 (progn (compose-region (match-beginning 1)
(match-end 1)
"\u03bb"
'decompose-region)))))))
(add-hook 'clojure-mode-hook 'my-pretty-lambda)
(add-hook 'clojurescript-mode-hook 'my-pretty-fn)
(add-hook 'clojure-mode-hook 'smartparens-strict-mode)
;;;;;;;;;;;;;;;;;;;;;;;
;; cider : clojure developping environment
(require 'cider)
;; eliminate ^M at dos lines.
(defun remove-dos-eol ()
"Do not show ^M in files containing mixed UNIX and DOS line endings."
(interactive)
(setq buffer-display-table (make-display-table))
(aset buffer-display-table ?\^M []))
(add-hook 'cider-repl-mode-hook 'remove-dos-eol)
(add-hook 'cider-repl-mode-hook 'smartparens-strict-mode)
;;(add-hook 'cider-repl-mode-hook 'paredit-mode)
;;(add-hook 'cider-mode-hook 'cider-turn-on-eldoc-mode)
(add-hook 'cider-mode-hook #'eldoc-mode)
(setq cider-eldoc-display-for-symbol-at-point nil)
(setq nrepl-hide-special-buffers t)
(setq cider-repl-tab-command 'indent-for-tab-command)
(setq cider-repl-pop-to-buffer-on-connect t)
(setq cider-show-error-buffer t)
;;(setq cider-show-error-buffer 'except-in-repl)
;;(setq cider-show-error-buffer 'only-in-repl)
(setq cider-font-lock-dynamically '(macro core function var))
(setq cider-auto-select-error-buffer nil)
(setq nrepl-buffer-name-show-port nil)
(setq cider-repl-print-length 100)
(setq cider-repl-result-prefix ";;=> ")
;;(require 'cljdoc)
;; auto complete with company
(add-hook 'cider-repl-mode-hook 'company-mode)
(add-hook 'cider-mode-hook 'company-mode)
;; magit
(set-variable 'magit-emacsclient-executable
"emacsclient")
;; arduino
(require 'arduino-mode)
;; markdown
(defun my--markdown-entery-key-ad (this-func &rest args)
"markdown-modeでskk-henkan-mode中にエンターすると行頭にカーソルが飛んでしまう問題の対応"
(if skk-henkan-mode (skk-kakutei)
(apply this-func args)))
(advice-add #'markdown-enter-key :around #'my--markdown-entery-key-ad)
;; eshell
;; change prompt
(setq eshell-prompt-function
(lambda()
(concat ((lambda (p-lst)
(if (> (length p-lst) 4)
(concat
(mapconcat (lambda (elm) (if (equal elm "")
elm
(substring elm 0 1)))
(butlast p-lst 2)
"/")
"/"
(mapconcat (lambda (elm) elm)
(last p-lst 2)
"/"))
(mapconcat (lambda (elm) elm)
p-lst
"/")))
(split-string (abbreviate-file-name (eshell/pwd)) "/"))
(if (= (user-uid) 0) " # " " $ "))))
(setq line-spacing 0)
(defun toggle-line-spacing ()
"Toggle line spacing between no extra space to extra half line height."
(interactive)
(if (eq line-spacing nil)
(setq-default line-spacing 0.2) ; add 0.1 height between lines
(setq-default line-spacing nil) ; no extra heigh between lines
)
(redraw-display))
;; cperl mode
(defalias 'perl-mode 'cperl-mode)
(add-hook 'cperl-mode-hook
'(lambda ()
(cperl-set-style "PerlStyle")))
;; python mode
;; (setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist))
;; (setq interpreter-mode-alist (cons '("python" . python-mode)
;; interpreter-mode-alist))
;; (autoload 'python-mode "python-mode" "Python editing mode." t)
;; (add-hook 'python-mode-hook
;; (function (lambda ()
;; (setq py-indent-offset 4)
;; (setq indent-tabs-mode nil))))
;; mouse control
(setq mouse-wheel-scroll-amount '(1 ((shift) . 3) ((control) . nil)))
(setq mouse-wheel-progressive-speed nil)
;; focus follows mouse
(setq mouse-autoselect-window t)
;; colorized compilation buffer
(require 'ansi-color)
(defun my/ansi-colorize-buffer ()
(let ((buffer-read-only nil))
(ansi-color-apply-on-region (point-min) (point-max))))
(add-hook 'compilation-filter-hook 'my/ansi-colorize-buffer)
;;;;;;;;
;; tools
(defun find-pid (proc-name)
(interactive "sProcName: ")
(process-id (get-process proc-name)))
;; from http://www.emacswiki.org/emacs/AutoIndentation
(dolist (command '(yank yank-pop))
(eval `(defadvice ,command (after indent-region activate)
(and (not current-prefix-arg)
(member major-mode '(emacs-lisp-mode lisp-mode
clojure-mode scheme-mode
haskell-mode ruby-mode
rspec-mode python-mode
c-mode c++-mode
objc-mode latex-mode
plain-tex-mode))
(let ((mark-even-if-inactive transient-mark-mode))
(indent-region (region-beginning) (region-end) nil))))))
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ansi-color-faces-vector
[default default default italic underline success warning error])
'(ansi-color-names-vector
["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
'(blink-cursor-mode nil)
'(c-basic-offset 4)
'(c-default-style
(quote
((c-mode . "bsd")
(c++-mode . "bsd")
(java-mode . "java")
(awk-mode . "awk")
(other . "gnu"))))
'(custom-enabled-themes (quote (wheatgrass)))
'(custom-safe-themes
(quote
("bb5ac59e63d13acfc03e1abdcac18d850396f72f590acdf8d8691b1c96121c43" "e9c458828e4261bf0d3925a9998e4bba1338b1b6a72eaf08ef6d32af83e686ad" "76f21bb8bdd25a6b002d0ffba05da6e8f2d40abd8a2b35c3d0675fc79912580d" "4378846f8e6bf4b705fcc44379b4b8cd15be96e07a001338cd2e3e2c6db4b670" "5ab29722239a8dab3480f17a5aa232f350dff78c0aab098ca5e19ec8c0ccabce" "aa7419efd76774470afee5084c1adcf660b53990a61ce416e9d7d21ad8380630" "bf3891489e90b2eb599187cc26b8056630a8cd3f8bc296b66c702f3ffbf7f9e6" "910d2e5ee401a9cb3973ee006f656a5ccd508b9a7a2bd17474a2645e2a208cb5" default)))
'(default-frame-alist
(quote
((font . "fontset-Minamoto")
(vertical-scroll-bars)
(height . 50)
(width . 100))))
'(ibuffer-saved-filter-groups
(quote
(("clojure-dev"
("directory"
(used-mode . dired-mode))
("clojure"
(used-mode . clojure-mode))))))
'(ibuffer-saved-filters
(quote
(("gnus"
((or
(mode . message-mode)
(mode . mail-mode)
(mode . gnus-group-mode)
(mode . gnus-summary-mode)
(mode . gnus-article-mode))))
("programming"
((or
(mode . emacs-lisp-mode)
(mode . cperl-mode)
(mode . c-mode)
(mode . java-mode)
(mode . idl-mode)
(mode . lisp-mode)))))))
'(initial-frame-alist
(quote
((vertical-scroll-bars)
(height . 40)
(widch . 100))))
'(package-selected-packages
(quote
(ssh-agency yaml-mode csv csv-mode cider-eval-sexp-fu markdown-mode smex smartrep smartparens multiple-cursors magit ido-ubiquitous expand-region company clojure-mode-extra-font-locking cider)))
'(safe-local-variable-values
(quote
((cider-ns-refresh-after-fn . "integrant.repl/resume")
(cider-ns-refresh-before-fn . "integrant.repl/suspend"))))
'(skk-henkan-show-candidates-keys
(quote
(97 111 101 117 105 100 104 116 110 115 39 44 46 112 103 99 114 108 109 119 118)))
'(smtpmail-smtp-service 25)
'(tool-bar-mode nil)
'(url-proxy-services nil))
(put 'narrow-to-region 'disabled nil)
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment