Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

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