Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

emacs.el 88 KiB

12 år sedan
13 år sedan
12 år sedan
13 år sedan
13 år sedan
10 år sedan
12 år sedan
11 år sedan
11 år sedan
11 år sedan
11 år sedan
12 år sedan
12 år sedan
11 år sedan
12 år sedan
12 år sedan
12 år sedan
11 år sedan
11 år sedan
13 år sedan
13 år sedan
12 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
12 år sedan
12 år sedan
13 år sedan
13 år sedan
13 år sedan
11 år sedan
11 år sedan
11 år sedan
11 år sedan
12 år sedan
12 år sedan
12 år sedan
11 år sedan
11 år sedan
11 år sedan
12 år sedan
12 år sedan
11 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
11 år sedan
13 år sedan
13 år sedan
13 år sedan
12 år sedan
13 år sedan
12 år sedan
13 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
13 år sedan
13 år sedan
12 år sedan
11 år sedan
13 år sedan
12 år sedan
13 år sedan
13 år sedan
13 år sedan
11 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
11 år sedan
11 år sedan
11 år sedan
11 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
11 år sedan
11 år sedan
12 år sedan
12 år sedan
13 år sedan
13 år sedan
11 år sedan
12 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
12 år sedan
13 år sedan
13 år sedan
12 år sedan
12 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
13 år sedan
12 år sedan
12 år sedan
13 år sedan
13 år sedan
13 år sedan
12 år sedan
13 år sedan
13 år sedan
12 år sedan
13 år sedan
12 år sedan
13 år sedan
12 år sedan
13 år sedan
12 år sedan
13 år sedan
12 år sedan
13 år sedan
13 år sedan
12 år sedan
13 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
12 år sedan
13 år sedan
13 år sedan
13 år sedan
12 år sedan
12 år sedan
13 år sedan
12 år sedan
13 år sedan
12 år sedan
13 år sedan
12 år sedan
12 år sedan
12 år sedan
10 år sedan
12 år sedan
10 år sedan
10 år sedan
10 år sedan
10 år sedan
12 år sedan
10 år sedan
10 år sedan
10 år sedan
10 år sedan
10 år sedan
12 år sedan
10 år sedan
12 år sedan
12 år sedan
13 år sedan
12 år sedan
10 år sedan
10 år sedan
12 år sedan
12 år sedan
12 år sedan
10 år sedan
12 år sedan
12 år sedan
13 år sedan
11 år sedan
12 år sedan
12 år sedan
12 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
12 år sedan
11 år sedan
11 år sedan
11 år sedan
11 år sedan
11 år sedan
12 år sedan
12 år sedan
13 år sedan
13 år sedan
13 år sedan
13 år sedan
10 år sedan
10 år sedan
10 år sedan
10 år sedan
10 år sedan
13 år sedan
12 år sedan
13 år sedan
11 år sedan
10 år sedan
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572
  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. (when (eq major-mode
  777. 'diff-mode)
  778. ;; do not pass when major-mode is derived mode of diff-mode
  779. (view-mode 1))
  780. (set-face-attribute 'diff-header nil
  781. :foreground nil
  782. :background nil
  783. :weight 'bold)
  784. (set-face-attribute 'diff-file-header nil
  785. :foreground nil
  786. :background nil
  787. :weight 'bold)
  788. (set-face-foreground 'diff-index-face "blue")
  789. (set-face-attribute 'diff-hunk-header nil
  790. :foreground "cyan"
  791. :weight 'normal)
  792. (set-face-attribute 'diff-context nil
  793. ;; :foreground "white"
  794. :foreground nil
  795. :weight 'normal)
  796. (set-face-foreground 'diff-removed-face "red")
  797. (set-face-foreground 'diff-added-face "green")
  798. (set-face-background 'diff-removed-face nil)
  799. (set-face-background 'diff-added-face nil)
  800. (set-face-attribute 'diff-changed nil
  801. :foreground "magenta"
  802. :weight 'normal)
  803. ))
  804. ;; (ffap-bindings)
  805. (add-hook 'sh-mode-hook
  806. (lambda ()
  807. (define-key sh-mode-map
  808. (kbd "C-x C-e")
  809. 'my-execute-shell-command-current-line)))
  810. (setq sh-here-document-word "__EOC__")
  811. (defun my-execute-shell-command-current-line ()
  812. "Run current line as shell command."
  813. (interactive)
  814. (shell-command (buffer-substring-no-properties (point-at-bol)
  815. (point))))
  816. (setq auto-mode-alist
  817. `(("autostart\\'" . sh-mode)
  818. ("xinitrc\\'" . sh-mode)
  819. ("xprograms\\'" . sh-mode)
  820. ("PKGBUILD\\'" . sh-mode)
  821. ,@auto-mode-alist))
  822. (and (lazy-load-eval 'pkgbuild-mode)
  823. (setq auto-mode-alist (append '(("PKGBUILD\\'" . pkgbuild-mode))
  824. auto-mode-alist)))
  825. (add-hook 'html-mode-hook
  826. (lambda ()
  827. (define-key html-mode-map (kbd "C-m")
  828. 'reindent-then-newline-and-indent)))
  829. (add-hook 'text-mode-hook
  830. (lambda ()
  831. (define-key text-mode-map (kbd "C-m") 'newline)))
  832. (add-to-list 'Info-default-directory-list
  833. (expand-file-name "~/.info/emacs-ja"))
  834. (add-hook 'apropos-mode-hook
  835. (lambda ()
  836. (define-key apropos-mode-map "n" 'next-line)
  837. (define-key apropos-mode-map "p" 'previous-line)
  838. ))
  839. (add-hook 'isearch-mode-hook
  840. (lambda ()
  841. ;; (define-key isearch-mode-map
  842. ;; (kbd "C-j") 'isearch-other-control-char)
  843. ;; (define-key isearch-mode-map
  844. ;; (kbd "C-k") 'isearch-other-control-char)
  845. ;; (define-key isearch-mode-map
  846. ;; (kbd "C-h") 'isearch-other-control-char)
  847. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  848. (define-key isearch-mode-map (kbd "M-r")
  849. 'isearch-query-replace-regexp)))
  850. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  851. (setq lazy-highlight-cleanup nil)
  852. ;; face for isearch highlighing
  853. (set-face-attribute 'lazy-highlight
  854. nil
  855. :foreground `unspecified
  856. :background `unspecified
  857. :underline t
  858. ;; :weight `bold
  859. )
  860. (add-hook 'outline-mode-hook
  861. (lambda ()
  862. (if (string-match "\\.md\\'" buffer-file-name)
  863. (set (make-local-variable 'outline-regexp) "#+ "))))
  864. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  865. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  866. (when (fetch-library
  867. "http://jblevins.org/projects/markdown-mode/markdown-mode.el"
  868. t)
  869. (lazy-load-eval 'markdown-mode)
  870. (setq markdown-command (or (executable-find "markdown")
  871. (executable-find "markdown.pl")))
  872. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'markdown-mode))
  873. (add-hook 'markdown-mode-hook
  874. (lambda ()
  875. (outline-minor-mode 1)
  876. (flyspell-mode)
  877. (set (make-local-variable 'comment-start) ";"))))
  878. ;; c-mode
  879. ;; http://www.emacswiki.org/emacs/IndentingC
  880. ;; http://en.wikipedia.org/wiki/Indent_style
  881. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  882. (when (lazy-load-eval 'cc-vars
  883. nil
  884. (add-to-list 'c-default-style
  885. '(c-mode . "k&r"))
  886. (add-to-list 'c-default-style
  887. '(c++-mode . "k&r"))
  888. (add-hook 'c-mode-common-hook
  889. (lambda ()
  890. ;; why c-basic-offset in k&r style defaults to 5 ???
  891. (setq c-basic-offset 4
  892. indent-tabs-mode nil)
  893. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  894. (c-toggle-hungry-state -1)
  895. ;; (and (require 'gtags nil t)
  896. ;; (gtags-mode 1))
  897. ))))
  898. (when (fetch-library
  899. "https://raw.github.com/mooz/js2-mode/master/js2-mode.el"
  900. t)
  901. (lazy-load-eval 'js2-mode)
  902. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  903. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  904. (add-hook 'js2-mode-hook
  905. (lambda ()
  906. (define-key js2-mode-map (kbd "C-m") (lambda ()
  907. (interactive)
  908. (js2-enter-key)
  909. (indent-for-tab-command)))
  910. ;; (add-hook (kill-local-variable 'before-save-hook)
  911. ;; 'js2-before-save)
  912. ;; (add-hook 'before-save-hook
  913. ;; 'my-indent-buffer
  914. ;; nil
  915. ;; t)
  916. )))
  917. (when (lazy-load-eval 'flymake-jslint
  918. '(flymake-jslint-load))
  919. (lazy-load-eval 'js nil
  920. (add-hook 'js-mode-hook
  921. 'flymake-jslint-load)))
  922. (require 'js-doc nil t)
  923. (when (require 'uniquify nil t)
  924. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  925. (setq uniquify-ignore-buffers-re "*[^*]+*")
  926. (setq uniquify-min-dir-content 1))
  927. (add-hook 'view-mode-hook
  928. (lambda()
  929. (define-key view-mode-map "j"
  930. (lambda() (interactive) (scroll-up 1)))
  931. (define-key view-mode-map "k"
  932. (lambda() (interactive) (scroll-down 1)))
  933. (define-key view-mode-map "v" 'toggle-read-only)
  934. (define-key view-mode-map "q" 'bury-buffer)
  935. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  936. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  937. ;; (define-key view-mode-map
  938. ;; "n" 'nonincremental-repeat-search-forward)
  939. ;; (define-key view-mode-map
  940. ;; "N" 'nonincremental-repeat-search-backward)
  941. (define-key view-mode-map "/" 'isearch-forward-regexp)
  942. (define-key view-mode-map "?" 'isearch-backward-regexp)
  943. (define-key view-mode-map "n" 'isearch-repeat-forward)
  944. (define-key view-mode-map "N" 'isearch-repeat-backward)
  945. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point)
  946. ))
  947. (global-set-key "\M-r" 'view-mode)
  948. ;; (setq view-read-only t)
  949. ;; (defun my-view-mode-search-word (word)
  950. ;; "Search for word current directory and subdirectories.
  951. ;; If called intearctively, find word at point."
  952. ;; (interactive (list (thing-at-point 'symbol)))
  953. ;; (if word
  954. ;; (if (and (require 'gtags nil t)
  955. ;; (gtags-get-rootpath))
  956. ;; (gtags-goto-tag word "s")
  957. ;; (my-rgrep word))
  958. ;; (message "No word at point.")
  959. ;; nil))
  960. (add-hook 'Man-mode-hook
  961. (lambda ()
  962. (view-mode 1)
  963. (setq truncate-lines nil)))
  964. (setq Man-notify-method (if window-system
  965. 'newframe
  966. 'aggressive))
  967. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  968. ;; python
  969. (when (lazy-load-eval 'python '(python-mode))
  970. (setq python-python-command (or (executable-find "python3")
  971. (executable-find "python")))
  972. ;; (defun my-python-run-as-command ()
  973. ;; ""
  974. ;; (interactive)
  975. ;; (shell-command (concat python-python-command " " buffer-file-name)))
  976. (defun my-python-display-python-buffer ()
  977. ""
  978. (interactive)
  979. (set-window-text-height (display-buffer python-buffer
  980. t)
  981. 7))
  982. (add-hook 'python-mode-hook
  983. (lambda ()
  984. (define-key python-mode-map
  985. (kbd "C-c C-e") 'my-python-run-as-command)
  986. (define-key python-mode-map
  987. (kbd "C-c C-b") 'my-python-display-python-buffer)
  988. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)))
  989. (add-hook 'inferior-python-mode-hook
  990. (lambda ()
  991. (my-python-display-python-buffer)
  992. (define-key inferior-python-mode-map
  993. (kbd "<up>") 'comint-previous-input)
  994. (define-key inferior-python-mode-map
  995. (kbd "<down>") 'comint-next-input))))
  996. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  997. ;; GNU GLOBAL(gtags)
  998. ;; http://uguisu.skr.jp/Windows/gtags.html
  999. ;; http://eigyr.dip.jp/gtags.html
  1000. ;; http://cha.la.coocan.jp/doc/gnu_global.html
  1001. (let ((d "/opt/local/share/gtags/"))
  1002. (and (file-directory-p d)
  1003. (add-to-list 'load-path
  1004. d)))
  1005. (when (lazy-load-eval 'gtags '(gtags-mode))
  1006. (add-hook 'gtags-mode-hook
  1007. (lambda ()
  1008. (view-mode gtags-mode)
  1009. (setq gtags-select-buffer-single t)
  1010. ;; (local-set-key "\M-t" 'gtags-find-tag)
  1011. ;; (local-set-key "\M-r" 'gtags-find-rtag)
  1012. ;; (local-set-key "\M-s" 'gtags-find-symbol)
  1013. ;; (local-set-key "\C-t" 'gtags-pop-stack)
  1014. (define-key gtags-mode-map (kbd "C-x t h")
  1015. 'gtags-find-tag-from-here)
  1016. (define-key gtags-mode-map (kbd "C-x t t") 'gtags-find-tag)
  1017. (define-key gtags-mode-map (kbd "C-x t r") 'gtags-find-rtag)
  1018. (define-key gtags-mode-map (kbd "C-x t s") 'gtags-find-symbol)
  1019. (define-key gtags-mode-map (kbd "C-x t p") 'gtags-find-pattern)
  1020. (define-key gtags-mode-map (kbd "C-x t f") 'gtags-find-file)
  1021. (define-key gtags-mode-map (kbd "C-x t b") 'gtags-pop-stack) ;back
  1022. ))
  1023. (add-hook 'gtags-select-mode-hook
  1024. (lambda ()
  1025. (define-key gtags-select-mode-map (kbd "C-m") 'gtags-select-tag)
  1026. ))
  1027. )
  1028. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1029. ;; term mode
  1030. ;; (setq multi-term-program shell-file-name)
  1031. (and (fetch-library "http://www.emacswiki.org/emacs/download/multi-term.el"
  1032. t)
  1033. (lazy-load-eval 'multi-term)
  1034. (progn
  1035. (setq multi-term-switch-after-close nil)
  1036. (setq multi-term-dedicated-select-after-open-p t)
  1037. (setq multi-term-dedicated-window-height 20)))
  1038. (when (lazy-load-eval 'term '(term ansi-term))
  1039. (defun my-term-quit-or-send-raw ()
  1040. ""
  1041. (interactive)
  1042. (if (get-buffer-process (current-buffer))
  1043. (call-interactively 'term-send-raw)
  1044. (kill-buffer)))
  1045. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  1046. ;; (setq term-ansi-default-program shell-file-name)
  1047. (add-hook 'term-setup-hook
  1048. (lambda ()
  1049. (setq term-display-table (make-display-table))))
  1050. (add-hook 'term-mode-hook
  1051. (lambda ()
  1052. (unless (memq (current-buffer)
  1053. (and (featurep 'multi-term)
  1054. ;; current buffer is not multi-term buffer
  1055. (multi-term-list)))
  1056. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  1057. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  1058. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  1059. ;; (define-key term-raw-map "\C-f" 'forward-char)
  1060. ;; (define-key term-raw-map "\C-b" 'backward-char)
  1061. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  1062. (define-key term-raw-map
  1063. "\C-x" (lookup-key (current-global-map) "\C-x"))
  1064. (define-key term-raw-map
  1065. "\C-z" (lookup-key (current-global-map) "\C-z"))
  1066. )
  1067. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  1068. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  1069. (define-key term-raw-map (kbd "<up>")
  1070. (lambda () (interactive) (scroll-down 1)))
  1071. (define-key term-raw-map (kbd "<down>")
  1072. (lambda () (interactive) (scroll-up 1)))
  1073. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  1074. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  1075. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  1076. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  1077. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  1078. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  1079. (define-key term-raw-map [delete] 'term-send-raw)
  1080. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  1081. (define-key term-raw-map "\C-y" 'term-paste)
  1082. (define-key term-raw-map
  1083. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  1084. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  1085. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  1086. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  1087. ;; (define-key term-raw-map "\C-d" 'delete-char)
  1088. (set (make-local-variable 'scroll-margin) 0)
  1089. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  1090. ;; (cua-mode 0)
  1091. ;; (and cua-mode
  1092. ;; (local-unset-key (kbd "C-c")))
  1093. ;; (define-key cua--prefix-override-keymap
  1094. ;;"\C-c" 'term-interrupt-subjob)
  1095. (set (make-local-variable 'hl-line-range-function)
  1096. (lambda ()
  1097. '(0 . 0)))
  1098. ))
  1099. ;; (add-hook 'term-exec-hook 'forward-char)
  1100. )
  1101. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1102. ;; buffer switching
  1103. (when (lazy-load-eval 'bs '(bs-show)
  1104. ;; (add-to-list 'bs-configurations
  1105. ;; '("processes" nil get-buffer-process ".*" nil nil))
  1106. (add-to-list 'bs-configurations
  1107. '("this-frame" nil (lambda (buf)
  1108. (memq buf (my-frame-buffer-get)))
  1109. ".*" nil nil))
  1110. (add-to-list 'bs-configurations
  1111. '("files-and-terminals" nil nil nil
  1112. (lambda (buf)
  1113. (and (bs-visits-non-file buf)
  1114. (save-excursion
  1115. (set-buffer buf)
  1116. (not (memq major-mode
  1117. '(term-mode
  1118. eshell-mode))))))))
  1119. ;; (setq bs-configurations (list
  1120. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1121. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1122. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1123. )
  1124. ;; (global-set-key "\C-x\C-b" 'bs-show)
  1125. (defalias 'list-buffers 'bs-show)
  1126. (setq bs-default-configuration "files-and-terminals")
  1127. (setq bs-default-sort-name "by nothing")
  1128. (add-hook 'bs-mode-hook
  1129. (lambda ()
  1130. ;; (setq bs-default-configuration "files")
  1131. ;; (and bs--show-all
  1132. ;; (call-interactively 'bs-toggle-show-all))
  1133. (set (make-local-variable 'scroll-margin) 0))))
  1134. (iswitchb-mode 1)
  1135. (defun iswitchb-buffer-display-other-window ()
  1136. "Do iswitchb in other window."
  1137. (interactive)
  1138. (let ((iswitchb-default-method 'display))
  1139. (call-interactively 'iswitchb-buffer)))
  1140. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1141. ;; sdic
  1142. (when (lazy-load-eval 'sdic '(sdic-describe-word-at-point))
  1143. ;; (define-key my-prefix-map "\C-w" 'sdic-describe-word)
  1144. (define-key my-prefix-map "\C-t" 'sdic-describe-word-at-point-echo)
  1145. (defun sdic-describe-word-at-point-echo ()
  1146. ""
  1147. (interactive)
  1148. (save-window-excursion
  1149. (sdic-describe-word-at-point))
  1150. (save-excursion
  1151. (set-buffer sdic-buffer-name)
  1152. (message (buffer-substring (point-min)
  1153. (progn (goto-char (point-min))
  1154. (or (and (re-search-forward "^\\w"
  1155. nil
  1156. t
  1157. 4)
  1158. (progn (previous-line) t)
  1159. (point-at-eol))
  1160. (point-max)))))))
  1161. (setq sdic-eiwa-dictionary-list '((sdicf-client "/usr/share/dict/gene.sdic")))
  1162. (setq sdic-waei-dictionary-list
  1163. '((sdicf-client "/usr/share/dict/jedict.sdic" (add-keys-to-headword t))))
  1164. (setq sdic-disable-select-window t)
  1165. (setq sdic-window-height 7))
  1166. ;;;;;;;;;;;;;;;;;;;;;;;;
  1167. ;; ilookup
  1168. (when (fetch-library
  1169. "https://raw.github.com/10sr/emacs-lisp/master/ilookup.el"
  1170. t)
  1171. (lazy-load-eval 'ilookup
  1172. '(ilookup-open)
  1173. (setq ilookup-dict-alist
  1174. '(
  1175. ("en" . (lambda (word)
  1176. (shell-command-to-string
  1177. (format "sdcv -n -u dictd_www.dict.org_gcide '%s'"
  1178. word))))
  1179. ("ja" . (lambda (word)
  1180. (shell-command-to-string
  1181. (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'"
  1182. word))))
  1183. ("jaj" . (lambda (word)
  1184. (shell-command-to-string
  1185. (format "sdcv -n -u jmdict-en-ja '%s'"
  1186. word))))
  1187. ("jag" .
  1188. (lambda (word)
  1189. (with-temp-buffer
  1190. (insert (shell-command-to-string
  1191. (format "sdcv -n -u 'Genius English-Japanese' '%s'"
  1192. word)))
  1193. (html2text)
  1194. (buffer-substring (point-min)
  1195. (point-max)))))
  1196. ("alc" . (lambda (word)
  1197. (shell-command-to-string
  1198. (format "alc '%s' | head -n 20"
  1199. word))))
  1200. ("app" . (lambda (word)
  1201. (shell-command-to-string
  1202. (format "dict_app '%s'"
  1203. word))))
  1204. ;; letters broken
  1205. ("ms" .
  1206. (lambda (word)
  1207. (let ((url (concat
  1208. "http://api.microsofttranslator.com/V2/Ajax.svc/"
  1209. "Translate?appId=%s&text=%s&to=%s"))
  1210. (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51")
  1211. (target "ja")
  1212. (eword (url-hexify-string word)))
  1213. (with-current-buffer (url-retrieve-synchronously
  1214. (format url
  1215. apikey
  1216. eword
  1217. target))
  1218. (message "")
  1219. (goto-char (point-min))
  1220. (search-forward-regexp "^$"
  1221. nil
  1222. t)
  1223. (url-unhex-string (buffer-substring-no-properties
  1224. (point)
  1225. (point-max)))))))
  1226. ))
  1227. ;; (funcall (cdr (assoc "ms"
  1228. ;; ilookup-alist))
  1229. ;; "dictionary")
  1230. ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja"))
  1231. ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com"))
  1232. (setq ilookup-default "ja")
  1233. (when (locate-library "google-translate")
  1234. (add-to-list 'ilookup-dict-alist
  1235. '("gt" .
  1236. (lambda (word)
  1237. (save-excursion
  1238. (google-translate-translate "auto"
  1239. "ja"
  1240. word))
  1241. (with-current-buffer "*Google Translate*"
  1242. (buffer-substring-no-properties (point-min)
  1243. (point-max)))))))
  1244. ))
  1245. (when (lazy-load-eval 'google-translate '(google-translate-translate
  1246. google-translate-at-point))
  1247. (setq google-translate-default-source-language "auto")
  1248. (setq google-translate-default-target-language "ja"))
  1249. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1250. ;; vc
  1251. ;; (require 'vc)
  1252. (setq vc-handled-backends '())
  1253. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1254. ;; gauche-mode
  1255. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  1256. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  1257. (when (and (fetch-library
  1258. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  1259. t)
  1260. (lazy-load-eval 'gauche-mode '(gauche-mode run-scheme)))
  1261. (let ((s (executable-find "gosh")))
  1262. (setq scheme-program-name s
  1263. gauche-program-name s))
  1264. (defun run-gauche-other-window ()
  1265. "Run gauche on other window"
  1266. (interactive)
  1267. (switch-to-buffer-other-window
  1268. (get-buffer-create "*scheme*"))
  1269. (run-gauche))
  1270. (defun run-gauche ()
  1271. "run gauche"
  1272. (run-scheme gauche-program-name)
  1273. )
  1274. (defun scheme-send-buffer ()
  1275. ""
  1276. (interactive)
  1277. (scheme-send-region (point-min) (point-max))
  1278. (my-scheme-display-scheme-buffer)
  1279. )
  1280. (defun my-scheme-display-scheme-buffer ()
  1281. ""
  1282. (interactive)
  1283. (set-window-text-height (display-buffer scheme-buffer
  1284. t)
  1285. 7))
  1286. (add-hook 'scheme-mode-hook
  1287. (lambda ()
  1288. nil))
  1289. (add-hook 'inferior-scheme-mode-hook
  1290. (lambda ()
  1291. ;; (my-scheme-display-scheme-buffer)
  1292. ))
  1293. (setq auto-mode-alist
  1294. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1295. (setq auto-mode-alist
  1296. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1297. (add-hook 'gauche-mode-hook
  1298. (lambda ()
  1299. (define-key gauche-mode-map
  1300. (kbd "C-c C-z") 'run-gauche-other-window)
  1301. (define-key scheme-mode-map
  1302. (kbd "C-c C-c") 'scheme-send-buffer)
  1303. (define-key scheme-mode-map
  1304. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer))))
  1305. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1306. ;; recentf-mode
  1307. (setq recentf-save-file (expand-file-name "~/.emacs.d/recentf")
  1308. recentf-max-menu-items 20
  1309. recentf-max-saved-items 30
  1310. recentf-show-file-shortcuts-flag nil)
  1311. (when (require 'recentf nil t)
  1312. (add-to-list 'recentf-exclude (regexp-quote recentf-save-file))
  1313. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1314. (add-hook 'find-file-hook
  1315. 'recentf-save-list
  1316. t) ; save to file immediately after adding file to recentf list
  1317. (add-hook 'kill-emacs-hook
  1318. 'recentf-load-list)
  1319. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1320. ;; (add-hook 'find-file-hook
  1321. ;; (lambda ()
  1322. ;; (recentf-add-file default-directory)))
  1323. (and (fetch-library
  1324. "https://raw.github.com/10sr/emacs-lisp/master/recentf-show.el"
  1325. t)
  1326. (lazy-load-eval 'recentf-show)
  1327. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1328. (add-hook 'recentf-show-before-listing-hook
  1329. 'recentf-load-list))
  1330. (recentf-mode 1)
  1331. (add-hook 'recentf-dialog-mode-hook
  1332. (lambda ()
  1333. ;; (recentf-save-list)
  1334. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1335. ;; 'my-recentf-cd-and-find-file)
  1336. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1337. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1338. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1339. (define-key recentf-dialog-mode-map "n" 'next-line)
  1340. (cd "~/"))))
  1341. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1342. ;; dired
  1343. (when (lazy-load-eval 'dired nil)
  1344. (defun my-dired-echo-file-head (arg)
  1345. ""
  1346. (interactive "P")
  1347. (let ((f (dired-get-filename)))
  1348. (message "%s"
  1349. (with-temp-buffer
  1350. (insert-file-contents f)
  1351. (buffer-substring-no-properties
  1352. (point-min)
  1353. (progn (goto-line (if arg
  1354. (prefix-numeric-value arg)
  1355. 10))
  1356. (point-at-eol)))))))
  1357. (defun my-dired-diff ()
  1358. ""
  1359. (interactive)
  1360. (let ((files (dired-get-marked-files nil nil nil t)))
  1361. (if (eq (car files)
  1362. t)
  1363. (diff (cadr files) (dired-get-filename))
  1364. (message "One files must be marked!"))))
  1365. (defun my-pop-to-buffer-erase-noselect (buffer-or-name)
  1366. "pop up buffer using `display-buffer' and return that buffer."
  1367. (let ((bf (get-buffer-create buffer-or-name)))
  1368. (with-current-buffer bf
  1369. (cd ".")
  1370. (erase-buffer))
  1371. (display-buffer bf)
  1372. bf))
  1373. (defun my-replace-nasi-none ()
  1374. ""
  1375. (save-excursion
  1376. (let ((buffer-read-only nil))
  1377. (goto-char (point-min))
  1378. (while (search-forward "なし" nil t)
  1379. (replace-match "none")))))
  1380. (defun dired-get-file-info ()
  1381. "dired get file info"
  1382. (interactive)
  1383. (let ((f (shell-quote-argument (dired-get-filename t))))
  1384. (if (file-directory-p f)
  1385. (progn
  1386. (message "Calculating disk usage...")
  1387. (shell-command (concat "du -hsD "
  1388. f)))
  1389. (shell-command (concat "file "
  1390. f)))))
  1391. (defun my-dired-scroll-up ()
  1392. ""
  1393. (interactive)
  1394. (my-dired-previous-line (- (window-height) 1)))
  1395. (defun my-dired-scroll-down ()
  1396. ""
  1397. (interactive)
  1398. (my-dired-next-line (- (window-height) 1)))
  1399. ;; (defun my-dired-forward-line (arg)
  1400. ;; ""
  1401. ;; (interactive "p"))
  1402. (defun my-dired-previous-line (arg)
  1403. ""
  1404. (interactive "p")
  1405. (if (> arg 0)
  1406. (progn
  1407. (if (eq (line-number-at-pos)
  1408. 1)
  1409. (goto-char (point-max))
  1410. (forward-line -1))
  1411. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1412. (dired-get-subdir))
  1413. (- arg 1)
  1414. arg)))
  1415. (dired-move-to-filename)))
  1416. (defun my-dired-next-line (arg)
  1417. ""
  1418. (interactive "p")
  1419. (if (> arg 0)
  1420. (progn
  1421. (if (eq (point)
  1422. (point-max))
  1423. (goto-char (point-min))
  1424. (forward-line 1))
  1425. (my-dired-next-line (if (or (dired-get-filename nil t)
  1426. (dired-get-subdir))
  1427. (- arg 1)
  1428. arg)))
  1429. (dired-move-to-filename)))
  1430. (defun my-dired-print-current-dir-and-file ()
  1431. (message "%s %s"
  1432. default-directory
  1433. (buffer-substring-no-properties (point-at-bol)
  1434. (point-at-eol))))
  1435. (defun dired-do-execute-as-command ()
  1436. ""
  1437. (interactive)
  1438. (let ((file (dired-get-filename t)))
  1439. (if (file-executable-p file)
  1440. (start-process file nil file)
  1441. (when (y-or-n-p
  1442. "this file cant be executed. mark as executable and go? : ")
  1443. (set-file-modes file
  1444. (file-modes-symbolic-to-number "u+x" (file-modes file)))
  1445. (start-process file nil file)))))
  1446. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1447. (defun my-dired-x-open ()
  1448. ""
  1449. (interactive)
  1450. (my-x-open (dired-get-filename t t)))
  1451. (if (eq window-system 'mac)
  1452. (setq dired-listing-switches "-lhF")
  1453. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1454. )
  1455. (setq dired-listing-switches "-lhF")
  1456. (put 'dired-find-alternate-file 'disabled nil)
  1457. ;; when using dired-find-alternate-file
  1458. ;; reuse current dired buffer for the file to open
  1459. (setq dired-ls-F-marks-symlinks t)
  1460. (when (require 'ls-lisp nil t)
  1461. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1462. (setq ls-lisp-dirs-first t)
  1463. (setq ls-lisp-use-localized-time-format t)
  1464. (setq ls-lisp-format-time-list
  1465. '("%Y-%m-%d %H:%M"
  1466. "%Y-%m-%d ")))
  1467. (setq dired-dwim-target t)
  1468. ;; (add-hook 'dired-after-readin-hook
  1469. ;; 'my-replace-nasi-none)
  1470. ;; (add-hook 'after-init-hook
  1471. ;; (lambda ()
  1472. ;; (dired ".")))
  1473. (add-hook 'dired-mode-hook
  1474. (lambda ()
  1475. (define-key dired-mode-map "o" 'my-dired-x-open)
  1476. (define-key dired-mode-map "i" 'dired-get-file-info)
  1477. (define-key dired-mode-map "f" 'find-file)
  1478. (define-key dired-mode-map "!" 'shell-command)
  1479. (define-key dired-mode-map "&" 'async-shell-command)
  1480. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1481. (define-key dired-mode-map "=" 'my-dired-diff)
  1482. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1483. (define-key dired-mode-map "b" 'gtkbm)
  1484. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1485. (define-key dired-mode-map "@" (lambda ()
  1486. (interactive) (my-x-open ".")))
  1487. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1488. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1489. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1490. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1491. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1492. (substitute-key-definition 'dired-next-line
  1493. 'my-dired-next-line dired-mode-map)
  1494. (substitute-key-definition 'dired-previous-line
  1495. 'my-dired-previous-line dired-mode-map)
  1496. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1497. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1498. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1499. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1500. (let ((file "._Icon\015"))
  1501. (when nil (file-readable-p file)
  1502. (delete-file file)))))
  1503. (and (fetch-library "https://raw.github.com/10sr/emacs-lisp/master/pack.el"
  1504. t)
  1505. (lazy-load-eval 'pack '(dired-do-pack-or-unpack pack))
  1506. (add-hook 'dired-mode-hook
  1507. (lambda ()
  1508. (define-key dired-mode-map "P" 'dired-do-pack-or-unpack))))
  1509. (and (fetch-library
  1510. "https://raw.github.com/10sr/emacs-lisp/master/dired-list-all-mode.el"
  1511. t)
  1512. (lazy-load-eval 'dired-list-all-mode)
  1513. (setq dired-listing-switches "-lhF")
  1514. (add-hook 'dired-mode-hook
  1515. (lambda ()
  1516. (define-key dired-mode-map "a" 'dired-list-all-mode)
  1517. )))
  1518. ) ; when dired locate
  1519. ;; http://blog.livedoor.jp/tek_nishi/archives/4693204.html
  1520. (defun my-dired-toggle-mark()
  1521. (let ((cur (cond ((eq (following-char) dired-marker-char) ?\040)
  1522. (t dired-marker-char))))
  1523. (delete-char 1)
  1524. (insert cur)))
  1525. (defun my-dired-mark (arg)
  1526. "Toggle mark the current (or next ARG) files.
  1527. If on a subdir headerline, mark all its files except `.' and `..'.
  1528. Use \\[dired-unmark-all-files] to remove all marks
  1529. and \\[dired-unmark] on a subdir to remove the marks in
  1530. this subdir."
  1531. (interactive "P")
  1532. (if (dired-get-subdir)
  1533. (save-excursion (dired-mark-subdir-files))
  1534. (let ((inhibit-read-only t))
  1535. (dired-repeat-over-lines
  1536. (prefix-numeric-value arg)
  1537. 'my-dired-toggle-mark))))
  1538. (defun my-dired-mark-backward (arg)
  1539. "In Dired, move up lines and toggle mark there.
  1540. Optional prefix ARG says how many lines to unflag; default is one line."
  1541. (interactive "p")
  1542. (my-dired-mark (- arg)))
  1543. (add-hook 'dired-mode-hook
  1544. (lambda ()
  1545. (local-set-key (kbd "SPC") 'my-dired-mark)
  1546. (local-set-key (kbd "S-SPC") 'my-dired-mark-backward))
  1547. )
  1548. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1549. ;; eshell
  1550. (lazy-load-eval 'eshell nil
  1551. (defvar eshell-text-mode-map
  1552. (let ((map (make-sparse-keymap)))
  1553. (define-key map (kbd "C-x t") 'eshell-text-mode-toggle)
  1554. map))
  1555. (define-derived-mode eshell-text-mode text-mode
  1556. "Eshell-Text"
  1557. "Text-mode for Eshell."
  1558. nil)
  1559. (defun eshell-text-mode-toggle ()
  1560. "Toggle eshell-text-mode and eshell-mode."
  1561. (interactive)
  1562. (cond ((eq major-mode
  1563. 'eshell-text-mode)
  1564. (goto-char (point-max))
  1565. (eshell-mode))
  1566. ((eq major-mode
  1567. 'eshell-mode)
  1568. (eshell-text-mode))
  1569. (t
  1570. (message "Not in eshell buffer")
  1571. nil)))
  1572. (defun my-eshell-backward-delete-char ()
  1573. (interactive)
  1574. (when (< (save-excursion
  1575. (eshell-bol)
  1576. (point))
  1577. (point))
  1578. (backward-delete-char 1)))
  1579. (defun my-file-owner-p (file)
  1580. "t if FILE is owned by me."
  1581. (eq (user-uid) (nth 2 (file-attributes file))))
  1582. "http://www.bookshelf.jp/pukiwiki/pukiwiki.php\
  1583. ?Eshell%A4%F2%BB%C8%A4%A4%A4%B3%A4%CA%A4%B9"
  1584. ;; ;; written by Stefan Reichoer <reichoer@web.de>
  1585. ;; (defun eshell/less (&rest args)
  1586. ;; "Invoke `view-file' on the file.
  1587. ;; \"less +42 foo\" also goes to line 42 in the buffer."
  1588. ;; (if args
  1589. ;; (while args
  1590. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1591. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1592. ;; (file (pop args)))
  1593. ;; (view-file file)
  1594. ;; (goto-line line))
  1595. ;; (view-file (pop args))))))
  1596. (defun eshell/o (&optional file)
  1597. (my-x-open (or file ".")))
  1598. ;; (defun eshell/vi (&rest args)
  1599. ;; "Invoke `find-file' on the file.
  1600. ;; \"vi +42 foo\" also goes to line 42 in the buffer."
  1601. ;; (while args
  1602. ;; (if (string-match "\\`\\+\\([0-9]+\\)\\'" (car args))
  1603. ;; (let* ((line (string-to-number (match-string 1 (pop args))))
  1604. ;; (file (pop args)))
  1605. ;; (find-file file)
  1606. ;; (goto-line line))
  1607. ;; (find-file (pop args)))))
  1608. (defun eshell/clear ()
  1609. "Clear the current buffer, leaving one prompt at the top."
  1610. (interactive)
  1611. (let ((inhibit-read-only t))
  1612. (erase-buffer)))
  1613. (defun eshell-clear ()
  1614. (interactive)
  1615. (let ((inhibit-read-only t))
  1616. (erase-buffer)
  1617. (insert (funcall eshell-prompt-function))))
  1618. (defun eshell/d (&optional dirname switches)
  1619. "if first arg is omitted open current directory."
  1620. (dired (or dirname ".") switches))
  1621. (defun eshell/v ()
  1622. (view-mode 1))
  1623. ;; (defun eshell/aaa (&rest args)
  1624. ;; (message "%S"
  1625. ;; args))
  1626. (defvar eshell/git-cat-command
  1627. nil
  1628. "List of git commands that cat just return strings as results.")
  1629. (setq eshell/git-cat-command
  1630. '("status" "st" "b" "branch" "ls" "ls-files")
  1631. )
  1632. (defun eshell/git (&rest args)
  1633. (if (member (car args)
  1634. eshell/git-cat-command)
  1635. (shell-command-to-string (mapconcat 'shell-quote-argument
  1636. `("git"
  1637. "-c"
  1638. "color.ui=always"
  1639. ,@args)
  1640. " "))
  1641. ;; (eshell-git-shell-command-to-string args)
  1642. (if (require 'git-command nil t)
  1643. (git-command (mapconcat 'shell-quote-argument
  1644. args
  1645. " "))
  1646. (apply 'eshell-exec-visual "git" args))))
  1647. ;; (defun eshell-git-shell-command-to-string (args)
  1648. ;; "Return string of output of ARGS."
  1649. ;; (let ((sargs (mapconcat 'shell-quote-argument
  1650. ;; args
  1651. ;; " ")))
  1652. ;; (if (require 'ansi-color nil t)
  1653. ;; (identity
  1654. ;; (shell-command-to-string (concat "git "
  1655. ;; "-c color.ui=always "
  1656. ;; sargs)))
  1657. ;; (shell-command-to-string (concat "git "
  1658. ;; sargs)))))
  1659. (defalias 'eshell/g 'eshell/git)
  1660. (defalias 'eshell/: 'ignore)
  1661. (defalias 'eshell/type 'eshell/which)
  1662. ;; (defalias 'eshell/vim 'eshell/vi)
  1663. (defalias 'eshell/ff 'find-file)
  1664. (defalias 'eshell/q 'eshell/exit)
  1665. (defun eshell-goto-prompt ()
  1666. ""
  1667. (interactive)
  1668. (goto-char (point-max)))
  1669. (defun eshell-delete-char-or-logout (n)
  1670. (interactive "p")
  1671. (if (equal (eshell-get-old-input)
  1672. "")
  1673. (progn
  1674. (insert "exit")
  1675. (eshell-send-input))
  1676. (delete-char n)))
  1677. (defun eshell-kill-input ()
  1678. (interactive)
  1679. (delete-region (point)
  1680. (progn (eshell-bol)
  1681. (point))))
  1682. (defalias 'eshell/logout 'eshell/exit)
  1683. (defun eshell-cd-default-directory (&optional eshell-buffer-or-name)
  1684. "open eshell and change wd
  1685. if arg given, use that eshell buffer, otherwise make new eshell buffer."
  1686. (interactive)
  1687. (let ((dir (expand-file-name default-directory)))
  1688. (switch-to-buffer (or eshell-buffer-or-name
  1689. (eshell t)))
  1690. (unless (equal dir (expand-file-name default-directory))
  1691. ;; (cd dir)
  1692. ;; (eshell-interactive-print (concat "cd " dir "\n"))
  1693. ;; (eshell-emit-prompt)
  1694. (goto-char (point-max))
  1695. (eshell-kill-input)
  1696. (insert "cd " dir)
  1697. (eshell-send-input))))
  1698. (defadvice eshell-next-matching-input-from-input
  1699. ;; do not cycle history
  1700. (around eshell-history-do-not-cycle activate)
  1701. (if (= 0
  1702. (or eshell-history-index
  1703. 0))
  1704. (progn
  1705. (delete-region eshell-last-output-end (point))
  1706. (insert-and-inherit eshell-matching-input-from-input-string)
  1707. (setq eshell-history-index nil))
  1708. ad-do-it))
  1709. (setq eshell-directory-name "~/.emacs.d/eshell/")
  1710. (setq eshell-term-name "eterm-color")
  1711. (setq eshell-scroll-to-bottom-on-input t)
  1712. (setq eshell-cmpl-ignore-case t)
  1713. (setq eshell-cmpl-cycle-completions nil)
  1714. (setq eshell-highlight-prompt nil)
  1715. (setq eshell-ls-initial-args '("-hCFG"
  1716. "--color=auto"
  1717. "--time-style=long-iso")) ; "-hF")
  1718. (setq eshell-prompt-function
  1719. 'my-eshell-prompt-function)
  1720. (defun my-eshell-prompt-function ()
  1721. (with-temp-buffer
  1722. (let (p1 p2 p3 p4)
  1723. (insert ":: [")
  1724. (setq p1 (point))
  1725. (insert user-login-name
  1726. "@"
  1727. (car (split-string system-name
  1728. "\\."))
  1729. )
  1730. (setq p2 (point))
  1731. (insert ":")
  1732. (setq p3 (point))
  1733. (insert (abbreviate-file-name default-directory))
  1734. (setq p4 (point))
  1735. (insert "]")
  1736. (insert "\n:: ")
  1737. (unless (eq 0
  1738. eshell-last-command-status)
  1739. (insert (format "[STATUS:%d] "
  1740. eshell-last-command-status)))
  1741. (insert (if (= (user-uid)
  1742. 0)
  1743. "# "
  1744. "$ "))
  1745. (add-text-properties p1
  1746. p2
  1747. '(face underline))
  1748. (add-text-properties p3
  1749. p4
  1750. '(face underline))
  1751. (buffer-substring (point-min)
  1752. (point-max)))))
  1753. (add-hook 'eshell-mode-hook
  1754. (lambda ()
  1755. ;; (define-key eshell-mode-map (kbd "C-x C-x") (lambda ()
  1756. ;; (interactive)
  1757. ;; (switch-to-buffer (other-buffer))))
  1758. ;; (define-key eshell-mode-map (kbd "C-g") (lambda ()
  1759. ;; (interactive)
  1760. ;; (eshell-goto-prompt)
  1761. ;; (keyboard-quit)))
  1762. (define-key eshell-mode-map (kbd "C-x t")
  1763. 'eshell-text-mode-toggle)
  1764. (define-key eshell-mode-map (kbd "C-u")
  1765. 'eshell-kill-input)
  1766. (define-key eshell-mode-map (kbd "C-d")
  1767. 'eshell-delete-char-or-logout)
  1768. ;; (define-key eshell-mode-map (kbd "C-l")
  1769. ;; 'eshell-clear)
  1770. (define-key eshell-mode-map (kbd "DEL")
  1771. 'my-eshell-backward-delete-char)
  1772. (define-key eshell-mode-map
  1773. (kbd "C-p") 'eshell-previous-matching-input-from-input)
  1774. (define-key eshell-mode-map
  1775. (kbd "C-n") 'eshell-next-matching-input-from-input)
  1776. (apply 'eshell/addpath exec-path)
  1777. (set (make-local-variable 'scroll-margin) 0)
  1778. ;; (eshell/export "GIT_PAGER=")
  1779. ;; (eshell/export "GIT_EDITOR=")
  1780. (eshell/export "LC_MESSAGES=C")
  1781. (switch-to-buffer (current-buffer)) ; move buffer top of list
  1782. (set (make-local-variable 'hl-line-range-function)
  1783. (lambda ()
  1784. '(0 . 0)))
  1785. (add-to-list 'eshell-virtual-targets
  1786. '("/dev/less"
  1787. (lambda (str)
  1788. (if str
  1789. (with-current-buffer nil)))
  1790. nil))
  1791. ))
  1792. (add-hook 'eshell-mode-hook
  1793. (lambda ()
  1794. (add-to-list 'eshell-visual-commands "vim")
  1795. ;; (add-to-list 'eshell-visual-commands "git")
  1796. (add-to-list 'eshell-output-filter-functions
  1797. 'eshell-truncate-buffer)
  1798. (mapcar (lambda (alias)
  1799. (add-to-list 'eshell-command-aliases-list
  1800. alias))
  1801. '(
  1802. ; ("ll" "ls -l $*")
  1803. ; ("la" "ls -a $*")
  1804. ; ("lla" "ls -al $*")
  1805. ("eless"
  1806. (concat "cat >>> (with-current-buffer "
  1807. "(get-buffer-create \"*eshell output\") "
  1808. "(erase-buffer) "
  1809. "(setq buffer-read-only nil) "
  1810. "(current-buffer)) "
  1811. "(view-buffer (get-buffer \"*eshell output*\"))")
  1812. ))
  1813. )))
  1814. ) ; eval after load eshell
  1815. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1816. ;; frame buffer
  1817. ;; todo: work well when opening files already opened on another window
  1818. (add-hook 'after-make-frame-functions
  1819. (lambda (f)
  1820. (set-window-buffer (frame-selected-window f)
  1821. "*Messages*")))
  1822. (defun make-frame-command-with-name (name)
  1823. "Make frame with NAME specified."
  1824. (interactive "sName for new frame: ")
  1825. (set-frame-parameter (make-frame-command)
  1826. 'name
  1827. name))
  1828. (defvar my-frame-buffer-plist nil)
  1829. (defun my-frame-buffer-add (&optional buf frame)
  1830. "Add BUF to buffer list for FRAME."
  1831. (setq my-frame-buffer-plist
  1832. (plist-put my-frame-buffer-plist
  1833. (or frame
  1834. (selected-frame))
  1835. (let ((lst (my-frame-buffer-get frame)))
  1836. (if lst
  1837. (add-to-list 'lst
  1838. (or buf
  1839. (current-buffer)))
  1840. (list (or buf
  1841. (current-buffer))))))))
  1842. (defun my-frame-buffer-remove (&optional buf frame)
  1843. "Remove BUF from bufferlist for FRAME."
  1844. (setq my-frame-buffer-plist
  1845. (plist-put my-frame-buffer-plist
  1846. (or frame
  1847. (selected-frame))
  1848. (delq (or buf
  1849. (current-buffer))
  1850. (my-frame-buffer-get frame)))))
  1851. (defun my-frame-buffer-get (&optional frame)
  1852. "Get buffer list for FRAME."
  1853. (plist-get my-frame-buffer-plist
  1854. (or frame
  1855. (selected-frame))))
  1856. (defun my-frame-buffer-kill-all-buffer (&optional frame)
  1857. "Kill all buffer of FRAME."
  1858. (mapcar 'kill-buffer
  1859. (my-frame-buffer-get frame)))
  1860. (add-hook 'find-file-hook
  1861. 'my-frame-buffer-add)
  1862. ;; (add-hook 'term-mode-hook
  1863. ;; 'my-frame-buffer-add)
  1864. (add-hook 'eshell-mode-hook
  1865. 'my-frame-buffer-add)
  1866. (add-hook 'Man-mode-hook
  1867. 'my-frame-buffer-add)
  1868. (add-hook 'kill-buffer-hook
  1869. 'my-frame-buffer-remove)
  1870. (add-hook 'delete-frame-functions
  1871. 'my-frame-buffer-kill-all-buffer)
  1872. (defvar my-desktop-terminal "roxterm")
  1873. (defun my-execute-terminal ()
  1874. "Invole terminal program."
  1875. (interactive)
  1876. (if (and (or (eq system-type 'windows-nt)
  1877. window-system)
  1878. my-desktop-terminal
  1879. )
  1880. (let ((process-environment (cons "TERM=xterm" process-environment)))
  1881. (start-process "terminal"
  1882. nil
  1883. my-desktop-terminal))
  1884. (my-term)))
  1885. (defun my-delete-frame-or-kill-emacs ()
  1886. "Delete frame when opening multiple frame, kill Emacs when only one."
  1887. (interactive)
  1888. (if (eq 1
  1889. (length (frame-list)))
  1890. (save-buffers-kill-emacs)
  1891. (delete-frame)))
  1892. ;; (define-key my-prefix-map (kbd "C-s") 'my-execute-terminal)
  1893. (define-key my-prefix-map (kbd "C-f") 'make-frame-command-with-name)
  1894. (global-set-key (kbd "C-x C-c") 'my-delete-frame-or-kill-emacs)
  1895. (define-key my-prefix-map (kbd "C-x C-c") 'save-buffers-kill-emacs)
  1896. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1897. ;; my-term
  1898. (defvar my-term nil
  1899. "My terminal buffer.")
  1900. (defvar my-term-function nil
  1901. "Function to create terminal buffer.
  1902. This function accept no argument and return newly created buffer of terminal.")
  1903. (defun my-term (&optional arg)
  1904. "Open terminal buffer and return that buffer.
  1905. ARG is ignored."
  1906. (interactive "P")
  1907. (if (and my-term
  1908. (buffer-name my-term))
  1909. (pop-to-buffer my-term)
  1910. (setq my-term
  1911. (save-window-excursion
  1912. (funcall my-term-function)))
  1913. (and my-term
  1914. (my-term))))
  1915. ;; (setq my-term-function
  1916. ;; (lambda ()
  1917. ;; (if (eq system-type 'windows-nt)
  1918. ;; (eshell)
  1919. ;; (if (require 'multi-term nil t)
  1920. ;; (multi-term)
  1921. ;; (ansi-term shell-file-name)))))
  1922. (setq my-term-function 'eshell)
  1923. (define-key my-prefix-map (kbd "C-s") 'my-term)
  1924. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1925. ;; x open
  1926. (defvar my-filer nil)
  1927. (setq my-filer (or (executable-find "pcmanfm")
  1928. (executable-find "nautilus")))
  1929. (defun my-x-open (file)
  1930. "open FILE."
  1931. (interactive "FOpen File: ")
  1932. (setq file (expand-file-name file))
  1933. (message "Opening %s..." file)
  1934. (cond ((eq system-type 'windows-nt)
  1935. (call-process "cmd.exe" nil 0 nil
  1936. "/c" "start" "" (convert-standard-filename file)))
  1937. ((eq system-type 'darwin)
  1938. (call-process "open" nil 0 nil file))
  1939. ((getenv "DISPLAY")
  1940. (call-process (or my-filer "xdg-open") nil 0 nil file))
  1941. (t
  1942. (find-file file))
  1943. )
  1944. ;; (recentf-add-file file)
  1945. (message "Opening %s...done" file))
  1946. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1947. ;; misc funcs
  1948. (defun memo (&optional dir)
  1949. "Open memo.txt in DIR."
  1950. (interactive)
  1951. (pop-to-buffer (find-file-noselect (concat (if dir
  1952. (file-name-as-directory dir)
  1953. "")
  1954. "memo.txt"))))
  1955. (defvar my-rgrep-alist
  1956. `(
  1957. ;; the silver searcher
  1958. ("ag"
  1959. (executable-find "ag")
  1960. "ag --nocolor --nogroup --nopager ")
  1961. ;; ack
  1962. ("ack"
  1963. (executable-find "ack")
  1964. "ack --nocolor --nogroup --nopager ")
  1965. ;; gnu global
  1966. ("global"
  1967. (and (require 'gtags nil t)
  1968. (executable-find "global")
  1969. (gtags-get-rootpath))
  1970. "global --result grep ")
  1971. ;; git grep
  1972. ("gitgrep"
  1973. (eq 0
  1974. (shell-command "git rev-parse --git-dir"))
  1975. "git --no-pager -c color.grep=false grep -nH -e ")
  1976. ;; grep
  1977. ("grep"
  1978. t
  1979. ,(concat "find . "
  1980. "-path '*/.git' -prune -o "
  1981. "-path '*/.svn' -prune -o "
  1982. "-type f -print0 | "
  1983. "xargs -0 grep -nH -e "))
  1984. )
  1985. "Alist of rgrep command.
  1986. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1987. condition to choose COMMAND when evaluated.")
  1988. (defvar my-rgrep-default nil
  1989. "Default command name for my-rgrep.")
  1990. (defun my-rgrep-grep-command (&optional name alist)
  1991. "Return recursive grep command for current directory or nil.
  1992. If NAME is given, use that without testing.
  1993. Commands are searched from ALIST."
  1994. (if alist
  1995. (if name
  1996. ;; if name is given search that from alist and return the command
  1997. (nth 2 (assoc name
  1998. alist))
  1999. ;; if name is not given try test in 1th elem
  2000. (let ((car (car alist))
  2001. (cdr (cdr alist)))
  2002. (if (eval (nth 1 car))
  2003. ;; if the condition is true return the command
  2004. (nth 2 car)
  2005. ;; try next one
  2006. (and cdr
  2007. (my-rgrep-grep-command name cdr)))))
  2008. ;; if alist is not given set default value
  2009. (my-rgrep-grep-command name my-rgrep-alist)))
  2010. (my-rgrep-grep-command "ag" nil)
  2011. (defun my-rgrep (command-args)
  2012. "My recursive grep. Run COMMAND-ARGS."
  2013. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  2014. nil)))
  2015. (if cmd
  2016. (list (read-shell-command "grep command: "
  2017. cmd
  2018. 'grep-find-history))
  2019. (error "my-rgrep: Command for rgrep not found")
  2020. )))
  2021. (compilation-start command-args
  2022. 'grep-mode))
  2023. ;; (defun my-rgrep-symbol-at-point (command-args)
  2024. ;; "My recursive grep. Run COMMAND-ARGS."
  2025. ;; (interactive (list (read-shell-command "grep command: "
  2026. ;; (concat (my-rgrep-grep-command)
  2027. ;; " "
  2028. ;; (thing-at-point 'symbol))
  2029. ;; 'grep-find-history)))
  2030. ;; (compilation-start command-args
  2031. ;; 'grep-mode))
  2032. (defun my-rgrep-ack ()
  2033. "My recursive grep by ack."
  2034. (interactive)
  2035. (let ((my-rgrep-default "ack"))
  2036. (if (called-interactively-p 'any)
  2037. (call-interactively 'my-rgrep)
  2038. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2039. (defun my-rgrep-ag ()
  2040. "My recursive grep by ack."
  2041. (interactive)
  2042. (let ((my-rgrep-default "ag"))
  2043. (if (called-interactively-p 'any)
  2044. (call-interactively 'my-rgrep)
  2045. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2046. (defun my-rgrep-gitgrep ()
  2047. "My recursive grep by ack."
  2048. (interactive)
  2049. (let ((my-rgrep-default "gitgrep"))
  2050. (if (called-interactively-p 'any)
  2051. (call-interactively 'my-rgrep)
  2052. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2053. (defun my-rgrep-grep ()
  2054. "My recursive grep by ack."
  2055. (interactive)
  2056. (let ((my-rgrep-default "grep"))
  2057. (if (called-interactively-p 'any)
  2058. (call-interactively 'my-rgrep)
  2059. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2060. (defun my-rgrep-global ()
  2061. "My recursive grep by ack."
  2062. (interactive)
  2063. (let ((my-rgrep-default "global"))
  2064. (if (called-interactively-p 'any)
  2065. (call-interactively 'my-rgrep)
  2066. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  2067. (define-key ctl-x-map "s" 'my-rgrep)
  2068. ;; (defun make ()
  2069. ;; "Run \"make -k\" in current directory."
  2070. ;; (interactive)
  2071. ;; (compile "make -k"))
  2072. (defalias 'make 'compile)
  2073. (defvar sed-in-place-history nil
  2074. "History of `sed-in-place'.")
  2075. (defvar sed-in-place-command "sed --in-place=.bak -e")
  2076. (defun sed-in-place (command)
  2077. "Issue sed in place COMMAND."
  2078. (interactive (list (read-shell-command "sed in place: "
  2079. (concat sed-in-place-command " ")
  2080. 'sed-in-place-history)))
  2081. (shell-command command
  2082. "*sed in place*"))
  2083. (defun dired-do-sed-in-place (&optional arg)
  2084. "Issue sed in place dired. If ARG is given, use the next ARG files."
  2085. (interactive "p")
  2086. (require 'dired-aux)
  2087. (let* ((files (dired-get-marked-files t arg))
  2088. (expr (dired-mark-read-string "Run sed-in-place for %s: "
  2089. nil
  2090. 'sed-in-place
  2091. arg
  2092. files)))
  2093. (if (equal expr
  2094. "")
  2095. (error "No expression specified")
  2096. (shell-command (concat sed-in-place-command
  2097. " '"
  2098. expr
  2099. "' "
  2100. (mapconcat 'shell-quote-argument
  2101. files
  2102. " "))
  2103. "*sed in place*"))))
  2104. (defun dir-show (&optional dir)
  2105. "Show DIR list."
  2106. (interactive)
  2107. (let ((bf (get-buffer-create "*dir show*"))
  2108. (list-directory-brief-switches "-C"))
  2109. (with-current-buffer bf
  2110. (list-directory (or nil
  2111. default-directory)
  2112. nil))
  2113. ))
  2114. (defun my-convmv-sjis2utf8-test ()
  2115. "Run `convmv -r -f sjis -t utf8 *'.
  2116. this is test, does not rename files."
  2117. (interactive)
  2118. (shell-command "convmv -r -f sjis -t utf8 *"))
  2119. (defun my-convmv-sjis2utf8-notest ()
  2120. "Run `convmv -r -f sjis -t utf8 * --notest'."
  2121. (interactive)
  2122. (shell-command "convmv -r -f sjis -t utf8 * --notest"))
  2123. (defun kill-ring-save-buffer-file-name ()
  2124. "Get current filename."
  2125. (interactive)
  2126. (let ((file buffer-file-name))
  2127. (if file
  2128. (progn (kill-new file)
  2129. (message file))
  2130. (message "not visiting file."))))
  2131. (defvar kill-ring-buffer-name "*kill-ring*"
  2132. "Buffer name for `kill-ring-buffer'.")
  2133. (defun open-kill-ring-buffer ()
  2134. "Open kill- ring buffer."
  2135. (interactive)
  2136. (pop-to-buffer
  2137. (with-current-buffer (get-buffer-create kill-ring-buffer-name)
  2138. (erase-buffer)
  2139. (yank)
  2140. (text-mode)
  2141. (current-local-map)
  2142. (goto-char (point-min))
  2143. (yank)
  2144. (current-buffer))))
  2145. (defun set-terminal-header (string)
  2146. "Set terminal header STRING."
  2147. (let ((savepos "\033[s")
  2148. (restorepos "\033[u")
  2149. (movecursor "\033[0;%dH")
  2150. (inverse "\033[7m")
  2151. (restorecolor "\033[0m")
  2152. (cols (frame-parameter nil 'width))
  2153. (length (length string)))
  2154. ;; (redraw-frame (selected-frame))
  2155. (send-string-to-terminal (concat savepos
  2156. (format movecursor
  2157. (1+ (- cols length)))
  2158. inverse
  2159. string
  2160. restorecolor
  2161. restorepos))
  2162. ))
  2163. (defun my-set-terminal-header ()
  2164. "Set terminal header."
  2165. (set-terminal-header (concat " "
  2166. user-login-name
  2167. "@"
  2168. (car (split-string system-name
  2169. "\\."))
  2170. " "
  2171. (format-time-string "%Y/%m/%d %T %z")
  2172. " ")))
  2173. ;; (run-with-timer
  2174. ;; 0.1
  2175. ;; 1
  2176. ;; 'my-set-terminal-header)
  2177. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2178. ;; ;; savage emacs
  2179. ;; ;; when enabled emacs fails to complete
  2180. ;; ;; http://e-arrows.sakura.ne.jp/2010/05/emacs-should-be-more-savage.html
  2181. ;; (defadvice message (before message-for-stupid (arg &rest arg2) activate)
  2182. ;; (setq arg
  2183. ;; (concat arg
  2184. ;; (if (eq nil
  2185. ;; (string-match "\\. *$"
  2186. ;; arg))
  2187. ;; ".")
  2188. ;; " Stupid!")))
  2189. (defvar info-in-prompt
  2190. nil
  2191. "System info in the form of \"[user@host] \".")
  2192. (setq info-in-prompt
  2193. (concat "["
  2194. user-login-name
  2195. "@"
  2196. (car (split-string system-name
  2197. "\\."))
  2198. "]"))
  2199. (defun my-real-function-subr-p (function)
  2200. "Return t if FUNCTION is a built-in function even if it is advised."
  2201. (let* ((advised (and (symbolp function)
  2202. (featurep 'advice)
  2203. (ad-get-advice-info function)))
  2204. (real-function
  2205. (or (and advised (let ((origname (cdr (assq 'origname advised))))
  2206. (and (fboundp origname)
  2207. origname)))
  2208. function))
  2209. (def (if (symbolp real-function)
  2210. (symbol-function real-function)
  2211. function)))
  2212. (subrp def)))
  2213. ;; (my-real-function-subr-p 'my-real-function-subr-p)
  2214. ;; (defadvice read-from-minibuffer (before info-in-prompt activate)
  2215. ;; "Show system info when use `read-from-minibuffer'."
  2216. ;; (ad-set-arg 0
  2217. ;; (concat my-system-info
  2218. ;; (ad-get-arg 0))))
  2219. ;; (defadvice read-string (before info-in-prompt activate)
  2220. ;; "Show system info when use `read-string'."
  2221. ;; (ad-set-arg 0
  2222. ;; (concat my-system-info
  2223. ;; (ad-get-arg 0))))
  2224. ;; (when (< emacs-major-version 24)
  2225. ;; (defadvice completing-read (before info-in-prompt activate)
  2226. ;; "Show system info when use `completing-read'."
  2227. ;; (ad-set-arg 0
  2228. ;; (concat my-system-info
  2229. ;; (ad-get-arg 0)))))
  2230. (defmacro info-in-prompt-set (&rest functions)
  2231. "Set info-in-prompt advices for FUNCTIONS."
  2232. `(progn
  2233. ,@(mapcar (lambda (f)
  2234. `(defadvice ,f (before info-in-prompt activate)
  2235. "Show info in prompt."
  2236. (let ((orig (ad-get-arg 0)))
  2237. (unless (string-match-p (regexp-quote info-in-prompt)
  2238. orig)
  2239. (ad-set-arg 0
  2240. (concat info-in-prompt
  2241. " "
  2242. orig))))))
  2243. functions)))
  2244. (info-in-prompt-set read-from-minibuffer
  2245. read-string
  2246. completing-read)
  2247. ;;; emacs.el ends here