Skip to content

Instantly share code, notes, and snippets.

@itouhiro
Last active December 23, 2015 14:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itouhiro/6650379 to your computer and use it in GitHub Desktop.
Save itouhiro/6650379 to your computer and use it in GitHub Desktop.
put it in $HOME/.emacs.d/
;;; -*- mode: lisp-interaction; syntax: elisp -*-
;; Time-stamp: <Sep 15 2013>
;; ------------------------------------------------------------------------
;; @ keyset
(global-set-key "\C-h" 'backward-delete-char) ;C-h as BackSpace
(global-set-key "\M-?" 'help-for-help) ;M-? as help
(global-set-key "\C-q" 'dabbrev-expand)
;(global-set-key "\C-q" 'quoted-insert) ;C-q original
(global-set-key "\C-x\C-b" 'buffer-menu)
(global-set-key "\C-z" 'scroll-down)
;(global-set-key "\C-z" 'suspend-frame) ; C-z original
;; コンテキスト依存バッファ移動
;; 画面分割されていない→分割して新しいバッファに移動
;; 分割されている→別バッファに移動
;; http://d.hatena.ne.jp/rubikitch/20100210/emacs
(defun other-window-or-split ()
(interactive)
(cond ((one-window-p)
(split-window)
(other-window 1)
(buffer-menu)
)
(t
(other-window 1))))
(global-set-key (kbd "C-t") 'other-window-or-split)
;; 編集中のファイルを開き直す
;; http://www.bookshelf.jp/soft/meadow_24.html#SEC254
;; - revert-buffer は yes/no の確認がうるさい
;; - find-alternate-file は開き直したら元のバッファの状態に戻れない
(defun reopen-file ()
(interactive)
(let ((file-name (buffer-file-name))
(old-supersession-threat
(symbol-function 'ask-user-about-supersession-threat))
(point (point)))
(when file-name
(fset 'ask-user-about-supersession-threat (lambda (fn)))
(unwind-protect
(progn
(erase-buffer)
(insert-file file-name)
(set-visited-file-modtime)
(goto-char point))
(fset 'ask-user-about-supersession-threat
old-supersession-threat)))))
(global-set-key "\C-xR" 'reopen-file)
;; ------------------------------------------------------------------------
;; @ display
(setq inhibit-startup-message t) ; スプラッシュ(起動画面)非表示
(menu-bar-mode -1) ; erase memubar, scrollbar(icon)
(line-number-mode t) ; 行番号の表示
(column-number-mode t) ; 列番号の表示
;(scroll-bar-mode -1) ; 画面横に出るスクロールバーを消す
(transient-mark-mode -1) ; 選択したとき色がつかないようにする
(setq diff-switches "-u") ; diff
(setq cursor-in-non-selected-windows nil) ;入力バッファ以外はカーソル非表示
(setq visible-bell nil) ; beep
(cond (window-system
(tool-bar-mode 0) ; tool-bar を消す
(blink-cursor-mode nil) ; カーソルを点滅させない
;(setq scalable-fonts-allowed nil) ; フォントのスケーラブルをしない
))
;; elisp変数表示のとき途中で省略しない
(setq eval-expression-print-level nil)
(setq eval-expression-print-length nil)
;; ------------------------------------------------------------------------
;; @ color
(setq transient-mark-mode t) ; リージョンに色をつける
(global-font-lock-mode t) ; font-lock use-all
(setq font-lock-maximum-decoration
'((c-mode . 1) (c++-mode . 1))) ;level of fontification: least level
;; タブ, 全角スペースを色つき表示 (色名は M-x list-color-displayで調べる)
;; http://homepage1.nifty.com/blankspace/emacs/color.html
(defface my-face-b-1 '((t (:background "gray15"))) nil)
(defface my-face-b-2 '((t (:background "gray26"))) nil)
(defface my-face-u-1 '((t (:foreground "DarkSlateBlue" :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
'(("\t" 0 my-face-b-2 append)
(" " 0 my-face-b-1 append)
("[ \t]+$" 0 my-face-u-1 append)
;;("[\r]*\n" 0 my-face-r-1 append)
)))
(ad-enable-advice 'font-lock-mode 'before 'my-font-lock-mode)
(ad-activate 'font-lock-mode)
;; kill-ring でテキスト属性(色情報など)を保存しない
;; http://www-tsujii.is.s.u-tokyo.ac.jp/~yoshinag/tips/elisp_tips.html#yankoff
(defadvice kill-new (around my-kill-ring-disable-text-property activate)
(let ((new (ad-get-arg 0)))
(set-text-properties 0 (length new) nil new)
ad-do-it))
;; ------------------------------------------------------------------------
;; @ operation
;[TAB]キー押下時にTabではなくスペース入力
(setq-default indent-tabs-mode nil)
;; 前回編集していた場所を記憶し,ファイルを開いた時にそこへカーソルを移動
(load "saveplace")
(setq-default save-place t)
;; dired バッファを編集(一括ファイル名リネーム)
(require 'wdired)
(define-key dired-mode-map "r" 'wdired-change-to-wdired-mode)
;; grep で絞り込んだ行を、そのバッファ内で直接編集
(require 'wgrep nil t)
(setq wgrep-enable-key "r")
;; file名の補完で大文字小文字を区別しない
(setq completion-ignore-case t)
;; バッファ自動再読み込み
(global-auto-revert-mode 1)
;; auto-insert LAST-MODIFIED-DATEn
(if (not (memq 'time-stamp write-file-hooks))
(setq write-file-hooks
(cons 'time-stamp write-file-hooks)))
(setq time-stamp-line-limit 40)
(setq system-time-locale "C")
(setq time-stamp-format "%3b %02d %:y") ; Jan 22 2012
;(setq time-stamp-format "%:y-%02m-%02d %02H:%02M JST") ;2010-11-19 09:27 JST
;(setq time-stamp-format "%:y-%02m-%02dT%02H:%02M:%02S+09:00") ;2010-11-19T09:27:32+09:00
;; insert-current-time-string
(defun insert-current-day-string ()
"Inserts current time string at point."
(interactive)
(move-beginning-of-line nil) ;行頭に移動
(goto-char (point-min)) ;buffer先頭に移動
(setq insert-current-time-wday (vector '日 '月 '火 '水 '木 '金 '土))
(insert (format "%s(%s)\n%s "
(format-time-string "%Y-%02m-%d")
(aref insert-current-time-wday (string-to-int (format-time-string "%w")))
(format-time-string "%H:%M"))))
(defun insert-current-time-string ()
"Inserts current time string at point."
(interactive)
(insert (format "%s " (format-time-string "%H:%M"))))
(global-set-key "\C-xT" 'insert-current-day-string)
(global-set-key "\C-xt" 'insert-current-time-string)
;; distinguishing Emacsen
(cond
((and (equal system-type 'windows-nt) (= emacs-major-version 24))
(load "~/.emacs.d/ntemacs24.el"))
((and (equal system-type 'windows-nt) (= emacs-major-version 23))
(load "~/.emacs.d/ntemacs23.el"))
((= emacs-major-version 24)
(load "~/.emacs.d/emacs24.el"))
((= emacs-major-version 23)
(load "~/.emacs.d/emacs23.el"))
((= emacs-major-version 22)
(load "~/.emacs.d/emacs22.el")))
;; end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment