Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

emacs.el 93 KiB

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