25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1799 lines
64 KiB

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