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

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