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.
 
 
 
 
 
 

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