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 70 KiB

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