Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 
 

1947 строки
66 KiB

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