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.
 
 
 
 
 
 

1967 lines
67 KiB

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