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

emacs.el 88 KiB

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