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.
 
 
 
 
 
 

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