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

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