Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

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