選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

emacs.el 61 KiB

11年前
11年前
11年前
13年前
12年前
11年前
13年前
10年前
12年前
12年前
12年前
12年前
12年前
12年前
12年前
12年前
12年前
12年前
12年前
12年前
12年前
11年前
11年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818
  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. (setq debug-on-error t)
  8. ;; make directories
  9. (unless (file-directory-p (expand-file-name user-emacs-directory))
  10. (make-directory (expand-file-name user-emacs-directory)))
  11. (let ((d (expand-file-name (concat user-emacs-directory
  12. "lisp"))))
  13. (unless (file-directory-p d)
  14. (make-directory d))
  15. (add-to-list 'load-path d))
  16. (require 'cl-lib)
  17. (require 'simple)
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19. ;; Some macros for internals
  20. ;; `emacs --load emacs.el` with Emacs 24.3 requires with-eval-after-load to be
  21. ;; defined at the toplevel (means that it should not be defined inside of some
  22. ;; special forms like `when'. I do not now how to do with about this...)
  23. (unless (fboundp 'with-eval-after-load)
  24. ;; polyfill for Emacs < 24.4
  25. (defmacro with-eval-after-load (file &rest body)
  26. "After FILE is loaded execute BODY."
  27. (declare (indent 1) (debug t))
  28. `(eval-after-load ,file (quote (progn ,@body)))))
  29. (defun call-after-init (func)
  30. "If `after-init-hook' has been run, call FUNC immediately.
  31. Otherwize hook it."
  32. (if after-init-time
  33. (funcall func)
  34. (add-hook 'after-init-hook
  35. func)))
  36. (defmacro safe-require-or-eval (feature)
  37. "Require FEATURE if available.
  38. At compile time the feature will be loaded immediately."
  39. `(eval-and-compile
  40. (message "safe-require-or-eval: Trying to require %s" ,feature)
  41. (require ,feature nil t)))
  42. (defmacro autoload-eval-lazily (feature &optional functions &rest body)
  43. "Define autoloading FEATURE that defines FUNCTIONS.
  44. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  45. the function same as FEATURE is defined as autoloaded function. BODY is passed
  46. to `eval-after-load'.
  47. After this macro is expanded, this returns the path to library if FEATURE
  48. found, otherwise returns nil."
  49. (declare (indent 2) (debug t))
  50. (let* ((libname (symbol-name (eval feature)))
  51. (libpath (locate-library libname)))
  52. `(progn
  53. (when (locate-library ,libname)
  54. ,@(mapcar (lambda (f)
  55. `(unless (fboundp ',f)
  56. (progn
  57. (message "Autoloaded function `%S' defined (%s)"
  58. (quote ,f)
  59. ,libpath)
  60. (autoload (quote ,f)
  61. ,libname
  62. ,(concat "Autoloaded function defined in \""
  63. libpath
  64. "\".")
  65. t))))
  66. (or (eval functions)
  67. `(,(eval feature)))))
  68. (eval-after-load ,feature
  69. (quote (progn
  70. ,@body)))
  71. (locate-library ,libname))))
  72. (when (autoload-eval-lazily 'tetris nil
  73. (message "Tetris loaded!"))
  74. (message "Tetris found!"))
  75. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  76. ;; package
  77. (set (defvar 10sr-package-list)
  78. '(
  79. markdown-mode
  80. yaml-mode
  81. gnuplot-mode
  82. php-mode
  83. erlang
  84. js2-mode
  85. js-doc
  86. git-commit
  87. gitignore-mode
  88. adoc-mode
  89. malabar-mode
  90. ;; ack
  91. color-moccur
  92. ggtags
  93. flycheck
  94. auto-highlight-symbol
  95. ;; is flymake installs are required?
  96. ;;flymake-jshint
  97. ;;flymake-python-pyflakes
  98. xclip
  99. foreign-regexp
  100. multi-term
  101. term-run
  102. editorconfig
  103. git-ps1-mode
  104. restart-emacs
  105. fill-column-indicator
  106. pkgbuild-mode
  107. minibuffer-line
  108. scala-mode
  109. ensime
  110. editorconfig
  111. cyberpunk-theme
  112. grandshell-theme
  113. afternoon-theme
  114. git-command
  115. prompt-text
  116. ;; 10sr repository
  117. ;; 10sr-extras
  118. terminal-title
  119. recentf-show
  120. dired-list-all-mode
  121. pack
  122. set-modeline-color
  123. read-only-only-mode
  124. smart-revert
  125. autosave
  126. ;;window-organizer
  127. remember-major-modes-mode
  128. ilookup
  129. pasteboard
  130. end-mark
  131. sl
  132. gosh-mode
  133. ))
  134. (when (safe-require-or-eval 'package)
  135. (setq package-archives
  136. `(,@package-archives
  137. ("melpa" . "https://melpa.org/packages/")
  138. ("10sr-el" . "https://10sr.github.io/emacs-lisp/p/")))
  139. (package-initialize)
  140. (defun my-auto-install-package ()
  141. "Install packages semi-automatically."
  142. (interactive)
  143. (package-refresh-contents)
  144. (mapc (lambda (pkg)
  145. (or (package-installed-p pkg)
  146. (locate-library (symbol-name pkg))
  147. (package-install pkg)))
  148. 10sr-package-list))
  149. )
  150. ;; (lazy-load-eval 'sudoku)
  151. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  152. ;; my-idle-hook
  153. (defvar my-idle-hook nil
  154. "Hook run when idle for several secs.")
  155. (defvar my-idle-hook-sec 5
  156. "Second to run `my-idle-hook'.")
  157. (run-with-idle-timer my-idle-hook-sec
  158. t
  159. (lambda ()
  160. (run-hooks 'my-idle-hook)))
  161. ;; (add-hook 'my-idle-hook
  162. ;; (lambda ()
  163. ;; (message "idle hook message")))
  164. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  165. ;; start and quit
  166. (setq inhibit-startup-message t)
  167. (setq confirm-kill-emacs 'y-or-n-p)
  168. (setq gc-cons-threshold (* 1024 1024 4))
  169. (when window-system
  170. (add-to-list 'default-frame-alist '(cursor-type . box))
  171. (add-to-list 'default-frame-alist '(background-color . "white"))
  172. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  173. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  174. ;; does not work?
  175. )
  176. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  177. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  178. (and (fboundp 'tool-bar-mode)
  179. (tool-bar-mode 0))
  180. (and (fboundp 'set-scroll-bar-mode)
  181. (set-scroll-bar-mode nil))
  182. (add-hook 'kill-emacs-hook
  183. ;; load init file when terminating emacs to ensure file is not broken
  184. 'reload-init-file)
  185. (defun my-force-kill-emacs ()
  186. "My force kill Emacs."
  187. (interactive)
  188. (let ((kill-emacs-hook nil))
  189. (kill-emacs)))
  190. (call-after-init
  191. (lambda ()
  192. (message "%s %s" invocation-name emacs-version)
  193. (message "Invocation directory: %s" default-directory)
  194. (message "%s was taken to initialize emacs." (emacs-init-time))
  195. (switch-to-buffer "*Messages*")))
  196. (cd ".") ; when using windows use / instead of \ in `default-directory'
  197. ;; locale
  198. (set-language-environment "Japanese")
  199. (set-default-coding-systems 'utf-8-unix)
  200. (prefer-coding-system 'utf-8-unix)
  201. (setq system-time-locale "C")
  202. ;; my prefix map
  203. (defvar my-prefix-map nil
  204. "My prefix map.")
  205. (define-prefix-command 'my-prefix-map)
  206. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  207. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  208. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  209. ;; (comint-show-maximum-output)
  210. ;; kill scratch
  211. (call-after-init (lambda ()
  212. (let ((buf (get-buffer "*scratch*")))
  213. (when buf
  214. (kill-buffer buf)))))
  215. ;; modifier keys
  216. ;; (setq mac-option-modifier 'control)
  217. ;; display
  218. (setq visible-bell t)
  219. (setq ring-bell-function 'ignore)
  220. (mouse-avoidance-mode 'banish)
  221. (setq echo-keystrokes 0.1)
  222. (defun reload-init-file ()
  223. "Reload Emacs init file."
  224. (interactive)
  225. (when (and user-init-file
  226. (file-readable-p user-init-file))
  227. (load-file user-init-file)))
  228. (safe-require-or-eval 'session)
  229. ;; server
  230. (set-variable 'server-name (concat "server"
  231. (number-to-string (emacs-pid))))
  232. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  233. ;; In Darwin environment, init fails with message like 'Service name too long'
  234. ;; when server-use-tcp is nil
  235. (when (or (eq system-type
  236. 'cygwin)
  237. (eq system-type
  238. 'darwin))
  239. (set-variable 'server-use-tcp t))
  240. ;; MSYS2 fix
  241. (when (eq system-type
  242. 'windows-nt)
  243. (setq shell-file-name
  244. (executable-find "bash"))
  245. '(setq function-key-map
  246. `(,@function-key-map ([pause] . [?\C-c])
  247. ))
  248. (define-key key-translation-map
  249. (kbd "<pause>")
  250. (kbd "C-c"))
  251. '(keyboard-translate [pause]
  252. (kbd "C-c")p)
  253. ;; TODO: move to other place later
  254. (when (not window-system)
  255. (setq interprogram-paste-function nil)
  256. (setq interprogram-cut-function nil)))
  257. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  258. ;; global keys
  259. (global-set-key (kbd "<up>") 'scroll-down-line)
  260. (global-set-key (kbd "<down>") 'scroll-up-line)
  261. (global-set-key (kbd "<left>") 'scroll-down)
  262. (global-set-key (kbd "<right>") 'scroll-up)
  263. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  264. (global-set-key (kbd "C-\\") help-map)
  265. (define-key ctl-x-map (kbd "DEL") help-map)
  266. (define-key ctl-x-map (kbd "C-h") help-map)
  267. (define-key help-map "a" 'apropos)
  268. ;; disable annoying keys
  269. (global-set-key [prior] 'ignore)
  270. (global-set-key (kbd "<next>") 'ignore)
  271. (global-set-key [menu] 'ignore)
  272. (global-set-key [down-mouse-1] 'ignore)
  273. (global-set-key [down-mouse-2] 'ignore)
  274. (global-set-key [down-mouse-3] 'ignore)
  275. (global-set-key [mouse-1] 'ignore)
  276. (global-set-key [mouse-2] 'ignore)
  277. (global-set-key [mouse-3] 'ignore)
  278. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  279. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  280. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  281. ;; editting
  282. (defun my-copy-whole-line ()
  283. "Copy whole line."
  284. (interactive)
  285. (kill-new (concat (buffer-substring (point-at-bol)
  286. (point-at-eol))
  287. "\n")))
  288. (setq require-final-newline t)
  289. (setq kill-whole-line t)
  290. (setq scroll-conservatively 35
  291. scroll-margin 2
  292. scroll-step 0)
  293. (setq-default major-mode 'text-mode)
  294. (setq next-line-add-newlines nil)
  295. (setq kill-read-only-ok t)
  296. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  297. ;; (setq-default line-spacing 0.2)
  298. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  299. (setq-default tab-width 4)
  300. (setq-default indent-tabs-mode nil)
  301. (setq-default indent-line-function nil)
  302. (setq-default truncate-lines nil)
  303. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  304. (delete-selection-mode 1)
  305. (cua-mode 0)
  306. (setq line-move-visual nil)
  307. ;; key bindings
  308. ;; moving around
  309. ;; (global-set-key (kbd "M-j") 'next-line)
  310. ;; (global-set-key (kbd "M-k") 'previous-line)
  311. ;; (global-set-key (kbd "M-h") 'backward-char)
  312. ;; (global-set-key (kbd "M-l") 'forward-char)
  313. ;;(keyboard-translate ?\M-j ?\C-j)
  314. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  315. (define-key esc-map "p" 'backward-paragraph)
  316. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  317. (define-key esc-map "n" 'forward-paragraph)
  318. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  319. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  320. (global-set-key (kbd "C-<left>") 'scroll-down)
  321. (global-set-key (kbd "C-<right>") 'scroll-up)
  322. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  323. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  324. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  325. ;; C-h and DEL
  326. (global-set-key (kbd "C-h") (kbd "DEL"))
  327. (global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  328. (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  329. (define-key esc-map "k" 'my-copy-whole-line)
  330. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  331. (define-key esc-map "u" 'undo)
  332. (define-key esc-map "i" (kbd "ESC TAB"))
  333. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  334. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  335. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  336. (define-key my-prefix-map (kbd "C-o") 'occur)
  337. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  338. ;; title and mode-line
  339. (when (safe-require-or-eval 'terminal-title)
  340. ;; if TERM is not screen use default value
  341. (if (getenv "TMUX")
  342. ;; if use tmux locally just basename of current dir
  343. (set-variable 'terminal-title-format
  344. '((file-name-nondirectory (directory-file-name
  345. default-directory))))
  346. (if (and (let ((tty-type (frame-parameter nil
  347. 'tty-type)))
  348. (and tty-type
  349. (equal (car (split-string tty-type
  350. "-"))
  351. "screen")))
  352. (not (getenv "SSH_CONNECTION")))
  353. (set-variable 'terminal-title-format
  354. '((file-name-nondirectory (directory-file-name
  355. default-directory))))
  356. ;; seems that TMUX is used locally and ssh to remote host
  357. (set-variable 'terminal-title-format
  358. `("em:"
  359. ,user-login-name
  360. "@"
  361. ,(car (split-string system-name
  362. "\\."))
  363. ":"
  364. default-directory))
  365. )
  366. )
  367. (terminal-title-mode))
  368. (setq eol-mnemonic-dos "\\r\\n")
  369. (setq eol-mnemonic-mac "\\r")
  370. (setq eol-mnemonic-unix "\\n")
  371. (which-function-mode 0)
  372. (line-number-mode 0)
  373. (column-number-mode 0)
  374. (size-indication-mode 0)
  375. (setq mode-line-position
  376. '(:eval (format "L%%l/%d,C%%c"
  377. (count-lines (point-max)
  378. (point-min)))))
  379. (when (safe-require-or-eval 'git-ps1-mode)
  380. (git-ps1-mode))
  381. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  382. ;; display date
  383. (when (safe-require-or-eval 'time)
  384. (setq display-time-interval 29)
  385. (setq display-time-day-and-date t)
  386. (setq display-time-format "%Y/%m/%d %a %H:%M")
  387. ;; (if window-system
  388. ;; (display-time-mode 0)
  389. ;; (display-time-mode 1))
  390. (when display-time-mode
  391. (display-time-update)))
  392. ;; ;; current directory
  393. ;; (let ((ls (member 'mode-line-buffer-identification
  394. ;; mode-line-format)))
  395. ;; (setcdr ls
  396. ;; (cons '(:eval (concat " ("
  397. ;; (abbreviate-file-name default-directory)
  398. ;; ")"))
  399. ;; (cdr ls))))
  400. ;; ;; display last modified time
  401. ;; (let ((ls (member 'mode-line-buffer-identification
  402. ;; mode-line-format)))
  403. ;; (setcdr ls
  404. ;; (cons '(:eval (concat " "
  405. ;; my-buffer-file-last-modified-time))
  406. ;; (cdr ls))))
  407. (defun buffer-list-not-start-with-space ()
  408. "Return a list of buffers that not start with whitespaces."
  409. (let ((bl (buffer-list))
  410. b nbl)
  411. (while bl
  412. (setq b (pop bl))
  413. (unless (string-equal " "
  414. (substring (buffer-name b)
  415. 0
  416. 1))
  417. (add-to-list 'nbl b)))
  418. nbl))
  419. ;; http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/
  420. ;; (add-to-list 'minor-mode-alist
  421. ;; '(global-whitespace-mode ""))
  422. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  423. ;; minibuffer
  424. (setq insert-default-directory t)
  425. (setq completion-ignore-case t
  426. read-file-name-completion-ignore-case t
  427. read-buffer-completion-ignore-case t)
  428. (setq resize-mini-windows t)
  429. (temp-buffer-resize-mode 1)
  430. (savehist-mode 1)
  431. (fset 'yes-or-no-p 'y-or-n-p)
  432. ;; complete symbol when `eval'
  433. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  434. (define-key minibuffer-local-map (kbd "C-u")
  435. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  436. ;; I dont know these bindings are good
  437. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  438. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  439. (when (safe-require-or-eval 'minibuffer-line)
  440. (set-face-underline 'minibuffer-line nil)
  441. (set-variable 'minibuffer-line-refresh-interval
  442. 25)
  443. (set-variable 'minibuffer-line-format
  444. `(,(concat user-login-name
  445. "@"
  446. (car (split-string system-name
  447. "\\."))
  448. ":")
  449. (:eval (abbreviate-file-name (or buffer-file-name
  450. default-directory)))
  451. (:eval (and (fboundp 'git-ps1-mode-get-current)
  452. (git-ps1-mode-get-current " [GIT:%s]")))
  453. " "
  454. (:eval (format-time-string display-time-format))))
  455. (minibuffer-line-mode 1)
  456. )
  457. (when (safe-require-or-eval 'prompt-text)
  458. (set-variable 'prompt-text-format
  459. `(,(concat ""
  460. user-login-name
  461. "@"
  462. (car (split-string system-name
  463. "\\."))
  464. ":")
  465. (:eval (abbreviate-file-name (or buffer-file-name
  466. default-directory)))
  467. (:eval (and (fboundp 'git-ps1-mode-get-current)
  468. (git-ps1-mode-get-current " [GIT:%s]")))
  469. " "
  470. (:eval (format-time-string display-time-format))
  471. "\n"
  472. (:eval (symbol-name this-command))
  473. ": "))
  474. (prompt-text-mode 1))
  475. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  476. ;; letters, font-lock mode and fonts
  477. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  478. ;; (set-window-margins (selected-window) 1 1)
  479. (and (or (eq system-type 'Darwin)
  480. (eq system-type 'darwin))
  481. (fboundp 'mac-set-input-method-parameter)
  482. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  483. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  484. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  485. (boundp 'input-method-inactivate-hook))
  486. (add-hook 'input-method-activate-hook
  487. (lambda () (set-cursor-color "red")))
  488. (add-hook 'input-method-inactivate-hook
  489. (lambda () (set-cursor-color "black"))))
  490. (when (safe-require-or-eval 'paren)
  491. (show-paren-mode 1)
  492. (setq show-paren-delay 0.5
  493. show-paren-style 'parenthesis) ; mixed is hard to read
  494. ;; (set-face-background 'show-paren-match
  495. ;; "black")
  496. ;; ;; (face-foreground 'default))
  497. ;; (set-face-foreground 'show-paren-match
  498. ;; "white")
  499. ;; (set-face-inverse-video-p 'show-paren-match
  500. ;; t)
  501. )
  502. (transient-mark-mode 1)
  503. (global-font-lock-mode 1)
  504. (setq font-lock-global-modes
  505. '(not
  506. help-mode
  507. eshell-mode
  508. ;;term-mode
  509. Man-mode))
  510. ;; (standard-display-ascii ?\n "$\n")
  511. ;; (defvar my-eol-face
  512. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  513. ;; )
  514. ;; (defvar my-tab-face
  515. ;; '(("\t" . '(0 highlight t nil))))
  516. (defvar my-jspace-face
  517. '(("\u3000" . '(0 highlight t nil))))
  518. (add-hook 'font-lock-mode-hook
  519. (lambda ()
  520. ;; (font-lock-add-keywords nil my-eol-face)
  521. (font-lock-add-keywords nil my-jspace-face)
  522. ))
  523. (when (safe-require-or-eval 'whitespace)
  524. (add-to-list 'whitespace-display-mappings ; not work
  525. `(tab-mark ?\t ,(vconcat "^I\t")))
  526. ;; (add-to-list 'whitespace-display-mappings
  527. ;; `(newline-mark ?\n ,(vconcat "$\n")))
  528. (setq whitespace-style '(face
  529. trailing ; trailing blanks
  530. newline ; newlines
  531. newline-mark ; use display table for newline
  532. tab-mark
  533. empty ; empty lines at beg or end of buffer
  534. lines-tail ; lines over 80
  535. ))
  536. ;; (setq whitespace-newline 'font-lock-comment-face)
  537. (set-variable 'whitespace-line-column nil)
  538. (global-whitespace-mode t)
  539. (add-hook 'dired-mode-hook
  540. (lambda ()
  541. (set (make-local-variable 'whitespace-style) nil)))
  542. (if (eq (display-color-cells)
  543. 256)
  544. (set-face-foreground 'whitespace-newline "color-109")
  545. ;; (progn
  546. ;; (set-face-bold-p 'whitespace-newline
  547. ;; t))
  548. ))
  549. (and nil
  550. (safe-require-or-eval 'fill-column-indicator)
  551. (setq fill-column-indicator))
  552. ;; highlight current line
  553. ;; http://wiki.riywo.com/index.php?Meadow
  554. (face-spec-set 'hl-line
  555. '((((min-colors 256)
  556. (background dark))
  557. (:background "color-234"))
  558. (((min-colors 256)
  559. (background light))
  560. (:background "color-234"))
  561. (t
  562. (:underline "black"))))
  563. (set-variable 'hl-line-global-modes
  564. '(not
  565. term-mode))
  566. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  567. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  568. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  569. ;;(safe-require-or-eval 'set-modeline-color)
  570. ;; (let ((fg (face-foreground 'default))
  571. ;; (bg (face-background 'default)))
  572. ;; (set-face-background 'mode-line-inactive
  573. ;; (if (face-inverse-video-p 'mode-line) fg bg))
  574. ;; (set-face-foreground 'mode-line-inactive
  575. ;; (if (face-inverse-video-p 'mode-line) bg fg)))
  576. ;; (set-face-underline 'mode-line-inactive
  577. ;; t)
  578. ;; (set-face-underline 'vertical-border
  579. ;; nil)
  580. (when (safe-require-or-eval 'end-mark)
  581. (global-end-mark-mode))
  582. (when (safe-require-or-eval 'auto-highlight-symbol)
  583. (set-variable 'ahs-idle-interval 0.6)
  584. (global-auto-highlight-symbol-mode 1))
  585. (when (safe-require-or-eval 'cyberpunk-theme)
  586. (load-theme 'cyberpunk t)
  587. (set-face-attribute 'button
  588. nil
  589. :inherit 'highlight)
  590. (set-face-foreground 'mode-line-inactive
  591. "white")
  592. )
  593. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  594. ;; file handling
  595. (when (safe-require-or-eval 'editorconfig)
  596. ;; (set-variable 'editorconfig-get-properties-function
  597. ;; 'editorconfig-core-get-properties-hash)
  598. (editorconfig-mode 1))
  599. (setq revert-without-query '(".+"))
  600. ;; save cursor position
  601. (when (safe-require-or-eval 'saveplace)
  602. (setq-default save-place t)
  603. (setq save-place-file (concat user-emacs-directory
  604. "places")))
  605. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  606. (setq make-backup-files t)
  607. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  608. (setq backup-directory-alist
  609. (cons (cons "\\.*$" (expand-file-name (concat user-emacs-directory
  610. "backup")))
  611. backup-directory-alist))
  612. (setq version-control 'never)
  613. (setq delete-old-versions t)
  614. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  615. "auto-save/")))
  616. (setq delete-auto-save-files t)
  617. (add-to-list 'completion-ignored-extensions ".bak")
  618. ;; (setq delete-by-moving-to-trash t
  619. ;; trash-directory "~/.emacs.d/trash")
  620. (add-hook 'after-save-hook
  621. 'executable-make-buffer-file-executable-if-script-p)
  622. (set (defvar bookmark-default-file)
  623. (expand-file-name (concat user-emacs-directory
  624. "bmk")))
  625. (with-eval-after-load 'recentf
  626. (defvar recentf-exclude nil)
  627. (add-to-list 'recentf-exclude
  628. (regexp-quote bookmark-default-file)))
  629. (when (safe-require-or-eval 'smart-revert)
  630. (smart-revert-on))
  631. ;; autosave
  632. (when (safe-require-or-eval 'autosave)
  633. (autosave-set 2))
  634. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  635. ;; buffer killing
  636. ;; (defun my-delete-window-killing-buffer () nil)
  637. (defun my-query-kill-current-buffer ()
  638. "Interactively kill current buffer."
  639. (interactive)
  640. (if (y-or-n-p (concat "kill current buffer? :"))
  641. (kill-buffer (current-buffer))))
  642. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  643. (substitute-key-definition 'kill-buffer
  644. 'my-query-kill-current-buffer
  645. global-map)
  646. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  647. ;; share clipboard with x
  648. ;; this page describes this in details, but only these sexps seem to be needed
  649. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  650. (and (not window-system)
  651. (not (eq window-system 'mac))
  652. (getenv "DISPLAY")
  653. (not (equal (getenv "DISPLAY") ""))
  654. (executable-find "xclip")
  655. ;; (< emacs-major-version 24)
  656. (safe-require-or-eval 'xclip)
  657. nil
  658. (turn-on-xclip))
  659. (and (eq system-type 'darwin)
  660. (safe-require-or-eval 'pasteboard)
  661. (turn-on-pasteboard)
  662. (getenv "TMUX")
  663. (pasteboard-enable-rtun))
  664. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  665. ;; some modes and hooks
  666. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  667. (when (safe-require-or-eval 'company)
  668. (global-company-mode)
  669. (set-variable 'company-idle-delay 0.5)
  670. (set-variable 'company-minimum-prefix-length 2)
  671. (set-variable 'company-selection-wrap-around t))
  672. ;; https://github.com/lunaryorn/flycheck
  673. (when (safe-require-or-eval 'flycheck)
  674. (call-after-init 'global-flycheck-mode))
  675. (set-variable 'ac-ignore-case nil)
  676. (when (autoload-eval-lazily 'term-run '(term-run-shell-command term-run))
  677. (define-key ctl-x-map "t" 'term-run-shell-command))
  678. (add-to-list 'safe-local-variable-values
  679. '(encoding utf-8))
  680. (setq enable-local-variables :safe)
  681. (when (safe-require-or-eval 'remember-major-modes-mode)
  682. (remember-major-modes-mode 1))
  683. ;; Detect file type from shebang and set major-mode.
  684. (add-to-list 'interpreter-mode-alist
  685. '("python3" . python-mode))
  686. (add-to-list 'interpreter-mode-alist
  687. '("python2" . python-mode))
  688. ;; http://fukuyama.co/foreign-regexp
  689. '(and (safe-require-or-eval 'foreign-regexp)
  690. (progn
  691. (setq foreign-regexp/regexp-type 'perl)
  692. '(setq reb-re-syntax 'foreign-regexp)
  693. ))
  694. (autoload-eval-lazily 'sql '(sql-mode)
  695. (safe-require-or-eval 'sql-indent))
  696. (when (autoload-eval-lazily 'git-command)
  697. (define-key ctl-x-map "g" 'git-command))
  698. (when (safe-require-or-eval 'git-commit)
  699. (global-git-commit-mode 1))
  700. (autoload-eval-lazily 'sl)
  701. ;; jdee is too old! use malabar instead
  702. (with-eval-after-load 'jdee
  703. (add-hook 'jdee-mode-hook
  704. (lambda ()
  705. (make-local-variable 'global-mode-string)
  706. (add-to-list 'global-mode-string
  707. mode-line-position))))
  708. ;; Cannot enable error thrown. Why???
  709. ;; https://github.com/m0smith/malabar-mode#Installation
  710. ;; (when (autoload-eval-lazily 'malabar-mode)
  711. ;; (add-to-list 'load-path
  712. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  713. ;; (safe-require-or-eval 'cedet-devel-load)
  714. ;; (call-after-init 'activate-malabar-mode))
  715. (with-eval-after-load 'make-mode
  716. (defvar makefile-mode-map (make-sparse-keymap))
  717. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  718. ;; this functions is set in write-file-functions, i cannot find any
  719. ;; good way to remove this.
  720. (fset 'makefile-warn-suspicious-lines 'ignore))
  721. (with-eval-after-load 'verilog-mode
  722. (defvar verilog-mode-map (make-sparse-keymap))
  723. (define-key verilog-mode-map ";" 'self-insert-command))
  724. (setq diff-switches "-u")
  725. (with-eval-after-load 'diff-mode
  726. ;; (when (and (eq major-mode
  727. ;; 'diff-mode)
  728. ;; (not buffer-file-name))
  729. ;; ;; do not pass when major-mode is derived mode of diff-mode
  730. ;; (view-mode 1))
  731. (set-face-attribute 'diff-header nil
  732. :foreground nil
  733. :background nil
  734. :weight 'bold)
  735. (set-face-attribute 'diff-file-header nil
  736. :foreground nil
  737. :background nil
  738. :weight 'bold)
  739. (set-face-foreground 'diff-index-face "blue")
  740. (set-face-attribute 'diff-hunk-header nil
  741. :foreground "cyan"
  742. :weight 'normal)
  743. (set-face-attribute 'diff-context nil
  744. ;; :foreground "white"
  745. :foreground nil
  746. :weight 'normal)
  747. (set-face-foreground 'diff-removed-face "red")
  748. (set-face-foreground 'diff-added-face "green")
  749. (set-face-background 'diff-removed-face nil)
  750. (set-face-background 'diff-added-face nil)
  751. (set-face-attribute 'diff-changed nil
  752. :foreground "magenta"
  753. :weight 'normal)
  754. (set-face-attribute 'diff-refine-change nil
  755. :foreground nil
  756. :background nil
  757. :weight 'bold
  758. :inverse-video t)
  759. ;; Annoying !
  760. ;;(diff-auto-refine-mode)
  761. )
  762. ;; (ffap-bindings)
  763. (set-variable 'browse-url-browser-function
  764. 'eww-browse-url)
  765. (set-variable 'sh-here-document-word "__EOC__")
  766. (when (autoload-eval-lazily 'adoc-mode
  767. nil
  768. (defvar adoc-mode-map (make-sparse-keymap))
  769. (define-key adoc-mode-map (kbd "C-m") 'newline))
  770. (setq auto-mode-alist
  771. `(("\\.adoc\\'" . adoc-mode)
  772. ("\\.asciidoc\\'" . adoc-mode)
  773. ,@auto-mode-alist)))
  774. (with-eval-after-load 'markup-faces
  775. ;; Is this too match ?
  776. (set-face-foreground 'markup-meta-face
  777. "color-245")
  778. (set-face-foreground 'markup-meta-hide-face
  779. "color-245")
  780. )
  781. (setq auto-mode-alist
  782. `(("autostart\\'" . sh-mode)
  783. ("xinitrc\\'" . sh-mode)
  784. ("xprograms\\'" . sh-mode)
  785. ("PKGBUILD\\'" . sh-mode)
  786. ,@auto-mode-alist))
  787. ;; TODO: check if this is required
  788. (and (autoload-eval-lazily 'groovy-mode)
  789. (add-to-list 'auto-mode-alist
  790. '("build\\.gradle\\'" . groovy-mode)))
  791. (with-eval-after-load 'yaml-mode
  792. (defvar yaml-mode-map (make-sparse-keymap))
  793. (define-key yaml-mode-map (kbd "C-m") 'newline))
  794. (with-eval-after-load 'html-mode
  795. (defvar html-mode-map (make-sparse-keymap))
  796. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  797. (with-eval-after-load 'text-mode
  798. (define-key text-mode-map (kbd "C-m") 'newline))
  799. (add-to-list 'Info-default-directory-list
  800. (expand-file-name "~/.info/emacs-ja"))
  801. (with-eval-after-load 'apropos
  802. (defvar apropos-mode-map (make-sparse-keymap))
  803. (define-key apropos-mode-map "n" 'next-line)
  804. (define-key apropos-mode-map "p" 'previous-line))
  805. (with-eval-after-load 'isearch
  806. ;; (define-key isearch-mode-map
  807. ;; (kbd "C-j") 'isearch-other-control-char)
  808. ;; (define-key isearch-mode-map
  809. ;; (kbd "C-k") 'isearch-other-control-char)
  810. ;; (define-key isearch-mode-map
  811. ;; (kbd "C-h") 'isearch-other-control-char)
  812. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  813. (define-key isearch-mode-map (kbd "M-r")
  814. 'isearch-query-replace-regexp))
  815. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  816. (setq lazy-highlight-cleanup nil)
  817. ;; face for isearch highlighing
  818. (set-face-attribute 'lazy-highlight
  819. nil
  820. :foreground `unspecified
  821. :background `unspecified
  822. :underline t
  823. ;; :weight `bold
  824. )
  825. (add-hook 'outline-mode-hook
  826. (lambda ()
  827. (when (string-match "\\.md\\'" buffer-file-name)
  828. (set (make-local-variable 'outline-regexp) "#+ "))))
  829. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  830. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  831. (when (autoload-eval-lazily 'markdown-mode
  832. '(markdown-mode gfm-mode)
  833. (defvar gfm-mode-map (make-sparse-keymap))
  834. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline))
  835. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  836. (set-variable 'markdown-command (or (executable-find "markdown")
  837. (executable-find "markdown.pl")
  838. ""))
  839. (add-hook 'markdown-mode-hook
  840. (lambda ()
  841. (outline-minor-mode 1)
  842. (flyspell-mode)
  843. (set (make-local-variable 'comment-start) ";")))
  844. )
  845. ;; c-mode
  846. ;; http://www.emacswiki.org/emacs/IndentingC
  847. ;; http://en.wikipedia.org/wiki/Indent_style
  848. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  849. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  850. (with-eval-after-load 'cc-vars
  851. (defvar c-default-style nil)
  852. (add-to-list 'c-default-style
  853. '(c-mode . "k&r"))
  854. (add-to-list 'c-default-style
  855. '(c++-mode . "k&r"))
  856. (add-hook 'c-mode-common-hook
  857. (lambda ()
  858. ;; why c-basic-offset in k&r style defaults to 5 ???
  859. (set-variable 'c-basic-offset 4)
  860. (set-variable 'indent-tabs-mode nil)
  861. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  862. (c-toggle-hungry-state -1)
  863. ;; (and (require 'gtags nil t)
  864. ;; (gtags-mode 1))
  865. )))
  866. (autoload-eval-lazily 'js2-mode nil
  867. ;; currently do not use js2-mode
  868. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  869. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  870. (defvar js2-mode-map (make-sparse-keymap))
  871. (define-key js2-mode-map (kbd "C-m") (lambda ()
  872. (interactive)
  873. (js2-enter-key)
  874. (indent-for-tab-command)))
  875. ;; (add-hook (kill-local-variable 'before-save-hook)
  876. ;; 'js2-before-save)
  877. ;; (add-hook 'before-save-hook
  878. ;; 'my-indent-buffer
  879. ;; nil
  880. ;; t)
  881. )
  882. (add-to-list 'interpreter-mode-alist
  883. '("node" . js-mode))
  884. (when (autoload-eval-lazily 'flymake-jslint
  885. '(flymake-jslint-load))
  886. (autoload-eval-lazily 'js nil
  887. (add-hook 'js-mode-hook
  888. 'flymake-jslint-load)))
  889. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  890. (with-eval-after-load 'uniquify
  891. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  892. (setq uniquify-ignore-buffers-re "*[^*]+*")
  893. (setq uniquify-min-dir-content 1))
  894. (with-eval-after-load 'view
  895. (defvar view-mode-map (make-sparse-keymap))
  896. (define-key view-mode-map "j" 'scroll-up-line)
  897. (define-key view-mode-map "k" 'scroll-down-line)
  898. (define-key view-mode-map "v" 'toggle-read-only)
  899. (define-key view-mode-map "q" 'bury-buffer)
  900. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  901. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  902. ;; (define-key view-mode-map
  903. ;; "n" 'nonincremental-repeat-search-forward)
  904. ;; (define-key view-mode-map
  905. ;; "N" 'nonincremental-repeat-search-backward)
  906. (define-key view-mode-map "/" 'isearch-forward-regexp)
  907. (define-key view-mode-map "?" 'isearch-backward-regexp)
  908. (define-key view-mode-map "n" 'isearch-repeat-forward)
  909. (define-key view-mode-map "N" 'isearch-repeat-backward)
  910. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  911. (global-set-key "\M-r" 'view-mode)
  912. ;; (setq view-read-only t)
  913. (add-hook 'Man-mode-hook
  914. (lambda ()
  915. (view-mode 1)
  916. (setq truncate-lines nil)))
  917. (set-variable 'Man-notify-method (if window-system
  918. 'newframe
  919. 'aggressive))
  920. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  921. "woman_cache.el")))
  922. (defalias 'man 'woman)
  923. (add-to-list 'auto-mode-alist
  924. '("tox\\.ini\\'" . conf-unix-mode))
  925. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  926. ;; python
  927. (when (autoload-eval-lazily 'python '(python-mode)
  928. (defvar python-mode-map (make-sparse-keymap))
  929. (define-key python-mode-map (kbd "C-c C-e") 'my-python-run-as-command)
  930. (define-key python-mode-map (kbd "C-c C-b") 'my-python-display-python-buffer)
  931. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)
  932. (defvar inferior-python-mode-map (make-sparse-keymap))
  933. (define-key inferior-python-mode-map (kbd "<up>") 'comint-previous-input)
  934. (define-key inferior-python-mode-map (kbd "<down>") 'comint-next-input)
  935. )
  936. (set-variable 'python-python-command (or (executable-find "python3")
  937. (executable-find "python")))
  938. ;; (defun my-python-run-as-command ()
  939. ;; ""
  940. ;; (interactive)
  941. ;; (shell-command (concat python-python-command " " buffer-file-name)))
  942. (defun my-python-display-python-buffer ()
  943. ""
  944. (interactive)
  945. (defvar python-buffer nil)
  946. (set-window-text-height (display-buffer python-buffer
  947. t)
  948. 7))
  949. (add-hook 'inferior-python-mode-hook
  950. (lambda ()
  951. (my-python-display-python-buffer))))
  952. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  953. ;; gauche-mode
  954. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  955. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  956. ;; NOTE: This gauche-mode returns 404.
  957. ;; There is another gosh-mode, so for now I submitted a recipe for that into
  958. ;; github.com/10sr/emacs-lisp/p. I'll add setup for that later.
  959. (when nil (and '(fetch-library
  960. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  961. t)
  962. (autoload-eval-lazily 'gauche-mode '(gauche-mode run-scheme)
  963. (defvar gauche-mode-map (make-sparse-keymap))
  964. (defvar scheme-mode-map (make-sparse-keymap))
  965. (define-key gauche-mode-map
  966. (kbd "C-c C-z") 'run-gauche-other-window)
  967. (define-key scheme-mode-map
  968. (kbd "C-c C-c") 'scheme-send-buffer)
  969. (define-key scheme-mode-map
  970. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer)))
  971. (let ((s (executable-find "gosh")))
  972. (set-variable 'scheme-program-name s)
  973. (set-variable 'gauche-program-name s))
  974. (defvar gauche-program-name nil)
  975. (defvar scheme-buffer nil)
  976. (defun run-gauche-other-window ()
  977. "Run gauche on other window"
  978. (interactive)
  979. (switch-to-buffer-other-window
  980. (get-buffer-create "*scheme*"))
  981. (run-gauche))
  982. (defun run-gauche ()
  983. "run gauche"
  984. (interactive)
  985. (run-scheme gauche-program-name)
  986. )
  987. (defun scheme-send-buffer ()
  988. ""
  989. (interactive)
  990. (scheme-send-region (point-min) (point-max))
  991. (my-scheme-display-scheme-buffer)
  992. )
  993. (defun my-scheme-display-scheme-buffer ()
  994. ""
  995. (interactive)
  996. (set-window-text-height (display-buffer scheme-buffer
  997. t)
  998. 7))
  999. (add-hook 'scheme-mode-hook
  1000. (lambda ()
  1001. nil))
  1002. (add-hook 'inferior-scheme-mode-hook
  1003. (lambda ()
  1004. ;; (my-scheme-display-scheme-buffer)
  1005. ))
  1006. (setq auto-mode-alist
  1007. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1008. (setq auto-mode-alist
  1009. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1010. )
  1011. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1012. ;; term mode
  1013. ;; (setq multi-term-program shell-file-name)
  1014. (when (autoload-eval-lazily 'multi-term)
  1015. (set-variable 'multi-term-switch-after-close nil)
  1016. (set-variable 'multi-term-dedicated-select-after-open-p t)
  1017. (set-variable 'multi-term-dedicated-window-height 20))
  1018. (when (autoload-eval-lazily 'term '(term ansi-term)
  1019. (defvar term-raw-map (make-sparse-keymap))
  1020. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  1021. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  1022. (define-key term-raw-map (kbd "<up>") 'scroll-down-line)
  1023. (define-key term-raw-map (kbd "<down>") 'scroll-up-line)
  1024. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  1025. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  1026. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  1027. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  1028. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  1029. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  1030. (define-key term-raw-map [delete] 'term-send-raw)
  1031. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  1032. (define-key term-raw-map "\C-y" 'term-paste)
  1033. (define-key term-raw-map
  1034. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  1035. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  1036. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  1037. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  1038. ;; (define-key term-raw-map "\C-d" 'delete-char)
  1039. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  1040. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  1041. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  1042. ;; (define-key term-raw-map "\C-f" 'forward-char)
  1043. ;; (define-key term-raw-map "\C-b" 'backward-char)
  1044. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  1045. )
  1046. (defun my-term-quit-or-send-raw ()
  1047. ""
  1048. (interactive)
  1049. (if (get-buffer-process (current-buffer))
  1050. (call-interactively 'term-send-raw)
  1051. (kill-buffer)))
  1052. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  1053. ;; (setq term-ansi-default-program shell-file-name)
  1054. (add-hook 'term-setup-hook
  1055. (lambda ()
  1056. (set-variable 'term-display-table (make-display-table))))
  1057. (add-hook 'term-mode-hook
  1058. (lambda ()
  1059. (defvar term-raw-map (make-sparse-keymap))
  1060. ;; (unless (memq (current-buffer)
  1061. ;; (and (featurep 'multi-term)
  1062. ;; (defvar multi-term-buffer-list)
  1063. ;; ;; current buffer is not multi-term buffer
  1064. ;; multi-term-buffer-list))
  1065. ;; )
  1066. (set (make-local-variable 'scroll-margin) 0)
  1067. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  1068. ;; (cua-mode 0)
  1069. ;; (and cua-mode
  1070. ;; (local-unset-key (kbd "C-c")))
  1071. ;; (define-key cua--prefix-override-keymap
  1072. ;;"\C-c" 'term-interrupt-subjob)
  1073. (set (make-local-variable (defvar hl-line-range-function))
  1074. (lambda ()
  1075. '(0 . 0)))
  1076. (define-key term-raw-map
  1077. "\C-x" (lookup-key (current-global-map) "\C-x"))
  1078. (define-key term-raw-map
  1079. "\C-z" (lookup-key (current-global-map) "\C-z"))
  1080. ))
  1081. ;; (add-hook 'term-exec-hook 'forward-char)
  1082. )
  1083. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1084. ;; buffer switching
  1085. (defvar bs-configurations)
  1086. (when (autoload-eval-lazily 'bs '(bs-show)
  1087. (add-to-list 'bs-configurations
  1088. '("specials" "^\\*" nil ".*" nil nil))
  1089. (defvar bs-mode-map)
  1090. (defvar bs-current-configuration)
  1091. (define-key bs-mode-map (kbd "t")
  1092. (lambda ()
  1093. (interactive)
  1094. (if (string= "specials"
  1095. bs-current-configuration)
  1096. (bs-set-configuration "files")
  1097. (bs-set-configuration "specials"))
  1098. (bs-refresh)
  1099. (bs-message-without-log "%s"
  1100. (bs--current-config-message))))
  1101. ;; (setq bs-configurations (list
  1102. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1103. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1104. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1105. )
  1106. (defalias 'list-buffers 'bs-show)
  1107. (set-variable 'bs-default-configuration "files")
  1108. (set-variable 'bs-default-sort-name "by nothing")
  1109. (add-hook 'bs-mode-hook
  1110. (lambda ()
  1111. (set (make-local-variable 'scroll-margin) 0))))
  1112. ;;(iswitchb-mode 1)
  1113. (icomplete-mode)
  1114. (defun iswitchb-buffer-display-other-window ()
  1115. "Do iswitchb in other window."
  1116. (interactive)
  1117. (let ((iswitchb-default-method 'display))
  1118. (call-interactively 'iswitchb-buffer)))
  1119. ;;;;;;;;;;;;;;;;;;;;;;;;
  1120. ;; ilookup
  1121. (with-eval-after-load 'ilookup
  1122. (set-variable 'ilookup-dict-alist
  1123. '(
  1124. ("sdcv" . (lambda (word)
  1125. (shell-command-to-string
  1126. (format "sdcv -n '%s'"
  1127. word))))
  1128. ("en" . (lambda (word)
  1129. (shell-command-to-string
  1130. (format "sdcv -n -u dictd_www.dict.org_gcide '%s'"
  1131. word))))
  1132. ("ja" . (lambda (word)
  1133. (shell-command-to-string
  1134. (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'"
  1135. word))))
  1136. ("jaj" . (lambda (word)
  1137. (shell-command-to-string
  1138. (format "sdcv -n -u jmdict-en-ja '%s'"
  1139. word))))
  1140. ("jag" .
  1141. (lambda (word)
  1142. (with-temp-buffer
  1143. (insert (shell-command-to-string
  1144. (format "sdcv -n -u 'Genius English-Japanese' '%s'"
  1145. word)))
  1146. (html2text)
  1147. (buffer-substring (point-min)
  1148. (point-max)))))
  1149. ("alc" . (lambda (word)
  1150. (shell-command-to-string
  1151. (format "alc '%s' | head -n 20"
  1152. word))))
  1153. ("app" . (lambda (word)
  1154. (shell-command-to-string
  1155. (format "dict_app '%s'"
  1156. word))))
  1157. ;; letters broken
  1158. ("ms" .
  1159. (lambda (word)
  1160. (let ((url (concat
  1161. "http://api.microsofttranslator.com/V2/Ajax.svc/"
  1162. "Translate?appId=%s&text=%s&to=%s"))
  1163. (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51")
  1164. (target "ja")
  1165. (eword (url-hexify-string word)))
  1166. (with-current-buffer (url-retrieve-synchronously
  1167. (format url
  1168. apikey
  1169. eword
  1170. target))
  1171. (message "")
  1172. (goto-char (point-min))
  1173. (search-forward-regexp "^$"
  1174. nil
  1175. t)
  1176. (url-unhex-string (buffer-substring-no-properties
  1177. (point)
  1178. (point-max)))))))
  1179. ))
  1180. ;; (funcall (cdr (assoc "ms"
  1181. ;; ilookup-alist))
  1182. ;; "dictionary")
  1183. ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja"))
  1184. ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com"))
  1185. (set-variable 'ilookup-default "ja")
  1186. (when (locate-library "google-translate")
  1187. (defvar ilookup-dict-alist nil)
  1188. (add-to-list 'ilookup-dict-alist
  1189. '("gt" .
  1190. (lambda (word)
  1191. (save-excursion
  1192. (google-translate-translate "auto"
  1193. "ja"
  1194. word))
  1195. (with-current-buffer "*Google Translate*"
  1196. (buffer-substring-no-properties (point-min)
  1197. (point-max)))))))
  1198. )
  1199. (when (autoload-eval-lazily 'google-translate '(google-translate-translate
  1200. google-translate-at-point))
  1201. (set-variable 'google-translate-default-source-language "auto")
  1202. (set-variable 'google-translate-default-target-language "ja"))
  1203. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1204. ;; vc
  1205. (set-variable 'vc-handled-backends '())
  1206. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1207. ;; recentf-mode
  1208. (set-variable 'recentf-save-file (expand-file-name (concat user-emacs-directory
  1209. "recentf")))
  1210. (set-variable 'recentf-max-menu-items 20)
  1211. (set-variable 'recentf-max-saved-items 30)
  1212. (set-variable 'recentf-show-file-shortcuts-flag nil)
  1213. (when (safe-require-or-eval 'recentf)
  1214. (add-to-list 'recentf-exclude
  1215. (regexp-quote recentf-save-file))
  1216. (add-to-list 'recentf-exclude
  1217. (regexp-quote (expand-file-name user-emacs-directory)))
  1218. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1219. (remove-hook 'find-file-hook
  1220. 'recentf-track-opened-file)
  1221. (defun my-recentf-load-track-save-list ()
  1222. "Load current recentf list from file, track current visiting file, then save
  1223. the list."
  1224. (recentf-load-list)
  1225. (recentf-track-opened-file)
  1226. (recentf-save-list))
  1227. (add-hook 'find-file-hook
  1228. 'my-recentf-load-track-save-list)
  1229. (add-hook 'kill-emacs-hook
  1230. 'recentf-load-list)
  1231. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1232. ;; (add-hook 'find-file-hook
  1233. ;; (lambda ()
  1234. ;; (recentf-add-file default-directory)))
  1235. (and (autoload-eval-lazily 'recentf-show)
  1236. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1237. (add-hook 'recentf-show-before-listing-hook
  1238. 'recentf-load-list))
  1239. (recentf-mode 1)
  1240. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1241. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1242. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1243. (define-key recentf-dialog-mode-map "n" 'next-line)
  1244. (add-hook 'recentf-dialog-mode-hook
  1245. (lambda ()
  1246. ;; (recentf-save-list)
  1247. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1248. ;; 'my-recentf-cd-and-find-file)
  1249. (cd "~/"))))
  1250. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1251. ;; dired
  1252. (defun my-dired-echo-file-head (arg)
  1253. ""
  1254. (interactive "P")
  1255. (let ((f (dired-get-filename)))
  1256. (message "%s"
  1257. (with-temp-buffer
  1258. (insert-file-contents f)
  1259. (buffer-substring-no-properties
  1260. (point-min)
  1261. (progn (goto-char (point-min))
  1262. (forward-line (1- (if arg
  1263. (prefix-numeric-value arg)
  1264. 7)))
  1265. (point-at-eol)))))))
  1266. (defun my-dired-diff ()
  1267. ""
  1268. (interactive)
  1269. (let ((files (dired-get-marked-files nil nil nil t)))
  1270. (if (eq (car files)
  1271. t)
  1272. (diff (cadr files) (dired-get-filename))
  1273. (message "One file must be marked!"))))
  1274. (defun dired-get-file-info ()
  1275. "dired get file info"
  1276. (interactive)
  1277. (let ((f (shell-quote-argument (dired-get-filename t))))
  1278. (if (file-directory-p f)
  1279. (progn
  1280. (message "Calculating disk usage...")
  1281. (shell-command (concat "du -hsD "
  1282. f)))
  1283. (shell-command (concat "file "
  1284. f)))))
  1285. (defun my-dired-scroll-up ()
  1286. ""
  1287. (interactive)
  1288. (my-dired-previous-line (- (window-height) 1)))
  1289. (defun my-dired-scroll-down ()
  1290. ""
  1291. (interactive)
  1292. (my-dired-next-line (- (window-height) 1)))
  1293. ;; (defun my-dired-forward-line (arg)
  1294. ;; ""
  1295. ;; (interactive "p"))
  1296. (defun my-dired-previous-line (arg)
  1297. ""
  1298. (interactive "p")
  1299. (if (> arg 0)
  1300. (progn
  1301. (if (eq (line-number-at-pos)
  1302. 1)
  1303. (goto-char (point-max))
  1304. (forward-line -1))
  1305. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1306. (dired-get-subdir))
  1307. (- arg 1)
  1308. arg)))
  1309. (dired-move-to-filename)))
  1310. (defun my-dired-next-line (arg)
  1311. ""
  1312. (interactive "p")
  1313. (if (> arg 0)
  1314. (progn
  1315. (if (eq (point)
  1316. (point-max))
  1317. (goto-char (point-min))
  1318. (forward-line 1))
  1319. (my-dired-next-line (if (or (dired-get-filename nil t)
  1320. (dired-get-subdir))
  1321. (- arg 1)
  1322. arg)))
  1323. (dired-move-to-filename)))
  1324. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1325. (if (eq window-system 'mac)
  1326. (setq dired-listing-switches "-lhF")
  1327. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1328. )
  1329. (setq dired-listing-switches "-lhF")
  1330. (put 'dired-find-alternate-file 'disabled nil)
  1331. ;; when using dired-find-alternate-file
  1332. ;; reuse current dired buffer for the file to open
  1333. (set-variable 'dired-ls-F-marks-symlinks t)
  1334. (with-eval-after-load 'ls-lisp
  1335. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1336. (setq ls-lisp-dirs-first t)
  1337. (setq ls-lisp-use-localized-time-format t)
  1338. (setq ls-lisp-format-time-list
  1339. '("%Y-%m-%d %H:%M"
  1340. "%Y-%m-%d ")))
  1341. (set-variable 'dired-dwim-target t)
  1342. (set-variable 'dired-isearch-filenames t)
  1343. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  1344. (set-variable 'dired-hide-details-hide-information-lines nil)
  1345. ;; (add-hook 'dired-after-readin-hook
  1346. ;; 'my-replace-nasi-none)
  1347. ;; (add-hook 'after-init-hook
  1348. ;; (lambda ()
  1349. ;; (dired ".")))
  1350. (with-eval-after-load 'dired
  1351. (defvar dired-mode-map (make-sparse-keymap))
  1352. (define-key dired-mode-map "o" 'my-dired-x-open)
  1353. (define-key dired-mode-map "i" 'dired-get-file-info)
  1354. (define-key dired-mode-map "f" 'find-file)
  1355. (define-key dired-mode-map "!" 'shell-command)
  1356. (define-key dired-mode-map "&" 'async-shell-command)
  1357. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1358. (define-key dired-mode-map "=" 'my-dired-diff)
  1359. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1360. (define-key dired-mode-map "b" 'gtkbm)
  1361. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1362. (define-key dired-mode-map "@" (lambda ()
  1363. (interactive) (my-x-open ".")))
  1364. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1365. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1366. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1367. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1368. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1369. (substitute-key-definition 'dired-next-line
  1370. 'my-dired-next-line
  1371. dired-mode-map)
  1372. (substitute-key-definition 'dired-previous-line
  1373. 'my-dired-previous-line
  1374. dired-mode-map)
  1375. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  1376. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  1377. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  1378. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  1379. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1380. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1381. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1382. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1383. (add-hook 'dired-mode-hook
  1384. (lambda ()
  1385. (when (fboundp 'dired-hide-details-mode)
  1386. (dired-hide-details-mode t)
  1387. (local-set-key "l" 'dired-hide-details-mode))
  1388. (let ((file "._Icon\015"))
  1389. (when nil
  1390. '(file-readable-p file)
  1391. (delete-file file)))))
  1392. (when (autoload-eval-lazily 'pack '(dired-do-pack-or-unpack pack-pack))
  1393. (with-eval-after-load 'dired
  1394. (define-key dired-mode-map "P" 'dired-do-pack-or-unpack)))
  1395. (when (autoload-eval-lazily 'dired-list-all-mode)
  1396. (setq dired-listing-switches "-lhF")
  1397. (with-eval-after-load 'dired
  1398. (define-key dired-mode-map "a" 'dired-list-all-mode))))
  1399. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1400. ;; my-term
  1401. (defvar my-term nil
  1402. "My terminal buffer.")
  1403. (defvar my-term-function nil
  1404. "Function to create terminal buffer.
  1405. This function accept no argument and return newly created buffer of terminal.")
  1406. (defun my-term (&optional arg)
  1407. "Open terminal buffer and return that buffer.
  1408. If ARG is given or called with prefix argument, create new buffer."
  1409. (interactive "P")
  1410. (if (and (not arg)
  1411. my-term
  1412. (buffer-name my-term))
  1413. (pop-to-buffer my-term)
  1414. (setq my-term
  1415. (save-window-excursion
  1416. (funcall my-term-function)))
  1417. (and my-term
  1418. (my-term))))
  1419. ;; (setq my-term-function
  1420. ;; (lambda ()
  1421. ;; (if (eq system-type 'windows-nt)
  1422. ;; (eshell)
  1423. ;; (if (require 'multi-term nil t)
  1424. ;; (multi-term)
  1425. ;; (ansi-term shell-file-name)))))
  1426. (setq my-term-function (lambda () (eshell t)))
  1427. ;;(define-key my-prefix-map (kbd "C-s") 'my-term)
  1428. (define-key ctl-x-map "i" 'my-term)
  1429. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1430. ;; misc funcs
  1431. (defalias 'qcalc 'quick-calc)
  1432. (defun memo (&optional dir)
  1433. "Open memo.txt in DIR."
  1434. (interactive)
  1435. (pop-to-buffer (find-file-noselect (concat (if dir
  1436. (file-name-as-directory dir)
  1437. "")
  1438. "memo.txt"))))
  1439. (defvar my-rgrep-alist
  1440. `(
  1441. ;; the silver searcher
  1442. ("ag"
  1443. (executable-find "ag")
  1444. "ag --nocolor --nogroup --nopager --filename ")
  1445. ;; ack
  1446. ("ack"
  1447. (executable-find "ack")
  1448. "ack --nocolor --nogroup --nopager --with-filename ")
  1449. ;; gnu global
  1450. ("global"
  1451. (and (require 'gtags nil t)
  1452. (executable-find "global")
  1453. (gtags-get-rootpath))
  1454. "global --result grep ")
  1455. ;; git grep
  1456. ("gitgrep"
  1457. (eq 0
  1458. (shell-command "git rev-parse --git-dir"))
  1459. "git --no-pager -c color.grep=false grep -nH -e ")
  1460. ;; grep
  1461. ("grep"
  1462. t
  1463. ,(concat "find . "
  1464. "-path '*/.git' -prune -o "
  1465. "-path '*/.svn' -prune -o "
  1466. "-type f -print0 | "
  1467. "xargs -0 grep -nH -e "))
  1468. )
  1469. "Alist of rgrep command.
  1470. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1471. condition to choose COMMAND when evaluated.")
  1472. (defvar my-rgrep-default nil
  1473. "Default command name for my-rgrep.")
  1474. (defun my-rgrep-grep-command (&optional name alist)
  1475. "Return recursive grep command for current directory or nil.
  1476. If NAME is given, use that without testing.
  1477. Commands are searched from ALIST."
  1478. (if alist
  1479. (if name
  1480. ;; if name is given search that from alist and return the command
  1481. (nth 2 (assoc name
  1482. alist))
  1483. ;; if name is not given try test in 1th elem
  1484. (let ((car (car alist))
  1485. (cdr (cdr alist)))
  1486. (if (eval (nth 1 car))
  1487. ;; if the condition is true return the command
  1488. (nth 2 car)
  1489. ;; try next one
  1490. (and cdr
  1491. (my-rgrep-grep-command name cdr)))))
  1492. ;; if alist is not given set default value
  1493. (my-rgrep-grep-command name my-rgrep-alist)))
  1494. (defun my-rgrep (command-args)
  1495. "My recursive grep. Run COMMAND-ARGS."
  1496. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  1497. nil)))
  1498. (if cmd
  1499. (list (read-shell-command "grep command: "
  1500. cmd
  1501. 'grep-find-history))
  1502. (error "My-Rgrep: Command for rgrep not found")
  1503. )))
  1504. (compilation-start command-args
  1505. 'grep-mode))
  1506. ;; (defun my-rgrep-symbol-at-point (command-args)
  1507. ;; "My recursive grep. Run COMMAND-ARGS."
  1508. ;; (interactive (list (read-shell-command "grep command: "
  1509. ;; (concat (my-rgrep-grep-command)
  1510. ;; " "
  1511. ;; (thing-at-point 'symbol))
  1512. ;; 'grep-find-history)))
  1513. ;; (compilation-start command-args
  1514. ;; 'grep-mode))
  1515. (defmacro define-my-rgrep (name)
  1516. "Define rgrep for NAME."
  1517. `(defun ,(intern (concat "my-rgrep-"
  1518. name)) ()
  1519. ,(format "My recursive grep by %s."
  1520. name)
  1521. (interactive)
  1522. (let ((my-rgrep-default ,name))
  1523. (if (called-interactively-p 'any)
  1524. (call-interactively 'my-rgrep)
  1525. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1526. )
  1527. (define-my-rgrep "ack")
  1528. (define-my-rgrep "ag")
  1529. (define-my-rgrep "gitgrep")
  1530. (define-my-rgrep "grep")
  1531. (define-my-rgrep "global")
  1532. (define-key ctl-x-map "s" 'my-rgrep)
  1533. ;; (defun make ()
  1534. ;; "Run \"make -k\" in current directory."
  1535. ;; (interactive)
  1536. ;; (compile "make -k"))
  1537. (defalias 'make 'compile)
  1538. (define-key ctl-x-map "c" 'compile)
  1539. ;;;;;;;;;;;;;;;;;;;;;;;
  1540. ;; adoc-simple-mode
  1541. (when (safe-require-or-eval 'adoc-mode)
  1542. (defvar adoc-simple-font-lock-keywords
  1543. nil)
  1544. (define-derived-mode adoc-simple-mode adoc-mode
  1545. "Adoc-Simple"
  1546. "Major mode for editing AsciiDoc text files.
  1547. This mode is a simplified version of `adoc-mode'."
  1548. '(set (make-local-variable 'font-lock-defaults)
  1549. '(adoc-simple-font-lock-keywords
  1550. nil nil nil nil
  1551. (font-lock-multiline . t)
  1552. (font-lock-mark-block-function . adoc-font-lock-mark-block-function))))
  1553. (add-to-list 'auto-mode-alist
  1554. '("\\.adoc\\'" . adoc-simple-mode)))
  1555. (when (and (safe-require-or-eval 'google-translate)
  1556. (safe-require-or-eval 'google-translate-smooth-ui))
  1557. (add-to-list 'google-translate-translation-directions-alist
  1558. '("en" . "ja"))
  1559. (defun translate-echo-at-point ()
  1560. "Translate popup at point."
  1561. (interactive)
  1562. (let ((google-translate-output-destination 'echo-area))
  1563. (google-translate-translate "auto" "ja" (current-word t t))))
  1564. (define-minor-mode auto-translate-mode
  1565. "Translate word at point automatically."
  1566. :global nil
  1567. :lighter "ATranslate"))
  1568. ;;; emacs.el ends here