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

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