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
4 anni fa
11 anni fa
11 anni fa
3 anni fa
11 anni fa
13 anni fa
5 anni fa
13 anni fa
4 anni fa
13 anni fa
12 anni fa
4 anni fa
5 anni fa
13 anni fa
13 anni fa
12 anni fa
13 anni fa
4 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
3 anni fa
5 anni fa
3 anni fa
1 anno fa
4 anni fa
3 anni fa
5 anni fa
4 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
1 anno 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
4 anni fa
4 anni fa
3 anni fa
4 anni fa
4 anni fa
1 anno fa
4 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
4 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
5 anni fa
6 anni fa
6 anni fa
5 anni fa
3 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
5 anni fa
3 anni fa
6 anni fa
5 anni fa
5 anni fa
5 anni fa
3 anni fa
4 anni fa
13 anni fa
13 anni fa
3 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
9 anni fa
13 anni fa
1 anno fa
13 anni fa
13 anni fa
13 anni fa
13 anni fa
8 anni fa
13 anni fa
6 anni fa
1 anno 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
6 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
5 anni fa
5 anni fa
5 anni fa
12 anni fa
12 anni fa
12 anni fa
6 anni fa
12 anni fa
12 anni fa
6 anni fa
6 anni fa
12 anni fa
5 anni fa
3 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
1 anno fa
11 anni fa
6 anni fa
6 anni fa
6 anni fa
11 anni fa
5 anni fa
3 anni fa
5 anni fa
5 anni fa
4 anni fa
4 anni fa
4 anni fa
4 anni fa
5 anni fa
4 anni fa
4 anni fa
4 anni fa
3 anni fa
1 anno fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
3 anni fa
1 anno fa
3 anni fa
3 anni fa
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065
  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Code:
  3. ;; SETUP_LOAD: (load "bytecomp") ;; Required for WSL environment
  4. ;; SETUP_LOAD: (let ((file "DOTFILES_DIR/emacs.el"))
  5. ;; SETUP_LOAD: (and (file-readable-p file)
  6. ;; SETUP_LOAD: (byte-recompile-file file nil 0 t)))
  7. ;; TODO: Use custom-set-variables in place of set-variable
  8. (setq debug-on-error t)
  9. (when (getenv "_EMACS_EL_PROFILE")
  10. (eval-and-compile
  11. (require 'profiler))
  12. (profiler-start 'cpu))
  13. ;; https://emacs-jp.github.io/tips/startup-optimization
  14. ;; Temporarily change values to speed up initialization
  15. (defconst my-orig-file-name-handler-alist file-name-handler-alist)
  16. (setq file-name-handler-alist nil)
  17. (defconst my-orig-gc-cons-threshold gc-cons-threshold)
  18. (setq gc-cons-threshold most-positive-fixnum)
  19. ;; make directories
  20. (unless (file-directory-p (expand-file-name user-emacs-directory))
  21. (make-directory (expand-file-name user-emacs-directory)))
  22. (unless (file-directory-p (expand-file-name "info" user-emacs-directory))
  23. (make-directory (expand-file-name "info" user-emacs-directory)))
  24. ;; Custom file
  25. (setq custom-file (expand-file-name "custom.el" user-emacs-directory))
  26. (when (file-readable-p custom-file)
  27. (load custom-file))
  28. (require 'cl-lib)
  29. (require 'simple)
  30. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  31. ;; Some macros for internals
  32. (defvar after-first-visit-hook nil
  33. "Run only once at the first visit of file.")
  34. (defvar after-first-visit-hook--done nil
  35. "Non-nil when `after-first-visit-hook' has already been called.")
  36. (defun after-first-visit-hook-run ()
  37. "Run `after-first-visit-hook' and clear its config."
  38. (when (not after-first-visit-hook--done)
  39. (run-hooks 'after-first-visit-hook))
  40. (setq after-first-visit-hook--done t)
  41. (remove-hook 'find-file-hook
  42. 'after-first-visit-hook-run))
  43. (add-hook 'find-file-hook
  44. 'after-first-visit-hook-run)
  45. (defmacro eval-after-init (&rest body)
  46. "If `after-init-hook' has been run, run BODY immediately.
  47. Otherwize hook it."
  48. (declare (indent 0) (debug t))
  49. `(if after-init-time
  50. ;; Currently after-init-hook is run just after setting after-init-hook
  51. (progn
  52. ,@body)
  53. (add-hook 'after-init-hook
  54. (lambda ()
  55. ,@body))))
  56. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  57. ;; package
  58. (require 'package)
  59. (set-variable 'package-archives
  60. `(,@package-archives
  61. ("melpa" . "https://melpa.org/packages/")
  62. ;; Somehow fails to download via https
  63. ("10sr-el" . "http://10sr.github.io/emacs-lisp/elpa/")))
  64. (when (< emacs-major-version 27)
  65. (package-initialize))
  66. ;; Use package-install-selected-packages to install these
  67. (let ((my '(
  68. vimrc-mode
  69. markdown-mode
  70. yaml-mode
  71. gnuplot-mode
  72. php-mode
  73. erlang
  74. js2-mode
  75. js-doc
  76. ;; git-commit
  77. gitignore-mode
  78. adoc-mode
  79. go-mode
  80. ;; It seems malabar has been merged into jdee and this package
  81. ;; already removed
  82. ;; malabar-mode
  83. gosh-mode
  84. scala-mode
  85. web-mode
  86. toml-mode
  87. json-mode
  88. color-moccur
  89. ggtags
  90. flycheck
  91. auto-highlight-symbol
  92. hl-todo
  93. ;; Currently not available
  94. ;; pp-c-l
  95. xclip
  96. foreign-regexp
  97. multi-term
  98. term-run
  99. editorconfig
  100. git-ps1-mode
  101. restart-emacs
  102. pkgbuild-mode
  103. minibuffer-line
  104. which-key
  105. ;; I think this works in place of my autosave lib
  106. super-save
  107. pipenv
  108. imenu-list
  109. page-break-lines
  110. ;; aggressive-indent
  111. dired-filter
  112. wgrep
  113. magit
  114. git-gutter
  115. end-mark
  116. sl
  117. ;; TODO: Configure pony-tpl-mode
  118. pony-mode
  119. gited
  120. highlight-indentation
  121. diminish
  122. fic-mode
  123. term-cursor
  124. pydoc
  125. color-identifiers-mode
  126. dired-k
  127. blacken
  128. back-button
  129. with-venv
  130. nyan-mode
  131. diredfl
  132. hardhat
  133. hungry-delete
  134. counsel
  135. ivy-prescient
  136. editorconfig
  137. editorconfig-custom-majormode
  138. git-command
  139. prompt-text
  140. ;; 10sr repository
  141. ;; 10sr-extras
  142. terminal-title
  143. dired-list-all-mode
  144. pack
  145. set-modeline-color
  146. read-only-only-mode
  147. smart-revert
  148. autosave
  149. ;;window-organizer
  150. ilookup
  151. pasteboard
  152. awk-preview
  153. recently
  154. fuzzy-finder
  155. )))
  156. (set-variable 'package-selected-packages
  157. (cl-remove-duplicates (append package-selected-packages
  158. my
  159. ()))))
  160. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  161. ;; my-idle-hook
  162. (defvar my-idle-hook nil
  163. "Hook run when idle for several secs.")
  164. (defvar my-idle-hook-sec 5
  165. "Second to run `my-idle-hook'.")
  166. (run-with-idle-timer my-idle-hook-sec
  167. t
  168. (lambda ()
  169. (run-hooks 'my-idle-hook)))
  170. ;; (add-hook 'my-idle-hook
  171. ;; (lambda ()
  172. ;; (message "idle hook message")))
  173. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  174. ;; start and quit
  175. (setq inhibit-startup-message t)
  176. (setq initial-buffer-choice 'messages-buffer)
  177. (setq confirm-kill-emacs 'y-or-n-p)
  178. ;; (setq gc-cons-threshold (* 1024 1024 16))
  179. (setq garbage-collection-messages nil)
  180. (when window-system
  181. (add-to-list 'default-frame-alist '(cursor-type . box))
  182. (add-to-list 'default-frame-alist '(background-color . "white"))
  183. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  184. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  185. ;; does not work?
  186. )
  187. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  188. (menu-bar-mode 1)
  189. (define-key ctl-x-map "M" 'menu-bar-open)
  190. (defalias 'menu 'menu-bar-open)
  191. (and (fboundp 'tool-bar-mode)
  192. (tool-bar-mode 0))
  193. (and (fboundp 'set-scroll-bar-mode)
  194. (set-scroll-bar-mode nil))
  195. (eval-after-init
  196. (message "%s %s" invocation-name emacs-version)
  197. (message "Invocation directory: %s" default-directory)
  198. (message "%s was taken to initialize emacs." (emacs-init-time))
  199. ;; (view-echo-area-messages)
  200. ;; (view-emacs-news)
  201. )
  202. (with-current-buffer "*Messages*"
  203. (emacs-lock-mode 'kill))
  204. (cd ".") ; when using windows use / instead of \ in `default-directory'
  205. ;; locale
  206. (set-language-environment "Japanese")
  207. (set-default-coding-systems 'utf-8-unix)
  208. (prefer-coding-system 'utf-8-unix)
  209. (setq system-time-locale "C")
  210. ;; my prefix map
  211. (defvar my-prefix-map nil
  212. "My prefix map.")
  213. (define-prefix-command 'my-prefix-map)
  214. (global-set-key (kbd "C-^") 'my-prefix-map)
  215. ;; (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  216. ;; (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  217. ;; (comint-show-maximum-output)
  218. ;; kill scratch
  219. (eval-after-init
  220. (let ((buf (get-buffer "*scratch*")))
  221. (when buf
  222. (kill-buffer buf))))
  223. ;; modifier keys
  224. ;; (setq mac-option-modifier 'control)
  225. ;; display
  226. (setq visible-bell t)
  227. (setq ring-bell-function 'ignore)
  228. (mouse-avoidance-mode 'banish)
  229. (setq echo-keystrokes 0.1)
  230. (defun reload-init-file ()
  231. "Reload Emacs init file."
  232. (interactive)
  233. (when (and user-init-file
  234. (file-readable-p user-init-file))
  235. (load-file user-init-file)))
  236. (require 'session nil t)
  237. ;; server
  238. (set-variable 'server-name (concat "server"
  239. (number-to-string (emacs-pid))))
  240. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  241. ;; In Darwin environment, init fails with message like 'Service name too long'
  242. ;; when server-use-tcp is nil
  243. (when (or (eq system-type
  244. 'cygwin)
  245. (eq system-type
  246. 'darwin))
  247. (set-variable 'server-use-tcp t))
  248. (add-hook 'server-visit-hook
  249. (lambda ()
  250. (use-local-map (copy-keymap (current-local-map)))
  251. (local-set-key (kbd "C-c C-c") 'server-edit)
  252. ))
  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. ;; This is often fired mistakenly
  281. (define-key ctl-x-map "h" 'ignore) ;; Previously mark-whole-buffer
  282. (define-key help-map "a" 'apropos)
  283. ;; disable annoying keys
  284. (global-set-key [prior] 'ignore)
  285. (global-set-key (kbd "<next>") 'ignore)
  286. (global-set-key [menu] 'ignore)
  287. (global-set-key [down-mouse-1] 'ignore)
  288. (global-set-key [down-mouse-2] 'ignore)
  289. (global-set-key [down-mouse-3] 'ignore)
  290. (global-set-key [mouse-1] 'ignore)
  291. (global-set-key [mouse-2] 'ignore)
  292. (global-set-key [mouse-3] 'ignore)
  293. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  294. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  295. ;; Interactively evaluate Emacs Lisp expressions
  296. (define-key ctl-x-map "i" 'ielm)
  297. (when (fboundp 'which-key-mode)
  298. (set-variable 'which-key-idle-delay 0.3)
  299. (which-key-mode 1))
  300. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  301. ;; editor
  302. ;; Basically it should not set globally (instead use something like file local
  303. ;; variables or editorconfig), but for most cases I just need this...
  304. (defun my-set-require-final-newline ()
  305. "Set `require-final-newline'."
  306. (set (make-local-variable 'require-final-newline)
  307. mode-require-final-newline))
  308. (add-hook 'prog-mode-hook
  309. 'my-set-require-final-newline)
  310. (add-hook 'text-mode-hook
  311. 'my-set-require-final-newline)
  312. (add-hook 'conf-mode-hook
  313. 'my-set-require-final-newline)
  314. ;; Used from term-cursor
  315. ;; hbar is too hard to find...
  316. (defun my-cursor-type-change (&rest args)
  317. "ARGS are discarded."
  318. ;; TODO: Support wdired and wgrep
  319. (if buffer-read-only
  320. (setq cursor-type 'hbar)
  321. (setq cursor-type 'box)))
  322. ;; (add-hook 'switch-buffer-functions
  323. ;; 'my-cursor-type-change)
  324. ;; (add-hook 'read-only-mode-hook
  325. ;; 'my-cursor-type-change)
  326. ;; (when (fboundp 'global-term-cursor-mode)
  327. ;; (global-term-cursor-mode 1))
  328. ;; ;; (term-cursor--eval)
  329. (setq kill-whole-line t)
  330. (setq scroll-conservatively 35
  331. scroll-margin 2)
  332. (setq-default major-mode 'text-mode)
  333. (setq next-line-add-newlines nil)
  334. (setq kill-read-only-ok t)
  335. ;; (setq-default line-spacing 0.2)
  336. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  337. ;; (setq-default tab-width 4)
  338. (setq-default indent-tabs-mode nil)
  339. (setq-default indent-line-function 'indent-to-left-margin)
  340. ;; (setq-default indent-line-function nil)
  341. ;; (setq-default truncate-lines t)
  342. ;; (setq truncate-partial-width-windows nil) ; when splitted horizontally
  343. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  344. (delete-selection-mode 1)
  345. (cua-mode 0)
  346. (setq line-move-visual nil)
  347. (setq create-lockfiles nil)
  348. (setq set-mark-command-repeat-pop t)
  349. (add-hook 'before-save-hook
  350. 'time-stamp)
  351. ;; Add Time-stamp: <> to insert timestamp there
  352. (set-variable 'time-stamp-format
  353. "%:y-%02m-%02d %02H:%02M:%02S %Z 10sr")
  354. ;; key bindings
  355. ;; moving around
  356. ;;(keyboard-translate ?\M-j ?\C-j)
  357. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  358. (define-key esc-map "p" 'backward-paragraph)
  359. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  360. (define-key esc-map "n" 'forward-paragraph)
  361. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  362. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  363. (global-set-key (kbd "C-<left>") 'scroll-down)
  364. (global-set-key (kbd "C-<right>") 'scroll-up)
  365. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  366. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  367. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  368. ;; C-h and DEL
  369. (global-set-key (kbd "C-h") (kbd "DEL"))
  370. ;; (normal-erase-is-backspace-mode 1)
  371. ;; M-SPC fixup-whitespace]
  372. ;; (when (fboundp 'global-hungry-delete-mode)
  373. ;; (set-variable 'hungry-delete-join-reluctantly t)
  374. ;; (add-hook 'after-first-visit-hook
  375. ;; 'global-hungry-delete-mode))
  376. ;;(global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  377. (global-set-key (kbd "C-m") 'newline-and-indent)
  378. ;; (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  379. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  380. (define-key esc-map "u" 'undo)
  381. (define-key esc-map "i" (kbd "ESC TAB"))
  382. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  383. ;; (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  384. ;; (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  385. (if (locate-library "prescient")
  386. (progn
  387. (declare-function prescient-fuzzy-regexp
  388. "prescient")
  389. (autoload 'prescient-fuzzy-regexp
  390. "prescient")
  391. (set-variable 'search-default-mode
  392. (lambda (orig lax)
  393. (prescient-fuzzy-regexp orig))))
  394. (set-variable 'search-default-mode t))
  395. ;; (set-variable 'search-whitespace-regexp ".*?")
  396. ;; (set-variable 'isearch-regexp-lax-whitespace t)
  397. ;; (replace-regexp-in-string "\n" "" (prescient-fuzzy-regexp "abc"))
  398. ;; (string-match-p (prescient-fuzzy-regexp "abc") "aaa\nbc")
  399. ;; (isearch-symbol-regexp "abc def" nil)
  400. ;; (isearch-symbol-regexp "abc def" t)
  401. ;; (word-search-regexp "abc def" nil)
  402. ;; (word-search-regexp "abc def" t)
  403. (when (fboundp 'undo-fu-only-undo)
  404. (global-set-key (kbd "C-_") 'undo-fu-only-undo))
  405. (when (fboundp 'undo-fu-only-redo)
  406. (global-set-key (kbd "C-M-_") 'undo-fu-only-redo))
  407. (require 'page-ext nil t)
  408. (when (fboundp 'global-page-break-lines-mode)
  409. (add-hook 'after-first-visit-hook
  410. 'global-page-break-lines-mode))
  411. (with-eval-after-load 'page-break-lines
  412. (set-face-foreground 'page-break-lines
  413. "cyan")
  414. )
  415. (defun my-insert-page-break ()
  416. "Insert ^L."
  417. (interactive)
  418. (insert "\^L\n"))
  419. (define-key esc-map (kbd "C-m") 'my-insert-page-break)
  420. (when (fboundp 'global-git-gutter-mode)
  421. (add-hook 'after-first-visit-hook
  422. 'global-git-gutter-mode))
  423. (with-eval-after-load 'git-gutter
  424. (declare-function global-git-gutter-mode "git-gutter")
  425. (custom-set-variables
  426. '(git-gutter:lighter " Gttr"))
  427. (custom-set-variables
  428. '(git-gutter:update-interval 2))
  429. (custom-set-variables
  430. '(git-gutter:unchanged-sign " "))
  431. (when (>= (display-color-cells)
  432. 256)
  433. (let ((c "color-233"))
  434. (set-face-background 'git-gutter:modified c)
  435. (set-face-background 'git-gutter:added c)
  436. (set-face-background 'git-gutter:deleted c)
  437. (set-face-background 'git-gutter:unchanged c)))
  438. (set-face-background 'git-gutter:modified "magenta")
  439. (set-face-background 'git-gutter:added "green")
  440. (set-face-background 'git-gutter:deleted "red")
  441. )
  442. ;; (when (fboundp 'fancy-narrow-mode)
  443. ;; (add-hook 'after-first-visit-hook
  444. ;; 'fancy-narrow-mode))
  445. ;; https://solist.work/blog/posts/mark-ring/
  446. (set-variable 'mark-ring-max 32)
  447. (defun my-exchange-point-and-mark ()
  448. "`exchange-point-and-mark' without mark activation."
  449. (interactive)
  450. (exchange-point-and-mark)
  451. (deactivate-mark))
  452. (define-key ctl-x-map (kbd "C-x") 'my-exchange-point-and-mark)
  453. (when (fboundp 'counsel-mark-ring)
  454. (define-key ctl-x-map "m" 'counsel-mark-ring))
  455. ;; ?
  456. ;; (with-eval-after-load 'ivy
  457. ;; (defvar ivy-sort-functions-alist)
  458. ;; (add-to-list 'ivy-sort-functions-alist
  459. ;; '(counsel-mark-ring)))
  460. (run-with-idle-timer 10 t
  461. (lambda ()
  462. (push-mark)
  463. ;; (when (fboundp 'visible-mark-move-overlays)
  464. ;; (visible-mark-move-overlays))
  465. ))
  466. (add-hook 'switch-buffer-functions
  467. (lambda (&rest _)
  468. (unless (or (mark t)
  469. (minibufferp))
  470. (push-mark))))
  471. (add-hook 'switch-buffer-functions
  472. (lambda (&rest _)
  473. (when (minibufferp)
  474. ;; Remove mark in minibuffer
  475. (set-mark nil))))
  476. ;; (when (fboundp 'back-button-mode)
  477. ;; (back-button-mode 1))
  478. ;; (when (fboundp 'back-button-local-forward)
  479. ;; (global-set-key (kbd "<right>") 'back-button-local-forward))
  480. ;; (when (fboundp 'back-button-local-backward)
  481. ;; (global-set-key (kbd "<left>") 'back-button-local-backward))
  482. (when (fboundp 'global-visible-mark-mode)
  483. (set-variable 'visible-mark-max 2)
  484. ;; (set-variable 'visible-mark-faces '(visible-mark-face1 visible-mark-face2))
  485. ;; http://emacs.rubikitch.com/visible-mark/
  486. ;; transient-mark-modeでC-SPC C-SPC、あるいはC-SPC C-gすると消えるバグ修正
  487. (defun visible-mark-move-overlays--avoid-disappear (&rest them)
  488. "Fix.
  489. THEM are function and its args."
  490. (let ((mark-active t)) (apply them)))
  491. (advice-add 'visible-mark-move-overlays
  492. :around
  493. 'visible-mark-move-overlays--avoid-disappear)
  494. ;; (global-visible-mark-mode 1)
  495. )
  496. ;; visible-mark-mode
  497. ;; visible-mark-overlays
  498. ;; mark-ring
  499. ;; (equal mark-ring (cl-copy-list mark-ring))
  500. (when (fboundp 'global-hardhat-mode)
  501. (with-eval-after-load 'hardhat
  502. (defvar hardhat-fullpath-protected-regexps)
  503. (add-to-list 'hardhat-fullpath-protected-regexps
  504. "/\\.venv/")
  505. (defvar hardhat-fullpath-editable-regexps)
  506. (add-to-list 'hardhat-fullpath-editable-regexps
  507. "/\\.git/hooks/.*'")
  508. (add-to-list 'hardhat-fullpath-editable-regexps
  509. "/\\.git/EDIT_INDEX\\.diff\\'")
  510. (defvar hardhat-basename-editable-regexps)
  511. (add-to-list 'hardhat-basename-editable-regexps
  512. "\\`Pipfile.lock\\'")
  513. )
  514. (global-hardhat-mode 1))
  515. (with-eval-after-load 'ignoramus
  516. (defvar ignoramus-file-basename-exact-names)
  517. (set-variable 'ignoramus-file-basename-exact-names
  518. (delete "profile"
  519. ignoramus-file-basename-exact-names))
  520. (set-variable 'ignoramus-file-basename-exact-names
  521. (delete "Profile"
  522. ignoramus-file-basename-exact-names))
  523. )
  524. ;; Fill column
  525. (setq-default fill-column 80)
  526. ;; (add-hook 'text-mode-hook 'turn-on-auto-fill)
  527. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  528. ;; title and mode-line
  529. (when (fboundp 'terminal-title-mode)
  530. ;; if TERM is not screen use default value
  531. (if (getenv "TMUX")
  532. ;; if use tmux locally just basename of current dir
  533. (set-variable 'terminal-title-format
  534. '((file-name-nondirectory (directory-file-name
  535. default-directory))))
  536. (if (and (let ((tty-type (frame-parameter nil
  537. 'tty-type)))
  538. (and tty-type
  539. (equal (car (split-string tty-type
  540. "-"))
  541. "screen")))
  542. (not (getenv "SSH_CONNECTION")))
  543. (set-variable 'terminal-title-format
  544. '((file-name-nondirectory (directory-file-name
  545. default-directory))))
  546. ;; seems that TMUX is used locally and ssh to remote host
  547. (set-variable 'terminal-title-format
  548. `("em:"
  549. ,user-login-name
  550. "@"
  551. ,(car (split-string (system-name)
  552. "\\."))
  553. ":"
  554. default-directory))
  555. )
  556. )
  557. (terminal-title-mode))
  558. (setq eol-mnemonic-dos "\\r\\n")
  559. (setq eol-mnemonic-mac "\\r")
  560. (setq eol-mnemonic-unix "")
  561. (add-hook 'after-first-visit-hook
  562. 'which-function-mode)
  563. (line-number-mode 0)
  564. (column-number-mode 0)
  565. (size-indication-mode 0)
  566. (setq mode-line-position
  567. '(:eval (format ":%%l:%%c /%d%s"
  568. (count-lines (point-max)
  569. (point-min))
  570. (if (buffer-narrowed-p)
  571. "[N]"
  572. "")
  573. )))
  574. (when (fboundp 'diminish)
  575. (eval-after-init
  576. (diminish 'recently-mode)
  577. (diminish 'editorconfig-mode)
  578. (diminish 'which-key-mode)
  579. )
  580. (with-eval-after-load 'whitespace
  581. (diminish 'global-whitespace-mode))
  582. (with-eval-after-load 'page-break-lines
  583. (diminish 'page-break-lines-mode))
  584. (with-eval-after-load 'auto-highlight-symbol
  585. (diminish 'auto-highlight-symbol-mode))
  586. (with-eval-after-load 'color-identifiers-mode
  587. (diminish 'color-identifiers-mode))
  588. (with-eval-after-load 'highlight-indentation
  589. (diminish 'highlight-indentation-mode))
  590. (with-eval-after-load 'back-button
  591. (diminish 'back-button-mode))
  592. (with-eval-after-load 'git-gutter
  593. (diminish 'git-gutter-mode))
  594. (with-eval-after-load 'autorevert
  595. (diminish 'auto-revert-mode))
  596. )
  597. (setq mode-line-front-space "")
  598. ;; (setq mode-line-end-spaces "")
  599. ;; Set current frame name to empty string
  600. (setq-default mode-line-format
  601. (let* ((l mode-line-format)
  602. (l (cl-substitute " " " "
  603. l
  604. :test 'equal))
  605. (l (cl-substitute " " " "
  606. l
  607. :test 'equal))
  608. )
  609. l))
  610. (set-frame-parameter nil 'name "")
  611. ;; See color-name-rgb-alist for available color names
  612. ;; http://www.raebear.net/computers/emacs-colors/
  613. ;; https://www.emacswiki.org/emacs/ListColors
  614. ;; (list-colors-display is not a complete list)
  615. (defconst my-mode-line-background-default
  616. (face-background 'mode-line)
  617. "Default color of mode-line at init.")
  618. (defun my-mode-line-color-update (&rest args)
  619. "ARGS are discarded"
  620. (let ((ro "skyblue")
  621. (rw my-mode-line-background-default))
  622. (if (or (not buffer-read-only)
  623. (and (eq major-mode 'wdired-mode)))
  624. (set-face-background 'mode-line
  625. rw)
  626. (set-face-background 'mode-line
  627. ro))))
  628. (add-hook 'switch-buffer-functions
  629. 'my-mode-line-color-update)
  630. (add-hook 'read-only-mode-hook
  631. 'my-mode-line-color-update)
  632. (add-hook 'wdired-mode-hook
  633. 'my-mode-line-color-update)
  634. (advice-add 'wdired-change-to-dired-mode
  635. :after
  636. 'my-mode-line-color-update)
  637. (advice-add 'wgrep-change-to-wgrep-mode
  638. :after
  639. 'my-mode-line-color-update)
  640. (advice-add 'wgrep-to-original-mode
  641. :after
  642. 'my-mode-line-color-update)
  643. (with-eval-after-load 'hardhat
  644. ;; hardhat-mode-hook does not work as expected...
  645. (advice-add 'hardhat-local-hook
  646. :after
  647. 'my-mode-line-color-update))
  648. (set-face-background 'header-line
  649. my-mode-line-background-default)
  650. ;; sky-color-clock
  651. ;; https://tsuu32.hatenablog.com/entry/2019/11/07/020005
  652. (declare-function sky-color-clock "sky-color-clock")
  653. (declare-function sky-color-clock-initialize "sky-color-clock")
  654. (defun sky-color-clock--form ()
  655. "Gen string for right aligned form."
  656. (let* ((sky-color-clock-str
  657. (propertize (sky-color-clock) 'help-echo (format-time-string "Sky color clock\n%F (%a)")))
  658. (mode-line-right-margin
  659. (propertize " " 'display `(space :align-to (- right-fringe ,(length sky-color-clock-str))))))
  660. (concat mode-line-right-margin sky-color-clock-str)))
  661. (when (require 'sky-color-clock nil t)
  662. (sky-color-clock-initialize 35) ; Tokyo, Japan
  663. (set-variable 'sky-color-clock-format "%H:%M")
  664. (set-variable 'sky-color-clock-enable-emoji-icon nil)
  665. (setq mode-line-end-spaces '(:eval (sky-color-clock--form))))
  666. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  667. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  668. ;; minibuffer
  669. (setq insert-default-directory t)
  670. (setq completion-ignore-case t
  671. read-file-name-completion-ignore-case t
  672. read-buffer-completion-ignore-case t)
  673. (setq resize-mini-windows t)
  674. (temp-buffer-resize-mode 1)
  675. (savehist-mode 1)
  676. (defvar display-time-format "%Y/%m/%d %a %H:%M")
  677. (set-variable 'help-at-pt-display-when-idle t)
  678. (fset 'yes-or-no-p 'y-or-n-p)
  679. ;; complete symbol when `eval'
  680. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  681. (define-key minibuffer-local-map (kbd "C-u")
  682. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  683. ;; I dont know these bindings are good
  684. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  685. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  686. (with-eval-after-load 'minibuffer-line
  687. (set-face-underline 'minibuffer-line nil)
  688. )
  689. (with-eval-after-load 'git-ps1-mode
  690. (defvar git-ps1-mode-ps1-file-candidates-list)
  691. (add-to-list 'git-ps1-mode-ps1-file-candidates-list
  692. "/Library/Developer/CommandLineTools/usr/share/git-core/git-prompt.sh"))
  693. (when (fboundp 'minibuffer-line-mode)
  694. (set-variable 'minibuffer-line-refresh-interval
  695. 25)
  696. ;; Set idle timer
  697. (defvar my-minibuffer-line--idle-timer nil)
  698. (defvar minibuffer-line-mode)
  699. (add-hook 'minibuffer-line-mode-hook
  700. (lambda ()
  701. (when my-minibuffer-line--idle-timer
  702. (cancel-timer my-minibuffer-line--idle-timer)
  703. (setq my-minibuffer-line--idle-timer nil))
  704. (when minibuffer-line-mode
  705. (setq my-minibuffer-line--idle-timer
  706. (run-with-idle-timer 0.5
  707. t
  708. 'minibuffer-line--update)))))
  709. (set-variable 'minibuffer-line-format
  710. `(,(concat user-login-name
  711. "@"
  712. (car (split-string (system-name)
  713. "\\."))
  714. ":")
  715. (:eval (abbreviate-file-name (or buffer-file-name
  716. default-directory)))
  717. (:eval (and (fboundp 'git-ps1-mode-get-current)
  718. (git-ps1-mode-get-current " [GIT:%s]")))
  719. " "
  720. (:eval (format-time-string display-time-format))))
  721. (when (eval-and-compile (require 'nyan-mode nil t))
  722. (set-variable 'minibuffer-line-format
  723. '((:eval (progn
  724. (list (nyan-create))))))
  725. (defun my-nyan-set-length (&rest _)
  726. "Set `nyan-mode' length to window width."
  727. (set-variable 'nyan-bar-length
  728. (- (frame-parameter nil 'width) 4)))
  729. ;; (my-nyan-set-length)
  730. ;; (add-hook 'after-init-hook
  731. ;; 'my-nyan-set-length)
  732. (add-hook 'window-configuration-change-hook
  733. 'my-nyan-set-length)
  734. (add-hook 'switch-buffer-functions
  735. 'my-nyan-set-length)
  736. )
  737. (minibuffer-line-mode 1)
  738. )
  739. (when (fboundp 'prompt-text-mode)
  740. (set-variable 'prompt-text-format
  741. `(,(concat ""
  742. user-login-name
  743. "@"
  744. (car (split-string (system-name)
  745. "\\."))
  746. ":")
  747. (:eval (abbreviate-file-name (or buffer-file-name
  748. default-directory)))
  749. (:eval (and (fboundp 'git-ps1-mode-get-current)
  750. (git-ps1-mode-get-current " [GIT:%s]")))
  751. " "
  752. (:eval (format-time-string display-time-format))
  753. "\n"
  754. (:eval (symbol-name this-command))
  755. ": "))
  756. (prompt-text-mode 1))
  757. (with-eval-after-load 'helm
  758. (defvar helm-map)
  759. (define-key helm-map (kbd "C-h") (kbd "DEL")))
  760. (defun my-shrink-path-width (path width)
  761. "Shrink PATH to be same or shorter than WIDTH."
  762. (setq path (abbreviate-file-name path))
  763. (if (file-remote-p path)
  764. (let* ((remote (file-remote-p path))
  765. (localname (file-remote-p path 'localname))
  766. (remote-length (length remote))
  767. (width-localname (- width remote-length))
  768. (localname-shrinked (my-shrink-path-width localname width-localname)))
  769. (concat remote localname-shrinked))
  770. (let ((yet (split-string path "/"))
  771. (done nil)
  772. (result path))
  773. (while (and yet
  774. (< width (length result)))
  775. (let ((current (pop yet)))
  776. (unless (string= "" current)
  777. (setq current (substring current 0 1)))
  778. (setq done
  779. (append done (list current))))
  780. (setq result
  781. (concat (mapconcat 'identity
  782. (append done yet)
  783. "/"))))
  784. result)))
  785. ;; (my-shrink-path-width "/Applications/Vivaldi.app/Contents/MacOS/Vivaldi" 20)
  786. ;; (my-shrink-path-width "/scp:sakura:/Applications/Vivaldi.app/Contents/MacOS/Vivaldi" 30)
  787. ;; (my-shrink-path-width "/scp:sakura:/Applications/Vivaldi.app/Contents/MacOS/Vivaldi" 20)
  788. (setq-default header-line-format
  789. '(:eval (let ((f (or (buffer-file-name)
  790. default-directory)))
  791. (when f
  792. (my-shrink-path-width f (window-width))))))
  793. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  794. ;; letters, font-lock mode and fonts
  795. (when (fboundp 'color-identifiers-mode)
  796. (add-hook 'prog-mode-hook
  797. 'color-identifiers-mode))
  798. (setq text-quoting-style 'grave)
  799. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  800. ;; (set-window-margins (selected-window) 1 1)
  801. (unless window-system
  802. (setq frame-background-mode 'dark))
  803. (and (or (eq system-type 'Darwin)
  804. (eq system-type 'darwin))
  805. (fboundp 'mac-set-input-method-parameter)
  806. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  807. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  808. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  809. (boundp 'input-method-inactivate-hook))
  810. (add-hook 'input-method-activate-hook
  811. (lambda () (set-cursor-color "red")))
  812. (add-hook 'input-method-inactivate-hook
  813. (lambda () (set-cursor-color "black"))))
  814. (when (fboundp 'show-paren-mode)
  815. (add-hook 'after-first-visit-hook
  816. 'show-paren-mode))
  817. (set-variable 'show-paren-delay 0.5)
  818. (set-variable 'show-paren-style 'parenthesis) ; mixed is hard to read
  819. ;; (set-face-background 'show-paren-match
  820. ;; "black")
  821. ;; ;; (face-foreground 'default))
  822. ;; (set-face-foreground 'show-paren-match
  823. ;; "white")
  824. ;; (set-face-inverse-video-p 'show-paren-match
  825. ;; t)
  826. (transient-mark-mode 1)
  827. (global-font-lock-mode 1)
  828. (setq font-lock-global-modes
  829. '(not
  830. help-mode
  831. eshell-mode
  832. ;;term-mode
  833. Man-mode
  834. ))
  835. ;; (standard-display-ascii ?\n "$\n")
  836. ;; (defvar my-eol-face
  837. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  838. ;; )
  839. ;; (defvar my-tab-face
  840. ;; '(("\t" . '(0 highlight t nil))))
  841. (defvar my-jspace-face
  842. '(("\u3000" . '(0 highlight t nil))))
  843. (add-hook 'font-lock-mode-hook
  844. (lambda ()
  845. ;; (font-lock-add-keywords nil my-eol-face)
  846. (font-lock-add-keywords nil my-jspace-face)
  847. ))
  848. (set-variable 'font-lock-maximum-decoration
  849. '(
  850. ;; (python-mode . 2)
  851. (t . 2)
  852. ))
  853. (when (fboundp 'global-whitespace-mode)
  854. (add-hook 'after-first-visit-hook
  855. 'global-whitespace-mode))
  856. (add-hook 'dired-mode-hook
  857. ;; Other way to disable in dired buffers?
  858. (lambda () (set-variable 'whitespace-style nil t)))
  859. (with-eval-after-load 'whitespace
  860. (defvar whitespace-display-mappings)
  861. (defvar whitespace-mode)
  862. (add-to-list 'whitespace-display-mappings
  863. ;; We need t since last one takes precedence
  864. `(tab-mark ?\t ,(vconcat "|>\t")) t)
  865. ;; (add-to-list 'whitespace-display-mappings
  866. ;; `(newline-mark ?\n ,(vconcat "$\n")))
  867. (set-variable 'whitespace-style '(face
  868. trailing ; trailing blanks
  869. ;; tabs
  870. ;; spaces
  871. ;; lines
  872. lines-tail ; lines over 80
  873. newline ; newlines
  874. ;; empty ; empty lines at beg or end of buffer
  875. ;; big-indent
  876. ;; space-mark
  877. tab-mark
  878. newline-mark ; use display table for newline
  879. ))
  880. ;; (setq whitespace-newline 'font-lock-comment-face)
  881. ;; (setq whitespace-style (delq 'newline-mark whitespace-style))
  882. (defun my-whitesspace-mode-reload ()
  883. "Reload whitespace-mode config."
  884. (interactive)
  885. (when whitespace-mode
  886. (whitespace-mode 0)
  887. (whitespace-mode 1)))
  888. (set-variable 'whitespace-line-column nil) ; Use value of `fill-column'
  889. (when (>= (display-color-cells)
  890. 256)
  891. (set-face-foreground 'whitespace-newline "color-109")
  892. (set-face-foreground 'whitespace-line
  893. nil)
  894. (set-face-background 'whitespace-line
  895. "gray35")
  896. ;; (progn
  897. ;; (set-face-bold-p 'whitespace-newline
  898. ;; t))
  899. ))
  900. (defun my-gen-hl-line-color-dark ()
  901. "Generate color for current line in black background."
  902. (let* ((candidates (mapcar 'number-to-string (number-sequence 1 6)))
  903. (limit (length candidates))
  904. (r 0) (g 0) (b 0))
  905. (while (and (<= (abs (- r g)) 1)
  906. (<= (abs (- g b)) 1)
  907. (<= (abs (- b r)) 1))
  908. (setq r (random limit))
  909. (setq g (random limit))
  910. (setq b (random limit)))
  911. (format "#%s%s%s"
  912. (nth r candidates)
  913. (nth g candidates)
  914. (nth b candidates)
  915. )))
  916. ;; (my-gen-hl-line-color-dark)
  917. ;; highlight current line
  918. ;; http://wiki.riywo.com/index.php?Meadow
  919. (face-spec-set 'hl-line
  920. `((((min-colors 256)
  921. (background dark))
  922. ;; Rotate midnightblue
  923. (:background ,(my-gen-hl-line-color-dark)))
  924. (((min-colors 256)
  925. (background light))
  926. ;; TODO: What is should be?
  927. (:background "color-234"))
  928. (t
  929. (:underline "black"))))
  930. (set-variable 'hl-line-global-modes
  931. '(not
  932. term-mode))
  933. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  934. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  935. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  936. ;;(require 'set-modeline-color nil t)
  937. ;; (let ((fg (face-foreground 'default))
  938. ;; (bg (face-background 'default)))
  939. ;; (set-face-background 'mode-line-inactive
  940. ;; (if (face-inverse-video-p 'mode-line) fg bg))
  941. ;; (set-face-foreground 'mode-line-inactive
  942. ;; (if (face-inverse-video-p 'mode-line) bg fg)))
  943. ;; (set-face-underline 'mode-line-inactive
  944. ;; t)
  945. ;; (set-face-underline 'vertical-border
  946. ;; nil)
  947. ;; (when (require 'end-mark nil t)
  948. ;; (global-end-mark-mode))
  949. ;; M-x highlight-* to highlight things
  950. (global-hi-lock-mode 1)
  951. (unless (fboundp 'highlight-region-text)
  952. (defun highlight-region-text (beg end)
  953. "Highlight text between BEG and END."
  954. (interactive "r")
  955. (highlight-regexp (regexp-quote (buffer-substring-no-properties beg
  956. end)))
  957. (setq deactivate-mark t)))
  958. (when (fboundp 'auto-highlight-symbol-mode)
  959. (add-hook 'prog-mode-hook
  960. 'auto-highlight-symbol-mode))
  961. ;; Not work in combination with flyspell-mode
  962. ;; (when (fboundp 'global-auto-highlight-symbol-mode)
  963. ;; (add-hook 'after-first-visit-hook
  964. ;; 'global-auto-highlight-symbol-mode))
  965. (set-variable 'ahs-idle-interval 0.6)
  966. (when (fboundp 'highlight-indentation-mode)
  967. (dolist (hook
  968. '(
  969. prog-mode-hook
  970. text-mode-hook
  971. ))
  972. ;; Makes display slow?
  973. ;; (add-hook hook
  974. ;; 'highlight-indentation-mode)
  975. ))
  976. (with-eval-after-load 'highlight-indentation
  977. (set-face-background 'highlight-indentation-face "color-236"))
  978. ;; (set-face-background 'highlight-indentation-current-column-face "#c3b3b3")
  979. (when (fboundp 'fic-mode)
  980. (add-hook 'prog-mode-hook
  981. 'fic-mode))
  982. (when (fboundp 'global-tree-sitter-mode)
  983. (add-hook 'after-first-visit-hook
  984. 'global-tree-sitter-mode)
  985. (add-hook 'tree-sitter-after-on-hook
  986. 'tree-sitter-hl-mode))
  987. (with-eval-after-load 'tree-sitter
  988. (require 'tree-sitter-langs nil t))
  989. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  990. ;; file handling
  991. (auto-insert-mode 1)
  992. ;; fuzzy-finder
  993. (set-variable 'fuzzy-finder-executable "fzf")
  994. (set-variable 'fuzzy-finder-default-arguments
  995. (concat "--ansi "
  996. "--color='bg+:-1' "
  997. "--inline-info "
  998. "--cycle "
  999. "--reverse "
  1000. "--multi "
  1001. "--print0 "
  1002. "--prompt=\"[`pwd`]> \" "))
  1003. (set-variable 'fuzzy-finder-default-output-delimiter
  1004. "\0")
  1005. (set-variable 'fuzzy-finder-default-input-command
  1006. (let ((find (or (executable-find "bfs") ;; Breadth-first find https://github.com/tavianator/bfs
  1007. ;; Use gfind if available?
  1008. "find"))
  1009. (fd (or (executable-find "fdfind")
  1010. (executable-find "fd"))))
  1011. (if fd
  1012. (concat "set -eu; set -o pipefail; "
  1013. "echo .; "
  1014. "echo ..; "
  1015. "command " fd " "
  1016. "--follow --hidden --no-ignore "
  1017. "--color always "
  1018. "2>/dev/null")
  1019. (concat "set -eu; set -o pipefail; "
  1020. "echo .; "
  1021. "echo ..; "
  1022. "command " find " -L . "
  1023. "-mindepth 1 "
  1024. "\\( -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune "
  1025. "-o -print "
  1026. "2> /dev/null "
  1027. "| "
  1028. "cut -b3-"))))
  1029. (declare-function fuzzy-finder
  1030. "fuzzy-finder")
  1031. (declare-function fuzzy-finder-find-files-projectile
  1032. "fuzzy-finder")
  1033. (defun my-fuzzy-finder-or-find-file ()
  1034. "Call `fuzzy-finder' if usable or call `find-file'."
  1035. (declare (interactive-only t))
  1036. (interactive)
  1037. (if (and (executable-find "fzf")
  1038. (fboundp 'fuzzy-finder)
  1039. (not (file-remote-p default-directory)))
  1040. (fuzzy-finder-find-files-projectile)
  1041. (call-interactively 'find-file)))
  1042. (define-key ctl-x-map "f" 'my-fuzzy-finder-or-find-file)
  1043. (declare-function fuzzy-finder-action-find-files-goto-line
  1044. "fuzzy-finder")
  1045. (defun my-fuzzy-finder-ripgrep-lines ()
  1046. "Fzf all lines."
  1047. (interactive)
  1048. (unless (executable-find "rg")
  1049. (error "rg not found"))
  1050. (fuzzy-finder :input-command "rg -nH --no-heading --hidden --follow --glob '!.git/*' --color=always ^"
  1051. :action 'fuzzy-finder-action-find-files-goto-line))
  1052. (define-key ctl-x-map "S" 'my-fuzzy-finder-ripgrep-lines)
  1053. (defun my-fuzzy-finder-dired ()
  1054. "Fuzzy finder directory."
  1055. (interactive)
  1056. (fuzzy-finder :input-command "fd --hidden --no-ignore --type directory"
  1057. :directory (expand-file-name "~")))
  1058. (define-key ctl-x-map "d" 'my-fuzzy-finder-dired)
  1059. ;; (set-variable 'fuzzy-finder-default-command "selecta")
  1060. ;; (set-variable 'fuzzy-finder-default-command "peco")
  1061. ;; (set-variable 'fuzzy-finder-default-command "percol")
  1062. ;; (set-variable 'fuzzy-finder-default-command "fzy")
  1063. ;; (set-variable 'fuzzy-finder-default-command "sk --ansi --no-hscroll --reverse")
  1064. ;; (set-variable 'fuzzy-finder-default-command "pick")
  1065. ;; recently
  1066. ;; TODO: Enable after first visit file?
  1067. (with-eval-after-load 'recently
  1068. (defvar recently-excludes)
  1069. (add-to-list 'recently-excludes
  1070. (rx-to-string (list 'and
  1071. 'string-start
  1072. (expand-file-name package-user-dir))
  1073. t)))
  1074. (when (fboundp 'recently-mode)
  1075. (define-key ctl-x-map (kbd "C-r") 'recently-show)
  1076. (set-variable 'recently-max 1000)
  1077. (recently-mode 1))
  1078. (defvar my-cousel-recently-history nil "History of `my-counsel-recently'.")
  1079. (declare-function recently-list "recently" t)
  1080. (when (and (require 'recently nil t)
  1081. (fboundp 'ivy-read))
  1082. (defun my-counsel-recently ()
  1083. "Counsel `recently'."
  1084. (interactive)
  1085. (ivy-read "Recently: " (mapcar 'abbreviate-file-name (recently-list))
  1086. :require-match t
  1087. :history 'my-cousel-recently-history
  1088. :preselect default-directory
  1089. :action (lambda (x) (find-file x))
  1090. :sort nil
  1091. :caller 'my-counsel-recently))
  1092. (define-key ctl-x-map (kbd "C-r") 'my-counsel-recently)
  1093. )
  1094. ;; (when (fboundp 'editorconfig-mode)
  1095. ;; (add-hook 'after-first-visit-hook
  1096. ;; 'editorconfig-mode)
  1097. ;; (add-hook 'after-first-visit-hook
  1098. ;; 'editorconfig-mode-apply
  1099. ;; t)) ;; Do after enabling editorconfig-mode
  1100. (when (eval-and-compile (require 'editorconfig nil t))
  1101. (set-variable 'editorconfig--enable-20210221-testing t)
  1102. (editorconfig-mode 1))
  1103. (set-variable 'editorconfig-get-properties-function
  1104. 'editorconfig-core-get-properties-hash)
  1105. (set-variable 'editorconfig-mode-lighter "")
  1106. (when (fboundp 'ws-butler-mode)
  1107. (set-variable 'editorconfig-trim-whitespaces-mode
  1108. 'ws-butler-mode))
  1109. (with-eval-after-load 'org-src
  1110. ;; [*.org\[\*Org Src*\[ c \]*\]]
  1111. (add-hook 'org-src-mode-hook
  1112. 'editorconfig-mode-apply t))
  1113. (when (fboundp 'editorconfig-custom-majormode)
  1114. (add-hook 'editorconfig-after-apply-functions
  1115. 'editorconfig-custom-majormode))
  1116. ;; Add readonly=true to set read-only-mode
  1117. (add-hook 'editorconfig-after-apply-functions
  1118. (lambda (props)
  1119. (let ((r (gethash 'readonly props)))
  1120. (when (and (string= r "true")
  1121. (not buffer-read-only))
  1122. (read-only-mode 1)))))
  1123. (add-hook 'editorconfig-after-apply-functions
  1124. (lambda (props)
  1125. (when (derived-mode-p 'makefile-mode)
  1126. (setq indent-tabs-mode t))
  1127. (when (derived-mode-p 'diff-mode)
  1128. (editorconfig-set-trailing-ws "false")
  1129. (editorconfig-set-trailing-nl "false")
  1130. )
  1131. ))
  1132. (when (fboundp 'editorconfig-auto-apply-enable)
  1133. (add-hook 'editorconfig-conf-mode-hook
  1134. 'editorconfig-auto-apply-enable))
  1135. ;; (when (fboundp 'editorconfig-charset-extras)
  1136. ;; (add-hook 'editorconfig-custom-hooks
  1137. ;; 'editorconfig-charset-extras))
  1138. (setq revert-without-query '(".+"))
  1139. ;; save cursor position
  1140. (when (fboundp 'save-place-mode)
  1141. (autoload 'save-place-find-file-hook "saveplace")
  1142. (add-hook 'after-first-visit-hook
  1143. 'save-place-mode)
  1144. (add-hook 'after-first-visit-hook
  1145. 'save-place-find-file-hook
  1146. t))
  1147. (set-variable 'save-place-file (concat user-emacs-directory
  1148. "places"))
  1149. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  1150. (setq make-backup-files t)
  1151. (setq vc-make-backup-files t)
  1152. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  1153. (setq backup-directory-alist
  1154. (cons (cons "." (expand-file-name (concat user-emacs-directory
  1155. "backup")))
  1156. backup-directory-alist))
  1157. (setq version-control 't)
  1158. (setq delete-old-versions t)
  1159. (setq kept-new-versions 20)
  1160. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  1161. "auto-save/")))
  1162. ;; (setq delete-auto-save-files t)
  1163. (setq auto-save-visited-interval 8)
  1164. (auto-save-visited-mode 1)
  1165. ;; (add-to-list 'auto-save-file-name-transforms
  1166. ;; `(".*" ,(concat user-emacs-directory "auto-save-dir") t))
  1167. ;; (setq auto-save-interval 3)
  1168. ;; (auto-save-mode 1)
  1169. (add-to-list 'completion-ignored-extensions ".bak")
  1170. (set-variable 'completion-cycle-threshold nil) ;; NEVER use
  1171. (setq delete-by-moving-to-trash t)
  1172. ;; trash-directory "~/.emacs.d/trash")
  1173. (add-hook 'after-save-hook
  1174. 'executable-make-buffer-file-executable-if-script-p)
  1175. (when (fboundp 'smart-revert-on)
  1176. (smart-revert-on))
  1177. ;; autosave
  1178. ;; auto-save-visited-mode can be used instead?
  1179. ;; (when (require 'autosave nil t)
  1180. ;; (autosave-set 8))
  1181. ;; bookmarks
  1182. (set-variable 'bookmark-default-file
  1183. (expand-file-name (concat user-emacs-directory
  1184. "bmk")))
  1185. (set-variable 'bookmark-sort-flag nil)
  1186. (defun my-bookmark-set ()
  1187. "My `bookmark-set'."
  1188. (interactive)
  1189. (cl-assert (or buffer-file-name
  1190. default-directory))
  1191. (let ((name (file-name-nondirectory (or buffer-file-name
  1192. (directory-file-name default-directory))))
  1193. (linenum (count-lines (point-min)
  1194. (point)))
  1195. (linetext (buffer-substring-no-properties (point-at-bol)
  1196. (point-at-eol))))
  1197. (bookmark-set (format "%s:%d:%s"
  1198. name linenum linetext)
  1199. nil)))
  1200. ;; Done by advice instead
  1201. ;; (set-variable 'bookmark-save-flag
  1202. ;; 1)
  1203. (with-eval-after-load 'recentf
  1204. (defvar recentf-exclude)
  1205. (defvar bookmark-default-file)
  1206. (add-to-list 'recentf-exclude
  1207. (regexp-quote bookmark-default-file)))
  1208. (defvar bookmark-default-file)
  1209. (defun my-bookmark-set--advice (orig-func &rest args)
  1210. "Function for `bookmark-set-internal'.
  1211. ORIG-FUNC is the target function, and ARGS is the argument when it is called."
  1212. (bookmark-load bookmark-default-file)
  1213. (apply orig-func args)
  1214. (bookmark-save))
  1215. (with-eval-after-load 'bookmark
  1216. (advice-add 'bookmark-set-internal
  1217. :around
  1218. 'my-bookmark-set--advice))
  1219. (define-key ctl-x-map "b" 'list-bookmarks)
  1220. (when (fboundp 'counsel-bookmark)
  1221. (define-key ctl-x-map "b" 'counsel-bookmark))
  1222. (define-key ctl-x-map "B" 'my-bookmark-set)
  1223. ;; vc
  1224. (set-variable 'vc-handled-backends '(RCS))
  1225. (set-variable 'vc-rcs-register-switches "-l")
  1226. (set-variable 'vc-rcs-checkin-switches "-l")
  1227. (set-variable 'vc-command-messages t)
  1228. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1229. ;; share clipboard with x
  1230. ;; this page describes this in details, but only these sexps seem to be needed
  1231. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  1232. (and nil
  1233. (not window-system)
  1234. (not (eq window-system 'mac))
  1235. (getenv "DISPLAY")
  1236. (not (equal (getenv "DISPLAY") ""))
  1237. (executable-find "xclip")
  1238. ;; (< emacs-major-version 24)
  1239. '(require 'xclip nil t)
  1240. nil
  1241. (turn-on-xclip))
  1242. (declare-function turn-on-pasteboard "pasteboard")
  1243. (and (eq system-type 'darwin)
  1244. (require 'pasteboard nil t)
  1245. (turn-on-pasteboard))
  1246. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1247. ;; some modes and hooks
  1248. ;; Include some extra modes
  1249. (require 'generic-x)
  1250. ;; Derived from https://github.com/ensime/ensime-emacs/issues/591#issuecomment-291916753
  1251. (defun my-scalafmt ()
  1252. (interactive)
  1253. (cl-assert buffer-file-name)
  1254. (cl-assert (not (buffer-modified-p)))
  1255. (let* ((configdir (locate-dominating-file default-directory ".scalafmt.conf"))
  1256. (configoption (if configdir
  1257. (concat " --config "
  1258. (shell-quote-argument (expand-file-name configdir))
  1259. ".scalafmt.conf"
  1260. )
  1261. ""))
  1262. (str (concat "scalafmt -f "
  1263. (shell-quote-argument buffer-file-name)
  1264. configoption
  1265. " -i --exclude ensime")))
  1266. (message str)
  1267. (shell-command-to-string str))
  1268. (message "scalafmt done")
  1269. (revert-buffer nil t))
  1270. (when (fboundp 'web-mode)
  1271. (add-to-list 'auto-mode-alist
  1272. '("\\.html\\.j2\\'" . web-mode))
  1273. (add-to-list 'auto-mode-alist
  1274. ;; Django Template Language
  1275. '("\\.dtl\\'" . web-mode))
  1276. )
  1277. (when (locate-library "wgrep")
  1278. (set-variable 'wgrep-auto-save-buffer t)
  1279. (with-eval-after-load 'grep
  1280. (defvar grep-mode-map)
  1281. (define-key grep-mode-map
  1282. "e"
  1283. 'wgrep-change-to-wgrep-mode)))
  1284. (when (fboundp 'grep-context-mode)
  1285. (add-hook 'compilation-mode-hook #'grep-context-mode))
  1286. (with-eval-after-load 'remember
  1287. (defvar remember-mode-map)
  1288. (define-key remember-mode-map (kbd "C-x C-s") 'ignore))
  1289. (set-variable 'remember-notes-initial-major-mode
  1290. 'change-log-mode)
  1291. (set-variable 'magit-define-global-key-bindings nil)
  1292. (with-eval-after-load 'magit-section
  1293. (set-face-background 'magit-section-highlight
  1294. nil))
  1295. ;; Sane colors
  1296. (with-eval-after-load 'magit-diff
  1297. (set-face-background 'magit-diff-context nil)
  1298. (set-face-background 'magit-diff-context-highlight nil)
  1299. (set-face-foreground 'magit-diff-hunk-heading nil)
  1300. (set-face-background 'magit-diff-hunk-heading nil)
  1301. (set-face-foreground 'magit-diff-hunk-heading-highlight nil)
  1302. (set-face-background 'magit-diff-hunk-heading-highlight nil)
  1303. ;; https://blog.shibayu36.org/entry/2016/03/27/220552
  1304. (set-face-foreground 'magit-diff-added "green")
  1305. (set-face-background 'magit-diff-added nil)
  1306. (set-face-foreground 'magit-diff-added-highlight "green")
  1307. (set-face-background 'magit-diff-added-highlight nil)
  1308. (set-face-foreground 'magit-diff-removed "red")
  1309. (set-face-background 'magit-diff-removed nil)
  1310. (set-face-foreground 'magit-diff-removed-highlight "red")
  1311. (set-face-background 'magit-diff-removed-highlight nil)
  1312. (set-face-background 'magit-diff-lines-boundary "blue")
  1313. )
  1314. (declare-function magit-show-commit "magit")
  1315. (defun my-magit-messenger (file line)
  1316. "Magit messenger."
  1317. (interactive (list buffer-file-name
  1318. (line-number-at-pos)))
  1319. (cl-assert file)
  1320. (cl-assert line)
  1321. (let* ((blame-args '("-w"))
  1322. (id (with-temp-buffer
  1323. (let ((exit (apply 'call-process
  1324. "git" ;; PROGRAM
  1325. nil ;; INFILE
  1326. t ;; DESTINATION
  1327. nil ;; DISPLAY
  1328. "--no-pager" ;; ARGS
  1329. "blame"
  1330. "-L"
  1331. (format "%d,+1" line)
  1332. "--porcelain"
  1333. file
  1334. blame-args
  1335. )))
  1336. (goto-char (point-min))
  1337. (cl-assert (eq exit 0)
  1338. "Failed: %s" (buffer-substring (point)
  1339. (point-at-eol)))
  1340. (save-match-data
  1341. (re-search-forward (rx buffer-start
  1342. (one-or-more hex-digit)))
  1343. (match-string 0))))))
  1344. (magit-show-commit id)))
  1345. (when (boundp 'git-rebase-filename-regexp)
  1346. (add-to-list 'auto-mode-alist
  1347. `(,git-rebase-filename-regexp . text-mode)))
  1348. (when (fboundp 'ggtags-mode)
  1349. (add-hook 'c-mode-common-hook
  1350. 'ggtags-mode)
  1351. (add-hook 'python-mode-hook
  1352. 'ggtags-mode)
  1353. (add-hook 'js-mode-hook
  1354. 'ggtags-mode)
  1355. (add-hook 'scheme-mode-hook
  1356. 'ggtags-mode)
  1357. )
  1358. (when (fboundp 'imenu-list-minor-mode)
  1359. (defvar imenu-list-buffer-name)
  1360. (defun my-imenu-list-toggle ()
  1361. "My 'imenu-list` toggle."
  1362. (interactive)
  1363. (require 'imenu-list)
  1364. (if (eq (window-buffer)
  1365. (get-buffer imenu-list-buffer-name))
  1366. (imenu-list-minor-mode -1)
  1367. (imenu-list-minor-mode 1)))
  1368. ;; (set-variable 'imenu-list-auto-resize t)
  1369. (set-variable 'imenu-list-focus-after-activation t)
  1370. ;; (define-key ctl-x-map (kbd "C-l") 'my-imenu-list-toggle)
  1371. (define-key ctl-x-map (kbd "C-l") 'imenu-list-smart-toggle)
  1372. )
  1373. (add-hook 'emacs-lisp-mode-hook
  1374. (lambda ()
  1375. (setq imenu-generic-expression
  1376. `(("Sections" ";;;\+\n;; \\(.*\\)\n" 1)
  1377. ,@imenu-generic-expression))))
  1378. ;; TODO: Try paraedit http://daregada.blogspot.com/2012/03/paredit.html
  1379. (with-eval-after-load 'compile
  1380. (defvar compilation-filter-start)
  1381. (defvar compilation-error-regexp-alist)
  1382. (eval-and-compile (require 'ansi-color))
  1383. (add-hook 'compilation-filter-hook
  1384. (lambda ()
  1385. (let ((inhibit-read-only t))
  1386. (ansi-color-apply-on-region compilation-filter-start
  1387. (point)))))
  1388. (add-to-list 'compilation-error-regexp-alist
  1389. ;; ansible-lint
  1390. '("^\\([^ \n]+\\):\\([0-9]+\\)$" 1 2))
  1391. (add-to-list 'compilation-error-regexp-alist
  1392. ;; pydocstyle
  1393. '("^\\([^ \n]+\\):\\([0-9]+\\) " 1 2))
  1394. )
  1395. (declare-function company-cancel "company")
  1396. (when (fboundp 'global-company-mode)
  1397. (add-hook 'after-first-visit-hook
  1398. 'global-company-mode))
  1399. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  1400. ;; https://qiita.com/yuze/items/a145b1e3edb6d0c24cbf
  1401. (set-variable 'company-idle-delay nil)
  1402. (set-variable 'company-minimum-prefix-length 2)
  1403. (set-variable 'company-selection-wrap-around t)
  1404. (set-variable 'company-global-modes '(not term-char-mode
  1405. term-line-mode))
  1406. (declare-function company-manual-begin "company")
  1407. (with-eval-after-load 'company
  1408. (defvar company-mode-map)
  1409. (define-key company-mode-map (kbd "C-i") 'company-indent-or-complete-common)
  1410. ;; (with-eval-after-load 'python
  1411. ;; (defvar python-indent-trigger-commands)
  1412. ;; ;; TODO: This disables completion in python?
  1413. ;; (add-to-list 'python-indent-trigger-commands
  1414. ;; 'company-indent-or-complete-common))
  1415. (define-key ctl-x-map (kbd "C-i") 'company-complete) ; Originally `indent-rigidly'
  1416. (defvar company-active-map)
  1417. (define-key company-active-map (kbd "C-n") 'company-select-next)
  1418. (define-key company-active-map (kbd "C-p") 'company-select-previous)
  1419. (define-key company-active-map (kbd "C-s") 'company-filter-candidates)
  1420. (define-key company-active-map (kbd "C-i") 'company-complete-selection)
  1421. (define-key company-active-map (kbd "C-f") 'company-complete-selection)
  1422. (defvar company-mode)
  1423. (defvar company-candidates)
  1424. (defvar company-candidates-length)
  1425. ;; (popup-tip "Hello, World!")
  1426. (defun my-company-lighter-current-length ()
  1427. "Get current candidate length."
  1428. (interactive)
  1429. (let ((l nil)
  1430. (inhibit-message t))
  1431. (when (and company-mode
  1432. (not (minibufferp))
  1433. ;; Do nothing when already in company completion
  1434. (not company-candidates))
  1435. ;; FIXME: Somehow it cannto catch errors from ggtags
  1436. (ignore-errors
  1437. ;; (company-auto-begin)
  1438. (company-manual-begin)
  1439. (setq l company-candidates-length)
  1440. (company-cancel)))
  1441. (if l
  1442. (format "[%d]" l)
  1443. "")))
  1444. (defvar company-lighter)
  1445. (set-variable 'company-lighter-base "Cmp")
  1446. ;; (add-to-list 'company-lighter
  1447. ;; '(:eval (my-company-lighter-current-length))
  1448. ;; t)
  1449. ;; This breaks japanese text input
  1450. ;; (set-variable 'my-company-length-popup-tip-timer
  1451. ;; (run-with-idle-timer 0.2 t
  1452. ;; 'my-company-length-popup-tip))
  1453. ;; (current-active-maps)
  1454. ;; (lookup-key)
  1455. '(mapcar (lambda (map)
  1456. (lookup-key map (kbd "C-i")))
  1457. (current-active-maps))
  1458. ;; https://qiita.com/syohex/items/8d21d7422f14e9b53b17
  1459. (set-face-attribute 'company-tooltip nil
  1460. :foreground "black" :background "lightgrey")
  1461. (set-face-attribute 'company-tooltip-common nil
  1462. :foreground "black" :background "lightgrey")
  1463. (set-face-attribute 'company-tooltip-common-selection nil
  1464. :foreground "white" :background "steelblue")
  1465. (set-face-attribute 'company-tooltip-selection nil
  1466. :foreground "black" :background "steelblue")
  1467. (set-face-attribute 'company-preview-common nil
  1468. :background nil :foreground "lightgrey" :underline t)
  1469. (set-face-attribute 'company-scrollbar-fg nil
  1470. :background "orange")
  1471. (set-face-attribute 'company-scrollbar-bg nil
  1472. :background "gray40")
  1473. )
  1474. ;; https://github.com/lunaryorn/flycheck
  1475. ;; TODO: Any way to disable auto check?
  1476. ;; Update flycheck-hooks-alist?
  1477. (when (fboundp 'global-flycheck-mode)
  1478. (add-hook 'after-first-visit-hook
  1479. 'global-flycheck-mode))
  1480. ;; (set-variable 'flycheck-display-errors-delay 2.0)
  1481. ;; (fset 'flycheck-display-error-at-point-soon 'ignore)
  1482. ;; (with-eval-after-load 'flycheck
  1483. ;; (when (fboundp 'flycheck-black-check-setup)
  1484. ;; (flycheck-black-check-setup)))
  1485. ;; (when (fboundp 'ilookup-open-word)
  1486. ;; (define-key ctl-x-map "d" 'ilookup-open-word)
  1487. ;; )
  1488. (set-variable 'ac-ignore-case nil)
  1489. (when (fboundp 'term-run-shell-command)
  1490. (define-key ctl-x-map "t" 'term-run-shell-command))
  1491. (add-to-list 'safe-local-variable-values
  1492. '(encoding utf-8))
  1493. (setq enable-local-variables :safe)
  1494. ;; Detect file type from shebang and set major-mode.
  1495. (add-to-list 'interpreter-mode-alist
  1496. '("python3" . python-mode))
  1497. (add-to-list 'interpreter-mode-alist
  1498. '("python2" . python-mode))
  1499. (with-eval-after-load 'python
  1500. (defvar python-mode-map (make-sparse-keymap))
  1501. (define-key python-mode-map (kbd "C-m") 'newline-and-indent))
  1502. ;; I want to use this, but this breaks normal self-insert-command
  1503. ;; (set-variable 'py-indent-list-style
  1504. ;; 'one-level-to-beginning-of-statement)
  1505. (set-variable 'pydoc-command
  1506. "python3 -m pydoc")
  1507. (declare-function with-venv-advice-add "with-venv")
  1508. (with-eval-after-load 'pydoc
  1509. ;; pydoc depends on python-shell-interpreter but it does not load this
  1510. (require 'python)
  1511. (when (require 'with-venv nil t)
  1512. (with-venv-advice-add 'pydoc)
  1513. ;; Used in interactive function of pydoc
  1514. (with-venv-advice-add 'pydoc-all-modules)))
  1515. (defvar my-cousel-pydoc-history nil "History of `my-counsel-pydoc'.")
  1516. (defun my-counsel-pydoc ()
  1517. "Counsel `pydoc'."
  1518. (interactive)
  1519. (eval-and-compile (require 'pydoc nil t))
  1520. (ivy-read "Recently: " (pydoc-all-modules)
  1521. :require-match t
  1522. :history 'my-cousel-pydoc-history
  1523. :action (lambda (x) (pydoc x))
  1524. :caller 'my-counsel-pydoc))
  1525. (set-variable 'flycheck-python-mypy-config '("mypy.ini" ".mypy.ini" "setup.cfg"))
  1526. (set-variable 'flycheck-flake8rc '("setup.cfg" "tox.ini" ".flake8rc"))
  1527. (set-variable 'flycheck-python-pylint-executable "python3")
  1528. (set-variable 'flycheck-python-pycompile-executable "python3")
  1529. (set-variable 'python-indent-guess-indent-offset nil)
  1530. (with-eval-after-load 'blacken
  1531. (when (require 'with-venv nil t)
  1532. (with-venv-advice-add 'blacken-buffer)))
  1533. (with-eval-after-load 'ansible-doc
  1534. (when (require 'with-venv nil t)
  1535. (with-venv-advice-add 'ansible-doc)))
  1536. ;; `isortify-buffer' breaks buffer when it contains japanese text
  1537. (defun my-isortify ()
  1538. (interactive)
  1539. (cl-assert buffer-file-name)
  1540. (cl-assert (not (buffer-modified-p)))
  1541. (call-process "python" ;; PROGRAM
  1542. nil ;; INFILE
  1543. nil ;; DESTINATION
  1544. nil ;; DISPLAY
  1545. "-m" "isort" buffer-file-name)
  1546. (message "isortify done")
  1547. (revert-buffer nil t))
  1548. (when (fboundp 'with-venv-advice-add)
  1549. ;; TODO: Lazy load with-venv
  1550. (with-venv-advice-add 'my-isortify))
  1551. ;; https://github.com/lunaryorn/old-emacs-configuration/blob/master/lisp/flycheck-virtualenv.el
  1552. (defun my-set-venv-flycheck-executable-find ()
  1553. "Set flycheck executabie find."
  1554. (interactive)
  1555. (when (fboundp 'with-venv)
  1556. (set-variable 'flycheck-executable-find
  1557. '(lambda (e)
  1558. (with-venv
  1559. (executable-find e)))
  1560. t)))
  1561. (defun my-update-flycheck-flake8-error-level-alist ()
  1562. "Update `flycheck-flake8-error-level-alist'."
  1563. (defvar flycheck-flake8-error-level-alist)
  1564. ;; (add-to-list 'flycheck-flake8-error-level-alist
  1565. ;; '("^D.*$" . warning))
  1566. (set-variable 'flycheck-flake8-error-level-alist
  1567. nil)
  1568. )
  1569. (add-hook 'python-mode-hook
  1570. 'my-set-venv-flycheck-executable-find)
  1571. (add-hook 'python-mode-hook
  1572. 'my-update-flycheck-flake8-error-level-alist)
  1573. (when (fboundp 'with-venv-info-mode)
  1574. (add-hook 'python-mode-hook
  1575. 'with-venv-info-mode))
  1576. ;; Run multiple chekcers
  1577. ;; https://github.com/flycheck/flycheck/issues/186
  1578. (add-hook 'python-mode-hook
  1579. (lambda ()
  1580. ;; Currently on python-mode eldoc-mode sometimes print
  1581. ;; wired message on "from" keyword:
  1582. ;;var from = require("./from")
  1583. (eldoc-mode -1)))
  1584. ;; http://fukuyama.co/foreign-regexp
  1585. '(and (require 'foreign-regexp nil t)
  1586. (progn
  1587. (setq foreign-regexp/regexp-type 'perl)
  1588. '(setq reb-re-syntax 'foreign-regexp)
  1589. ))
  1590. (with-eval-after-load 'sql
  1591. (require 'sql-indent nil t)
  1592. (set-variable 'sqlind-basic-offset 2))
  1593. (add-to-list 'auto-mode-alist
  1594. '("\\.hql\\'" . sql-mode))
  1595. (set-variable 'sqlformat-command 'pgformatter)
  1596. (when (fboundp 'git-command)
  1597. (define-key ctl-x-map "g" 'git-command))
  1598. (when (fboundp 'gited-list)
  1599. (defalias 'gited 'gited-list))
  1600. (when (and (eval-and-compile (require 'git-commit nil t))
  1601. (fboundp 'global-git-commit-mode))
  1602. ;; git-commit is defined badly and breaks the convention that only loading a
  1603. ;; library should not change the Emacs behavior:
  1604. ;; anyway I enable this manually here.
  1605. (global-git-commit-mode 1))
  1606. (with-eval-after-load 'git-commit
  1607. (add-hook 'git-commit-setup-hook
  1608. 'turn-off-auto-fill t))
  1609. (with-eval-after-load 'rst
  1610. (defvar rst-mode-map)
  1611. (define-key rst-mode-map (kbd "C-m") 'newline-and-indent))
  1612. (with-eval-after-load 'jdee
  1613. (add-hook 'jdee-mode-hook
  1614. (lambda ()
  1615. (make-local-variable 'global-mode-string)
  1616. (add-to-list 'global-mode-string
  1617. mode-line-position))))
  1618. ;; Cannot enable error thrown. Why???
  1619. ;; https://github.com/m0smith/malabar-mode#Installation
  1620. ;; (when (require 'malabar-mode nil t)
  1621. ;; (add-to-list 'load-path
  1622. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  1623. ;; (require 'cedet-devel-load nil t)
  1624. ;; (eval-after-init (activate-malabar-mode)))
  1625. (with-eval-after-load 'make-mode
  1626. (defvar makefile-mode-map (make-sparse-keymap))
  1627. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  1628. ;; this functions is set in write-file-functions, i cannot find any
  1629. ;; good way to remove this.
  1630. (fset 'makefile-warn-suspicious-lines 'ignore))
  1631. (with-eval-after-load 'verilog-mode
  1632. (defvar verilog-mode-map (make-sparse-keymap))
  1633. (define-key verilog-mode-map ";" 'self-insert-command))
  1634. (setq diff-switches "-u")
  1635. (autoload 'diff-goto-source "diff-mode" nil t)
  1636. (with-eval-after-load 'diff-mode
  1637. ;; (when (and (eq major-mode
  1638. ;; 'diff-mode)
  1639. ;; (not buffer-file-name))
  1640. ;; ;; do not pass when major-mode is derived mode of diff-mode
  1641. ;; (view-mode 1))
  1642. (set-face-attribute 'diff-header nil
  1643. :foreground nil
  1644. :background nil
  1645. :weight 'bold)
  1646. (set-face-attribute 'diff-file-header nil
  1647. :foreground nil
  1648. :background nil
  1649. :weight 'bold)
  1650. (set-face-foreground 'diff-index "blue")
  1651. (set-face-attribute 'diff-hunk-header nil
  1652. :foreground "cyan"
  1653. :weight 'normal)
  1654. (set-face-attribute 'diff-context nil
  1655. ;; :foreground "white"
  1656. :foreground nil
  1657. :weight 'normal)
  1658. (set-face-foreground 'diff-removed "red")
  1659. (set-face-foreground 'diff-added "green")
  1660. (set-face-background 'diff-removed nil)
  1661. (set-face-background 'diff-added nil)
  1662. (set-face-attribute 'diff-changed nil
  1663. :foreground "magenta"
  1664. :weight 'normal)
  1665. (set-face-attribute 'diff-refine-changed nil
  1666. :foreground nil
  1667. :background nil
  1668. :weight 'bold
  1669. :inverse-video t)
  1670. ;; Annoying !
  1671. ;;(diff-auto-refine-mode)
  1672. (set-variable 'diff-refine nil)
  1673. )
  1674. ;; (ffap-bindings)
  1675. (with-eval-after-load 'browse-url
  1676. (set-variable 'browse-url-browser-function
  1677. 'eww-browse-url))
  1678. (set-variable 'sh-here-document-word "__EOC__")
  1679. (with-eval-after-load 'adoc-mode
  1680. (defvar adoc-mode-map)
  1681. (define-key adoc-mode-map (kbd "C-m") 'newline))
  1682. (when (fboundp 'adoc-mode)
  1683. (setq auto-mode-alist
  1684. `(("\\.adoc\\'" . adoc-mode)
  1685. ("\\.asciidoc\\'" . adoc-mode)
  1686. ,@auto-mode-alist)))
  1687. (with-eval-after-load 'markup-faces
  1688. ;; Is this too match ?
  1689. (set-face-foreground 'markup-meta-face
  1690. "color-245")
  1691. (set-face-foreground 'markup-meta-hide-face
  1692. "color-245")
  1693. )
  1694. ;; TODO: check if this is required
  1695. (with-eval-after-load 'groovy-mode
  1696. (defvar groovy-mode-map)
  1697. (define-key groovy-mode-map "(" 'self-insert-command)
  1698. (define-key groovy-mode-map ")" 'self-insert-command)
  1699. (define-key groovy-mode-map (kbd "C-m") 'newline-and-indent)
  1700. )
  1701. (when (fboundp 'groovy-mode)
  1702. (add-to-list 'auto-mode-alist
  1703. '("build\\.gradle\\'" . groovy-mode)))
  1704. (add-to-list 'auto-mode-alist
  1705. '("\\.gawk\\'" . awk-mode))
  1706. (with-eval-after-load 'yaml-mode
  1707. (defvar yaml-mode-map (make-sparse-keymap))
  1708. (define-key yaml-mode-map (kbd "C-m") 'newline))
  1709. (with-eval-after-load 'html-mode
  1710. (defvar html-mode-map (make-sparse-keymap))
  1711. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  1712. (with-eval-after-load 'text-mode
  1713. (define-key text-mode-map (kbd "C-m") 'newline))
  1714. (with-eval-after-load 'info
  1715. (defvar Info-additional-directory-list)
  1716. (dolist (dir (directory-files (concat user-emacs-directory
  1717. "info")
  1718. t
  1719. "^[^.].*"))
  1720. (when (file-directory-p dir)
  1721. (add-to-list 'Info-additional-directory-list
  1722. dir)))
  1723. (let ((dir (expand-file-name "~/.brew/share/info")))
  1724. (when (file-directory-p dir)
  1725. (add-to-list 'Info-additional-directory-list
  1726. dir))))
  1727. (with-eval-after-load 'apropos
  1728. (defvar apropos-mode-map (make-sparse-keymap))
  1729. (define-key apropos-mode-map "n" 'next-line)
  1730. (define-key apropos-mode-map "p" 'previous-line))
  1731. ;; `isearch' library does not call `provide' so cannot use with-eval-after-load
  1732. ;; (define-key isearch-mode-map
  1733. ;; (kbd "C-j") 'isearch-other-control-char)
  1734. ;; (define-key isearch-mode-map
  1735. ;; (kbd "C-k") 'isearch-other-control-char)
  1736. ;; (define-key isearch-mode-map
  1737. ;; (kbd "C-h") 'isearch-other-control-char)
  1738. (define-key isearch-mode-map (kbd "C-h") 'isearch-del-char)
  1739. (define-key isearch-mode-map (kbd "M-r")
  1740. 'isearch-query-replace-regexp)
  1741. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  1742. (setq lazy-highlight-cleanup nil)
  1743. ;; face for isearch highlighting
  1744. (set-face-attribute 'lazy-highlight
  1745. nil
  1746. :foreground `unspecified
  1747. :background `unspecified
  1748. :underline t
  1749. ;; :weight `bold
  1750. )
  1751. (add-hook 'outline-mode-hook
  1752. (lambda ()
  1753. (when (string-match "\\.md\\'" buffer-file-name)
  1754. (setq-local outline-regexp "#+ "))))
  1755. (add-hook 'outline-mode-hook
  1756. 'outline-show-all)
  1757. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  1758. (with-eval-after-load 'markdown-mode
  1759. (defvar gfm-mode-map)
  1760. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline)
  1761. (define-key gfm-mode-map "`" nil) ;; markdown-electric-backquote
  1762. )
  1763. (when (fboundp 'gfm-mode)
  1764. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  1765. (add-hook 'markdown-mode-hook
  1766. 'outline-minor-mode)
  1767. (add-hook 'markdown-mode-hook
  1768. (lambda ()
  1769. (setq-local comment-start ";")))
  1770. )
  1771. ;; http://keisanbutsuriya.hateblo.jp/entry/2015/02/10/152543
  1772. ;; M-$ to ispell word
  1773. ;; M-x flyspell-buffer to highlight all suspicious words
  1774. (when (executable-find "aspell")
  1775. (set-variable 'ispell-program-name "aspell")
  1776. (set-variable 'ispell-extra-args '("--lang=en_US")))
  1777. (with-eval-after-load 'ispell
  1778. (add-to-list 'ispell-skip-region-alist '("[^\000-\377]+")))
  1779. (when (fboundp 'flyspell-mode)
  1780. (add-hook 'text-mode-hook
  1781. 'flyspell-mode))
  1782. (when (fboundp 'flyspell-prog-mode)
  1783. (add-hook 'prog-mode-hook
  1784. 'flyspell-prog-mode))
  1785. ;; c-mode
  1786. ;; http://www.emacswiki.org/emacs/IndentingC
  1787. ;; http://en.wikipedia.org/wiki/Indent_style
  1788. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  1789. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  1790. (with-eval-after-load 'cc-vars
  1791. (defvar c-default-style nil)
  1792. (add-to-list 'c-default-style
  1793. '(c-mode . "k&r"))
  1794. (add-to-list 'c-default-style
  1795. '(c++-mode . "k&r")))
  1796. (add-to-list 'auto-mode-alist
  1797. '("\\.gs\\'" . js-mode))
  1798. (with-eval-after-load 'js2-mode
  1799. ;; currently do not use js2-mode
  1800. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  1801. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  1802. ;; (defvar js2-mode-map (make-sparse-keymap))
  1803. ;; (define-key js2-mode-map (kbd "C-m") (lambda ()
  1804. ;; (interactive)
  1805. ;; (js2-enter-key)
  1806. ;; (indent-for-tab-command)))
  1807. ;; (add-hook (kill-local-variable 'before-save-hook)
  1808. ;; 'js2-before-save)
  1809. ;; (add-hook 'before-save-hook
  1810. ;; 'my-indent-buffer
  1811. ;; nil
  1812. ;; t)
  1813. )
  1814. (add-to-list 'interpreter-mode-alist
  1815. '("node" . js-mode))
  1816. (add-hook 'js-mode-hook
  1817. (lambda ()
  1818. ;; Stop current line highlighting
  1819. (set-variable 'js-indent-level 2 t)
  1820. ))
  1821. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  1822. (with-eval-after-load 'uniquify
  1823. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  1824. (setq uniquify-ignore-buffers-re "*[^*]+*")
  1825. (setq uniquify-min-dir-content 1))
  1826. (with-eval-after-load 'view
  1827. (defvar view-mode-map (make-sparse-keymap))
  1828. (define-key view-mode-map "j" 'scroll-up-line)
  1829. (define-key view-mode-map "k" 'scroll-down-line)
  1830. (define-key view-mode-map "v" 'toggle-read-only)
  1831. (define-key view-mode-map "q" 'bury-buffer)
  1832. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  1833. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  1834. ;; (define-key view-mode-map
  1835. ;; "n" 'nonincremental-repeat-search-forward)
  1836. ;; (define-key view-mode-map
  1837. ;; "N" 'nonincremental-repeat-search-backward)
  1838. ;; N conflicts with git-walktree
  1839. ;; (define-key view-mode-map "/" 'isearch-forward-regexp)
  1840. ;; (define-key view-mode-map "?" 'isearch-backward-regexp)
  1841. ;; (define-key view-mode-map "n" 'isearch-repeat-forward)
  1842. ;; (define-key view-mode-map "N" 'isearch-repeat-backward)
  1843. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  1844. (global-set-key "\M-r" 'view-mode)
  1845. ;; (setq view-read-only t)
  1846. (with-eval-after-load 'term
  1847. (defvar term-raw-map (make-sparse-keymap))
  1848. (define-key term-raw-map (kbd "C-x")
  1849. (lookup-key (current-global-map)
  1850. (kbd "C-x"))))
  1851. (add-hook 'term-mode-hook
  1852. (lambda ()
  1853. ;; Stop current line highlighting
  1854. (set-variable 'hl-line-range-function (lambda () '(0 . 0)) t)
  1855. (set-variable 'scroll-margin 0 t)
  1856. ))
  1857. (set-variable 'term-buffer-maximum-size 20480)
  1858. (set-variable 'term-suppress-hard-newline t)
  1859. (add-hook 'Man-mode-hook
  1860. (lambda ()
  1861. (view-mode 1)
  1862. (setq truncate-lines nil)))
  1863. (set-variable 'Man-notify-method (if window-system
  1864. 'newframe
  1865. 'aggressive))
  1866. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  1867. "woman_cache.el")))
  1868. ;; not work because man.el will be loaded when man called
  1869. (defalias 'man 'woman)
  1870. (add-to-list 'auto-mode-alist
  1871. '("/tox\\.ini\\'" . conf-unix-mode))
  1872. (add-to-list 'auto-mode-alist
  1873. '("/setup\\.cfg\\'" . conf-unix-mode))
  1874. (when (fboundp 'toml-mode)
  1875. (add-to-list 'auto-mode-alist
  1876. '("/tox\\.ini\\'" . toml-mode))
  1877. (add-to-list 'auto-mode-alist
  1878. '("/setup\\.cfg\\'" . toml-mode))
  1879. (add-to-list 'auto-mode-alist
  1880. '("/Pipfile\\'" . toml-mode))
  1881. (add-to-list 'auto-mode-alist
  1882. '("/poetry\\.lock\\'" . toml-mode))
  1883. )
  1884. (when (fboundp 'json-mode)
  1885. (add-to-list 'auto-mode-alist
  1886. '("/Pipfile\\.lock\\'" . json-mode)))
  1887. (add-hook 'json-mode-hook
  1888. (lambda ()
  1889. ;; Stop current line highlighting
  1890. (set-variable 'js-indent-level 2 t)
  1891. ))
  1892. (add-hook 'go-mode-hook
  1893. (lambda()
  1894. (defvar go-mode-map)
  1895. (add-hook 'before-save-hook 'gofmt-before-save nil t)
  1896. (define-key go-mode-map (kbd "M-.") 'godef-jump)))
  1897. (when (fboundp 'k8s-mode)
  1898. (add-to-list 'auto-mode-alist
  1899. '("\\.k8s\\'" . k8s-mode)))
  1900. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1901. ;; buffers
  1902. (defvar bs-configurations)
  1903. (declare-function bs-set-configuration "bs")
  1904. (declare-function bs-refresh "bs")
  1905. (declare-function bs-message-without-log "bs")
  1906. (declare-function bs--current-config-message "bs")
  1907. (with-eval-after-load 'bs
  1908. (add-to-list 'bs-configurations
  1909. '("specials" "^\\*" nil ".*" nil nil))
  1910. (add-to-list 'bs-configurations
  1911. '("files-and-specials" "^\\*" buffer-file-name ".*" nil nil))
  1912. (defvar bs-mode-map)
  1913. (defvar bs-current-configuration)
  1914. (define-key bs-mode-map (kbd "t")
  1915. ;; TODO: fix toggle feature
  1916. (lambda ()
  1917. (interactive)
  1918. (if (string= "specials"
  1919. bs-current-configuration)
  1920. (bs-set-configuration "files")
  1921. (bs-set-configuration "specials"))
  1922. (bs-refresh)
  1923. (bs-message-without-log "%s"
  1924. (bs--current-config-message))))
  1925. ;; (setq bs-configurations (list
  1926. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1927. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1928. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1929. )
  1930. (when (fboundp 'bs-show)
  1931. (defalias 'list-buffers 'bs-show)
  1932. (set-variable 'bs-default-configuration "files-and-specials")
  1933. (set-variable 'bs-default-sort-name "by nothing")
  1934. (add-hook 'bs-mode-hook
  1935. (lambda ()
  1936. (setq-local scroll-margin 0)
  1937. (setq-local header-line-format nil)
  1938. (setq-local mode-line-format nil)
  1939. )))
  1940. ;;(iswitchb-mode 1)
  1941. (icomplete-mode)
  1942. (defun iswitchb-buffer-display-other-window ()
  1943. "Do iswitchb in other window."
  1944. (interactive)
  1945. (let ((iswitchb-default-method 'display))
  1946. (call-interactively 'iswitchb-buffer)))
  1947. ;; buffer killing
  1948. ;; (defun my-delete-window-killing-buffer () nil)
  1949. (defun my-query-kill-current-buffer ()
  1950. "Interactively kill current buffer."
  1951. (interactive)
  1952. (if (y-or-n-p (concat "kill current buffer? :"))
  1953. (kill-buffer (current-buffer))))
  1954. (defun my-force-query-kill-current-buffer ()
  1955. "Interactively kill current buffer."
  1956. (interactive)
  1957. (when (y-or-n-p (concat "kill current buffer? :"))
  1958. (let ((kill-buffer-hook nil)
  1959. (kill-buffer-query-functions nil))
  1960. (kill-buffer (current-buffer)))))
  1961. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  1962. ;; Originally C-x C-k -> kmacro-keymap
  1963. ;; (global-set-key "\C-x\C-k" 'kmacro-keymap)
  1964. (global-set-key (kbd "C-x C-k") 'my-query-kill-current-buffer)
  1965. (substitute-key-definition 'kill-buffer
  1966. 'my-query-kill-current-buffer
  1967. global-map)
  1968. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1969. ;; dired
  1970. (defun my-file-head (filename &optional n)
  1971. "Return list of first N lines of file FILENAME."
  1972. ;; TODO: Fix for janapese text
  1973. ;; TODO: Fix for short text
  1974. (let ((num (or n 10))
  1975. (size 100)
  1976. (beg 0)
  1977. (end 0)
  1978. (result '())
  1979. (read -1))
  1980. (with-temp-buffer
  1981. (erase-buffer)
  1982. (while (or (<= (count-lines (point-min)
  1983. (point-max))
  1984. num)
  1985. (eq read 0))
  1986. (setq end (+ beg size))
  1987. (setq read (nth 1 (insert-file-contents-literally filename
  1988. nil
  1989. beg
  1990. end)))
  1991. (goto-char (point-max))
  1992. (setq beg (+ beg size)))
  1993. (goto-char (point-min))
  1994. (while (< (length result) num)
  1995. (let ((start (point)))
  1996. (forward-line 1)
  1997. (setq result
  1998. `(,@result ,(buffer-substring-no-properties start
  1999. (point))))))
  2000. result
  2001. ;; (buffer-substring-no-properties (point-min)
  2002. ;; (progn
  2003. ;; (forward-line num)
  2004. ;; (point)))
  2005. )))
  2006. ;; (apply 'concat (my-file-head "./shrc" 10)
  2007. (declare-function dired-get-filename "dired" t)
  2008. (defun my-dired-echo-file-head (arg)
  2009. "Echo head of current file.
  2010. ARG is num to show, or defaults to 7."
  2011. (interactive "P")
  2012. (let ((f (dired-get-filename)))
  2013. (message "%s"
  2014. (apply 'concat
  2015. (my-file-head f
  2016. 7)))))
  2017. (declare-function dired-get-marked-files "dired")
  2018. (defun my-dired-diff ()
  2019. "Show diff of marked file and file of current line."
  2020. (interactive)
  2021. (let ((files (dired-get-marked-files nil nil nil t)))
  2022. (if (eq (car files)
  2023. t)
  2024. (diff (cadr files) (dired-get-filename))
  2025. (message "One file must be marked!"))))
  2026. (defun dired-get-file-info ()
  2027. "Print information of current line file."
  2028. (interactive)
  2029. (let* ((file (dired-get-filename t))
  2030. (quoted (shell-quote-argument file)))
  2031. (if (file-directory-p file)
  2032. (progn
  2033. (message "Calculating disk usage...")
  2034. (let ((du (or (executable-find "gdu")
  2035. (executable-find "du")
  2036. (error "du not found"))))
  2037. (shell-command (concat du
  2038. " -hsD "
  2039. quoted))))
  2040. (shell-command (concat "file "
  2041. quoted)))))
  2042. (defun my-dired-scroll-up ()
  2043. "Scroll up."
  2044. (interactive)
  2045. (my-dired-previous-line (- (window-height) 1)))
  2046. (defun my-dired-scroll-down ()
  2047. "Scroll down."
  2048. (interactive)
  2049. (my-dired-next-line (- (window-height) 1)))
  2050. ;; (defun my-dired-forward-line (arg)
  2051. ;; ""
  2052. ;; (interactive "p"))
  2053. (declare-function dired-get-subdir "dired")
  2054. (declare-function dired-move-to-filename "dired")
  2055. (defun my-dired-previous-line (arg)
  2056. "Move ARG lines up."
  2057. (interactive "p")
  2058. (if (> arg 0)
  2059. (progn
  2060. (if (eq (line-number-at-pos)
  2061. 1)
  2062. (goto-char (point-max))
  2063. (forward-line -1))
  2064. (my-dired-previous-line (if (or (dired-get-filename nil t)
  2065. (dired-get-subdir))
  2066. (- arg 1)
  2067. arg)))
  2068. (dired-move-to-filename)))
  2069. (defun my-dired-next-line (arg)
  2070. "Move ARG lines down."
  2071. (interactive "p")
  2072. (if (> arg 0)
  2073. (progn
  2074. (if (eq (point)
  2075. (point-max))
  2076. (goto-char (point-min))
  2077. (forward-line 1))
  2078. (my-dired-next-line (if (or (dired-get-filename nil t)
  2079. (dired-get-subdir))
  2080. (- arg 1)
  2081. arg)))
  2082. (dired-move-to-filename)))
  2083. (defun my-tramp-remote-find-file (f)
  2084. "Open F."
  2085. (interactive (list (read-file-name "My Find File Tramp: "
  2086. "/scp:"
  2087. nil ;; "/scp:"
  2088. (confirm-nonexistent-file-or-buffer))))
  2089. (find-file f))
  2090. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  2091. (if (eq window-system 'mac)
  2092. (setq dired-listing-switches "-lhFA")
  2093. (setq dired-listing-switches "-lhFA --time-style=long-iso")
  2094. )
  2095. (setq dired-listing-switches "-lhFA")
  2096. ;; when using dired-find-alternate-file
  2097. ;; reuse current dired buffer for the file to open
  2098. ;; (put 'dired-find-alternate-file 'disabled nil)
  2099. (set-variable 'dired-ls-F-marks-symlinks t)
  2100. (set-variable 'ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  2101. (set-variable 'ls-lisp-dirs-first t)
  2102. (set-variable 'ls-lisp-use-localized-time-format t)
  2103. (set-variable 'ls-lisp-format-time-list
  2104. '("%Y-%m-%d %H:%M"
  2105. "%Y-%m-%d "))
  2106. (set-variable 'dired-dwim-target t)
  2107. (set-variable 'dired-isearch-filenames t)
  2108. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  2109. (set-variable 'dired-hide-details-hide-information-lines nil)
  2110. (set-variable 'dired-deletion-confirmer 'y-or-n-p)
  2111. (set-variable 'dired-recursive-deletes 'always)
  2112. ;; (add-hook 'dired-after-readin-hook
  2113. ;; 'my-replace-nasi-none)
  2114. (with-eval-after-load 'dired
  2115. (require 'ls-lisp nil t)
  2116. (defvar dired-mode-map (make-sparse-keymap))
  2117. ;; dired-do-chgrp sometimes cause system hung
  2118. (define-key dired-mode-map "G" 'ignore)
  2119. (define-key dired-mode-map "e" 'wdired-change-to-wdired-mode)
  2120. (define-key dired-mode-map "i" 'dired-get-file-info)
  2121. ;; (define-key dired-mode-map "f" 'find-file)
  2122. (define-key dired-mode-map "f" 'my-fuzzy-finder-or-find-file)
  2123. (define-key dired-mode-map "!" 'shell-command)
  2124. (define-key dired-mode-map "&" 'async-shell-command)
  2125. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  2126. (define-key dired-mode-map "=" 'my-dired-diff)
  2127. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  2128. (define-key dired-mode-map "b" 'gtkbm)
  2129. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  2130. (define-key dired-mode-map (kbd "TAB") 'other-window)
  2131. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  2132. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  2133. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  2134. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  2135. (substitute-key-definition 'dired-next-line
  2136. 'my-dired-next-line
  2137. dired-mode-map)
  2138. (substitute-key-definition 'dired-previous-line
  2139. 'my-dired-previous-line
  2140. dired-mode-map)
  2141. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  2142. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  2143. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  2144. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  2145. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  2146. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  2147. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  2148. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  2149. (add-hook 'dired-mode-hook
  2150. (lambda ()
  2151. (when (fboundp 'dired-hide-details-mode)
  2152. (dired-hide-details-mode t)
  2153. (local-set-key "l" 'dired-hide-details-mode))
  2154. (when (fboundp 'dired-omit-mode)
  2155. (dired-omit-mode 1)
  2156. (local-set-key "a" 'dired-omit-mode))
  2157. (let ((file "._Icon\015"))
  2158. (when nil
  2159. '(file-readable-p file)
  2160. (delete-file file)))))
  2161. (when (fboundp 'pack-dired-dwim)
  2162. (with-eval-after-load 'dired
  2163. (define-key dired-mode-map "P" 'pack-dired-dwim)))
  2164. ;; https://emacs.stackexchange.com/questions/68585/dired-mode-toggle-show-hidden-files-folders-by-keyboard-shortcut
  2165. (set-variable 'dired-omit-files
  2166. (rx (or (regexp "\\`[.]?#\\|\\`[.][.]?\\'")
  2167. (seq bos "." (not (any "."))))))
  2168. ;; (string-match-p dired-omit-files ".abc")
  2169. (when (fboundp 'dired-omit-mode)
  2170. (with-eval-after-load 'dired
  2171. ))
  2172. )
  2173. (when (fboundp 'dired-filter-mode)
  2174. (add-hook 'dired-mode-hook
  2175. 'dired-filter-mode))
  2176. (set-variable 'dired-filter-stack nil)
  2177. ;; Currently disabled in favor of dired-from-git-ls-files
  2178. ;; (define-key ctl-x-map "f" 'find-dired)
  2179. (defvar my-dired-git-ls-files-history
  2180. "History for `my-dired-git-ls-files'." nil)
  2181. (defun my-dired-git-ls-files (arg)
  2182. "Dired from git ls-files."
  2183. (interactive (list
  2184. (read-shell-command "git ls-files: "
  2185. "git ls-files -z ")))
  2186. (pop-to-buffer-same-window
  2187. (dired-noselect `(,default-directory
  2188. ,@(split-string (shell-command-to-string arg)
  2189. "\0" t))
  2190. ""))
  2191. )
  2192. (define-key ctl-x-map (kbd "G") 'my-dired-git-ls-files)
  2193. (with-eval-after-load 'dired
  2194. (defvar dired-mode-map (make-sparse-keymap))
  2195. (define-key dired-mode-map "G" 'my-dired-git-ls-files))
  2196. (with-eval-after-load 'pack
  2197. (set-variable 'pack-silence
  2198. t)
  2199. (defvar pack-program-alist)
  2200. (add-to-list 'pack-program-alist
  2201. '("\\.txz\\'" :pack "tar -cJf" :unpack "tar -xf"))
  2202. (when (executable-find "aunpack")
  2203. (add-to-list 'pack-program-alist
  2204. ' ("\\.zip\\'"
  2205. :pack ("zip" "-r" archive sources)
  2206. :pack-append ("zip" "-r" archive sources)
  2207. :unpack ("aunpack" archive))))
  2208. )
  2209. ;; dired-k
  2210. (declare-function dired-k-no-revert "dired-k")
  2211. (when (fboundp 'dired-k)
  2212. (set-variable 'dired-k-style 'git)
  2213. ;; What is the best way of doing this?
  2214. (with-eval-after-load 'dired-k
  2215. (fset 'dired-k--highlight-by-file-attribyte 'ignore))
  2216. ;; (set-variable 'dired-k-size-colors
  2217. ;; `((,most-positive-fixnum)))
  2218. ;; (set-variable 'dired-k-date-colors
  2219. ;; `((,most-positive-fixnum)))
  2220. (add-hook 'dired-after-readin-hook #'dired-k-no-revert)
  2221. )
  2222. ;; (when (eval-and-compile (require 'dired-rainbow nil t))
  2223. ;; (dired-rainbow-define gtags "brightblack" "GTAGS"))
  2224. (with-eval-after-load 'diredfl
  2225. (set-face-foreground 'diredfl-file-name nil)
  2226. )
  2227. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2228. ;; misc funcs
  2229. (define-key ctl-x-map "T" 'git-worktree)
  2230. (define-key ctl-x-map "W" 'git-walktree)
  2231. (defun mkcdd ()
  2232. "Make date directory and open it with dired."
  2233. (interactive)
  2234. (let ((d (format-time-string "%Y%m%d-%H%M%S")))
  2235. (make-directory d)
  2236. (find-file d)))
  2237. (when (fboundp 'browse-url-default-macosx-browser)
  2238. (defalias 'browse-osx 'browse-url-default-macosx-browser))
  2239. (defalias 'qcalc 'quick-calc)
  2240. (defun memo (&optional dir)
  2241. "Open memo.txt in DIR."
  2242. (interactive)
  2243. (pop-to-buffer (find-file-noselect (concat (if dir
  2244. (file-name-as-directory dir)
  2245. "")
  2246. "memo.txt"))))
  2247. ;; TODO: remember-projectile
  2248. (set (defvar my-privnotes-path nil
  2249. "My privnotes repository path.")
  2250. (expand-file-name "~/my/privnotes"))
  2251. (defun my-privnotes-readme (dir)
  2252. "Open my privnotes DIR."
  2253. (interactive (list
  2254. (read-file-name "Privnotes: "
  2255. (expand-file-name (format-time-string "%Y%m%d_")
  2256. my-privnotes-path))))
  2257. (let ((path (expand-file-name "README.md" dir)))
  2258. (with-current-buffer (find-file path)
  2259. (unless (file-exists-p path)
  2260. (insert (file-name-base dir)
  2261. "\n"
  2262. "=======\n"
  2263. "\n\n")))))
  2264. (define-key ctl-x-map "p" 'my-privnotes-readme)
  2265. (set (defvar my-rgrep-alist nil
  2266. "Alist of rgrep command.
  2267. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  2268. condition to choose COMMAND when evaluated.")
  2269. `(
  2270. ;; ripgrep
  2271. ("rg"
  2272. (executable-find "rg")
  2273. "rg -nH --no-heading --hidden --no-ignore-parent --glob '!.git/' --smart-case -M 1280 ")
  2274. ;; git grep
  2275. ("gitgrep"
  2276. (eq 0
  2277. (shell-command "git rev-parse --git-dir"))
  2278. "git --no-pager grep -nH -e ")
  2279. ;; sift
  2280. ("sift"
  2281. (executable-find "sift")
  2282. ("sift --binary-skip --filename --line-number --git --smart-case "))
  2283. ;; the silver searcher
  2284. ("ag"
  2285. (executable-find "ag")
  2286. "ag --nogroup --nopager --filename ")
  2287. ;; ack
  2288. ("ack"
  2289. (executable-find "ack")
  2290. "ack --nogroup --nopager --with-filename ")
  2291. ;; gnu global
  2292. ("global"
  2293. (and (require 'ggtags nil t)
  2294. (executable-find "global")
  2295. (ggtags-current-project-root))
  2296. "global --result grep ")
  2297. ;; grep
  2298. ("grep"
  2299. t
  2300. ,(concat "find . "
  2301. "-path '*/.git' -prune -o "
  2302. "-path '*/.svn' -prune -o "
  2303. "-type f -print0 | "
  2304. "xargs -0 grep -nH -e "))
  2305. )
  2306. )
  2307. (defvar my-rgrep-default nil
  2308. "Default command name for my-rgrep.")
  2309. (defun my-rgrep-grep-command (&optional name alist)
  2310. "Return recursive grep command for current directory or nil.
  2311. If NAME is given, use that without testing.
  2312. Commands are searched from ALIST."
  2313. (if alist
  2314. (if name
  2315. ;; if name is given search that from alist and return the command
  2316. (nth 2 (assoc name
  2317. alist))
  2318. ;; if name is not given try test in 1th elem
  2319. (let ((car (car alist))
  2320. (cdr (cdr alist)))
  2321. (if (eval (nth 1 car))
  2322. ;; if the condition is true return the command
  2323. (nth 2 car)
  2324. ;; try next one
  2325. (and cdr
  2326. (my-rgrep-grep-command name cdr)))))
  2327. ;; if alist is not given set default value
  2328. (my-rgrep-grep-command name my-rgrep-alist)))
  2329. (declare-function projectile-project-p "projectile")
  2330. (declare-function projectile-with-default-dir "projectile")
  2331. (declare-function projectile-project-root "projectile")
  2332. (defun my-rgrep (command-args)
  2333. "My recursive grep. Run COMMAND-ARGS.
  2334. If prefix argument is given, use current symbol as default search target
  2335. and search from projectile root (if projectile is available)."
  2336. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  2337. nil)))
  2338. (if cmd
  2339. (list (read-shell-command "grep command: "
  2340. (concat cmd
  2341. (if current-prefix-arg
  2342. (thing-at-point 'symbol t)
  2343. ""))
  2344. 'grep-find-history))
  2345. (error "My-Rgrep: Command for rgrep not found")
  2346. )))
  2347. (if (and current-prefix-arg
  2348. (eval-and-compile (require 'projectile nil t))
  2349. (projectile-project-p))
  2350. (projectile-with-default-dir (projectile-project-root)
  2351. (compilation-start command-args
  2352. 'grep-mode))
  2353. (compilation-start command-args
  2354. 'grep-mode)))
  2355. (defun my-rgrep-thing-at-point-projectile-root ()
  2356. "My recursive grep to find thing at point from project root."
  2357. (interactive)
  2358. (let* ((cmd (my-rgrep-grep-command my-rgrep-default
  2359. nil))
  2360. (command-args
  2361. (if cmd
  2362. (concat cmd
  2363. (or (thing-at-point 'symbol t)
  2364. (error "No symbol at point")))
  2365. (error "My-Rgrep: Command for rgrep not found"))))
  2366. (if (eval-and-compile (require 'projectile nil t))
  2367. (with-temp-buffer
  2368. (cd (or (projectile-project-root)
  2369. default-directory))
  2370. (compilation-start command-args
  2371. 'grep-mode))
  2372. (compilation-start command-args
  2373. 'grep-mode))))
  2374. (defmacro define-my-rgrep (name)
  2375. "Define rgrep for NAME."
  2376. `(defun ,(intern (concat "my-rgrep-"
  2377. name)) ()
  2378. ,(format "My recursive grep by %s."
  2379. name)
  2380. (interactive)
  2381. (let ((my-rgrep-default ,name))
  2382. (if (called-interactively-p 'any)
  2383. (call-interactively 'my-rgrep)
  2384. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2385. )
  2386. (define-my-rgrep "ack")
  2387. (define-my-rgrep "ag")
  2388. (define-my-rgrep "rg")
  2389. (define-my-rgrep "sift")
  2390. (define-my-rgrep "gitgrep")
  2391. (define-my-rgrep "grep")
  2392. (define-my-rgrep "global")
  2393. (define-key ctl-x-map "s" 'my-rgrep)
  2394. (define-key ctl-x-map "." 'my-rgrep-thing-at-point-projectile-root)
  2395. (defun my-occur (regexp &optional region)
  2396. "My occur command to search REGEXP to search REGION."
  2397. (interactive (list (read-string "List lines matching regexp: "
  2398. (thing-at-point 'symbol t))))
  2399. (occur regexp nil region))
  2400. (define-key ctl-x-map (kbd "C-o") 'my-occur)
  2401. (set-variable 'dumb-jump-prefer-searcher 'rg)
  2402. (defalias 'make 'compile)
  2403. (define-key ctl-x-map "c" 'compile)
  2404. (autoload 'pb/push-item "pushbullet")
  2405. (defun my-pushbullet-note (text &optional title)
  2406. "Push TEXT with optional TITLE."
  2407. (interactive "sText to Push: ")
  2408. (pb/push-item '("") text "note" (or title "")))
  2409. ;;;;;;;;;;;;;;;;;;;
  2410. ;; peek-file-mode
  2411. (defvar peek-file-buffers
  2412. ()
  2413. "Peek buffers.")
  2414. (defun peek-file (file)
  2415. "Peek FILE."
  2416. (interactive "fFile to peek: ")
  2417. (with-current-buffer (find-file file)
  2418. (peek-file-mode)))
  2419. (define-minor-mode peek-file-mode
  2420. "Peek file mode."
  2421. :lighter "PK"
  2422. (view-mode peek-file-mode)
  2423. (add-to-list 'peek-file-buffers
  2424. (current-buffer))
  2425. (add-hook 'switch-buffer-functions
  2426. 'peek-file-remove-buffers))
  2427. (defun peek-file-remove-buffers (&args _)
  2428. "Remove peek file buffers."
  2429. (cl-dolist (buf (cl-copy-list peek-file-buffers))
  2430. (unless (get-buffer-window buf t)
  2431. (setq peek-file-buffers
  2432. (delq buf
  2433. peek-file-buffers))
  2434. (with-current-buffer buf
  2435. (when peek-file-mode
  2436. (kill-buffer))))))
  2437. (declare-function dired-get-file-for-visit "dired")
  2438. (with-eval-after-load 'dired
  2439. (defun dired-peek-file (&rest files)
  2440. "Dired `peak-file' FILES."
  2441. (interactive (list (dired-get-file-for-visit)))
  2442. (message "AAA %S" files)
  2443. (dolist (file files)
  2444. (peek-file file)))
  2445. (defvar dired-mode-map (make-sparse-keymap))
  2446. (define-key dired-mode-map "v" 'dired-peek-file))
  2447. ;;;;;;;;;;;;;;;;;;;;
  2448. ;; remember-projectile
  2449. ;; TODO: Add global-minor-mode
  2450. (defvar remember-data-file)
  2451. (defun my-set-remember-data-file-buffer-local ()
  2452. "Set `remember-data-file'."
  2453. (when (require 'projectile nil t)
  2454. (setq-local remember-data-file
  2455. (expand-file-name ".remember.notes"
  2456. (projectile-project-root)))))
  2457. (add-hook 'after-change-major-mode-hook
  2458. 'my-set-remember-data-file-buffer-local)
  2459. (define-key ctl-x-map "R" 'remember)
  2460. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2461. ;; ivy
  2462. (set-variable 'ivy-format-functions-alist
  2463. '((t . (lambda (cands) (ivy--format-function-generic
  2464. (lambda (str)
  2465. (concat "+> "
  2466. (ivy--add-face str 'ivy-current-match)
  2467. ))
  2468. (lambda (str)
  2469. (concat "| " str))
  2470. cands
  2471. "\n")))))
  2472. (set-variable 'ivy-wrap t)
  2473. (set-variable 'ivy-sort-max-size 500)
  2474. (when (fboundp 'ivy-rich-mode)
  2475. (ivy-rich-mode 1))
  2476. (with-eval-after-load 'ivy
  2477. (defvar ivy-minibuffer-map)
  2478. (define-key ivy-minibuffer-map (kbd "C-u")
  2479. (lambda () (interactive) (delete-region (point-at-bol) (point)))))
  2480. (set-variable 'ivy-on-del-error-function 'ignore)
  2481. (when (fboundp 'counsel-M-x)
  2482. (define-key esc-map "x" 'counsel-M-x)
  2483. )
  2484. (declare-function ivy-thing-at-point "ivy")
  2485. (when (and (fboundp 'ivy-read)
  2486. (locate-library "counsel"))
  2487. (defvar counsel-describe-map)
  2488. (defun my-counsel-describe-symbol ()
  2489. "Forwaord to `describe-symbol'."
  2490. (interactive)
  2491. (cl-assert (eval-and-compile (require 'help-mode nil t))) ;; describe-symbol-backends
  2492. (cl-assert (eval-and-compile (require 'counsel nil t)))
  2493. (ivy-read "Describe symbol: " obarray
  2494. ;; From describe-symbol definition
  2495. :predicate (lambda (vv)
  2496. (cl-some (lambda (x) (funcall (nth 1 x) vv))
  2497. describe-symbol-backends))
  2498. :require-match t
  2499. :history 'counsel-describe-symbol-history
  2500. :keymap counsel-describe-map
  2501. :preselect (ivy-thing-at-point)
  2502. :action (lambda (x)
  2503. (describe-symbol (intern x)))
  2504. :caller 'my-counsel-describe-symbol))
  2505. (define-key help-map "o" 'my-counsel-describe-symbol)
  2506. )
  2507. (declare-function ivy-configure "ivy")
  2508. (with-eval-after-load 'counsel ;; Hook to counsel, not ivy
  2509. ;; (ivy-configure 'my-counsel-describe-symbol
  2510. ;; :sort-fn 'my-ivy-length)
  2511. (ivy-configure 'counsel-M-x
  2512. :initial-input ""
  2513. ;; :sort-fn 'my-ivy-length
  2514. )
  2515. )
  2516. (when (fboundp 'counsel-imenu)
  2517. (define-key ctl-x-map "l" 'counsel-imenu))
  2518. (when (fboundp 'swiper)
  2519. (define-key esc-map (kbd "C-s") 'swiper))
  2520. (with-eval-after-load 'ivy
  2521. ;; ivy-prescient requires counsel already loaded
  2522. (require 'counsel nil t)
  2523. (when (fboundp 'ivy-prescient-mode)
  2524. (set-variable 'prescient-filter-method
  2525. '(literal regexp initialism fuzzy prefix))
  2526. (ivy-prescient-mode 1)))
  2527. ;; ?
  2528. (define-key input-decode-map "\e[1;5C" [C-right])
  2529. (define-key input-decode-map "\e[1;5D" [C-left])
  2530. ;;;;;;;;;;;;;;;;;;;;;;;;
  2531. ;; mozc
  2532. (global-set-key (kbd "C-c m e") 'ignore)
  2533. (global-set-key (kbd "C-c m d") 'ignore)
  2534. ;; mozc
  2535. (when (locate-library "mozc")
  2536. ;; https://tottoto.net/mac-emacs-karabiner-elements-japanese-input-method-config/
  2537. (with-eval-after-load 'mozc
  2538. ;; (define-key mozc-mode-map (kbd "C-h") 'backward-delete-char)
  2539. ;; (define-key mozc-mode-map (kbd "C-p") (kbd "<up>"))
  2540. ;; (define-key mozc-mode-map (kbd "C-n") (kbd "SPC"))
  2541. )
  2542. (setq default-input-method "japanese-mozc")
  2543. (custom-set-variables '(mozc-leim-title "あ"))
  2544. (defun turn-on-input-method ()
  2545. (interactive)
  2546. (activate-input-method default-input-method))
  2547. (defun turn-off-input-method ()
  2548. (interactive)
  2549. (deactivate-input-method))
  2550. ;; (setq mozc-candidate-style 'echo-area)
  2551. (global-set-key (kbd "C-c m e") 'turn-on-input-method)
  2552. (global-set-key (kbd "C-c m d") 'turn-off-input-method)
  2553. (global-set-key (kbd "<f7>") 'turn-off-input-method)
  2554. (global-set-key (kbd "<f8>") 'turn-on-input-method)
  2555. (require 'mozc-popup)
  2556. (set-variable 'mozc-candidate-style 'popup)
  2557. ;; これいる?
  2558. (when (require 'mozc-im nil t)
  2559. (setq default-input-method "japanese-mozc-im")
  2560. ;; (global-set-key (kbd "C-j") 'toggle-input-method)
  2561. )
  2562. )
  2563. (defun browse-url-macosx-vivaldi-browser (url &rest args)
  2564. "Invoke the macOS Vlvaldi Web browser with URL.
  2565. ARGS are not used."
  2566. (interactive (browse-url-interactive-arg "URL: "))
  2567. (start-process (concat "vivaldi " url)
  2568. nil
  2569. "/Applications/Vivaldi.app/Contents/MacOS/Vivaldi"
  2570. url))
  2571. (declare-function vterm "vterm")
  2572. ;; 前の実行結果を残したまま次のコマンドを実行する方法はあるだろうか
  2573. (defun my-vterm-cmd (command)
  2574. "Start arbitrary command in vterm buffer."
  2575. (interactive "sCommand: ")
  2576. (let ((vterm-shell command)
  2577. (vterm-buffer-name "*vterm-cmd*")
  2578. (vterm-kill-buffer-on-exit nil))
  2579. (when (get-buffer vterm-buffer-name)
  2580. (kill-buffer (get-buffer vterm-buffer-name)))
  2581. (vterm)))
  2582. ;; (setq vterm-shell "bash -l")
  2583. ;; (setq vterm-kill-buffer-on-exit nil)
  2584. ;; ;; (setq vterm-term-environment-variable "screen-256color")
  2585. ;; これいつ動くの?
  2586. ;; 自動で project を switch させる方法はある?
  2587. (add-hook 'projectile-after-switch-project-hook
  2588. (lambda ()
  2589. (message "Projecttile switched to: %s"
  2590. (projectile-project-root))))
  2591. (when (fboundp 'projectile-mode)
  2592. (projectile-mode 1))
  2593. ;; (with-eval-after-load 'eglot
  2594. ;; (when (fboundp 'with-venv-advice-add)
  2595. ;; (with-venv-advice-add 'eglot--executable-find))
  2596. ;; (set-variable 'eldoc-echo-area-use-multiline-p nil)
  2597. ;; (set-variable 'eglot-extend-to-xref t))
  2598. (set-variable 'lsp-python-ms-auto-install-server t)
  2599. (set-variable 'lsp-python-ms-parse-dot-env-enabled t)
  2600. (set-variable 'lsp-python-ms-python-executable-cmd "python3")
  2601. ;; (add-hook 'python-mode-hook #'my-lsp-python-setup)
  2602. (defun my-lsp-python-setup ()
  2603. "Setup python ms."
  2604. (when (and (fboundp 'lsp)
  2605. (require 'lsp-python-ms nil t))
  2606. (lsp)))
  2607. (set-variable 'awk-preview-default-program
  2608. "# C-c C-l: Update preview C-c C-c: Commit and exit
  2609. # C-c C-r: Resest to original C-c C-k: Abort
  2610. {
  2611. # Replace string
  2612. # gsub(BEFORE, AFTER, $0)
  2613. print NR, $0
  2614. }
  2615. ")
  2616. (message "Emacs started at %s"
  2617. (current-time-string))
  2618. (run-with-idle-timer (* 3 60 60) ;; 3 hours
  2619. t
  2620. (lambda ()
  2621. (message "Emacs does nothing for 3 hours: %s"
  2622. (current-time-string))))
  2623. ;; https://emacs-jp.github.io/tips/startup-optimization
  2624. ;; Restore to original value
  2625. (setq gc-cons-threshold my-orig-gc-cons-threshold)
  2626. (setq file-name-handler-alist my-orig-file-name-handler-alist)
  2627. (when (getenv "_EMACS_EL_PROFILE")
  2628. (profiler-report)
  2629. (profiler-stop))
  2630. ;; Local Variables:
  2631. ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
  2632. ;; flycheck-checker: emacs-lisp
  2633. ;; End:
  2634. ;;; emancs.el ends here