Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

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