Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

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