Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

emacs.el 87 KiB

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