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

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