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.
 
 
 
 
 
 

1969 lines
68 KiB

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