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.
 
 
 
 
 
 

1951 lines
67 KiB

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