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.
 
 
 
 
 
 

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