Skip to content

Instantly share code, notes, and snippets.

@tksmiura
Last active March 17, 2024 11:53
Show Gist options
  • Save tksmiura/06b505c73038615308c7ecae65f727f6 to your computer and use it in GitHub Desktop.
Save tksmiura/06b505c73038615308c7ecae65f727f6 to your computer and use it in GitHub Desktop.
dot_emacs_mac
(save-place-mode 1)
(add-hook 'before-save-hook 'delete-trailing-whitespace)
; menu-bar off
;(tool-bar-mode 0)
(menu-bar-mode 0)
; package
(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)
;(exec-path-from-shell-initialize)
;(server-start)
;markdown
;(autoload 'markdown-mode "markdown-mode.el" "Major mode for editing Markdown files" t)
;(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
; shell path設定(http://qiita.com/catatsuy/items/3dda714f4c60c435bb25)
;; (defun set-exec-path-from-shell-PATH ()
;; "Set up Emacs' `exec-path' and PATH environment variable to match that used by the user's shell.
;; This is particularly useful under Mac OSX, where GUI apps are not started from a shell."
;; (interactive)
;; (let ((path-from-shell (replace-regexp-in-string "[ \t\n]*$" "" (shell-command-to-string "$SHELL --login -i -c 'echo $PATH'"))))
;; (setenv "PATH" path-from-shell)
;; (setq exec-path (split-string path-from-shell path-separator))))
;; (set-exec-path-from-shell-PATH)
; current dir
(setq inhibit-splash-screen t)
(defun cd-to-homedir-all-buffers ()
"Change every current directory of all buffers to the home directory."
(mapc
(lambda (buf) (set-buffer buf) (cd (expand-file-name "~"))) (buffer-list)))
(add-hook 'after-init-hook 'cd-to-homedir-all-buffers)
;; macフォント設定(簡易版)
;(if (eq window-system 'mac) (require 'carbon-font))
;;;(fixed-width-set-fontset "hiramaru" 12)
;(fixed-width-set-fontset "osaka" 14)
;;; 初期フレームの設定
(setq initial-frame-alist
(append
'((top . 0) ; フレームの Y 位置(ピクセル数)
(left . 0) ; フレームの X 位置(ピクセル数)
(width . 100) ; フレーム幅(文字数)
(height . 35)) ; フレーム高(文字数)
initial-frame-alist))
;;; 新規フレームのデフォルト設定
(setq default-frame-alist
(append
'((width . 80)
(height . 30)) ; フレーム高(文字数)
default-frame-alist))
;;elisp load-path
(setq load-path
(append
(list
(expand-file-name "~/site-lisp/")
)
load-path))
;; spaceで補完
(if (boundp 'minibuffer-local-filename-completion-map)
(progn
(define-key minibuffer-local-filename-completion-map
" " 'minibuffer-complete-word)))
;; for perl
(add-hook 'perl-mode-hook '(lambda ()
(setq tab-width 4
indent-tabs-mode nil
comment-column 65)
) t)
;;; for C++-mode
(defconst my-c-style
'((c-tab-always-indent . nil)
(c-comment-only-line-offset . 4)
(c-hanging-braces-alist . ((substatement-open after)
(brace-list-open)))
(c-hanging-colons-alist . ((member-init-intro before)
(inher-intro)
(case-label after)
(label after)
(access-label after)))
(c-cleanup-list . (scope-operator
empty-defun-braces
defun-close-semi))
(c-offsets-alist . ((arglist-close . c-lineup-arglist)
(substatement-open . 0)
(case-label . 2)
(statement-case-intro . 2)
(comment-intro . 0)
(block-open . 0)
(knr-argdecl-intro . -)))
(c-echo-syntactic-information-p . t)
)
"My C Programming Style")
;; Customizations for all of c-mode, c++-mode, and objc-mode
(defun my-c-mode-common-hook ()
;; add my personal style and set it for the current buffer
(c-add-style "PERSONAL" my-c-style t)
;; offset customizations not in my-c-style
(c-set-offset 'member-init-intro '++)
;; other customizations
(setq tab-width 4
;; this will make sure spaces are used instead of tabs
indent-tabs-mode nil)
;; we like auto-newline and hungry-delete
;; (c-toggle-auto-hungry-state 1)
;; keybindings for all supported languages. We can put these in
;; c-mode-base-map because c-mode-map, c++-mode-map, objc-mode-map,
;; java-mode-map, and idl-mode-map inherit from it.
(define-key c-mode-base-map "\C-m" 'newline-and-indent)
(make-local-variable 'compile-command)
(setq compile-command "make ")
(setq compilation-scroll-output t)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
(setq compilation-scroll-output t)
;;
;; Outline Mode for *.txt
;;http://www.bookshelf.jp/soft/meadow_35.html#IDX349 参考
(add-hook 'outline-mode-hook
(function
(lambda ()
(setq outline-regexp "[  \t]*\\(■\\|・\\|-\\|\\+\\|http:\\)")
(setq outline-level
(function
(lambda ()
(save-excursion
(let ((str nil))
(looking-at outline-regexp)
(setq str
(buffer-substring-no-properties
(match-beginning 0) (match-end 0)))
(cond
((string-match "■" str)
;; 階層 1 を返す
1)
((string-match "・" str)
2)
((string-match "-" str)
3)
((string-match "+" str)
3)
((string-match "http:" str)
4)
))))))
;; imenu
(make-local-variable 'imenu-generic-expression)
(setq imenu-generic-expression
'((nil "■\\(.*\\)" 1)))
(make-local-variable 'imenu-sort-function)
(setq imenu-sort-function nil)
(make-local-variable 'font-lock-defaults))))
(setq auto-mode-alist
(cons (cons "\\.txt$" 'outline-mode) auto-mode-alist))
;;
;; KEY BINDING
;;
(global-set-key "\C-h" 'backward-delete-char-untabify)
(global-set-key "\C-w" 'other-window)
(global-set-key "\C-z" 'scroll-up)
(global-set-key "\C-q" 'scroll-down)
(global-set-key "\C-v" 'quoted-insert)
(global-set-key "\C-u" 'undo)
(global-set-key "\C-o" 'copy-line-as-kill)
(global-set-key "\C-^" 'enlarge-window)
(global-set-key "\C-x\C-c" 'suspend-emacs)
(global-set-key "\C-x\C-u" 'backward-upcase-word)
(global-set-key "\C-x\C-t" 'find-tag-other-window)
(global-set-key "\C-x\C-e" 'abbrev-prefix-mark)
(global-set-key "\C-x\C-d" 'kill-word)
(global-set-key "\C-x\C-h" 'backward-kill-word)
(global-set-key "\C-x\C-j" 'backward-kill-line)
(global-set-key "\C-x\C-k" 'kill-region)
(global-set-key "\C-x\C-l" 'unexpand-abbrev)
(global-set-key "\C-x\C-n" 'next-error)
(global-set-key "\C-x\C-p" 'copy-region-as-kill)
(global-set-key "\C-x\C-v" 'find-file-other-window)
(global-set-key "\C-x\C-w" 'dabbrev-expand)
(global-set-key "\C-x\C-y" 'yank-pop)
(global-set-key "\C-xf" 'fill-paragraph)
(global-set-key "\C-xh" 'help-for-help)
(global-set-key "\C-xc" 'save-buffers-kill-emacs)
(global-set-key "\C-xo" 'occur)
(global-set-key "\C-x " 'just-one-space)
(global-set-key "\C-[a" 'abbrev-mode)
(global-set-key "\C-[b" 'backward-word)
(global-set-key "\C-[f" 'forward-word)
(global-set-key "\C-[c" 'compile)
(global-set-key "\C-[g" 'goto-line)
;;(define-key c-mode-map "\C-[m" 'mark-c-function)
(global-set-key "\C-[i" 'indent-region)
(global-set-key "\C-[t" 'find-other-tag)
(global-set-key "\C-[o" 'outline-mode)
(global-set-key "\C-[p" 'mark-paragraph)
(global-set-key "\C-[r" 'repeat-complex-command)
(global-set-key "\C-[s" 'save-some-buffers)
(global-set-key "\C-[z" 'forward-paragraph)
(global-set-key "\C-[q" 'backward-paragraph)
(global-set-key "\C-[w" 'write-file)
(global-set-key "\C-[e" 'previous-line)
(global-set-key "\C-[d" 'next-line)
(global-set-key "\C-[s" 'backward-char)
;;; MY COMMANDS
(fset 'backward-upcase-word "\C-[b\C-[u")
(fset 'copy-line-as-kill "\C-@\C-@\C-e\C-x\C-p")
(fset 'backward-kill-line "\C-@\C-@\C-a\C-x\C-k")
(fset 'find-other-tag "\C-[4\C-t")
(fset 'ring-mark "\C-[4\C-@\C-@")
(defun cpp-abbrev-hook ()
(if (save-excursion
(beginning-of-line)
(and (re-search-forward "^#[ \t]*" nil t)
(= (point) last-abbrev-location) ))
nil
(unexpand-abbrev) ))
(defun tex-abbrev-hook ()
(if (save-excursion
(beginning-of-line)
(and (re-search-forward "\\\\" nil t)
(= (point) last-abbrev-location) ))
nil
(unexpand-abbrev) ))
(fset 'occur-remark
"\C-[<\C-xo^[ ]*/\C-m\C-x\C-x")
(defun open-next-line ()
"Open next line as same indent.
If current line is blank then delete."
(interactive)
(end-of-line)
(skip-chars-backward " \t")
(kill-line)
(open-line 1)
(auto-indent)
)
(defun scroll-down-next-window ()
"Scroll down next window."
(interactive)
(other-window 1)
(scroll-down)
(other-window -1)
)
(defun scroll-up-next-window ()
"Scroll up next window."
(interactive)
(other-window 1)
(scroll-up)
(other-window -1)
)
(setq time-stamp-start "\*\*[ \t]+DATE[ \t]+= ")
(setq time-stamp-end " ;")
(setq time-stamp-format '(time-stamp-yy/mm/dd))
(put 'narrow-to-region 'disabled nil)
(put 'eval-expression 'disabled nil)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;バッファの切り替え
;;http://d.hatena.ne.jp/goryugo/20080422/1208801683
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar my-ignore-blst ; 移動の際に無視するバッファのリスト
'("*Help*" "*Compile-Log*" "*Mew completions*" "*Completions*"
"*Shell Command Output*" "*Apropos*" "*Buffer List*" "*GNU Emacs*"
".howm-keys" "*Messages*" "*SimpleHatena*" ".howm-history"))
(defvar my-visible-blst nil) ; 移動開始時の buffer list を保存
(defvar my-bslen 15) ; buffer list 中の buffer name の最大長
(defvar my-blist-display-time 10) ; buffer list の表示時間
(defface my-cbface ; buffer list 中で current buffer を示す face
'((t (:foreground "wheat" :underline t))) nil)
(defun my-visible-buffers (blst)
(if (eq blst nil) '()
(let ((bufn (buffer-name (car blst))))
(if (or (= (aref bufn 0) ? ) (member bufn my-ignore-blst))
;; ミニバッファと無視するバッファには移動しない
(my-visible-buffers (cdr blst))
(cons (car blst) (my-visible-buffers (cdr blst)))))))
(defun my-show-buffer-list (prompt spliter)
(let* ((len (string-width prompt))
(str (mapconcat
(lambda (buf)
(let ((bs (copy-sequence (buffer-name buf))))
(when (> (string-width bs) my-bslen) ;; 切り詰め
(setq bs (concat (substring bs 0 (- my-bslen 2)) "..")))
(setq len (+ len (string-width (concat bs spliter))))
(when (eq buf (current-buffer)) ;; 現在のバッファは強調表示
(put-text-property 0 (length bs) 'face 'my-cbface bs))
(cond ((>= len (frame-width)) ;; frame 幅で適宜改行
(setq len (+ (string-width (concat prompt bs spliter))))
(concat "\n" (make-string (string-width prompt) ? ) bs))
(t bs))))
my-visible-blst spliter)))
(let (message-log-max)
(message "%s" (concat prompt str))
(when (sit-for my-blist-display-time) (message nil)))))
(defun my-operate-buffer (pos)
(unless (window-minibuffer-p (selected-window));; ミニバッファ以外で
(unless (eq last-command 'my-operate-buffer)
;; 直前にバッファを切り替えてなければバッファリストを更新
(setq my-visible-blst (my-visible-buffers (buffer-list))))
(let* ((blst (if pos my-visible-blst (reverse my-visible-blst))))
(switch-to-buffer (or (cadr (memq (current-buffer) blst)) (car blst))))
(my-show-buffer-list (if pos "[-->] " "[<--] ") (if pos " > " " < " )))
(setq this-command 'my-operate-buffer))
(global-set-key [?\C-,] (lambda () (interactive) (my-operate-buffer nil)))
(global-set-key [?\C-.] (lambda () (interactive) (my-operate-buffer t)))
(global-set-key "\C-t" 'find-tag)
(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.
'(gud-gdb-command-name "gdb --annotate=1")
'(large-file-warning-threshold nil)
'(package-selected-packages (quote (trr exec-path-from-shell))))
(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.
'(font-lock-function-name-face ((((class color) (min-colors 88) (background light)) (:foreground "cyan"))))
'(minibuffer-prompt ((t (:foreground "cyan"))))
'(mode-line ((((class color) (min-colors 88)) (:background "brightwhite" :foreground "black" :box (:line-width -1 :style released-button)))))
'(mode-line-inactive ((default (:inherit mode-line)) (((class color) (min-colors 88) (background light)) (:background "color-253" :foreground "grey20" :box (:line-width -1 :color "white") :weight light)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment