You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

emacs.el 94 KiB

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