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