Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 
 

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