25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

emacs.el 70 KiB

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