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.
 
 
 
 
 
 

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