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.
 
 
 
 
 
 

1971 lines
67 KiB

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