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