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

emacs.el 93 KiB

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