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.
 
 
 
 
 
 

1873 line
65 KiB

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