Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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