You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1776 lines
63 KiB

  1. ;; load another file
  2. ;; (load-file "~/filepath")
  3. (unless (file-directory-p (expand-file-name user-emacs-directory))
  4. (make-directory (expand-file-name user-emacs-directory)))
  5. (let ((d (expand-file-name (concat user-emacs-directory
  6. "lisp"))))
  7. (unless (file-directory-p d)
  8. (make-directory d))
  9. (add-to-list 'load-path d))
  10. (require 'cl nil t)
  11. (progn ; hook run when directory changed
  12. (defvar buffer-file-changed-function nil "Hook run when buffer file changed.
  13. Each function is called with two args, the filename before changing and after changing.")
  14. (declare-function run-buffer-file-change-function "emacs.el")
  15. (add-hook 'post-command-hook
  16. 'run-buffer-file-changed-function)
  17. (lexical-let (previous-file)
  18. (defun run-buffer-file-changed-function ()
  19. ""
  20. (unless (and previous-file
  21. (equal previous-file
  22. (expand-file-name (or buffer-file-name
  23. default-directory))))
  24. (let ((pfile previous-file)
  25. (cfile (expand-file-name (or buffer-file-name
  26. default-directory))))
  27. (setq previous-file cfile)
  28. (run-hook-with-args 'directory-changed-function pfile cfile)))))
  29. ;; (add-hook 'directory-changed-function
  30. ;; (lambda (pdir cdir)
  31. ;; (message "dir changed %s to %s !" pdir cdir)))
  32. )
  33. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  34. ;; download library from web
  35. (require 'url)
  36. (defun dllib-if-unfound (url &optional bite-compile-p force-download-p)
  37. "if LIB does not exist, download it from URL and locate it to \"~/emacs.d/lisp/LIB.el\".
  38. return nil if LIB unfound and downloading failed, otherwise the path of LIB."
  39. (let* ((dir (expand-file-name (concat user-emacs-directory "lisp/")))
  40. (lib (file-name-nondirectory url))
  41. (lpath (concat dir lib))
  42. (locate-p (locate-library lib)))
  43. (if (or force-download-p (not locate-p))
  44. (progn (condition-case nil
  45. (progn (message "downloading %s..." url)
  46. (url-copy-file url
  47. lpath
  48. t)
  49. (when bite-compile-p
  50. (byte-compile-file lpath)))
  51. (error (and (file-readable-p lpath)
  52. (delete-file lpath))
  53. (message "downloading %s...something wrong happened!" url)
  54. nil))
  55. (locate-library lib))
  56. locate-p)))
  57. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  58. ;; start and quit
  59. (setq inhibit-startup-message t)
  60. (setq frame-title-format (list '(:eval (format-time-string (or display-time-format "")))
  61. " | %b "
  62. '(:eval (number-to-string (length (buffer-list-not-start-with-space))))
  63. " buffers ["
  64. invocation-name
  65. " "
  66. emacs-version
  67. " "
  68. (symbol-name system-type)
  69. "] "
  70. '(:eval (symbol-name last-command))))
  71. (defun set-terminal-title (&rest args)
  72. ""
  73. (interactive "sString to set as title: ")
  74. (let ((tty (frame-parameter nil
  75. 'tty-type)))
  76. (when (and tty
  77. (eq t (compare-strings "xterm" 0 5
  78. tty 0 5)))
  79. (send-string-to-terminal (apply 'concat
  80. "\033]0;"
  81. `(,@args "\007"))))))
  82. (defun my-set-terminal-title ()
  83. ""
  84. (set-terminal-title "["
  85. invocation-name
  86. " "
  87. emacs-version
  88. " "
  89. (symbol-name system-type)
  90. "] "
  91. (abbreviate-file-name (or buffer-file-name default-directory))))
  92. (add-hook 'directory-changed-function
  93. (lambda (p c)
  94. (my-set-terminal-title)))
  95. (add-hook 'suspend-resume-hook
  96. 'my-set-terminal-title)
  97. (defun buffer-list-not-start-with-space ()
  98. (let ((bl (buffer-list))
  99. b nbl)
  100. (while bl
  101. (setq b (pop bl))
  102. (unless (string-equal " "
  103. (substring (buffer-name b)
  104. 0
  105. 1))
  106. (add-to-list 'nbl b)))
  107. nbl))
  108. (setq confirm-kill-emacs 'y-or-n-p)
  109. (setq gc-cons-threshold (* 1024 1024 4))
  110. (when window-system
  111. (add-to-list 'default-frame-alist '(cursor-type . box))
  112. (add-to-list 'default-frame-alist '(background-color . "white"))
  113. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  114. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100))) ; does not work?
  115. )
  116. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  117. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  118. (tool-bar-mode 0)
  119. (set-scroll-bar-mode nil)
  120. (add-hook 'kill-emacs-hook ; load when exitting to examine if file is written properly
  121. (lambda ()
  122. (when (file-readable-p "~/.emacs")
  123. (load-file "~/.emacs"))
  124. ))
  125. (add-hook 'after-init-hook
  126. (lambda ()
  127. (message (emacs-init-time))
  128. (switch-to-buffer "*Messages*")
  129. ))
  130. (cd ".") ; when using windows use / instead of \ in `default-directory'
  131. ;; locale
  132. (set-language-environment "Japanese")
  133. (set-default-coding-systems 'utf-8-unix)
  134. (prefer-coding-system 'utf-8-unix)
  135. (setq system-time-locale "C")
  136. ;; my prefix map
  137. (define-prefix-command 'my-prefix-map)
  138. '(add-hook 'after-init-hook
  139. (lambda ()
  140. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  141. ))
  142. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  143. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  144. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  145. ;; (comint-show-maximum-output)
  146. ;; kill scratch
  147. (add-hook 'after-init-hook
  148. (lambda ()
  149. (kill-buffer "*scratch*")))
  150. ;; modifier keys
  151. (setq mac-option-modifier 'control)
  152. (setq w32-apps-modifier 'meta)
  153. ;; display
  154. (setq redisplay-dont-pause t)
  155. (setq visible-bell t)
  156. (setq ring-bell-function 'ignore)
  157. (mouse-avoidance-mode 'banish)
  158. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  159. ;; global keys
  160. (and (dllib-if-unfound "https://raw.github.com/k1LoW/emacs-drill-instructor/master/drill-instructor.el"
  161. t)
  162. (require 'drill-instructor nil t)
  163. (setq drill-instructor-global t)
  164. (let ((map drill-instructor-key-map))
  165. (define-key map (kbd "RET") nil)
  166. (define-key map (kbd "DEL") nil)
  167. (define-key map (kbd "C-h") nil)))
  168. '(mapc (lambda (key)
  169. (global-set-key (read-kbd-macro key) 'ignore))
  170. '("<up>" "<down>" "<right>" "<left>"))
  171. (define-key my-prefix-map (kbd "C-o") 'occur)
  172. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  173. (global-set-key (kbd "C-\\") help-map)
  174. (define-key ctl-x-map (kbd "DEL") help-map)
  175. (define-key ctl-x-map (kbd "C-h") help-map)
  176. (define-key help-map "a" 'apropos)
  177. ;; compose window
  178. (global-set-key [?\C--] 'other-window)
  179. (global-set-key [?\C-0] 'delete-window)
  180. (global-set-key [?\C-1] 'delete-other-windows)
  181. (global-set-key [?\C-2] 'split-window-vertically)
  182. (global-set-key [?\C-3] 'split-window-horizontally)
  183. ;; disable annoying keys
  184. (global-set-key [prior] 'ignore)
  185. (global-set-key (kbd "<next>") 'ignore)
  186. (global-set-key [menu] 'ignore)
  187. (global-set-key [down-mouse-1] 'ignore)
  188. (global-set-key [down-mouse-2] 'ignore)
  189. (global-set-key [down-mouse-3] 'ignore)
  190. (global-set-key [mouse-1] 'ignore)
  191. (global-set-key [mouse-2] 'ignore)
  192. (global-set-key [mouse-3] 'ignore)
  193. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  194. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  195. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  196. ;; mode-line
  197. (setq eol-mnemonic-dos "crlf")
  198. (setq eol-mnemonic-mac "cr")
  199. (setq eol-mnemonic-unix "lf")
  200. (which-function-mode 0)
  201. (line-number-mode 0)
  202. (column-number-mode 0)
  203. (size-indication-mode 0)
  204. (setq mode-line-position
  205. '(:eval (format "L%%l/%d,C%%c"
  206. (count-lines (point-max)
  207. (point-min)))))
  208. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  209. ;; display date
  210. (add-hook 'after-init-hook
  211. (lambda ()
  212. (when display-time-mode
  213. (display-time-update))
  214. ))
  215. (setq display-time-interval 29)
  216. (setq display-time-day-and-date t)
  217. (setq display-time-format "%a, %d %b %Y %T")
  218. (if window-system
  219. (display-time-mode 0)
  220. (display-time-mode 1))
  221. ;; ;; current directory
  222. ;; (let ((ls (member 'mode-line-buffer-identification
  223. ;; mode-line-format)))
  224. ;; (setcdr ls
  225. ;; (cons '(:eval (concat " ("
  226. ;; (abbreviate-file-name default-directory)
  227. ;; ")"))
  228. ;; (cdr ls))))
  229. ;; ;; display last modified time
  230. ;; (let ((ls (member 'mode-line-buffer-identification
  231. ;; mode-line-format)))
  232. ;; (setcdr ls
  233. ;; (cons '(:eval (concat " "
  234. ;; my-buffer-file-last-modified-time))
  235. ;; (cdr ls))))
  236. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  237. ;; minibuffer
  238. (setq insert-default-directory t)
  239. (setq completion-ignore-case t
  240. read-file-name-completion-ignore-case t
  241. read-buffer-completion-ignore-case t)
  242. (setq resize-mini-window t)
  243. (temp-buffer-resize-mode 1)
  244. (savehist-mode 1)
  245. (fset 'yes-or-no-p 'y-or-n-p)
  246. (define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol) ; complete symbol when `eval'
  247. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  248. ;; letters, font-lock mode and fonts
  249. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  250. (when (eq system-type 'Darwin)
  251. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  252. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  253. (when (and (boundp 'input-method-activate-hook) ;ちょっと正しいかわかんない
  254. (boundp 'input-method-inactivate-hook))
  255. (add-hook 'input-method-activate-hook
  256. (lambda () (set-cursor-color "red")))
  257. (add-hook 'input-method-inactivate-hook
  258. (lambda () (set-cursor-color "black"))))
  259. (show-paren-mode 1)
  260. (setq show-paren-style 'mixed)
  261. (transient-mark-mode 1)
  262. (global-font-lock-mode 1)
  263. (setq font-lock-global-modes
  264. '(not
  265. help-mode
  266. eshell-mode
  267. term-mode
  268. Man-mode))
  269. (standard-display-ascii ?\n "$\n")
  270. (defvar my-eol-face
  271. '(("\n" . (0 font-lock-comment-face t nil)))
  272. )
  273. (defvar my-tab-face
  274. '(("\t" . '(0 highlight t nil))))
  275. (defvar my-jspace-face
  276. '(("\u3000" . '(0 highlight t nil))))
  277. (add-hook 'font-lock-mode-hook
  278. (lambda ()
  279. (font-lock-add-keywords nil my-eol-face)
  280. (font-lock-add-keywords nil my-jspace-face)
  281. ))
  282. ;; highlight current line
  283. ;; http://wiki.riywo.com/index.php?Meadow
  284. (defface hlline-face
  285. '((((type x w32)
  286. (class color)
  287. (background dark))
  288. (:background "midnightblue")) ; :foreground "white")) ;; ハイライトの文字色は変えない方がいいかも
  289. (((type x w32)
  290. (class color)
  291. (background light))
  292. (:background "gainsboro"))
  293. (t
  294. (:underline "black")))
  295. "*Face used by hl-line.")
  296. ;; (defface hlline-ul-face
  297. ;; '((t (:underline "yellow")))
  298. ;; "underline yellow")
  299. (setq hl-line-face 'hlline-face) ;; (setq hl-line-face nil)
  300. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  301. (setq hl-line-global-modes
  302. '(not
  303. term-mode))
  304. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  305. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  306. ;; fonts
  307. (defun my-set-ascii-and-jp-font-with-size (list)
  308. ""
  309. (if (> emacs-major-version 22)
  310. (progn ; 23 or later
  311. (set-face-attribute 'default nil
  312. :family (nth 0 list)
  313. :height (nth 1 list))
  314. (set-fontset-font "fontset-default"
  315. 'japanese-jisx0208
  316. (font-spec :family (nth 2 list) :size (nth 3 list)))
  317. (set-fontset-font "fontset-default"
  318. 'katakana-jisx0201
  319. (font-spec :family (nth 2 list) :size (nth 3 list))))
  320. ; font spec is available in emacs23 and later, cannot used in emacs22
  321. (progn ; 22
  322. (set-face-attribute 'default nil
  323. :family (nth 0 list)
  324. :height (nth 1 list))
  325. (set-fontset-font "fontset-default"
  326. 'japanese-jisx0208
  327. (cons (nth 2 list) "jisx0208.*"))
  328. (set-fontset-font "fontset-default"
  329. 'katakana-jisx0201
  330. (cons (nth 2 list) "jisx0201.*"))
  331. )))
  332. ;; (my-set-ascii-and-jp-font-with-size '("dejavu sans mono" 90 "takaogothic" 13))
  333. ;; (my-set-ascii-and-jp-font-with-size '("dejavu sans mono" 100 "takaogothic" 14))
  334. ;; (my-set-ascii-and-jp-font-with-size '("dejavu sans mono" 100 "ms gothic" 14))
  335. ;; (my-set-ascii-and-jp-font-with-size '("monaco" 75 "takaogothic" 11))
  336. ;; (my-set-ascii-and-jp-font-with-size '("monaco" 90 "takaogothic" 13))
  337. ;; (my-set-ascii-and-jp-font-with-size '("ProggyCleanTTSZ" 120 "takaogothic" 11))
  338. ;; あ a
  339. (and (dllib-if-unfound "https://raw.github.com/10sr/emacs-lisp/master/set-modeline-color.el"
  340. t)
  341. (progn
  342. (require 'set-modeline-color nil t)))
  343. (let ((fg (face-foreground 'default))
  344. (bg (face-background 'default)))
  345. (set-face-background 'mode-line-inactive (if (face-inverse-video-p 'mode-line) fg bg))
  346. (set-face-foreground 'mode-line-inactive (if (face-inverse-video-p 'mode-line) bg fg)))
  347. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  348. ;; file handling
  349. (setq revert-without-query '(".+"))
  350. ;; save cursor position
  351. (setq save-place-file (concat user-emacs-directory
  352. "places"))
  353. (when (require 'saveplace nil t)
  354. (setq-default save-place t))
  355. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  356. (setq make-backup-files t)
  357. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  358. (setq backup-directory-alist
  359. (cons (cons "\\.*$" (expand-file-name "~/.emacs.d/backup"))
  360. backup-directory-alist))
  361. (setq version-control 'never)
  362. (setq delete-old-versions t)
  363. (setq auto-save-list-file-prefix (expand-file-name "~/.emacs.d/autosave/"))
  364. (setq delete-auto-save-files t)
  365. (add-to-list 'completion-ignored-extensions ".bak")
  366. ;; (setq delete-by-moving-to-trash t
  367. ;; trash-directory "~/.emacs.d/trash")
  368. (add-hook 'after-save-hook
  369. 'executable-make-buffer-file-executable-if-script-p)
  370. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  371. ;; editting
  372. (setq require-final-newline t)
  373. (setq kill-whole-line t)
  374. (setq scroll-conservatively 35
  375. scroll-margin 2
  376. scroll-step 0)
  377. (setq default-major-mode 'text-mode)
  378. (setq next-line-add-newlines nil)
  379. (setq kill-read-only-ok t)
  380. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  381. ;; (setq-default line-spacing 0.2)
  382. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  383. (setq-default tab-width 4)
  384. (setq-default indent-tabs-mode nil)
  385. (setq-default indent-line-function nil)
  386. ;(pc-selection-mode 1) ; this make some already defined keybind back to default
  387. (delete-selection-mode 1)
  388. (cua-mode 0)
  389. (setq line-move-visual nil)
  390. ;; key bindings
  391. ;; moving around
  392. ;; (global-set-key (kbd "M-j") 'next-line)
  393. ;; (global-set-key (kbd "M-k") 'previous-line)
  394. ;; (global-set-key (kbd "M-h") 'backward-char)
  395. ;; (global-set-key (kbd "M-l") 'forward-char)
  396. ;;(keyboard-translate ?\M-j ?\C-j)
  397. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  398. (define-key esc-map "p" 'backward-paragraph)
  399. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  400. (define-key esc-map "n" 'forward-paragraph)
  401. (global-set-key (kbd "C-<up>") (lambda () (interactive)(scroll-down 1)))
  402. (global-set-key (kbd "C-<down>") (lambda () (interactive)(scroll-up 1)))
  403. (global-set-key (kbd "C-<left>") 'scroll-down)
  404. (global-set-key (kbd "C-<right>") 'scroll-up)
  405. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  406. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  407. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  408. ;; C-h and DEL
  409. (global-set-key (kbd "C-h") (kbd "DEL"))
  410. (global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  411. (global-set-key (kbd "C-o")
  412. ;; (lambda ()
  413. ;; (interactive)
  414. ;; (move-end-of-line nil)
  415. ;; (newline-and-indent))
  416. (kbd "C-e C-m")
  417. )
  418. (global-set-key (kbd "C-k") 'kill-whole-line)
  419. (global-set-key (kbd "M-k") 'my-copy-whole-line)
  420. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  421. (global-set-key (kbd "M-u") 'undo)
  422. (global-set-key (kbd "C-r") 'query-replace-regexp)
  423. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  424. (global-set-key (kbd "M-i") (kbd "ESC TAB"))
  425. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  426. ;; gmail
  427. (setq mail-interactive t
  428. send-mail-function 'smtpmail-send-it
  429. ;; message-send-mail-function 'smtpmail-send-it
  430. smtpmail-smtp-server "smtp.gmail.com"
  431. smtpmail-smtp-service 587
  432. smtpmail-starttls-credentials '(("smtp.gmail.com" 587 "8.slashes@gmail.com" nil))
  433. smtpmail-auth-credentials '(("smtp.gmail.com" 587 "8.slashes@gmail.com" nil))
  434. user-mail-address "8.slashes@gmail.com")
  435. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  436. ;; buffer killing
  437. (defun my-query-kill-this-buffer ()
  438. ""
  439. (interactive)
  440. (if (y-or-n-p (concat "kill this buffer? :"))
  441. (kill-buffer (current-buffer))))
  442. (substitute-key-definition 'kill-buffer 'my-query-kill-this-buffer global-map)
  443. ;;(global-set-key "\C-xk" 'my-query-kill-this-buffer)
  444. '(setq package-archives '(("ELPA" . "http://tromey.com/elpa/")
  445. ("gnu" . "http://elpa.gnu.org/packages/")
  446. ("marmalade" . "http://marmalade-repo.org/packages/")))
  447. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  448. ;; some modes and hooks
  449. (require 'simple nil t)
  450. (and window-system
  451. (dllib-if-unfound "https://raw.github.com/10sr/emacs-lisp/master/save-window-size.el" t)
  452. (require 'save-window-size nil t))
  453. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  454. ;; share clipboard with x
  455. ;; this page describes this in details, but only these sexps are needed
  456. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  457. (when (and window-system
  458. (not (eq window-system 'mac))
  459. )
  460. (setq x-select-enable-clipboard t ; these settings seems to be useless when using emacs in terminal
  461. x-select-enable-primary nil)
  462. ;; (global-set-key "\C-y" 'x-clipboard-yank)
  463. )
  464. (and (not x-select-enable-clipboard)
  465. (getenv "DISPLAY")
  466. (executable-find "xclip")
  467. (dllib-if-unfound "http://www.emacswiki.org/emacs/download/xclip.el" t)
  468. (require 'xclip nil t)
  469. (turn-on-xclip))
  470. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  471. ;; mode
  472. (add-hook 'verilog-mode-hook
  473. (lambda ()
  474. (define-key verilog-mode-map ";" 'self-insert-command)))
  475. (setq diff-switches "-u")
  476. (add-hook 'diff-mode-hook
  477. (lambda ()
  478. (view-mode 1)
  479. (set-face-foreground 'diff-file-header-face nil)
  480. (set-face-foreground 'diff-header-face nil)
  481. (set-face-foreground 'diff-index-face "blue")
  482. (set-face-foreground 'diff-hunk-header-face "cyan")
  483. (set-face-foreground 'diff-context-face nil)
  484. (set-face-foreground 'diff-removed-face "red")
  485. (set-face-foreground 'diff-added-face "green")
  486. (set-face-foreground 'diff-changed-face "magenda")
  487. ))
  488. ;; (ffap-bindings)
  489. (add-hook 'sh-mode-hook
  490. (lambda ()
  491. (define-key sh-mode-map (kbd "C-x C-e") 'my-execute-shell-command-current-line)))
  492. (defun my-execute-shell-command-current-line ()
  493. ""
  494. (interactive)
  495. (shell-command (buffer-substring-no-properties (point-at-bol)
  496. (point))))
  497. (add-to-list 'auto-mode-alist
  498. '("\\(xinitrc\\|xprograms\\)\\'" . sh-mode))
  499. (setq python-python-command (or (executable-find "python3")
  500. (executable-find "python")))
  501. (defun my-python-run-as-command ()
  502. ""
  503. (interactive)
  504. (shell-command (concat python-python-command " " buffer-file-name)))
  505. (defun my-python-display-python-buffer ()
  506. ""
  507. (interactive)
  508. (set-window-text-height (display-buffer python-buffer
  509. t)
  510. 7))
  511. (add-hook 'python-mode-hook
  512. (lambda ()
  513. (define-key python-mode-map (kbd "C-c C-e") 'my-python-run-as-command)
  514. (define-key python-mode-map (kbd "C-c C-b") 'my-python-display-python-buffer)
  515. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)))
  516. (add-hook 'inferior-python-mode-hook
  517. (lambda ()
  518. (my-python-display-python-buffer)
  519. (define-key inferior-python-mode-map (kbd "<up>") 'comint-previous-input)
  520. (define-key inferior-python-mode-map (kbd "<down>") 'comint-next-input)))
  521. (add-hook 'text-mode-hook
  522. (lambda ()
  523. (define-key text-mode-map (kbd "C-m") 'newline)))
  524. (add-to-list 'Info-default-directory-list (expand-file-name "~/.info/emacs-ja"))
  525. (setq bookmark-default-file "~/.emacs.d/bmk")
  526. (add-hook 'apropos-mode-hook
  527. (lambda ()
  528. (define-key apropos-mode-map "n" 'next-line)
  529. (define-key apropos-mode-map "p" 'previous-line)
  530. ))
  531. (define-key minibuffer-local-map (kbd "C-u") (lambda () (interactive) (delete-region (point-at-bol) (point))))
  532. (add-hook 'isearch-mode-hook
  533. (lambda ()
  534. ;; (define-key isearch-mode-map (kbd "C-j") 'isearch-other-control-char)
  535. ;; (define-key isearch-mode-map (kbd "C-k") 'isearch-other-control-char)
  536. ;; (define-key isearch-mode-map (kbd "C-h") 'isearch-other-control-char)
  537. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  538. (define-key isearch-mode-map (kbd "M-r") 'isearch-query-replace-regexp)))
  539. (add-hook 'outline-mode-hook
  540. (lambda ()
  541. (if (string-match "\\.md\\'" buffer-file-name)
  542. (set (make-local-variable 'outline-regexp) "#+ "))))
  543. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  544. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  545. (setq markdown-command (or (executable-find "markdown")
  546. (executable-find "markdown.pl")))
  547. (when (dllib-if-unfound "http://jblevins.org/projects/markdown-mode/markdown-mode.el"
  548. t)
  549. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'markdown-mode))
  550. (autoload 'markdown-mode "markdown-mode" "Major mode for editing Markdown files." nil)
  551. (add-hook 'markdown-mode-hook
  552. (lambda ()
  553. (outline-minor-mode 1)
  554. (set (make-local-variable 'comment-start) ";"))))
  555. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  556. ;; c-mode
  557. ;; (setq c-default-style "bsd")
  558. ;; BackSpace キーを「賢く」し,インデント幅は2桁,タブはスペースに展開
  559. (add-hook 'c-mode-common-hook
  560. (lambda ()
  561. (setq c-basic-offset 2
  562. indent-tabs-mode nil)
  563. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  564. (c-toggle-hungry-state 1)
  565. ))
  566. (when (dllib-if-unfound "https://raw.github.com/mooz/js2-mode/master/js2-mode.el"
  567. t)
  568. (autoload 'js2-mode "js2-mode" nil t)
  569. (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  570. (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode)))
  571. ;; (add-hook 'js2-mode-hook
  572. ;; (lambda ()
  573. ;; (add-hook 'before-save-hook
  574. ;; 'my-indent-buffer
  575. ;; nil
  576. ;; t)))
  577. (add-hook 'js2-mode-hook
  578. (lambda ()
  579. (define-key js2-mode-map (kbd "C-m") (lambda ()
  580. (interactive)
  581. (js2-enter-key)
  582. (indent-for-tab-command)))
  583. (add-hook (kill-local-variable 'before-save-hook)
  584. 'js2-before-save)))
  585. (and nil
  586. (require 'zone nil t)
  587. (not (eq system-type 'windows-nt))
  588. ;; (zone-when-idle 180)
  589. (run-with-idle-timer 180 t (lambda ()
  590. (unless (memq major-mode
  591. '(term-mode))
  592. (zone)))))
  593. (when (require 'uniquify nil t)
  594. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  595. (setq uniquify-ignore-buffers-re "*[^*]+*")
  596. (setq uniquify-min-dir-content 1))
  597. (add-hook 'view-mode-hook
  598. (lambda()
  599. (define-key view-mode-map "j" (lambda() (interactive) (scroll-up 1)))
  600. (define-key view-mode-map "k" (lambda() (interactive) (scroll-down 1)))
  601. (define-key view-mode-map "v" 'toggle-read-only)
  602. (define-key view-mode-map "q" 'bury-buffer)
  603. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  604. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  605. ;; (define-key view-mode-map "n" 'nonincremental-repeat-search-forward)
  606. ;; (define-key view-mode-map "N" 'nonincremental-repeat-search-backward)
  607. (define-key view-mode-map "/" 'isearch-forward-regexp)
  608. (define-key view-mode-map "?" 'isearch-backward-regexp)
  609. (define-key view-mode-map "n" 'isearch-repeat-forward)
  610. (define-key view-mode-map "N" 'isearch-repeat-backward)
  611. ))
  612. (global-set-key "\M-r" 'view-mode)
  613. (setq view-read-only t)
  614. (add-hook 'Man-mode-hook
  615. (lambda ()
  616. (view-mode 1)
  617. (setq truncate-lines nil)))
  618. (setq Man-notify-method (if window-system
  619. 'newframe
  620. 'pushy))
  621. (require 'session nil t)
  622. (and (dllib-if-unfound "https://raw.github.com/10sr/emacs-lisp/master/gtkbm.el"
  623. t)
  624. (require 'gtkbm nil t)
  625. (global-set-key (kbd "C-x C-d") 'gtkbm))
  626. (and (dllib-if-unfound "https://raw.github.com/10sr/emacs-lisp/master/git-command.el"
  627. t)
  628. (require 'git-command nil t)
  629. (define-key ctl-x-map "g" 'git-command))
  630. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  631. ;; term mode
  632. ;; (setq multi-term-program shell-file-name)
  633. (and (dllib-if-unfound "http://www.emacswiki.org/emacs/download/multi-term.el"
  634. t)
  635. (require 'multi-term nil t)
  636. (setq multi-term-switch-after-close nil))
  637. (defun my-term-quit-or-send-raw ()
  638. ""
  639. (interactive)
  640. (if (get-buffer-process (current-buffer))
  641. (call-interactively 'term-send-raw)
  642. (kill-buffer)))
  643. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  644. ;; (setq term-ansi-default-program shell-file-name)
  645. (add-hook 'term-setup-hook
  646. (lambda ()
  647. (setq term-display-table (make-display-table))))
  648. (add-hook 'term-mode-hook
  649. (lambda ()
  650. (unless (memq (current-buffer) (and (featurep 'multi-term) ; current buffer is not multi-term buffer
  651. (multi-term-list)))
  652. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  653. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  654. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  655. ;; (define-key term-raw-map "\C-f" 'forward-char)
  656. ;; (define-key term-raw-map "\C-b" 'backward-char)
  657. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  658. (define-key term-raw-map "\C-x" (lookup-key (current-global-map) "\C-x"))
  659. (define-key term-raw-map "\C-z" (lookup-key (current-global-map) "\C-z")))
  660. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  661. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  662. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  663. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  664. (define-key term-raw-map [delete] 'term-send-raw)
  665. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  666. (define-key term-raw-map "\C-y" 'term-paste)
  667. (define-key term-raw-map "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  668. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  669. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  670. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  671. ;; (define-key term-raw-map "\C-d" 'delete-char)
  672. (set (make-local-variable 'scroll-margin) 0)
  673. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  674. ;; (cua-mode 0)
  675. ;; (and cua-mode
  676. ;; (local-unset-key (kbd "C-c")))
  677. ;; (define-key cua--prefix-override-keymap "\C-c" 'term-interrupt-subjob)
  678. (set (make-local-variable 'hl-line-range-function)
  679. (lambda ()
  680. '(0 . 0)))
  681. ))
  682. ;; (add-hook 'term-exec-hook 'forward-char)
  683. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  684. ;; buffer switching
  685. (when (require 'bs nil t)
  686. ;; (global-set-key "\C-x\C-b" 'bs-show)
  687. (defalias 'list-buffers 'bs-show))
  688. ;; (add-to-list 'bs-configurations '("processes" nil get-buffer-process ".*" nil nil))
  689. (add-to-list 'bs-configurations '("same-dir" nil buffer-same-dir-p ".*" nil nil))
  690. (add-to-list 'bs-configurations '("this-frame" nil (lambda (buf) (memq buf (my-frame-buffer-get))) ".*" nil nil))
  691. ;; (setq bs-configurations (list '("processes" nil get-buffer-process ".*" nil nil)
  692. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil bs-visits-non-file bs-sort-buffer-interns-are-last)))
  693. (setq bs-default-configuration "this-frame")
  694. (setq bs-default-sort-name "by name")
  695. (add-hook 'bs-mode-hook
  696. (lambda ()
  697. (setq bs-default-configuration "this-frame")
  698. ;; (and bs--show-all
  699. ;; (call-interactively 'bs-toggle-show-all))
  700. (set (make-local-variable 'scroll-margin) 0)
  701. ))
  702. (defun buffer-same-dir-p (bf)
  703. "return t if BF's dir is same as current dir, otherwise nil."
  704. (let ((cdir (expand-file-name default-directory)))
  705. (with-current-buffer bf
  706. (equal (expand-file-name default-directory) cdir))))
  707. (iswitchb-mode 1)
  708. (defun iswitchb-buffer-display-other-window ()
  709. ""
  710. (interactive)
  711. (let ((iswitchb-default-method 'display))
  712. (call-interactively 'iswitchb-buffer)))
  713. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  714. ;; sdic
  715. (defun sdic-describe-word-at-point-echo ()
  716. ""
  717. (interactive)
  718. (save-window-excursion
  719. (sdic-describe-word-at-point))
  720. (save-excursion
  721. (set-buffer sdic-buffer-name)
  722. (message (buffer-substring (point-min)
  723. (progn (goto-char (point-min))
  724. (or (and (re-search-forward "^\\w" nil t 4)
  725. (progn (previous-line) t)
  726. (point-at-eol))
  727. (point-max)))))))
  728. (setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  729. (setq sdic-waei-dictionary-list '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  730. (setq sdic-disable-select-window t)
  731. (setq sdic-window-height 7)
  732. (when (require 'sdic nil t)
  733. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  734. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo))
  735. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  736. ;; vc
  737. ;; (require 'vc)
  738. (setq vc-handled-backends '())
  739. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  740. ;; gauche-mode
  741. (let ((s (executable-find "gosh")))
  742. (setq scheme-program-name s
  743. gauche-program-name s))
  744. (defun run-gauche-other-window ()
  745. "Run gauche on other window"
  746. (interactive)
  747. (switch-to-buffer-other-window
  748. (get-buffer-create "*scheme*"))
  749. (run-gauche))
  750. (defun run-gauche ()
  751. "run gauche"
  752. (run-scheme gauche-program-name)
  753. )
  754. (defun scheme-send-buffer ()
  755. ""
  756. (interactive)
  757. (scheme-send-region (point-min) (point-max))
  758. (my-scheme-display-scheme-buffer)
  759. )
  760. (defun my-scheme-display-scheme-buffer ()
  761. ""
  762. (interactive)
  763. (set-window-text-height (display-buffer scheme-buffer
  764. t)
  765. 7))
  766. (add-hook 'scheme-mode-hook
  767. (lambda ()
  768. nil))
  769. (add-hook 'inferior-scheme-mode-hook
  770. (lambda ()
  771. ;; (my-scheme-display-scheme-buffer)
  772. ))
  773. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  774. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  775. (when (dllib-if-unfound "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  776. t)
  777. (setq auto-mode-alist
  778. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  779. (setq auto-mode-alist
  780. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  781. (autoload 'gauche-mode "gauche-mode" "Major mode for Scheme." t)
  782. (autoload 'run-scheme "gauche-mode" "Run an inferior Scheme process." t)
  783. (add-hook 'gauche-mode-hook
  784. (lambda ()
  785. (define-key gauche-mode-map (kbd "C-c C-z") 'run-gauche-other-window)
  786. (define-key scheme-mode-map (kbd "C-c C-c") 'scheme-send-buffer)
  787. (define-key scheme-mode-map (kbd "C-c C-b") 'my-scheme-display-scheme-buffer)
  788. )))
  789. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  790. ;; recentf-mode
  791. (setq recentf-save-file (expand-file-name "~/.emacs.d/recentf")
  792. recentf-max-menu-items 20
  793. recentf-max-saved-items 30
  794. recentf-show-file-shortcuts-flag nil)
  795. (when (require 'recentf nil t)
  796. ;; (global-set-key "\C-x\C-r" 'recentf-open-files)
  797. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  798. ;; (add-hook 'find-file-hook
  799. ;; (lambda ()
  800. ;; (recentf-add-file default-directory)))
  801. (recentf-mode 1)
  802. ;; (add-to-list 'recentf-filename-handlers 'abbreviate-file-name)
  803. (add-to-list 'recentf-exclude (regexp-quote recentf-save-file))
  804. (and (dllib-if-unfound "https://raw.github.com/10sr/emacs-lisp/master/recentf-show.el"
  805. t)
  806. (require 'recentf-show nil t)
  807. (define-key ctl-x-map (kbd "C-r") 'recentf-show)))
  808. (add-hook 'recentf-dialog-mode-hook
  809. (lambda ()
  810. (recentf-save-list)
  811. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f") 'my-recentf-cd-and-find-file)
  812. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  813. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  814. (define-key recentf-dialog-mode-map "p" 'previous-line)
  815. (define-key recentf-dialog-mode-map "n" 'next-line)
  816. (cd "~/")))
  817. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  818. ;; dired
  819. (require 'dired)
  820. (defun my-dired-echo-file-head (arg)
  821. ""
  822. (interactive "P")
  823. (let ((f (dired-get-filename)))
  824. (message "%s"
  825. (with-temp-buffer
  826. (insert-file-contents f)
  827. (buffer-substring-no-properties (point-min)
  828. (progn (goto-line (if arg
  829. (prefix-numeric-value arg)
  830. 10))
  831. (point-at-eol)))))))
  832. (defun my-dired-diff ()
  833. ""
  834. (interactive)
  835. (let ((files (dired-get-marked-files nil nil nil t)))
  836. (if (eq (car files)
  837. t)
  838. (diff (cadr files) (dired-get-filename))
  839. (message "One files must be marked!"))))
  840. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  841. "pop up buffer using `display-buffer' and return that buffer."
  842. (let ((bf (get-buffer-create buffer-or-name)))
  843. (with-current-buffer bf
  844. (cd ".")
  845. (erase-buffer))
  846. (display-buffer bf)
  847. bf))
  848. (defun my-replace-nasi-none ()
  849. ""
  850. (save-excursion
  851. (let ((buffer-read-only nil))
  852. (goto-char (point-min))
  853. (while (search-forward "なし" nil t)
  854. (replace-match "none")))))
  855. (defun dired-get-file-info ()
  856. "dired get disk usage"
  857. (interactive)
  858. (let ((f (dired-get-filename)))
  859. (if (file-directory-p f)
  860. (progn
  861. (message "calculating du...")
  862. (shell-command (concat "du -hsD "
  863. f)))
  864. (shell-command (concat "file "
  865. f)))))
  866. (defun my-dired-scroll-up ()
  867. ""
  868. (interactive)
  869. (my-dired-previous-line (- (window-height) 1)))
  870. (defun my-dired-scroll-down ()
  871. ""
  872. (interactive)
  873. (my-dired-next-line (- (window-height) 1)))
  874. (defun my-dired-previous-line (arg)
  875. ""
  876. (interactive "p")
  877. (when (> arg 0)
  878. ;; (ignore 'my-dired-print-current-dir-and-file)
  879. (dired-previous-line 1)
  880. (when (eq (line-number-at-pos)
  881. 2)
  882. (goto-line (- (line-number-at-pos (point-max))
  883. 1))
  884. (dired-move-to-filename))
  885. (my-dired-previous-line (- arg 1))
  886. ))
  887. (defun my-dired-next-line (arg)
  888. ""
  889. (interactive "p")
  890. (when (> arg 0)
  891. ;; (ignore 'my-dired-print-current-dir-and-file)
  892. (dired-next-line 1)
  893. (when (eq (point)
  894. (point-max))
  895. (goto-line 3)
  896. (dired-move-to-filename))
  897. (my-dired-next-line (- arg 1))
  898. ))
  899. (defun my-dired-print-current-dir-and-file ()
  900. (message "%s %s"
  901. default-directory
  902. (buffer-substring-no-properties (point-at-bol)
  903. (point-at-eol))))
  904. (defun dired-do-execute-as-command ()
  905. ""
  906. (interactive)
  907. (let ((file (dired-get-filename t)))
  908. (if (file-executable-p file)
  909. (start-process file nil file)
  910. (when (y-or-n-p "this file cant be executed. mark as executable and go? : ")
  911. (set-file-modes file (file-modes-symbolic-to-number "u+x" (file-modes file)))
  912. (start-process file nil file)))))
  913. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  914. (defun my-dired-x-open ()
  915. ""
  916. (interactive)
  917. (my-x-open (dired-get-filename t t)))
  918. (if (eq window-system 'mac)
  919. (setq dired-listing-switches "-lhFG")
  920. (setq dired-listing-switches "-lhFG --time-style=long-iso")
  921. )
  922. (setq dired-listing-switches "-lhFG")
  923. (put 'dired-find-alternate-file 'disabled nil) ; when using dired-find-alternate-file reuse current dired buffer for the file to open
  924. (setq dired-ls-F-marks-symlinks t)
  925. (require 'ls-lisp)
  926. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  927. (setq ls-lisp-dirs-first t)
  928. (setq ls-lisp-use-localized-time-format t)
  929. (setq ls-lisp-format-time-list
  930. '("%Y-%m-%d %H:%M"
  931. "%Y-%m-%d "))
  932. (setq dired-dwim-target t)
  933. ;; (add-hook 'dired-after-readin-hook
  934. ;; 'my-replace-nasi-none)
  935. ;; (add-hook 'after-init-hook
  936. ;; (lambda ()
  937. ;; (dired ".")))
  938. (add-hook 'dired-mode-hook
  939. (lambda ()
  940. (define-key dired-mode-map "o" 'my-dired-x-open)
  941. (define-key dired-mode-map "i" 'dired-get-file-info)
  942. (define-key dired-mode-map "f" 'find-file)
  943. (define-key dired-mode-map "!" 'shell-command)
  944. (define-key dired-mode-map "&" 'async-shell-command)
  945. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  946. (define-key dired-mode-map "=" 'my-dired-diff)
  947. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  948. (define-key dired-mode-map "b" 'gtkbm)
  949. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  950. (define-key dired-mode-map "@" (lambda () (interactive) (my-x-open ".")))
  951. (define-key dired-mode-map (kbd "TAB") 'other-window)
  952. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  953. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  954. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  955. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  956. (substitute-key-definition 'dired-next-line 'my-dired-next-line dired-mode-map)
  957. (substitute-key-definition 'dired-previous-line 'my-dired-previous-line dired-mode-map)
  958. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  959. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  960. (let ((file "._Icon\015"))
  961. (when (file-readable-p file)
  962. (delete-file file)))))
  963. (and (dllib-if-unfound "https://raw.github.com/10sr/emacs-lisp/master/pack.el"
  964. t)
  965. (require 'pack nil t)
  966. (add-hook 'dired-mode-hook
  967. (lambda ()
  968. (define-key dired-mode-map "P" 'dired-do-pack-or-unpack))))
  969. (and (dllib-if-unfound "https://raw.github.com/10sr/emacs-lisp/master/dired-list-all-mode.el"
  970. t)
  971. (require 'dired-list-all-mode nil t)
  972. (setq dired-listing-switches "-lhFG")
  973. (add-hook 'dired-mode-hook
  974. (lambda ()
  975. (define-key dired-mode-map "a" 'dired-list-all-mode)
  976. )))
  977. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  978. (defun my-dired-toggle-mark()
  979. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  980. (t dired-marker-char))))
  981. (delete-char 1)
  982. (insert cur)))
  983. (defun my-dired-mark (arg)
  984. "toggle mark the current (or next ARG) files.
  985. If on a subdir headerline, mark all its files except `.' and `..'.
  986. Use \\[dired-unmark-all-files] to remove all marks
  987. and \\[dired-unmark] on a subdir to remove the marks in
  988. this subdir."
  989. (interactive "P")
  990. (if (dired-get-subdir)
  991. (save-excursion (dired-mark-subdir-files))
  992. (let ((inhibit-read-only t))
  993. (dired-repeat-over-lines
  994. (prefix-numeric-value arg)
  995. 'my-dired-toggle-mark))))
  996. (defun my-dired-mark-backward (arg)
  997. "In Dired, move up lines and toggle mark there.
  998. Optional prefix ARG says how many lines to unflag; default is one line."
  999. (interactive "p")
  1000. (my-dired-mark (- arg)))
  1001. (add-hook 'dired-mode-hook
  1002. (lambda ()
  1003. (local-set-key (kbd "SPC") 'my-dired-mark)
  1004. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1005. )
  1006. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1007. ;; eshell
  1008. (defun my-eshell-backward-delete-char ()
  1009. (interactive)
  1010. (when (< (save-excursion
  1011. (eshell-bol)
  1012. (point))
  1013. (point))
  1014. (backward-delete-char 1)))
  1015. (defun my-file-owner-p (file)
  1016. "t if FILE is owned by me."
  1017. (eq (user-uid) (nth 2 (file-attributes file))))
  1018. ;; ;; http://www.bookshelf.jp/pukiwiki/pukiwiki.php?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9
  1019. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1020. ;; (defun eshell/less (&rest args)
  1021. ;; "Invoke `view-file' on the file.
  1022. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1023. ;; (if args
  1024. ;; (while args
  1025. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1026. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1027. ;; (file (pop args)))
  1028. ;; (view-file file)
  1029. ;; (goto-line line))
  1030. ;; (view-file (pop args))))))
  1031. (defun eshell/o (&optional file)
  1032. (my-x-open (or file ".")))
  1033. ;; (defun eshell/vi (&rest args)
  1034. ;; "Invoke `find-file' on the file.
  1035. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1036. ;; (while args
  1037. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1038. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1039. ;; (file (pop args)))
  1040. ;; (find-file file)
  1041. ;; (goto-line line))
  1042. ;; (find-file (pop args)))))
  1043. (defun eshell/clear ()
  1044. "Clear the current buffer, leaving one prompt at the top."
  1045. (let ((inhibit-read-only t))
  1046. (erase-buffer)))
  1047. (defun eshell/d (&optional dirname switches)
  1048. "if first arg is omitted open current directory."
  1049. (dired (or dirname ".") switches))
  1050. (defun eshell/v ()
  1051. (view-mode 1))
  1052. (defun eshell/git (&rest args)
  1053. ""
  1054. (if (member (car args)
  1055. '("di" "diff" "log" "show"))
  1056. (apply 'eshell-exec-visual "git" args)
  1057. (shell-command (mapconcat 'shell-quote-argument
  1058. `("git" ,@args)
  1059. " ")
  1060. t)
  1061. ;; (eshell-external-command "git" args)
  1062. ))
  1063. (defalias 'eshell/: 'ignore)
  1064. (defalias 'eshell/type 'eshell/which)
  1065. ;; (defalias 'eshell/vim 'eshell/vi)
  1066. (defalias 'eshell/ff 'find-file)
  1067. (defalias 'eshell/q 'eshell/exit)
  1068. (defun eshell-goto-prompt ()
  1069. ""
  1070. (interactive)
  1071. (goto-char (point-max)))
  1072. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1073. "open eshell and change wd
  1074. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1075. (interactive)
  1076. (let ((dir (expand-file-name default-directory)))
  1077. (switch-to-buffer (or eshell-buffer-or-name
  1078. (eshell t)))
  1079. (unless (equal dir (expand-file-name default-directory))
  1080. ;; (cd dir)
  1081. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1082. ;; (eshell-emit-prompt)
  1083. (goto-char (point-max))
  1084. (eshell-kill-input)
  1085. (insert "cd " dir)
  1086. (eshell-send-input))))
  1087. (setq eshell-directory-name "~/.emacs.d/eshell/")
  1088. (setq eshell-term-name "eterm-color")
  1089. (setq eshell-scroll-to-bottom-on-input t)
  1090. (setq eshell-cmpl-ignore-case t)
  1091. (setq eshell-cmpl-cycle-completions nil)
  1092. (setq eshell-highlight-prompt nil)
  1093. (setq eshell-ls-initial-args '("-hCFG"
  1094. "--color=auto"
  1095. "--time-style=long-iso")) ; "-hF")
  1096. (setq eshell-prompt-function
  1097. (lambda ()
  1098. (with-temp-buffer
  1099. (let (p1 p2 p3 p4)
  1100. (insert " [")
  1101. (setq p1 (point))
  1102. (insert (abbreviate-file-name default-directory))
  1103. (setq p2 (point))
  1104. (insert "]"
  1105. "\n")
  1106. (setq p3 (point))
  1107. (insert user-login-name
  1108. "@"
  1109. (or (getenv "HOSTNAME")
  1110. (substring (shell-command-to-string (or (executable-find "hostname")
  1111. "echo ''"))
  1112. 0
  1113. -1)))
  1114. (setq p4 (point))
  1115. (insert " "
  1116. (format-time-string "%a, %d %b %Y %T %z")
  1117. " eshell\n"
  1118. "last:"
  1119. (number-to-string eshell-last-command-status)
  1120. (if (= (user-uid)
  1121. 0)
  1122. " # "
  1123. " $ "))
  1124. (add-text-properties p1
  1125. p2
  1126. '(face ((foreground-color . "yellow"))))
  1127. (add-text-properties p3
  1128. p4
  1129. '(face ((foreground-color . "cyan"))))
  1130. (buffer-substring (point-min)
  1131. (point-max))))))
  1132. (add-hook 'eshell-mode-hook
  1133. (lambda ()
  1134. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1135. ;; (interactive)
  1136. ;; (switch-to-buffer (other-buffer))))
  1137. (define-key eshell-mode-map (kbd "C-u") (lambda ()
  1138. (interactive)
  1139. (eshell-goto-prompt)
  1140. (eshell-kill-input)))
  1141. (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1142. (interactive)
  1143. (eshell-goto-prompt)
  1144. (my-keyboard-quit)))
  1145. (define-key eshell-mode-map (kbd "DEL") 'my-eshell-backward-delete-char)
  1146. (define-key eshell-mode-map (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1147. (define-key eshell-mode-map (kbd "C-n") 'eshell-next-matching-input-from-input)
  1148. (apply 'eshell/addpath exec-path)
  1149. (set (make-local-variable 'scroll-margin) 0)
  1150. ;; (eshell/export "GIT_PAGER=")
  1151. ;; (eshell/export "GIT_EDITOR=")
  1152. (eshell/export "LC_MESSAGES=C")
  1153. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1154. (set (make-local-variable 'hl-line-range-function)
  1155. (lambda ()
  1156. '(0 . 0)))
  1157. (add-to-list 'eshell-virtual-targets
  1158. '("/dev/less"
  1159. (lambda (str)
  1160. (if str
  1161. (with-current-buffer nil)))
  1162. nil))
  1163. ))
  1164. (add-hook 'eshell-mode-hook
  1165. (lambda ()
  1166. (add-to-list 'eshell-visual-commands "vim")
  1167. ;; (add-to-list 'eshell-visual-commands "git")
  1168. (add-to-list 'eshell-output-filter-functions 'eshell-truncate-buffer)
  1169. (mapcar (lambda (alias)
  1170. (add-to-list 'eshell-command-aliases-list
  1171. alias))
  1172. '(
  1173. ; ("ll" "ls -l $*")
  1174. ; ("la" "ls -a $*")
  1175. ; ("lla" "ls -al $*")
  1176. ("ut" "slogin 03110414@un001.ecc.u-tokyo.ac.jp $*")
  1177. ("aptin" "apt-get install $*")
  1178. ("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*\"))")
  1179. ("g" "git $*")
  1180. ))
  1181. ))
  1182. ;; (eval-after-load "em-alias"
  1183. ;; '(progn ;; (eshell/alias "ll" "ls -l")
  1184. ;; ;; (eshell/alias "la" "ls -a")
  1185. ;; ;; (eshell/alias "lla" "ls -al")
  1186. ;; (eshell/alias "sgcc" (if (eq system-type 'windows-nt)
  1187. ;; "gcc -o win.$1.exe $1"
  1188. ;; "gcc -o ${uname}.$1.out $1"))
  1189. ;; (eshell/alias "slmgcc" (if (eq system-type 'windows-nt)
  1190. ;; "gcc -lm -o win.$1.exe $1"
  1191. ;; "gcc -lm -o ${uname}.$1.out $1"))
  1192. ;; ;; (eshell/alias "ut" "ssh g841105@un001.ecc.u-tokyo.ac.jp")
  1193. ;; (add-to-list 'recentf-exclude (concat eshell-directory-name "alias"))))
  1194. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1195. ;; get last modified date
  1196. (defvar my-buffer-file-last-modified-time nil "")
  1197. (make-variable-buffer-local 'my-buffer-file-last-modified-time)
  1198. (defun my-get-file-last-modified-time (file)
  1199. ""
  1200. (nth 5
  1201. (file-attributes file)))
  1202. (defun my-set-buffer-file-last-modified-time ()
  1203. ""
  1204. (make-local-variable 'my-buffer-file-last-modified-time)
  1205. (setq my-buffer-file-last-modified-time
  1206. (format-time-string "%Y/%m/%d %H:%M" (my-get-file-last-modified-time buffer-file-name))))
  1207. (add-hook 'find-file-hook
  1208. 'my-set-buffer-file-last-modified-time)
  1209. (add-hook 'after-save-hook
  1210. 'my-set-buffer-file-last-modified-time)
  1211. (add-hook 'after-revert-hook
  1212. 'my-set-buffer-file-last-modified-time)
  1213. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1214. ;; frame buffer
  1215. ;; todo: work well when opening the file that was already opened on another window
  1216. (add-hook 'after-make-frame-functions
  1217. (lambda (f)
  1218. (set-window-buffer (frame-selected-window f)
  1219. "*Messages*")))
  1220. (defun make-frame-command-with-name (name)
  1221. "Make frame with name specified."
  1222. (interactive "sName for new frame: ")
  1223. (set-frame-parameter (make-frame-command)
  1224. 'name
  1225. name))
  1226. (defvar my-frame-buffer-plist nil)
  1227. (defun my-frame-buffer-add (&optional buf frame)
  1228. ""
  1229. (setq my-frame-buffer-plist
  1230. (plist-put my-frame-buffer-plist
  1231. (or frame
  1232. (selected-frame))
  1233. (let ((lst (my-frame-buffer-get frame)))
  1234. (if lst
  1235. (add-to-list 'lst
  1236. (or buf
  1237. (current-buffer)))
  1238. (list (or buf
  1239. (current-buffer))))))))
  1240. (defun my-frame-buffer-remove (&optional buf frame)
  1241. ""
  1242. (setq my-frame-buffer-plist
  1243. (plist-put my-frame-buffer-plist
  1244. (or frame
  1245. (selected-frame))
  1246. (delq (or buf
  1247. (current-buffer))
  1248. (my-frame-buffer-get frame)))))
  1249. (defun my-frame-buffer-get (&optional frame)
  1250. ""
  1251. (plist-get my-frame-buffer-plist
  1252. (or frame
  1253. (selected-frame))))
  1254. (defun my-frame-buffer-kill-all-buffer (&optional frame)
  1255. ""
  1256. (mapcar 'kill-buffer
  1257. (my-frame-buffer-get frame)))
  1258. (add-hook 'find-file-hook
  1259. 'my-frame-buffer-add)
  1260. (add-hook 'term-mode-hook
  1261. 'my-frame-buffer-add)
  1262. (add-hook 'eshell-mode-hook
  1263. 'my-frame-buffer-add)
  1264. (add-hook 'Man-mode-hook
  1265. 'my-frame-buffer-add)
  1266. (add-hook 'kill-buffer-hook
  1267. 'my-frame-buffer-remove)
  1268. (add-hook 'delete-frame-functions
  1269. 'my-frame-buffer-kill-all-buffer)
  1270. (defvar my-desktop-terminal "roxterm")
  1271. (defun my-execute-terminal ()
  1272. ""
  1273. (interactive)
  1274. (if (and (or (eq system-type 'windows-nt)
  1275. window-system)
  1276. my-desktop-terminal
  1277. )
  1278. (let ((process-environment (cons "TERM=xterm" process-environment)))
  1279. (start-process "terminal"
  1280. nil
  1281. my-desktop-terminal))
  1282. (my-term)))
  1283. (defun my-term ()
  1284. "open terminal buffer and return that buffer."
  1285. (interactive)
  1286. (if (eq system-type 'windows-nt)
  1287. (eshell t)
  1288. (if (featurep 'multi-term)
  1289. (multi-term)
  1290. (ansi-term "/bin/bash"))))
  1291. (defun my-delete-frame-or-kill-emacs ()
  1292. "delete frame when opening multiple frame, kill emacs when only one."
  1293. (interactive)
  1294. (if (eq 1
  1295. (length (frame-list)))
  1296. (save-buffers-kill-emacs)
  1297. (delete-frame)))
  1298. (define-key my-prefix-map (kbd "C-s") 'my-execute-terminal)
  1299. (define-key my-prefix-map (kbd "C-f") 'make-frame-command-with-name)
  1300. (global-set-key (kbd "C-x C-c") 'my-delete-frame-or-kill-emacs)
  1301. (define-key my-prefix-map (kbd "C-x C-c") 'save-buffers-kill-emacs)
  1302. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1303. ;; auto saving
  1304. (defun my-save-this-buffer (silent-p)
  1305. "save current buffer if can without asking"
  1306. (let ((cm (if (current-message)
  1307. (format "%s\n" (current-message))
  1308. ""))
  1309. (fun (symbol-function (if silent-p
  1310. 'ignore
  1311. 'message))))
  1312. (cond ((active-minibuffer-window) nil)
  1313. ((not buffer-file-name) (funcall fun "%ssaving... this buffer doesn't visit any file." cm) nil)
  1314. ((not (file-exists-p buffer-file-name)) (funcall fun "%ssaving... file not exist. save manually first." com) nil)
  1315. (buffer-read-only (funcall fun "%ssaving... this buffer is read-only." cm) nil)
  1316. ((not (buffer-modified-p)) (funcal fun "%ssaving... not modified yet." cm) nil)
  1317. ((not (file-writable-p buffer-file-name)) (funcall fun "%ssaving... you cannot change this file." cm) nil)
  1318. (t (funcall fun "%ssaving..." cm)
  1319. (save-buffer)
  1320. (funcall fun "%ssaving... done." cm)))))
  1321. ;; (if (and buffer-file-name
  1322. ;; (not buffer-read-only)
  1323. ;; (buffer-modified-p)
  1324. ;; (file-writable-p buffer-file-name))
  1325. ;; (save-buffer))) ; silent one
  1326. (defvar my-auto-save-this-buffer nil "auto save timer object")
  1327. (defun my-auto-save-this-buffer (sec &optional silent-p)
  1328. "auto save current buffer if idle for SEC.
  1329. when SEC is nil, stop auto save if enabled."
  1330. (if sec
  1331. (progn (when my-auto-save-this-buffer
  1332. (cancel-timer my-auto-save-this-buffer)
  1333. (setq my-auto-save-this-buffer nil))
  1334. (setq my-auto-save-this-buffer (run-with-idle-timer sec t 'my-save-this-buffer silent-p)))
  1335. (when my-auto-save-this-buffer
  1336. (cancel-timer my-auto-save-this-buffer)
  1337. (setq my-auto-save-this-buffer nil))))
  1338. (my-auto-save-this-buffer 2 t)
  1339. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1340. ;; misc funcs
  1341. (defun dir-show (&optional dir)
  1342. (interactive)
  1343. (let ((bf (get-buffer-create "*dir show*"))
  1344. (list-directory-brief-switches "-C"))
  1345. (with-current-buffer bf
  1346. (list-directory (or nil
  1347. default-directory)
  1348. nil))
  1349. ))
  1350. (defalias 'qcalc 'quick-calc)
  1351. (defun my-kill-buffers ()
  1352. ""
  1353. (interactive)
  1354. (mapcar (lambda (buf)
  1355. (when (buffer-file-name buf)
  1356. (kill-buffer buf)))
  1357. (buffer-list)))
  1358. (defvar my-filer nil)
  1359. (setq my-filer (or (executable-find "pcmanfm")
  1360. (executable-find "nautilus")))
  1361. (defun my-x-open (file)
  1362. "open file."
  1363. (interactive "FOpen File: ")
  1364. (setq file (expand-file-name file))
  1365. (message "Opening %s..." file)
  1366. (cond ((eq system-type 'windows-nt)
  1367. (call-process "cmd.exe" nil 0 nil "/c" "start" "" (convert-standard-filename file)))
  1368. ((eq system-type 'darwin)
  1369. (call-process "open" nil 0 nil file))
  1370. ((getenv "DISPLAY")
  1371. (call-process (or my-filer "xdg-open") nil 0 nil file))
  1372. (t
  1373. (find-file file))
  1374. )
  1375. ;; (recentf-add-file file)
  1376. (message "Opening %s...done" file))
  1377. (defun my-keyboard-quit ()
  1378. ""
  1379. (interactive)
  1380. (run-hooks 'before-keyboard-quit-hook)
  1381. ;; (redisplay t)
  1382. (redraw-display)
  1383. ;; (run-hooks 'window-configuration-change-hook)
  1384. (my-revert-buffer-if-needed)
  1385. ;; (revert-buffer t t)
  1386. (keyboard-quit)
  1387. (insert "insert me")
  1388. (run-hooks 'after-keyboard-quit-hook))
  1389. (substitute-key-definition 'keyboard-quit 'my-keyboard-quit global-map)
  1390. ;; (global-set-key (kbd "C-g") 'my-keyboard-quit)
  1391. (defun my-convmv-sjis2utf8-test ()
  1392. "run `convmv -r -f sjis -t utf8 *'
  1393. this is test, does not rename files"
  1394. (interactive)
  1395. (shell-command "convmv -r -f sjis -t utf8 *"))
  1396. (defun my-convmv-sjis2utf8-notest ()
  1397. "run `convmv -r -f sjis -t utf8 * --notest'"
  1398. (interactive)
  1399. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  1400. (defun my-copy-whole-line ()
  1401. ""
  1402. (interactive)
  1403. (kill-new (concat (buffer-substring (point-at-bol)
  1404. (point-at-eol))
  1405. "\n")))
  1406. (defun kill-ring-save-buffer-file-name ()
  1407. "get current filename"
  1408. (interactive)
  1409. (let ((file buffer-file-name))
  1410. (if file
  1411. (progn (kill-new file)
  1412. (message file))
  1413. (message "not visiting file."))))
  1414. (defvar my-revert-buffer-if-needed-last-buffer nil)
  1415. (defun my-revert-buffer-if-needed ()
  1416. ""
  1417. (interactive)
  1418. (unless (eq my-revert-buffer-if-needed-last-buffer (current-buffer))
  1419. (setq my-revert-buffer-if-needed-last-buffer (current-buffer))
  1420. (when (or (and (eq major-mode 'dired-mode)
  1421. (dired-directory-changed-p default-directory))
  1422. (not (verify-visited-file-modtime (current-buffer))))
  1423. (revert-buffer t t)
  1424. (message "%s reverted." (buffer-name))
  1425. )))
  1426. (add-hook 'post-command-hook ; 'window-configuration-change-hook
  1427. 'my-revert-buffer-if-needed)
  1428. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1429. ;; forked from http://d.hatena.ne.jp/khiker/20100119/window_resize
  1430. (define-key my-prefix-map (kbd "C-w") 'my-window-organizer)
  1431. (defun my-window-organizer ()
  1432. "Control window size and position."
  1433. (interactive)
  1434. (save-selected-window
  1435. (select-window (window-at 0 0))
  1436. (let ( ;; (window-obj (selected-window))
  1437. ;; (current-width (window-width))
  1438. ;; (current-height (window-height))
  1439. action
  1440. c)
  1441. (catch 'end-flag
  1442. (while t
  1443. (setq action
  1444. (read-key-sequence-vector (format "size[%dx%d] 1: maximize; 2, 3: split; 0: delete; o: select other; j, l: enlarge; h, k: shrink; q: quit."
  1445. (window-width)
  1446. (window-height))))
  1447. (setq c (aref action 0))
  1448. (cond ((= c ?l)
  1449. (unless (eq (window-width) (frame-width))
  1450. (enlarge-window-horizontally 1)))
  1451. ((= c ?h)
  1452. (unless (eq (window-width) (frame-width))
  1453. (shrink-window-horizontally 1)))
  1454. ((= c ?j)
  1455. (enlarge-window 1))
  1456. ((= c ?k)
  1457. (shrink-window 1))
  1458. ((= c ?o)
  1459. (other-window 1))
  1460. ((memq c '(?d ?0))
  1461. (unless (eq (selected-window) (next-window (selected-window) 0 1))
  1462. (delete-window (selected-window))))
  1463. ((= c ?1)
  1464. (delete-other-windows))
  1465. ((= c ?2)
  1466. (split-window-vertically))
  1467. ((= c ?3)
  1468. (split-window-horizontally))
  1469. ((memq c '(?q ?\C-g))
  1470. (message "Quit")
  1471. (throw 'end-flag t))
  1472. (t
  1473. (beep))))))))
  1474. ;; (aref (read-key-sequence-vector "aa") 0)
  1475. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1476. ;; ;; emacsを殺伐とさせる
  1477. ;; ;; 補完させるとき失敗するからなし
  1478. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  1479. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  1480. ;; (setq arg
  1481. ;; (concat arg
  1482. ;; (if (eq nil (string-match "\\. *$" arg)) ".")
  1483. ;; " Stupid!")))
  1484. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1485. ;; japanese input method
  1486. (defun my-load-scim ()
  1487. "use scim-bridge.el as japanese im."
  1488. ;; Load scim-bridge.
  1489. (when (require 'scim-bridge nil t)
  1490. ;; Turn on scim-mode automatically after loading .emacs
  1491. (add-hook 'after-init-hook 'scim-mode-on)
  1492. (setq scim-cursor-color "red")
  1493. (scim-define-preedit-key ?\^h t)
  1494. (scim-define-common-key ?\* nil)
  1495. (scim-define-common-key ?\^/ nil)))
  1496. (defun my-load-anthy ()
  1497. "use anthy.el as japanese im."
  1498. ;; anthy
  1499. (when (require 'anthy nil t)
  1500. (global-set-key (kbd "<muhenkan>") (lambda () (interactive) (anthy-mode-off)))
  1501. (global-set-key (kbd "<henkan>") (lambda () (interactive) (anthy-mode-on)))
  1502. (when (>= emacs-major-version 23)
  1503. (setq anthy-accept-timeout 1))))
  1504. ;; quail
  1505. ;; aproposs input-method for some information
  1506. ;; (setq default-input-method "japanese")
  1507. (defun my-load-mozc-el ()
  1508. ""
  1509. (setq mozc-leim-title "[MZ]")
  1510. (when (require 'mozc nil t)
  1511. (setq defauit-input-method "japanese-mozc")
  1512. ))
  1513. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1514. ;; for windows
  1515. ;; (add-to-list 'exec-path "c:/Program Files/Gauche/bin/")
  1516. (defun start-ckw-bash ()
  1517. ""
  1518. (interactive)
  1519. (start-process "ckw_bash"
  1520. nil
  1521. "C:/Documents and Settings/sr/Application Data/dbx/apps/ckw/ckw.exe")) ; cじゃないといけないらしい
  1522. (defun my-w32-add-export-path (&rest args)
  1523. ""
  1524. (mapcar (lambda (path)
  1525. (add-to-list 'exec-path (expand-file-name path)))
  1526. (reverse args))
  1527. (setenv "PATH"
  1528. (mapconcat 'convert-standard-filename
  1529. exec-path
  1530. ";")))
  1531. (when (eq system-type 'windows-nt)
  1532. ;; (setq scheme-program-name "\"c:/Program Files/Gauche/bin/gosh.exe\" -i")
  1533. ;; (setq python-python-command "c:/Python26/python.exe")
  1534. (define-key my-prefix-map (kbd "C-c") 'start-ckw-bash)
  1535. (my-w32-add-export-path "c:/WINDOWS"
  1536. (expand-file-name "~/bin")
  1537. (expand-file-name "~/dbx/apps/bin"))
  1538. (when window-system
  1539. (setq w32-enable-synthesized-fonts t))
  1540. (setq file-name-coding-system 'sjis))