Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

emacs.el 87 KiB

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