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.
 
 
 
 
 
 

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