25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

emacs.el 94 KiB

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