Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

2041 linhas
70 KiB

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