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.
 
 
 
 
 
 

1978 lines
68 KiB

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