Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

emacs.el 95 KiB

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