commit be5766309dca945f026a844e29e714c348c05f50 Author: 10sr Date: Thu Sep 15 22:13:49 2011 +0900 first commit diff --git a/.bashrc b/.bashrc new file mode 100755 index 0000000..2ccf463 --- /dev/null +++ b/.bashrc @@ -0,0 +1,230 @@ +#!/bin/bash +# 外部ファイルの読み込み +# test -r ~/filepath && . ~/filepath +# ln SRC DST +########################################## +test -r /etc/bashrc && . /etc/bashrc + +# export PS1="\[\e[32m\]\u@\H \[\e[33m\]\w\[\e[0m\] \d \t\n\s \# \j \$ " +# export PS1="[\[\e[33m\]\w\[\e[0m\]]\n\[\e[32m\]\u@\H\[\e[0m\] \d \t \s.\v\nhist:\# jobs:\j \$ " +export PS1="\$(prompt_function)\$ " +# PROMPT_COMMAND=prompt_function +export PAGER="less" +export EDITOR="vim" +export VISUAL=$EDITOR +export LESS="-M" +# export LC_MESSAGES="C" +# export LANG=ja_JP.UTF-8 +# export CDPATH=".:~" # 使い方がよく分からない +export GIT_PAGER=$PAGER +export GIT_EDITOR=$EDITOR + +mkunfddir(){ # create dir if unfound. ? + test -e "$1" || mkdir "$1" +} +if test "${TERM}" == dumb +then + alias ls="ls -CFG --time-style=long-iso" +else + alias ls="ls -CFG --color=auto --time-style=long-iso" +fi +alias ll="ls -l" +alias la="ls -A" +alias lla="ls -Al" +alias vl=/usr/share/vim/vimcurrent/macros/less.sh +alias emacs="emacs -nw" +alias aptin="sudo apt-get install" +alias ut="slogin t110414@un001.ecc.u-tokyo.ac.jp" +alias rand="echo \$RANDOM" +alias xunp="file-roller -h" +alias pacome="sudo \paco -D" +# type trash >/dev/null 2>&1 && alias rm=trash +o(){ + if [ $# -eq 0 ]; then + local f=. + else + local f="$1" + fi + if iswindows; then + cmd.exe //c start "" "$f" + elif isdarwin; then + open "$f" + else + xdg-open "$f" + fi +} +sgcc(){ + if iswindows; then + gcc -o win.$1.exe $1 + else + gcc -o $(uname).$1.out $1 + fi +} +sggcc(){ + gcc -g -o $(uname).$1.out $1 +} +slmggcc(){ + gcc -g -lm -o $(uname).$1.out $1 +} +convmv-sjis2utf8-test(){ + convmv -r -f sjis -t utf8 * +} +convmv-sjis2utf8-notest(){ + convmv -r -f sjis -t utf8 * --notest +} +dl-my-init-files(){ + for file in .bashrc .vimrc .emacs + do + local flag=0 + if test -f ~/${file}.new + then + mv ~/${file}.new ~/${file}.old + echo "${file}.new already exist. Rename it to ${file}.old." + flag=1 + fi + wget https://dl.dropbox.com/u/1751156/${file} -O ~/${file}.new + local wgetreturn=$? + if test ${flag} -eq 1 -a ${wgetreturn} -eq 0 + then + rm ~/${file}.old + echo "${file}.old deleted." + fi + done +} +port-auto(){ + port selfupdate && port sync && port upgrade installed +} + +prompt_function(){ # used by PS1 + local lastreturn=$? + if test "${TERM}" == dumb + then + local c1="" + local c2="" + local cdef="" + else + local c1="\e[33m" + local c2="\e[32m" + local cdef="\e[0m" + fi + local pwd=$(echo "${PWD}/" | sed -e "s:${HOME}:~:") + local date=$(LANG=C date +"%a, %d %b %Y %T %z") + local jobnum=$(jobs | wc -l) + type __git_ps1 >/dev/null 2>&1 && local gitb=$(__git_ps1 GIT:%s) + type git >/dev/null 2>&1 && local git="[${gitb}]" + printf " [${c1}${pwd}${cdef}]${git}\n" + printf "${c2}${USERNAME}@${HOSTNAME}${cdef} ${date} ${BASH} ${BASH_VERSION}\n" + printf "jobs:${jobnum} last:${lastreturn} " +} + +# type date >/dev/null 2>&1 || alias date=":" # "cmd /c echo %time%" + +if [ "${EMACS}" = "t" ]; then # emacs shell用 + export PS1="\u@\H \d \t \w\nemacs shell\$ " +elif echo "$EMACS" | grep term >/dev/null 2>&1; then # emacs term用 + echo "emacs term" +fi + +# #Change ANSI Colors +# if [ $TERM = "xterm" ] +# then +# echo -e \ +# "\e]P0000000" \ +# "\e]P1cd0000" \ +# "\e]P200cd00" \ +# "\e]P3cdcd00" \ +# "\e]P41e90ff" \ +# "\e]P5cd00cd" \ +# "\e]P600cdcd" \ +# "\e]P7353535" \ +# "\e]P8666666" \ +# "\e]P9ff9999" \ +# "\e]Pa99ff99" \ +# "\e]Pbffff99" \ +# "\e]Pc9999ff" \ +# "\e]Pdff99ff" \ +# "\e]Pe99ffff" \ +# "\e]Pfffffff" +# fi + +# printf "\e]P7353535" \ + +_echocolors(){ + echo -e \ + "\e[30mBlack\n" \ + "\e[31mRed\n" \ + "\e[32mGreen\n" \ + "\e[33mYellow\n" \ + "\e[34mBlue\n" \ + "\e[35mMagenta\n" \ + "\e[36mCyan\n" \ + "\e[37mWhite\n" \ + "\e[30;1mBright Black\n" \ + "\e[31;1mBright Red\n" \ + "\e[32;1mBright Green\n" \ + "\e[33;1mBright Yellow\n" \ + "\e[34;1mBright Blue\n" \ + "\e[35;1mBright Magenta\n" \ + "\e[36;1mBright Cyan\n" \ + "\e[37;1mBright White\n" \ + "\e[0m" +} + + +########################## +# system type +# $OSTYPEとか使えるのかな + +iswindows(){ + uname | grep -iE 'windows|MINGW' >/dev/null 2>&1 +} + +isdarwin(){ + uname | grep -E 'Darwin' >/dev/null 2>&1 +} + +######################### +# for windose + +winln(){ + if [ $# -eq 0 ]; then + echo "usage: winln TARGET LINK_NAME" + echo "Create a link to TARGET with the name LINK_NAME (that is, TARGET must already exist)." + echo "About other features run 'junction'." + return 1 + else + junction "$2" "$1" + fi +} + +######################## +if [ "${CYGWIN}" = "t" ]; then # cygwin判定ってどうやるんだろ 多分unameとか使う + # for cygwin + export TMP=/tmp + export TEMP=/tmp + catclip(){ + cat /dev/clipboard | tr -d \\r + } + setclip(){ + if [ $# -eq 0 ]; then # 引数があるかを判定 + sed -e 's/$/\r/' | tee /dev/clipboard + else + cat $1 | sed -e 's/$/\r/' | tee /dev/clipboard + fi + } + # alias setclip="tee /dev/clipboard" + # alias catclip="cat /dev/clipboard | tr -d \\r" + alias cygsu="cygstart /cygwinsetup.exe" + alias emacs="CYGWIN=tty emacs" + echo "cygwin bash" +fi + +echo "Japanese letters are 表示可能" + +####################### + +type diskinfo >/dev/null 2>&1 && diskinfo + +finger sr +LANG=C id + diff --git a/.emacs b/.emacs new file mode 100644 index 0000000..0ae18f2 --- /dev/null +++ b/.emacs @@ -0,0 +1,1816 @@ +;; 外部ファイル読み込み +;; (load-file "~/filepath") + +;; (thing-at-point 'word) +;; (define-generic-mode) + +(unless (file-directory-p (expand-file-name "~/.emacs.d")) + (make-directory (expand-file-name "~/.emacs.d"))) +(unless (file-directory-p (expand-file-name "~/.emacs.d/lisp")) + (make-directory (expand-file-name "~/.emacs.d/lisp"))) +(add-to-list 'load-path "~/.emacs.d/lisp") +(add-to-list 'load-path "~/dbx/Public/myelisp") + +(require 'cl) + +(defvar my-prefix-map + (make-sparse-keymap)) +(global-set-key (kbd "C-z") my-prefix-map) +(define-key my-prefix-map (kbd "C-z") 'suspend-frame) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; start and quit + +(setq inhibit-startup-message t) +(setq frame-title-format (list '(:eval (my-format-time-string)) + " | %b " + '(:eval (number-to-string (length (buffer-list-not-start-with-space)))) + " buffers [" + invocation-name + " " + emacs-version + " " + (symbol-name system-type) + "] " + '(:eval (symbol-name last-command)))) +(defun buffer-list-not-start-with-space () + (let ((bl (buffer-list)) + b nbl) + (while bl + (setq b (pop bl)) + (unless (string-equal " " + (substring (buffer-name b) + 0 + 1)) + (add-to-list 'nbl b))) + nbl)) +(setq confirm-kill-emacs 'y-or-n-p) +(setq gc-cons-threshold (* 1024 1024 4)) +(when window-system + (add-to-list 'default-frame-alist '(cursor-type . box)) + (add-to-list 'default-frame-alist '(background-color . "white")) + (add-to-list 'default-frame-alist '(foreground-color . "gray10")) + (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))) ;聞いてないみたい +(if window-system (menu-bar-mode 1) (menu-bar-mode 0)) +(tool-bar-mode 0) +(set-scroll-bar-mode nil) +(add-hook 'kill-emacs-hook ; 終了時に読み込んで壊れてないか調べる + (lambda () + (when (file-readable-p "~/.emacs") + (load-file "~/.emacs")))) + +(when (eq system-type 'Darwin) + (mac-set-input-method-parameter ’japanese ’cursor-color ”red”) + (mac-set-input-method-parameter ’roman ’cursor-color ”black”)) + +(when (and (boundp 'input-method-activate-hook) ;ちょっと正しいかわかんない + (boundp 'input-method-inactivate-hook)) + (add-hook 'input-method-activate-hook + (lambda () (set-cursor-color "red"))) + (add-hook 'input-method-inactivate-hook + (lambda () (set-cursor-color "black")))) + +(cd ".") ; when using windows use / instead of \ in default-directory + +;; locale +(set-language-environment "Japanese") +(set-default-coding-systems 'utf-8) +(prefer-coding-system 'utf-8) +(setq system-time-locale "C") + +;; display +(setq redisplay-dont-pause t) +(setq visible-bell t) +(setq ring-bell-function 'ignore) + +;; (comint-show-maximum-output) + +;; change color for border +(set-face-foreground (make-face 'vertical-border-face) "red") +(set-display-table-slot standard-display-table 'vertical-border + (make-glyph-code #x3a 'vertical-border-face)) + +;; kill scratch +(add-hook 'after-init-hook + (lambda () + (kill-buffer "*scratch*"))) + +(defun my-delete-frame-or-kill-emacs () + "delete frame when opening multiple frame, kill emacs when only one." + (interactive) + (if (eq 1 + (length (frame-list))) + (save-buffers-kill-emacs) + (delete-frame))) +(global-set-key (kbd "C-x C-c") 'my-delete-frame-or-kill-emacs) +(define-key my-prefix-map (kbd "C-x C-c") 'save-buffers-kill-emacs) + +;; modifier keys +(setq mac-option-modifier 'control) +(setq w32-apps-modifier 'meta) + +;; http://www.emacswiki.org/emacs/ChangingCursorDynamically +;; bufferの保存はなんで必要なんだろう? +;; Change cursor color according to mode +(defvar hcz-set-cursor-color-color "") +(defvar hcz-set-cursor-color-buffer "") +(defun hcz-set-cursor-color-according-to-mode () + "change cursor color according to some minor modes." + ;; set-cursor-color is somewhat costly, so we only call it when needed: + (let ((color + (if buffer-read-only "blue" + (if overwrite-mode "yellow" + "black")))) + (unless (and + (string= color hcz-set-cursor-color-color) + (string= (buffer-name) hcz-set-cursor-color-buffer)) + (set-cursor-color (setq hcz-set-cursor-color-color color)) + (setq hcz-set-cursor-color-buffer (buffer-name))))) +(add-hook 'post-command-hook 'hcz-set-cursor-color-according-to-mode) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; minibuffer + +(setq insert-default-directory t) +(setq completion-ignore-case t + read-file-name-completion-ignore-case t + read-buffer-completion-ignore-case t) +(setq resize-mini-window t) +(temp-buffer-resize-mode 1) + +(fset 'yes-or-no-p 'y-or-n-p) + +(define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol) ; complete symbol when `eval' + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; editting +(setq require-final-newline t) +(setq kill-whole-line t) +(setq scroll-conservatively 35 + scroll-margin 2 + scroll-step 0) ;4行ずつスクロール? +(setq default-major-mode 'text-mode) +(setq next-line-add-newlines nil) +(setq kill-read-only-ok t) +(setq truncate-partial-width-windows nil) ; when splitted horizontally +;; (setq-default line-spacing 0.2) +(setq-default indicate-empty-lines t) ; なんだろうこれ +(setq-default tab-width 4) +(setq-default indent-tabs-mode nil) +(pc-selection-mode 1) +(delete-selection-mode 1) + +;; key bindings +(global-set-key (kbd "C-m") 'newline-and-indent) +(global-set-key (kbd "C-o") (lambda () + (interactive) + (goto-char (point-at-eol)) + (newline-and-indent))) +(global-set-key (kbd "C-k") 'kill-whole-line) +(global-set-key (kbd "M-k") 'my-copy-whole-line) +;; (global-set-key "\C-z" 'undo) ; undo is C-/ +;; (global-set-key (kbd "C-") (lambda () (interactive) (insert "\f\n"))) +(global-set-key (kbd "M-u") 'undo) +(global-set-key (kbd "C-r") 'query-replace-regexp) +(global-set-key (kbd "C-s") 'isearch-forward-regexp) +(global-set-key (kbd "M-i") (lambda () + (interactive) + (call-interactively (key-binding (kbd "M-TAB"))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; letters and font-lock-mode + +(show-paren-mode 1) +(setq show-paren-style 'mixed) + +(transient-mark-mode 1) +(global-font-lock-mode 1) + +(standard-display-ascii ?\n "$\n") +(defface my-eol-face + '((t (:foreground "gray"))) + "eol.") + +(standard-display-ascii ?\f "---------------------------------------------------------------------------------------^L") +(defface my-pagebreak-face + '((t (:foreground "gray"))) + "pagebreak.") + +(defvar my-eol-face + '(("\n" . '(0 my-eol-face t nil)))) +(defvar my-pagebreak-face + '(("\f" . 'my-pagebreak-face))) +(defvar my-highlight-face + '(("\t" . '(0 highlight t nil)) + (" " . '(0 highlight t nil)))) + +;; (defvar my-face +;; '(("\t" . 'highlight) +;; (" " . 'highlight) +;; ("\n" . '(0 my-eol-face t nil)) +;; ("\f" . 'my-pagebreak-face))) + +(setq font-lock-global-modes + '(not + help-mode + eshell-mode + term-mode)) + +(add-hook 'font-lock-mode-hook + (lambda () + (font-lock-add-keywords nil my-eol-face) + (font-lock-add-keywords nil my-highlight-face))) + +(set-face-foreground 'font-lock-regexp-grouping-backslash "#666") +(set-face-foreground 'font-lock-regexp-grouping-construct "#f60") + +;; fonts + +;; (defun my-w32-set-font () +;; "set font for windows." +;; ((lambda (&rest lists) +;; (let ((dir "c:/WINDOWS/Fonts") +;; lfs) +;; (while lists +;; (setq lfs (pop lists)) +;; (when (directory-files dir nil (car lfs)) +;; (my-set-ascii-and-jp-font-with-size (cdr lfs)) +;; (setq lists nil))))) +;; '("^DejaVuSansMono" "dejavu sans mono" 80 "ms gothic" 12) +;; '("^inconsolata" "inconsolata" 100 "ms gothic" 12))) + +;; (defun my-w32-set-available-ascii-and-jp-font-with-size (&rest lists) +;; "" +;; (let ((dir "c:/WINDOWS/Fonts") +;; lfs) +;; (while lists +;; (setq lfs (pop lists)) +;; (when (directory-files dir nil (car lfs)) +;; (my-set-ascii-and-jp-font-with-size (cdr lfs)) +;; (setq lists nil))))) + +(defun my-set-ascii-and-jp-font-with-size (list) + "" + (set-face-attribute 'default nil + :family (nth 0 list) + :height (nth 1 list)) + (set-fontset-font "fontset-default" + 'japanese-jisx0208 + (font-spec :family (nth 2 list) :size (nth 3 list))) + (set-fontset-font "fontset-default" + 'katakana-jisx0201 + (font-spec :family (nth 2 list) :size (nth 3 list)))) ; font spec is available in emacs23 and later, cannot used in emacs22 +;; (my-set-ascii-and-jp-font-with-size '("dejavu sans mono" 90 "takaogothic" 13)) +;; (my-set-ascii-and-jp-font-with-size '("dejavu sans mono" 100 "takaogothic" 14)) +;; (my-set-ascii-and-jp-font-with-size '("monaco" 75 "takaogothic" 11)) +;; (my-set-ascii-and-jp-font-with-size '("monaco" 90 "takaogothic" 13)) +;; (my-set-ascii-and-jp-font-with-size '("ProggyCleanTTSZ" 120 "takaogothic" 11)) +;; あ + +(defun my-22-set-ascii-and-jp-font-with-size (list) + "" + (set-face-attribute 'default nil + :family (nth 0 list) + :height (nth 1 list)) + (set-fontset-font "fontset-default" + 'japanese-jisx0208 + (cons (nth 2 list) "jisx0208.*")) + (set-fontset-font "fontset-default" + 'katakana-jisx0201 + (cons (nth 2 list) "jisx0201.*"))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; mode-line + +(which-function-mode 0) + +(line-number-mode 0) +(column-number-mode 0) +(size-indication-mode 0) +(setq mode-line-position + '(:eval (format "L%%l/%d,C%%c" + (count-lines (point-max) + (point-min))))) + + +;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title +;; display date +(add-hook 'after-init-hook + (lambda () + (setq display-time-string-forms + '(dayname ", " day " " monthname " " year " " 24-hours ":"minutes ":" seconds)) + (setq display-time-string-forms + '((my-format-time-string))) + (when display-time-mode + (display-time-update)) + )) +(setq display-time-interval 29) +(setq display-time-day-and-date t) +(if window-system + (display-time-mode 0) + (display-time-mode 1)) + +;; current directory +(let ((ls (member 'mode-line-buffer-identification + mode-line-format))) + (setcdr ls + (cons '(:eval (concat " (" + (abbreviate-file-name default-directory) + ")")) + (cdr ls)))) + +(let ((ls (member 'mode-line-buffer-identification + mode-line-format))) + (setcdr ls + (cons '(:eval (concat " " + my-buffer-file-last-modified-time)) + (cdr ls)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; back up and auto saving +;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260 +(setq make-backup-files t) +;; (make-directory (expand-file-name "~/.emacsbackup")) +(setq backup-directory-alist + (cons (cons "\\.*$" (expand-file-name "~/.emacs.d/backup")) + backup-directory-alist)) +(setq version-control t) +(setq delete-old-versions t) + +(setq auto-save-list-file-prefix (expand-file-name "~/.emacs.d/autosave/")) +(setq delete-auto-save-files t) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; for emacsclient +;; (if window-system (server-start)) + + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; global keys + +(define-key my-prefix-map (kbd "C-f") 'make-frame-command) +(define-key my-prefix-map (kbd "C-o") 'occur) + +;; moving around +;; (global-set-key (kbd "M-j") 'next-line) +;; (global-set-key (kbd "M-k") 'previous-line) +;; (global-set-key (kbd "M-h") 'backward-char) +;; (global-set-key (kbd "M-l") 'forward-char) +;;(keyboard-translate ?\M-j ?\C-j) +(global-set-key (kbd "M-p") 'backward-paragraph) +(global-set-key (kbd "M-n") 'forward-paragraph) +(global-set-key (kbd "C-") (lambda () (interactive)(scroll-down 1))) +(global-set-key (kbd "C-") (lambda () (interactive)(scroll-up 1))) +(global-set-key (kbd "C-") 'scroll-down) +(global-set-key (kbd "C-") 'scroll-up) + +;; C-h and DEL +;; (global-set-key (kbd "C-h") 'backward-delete-char-untabify) +;; (global-set-key (kbd "DEL") help-map) +(global-set-key (kbd "C-h") (lambda () + (interactive) + (call-interactively (key-binding (kbd "DEL"))))) +;; (keyboard-translate ?\^h ?\^?) ; scimにはC-hを送りたい +;; (keyboard-translate ?\b ?\^h) ; dont translate backspace + +;; (define-key my-prefix-map (kbd "C-h") help-map) +(global-set-key (kbd "C-\\") help-map) +(global-set-key (kbd "C-x DEL") help-map) +(global-set-key (kbd "C-x C-h") help-map) +(define-key help-map "a" 'apropos) + +;; compose window +(global-set-key [?\C--] 'other-window) +(global-set-key [?\C-0] 'delete-window) +(global-set-key [?\C-1] 'delete-other-windows) +(global-set-key [?\C-2] 'split-window-vertically) +(global-set-key [?\C-3] 'split-window-horizontally) + +;; disable annoying keys +(global-set-key [prior] 'ignore) +(global-set-key (kbd "") 'ignore) +(global-set-key [menu] 'ignore) +(global-set-key [down-mouse-1] 'ignore) +(global-set-key [down-mouse-2] 'ignore) +(global-set-key [down-mouse-3] 'ignore) +(global-set-key [mouse-1] 'ignore) +(global-set-key [mouse-2] 'ignore) +(global-set-key [mouse-3] 'ignore) +(global-set-key (kbd "") 'ignore) +(global-set-key (kbd "C-") 'ignore) + +(mouse-avoidance-mode 'banish) + + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; download library from web + +;; (require 'url) + +;; (defun dllib-if-needed (lib url &optional callback bite-compile-p force-download-p) ; dont use it +;; "if LIB does not exist, download it from URL and rename to \"~/emacs.d/lisp/LIB.el\". +;; after download LIB successfully call CALLBACK. if LIB already exist, call CALLBACK immediately." +;; (let* ((dir (expand-file-name "~/.emacs.d/lisp/")) +;; (lpath (concat dir lib ".el"))) +;; (and (if (or force-download-p (not (locate-library lib))) +;; (condition-case nil +;; (progn (url-copy-file url +;; lpath +;; t) +;; (and bite-compile-p +;; (byte-compile-file lpath) +;; t)) +;; (error (message "downloading %s...something wrong happened!" url) +;; nil)) +;; t) +;; callback +;; (funcall callback)))) + +(defun dllib-if-unfound (lib url &optional bite-compile-p force-download-p) ; new version + "if LIB does not exist, download it from URL and locate it to \"~/emacs.d/lisp/LIB.el\". +return nil if LIB unfound and downloading failed, otherwise the path of LIB." + (let* ((dir (expand-file-name "~/.emacs.d/lisp/")) + (lpath (concat dir lib ".el")) + (locate-p (locate-library lib))) + (if (or force-download-p (not locate-p)) + (progn (condition-case nil + (progn (message "downloading %s..." url) + (url-copy-file url + lpath + t) + (when bite-compile-p + (byte-compile-file lpath))) + (error (message "downloading %s...something wrong happened!" url) + nil)) + (locate-library lib)) + locate-p))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;requireが必要なelispおよびhook + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; share clipboard with x +(when (or window-system + (getenv "DESKTOP_SESSION")) + (setq x-select-enable-clipboard t)) + +;; urlに細かい説明あり。でも設定は上記だけでよさそう +;; http://garin.jp/doc/Linux/xwindow_clipboard + +(and x-select-enable-clipboard + (executable-find "xclip") + (dllib-if-unfound "xclip" "http://www.emacswiki.org/emacs/download/xclip.el" t) + (require 'xclip nil t) + (turn-on-xclip)) + +;; カーソルの場所を保存する +(when (require 'saveplace nil t) + (setq-default save-place t)) + +;; その他のhook +(add-hook 'after-save-hook + 'executable-make-buffer-file-executable-if-script-p) +(add-hook 'find-file-hook + (lambda () + (when buffer-read-only + (view-mode 1)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; mode関連 + +;; (ffap-bindings) + +(add-hook 'inferior-python-mode-hook + (lambda () + (define-key inferior-python-mode-map (kbd "") 'comint-previous-input) + (define-key inferior-python-mode-map (kbd "") 'comint-next-input))) + +(add-to-list 'Info-default-directory-list (expand-file-name "~/.info/emacs-ja")) + +(setq bookmark-default-file "~/.emacs.d/bmk") + +(add-hook 'apropos-mode-hook + (lambda () + (define-key apropos-mode-map "j" 'next-line) + (define-key apropos-mode-map "k" 'previous-line))) + +(define-key minibuffer-local-map (kbd "C-u") (lambda () (interactive) (delete-region (point-at-bol) (point-at-eol)))) + +(add-hook 'isearch-mode-hook + (lambda () + ;; (define-key isearch-mode-map (kbd "C-j") 'isearch-other-control-char) + ;; (define-key isearch-mode-map (kbd "C-k") 'isearch-other-control-char) + ;; (define-key isearch-mode-map (kbd "C-h") 'isearch-other-control-char) + (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char) + (define-key isearch-mode-map (kbd "M-r") 'isearch-query-replace-regexp))) + +(add-hook 'outline-mode-hook + (lambda () + (if (string-match "\\.md$" buffer-file-name) + (set (make-local-variable 'outline-regexp) "#+ ")))) +(add-to-list 'auto-mode-alist (cons "\\.ol$" 'outline-mode)) + +(add-to-list 'auto-mode-alist (cons "\\.md$" 'outline-mode)) +(when (dllib-if-unfound "markdown-mode" + "http://jblevins.org/projects/markdown-mode/markdown-mode.el" + t) + (add-to-list 'auto-mode-alist (cons "\\.md$" 'markdown-mode)) + (autoload 'markdown-mode "markdown-mode" "Major mode for editing Markdown files." nil) + (add-hook 'markdown-mode-hook + (lambda () + (outline-minor-mode 1) + (set (make-local-variable 'comment-start) ";")))) + +;; (add-hook 'c-mode-hook +;; (lambda () +;; (set (make-local-variable 'comment-start) "//") +;; (set (make-local-variable 'comment-end) ""))) + +;; http://d.hatena.ne.jp/emergent/20070203/1170512717 +;; c-mode +;; (setq c-default-style "bsd") +;; BackSpace キーを「賢く」し,インデント幅は2桁,タブはスペースに展開 +(add-hook 'c-mode-common-hook + (lambda () + (setq c-basic-offset 2 + indent-tabs-mode nil) + ;; (set-face-foreground 'font-lock-keyword-face "blue") + )) +(defun my-compile-c-this-file () + "" + (interactive) + (compile (format "gcc -Wall -g -o %s %s" + (file-name-sans-extension buffer-file-name) + buffer-file-name))) + +(when (dllib-if-unfound "js2-mode" + "https://github.com/mooz/js2-mode/raw/master/js2-mode.el" + t) + (autoload 'js2-mode "js2-mode" nil t) + (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode))) +;; (add-hook 'js2-mode-hook +;; (lambda () +;; (add-hook 'before-save-hook +;; 'my-indent-buffer +;; nil +;; t))) +(add-hook 'js2-mode-hook + (lambda () + (define-key js2-mode-map (kbd "C-m") (lambda () + (interactive) + (js2-enter-key) + (indent-for-tab-command))) + (add-hook (kill-local-variable 'before-save-hook) + 'js2-before-save))) + +(when (require 'zone nil t) + (zone-when-idle 180)) + +(when (require 'uniquify nil t) + (setq uniquify-buffer-name-style 'post-forward-angle-brackets) + (setq uniquify-ignore-buffers-re "*[^*]+*") + (setq uniquify-min-dir-content 1)) + +(add-hook 'view-mode-hook + (lambda() + (define-key view-mode-map "j" (lambda() (interactive) (scroll-up 1))) + (define-key view-mode-map "k" (lambda() (interactive) (scroll-down 1))) + (define-key view-mode-map "/" 'isearch-forward) + (define-key view-mode-map "v" 'toggle-read-only) + (define-key view-mode-map "q" 'kill-this-buffer))) +(global-set-key "\M-r" 'view-mode) + +(add-hook 'Man-mode-hook + (lambda () + (view-mode 1) + (setq truncate-lines nil))) +(setq Man-notify-method (if window-system + 'newframe + 'pushy)) + +;; http://d.hatena.ne.jp/goinger/20100416/1271399150 +(add-hook 'term-mode-hook (lambda () + (define-key term-raw-map "\C-y" 'term-paste) + ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line) + ;; (define-key term-raw-map "\C-r" 'term-send-raw) + ;; (define-key term-raw-map "\C-s" 'term-send-raw) + ;; (define-key term-raw-map "\C-f" 'forward-char) + ;; (define-key term-raw-map "\C-b" 'backward-char) + ;; (define-key term-raw-map "\C-t" 'set-mark-command) + (define-key term-raw-map (kbd "ESC") 'term-send-raw) + (define-key term-raw-map [delete] 'term-send-raw) + (define-key term-raw-map "\C-c" 'term-send-raw) + (define-key term-raw-map "\C-x" (lookup-key (current-global-map) "\C-x")) + (define-key term-raw-map "\C-z" (lookup-key (current-global-map) "\C-z")))) + +;; (when (and (executable-find "git") +;; (require 'sgit-mode nil t)) +;; (add-hook 'find-file-hook +;; 'sgit-load)) + +(when (require 'gtkbm nil t) + (global-set-key (kbd "C-x C-d") 'gtkbm)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; gmail +(setq mail-interactive t + send-mail-function 'smtpmail-send-it + ;; message-send-mail-function 'smtpmail-send-it + smtpmail-smtp-server "smtp.gmail.com" + smtpmail-smtp-service 587 + smtpmail-starttls-credentials '(("smtp.gmail.com" 587 "8.slashes@gmail.com" nil)) + smtpmail-auth-credentials '(("smtp.gmail.com" 587 "8.slashes@gmail.com" nil)) + user-mail-address "8.slashes@gmail.com") + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; buffer killing + +;; (add-hook 'kill-buffer-hook +;; (lambda () +;; (when buffer-file-name +;; (dired ".")))) + +(defun kill-buffer-by-major-mode (mode &optional exclude-current-buffer-p) ;mapcarとかつかって全部書き換える + "kill buffers. +if EXCLUDE-CURRENT-BUFFER-P is non-nil, never kill current buffer" + (interactive "xmajor mode of buffer to kill: ") + (save-excursion + (let ((bflist (buffer-list)) + (cbf (current-buffer)) + bf) + (while bflist + (setq bf (pop bflist)) + (set-buffer bf) + (if (and (eq mode major-mode) ;メジャーモードが一致し、かつ + (not (and exclude-current-buffer-p ;今のバッファを除外、今のバッファと一致 がともには満たされない + (eq bf cbf)))) + (kill-buffer bf)))))) + +(defun my-kill-this-buffer-when-hide (&optional buffer all-frames) + "" + (interactive) + (let ((bf (or buffer + (current-buffer)))) + (if (or (not buffer) (get-buffer-window bf all-frames)) + (run-with-timer 3 nil 'my-kill-this-buffer-when-hide bf all-frames) + (kill-buffer bf)))) +;; (add-hook 'dired-mode-hook +;; 'my-kill-this-buffer-when-hide) + +(defvar my-kill-previous-buffer nil) +(defun my-kill-previous-buffer () + "" + (when my-kill-previous-buffer + (kill-buffer my-kill-previous-buffer)) + (setq my-kill-previous-buffer (current-buffer))) +;; (add-hook 'dired-mode-hook +;; 'my-kill-previous-buffer) + +(defun my-query-kill-this-buffer () + "" + (interactive) + (if (y-or-n-p (concat "kill this buffer? :")) + (kill-buffer (current-buffer)))) +(substitute-key-definition 'kill-buffer 'my-query-kill-this-buffer global-map) +;;(global-set-key "\C-xk" 'my-query-kill-this-buffer) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; buffer switching + +(when (require 'bs nil t) + (global-set-key "\C-x\C-b" 'bs-show)) +;; (add-to-list 'bs-configurations '("processes" nil get-buffer-process ".*" nil nil)) +(add-to-list 'bs-configurations '("same-dir" nil buffer-same-dir-p ".*" nil nil)) +;; (setq bs-configurations (list '("processes" nil get-buffer-process ".*" nil nil) +;; '("files-and-scratch" "^\\*scratch\\*$" nil nil bs-visits-non-file bs-sort-buffer-interns-are-last))) +(setq bs-default-configuration "all") +(add-hook 'bs-mode-hook + (lambda () + (setq bs-default-configuration "all"))) + +(defun buffer-same-dir-p (bf) + "return t if BF's dir is same as current dir, otherwise nil." + (let ((cdir (expand-file-name default-directory))) + (with-current-buffer bf + (equal (expand-file-name default-directory) cdir)))) + +(defun echo-buffer-list (&optional blist) + "echo buffer list as string. BLIST is list with buffer objects as elements. +if arg is omitted use value of `buffer-list'." + (interactive) + (message (or (mapconcat (lambda (bf) + (concat (buffer-name bf) + "\t" + (with-current-buffer bf + (symbol-name major-mode)) + "\t" + (abbreviate-file-name (buffer-file-name bf)))) + (or blist + (buffer-list)) + "\n") + ""))) + +(defun my-buffer-list () + "return buffer list." + (delq nil + (mapcar (lambda (bf) + (with-current-buffer bf + (and buffer-file-name + bf))) + (buffer-list (selected-frame))))) + +(defvar buffer-switch-list-function 'my-buffer-list) + +(defun switch-to-previous-buffer-cycle (&optional silent-p) + "" + (interactive) + (let ((bl (funcall buffer-switch-list-function))) + (when bl + (bury-buffer (car bl)) + (switch-to-buffer (or (nth 1 bl) + (car bl))) + (or silent-p + (echo-buffer-list (funcall buffer-switch-list-function)))))) + +(defun switch-to-next-buffer-cycle (&optional silent-p) + "" + (interactive) + (let* ((bl (funcall buffer-switch-list-function)) + (bf (nth (- (length bl) + 1) + bl))) + (when bl + (switch-to-buffer bf) + (or silent-p + (echo-buffer-list (funcall buffer-switch-list-function)))))) + +(iswitchb-mode 1) + +(defun iswitchb-buffer-display-other-window () + "" + (interactive) + (let ((iswitchb-default-method 'display)) + (call-interactively 'iswitchb-buffer))) + +(defun switch-to-other-buffer () + "" + (interactive) + (let ((buffer-switch-list-function 'buffer-list)) + (switch-to-previous-buffer-cycle t))) + +(global-set-key (kbd "C-.") 'switch-to-previous-buffer-cycle) +(global-set-key (kbd "C-,") 'switch-to-next-buffer-cycle) +;; (global-set-key (kbd "C-\\") 'switch-to-other-buffer) +;; (global-set-key (kbd "C-\\") 'bury-buffer) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; sdic + +(defun sdic-describe-word-echo () + "" + (interactive) + (save-window-excursion + (sdic-describe-word-at-point)) + (save-excursion + (set-buffer sdic-buffer-name) + (message (buffer-substring (point-min) + (progn (goto-char (point-min)) + (or (and (re-search-forward "^\\w" nil t 4) + (progn (previous-line) t) + (point-at-eol)) + (point-max))))))) + +(setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic"))) +(setq sdic-waei-dictionary-list '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t)))) +(setq sdic-disable-select-window t) +(setq sdic-window-height 7) +(when (require 'sdic nil t) + (global-set-key "\C-cw" 'sdic-describe-word) + (global-set-key "\C-ct" 'sdic-describe-word-at-point) + (global-set-key "\C-t" 'sdic-describe-word-echo)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; vc +;; (require 'vc) + +(unless (executable-find "rcs") + (setq vc-handled-backends (delq 'RCS vc-handled-backends))) + +(defadvice vc-rcs-register (after rcs-register-non-strict-locking activate) + "" + (when (eq (vc-backend (buffer-file-name)) 'RCS) + (vc-rcs-set-non-strict-locking (buffer-file-name)))) + +(defadvice vc-next-action (before rcs-save-before-next-action activate) + "" + (save-buffer)) + +(setq vc-command-messages t) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; gauche-mode + +(setq scheme-program-name "gosh") + +(defun run-gauche-other-window () + "Run gauche on other window" + (interactive) + (switch-to-buffer-other-window + (get-buffer-create "*scheme*")) + (run-gauche)) + +(defun run-gauche () + "run gauche" + (run-scheme "gosh")) + +(defun scheme-send-buffer () + "" + (interactive) + (scheme-send-region (point-min) (point-max))) + +(add-hook 'scheme-mode-hook + (lambda () + (define-key scheme-mode-map "\C-c\C-b" 'scheme-send-buffer))) + +;; http://d.hatena.ne.jp/kobapan/20090305/1236261804 +;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el + +(when (dllib-if-unfound "gauche-mode" + "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el" + t) + (setq auto-mode-alist + (cons '("\.scm$" . gauche-mode) auto-mode-alist)) + (autoload 'gauche-mode "gauche-mode" "Major mode for Scheme." t) + (autoload 'run-scheme "gauche-mode" "Run an inferior Scheme process." t) + (add-hook 'gauche-mode-hook + (lambda () + (define-key scheme-mode-map "\C-c\C-z" 'run-gauche-other-window)))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; recentf-mode + +(add-hook 'recentf-dialog-mode-hook + 'my-recentf-abbrev-list) + +(defun my-recentf-delete-entry () + "" + (interactive) + (let ((p (point))) + (setq recentf-list + (delete (my-recentf-get-filename) recentf-list)) + (recentf-open-files) + (goto-char p))) + +(defun my-recentf-abbrev-list () + "" + (setq recentf-list + (mapcar 'abbreviate-file-name + recentf-list))) + +(defun my-recentf-view-file () + "" + (interactive) + (view-file (my-recentf-get-filename))) + +(defun my-recentf-dired () + "" + (interactive) + (let ((file (my-recentf-get-filename))) + (if (file-directory-p file) + (dired file) + (dired (or (file-name-directory file) + "."))))) + +(defun my-recentf-x-open () + "" + (interactive) + (my-x-open (my-recentf-get-filename))) + +(defun my-recentf-cd-and-find-file () + "" + (interactive) + (cd (file-name-directory (my-recentf-get-filename))) + (call-interactively 'find-file)) + +(defun my-recentf-get-filename () + "get file name in recentf-mode" + (replace-regexp-in-string " \\(\\[.+?\\] \\)?" ; " " or " [\\d] " + "" + (buffer-substring-no-properties (point-at-bol) + (point-at-eol)))) + +(setq recentf-save-file (expand-file-name "~/.emacs.d/.recentf") + recentf-max-menu-items 20 + recentf-max-saved-items 30 + recentf-show-file-shortcuts-flag nil) + +(when (require 'recentf nil t) + (global-set-key "\C-x\C-r" 'recentf-open-files) + ;; (add-hook 'find-file-hook + ;; (lambda () + ;; (recentf-add-file default-directory))) + (recentf-mode 1) + (add-to-list 'recentf-filename-handlers 'abbreviate-file-name) + (add-to-list 'recentf-exclude "\\.emacs\\.d/\\.recentf")) + +(add-hook 'recentf-dialog-mode-hook + (lambda () + (recentf-save-list) + ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f") 'my-recentf-cd-and-find-file) + (define-key recentf-dialog-mode-map (kbd "") 'previous-line) + (define-key recentf-dialog-mode-map (kbd "") 'next-line) + (define-key recentf-dialog-mode-map "o" 'my-recentf-x-open) + (define-key recentf-dialog-mode-map "d" 'my-recentf-delete-entry) + (define-key recentf-dialog-mode-map "@" 'my-recentf-dired) + (define-key recentf-dialog-mode-map "v" 'my-recentf-view-file) + (cd "~/"))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; dired + +(require 'dired) + +(require 'dired-aux) ;; needed to use dired-dwim-target-directory +(defun my-dired-do-compress-or-uncompress () + "" + (interactive) + (let* ((infiles (dired-get-marked-files t)) + (onefile (and (eq 1 ; filename if only one file targeted, otherwise nil. + (length infiles)) + (car infiles)))) + (if (and onefile + (assoc (file-name-extension onefile) + my-compress-program-alist)) + (when (y-or-n-p (format "uncompress %s? " onefile)) + (my-uncompress onefile) + (revert-buffer)) + (let* ((dir-default (dired-dwim-target-directory)) + (outfile-default (my-compress-file-extension (concat dir-default + (file-name-nondirectory (car infiles))))) + (outfile (if (interactive-p) + (read-file-name (format "Output file to compress (default for %s) : " + outfile-default) + dir-default + outfile-default) + outfile-default))) + (apply 'my-compress + outfile + infiles) + (revert-buffer))) + (dired-unmark-all-marks))) + +(defun my-file-name-extension-with-tar (filename) + "if FILENAME has extension with tar, like \"tar.gz\", return that. +otherwise, return extension normally." + (if (string-equal "tar" (file-name-extension (file-name-sans-extension filename))) + (concat "tar." + (file-name-extension filename)) + (file-name-extension filename))) + +(defun my-compress-file-extension (filename) + "if FILENAME has extension and it can be used for compress, return FILENAME. +otherwise, return FILENAME with `my-compress-default-extension'" + (if (assoc (file-name-extension filename) + my-compress-program-alist) + filename + (concat filename "." my-compress-default-extension))) + +(defvar my-7z-program + (or (executable-find "7z") + (executable-find "7za") + (executable-find "7zr"))) + +(defvar my-compress-default-extension + "7z") + +(defvar my-compress-program-alist + `(("7z" ,my-7z-program "a" ,my-7z-program "x") + ("tar" "tar" "cvf" "tar" "xvf") + ("tgz" "tar" "czf" "tar" "xzf") + ("txz" "tar" "cJf" "tar" "xJf") + ("zip" "zip" "-r" "unzip" nil))) + +(defun my-uncompress (file) + "" + (interactive "fFile to extract: ") + (let* ((efile (expand-file-name file)) + (ext (file-name-extension efile)) + (lst (assoc ext + my-compress-program-alist)) + (com (nth 3 lst)) + (op (nth 4 lst)) + (args (if op + (list op efile) + (list efile)))) + (message "uncompressing %s..." file) + (apply 'call-process + com + nil + (my-pop-to-buffer-erase-noselect "*compressing output*") + t + args) + (message "uncompressing %s...done." file))) + +(defun my-compress (outfile &rest infiles) + "if outfile have extension for compress, use it. +otherwise, use `my-compress-default-extension'. for compress." + (let* ((outfile-ext (my-compress-file-extension (expand-file-name outfile))) + (ext (file-name-extension outfile-ext)) + (lst (assoc ext + my-compress-program-alist)) + (com (nth 1 lst)) + (op (nth 2 lst)) + (args (if op + (apply 'list + op + outfile-ext + infiles) + (apply 'list + outfile-ext + infiles)))) + (message "compressing to %s..." outfile) + (apply 'call-process + com + nil + (my-pop-to-buffer-erase-noselect "*compressing output*") + t + args) + (message "compressing to %s...done." outfile))) + +(defun my-pop-to-buffer-erase-noselect (buffer-or-name) + "pop up buffer using `display-buffer' and return that buffer." + (let ((bf (get-buffer-create buffer-or-name))) + (with-current-buffer bf + (cd ".") + (erase-buffer)) + (display-buffer bf) + bf)) + +(defun my-replace-nasi-none () + "" + (save-excursion + (let ((buffer-read-only nil)) + (goto-char (point-min)) + (while (search-forward "なし" nil t) + (replace-match "none"))))) + +(defun dired-get-du () ;em-unix.el使えるかも + "dired get disk usage" + (interactive) + (message "calculating du...") + (dired-do-shell-command "du -hs * " nil (dired-get-marked-files))) + +(defun my-dired-scroll-up () + "" + (interactive) + (my-dired-previous-line (- (window-height) 1))) + +(defun my-dired-scroll-down () + "" + (interactive) + (my-dired-next-line (- (window-height) 1))) + +(defun my-dired-previous-line (&optional arg) + "" + (interactive) + (dired-previous-line (or arg 1)) + (my-dired-print-current-dir-and-file)) + +(defun my-dired-next-line (&optional arg) + "" + (interactive) + (dired-next-line (or arg 1)) + (my-dired-print-current-dir-and-file)) + +(defun my-dired-print-current-dir-and-file () + (message "%s %s" + default-directory + (buffer-substring-no-properties (point-at-bol) + (point-at-eol)))) + +(defun dired-do-execute-as-command () + "" + (interactive) + (let ((file (dired-get-filename t))) + (if (file-executable-p file) + (start-process file nil file) + (when (y-or-n-p "this file cant be executed. mark as executable and go? : ") + (set-file-modes file (file-modes-symbolic-to-number "u+x" (file-modes file))) + (start-process file nil file))))) + +;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html + +(defun my-dired-x-open () + "" + (interactive) + (my-x-open (dired-get-filename t t))) + +(defun my-dired-up-directory () + "" + (interactive) + (my-dired-find-file "..")) + +(defun my-dired-find-file (&optional filename) + "" + (interactive) + (let ((f (expand-file-name (or filename + (dired-get-filename)))) + (bf (current-buffer))) + (find-file f) + (when (and (file-directory-p f) + (not (get-buffer-window bf))) + (kill-buffer bf)))) + +(setq dired-listing-switches "-lhFG --time-style=long-iso") +(define-minor-mode my-dired-display-all-mode + "" + :init-value nil + (if my-dired-display-all-mode + (setq dired-actual-switches + (concat "-A " + dired-actual-switches)) + (setq dired-actual-switches + (replace-regexp-in-string "-A " "" dired-actual-switches))) + (when (eq major-mode 'dired-mode) + (revert-buffer))) + +(put 'dired-find-alternate-file 'disabled nil) +(require 'ls-lisp) +;; (setq ls-lisp-use-insert-directory-program nil) +(setq ls-lisp-dirs-first t) +(setq dired-ls-F-marks-symlinks t) +(setq dired-dwim-target t) + +;; (add-hook 'dired-after-readin-hook +;; 'my-replace-nasi-none) + +(add-hook 'after-init-hook + (lambda () + (dired "."))) + +(add-hook 'dired-mode-hook + (lambda () + (define-key dired-mode-map "o" 'my-dired-x-open) + (define-key dired-mode-map "i" 'dired-get-du) + (define-key dired-mode-map "!" 'shell-command) + (define-key dired-mode-map "&" 'async-shell-command) + (define-key dired-mode-map "X" 'dired-do-async-shell-command) + (define-key dired-mode-map "B" 'gtkbm-add-current-dir) + (define-key dired-mode-map "b" 'gtkbm) + (define-key dired-mode-map "@" (lambda () (interactive) (my-x-open "."))) + (define-key dired-mode-map (kbd "TAB") 'other-window) + (define-key dired-mode-map "Z" 'my-dired-do-compress-or-uncompress) + (define-key dired-mode-map "a" 'my-dired-display-all-mode) + (define-key dired-mode-map "h" 'my-dired-display-all-mode) + (substitute-key-definition 'dired-advertised-find-file 'my-dired-find-file dired-mode-map) + (substitute-key-definition 'dired-up-directory 'my-dired-up-directory dired-mode-map) + (define-key dired-mode-map (kbd "DEL") 'my-dired-up-directory) + (substitute-key-definition 'dired-next-line 'my-dired-next-line dired-mode-map) + (substitute-key-definition 'dired-previous-line 'my-dired-previous-line dired-mode-map) + (define-key dired-mode-map (kbd "") 'my-dired-scroll-up) + (define-key dired-mode-map (kbd "") 'my-dired-scroll-down) + (let ((file "._Icon\015")) + (when (file-readable-p file) + (delete-file file))))) + +;; http://homepage1.nifty.com/blankspace/emacs/dired.html +;; (add-hook 'dired-load-hook +;; (lambda () +;; (load-library "ls-lisp") +;; (setq ls-lisp-dirs-first t) +;; (setq dired-listing-switches "-alhF"))) ;これ書く場所間違えてね? + +;; (defadvice dired-next-line (after dired-next-line-print-directory activate) +;; "print current directory when go down line" +;; (dired-print-current-dir-and-file)) + +;; (defadvice dired-previous-line (after dired-previous-line-print-directory activate) +;; "print current directory when go up line" +;; (dired-print-current-dir-and-file)) + +;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html + +(defun my-dired-toggle-mark() + (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040) + (t dired-marker-char)))) + (delete-char 1) + (insert cur))) + +(defun my-dired-mark (arg) + "toggle mark the current (or next ARG) files. +If on a subdir headerline, mark all its files except `.' and `..'. + +Use \\[dired-unmark-all-files] to remove all marks +and \\[dired-unmark] on a subdir to remove the marks in +this subdir." + + (interactive "P") + (if (dired-get-subdir) + (save-excursion (dired-mark-subdir-files)) + (let ((inhibit-read-only t)) + (dired-repeat-over-lines + (prefix-numeric-value arg) + 'my-dired-toggle-mark)))) + +(defun my-dired-mark-backward (arg) + "In Dired, move up lines and toggle mark there. +Optional prefix ARG says how many lines to unflag; default is one line." + (interactive "p") + (my-dired-mark (- arg))) + +(defun dired-mode-hooks() + (local-set-key (kbd "SPC") 'my-dired-mark) + (local-set-key (kbd "S-SPC") 'my-dired-mark-backward)) +(add-hook 'dired-mode-hook 'dired-mode-hooks) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; eshell + +(defun my-eshell-backward-delete-char () + (interactive) + (when (< (save-excursion + (eshell-bol) + (point)) + (point)) + (backward-delete-char 1))) + +(defvar my-eshell-frame-buffer-alist nil) + +(defun my-eshell-frame-buffer (frame) + "get buffer associated with FRAME. if buffer doesnt exist or killed, return nil." + (let ((bf (cdr (assq frame my-eshell-frame-buffer-alist)))) + (and bf ;関連付けられたバッファが存在し + (buffer-name bf) ;かつkillされてない + bf))) + +(add-hook 'eshell-mode-hook + (lambda () + (add-to-list 'my-eshell-frame-buffer-alist + (cons (selected-frame) (current-buffer))))) + +(defun my-file-owner-p (file) + "t if FILE is owned by me." + (eq (user-uid) (nth 2 (file-attributes file)))) + +;; http://www.bookshelf.jp/pukiwiki/pukiwiki.php?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9 +;; written by Stefan Reichoer +(defun eshell/less (&rest args) + "Invoke `view-file' on the file. +\"less +42 foo\" also goes to line 42 in the buffer." + (if args + (while args + (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args)) + (let* ((line (string-to-number (match-string 1 (pop args)))) + (file (pop args))) + (view-file file) + (goto-line line)) + (view-file (pop args)))))) + +(defun eshell/o (&optional file) + (my-x-open (or file "."))) + +(defun eshell/vi (&rest args) + "Invoke `find-file' on the file. +\"vi +42 foo\" also goes to line 42 in the buffer." + (while args + (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args)) + (let* ((line (string-to-number (match-string 1 (pop args)))) + (file (pop args))) + (find-file file) + (goto-line line)) + (find-file (pop args))))) + +(defun eshell/clear () + "Clear the current buffer, leaving one prompt at the top." + (let ((inhibit-read-only t)) + (erase-buffer))) + +(defun eshell/d (&optional dirname switches) + "if first arg is omitted open current directory." + (dired (or dirname ".") switches)) + +(defalias 'eshell/type 'eshell/which) +(defalias 'eshell/vim 'eshell/vi) +(defalias 'eshell/ff 'find-file) + +(defun eshell-goto-prompt () + "" + (interactive) + (goto-char (point-max))) + +(defun eshell-cd-default-directory (&optional eshell-buffer-or-name) + "open eshell and change wd +if arg given, use that eshell buffer, otherwise make new eshell buffer." + (interactive) + (let ((dir (expand-file-name default-directory))) + (switch-to-buffer (or eshell-buffer-or-name + (eshell t))) + (unless (equal dir (expand-file-name default-directory)) + ;; (cd dir) + ;; (eshell-interactive-print (concat "cd " dir "\n")) + ;; (eshell-emit-prompt) + (goto-char (point-max)) + (eshell-kill-input) + (insert "cd " dir) + (eshell-send-input)))) + +(setq eshell-directory-name "~/.emacs.d/eshell/") +(setq eshell-scroll-to-bottom-on-input t) +(setq eshell-cmpl-ignore-case t) +(setq eshell-cmpl-cycle-completions nil) +(setq eshell-highlight-prompt nil) +(setq eshell-ls-initial-args "-FG") ; "-hF") +(setq eshell-prompt-function + (lambda () + (with-temp-buffer + (let (p1 p2 p3 p4) + (insert " [") + (setq p1 (point)) + (insert (abbreviate-file-name default-directory)) + (setq p2 (point)) + (insert "]" + "\n") + (setq p3 (point)) + (insert user-login-name + "@" + (or (getenv "HOSTNAME") + (substring (shell-command-to-string (or (executable-find "hostname") + ":")) + 0 + -1))) + (setq p4 (point)) + (insert " " + (format-time-string "%a, %d %b %Y %T %z") + " ESHELL\n" + "last:" + (number-to-string eshell-last-command-status) + (if (= (user-uid) + 0) + " # " + " $ ")) + (add-text-properties p1 + p2 + '(face ((foreground-color . "red")))) + (add-text-properties p3 + p4 + '(face ((foreground-color . "blue")))) + (buffer-substring (point-min) + (point-max)))))) + +(add-hook 'eshell-mode-hook + (lambda () + ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda () + ;; (interactive) + ;; (switch-to-buffer (other-buffer)))) + (define-key eshell-mode-map (kbd "C-u") (lambda () + (interactive) + (eshell-goto-prompt) + (eshell-kill-input))) + (define-key eshell-mode-map (kbd "C-g") (lambda () + (interactive) + (eshell-goto-prompt) + (my-keyboard-quit))) + (define-key eshell-mode-map (kbd "DEL") 'my-eshell-backward-delete-char) + (mapcar (lambda (alias) + (add-to-list 'eshell-command-aliases-list + alias)) + '(("ll" "ls -l") + ("la" "ls -a") + ("lla" "ls -al") + ("ut" "slogin 03110414@un001.ecc.u-tokyo.ac.jp") + ("aptin" "sudo apt-get install") + ("u" "uname") + ("eless" "cat >>> (with-current-buffer (get-buffer-create \"*eshell output\") (erase-buffer) (setq buffer-read-only nil) (current-buffer)); (view-buffer (get-buffer \"*eshell output*\"))"))) + (add-to-list 'eshell-output-filter-functions 'eshell-truncate-buffer) + (apply 'eshell/addpath exec-path) + (set (make-variable-buffer-local 'scroll-margin) 0) + (eshell/export "GIT_PAGER=") + (eshell/export "LC_MESSAGES=C") + )) + +;; (eval-after-load "em-alias" +;; '(progn ;; (eshell/alias "ll" "ls -l") +;; ;; (eshell/alias "la" "ls -a") +;; ;; (eshell/alias "lla" "ls -al") +;; (eshell/alias "sgcc" (if (eq system-type 'windows-nt) +;; "gcc -o win.$1.exe $1" +;; "gcc -o ${uname}.$1.out $1")) +;; (eshell/alias "slmgcc" (if (eq system-type 'windows-nt) +;; "gcc -lm -o win.$1.exe $1" +;; "gcc -lm -o ${uname}.$1.out $1")) +;; ;; (eshell/alias "ut" "ssh g841105@un001.ecc.u-tokyo.ac.jp") +;; (add-to-list 'recentf-exclude (concat eshell-directory-name "alias")))) + +(define-key my-prefix-map (kbd "C-s") (lambda () + (interactive) + (eshell-cd-default-directory (buffer-name (or (my-eshell-frame-buffer (selected-frame)) + (eshell t)))))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; 最終更新日時を得る + +(defvar my-buffer-file-last-modified-time nil "") + +(make-variable-buffer-local 'my-buffer-file-last-modified-time) + +(defun my-get-file-last-modified-time (file) + "" + (nth 5 + (file-attributes file))) + +(defun my-set-buffer-file-last-modified-time () + "" + (make-local-variable 'my-buffer-file-last-modified-time) + (setq my-buffer-file-last-modified-time + (format-time-string "%Y/%m/%d %H:%M" (my-get-file-last-modified-time buffer-file-name)))) + +(add-hook 'find-file-hook + 'my-set-buffer-file-last-modified-time) +(add-hook 'after-save-hook + 'my-set-buffer-file-last-modified-time) +(add-hook 'after-revert-hook + 'my-set-buffer-file-last-modified-time) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; auto saving + +(defun my-save-this-buffer (silent-p) + "save current buffer if can without asking" + (let ((cm (if (current-message) + (format "%s\n" (current-message)) + "")) + (fun (symbol-function (if silent-p + 'ignore + 'message)))) + (cond ((active-minibuffer-window) nil) + ((not buffer-file-name) (funcall fun "%ssaving... this buffer doesn't visit any file." cm) nil) + (buffer-read-only (funcall fun "%ssaving... this buffer is read-only." cm) nil) + ((not (buffer-modified-p)) (funcal fun "%ssaving... not modified yet." cm) nil) + ((not (file-writable-p buffer-file-name)) (funcall fun "%ssaving... you cannot change this file." cm) nil) + (t (funcall fun "%ssaving..." cm) + (save-buffer) + (funcall fun "%ssaving... done." cm))))) +;; (if (and buffer-file-name +;; (not buffer-read-only) +;; (buffer-modified-p) +;; (file-writable-p buffer-file-name)) +;; (save-buffer))) ; 静かな方 + +(defvar my-auto-save-this-buffer nil "auto save timer object") + +(defun my-auto-save-this-buffer (secs &optional silent-p) + "auto save current buffer if idle for SEC. +when SEC is nil, stop auto save if enabled." + (if secs + (progn (when my-auto-save-this-buffer + (cancel-timer my-auto-save-this-buffer) + (setq my-auto-save-this-buffer nil)) + (setq my-auto-save-this-buffer (run-with-idle-timer secs t 'my-save-this-buffer silent-p))) + (when my-auto-save-this-buffer + (cancel-timer my-auto-save-this-buffer) + (setq my-auto-save-this-buffer nil)))) + +(my-auto-save-this-buffer 2 t) + + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; misc funcs + +(defun my-format-time-string (&optional time) + "" + (let ((system-time-locale "C")) + (format-time-string "%a, %d %b %Y %T" time))) + +(defvar my-filer nil) +(setq my-filer (or (executable-find "pcmanfm") + (executable-find "nautilus"))) +(defun my-x-open (file) + "open file." + (interactive "FOpen File: ") + (setq file (expand-file-name file)) + (message "Opening %s..." file) + (cond ((eq system-type 'windows-nt) + (call-process "cmd.exe" nil 0 nil "/c" "start" "" (convert-standard-filename file))) + ((eq system-type 'darwin) + (call-process "open" nil 0 nil file)) + ((not (getenv "DESKTOP_SESSION")) + (find-file file)) + (t + (if (file-directory-p file) + (call-process my-filer nil 0 nil file) + (call-process "xdg-open" nil 0 nil file)))) + (recentf-add-file file) + (message "Opening %s...done" file)) + +(defvar my-indent-buffer-mode-list + '(emacs-lisp-mode + sh-mode + js-mode + sgml-mode + c-mode)) +(defun my-indent-buffer () + "" + (interactive) + (indent-region (point-min) + (point-max))) +(add-hook 'before-save-hook + (lambda () + (when (memq major-mode my-indent-buffer-mode-list) + (my-indent-buffer)))) + +(defun my-keyboard-quit () + "" + (interactive) + (run-hooks 'before-keyboard-quit-hook) + (redisplay) + (keyboard-quit) + (run-hooks 'after-keyboard-quit-hook)) +(substitute-key-definition 'keyboard-quit 'my-keyboard-quit global-map) +;; (global-set-key (kbd "C-g") 'my-keyboard-quit) + +(defun my-convmv-sjis2utf8-test () + "run `convmv -r -f sjis -t utf8 *' +this is test, does not rename files" + (interactive) + (shell-command "convmv -r -f sjis -t utf8 *")) + +(defun my-convmv-sjis2utf8-notest () + "run `convmv -r -f sjis -t utf8 * --notest'" + (interactive) + (shell-command "convmv -r -f sjis -t utf8 * --notest")) + +(defun my-copy-whole-line () + "" + (interactive) + (kill-new (concat (buffer-substring (point-at-bol) + (point-at-eol)) + "\n"))) + +(defun kill-ring-save-buffer-file-name () + "get current filename" + (interactive) + (let ((file buffer-file-name)) + (if file + (progn (kill-new file) + (message file)) + (message "not visiting file.")))) + +;; ;; コマンド的な +;; (defvar my-execute-func-list nil "func list") +;; (defvar my-execute-func-hist-list nil "func hist list") +;; (setq my-execute-func-list '("(call-interactively 'my-francaiscd-b)" +;; "(call-interactively 'my-francaiscd-a)" +;; "parsec47" +;; "chromium-browser" +;; "inkscape" +;; "audacious" +;; "gnome-terminal" +;; "zkaicd.py" +;; "glchess")) + +;; (defun my-execute-start-process-or-eval-sexp () +;; "execute something" +;; (interactive) +;; (let ((func (completing-read "command?: " my-execute-func-list nil nil "" my-execute-func-hist-list))) +;; (if (string= "(" (substring func 0 1)) +;; (with-temp-buffer (insert func) +;; (eval-buffer)) +;; (start-process "ps" +;; nil +;; func)))) + +;; delete-trailing-whitespace +;; (defun my-delete-blanks-on-eol () +;; "" +;; (interactive) +;; (save-excursion +;; (goto-char (point-min)) +;; (while (re-search-forward "[ \t]+$" nil t) +;; (replace-match "" nil nil)))) + +(defun my-revert-buffer-if-needed () + "" + (interactive) + (unless (verify-visited-file-modtime (current-buffer)) + (revert-buffer t t))) + +(add-hook 'window-configuration-change-hook + (lambda () + (run-with-timer 0.5 + nil + 'my-revert-buffer-if-needed))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; forked from http://d.hatena.ne.jp/khiker/20100119/window_resize +(define-key my-prefix-map (kbd "C-w") 'my-window-organizer) +(defun my-window-organizer () + "Control window size and position." + (interactive) + (save-selected-window + (select-window (window-at 0 0)) + (let ( ;; (window-obj (selected-window)) + ;; (current-width (window-width)) + ;; (current-height (window-height)) + action + c) + (catch 'end-flag + (while t + (setq action + (read-key-sequence-vector (format "size[%dx%d] 1 to maximize; 2, 3 to split; 0 to delete; o to select other; j, l to enlarge; h, k to shrink; q to quit." + (window-width) + (window-height)))) + (setq c (aref action 0)) + (cond ((= c ?l) + (unless (eq (window-width) (frame-width)) + (enlarge-window-horizontally 1))) + ((= c ?h) + (unless (eq (window-width) (frame-width)) + (shrink-window-horizontally 1))) + ((= c ?j) + (enlarge-window 1)) + ((= c ?k) + (shrink-window 1)) + ((= c ?o) + (other-window 1)) + ((memq c '(?d ?0)) + (unless (eq (selected-window) (next-window (selected-window) 0 1)) + (delete-window (selected-window)))) + ((= c ?1) + (delete-other-windows)) + ((= c ?2) + (split-window-vertically)) + ((= c ?3) + (split-window-horizontally)) + ((memq c '(?q ?\C-g)) + (message "Quit") + (throw 'end-flag t)) + (t + (beep)))))))) +;; (aref (read-key-sequence-vector "aa") 0) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; save and restore frame size +;;http://www.bookshelf.jp/soft/meadow_30.html#SEC416 +(defun my-window-size-save () + (let* ((rlist (frame-parameters (selected-frame))) + (ilist initial-frame-alist) + (nCHeight (frame-height)) + (nCWidth (frame-width)) + (tMargin (if (integerp (cdr (assoc 'top rlist))) + (cdr (assoc 'top rlist)) 0)) + (lMargin (if (integerp (cdr (assoc 'left rlist))) + (cdr (assoc 'left rlist)) 0)) + buf + (file "~/.emacs.d/.framesize.el") + (recentf-exclude '("\\.emacs\\.d/\\.framesize\\.el$"))) + (if (get-file-buffer (expand-file-name file)) + (setq buf (get-file-buffer (expand-file-name file))) + (setq buf (find-file-noselect file))) + (set-buffer buf) + (erase-buffer) + (insert (concat + ;; 初期値をいじるよりも modify-frame-parameters + ;; で変えるだけの方がいい? + "(delete 'width default-frame-alist)\n" + "(delete 'height default-frame-alist)\n" + "(delete 'top default-frame-alist)\n" + "(delete 'left default-frame-alist)\n" + "(setq default-frame-alist (append (list\n" + "'(width . " (int-to-string nCWidth) ")\n" + "'(height . " (int-to-string nCHeight) ")\n" + "'(top . " (int-to-string tMargin) ")\n" + "'(left . " (int-to-string lMargin) "))\n" + "default-frame-alist))\n" + ;;"(setq default-frame-alist default-frame-alist)" + )) + (save-buffer) + )) +(defun my-window-size-load () + (let* ((file "~/.emacs.d/.framesize.el")) + (if (file-exists-p file) + (load file)))) +(when window-system + (my-window-size-load) + (add-hook 'after-init-hook ;何かがframeの大きさ勝手に変えやがる + (lambda () + (run-with-timer 1 + nil + (lambda () + (modify-frame-parameters (selected-frame) + default-frame-alist)))) + t) + ;; (add-hook 'make-frame-hook + ;; (lambda () + ;; (run-with-timer 1 + ;; nil + ;; (lambda () + ;; (modify-frame-parameters (selected-frame) + ;; initial-frame-alist)))) + ;; t) + (add-hook 'kill-emacs-hook + 'my-window-size-save)) + +;; windowサイズを固定 +;; setq default-frame-alist +;; (append (list '(width . 80) +;; '(height . 35) +;; ) +;; default-frame-alist) +;; ) ;;デフォルトのフレーム設定 + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; 現在行をハイライト +;; http://wiki.riywo.com/index.php?Meadow +(defface hlline-face + '((((type x w32) + (class color) + (background dark)) + (:background "midnightblue")) ; :foreground "white")) ;; ハイライトの文字色は変えない方がいいかも + (((type x w32) + (class color) + (background light)) + (:background "gainsboro")) + (t + ())) + "*Face used by hl-line.") +(defface hlline-ul-face + '((t (:underline "yellow"))) + "underline yellow") +(setq hl-line-face 'hlline-face) +(global-hl-line-mode 1) + +;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ;; emacsを殺伐とさせる +;; ;; 補完させるとき失敗するからなし +;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html +;; (defadvice message (before message-for-stupid (arg &rest arg2) activate) +;; (setq arg +;; (concat arg +;; (if (eq nil (string-match "\\. *$" arg)) ".") +;; " And You are a Coward!"))) + + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; ubuntu + +(defun my-load-scim () + "use scim-bridge.el as japanese im." + ;; Load scim-bridge. + (require 'scim-bridge) + ;; Turn on scim-mode automatically after loading .emacs + (add-hook 'after-init-hook 'scim-mode-on) + (setq scim-cursor-color "red") + (scim-define-preedit-key ?\^h t) + (scim-define-common-key ?\* nil) + (scim-define-common-key ?\^/ nil)) + + + +(defun my-load-anthy () + "use anthy.el as japanese im." + ;; anthy + (require 'anthy) + (global-set-key [muhenkan] (lambda () (interactive) (anthy-mode-off))) + (global-set-key [henkan] (lambda () (interactive) (anthy-mode-on))) + (when (>= emacs-major-version 23) + (setq anthy-accept-timeout 1))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; windows用設定 + +;; (add-to-list 'exec-path "c:/Program Files/Gauche/bin/") + +(defun start-ckw-bash () + "" + (interactive) + (start-process "ckw_bash" + nil + "C:/Documents and Settings/sr/Application Data/dbx/apps/ckw/ckw.exe")) ; cじゃないといけないらしい + +(defun my-w32-add-export-path (&rest args) + "" + (mapcar (lambda (path) + (add-to-list 'exec-path (expand-file-name path))) + args) + (setenv "PATH" + (mapconcat 'convert-standard-filename + exec-path + ";"))) + +(when (eq system-type 'windows-nt) + ;; (setq scheme-program-name "\"c:/Program Files/Gauche/bin/gosh.exe\" -i") + ;; (setq python-python-command "c:/Python26/python.exe") + + (define-key my-prefix-map (kbd "C-c") 'start-ckw-bash) + (my-w32-add-export-path "c:/WINDOWS" + (expand-file-name "~/bin") + (expand-file-name "~/dbx/apps/bin")) + + (when window-system + (setq w32-enable-synthesized-fonts t)) + (setq file-name-coding-system 'sjis)) + diff --git a/.keysnail.js b/.keysnail.js new file mode 100644 index 0000000..9a5d821 --- /dev/null +++ b/.keysnail.js @@ -0,0 +1,896 @@ +// ========================== KeySnail Init File =========================== // + +// この領域は, GUI により設定ファイルを生成した際にも引き継がれます +// 特殊キー, キーバインド定義, フック, ブラックリスト以外のコードは, この中に書くようにして下さい +// ========================================================================= // +//{{%PRESERVE% +// prompt.rows = 12; +// prompt.useMigemo = false; +// prompt.migemoMinWordLength = 2; +// prompt.displayDelayTime = 300; +// command.kill.killRingMax = 15; +// command.kill.textLengthMax = 8192; + +//userscript.addLoadPath("."); +//userscript.require("verticaltab.js"); + +////////////////////////////////////// +//// sitelocalkeymap +var local = {}; +plugins.options["site_local_keymap.local_keymap"] = local; +function fake(k, i) function () { key.feed(k, i); }; +function pass(k, i) [k, fake(k, i)]; +function ignore(k, i) [k, null]; + +// ext.add("ext-name", function () {}, "ext description"); +// style.register(""); +// local["^http://"] = [['a', function(ev, arg){}],]; + +/////////////////////////////////////////// +//// firefox +// style.register("#bookmarksPanel > hbox,#history-panel > hbox {display: none !important;} //#urlbar-container{max-width: 500px !important;}"); +util.setPrefs( + { + "browser.tabs.loadDivertedInBackground": true, + "dom.disable_window_open_feature.location": false, + "dom.max_script_run_time": 30, + "browser.bookmarks.max_backups":0, + "browser.urlbar.autocomplete.enabled":false, + "browser.cache.memory.capacity":16384, + "browser.sessionhistory.max_total_viewers":8, + "browser.download.manager.closeWhenDone":true, + "browser.download.useDownloadDir":false, + "browser.tabs.closeWindowWithLastTab":false, + "network.dns.disableIPv6":true + } +); + + +/////////////////////////////////// +//検索エンジン +plugins.options["search-url-list"] = [ + ["bing","http://bing.com/search?q=%q"], + ["yatwitter search","http://yats-data.com/yats/search?query=%q"], + ["twitter search","http://search.twitter.com/search?q=%q&lang=all"], + ["2ch","http://2ch-ranking.net/search.php?q=%q&imp=and&order=time"], + ["I\'m feelig lucky!","http://www.google.co.jp/search?q=%q&btnI=kudos"], + ["uncyclopedia","http://ja.uncyclopedia.info/wiki/%q"], + ["wikipedia","http://ja.wikipedia.org/wiki/%q"], + ["nicovideo.jp","http://www.nicovideo.jp/search/%q"], + ["alc","http://eow.alc.co.jp/%q/UTF-8/"], + ["google map","http://maps.google.co.jp/maps?hl=ja&q=%q&um=1&ie=UTF-8&sa=N&tab=wl"], + ["weblio","http://www.weblio.jp/content_find?query=%q"], + ["shoutcast","http://www.shoutcast.com/Internet-Radio/%q"], + ["10sr.posterous.com","http://www.google.com/search?q=%q&ie=UTF-8&oe=UTF-8&hl=ja&domains=10sr.posterous.com&sitesearch=10sr.posterous.com"], + ["delicious 10sr","http://delicious.com/10sr?addtag=%q&setcount=50&opennew=1"], + ["open raw","%r"], +]; + +plugins.options["my-keysnail-bookmarks"] = [ + "twitter.com", +]; + + + +//sitelocal +////////////////////////////////////////// +// 2ch chaika +local["^http://127.0.0.1:8823/thread/"] = [ + ['k', function (ev, arg) { + curl = window.content.location.href; + kurl = curl.replace(/http:.*thread\/(.*\/).*/, "chaika://post/$1"); + window.content.location.href = kurl; + } + ], +]; + +local["^http://w2.p2.2ch.net/p2/read.php"] = [ + ['k', function (ev, arg) { + var url = window.content.location.href; + var pt = /host=(.*?)&bbs=(.*?)&key=(.*?)&ls=/ ; + var result = url.match(pt); + var k = format("chaika://post/http://%s/test/read.cgi/%s/%s/", result[1], result[2], result[3]); + window.content.location.href = k; + } + ], +]; + +///////////////////////////////////////// +// feedly用マップ +local["^http://www.feedly.com/"] = [ + ['d', null], + ['j', null], + ['k', null], + ['n', null], + ['p', null], + ['o', null], + ['b', null], + ['S', null], + ['s', null], + ['?', null], + ['l', function (ev, arg) {window.content.location.href = "http://www.feedly.com/home#latest";}], + ['r', null], + ['x', function (ev, arg) {ev.target.dispatchEvent(key.stringToKeyEvent("g", true));}], + [['t', 'p'], function (ev, arg) {ev.target.dispatchEvent(key.stringToKeyEvent("t", true));}], + [['t', 'w'], function (ev, arg) {ext.exec("twitter-client-tweet", arg, ev);}], +]; + +///////////////////////////////////////// +//nicovideo用 +local["http://(www|tw|es|de|)\.nicovideo\.jp\/watch/*"] = [ + ["i", function (ev, arg) { ext.exec("nicoinfo", arg); }], + ["p", function (ev, arg) { ext.exec("nicopause", arg); }], + ["o", function (ev, arg) { ext.exec("nicommentvisible", arg); }], + ["m", function (ev, arg) { ext.exec("nicomute", arg); }], + [".", function (ev, arg) { ext.exec("nicovolumeIncrement", arg); }], + [",", function (ev, arg) { ext.exec("nicovolumeDecrement", arg); }], + ['f', function (ev, arg) { + curl = window.content.location.href; + kurl = curl.replace(/nicovideo.jp/, "nicovideofire.jp"); + window.content.location.href = kurl; + } + ], +]; + +///////////////////////////////////////// +// tumblr/dashboard +local["^http://www.tumblr.com/dashboard"] = [ + // ["C-", function (ev, arg) {gBrowser.mTabContainer.advanceSelectedTab(-1, true); }], + // ["C-", function (ev, arg) {gBrowser.mTabContainer.advanceSelectedTab(1, true); }], + ["", function (ev, arg) {window.content.location.href = "http://www.tumblr.com/dashboard"; }], + // ["", null], + ["J", function (ev, arg) { + if (window.loadURI) { + loadURI("javascript:(function(){b=20;s=100;t=document.getElementById('next_page_link').href.split('/')[5];max=t.substr(0,t.length-5);min=max-s;i=Math.floor(Math.random()*(max-min)+min);u=(i " + tglang + " : " + to); + }; + function decodeJSON(json) { + return util.safeEval("(" + json + ")"); + }; + function lookupword(word, target){ + translate(word, target, function (src, tg, translated) { + echo(src, word, tg, translated); + }); + }; + function read (aInitialInput) { + let prevText = ""; + + prompt.reader({ + message : "word or sentence to translate:", + initialinput : aInitialInput, + onChange: function (arg) { + let word = arg.textbox.value; + if (word !== prevText) { + prevText = word; + lookupword(word, targetLang); + } + }, + callback: function (s){}, + }); + }; + ext.add("google-itranslate",function(){read(content.document.getSelection() || "");},"google itranslate"); +})(); + +////////////////////////////////////// +// +ext.add("restart-firefox-add-menu", function(){ + const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; + var elm = document.createElementNS(XUL_NS, "menuitem"); + elm.setAttribute("label", "Restart Firefox"); + elm.setAttribute("id", "menu_RestartFirefoxKs") + elm.setAttribute("oncommand", function(){ + ext.exec("restart-firefox");}); + var menu = document.getElementById("menu_FilePopup"); + // menu.insertBefore(elm, menu.getElementById("menu_FileQuitItem")); + menu.appendChild(elm); +}, "add restart firefox menu"); + +////////////////////////////////////// +// +ext.add("fullscreen-page",function (ev) { + getBrowser().selectedTab = getBrowser().addTab("http://home.tiscali.nl/annejan/swf/timeline.swf"); + BrowserFullScreen(); +}, "fullscreen page"); + +////////////////////////////////////// +// restart firefox +// http://keysnail.g.hatena.ne.jp/Shinnya/20100723/1279878815 +ext.add("restart-firefox",function (ev) { + const nsIAppStartup = Components.interfaces.nsIAppStartup; + // Notify all windows that an application quit has been requested. + var os = Components.classes["@mozilla.org/observer-service;1"] + .getService(Components.interfaces.nsIObserverService); + var cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"] + .createInstance(Components.interfaces.nsISupportsPRBool); + os.notifyObservers(cancelQuit, "quit-application-requested", null); + // Something aborted the quit process. + if (cancelQuit.data) + return; + // Notify all windows that an application quit has been granted. + os.notifyObservers(null, "quit-application-granted", null); + // Enumerate all windows and call shutdown handlers + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + var windows = wm.getEnumerator(null); + while (windows.hasMoreElements()) { + var win = windows.getNext(); + if (("tryToClose" in win) && !win.tryToClose()) + return; + } + Components.classes["@mozilla.org/toolkit/app-startup;1"].getService(nsIAppStartup) + .quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit); +}, "restart firefox"); + +///////////////////////////////////////// +// copy feed url +ext.add("copy-url", function () { + const doc = content.document; + + let feeds = [[e.getAttribute("title"), e.getAttribute("href")] + for ([, e] in Iterator(doc.querySelectorAll(['link[type="application/rss+xml"]', + 'link[type="application/atom+xml"]'])))]; + var uh = window.content.location.href.replace(/(.*?\/\/[^/]*)(\/.*)?/,"$1"); + for (i = 0; i < feeds.length; i++) + if ( feeds[i][1].substr(0,1) == "/" ) feeds[i][1] = uh + feeds[i][1]; + feeds.unshift([window.content.document.title,window.content.location.href]); + prompt.selector( + { + message : "Select Feed", + collection : feeds, + callback : function (i) { + if (i >= 0) + command.setClipboardText(feeds[i][1]); + } + } + ); +}, "Copy url or feed url of current page"); + +/////////////////////////////////////// +// 評価しちゃうっぽい とりあえずこんな感じで +ext.add("keysnail-setting-menu",function(){ + var settingmenulist = [["keysnail setting dialogue",function(){return function(){KeySnail.openPreference();};}], + ["firefox addon manager",function(){return function(){BrowserOpenAddonsMgr();};}], + ["reload .keysnail.js",function(){return function() {userscript.reload();};}], + ["check for plugins update",function(){return function(){ext.exec("check-for-plugins-update");};}], + ]; + prompt.selector( + { + message : "open setting dialog", + collection : settingmenulist, + callback : function (i) { settingmenulist[i][1]()(); }, + }); +},"open keysnail setting menu"); + +////////////////////////// +//プラグイン一括アップデート +ext.add("check-for-plugins-update", function () { + [p for (p in plugins.context)].forEach(function (p) { try { userscript.updatePlugin(p); } catch(e) {} }); +}, "Check for all plugin's update"); + +//////////////////////// +//マルチプルタブハンドラ +ext.add("multiple-tab-handler-close-selected-and-current-tabs", function () { + BrowserCloseTabOrWindow(); + // if (MultipleTabService) { + // //BrowserCloseTabOrWindow(); + // //MultipleTabService.setSelection(gBrowser.mCurrentTab, true); + MultipleTabService.closeTabs(MultipleTabService.getSelectedTabs()); + // } else { + // BrowserCloseTabOrWindow();} +}, '選択タブと現在のタブを閉じる'); + +ext.add("if-mth-exist", function() { + if (MultipleTabService != undefined) display.echoStatusBar("true"); +},'if mth exist'); + +//////////////////////// +// instapaper +ext.add("instapaper-add-this-page-and-close",function(){ + var url = window.content.location.href; + var title = window.content.document.title; + var tab = gBrowser.selectedTab; + var username = "8slashes+instapaper@gmail.com"; + var password = ""; + var passwordManager = (Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager)); + var logins = passwordManager.findLogins({}, "http://www.instapaper.com", "", null); + for (var i = 0; i < logins.length; i++) { + if (logins[i].username == username) { + password = logins[i].password; + break; + } + } + var comment = ""; + // prompt.read("Instapaper comment:",function(cm){ + // if(cm){comment = cm;} + // }); + display.echoStatusBar("Instapaper: adding " + url + "..."); + util.httpPost("https://www.instapaper.com/api/add", + {"username" : encodeURIComponent(username), + "password" : password, + "url" : encodeURIComponent(url), + "title" : encodeURIComponent(title),}, + function (xhr) { + display.echoStatusBar(xhr.status); + if (xhr.readyState == 4 && xhr.status == 201) { + // var title = decodeURIComponent(xhr.getResponseHeader("X-Instapaper-Title")); //超文字化けする + try { + Components.classes['@mozilla.org/alerts-service;1']. + getService(Components.interfaces.nsIAlertsService). + showAlertNotification(null, "Instapaper", "Page " + title + " added successfully", false, '', null); + } catch(e) { + // prevents runtime error on platforms that don't implement nsIAlertsService + } + display.echoStatusBar("Instapaper: adding " + url + "...done."); + gBrowser.removeTab(tab); + } else{ + display.echoStatusBar("Instapaper: Something wrong has happended!"); + if (window.loadURI) { + loadURI("javascript:function%20iprl5(){var%20d=document,z=d.createElement('scr'+'ipt'),b=d.body,l=d.location;try{if(!b)throw(0);d.title='(Saving...)%20'+d.title;z.setAttribute('src',l.protocol+'//www.instapaper.com/j/mt8YO6Cuosmf?u='+encodeURIComponent(l.href)+'&t='+(new%20Date().getTime()));b.appendChild(z);}catch(e){alert('Please%20wait%20until%20the%20page%20has%20loaded.');}}iprl5();void(0)"); + } + } + }); +},'instapaper add page and close tab when done without error.'); + +//////////////////////// +//検索 +ext.add("query-then-engine", function () { + prompt.reader({message : "Search Word?:", + callback : function (q) { + if (q) { + prompt.selector({ message : "search \"" + q + "\" with?", + collection : plugins.options["search-url-list"], + width : [20,80], + callback : function (i) { getBrowser().selectedTab = getBrowser().addTab(plugins.options["search-url-list"][i][1].replace("%r",q).replace("%q",encodeURIComponent(q))); }, + }); + }; + }, + initialInput : content.document.getSelection() || "", + }); +}, "enter search word and then select engine"); + +/////////////////////// +//diggler +ext.add("dig-url", function () { + var url = window.content.location.href; + var nsurl = []; + var pname = ""; + var ssurl = []; + var durl = []; + nsurl = url.split("#"); + var pname = nsurl[1]; + ssurl = nsurl[0].split("/"); + durl[0] = ssurl[0] + "//" + ssurl[2]; + ssurl.splice(0,3); + for (var i = 0; i < ssurl.length; i++){ + var durlsaved = durl[0]; + durl.unshift(durlsaved + "/" + ssurl[i]); + }; + if (pname) { + var durlfull = durl[0] + "#"+ pname; + durl.unshift(durlfull); + }; + prompt.selector({ message : "dig " + url, + collection : durl, + callback : function (i) { window.content.location.href = durl[i]; }, + }); +},"keysnail diggler "); + +///////////////////////////////////// +// 閉じたタブリスト +ext.add("list-closed-tabs", function () { + const fav = "chrome://mozapps/skin/places/defaultFavicon.png"; + var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore); + var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON); + var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))]; + + if (!closedTabs.length) + return void display.echoStatusBar("最近閉じたタブが見つかりませんでした", 2000); + + prompt.selector( + { + message : "select tab to undo:", + collection : closedTabs, + flags : [ICON | IGNORE, 0, 0], + callback : function (i) { if (i >= 0) window.undoCloseTab(i); } + }); +}, "List closed tabs"); + +ext.add("echo-closed-tabs", function () { + var ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore); + var json = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON); + // var closedTabs = [[tab.image || fav, tab.title, tab.url] for each (tab in json.decode(ss.getClosedTabData(window)))]; + var lasttab = json.decode(ss.getClosedTabData(window))[0]; + dump = "" + for (var i in lasttab) { dump += lasttab[i] + "\n"; } + confirm(dump); + +}, "List closed tabs"); + +/////////////////////////////////////// +// +ext.add("focus-on-content", function(){ + document.getElementById("searchbar").focus(); + document.commandDispatcher.advanceFocus(); + document.commandDispatcher.advanceFocus(); +}, "forcus on content"); + +ext.add("_focus-on-content", function(){ + gBrowser.focus(); + _content.focus(); +}, "focus on content"); + +ext.add("hide-sidebar", function(){ + var sidebarBox = document.getElementById("sidebar-box"); + if (!sidebarBox.hidden) { + toggleSidebar(sidebarBox.getAttribute("sidebarcommand")); + } +}, "hide-sidebar"); + + +//}}%PRESERVE% +// ========================================================================= // + +// ========================= Special key settings ========================== // + +key.quitKey = "ESC"; +key.helpKey = "C-h"; +key.escapeKey = "C-q"; +key.macroStartKey = ""; +key.macroEndKey = ""; +key.universalArgumentKey = "C-u"; +key.negativeArgument1Key = "C--"; +key.negativeArgument2Key = "C-M--"; +key.negativeArgument3Key = "M--"; +key.suspendKey = "Not defined"; + +// ================================= Hooks ================================= // + +hook.setHook('KeySnailInitialized', function () { + ext.exec("shiitake-toggle-style"); +}); + +hook.setHook('KeyBoardQuit', function (aEvent) { + command.closeFindBar(); + if (util.isCaretEnabled()) { + command.resetMark(aEvent); + } else { + goDoCommand("cmd_selectNone"); + } + key.generateKey(aEvent.originalTarget, KeyEvent.DOM_VK_ESCAPE, true); +}); +hook.addToHook('KeyBoardQuit', function (aEvent) { + ext.exec("hide-sidebar"); +}); + +hook.setHook('Unload', function () { + util.getBrowserWindows().some(function (win) { + if (win === window) { + return false; + } + const ks = win.KeySnail; + share.pluginUpdater = ks.getPluginUpdater(share.pluginUpdater.pluginsWithUpdate); + ks.setUpPluginUpdaterDelegator(); + return true; + }); +}); + + +// ============================= Key bindings ============================== // + +key.setGlobalKey([[''], ['\\']], function (ev, arg) { + ev.target.dispatchEvent(key.stringToKeyEvent("ESC", true)); +}, 'escape'); + +key.setGlobalKey('C-', function () { + gBrowser.mTabContainer.advanceSelectedTab(1, true); +}, 'ひとつ右のタブへ'); + +key.setGlobalKey('C-', function () { + gBrowser.mTabContainer.advanceSelectedTab(-1, true); +}, 'ひとつ左のタブへ'); + +key.setGlobalKey('C-', function () { + var browser = getBrowser(); + if (browser.mCurrentTab.previousSibling) { + browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1); + } else { + browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1); + } +}, '選択中のタブを右へ'); + +key.setGlobalKey('C-', function () { + var browser = getBrowser(); + if (browser.mCurrentTab.nextSibling) { + browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1); + } else { + browser.moveTabTo(browser.mCurrentTab, 0); + } +}, '選択中のタブを左へ'); + +key.setGlobalKey('M-:', function (ev) { + command.interpreter(); +}, 'JavaScript のコードを評価'); + +key.setGlobalKey('C-g', function (ev, arg) { + return; +}, 'ignore'); + +key.setViewKey('0', function (ev, arg) { + var n = gBrowser.mCurrentTab._tPos; + BrowserCloseTabOrWindow(); + gBrowser.selectedTab = gBrowser.mTabs[n]; +}, '閉じて次のタブ'); + +key.setViewKey('x', function (aEvent, aArg) { + ext.select(aArg, aEvent); +}, 'エクステ一覧'); + +key.setViewKey(['t', 'm'], function (ev, arg) { + if (window.loadURI) { + loadURI("javascript:window.location='http://api.tweetmeme.com/visit?url='+window.location;"); + } +}, 'open with tweetmeme'); + +key.setViewKey(['t', 'w'], function (ev, arg) { + ext.exec("twitter-client-tweet", arg, ev); +}, 'つぶやく', true); + +key.setViewKey(['t', 'p'], function (ev, arg) { + ext.exec("twitter-client-tweet-this-page", arg, ev); +}, 'このページのタイトルと URL を使ってつぶやく', true); + +key.setViewKey('u', function () { + undoCloseTab(); +}, '閉じたタブを元に戻す'); + +key.setViewKey('g', function () { + goDoCommand("cmd_scrollTop"); +}, 'ページ先頭へ移動'); + +key.setViewKey('G', function () { + goDoCommand("cmd_scrollBottom"); +}, 'ページ末尾へ移動'); + +key.setViewKey('r', function (aEvent) { + BrowserReload(); +}, '再読み込み'); + +key.setViewKey('m', function (ev, arg) { + _fi.toogle(); +}, 'fetchimiをトグル'); + +key.setViewKey('d', function (ev, arg) { + if (window.loadURI) { + loadURI("javascript:(function(){f='http://delicious.com/save?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'&v=5&';a=function(){if(!window.open(f+'noui=1&jump=doclose','deliciousuiv5','location=no,links=no,scrollbars=no,toolbar=no,width=550,height=550'))location.href=f+'jump=yes'};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()"); + } +}, 'deliciousでブックマーク'); + +key.setViewKey('p', function (ev, arg) { + if (window.loadURI) { + loadURI("javascript:var%20b=document.body;var%20POSTEROUS___bookmarklet_domain='http://posterous.com';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.type='text/javascript');void(z.src='http://posterous.com/javascripts/bookmarklet2.js');void(b.appendChild(z));}else{}"); + } +}, 'posterousに投稿'); + +key.setViewKey('SPC', function (ev, arg) { + MultipleTabService.toggleSelection(gBrowser.mCurrentTab); + gBrowser.mTabContainer.advanceSelectedTab(1, true); +}, 'タブの選択をトグルして次のタブ'); + +key.setViewKey('S-SPC', function (ev, arg) { + MultipleTabService.toggleSelection(gBrowser.selectedTab); + gBrowser.mTabContainer.advanceSelectedTab(-1, true); +}, 'タブの選択をトグルして前のタブ'); + +key.setViewKey('z', function (ev, arg) { + ext.exec("keysnail-setting-menu", arg, ev); +}, 'open keysnail setting menu', true); + +key.setViewKey('T', function (ev, arg) { + ext.exec("google-itranslate", arg, ev); +}, 'google itranslate', true); + +key.setViewKey('l', function (ev, arg) { + var n = gBrowser.mCurrentTab._tPos; + gBrowser.moveTabTo(gBrowser.mCurrentTab, gBrowser.mTabContainer.childNodes.length - 1); + gBrowser.selectedTab = gBrowser.mTabs[n]; +}, 'このタブを後回し'); + +key.setViewKey('C-SPC', function (ev, arg) { + MultipleTabService.toggleSelection(gBrowser.selectedTab); +}, 'タブの選択をトグル'); + +key.setViewKey('s', function (ev, arg) { + var n = gBrowser.mCurrentTab._tPos; + gBrowser.moveTabTo(gBrowser.mCurrentTab, 0); + if (n != 0) { + gBrowser.selectedTab = gBrowser.mTabs[n]; + } +}, 'このタブを保持する'); + +key.setViewKey('U', function (ev, arg) { + ext.exec("list-closed-tabs", arg, ev); +}, 'List closed tabs', true); + +key.setViewKey('e', function () { + command.focusElement(command.elementsRetrieverTextarea, 0); +}, '最初のインプットエリアへフォーカス', true); + +key.setViewKey('S', function (ev, arg) { + if (window.loadURI) { + loadURI("javascript:var%20b=document.body;var%20GR________bookmarklet_domain='https://www.google.com';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.src='https://www.google.com/reader/ui/link-bookmarklet.js');void(b.appendChild(z));}else{}"); + } +}, 'google reader share'); + +key.setViewKey('!', function (ev, arg) { + shell.input(); +}, 'Command system'); + +key.setViewKey('b', function (ev, arg) { + BarTap.putOnTap(gBrowser.mCurrentTab, gBrowser); +}, 'bartab put on tab'); + +key.setViewKey('R', function () { + BrowserReloadSkipCache(); +}, '更新(キャッシュを無視)'); + +key.setViewKey('', function () { + BrowserBack(); +}, '戻る'); + +key.setViewKey('S-', function () { + BrowserForward(); +}, '進む'); + +key.setViewKey('q', function (ev, arg) { + ext.exec("query-then-engine", arg, ev); +}, 'enter search word and then select engine', true); + +key.setViewKey('D', function (ev, arg) { + ext.exec("dig-url", arg, ev); +}, 'keysnail diggler ', true); + +key.setViewKey('/', function () { + command.iSearchForward(); +}, 'インクリメンタル検索', true); + +key.setViewKey('?', function (ev) { + command.iSearchForwardKs(ev); +}, 'Emacs ライクなインクリメンタル検索', true); + +key.setViewKey('a', function (ev, arg) { + allTabs.open(); +}, 'alltabs.open'); + +key.setViewKey('C', function (ev, arg) { + ext.exec("copy-url", arg, ev); +}, '選択タブと現在のタブを閉じる', true); + +key.setViewKey('I', function (ev, arg) { + ext.exec("instapaper-add-this-page-and-close", arg, ev); +}, 'instapaper add page', true); + +key.setViewKey('', function (ev) { + goDoCommand("cmd_scrollPageUp"); +}, '一画面分スクロールアップ'); + +key.setViewKey('', function (ev) { + goDoCommand("cmd_scrollPageDown"); +}, '一画面スクロールダウン'); + +key.setViewKey('C-w', function (ev) { + command.copyRegion(ev); +}, '選択中のテキストをコピー'); + +key.setViewKey([[''], ['']], function (ev, arg) { + return; +}, 'ignore'); + +key.setEditKey(['C-x', 'h'], function (ev) { + command.selectAll(ev); +}, '全て選択', true); + +key.setEditKey([['C-x', 'u'], ['C-_']], function (ev) { + display.echoStatusBar("Undo!", 2000); + goDoCommand("cmd_undo"); +}, 'アンドゥ'); + +key.setEditKey(['C-x', 'r', 'd'], function (ev, arg) { + command.replaceRectangle(ev.originalTarget, "", false, !arg); +}, '矩形削除', true); + +key.setEditKey(['C-x', 'r', 't'], function (ev) { + prompt.read("String rectangle: ", function (aStr, aInput) {command.replaceRectangle(aInput, aStr);}, ev.originalTarget); +}, '矩形置換', true); + +key.setEditKey(['C-x', 'r', 'o'], function (ev) { + command.openRectangle(ev.originalTarget); +}, '矩形行空け', true); + +key.setEditKey(['C-x', 'r', 'k'], function (ev, arg) { + command.kill.buffer = command.killRectangle(ev.originalTarget, !arg); +}, '矩形キル', true); + +key.setEditKey(['C-x', 'r', 'y'], function (ev) { + command.yankRectangle(ev.originalTarget, command.kill.buffer); +}, '矩形ヤンク', true); + +key.setEditKey([['C-SPC'], ['C-@']], function (ev) { + command.setMark(ev); +}, 'マークをセット', true); + +key.setEditKey('C-o', function (ev) { + command.openLine(ev); +}, '行を開く (Open line)'); + +key.setEditKey('C-\\', function (ev) { + display.echoStatusBar("Redo!", 2000); + goDoCommand("cmd_redo"); +}, 'リドゥ'); + +key.setEditKey('C-a', function (ev) { + command.beginLine(ev); +}, '行頭へ移動'); + +key.setEditKey('C-e', function (ev) { + command.endLine(ev); +}, '行末へ'); + +key.setEditKey('M-h', function (ev) { + command.previousChar(ev); +}, '一文字左へ移動'); + +key.setEditKey('M-f', function (ev) { + command.forwardWord(ev); +}, '一単語右へ移動'); + +key.setEditKey('M-b', function (ev) { + command.backwardWord(ev); +}, '一単語左へ移動'); + +key.setEditKey('M-j', function (ev) { + command.nextLine(ev); +}, '一行下へ'); + +key.setEditKey('M-k', function (ev) { + command.previousLine(ev); +}, '一行上へ'); + +key.setEditKey('C-v', function (ev) { + command.pageDown(ev); +}, '一画面分下へ'); + +key.setEditKey('M-v', function (ev) { + command.pageUp(ev); +}, '一画面分上へ'); + +key.setEditKey('M-<', function (ev) { + command.moveTop(ev); +}, 'テキストエリア先頭へ'); + +key.setEditKey('M->', function (ev) { + command.moveBottom(ev); +}, 'テキストエリア末尾へ'); + +key.setEditKey('C-d', function (ev) { + goDoCommand("cmd_deleteCharForward"); +}, '次の一文字削除'); + +key.setEditKey('C-h', function (ev) { + goDoCommand("cmd_deleteCharBackward"); +}, '前の一文字を削除'); + +key.setEditKey('M-d', function (ev) { + command.deleteForwardWord(ev); +}, '次の一単語を削除'); + +key.setEditKey([['C-'], ['M-']], function (ev) { + command.deleteBackwardWord(ev); +}, '前の一単語を削除'); + +key.setEditKey('M-u', function (ev, arg) { + command.wordCommand(ev, arg, command.upcaseForwardWord, command.upcaseBackwardWord); +}, '次の一単語を全て大文字に (Upper case)'); + +key.setEditKey('M-c', function (ev, arg) { + command.wordCommand(ev, arg, command.capitalizeForwardWord, command.capitalizeBackwardWord); +}, '次の一単語をキャピタライズ'); + +key.setEditKey('C-k', function (ev) { + command.killLine(ev); +}, 'カーソルから先を一行カット (Kill line)'); + +key.setEditKey('C-y', command.yank, '貼り付け (Yank)'); + +key.setEditKey('M-y', command.yankPop, '古いクリップボードの中身を順に貼り付け (Yank pop)', true); + +key.setEditKey('C-M-y', function (ev) { + if (!command.kill.ring.length) { + return; + } + let (ct = command.getClipboardText()) (!command.kill.ring.length || ct != command.kill.ring[0]) && + command.pushKillRing(ct); + prompt.selector({message: "Paste:", collection: command.kill.ring, callback: function (i) {if (i >= 0) {key.insertText(command.kill.ring[i]);}}}); +}, '以前にコピーしたテキスト一覧から選択して貼り付け', true); + +key.setEditKey('C-w', function (ev) { + goDoCommand("cmd_copy"); + goDoCommand("cmd_delete"); + command.resetMark(ev); +}, '選択中のテキストを切り取り (Kill region)', true); + +key.setEditKey('M-n', function (ev) { + command.walkInputElement(command.elementsRetrieverTextarea, true, true); +}, '次のテキストエリアへフォーカス'); + +key.setEditKey('M-p', function (ev) { + command.walkInputElement(command.elementsRetrieverTextarea, false, true); +}, '前のテキストエリアへフォーカス'); + +key.setEditKey('M-w', function (ev) { + command.copyRegion(ev); +}, '選択中のテキストをコピー'); + +key.setEditKey('M-l', function (ev) { + command.nextChar(ev); +}, '一文字右へ移動'); diff --git a/.profile b/.profile new file mode 100755 index 0000000..589efd1 --- /dev/null +++ b/.profile @@ -0,0 +1,41 @@ +#!/bin/bash +if [ -n "${DESKTOP_SESSION}" ]; then + xmodmap -e 'keycode 135 = Alt_R Meta_R' # menu key as alt + xmodmap -e 'keycode 101 = Alt_R Meta_R' # hiragana key as alt + xmodmap -e 'remove Lock = Caps_Lock' + xmodmap -e 'add Control = Caps_Lock' + + synclient VertEdgeScroll=0 + synclient HorizEdgeScroll=0 + synclient MaxTapTime=0 + synclient MaxSpeed=0.4 + synclient MinSpeed=0.2 +fi + +export LC_TIME=C +export TERMCAP="${TERMCAP}:vb=" +export HOSTNAME +export BROWSER=firefox +# export TMP=/tmp +# export TEMP=/tmp + +addtopath(){ + for p in "$@" + do + echo $PATH | grep -E "^$p:|:$p:|:$p$" >/dev/null 2>&1 || PATH="$p:${PATH}" + done +} +# export PATH="${PATH}:${HOME}/bin:${HOME}/dbx/dev/bin" +addtopath ${HOME}/bin + +type git 1>/dev/null 2>&1 && test ! -f ~/.gitconfig && { + # export GISTY_DIR="$HOME/dev/gists" + git config --global user.name "10sr" + git config --global user.email sr10@users.sourceforge.jp + git config --global core.autocrlf false + # git config --global github.token ** +} + +test -f "${HOME}/.pythonrc" && export PYTHONSTARTUP="${HOME}/.pythonrc" +export PYTHONPATH=~/.py + diff --git a/.vimrc b/.vimrc new file mode 100644 index 0000000..25f6a21 --- /dev/null +++ b/.vimrc @@ -0,0 +1,137 @@ +"外部ファイル読み込み +"if filereadable(expand('~/filepath')) +"source ~/filepath +"endif +if !isdirectory(expand('~/.vim')) + call mkdir(expand('~/.vim')) +endif + +""""""""""""""""""""""""""""""""""" +"set nocompatible "vi互換にしない +"バックアップファイルを作るディレクトリ +if !isdirectory(expand('~/.vim/backup')) + call mkdir(expand('~/.vim/backup')) +endif +filetype plugin indent on +set backup "バックアップ +set backupdir=$HOME/.vim/backup +set swapfile "スワップファイル用のディレクトリ +set directory=$HOME/.vim/backup +set viminfo+=n~/.vim/viminfo "viminfo +set list "タブ文字、行末など不可視文字を表示する +set listchars=tab:>-,extends:<,trail:-,eol:$ "listで表示される文字のフォーマットを指定する +set showmatch "閉じ括弧が入力されたとき、対応する括弧を表示する +set ignorecase +set smartcase "検索時に大文字を含んでいたら大/小を区別 +set whichwrap=b,s,h,l,<,>,[,] "カーソルを行頭、行末で止まらないようにする +set showmode "モード表示 +"set title "編集中のファイル名を表示 +set incsearch +set wrapscan "折り返し検索 +set showmatch "括弧を閉じた時、対になる括弧を一瞬ハイライトする +set ruler "行番号、カーソル位置を表示 +"set number +set laststatus=2 "ステータスラインを常に表示 +set showcmd +set scrolloff=2 "常に前後2行を表示 +syntax enable "シンタックス +set hidden "編集中でも他ファイルへ移動可 +set backspace=indent,eol,start "バックスペースでなんでも消せるように +"set autochdir "自動的にカレントディレクトリを現在のファイルのディレクトリにする macだと出来ないってゆわれた +set encoding=utf-8 "言語設定 +set fileencodings=utf-8,shift-jis,euc-jp,latin1 +set mouse=h "マウス使わない +set clipboard+=unnamed "クリップボードをWindowsと連携 +set visualbell "ビープしない +set browsedir=buffer "バッファで開いているファイルのディレクトリ + +set tabstop=4 "タブの画面上での幅 +set shiftwidth=4 "width of indent +set expandtab "タブをスペースに展開する +set autoindent "オートインデント +set smartindent + +let g:netrw_liststyle = 1 +let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+' + +"gvimrc分けるのめんどい +if has('gui_running') + "ツールバー、スクロールバー消す + set guioptions-=T + set guioptions-=r + set lines=45 + set columns=110 + set guifont=DejaVu\ Sans\ Mono\ 9 +endif + +if has('win32') +"Windows 用の設定 +endif + +""""""""""""""""""""""""""""""""""""""" +"マップ +"imap でC-Jをescにできる。? +"nmap +"vmap +"map でそれぞれのモードでマップを指定 +"キーマッピングには大きく分けて map と noremap の 2 つの種類があります。 +"* map はキーシーケンスを展開したあと、さらに別のマップを適用しようとします。 +"* noremap は一度だけ展開します。 +"→マップを再帰的に展開するときはmap、決め打ちはnoremap(キーの入れ替えなど) +"割と保存 +inoremap :w +inoremap :w +noremap :w + +"方向キーでバッファ操作 +"nnoremap :bp! +"nnoremap :bn! +"nnoremap :ls! +"nnoremap :bd +"nnoremap cd :cd%:h +nnoremap :Explore + +"http://d.hatena.ne.jp/yuroyoro/20101104/1288879591 +"見た目で行移動 +nnoremap j gj +nnoremap k gk + +" highlight current line +" set cursorline +" カレントウィンドウにのみ罫線を引く +augroup cch + autocmd! cch + autocmd WinLeave * set nocursorline + autocmd WinEnter,BufRead * set cursorline +augroup END + +hi clear CursorLine +highlight CursorLine term=underline cterm=underline gui=underline + +"入力モード時、ステータスラインのカラーを変更 +augroup InsertHook +autocmd! +autocmd InsertEnter * highlight StatusLine guifg=#ccdc90 guibg=#2E4340 +autocmd InsertLeave * highlight StatusLine guifg=#2E4340 guibg=#ccdc90 +augroup END + +" save window position and size +if has('gui_running') +let g:save_window_file = expand('~/.vimwinpos') +augroup SaveWindow + autocmd! + autocmd VimLeavePre * call s:save_window() + function! s:save_window() + let options = [ + \ 'set columns=' . &columns, + \ 'set lines=' . &lines, + \ 'winpos ' . getwinposx() . ' ' . getwinposy(), + \ ] + call writefile(options, g:save_window_file) + endfunction +augroup END + +if filereadable(g:save_window_file) + execute 'source' g:save_window_file +endif +endif