Skip to content

Instantly share code, notes, and snippets.

@shibainurou
Last active October 21, 2020 01:52
Show Gist options
  • Save shibainurou/4380371 to your computer and use it in GitHub Desktop.
Save shibainurou/4380371 to your computer and use it in GitHub Desktop.
emacsの設定ファイル
;; 配下のフォルダ全読み込み
(setq load-path(cons "~/.emacs.d/elisp" load-path))
(setq inhibit-startup-message t)
(let ((dir (expand-file-name "~/.emacs.d/elisp")))
(if (member dir load-path) nil
(setq load-path (cons dir load-path))
(let ((default-directory dir))
(load (expand-file-name "subdirs.el") t t t))))
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)
;======================================================================
; 言語ー文字コード関連の設定
;======================================================================
;; 文字コード
(set-language-environment "Japanese")
(let ((ws window-system))
(cond ((eq ws 'w32)
(prefer-coding-system 'utf-8-unix)
(set-default-coding-systems 'utf-8-unix)
(setq file-name-coding-system 'sjis)
(setq locale-coding-system 'utf-8))
((eq ws 'ns)
(require 'ucs-normalize)
(prefer-coding-system 'utf-8-hfs)
(setq file-name-coding-system 'utf-8-hfs)
(setq locale-coding-system 'utf-8-hfs))))
;=======================================================================
;フォント
;=======================================================================
(let ((ws window-system))
(cond ((eq ws 'w32)
(set-face-attribute 'default nil
:family "MigMix 1M" ;; 英数
:height 100))
((eq ws 'ns)
(set-face-attribute 'default nil
:family "MeiryoK_Gothic" ;; 英数
:height 140)
(set-fontset-font nil 'japanese-jisx0208 (font-spec :family "MeiryoK_Gothic"))))) ;; 日本語
(setq line-spacing 0)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; emacsシステム設定
;; テキストエンコーディングとしてUTF-8を優先使用
(prefer-coding-system 'utf-8)
;; 起動時のウィンドウサイズを設定
(if (boundp 'window-system)
(setq initial-frame-alist
(append (list
'(top . 50)
'(left . 150)
'(width . 150)
'(height . 45))
initial-frame-alist)))
(setq default-frame-alist initial-frame-alist)
;; 起動時のメッセージを非表示
(setq inhibit-startup-meesage t)
;; 改行コードを表示
(setq eol-mnemonic-dos "(CRLF)")
(setq eol-mnemonic-mac "(CR)")
(setq eol-mnemonic-unix "(LF)")
;; *scratch*を消さない
(defun my-make-scratch (&optional arg)
(interactive)
(progn
;; "*scratch*" を作成して buffer-list に放り込む
(set-buffer (get-buffer-create "*scratch*"))
(funcall initial-major-mode)
(erase-buffer)
(when (and initial-scratch-message (not inhibit-startup-message))
(insert initial-scratch-message))
(or arg (progn (setq arg 0)
(switch-to-buffer "*scratch*")))
(cond ((= arg 0) (message "*scratch* is cleared up."))
((= arg 1) (message "another *scratch* is created")))))
(add-hook 'kill-buffer-query-functions
;; *scratch* バッファで kill-buffer したら内容を消去するだけにする
(lambda ()
(if (string= "*scratch*" (buffer-name))
(progn (my-make-scratch 0) nil)
t)))
(add-hook 'after-save-hook
;; *scratch* バッファの内容を保存したら *scratch* バッファを新しく作る
(lambda ()
(unless (member (get-buffer "*scratch*") (buffer-list))
(my-make-scratch 1))))
;; beepを消す
(defun my-bl-function ()
(unless (memq this-command
'(isearch-abort abort-recursive-edit exit-minibuffer
keyboard-quit mwheel-scroll down up next-line previous-line
backward-char forward-char))
(ding)))
(setq ring-bell-function 'my-bell-function)
;; 矩形選択
(cua-mode t)
(setq cua-enable-cua-keys nil) ;; 変なキーバインド禁止
;;; .#* とかのバックアップファイルを作らない
(setq auto-save-default nil)
(setq delete-auto-save-files t)
(setq make-backup-files nil)
;;; リージョンマークに色つける
(setq transient-mark-mode t)
;;region選択状態でC-dで削除できるように。
(delete-selection-mode 1)
;;TAB幅の設定
(setq-default tab-width 4)
(setq tab-stop-list
'(2 4 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60))
(column-number-mode t)
(line-number-mode t)
;;TAB押下時バックスペースに置き換える
(setq-default indent-tabs-mode nil)
(setq indent-line-function 'indent-relative-maybe)
;;スクロールバーの設定
(setq truncate-partial-width-windows nil)
(set-scroll-bar-mode nil)
;; タイトルバーにファイルのフルパス表示
(setq frame-title-format
(format "%%f - Emacs@%s" (system-name)))
;; 1行ずつスクロール
(setq scroll-conservatively 35
scroll-margin 0
scroll-step 1)
(setq comint-scroll-show-maximum-output t) ;; shell-mode
;;====================
;; key
;;====================
;; \C-aでインデントを飛ばした行頭に移動
(defun beginning-of-indented-line (current-point)
"インデント文字を飛ばした行頭に戻る。ただし、ポイントから行頭までの間にインデント文字しかない場合は、行頭に戻る。"
(interactive "d")
(if (string-match
"^[ \t]+$"
(save-excursion
(buffer-substring-no-properties
(progn (beginning-of-line) (point))
current-point)))
(beginning-of-line)
(back-to-indentation)))
(defun beginning-of-visual-indented-line (current-point)
"インデント文字を飛ばした行頭に戻る。ただし、ポイントから行頭までの間にインデント文 字しかない場合は、行頭に戻る。"
(interactive "d")
(let ((vhead-pos (save-excursion (progn (beginning-of-visual-line) (point))))
(head-pos (save-excursion (progn (beginning-of-line) (point)))))
(cond
;; 物理行の1行目にいる場合
((eq vhead-pos head-pos)
(if (string-match
"^[ \t]+$"
(buffer-substring-no-properties vhead-pos current-point))
(beginning-of-visual-line)
(back-to-indentation)))
;; 物理行の2行目以降の先頭にいる場合
((eq vhead-pos current-point)
(backward-char)
(beginning-of-visual-indented-line (point)))
;; 物理行の2行目以降の途中にいる場合
(t (beginning-of-visual-line)))))
;; C-kで行全体を削除
(setq kill-whole-line t)
;;-------------------
;; key bind
;;-------------------
(define-key global-map (kbd "C-h") 'delete-backward-char) ; 削除
(define-key global-map (kbd "M-h") 'backward-kill-word) ; M-h delete back word
(define-key global-map (kbd "C-z") 'undo) ; undo
(define-key global-map (kbd "C-a") 'beginning-of-visual-indented-line)
(define-key global-map (kbd "C-e") 'end-of-visual-line)
(global-set-key "\C-x\C-l" 'clmemo) ;clmemo起動
(define-key global-map (kbd "M-?") 'help-for-help) ; ヘルプ
(define-key global-map (kbd "C-x C-b") 'bs-show) ; バッファ一覧をまともに
(define-key global-map [(f5)] 'compile) ;compile
;; rails-mode
;; (define-key rails-minor-mode-map "\C-c\C-p" 'rails-lib:run-primary-switch)
;; (define-key rails-minor-mode-map "\C-c\C-n" 'rails-lib:run-secondary-switch)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; elispの設定
;; menu-tree -----------------------------------
;; メニューバー日本語化
;; (if (and (= emacs-major-version 22)
;; (eq window-system 'x))
;; (setq menu-tree-coding-system 'utf-8))
;; (require 'menu-tree nil t)
;; auto-highlight-symbol
(require 'auto-highlight-symbol)
(global-auto-highlight-symbol-mode t)
;; auto-install ---------------------------------
(require 'auto-install)
(setq auto-install-directory "~/.emacs.d/elisp/")
(auto-install-update-emacswiki-package-name t)
(auto-install-compatibility-setup) ; 互換性確保
(require 'install-elisp)
(setq install-elisp-repository-directory "~/.emacs.d/elisp/")
;; auto-complete ---------------------------------
(require 'auto-complete)
;(global-auto-complete-mode t)
;;color themの設定
(require 'color-theme)
(color-theme-initialize)
(color-theme-tango)
;; YASnippet ---------------------------------
(add-to-list 'load-path
"~/.emacs.d/elisp/yasnippet")
(require 'yasnippet)
(setq yas/snippet-dirs "~/.emacs.d/elisp/yasnippet/snippets")
(yas/initialize)
(yas/load-directory "~/.emacs.d/elisp/yasnippet/snippets")
(setq yas/prompt-functions '(yas/dropdown-prompt))
;; 自動セーブ ---------------------------------
(require 'auto-save-buffers)
(run-with-idle-timer 0.5 t 'auto-save-buffers)
;;compile ----------------------------------------
(setq compilation-read-command nil)
(setq compile-command "nmake /NOLOGO ")
;;====================
;; Visual
;;====================
;; 余計なものを表示しない
(when window-system
(tool-bar-mode 0) ;; ツールバー
(toggle-scroll-bar nil)) ;; スクロールバー
;; キーワードのカラー表示を有効化
(global-font-lock-mode t)
;; 選択範囲をハイライト
(setq-default transient-mark-mode t)
;; 選択中のリージョンの色を設定します。
(set-face-background 'region "HotPink4")
;; 対応するカッコをハイライト
(show-paren-mode t)
;; カーソル行をハイライト
(defface hlline-face
'((((class color)
(background dark))
(:background "dark slate gray"))
(((class color)
(background light))
(:background "ForestGreen"))
(t
()))
"*Face used by hl-line.")
(setq hl-line-face 'hlline-face)
(global-hl-line-mode)
;; 行間
(setq-default line-spacing 0)
;; モードラインに行数と桁数を表示
(line-number-mode t)
(column-number-mode t)
;; モードラインの割合表示を総行数表示
(defvar my-lines-page-mode t)
(defvar my-mode-line-format)
(when my-lines-page-mode
(setq my-mode-line-format "%d")
(if size-indication-mode
(setq my-mode-line-format (concat my-mode-line-format " of %%I")))
(cond ((and (eq line-number-mode t) (eq column-number-mode t))
(setq my-mode-line-format (concat my-mode-line-format " (%%l,%%c)")))
((eq line-number-mode t)
(setq my-mode-line-format (concat my-mode-line-format " L%%l")))
((eq column-number-mode t)
(setq my-mode-line-format (concat my-mode-line-format " C%%c"))))
(setq mode-line-position
'(:eval (format my-mode-line-format
(count-lines (point-max) (point-min))))))
;; 行番号表示
(global-linum-mode t)
(set-face-attribute 'linum nil
:foreground "#1e90ff"
:height 0.9)
;;全角スペース/タブ文字を可視化
(defface my-face-b-1 '((t (:background "medium aquamarine"))) nil)
(defface my-face-b-2 '((t (:background "gray26"))) nil)
(defface my-face-u-1 '((t (:foreground "SteelBlue" :underline t))) nil)
(defvar my-face-b-1 'my-face-b-1)
(defvar my-face-b-2 'my-face-b-2)
(defvar my-face-u-1 'my-face-u-1)
(defadvice font-lock-mode (before my-font-lock-mode ())
(font-lock-add-keywords
major-mode
'(
(" " 0 my-face-b-1 append)
("\t" 0 my-face-b-2 append)
("[ ]+$" 0 my-face-u-1 append)
)))
(ad-enable-advice 'font-lock-mode 'before 'my-font-lock-mode)
(ad-activate 'font-lock-mode)
(add-hook 'find-file-hooks '(lambda ()
(if font-lock-mode
nil
(font-lock-mode t))) t)
;;====================
;; mode
;;====================
;; all
(setq skeleton-pair t)
(global-set-key (kbd "(") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "{") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "[") 'skeleton-pair-insert-maybe)
(global-set-key (kbd "\"") 'skeleton-pair-insert-maybe)
;; Emacs-Lisp
(add-hook 'elisp-mode-hook '(lambda () (setq tab-width 2)))
;; C++
(add-hook 'c++-mode-hook
'(lambda()
(c-set-style "k&r")
(setq tab-width 4)
(setq c-basic-offset 4)
))
;; -*- no-byte-compile: t -*-
(if (fboundp 'normal-top-level-add-subdirs-to-load-path)
(normal-top-level-add-subdirs-to-load-path))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment