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.
 
 
 
 
 
 

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