You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 11 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 13 година
пре 11 година
пре 13 година
пре 10 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 10 година
пре 11 година
пре 11 година
пре 11 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 11 година
пре 11 година
пре 13 година
пре 13 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 12 година
пре 10 година
пре 12 година
пре 13 година
пре 13 година
пре 13 година
пре 12 година
пре 13 година
пре 10 година
пре 11 година
пре 10 година
пре 11 година
пре 10 година
пре 11 година
пре 11 година
пре 10 година
пре 11 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 12 година
пре 10 година
пре 12 година
пре 12 година
пре 10 година
пре 12 година
пре 11 година
пре 11 година
пре 10 година
пре 11 година
пре 10 година
пре 11 година
пре 11 година
пре 13 година
пре 12 година
пре 13 година
пре 13 година
пре 12 година
пре 13 година
пре 13 година
пре 13 година
пре 11 година
пре 12 година
пре 12 година
пре 10 година
пре 13 година
пре 13 година
пре 13 година
пре 12 година
пре 13 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 12 година
пре 10 година
пре 12 година
пре 12 година
пре 13 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 10 година
пре 12 година
пре 11 година
пре 13 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 13 година
пре 13 година
пре 12 година
пре 13 година
пре 13 година
пре 13 година
пре 12 година
пре 12 година
пре 11 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 10 година
пре 12 година
пре 12 година
пре 10 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 10 година
пре 11 година
пре 10 година
пре 11 година
пре 10 година
пре 11 година
пре 12 година
пре 10 година
пре 12 година
пре 10 година
пре 11 година
пре 12 година
пре 10 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
пре 11 година
пре 12 година
пре 12 година
пре 11 година
пре 13 година
пре 12 година
пре 11 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 12 година
пре 13 година
пре 13 година
пре 12 година
пре 13 година
пре 13 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 11 година
пре 13 година
пре 13 година
пре 12 година
пре 13 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 10 година
пре 13 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 13 година
пре 12 година
пре 12 година
пре 11 година
пре 12 година
пре 11 година
пре 12 година
пре 13 година
пре 10 година
пре 13 година
пре 13 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 10 година
пре 12 година
пре 13 година
пре 10 година
пре 13 година
пре 10 година
пре 13 година
пре 13 година
пре 13 година
пре 11 година
пре 13 година
пре 12 година
пре 10 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 10 година
пре 12 година
пре 10 година
пре 12 година
пре 10 година
пре 12 година
пре 10 година
пре 12 година
пре 10 година
пре 12 година
пре 13 година
пре 13 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 11 година
пре 12 година
пре 12 година
пре 11 година
пре 12 година
пре 12 година
пре 11 година
пре 12 година
пре 12 година
пре 13 година
пре 10 година
пре 13 година
пре 10 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
пре 10 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 13 година
пре 13 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 11 година
пре 13 година
пре 13 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 12 година
пре 11 година
пре 12 година
пре 10 година
пре 12 година
пре 12 година
пре 12 година
пре 11 година
пре 12 година
пре 13 година
пре 10 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 13 година
пре 12 година
пре 12 година
пре 12 година
пре 10 година
пре 12 година
пре 10 година
пре 10 година
пре 10 година
пре 12 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 12 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 12 година
пре 10 година
пре 10 година
пре 12 година
пре 10 година
пре 12 година
пре 13 година
пре 12 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 12 година
пре 10 година
пре 12 година
пре 10 година
пре 12 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 12 година
пре 12 година
пре 13 година
пре 11 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 12 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 12 година
пре 11 година
пре 11 година
пре 11 година
пре 10 година
пре 10 година
пре 12 година
пре 12 година
пре 13 година
пре 10 година
пре 13 година
пре 12 година
пре 13 година
пре 13 година
пре 13 година
пре 12 година
пре 11 година
пре 10 година
пре 11 година
пре 11 година
пре 10 година
пре 10 година
пре 10 година
пре 11 година
пре 10 година
пре 11 година
пре 11 година
пре 10 година
пре 10 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 12 година
пре 10 година
пре 12 година
пре 12 година
пре 12 година
пре 10 година
пре 12 година
пре 12 година
пре 12 година
пре 12 година
пре 10 година
пре 12 година
пре 12 година
пре 12 година
пре 10 година
пре 12 година
пре 13 година
пре 11 година
пре 13 година
пре 11 година
пре 13 година
пре 11 година
пре 13 година
пре 11 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 10 година
пре 11 година
пре 13 година
пре 12 година
пре 13 година
пре 13 година
пре 11 година
пре 12 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 11 година
пре 10 година
пре 11 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568
  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Commentary:
  3. ;;; Code:
  4. ;; (and (file-readable-p "~/.dotfiles/emacs.el")
  5. ;; (load-file "~/.dotfiles/emacs.el"))
  6. ;; make directories
  7. (unless (file-directory-p (expand-file-name user-emacs-directory))
  8. (make-directory (expand-file-name user-emacs-directory)))
  9. (let ((d (expand-file-name (concat user-emacs-directory
  10. "lisp"))))
  11. (unless (file-directory-p d)
  12. (make-directory d))
  13. (add-to-list 'load-path d))
  14. (eval-when-compile
  15. (require 'cl nil t))
  16. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  17. ;; download library from web
  18. (defun fetch-library (url &optional byte-compile-p force-download-p)
  19. "Download a library from URL and locate it in \"~/emacs.d/lisp/\".
  20. Return nil if library unfound and failed to download,
  21. otherwise the path where the library installed.
  22. If BYTE-COMPILE-P is t byte compile the file after downloading.
  23. If FORCE-DOWNLOAD-P it t ignore exisiting library and always download."
  24. (let* ((dir (expand-file-name (concat user-emacs-directory "lisp/")))
  25. (lib (file-name-sans-extension (file-name-nondirectory url)))
  26. (lpath (concat dir lib ".el"))
  27. (locate-p (locate-library lib)))
  28. (if (or force-download-p (not locate-p))
  29. (if (progn (message "Downloading %s..."
  30. url)
  31. (download-file url
  32. lpath
  33. t))
  34. (progn (message "Downloading %s...done"
  35. url)
  36. (when (and byte-compile-p
  37. (require 'bytecomp nil t))
  38. (and (file-exists-p (byte-compile-dest-file lpath))
  39. (delete-file (byte-compile-dest-file lpath)))
  40. (byte-compile-file lpath)))
  41. (progn (and (file-writable-p lpath)
  42. (delete-file lpath))
  43. (message "Downloading %s...failed"
  44. url))))
  45. (locate-library lib)))
  46. (defun download-file (url path &optional ok-if-already-exists)
  47. "Download file from URL and output to PATH.
  48. IF OK-IF-ALREADY-EXISTS is true force download."
  49. (or
  50. (let ((curl (executable-find "curl")))
  51. (when curl
  52. (if (and (not ok-if-already-exists)
  53. (file-exists-p path))
  54. nil
  55. (and (eq 0
  56. (call-process curl
  57. nil
  58. nil
  59. nil
  60. "--output"
  61. path
  62. url
  63. ))
  64. path))))
  65. (ignore-errors
  66. (require 'url)
  67. (url-copy-file url
  68. path
  69. ok-if-already-exists)
  70. path)))
  71. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  72. ;; package
  73. (defvar my-package-list nil
  74. "Package list just for me.")
  75. (setq my-package-list
  76. '(
  77. markdown-mode
  78. yaml-mode
  79. ;; ack
  80. color-moccur
  81. gtags
  82. flymake-jslint
  83. flymake-python-pyflakes
  84. xclip
  85. gnuplot-mode
  86. erlang
  87. )
  88. )
  89. (when (require 'package nil t)
  90. (add-to-list 'package-archives
  91. '("ELPA" . "http://tromey.com/elpa/"))
  92. (add-to-list 'package-archives
  93. '("melpa" . "http://melpa.milkbox.net/packages/")
  94. t)
  95. (add-to-list 'package-archives
  96. '("marmalade" . "http://marmalade-repo.org/packages/"))
  97. (package-initialize)
  98. ;; (package-refresh-contents)
  99. (defun my-auto-install-package ()
  100. "Install packages semi-automatically."
  101. (interactive)
  102. (mapc (lambda (pkg)
  103. (or (package-installed-p pkg)
  104. (locate-library (symbol-name pkg))
  105. (package-install pkg)))
  106. my-package-list))
  107. )
  108. ;; (lazy-load-eval 'sudoku)
  109. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  110. ;; autoload
  111. (defmacro lazy-load-eval (feature &optional functions &rest body)
  112. "Define autoloading FEATURE that defines FUNCTIONS.
  113. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  114. the function same as FEATURE is defined as autoloaded function. BODY is passed
  115. to `eval-after-load'.
  116. When this macro is evaluated, this returns the path to library if FEATURE
  117. found, otherwise returns nil."
  118. (let* ((libname (symbol-name (eval feature)))
  119. (libpath (locate-library libname)))
  120. (and libpath
  121. `(progn
  122. ,@(mapcar (lambda (f)
  123. (unless (fboundp f)
  124. `(progn
  125. (message "Autoloaded function `%S' defined (%s)"
  126. (quote ,f)
  127. ,libpath)
  128. (autoload (quote ,f)
  129. ,libname
  130. ,(concat "Autoloaded function defined in \""
  131. libpath
  132. "\".")
  133. t))))
  134. (or (eval functions)
  135. `(,(eval feature))))
  136. (eval-after-load ,feature
  137. (quote (progn
  138. ,@body)))
  139. (locate-library ,libname)))))
  140. (put 'lazy-load-eval 'lisp-indent-function 2)
  141. (when (lazy-load-eval 'tetris nil
  142. (message "Tetris loaded!"))
  143. (message "Tetris found!"))
  144. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  145. ;; my-idle-hook
  146. (defvar my-idle-hook nil
  147. "Hook run when idle for several secs.")
  148. (defvar my-idle-hook-sec 5
  149. "Second to run `my-idle-hook'.")
  150. (run-with-idle-timer my-idle-hook-sec
  151. t
  152. (lambda ()
  153. (run-hooks 'my-idle-hook)))
  154. ;; (add-hook 'my-idle-hook
  155. ;; (lambda ()
  156. ;; (message "idle hook message")))
  157. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  158. ;; start and quit
  159. (setq inhibit-startup-message t)
  160. (setq confirm-kill-emacs 'y-or-n-p)
  161. (setq gc-cons-threshold (* 1024 1024 4))
  162. (when window-system
  163. (add-to-list 'default-frame-alist '(cursor-type . box))
  164. (add-to-list 'default-frame-alist '(background-color . "white"))
  165. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  166. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  167. ;; does not work?
  168. )
  169. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  170. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  171. (and (fboundp 'tool-bar-mode)
  172. (tool-bar-mode 0))
  173. (and (fboundp 'set-scroll-bar-mode)
  174. (set-scroll-bar-mode nil))
  175. (add-hook 'kill-emacs-hook
  176. ;; load init file when terminating emacs to ensure file is not broken
  177. 'reload-init-file)
  178. (add-hook 'after-init-hook
  179. (lambda ()
  180. (message "%s %s" invocation-name emacs-version)
  181. (message "%s was taken to initialize emacs." (emacs-init-time))
  182. (switch-to-buffer "*Messages*")
  183. ))
  184. (cd ".") ; when using windows use / instead of \ in `default-directory'
  185. ;; locale
  186. (set-language-environment "Japanese")
  187. (set-default-coding-systems 'utf-8-unix)
  188. (prefer-coding-system 'utf-8-unix)
  189. (setq system-time-locale "C")
  190. ;; my prefix map
  191. (defvar my-prefix-map nil
  192. "My prefix map.")
  193. (define-prefix-command 'my-prefix-map)
  194. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  195. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  196. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  197. ;; (comint-show-maximum-output)
  198. ;; kill scratch
  199. (add-hook 'after-init-hook
  200. (lambda ()
  201. (kill-buffer "*scratch*")))
  202. ;; modifier keys
  203. ;; (setq mac-option-modifier 'control)
  204. ;; display
  205. (setq redisplay-dont-pause t)
  206. (setq visible-bell t)
  207. (setq ring-bell-function 'ignore)
  208. (mouse-avoidance-mode 'banish)
  209. (and window-system
  210. (fetch-library
  211. "https://raw.github.com/10sr/emacs-lisp/master/save-window-size.el"
  212. t)
  213. (require 'save-window-size nil t))
  214. (defun reload-init-file ()
  215. "Reload Emacs init file."
  216. (interactive)
  217. (when (file-readable-p user-init-file)
  218. (load-file user-init-file)))
  219. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  220. ;; for windows
  221. (defun start-ckw-bash ()
  222. "Start ckw in windows."
  223. (interactive)
  224. (start-process
  225. "ckw_bash"
  226. nil
  227. "C:/Documents and Settings/sr/Application Data/dbx/apps/ckw/ckw.exe"))
  228. ;; command seems to have to be in c drive
  229. (defun my-w32-add-export-path (&rest args)
  230. "Add pathes ARGS for windows."
  231. (mapc (lambda (path)
  232. (add-to-list 'exec-path (expand-file-name path)))
  233. (reverse args))
  234. (setenv "PATH"
  235. (mapconcat 'convert-standard-filename
  236. exec-path
  237. ";")))
  238. (when (eq system-type 'windows-nt)
  239. ;; (setq scheme-program-name "\"c:/Program Files/Gauche/bin/gosh.exe\" -i")
  240. ;; (setq python-python-command "c:/Python26/python.exe")
  241. ;; (define-key my-prefix-map (kbd "C-c") 'start-ckw-bash)
  242. (my-w32-add-export-path "c:/Windows/system"
  243. "c:/Windows/System32"
  244. "c:/Program Files/Git/bin"
  245. "c:/MinGW/bin"
  246. "c:/MinGW/mingw32/bin"
  247. (expand-file-name "~/.local/bin")
  248. (expand-file-name "~/dbx/apps/bin"))
  249. (when window-system
  250. (setq w32-enable-synthesized-fonts t))
  251. (setq w32-apps-modifier 'meta)
  252. (setq file-name-coding-system 'sjis))
  253. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  254. ;; global keys
  255. (global-set-key (kbd "<up>") 'scroll-down-line)
  256. (global-set-key (kbd "<down>") 'scroll-up-line)
  257. (global-set-key (kbd "<left>") 'scroll-down)
  258. (global-set-key (kbd "<right>") 'scroll-up)
  259. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  260. (global-set-key (kbd "C-\\") help-map)
  261. (define-key ctl-x-map (kbd "DEL") help-map)
  262. (define-key ctl-x-map (kbd "C-h") help-map)
  263. (define-key help-map "a" 'apropos)
  264. ;; disable annoying keys
  265. (global-set-key [prior] 'ignore)
  266. (global-set-key (kbd "<next>") 'ignore)
  267. (global-set-key [menu] 'ignore)
  268. (global-set-key [down-mouse-1] 'ignore)
  269. (global-set-key [down-mouse-2] 'ignore)
  270. (global-set-key [down-mouse-3] 'ignore)
  271. (global-set-key [mouse-1] 'ignore)
  272. (global-set-key [mouse-2] 'ignore)
  273. (global-set-key [mouse-3] 'ignore)
  274. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  275. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  276. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  277. ;; title and mode-line
  278. (when (fetch-library
  279. "https://raw.github.com/10sr/emacs-lisp/master/terminal-title.el"
  280. t)
  281. (require 'terminal-title nil t)
  282. ;; if TERM is not screen use default value
  283. (if (getenv "TMUX")
  284. ;; if use tmux locally just basename of current dir
  285. (setq terminal-title-format
  286. '((file-name-nondirectory (directory-file-name
  287. default-directory))))
  288. (when (equal (car (split-string (frame-parameter nil
  289. 'tty-type)
  290. "-"))
  291. "screen")
  292. (if (getenv "SSH_CONNECTION")
  293. ;; TMUX is not set but TERM is screen:
  294. ;; it seems that TMUX is used by locally and ssh to remote host
  295. (setq terminal-title-format
  296. `("em:"
  297. ,user-login-name
  298. "@"
  299. ,(car (split-string system-name
  300. "\\."))
  301. ":"
  302. (file-name-nondirectory (directory-file-name
  303. default-directory))))
  304. ;; this wont happen? (TMUX is not set, TERM is screen, not ssh-ed)
  305. (setq terminal-title-format
  306. '((file-name-nondirectory (directory-file-name
  307. default-directory)))))))
  308. (terminal-title-mode))
  309. (setq eol-mnemonic-dos "\\r\\n")
  310. (setq eol-mnemonic-mac "\\r")
  311. (setq eol-mnemonic-unix "\\n")
  312. (which-function-mode 0)
  313. (line-number-mode 0)
  314. (column-number-mode 0)
  315. (size-indication-mode 0)
  316. (setq mode-line-position
  317. '(:eval (format "L%%l/%d,C%%c"
  318. (count-lines (point-max)
  319. (point-min)))))
  320. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  321. ;; display date
  322. (add-hook 'after-init-hook
  323. (lambda ()
  324. (when display-time-mode
  325. (display-time-update))
  326. ))
  327. (when (require 'time nil t)
  328. (setq display-time-interval 29)
  329. (setq display-time-day-and-date t)
  330. (setq display-time-format "%a, %d %b %Y %T")
  331. (if window-system
  332. (display-time-mode 0)
  333. (display-time-mode 1)))
  334. ;; ;; current directory
  335. ;; (let ((ls (member 'mode-line-buffer-identification
  336. ;; mode-line-format)))
  337. ;; (setcdr ls
  338. ;; (cons '(:eval (concat " ("
  339. ;; (abbreviate-file-name default-directory)
  340. ;; ")"))
  341. ;; (cdr ls))))
  342. ;; ;; display last modified time
  343. ;; (let ((ls (member 'mode-line-buffer-identification
  344. ;; mode-line-format)))
  345. ;; (setcdr ls
  346. ;; (cons '(:eval (concat " "
  347. ;; my-buffer-file-last-modified-time))
  348. ;; (cdr ls))))
  349. (defun buffer-list-not-start-with-space ()
  350. "Return a list of buffers that not start with whitespaces."
  351. (let ((bl (buffer-list))
  352. b nbl)
  353. (while bl
  354. (setq b (pop bl))
  355. (unless (string-equal " "
  356. (substring (buffer-name b)
  357. 0
  358. 1))
  359. (add-to-list 'nbl b)))
  360. nbl))
  361. ;; http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/
  362. ;; (add-to-list 'minor-mode-alist
  363. ;; '(global-whitespace-mode ""))
  364. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  365. ;; system info
  366. (defun my-message-current-info ()
  367. "Echo current login name, hostname and directory."
  368. (interactive)
  369. (message "%s@%s:%s"
  370. user-login-name
  371. system-name
  372. (abbreviate-file-name default-directory)))
  373. ;; (run-with-idle-timer 3
  374. ;; t
  375. ;; 'my-message-current-info)
  376. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  377. ;; minibuffer
  378. (setq insert-default-directory t)
  379. (setq completion-ignore-case t
  380. read-file-name-completion-ignore-case t
  381. read-buffer-completion-ignore-case t)
  382. (setq resize-mini-windows t)
  383. (temp-buffer-resize-mode 1)
  384. (savehist-mode 1)
  385. (fset 'yes-or-no-p 'y-or-n-p)
  386. ;; complete symbol when `eval'
  387. (define-key read-expression-map (kbd "TAB") 'lisp-complete-symbol)
  388. (define-key minibuffer-local-map (kbd "C-u")
  389. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  390. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  391. ;; letters, font-lock mode and fonts
  392. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  393. ;; (set-window-margins (selected-window) 1 1)
  394. (and (or (eq system-type 'Darwin)
  395. (eq system-type 'darwin))
  396. (fboundp 'mac-set-input-method-parameter)
  397. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  398. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  399. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  400. (boundp 'input-method-inactivate-hook))
  401. (add-hook 'input-method-activate-hook
  402. (lambda () (set-cursor-color "red")))
  403. (add-hook 'input-method-inactivate-hook
  404. (lambda () (set-cursor-color "black"))))
  405. (when (require 'paren nil t)
  406. (show-paren-mode 1)
  407. (setq show-paren-delay 0.5
  408. show-paren-style 'parenthesis) ; mixed is hard to read
  409. (set-face-background 'show-paren-match
  410. (face-foreground 'default))
  411. (set-face-inverse-video-p 'show-paren-match
  412. t))
  413. (transient-mark-mode 1)
  414. (global-font-lock-mode 1)
  415. (setq font-lock-global-modes
  416. '(not
  417. help-mode
  418. eshell-mode
  419. term-mode
  420. Man-mode))
  421. ;; (standard-display-ascii ?\n "$\n")
  422. (defvar my-eol-face
  423. '(("\n" . (0 font-lock-comment-face t nil)))
  424. )
  425. (defvar my-tab-face
  426. '(("\t" . '(0 highlight t nil))))
  427. (defvar my-jspace-face
  428. '(("\u3000" . '(0 highlight t nil))))
  429. (add-hook 'font-lock-mode-hook
  430. (lambda ()
  431. ;; (font-lock-add-keywords nil my-eol-face)
  432. (font-lock-add-keywords nil my-jspace-face)
  433. ))
  434. (when (require 'whitespace nil t)
  435. (add-to-list 'whitespace-display-mappings ; not work
  436. `(tab-mark ?\t ,(vconcat "^I\t")))
  437. (add-to-list 'whitespace-display-mappings
  438. `(newline-mark ?\n ,(vconcat "$\n")))
  439. (setq whitespace-style '(face
  440. trailing ; trailing blanks
  441. newline ; newlines
  442. newline-mark ; use display table for newline
  443. ;; tab-mark
  444. empty ; empty lines at beg or end of buffer
  445. lines-tail ; lines over 80
  446. ))
  447. ;; (setq whitespace-newline 'font-lock-comment-face)
  448. (global-whitespace-mode t)
  449. (when (eq (display-color-cells)
  450. 256)
  451. (set-face-foreground 'whitespace-newline "brightblack")))
  452. (and nil
  453. (fetch-library
  454. "http://www.emacswiki.org/emacs/download/fill-column-indicator.el"
  455. t)
  456. (require 'fill-column-indicator nil t)
  457. (setq fill-column-indicator))
  458. ;; highlight current line
  459. ;; http://wiki.riywo.com/index.php?Meadow
  460. (defface my-hl-line
  461. '((((min-colors 256)
  462. (background dark))
  463. (:background "color-234"))
  464. (((min-colors 256)
  465. (background light))
  466. (:background "color-234"))
  467. (t
  468. (:underline "black")))
  469. "*Face used by hl-line.")
  470. (setq hl-line-face 'my-hl-line) ;; (setq hl-line-face nil)
  471. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  472. (setq hl-line-global-modes
  473. '(not
  474. term-mode))
  475. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  476. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  477. ;; fonts
  478. (defun my-set-ascii-and-jp-font (list)
  479. "Set font configuration List."
  480. (let ((fspec1 (if (> emacs-major-version 22)
  481. ;; font spec is available in emacs23 and later
  482. (font-spec :family (nth 2 list) :size (nth 3 list))
  483. (cons (nth 2 list) "jisx0208.*")))
  484. (fspec2 (if (> emacs-major-version 22)
  485. (font-spec :family (nth 2 list) :size (nth 3 list))
  486. (cons (nth 2 list) "jisx0201.*"))))
  487. (set-face-attribute 'default nil
  488. :family (nth 0 list)
  489. :height (nth 1 list))
  490. (set-fontset-font "fontset-default"
  491. 'japanese-jisx0208
  492. fspec1)
  493. (set-fontset-font "fontset-default"
  494. 'katakana-jisx0201
  495. fspec2)))
  496. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 90 "takaogothic" 13))
  497. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "takaogothic" 14))
  498. ;; (my-set-ascii-and-jp-font '("dejavu sans mono" 100 "ms gothic" 14))
  499. ;; (my-set-ascii-and-jp-font '("monaco" 75 "takaogothic" 11))
  500. ;; (my-set-ascii-and-jp-font '("monaco" 90 "takaogothic" 13))
  501. ;; (my-set-ascii-and-jp-font '("ProggyCleanTTSZ" 120 "takaogothic" 11))
  502. ;; あ a
  503. (and (fetch-library
  504. "https://raw.github.com/10sr/emacs-lisp/master/set-modeline-color.el"
  505. t)
  506. (progn
  507. (require 'set-modeline-color nil t)))
  508. (let ((fg (face-foreground 'default))
  509. (bg (face-background 'default)))
  510. (set-face-background 'mode-line-inactive
  511. (if (face-inverse-video-p 'mode-line) fg bg))
  512. (set-face-foreground 'mode-line-inactive
  513. (if (face-inverse-video-p 'mode-line) bg fg)))
  514. (set-face-underline 'mode-line-inactive
  515. t)
  516. (set-face-underline 'vertical-border
  517. nil)
  518. (and (fetch-library
  519. "https://raw.github.com/tarao/elisp/master/end-mark.el"
  520. t)
  521. (require 'end-mark nil t)
  522. (global-end-mark-mode))
  523. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  524. ;; file handling
  525. (setq revert-without-query '(".+"))
  526. ;; save cursor position
  527. (setq save-place-file (concat user-emacs-directory
  528. "places"))
  529. (when (require 'saveplace nil t)
  530. (setq-default save-place t))
  531. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  532. (setq make-backup-files t)
  533. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  534. (setq backup-directory-alist
  535. (cons (cons "\\.*$" (expand-file-name "~/.emacs.d/backup"))
  536. backup-directory-alist))
  537. (setq version-control 'never)
  538. (setq delete-old-versions t)
  539. (setq auto-save-list-file-prefix (expand-file-name "~/.emacs.d/auto-save/"))
  540. (setq delete-auto-save-files t)
  541. (add-to-list 'completion-ignored-extensions ".bak")
  542. ;; (setq delete-by-moving-to-trash t
  543. ;; trash-directory "~/.emacs.d/trash")
  544. (add-hook 'after-save-hook
  545. 'executable-make-buffer-file-executable-if-script-p)
  546. (setq bookmark-default-file "~/.emacs.d/bmk")
  547. (add-hook 'recentf-load-hook
  548. (lambda ()
  549. (add-to-list 'recentf-exclude
  550. (regexp-quote bookmark-default-file))))
  551. (and (fetch-library
  552. "https://raw.github.com/10sr/emacs-lisp/master/read-only-only-mode.el"
  553. t)
  554. (lazy-load-eval 'read-only-only-mode))
  555. (and (fetch-library
  556. "https://raw.github.com/10sr/emacs-lisp/master/smart-revert.el"
  557. t)
  558. (require 'smart-revert nil t)
  559. (smart-revert-on))
  560. ;; autosave
  561. (and (fetch-library
  562. "https://raw.github.com/10sr/emacs-lisp/master/autosave.el"
  563. t)
  564. (require 'autosave nil t)
  565. (autosave-set 2))
  566. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  567. ;; editting
  568. (defun my-copy-whole-line ()
  569. "Copy whole line."
  570. (interactive)
  571. (kill-new (concat (buffer-substring (point-at-bol)
  572. (point-at-eol))
  573. "\n")))
  574. (setq require-final-newline t)
  575. (setq kill-whole-line t)
  576. (setq scroll-conservatively 35
  577. scroll-margin 2
  578. scroll-step 0)
  579. (setq-default major-mode 'text-mode)
  580. (setq next-line-add-newlines nil)
  581. (setq kill-read-only-ok t)
  582. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  583. ;; (setq-default line-spacing 0.2)
  584. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  585. (setq-default tab-width 4)
  586. (setq-default indent-tabs-mode nil)
  587. (setq-default indent-line-function nil)
  588. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  589. (delete-selection-mode 1)
  590. (cua-mode 0)
  591. (setq line-move-visual nil)
  592. ;; key bindings
  593. ;; moving around
  594. ;; (global-set-key (kbd "M-j") 'next-line)
  595. ;; (global-set-key (kbd "M-k") 'previous-line)
  596. ;; (global-set-key (kbd "M-h") 'backward-char)
  597. ;; (global-set-key (kbd "M-l") 'forward-char)
  598. ;;(keyboard-translate ?\M-j ?\C-j)
  599. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  600. (define-key esc-map "p" 'backward-paragraph)
  601. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  602. (define-key esc-map "n" 'forward-paragraph)
  603. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  604. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  605. (global-set-key (kbd "C-<left>") 'scroll-down)
  606. (global-set-key (kbd "C-<right>") 'scroll-up)
  607. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  608. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  609. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  610. ;; C-h and DEL
  611. (global-set-key (kbd "C-h") (kbd "DEL"))
  612. (global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  613. (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  614. (define-key esc-map "k" 'my-copy-whole-line)
  615. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  616. (define-key esc-map "u" 'undo)
  617. (define-key esc-map "i" (kbd "ESC TAB"))
  618. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  619. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  620. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  621. (define-key my-prefix-map (kbd "C-o") 'occur)
  622. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  623. ;; japanese input method
  624. (defun my-load-scim ()
  625. "Use scim-bridge.el as japanese im."
  626. ;; Load scim-bridge.
  627. (when (require 'scim-bridge nil t)
  628. ;; Turn on scim-mode automatically after loading .emacs
  629. (add-hook 'after-init-hook 'scim-mode-on)
  630. (setq scim-cursor-color "red")
  631. (scim-define-preedit-key ?\^h t)
  632. (scim-define-common-key ?\* nil)
  633. (scim-define-common-key ?\^/ nil)))
  634. (defun my-load-anthy ()
  635. "Use anthy.el as japanese im."
  636. ;; anthy
  637. (when (require 'anthy nil t)
  638. (global-set-key
  639. (kbd "<muhenkan>") (lambda () (interactive) (anthy-mode-off)))
  640. (global-set-key (kbd "<henkan>") (lambda () (interactive) (anthy-mode-on)))
  641. (when (>= emacs-major-version 23)
  642. (setq anthy-accept-timeout 1))))
  643. ;; quail
  644. ;; aproposs input-method for some information
  645. ;; (setq default-input-method "japanese")
  646. (defun my-load-mozc-el ()
  647. "Use mozc.el as japanese im."
  648. (setq mozc-leim-title "[MZ]")
  649. (when (require 'mozc nil t)
  650. (setq defauit-input-method "japanese-mozc")
  651. ))
  652. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  653. ;; gmail
  654. (setq mail-interactive t
  655. send-mail-function 'smtpmail-send-it
  656. ;; message-send-mail-function 'smtpmail-send-it
  657. smtpmail-smtp-server "smtp.gmail.com"
  658. smtpmail-smtp-service 587
  659. smtpmail-starttls-credentials '(("smtp.gmail.com" 587
  660. "8.slashes@gmail.com" nil))
  661. smtpmail-auth-credentials '(("smtp.gmail.com" 587
  662. "8.slashes@gmail.com" nil))
  663. user-mail-address "8.slashes@gmail.com")
  664. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  665. ;; buffer killing
  666. ;; (defun my-delete-window-killing-buffer () nil)
  667. (defun my-query-kill-current-buffer ()
  668. "Interactively kill current buffer."
  669. (interactive)
  670. (if (y-or-n-p (concat "kill current buffer? :"))
  671. (kill-buffer (current-buffer))))
  672. (substitute-key-definition 'kill-buffer
  673. 'my-query-kill-current-buffer
  674. global-map)
  675. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  676. (defun my-kill-buffers ()
  677. "Kill buffers that visit files."
  678. (interactive)
  679. (mapcar (lambda (buf)
  680. (when (buffer-file-name buf)
  681. (kill-buffer buf)))
  682. (buffer-list)))
  683. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  684. ;; share clipboard with x
  685. ;; this page describes this in details, but only these sexps seem to be needed
  686. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  687. (and (not window-system)
  688. (not (eq window-system 'mac))
  689. (getenv "DISPLAY")
  690. (not (equal (getenv "DISPLAY") ""))
  691. (executable-find "xclip")
  692. ;; (< emacs-major-version 24)
  693. (fetch-library "http://www.emacswiki.org/emacs/download/xclip.el" t)
  694. (require 'xclip nil t)
  695. (turn-on-xclip))
  696. (and (eq system-type 'darwin)
  697. (fetch-library
  698. "https://raw.github.com/10sr/emacs-lisp/master/pasteboard.el"
  699. t)
  700. (require 'pasteboard nil t)
  701. (turn-on-pasteboard)
  702. (getenv "TMUX")
  703. (pasteboard-enable-rtun))
  704. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  705. ;; https://github.com/lunaryorn/flycheck
  706. (when (require 'flycheck nil t)
  707. (add-hook 'after-init-hook 'global-flycheck-mode))
  708. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  709. ;; window
  710. (and (fetch-library
  711. "https://raw.github.com/10sr/emacs-lisp/master/window-organizer.el"
  712. t)
  713. (lazy-load-eval 'window-organizer)
  714. (define-key ctl-x-map (kbd "w") 'window-organizer))
  715. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  716. ;; some modes and hooks
  717. (and (fetch-library
  718. "https://raw.github.com/10sr/emacs-lisp/master/remember-major-modes-mode.el"
  719. t)
  720. (require 'remember-major-modes-mode nil t)
  721. (remember-major-modes-mode 1)
  722. )
  723. ;; Detect file type from shebang and set major-mode.
  724. (add-to-list 'interpreter-mode-alist
  725. '("python3" . python-mode))
  726. (add-to-list 'interpreter-mode-alist
  727. '("python2" . python-mode))
  728. ;; http://fukuyama.co/foreign-regexp
  729. '(and (fetch-library
  730. "https://raw.github.com/k-talo/foreign-regexp.el/master/foreign-regexp.el"
  731. t)
  732. (require 'foreign-regexp nil t)
  733. (progn
  734. (setq foreign-regexp/regexp-type 'perl)
  735. '(setq reb-re-syntax 'foreign-regexp)
  736. ))
  737. (require 'session nil t)
  738. (lazy-load-eval 'sql '(sql-mode)
  739. (require 'sql-indent nil t))
  740. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/gtkbm.el"
  741. t)
  742. (lazy-load-eval 'gtkbm)
  743. (global-set-key (kbd "C-x C-d") 'gtkbm))
  744. (and (fetch-library
  745. "https://raw.github.com/10sr/emacs-lisp/master/git-command.el"
  746. t)
  747. (lazy-load-eval 'git-command
  748. nil
  749. (add-to-list 'git-command-major-mode-alist
  750. '("di" . diff-mode))
  751. (add-to-list 'git-command-major-mode-alist
  752. '("graph" . fundamental-mode))
  753. (add-to-list 'git-command-major-mode-alist
  754. '("log" . fundamental-mode)))
  755. ;; (setq git-command-default-options "-c color.ui=always")
  756. (define-key ctl-x-map "g" 'git-command))
  757. (and (fetch-library
  758. "http://www.emacswiki.org/emacs/download/sl.el"
  759. t)
  760. (lazy-load-eval 'sl))
  761. (defalias 'qcalc 'quick-calc)
  762. (require 'simple nil t)
  763. (add-hook 'makefile-mode-hook
  764. (lambda ()
  765. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  766. ;; this functions is set in write-file-functions, i cannot find any
  767. ;; good way to remove this.
  768. (fset 'makefile-warn-suspicious-lines 'ignore)
  769. ))
  770. (add-hook 'verilog-mode-hook
  771. (lambda ()
  772. (define-key verilog-mode-map ";" 'self-insert-command)))
  773. (setq diff-switches "-u")
  774. (add-hook 'diff-mode-hook
  775. (lambda ()
  776. (when (eq major-mode
  777. 'diff-mode)
  778. ;; do not pass when major-mode is derived mode of diff-mode
  779. (view-mode 1))
  780. (set-face-attribute 'diff-header nil
  781. :foreground nil
  782. :background nil
  783. :weight 'bold)
  784. (set-face-attribute 'diff-file-header nil
  785. :foreground nil
  786. :background nil
  787. :weight 'bold)
  788. (set-face-foreground 'diff-index-face "blue")
  789. (set-face-attribute 'diff-hunk-header nil
  790. :foreground "cyan"
  791. :weight 'normal)
  792. (set-face-attribute 'diff-context nil
  793. ;; :foreground "white"
  794. :foreground nil
  795. :weight 'normal)
  796. (set-face-foreground 'diff-removed-face "red")
  797. (set-face-foreground 'diff-added-face "green")
  798. (set-face-background 'diff-removed-face nil)
  799. (set-face-background 'diff-added-face nil)
  800. (set-face-attribute 'diff-changed nil
  801. :foreground "magenta"
  802. :weight 'normal)
  803. ))
  804. ;; (ffap-bindings)
  805. (add-hook 'sh-mode-hook
  806. (lambda ()
  807. (define-key sh-mode-map
  808. (kbd "C-x C-e")
  809. 'my-execute-shell-command-current-line)))
  810. (setq sh-here-document-word "__EOC__")
  811. (defun my-execute-shell-command-current-line ()
  812. "Run current line as shell command."
  813. (interactive)
  814. (shell-command (buffer-substring-no-properties (point-at-bol)
  815. (point))))
  816. (setq auto-mode-alist
  817. `(("autostart\\'" . sh-mode)
  818. ("xinitrc\\'" . sh-mode)
  819. ("xprograms\\'" . sh-mode)
  820. ("PKGBUILD\\'" . sh-mode)
  821. ,@auto-mode-alist))
  822. (and (lazy-load-eval 'pkgbuild-mode)
  823. (setq auto-mode-alist (append '(("PKGBUILD\\'" . pkgbuild-mode))
  824. auto-mode-alist)))
  825. (add-hook 'html-mode-hook
  826. (lambda ()
  827. (define-key html-mode-map (kbd "C-m")
  828. 'reindent-then-newline-and-indent)))
  829. (add-hook 'text-mode-hook
  830. (lambda ()
  831. (define-key text-mode-map (kbd "C-m") 'newline)))
  832. (add-to-list 'Info-default-directory-list
  833. (expand-file-name "~/.info/emacs-ja"))
  834. (add-hook 'apropos-mode-hook
  835. (lambda ()
  836. (define-key apropos-mode-map "n" 'next-line)
  837. (define-key apropos-mode-map "p" 'previous-line)
  838. ))
  839. (add-hook 'isearch-mode-hook
  840. (lambda ()
  841. ;; (define-key isearch-mode-map
  842. ;; (kbd "C-j") 'isearch-other-control-char)
  843. ;; (define-key isearch-mode-map
  844. ;; (kbd "C-k") 'isearch-other-control-char)
  845. ;; (define-key isearch-mode-map
  846. ;; (kbd "C-h") 'isearch-other-control-char)
  847. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  848. (define-key isearch-mode-map (kbd "M-r")
  849. 'isearch-query-replace-regexp)))
  850. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  851. (setq lazy-highlight-cleanup nil)
  852. ;; face for isearch highlighing
  853. (set-face-attribute 'lazy-highlight
  854. nil
  855. :foreground `unspecified
  856. :background `unspecified
  857. :underline t
  858. ;; :weight `bold
  859. )
  860. (add-hook 'outline-mode-hook
  861. (lambda ()
  862. (if (string-match "\\.md\\'" buffer-file-name)
  863. (set (make-local-variable 'outline-regexp) "#+ "))))
  864. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  865. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  866. (when (fetch-library
  867. "http://jblevins.org/projects/markdown-mode/markdown-mode.el"
  868. t)
  869. (lazy-load-eval 'markdown-mode)
  870. (setq markdown-command (or (executable-find "markdown")
  871. (executable-find "markdown.pl")))
  872. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'markdown-mode))
  873. (add-hook 'markdown-mode-hook
  874. (lambda ()
  875. (outline-minor-mode 1)
  876. (flyspell-mode)
  877. (set (make-local-variable 'comment-start) ";"))))
  878. ;; c-mode
  879. ;; http://www.emacswiki.org/emacs/IndentingC
  880. ;; http://en.wikipedia.org/wiki/Indent_style
  881. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  882. (when (lazy-load-eval 'cc-vars
  883. nil
  884. (add-to-list 'c-default-style
  885. '(c-mode . "k&r"))
  886. (add-to-list 'c-default-style
  887. '(c++-mode . "k&r"))
  888. (add-hook 'c-mode-common-hook
  889. (lambda ()
  890. ;; why c-basic-offset in k&r style defaults to 5 ???
  891. (setq c-basic-offset 4
  892. indent-tabs-mode nil)
  893. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  894. (c-toggle-hungry-state -1)
  895. ;; (and (require 'gtags nil t)
  896. ;; (gtags-mode 1))
  897. ))))
  898. (when (fetch-library
  899. "https://raw.github.com/mooz/js2-mode/master/js2-mode.el"
  900. t)
  901. (lazy-load-eval 'js2-mode)
  902. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  903. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  904. (add-hook 'js2-mode-hook
  905. (lambda ()
  906. (define-key js2-mode-map (kbd "C-m") (lambda ()
  907. (interactive)
  908. (js2-enter-key)
  909. (indent-for-tab-command)))
  910. ;; (add-hook (kill-local-variable 'before-save-hook)
  911. ;; 'js2-before-save)
  912. ;; (add-hook 'before-save-hook
  913. ;; 'my-indent-buffer
  914. ;; nil
  915. ;; t)
  916. )))
  917. (when (lazy-load-eval 'flymake-jslint
  918. '(flymake-jslint-load))
  919. (lazy-load-eval 'js nil
  920. (add-hook 'js-mode-hook
  921. 'flymake-jslint-load)))
  922. (require 'js-doc nil t)
  923. (when (require 'uniquify nil t)
  924. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  925. (setq uniquify-ignore-buffers-re "*[^*]+*")
  926. (setq uniquify-min-dir-content 1))
  927. (add-hook 'view-mode-hook
  928. (lambda()
  929. (define-key view-mode-map "j" 'scroll-up-line)
  930. (define-key view-mode-map "k" 'scroll-down-line)
  931. (define-key view-mode-map "v" 'toggle-read-only)
  932. (define-key view-mode-map "q" 'bury-buffer)
  933. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  934. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  935. ;; (define-key view-mode-map
  936. ;; "n" 'nonincremental-repeat-search-forward)
  937. ;; (define-key view-mode-map
  938. ;; "N" 'nonincremental-repeat-search-backward)
  939. (define-key view-mode-map "/" 'isearch-forward-regexp)
  940. (define-key view-mode-map "?" 'isearch-backward-regexp)
  941. (define-key view-mode-map "n" 'isearch-repeat-forward)
  942. (define-key view-mode-map "N" 'isearch-repeat-backward)
  943. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point)
  944. ))
  945. (global-set-key "\M-r" 'view-mode)
  946. ;; (setq view-read-only t)
  947. ;; (defun my-view-mode-search-word (word)
  948. ;; "Search for word current directory and subdirectories.
  949. ;; If called intearctively, find word at point."
  950. ;; (interactive (list (thing-at-point 'symbol)))
  951. ;; (if word
  952. ;; (if (and (require 'gtags nil t)
  953. ;; (gtags-get-rootpath))
  954. ;; (gtags-goto-tag word "s")
  955. ;; (my-rgrep word))
  956. ;; (message "No word at point.")
  957. ;; nil))
  958. (add-hook 'Man-mode-hook
  959. (lambda ()
  960. (view-mode 1)
  961. (setq truncate-lines nil)))
  962. (setq Man-notify-method (if window-system
  963. 'newframe
  964. 'aggressive))
  965. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  966. ;; python
  967. (when (lazy-load-eval 'python '(python-mode))
  968. (setq python-python-command (or (executable-find "python3")
  969. (executable-find "python")))
  970. ;; (defun my-python-run-as-command ()
  971. ;; ""
  972. ;; (interactive)
  973. ;; (shell-command (concat python-python-command " " buffer-file-name)))
  974. (defun my-python-display-python-buffer ()
  975. ""
  976. (interactive)
  977. (set-window-text-height (display-buffer python-buffer
  978. t)
  979. 7))
  980. (add-hook 'python-mode-hook
  981. (lambda ()
  982. (define-key python-mode-map
  983. (kbd "C-c C-e") 'my-python-run-as-command)
  984. (define-key python-mode-map
  985. (kbd "C-c C-b") 'my-python-display-python-buffer)
  986. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)))
  987. (add-hook 'inferior-python-mode-hook
  988. (lambda ()
  989. (my-python-display-python-buffer)
  990. (define-key inferior-python-mode-map
  991. (kbd "<up>") 'comint-previous-input)
  992. (define-key inferior-python-mode-map
  993. (kbd "<down>") 'comint-next-input))))
  994. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  995. ;; GNU GLOBAL(gtags)
  996. ;; http://uguisu.skr.jp/Windows/gtags.html
  997. ;; http://eigyr.dip.jp/gtags.html
  998. ;; http://cha.la.coocan.jp/doc/gnu_global.html
  999. (let ((d "/opt/local/share/gtags/"))
  1000. (and (file-directory-p d)
  1001. (add-to-list 'load-path
  1002. d)))
  1003. (when (lazy-load-eval 'gtags '(gtags-mode))
  1004. (add-hook 'gtags-mode-hook
  1005. (lambda ()
  1006. (view-mode gtags-mode)
  1007. (setq gtags-select-buffer-single t)
  1008. ;; (local-set-key "\M-t" 'gtags-find-tag)
  1009. ;; (local-set-key "\M-r" 'gtags-find-rtag)
  1010. ;; (local-set-key "\M-s" 'gtags-find-symbol)
  1011. ;; (local-set-key "\C-t" 'gtags-pop-stack)
  1012. (define-key gtags-mode-map (kbd "C-x t h")
  1013. 'gtags-find-tag-from-here)
  1014. (define-key gtags-mode-map (kbd "C-x t t") 'gtags-find-tag)
  1015. (define-key gtags-mode-map (kbd "C-x t r") 'gtags-find-rtag)
  1016. (define-key gtags-mode-map (kbd "C-x t s") 'gtags-find-symbol)
  1017. (define-key gtags-mode-map (kbd "C-x t p") 'gtags-find-pattern)
  1018. (define-key gtags-mode-map (kbd "C-x t f") 'gtags-find-file)
  1019. (define-key gtags-mode-map (kbd "C-x t b") 'gtags-pop-stack) ;back
  1020. ))
  1021. (add-hook 'gtags-select-mode-hook
  1022. (lambda ()
  1023. (define-key gtags-select-mode-map (kbd "C-m") 'gtags-select-tag)
  1024. ))
  1025. )
  1026. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1027. ;; term mode
  1028. ;; (setq multi-term-program shell-file-name)
  1029. (and (fetch-library "http://www.emacswiki.org/emacs/download/multi-term.el"
  1030. t)
  1031. (lazy-load-eval 'multi-term)
  1032. (progn
  1033. (setq multi-term-switch-after-close nil)
  1034. (setq multi-term-dedicated-select-after-open-p t)
  1035. (setq multi-term-dedicated-window-height 20)))
  1036. (when (lazy-load-eval 'term '(term ansi-term))
  1037. (defun my-term-quit-or-send-raw ()
  1038. ""
  1039. (interactive)
  1040. (if (get-buffer-process (current-buffer))
  1041. (call-interactively 'term-send-raw)
  1042. (kill-buffer)))
  1043. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  1044. ;; (setq term-ansi-default-program shell-file-name)
  1045. (add-hook 'term-setup-hook
  1046. (lambda ()
  1047. (setq term-display-table (make-display-table))))
  1048. (add-hook 'term-mode-hook
  1049. (lambda ()
  1050. (unless (memq (current-buffer)
  1051. (and (featurep 'multi-term)
  1052. ;; current buffer is not multi-term buffer
  1053. (multi-term-list)))
  1054. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  1055. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  1056. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  1057. ;; (define-key term-raw-map "\C-f" 'forward-char)
  1058. ;; (define-key term-raw-map "\C-b" 'backward-char)
  1059. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  1060. (define-key term-raw-map
  1061. "\C-x" (lookup-key (current-global-map) "\C-x"))
  1062. (define-key term-raw-map
  1063. "\C-z" (lookup-key (current-global-map) "\C-z"))
  1064. )
  1065. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  1066. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  1067. (define-key term-raw-map (kbd "<up>") 'scroll-down-line)
  1068. (define-key term-raw-map (kbd "<down>") 'scroll-up-line)
  1069. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  1070. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  1071. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  1072. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  1073. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  1074. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  1075. (define-key term-raw-map [delete] 'term-send-raw)
  1076. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  1077. (define-key term-raw-map "\C-y" 'term-paste)
  1078. (define-key term-raw-map
  1079. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  1080. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  1081. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  1082. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  1083. ;; (define-key term-raw-map "\C-d" 'delete-char)
  1084. (set (make-local-variable 'scroll-margin) 0)
  1085. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  1086. ;; (cua-mode 0)
  1087. ;; (and cua-mode
  1088. ;; (local-unset-key (kbd "C-c")))
  1089. ;; (define-key cua--prefix-override-keymap
  1090. ;;"\C-c" 'term-interrupt-subjob)
  1091. (set (make-local-variable 'hl-line-range-function)
  1092. (lambda ()
  1093. '(0 . 0)))
  1094. ))
  1095. ;; (add-hook 'term-exec-hook 'forward-char)
  1096. )
  1097. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1098. ;; buffer switching
  1099. (when (lazy-load-eval 'bs '(bs-show)
  1100. ;; (add-to-list 'bs-configurations
  1101. ;; '("processes" nil get-buffer-process ".*" nil nil))
  1102. (add-to-list 'bs-configurations
  1103. '("this-frame" nil (lambda (buf)
  1104. (memq buf (my-frame-buffer-get)))
  1105. ".*" nil nil))
  1106. (add-to-list 'bs-configurations
  1107. '("files-and-terminals" nil nil nil
  1108. (lambda (buf)
  1109. (and (bs-visits-non-file buf)
  1110. (save-excursion
  1111. (set-buffer buf)
  1112. (not (memq major-mode
  1113. '(term-mode
  1114. eshell-mode))))))))
  1115. ;; (setq bs-configurations (list
  1116. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1117. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1118. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1119. )
  1120. ;; (global-set-key "\C-x\C-b" 'bs-show)
  1121. (defalias 'list-buffers 'bs-show)
  1122. (setq bs-default-configuration "files-and-terminals")
  1123. (setq bs-default-sort-name "by nothing")
  1124. (add-hook 'bs-mode-hook
  1125. (lambda ()
  1126. ;; (setq bs-default-configuration "files")
  1127. ;; (and bs--show-all
  1128. ;; (call-interactively 'bs-toggle-show-all))
  1129. (set (make-local-variable 'scroll-margin) 0))))
  1130. (iswitchb-mode 1)
  1131. (defun iswitchb-buffer-display-other-window ()
  1132. "Do iswitchb in other window."
  1133. (interactive)
  1134. (let ((iswitchb-default-method 'display))
  1135. (call-interactively 'iswitchb-buffer)))
  1136. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1137. ;; sdic
  1138. (when (lazy-load-eval 'sdic '(sdic-describe-word-at-point))
  1139. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  1140. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo)
  1141. (defun sdic-describe-word-at-point-echo ()
  1142. ""
  1143. (interactive)
  1144. (save-window-excursion
  1145. (sdic-describe-word-at-point))
  1146. (save-excursion
  1147. (set-buffer sdic-buffer-name)
  1148. (message (buffer-substring (point-min)
  1149. (progn (goto-char (point-min))
  1150. (or (and (re-search-forward "^\\w"
  1151. nil
  1152. t
  1153. 4)
  1154. (progn (previous-line) t)
  1155. (point-at-eol))
  1156. (point-max)))))))
  1157. (setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  1158. (setq sdic-waei-dictionary-list
  1159. '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  1160. (setq sdic-disable-select-window t)
  1161. (setq sdic-window-height 7))
  1162. ;;;;;;;;;;;;;;;;;;;;;;;;
  1163. ;; ilookup
  1164. (when (fetch-library
  1165. "https://raw.github.com/10sr/emacs-lisp/master/ilookup.el"
  1166. t)
  1167. (lazy-load-eval 'ilookup
  1168. '(ilookup-open)
  1169. (setq ilookup-dict-alist
  1170. '(
  1171. ("en" . (lambda (word)
  1172. (shell-command-to-string
  1173. (format "sdcv -n -u dictd_www.dict.org_gcide '%s'"
  1174. word))))
  1175. ("ja" . (lambda (word)
  1176. (shell-command-to-string
  1177. (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'"
  1178. word))))
  1179. ("jaj" . (lambda (word)
  1180. (shell-command-to-string
  1181. (format "sdcv -n -u jmdict-en-ja '%s'"
  1182. word))))
  1183. ("jag" .
  1184. (lambda (word)
  1185. (with-temp-buffer
  1186. (insert (shell-command-to-string
  1187. (format "sdcv -n -u 'Genius English-Japanese' '%s'"
  1188. word)))
  1189. (html2text)
  1190. (buffer-substring (point-min)
  1191. (point-max)))))
  1192. ("alc" . (lambda (word)
  1193. (shell-command-to-string
  1194. (format "alc '%s' | head -n 20"
  1195. word))))
  1196. ("app" . (lambda (word)
  1197. (shell-command-to-string
  1198. (format "dict_app '%s'"
  1199. word))))
  1200. ;; letters broken
  1201. ("ms" .
  1202. (lambda (word)
  1203. (let ((url (concat
  1204. "http://api.microsofttranslator.com/V2/Ajax.svc/"
  1205. "Translate?appId=%s&text=%s&to=%s"))
  1206. (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51")
  1207. (target "ja")
  1208. (eword (url-hexify-string word)))
  1209. (with-current-buffer (url-retrieve-synchronously
  1210. (format url
  1211. apikey
  1212. eword
  1213. target))
  1214. (message "")
  1215. (goto-char (point-min))
  1216. (search-forward-regexp "^$"
  1217. nil
  1218. t)
  1219. (url-unhex-string (buffer-substring-no-properties
  1220. (point)
  1221. (point-max)))))))
  1222. ))
  1223. ;; (funcall (cdr (assoc "ms"
  1224. ;; ilookup-alist))
  1225. ;; "dictionary")
  1226. ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja"))
  1227. ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com"))
  1228. (setq ilookup-default "ja")
  1229. (when (locate-library "google-translate")
  1230. (add-to-list 'ilookup-dict-alist
  1231. '("gt" .
  1232. (lambda (word)
  1233. (save-excursion
  1234. (google-translate-translate "auto"
  1235. "ja"
  1236. word))
  1237. (with-current-buffer "*Google Translate*"
  1238. (buffer-substring-no-properties (point-min)
  1239. (point-max)))))))
  1240. ))
  1241. (when (lazy-load-eval 'google-translate '(google-translate-translate
  1242. google-translate-at-point))
  1243. (setq google-translate-default-source-language "auto")
  1244. (setq google-translate-default-target-language "ja"))
  1245. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1246. ;; vc
  1247. ;; (require 'vc)
  1248. (setq vc-handled-backends '())
  1249. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1250. ;; gauche-mode
  1251. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  1252. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  1253. (when (and (fetch-library
  1254. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  1255. t)
  1256. (lazy-load-eval 'gauche-mode '(gauche-mode run-scheme)))
  1257. (let ((s (executable-find "gosh")))
  1258. (setq scheme-program-name s
  1259. gauche-program-name s))
  1260. (defun run-gauche-other-window ()
  1261. "Run gauche on other window"
  1262. (interactive)
  1263. (switch-to-buffer-other-window
  1264. (get-buffer-create "*scheme*"))
  1265. (run-gauche))
  1266. (defun run-gauche ()
  1267. "run gauche"
  1268. (run-scheme gauche-program-name)
  1269. )
  1270. (defun scheme-send-buffer ()
  1271. ""
  1272. (interactive)
  1273. (scheme-send-region (point-min) (point-max))
  1274. (my-scheme-display-scheme-buffer)
  1275. )
  1276. (defun my-scheme-display-scheme-buffer ()
  1277. ""
  1278. (interactive)
  1279. (set-window-text-height (display-buffer scheme-buffer
  1280. t)
  1281. 7))
  1282. (add-hook 'scheme-mode-hook
  1283. (lambda ()
  1284. nil))
  1285. (add-hook 'inferior-scheme-mode-hook
  1286. (lambda ()
  1287. ;; (my-scheme-display-scheme-buffer)
  1288. ))
  1289. (setq auto-mode-alist
  1290. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1291. (setq auto-mode-alist
  1292. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1293. (add-hook 'gauche-mode-hook
  1294. (lambda ()
  1295. (define-key gauche-mode-map
  1296. (kbd "C-c C-z") 'run-gauche-other-window)
  1297. (define-key scheme-mode-map
  1298. (kbd "C-c C-c") 'scheme-send-buffer)
  1299. (define-key scheme-mode-map
  1300. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer))))
  1301. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1302. ;; recentf-mode
  1303. (setq recentf-save-file (expand-file-name "~/.emacs.d/recentf")
  1304. recentf-max-menu-items 20
  1305. recentf-max-saved-items 30
  1306. recentf-show-file-shortcuts-flag nil)
  1307. (when (require 'recentf nil t)
  1308. (add-to-list 'recentf-exclude (regexp-quote recentf-save-file))
  1309. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1310. (add-hook 'find-file-hook
  1311. 'recentf-save-list
  1312. t) ; save to file immediately after adding file to recentf list
  1313. (add-hook 'kill-emacs-hook
  1314. 'recentf-load-list)
  1315. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1316. ;; (add-hook 'find-file-hook
  1317. ;; (lambda ()
  1318. ;; (recentf-add-file default-directory)))
  1319. (and (fetch-library
  1320. "https://raw.github.com/10sr/emacs-lisp/master/recentf-show.el"
  1321. t)
  1322. (lazy-load-eval 'recentf-show)
  1323. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1324. (add-hook 'recentf-show-before-listing-hook
  1325. 'recentf-load-list))
  1326. (recentf-mode 1)
  1327. (add-hook 'recentf-dialog-mode-hook
  1328. (lambda ()
  1329. ;; (recentf-save-list)
  1330. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1331. ;; 'my-recentf-cd-and-find-file)
  1332. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1333. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1334. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1335. (define-key recentf-dialog-mode-map "n" 'next-line)
  1336. (cd "~/"))))
  1337. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1338. ;; dired
  1339. (when (lazy-load-eval 'dired nil)
  1340. (defun my-dired-echo-file-head (arg)
  1341. ""
  1342. (interactive "P")
  1343. (let ((f (dired-get-filename)))
  1344. (message "%s"
  1345. (with-temp-buffer
  1346. (insert-file-contents f)
  1347. (buffer-substring-no-properties
  1348. (point-min)
  1349. (progn (goto-line (if arg
  1350. (prefix-numeric-value arg)
  1351. 10))
  1352. (point-at-eol)))))))
  1353. (defun my-dired-diff ()
  1354. ""
  1355. (interactive)
  1356. (let ((files (dired-get-marked-files nil nil nil t)))
  1357. (if (eq (car files)
  1358. t)
  1359. (diff (cadr files) (dired-get-filename))
  1360. (message "One files must be marked!"))))
  1361. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  1362. "pop up buffer using `display-buffer' and return that buffer."
  1363. (let ((bf (get-buffer-create buffer-or-name)))
  1364. (with-current-buffer bf
  1365. (cd ".")
  1366. (erase-buffer))
  1367. (display-buffer bf)
  1368. bf))
  1369. (defun my-replace-nasi-none ()
  1370. ""
  1371. (save-excursion
  1372. (let ((buffer-read-only nil))
  1373. (goto-char (point-min))
  1374. (while (search-forward "なし" nil t)
  1375. (replace-match "none")))))
  1376. (defun dired-get-file-info ()
  1377. "dired get file info"
  1378. (interactive)
  1379. (let ((f (shell-quote-argument (dired-get-filename t))))
  1380. (if (file-directory-p f)
  1381. (progn
  1382. (message "Calculating disk usage...")
  1383. (shell-command (concat "du -hsD "
  1384. f)))
  1385. (shell-command (concat "file "
  1386. f)))))
  1387. (defun my-dired-scroll-up ()
  1388. ""
  1389. (interactive)
  1390. (my-dired-previous-line (- (window-height) 1)))
  1391. (defun my-dired-scroll-down ()
  1392. ""
  1393. (interactive)
  1394. (my-dired-next-line (- (window-height) 1)))
  1395. ;; (defun my-dired-forward-line (arg)
  1396. ;; ""
  1397. ;; (interactive "p"))
  1398. (defun my-dired-previous-line (arg)
  1399. ""
  1400. (interactive "p")
  1401. (if (> arg 0)
  1402. (progn
  1403. (if (eq (line-number-at-pos)
  1404. 1)
  1405. (goto-char (point-max))
  1406. (forward-line -1))
  1407. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1408. (dired-get-subdir))
  1409. (- arg 1)
  1410. arg)))
  1411. (dired-move-to-filename)))
  1412. (defun my-dired-next-line (arg)
  1413. ""
  1414. (interactive "p")
  1415. (if (> arg 0)
  1416. (progn
  1417. (if (eq (point)
  1418. (point-max))
  1419. (goto-char (point-min))
  1420. (forward-line 1))
  1421. (my-dired-next-line (if (or (dired-get-filename nil t)
  1422. (dired-get-subdir))
  1423. (- arg 1)
  1424. arg)))
  1425. (dired-move-to-filename)))
  1426. (defun my-dired-print-current-dir-and-file ()
  1427. (message "%s %s"
  1428. default-directory
  1429. (buffer-substring-no-properties (point-at-bol)
  1430. (point-at-eol))))
  1431. (defun dired-do-execute-as-command ()
  1432. ""
  1433. (interactive)
  1434. (let ((file (dired-get-filename t)))
  1435. (if (file-executable-p file)
  1436. (start-process file nil file)
  1437. (when (y-or-n-p
  1438. "this file cant be executed. mark as executable and go? : ")
  1439. (set-file-modes file
  1440. (file-modes-symbolic-to-number "u+x" (file-modes file)))
  1441. (start-process file nil file)))))
  1442. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1443. (defun my-dired-x-open ()
  1444. ""
  1445. (interactive)
  1446. (my-x-open (dired-get-filename t t)))
  1447. (if (eq window-system 'mac)
  1448. (setq dired-listing-switches "-lhF")
  1449. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1450. )
  1451. (setq dired-listing-switches "-lhF")
  1452. (put 'dired-find-alternate-file 'disabled nil)
  1453. ;; when using dired-find-alternate-file
  1454. ;; reuse current dired buffer for the file to open
  1455. (setq dired-ls-F-marks-symlinks t)
  1456. (when (require 'ls-lisp nil t)
  1457. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1458. (setq ls-lisp-dirs-first t)
  1459. (setq ls-lisp-use-localized-time-format t)
  1460. (setq ls-lisp-format-time-list
  1461. '("%Y-%m-%d %H:%M"
  1462. "%Y-%m-%d ")))
  1463. (setq dired-dwim-target t)
  1464. ;; (add-hook 'dired-after-readin-hook
  1465. ;; 'my-replace-nasi-none)
  1466. ;; (add-hook 'after-init-hook
  1467. ;; (lambda ()
  1468. ;; (dired ".")))
  1469. (add-hook 'dired-mode-hook
  1470. (lambda ()
  1471. (define-key dired-mode-map "o" 'my-dired-x-open)
  1472. (define-key dired-mode-map "i" 'dired-get-file-info)
  1473. (define-key dired-mode-map "f" 'find-file)
  1474. (define-key dired-mode-map "!" 'shell-command)
  1475. (define-key dired-mode-map "&" 'async-shell-command)
  1476. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1477. (define-key dired-mode-map "=" 'my-dired-diff)
  1478. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1479. (define-key dired-mode-map "b" 'gtkbm)
  1480. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1481. (define-key dired-mode-map "@" (lambda ()
  1482. (interactive) (my-x-open ".")))
  1483. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1484. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1485. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1486. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1487. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1488. (substitute-key-definition 'dired-next-line
  1489. 'my-dired-next-line dired-mode-map)
  1490. (substitute-key-definition 'dired-previous-line
  1491. 'my-dired-previous-line dired-mode-map)
  1492. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1493. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1494. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1495. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1496. (let ((file "._Icon\015"))
  1497. (when nil (file-readable-p file)
  1498. (delete-file file)))))
  1499. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/pack.el"
  1500. t)
  1501. (lazy-load-eval 'pack '(dired-do-pack-or-unpack pack))
  1502. (add-hook 'dired-mode-hook
  1503. (lambda ()
  1504. (define-key dired-mode-map "P" 'dired-do-pack-or-unpack))))
  1505. (and (fetch-library
  1506. "https://raw.github.com/10sr/emacs-lisp/master/dired-list-all-mode.el"
  1507. t)
  1508. (lazy-load-eval 'dired-list-all-mode)
  1509. (setq dired-listing-switches "-lhF")
  1510. (add-hook 'dired-mode-hook
  1511. (lambda ()
  1512. (define-key dired-mode-map "a" 'dired-list-all-mode)
  1513. )))
  1514. ) ; when dired locate
  1515. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  1516. (defun my-dired-toggle-mark()
  1517. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  1518. (t dired-marker-char))))
  1519. (delete-char 1)
  1520. (insert cur)))
  1521. (defun my-dired-mark (arg)
  1522. "Toggle mark the current (or next ARG) files.
  1523. If on a subdir headerline, mark all its files except `.' and `..'.
  1524. Use \\[dired-unmark-all-files] to remove all marks
  1525. and \\[dired-unmark] on a subdir to remove the marks in
  1526. this subdir."
  1527. (interactive "P")
  1528. (if (dired-get-subdir)
  1529. (save-excursion (dired-mark-subdir-files))
  1530. (let ((inhibit-read-only t))
  1531. (dired-repeat-over-lines
  1532. (prefix-numeric-value arg)
  1533. 'my-dired-toggle-mark))))
  1534. (defun my-dired-mark-backward (arg)
  1535. "In Dired, move up lines and toggle mark there.
  1536. Optional prefix ARG says how many lines to unflag; default is one line."
  1537. (interactive "p")
  1538. (my-dired-mark (- arg)))
  1539. (add-hook 'dired-mode-hook
  1540. (lambda ()
  1541. (local-set-key (kbd "SPC") 'my-dired-mark)
  1542. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1543. )
  1544. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1545. ;; eshell
  1546. (lazy-load-eval 'eshell nil
  1547. (defvar eshell-text-mode-map
  1548. (let ((map (make-sparse-keymap)))
  1549. (define-key map (kbd "C-x t") 'eshell-text-mode-toggle)
  1550. map))
  1551. (define-derived-mode eshell-text-mode text-mode
  1552. "Eshell-Text"
  1553. "Text-mode for Eshell."
  1554. nil)
  1555. (defun eshell-text-mode-toggle ()
  1556. "Toggle eshell-text-mode and eshell-mode."
  1557. (interactive)
  1558. (cond ((eq major-mode
  1559. 'eshell-text-mode)
  1560. (goto-char (point-max))
  1561. (eshell-mode))
  1562. ((eq major-mode
  1563. 'eshell-mode)
  1564. (eshell-text-mode))
  1565. (t
  1566. (message "Not in eshell buffer")
  1567. nil)))
  1568. (defun my-eshell-backward-delete-char ()
  1569. (interactive)
  1570. (when (< (save-excursion
  1571. (eshell-bol)
  1572. (point))
  1573. (point))
  1574. (backward-delete-char 1)))
  1575. (defun my-file-owner-p (file)
  1576. "t if FILE is owned by me."
  1577. (eq (user-uid) (nth 2 (file-attributes file))))
  1578. "http://www.bookshelf.jp/pukiwiki/pukiwiki.php\
  1579. ?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9"
  1580. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1581. ;; (defun eshell/less (&rest args)
  1582. ;; "Invoke `view-file' on the file.
  1583. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1584. ;; (if args
  1585. ;; (while args
  1586. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1587. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1588. ;; (file (pop args)))
  1589. ;; (view-file file)
  1590. ;; (goto-line line))
  1591. ;; (view-file (pop args))))))
  1592. (defun eshell/o (&optional file)
  1593. (my-x-open (or file ".")))
  1594. ;; (defun eshell/vi (&rest args)
  1595. ;; "Invoke `find-file' on the file.
  1596. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1597. ;; (while args
  1598. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1599. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1600. ;; (file (pop args)))
  1601. ;; (find-file file)
  1602. ;; (goto-line line))
  1603. ;; (find-file (pop args)))))
  1604. (defun eshell/clear ()
  1605. "Clear the current buffer, leaving one prompt at the top."
  1606. (interactive)
  1607. (let ((inhibit-read-only t))
  1608. (erase-buffer)))
  1609. (defun eshell-clear ()
  1610. (interactive)
  1611. (let ((inhibit-read-only t))
  1612. (erase-buffer)
  1613. (insert (funcall eshell-prompt-function))))
  1614. (defun eshell/d (&optional dirname switches)
  1615. "if first arg is omitted open current directory."
  1616. (dired (or dirname ".") switches))
  1617. (defun eshell/v ()
  1618. (view-mode 1))
  1619. ;; (defun eshell/aaa (&rest args)
  1620. ;; (message "%S"
  1621. ;; args))
  1622. (defvar eshell/git-cat-command
  1623. nil
  1624. "List of git commands that cat just return strings as results.")
  1625. (setq eshell/git-cat-command
  1626. '("status" "st" "b" "branch" "ls" "ls-files")
  1627. )
  1628. (defun eshell/git (&rest args)
  1629. (if (member (car args)
  1630. eshell/git-cat-command)
  1631. (shell-command-to-string (mapconcat 'shell-quote-argument
  1632. `("git"
  1633. "-c"
  1634. "color.ui=always"
  1635. ,@args)
  1636. " "))
  1637. ;; (eshell-git-shell-command-to-string args)
  1638. (if (require 'git-command nil t)
  1639. (git-command (mapconcat 'shell-quote-argument
  1640. args
  1641. " "))
  1642. (apply 'eshell-exec-visual "git" args))))
  1643. ;; (defun eshell-git-shell-command-to-string (args)
  1644. ;; "Return string of output of ARGS."
  1645. ;; (let ((sargs (mapconcat 'shell-quote-argument
  1646. ;; args
  1647. ;; " ")))
  1648. ;; (if (require 'ansi-color nil t)
  1649. ;; (identity
  1650. ;; (shell-command-to-string (concat "git "
  1651. ;; "-c color.ui=always "
  1652. ;; sargs)))
  1653. ;; (shell-command-to-string (concat "git "
  1654. ;; sargs)))))
  1655. (defalias 'eshell/g 'eshell/git)
  1656. (defalias 'eshell/: 'ignore)
  1657. (defalias 'eshell/type 'eshell/which)
  1658. ;; (defalias 'eshell/vim 'eshell/vi)
  1659. (defalias 'eshell/ff 'find-file)
  1660. (defalias 'eshell/q 'eshell/exit)
  1661. (defun eshell-goto-prompt ()
  1662. ""
  1663. (interactive)
  1664. (goto-char (point-max)))
  1665. (defun eshell-delete-char-or-logout (n)
  1666. (interactive "p")
  1667. (if (equal (eshell-get-old-input)
  1668. "")
  1669. (progn
  1670. (insert "exit")
  1671. (eshell-send-input))
  1672. (delete-char n)))
  1673. (defun eshell-kill-input ()
  1674. (interactive)
  1675. (delete-region (point)
  1676. (progn (eshell-bol)
  1677. (point))))
  1678. (defalias 'eshell/logout 'eshell/exit)
  1679. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1680. "open eshell and change wd
  1681. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1682. (interactive)
  1683. (let ((dir (expand-file-name default-directory)))
  1684. (switch-to-buffer (or eshell-buffer-or-name
  1685. (eshell t)))
  1686. (unless (equal dir (expand-file-name default-directory))
  1687. ;; (cd dir)
  1688. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1689. ;; (eshell-emit-prompt)
  1690. (goto-char (point-max))
  1691. (eshell-kill-input)
  1692. (insert "cd " dir)
  1693. (eshell-send-input))))
  1694. (defadvice eshell-next-matching-input-from-input
  1695. ;; do not cycle history
  1696. (around eshell-history-do-not-cycle activate)
  1697. (if (= 0
  1698. (or eshell-history-index
  1699. 0))
  1700. (progn
  1701. (delete-region eshell-last-output-end (point))
  1702. (insert-and-inherit eshell-matching-input-from-input-string)
  1703. (setq eshell-history-index nil))
  1704. ad-do-it))
  1705. (setq eshell-directory-name "~/.emacs.d/eshell/")
  1706. (setq eshell-term-name "eterm-color")
  1707. (setq eshell-scroll-to-bottom-on-input t)
  1708. (setq eshell-cmpl-ignore-case t)
  1709. (setq eshell-cmpl-cycle-completions nil)
  1710. (setq eshell-highlight-prompt nil)
  1711. (setq eshell-ls-initial-args '("-hCFG"
  1712. "--color=auto"
  1713. "--time-style=long-iso")) ; "-hF")
  1714. (setq eshell-prompt-function
  1715. 'my-eshell-prompt-function)
  1716. (defun my-eshell-prompt-function ()
  1717. (with-temp-buffer
  1718. (let (p1 p2 p3 p4)
  1719. (insert ":: [")
  1720. (setq p1 (point))
  1721. (insert user-login-name
  1722. "@"
  1723. (car (split-string system-name
  1724. "\\."))
  1725. )
  1726. (setq p2 (point))
  1727. (insert ":")
  1728. (setq p3 (point))
  1729. (insert (abbreviate-file-name default-directory))
  1730. (setq p4 (point))
  1731. (insert "]")
  1732. (insert "\n:: ")
  1733. (unless (eq 0
  1734. eshell-last-command-status)
  1735. (insert (format "[STATUS:%d] "
  1736. eshell-last-command-status)))
  1737. (insert (if (= (user-uid)
  1738. 0)
  1739. "# "
  1740. "$ "))
  1741. (add-text-properties p1
  1742. p2
  1743. '(face underline))
  1744. (add-text-properties p3
  1745. p4
  1746. '(face underline))
  1747. (buffer-substring (point-min)
  1748. (point-max)))))
  1749. (add-hook 'eshell-mode-hook
  1750. (lambda ()
  1751. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1752. ;; (interactive)
  1753. ;; (switch-to-buffer (other-buffer))))
  1754. ;; (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1755. ;; (interactive)
  1756. ;; (eshell-goto-prompt)
  1757. ;; (keyboard-quit)))
  1758. (define-key eshell-mode-map (kbd "C-x t")
  1759. 'eshell-text-mode-toggle)
  1760. (define-key eshell-mode-map (kbd "C-u")
  1761. 'eshell-kill-input)
  1762. (define-key eshell-mode-map (kbd "C-d")
  1763. 'eshell-delete-char-or-logout)
  1764. ;; (define-key eshell-mode-map (kbd "C-l")
  1765. ;; 'eshell-clear)
  1766. (define-key eshell-mode-map (kbd "DEL")
  1767. 'my-eshell-backward-delete-char)
  1768. (define-key eshell-mode-map
  1769. (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1770. (define-key eshell-mode-map
  1771. (kbd "C-n") 'eshell-next-matching-input-from-input)
  1772. (apply 'eshell/addpath exec-path)
  1773. (set (make-local-variable 'scroll-margin) 0)
  1774. ;; (eshell/export "GIT_PAGER=")
  1775. ;; (eshell/export "GIT_EDITOR=")
  1776. (eshell/export "LC_MESSAGES=C")
  1777. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1778. (set (make-local-variable 'hl-line-range-function)
  1779. (lambda ()
  1780. '(0 . 0)))
  1781. (add-to-list 'eshell-virtual-targets
  1782. '("/dev/less"
  1783. (lambda (str)
  1784. (if str
  1785. (with-current-buffer nil)))
  1786. nil))
  1787. ))
  1788. (add-hook 'eshell-mode-hook
  1789. (lambda ()
  1790. (add-to-list 'eshell-visual-commands "vim")
  1791. ;; (add-to-list 'eshell-visual-commands "git")
  1792. (add-to-list 'eshell-output-filter-functions
  1793. 'eshell-truncate-buffer)
  1794. (mapcar (lambda (alias)
  1795. (add-to-list 'eshell-command-aliases-list
  1796. alias))
  1797. '(
  1798. ; ("ll" "ls -l $*")
  1799. ; ("la" "ls -a $*")
  1800. ; ("lla" "ls -al $*")
  1801. ("eless"
  1802. (concat "cat >>> (with-current-buffer "
  1803. "(get-buffer-create \"*eshell output\") "
  1804. "(erase-buffer) "
  1805. "(setq buffer-read-only nil) "
  1806. "(current-buffer)) "
  1807. "(view-buffer (get-buffer \"*eshell output*\"))")
  1808. ))
  1809. )))
  1810. ) ; eval after load eshell
  1811. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1812. ;; frame buffer
  1813. ;; todo: work well when opening files already opened on another window
  1814. (add-hook 'after-make-frame-functions
  1815. (lambda (f)
  1816. (set-window-buffer (frame-selected-window f)
  1817. "*Messages*")))
  1818. (defun make-frame-command-with-name (name)
  1819. "Make frame with NAME specified."
  1820. (interactive "sName for new frame: ")
  1821. (set-frame-parameter (make-frame-command)
  1822. 'name
  1823. name))
  1824. (defvar my-frame-buffer-plist nil)
  1825. (defun my-frame-buffer-add (&optional buf frame)
  1826. "Add BUF to buffer list for FRAME."
  1827. (setq my-frame-buffer-plist
  1828. (plist-put my-frame-buffer-plist
  1829. (or frame
  1830. (selected-frame))
  1831. (let ((lst (my-frame-buffer-get frame)))
  1832. (if lst
  1833. (add-to-list 'lst
  1834. (or buf
  1835. (current-buffer)))
  1836. (list (or buf
  1837. (current-buffer))))))))
  1838. (defun my-frame-buffer-remove (&optional buf frame)
  1839. "Remove BUF from bufferlist for FRAME."
  1840. (setq my-frame-buffer-plist
  1841. (plist-put my-frame-buffer-plist
  1842. (or frame
  1843. (selected-frame))
  1844. (delq (or buf
  1845. (current-buffer))
  1846. (my-frame-buffer-get frame)))))
  1847. (defun my-frame-buffer-get (&optional frame)
  1848. "Get buffer list for FRAME."
  1849. (plist-get my-frame-buffer-plist
  1850. (or frame
  1851. (selected-frame))))
  1852. (defun my-frame-buffer-kill-all-buffer (&optional frame)
  1853. "Kill all buffer of FRAME."
  1854. (mapcar 'kill-buffer
  1855. (my-frame-buffer-get frame)))
  1856. (add-hook 'find-file-hook
  1857. 'my-frame-buffer-add)
  1858. ;; (add-hook 'term-mode-hook
  1859. ;; 'my-frame-buffer-add)
  1860. (add-hook 'eshell-mode-hook
  1861. 'my-frame-buffer-add)
  1862. (add-hook 'Man-mode-hook
  1863. 'my-frame-buffer-add)
  1864. (add-hook 'kill-buffer-hook
  1865. 'my-frame-buffer-remove)
  1866. (add-hook 'delete-frame-functions
  1867. 'my-frame-buffer-kill-all-buffer)
  1868. (defvar my-desktop-terminal "roxterm")
  1869. (defun my-execute-terminal ()
  1870. "Invole terminal program."
  1871. (interactive)
  1872. (if (and (or (eq system-type 'windows-nt)
  1873. window-system)
  1874. my-desktop-terminal
  1875. )
  1876. (let ((process-environment (cons "TERM=xterm" process-environment)))
  1877. (start-process "terminal"
  1878. nil
  1879. my-desktop-terminal))
  1880. (my-term)))
  1881. (defun my-delete-frame-or-kill-emacs ()
  1882. "Delete frame when opening multiple frame, kill Emacs when only one."
  1883. (interactive)
  1884. (if (eq 1
  1885. (length (frame-list)))
  1886. (save-buffers-kill-emacs)
  1887. (delete-frame)))
  1888. ;; (define-key my-prefix-map (kbd "C-s") 'my-execute-terminal)
  1889. (define-key my-prefix-map (kbd "C-f") 'make-frame-command-with-name)
  1890. (global-set-key (kbd "C-x C-c") 'my-delete-frame-or-kill-emacs)
  1891. (define-key my-prefix-map (kbd "C-x C-c") 'save-buffers-kill-emacs)
  1892. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1893. ;; my-term
  1894. (defvar my-term nil
  1895. "My terminal buffer.")
  1896. (defvar my-term-function nil
  1897. "Function to create terminal buffer.
  1898. This function accept no argument and return newly created buffer of terminal.")
  1899. (defun my-term (&optional arg)
  1900. "Open terminal buffer and return that buffer.
  1901. ARG is ignored."
  1902. (interactive "P")
  1903. (if (and my-term
  1904. (buffer-name my-term))
  1905. (pop-to-buffer my-term)
  1906. (setq my-term
  1907. (save-window-excursion
  1908. (funcall my-term-function)))
  1909. (and my-term
  1910. (my-term))))
  1911. ;; (setq my-term-function
  1912. ;; (lambda ()
  1913. ;; (if (eq system-type 'windows-nt)
  1914. ;; (eshell)
  1915. ;; (if (require 'multi-term nil t)
  1916. ;; (multi-term)
  1917. ;; (ansi-term shell-file-name)))))
  1918. (setq my-term-function 'eshell)
  1919. (define-key my-prefix-map (kbd "C-s") 'my-term)
  1920. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1921. ;; x open
  1922. (defvar my-filer nil)
  1923. (setq my-filer (or (executable-find "pcmanfm")
  1924. (executable-find "nautilus")))
  1925. (defun my-x-open (file)
  1926. "open FILE."
  1927. (interactive "FOpen File: ")
  1928. (setq file (expand-file-name file))
  1929. (message "Opening %s..." file)
  1930. (cond ((eq system-type 'windows-nt)
  1931. (call-process "cmd.exe" nil 0 nil
  1932. "/c" "start" "" (convert-standard-filename file)))
  1933. ((eq system-type 'darwin)
  1934. (call-process "open" nil 0 nil file))
  1935. ((getenv "DISPLAY")
  1936. (call-process (or my-filer "xdg-open") nil 0 nil file))
  1937. (t
  1938. (find-file file))
  1939. )
  1940. ;; (recentf-add-file file)
  1941. (message "Opening %s...done" file))
  1942. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1943. ;; misc funcs
  1944. (defun memo (&optional dir)
  1945. "Open memo.txt in DIR."
  1946. (interactive)
  1947. (pop-to-buffer (find-file-noselect (concat (if dir
  1948. (file-name-as-directory dir)
  1949. "")
  1950. "memo.txt"))))
  1951. (defvar my-rgrep-alist
  1952. `(
  1953. ;; the silver searcher
  1954. ("ag"
  1955. (executable-find "ag")
  1956. "ag --nocolor --nogroup --nopager ")
  1957. ;; ack
  1958. ("ack"
  1959. (executable-find "ack")
  1960. "ack --nocolor --nogroup --nopager ")
  1961. ;; gnu global
  1962. ("global"
  1963. (and (require 'gtags nil t)
  1964. (executable-find "global")
  1965. (gtags-get-rootpath))
  1966. "global --result grep ")
  1967. ;; git grep
  1968. ("gitgrep"
  1969. (eq 0
  1970. (shell-command "git rev-parse --git-dir"))
  1971. "git --no-pager -c color.grep=false grep -nH -e ")
  1972. ;; grep
  1973. ("grep"
  1974. t
  1975. ,(concat "find . "
  1976. "-path '*/.git' -prune -o "
  1977. "-path '*/.svn' -prune -o "
  1978. "-type f -print0 | "
  1979. "xargs -0 grep -nH -e "))
  1980. )
  1981. "Alist of rgrep command.
  1982. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1983. condition to choose COMMAND when evaluated.")
  1984. (defvar my-rgrep-default nil
  1985. "Default command name for my-rgrep.")
  1986. (defun my-rgrep-grep-command (&optional name alist)
  1987. "Return recursive grep command for current directory or nil.
  1988. If NAME is given, use that without testing.
  1989. Commands are searched from ALIST."
  1990. (if alist
  1991. (if name
  1992. ;; if name is given search that from alist and return the command
  1993. (nth 2 (assoc name
  1994. alist))
  1995. ;; if name is not given try test in 1th elem
  1996. (let ((car (car alist))
  1997. (cdr (cdr alist)))
  1998. (if (eval (nth 1 car))
  1999. ;; if the condition is true return the command
  2000. (nth 2 car)
  2001. ;; try next one
  2002. (and cdr
  2003. (my-rgrep-grep-command name cdr)))))
  2004. ;; if alist is not given set default value
  2005. (my-rgrep-grep-command name my-rgrep-alist)))
  2006. (my-rgrep-grep-command "ag" nil)
  2007. (defun my-rgrep (command-args)
  2008. "My recursive grep. Run COMMAND-ARGS."
  2009. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  2010. nil)))
  2011. (if cmd
  2012. (list (read-shell-command "grep command: "
  2013. cmd
  2014. 'grep-find-history))
  2015. (error "my-rgrep: Command for rgrep not found")
  2016. )))
  2017. (compilation-start command-args
  2018. 'grep-mode))
  2019. ;; (defun my-rgrep-symbol-at-point (command-args)
  2020. ;; "My recursive grep. Run COMMAND-ARGS."
  2021. ;; (interactive (list (read-shell-command "grep command: "
  2022. ;; (concat (my-rgrep-grep-command)
  2023. ;; " "
  2024. ;; (thing-at-point 'symbol))
  2025. ;; 'grep-find-history)))
  2026. ;; (compilation-start command-args
  2027. ;; 'grep-mode))
  2028. (defun my-rgrep-ack ()
  2029. "My recursive grep by ack."
  2030. (interactive)
  2031. (let ((my-rgrep-default "ack"))
  2032. (if (called-interactively-p 'any)
  2033. (call-interactively 'my-rgrep)
  2034. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2035. (defun my-rgrep-ag ()
  2036. "My recursive grep by ack."
  2037. (interactive)
  2038. (let ((my-rgrep-default "ag"))
  2039. (if (called-interactively-p 'any)
  2040. (call-interactively 'my-rgrep)
  2041. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2042. (defun my-rgrep-gitgrep ()
  2043. "My recursive grep by ack."
  2044. (interactive)
  2045. (let ((my-rgrep-default "gitgrep"))
  2046. (if (called-interactively-p 'any)
  2047. (call-interactively 'my-rgrep)
  2048. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2049. (defun my-rgrep-grep ()
  2050. "My recursive grep by ack."
  2051. (interactive)
  2052. (let ((my-rgrep-default "grep"))
  2053. (if (called-interactively-p 'any)
  2054. (call-interactively 'my-rgrep)
  2055. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2056. (defun my-rgrep-global ()
  2057. "My recursive grep by ack."
  2058. (interactive)
  2059. (let ((my-rgrep-default "global"))
  2060. (if (called-interactively-p 'any)
  2061. (call-interactively 'my-rgrep)
  2062. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2063. (define-key ctl-x-map "s" 'my-rgrep)
  2064. ;; (defun make ()
  2065. ;; "Run \"make -k\" in current directory."
  2066. ;; (interactive)
  2067. ;; (compile "make -k"))
  2068. (defalias 'make 'compile)
  2069. (defvar sed-in-place-history nil
  2070. "History of `sed-in-place'.")
  2071. (defvar sed-in-place-command "sed --in-place=.bak -e")
  2072. (defun sed-in-place (command)
  2073. "Issue sed in place COMMAND."
  2074. (interactive (list (read-shell-command "sed in place: "
  2075. (concat sed-in-place-command " ")
  2076. 'sed-in-place-history)))
  2077. (shell-command command
  2078. "*sed in place*"))
  2079. (defun dired-do-sed-in-place (&optional arg)
  2080. "Issue sed in place dired. If ARG is given, use the next ARG files."
  2081. (interactive "p")
  2082. (require 'dired-aux)
  2083. (let* ((files (dired-get-marked-files t arg))
  2084. (expr (dired-mark-read-string "Run sed-in-place for %s: "
  2085. nil
  2086. 'sed-in-place
  2087. arg
  2088. files)))
  2089. (if (equal expr
  2090. "")
  2091. (error "No expression specified")
  2092. (shell-command (concat sed-in-place-command
  2093. " '"
  2094. expr
  2095. "' "
  2096. (mapconcat 'shell-quote-argument
  2097. files
  2098. " "))
  2099. "*sed in place*"))))
  2100. (defun dir-show (&optional dir)
  2101. "Show DIR list."
  2102. (interactive)
  2103. (let ((bf (get-buffer-create "*dir show*"))
  2104. (list-directory-brief-switches "-C"))
  2105. (with-current-buffer bf
  2106. (list-directory (or nil
  2107. default-directory)
  2108. nil))
  2109. ))
  2110. (defun my-convmv-sjis2utf8-test ()
  2111. "Run `convmv -r -f sjis -t utf8 *'.
  2112. this is test, does not rename files."
  2113. (interactive)
  2114. (shell-command "convmv -r -f sjis -t utf8 *"))
  2115. (defun my-convmv-sjis2utf8-notest ()
  2116. "Run `convmv -r -f sjis -t utf8 * --notest'."
  2117. (interactive)
  2118. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  2119. (defun kill-ring-save-buffer-file-name ()
  2120. "Get current filename."
  2121. (interactive)
  2122. (let ((file buffer-file-name))
  2123. (if file
  2124. (progn (kill-new file)
  2125. (message file))
  2126. (message "not visiting file."))))
  2127. (defvar kill-ring-buffer-name "*kill-ring*"
  2128. "Buffer name for `kill-ring-buffer'.")
  2129. (defun open-kill-ring-buffer ()
  2130. "Open kill- ring buffer."
  2131. (interactive)
  2132. (pop-to-buffer
  2133. (with-current-buffer (get-buffer-create kill-ring-buffer-name)
  2134. (erase-buffer)
  2135. (yank)
  2136. (text-mode)
  2137. (current-local-map)
  2138. (goto-char (point-min))
  2139. (yank)
  2140. (current-buffer))))
  2141. (defun set-terminal-header (string)
  2142. "Set terminal header STRING."
  2143. (let ((savepos "\033[s")
  2144. (restorepos "\033[u")
  2145. (movecursor "\033[0;%dH")
  2146. (inverse "\033[7m")
  2147. (restorecolor "\033[0m")
  2148. (cols (frame-parameter nil 'width))
  2149. (length (length string)))
  2150. ;; (redraw-frame (selected-frame))
  2151. (send-string-to-terminal (concat savepos
  2152. (format movecursor
  2153. (1+ (- cols length)))
  2154. inverse
  2155. string
  2156. restorecolor
  2157. restorepos))
  2158. ))
  2159. (defun my-set-terminal-header ()
  2160. "Set terminal header."
  2161. (set-terminal-header (concat " "
  2162. user-login-name
  2163. "@"
  2164. (car (split-string system-name
  2165. "\\."))
  2166. " "
  2167. (format-time-string "%Y/%m/%d %T %z")
  2168. " ")))
  2169. ;; (run-with-timer
  2170. ;; 0.1
  2171. ;; 1
  2172. ;; 'my-set-terminal-header)
  2173. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2174. ;; ;; savage emacs
  2175. ;; ;; when enabled emacs fails to complete
  2176. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  2177. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  2178. ;; (setq arg
  2179. ;; (concat arg
  2180. ;; (if (eq nil
  2181. ;; (string-match "\\. *$"
  2182. ;; arg))
  2183. ;; ".")
  2184. ;; " Stupid!")))
  2185. (defvar info-in-prompt
  2186. nil
  2187. "System info in the form of \"[user@host] \".")
  2188. (setq info-in-prompt
  2189. (concat "["
  2190. user-login-name
  2191. "@"
  2192. (car (split-string system-name
  2193. "\\."))
  2194. "]"))
  2195. (defun my-real-function-subr-p (function)
  2196. "Return t if FUNCTION is a built-in function even if it is advised."
  2197. (let* ((advised (and (symbolp function)
  2198. (featurep 'advice)
  2199. (ad-get-advice-info function)))
  2200. (real-function
  2201. (or (and advised (let ((origname (cdr (assq 'origname advised))))
  2202. (and (fboundp origname)
  2203. origname)))
  2204. function))
  2205. (def (if (symbolp real-function)
  2206. (symbol-function real-function)
  2207. function)))
  2208. (subrp def)))
  2209. ;; (my-real-function-subr-p 'my-real-function-subr-p)
  2210. ;; (defadvice read-from-minibuffer (before info-in-prompt activate)
  2211. ;; "Show system info when use `read-from-minibuffer'."
  2212. ;; (ad-set-arg 0
  2213. ;; (concat my-system-info
  2214. ;; (ad-get-arg 0))))
  2215. ;; (defadvice read-string (before info-in-prompt activate)
  2216. ;; "Show system info when use `read-string'."
  2217. ;; (ad-set-arg 0
  2218. ;; (concat my-system-info
  2219. ;; (ad-get-arg 0))))
  2220. ;; (when (< emacs-major-version 24)
  2221. ;; (defadvice completing-read (before info-in-prompt activate)
  2222. ;; "Show system info when use `completing-read'."
  2223. ;; (ad-set-arg 0
  2224. ;; (concat my-system-info
  2225. ;; (ad-get-arg 0)))))
  2226. (defmacro info-in-prompt-set (&rest functions)
  2227. "Set info-in-prompt advices for FUNCTIONS."
  2228. `(progn
  2229. ,@(mapcar (lambda (f)
  2230. `(defadvice ,f (before info-in-prompt activate)
  2231. "Show info in prompt."
  2232. (let ((orig (ad-get-arg 0)))
  2233. (unless (string-match-p (regexp-quote info-in-prompt)
  2234. orig)
  2235. (ad-set-arg 0
  2236. (concat info-in-prompt
  2237. " "
  2238. orig))))))
  2239. functions)))
  2240. (info-in-prompt-set read-from-minibuffer
  2241. read-string
  2242. completing-read)
  2243. ;;; emacs.el ends here