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.
 
 
 
 
 
 

1940 lines
66 KiB

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