Skip to content

Instantly share code, notes, and snippets.

@makoto-unity
Last active June 12, 2025 02:39
Show Gist options
  • Save makoto-unity/f3e9f635c34fa6cb032410d913e102cb to your computer and use it in GitHub Desktop.
Save makoto-unity/f3e9f635c34fa6cb032410d913e102cb to your computer and use it in GitHub Desktop.
;; 引数を load-path へ追加
;; normal-top-level-add-subdirs-to-load-path はディレクトリ中の中で
;; [A-Za-z] で開始する物だけ追加するので、追加したくない物は . や _ を先頭に付与しておけばロードしない
;; dolist は Emacs 21 から標準関数なので積極的に利用して良い
(defun add-to-load-path (&rest paths)
(let (path)
(dolist (path paths paths)
(let ((default-directory (expand-file-name (concat user-emacs-directory path))))
(add-to-list 'load-path default-directory)
(if (fboundp 'normal-top-level-add-subdirs-to-load-path)
(normal-top-level-add-subdirs-to-load-path))))))
;; Emacs Lisp のPathを通す
(add-to-load-path "lisp")
; 言語を日本語にする
(set-language-environment 'Japanese)
; 極力UTF-8とする
(prefer-coding-system 'utf-8)
; フォントを変更
(when (>= emacs-major-version 23)
(set-face-attribute 'default nil
:family "monaco"
:height 120)
(set-fontset-font
(frame-parameter nil 'font)
'japanese-jisx0208
'("Hiragino Maru Gothic Pro" . "iso10646-1"))
(set-fontset-font
(frame-parameter nil 'font)
'japanese-jisx0212
'("Hiragino Maru Gothic Pro" . "iso10646-1"))
(set-fontset-font
(frame-parameter nil 'font)
'mule-unicode-0100-24ff
'("monaco" . "iso10646-1"))
(setq face-font-rescale-alist
'(("^-apple-hiragino.*" . 1.2)
(".*osaka-bold.*" . 1.2)
(".*osaka-medium.*" . 1.2)
(".*courier-bold-.*-mac-roman" . 1.0)
(".*monaco cy-bold-.*-mac-cyrillic" . 0.9)
(".*monaco-bold-.*-mac-roman" . 0.9)
("-cdac$" . 1.3))))
;; ウィンドウ分割
;(global-set-key "M-1" 'delete-other-windows)
;(global-set-key "M-2" 'split-window-vertically)
;(global-set-key "M-3" 'split-window)
;(global-set-key "M-0" 'delete-window)
;(define-key ctl-x-map #\3 'split-window-vertically)
;========================================
; 他のウィンドウの内容をカレントウィンドウと同じにする
;========================================
(defun buffer-opposite()
(interactive)
(delete-other-windows)
(split-window-horizontally))
(global-set-key (kbd "C-x 4") 'buffer-opposite)
;========================================
; バッファを殺す
;========================================
(global-set-key (kbd "C-z") 'kill-buffer )
;; ファンクションキー
;(global-set-key #\F1
; #'(lambda ()
; (interactive "p")
; (pop-to-buffer "*Command Output*")
; (beginning-of-buffer)
; (first-error)))
;(global-set-key #\F1 'first-error)
;(global-set-key #\F2 'next-error)
;(global-set-key #\F3 'jump-tag)
;(global-set-key #\S-F3 'back-tag-jump)
;(global-set-key #\F4 'toggle-comment)
;(global-set-key #\F5 'set-mark-command)
;(global-set-key #\F6 'my-cut)
;(global-set-key #\F7 'my-copy)
(global-set-key (kbd "<f8>") 'yank)
(global-set-key (kbd "<f10>") 'start-kbd-macro)
(global-set-key (kbd "<f11>") 'end-kbd-macro)
(global-set-key (kbd "<f12>") 'call-last-kbd-macro)
;; カラーテーマ
;; Color theme
;; lisp/color-theme.el
(require 'color-theme)
(eval-after-load "color-theme"
'(progn
(color-theme-initialize)
(color-theme-hober)))
(if (eq (window-system) 'ns)
(progn
(add-to-list 'default-frame-alist '(width . 180))
(add-to-list 'default-frame-alist '(height . 47))
(add-to-list 'default-frame-alist '(top . 0))
(add-to-list 'default-frame-alist '(left . 0))))
;========================================
; 同ウインドウ内のアクティブバッファの移動
;========================================
(global-set-key (kbd "M-O") 'other-window)
;========================================
; バッファきりかえ
;========================================
(global-set-key (kbd "M-B") 'switch-to-buffer)
;========================================
; 履歴を次回Emacs起動時にも保存する
;========================================
(savehist-mode 1)
;========================================
; 場所を覚えておく
;========================================
(setq-default save-place t)
;========================================
; 最近開いたファイルを保存する数を増やす
;========================================
(setq recentf-max-saved-items 10000)
;====================================
; 最近使ったファイル」を(メニューに)表示する
;====================================
; M-x recentf-open-files で履歴一覧バッファが表示される。
(require 'recentf)
;;http://homepage.mac.com/zenitani/elisp-j.html#recentf
(setq recentf-auto-cleanup 'never) ;;tramp対策。
(recentf-mode 1)
;====================================
; CTRL+/ でアンドゥ
;====================================
; lisp/redo.el
(require 'redo)
(global-set-key (kbd "C-/") 'undo)
(global-set-key (kbd "C-.") 'redo)
(global-set-key (kbd "C-x C-r") 'recentf-open-files)
;====================================
; ドラッグドロップ
;====================================
(define-key global-map [ns-drag-file] 'ns-find-file)
;====================================
;; C# support
;====================================
;; lisp/csharp-mode.el
(autoload 'csharp-mode "csharp-mode" "Major mode for editing C# code." t)
(setq auto-mode-alist (cons '("\\.cs$" . csharp-mode) auto-mode-alist))
;====================================
;; Obj-C support
;====================================
(add-to-list 'magic-mode-alist '("\\(.\\|\n\\)*\n@implementation" . objc-mode))
(add-to-list 'magic-mode-alist '("\\(.\\|\n\\)*\n@interface" . objc-mode))
(add-to-list 'magic-mode-alist '("\\(.\\|\n\\)*\n@protocol" . objc-mode))
(add-hook 'c-mode-common-hook
'(lambda()
(c-set-style "cc-mode")))
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)
;; Patterns for finding Microsoft C# compiler error messages:
(require 'compile)
(push '("^\\(.*\\)(\\([0-9]+\\),\\([0-9]+\\)): error" 1 2 3 2) compilation-error-regexp-alist)
(push '("^\\(.*\\)(\\([0-9]+\\),\\([0-9]+\\)): warning" 1 2 3 1) compilation-error-regexp-alist)
;; Patterns for defining blocks to hide/show:
(push '(csharp-mode
"\\(^\\s *#\\s *region\\b\\)\\|{"
"\\(^\\s *#\\s *endregion\\b\\)\\|}"
"/[*/]"
nil
hs-c-like-adjust-block-beginning)
hs-special-modes-alist)
;====================================
; Alt+r で全置換
;====================================
(global-set-key (kbd "M-r") 'replace-string)
;====================================
;;php-mode
;====================================
;; lisp/php-mode.el
(autoload 'php-mode "php-mode" "Major mode for editing PHP code." t)
(setq auto-mode-alist (cons '("\\.php$" . php-mode) auto-mode-alist))
;;複数ウィンドウを開かないようにする
(setq ns-pop-up-frames nil)
;; ツールバーをオフ
(tool-bar-mode -1)
;;; counter.el
(global-set-key "\C-cc" 'counter)
(autoload 'counter "counter" nil t)
(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.
'(warning-suppress-log-types
'(((unlock-file))
((unlock-file))
((unlock-file))
((unlock-file))
((unlock-file))
((unlock-file))))
'(warning-suppress-types
'(((unlock-file))
((unlock-file))
((unlock-file))
((unlock-file))
((unlock-file)))))
(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