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.
 
 
 
 
 
 

1975 lines
67 KiB

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