25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 
 

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