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

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