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.
 
 
 
 
 
 

1984 lines
69 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. "font configuration"
  398. (let ((fspec1 (if (> emacs-major-version 22)
  399. ;; font spec is available in emacs23 and later
  400. (font-spec :family (nth 2 list) :size (nth 3 list))
  401. (cons (nth 2 list) "jisx0208.*")))
  402. (fspec2 (if (> emacs-major-version 22)
  403. (font-spec :family (nth 2 list) :size (nth 3 list))
  404. (cons (nth 2 list) "jisx0201.*"))))
  405. (set-face-attribute 'default nil
  406. :family (nth 0 list)
  407. :height (nth 1 list))
  408. (set-fontset-font "fontset-default"
  409. 'japanese-jisx0208
  410. fspec1)
  411. (set-fontset-font "fontset-default"
  412. 'katakana-jisx0201
  413. fspec2)))
  414. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 90 "takaogothic" 13))
  415. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "takaogothic" 14))
  416. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "ms gothic" 14))
  417. ;; (my-set-ascii-and-jp-font '("monaco" 75 "takaogothic" 11))
  418. ;; (my-set-ascii-and-jp-font '("monaco" 90 "takaogothic" 13))
  419. ;; (my-set-ascii-and-jp-font '("ProggyCleanTTSZ" 120 "takaogothic" 11))
  420. ;; あ a
  421. (and (fetch-library
  422. "https://raw.github.com/10sr/emacs-lisp/master/set-modeline-color.el"
  423. t)
  424. (progn
  425. (require 'set-modeline-color nil t)))
  426. (let ((fg (face-foreground 'default))
  427. (bg (face-background 'default)))
  428. (set-face-background 'mode-line-inactive
  429. (if (face-inverse-video-p 'mode-line) fg bg))
  430. (set-face-foreground 'mode-line-inactive
  431. (if (face-inverse-video-p 'mode-line) bg fg)))
  432. (set-face-underline-p 'mode-line-inactive
  433. t)
  434. (set-face-underline-p 'vertical-border
  435. nil)
  436. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  437. ;; file handling
  438. (setq revert-without-query '(".+"))
  439. ;; save cursor position
  440. (setq save-place-file (concat user-emacs-directory
  441. "places"))
  442. (when (require 'saveplace nil t)
  443. (setq-default save-place t))
  444. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  445. (setq make-backup-files t)
  446. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  447. (setq backup-directory-alist
  448. (cons (cons "\\.*$" (expand-file-name "~/.emacs.d/backup"))
  449. backup-directory-alist))
  450. (setq version-control 'never)
  451. (setq delete-old-versions t)
  452. (setq auto-save-list-file-prefix (expand-file-name "~/.emacs.d/auto-save/"))
  453. (setq delete-auto-save-files t)
  454. (add-to-list 'completion-ignored-extensions ".bak")
  455. ;; (setq delete-by-moving-to-trash t
  456. ;; trash-directory "~/.emacs.d/trash")
  457. (add-hook 'after-save-hook
  458. 'executable-make-buffer-file-executable-if-script-p)
  459. (setq bookmark-default-file "~/.emacs.d/bmk")
  460. (add-hook 'recentf-load-hook
  461. (lambda ()
  462. (add-to-list 'recentf-exclude
  463. (regexp-quote bookmark-default-file))))
  464. (and (fetch-library
  465. "https://github.com/10sr/emacs-lisp/raw/master/read-only-only-mode.el"
  466. t)
  467. (lazy-load-eval 'read-only-only-mode))
  468. (and (fetch-library
  469. "https://raw.github.com/10sr/emacs-lisp/master/smart-revert.el"
  470. t)
  471. (require 'smart-revert nil t)
  472. (smart-revert-on))
  473. ;; autosave
  474. (and (fetch-library
  475. "https://raw.github.com/10sr/emacs-lisp/master/autosave.el"
  476. t)
  477. (require 'autosave nil t)
  478. (autosave-set 2))
  479. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  480. ;; editting
  481. (defun my-copy-whole-line ()
  482. ""
  483. (interactive)
  484. (kill-new (concat (buffer-substring (point-at-bol)
  485. (point-at-eol))
  486. "\n")))
  487. (setq require-final-newline t)
  488. (setq kill-whole-line t)
  489. (setq scroll-conservatively 35
  490. scroll-margin 2
  491. scroll-step 0)
  492. (setq default-major-mode 'text-mode)
  493. (setq next-line-add-newlines nil)
  494. (setq kill-read-only-ok t)
  495. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  496. ;; (setq-default line-spacing 0.2)
  497. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  498. (setq-default tab-width 4)
  499. (setq-default indent-tabs-mode nil)
  500. (setq-default indent-line-function nil)
  501. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  502. (delete-selection-mode 1)
  503. (cua-mode 0)
  504. (setq line-move-visual nil)
  505. ;; key bindings
  506. ;; moving around
  507. ;; (global-set-key (kbd "M-j") 'next-line)
  508. ;; (global-set-key (kbd "M-k") 'previous-line)
  509. ;; (global-set-key (kbd "M-h") 'backward-char)
  510. ;; (global-set-key (kbd "M-l") 'forward-char)
  511. ;;(keyboard-translate ?\M-j ?\C-j)
  512. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  513. (define-key esc-map "p" 'backward-paragraph)
  514. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  515. (define-key esc-map "n" 'forward-paragraph)
  516. (global-set-key (kbd "C-<up>") (lambda () (interactive)(scroll-down 1)))
  517. (global-set-key (kbd "C-<down>") (lambda () (interactive)(scroll-up 1)))
  518. (global-set-key (kbd "C-<left>") 'scroll-down)
  519. (global-set-key (kbd "C-<right>") 'scroll-up)
  520. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  521. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  522. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  523. ;; C-h and DEL
  524. (global-set-key (kbd "C-h") (kbd "DEL"))
  525. (global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  526. (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  527. (define-key esc-map "k" 'my-copy-whole-line)
  528. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  529. (define-key esc-map "u" 'undo)
  530. (define-key esc-map "i" (kbd "ESC TAB"))
  531. ;(global-set-key (kbd "C-r") 'query-replace-regexp)
  532. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  533. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  534. (define-key my-prefix-map (kbd "C-o") 'occur)
  535. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  536. ;; gmail
  537. (setq mail-interactive t
  538. send-mail-function 'smtpmail-send-it
  539. ;; message-send-mail-function 'smtpmail-send-it
  540. smtpmail-smtp-server "smtp.gmail.com"
  541. smtpmail-smtp-service 587
  542. smtpmail-starttls-credentials '(("smtp.gmail.com" 587
  543. "8.slashes@gmail.com" nil))
  544. smtpmail-auth-credentials '(("smtp.gmail.com" 587
  545. "8.slashes@gmail.com" nil))
  546. user-mail-address "8.slashes@gmail.com")
  547. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  548. ;; buffer killing
  549. (defun my-delete-window-killing-buffer () nil)
  550. (defun my-query-kill-current-buffer ()
  551. ""
  552. (interactive)
  553. (if (y-or-n-p (concat "kill current buffer? :"))
  554. (kill-buffer (current-buffer))))
  555. (substitute-key-definition 'kill-buffer 'my-query-kill-current-buffer global-map)
  556. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  557. (defun my-kill-buffers ()
  558. ""
  559. (interactive)
  560. (mapcar (lambda (buf)
  561. (when (buffer-file-name buf)
  562. (kill-buffer buf)))
  563. (buffer-list)))
  564. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  565. ;; share clipboard with x
  566. ;; this page describes this in details, but only these sexps seem to be needed
  567. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  568. (and (not window-system)
  569. (not (eq window-system 'mac))
  570. (getenv "DISPLAY")
  571. (not (equal (getenv "DISPLAY") ""))
  572. (executable-find "xclip")
  573. ;; (< emacs-major-version 24)
  574. (fetch-library "http://www.emacswiki.org/emacs/download/xclip.el" t)
  575. (require 'xclip nil t)
  576. (turn-on-xclip))
  577. (and (eq system-type 'darwin)
  578. (fetch-library
  579. "https://raw.github.com/10sr/emacs-lisp/master/pasteboard.el"
  580. t)
  581. (require 'pasteboard nil t)
  582. (turn-on-pasteboard)
  583. (getenv "TMUX")
  584. (pasteboard-enable-rtun))
  585. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  586. ;; package
  587. (when (require 'package nil t)
  588. (add-to-list 'package-archives
  589. '("melpa" . "http://melpa.milkbox.net/packages/")
  590. t)
  591. (add-to-list 'package-archives
  592. '("marmalade" . "http://marmalade-repo.org/packages/"))
  593. (add-to-list 'package-archives
  594. '("ELPA" . "http://tromey.com/elpa/"))
  595. (package-initialize))
  596. (lazy-load-eval 'sudoku)
  597. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  598. ;; window
  599. ;; forked from http://d.hatena.ne.jp/khiker/20100119/window_resize
  600. (define-key ctl-x-map (kbd "w") 'my-window-organizer)
  601. (defun my-window-organizer ()
  602. "Control window size and position."
  603. (interactive)
  604. (save-selected-window
  605. (select-window (window-at 0 0))
  606. (let ( ;; (window-obj (selected-window))
  607. ;; (current-width (window-width))
  608. ;; (current-height (window-height))
  609. action
  610. c)
  611. (catch 'end-flag
  612. (while t
  613. (setq action
  614. (read-key-sequence-vector
  615. (format "size[%dx%d] 1: maximize; 2, 3: split; 0: \
  616. delete; o: select other; j, l: enlarge; h, k: shrink; q: quit."
  617. (window-width)
  618. (window-height))))
  619. (setq c (aref action 0))
  620. (cond ((= c ?l)
  621. (unless (eq (window-width) (frame-width))
  622. (enlarge-window-horizontally 1)))
  623. ((= c ?h)
  624. (unless (eq (window-width) (frame-width))
  625. (shrink-window-horizontally 1)))
  626. ((= c ?j)
  627. (enlarge-window 1))
  628. ((= c ?k)
  629. (shrink-window 1))
  630. ((= c ?o)
  631. (other-window 1))
  632. ((memq c '(?d ?0))
  633. (unless (eq (selected-window)
  634. (next-window (selected-window) 0 1))
  635. (delete-window (selected-window))))
  636. ((= c ?1)
  637. (delete-other-windows))
  638. ((= c ?2)
  639. (split-window-vertically))
  640. ((= c ?3)
  641. (split-window-horizontally))
  642. ((memq c '(?q ?\C-g))
  643. (message "Quit")
  644. (throw 'end-flag t))
  645. (t
  646. (beep))))))))
  647. ;; (aref (read-key-sequence-vector "aa") 0)
  648. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  649. ;; some modes and hooks
  650. ;; http://fukuyama.co/foreign-regexp
  651. '(and (fetch-library
  652. "https://raw.github.com/k-talo/foreign-regexp.el/master/foreign-regexp.el"
  653. t)
  654. (require 'foreign-regexp nil t)
  655. (progn
  656. (setq foreign-regexp/regexp-type 'perl)
  657. '(setq reb-re-syntax 'foreign-regexp)
  658. ))
  659. (require 'session nil t)
  660. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/gtkbm.el"
  661. t)
  662. (lazy-load-eval 'gtkbm)
  663. (global-set-key (kbd "C-x C-d") 'gtkbm))
  664. (and (fetch-library
  665. "https://raw.github.com/10sr/emacs-lisp/master/git-command.el"
  666. t)
  667. (lazy-load-eval 'git-command)
  668. (define-key ctl-x-map "g" 'git-command))
  669. (and (fetch-library
  670. "http://www.emacswiki.org/emacs/download/sl.el"
  671. t)
  672. (lazy-load-eval 'sl))
  673. (defalias 'qcalc 'quick-calc)
  674. (require 'simple nil t)
  675. (add-hook 'makefile-mode-hook
  676. (lambda ()
  677. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)))
  678. (defun make ()
  679. "Run \"make -k\" in current directory."
  680. (interactive)
  681. (compile "make -k"))
  682. (add-hook 'verilog-mode-hook
  683. (lambda ()
  684. (define-key verilog-mode-map ";" 'self-insert-command)))
  685. (setq diff-switches "-u")
  686. (add-hook 'diff-mode-hook
  687. (lambda ()
  688. (view-mode 1)
  689. (set-face-attribute 'diff-header nil
  690. :foreground nil
  691. :background nil
  692. :weight 'bold)
  693. (set-face-attribute 'diff-file-header nil
  694. :foreground nil
  695. :background nil
  696. :weight 'bold)
  697. (set-face-foreground 'diff-index-face "blue")
  698. (set-face-attribute 'diff-hunk-header nil
  699. :foreground "cyan"
  700. :weight 'normal)
  701. (set-face-attribute 'diff-context nil
  702. ;; :foreground "white"
  703. :foreground nil
  704. :weight 'normal)
  705. (set-face-foreground 'diff-removed-face "red")
  706. (set-face-foreground 'diff-added-face "green")
  707. (set-face-attribute 'diff-changed nil
  708. :foreground "magenta"
  709. :weight 'normal)
  710. ))
  711. ;; (ffap-bindings)
  712. (add-hook 'sh-mode-hook
  713. (lambda ()
  714. (define-key sh-mode-map
  715. (kbd "C-x C-e")
  716. 'my-execute-shell-command-current-line)))
  717. (setq sh-here-document-word "__EOC__")
  718. (defun my-execute-shell-command-current-line ()
  719. ""
  720. (interactive)
  721. (shell-command (buffer-substring-no-properties (point-at-bol)
  722. (point))))
  723. (setq auto-mode-alist
  724. `(("autostart\\'" . sh-mode)
  725. ("xinitrc\\'" . sh-mode)
  726. ("xprograms\\'" . sh-mode)
  727. ("PKGBUILD\\'" . sh-mode)
  728. ,@auto-mode-alist))
  729. (and (lazy-load-eval 'pkgbuild-mode)
  730. (setq auto-mode-alist (append '(("PKGBUILD\\'" . pkgbuild-mode))
  731. auto-mode-alist)))
  732. (add-hook 'text-mode-hook
  733. (lambda ()
  734. (define-key text-mode-map (kbd "C-m") 'newline)))
  735. (add-to-list 'Info-default-directory-list (expand-file-name "~/.info/emacs-ja"))
  736. (add-hook 'apropos-mode-hook
  737. (lambda ()
  738. (define-key apropos-mode-map "n" 'next-line)
  739. (define-key apropos-mode-map "p" 'previous-line)
  740. ))
  741. (add-hook 'isearch-mode-hook
  742. (lambda ()
  743. ;; (define-key isearch-mode-map
  744. ;; (kbd "C-j") 'isearch-other-control-char)
  745. ;; (define-key isearch-mode-map
  746. ;; (kbd "C-k") 'isearch-other-control-char)
  747. ;; (define-key isearch-mode-map
  748. ;; (kbd "C-h") 'isearch-other-control-char)
  749. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  750. (define-key isearch-mode-map (kbd "M-r")
  751. 'isearch-query-replace-regexp)))
  752. (add-hook 'outline-mode-hook
  753. (lambda ()
  754. (if (string-match "\\.md\\'" buffer-file-name)
  755. (set (make-local-variable 'outline-regexp) "#+ "))))
  756. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  757. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  758. (when (fetch-library
  759. "http://jblevins.org/projects/markdown-mode/markdown-mode.el"
  760. t)
  761. (lazy-load-eval 'markdown-mode)
  762. (setq markdown-command (or (executable-find "markdown")
  763. (executable-find "markdown.pl")))
  764. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'markdown-mode))
  765. (add-hook 'markdown-mode-hook
  766. (lambda ()
  767. (outline-minor-mode 1)
  768. (set (make-local-variable 'comment-start) ";"))))
  769. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  770. ;; c-mode
  771. ;; (setq c-default-style "bsd")
  772. (add-hook 'c-mode-common-hook
  773. (lambda ()
  774. (setq c-basic-offset 2
  775. indent-tabs-mode nil)
  776. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  777. (c-toggle-hungry-state -1)
  778. (and (require 'gtags nil t)
  779. (gtags-mode 1))
  780. ))
  781. (when (fetch-library
  782. "https://raw.github.com/mooz/js2-mode/master/js2-mode.el"
  783. t)
  784. (lazy-load-eval 'js2-mode)
  785. (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  786. (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  787. ;; (add-hook 'js2-mode-hook
  788. ;; (lambda ()
  789. (add-hook 'js2-mode-hook
  790. (lambda ()
  791. (define-key js2-mode-map (kbd "C-m") (lambda ()
  792. (interactive)
  793. (js2-enter-key)
  794. (indent-for-tab-command)))
  795. (add-hook (kill-local-variable 'before-save-hook)
  796. 'js2-before-save)
  797. ;; (add-hook 'before-save-hook
  798. ;; 'my-indent-buffer
  799. ;; nil
  800. ;; t)
  801. )))
  802. (when (require 'uniquify nil t)
  803. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  804. (setq uniquify-ignore-buffers-re "*[^*]+*")
  805. (setq uniquify-min-dir-content 1))
  806. (add-hook 'view-mode-hook
  807. (lambda()
  808. (define-key view-mode-map "j"
  809. (lambda() (interactive) (scroll-up 1)))
  810. (define-key view-mode-map "k"
  811. (lambda() (interactive) (scroll-down 1)))
  812. (define-key view-mode-map "v" 'toggle-read-only)
  813. (define-key view-mode-map "q" 'bury-buffer)
  814. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  815. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  816. ;; (define-key view-mode-map
  817. ;; "n" 'nonincremental-repeat-search-forward)
  818. ;; (define-key view-mode-map
  819. ;; "N" 'nonincremental-repeat-search-backward)
  820. (define-key view-mode-map "/" 'isearch-forward-regexp)
  821. (define-key view-mode-map "?" 'isearch-backward-regexp)
  822. (define-key view-mode-map "n" 'isearch-repeat-forward)
  823. (define-key view-mode-map "N" 'isearch-repeat-backward)
  824. ))
  825. (global-set-key "\M-r" 'view-mode)
  826. (setq view-read-only t)
  827. (add-hook 'Man-mode-hook
  828. (lambda ()
  829. (view-mode 1)
  830. (setq truncate-lines nil)))
  831. (setq Man-notify-method (if window-system
  832. 'newframe
  833. 'pushy))
  834. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  835. ;; python
  836. (when (lazy-load-eval 'python '(python-mode))
  837. (setq python-python-command (or (executable-find "python3")
  838. (executable-find "python")))
  839. (defun my-python-run-as-command ()
  840. ""
  841. (interactive)
  842. (shell-command (concat python-python-command " " buffer-file-name)))
  843. (defun my-python-display-python-buffer ()
  844. ""
  845. (interactive)
  846. (set-window-text-height (display-buffer python-buffer
  847. t)
  848. 7))
  849. (add-hook 'python-mode-hook
  850. (lambda ()
  851. (define-key python-mode-map
  852. (kbd "C-c C-e") 'my-python-run-as-command)
  853. (define-key python-mode-map
  854. (kbd "C-c C-b") 'my-python-display-python-buffer)
  855. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)))
  856. (add-hook 'inferior-python-mode-hook
  857. (lambda ()
  858. (my-python-display-python-buffer)
  859. (define-key inferior-python-mode-map
  860. (kbd "<up>") 'comint-previous-input)
  861. (define-key inferior-python-mode-map
  862. (kbd "<down>") 'comint-next-input))))
  863. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  864. ;; GNU GLOBAL(gtags)
  865. ;; http://uguisu.skr.jp/Windows/gtags.html
  866. ;; http://eigyr.dip.jp/gtags.html
  867. ;; http://cha.la.coocan.jp/doc/gnu_global.html
  868. (when (lazy-load-eval 'gtags '(gtags-mode))
  869. (add-hook 'gtags-mode-hook
  870. (lambda ()
  871. (setq gtags-select-buffer-single t)
  872. ;; (local-set-key "\M-t" 'gtags-find-tag)
  873. ;; (local-set-key "\M-r" 'gtags-find-rtag)
  874. ;; (local-set-key "\M-s" 'gtags-find-symbol)
  875. ;; (local-set-key "\C-t" 'gtags-pop-stack)
  876. (define-key gtags-mode-map (kbd "C-x t h") 'gtags-find-tag-from-here)
  877. (define-key gtags-mode-map (kbd "C-x t t") 'gtags-find-tag)
  878. (define-key gtags-mode-map (kbd "C-x t r") 'gtags-find-rtag)
  879. (define-key gtags-mode-map (kbd "C-x t s") 'gtags-find-symbol)
  880. (define-key gtags-mode-map (kbd "C-x t p") 'gtags-find-pattern)
  881. (define-key gtags-mdoe-map (kbd "C-x t f") 'gtags-find-file)
  882. (define-key gtags-mode-map (kbd "C-x t b") 'gtags-pop-stack) ;back
  883. )))
  884. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  885. ;; term mode
  886. ;; (setq multi-term-program shell-file-name)
  887. (and (fetch-library "http://www.emacswiki.org/emacs/download/multi-term.el"
  888. t)
  889. (lazy-load-eval 'multi-term)
  890. (progn
  891. (setq multi-term-switch-after-close nil)
  892. (setq multi-term-dedicated-select-after-open-p t)
  893. (setq multi-term-dedicated-window-height 20)))
  894. (when (lazy-load-eval 'term '(term ansi-term))
  895. (defun my-term-quit-or-send-raw ()
  896. ""
  897. (interactive)
  898. (if (get-buffer-process (current-buffer))
  899. (call-interactively 'term-send-raw)
  900. (kill-buffer)))
  901. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  902. ;; (setq term-ansi-default-program shell-file-name)
  903. (add-hook 'term-setup-hook
  904. (lambda ()
  905. (setq term-display-table (make-display-table))))
  906. (add-hook 'term-mode-hook
  907. (lambda ()
  908. (unless (memq (current-buffer)
  909. (and (featurep 'multi-term)
  910. ;; current buffer is not multi-term buffer
  911. (multi-term-list)))
  912. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  913. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  914. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  915. ;; (define-key term-raw-map "\C-f" 'forward-char)
  916. ;; (define-key term-raw-map "\C-b" 'backward-char)
  917. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  918. (define-key term-raw-map
  919. "\C-x" (lookup-key (current-global-map) "\C-x"))
  920. (define-key term-raw-map
  921. "\C-z" (lookup-key (current-global-map) "\C-z"))
  922. )
  923. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  924. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  925. (define-key term-raw-map (kbd "<up>")
  926. (lambda () (interactive) (scroll-down 1)))
  927. (define-key term-raw-map (kbd "<down>")
  928. (lambda () (interactive) (scroll-up 1)))
  929. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  930. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  931. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  932. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  933. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  934. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  935. (define-key term-raw-map [delete] 'term-send-raw)
  936. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  937. (define-key term-raw-map "\C-y" 'term-paste)
  938. (define-key term-raw-map
  939. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  940. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  941. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  942. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  943. ;; (define-key term-raw-map "\C-d" 'delete-char)
  944. (set (make-local-variable 'scroll-margin) 0)
  945. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  946. ;; (cua-mode 0)
  947. ;; (and cua-mode
  948. ;; (local-unset-key (kbd "C-c")))
  949. ;; (define-key cua--prefix-override-keymap
  950. ;;"\C-c" 'term-interrupt-subjob)
  951. (set (make-local-variable 'hl-line-range-function)
  952. (lambda ()
  953. '(0 . 0)))
  954. ))
  955. ;; (add-hook 'term-exec-hook 'forward-char)
  956. )
  957. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  958. ;; buffer switching
  959. (when (lazy-load-eval 'bs '(bs-show)
  960. ;; (add-to-list 'bs-configurations
  961. ;; '("processes" nil get-buffer-process ".*" nil nil))
  962. (add-to-list 'bs-configurations
  963. '("this-frame" nil (lambda (buf)
  964. (memq buf (my-frame-buffer-get)))
  965. ".*" nil nil))
  966. ;; (setq bs-configurations (list
  967. ;; '("processes" nil get-buffer-process ".*" nil nil)
  968. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  969. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  970. )
  971. ;; (global-set-key "\C-x\C-b" 'bs-show)
  972. (defalias 'list-buffers 'bs-show)
  973. (setq bs-default-configuration "files")
  974. (setq bs-default-sort-name "by nothing")
  975. (add-hook 'bs-mode-hook
  976. (lambda ()
  977. (setq bs-default-configuration "files")
  978. ;; (and bs--show-all
  979. ;; (call-interactively 'bs-toggle-show-all))
  980. (set (make-local-variable 'scroll-margin) 0))))
  981. (iswitchb-mode 1)
  982. (defun iswitchb-buffer-display-other-window ()
  983. ""
  984. (interactive)
  985. (let ((iswitchb-default-method 'display))
  986. (call-interactively 'iswitchb-buffer)))
  987. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  988. ;; sdic
  989. (when (lazy-load-eval 'sdic '(sdic-describe-word-at-point))
  990. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  991. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo)
  992. (defun sdic-describe-word-at-point-echo ()
  993. ""
  994. (interactive)
  995. (save-window-excursion
  996. (sdic-describe-word-at-point))
  997. (save-excursion
  998. (set-buffer sdic-buffer-name)
  999. (message (buffer-substring (point-min)
  1000. (progn (goto-char (point-min))
  1001. (or (and (re-search-forward "^\\w"
  1002. nil
  1003. t
  1004. 4)
  1005. (progn (previous-line) t)
  1006. (point-at-eol))
  1007. (point-max)))))))
  1008. (setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  1009. (setq sdic-waei-dictionary-list
  1010. '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  1011. (setq sdic-disable-select-window t)
  1012. (setq sdic-window-height 7))
  1013. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1014. ;; vc
  1015. ;; (require 'vc)
  1016. (setq vc-handled-backends '())
  1017. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1018. ;; gauche-mode
  1019. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  1020. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  1021. (when (and (fetch-library
  1022. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  1023. t)
  1024. (lazy-load-eval 'gauche-mode '(gauche-mode run-scheme)))
  1025. (let ((s (executable-find "gosh")))
  1026. (setq scheme-program-name s
  1027. gauche-program-name s))
  1028. (defun run-gauche-other-window ()
  1029. "Run gauche on other window"
  1030. (interactive)
  1031. (switch-to-buffer-other-window
  1032. (get-buffer-create "*scheme*"))
  1033. (run-gauche))
  1034. (defun run-gauche ()
  1035. "run gauche"
  1036. (run-scheme gauche-program-name)
  1037. )
  1038. (defun scheme-send-buffer ()
  1039. ""
  1040. (interactive)
  1041. (scheme-send-region (point-min) (point-max))
  1042. (my-scheme-display-scheme-buffer)
  1043. )
  1044. (defun my-scheme-display-scheme-buffer ()
  1045. ""
  1046. (interactive)
  1047. (set-window-text-height (display-buffer scheme-buffer
  1048. t)
  1049. 7))
  1050. (add-hook 'scheme-mode-hook
  1051. (lambda ()
  1052. nil))
  1053. (add-hook 'inferior-scheme-mode-hook
  1054. (lambda ()
  1055. ;; (my-scheme-display-scheme-buffer)
  1056. ))
  1057. (setq auto-mode-alist
  1058. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1059. (setq auto-mode-alist
  1060. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1061. (add-hook 'gauche-mode-hook
  1062. (lambda ()
  1063. (define-key gauche-mode-map
  1064. (kbd "C-c C-z") 'run-gauche-other-window)
  1065. (define-key scheme-mode-map
  1066. (kbd "C-c C-c") 'scheme-send-buffer)
  1067. (define-key scheme-mode-map
  1068. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer))))
  1069. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1070. ;; recentf-mode
  1071. (setq recentf-save-file (expand-file-name "~/.emacs.d/recentf")
  1072. recentf-max-menu-items 20
  1073. recentf-max-saved-items 30
  1074. recentf-show-file-shortcuts-flag nil)
  1075. (when (require 'recentf nil t)
  1076. (add-to-list 'recentf-exclude (regexp-quote recentf-save-file))
  1077. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1078. (add-hook 'find-file-hook
  1079. 'recentf-save-list
  1080. t) ; save to file immediately after adding file to recentf list
  1081. (add-hook 'kill-emacs-hook
  1082. 'recentf-load-list)
  1083. (add-hook 'recentf-mode-hook
  1084. 'recentf-save-list)
  1085. ;; (add-hook 'find-file-hook
  1086. ;; (lambda ()
  1087. ;; (recentf-add-file default-directory)))
  1088. (and (fetch-library
  1089. "https://raw.github.com/10sr/emacs-lisp/master/recentf-show.el"
  1090. t)
  1091. (lazy-load-eval 'recentf-show)
  1092. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1093. (add-hook 'recentf-show-before-listing-hook
  1094. 'recentf-load-list))
  1095. (recentf-mode 1)
  1096. (add-hook 'recentf-dialog-mode-hook
  1097. (lambda ()
  1098. ;; (recentf-save-list)
  1099. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1100. ;; 'my-recentf-cd-and-find-file)
  1101. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1102. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1103. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1104. (define-key recentf-dialog-mode-map "n" 'next-line)
  1105. (cd "~/"))))
  1106. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1107. ;; dired
  1108. (when (lazy-load-eval 'dired nil)
  1109. (defun my-dired-echo-file-head (arg)
  1110. ""
  1111. (interactive "P")
  1112. (let ((f (dired-get-filename)))
  1113. (message "%s"
  1114. (with-temp-buffer
  1115. (insert-file-contents f)
  1116. (buffer-substring-no-properties
  1117. (point-min)
  1118. (progn (goto-line (if arg
  1119. (prefix-numeric-value arg)
  1120. 10))
  1121. (point-at-eol)))))))
  1122. (defun my-dired-diff ()
  1123. ""
  1124. (interactive)
  1125. (let ((files (dired-get-marked-files nil nil nil t)))
  1126. (if (eq (car files)
  1127. t)
  1128. (diff (cadr files) (dired-get-filename))
  1129. (message "One files must be marked!"))))
  1130. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  1131. "pop up buffer using `display-buffer' and return that buffer."
  1132. (let ((bf (get-buffer-create buffer-or-name)))
  1133. (with-current-buffer bf
  1134. (cd ".")
  1135. (erase-buffer))
  1136. (display-buffer bf)
  1137. bf))
  1138. (defun my-replace-nasi-none ()
  1139. ""
  1140. (save-excursion
  1141. (let ((buffer-read-only nil))
  1142. (goto-char (point-min))
  1143. (while (search-forward "なし" nil t)
  1144. (replace-match "none")))))
  1145. (defun dired-get-file-info ()
  1146. "dired get file info"
  1147. (interactive)
  1148. (let ((f (shell-quote-argument (dired-get-filename t))))
  1149. (if (file-directory-p f)
  1150. (progn
  1151. (message "Calculating disk usage...")
  1152. (shell-command (concat "du -hsD "
  1153. f)))
  1154. (shell-command (concat "file "
  1155. f)))))
  1156. (defun my-dired-scroll-up ()
  1157. ""
  1158. (interactive)
  1159. (my-dired-previous-line (- (window-height) 1)))
  1160. (defun my-dired-scroll-down ()
  1161. ""
  1162. (interactive)
  1163. (my-dired-next-line (- (window-height) 1)))
  1164. ;; (defun my-dired-forward-line (arg)
  1165. ;; ""
  1166. ;; (interactive "p"))
  1167. (defun my-dired-previous-line (arg)
  1168. ""
  1169. (interactive "p")
  1170. (if (> arg 0)
  1171. (progn
  1172. (if (eq (line-number-at-pos)
  1173. 1)
  1174. (goto-char (point-max))
  1175. (forward-line -1))
  1176. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1177. (dired-get-subdir))
  1178. (- arg 1)
  1179. arg)))
  1180. (dired-move-to-filename)))
  1181. (defun my-dired-next-line (arg)
  1182. ""
  1183. (interactive "p")
  1184. (if (> arg 0)
  1185. (progn
  1186. (if (eq (point)
  1187. (point-max))
  1188. (goto-char (point-min))
  1189. (forward-line 1))
  1190. (my-dired-next-line (if (or (dired-get-filename nil t)
  1191. (dired-get-subdir))
  1192. (- arg 1)
  1193. arg)))
  1194. (dired-move-to-filename)))
  1195. (defun my-dired-print-current-dir-and-file ()
  1196. (message "%s %s"
  1197. default-directory
  1198. (buffer-substring-no-properties (point-at-bol)
  1199. (point-at-eol))))
  1200. (defun dired-do-execute-as-command ()
  1201. ""
  1202. (interactive)
  1203. (let ((file (dired-get-filename t)))
  1204. (if (file-executable-p file)
  1205. (start-process file nil file)
  1206. (when (y-or-n-p
  1207. "this file cant be executed. mark as executable and go? : ")
  1208. (set-file-modes file
  1209. (file-modes-symbolic-to-number "u+x" (file-modes file)))
  1210. (start-process file nil file)))))
  1211. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1212. (defun my-dired-x-open ()
  1213. ""
  1214. (interactive)
  1215. (my-x-open (dired-get-filename t t)))
  1216. (if (eq window-system 'mac)
  1217. (setq dired-listing-switches "-lhFG")
  1218. (setq dired-listing-switches "-lhFG --time-style=long-iso")
  1219. )
  1220. (setq dired-listing-switches "-lhFG")
  1221. (put 'dired-find-alternate-file 'disabled nil)
  1222. ;; when using dired-find-alternate-file
  1223. ;; reuse current dired buffer for the file to open
  1224. (setq dired-ls-F-marks-symlinks t)
  1225. (require 'ls-lisp)
  1226. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1227. (setq ls-lisp-dirs-first t)
  1228. (setq ls-lisp-use-localized-time-format t)
  1229. (setq ls-lisp-format-time-list
  1230. '("%Y-%m-%d %H:%M"
  1231. "%Y-%m-%d "))
  1232. (setq dired-dwim-target t)
  1233. ;; (add-hook 'dired-after-readin-hook
  1234. ;; 'my-replace-nasi-none)
  1235. ;; (add-hook 'after-init-hook
  1236. ;; (lambda ()
  1237. ;; (dired ".")))
  1238. (add-hook 'dired-mode-hook
  1239. (lambda ()
  1240. (define-key dired-mode-map "o" 'my-dired-x-open)
  1241. (define-key dired-mode-map "i" 'dired-get-file-info)
  1242. (define-key dired-mode-map "f" 'find-file)
  1243. (define-key dired-mode-map "!" 'shell-command)
  1244. (define-key dired-mode-map "&" 'async-shell-command)
  1245. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1246. (define-key dired-mode-map "=" 'my-dired-diff)
  1247. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1248. (define-key dired-mode-map "b" 'gtkbm)
  1249. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1250. (define-key dired-mode-map "@" (lambda ()
  1251. (interactive) (my-x-open ".")))
  1252. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1253. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1254. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1255. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1256. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1257. (substitute-key-definition 'dired-next-line
  1258. 'my-dired-next-line dired-mode-map)
  1259. (substitute-key-definition 'dired-previous-line
  1260. 'my-dired-previous-line dired-mode-map)
  1261. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1262. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1263. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1264. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1265. (let ((file "._Icon\015"))
  1266. (when nil (file-readable-p file)
  1267. (delete-file file)))))
  1268. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/pack.el"
  1269. t)
  1270. (lazy-load-eval 'pack '(dired-do-pack-or-unpack pack))
  1271. (add-hook 'dired-mode-hook
  1272. (lambda ()
  1273. (define-key dired-mode-map "P" 'dired-do-pack-or-unpack))))
  1274. (and (fetch-library
  1275. "https://raw.github.com/10sr/emacs-lisp/master/dired-list-all-mode.el"
  1276. t)
  1277. (lazy-load-eval 'dired-list-all-mode)
  1278. (setq dired-listing-switches "-lhFG")
  1279. (add-hook 'dired-mode-hook
  1280. (lambda ()
  1281. (define-key dired-mode-map "a" 'dired-list-all-mode)
  1282. )))
  1283. ) ; when dired locate
  1284. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  1285. (defun my-dired-toggle-mark()
  1286. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  1287. (t dired-marker-char))))
  1288. (delete-char 1)
  1289. (insert cur)))
  1290. (defun my-dired-mark (arg)
  1291. "toggle mark the current (or next ARG) files.
  1292. If on a subdir headerline, mark all its files except `.' and `..'.
  1293. Use \\[dired-unmark-all-files] to remove all marks
  1294. and \\[dired-unmark] on a subdir to remove the marks in
  1295. this subdir."
  1296. (interactive "P")
  1297. (if (dired-get-subdir)
  1298. (save-excursion (dired-mark-subdir-files))
  1299. (let ((inhibit-read-only t))
  1300. (dired-repeat-over-lines
  1301. (prefix-numeric-value arg)
  1302. 'my-dired-toggle-mark))))
  1303. (defun my-dired-mark-backward (arg)
  1304. "In Dired, move up lines and toggle mark there.
  1305. Optional prefix ARG says how many lines to unflag; default is one line."
  1306. (interactive "p")
  1307. (my-dired-mark (- arg)))
  1308. (add-hook 'dired-mode-hook
  1309. (lambda ()
  1310. (local-set-key (kbd "SPC") 'my-dired-mark)
  1311. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1312. )
  1313. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1314. ;; eshell
  1315. (lazy-load-eval 'eshell nil
  1316. (defun my-eshell-backward-delete-char ()
  1317. (interactive)
  1318. (when (< (save-excursion
  1319. (eshell-bol)
  1320. (point))
  1321. (point))
  1322. (backward-delete-char 1)))
  1323. (defun my-file-owner-p (file)
  1324. "t if FILE is owned by me."
  1325. (eq (user-uid) (nth 2 (file-attributes file))))
  1326. "http://www.bookshelf.jp/pukiwiki/pukiwiki.php\
  1327. ?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9"
  1328. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1329. ;; (defun eshell/less (&rest args)
  1330. ;; "Invoke `view-file' on the file.
  1331. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1332. ;; (if args
  1333. ;; (while args
  1334. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1335. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1336. ;; (file (pop args)))
  1337. ;; (view-file file)
  1338. ;; (goto-line line))
  1339. ;; (view-file (pop args))))))
  1340. (defun eshell/o (&optional file)
  1341. (my-x-open (or file ".")))
  1342. ;; (defun eshell/vi (&rest args)
  1343. ;; "Invoke `find-file' on the file.
  1344. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1345. ;; (while args
  1346. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1347. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1348. ;; (file (pop args)))
  1349. ;; (find-file file)
  1350. ;; (goto-line line))
  1351. ;; (find-file (pop args)))))
  1352. (defun eshell/clear ()
  1353. "Clear the current buffer, leaving one prompt at the top."
  1354. (let ((inhibit-read-only t))
  1355. (erase-buffer)))
  1356. (defun eshell/d (&optional dirname switches)
  1357. "if first arg is omitted open current directory."
  1358. (dired (or dirname ".") switches))
  1359. (defun eshell/v ()
  1360. (view-mode 1))
  1361. (defun eshell/git (&rest args)
  1362. ""
  1363. (if (member (car args)
  1364. '("di" "diff" "log" "show"))
  1365. (apply 'eshell-exec-visual "git" args)
  1366. (shell-command (mapconcat 'shell-quote-argument
  1367. `("git" ,@args)
  1368. " ")
  1369. t)
  1370. ;; (eshell-external-command "git" args)
  1371. ))
  1372. (defalias 'eshell/: 'ignore)
  1373. (defalias 'eshell/type 'eshell/which)
  1374. ;; (defalias 'eshell/vim 'eshell/vi)
  1375. (defalias 'eshell/ff 'find-file)
  1376. (defalias 'eshell/q 'eshell/exit)
  1377. (defun eshell-goto-prompt ()
  1378. ""
  1379. (interactive)
  1380. (goto-char (point-max)))
  1381. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1382. "open eshell and change wd
  1383. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1384. (interactive)
  1385. (let ((dir (expand-file-name default-directory)))
  1386. (switch-to-buffer (or eshell-buffer-or-name
  1387. (eshell t)))
  1388. (unless (equal dir (expand-file-name default-directory))
  1389. ;; (cd dir)
  1390. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1391. ;; (eshell-emit-prompt)
  1392. (goto-char (point-max))
  1393. (eshell-kill-input)
  1394. (insert "cd " dir)
  1395. (eshell-send-input))))
  1396. (setq eshell-directory-name "~/.emacs.d/eshell/")
  1397. (setq eshell-term-name "eterm-color")
  1398. (setq eshell-scroll-to-bottom-on-input t)
  1399. (setq eshell-cmpl-ignore-case t)
  1400. (setq eshell-cmpl-cycle-completions nil)
  1401. (setq eshell-highlight-prompt nil)
  1402. (setq eshell-ls-initial-args '("-hCFG"
  1403. "--color=auto"
  1404. "--time-style=long-iso")) ; "-hF")
  1405. (setq eshell-prompt-function
  1406. (lambda ()
  1407. (with-temp-buffer
  1408. (let (p1 p2 p3 p4)
  1409. (insert " [")
  1410. (setq p1 (point))
  1411. (insert (abbreviate-file-name default-directory))
  1412. (setq p2 (point))
  1413. (insert "]"
  1414. "\n")
  1415. (setq p3 (point))
  1416. (insert user-login-name
  1417. "@"
  1418. (or (getenv "HOSTNAME")
  1419. (substring (shell-command-to-string
  1420. (or (executable-find "hostname")
  1421. "echo ''"))
  1422. 0
  1423. -1)))
  1424. (setq p4 (point))
  1425. (insert " "
  1426. (format-time-string "%a, %d %b %Y %T %z")
  1427. " eshell\n"
  1428. "last:"
  1429. (number-to-string eshell-last-command-status)
  1430. (if (= (user-uid)
  1431. 0)
  1432. " # "
  1433. " $ "))
  1434. (add-text-properties p1
  1435. p2
  1436. '(face ((foreground-color . "yellow"))))
  1437. (add-text-properties p3
  1438. p4
  1439. '(face ((foreground-color . "cyan"))))
  1440. (buffer-substring (point-min)
  1441. (point-max))))))
  1442. (add-hook 'eshell-mode-hook
  1443. (lambda ()
  1444. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1445. ;; (interactive)
  1446. ;; (switch-to-buffer (other-buffer))))
  1447. (define-key eshell-mode-map (kbd "C-u") (lambda ()
  1448. (interactive)
  1449. (eshell-goto-prompt)
  1450. (eshell-kill-input)))
  1451. (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1452. (interactive)
  1453. (eshell-goto-prompt)
  1454. (my-keyboard-quit)))
  1455. (define-key eshell-mode-map
  1456. (kbd "DEL") 'my-eshell-backward-delete-char)
  1457. (define-key eshell-mode-map
  1458. (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1459. (define-key eshell-mode-map
  1460. (kbd "C-n") 'eshell-next-matching-input-from-input)
  1461. (apply 'eshell/addpath exec-path)
  1462. (set (make-local-variable 'scroll-margin) 0)
  1463. ;; (eshell/export "GIT_PAGER=")
  1464. ;; (eshell/export "GIT_EDITOR=")
  1465. (eshell/export "LC_MESSAGES=C")
  1466. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1467. (set (make-local-variable 'hl-line-range-function)
  1468. (lambda ()
  1469. '(0 . 0)))
  1470. (add-to-list 'eshell-virtual-targets
  1471. '("/dev/less"
  1472. (lambda (str)
  1473. (if str
  1474. (with-current-buffer nil)))
  1475. nil))
  1476. ))
  1477. (add-hook 'eshell-mode-hook
  1478. (lambda ()
  1479. (add-to-list 'eshell-visual-commands "vim")
  1480. ;; (add-to-list 'eshell-visual-commands "git")
  1481. (add-to-list 'eshell-output-filter-functions
  1482. 'eshell-truncate-buffer)
  1483. (mapcar (lambda (alias)
  1484. (add-to-list 'eshell-command-aliases-list
  1485. alias))
  1486. '(
  1487. ; ("ll" "ls -l $*")
  1488. ; ("la" "ls -a $*")
  1489. ; ("lla" "ls -al $*")
  1490. ("aptin" "apt-get install $*")
  1491. ("eless"
  1492. (concat "cat >>> (with-current-buffer "
  1493. "(get-buffer-create \"*eshell output\") "
  1494. "(erase-buffer) "
  1495. "(setq buffer-read-only nil) "
  1496. "(current-buffer)) "
  1497. "(view-buffer (get-buffer \"*eshell output*\"))")
  1498. ("g" "git $*")
  1499. ))
  1500. )))
  1501. ) ; eval after load eshell
  1502. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1503. ;; frame buffer
  1504. ;; todo:
  1505. ;; work well when opening the file that was already opened on another window
  1506. (add-hook 'after-make-frame-functions
  1507. (lambda (f)
  1508. (set-window-buffer (frame-selected-window f)
  1509. "*Messages*")))
  1510. (defun make-frame-command-with-name (name)
  1511. "Make frame with name specified."
  1512. (interactive "sName for new frame: ")
  1513. (set-frame-parameter (make-frame-command)
  1514. 'name
  1515. name))
  1516. (defvar my-frame-buffer-plist nil)
  1517. (defun my-frame-buffer-add (&optional buf frame)
  1518. ""
  1519. (setq my-frame-buffer-plist
  1520. (plist-put my-frame-buffer-plist
  1521. (or frame
  1522. (selected-frame))
  1523. (let ((lst (my-frame-buffer-get frame)))
  1524. (if lst
  1525. (add-to-list 'lst
  1526. (or buf
  1527. (current-buffer)))
  1528. (list (or buf
  1529. (current-buffer))))))))
  1530. (defun my-frame-buffer-remove (&optional buf frame)
  1531. ""
  1532. (setq my-frame-buffer-plist
  1533. (plist-put my-frame-buffer-plist
  1534. (or frame
  1535. (selected-frame))
  1536. (delq (or buf
  1537. (current-buffer))
  1538. (my-frame-buffer-get frame)))))
  1539. (defun my-frame-buffer-get (&optional frame)
  1540. ""
  1541. (plist-get my-frame-buffer-plist
  1542. (or frame
  1543. (selected-frame))))
  1544. (defun my-frame-buffer-kill-all-buffer (&optional frame)
  1545. ""
  1546. (mapcar 'kill-buffer
  1547. (my-frame-buffer-get frame)))
  1548. (add-hook 'find-file-hook
  1549. 'my-frame-buffer-add)
  1550. ;; (add-hook 'term-mode-hook
  1551. ;; 'my-frame-buffer-add)
  1552. (add-hook 'eshell-mode-hook
  1553. 'my-frame-buffer-add)
  1554. (add-hook 'Man-mode-hook
  1555. 'my-frame-buffer-add)
  1556. (add-hook 'kill-buffer-hook
  1557. 'my-frame-buffer-remove)
  1558. (add-hook 'delete-frame-functions
  1559. 'my-frame-buffer-kill-all-buffer)
  1560. (defvar my-desktop-terminal "roxterm")
  1561. (defun my-execute-terminal ()
  1562. ""
  1563. (interactive)
  1564. (if (and (or (eq system-type 'windows-nt)
  1565. window-system)
  1566. my-desktop-terminal
  1567. )
  1568. (let ((process-environment (cons "TERM=xterm" process-environment)))
  1569. (start-process "terminal"
  1570. nil
  1571. my-desktop-terminal))
  1572. (my-term)))
  1573. (defvar my-term nil "my terminal buffer")
  1574. (defun my-term ()
  1575. "open terminal buffer and return that buffer."
  1576. (interactive)
  1577. (if (and my-term
  1578. (buffer-name my-term))
  1579. (pop-to-buffer my-term)
  1580. (setq my-term
  1581. (if (eq system-type 'windows-nt)
  1582. (eshell)
  1583. (if (require 'multi-term nil t)
  1584. (multi-term)
  1585. (ansi-term shell-file-name))))))
  1586. (defun my-delete-frame-or-kill-emacs ()
  1587. "delete frame when opening multiple frame, kill emacs when only one."
  1588. (interactive)
  1589. (if (eq 1
  1590. (length (frame-list)))
  1591. (save-buffers-kill-emacs)
  1592. (delete-frame)))
  1593. (define-key my-prefix-map (kbd "C-s") 'my-execute-terminal)
  1594. (define-key my-prefix-map (kbd "C-f") 'make-frame-command-with-name)
  1595. (global-set-key (kbd "C-x C-c") 'my-delete-frame-or-kill-emacs)
  1596. (define-key my-prefix-map (kbd "C-x C-c") 'save-buffers-kill-emacs)
  1597. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1598. ;; x open
  1599. (defvar my-filer nil)
  1600. (setq my-filer (or (executable-find "pcmanfm")
  1601. (executable-find "nautilus")))
  1602. (defun my-x-open (file)
  1603. "open file."
  1604. (interactive "FOpen File: ")
  1605. (setq file (expand-file-name file))
  1606. (message "Opening %s..." file)
  1607. (cond ((eq system-type 'windows-nt)
  1608. (call-process "cmd.exe" nil 0 nil
  1609. "/c" "start" "" (convert-standard-filename file)))
  1610. ((eq system-type 'darwin)
  1611. (call-process "open" nil 0 nil file))
  1612. ((getenv "DISPLAY")
  1613. (call-process (or my-filer "xdg-open") nil 0 nil file))
  1614. (t
  1615. (find-file file))
  1616. )
  1617. ;; (recentf-add-file file)
  1618. (message "Opening %s...done" file))
  1619. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1620. ;; misc funcs
  1621. (defvar sed-in-place-history nil
  1622. "History of `sed-in-place'")
  1623. (defvar sed-in-place-command "sed --in-place=.bak -e")
  1624. (defun sed-in-place (command)
  1625. "sed in place"
  1626. (interactive (list (read-shell-command "sed in place: "
  1627. (concat sed-in-place-command " ")
  1628. 'sed-in-place-history)))
  1629. (shell-command command
  1630. "*sed in place*"))
  1631. (defun dired-do-sed-in-place (&optional arg)
  1632. "sed in place dired"
  1633. (interactive "P")
  1634. (require 'dired-aux)
  1635. (let* ((files (dired-get-marked-files t arg))
  1636. (expr (dired-mark-read-string "Run sed-in-place for %s: "
  1637. nil
  1638. 'sed-in-place
  1639. arg
  1640. files)))
  1641. (if (equal expr
  1642. "")
  1643. (error "No expression specified")
  1644. (shell-command (concat sed-in-place-command
  1645. " '"
  1646. expr
  1647. "' "
  1648. (mapconcat 'shell-quote-argument
  1649. files
  1650. " "))
  1651. "*sed in place*"))))
  1652. (defun dir-show (&optional dir)
  1653. (interactive)
  1654. (let ((bf (get-buffer-create "*dir show*"))
  1655. (list-directory-brief-switches "-C"))
  1656. (with-current-buffer bf
  1657. (list-directory (or nil
  1658. default-directory)
  1659. nil))
  1660. ))
  1661. (defun my-convmv-sjis2utf8-test ()
  1662. "run `convmv -r -f sjis -t utf8 *'
  1663. this is test, does not rename files"
  1664. (interactive)
  1665. (shell-command "convmv -r -f sjis -t utf8 *"))
  1666. (defun my-convmv-sjis2utf8-notest ()
  1667. "run `convmv -r -f sjis -t utf8 * --notest'"
  1668. (interactive)
  1669. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  1670. (defun kill-ring-save-buffer-file-name ()
  1671. "get current filename"
  1672. (interactive)
  1673. (let ((file buffer-file-name))
  1674. (if file
  1675. (progn (kill-new file)
  1676. (message file))
  1677. (message "not visiting file."))))
  1678. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1679. ;; ;; savage emacs
  1680. ;; ;; when enabled emacs fails to complete
  1681. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  1682. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  1683. ;; (setq arg
  1684. ;; (concat arg
  1685. ;; (if (eq nil (string-match "\\. *$" arg)) ".")
  1686. ;; " Stupid!")))
  1687. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1688. ;; japanese input method
  1689. (defun my-load-scim ()
  1690. "use scim-bridge.el as japanese im."
  1691. ;; Load scim-bridge.
  1692. (when (require 'scim-bridge nil t)
  1693. ;; Turn on scim-mode automatically after loading .emacs
  1694. (add-hook 'after-init-hook 'scim-mode-on)
  1695. (setq scim-cursor-color "red")
  1696. (scim-define-preedit-key ?\^h t)
  1697. (scim-define-common-key ?\* nil)
  1698. (scim-define-common-key ?\^/ nil)))
  1699. (defun my-load-anthy ()
  1700. "use anthy.el as japanese im."
  1701. ;; anthy
  1702. (when (require 'anthy nil t)
  1703. (global-set-key
  1704. (kbd "<muhenkan>") (lambda () (interactive) (anthy-mode-off)))
  1705. (global-set-key (kbd "<henkan>") (lambda () (interactive) (anthy-mode-on)))
  1706. (when (>= emacs-major-version 23)
  1707. (setq anthy-accept-timeout 1))))
  1708. ;; quail
  1709. ;; aproposs input-method for some information
  1710. ;; (setq default-input-method "japanese")
  1711. (defun my-load-mozc-el ()
  1712. ""
  1713. (setq mozc-leim-title "[MZ]")
  1714. (when (require 'mozc nil t)
  1715. (setq defauit-input-method "japanese-mozc")
  1716. ))
  1717. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1718. ;; for windows
  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))