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

emacs.el 74 KiB

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