You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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