Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

2626 righe
90 KiB

  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Commentary:
  3. ;;; Code:
  4. ;; SETUP_LOAD: (let ((file "DOTFILES_DIR/emacs.el"))
  5. ;; SETUP_LOAD: (and (file-readable-p file)
  6. ;; SETUP_LOAD: (load-file file)))
  7. ;; make directories
  8. (unless (file-directory-p (expand-file-name user-emacs-directory))
  9. (make-directory (expand-file-name user-emacs-directory)))
  10. (let ((d (expand-file-name (concat user-emacs-directory
  11. "lisp"))))
  12. (unless (file-directory-p d)
  13. (make-directory d))
  14. (add-to-list 'load-path d))
  15. (eval-when-compile
  16. ;; TODO: Use cl-lib intead
  17. (require 'cl nil t))
  18. ;; (add-hook 'after-change-major-mode-hook
  19. ;; (lambda ()
  20. ;; (message "cmm: %S %s"
  21. ;; major-mode
  22. ;; buffer-file-name)))
  23. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  24. ;; Some macros for internals
  25. (defun call-after-init (func)
  26. "If `after-init-hook' has been run, call FUNC immediately.
  27. Otherwize hook it."
  28. (if after-init-time
  29. (funcall func)
  30. (add-hook 'after-init-hook
  31. func)))
  32. (defmacro safe-require-or-eval (feature)
  33. "Require FEATURE if available.
  34. At compile time the feature will be loaded immediately."
  35. `(eval-and-compile
  36. (require ,feature nil t)))
  37. (defmacro autoload-eval-lazily (feature &optional functions &rest body)
  38. "Define autoloading FEATURE that defines FUNCTIONS.
  39. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  40. the function same as FEATURE is defined as autoloaded function. BODY is passed
  41. to `eval-after-load'.
  42. After this macro is expanded, this returns the path to library if FEATURE
  43. found, otherwise returns nil."
  44. (let* ((libname (symbol-name (eval feature)))
  45. (libpath (locate-library libname)))
  46. `(progn
  47. (when (locate-library ,libname)
  48. ,@(mapcar (lambda (f)
  49. (unless (fboundp f)
  50. `(progn
  51. (message "Autoloaded function `%S' defined (%s)"
  52. (quote ,f)
  53. ,libpath)
  54. (autoload (quote ,f)
  55. ,libname
  56. ,(concat "Autoloaded function defined in \""
  57. libpath
  58. "\".")
  59. t))))
  60. (or (eval functions)
  61. `(,(eval feature)))))
  62. (eval-after-load ,feature
  63. (quote (progn
  64. ,@body)))
  65. (locate-library ,libname))))
  66. (put 'autoload-eval-lazily 'lisp-indent-function 2)
  67. (when (autoload-eval-lazily 'tetris nil
  68. (message "Tetris loaded!"))
  69. (message "Tetris found!"))
  70. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  71. ;; download library from web
  72. (defvar fetch-library-enabled-p t
  73. "Set nil to skip downloading with `fetch-library'.")
  74. (defun fetch-library (url &optional byte-compile-p force-download-p)
  75. "Download a library from URL and locate it in \"~/emacs.d/lisp/\".
  76. Return nil if library unfound and failed to download,
  77. otherwise the path where the library installed.
  78. If BYTE-COMPILE-P is t byte compile the file after downloading.
  79. If FORCE-DOWNLOAD-P it t ignore exisiting library and always download.
  80. This function also checks the value of `fetch-library-enabled-p' and do not
  81. fetch libraries if this value is nil. In this case all arguments (including
  82. FORCE-DOWNLOAD-P) will be ignored."
  83. (let* ((dir (expand-file-name (concat user-emacs-directory "lisp/")))
  84. (lib (file-name-sans-extension (file-name-nondirectory url)))
  85. (lpath (concat dir lib ".el"))
  86. (locate-p (locate-library lib)))
  87. (if (and fetch-library-enabled-p
  88. (or force-download-p
  89. (not locate-p)))
  90. (if (progn (message "Downloading %s..."
  91. url)
  92. (download-file url
  93. lpath
  94. t))
  95. (progn (message "Downloading %s...done"
  96. url)
  97. (when (and byte-compile-p
  98. (require 'bytecomp nil t))
  99. (and (file-exists-p (byte-compile-dest-file lpath))
  100. (delete-file (byte-compile-dest-file lpath)))
  101. (message "Byte-compiling %s..."
  102. lpath)
  103. (byte-compile-file lpath)
  104. (message "Byte-compiling %s...done"
  105. lpath)))
  106. (progn (and (file-writable-p lpath)
  107. (delete-file lpath))
  108. (message "Downloading %s...failed"
  109. url))))
  110. (locate-library lib)))
  111. ;; If EMACS_EL_DRY_RUN is set and it is not an empty string, fetch-library
  112. ;; does not actually fetch library.
  113. (let ((dryrun (getenv "EMACS_EL_DRY_RUN")))
  114. (when (and dryrun
  115. (< 0
  116. (length dryrun)))
  117. (setq fetch-library-enabled-p
  118. nil)
  119. (message "EMACS_EL_DRY_RUN is set. Skip fetching libraries.")))
  120. (defun download-file (url path &optional ok-if-already-exists)
  121. "Download file from URL and output to PATH.
  122. IF OK-IF-ALREADY-EXISTS is true force download."
  123. (let ((curl (executable-find "curl"))
  124. (wget (executable-find "wget")))
  125. (cond (wget
  126. (if (and (not ok-if-already-exists)
  127. (file-exists-p path))
  128. nil
  129. (and (eq 0
  130. (call-process wget
  131. nil
  132. nil
  133. nil
  134. "-O"
  135. path
  136. url
  137. ))
  138. path)))
  139. (curl
  140. (if (and (not ok-if-already-exists)
  141. (file-exists-p path))
  142. nil
  143. (and (eq 0
  144. (call-process curl
  145. nil
  146. nil
  147. nil
  148. "--output"
  149. path
  150. "-L"
  151. url
  152. ))
  153. path)))
  154. (t
  155. (ignore-errors
  156. (require 'url)
  157. (url-copy-file url
  158. path
  159. ok-if-already-exists)
  160. path)))))
  161. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  162. ;; package
  163. (set-variable 'my-package-list
  164. '(
  165. markdown-mode
  166. yaml-mode
  167. gnuplot-mode
  168. erlang
  169. js2-mode
  170. git-commit
  171. gitignore-mode
  172. ;; ack
  173. color-moccur
  174. ggtags
  175. flycheck
  176. ;; is flymake installs are required?
  177. ;;flymake-jshint
  178. ;;flymake-python-pyflakes
  179. xclip
  180. foreign-regexp
  181. multi-term
  182. term-run
  183. editorconfig
  184. git-ps1-mode
  185. restart-emacs
  186. fill-column-indicator
  187. scala-mode2
  188. ensime
  189. editorconfig
  190. git-command
  191. ;; 10sr repository
  192. terminal-title
  193. recentf-show
  194. dired-list-all-mode
  195. pack
  196. set-modeline-color
  197. read-only-only-mode
  198. smart-revert
  199. autosave
  200. ;;window-organizer
  201. remember-major-modes-mode
  202. ilookup
  203. pasteboard
  204. )
  205. "Package list just for me.")
  206. (when (safe-require-or-eval 'package)
  207. ;; (add-to-list 'package-archives
  208. ;; '("ELPA" . "http://tromey.com/elpa/"))
  209. (setq package-archives
  210. `(,@package-archives
  211. ("melpa" . "https://melpa.org/packages/")
  212. ("10sr-el" . "https://10sr.github.io/emacs-lisp/p/")))
  213. ;; (add-to-list 'package-archives
  214. ;; '("melpa" . "https://melpa.org/packages/")
  215. ;; t)
  216. ;; (add-to-list 'package-archives
  217. ;; '("marmalade" . "http://marmalade-repo.org/packages/"))
  218. (package-initialize)
  219. (defun my-auto-install-package ()
  220. "Install packages semi-automatically."
  221. (interactive)
  222. (package-refresh-contents)
  223. (mapc (lambda (pkg)
  224. (or (package-installed-p pkg)
  225. (locate-library (symbol-name pkg))
  226. (package-install pkg)))
  227. my-package-list))
  228. )
  229. ;; (lazy-load-eval 'sudoku)
  230. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  231. ;; my-idle-hook
  232. (defvar my-idle-hook nil
  233. "Hook run when idle for several secs.")
  234. (defvar my-idle-hook-sec 5
  235. "Second to run `my-idle-hook'.")
  236. (run-with-idle-timer my-idle-hook-sec
  237. t
  238. (lambda ()
  239. (run-hooks 'my-idle-hook)))
  240. ;; (add-hook 'my-idle-hook
  241. ;; (lambda ()
  242. ;; (message "idle hook message")))
  243. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  244. ;; start and quit
  245. (setq inhibit-startup-message t)
  246. (setq confirm-kill-emacs 'y-or-n-p)
  247. (setq gc-cons-threshold (* 1024 1024 4))
  248. (when window-system
  249. (add-to-list 'default-frame-alist '(cursor-type . box))
  250. (add-to-list 'default-frame-alist '(background-color . "white"))
  251. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  252. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  253. ;; does not work?
  254. )
  255. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  256. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  257. (and (fboundp 'tool-bar-mode)
  258. (tool-bar-mode 0))
  259. (and (fboundp 'set-scroll-bar-mode)
  260. (set-scroll-bar-mode nil))
  261. (add-hook 'kill-emacs-hook
  262. ;; load init file when terminating emacs to ensure file is not broken
  263. 'reload-init-file)
  264. (defun my-force-kill-emacs ()
  265. "My force kill Emacs."
  266. (interactive)
  267. (let ((kill-emacs-hook nil))
  268. (kill-emacs)))
  269. (call-after-init
  270. (lambda ()
  271. (message "%s %s" invocation-name emacs-version)
  272. (message "%s was taken to initialize emacs." (emacs-init-time))
  273. (switch-to-buffer "*Messages*")))
  274. (cd ".") ; when using windows use / instead of \ in `default-directory'
  275. ;; locale
  276. (set-language-environment "Japanese")
  277. (set-default-coding-systems 'utf-8-unix)
  278. (prefer-coding-system 'utf-8-unix)
  279. (setq system-time-locale "C")
  280. ;; my prefix map
  281. (defvar my-prefix-map nil
  282. "My prefix map.")
  283. (define-prefix-command 'my-prefix-map)
  284. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  285. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  286. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  287. ;; (comint-show-maximum-output)
  288. ;; kill scratch
  289. (call-after-init (lambda ()
  290. (let ((buf (get-buffer "*scratch*")))
  291. (when buf
  292. (kill-buffer buf)))))
  293. ;; modifier keys
  294. ;; (setq mac-option-modifier 'control)
  295. ;; display
  296. (setq visible-bell t)
  297. (setq ring-bell-function 'ignore)
  298. (mouse-avoidance-mode 'banish)
  299. (defun reload-init-file ()
  300. "Reload Emacs init file."
  301. (interactive)
  302. (when (and user-init-file
  303. (file-readable-p user-init-file))
  304. (load-file user-init-file)))
  305. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  306. ;; for windows
  307. (defun start-ckw-bash ()
  308. "Start ckw in windows."
  309. (interactive)
  310. (start-process
  311. "ckw_bash"
  312. nil
  313. "C:/Documents and Settings/sr/Application Data/dbx/apps/ckw/ckw.exe"))
  314. ;; command seems to have to be in c drive
  315. (defun my-w32-add-export-path (&rest args)
  316. "Add pathes ARGS for windows."
  317. (mapc (lambda (path)
  318. (add-to-list 'exec-path (expand-file-name path)))
  319. (reverse args))
  320. (setenv "PATH"
  321. (mapconcat 'convert-standard-filename
  322. exec-path
  323. ";")))
  324. (when (eq system-type 'windows-nt)
  325. ;; (setq scheme-program-name "\"c:/Program Files/Gauche/bin/gosh.exe\" -i")
  326. ;; (setq python-python-command "c:/Python26/python.exe")
  327. ;; (define-key my-prefix-map (kbd "C-c") 'start-ckw-bash)
  328. (my-w32-add-export-path "c:/Windows/system"
  329. "c:/Windows/System32"
  330. "c:/Program Files/Git/bin"
  331. "c:/MinGW/bin"
  332. "c:/MinGW/mingw32/bin"
  333. (expand-file-name "~/.local/bin")
  334. (expand-file-name "~/dbx/apps/bin"))
  335. (when window-system
  336. (set-variable 'w32-enable-synthesized-fonts t))
  337. (set-variable 'w32-apps-modifier 'meta)
  338. (setq file-name-coding-system 'sjis))
  339. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  340. ;; global keys
  341. (global-set-key (kbd "<up>") 'scroll-down-line)
  342. (global-set-key (kbd "<down>") 'scroll-up-line)
  343. (global-set-key (kbd "<left>") 'scroll-down)
  344. (global-set-key (kbd "<right>") 'scroll-up)
  345. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  346. (global-set-key (kbd "C-\\") help-map)
  347. (define-key ctl-x-map (kbd "DEL") help-map)
  348. (define-key ctl-x-map (kbd "C-h") help-map)
  349. (define-key help-map "a" 'apropos)
  350. ;; disable annoying keys
  351. (global-set-key [prior] 'ignore)
  352. (global-set-key (kbd "<next>") 'ignore)
  353. (global-set-key [menu] 'ignore)
  354. (global-set-key [down-mouse-1] 'ignore)
  355. (global-set-key [down-mouse-2] 'ignore)
  356. (global-set-key [down-mouse-3] 'ignore)
  357. (global-set-key [mouse-1] 'ignore)
  358. (global-set-key [mouse-2] 'ignore)
  359. (global-set-key [mouse-3] 'ignore)
  360. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  361. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  362. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  363. ;; title and mode-line
  364. (when (safe-require-or-eval 'terminal-title)
  365. ;; if TERM is not screen use default value
  366. (if (getenv "TMUX")
  367. ;; if use tmux locally just basename of current dir
  368. (setq terminal-title-format
  369. '((file-name-nondirectory (directory-file-name
  370. default-directory))))
  371. (if (and (let ((tty-type (frame-parameter nil
  372. 'tty-type)))
  373. (and tty-type
  374. (equal (car (split-string tty-type
  375. "-"))
  376. "screen")))
  377. (not (getenv "SSH_CONNECTION")))
  378. (setq terminal-title-format
  379. '((file-name-nondirectory (directory-file-name
  380. default-directory))))
  381. ;; seems that TMUX is used locally and ssh to remote host
  382. (setq terminal-title-format
  383. `("em:"
  384. ,user-login-name
  385. "@"
  386. ,(car (split-string system-name
  387. "\\."))
  388. ":"
  389. default-directory))
  390. )
  391. )
  392. (terminal-title-mode))
  393. (setq eol-mnemonic-dos "\\r\\n")
  394. (setq eol-mnemonic-mac "\\r")
  395. (setq eol-mnemonic-unix "\\n")
  396. (which-function-mode 0)
  397. (line-number-mode 0)
  398. (column-number-mode 0)
  399. (size-indication-mode 0)
  400. (setq mode-line-position
  401. '(:eval (format "L%%l/%d,C%%c"
  402. (count-lines (point-max)
  403. (point-min)))))
  404. (when (require 'git-ps1-mode nil t)
  405. (git-ps1-mode))
  406. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  407. ;; display date
  408. (call-after-init (lambda ()
  409. (when display-time-mode
  410. (display-time-update))))
  411. (when (safe-require-or-eval 'time)
  412. (setq display-time-interval 29)
  413. (setq display-time-day-and-date t)
  414. (setq display-time-format "%a, %d %b %Y %T")
  415. (if window-system
  416. (display-time-mode 0)
  417. (display-time-mode 1)))
  418. ;; ;; current directory
  419. ;; (let ((ls (member 'mode-line-buffer-identification
  420. ;; mode-line-format)))
  421. ;; (setcdr ls
  422. ;; (cons '(:eval (concat " ("
  423. ;; (abbreviate-file-name default-directory)
  424. ;; ")"))
  425. ;; (cdr ls))))
  426. ;; ;; display last modified time
  427. ;; (let ((ls (member 'mode-line-buffer-identification
  428. ;; mode-line-format)))
  429. ;; (setcdr ls
  430. ;; (cons '(:eval (concat " "
  431. ;; my-buffer-file-last-modified-time))
  432. ;; (cdr ls))))
  433. (defun buffer-list-not-start-with-space ()
  434. "Return a list of buffers that not start with whitespaces."
  435. (let ((bl (buffer-list))
  436. b nbl)
  437. (while bl
  438. (setq b (pop bl))
  439. (unless (string-equal " "
  440. (substring (buffer-name b)
  441. 0
  442. 1))
  443. (add-to-list 'nbl b)))
  444. nbl))
  445. ;; http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/
  446. ;; (add-to-list 'minor-mode-alist
  447. ;; '(global-whitespace-mode ""))
  448. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  449. ;; system info
  450. (defun my-message-current-info ()
  451. "Echo current login name, hostname and directory."
  452. (interactive)
  453. (message "%s@%s:%s"
  454. user-login-name
  455. system-name
  456. (abbreviate-file-name default-directory)))
  457. ;; (run-with-idle-timer 3
  458. ;; t
  459. ;; 'my-message-current-info)
  460. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  461. ;; minibuffer
  462. (setq insert-default-directory t)
  463. (setq completion-ignore-case t
  464. read-file-name-completion-ignore-case t
  465. read-buffer-completion-ignore-case t)
  466. (setq resize-mini-windows t)
  467. (temp-buffer-resize-mode 1)
  468. (savehist-mode 1)
  469. (fset 'yes-or-no-p 'y-or-n-p)
  470. ;; complete symbol when `eval'
  471. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  472. (define-key minibuffer-local-map (kbd "C-u")
  473. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  474. ;; I dont know these bindings are good
  475. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  476. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  477. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  478. ;; letters, font-lock mode and fonts
  479. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  480. ;; (set-window-margins (selected-window) 1 1)
  481. (and (or (eq system-type 'Darwin)
  482. (eq system-type 'darwin))
  483. (fboundp 'mac-set-input-method-parameter)
  484. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  485. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  486. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  487. (boundp 'input-method-inactivate-hook))
  488. (add-hook 'input-method-activate-hook
  489. (lambda () (set-cursor-color "red")))
  490. (add-hook 'input-method-inactivate-hook
  491. (lambda () (set-cursor-color "black"))))
  492. (when (safe-require-or-eval 'paren)
  493. (show-paren-mode 1)
  494. (setq show-paren-delay 0.5
  495. show-paren-style 'parenthesis) ; mixed is hard to read
  496. ;; (set-face-background 'show-paren-match
  497. ;; "black")
  498. ;; ;; (face-foreground 'default))
  499. ;; (set-face-foreground 'show-paren-match
  500. ;; "white")
  501. ;; (set-face-inverse-video-p 'show-paren-match
  502. ;; t)
  503. )
  504. (transient-mark-mode 1)
  505. (global-font-lock-mode 1)
  506. (setq font-lock-global-modes
  507. '(not
  508. help-mode
  509. eshell-mode
  510. ;;term-mode
  511. Man-mode))
  512. ;; (standard-display-ascii ?\n "$\n")
  513. (defvar my-eol-face
  514. '(("\n" . (0 font-lock-comment-face t nil)))
  515. )
  516. (defvar my-tab-face
  517. '(("\t" . '(0 highlight t nil))))
  518. (defvar my-jspace-face
  519. '(("\u3000" . '(0 highlight t nil))))
  520. (add-hook 'font-lock-mode-hook
  521. (lambda ()
  522. ;; (font-lock-add-keywords nil my-eol-face)
  523. (font-lock-add-keywords nil my-jspace-face)
  524. ))
  525. (when (safe-require-or-eval 'whitespace)
  526. (add-to-list 'whitespace-display-mappings ; not work
  527. `(tab-mark ?\t ,(vconcat "^I\t")))
  528. (add-to-list 'whitespace-display-mappings
  529. `(newline-mark ?\n ,(vconcat "$\n")))
  530. (setq whitespace-style '(face
  531. trailing ; trailing blanks
  532. newline ; newlines
  533. newline-mark ; use display table for newline
  534. ;; tab-mark
  535. empty ; empty lines at beg or end of buffer
  536. lines-tail ; lines over 80
  537. ))
  538. ;; (setq whitespace-newline 'font-lock-comment-face)
  539. (global-whitespace-mode t)
  540. (if (eq (display-color-cells)
  541. 256)
  542. (set-face-foreground 'whitespace-newline "brightblack")
  543. ;; (progn
  544. ;; (set-face-bold-p 'whitespace-newline
  545. ;; t))
  546. ))
  547. (and nil
  548. (safe-require-or-eval 'fill-column-indicator)
  549. (setq fill-column-indicator))
  550. ;; highlight current line
  551. ;; http://wiki.riywo.com/index.php?Meadow
  552. (defface my-hl-line
  553. '((((min-colors 256)
  554. (background dark))
  555. (:background "color-234"))
  556. (((min-colors 256)
  557. (background light))
  558. (:background "color-234"))
  559. (t
  560. (:underline "black")))
  561. "*Face used by hl-line.")
  562. (set-variable 'hl-line-face 'my-hl-line) ;; (setq hl-line-face nil)
  563. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  564. (set-variable 'hl-line-global-modes
  565. '(not
  566. term-mode))
  567. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  568. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  569. ;; fonts
  570. (defun my-set-ascii-and-jp-font (list)
  571. "Set font configuration to LIST."
  572. (let ((fspec1 (if (> emacs-major-version 22)
  573. ;; font spec is available in emacs23 and later
  574. (font-spec :family (nth 2 list) :size (nth 3 list))
  575. (cons (nth 2 list) "jisx0208.*")))
  576. (fspec2 (if (> emacs-major-version 22)
  577. (font-spec :family (nth 2 list) :size (nth 3 list))
  578. (cons (nth 2 list) "jisx0201.*"))))
  579. (set-face-attribute 'default nil
  580. :family (nth 0 list)
  581. :height (nth 1 list))
  582. (set-fontset-font "fontset-default"
  583. 'japanese-jisx0208
  584. fspec1)
  585. (set-fontset-font "fontset-default"
  586. 'katakana-jisx0201
  587. fspec2)))
  588. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 90 "takaogothic" 13))
  589. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "takaogothic" 14))
  590. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "ms gothic" 14))
  591. ;; (my-set-ascii-and-jp-font '("monaco" 75 "takaogothic" 11))
  592. ;; (my-set-ascii-and-jp-font '("monaco" 90 "takaogothic" 13))
  593. ;; (my-set-ascii-and-jp-font '("ProggyCleanTTSZ" 120 "takaogothic" 11))
  594. ;; あ a
  595. (safe-require-or-eval 'set-modeline-color)
  596. (let ((fg (face-foreground 'default))
  597. (bg (face-background 'default)))
  598. (set-face-background 'mode-line-inactive
  599. (if (face-inverse-video-p 'mode-line) fg bg))
  600. (set-face-foreground 'mode-line-inactive
  601. (if (face-inverse-video-p 'mode-line) bg fg)))
  602. (set-face-underline 'mode-line-inactive
  603. t)
  604. (set-face-underline 'vertical-border
  605. nil)
  606. ;; Not found in MELPA nor any other package repositories
  607. (and (fetch-library
  608. "https://raw.github.com/tarao/elisp/master/end-mark.el"
  609. t)
  610. (safe-require-or-eval 'end-mark)
  611. (global-end-mark-mode))
  612. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  613. ;; file handling
  614. (when (safe-require-or-eval 'editorconfig)
  615. (editorconfig-mode 1))
  616. (setq revert-without-query '(".+"))
  617. ;; save cursor position
  618. (when (safe-require-or-eval 'saveplace)
  619. (setq-default save-place t)
  620. (setq save-place-file (concat user-emacs-directory
  621. "places")))
  622. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  623. (setq make-backup-files t)
  624. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  625. (setq backup-directory-alist
  626. (cons (cons "\\.*$" (expand-file-name (concat user-emacs-directory
  627. "backup")))
  628. backup-directory-alist))
  629. (setq version-control 'never)
  630. (setq delete-old-versions t)
  631. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  632. "auto-save/")))
  633. (setq delete-auto-save-files t)
  634. (add-to-list 'completion-ignored-extensions ".bak")
  635. ;; (setq delete-by-moving-to-trash t
  636. ;; trash-directory "~/.emacs.d/trash")
  637. (add-hook 'after-save-hook
  638. 'executable-make-buffer-file-executable-if-script-p)
  639. (set-variable 'bookmark-default-file (concat user-emacs-directory
  640. "bmk"))
  641. (add-hook 'recentf-load-hook
  642. (lambda ()
  643. (defvar recentf-exclude)
  644. (add-to-list 'recentf-exclude
  645. (regexp-quote bookmark-default-file))))
  646. (when (safe-require-or-eval 'smart-revert)
  647. (smart-revert-on))
  648. ;; autosave
  649. (when (safe-require-or-eval 'autosave)
  650. (autosave-set 2))
  651. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  652. ;; editting
  653. (defun my-copy-whole-line ()
  654. "Copy whole line."
  655. (interactive)
  656. (kill-new (concat (buffer-substring (point-at-bol)
  657. (point-at-eol))
  658. "\n")))
  659. (setq require-final-newline t)
  660. (setq kill-whole-line t)
  661. (setq scroll-conservatively 35
  662. scroll-margin 2
  663. scroll-step 0)
  664. (setq-default major-mode 'text-mode)
  665. (setq next-line-add-newlines nil)
  666. (setq kill-read-only-ok t)
  667. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  668. ;; (setq-default line-spacing 0.2)
  669. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  670. (setq-default tab-width 4)
  671. (setq-default indent-tabs-mode nil)
  672. (setq-default indent-line-function nil)
  673. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  674. (delete-selection-mode 1)
  675. (cua-mode 0)
  676. (setq line-move-visual nil)
  677. ;; key bindings
  678. ;; moving around
  679. ;; (global-set-key (kbd "M-j") 'next-line)
  680. ;; (global-set-key (kbd "M-k") 'previous-line)
  681. ;; (global-set-key (kbd "M-h") 'backward-char)
  682. ;; (global-set-key (kbd "M-l") 'forward-char)
  683. ;;(keyboard-translate ?\M-j ?\C-j)
  684. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  685. (define-key esc-map "p" 'backward-paragraph)
  686. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  687. (define-key esc-map "n" 'forward-paragraph)
  688. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  689. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  690. (global-set-key (kbd "C-<left>") 'scroll-down)
  691. (global-set-key (kbd "C-<right>") 'scroll-up)
  692. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  693. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  694. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  695. ;; C-h and DEL
  696. (global-set-key (kbd "C-h") (kbd "DEL"))
  697. (global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  698. (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  699. (define-key esc-map "k" 'my-copy-whole-line)
  700. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  701. (define-key esc-map "u" 'undo)
  702. (define-key esc-map "i" (kbd "ESC TAB"))
  703. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  704. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  705. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  706. (define-key my-prefix-map (kbd "C-o") 'occur)
  707. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  708. ;; japanese input method
  709. (defun my-load-scim ()
  710. "Use scim-bridge.el as japanese im."
  711. ;; Load scim-bridge.
  712. (when (safe-require-or-eval 'scim-bridge)
  713. ;; Turn on scim-mode automatically after loading .emacs
  714. (call-after-init 'scim-mode-on)
  715. (set-variable 'scim-cursor-color "red")
  716. (scim-define-preedit-key ?\^h t)
  717. (scim-define-common-key ?\* nil)
  718. (scim-define-common-key ?\^/ nil)))
  719. (defun my-load-anthy ()
  720. "Use anthy.el as japanese im."
  721. ;; anthy
  722. (when (safe-require-or-eval 'anthy)
  723. (global-set-key
  724. (kbd "<muhenkan>") (lambda () (interactive) (anthy-mode-off)))
  725. (global-set-key (kbd "<henkan>") (lambda () (interactive) (anthy-mode-on)))
  726. (when (>= emacs-major-version 23)
  727. (set-variable 'anthy-accept-timeout 1))))
  728. ;; quail
  729. ;; aproposs input-method for some information
  730. ;; (setq default-input-method "japanese")
  731. (defun my-load-mozc-el ()
  732. "Use mozc.el as japanese im."
  733. (when (safe-require-or-eval 'mozc)
  734. (set-variable 'defauit-input-method "japanese-mozc")
  735. (set-variable 'mozc-leim-title "[MZ]")
  736. ))
  737. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  738. ;; gmail
  739. (setq mail-interactive t
  740. send-mail-function 'smtpmail-send-it)
  741. ;; message-send-mail-function 'smtpmail-send-it
  742. (with-eval-after-load 'smtpmail
  743. (setq smtpmail-smtp-server "smtp.gmail.com"
  744. smtpmail-smtp-service 587
  745. smtpmail-starttls-credentials '(("smtp.gmail.com" 587
  746. "8.slashes@gmail.com" nil))
  747. smtpmail-auth-credentials '(("smtp.gmail.com" 587
  748. "8.slashes@gmail.com" nil))
  749. user-mail-address "8.slashes@gmail.com"))
  750. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  751. ;; buffer killing
  752. ;; (defun my-delete-window-killing-buffer () nil)
  753. (defun my-query-kill-current-buffer ()
  754. "Interactively kill current buffer."
  755. (interactive)
  756. (if (y-or-n-p (concat "kill current buffer? :"))
  757. (kill-buffer (current-buffer))))
  758. (substitute-key-definition 'kill-buffer
  759. 'my-query-kill-current-buffer
  760. global-map)
  761. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  762. (defun my-kill-buffers ()
  763. "Kill buffers that visit files."
  764. (interactive)
  765. (mapcar (lambda (buf)
  766. (when (buffer-file-name buf)
  767. (kill-buffer buf)))
  768. (buffer-list)))
  769. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  770. ;; share clipboard with x
  771. ;; this page describes this in details, but only these sexps seem to be needed
  772. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  773. (and (not window-system)
  774. (not (eq window-system 'mac))
  775. (getenv "DISPLAY")
  776. (not (equal (getenv "DISPLAY") ""))
  777. (executable-find "xclip")
  778. ;; (< emacs-major-version 24)
  779. (safe-require-or-eval 'xclip)
  780. nil
  781. (turn-on-xclip))
  782. (and (eq system-type 'darwin)
  783. (safe-require-or-eval 'pasteboard)
  784. (turn-on-pasteboard)
  785. (getenv "TMUX")
  786. (pasteboard-enable-rtun))
  787. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  788. ;; https://github.com/lunaryorn/flycheck
  789. (when (safe-require-or-eval 'flycheck)
  790. (call-after-init 'global-flycheck-mode))
  791. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  792. ;; window
  793. ;; (when (autoload-eval-lazily 'window-organizer)
  794. ;; (define-key ctl-x-map (kbd "w") 'window-organizer))
  795. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  796. ;; server
  797. (when (safe-require-or-eval 'server)
  798. (setq server-name (concat "server"
  799. (number-to-string (emacs-pid))))
  800. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  801. ;; In Darwin environment, init fails with message like 'Service name too long'
  802. ;; when server-use-tcp is nil
  803. (when (or (eq system-type
  804. 'cygwin)
  805. (eq system-type
  806. 'darwin))
  807. (setq server-use-tcp t))
  808. (defun my-construct-emacsclient-editor-command ()
  809. "Construct and return command in a string to connect to current Emacs server."
  810. (if server-use-tcp
  811. (format "%s -f \"%s/%s\""
  812. "emacsclient"
  813. (expand-file-name server-auth-dir)
  814. server-name)
  815. (format "%s -s \"%s/%s\""
  816. "emacsclient"
  817. server-socket-dir
  818. server-name)))
  819. (setq process-environment
  820. `(,(concat "EDITOR="
  821. (my-construct-emacsclient-editor-command))
  822. ,(concat "GIT_EDITOR="
  823. (my-construct-emacsclient-editor-command))
  824. ,@process-environment))
  825. (server-start))
  826. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  827. ;; some modes and hooks
  828. (set-variable 'ac-ignore-case nil)
  829. ;; (when (require 'ensime nil t)
  830. ;; (set-variable 'ensime-ac-case-sensitive t)
  831. ;; (set-variable 'ensime-company-case-sensitive t)
  832. ;; (add-hook 'scala-mode-hook
  833. ;; 'ensime-scala-mode-hook)
  834. ;; (add-hook 'ensime-scala-mode-hook
  835. ;; 'ac-stop))
  836. (when (autoload-eval-lazily 'term-run '(term-run-shell-command term-run))
  837. (define-key ctl-x-map "t" 'term-run-shell-command))
  838. (add-to-list 'safe-local-variable-values
  839. '(encoding utf-8))
  840. (setq enable-local-variables :safe)
  841. (when (safe-require-or-eval 'remember-major-modes-mode)
  842. (remember-major-modes-mode 1))
  843. ;; Detect file type from shebang and set major-mode.
  844. (add-to-list 'interpreter-mode-alist
  845. '("python3" . python-mode))
  846. (add-to-list 'interpreter-mode-alist
  847. '("python2" . python-mode))
  848. ;; http://fukuyama.co/foreign-regexp
  849. '(and (safe-require-or-eval 'foreign-regexp)
  850. (progn
  851. (setq foreign-regexp/regexp-type 'perl)
  852. '(setq reb-re-syntax 'foreign-regexp)
  853. ))
  854. (safe-require-or-eval 'session)
  855. (autoload-eval-lazily 'sql '(sql-mode)
  856. (safe-require-or-eval 'sql-indent))
  857. (when (autoload-eval-lazily 'git-command)
  858. (define-key ctl-x-map "g" 'git-command))
  859. (and (fetch-library
  860. "http://www.emacswiki.org/emacs/download/sl.el"
  861. t)
  862. (autoload-eval-lazily 'sl))
  863. (defalias 'qcalc 'quick-calc)
  864. (safe-require-or-eval 'simple)
  865. (add-hook 'makefile-mode-hook
  866. (lambda ()
  867. (local-set-key (kbd "C-m") 'newline-and-indent)
  868. ;; this functions is set in write-file-functions, i cannot find any
  869. ;; good way to remove this.
  870. (fset 'makefile-warn-suspicious-lines 'ignore)
  871. ))
  872. (add-hook 'verilog-mode-hook
  873. (lambda ()
  874. (local-set-key ";" 'self-insert-command)))
  875. (setq diff-switches "-u")
  876. (add-hook 'diff-mode-hook
  877. (lambda ()
  878. ;; (when (and (eq major-mode
  879. ;; 'diff-mode)
  880. ;; (not buffer-file-name))
  881. ;; ;; do not pass when major-mode is derived mode of diff-mode
  882. ;; (view-mode 1))
  883. (set-face-attribute 'diff-header nil
  884. :foreground nil
  885. :background nil
  886. :weight 'bold)
  887. (set-face-attribute 'diff-file-header nil
  888. :foreground nil
  889. :background nil
  890. :weight 'bold)
  891. (set-face-foreground 'diff-index-face "blue")
  892. (set-face-attribute 'diff-hunk-header nil
  893. :foreground "cyan"
  894. :weight 'normal)
  895. (set-face-attribute 'diff-context nil
  896. ;; :foreground "white"
  897. :foreground nil
  898. :weight 'normal)
  899. (set-face-foreground 'diff-removed-face "red")
  900. (set-face-foreground 'diff-added-face "green")
  901. (set-face-background 'diff-removed-face nil)
  902. (set-face-background 'diff-added-face nil)
  903. (set-face-attribute 'diff-changed nil
  904. :foreground "magenta"
  905. :weight 'normal)
  906. (set-face-attribute 'diff-refine-change nil
  907. :foreground nil
  908. :background nil
  909. :weight 'bold
  910. :inverse-video t)
  911. ;; Annoying !
  912. ;;(diff-auto-refine-mode)
  913. ))
  914. ;; (ffap-bindings)
  915. (add-hook 'sh-mode-hook
  916. (lambda ()
  917. (local-set-key
  918. (kbd "C-x C-e")
  919. 'my-execute-shell-command-current-line)))
  920. (set-variable 'sh-here-document-word "__EOC__")
  921. (defun my-execute-shell-command-current-line ()
  922. "Run current line as shell command."
  923. (interactive)
  924. (shell-command (buffer-substring-no-properties (point-at-bol)
  925. (point))))
  926. (setq auto-mode-alist
  927. `(("autostart\\'" . sh-mode)
  928. ("xinitrc\\'" . sh-mode)
  929. ("xprograms\\'" . sh-mode)
  930. ("PKGBUILD\\'" . sh-mode)
  931. ,@auto-mode-alist))
  932. (and (autoload-eval-lazily 'pkgbuild-mode)
  933. (setq auto-mode-alist (append '(("PKGBUILD\\'" . pkgbuild-mode))
  934. auto-mode-alist)))
  935. (and (autoload-eval-lazily 'groovy-mode)
  936. (add-to-list 'auto-mode-alist
  937. '("build.gradle\\'" . groovy-mode)))
  938. (add-hook 'yaml-mode-hook
  939. (lambda ()
  940. (local-set-key(kbd "C-m") 'newline)))
  941. (add-hook 'html-mode-hook
  942. (lambda ()
  943. (local-set-key(kbd "C-m") 'reindent-then-newline-and-indent)))
  944. (add-hook 'text-mode-hook
  945. (lambda ()
  946. (local-set-key (kbd "C-m") 'newline)))
  947. (add-to-list 'Info-default-directory-list
  948. (expand-file-name "~/.info/emacs-ja"))
  949. (add-hook 'apropos-mode-hook
  950. (lambda ()
  951. (local-set-key "n" 'next-line)
  952. (local-set-key "p" 'previous-line)
  953. ))
  954. (add-hook 'isearch-mode-hook
  955. (lambda ()
  956. ;; (define-key isearch-mode-map
  957. ;; (kbd "C-j") 'isearch-other-control-char)
  958. ;; (define-key isearch-mode-map
  959. ;; (kbd "C-k") 'isearch-other-control-char)
  960. ;; (define-key isearch-mode-map
  961. ;; (kbd "C-h") 'isearch-other-control-char)
  962. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  963. (define-key isearch-mode-map (kbd "M-r")
  964. 'isearch-query-replace-regexp)))
  965. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  966. (setq lazy-highlight-cleanup nil)
  967. ;; face for isearch highlighing
  968. (set-face-attribute 'lazy-highlight
  969. nil
  970. :foreground `unspecified
  971. :background `unspecified
  972. :underline t
  973. ;; :weight `bold
  974. )
  975. (add-hook 'outline-mode-hook
  976. (lambda ()
  977. (if (string-match "\\.md\\'" buffer-file-name)
  978. (set (make-local-variable 'outline-regexp) "#+ "))))
  979. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  980. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  981. (when (autoload-eval-lazily 'markdown-mode
  982. '(markdown-mode gfm-mode))
  983. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  984. (setq markdown-command (or (executable-find "markdown")
  985. (executable-find "markdown.pl")))
  986. (add-hook 'markdown-mode-hook
  987. (lambda ()
  988. (outline-minor-mode 1)
  989. (flyspell-mode)
  990. (set (make-local-variable 'comment-start) ";")))
  991. (add-hook 'gfm-mode-hook
  992. (lambda ()
  993. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline)
  994. ;;(electric-indent-mode 0)
  995. )))
  996. ;; c-mode
  997. ;; http://www.emacswiki.org/emacs/IndentingC
  998. ;; http://en.wikipedia.org/wiki/Indent_style
  999. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  1000. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  1001. (with-eval-after-load 'cc-vars
  1002. (defvar c-default-style)
  1003. (add-to-list 'c-default-style
  1004. '(c-mode . "k&r"))
  1005. (add-to-list 'c-default-style
  1006. '(c++-mode . "k&r"))
  1007. (add-hook 'c-mode-common-hook
  1008. (lambda ()
  1009. ;; why c-basic-offset in k&r style defaults to 5 ???
  1010. (set-variable 'c-basic-offset 4)
  1011. (set-variable 'indent-tabs-mode nil)
  1012. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  1013. (c-toggle-hungry-state -1)
  1014. ;; (and (require 'gtags nil t)
  1015. ;; (gtags-mode 1))
  1016. )))
  1017. (when (autoload-eval-lazily 'php-mode)
  1018. (add-hook 'php-mode-hook
  1019. (lambda ()
  1020. (setq c-basic-offset 2))))
  1021. (when (autoload-eval-lazily 'js2-mode)
  1022. ;; currently do not use js2-mode
  1023. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  1024. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  1025. (add-hook 'js2-mode-hook
  1026. (lambda ()
  1027. (define-key js2-mode-map (kbd "C-m") (lambda ()
  1028. (interactive)
  1029. (js2-enter-key)
  1030. (indent-for-tab-command)))
  1031. ;; (add-hook (kill-local-variable 'before-save-hook)
  1032. ;; 'js2-before-save)
  1033. ;; (add-hook 'before-save-hook
  1034. ;; 'my-indent-buffer
  1035. ;; nil
  1036. ;; t)
  1037. )))
  1038. (eval-after-load "js"
  1039. (set-variable 'js-indent-level 2))
  1040. (add-to-list 'interpreter-mode-alist
  1041. '("node" . js-mode))
  1042. (when (autoload-eval-lazily 'flymake-jslint
  1043. '(flymake-jslint-load))
  1044. (autoload-eval-lazily 'js nil
  1045. (add-hook 'js-mode-hook
  1046. 'flymake-jslint-load)))
  1047. (safe-require-or-eval 'js-doc)
  1048. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  1049. (when (safe-require-or-eval 'uniquify)
  1050. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  1051. (setq uniquify-ignore-buffers-re "*[^*]+*")
  1052. (setq uniquify-min-dir-content 1))
  1053. (add-hook 'view-mode-hook
  1054. (lambda()
  1055. (defvar view-mode-map)
  1056. (define-key view-mode-map "j" 'scroll-up-line)
  1057. (define-key view-mode-map "k" 'scroll-down-line)
  1058. (define-key view-mode-map "v" 'toggle-read-only)
  1059. (define-key view-mode-map "q" 'bury-buffer)
  1060. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  1061. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  1062. ;; (define-key view-mode-map
  1063. ;; "n" 'nonincremental-repeat-search-forward)
  1064. ;; (define-key view-mode-map
  1065. ;; "N" 'nonincremental-repeat-search-backward)
  1066. (define-key view-mode-map "/" 'isearch-forward-regexp)
  1067. (define-key view-mode-map "?" 'isearch-backward-regexp)
  1068. (define-key view-mode-map "n" 'isearch-repeat-forward)
  1069. (define-key view-mode-map "N" 'isearch-repeat-backward)
  1070. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point)
  1071. ))
  1072. (global-set-key "\M-r" 'view-mode)
  1073. ;; (setq view-read-only t)
  1074. ;; (defun my-view-mode-search-word (word)
  1075. ;; "Search for word current directory and subdirectories.
  1076. ;; If called intearctively, find word at point."
  1077. ;; (interactive (list (thing-at-point 'symbol)))
  1078. ;; (if word
  1079. ;; (if (and (require 'gtags nil t)
  1080. ;; (gtags-get-rootpath))
  1081. ;; (gtags-goto-tag word "s")
  1082. ;; (my-rgrep word))
  1083. ;; (message "No word at point.")
  1084. ;; nil))
  1085. (add-hook 'Man-mode-hook
  1086. (lambda ()
  1087. (view-mode 1)
  1088. (setq truncate-lines nil)))
  1089. (set-variable 'Man-notify-method (if window-system
  1090. 'newframe
  1091. 'aggressive))
  1092. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  1093. "woman_cache.el")))
  1094. (defalias 'man 'woman)
  1095. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1096. ;; python
  1097. (when (autoload-eval-lazily 'python '(python-mode))
  1098. (set-variable 'python-python-command (or (executable-find "python3")
  1099. (executable-find "python")))
  1100. ;; (defun my-python-run-as-command ()
  1101. ;; ""
  1102. ;; (interactive)
  1103. ;; (shell-command (concat python-python-command " " buffer-file-name)))
  1104. (defun my-python-display-python-buffer ()
  1105. ""
  1106. (interactive)
  1107. (defvar python-buffer)
  1108. (set-window-text-height (display-buffer python-buffer
  1109. t)
  1110. 7))
  1111. (add-hook 'python-mode-hook
  1112. (lambda ()
  1113. (local-set-key (kbd "C-c C-e") 'my-python-run-as-command)
  1114. (local-set-key (kbd "C-c C-b") 'my-python-display-python-buffer)
  1115. (local-set-key (kbd "C-m") 'newline-and-indent)))
  1116. (add-hook 'inferior-python-mode-hook
  1117. (lambda ()
  1118. (my-python-display-python-buffer)
  1119. (local-set-key (kbd "<up>") 'comint-previous-input)
  1120. (local-set-key (kbd "<down>") 'comint-next-input))))
  1121. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1122. ;; GNU GLOBAL(gtags)
  1123. ;; http://uguisu.skr.jp/Windows/gtags.html
  1124. ;; http://eigyr.dip.jp/gtags.html
  1125. ;; http://cha.la.coocan.jp/doc/gnu_global.html
  1126. (let ((d "/opt/local/share/gtags/"))
  1127. (and (file-directory-p d)
  1128. (add-to-list 'load-path
  1129. d)))
  1130. (when (autoload-eval-lazily 'gtags '(gtags-mode))
  1131. (add-hook 'gtags-mode-hook
  1132. (lambda ()
  1133. (view-mode gtags-mode)
  1134. (setq gtags-select-buffer-single t)
  1135. ;; (local-set-key "\M-t" 'gtags-find-tag)
  1136. ;; (local-set-key "\M-r" 'gtags-find-rtag)
  1137. ;; (local-set-key "\M-s" 'gtags-find-symbol)
  1138. ;; (local-set-key "\C-t" 'gtags-pop-stack)
  1139. (define-key gtags-mode-map (kbd "C-x t h")
  1140. 'gtags-find-tag-from-here)
  1141. (define-key gtags-mode-map (kbd "C-x t t") 'gtags-find-tag)
  1142. (define-key gtags-mode-map (kbd "C-x t r") 'gtags-find-rtag)
  1143. (define-key gtags-mode-map (kbd "C-x t s") 'gtags-find-symbol)
  1144. (define-key gtags-mode-map (kbd "C-x t p") 'gtags-find-pattern)
  1145. (define-key gtags-mode-map (kbd "C-x t f") 'gtags-find-file)
  1146. (define-key gtags-mode-map (kbd "C-x t b") 'gtags-pop-stack) ;back
  1147. ))
  1148. (add-hook 'gtags-select-mode-hook
  1149. (lambda ()
  1150. (define-key gtags-select-mode-map (kbd "C-m") 'gtags-select-tag)
  1151. ))
  1152. )
  1153. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1154. ;; term mode
  1155. ;; (setq multi-term-program shell-file-name)
  1156. (when (autoload-eval-lazily 'multi-term)
  1157. (setq multi-term-switch-after-close nil)
  1158. (setq multi-term-dedicated-select-after-open-p t)
  1159. (setq multi-term-dedicated-window-height 20))
  1160. (when (autoload-eval-lazily 'term '(term ansi-term))
  1161. (defun my-term-quit-or-send-raw ()
  1162. ""
  1163. (interactive)
  1164. (if (get-buffer-process (current-buffer))
  1165. (call-interactively 'term-send-raw)
  1166. (kill-buffer)))
  1167. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  1168. ;; (setq term-ansi-default-program shell-file-name)
  1169. (add-hook 'term-setup-hook
  1170. (lambda ()
  1171. (set-variable 'term-display-table (make-display-table))))
  1172. (add-hook 'term-mode-hook
  1173. (lambda ()
  1174. (defvar term-raw-map)
  1175. (unless (memq (current-buffer)
  1176. (and (featurep 'multi-term)
  1177. (defvar multi-term-buffer-list)
  1178. ;; current buffer is not multi-term buffer
  1179. multi-term-buffer-list))
  1180. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  1181. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  1182. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  1183. ;; (define-key term-raw-map "\C-f" 'forward-char)
  1184. ;; (define-key term-raw-map "\C-b" 'backward-char)
  1185. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  1186. (define-key term-raw-map
  1187. "\C-x" (lookup-key (current-global-map) "\C-x"))
  1188. (define-key term-raw-map
  1189. "\C-z" (lookup-key (current-global-map) "\C-z"))
  1190. )
  1191. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  1192. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  1193. (define-key term-raw-map (kbd "<up>") 'scroll-down-line)
  1194. (define-key term-raw-map (kbd "<down>") 'scroll-up-line)
  1195. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  1196. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  1197. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  1198. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  1199. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  1200. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  1201. (define-key term-raw-map [delete] 'term-send-raw)
  1202. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  1203. (define-key term-raw-map "\C-y" 'term-paste)
  1204. (define-key term-raw-map
  1205. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  1206. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  1207. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  1208. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  1209. ;; (define-key term-raw-map "\C-d" 'delete-char)
  1210. (set (make-local-variable 'scroll-margin) 0)
  1211. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  1212. ;; (cua-mode 0)
  1213. ;; (and cua-mode
  1214. ;; (local-unset-key (kbd "C-c")))
  1215. ;; (define-key cua--prefix-override-keymap
  1216. ;;"\C-c" 'term-interrupt-subjob)
  1217. (set (make-local-variable (defvar hl-line-range-function))
  1218. (lambda ()
  1219. '(0 . 0)))
  1220. ))
  1221. ;; (add-hook 'term-exec-hook 'forward-char)
  1222. )
  1223. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1224. ;; buffer switching
  1225. (defvar bs-configurations)
  1226. (when (autoload-eval-lazily 'bs '(bs-show)
  1227. ;; (add-to-list 'bs-configurations
  1228. ;; '("processes" nil get-buffer-process ".*" nil nil))
  1229. (add-to-list 'bs-configurations
  1230. '("files-and-terminals" nil nil nil
  1231. (lambda (buf)
  1232. (and (bs-visits-non-file buf)
  1233. (save-excursion
  1234. (set-buffer buf)
  1235. (not (memq major-mode
  1236. '(term-mode
  1237. eshell-mode))))))))
  1238. ;; (setq bs-configurations (list
  1239. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1240. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1241. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1242. )
  1243. ;; (global-set-key "\C-x\C-b" 'bs-show)
  1244. (defalias 'list-buffers 'bs-show)
  1245. (set-variable 'bs-default-configuration "files-and-terminals")
  1246. (set-variable 'bs-default-sort-name "by nothing")
  1247. (add-hook 'bs-mode-hook
  1248. (lambda ()
  1249. ;; (setq bs-default-configuration "files")
  1250. ;; (and bs--show-all
  1251. ;; (call-interactively 'bs-toggle-show-all))
  1252. (set (make-local-variable 'scroll-margin) 0))))
  1253. ;;(iswitchb-mode 1)
  1254. (icomplete-mode)
  1255. (defun iswitchb-buffer-display-other-window ()
  1256. "Do iswitchb in other window."
  1257. (interactive)
  1258. (let ((iswitchb-default-method 'display))
  1259. (call-interactively 'iswitchb-buffer)))
  1260. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1261. ;; sdic
  1262. (when (autoload-eval-lazily 'sdic '(sdic-describe-word-at-point))
  1263. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  1264. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo)
  1265. (defun sdic-describe-word-at-point-echo ()
  1266. ""
  1267. (interactive)
  1268. (save-window-excursion
  1269. (sdic-describe-word-at-point))
  1270. (save-excursion
  1271. (set-buffer sdic-buffer-name)
  1272. (message (buffer-substring (point-min)
  1273. (progn (goto-char (point-min))
  1274. (or (and (re-search-forward "^\\w"
  1275. nil
  1276. t
  1277. 4)
  1278. (progn (previous-line) t)
  1279. (point-at-eol))
  1280. (point-max)))))))
  1281. (setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  1282. (setq sdic-waei-dictionary-list
  1283. '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  1284. (setq sdic-disable-select-window t)
  1285. (setq sdic-window-height 7))
  1286. ;;;;;;;;;;;;;;;;;;;;;;;;
  1287. ;; ilookup
  1288. (with-eval-after-load 'ilookup
  1289. (setq ilookup-dict-alist
  1290. '(
  1291. ("sdcv" . (lambda (word)
  1292. (shell-command-to-string
  1293. (format "sdcv -n '%s'"
  1294. word))))
  1295. ("en" . (lambda (word)
  1296. (shell-command-to-string
  1297. (format "sdcv -n -u dictd_www.dict.org_gcide '%s'"
  1298. word))))
  1299. ("ja" . (lambda (word)
  1300. (shell-command-to-string
  1301. (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'"
  1302. word))))
  1303. ("jaj" . (lambda (word)
  1304. (shell-command-to-string
  1305. (format "sdcv -n -u jmdict-en-ja '%s'"
  1306. word))))
  1307. ("jag" .
  1308. (lambda (word)
  1309. (with-temp-buffer
  1310. (insert (shell-command-to-string
  1311. (format "sdcv -n -u 'Genius English-Japanese' '%s'"
  1312. word)))
  1313. (html2text)
  1314. (buffer-substring (point-min)
  1315. (point-max)))))
  1316. ("alc" . (lambda (word)
  1317. (shell-command-to-string
  1318. (format "alc '%s' | head -n 20"
  1319. word))))
  1320. ("app" . (lambda (word)
  1321. (shell-command-to-string
  1322. (format "dict_app '%s'"
  1323. word))))
  1324. ;; letters broken
  1325. ("ms" .
  1326. (lambda (word)
  1327. (let ((url (concat
  1328. "http://api.microsofttranslator.com/V2/Ajax.svc/"
  1329. "Translate?appId=%s&text=%s&to=%s"))
  1330. (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51")
  1331. (target "ja")
  1332. (eword (url-hexify-string word)))
  1333. (with-current-buffer (url-retrieve-synchronously
  1334. (format url
  1335. apikey
  1336. eword
  1337. target))
  1338. (message "")
  1339. (goto-char (point-min))
  1340. (search-forward-regexp "^$"
  1341. nil
  1342. t)
  1343. (url-unhex-string (buffer-substring-no-properties
  1344. (point)
  1345. (point-max)))))))
  1346. ))
  1347. ;; (funcall (cdr (assoc "ms"
  1348. ;; ilookup-alist))
  1349. ;; "dictionary")
  1350. ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja"))
  1351. ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com"))
  1352. (setq ilookup-default "ja")
  1353. (when (locate-library "google-translate")
  1354. (add-to-list 'ilookup-dict-alist
  1355. '("gt" .
  1356. (lambda (word)
  1357. (save-excursion
  1358. (google-translate-translate "auto"
  1359. "ja"
  1360. word))
  1361. (with-current-buffer "*Google Translate*"
  1362. (buffer-substring-no-properties (point-min)
  1363. (point-max)))))))
  1364. )
  1365. (when (autoload-eval-lazily 'google-translate '(google-translate-translate
  1366. google-translate-at-point))
  1367. (setq google-translate-default-source-language "auto")
  1368. (setq google-translate-default-target-language "ja"))
  1369. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1370. ;; vc
  1371. (require 'vc)
  1372. (setq vc-handled-backends '())
  1373. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1374. ;; gauche-mode
  1375. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  1376. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  1377. (when (and (fetch-library
  1378. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  1379. t)
  1380. (autoload-eval-lazily 'gauche-mode '(gauche-mode run-scheme)))
  1381. (let ((s (executable-find "gosh")))
  1382. (setq scheme-program-name s
  1383. gauche-program-name s))
  1384. (defun run-gauche-other-window ()
  1385. "Run gauche on other window"
  1386. (interactive)
  1387. (switch-to-buffer-other-window
  1388. (get-buffer-create "*scheme*"))
  1389. (run-gauche))
  1390. (defun run-gauche ()
  1391. "run gauche"
  1392. (interactive)
  1393. (run-scheme gauche-program-name)
  1394. )
  1395. (defun scheme-send-buffer ()
  1396. ""
  1397. (interactive)
  1398. (scheme-send-region (point-min) (point-max))
  1399. (my-scheme-display-scheme-buffer)
  1400. )
  1401. (defun my-scheme-display-scheme-buffer ()
  1402. ""
  1403. (interactive)
  1404. (set-window-text-height (display-buffer scheme-buffer
  1405. t)
  1406. 7))
  1407. (add-hook 'scheme-mode-hook
  1408. (lambda ()
  1409. nil))
  1410. (add-hook 'inferior-scheme-mode-hook
  1411. (lambda ()
  1412. ;; (my-scheme-display-scheme-buffer)
  1413. ))
  1414. (setq auto-mode-alist
  1415. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1416. (setq auto-mode-alist
  1417. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1418. (add-hook 'gauche-mode-hook
  1419. (lambda ()
  1420. (define-key gauche-mode-map
  1421. (kbd "C-c C-z") 'run-gauche-other-window)
  1422. (define-key scheme-mode-map
  1423. (kbd "C-c C-c") 'scheme-send-buffer)
  1424. (define-key scheme-mode-map
  1425. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer))))
  1426. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1427. ;; recentf-mode
  1428. (setq recentf-save-file (expand-file-name (concat user-emacs-directory
  1429. "recentf"))
  1430. recentf-max-menu-items 20
  1431. recentf-max-saved-items 30
  1432. recentf-show-file-shortcuts-flag nil)
  1433. (when (safe-require-or-eval 'recentf)
  1434. (add-to-list 'recentf-exclude
  1435. (regexp-quote recentf-save-file))
  1436. (add-to-list 'recentf-exclude
  1437. (regexp-quote (expand-file-name user-emacs-directory)))
  1438. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1439. (remove-hook 'find-file-hook
  1440. 'recentf-track-opened-file)
  1441. (defun my-recentf-load-track-save-list ()
  1442. "Load current recentf list from file, track current visiting file, then save
  1443. the list."
  1444. (recentf-load-list)
  1445. (recentf-track-opened-file)
  1446. (recentf-save-list))
  1447. (add-hook 'find-file-hook
  1448. 'my-recentf-load-track-save-list)
  1449. (add-hook 'kill-emacs-hook
  1450. 'recentf-load-list)
  1451. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1452. ;; (add-hook 'find-file-hook
  1453. ;; (lambda ()
  1454. ;; (recentf-add-file default-directory)))
  1455. (and (autoload-eval-lazily 'recentf-show)
  1456. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1457. (add-hook 'recentf-show-before-listing-hook
  1458. 'recentf-load-list))
  1459. (recentf-mode 1)
  1460. (add-hook 'recentf-dialog-mode-hook
  1461. (lambda ()
  1462. ;; (recentf-save-list)
  1463. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1464. ;; 'my-recentf-cd-and-find-file)
  1465. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1466. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1467. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1468. (define-key recentf-dialog-mode-map "n" 'next-line)
  1469. (cd "~/"))))
  1470. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1471. ;; dired
  1472. (when (autoload-eval-lazily 'dired nil)
  1473. (defun my-dired-echo-file-head (arg)
  1474. ""
  1475. (interactive "P")
  1476. (let ((f (dired-get-filename)))
  1477. (message "%s"
  1478. (with-temp-buffer
  1479. (insert-file-contents f)
  1480. (buffer-substring-no-properties
  1481. (point-min)
  1482. (progn (goto-line (if arg
  1483. (prefix-numeric-value arg)
  1484. 7))
  1485. (point-at-eol)))))))
  1486. (defun my-dired-diff ()
  1487. ""
  1488. (interactive)
  1489. (let ((files (dired-get-marked-files nil nil nil t)))
  1490. (if (eq (car files)
  1491. t)
  1492. (diff (cadr files) (dired-get-filename))
  1493. (message "One files must be marked!"))))
  1494. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  1495. "pop up buffer using `display-buffer' and return that buffer."
  1496. (let ((bf (get-buffer-create buffer-or-name)))
  1497. (with-current-buffer bf
  1498. (cd ".")
  1499. (erase-buffer))
  1500. (display-buffer bf)
  1501. bf))
  1502. (defun my-replace-nasi-none ()
  1503. ""
  1504. (save-excursion
  1505. (let ((buffer-read-only nil))
  1506. (goto-char (point-min))
  1507. (while (search-forward "なし" nil t)
  1508. (replace-match "none")))))
  1509. (defun dired-get-file-info ()
  1510. "dired get file info"
  1511. (interactive)
  1512. (let ((f (shell-quote-argument (dired-get-filename t))))
  1513. (if (file-directory-p f)
  1514. (progn
  1515. (message "Calculating disk usage...")
  1516. (shell-command (concat "du -hsD "
  1517. f)))
  1518. (shell-command (concat "file "
  1519. f)))))
  1520. (defun my-dired-scroll-up ()
  1521. ""
  1522. (interactive)
  1523. (my-dired-previous-line (- (window-height) 1)))
  1524. (defun my-dired-scroll-down ()
  1525. ""
  1526. (interactive)
  1527. (my-dired-next-line (- (window-height) 1)))
  1528. ;; (defun my-dired-forward-line (arg)
  1529. ;; ""
  1530. ;; (interactive "p"))
  1531. (defun my-dired-previous-line (arg)
  1532. ""
  1533. (interactive "p")
  1534. (if (> arg 0)
  1535. (progn
  1536. (if (eq (line-number-at-pos)
  1537. 1)
  1538. (goto-char (point-max))
  1539. (forward-line -1))
  1540. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1541. (dired-get-subdir))
  1542. (- arg 1)
  1543. arg)))
  1544. (dired-move-to-filename)))
  1545. (defun my-dired-next-line (arg)
  1546. ""
  1547. (interactive "p")
  1548. (if (> arg 0)
  1549. (progn
  1550. (if (eq (point)
  1551. (point-max))
  1552. (goto-char (point-min))
  1553. (forward-line 1))
  1554. (my-dired-next-line (if (or (dired-get-filename nil t)
  1555. (dired-get-subdir))
  1556. (- arg 1)
  1557. arg)))
  1558. (dired-move-to-filename)))
  1559. (defun my-dired-print-current-dir-and-file ()
  1560. (message "%s %s"
  1561. default-directory
  1562. (buffer-substring-no-properties (point-at-bol)
  1563. (point-at-eol))))
  1564. (defun dired-do-execute-as-command ()
  1565. ""
  1566. (interactive)
  1567. (let ((file (dired-get-filename t)))
  1568. (if (file-executable-p file)
  1569. (start-process file nil file)
  1570. (when (y-or-n-p
  1571. "This file cant be executed. Mark as executable and go? ")
  1572. (set-file-modes file
  1573. (file-modes-symbolic-to-number "u+x" (file-modes file)))
  1574. (start-process file nil file)))))
  1575. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1576. (defun my-dired-x-open ()
  1577. ""
  1578. (interactive)
  1579. (my-x-open (dired-get-filename t t)))
  1580. (if (eq window-system 'mac)
  1581. (setq dired-listing-switches "-lhF")
  1582. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1583. )
  1584. (setq dired-listing-switches "-lhF")
  1585. (put 'dired-find-alternate-file 'disabled nil)
  1586. ;; when using dired-find-alternate-file
  1587. ;; reuse current dired buffer for the file to open
  1588. (set-variable 'dired-ls-F-marks-symlinks t)
  1589. (when (safe-require-or-eval 'ls-lisp)
  1590. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1591. (setq ls-lisp-dirs-first t)
  1592. (setq ls-lisp-use-localized-time-format t)
  1593. (setq ls-lisp-format-time-list
  1594. '("%Y-%m-%d %H:%M"
  1595. "%Y-%m-%d ")))
  1596. (set-variable 'dired-dwim-target t)
  1597. (set-variable 'dired-isearch-filenames t)
  1598. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  1599. (set-variable 'dired-hide-details-hide-information-lines nil)
  1600. ;; (add-hook 'dired-after-readin-hook
  1601. ;; 'my-replace-nasi-none)
  1602. ;; (add-hook 'after-init-hook
  1603. ;; (lambda ()
  1604. ;; (dired ".")))
  1605. (add-hook 'dired-mode-hook
  1606. (lambda ()
  1607. (local-set-key "o" 'my-dired-x-open)
  1608. (local-set-key "i" 'dired-get-file-info)
  1609. (local-set-key "f" 'find-file)
  1610. (local-set-key "!" 'shell-command)
  1611. (local-set-key "&" 'async-shell-command)
  1612. (local-set-key "X" 'dired-do-async-shell-command)
  1613. (local-set-key "=" 'my-dired-diff)
  1614. (local-set-key "B" 'gtkbm-add-current-dir)
  1615. (local-set-key "b" 'gtkbm)
  1616. (local-set-key "h" 'my-dired-echo-file-head)
  1617. (local-set-key "@" (lambda ()
  1618. (interactive) (my-x-open ".")))
  1619. (local-set-key (kbd "TAB") 'other-window)
  1620. ;; (local-set-key "P" 'my-dired-do-pack-or-unpack)
  1621. (local-set-key "/" 'dired-isearch-filenames)
  1622. (local-set-key (kbd "DEL") 'dired-up-directory)
  1623. (local-set-key (kbd "C-h") 'dired-up-directory)
  1624. (substitute-key-definition 'dired-next-line
  1625. 'my-dired-next-line
  1626. (current-local-map))
  1627. (substitute-key-definition 'dired-previous-line
  1628. 'my-dired-previous-line
  1629. (current-local-map))
  1630. ;; (local-set-key (kbd "C-p") 'my-dired-previous-line)
  1631. ;; (local-set-key (kbd "p") 'my-dired-previous-line)
  1632. ;; (local-set-key (kbd "C-n") 'my-dired-next-line)
  1633. ;; (local-set-key (kbd "n") 'my-dired-next-line)
  1634. (local-set-key (kbd "<left>") 'my-dired-scroll-up)
  1635. (local-set-key (kbd "<right>") 'my-dired-scroll-down)
  1636. (local-set-key (kbd "ESC p") 'my-dired-scroll-up)
  1637. (local-set-key (kbd "ESC n") 'my-dired-scroll-down)
  1638. (when (fboundp 'dired-hide-details-mode)
  1639. (dired-hide-details-mode t)
  1640. (local-set-key "l" 'dired-hide-details-mode))
  1641. (let ((file "._Icon\015"))
  1642. (when nil (file-readable-p file)
  1643. (delete-file file)))))
  1644. (and (autoload-eval-lazily 'pack '(dired-do-pack-or-unpack pack))
  1645. (add-hook 'dired-mode-hook
  1646. (lambda ()
  1647. (local-set-key "P" 'dired-do-pack-or-unpack))))
  1648. (and (autoload-eval-lazily 'dired-list-all-mode)
  1649. (setq dired-listing-switches "-lhF")
  1650. (add-hook 'dired-mode-hook
  1651. (lambda ()
  1652. (local-set-key "a" 'dired-list-all-mode)
  1653. )))
  1654. ) ; when dired locate
  1655. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  1656. (defvar dired-marker-char)
  1657. (defun my-dired-toggle-mark()
  1658. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  1659. (t dired-marker-char))))
  1660. (delete-char 1)
  1661. (insert cur)))
  1662. (defun my-dired-mark (arg)
  1663. "Toggle mark the current (or next ARG) files.
  1664. If on a subdir headerline, mark all its files except `.' and `..'.
  1665. Use \\[dired-unmark-all-files] to remove all marks
  1666. and \\[dired-unmark] on a subdir to remove the marks in
  1667. this subdir."
  1668. (interactive "P")
  1669. (if (dired-get-subdir)
  1670. (save-excursion (dired-mark-subdir-files))
  1671. (let ((inhibit-read-only t))
  1672. (dired-repeat-over-lines
  1673. (prefix-numeric-value arg)
  1674. 'my-dired-toggle-mark))))
  1675. (defun my-dired-mark-backward (arg)
  1676. "In Dired, move up lines and toggle mark there.
  1677. Optional prefix ARG says how many lines to unflag; default is one line."
  1678. (interactive "p")
  1679. (my-dired-mark (- arg)))
  1680. (add-hook 'dired-mode-hook
  1681. (lambda ()
  1682. (local-set-key (kbd "SPC") 'my-dired-mark)
  1683. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1684. )
  1685. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1686. ;; eshell
  1687. (autoload-eval-lazily 'eshell nil
  1688. (set-variable 'eshell-banner-message (format "Welcome to the Emacs shell
  1689. %s
  1690. C-x t to toggling emacs-text-mode
  1691. "
  1692. (shell-command-to-string "uname -a")
  1693. ))
  1694. (defvar eshell-text-mode-map
  1695. (let ((map (make-sparse-keymap)))
  1696. (define-key map (kbd "C-x t") 'eshell-text-mode-toggle)
  1697. map))
  1698. (define-derived-mode eshell-text-mode text-mode
  1699. "Eshell-Text"
  1700. "Text-mode for Eshell."
  1701. nil)
  1702. (defun eshell-text-mode-toggle ()
  1703. "Toggle eshell-text-mode and eshell-mode."
  1704. (interactive)
  1705. (cond ((eq major-mode
  1706. 'eshell-text-mode)
  1707. (goto-char (point-max))
  1708. (message "Eshell text mode disabled")
  1709. (eshell-mode))
  1710. ((eq major-mode
  1711. 'eshell-mode)
  1712. (message "Eshell text mode enabled")
  1713. (eshell-write-history)
  1714. (eshell-text-mode))
  1715. (t
  1716. (message "Not in eshell buffer")
  1717. nil)))
  1718. (defun my-eshell-backward-delete-char ()
  1719. (interactive)
  1720. (when (< (save-excursion
  1721. (eshell-bol)
  1722. (point))
  1723. (point))
  1724. (backward-delete-char 1)))
  1725. (defun my-file-owner-p (file)
  1726. "t if FILE is owned by me."
  1727. (eq (user-uid) (nth 2 (file-attributes file))))
  1728. "http://www.bookshelf.jp/pukiwiki/pukiwiki.php\
  1729. ?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9"
  1730. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1731. ;; (defun eshell/less (&rest args)
  1732. ;; "Invoke `view-file' on the file.
  1733. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1734. ;; (if args
  1735. ;; (while args
  1736. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1737. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1738. ;; (file (pop args)))
  1739. ;; (view-file file)
  1740. ;; (goto-line line))
  1741. ;; (view-file (pop args))))))
  1742. (defun eshell/o (&optional file)
  1743. (my-x-open (or file ".")))
  1744. ;; (defun eshell/vi (&rest args)
  1745. ;; "Invoke `find-file' on the file.
  1746. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1747. ;; (while args
  1748. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1749. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1750. ;; (file (pop args)))
  1751. ;; (find-file file)
  1752. ;; (goto-line line))
  1753. ;; (find-file (pop args)))))
  1754. (defun eshell/clear ()
  1755. "Clear the current buffer, leaving one prompt at the top."
  1756. (interactive)
  1757. (let ((inhibit-read-only t))
  1758. (erase-buffer)))
  1759. (defun eshell-clear ()
  1760. (interactive)
  1761. (let ((inhibit-read-only t))
  1762. (erase-buffer)
  1763. (insert (funcall eshell-prompt-function))))
  1764. (defun eshell/d (&optional dirname switches)
  1765. "if first arg is omitted open current directory."
  1766. (dired (or dirname ".") switches))
  1767. (defun eshell/v ()
  1768. (view-mode 1))
  1769. ;; (defun eshell/aaa (&rest args)
  1770. ;; (message "%S"
  1771. ;; args))
  1772. (defalias 'eshell/: 'ignore)
  1773. (defalias 'eshell/type 'eshell/which)
  1774. ;; (defalias 'eshell/vim 'eshell/vi)
  1775. (defalias 'eshell/ff 'find-file)
  1776. (defalias 'eshell/q 'eshell/exit)
  1777. (defun eshell-goto-prompt ()
  1778. ""
  1779. (interactive)
  1780. (goto-char (point-max)))
  1781. (defun eshell-delete-char-or-logout (n)
  1782. (interactive "p")
  1783. (if (equal (eshell-get-old-input)
  1784. "")
  1785. (progn
  1786. (insert "exit")
  1787. (eshell-send-input))
  1788. (delete-char n)))
  1789. (defun eshell-kill-input ()
  1790. (interactive)
  1791. (delete-region (point)
  1792. (progn (eshell-bol)
  1793. (point))))
  1794. (defalias 'eshell/logout 'eshell/exit)
  1795. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1796. "open eshell and change wd
  1797. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1798. (interactive)
  1799. (let ((dir (expand-file-name default-directory)))
  1800. (switch-to-buffer (or eshell-buffer-or-name
  1801. (eshell t)))
  1802. (unless (equal dir (expand-file-name default-directory))
  1803. ;; (cd dir)
  1804. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1805. ;; (eshell-emit-prompt)
  1806. (goto-char (point-max))
  1807. (eshell-kill-input)
  1808. (insert "cd " dir)
  1809. (eshell-send-input))))
  1810. (defadvice eshell-next-matching-input-from-input
  1811. ;; do not cycle history
  1812. (around eshell-history-do-not-cycle activate)
  1813. (if (= 0
  1814. (or eshell-history-index
  1815. 0))
  1816. (progn
  1817. (delete-region eshell-last-output-end (point))
  1818. (insert-and-inherit eshell-matching-input-from-input-string)
  1819. (setq eshell-history-index nil))
  1820. ad-do-it))
  1821. (set-variable 'eshell-directory-name (concat user-emacs-directory
  1822. "eshell/"))
  1823. (set-variable 'eshell-term-name "eterm-color")
  1824. (set-variable 'eshell-scroll-to-bottom-on-input t)
  1825. (set-variable 'eshell-cmpl-ignore-case t)
  1826. (set-variable 'eshell-cmpl-cycle-completions nil)
  1827. (set-variable 'eshell-highlight-prompt nil)
  1828. (if (eq system-type 'darwin)
  1829. (set-variable 'eshell-ls-initial-args '("-hCFG")
  1830. (set-variable 'eshell-ls-initial-args '("-hCFG"
  1831. "--color=auto"
  1832. "--time-style=long-iso")) ; "-hF")
  1833. ))
  1834. (set-variable 'eshell-prompt-function
  1835. 'my-eshell-prompt-function)
  1836. (defvar eshell-last-command-status)
  1837. (defun my-eshell-prompt-function()
  1838. "Prompt function.
  1839. It looks like:
  1840. :: [10sr@darwin:~/][ESHELL]
  1841. :: $
  1842. "
  1843. (concat ":: ["
  1844. (let ((str (concat user-login-name
  1845. "@"
  1846. (car (split-string system-name
  1847. "\\."))
  1848. )))
  1849. (put-text-property 0
  1850. (length str)
  1851. 'face
  1852. 'underline
  1853. str)
  1854. str)
  1855. ":"
  1856. (let ((str (abbreviate-file-name default-directory)))
  1857. (put-text-property 0
  1858. (length str)
  1859. 'face
  1860. 'underline
  1861. str)
  1862. str)
  1863. "][ESHELL]\n:: "
  1864. (if (eq 0
  1865. eshell-last-command-status)
  1866. ""
  1867. (format "[STATUS:%d] "
  1868. eshell-last-command-status))
  1869. (if (= (user-uid)
  1870. 0)
  1871. "# "
  1872. "$ ")
  1873. ))
  1874. (add-hook 'eshell-mode-hook
  1875. (lambda ()
  1876. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1877. ;; (interactive)
  1878. ;; (switch-to-buffer (other-buffer))))
  1879. ;; (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1880. ;; (interactive)
  1881. ;; (eshell-goto-prompt)
  1882. ;; (keyboard-quit)))
  1883. (local-set-key (kbd "C-x t") 'eshell-text-mode-toggle)
  1884. (local-set-key (kbd "C-u") 'eshell-kill-input)
  1885. (local-set-key (kbd "C-d") 'eshell-delete-char-or-logout)
  1886. ;; (define-key eshell-mode-map (kbd "C-l")
  1887. ;; 'eshell-clear)
  1888. (local-set-key (kbd "DEL") 'my-eshell-backward-delete-char)
  1889. (local-set-key (kbd "<up>") 'scroll-down-line)
  1890. (local-set-key (kbd "<down>") 'scroll-up-line)
  1891. ;; (define-key eshell-mode-map
  1892. ;; (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1893. ;; (define-key eshell-mode-map
  1894. ;; (kbd "C-n") 'eshell-next-matching-input-from-input)
  1895. (apply 'eshell/addpath exec-path)
  1896. (set (make-local-variable 'scroll-margin) 0)
  1897. ;; (eshell/export "GIT_PAGER=")
  1898. ;; (eshell/export "GIT_EDITOR=")
  1899. (eshell/export "LC_MESSAGES=C")
  1900. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1901. (set (make-local-variable (defvar hl-line-range-function))
  1902. (lambda ()
  1903. '(0 . 0)))
  1904. (defvar eshell-virtual-targets)
  1905. (add-to-list 'eshell-virtual-targets
  1906. '("/dev/less"
  1907. (lambda (str)
  1908. (if str
  1909. (with-current-buffer nil)))
  1910. nil))
  1911. ))
  1912. (add-hook 'eshell-mode-hook
  1913. (lambda ()
  1914. (defvar eshell-visual-commands)
  1915. (defvar eshell-output-filter-functions)
  1916. (defvar eshell-command-aliases-list)
  1917. (add-to-list 'eshell-visual-commands "vim")
  1918. ;; (add-to-list 'eshell-visual-commands "git")
  1919. (add-to-list 'eshell-output-filter-functions
  1920. 'eshell-truncate-buffer)
  1921. (mapcar (lambda (alias)
  1922. (add-to-list 'eshell-command-aliases-list
  1923. alias))
  1924. '(
  1925. ;; ("ll" "ls -l $*")
  1926. ;; ("la" "ls -a $*")
  1927. ;; ("lla" "ls -al $*")
  1928. ("git" "git -c color.ui=always $*")
  1929. ("g" "git $*")
  1930. ("eless"
  1931. (concat "cat >>> (with-current-buffer "
  1932. "(get-buffer-create \"*eshell output\") "
  1933. "(erase-buffer) "
  1934. "(setq buffer-read-only nil) "
  1935. "(current-buffer)) "
  1936. "(view-buffer (get-buffer \"*eshell output*\"))"))
  1937. )
  1938. )))
  1939. ) ; eval after load eshell
  1940. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1941. ;; my-term
  1942. (defvar my-term nil
  1943. "My terminal buffer.")
  1944. (defvar my-term-function nil
  1945. "Function to create terminal buffer.
  1946. This function accept no argument and return newly created buffer of terminal.")
  1947. (defun my-term (&optional arg)
  1948. "Open terminal buffer and return that buffer.
  1949. If ARG is given or called with prefix argument, create new buffer."
  1950. (interactive "P")
  1951. (if (and (not arg)
  1952. my-term
  1953. (buffer-name my-term))
  1954. (pop-to-buffer my-term)
  1955. (setq my-term
  1956. (save-window-excursion
  1957. (funcall my-term-function)))
  1958. (and my-term
  1959. (my-term))))
  1960. ;; (setq my-term-function
  1961. ;; (lambda ()
  1962. ;; (if (eq system-type 'windows-nt)
  1963. ;; (eshell)
  1964. ;; (if (require 'multi-term nil t)
  1965. ;; (multi-term)
  1966. ;; (ansi-term shell-file-name)))))
  1967. (setq my-term-function (lambda () (eshell t)))
  1968. ;;(define-key my-prefix-map (kbd "C-s") 'my-term)
  1969. (define-key ctl-x-map "i" 'my-term)
  1970. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1971. ;; x open
  1972. (defvar my-filer nil)
  1973. (setq my-filer (or (executable-find "pcmanfm")
  1974. (executable-find "nautilus")))
  1975. (defun my-x-open (file)
  1976. "Open FILE."
  1977. (interactive "FOpen File: ")
  1978. (setq file (expand-file-name file))
  1979. (message "Opening %s..." file)
  1980. (cond ((eq system-type 'windows-nt)
  1981. (call-process "cmd.exe" nil 0 nil
  1982. "/c" "start" "" (convert-standard-filename file)))
  1983. ((eq system-type 'darwin)
  1984. (call-process "open" nil 0 nil file))
  1985. ((getenv "DISPLAY")
  1986. (call-process (or my-filer "xdg-open") nil 0 nil file))
  1987. (t
  1988. (find-file file))
  1989. )
  1990. ;; (recentf-add-file file)
  1991. (message "Opening %s...done" file))
  1992. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1993. ;; misc funcs
  1994. (defun my-git-apply-index-from-buffer (&optional buf)
  1995. "Git apply buffer. BUF is buffer to apply. nil to use current buffer."
  1996. (interactive)
  1997. (let ((buf (or buf
  1998. (current-buffer)))
  1999. (file (make-temp-file "git-apply-diff.emacs")))
  2000. (with-current-buffer buf
  2001. (write-region (point-min)
  2002. (point-max)
  2003. file)
  2004. (call-process "git"
  2005. nil
  2006. nil
  2007. nil
  2008. "apply"
  2009. "--cached"
  2010. file))))
  2011. (defun memo (&optional dir)
  2012. "Open memo.txt in DIR."
  2013. (interactive)
  2014. (pop-to-buffer (find-file-noselect (concat (if dir
  2015. (file-name-as-directory dir)
  2016. "")
  2017. "memo.txt"))))
  2018. (defvar my-rgrep-alist
  2019. `(
  2020. ;; the silver searcher
  2021. ("ag"
  2022. (executable-find "ag")
  2023. "ag --nocolor --nogroup --nopager --filename ")
  2024. ;; ack
  2025. ("ack"
  2026. (executable-find "ack")
  2027. "ack --nocolor --nogroup --nopager --with-filename ")
  2028. ;; gnu global
  2029. ("global"
  2030. (and (require 'gtags nil t)
  2031. (executable-find "global")
  2032. (gtags-get-rootpath))
  2033. "global --result grep ")
  2034. ;; git grep
  2035. ("gitgrep"
  2036. (eq 0
  2037. (shell-command "git rev-parse --git-dir"))
  2038. "git --no-pager -c color.grep=false grep -nH -e ")
  2039. ;; grep
  2040. ("grep"
  2041. t
  2042. ,(concat "find . "
  2043. "-path '*/.git' -prune -o "
  2044. "-path '*/.svn' -prune -o "
  2045. "-type f -print0 | "
  2046. "xargs -0 grep -nH -e "))
  2047. )
  2048. "Alist of rgrep command.
  2049. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  2050. condition to choose COMMAND when evaluated.")
  2051. (defvar my-rgrep-default nil
  2052. "Default command name for my-rgrep.")
  2053. (defun my-rgrep-grep-command (&optional name alist)
  2054. "Return recursive grep command for current directory or nil.
  2055. If NAME is given, use that without testing.
  2056. Commands are searched from ALIST."
  2057. (if alist
  2058. (if name
  2059. ;; if name is given search that from alist and return the command
  2060. (nth 2 (assoc name
  2061. alist))
  2062. ;; if name is not given try test in 1th elem
  2063. (let ((car (car alist))
  2064. (cdr (cdr alist)))
  2065. (if (eval (nth 1 car))
  2066. ;; if the condition is true return the command
  2067. (nth 2 car)
  2068. ;; try next one
  2069. (and cdr
  2070. (my-rgrep-grep-command name cdr)))))
  2071. ;; if alist is not given set default value
  2072. (my-rgrep-grep-command name my-rgrep-alist)))
  2073. (defun my-rgrep (command-args)
  2074. "My recursive grep. Run COMMAND-ARGS."
  2075. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  2076. nil)))
  2077. (if cmd
  2078. (list (read-shell-command "grep command: "
  2079. cmd
  2080. 'grep-find-history))
  2081. (error "My-Rgrep: Command for rgrep not found")
  2082. )))
  2083. (compilation-start command-args
  2084. 'grep-mode))
  2085. ;; (defun my-rgrep-symbol-at-point (command-args)
  2086. ;; "My recursive grep. Run COMMAND-ARGS."
  2087. ;; (interactive (list (read-shell-command "grep command: "
  2088. ;; (concat (my-rgrep-grep-command)
  2089. ;; " "
  2090. ;; (thing-at-point 'symbol))
  2091. ;; 'grep-find-history)))
  2092. ;; (compilation-start command-args
  2093. ;; 'grep-mode))
  2094. (defmacro define-my-rgrep (name)
  2095. "Define rgrep for NAME."
  2096. `(defun ,(intern (concat "my-rgrep-"
  2097. name)) ()
  2098. ,(format "My recursive grep by %s."
  2099. name)
  2100. (interactive)
  2101. (let ((my-rgrep-default ,name))
  2102. (if (called-interactively-p 'any)
  2103. (call-interactively 'my-rgrep)
  2104. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2105. )
  2106. (define-my-rgrep "ack")
  2107. (define-my-rgrep "ag")
  2108. (define-my-rgrep "gitgrep")
  2109. (define-my-rgrep "grep")
  2110. (define-my-rgrep "global")
  2111. (define-key ctl-x-map "s" 'my-rgrep)
  2112. ;; (defun make ()
  2113. ;; "Run \"make -k\" in current directory."
  2114. ;; (interactive)
  2115. ;; (compile "make -k"))
  2116. (defalias 'make 'compile)
  2117. (define-key ctl-x-map "c" 'compile)
  2118. (defvar sed-in-place-history nil
  2119. "History of `sed-in-place'.")
  2120. (defvar sed-in-place-command "sed --in-place=.bak -e")
  2121. (defun sed-in-place (command)
  2122. "Issue sed in place COMMAND."
  2123. (interactive (list (read-shell-command "sed in place: "
  2124. (concat sed-in-place-command " ")
  2125. 'sed-in-place-history)))
  2126. (shell-command command
  2127. "*sed in place*"))
  2128. (defun dired-do-sed-in-place (&optional arg)
  2129. "Issue sed in place dired. If ARG is given, use the next ARG files."
  2130. (interactive "p")
  2131. (require 'dired-aux)
  2132. (let* ((files (dired-get-marked-files t arg))
  2133. (expr (dired-mark-read-string "Run sed-in-place for %s: "
  2134. nil
  2135. 'sed-in-place
  2136. arg
  2137. files)))
  2138. (if (equal expr
  2139. "")
  2140. (error "No expression specified")
  2141. (shell-command (concat sed-in-place-command
  2142. " '"
  2143. expr
  2144. "' "
  2145. (mapconcat 'shell-quote-argument
  2146. files
  2147. " "))
  2148. "*sed in place*"))))
  2149. (defun dir-show (&optional dir)
  2150. "Show DIR list."
  2151. (interactive)
  2152. (let ((bf (get-buffer-create "*dir show*"))
  2153. (list-directory-brief-switches "-C"))
  2154. (with-current-buffer bf
  2155. (list-directory (or nil
  2156. default-directory)
  2157. nil))
  2158. ))
  2159. (defun my-convmv-sjis2utf8-test ()
  2160. "Run `convmv -r -f sjis -t utf8 *'.
  2161. this is test, does not rename files."
  2162. (interactive)
  2163. (shell-command "convmv -r -f sjis -t utf8 *"))
  2164. (defun my-convmv-sjis2utf8-notest ()
  2165. "Run `convmv -r -f sjis -t utf8 * --notest'."
  2166. (interactive)
  2167. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  2168. (defun kill-ring-save-buffer-file-name ()
  2169. "Get current filename."
  2170. (interactive)
  2171. (let ((file buffer-file-name))
  2172. (if file
  2173. (progn (kill-new file)
  2174. (message file))
  2175. (message "not visiting file."))))
  2176. (defvar kill-ring-buffer-name "*kill-ring*"
  2177. "Buffer name for `kill-ring-buffer'.")
  2178. (defun open-kill-ring-buffer ()
  2179. "Open kill- ring buffer."
  2180. (interactive)
  2181. (pop-to-buffer
  2182. (with-current-buffer (get-buffer-create kill-ring-buffer-name)
  2183. (erase-buffer)
  2184. (yank)
  2185. (text-mode)
  2186. (current-local-map)
  2187. (goto-char (point-min))
  2188. (yank)
  2189. (current-buffer))))
  2190. (defun set-terminal-header (string)
  2191. "Set terminal header STRING."
  2192. (let ((savepos "\033[s")
  2193. (restorepos "\033[u")
  2194. (movecursor "\033[0;%dH")
  2195. (inverse "\033[7m")
  2196. (restorecolor "\033[0m")
  2197. (cols (frame-parameter nil 'width))
  2198. (length (length string)))
  2199. ;; (redraw-frame (selected-frame))
  2200. (send-string-to-terminal (concat savepos
  2201. (format movecursor
  2202. (1+ (- cols length)))
  2203. inverse
  2204. string
  2205. restorecolor
  2206. restorepos))
  2207. ))
  2208. (defun my-set-terminal-header ()
  2209. "Set terminal header."
  2210. (set-terminal-header (concat " "
  2211. user-login-name
  2212. "@"
  2213. (car (split-string system-name
  2214. "\\."))
  2215. " "
  2216. (format-time-string "%Y/%m/%d %T %z")
  2217. " ")))
  2218. ;; (run-with-timer
  2219. ;; 0.1
  2220. ;; 1
  2221. ;; 'my-set-terminal-header)
  2222. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2223. ;; ;; savage emacs
  2224. ;; ;; when enabled emacs fails to complete
  2225. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  2226. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  2227. ;; (setq arg
  2228. ;; (concat arg
  2229. ;; (if (eq nil
  2230. ;; (string-match "\\. *$"
  2231. ;; arg))
  2232. ;; ".")
  2233. ;; " Stupid!")))
  2234. ;; TODO: make these a library
  2235. (defvar info-in-prompt
  2236. nil
  2237. "System info in the form of \"[user@host] \".")
  2238. (setq info-in-prompt
  2239. (concat "["
  2240. user-login-name
  2241. "@"
  2242. (car (split-string system-name
  2243. "\\."))
  2244. "]"))
  2245. (defun my-real-function-subr-p (function)
  2246. "Return t if FUNCTION is a built-in function even if it is advised."
  2247. (let* ((advised (and (symbolp function)
  2248. (featurep 'advice)
  2249. (ad-get-advice-info function)))
  2250. (real-function
  2251. (or (and advised (let ((origname (cdr (assq 'origname advised))))
  2252. (and (fboundp origname)
  2253. origname)))
  2254. function))
  2255. (def (if (symbolp real-function)
  2256. (symbol-function real-function)
  2257. function)))
  2258. (subrp def)))
  2259. ;; (my-real-function-subr-p 'my-real-function-subr-p)
  2260. ;; (defadvice read-from-minibuffer (before info-in-prompt activate)
  2261. ;; "Show system info when use `read-from-minibuffer'."
  2262. ;; (ad-set-arg 0
  2263. ;; (concat my-system-info
  2264. ;; (ad-get-arg 0))))
  2265. ;; (defadvice read-string (before info-in-prompt activate)
  2266. ;; "Show system info when use `read-string'."
  2267. ;; (ad-set-arg 0
  2268. ;; (concat my-system-info
  2269. ;; (ad-get-arg 0))))
  2270. ;; (when (< emacs-major-version 24)
  2271. ;; (defadvice completing-read (before info-in-prompt activate)
  2272. ;; "Show system info when use `completing-read'."
  2273. ;; (ad-set-arg 0
  2274. ;; (concat my-system-info
  2275. ;; (ad-get-arg 0)))))
  2276. (defmacro info-in-prompt-set (&rest functions)
  2277. "Set info-in-prompt advices for FUNCTIONS."
  2278. `(progn
  2279. ,@(mapcar (lambda (f)
  2280. `(defadvice ,f (before info-in-prompt activate)
  2281. "Show info in prompt."
  2282. (let ((orig (ad-get-arg 0)))
  2283. (unless (string-match-p (regexp-quote info-in-prompt)
  2284. orig)
  2285. (ad-set-arg 0
  2286. (concat info-in-prompt
  2287. " "
  2288. orig))))))
  2289. functions)))
  2290. (info-in-prompt-set read-from-minibuffer
  2291. read-string
  2292. completing-read)
  2293. ;;; emacs.el ends here