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.

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