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.
 
 
 
 
 
 

1943 lines
66 KiB

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