25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

emacs.el 73 KiB

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