No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

emacs.el 94 KiB

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