diff --git a/README.md b/README.md new file mode 100644 index 0000000..8d8a936 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# これはなに? +Aintekで利用しているEmacs設定ファイルの中身 + +# どうやって使うか? +* 自身のホームディレクトリに.emacs.dディレクトリを作成する +* .emacs.d以下に本リポジトリの全ファイルを配置する +* 以上 diff --git a/init.el b/init.el new file mode 100644 index 0000000..ebaec2d --- /dev/null +++ b/init.el @@ -0,0 +1,481 @@ +;;; emacs-lisp; coding +;;; -*- coding:utf-8 -*- +;;; Common Lisp extensions for Emacs +(require 'cl) + +;;; debug on +;; (setq debug-on-error t) + +;;; server start for emacs client +(require 'server) +(unless (server-running-p) + (server-start)) + +;;; use global env path +(add-to-list 'load-path "~/.emacs.d/lisp") + +;;; call coding utf8 (C-c u) +(require 'coding-utf8) +;;; call 1row-scroll +(require '1row-scroll) + +;;; Set language +(set-language-environment "Japanese") +;;; ?? which one is better utf-8 or utf-8-unix ?? +(prefer-coding-system 'utf-8) +(set-terminal-coding-system 'utf-8) +(set-keyboard-coding-system 'utf-8) +(set-buffer-file-coding-system 'utf-8) +(set-clipboard-coding-system 'utf-8) +(setq default-buffer-file-coding-system 'utf-8) + +;;; Set Background and Forground color +(setq default-frame-alist + (append + (list + '(background-color . "gray20") + '(foreground-color . "gray85") + '(cursor-color . "yellow")) + default-frame-alist)) + +;;; Paren +(show-paren-mode 1) + +;;; global key setting +;;; For key of C-h(backspace) +;; (global-set-key "\C-h" 'backward-delete-char) +;;; For key of newline +(global-set-key "\C-m" 'newline-and-indent) + +;;; key of backspace +(normal-erase-is-backspace-mode 0) + +;;; indent +(setq-default indent-width 2) + +;;; default indent +(setq-default c-basic-offset 2 + tab-width 2 + indent-tabs-mode nil) + +;;; no make backup file +(setq backup-inhibited t) +(setq make-backup-files nil) +(setq auto-save-default nil) + +;;; delete auto-save-files when exit emacs +(setq delete-auto-save-files t) + +;;; bar setting +;(tool-bar-mode 0) +;(menu-bar-mode 0) +(scroll-bar-mode 0) + +;;; No init-screen +(setq inhibit-splash-screen t) + +;;; No newline +(setq next-line-add-newlines nil) + +;;; C-mode +(add-hook + 'c-mode-common-hook + (lambda () + ;;; bsd style + (c-set-style "bsd") + ;;; tab indent, no space + (setq indent-tabs-mode t) + ;;; tab -> 2 + (setq c-basic-offset 2) + (setq tab-width 2) + ;;; input ';' , goto next column + ;;; and delete brank (too bad) + ;; (c-toggle-auto-hungry-state 1) + ;;; delete brank + (C-toggle-hungry-state 1) + )) + +;;; Auto Fill Mode +;;(setq fill-column 80) +;;(setq-default auto-fill-mode -1) +;;(setq text-mode-hook 'turn-on-auto-fill) + +;;; Time +(setq display-time-day-and-date t) +(display-time) +(setq display-time-string-forms + '((format "%s/%s/%s(%s) %s:%s" + year month day + dayname + 24-hours minutes) + )) + +;;; Indicate Function +(which-function-mode 1) + +;;; insert template +(auto-insert-mode t) +;;; auto complete in mini buffer +(icomplete-mode 1) + +;;; Indicate Cursor +(column-number-mode t) +(line-number-mode t) + +;;; No beep +(setq visible-bell t) + +;;; Yatex mode +(setq auto-mode-alist (cons '("\\.tex$" . yatex-mode) auto-mode-alist)) +(autoload 'yatex-mode "yatex" "Yet Another LaTeX mode" t) +;(setq load-path +; (append '(expand-file-name +; "/usr/local/share/emacs/site-lisp/yatex") load-path)) +;;; Set character code +;;; 0: non converion +;;; 1: Shift JIS +;;; 2: ISO-2022-JP +;;; 3: EUC +;;; 4: UTF-8 +(setq YaTeX-kanji-code 4) + +;;; Yahtml mode +(autoload 'yahtml-mode "yahtml" "Yet Another HTML mode" t) +(setq auto-mode-alist (cons (cons "\\.html?$" 'yahtml-mode) auto-mode-alist)) +(setq yahtml-lint-program "htmllint") +(setq yahtml-kanji-code 4) +(add-hook 'yahtml-mode-hook '(lambda () (setq fill-column 80))) + +;;; Emacs-mozc +;;(require 'mozc) +;;(set-language-environment "Japanese") +;;(setq default-input-method "japanese-mozc") +;;(setq candidates-style 'echo-area) +;;(global-set-key (kbd "C-o") 'toggle-input-method) +;;(setq mozc-candidate-style 'overlay) + +;;; load site-lisp/misc +;;(setq load-path +;; (append '(expand-file-name +;; "/usr/local/share/emacs/site-lisp/misc/") load-path)) + +;;; Windows.el +;;; default is "C-c C-w" +;;; If windows.el is set, +;;; you don't need set (require 'revive). +;;; This already has loaded by including windows.el +(require 'windows) +;; no make new frame +(setq win:use-frame nil) +(win:startup-with-window) +;; C-x C-c saves this state +;; C-x C don't saves. +(define-key ctl-x-map "\C-c" 'see-you-again) +(define-key ctl-x-map "C" 'save-buffers-kill-emacs) + +;;; R-mode +;;(add-to-list 'load-path "~/usr/share/emacs/site-lisp/ess") +;;(setq auto-mode-alist +;; (cons (cons "\\.r$" 'R-mode) auto-mode-alist)) +;;(autoload 'R-mode "ess-site" "Emacs Speaks Statistics mode" t) +;;(setq ess-ask-for-ess-directory nil) + +;;; unformal repositories 'mepla' and 'marmalade' +;;; --- emacs package install --- +(require 'package) +(add-to-list 'package-archives + '("melpa" . "http://melpa.milkbox.net/packages/")) +(add-to-list 'package-archives + '("marmalade" . "http://marmalade-repo.org/packages/")) +(package-initialize) +;;; --- emacs package install --- +(defvar my-packages '( + ;;; --- refactoring --- + anzu + ;;; --- auto-complete --- + auto-complete + ;;; --- load path from shell --- + exec-path-from-shell + ;;; --- ruby mode --- + ruby-mode + ruby-electric + ruby-block + ruby-refactor + ;;; --- python mode --- + python-mode + elpy + jedi + py-autopep8 + flymake-easy + flymake-python-pyflakes + pyvenv + ;;; --- org mode --- + org + ;;; --- vue mode --- + vue-mode + mmm-mode + vue-html-mode + ssass-mode + edit-indirect + ;;; --- go mode --- + company + company-go + go-autocomplete + ;;; --- scss mode --- + scss-mode + ;;; --- web mode --- + web-mode + ;;; --- haml mode --- + haml-mode + ;;; --- coffee sript --- + coffee-mode + coffee-fof + ;;; --- php mode --- + php-mode + php-completion + cake + cake2 + helm + helm-gtags + ;;; --- clojure mode --- + clojure-mode + paredit + cider + rainbow-delimiters + ac-nrepl + ;;; --- ocaml util --- + caml + tuareg + ocp-indent + ;;; flymake-tuareg + )) +(dolist (p my-packages) + (when (not (package-installed-p p)) + (package-refresh-contents) + (package-install p))) + +;;; --- exec path from shell --- +;;(exec-path-from-shell-initialize) + +;;; --- anzu (refactoring mode) --- +(global-anzu-mode +1) +(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. + '(anzu-deactivate-region t) + '(anzu-mode-lighter "") + '(anzu-replace-to-string-separator " => ") + '(anzu-search-threshold 1000) + '(package-selected-packages + (quote + (exec-path-from-shell go-complete company-go go-mode flycheck web-mode vue-mode tuareg scss-mode ruby-refactor ruby-electric ruby-block rainbow-delimiters python-mode py-autopep8 php-mode php-completion paredit ocp-indent jedi ipython helm-gtags haml-mode flymake-python-pyflakes elpy coffee-fof caml cake2 cake auto-indent-mode anzu ac-nrepl))) + '(safe-local-variable-values (quote ((enconding . utf-8))))) + +;;; --- auto complete +(require 'auto-complete) +(require 'auto-complete-config) +;;; delay setting +(setq ac-delay 0.0) +(setq ac-quick-help-delay 0.5) +;;; commands settting +(define-key ac-complete-mode-map "\C-n" 'ac-next) +(define-key ac-complete-mode-map "\C-p" 'ac-previous) +;;; global setting +(ac-config-default) +(global-auto-complete-mode t) + +;;; --- go mode +(require 'go-autocomplete) +(add-hook 'go-mode-hook 'flycheck-mode) + +;;; tuareg-mode +(setq auto-mode-alist + (cons '("\\.ml[iylp]?$" . tuareg-mode) auto-mode-alist)) +(add-to-list 'auto-mode-alist + '("\\.eliom$" . tuareg-mode)) +(autoload 'tuareg-mode "tuareg" "Major mode for editing Caml code." t) +(add-hook 'tuareg-mode-hook 'utop-minor-mode) + +;;; --- flymake-tuareg +;;(require 'flymake-tuareg) +;;(add-hook 'tuareg-mode-hook 'flymake-tuareg-load) + +;;; --- python-mode +;;; extends python mode +(add-hook 'python-mode-hook + '(lambda () + (setq indent-tab-mode nil) + (setq indent-level 4) + (setq python-indent 4) + (setq tab-width 4) + (package-initialize) + (elpy-enable) + (elpy-mode) + )) +(add-hook 'elpy-mode-hook + '(lambda () + (elpy-use-ipython) + ;;; fix prompt + (setenv "IPY_TEST_SIMPLE_PROMPT" "1") + ;;; quickrun C-c C-r + ;;(define-key elpy-mode-map "\C-c\C-r" 'quickrun) + ;;; disable auto complete mode + (auto-complete-mode -1) + ;;; use jedi + (setq elpy-rpc-backend "jedi") + (define-key company-active-map (kbd "\C-n") 'company-select-next) + (define-key company-active-map (kbd "\C-p") 'company-select-previous) + (define-key company-active-map (kbd "\C-d") 'company-show-doc-buffer) + (define-key company-active-map (kbd "") 'company-complete) + )) +;;; set ipython +(setq python-shell-interpreter "ipython" + python-shell-interpreter-args "-i") +;;; refactor tool +;;; NOTE: pip install autopep8 before. +(require 'py-autopep8) +(add-hook 'python-mode-hook 'py-autopep8-enable-on-save) +(setq py-autopep8-options '("--max-line-length=80")) +;;; fly check (flymake-python-pyflakes requires flymake-easy) +;;; NOTE: pip install flake8 before. +(require 'flymake-easy) +(require 'flymake-python-pyflakes) +(add-hook 'python-mode-hook 'flymake-python-pyflakes-load) +(setq flymake-python-pyflakes-executable "flake8") +(require 'yasnippet) +(yas-global-mode 1) +;;; pyvenv is switching some resource. +(pyvenv-mode 1) +(pyvenv-tracking-mode 1) + +;;; --- ruby-mode +(autoload 'ruby-mode "ruby-mode" + "Mode for editing ruby source files" t) + +;;; --- org-mode +(require 'org) +(require 'org-install) +;;; if 80 characters, goto next line. +(setq org-startup-trucated nil) +(setq org-return-follows-link t) +(add-to-list 'auto-mode-alist '("\\.org$" . org-mode)) +(setq org-directory "~/Org/") +(setq org-default-notes-files (concat org-directory "agenda.org")) +(setq org-agenda-files (list org-directory)) + +;;; --- vue mode +(require 'vue-mode) +(require 'mmm-mode) +(defun my-vue-mode-hook () + "Hooks for vue mode." + (setq js-indent-level 2) + (setq css-indent-offset 2) + (setq tab-width 2) + (setq indent-tab-mode nil) +) +(add-hook 'vue-mode-hook 'my-vue-mode-hook) + +;;; --- Web mode (php, pl, js, html) +(require 'web-mode) +(defun web-mode-hook () + "Hooks for Web mode." + (setq web-mode-markup-indent-offset 2) + (setq web-mode-html-offset 2) + (setq web-mode-css-indent-offset 2) + (setq web-mode-script-indent-offset 2) + (setq web-mode-code-indent-offset 2) + (setq indent-tabs-mode nil) + (setq tab-width 2) +) +(add-hook 'web-mode-hook 'web-mode-hook) +;;; set auto closing pairing +(setq web-mode-auto-close-style 1) +(setq web-mode-tag-auto-close-style t) +(setq web-mode-enable-auto-pairing t) +;;; +(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode)) +(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode)) +(add-to-list 'auto-mode-alist '("\\.jsp\\'" . web-mode)) +(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode)) +(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode)) +(add-to-list 'auto-mode-alist '("\\.jsx?\\'" . web-mode)) + +;;; --- HAML mode +(require 'haml-mode) +(add-to-list 'auto-mode-alist '("\\.haml?\\'" . haml-mode)) +(add-hook 'haml-mode-hook + (lambda () + (setq indent-tabs-mode nil) + (define-key haml-mode-map "\C-m" 'newline-and-indent))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; OPAM configuration ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;;; Add opam emacs directory to the load-path +(setq opam-share (substring (shell-command-to-string "opam config var share 2> /dev/null") 0 -1)) +(add-to-list 'load-path (concat opam-share "/emacs/site-lisp")) +;;; Load merlin-mode +;;; find shared library installed opam (no neccesarry?) +(let ((opam-share (ignore-errors (car (process-lines "opam" "config" "var" "share"))))) + (when (and opam-share (file-directory-p opam-share)) + (add-to-list 'load-path (expand-file-name "emacs/site-lisp" opam-share)))) +(require 'merlin) +;;; Start merlin on ocaml files +(autoload 'merlin-mode "merlin" "Merlin mode" t) +(add-hook 'tuareg-mode-hook 'merlin-mode t) +(add-hook 'caml-mode-hook 'merlin-mode t) +;;; Enable auto-complete +(setq merlin-use-auto-complete-mode 'easy) +;;; (setq merlin-use-auto-complete-mode t) +;;; Use opam switch to lookup ocamlmerlin binary +(setq merlin-command 'opam) + +;;; use the opam installed utop +(require 'utop) +(require 'utop-custom) +(setq utop-command "opam config exec -- utop -emacs") +;;; Automatically load utop.el +(autoload 'utop "utop" "Toplevel for OCaml" t) +;;; minor mode +(autoload 'utop-minor-mode "utop" "Minor mode for utop" t) + +;;; omake mode +;;(setq load-path +;; (append '(expand-file-name +;; "/usr/local/share/emacs/site-lisp/omake-mode") load-path)) +;;(require 'omake) + +;;; flymake mode +(require 'flymake) +(push '("File \"\\(.*\\)\", line \\([0-9]+\\), characters \\([0-9]+\\)--?\\([0-9]+\\):\\(.*\\)" 1 2 3 5) flymake-err-line-patterns) +(push '("\\.ml\\'" flymake-ocaml-init) flymake-allowed-file-name-masks) +(defun flymake-ocaml-init () + (list (expand-file-name "~/.emacs.d/ocaml-flymake.sh"))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; End of OPAM configuration ;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;;; Set language 2 +;;; Must put bottom !!! +(set-coding-system-priority 'utf-8) +(set-default-coding-systems 'utf-8) + +(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. + '(company-preview ((t (:foreground "darkgray" :underline t)))) + '(company-preview-common ((t (:inherit company-preview)))) + '(company-tooltip ((t (:background "lightgray" :foreground "black")))) + '(company-tooltip-common ((((type x)) (:inherit company-tooltip :weight bold)) (t (:inherit company-tooltip)))) + '(company-tooltip-common-selection ((((type x)) (:inherit company-tooltip-selection :weight bold)) (t (:inherit company-tooltip-selection)))) + '(company-tooltip-selection ((t (:background "steelblue" :foreground "white"))))) +(put 'upcase-region 'disabled nil) +;; ## added by OPAM user-setup for emacs / base ## 56ab50dc8996d2bb95e7856a6eddb17b ## you can edit, but keep this line +(require 'opam-user-setup "~/.emacs.d/opam-user-setup.el") +;; ## end of OPAM user-setup addition for emacs / base ## keep this line diff --git a/lisp/1row-scroll.el b/lisp/1row-scroll.el new file mode 100644 index 0000000..7828cc0 --- /dev/null +++ b/lisp/1row-scroll.el @@ -0,0 +1,38 @@ +;;; 1row-scroll.el --- +;;;-*- coding:utf-8 -*- + +;; Copyright (C) 2015 toshiki KAWAI + +;; Author: toshiki KAWAI +;; Keywords: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; + +;;; Code: + +(global-set-key "\C-z" + '(lambda (arg) (interactive "p") (scroll-up arg))) + +(global-set-key "\C-o" + '(lambda (arg) (interactive "p") (scroll-down arg))) + +;;;(global-set-key "\C-u" +;;;'suspend-emacs) + +(provide '1row-scroll) +;;; 1row-scroll.el ends here diff --git a/lisp/coding-utf8.el b/lisp/coding-utf8.el new file mode 100644 index 0000000..232ee73 --- /dev/null +++ b/lisp/coding-utf8.el @@ -0,0 +1,26 @@ +;;-*- coding:utf-8 -*- + +;; Copyright (C) 2014 Toshiki KAWAI + +;; Author: Toshiki KAWAI +;; Keywords: coding utf-8 + +;; val -> pos :: 未実装 +(defun insert-utf8 () + (goto-char (point-min)) + (insert comment-start) + (insert "-*- coding:utf-8 -*- ") + (insert comment-end)) + +(defun insert-string-utf8 () + (interactive) + (save-excursion + (goto-char (point-min)) + (if (and (boundp 'comment-start) (char-or-string-p comment-start)) + (insert-utf8) + (insert "-*- coding:utf-8 -*- ")))) + +(define-key global-map "\C-cu" 'insert-string-utf8) + +(provide 'coding-utf8) +;;; coding-utf8.el ends here diff --git a/lisp/utop-custom.el b/lisp/utop-custom.el new file mode 100644 index 0000000..b0c837c --- /dev/null +++ b/lisp/utop-custom.el @@ -0,0 +1,97 @@ +;;-*- coding:utf-8 -*- +;;; utop-custom.el --- + +;; Keywords: utop + +;;; Code: + +(require 'utop) +(require 'cl) + +;;; copy from using-utop-in-emacs.html +(defconst init-file-name "toplevel.init") + +(defconst build-dir-name "_build") + +(defun upward-find-file (filename &optional startdir) + "Move up directories until we find a certain filename. If we + manage to find it, return the containing directory. Else if we + get to the toplevel directory and still can't find it, return + nil. Start at startdir or . if startdir not given" + + (let ((dirname (expand-file-name + (if startdir startdir "."))) + (found nil) ; found is set as a flag to leave loop if we find it + (top nil)) ; top is set when we get + ;; to / so that we only check it once + + ;; While we've neither been at the top last time nor have we found + ;; the file. + (while (not (or found top)) + ;; If we're at / set top flag. + (if (string= (expand-file-name dirname) "/") + (setq top t)) + + ;; Check for the file + (if (file-exists-p (expand-file-name filename dirname)) + (setq found t) + ;; If not, move up a directory + (setq dirname (expand-file-name ".." dirname)))) + ;; return statement + (if found dirname nil))) + +(defun should-include-p (file) + "A predicate for wether a given file-path is relevant for + setting up the `include` path of utop." + (cond ((string= (file-name-base file) ".") nil) + ((string= (file-name-base file) "..") nil) + ((string-match ".*\.dSYM" file) nil) + ((file-directory-p file) t))) + + +(defun ls (dir) + "Returns directory contents. Only includes folders that + are relevant for utop" + (if (should-include-p dir) + (remove-if-not 'should-include-p (directory-files dir t)) + nil)) + +(defun ls-r (dir) + "Returns directory contents, decending into subfolders + recursively. Only returns folders that are relevant for utop " + (defun tail-rec (directories result) + (if (> (length directories) 0) + (let* ((folders (remove-if-not 'should-include-p directories)) + (next (mapcar 'ls folders)) + (flattened (apply #'append next))) + (tail-rec flattened (append result folders))) + result)) + (tail-rec (list dir) nil)) + +(defun utop-invocation (&optional startdir) + "Generates an appropriately initialized utop buffer." + (interactive) + (let* ((dir (if startdir startdir default-directory)) + (project-root (upward-find-file init-file-name dir)) + (init-file (concat project-root "/" init-file-name)) + (build-dir (concat project-root "/" build-dir-name)) + (includes (ls-r build-dir)) + (includes-str (mapconcat (lambda (i) (concat "-I " i)) includes " ")) + (utop-command (concat "utop -emacs " "-init " init-file " " includes-str))) + ;; The part below is mostly copied from utop.el; Look at the source for comments. + (let ((buf (get-buffer utop-buffer-name))) + (cond + (buf + (pop-to-buffer buf) + (when (eq utop-state 'done) (utop-restart))) + (t + ;; This is the change. We set the command string explicitly. + (setq utop-command utop-command) + (setq buf (get-buffer-create utop-buffer-name)) + (pop-to-buffer buf) + (with-current-buffer buf (utop-mode)))) + buf))) + + +(provide 'utop-custom) +;;; utop-custom.el ends here