Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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