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