Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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