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

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