Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

11 роки тому
9 роки тому
13 роки тому
9 роки тому
12 роки тому
12 роки тому
13 роки тому
13 роки тому
9 роки тому
9 роки тому
11 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
11 роки тому
9 роки тому
9 роки тому
9 роки тому
9 роки тому
9 роки тому
9 роки тому
11 роки тому
9 роки тому
11 роки тому
11 роки тому
11 роки тому
13 роки тому
13 роки тому
12 роки тому
12 роки тому
13 роки тому
12 роки тому
13 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
13 роки тому
9 роки тому
13 роки тому
13 роки тому
13 роки тому
13 роки тому
13 роки тому
11 роки тому
12 роки тому
13 роки тому
9 роки тому
13 роки тому
12 роки тому
13 роки тому
11 роки тому
9 роки тому
9 роки тому
9 роки тому
12 роки тому
9 роки тому
13 роки тому
13 роки тому
11 роки тому
11 роки тому
9 роки тому
10 роки тому
9 роки тому
9 роки тому
12 роки тому
12 роки тому
13 роки тому
9 роки тому
13 роки тому
11 роки тому
11 роки тому
9 роки тому
13 роки тому
12 роки тому
11 роки тому
12 роки тому
12 роки тому
13 роки тому
12 роки тому
13 роки тому
13 роки тому
12 роки тому
9 роки тому
13 роки тому
13 роки тому
13 роки тому
13 роки тому
11 роки тому
12 роки тому
12 роки тому
11 роки тому
13 роки тому
13 роки тому
9 роки тому
13 роки тому
12 роки тому
13 роки тому
12 роки тому
12 роки тому
12 роки тому
13 роки тому
12 роки тому
12 роки тому
12 роки тому
13 роки тому
9 роки тому
9 роки тому
9 роки тому
13 роки тому
13 роки тому
9 роки тому
12 роки тому
9 роки тому
12 роки тому
11 роки тому
11 роки тому
9 роки тому
11 роки тому
13 роки тому
13 роки тому
9 роки тому
13 роки тому
13 роки тому
12 роки тому
13 роки тому
13 роки тому
13 роки тому
13 роки тому
13 роки тому
13 роки тому
13 роки тому
12 роки тому
9 роки тому
12 роки тому
12 роки тому
11 роки тому
12 роки тому
11 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
9 роки тому
11 роки тому
9 роки тому
11 роки тому
9 роки тому
12 роки тому
9 роки тому
12 роки тому
13 роки тому
13 роки тому
9 роки тому
12 роки тому
12 роки тому
12 роки тому
9 роки тому
9 роки тому
9 роки тому
13 роки тому
11 роки тому
13 роки тому
13 роки тому
12 роки тому
13 роки тому
12 роки тому
10 роки тому
9 роки тому
9 роки тому
10 роки тому
9 роки тому
13 роки тому
13 роки тому
9 роки тому
13 роки тому
10 роки тому
13 роки тому
10 роки тому
9 роки тому
10 роки тому
11 роки тому
13 роки тому
9 роки тому
11 роки тому
13 роки тому
13 роки тому
13 роки тому
13 роки тому
10 роки тому
10 роки тому
13 роки тому
11 роки тому
12 роки тому
12 роки тому
13 роки тому
13 роки тому
9 роки тому
13 роки тому
12 роки тому
12 роки тому
12 роки тому
9 роки тому
12 роки тому
12 роки тому
13 роки тому
9 роки тому
12 роки тому
10 роки тому
12 роки тому
12 роки тому
12 роки тому
12 роки тому
13 роки тому
13 роки тому
11 роки тому
13 роки тому
9 роки тому
9 роки тому
13 роки тому
9 роки тому
9 роки тому
13 роки тому
9 роки тому
13 роки тому
10 роки тому
10 роки тому
12 роки тому
11 роки тому
13 роки тому
13 роки тому
9 роки тому
12 роки тому
13 роки тому
9 роки тому
9 роки тому
12 роки тому
9 роки тому
12 роки тому
9 роки тому
12 роки тому
9 роки тому
9 роки тому
12 роки тому
12 роки тому
9 роки тому
9 роки тому
11 роки тому
11 роки тому
11 роки тому
12 роки тому
11 роки тому
11 роки тому
12 роки тому
9 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
10 роки тому
11 роки тому
11 роки тому
11 роки тому
10 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
10 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
11 роки тому
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852
  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Commentary:
  3. ;;; Code:
  4. ;; SETUP_LOAD: (let ((file "DOTFILES_DIR/emacs.el"))
  5. ;; SETUP_LOAD: (and (file-readable-p file)
  6. ;; SETUP_LOAD: (load-file file)))
  7. (setq debug-on-error t)
  8. ;; make directories
  9. (unless (file-directory-p (expand-file-name user-emacs-directory))
  10. (make-directory (expand-file-name user-emacs-directory)))
  11. (let ((d (expand-file-name (concat user-emacs-directory
  12. "lisp"))))
  13. (unless (file-directory-p d)
  14. (make-directory d))
  15. (add-to-list 'load-path d))
  16. (require 'cl-lib)
  17. (require 'simple)
  18. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  19. ;; Some macros for internals
  20. ;; `emacs --load emacs.el` with Emacs 24.3 requires with-eval-after-load to be
  21. ;; defined at the toplevel (means that it should not be defined inside of some
  22. ;; special forms like `when'. I do not now how to do with about this...)
  23. (unless (fboundp 'with-eval-after-load)
  24. ;; polyfill for Emacs < 24.4
  25. (defmacro with-eval-after-load (file &rest body)
  26. "After FILE is loaded execute BODY."
  27. (declare (indent 1) (debug t))
  28. `(eval-after-load ,file (quote (progn ,@body)))))
  29. (defun call-after-init (func)
  30. "If `after-init-hook' has been run, call FUNC immediately.
  31. Otherwize hook it."
  32. (if after-init-time
  33. (funcall func)
  34. (add-hook 'after-init-hook
  35. func)))
  36. (defmacro safe-require-or-eval (feature)
  37. "Require FEATURE if available.
  38. At compile time the feature will be loaded immediately."
  39. `(eval-and-compile
  40. (require ,feature nil t)))
  41. (defmacro autoload-eval-lazily (feature &optional functions &rest body)
  42. "Define autoloading FEATURE that defines FUNCTIONS.
  43. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  44. the function same as FEATURE is defined as autoloaded function. BODY is passed
  45. to `eval-after-load'.
  46. After this macro is expanded, this returns the path to library if FEATURE
  47. found, otherwise returns nil."
  48. (declare (indent 2) (debug t))
  49. (let* ((libname (symbol-name (eval feature)))
  50. (libpath (locate-library libname)))
  51. `(progn
  52. (when (locate-library ,libname)
  53. ,@(mapcar (lambda (f)
  54. `(unless (fboundp ',f)
  55. (progn
  56. (message "Autoloaded function `%S' defined (%s)"
  57. (quote ,f)
  58. ,libpath)
  59. (autoload (quote ,f)
  60. ,libname
  61. ,(concat "Autoloaded function defined in \""
  62. libpath
  63. "\".")
  64. t))))
  65. (or (eval functions)
  66. `(,(eval feature)))))
  67. (eval-after-load ,feature
  68. (quote (progn
  69. ,@body)))
  70. (locate-library ,libname))))
  71. (when (autoload-eval-lazily 'tetris nil
  72. (message "Tetris loaded!"))
  73. (message "Tetris found!"))
  74. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  75. ;; download library from web
  76. (defvar fetch-library-enabled-p t
  77. "Set nil to skip downloading with `fetch-library'.")
  78. (defun fetch-library (url &optional byte-compile-p force-download-p)
  79. "Download a library from URL and locate it in \"~/emacs.d/lisp/\".
  80. Return nil if library unfound and failed to download,
  81. otherwise the path where the library installed.
  82. If BYTE-COMPILE-P is t byte compile the file after downloading.
  83. If FORCE-DOWNLOAD-P it t ignore exisiting library and always download.
  84. This function also checks the value of `fetch-library-enabled-p' and do not
  85. fetch libraries if this value is nil. In this case all arguments (including
  86. FORCE-DOWNLOAD-P) will be ignored."
  87. (let* ((dir (expand-file-name (concat user-emacs-directory "lisp/")))
  88. (lib (file-name-sans-extension (file-name-nondirectory url)))
  89. (lpath (concat dir lib ".el"))
  90. (locate-p (locate-library lib)))
  91. (if (and fetch-library-enabled-p
  92. (or force-download-p
  93. (not locate-p)))
  94. (if (progn (message "Downloading %s..."
  95. url)
  96. (download-file url
  97. lpath
  98. t))
  99. (progn (message "Downloading %s...done"
  100. url)
  101. (when (and byte-compile-p
  102. (require 'bytecomp nil t))
  103. (and (file-exists-p (byte-compile-dest-file lpath))
  104. (delete-file (byte-compile-dest-file lpath)))
  105. (message "Byte-compiling %s..."
  106. lpath)
  107. (byte-compile-file lpath)
  108. (message "Byte-compiling %s...done"
  109. lpath)))
  110. (progn (and (file-writable-p lpath)
  111. (delete-file lpath))
  112. (message "Downloading %s...failed"
  113. url))))
  114. (locate-library lib)))
  115. ;; If EMACS_EL_DRY_RUN is set and it is not an empty string, fetch-library
  116. ;; does not actually fetch library.
  117. (let ((dryrun (getenv "EMACS_EL_DRY_RUN")))
  118. (when (and dryrun
  119. (< 0
  120. (length dryrun)))
  121. (setq fetch-library-enabled-p
  122. nil)
  123. (message "EMACS_EL_DRY_RUN is set. Skip fetching libraries.")))
  124. (defun download-file (url path &optional ok-if-already-exists)
  125. "Download file from URL and output to PATH.
  126. IF OK-IF-ALREADY-EXISTS is true force download."
  127. (let ((curl (executable-find "curl"))
  128. (wget (executable-find "wget")))
  129. (cond (wget
  130. (if (and (not ok-if-already-exists)
  131. (file-exists-p path))
  132. nil
  133. (and (eq 0
  134. (call-process wget
  135. nil
  136. nil
  137. nil
  138. "-O"
  139. path
  140. url
  141. ))
  142. path)))
  143. (curl
  144. (if (and (not ok-if-already-exists)
  145. (file-exists-p path))
  146. nil
  147. (and (eq 0
  148. (call-process curl
  149. nil
  150. nil
  151. nil
  152. "--output"
  153. path
  154. "-L"
  155. url
  156. ))
  157. path)))
  158. (t
  159. (ignore-errors
  160. (require 'url)
  161. (url-copy-file url
  162. path
  163. ok-if-already-exists)
  164. path)))))
  165. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  166. ;; package
  167. (set (defvar 10sr-package-list)
  168. '(
  169. markdown-mode
  170. yaml-mode
  171. gnuplot-mode
  172. php-mode
  173. erlang
  174. js2-mode
  175. git-commit
  176. gitignore-mode
  177. adoc-mode
  178. ;; ack
  179. color-moccur
  180. ggtags
  181. flycheck
  182. ;; is flymake installs are required?
  183. ;;flymake-jshint
  184. ;;flymake-python-pyflakes
  185. xclip
  186. foreign-regexp
  187. multi-term
  188. term-run
  189. editorconfig
  190. git-ps1-mode
  191. restart-emacs
  192. fill-column-indicator
  193. pkgbuild-mode
  194. minibuffer-line
  195. scala-mode2
  196. ensime
  197. editorconfig
  198. git-command
  199. prompt-text
  200. ;; 10sr repository
  201. ;; 10sr-extras
  202. terminal-title
  203. recentf-show
  204. dired-list-all-mode
  205. pack
  206. set-modeline-color
  207. read-only-only-mode
  208. smart-revert
  209. autosave
  210. ;;window-organizer
  211. remember-major-modes-mode
  212. ilookup
  213. pasteboard
  214. ))
  215. (when (safe-require-or-eval 'package)
  216. (setq package-archives
  217. `(,@package-archives
  218. ("melpa" . "https://melpa.org/packages/")
  219. ("10sr-el" . "https://10sr.github.io/emacs-lisp/p/")))
  220. (package-initialize)
  221. (defun my-auto-install-package ()
  222. "Install packages semi-automatically."
  223. (interactive)
  224. (package-refresh-contents)
  225. (mapc (lambda (pkg)
  226. (or (package-installed-p pkg)
  227. (locate-library (symbol-name pkg))
  228. (package-install pkg)))
  229. 10sr-package-list))
  230. )
  231. ;; (lazy-load-eval 'sudoku)
  232. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  233. ;; my-idle-hook
  234. (defvar my-idle-hook nil
  235. "Hook run when idle for several secs.")
  236. (defvar my-idle-hook-sec 5
  237. "Second to run `my-idle-hook'.")
  238. (run-with-idle-timer my-idle-hook-sec
  239. t
  240. (lambda ()
  241. (run-hooks 'my-idle-hook)))
  242. ;; (add-hook 'my-idle-hook
  243. ;; (lambda ()
  244. ;; (message "idle hook message")))
  245. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  246. ;; start and quit
  247. (setq inhibit-startup-message t)
  248. (setq confirm-kill-emacs 'y-or-n-p)
  249. (setq gc-cons-threshold (* 1024 1024 4))
  250. (when window-system
  251. (add-to-list 'default-frame-alist '(cursor-type . box))
  252. (add-to-list 'default-frame-alist '(background-color . "white"))
  253. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  254. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  255. ;; does not work?
  256. )
  257. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  258. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  259. (and (fboundp 'tool-bar-mode)
  260. (tool-bar-mode 0))
  261. (and (fboundp 'set-scroll-bar-mode)
  262. (set-scroll-bar-mode nil))
  263. (add-hook 'kill-emacs-hook
  264. ;; load init file when terminating emacs to ensure file is not broken
  265. 'reload-init-file)
  266. (defun my-force-kill-emacs ()
  267. "My force kill Emacs."
  268. (interactive)
  269. (let ((kill-emacs-hook nil))
  270. (kill-emacs)))
  271. (call-after-init
  272. (lambda ()
  273. (message "%s %s" invocation-name emacs-version)
  274. (message "%s was taken to initialize emacs." (emacs-init-time))
  275. (switch-to-buffer "*Messages*")))
  276. (cd ".") ; when using windows use / instead of \ in `default-directory'
  277. ;; locale
  278. (set-language-environment "Japanese")
  279. (set-default-coding-systems 'utf-8-unix)
  280. (prefer-coding-system 'utf-8-unix)
  281. (setq system-time-locale "C")
  282. ;; my prefix map
  283. (defvar my-prefix-map nil
  284. "My prefix map.")
  285. (define-prefix-command 'my-prefix-map)
  286. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  287. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  288. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  289. ;; (comint-show-maximum-output)
  290. ;; kill scratch
  291. (call-after-init (lambda ()
  292. (let ((buf (get-buffer "*scratch*")))
  293. (when buf
  294. (kill-buffer buf)))))
  295. ;; modifier keys
  296. ;; (setq mac-option-modifier 'control)
  297. ;; display
  298. (setq visible-bell t)
  299. (setq ring-bell-function 'ignore)
  300. (mouse-avoidance-mode 'banish)
  301. (setq echo-keystrokes 0.1)
  302. (defun reload-init-file ()
  303. "Reload Emacs init file."
  304. (interactive)
  305. (when (and user-init-file
  306. (file-readable-p user-init-file))
  307. (load-file user-init-file)))
  308. (safe-require-or-eval 'session)
  309. ;; server
  310. (when (safe-require-or-eval 'server)
  311. (setq server-name (concat "server"
  312. (number-to-string (emacs-pid))))
  313. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  314. ;; In Darwin environment, init fails with message like 'Service name too long'
  315. ;; when server-use-tcp is nil
  316. (when (or (eq system-type
  317. 'cygwin)
  318. (eq system-type
  319. 'darwin))
  320. (setq server-use-tcp t))
  321. (server-start))
  322. ;; MSYS2 fix
  323. (when (eq system-type
  324. 'windows-nt)
  325. (setq shell-file-name
  326. (executable-find "bash"))
  327. '(setq function-key-map
  328. `(,@function-key-map ([pause] . [?\C-c])
  329. ))
  330. (define-key key-translation-map
  331. (kbd "<pause>")
  332. (kbd "C-c"))
  333. '(keyboard-translate [pause]
  334. (kbd "C-c")p)
  335. ;; TODO: move to other place later
  336. (when (not window-system)
  337. (setq interprogram-paste-function nil)
  338. (setq interprogram-cut-function nil)))
  339. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  340. ;; global keys
  341. (global-set-key (kbd "<up>") 'scroll-down-line)
  342. (global-set-key (kbd "<down>") 'scroll-up-line)
  343. (global-set-key (kbd "<left>") 'scroll-down)
  344. (global-set-key (kbd "<right>") 'scroll-up)
  345. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  346. (global-set-key (kbd "C-\\") help-map)
  347. (define-key ctl-x-map (kbd "DEL") help-map)
  348. (define-key ctl-x-map (kbd "C-h") help-map)
  349. (define-key help-map "a" 'apropos)
  350. ;; disable annoying keys
  351. (global-set-key [prior] 'ignore)
  352. (global-set-key (kbd "<next>") 'ignore)
  353. (global-set-key [menu] 'ignore)
  354. (global-set-key [down-mouse-1] 'ignore)
  355. (global-set-key [down-mouse-2] 'ignore)
  356. (global-set-key [down-mouse-3] 'ignore)
  357. (global-set-key [mouse-1] 'ignore)
  358. (global-set-key [mouse-2] 'ignore)
  359. (global-set-key [mouse-3] 'ignore)
  360. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  361. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  362. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  363. ;; editting
  364. (defun my-copy-whole-line ()
  365. "Copy whole line."
  366. (interactive)
  367. (kill-new (concat (buffer-substring (point-at-bol)
  368. (point-at-eol))
  369. "\n")))
  370. (setq require-final-newline t)
  371. (setq kill-whole-line t)
  372. (setq scroll-conservatively 35
  373. scroll-margin 2
  374. scroll-step 0)
  375. (setq-default major-mode 'text-mode)
  376. (setq next-line-add-newlines nil)
  377. (setq kill-read-only-ok t)
  378. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  379. ;; (setq-default line-spacing 0.2)
  380. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  381. (setq-default tab-width 4)
  382. (setq-default indent-tabs-mode nil)
  383. (setq-default indent-line-function nil)
  384. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  385. (delete-selection-mode 1)
  386. (cua-mode 0)
  387. (setq line-move-visual nil)
  388. ;; key bindings
  389. ;; moving around
  390. ;; (global-set-key (kbd "M-j") 'next-line)
  391. ;; (global-set-key (kbd "M-k") 'previous-line)
  392. ;; (global-set-key (kbd "M-h") 'backward-char)
  393. ;; (global-set-key (kbd "M-l") 'forward-char)
  394. ;;(keyboard-translate ?\M-j ?\C-j)
  395. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  396. (define-key esc-map "p" 'backward-paragraph)
  397. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  398. (define-key esc-map "n" 'forward-paragraph)
  399. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  400. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  401. (global-set-key (kbd "C-<left>") 'scroll-down)
  402. (global-set-key (kbd "C-<right>") 'scroll-up)
  403. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  404. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  405. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  406. ;; C-h and DEL
  407. (global-set-key (kbd "C-h") (kbd "DEL"))
  408. (global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  409. (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  410. (define-key esc-map "k" 'my-copy-whole-line)
  411. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  412. (define-key esc-map "u" 'undo)
  413. (define-key esc-map "i" (kbd "ESC TAB"))
  414. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  415. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  416. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  417. (define-key my-prefix-map (kbd "C-o") 'occur)
  418. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  419. ;; title and mode-line
  420. (when (safe-require-or-eval 'terminal-title)
  421. ;; if TERM is not screen use default value
  422. (if (getenv "TMUX")
  423. ;; if use tmux locally just basename of current dir
  424. (set-variable 'terminal-title-format
  425. '((file-name-nondirectory (directory-file-name
  426. default-directory))))
  427. (if (and (let ((tty-type (frame-parameter nil
  428. 'tty-type)))
  429. (and tty-type
  430. (equal (car (split-string tty-type
  431. "-"))
  432. "screen")))
  433. (not (getenv "SSH_CONNECTION")))
  434. (set-variable 'terminal-title-format
  435. '((file-name-nondirectory (directory-file-name
  436. default-directory))))
  437. ;; seems that TMUX is used locally and ssh to remote host
  438. (set-variable 'terminal-title-format
  439. `("em:"
  440. ,user-login-name
  441. "@"
  442. ,(car (split-string system-name
  443. "\\."))
  444. ":"
  445. default-directory))
  446. )
  447. )
  448. (terminal-title-mode))
  449. (setq eol-mnemonic-dos "\\r\\n")
  450. (setq eol-mnemonic-mac "\\r")
  451. (setq eol-mnemonic-unix "\\n")
  452. (which-function-mode 0)
  453. (line-number-mode 0)
  454. (column-number-mode 0)
  455. (size-indication-mode 0)
  456. (setq mode-line-position
  457. '(:eval (format "L%%l/%d,C%%c"
  458. (count-lines (point-max)
  459. (point-min)))))
  460. (when (safe-require-or-eval 'git-ps1-mode)
  461. (git-ps1-mode))
  462. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  463. ;; display date
  464. (when (safe-require-or-eval 'time)
  465. (setq display-time-interval 29)
  466. (setq display-time-day-and-date t)
  467. (setq display-time-format "%Y/%m/%d %a %H:%M")
  468. ;; (if window-system
  469. ;; (display-time-mode 0)
  470. ;; (display-time-mode 1))
  471. (when display-time-mode
  472. (display-time-update)))
  473. ;; ;; current directory
  474. ;; (let ((ls (member 'mode-line-buffer-identification
  475. ;; mode-line-format)))
  476. ;; (setcdr ls
  477. ;; (cons '(:eval (concat " ("
  478. ;; (abbreviate-file-name default-directory)
  479. ;; ")"))
  480. ;; (cdr ls))))
  481. ;; ;; display last modified time
  482. ;; (let ((ls (member 'mode-line-buffer-identification
  483. ;; mode-line-format)))
  484. ;; (setcdr ls
  485. ;; (cons '(:eval (concat " "
  486. ;; my-buffer-file-last-modified-time))
  487. ;; (cdr ls))))
  488. (defun buffer-list-not-start-with-space ()
  489. "Return a list of buffers that not start with whitespaces."
  490. (let ((bl (buffer-list))
  491. b nbl)
  492. (while bl
  493. (setq b (pop bl))
  494. (unless (string-equal " "
  495. (substring (buffer-name b)
  496. 0
  497. 1))
  498. (add-to-list 'nbl b)))
  499. nbl))
  500. ;; http://www.masteringemacs.org/articles/2012/09/10/hiding-replacing-modeline-strings/
  501. ;; (add-to-list 'minor-mode-alist
  502. ;; '(global-whitespace-mode ""))
  503. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  504. ;; minibuffer
  505. (setq insert-default-directory t)
  506. (setq completion-ignore-case t
  507. read-file-name-completion-ignore-case t
  508. read-buffer-completion-ignore-case t)
  509. (setq resize-mini-windows t)
  510. (temp-buffer-resize-mode 1)
  511. (savehist-mode 1)
  512. (fset 'yes-or-no-p 'y-or-n-p)
  513. ;; complete symbol when `eval'
  514. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  515. (define-key minibuffer-local-map (kbd "C-u")
  516. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  517. ;; I dont know these bindings are good
  518. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  519. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  520. (when (safe-require-or-eval 'minibuffer-line)
  521. (set-face-underline 'minibuffer-line nil)
  522. (set-variable 'minibuffer-line-refresh-interval
  523. 25)
  524. (set-variable 'minibuffer-line-format
  525. `(,(concat user-login-name
  526. "@"
  527. (car (split-string system-name
  528. "\\."))
  529. ":")
  530. (:eval (abbreviate-file-name (or buffer-file-name
  531. default-directory)))
  532. (:eval (and (fboundp 'git-ps1-mode-get-current)
  533. (git-ps1-mode-get-current " [GIT:%s]")))
  534. " "
  535. (:eval (format-time-string display-time-format))))
  536. (minibuffer-line-mode 1)
  537. )
  538. (when (safe-require-or-eval 'prompt-text)
  539. (set-variable 'prompt-text-format
  540. `(,(concat ""
  541. user-login-name
  542. "@"
  543. (car (split-string system-name
  544. "\\."))
  545. ":")
  546. (:eval (abbreviate-file-name (or buffer-file-name
  547. default-directory)))
  548. (:eval (and (fboundp 'git-ps1-mode-get-current)
  549. (git-ps1-mode-get-current " [GIT:%s]")))
  550. " "
  551. (:eval (format-time-string display-time-format))
  552. "\n"
  553. (:eval (symbol-name this-command))
  554. ": "))
  555. (prompt-text-mode 1))
  556. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  557. ;; letters, font-lock mode and fonts
  558. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  559. ;; (set-window-margins (selected-window) 1 1)
  560. (and (or (eq system-type 'Darwin)
  561. (eq system-type 'darwin))
  562. (fboundp 'mac-set-input-method-parameter)
  563. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  564. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  565. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  566. (boundp 'input-method-inactivate-hook))
  567. (add-hook 'input-method-activate-hook
  568. (lambda () (set-cursor-color "red")))
  569. (add-hook 'input-method-inactivate-hook
  570. (lambda () (set-cursor-color "black"))))
  571. (when (safe-require-or-eval 'paren)
  572. (show-paren-mode 1)
  573. (setq show-paren-delay 0.5
  574. show-paren-style 'parenthesis) ; mixed is hard to read
  575. ;; (set-face-background 'show-paren-match
  576. ;; "black")
  577. ;; ;; (face-foreground 'default))
  578. ;; (set-face-foreground 'show-paren-match
  579. ;; "white")
  580. ;; (set-face-inverse-video-p 'show-paren-match
  581. ;; t)
  582. )
  583. (transient-mark-mode 1)
  584. (global-font-lock-mode 1)
  585. (setq font-lock-global-modes
  586. '(not
  587. help-mode
  588. eshell-mode
  589. ;;term-mode
  590. Man-mode))
  591. ;; (standard-display-ascii ?\n "$\n")
  592. ;; (defvar my-eol-face
  593. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  594. ;; )
  595. ;; (defvar my-tab-face
  596. ;; '(("\t" . '(0 highlight t nil))))
  597. (defvar my-jspace-face
  598. '(("\u3000" . '(0 highlight t nil))))
  599. (add-hook 'font-lock-mode-hook
  600. (lambda ()
  601. ;; (font-lock-add-keywords nil my-eol-face)
  602. (font-lock-add-keywords nil my-jspace-face)
  603. ))
  604. (when (safe-require-or-eval 'whitespace)
  605. (add-to-list 'whitespace-display-mappings ; not work
  606. `(tab-mark ?\t ,(vconcat "^I\t")))
  607. (add-to-list 'whitespace-display-mappings
  608. `(newline-mark ?\n ,(vconcat "$\n")))
  609. (setq whitespace-style '(face
  610. trailing ; trailing blanks
  611. newline ; newlines
  612. newline-mark ; use display table for newline
  613. tab-mark
  614. empty ; empty lines at beg or end of buffer
  615. lines-tail ; lines over 80
  616. ))
  617. ;; (setq whitespace-newline 'font-lock-comment-face)
  618. (global-whitespace-mode t)
  619. (if (eq (display-color-cells)
  620. 256)
  621. (set-face-foreground 'whitespace-newline "color-109")
  622. ;; (progn
  623. ;; (set-face-bold-p 'whitespace-newline
  624. ;; t))
  625. ))
  626. (and nil
  627. (safe-require-or-eval 'fill-column-indicator)
  628. (setq fill-column-indicator))
  629. ;; highlight current line
  630. ;; http://wiki.riywo.com/index.php?Meadow
  631. (face-spec-set 'hl-line
  632. '((((min-colors 256)
  633. (background dark))
  634. (:background "color-234"))
  635. (((min-colors 256)
  636. (background light))
  637. (:background "color-234"))
  638. (t
  639. (:underline "black"))))
  640. (set-variable 'hl-line-global-modes
  641. '(not
  642. term-mode))
  643. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  644. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  645. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  646. ;;(safe-require-or-eval 'set-modeline-color)
  647. ;; (let ((fg (face-foreground 'default))
  648. ;; (bg (face-background 'default)))
  649. ;; (set-face-background 'mode-line-inactive
  650. ;; (if (face-inverse-video-p 'mode-line) fg bg))
  651. ;; (set-face-foreground 'mode-line-inactive
  652. ;; (if (face-inverse-video-p 'mode-line) bg fg)))
  653. ;; (set-face-underline 'mode-line-inactive
  654. ;; t)
  655. ;; (set-face-underline 'vertical-border
  656. ;; nil)
  657. ;; Not found in MELPA nor any other package repositories
  658. (and (fetch-library
  659. "https://raw.github.com/tarao/elisp/master/end-mark.el"
  660. t)
  661. (safe-require-or-eval 'end-mark)
  662. (global-end-mark-mode))
  663. (when (safe-require-or-eval 'cyberpunk-theme)
  664. (load-theme 'cyberpunk t)
  665. (set-face-attribute 'button
  666. nil
  667. :inherit 'highlight))
  668. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  669. ;; file handling
  670. (when (safe-require-or-eval 'editorconfig)
  671. ;; (set-variable 'editorconfig-get-properties-function
  672. ;; 'editorconfig-core-get-properties-hash)
  673. (editorconfig-mode 1))
  674. (setq revert-without-query '(".+"))
  675. ;; save cursor position
  676. (when (safe-require-or-eval 'saveplace)
  677. (setq-default save-place t)
  678. (setq save-place-file (concat user-emacs-directory
  679. "places")))
  680. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  681. (setq make-backup-files t)
  682. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  683. (setq backup-directory-alist
  684. (cons (cons "\\.*$" (expand-file-name (concat user-emacs-directory
  685. "backup")))
  686. backup-directory-alist))
  687. (setq version-control 'never)
  688. (setq delete-old-versions t)
  689. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  690. "auto-save/")))
  691. (setq delete-auto-save-files t)
  692. (add-to-list 'completion-ignored-extensions ".bak")
  693. ;; (setq delete-by-moving-to-trash t
  694. ;; trash-directory "~/.emacs.d/trash")
  695. (add-hook 'after-save-hook
  696. 'executable-make-buffer-file-executable-if-script-p)
  697. (set (defvar bookmark-default-file)
  698. (expand-file-name (concat user-emacs-directory
  699. "bmk")))
  700. (with-eval-after-load 'recentf
  701. (defvar recentf-exclude nil)
  702. (add-to-list 'recentf-exclude
  703. (regexp-quote bookmark-default-file)))
  704. (when (safe-require-or-eval 'smart-revert)
  705. (smart-revert-on))
  706. ;; autosave
  707. (when (safe-require-or-eval 'autosave)
  708. (autosave-set 2))
  709. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  710. ;; buffer killing
  711. ;; (defun my-delete-window-killing-buffer () nil)
  712. (defun my-query-kill-current-buffer ()
  713. "Interactively kill current buffer."
  714. (interactive)
  715. (if (y-or-n-p (concat "kill current buffer? :"))
  716. (kill-buffer (current-buffer))))
  717. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  718. (substitute-key-definition 'kill-buffer
  719. 'my-query-kill-current-buffer
  720. global-map)
  721. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  722. ;; share clipboard with x
  723. ;; this page describes this in details, but only these sexps seem to be needed
  724. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  725. (and (not window-system)
  726. (not (eq window-system 'mac))
  727. (getenv "DISPLAY")
  728. (not (equal (getenv "DISPLAY") ""))
  729. (executable-find "xclip")
  730. ;; (< emacs-major-version 24)
  731. (safe-require-or-eval 'xclip)
  732. nil
  733. (turn-on-xclip))
  734. (and (eq system-type 'darwin)
  735. (safe-require-or-eval 'pasteboard)
  736. (turn-on-pasteboard)
  737. (getenv "TMUX")
  738. (pasteboard-enable-rtun))
  739. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  740. ;; some modes and hooks
  741. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  742. (global-company-mode)
  743. (set-variable 'company-idle-delay 0.5)
  744. (set-variable 'company-minimum-prefix-length 2)
  745. (set-variable 'company-selection-wrap-around t)
  746. ;; https://github.com/lunaryorn/flycheck
  747. (when (safe-require-or-eval 'flycheck)
  748. (call-after-init 'global-flycheck-mode))
  749. (set-variable 'ac-ignore-case nil)
  750. (when (autoload-eval-lazily 'term-run '(term-run-shell-command term-run))
  751. (define-key ctl-x-map "t" 'term-run-shell-command))
  752. (add-to-list 'safe-local-variable-values
  753. '(encoding utf-8))
  754. (setq enable-local-variables :safe)
  755. (when (safe-require-or-eval 'remember-major-modes-mode)
  756. (remember-major-modes-mode 1))
  757. ;; Detect file type from shebang and set major-mode.
  758. (add-to-list 'interpreter-mode-alist
  759. '("python3" . python-mode))
  760. (add-to-list 'interpreter-mode-alist
  761. '("python2" . python-mode))
  762. ;; http://fukuyama.co/foreign-regexp
  763. '(and (safe-require-or-eval 'foreign-regexp)
  764. (progn
  765. (setq foreign-regexp/regexp-type 'perl)
  766. '(setq reb-re-syntax 'foreign-regexp)
  767. ))
  768. (autoload-eval-lazily 'sql '(sql-mode)
  769. (safe-require-or-eval 'sql-indent))
  770. (when (autoload-eval-lazily 'git-command)
  771. (define-key ctl-x-map "g" 'git-command))
  772. (when (safe-require-or-eval 'git-commit)
  773. (global-git-commit-mode 1))
  774. (when (fetch-library
  775. "http://www.emacswiki.org/emacs/download/sl.el"
  776. t)
  777. (autoload-eval-lazily 'sl))
  778. (with-eval-after-load 'make-mode
  779. (defvar makefile-mode-map (make-sparse-keymap))
  780. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  781. ;; this functions is set in write-file-functions, i cannot find any
  782. ;; good way to remove this.
  783. (fset 'makefile-warn-suspicious-lines 'ignore))
  784. (with-eval-after-load 'verilog-mode
  785. (defvar verilog-mode-map (make-sparse-keymap))
  786. (define-key verilog-mode-map ";" 'self-insert-command))
  787. (setq diff-switches "-u")
  788. (with-eval-after-load 'diff-mode
  789. ;; (when (and (eq major-mode
  790. ;; 'diff-mode)
  791. ;; (not buffer-file-name))
  792. ;; ;; do not pass when major-mode is derived mode of diff-mode
  793. ;; (view-mode 1))
  794. (set-face-attribute 'diff-header nil
  795. :foreground nil
  796. :background nil
  797. :weight 'bold)
  798. (set-face-attribute 'diff-file-header nil
  799. :foreground nil
  800. :background nil
  801. :weight 'bold)
  802. (set-face-foreground 'diff-index-face "blue")
  803. (set-face-attribute 'diff-hunk-header nil
  804. :foreground "cyan"
  805. :weight 'normal)
  806. (set-face-attribute 'diff-context nil
  807. ;; :foreground "white"
  808. :foreground nil
  809. :weight 'normal)
  810. (set-face-foreground 'diff-removed-face "red")
  811. (set-face-foreground 'diff-added-face "green")
  812. (set-face-background 'diff-removed-face nil)
  813. (set-face-background 'diff-added-face nil)
  814. (set-face-attribute 'diff-changed nil
  815. :foreground "magenta"
  816. :weight 'normal)
  817. (set-face-attribute 'diff-refine-change nil
  818. :foreground nil
  819. :background nil
  820. :weight 'bold
  821. :inverse-video t)
  822. ;; Annoying !
  823. ;;(diff-auto-refine-mode)
  824. )
  825. ;; (ffap-bindings)
  826. (set-variable 'sh-here-document-word "__EOC__")
  827. (when (autoload-eval-lazily 'adoc-mode
  828. nil
  829. (defvar adoc-mode-map (make-sparse-keymap))
  830. (define-key adoc-mode-map (kbd "C-m") 'newline))
  831. (setq auto-mode-alist
  832. `(("\\.adoc\\'" . adoc-mode)
  833. ("\\.asciidoc\\'" . adoc-mode)
  834. ,@auto-mode-alist)))
  835. (with-eval-after-load 'markup-faces
  836. ;; Is this too match ?
  837. (set-face-foreground 'markup-meta-face
  838. "color-245")
  839. (set-face-foreground 'markup-meta-hide-face
  840. "color-245")
  841. )
  842. (setq auto-mode-alist
  843. `(("autostart\\'" . sh-mode)
  844. ("xinitrc\\'" . sh-mode)
  845. ("xprograms\\'" . sh-mode)
  846. ("PKGBUILD\\'" . sh-mode)
  847. ,@auto-mode-alist))
  848. ;; TODO: check if this is required
  849. (and (autoload-eval-lazily 'groovy-mode)
  850. (add-to-list 'auto-mode-alist
  851. '("build\\.gradle\\'" . groovy-mode)))
  852. (with-eval-after-load 'yaml-mode
  853. (defvar yaml-mode-map (make-sparse-keymap))
  854. (define-key yaml-mode-map (kbd "C-m") 'newline))
  855. (with-eval-after-load 'html-mode
  856. (defvar html-mode-map (make-sparse-keymap))
  857. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  858. (with-eval-after-load 'text-mode
  859. (define-key text-mode-map (kbd "C-m") 'newline))
  860. (add-to-list 'Info-default-directory-list
  861. (expand-file-name "~/.info/emacs-ja"))
  862. (with-eval-after-load 'apropos
  863. (defvar apropos-mode-map (make-sparse-keymap))
  864. (define-key apropos-mode-map "n" 'next-line)
  865. (define-key apropos-mode-map "p" 'previous-line))
  866. (with-eval-after-load 'isearch
  867. ;; (define-key isearch-mode-map
  868. ;; (kbd "C-j") 'isearch-other-control-char)
  869. ;; (define-key isearch-mode-map
  870. ;; (kbd "C-k") 'isearch-other-control-char)
  871. ;; (define-key isearch-mode-map
  872. ;; (kbd "C-h") 'isearch-other-control-char)
  873. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  874. (define-key isearch-mode-map (kbd "M-r")
  875. 'isearch-query-replace-regexp))
  876. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  877. (setq lazy-highlight-cleanup nil)
  878. ;; face for isearch highlighing
  879. (set-face-attribute 'lazy-highlight
  880. nil
  881. :foreground `unspecified
  882. :background `unspecified
  883. :underline t
  884. ;; :weight `bold
  885. )
  886. (add-hook 'outline-mode-hook
  887. (lambda ()
  888. (when (string-match "\\.md\\'" buffer-file-name)
  889. (set (make-local-variable 'outline-regexp) "#+ "))))
  890. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  891. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  892. (when (autoload-eval-lazily 'markdown-mode
  893. '(markdown-mode gfm-mode)
  894. (defvar gfm-mode-map (make-sparse-keymap))
  895. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline))
  896. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  897. (set-variable 'markdown-command (or (executable-find "markdown")
  898. (executable-find "markdown.pl")
  899. ""))
  900. (add-hook 'markdown-mode-hook
  901. (lambda ()
  902. (outline-minor-mode 1)
  903. (flyspell-mode)
  904. (set (make-local-variable 'comment-start) ";")))
  905. )
  906. ;; c-mode
  907. ;; http://www.emacswiki.org/emacs/IndentingC
  908. ;; http://en.wikipedia.org/wiki/Indent_style
  909. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  910. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  911. (with-eval-after-load 'cc-vars
  912. (defvar c-default-style nil)
  913. (add-to-list 'c-default-style
  914. '(c-mode . "k&r"))
  915. (add-to-list 'c-default-style
  916. '(c++-mode . "k&r"))
  917. (add-hook 'c-mode-common-hook
  918. (lambda ()
  919. ;; why c-basic-offset in k&r style defaults to 5 ???
  920. (set-variable 'c-basic-offset 4)
  921. (set-variable 'indent-tabs-mode nil)
  922. ;; (set-face-foreground 'font-lock-keyword-face "blue")
  923. (c-toggle-hungry-state -1)
  924. ;; (and (require 'gtags nil t)
  925. ;; (gtags-mode 1))
  926. )))
  927. (when (autoload-eval-lazily 'php-mode)
  928. (add-hook 'php-mode-hook
  929. (lambda ()
  930. (set-variable 'c-basic-offset 2))))
  931. (autoload-eval-lazily 'js2-mode nil
  932. ;; currently do not use js2-mode
  933. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  934. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  935. (defvar js2-mode-map (make-sparse-keymap))
  936. (define-key js2-mode-map (kbd "C-m") (lambda ()
  937. (interactive)
  938. (js2-enter-key)
  939. (indent-for-tab-command)))
  940. ;; (add-hook (kill-local-variable 'before-save-hook)
  941. ;; 'js2-before-save)
  942. ;; (add-hook 'before-save-hook
  943. ;; 'my-indent-buffer
  944. ;; nil
  945. ;; t)
  946. )
  947. (with-eval-after-load 'js
  948. (set-variable 'js-indent-level 2))
  949. (add-to-list 'interpreter-mode-alist
  950. '("node" . js-mode))
  951. (when (autoload-eval-lazily 'flymake-jslint
  952. '(flymake-jslint-load))
  953. (autoload-eval-lazily 'js nil
  954. (add-hook 'js-mode-hook
  955. 'flymake-jslint-load)))
  956. (safe-require-or-eval 'js-doc)
  957. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  958. (when (safe-require-or-eval 'uniquify)
  959. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  960. (setq uniquify-ignore-buffers-re "*[^*]+*")
  961. (setq uniquify-min-dir-content 1))
  962. (with-eval-after-load 'view
  963. (defvar view-mode-map (make-sparse-keymap))
  964. (define-key view-mode-map "j" 'scroll-up-line)
  965. (define-key view-mode-map "k" 'scroll-down-line)
  966. (define-key view-mode-map "v" 'toggle-read-only)
  967. (define-key view-mode-map "q" 'bury-buffer)
  968. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  969. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  970. ;; (define-key view-mode-map
  971. ;; "n" 'nonincremental-repeat-search-forward)
  972. ;; (define-key view-mode-map
  973. ;; "N" 'nonincremental-repeat-search-backward)
  974. (define-key view-mode-map "/" 'isearch-forward-regexp)
  975. (define-key view-mode-map "?" 'isearch-backward-regexp)
  976. (define-key view-mode-map "n" 'isearch-repeat-forward)
  977. (define-key view-mode-map "N" 'isearch-repeat-backward)
  978. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  979. (global-set-key "\M-r" 'view-mode)
  980. ;; (setq view-read-only t)
  981. (add-hook 'Man-mode-hook
  982. (lambda ()
  983. (view-mode 1)
  984. (setq truncate-lines nil)))
  985. (set-variable 'Man-notify-method (if window-system
  986. 'newframe
  987. 'aggressive))
  988. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  989. "woman_cache.el")))
  990. (defalias 'man 'woman)
  991. (add-to-list 'auto-mode-alist
  992. '("tox\\.ini\\'" . conf-unix-mode))
  993. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  994. ;; python
  995. (when (autoload-eval-lazily 'python '(python-mode)
  996. (defvar python-mode-map (make-sparse-keymap))
  997. (define-key python-mode-map (kbd "C-c C-e") 'my-python-run-as-command)
  998. (define-key python-mode-map (kbd "C-c C-b") 'my-python-display-python-buffer)
  999. (define-key python-mode-map (kbd "C-m") 'newline-and-indent)
  1000. (defvar inferior-python-mode-map (make-sparse-keymap))
  1001. (define-key inferior-python-mode-map (kbd "<up>") 'comint-previous-input)
  1002. (define-key inferior-python-mode-map (kbd "<down>") 'comint-next-input)
  1003. )
  1004. (set-variable 'python-python-command (or (executable-find "python3")
  1005. (executable-find "python")))
  1006. ;; (defun my-python-run-as-command ()
  1007. ;; ""
  1008. ;; (interactive)
  1009. ;; (shell-command (concat python-python-command " " buffer-file-name)))
  1010. (defun my-python-display-python-buffer ()
  1011. ""
  1012. (interactive)
  1013. (defvar python-buffer nil)
  1014. (set-window-text-height (display-buffer python-buffer
  1015. t)
  1016. 7))
  1017. (add-hook 'inferior-python-mode-hook
  1018. (lambda ()
  1019. (my-python-display-python-buffer))))
  1020. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1021. ;; gauche-mode
  1022. ;; http://d.hatena.ne.jp/kobapan/20090305/1236261804
  1023. ;; http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el
  1024. (when (and (fetch-library
  1025. "http://www.katch.ne.jp/~leque/software/repos/gauche-mode/gauche-mode.el"
  1026. t)
  1027. (autoload-eval-lazily 'gauche-mode '(gauche-mode run-scheme)
  1028. (defvar gauche-mode-map (make-sparse-keymap))
  1029. (defvar scheme-mode-map (make-sparse-keymap))
  1030. (define-key gauche-mode-map
  1031. (kbd "C-c C-z") 'run-gauche-other-window)
  1032. (define-key scheme-mode-map
  1033. (kbd "C-c C-c") 'scheme-send-buffer)
  1034. (define-key scheme-mode-map
  1035. (kbd "C-c C-b") 'my-scheme-display-scheme-buffer)))
  1036. (let ((s (executable-find "gosh")))
  1037. (set-variable 'scheme-program-name s)
  1038. (set-variable 'gauche-program-name s))
  1039. (defvar gauche-program-name nil)
  1040. (defvar scheme-buffer nil)
  1041. (defun run-gauche-other-window ()
  1042. "Run gauche on other window"
  1043. (interactive)
  1044. (switch-to-buffer-other-window
  1045. (get-buffer-create "*scheme*"))
  1046. (run-gauche))
  1047. (defun run-gauche ()
  1048. "run gauche"
  1049. (interactive)
  1050. (run-scheme gauche-program-name)
  1051. )
  1052. (defun scheme-send-buffer ()
  1053. ""
  1054. (interactive)
  1055. (scheme-send-region (point-min) (point-max))
  1056. (my-scheme-display-scheme-buffer)
  1057. )
  1058. (defun my-scheme-display-scheme-buffer ()
  1059. ""
  1060. (interactive)
  1061. (set-window-text-height (display-buffer scheme-buffer
  1062. t)
  1063. 7))
  1064. (add-hook 'scheme-mode-hook
  1065. (lambda ()
  1066. nil))
  1067. (add-hook 'inferior-scheme-mode-hook
  1068. (lambda ()
  1069. ;; (my-scheme-display-scheme-buffer)
  1070. ))
  1071. (setq auto-mode-alist
  1072. (cons '("\.gosh\\'" . gauche-mode) auto-mode-alist))
  1073. (setq auto-mode-alist
  1074. (cons '("\.gaucherc\\'" . gauche-mode) auto-mode-alist))
  1075. )
  1076. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1077. ;; term mode
  1078. ;; (setq multi-term-program shell-file-name)
  1079. (when (autoload-eval-lazily 'multi-term)
  1080. (set-variable 'multi-term-switch-after-close nil)
  1081. (set-variable 'multi-term-dedicated-select-after-open-p t)
  1082. (set-variable 'multi-term-dedicated-window-height 20))
  1083. (when (autoload-eval-lazily 'term '(term ansi-term)
  1084. (defvar term-raw-map (make-sparse-keymap))
  1085. ;; (define-key term-raw-map "\C-xl" 'term-line-mode)
  1086. ;; (define-key term-mode-map "\C-xc" 'term-char-mode)
  1087. (define-key term-raw-map (kbd "<up>") 'scroll-down-line)
  1088. (define-key term-raw-map (kbd "<down>") 'scroll-up-line)
  1089. (define-key term-raw-map (kbd "<right>") 'scroll-up)
  1090. (define-key term-raw-map (kbd "<left>") 'scroll-down)
  1091. (define-key term-raw-map (kbd "C-p") 'term-send-raw)
  1092. (define-key term-raw-map (kbd "C-n") 'term-send-raw)
  1093. (define-key term-raw-map "q" 'my-term-quit-or-send-raw)
  1094. ;; (define-key term-raw-map (kbd "ESC") 'term-send-raw)
  1095. (define-key term-raw-map [delete] 'term-send-raw)
  1096. (define-key term-raw-map (kbd "DEL") 'term-send-backspace)
  1097. (define-key term-raw-map "\C-y" 'term-paste)
  1098. (define-key term-raw-map
  1099. "\C-c" 'term-send-raw) ;; 'term-interrupt-subjob)
  1100. '(define-key term-mode-map (kbd "C-x C-q") 'term-pager-toggle)
  1101. ;; (dolist (key '("<up>" "<down>" "<right>" "<left>"))
  1102. ;; (define-key term-raw-map (read-kbd-macro key) 'term-send-raw))
  1103. ;; (define-key term-raw-map "\C-d" 'delete-char)
  1104. ;; (define-key term-raw-map "\C-q" 'move-beginning-of-line)
  1105. ;; (define-key term-raw-map "\C-r" 'term-send-raw)
  1106. ;; (define-key term-raw-map "\C-s" 'term-send-raw)
  1107. ;; (define-key term-raw-map "\C-f" 'forward-char)
  1108. ;; (define-key term-raw-map "\C-b" 'backward-char)
  1109. ;; (define-key term-raw-map "\C-t" 'set-mark-command)
  1110. )
  1111. (defun my-term-quit-or-send-raw ()
  1112. ""
  1113. (interactive)
  1114. (if (get-buffer-process (current-buffer))
  1115. (call-interactively 'term-send-raw)
  1116. (kill-buffer)))
  1117. ;; http://d.hatena.ne.jp/goinger/20100416/1271399150
  1118. ;; (setq term-ansi-default-program shell-file-name)
  1119. (add-hook 'term-setup-hook
  1120. (lambda ()
  1121. (set-variable 'term-display-table (make-display-table))))
  1122. (add-hook 'term-mode-hook
  1123. (lambda ()
  1124. (defvar term-raw-map (make-sparse-keymap))
  1125. ;; (unless (memq (current-buffer)
  1126. ;; (and (featurep 'multi-term)
  1127. ;; (defvar multi-term-buffer-list)
  1128. ;; ;; current buffer is not multi-term buffer
  1129. ;; multi-term-buffer-list))
  1130. ;; )
  1131. (set (make-local-variable 'scroll-margin) 0)
  1132. ;; (set (make-local-variable 'cua-enable-cua-keys) nil)
  1133. ;; (cua-mode 0)
  1134. ;; (and cua-mode
  1135. ;; (local-unset-key (kbd "C-c")))
  1136. ;; (define-key cua--prefix-override-keymap
  1137. ;;"\C-c" 'term-interrupt-subjob)
  1138. (set (make-local-variable (defvar hl-line-range-function))
  1139. (lambda ()
  1140. '(0 . 0)))
  1141. (define-key term-raw-map
  1142. "\C-x" (lookup-key (current-global-map) "\C-x"))
  1143. (define-key term-raw-map
  1144. "\C-z" (lookup-key (current-global-map) "\C-z"))
  1145. ))
  1146. ;; (add-hook 'term-exec-hook 'forward-char)
  1147. )
  1148. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1149. ;; buffer switching
  1150. (defvar bs-configurations)
  1151. (when (autoload-eval-lazily 'bs '(bs-show)
  1152. ;; (add-to-list 'bs-configurations
  1153. ;; '("processes" nil get-buffer-process ".*" nil nil))
  1154. (add-to-list 'bs-configurations
  1155. '("files-and-terminals" nil nil nil
  1156. (lambda (buf)
  1157. (and (bs-visits-non-file buf)
  1158. (save-excursion
  1159. (set-buffer buf)
  1160. (not (memq major-mode
  1161. '(term-mode
  1162. eshell-mode))))))))
  1163. ;; (setq bs-configurations (list
  1164. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1165. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1166. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1167. )
  1168. ;; (global-set-key "\C-x\C-b" 'bs-show)
  1169. (defalias 'list-buffers 'bs-show)
  1170. (set-variable 'bs-default-configuration "files-and-terminals")
  1171. (set-variable 'bs-default-sort-name "by nothing")
  1172. (add-hook 'bs-mode-hook
  1173. (lambda ()
  1174. ;; (setq bs-default-configuration "files")
  1175. ;; (and bs--show-all
  1176. ;; (call-interactively 'bs-toggle-show-all))
  1177. (set (make-local-variable 'scroll-margin) 0))))
  1178. ;;(iswitchb-mode 1)
  1179. (icomplete-mode)
  1180. (defun iswitchb-buffer-display-other-window ()
  1181. "Do iswitchb in other window."
  1182. (interactive)
  1183. (let ((iswitchb-default-method 'display))
  1184. (call-interactively 'iswitchb-buffer)))
  1185. ;;;;;;;;;;;;;;;;;;;;;;;;
  1186. ;; ilookup
  1187. (with-eval-after-load 'ilookup
  1188. (set-variable 'ilookup-dict-alist
  1189. '(
  1190. ("sdcv" . (lambda (word)
  1191. (shell-command-to-string
  1192. (format "sdcv -n '%s'"
  1193. word))))
  1194. ("en" . (lambda (word)
  1195. (shell-command-to-string
  1196. (format "sdcv -n -u dictd_www.dict.org_gcide '%s'"
  1197. word))))
  1198. ("ja" . (lambda (word)
  1199. (shell-command-to-string
  1200. (format "sdcv -n -u EJ-GENE95 -u jmdict-en-ja '%s'"
  1201. word))))
  1202. ("jaj" . (lambda (word)
  1203. (shell-command-to-string
  1204. (format "sdcv -n -u jmdict-en-ja '%s'"
  1205. word))))
  1206. ("jag" .
  1207. (lambda (word)
  1208. (with-temp-buffer
  1209. (insert (shell-command-to-string
  1210. (format "sdcv -n -u 'Genius English-Japanese' '%s'"
  1211. word)))
  1212. (html2text)
  1213. (buffer-substring (point-min)
  1214. (point-max)))))
  1215. ("alc" . (lambda (word)
  1216. (shell-command-to-string
  1217. (format "alc '%s' | head -n 20"
  1218. word))))
  1219. ("app" . (lambda (word)
  1220. (shell-command-to-string
  1221. (format "dict_app '%s'"
  1222. word))))
  1223. ;; letters broken
  1224. ("ms" .
  1225. (lambda (word)
  1226. (let ((url (concat
  1227. "http://api.microsofttranslator.com/V2/Ajax.svc/"
  1228. "Translate?appId=%s&text=%s&to=%s"))
  1229. (apikey "3C9778666C5BA4B406FFCBEE64EF478963039C51")
  1230. (target "ja")
  1231. (eword (url-hexify-string word)))
  1232. (with-current-buffer (url-retrieve-synchronously
  1233. (format url
  1234. apikey
  1235. eword
  1236. target))
  1237. (message "")
  1238. (goto-char (point-min))
  1239. (search-forward-regexp "^$"
  1240. nil
  1241. t)
  1242. (url-unhex-string (buffer-substring-no-properties
  1243. (point)
  1244. (point-max)))))))
  1245. ))
  1246. ;; (funcall (cdr (assoc "ms"
  1247. ;; ilookup-alist))
  1248. ;; "dictionary")
  1249. ;; (switch-to-buffer (url-retrieve-synchronously "http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=3C9778666C5BA4B406FFCBEE64EF478963039C51&text=dictionary&to=ja"))
  1250. ;; (switch-to-buffer (url-retrieve-synchronously "http://google.com"))
  1251. (set-variable 'ilookup-default "ja")
  1252. (when (locate-library "google-translate")
  1253. (defvar ilookup-dict-alist nil)
  1254. (add-to-list 'ilookup-dict-alist
  1255. '("gt" .
  1256. (lambda (word)
  1257. (save-excursion
  1258. (google-translate-translate "auto"
  1259. "ja"
  1260. word))
  1261. (with-current-buffer "*Google Translate*"
  1262. (buffer-substring-no-properties (point-min)
  1263. (point-max)))))))
  1264. )
  1265. (when (autoload-eval-lazily 'google-translate '(google-translate-translate
  1266. google-translate-at-point))
  1267. (set-variable 'google-translate-default-source-language "auto")
  1268. (set-variable 'google-translate-default-target-language "ja"))
  1269. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1270. ;; vc
  1271. (require 'vc)
  1272. (setq vc-handled-backends '())
  1273. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1274. ;; recentf-mode
  1275. (set-variable 'recentf-save-file (expand-file-name (concat user-emacs-directory
  1276. "recentf")))
  1277. (set-variable 'recentf-max-menu-items 20)
  1278. (set-variable 'recentf-max-saved-items 30)
  1279. (set-variable 'recentf-show-file-shortcuts-flag nil)
  1280. (when (safe-require-or-eval 'recentf)
  1281. (add-to-list 'recentf-exclude
  1282. (regexp-quote recentf-save-file))
  1283. (add-to-list 'recentf-exclude
  1284. (regexp-quote (expand-file-name user-emacs-directory)))
  1285. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1286. (remove-hook 'find-file-hook
  1287. 'recentf-track-opened-file)
  1288. (defun my-recentf-load-track-save-list ()
  1289. "Load current recentf list from file, track current visiting file, then save
  1290. the list."
  1291. (recentf-load-list)
  1292. (recentf-track-opened-file)
  1293. (recentf-save-list))
  1294. (add-hook 'find-file-hook
  1295. 'my-recentf-load-track-save-list)
  1296. (add-hook 'kill-emacs-hook
  1297. 'recentf-load-list)
  1298. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1299. ;; (add-hook 'find-file-hook
  1300. ;; (lambda ()
  1301. ;; (recentf-add-file default-directory)))
  1302. (and (autoload-eval-lazily 'recentf-show)
  1303. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1304. (add-hook 'recentf-show-before-listing-hook
  1305. 'recentf-load-list))
  1306. (recentf-mode 1)
  1307. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1308. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1309. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1310. (define-key recentf-dialog-mode-map "n" 'next-line)
  1311. (add-hook 'recentf-dialog-mode-hook
  1312. (lambda ()
  1313. ;; (recentf-save-list)
  1314. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1315. ;; 'my-recentf-cd-and-find-file)
  1316. (cd "~/"))))
  1317. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1318. ;; dired
  1319. (defun my-dired-echo-file-head (arg)
  1320. ""
  1321. (interactive "P")
  1322. (let ((f (dired-get-filename)))
  1323. (message "%s"
  1324. (with-temp-buffer
  1325. (insert-file-contents f)
  1326. (buffer-substring-no-properties
  1327. (point-min)
  1328. (progn (goto-char (point-min))
  1329. (forward-line (1- (if arg
  1330. (prefix-numeric-value arg)
  1331. 7)))
  1332. (point-at-eol)))))))
  1333. (defun my-dired-diff ()
  1334. ""
  1335. (interactive)
  1336. (let ((files (dired-get-marked-files nil nil nil t)))
  1337. (if (eq (car files)
  1338. t)
  1339. (diff (cadr files) (dired-get-filename))
  1340. (message "One file must be marked!"))))
  1341. (defun dired-get-file-info ()
  1342. "dired get file info"
  1343. (interactive)
  1344. (let ((f (shell-quote-argument (dired-get-filename t))))
  1345. (if (file-directory-p f)
  1346. (progn
  1347. (message "Calculating disk usage...")
  1348. (shell-command (concat "du -hsD "
  1349. f)))
  1350. (shell-command (concat "file "
  1351. f)))))
  1352. (defun my-dired-scroll-up ()
  1353. ""
  1354. (interactive)
  1355. (my-dired-previous-line (- (window-height) 1)))
  1356. (defun my-dired-scroll-down ()
  1357. ""
  1358. (interactive)
  1359. (my-dired-next-line (- (window-height) 1)))
  1360. ;; (defun my-dired-forward-line (arg)
  1361. ;; ""
  1362. ;; (interactive "p"))
  1363. (defun my-dired-previous-line (arg)
  1364. ""
  1365. (interactive "p")
  1366. (if (> arg 0)
  1367. (progn
  1368. (if (eq (line-number-at-pos)
  1369. 1)
  1370. (goto-char (point-max))
  1371. (forward-line -1))
  1372. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1373. (dired-get-subdir))
  1374. (- arg 1)
  1375. arg)))
  1376. (dired-move-to-filename)))
  1377. (defun my-dired-next-line (arg)
  1378. ""
  1379. (interactive "p")
  1380. (if (> arg 0)
  1381. (progn
  1382. (if (eq (point)
  1383. (point-max))
  1384. (goto-char (point-min))
  1385. (forward-line 1))
  1386. (my-dired-next-line (if (or (dired-get-filename nil t)
  1387. (dired-get-subdir))
  1388. (- arg 1)
  1389. arg)))
  1390. (dired-move-to-filename)))
  1391. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1392. (if (eq window-system 'mac)
  1393. (setq dired-listing-switches "-lhF")
  1394. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1395. )
  1396. (setq dired-listing-switches "-lhF")
  1397. (put 'dired-find-alternate-file 'disabled nil)
  1398. ;; when using dired-find-alternate-file
  1399. ;; reuse current dired buffer for the file to open
  1400. (set-variable 'dired-ls-F-marks-symlinks t)
  1401. (when (safe-require-or-eval 'ls-lisp)
  1402. (setq ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1403. (setq ls-lisp-dirs-first t)
  1404. (setq ls-lisp-use-localized-time-format t)
  1405. (setq ls-lisp-format-time-list
  1406. '("%Y-%m-%d %H:%M"
  1407. "%Y-%m-%d ")))
  1408. (set-variable 'dired-dwim-target t)
  1409. (set-variable 'dired-isearch-filenames t)
  1410. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  1411. (set-variable 'dired-hide-details-hide-information-lines nil)
  1412. ;; (add-hook 'dired-after-readin-hook
  1413. ;; 'my-replace-nasi-none)
  1414. ;; (add-hook 'after-init-hook
  1415. ;; (lambda ()
  1416. ;; (dired ".")))
  1417. (with-eval-after-load 'dired
  1418. (defvar dired-mode-map (make-sparse-keymap))
  1419. (define-key dired-mode-map "o" 'my-dired-x-open)
  1420. (define-key dired-mode-map "i" 'dired-get-file-info)
  1421. (define-key dired-mode-map "f" 'find-file)
  1422. (define-key dired-mode-map "!" 'shell-command)
  1423. (define-key dired-mode-map "&" 'async-shell-command)
  1424. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1425. (define-key dired-mode-map "=" 'my-dired-diff)
  1426. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1427. (define-key dired-mode-map "b" 'gtkbm)
  1428. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1429. (define-key dired-mode-map "@" (lambda ()
  1430. (interactive) (my-x-open ".")))
  1431. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1432. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1433. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1434. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1435. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1436. (substitute-key-definition 'dired-next-line
  1437. 'my-dired-next-line
  1438. dired-mode-map)
  1439. (substitute-key-definition 'dired-previous-line
  1440. 'my-dired-previous-line
  1441. dired-mode-map)
  1442. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  1443. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  1444. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  1445. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  1446. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1447. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1448. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1449. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1450. (add-hook 'dired-mode-hook
  1451. (lambda ()
  1452. (when (fboundp 'dired-hide-details-mode)
  1453. (dired-hide-details-mode t)
  1454. (local-set-key "l" 'dired-hide-details-mode))
  1455. (let ((file "._Icon\015"))
  1456. (when nil
  1457. '(file-readable-p file)
  1458. (delete-file file)))))
  1459. (when (autoload-eval-lazily 'pack '(dired-do-pack-or-unpack pack-pack))
  1460. (with-eval-after-load 'dired
  1461. (define-key dired-mode-map "P" 'dired-do-pack-or-unpack)))
  1462. (when (autoload-eval-lazily 'dired-list-all-mode)
  1463. (setq dired-listing-switches "-lhF")
  1464. (with-eval-after-load 'dired
  1465. (define-key dired-mode-map "a" 'dired-list-all-mode))))
  1466. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1467. ;; my-term
  1468. (defvar my-term nil
  1469. "My terminal buffer.")
  1470. (defvar my-term-function nil
  1471. "Function to create terminal buffer.
  1472. This function accept no argument and return newly created buffer of terminal.")
  1473. (defun my-term (&optional arg)
  1474. "Open terminal buffer and return that buffer.
  1475. If ARG is given or called with prefix argument, create new buffer."
  1476. (interactive "P")
  1477. (if (and (not arg)
  1478. my-term
  1479. (buffer-name my-term))
  1480. (pop-to-buffer my-term)
  1481. (setq my-term
  1482. (save-window-excursion
  1483. (funcall my-term-function)))
  1484. (and my-term
  1485. (my-term))))
  1486. ;; (setq my-term-function
  1487. ;; (lambda ()
  1488. ;; (if (eq system-type 'windows-nt)
  1489. ;; (eshell)
  1490. ;; (if (require 'multi-term nil t)
  1491. ;; (multi-term)
  1492. ;; (ansi-term shell-file-name)))))
  1493. (setq my-term-function (lambda () (eshell t)))
  1494. ;;(define-key my-prefix-map (kbd "C-s") 'my-term)
  1495. (define-key ctl-x-map "i" 'my-term)
  1496. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1497. ;; misc funcs
  1498. (defalias 'qcalc 'quick-calc)
  1499. (defun memo (&optional dir)
  1500. "Open memo.txt in DIR."
  1501. (interactive)
  1502. (pop-to-buffer (find-file-noselect (concat (if dir
  1503. (file-name-as-directory dir)
  1504. "")
  1505. "memo.txt"))))
  1506. (defvar my-rgrep-alist
  1507. `(
  1508. ;; the silver searcher
  1509. ("ag"
  1510. (executable-find "ag")
  1511. "ag --nocolor --nogroup --nopager --filename ")
  1512. ;; ack
  1513. ("ack"
  1514. (executable-find "ack")
  1515. "ack --nocolor --nogroup --nopager --with-filename ")
  1516. ;; gnu global
  1517. ("global"
  1518. (and (require 'gtags nil t)
  1519. (executable-find "global")
  1520. (gtags-get-rootpath))
  1521. "global --result grep ")
  1522. ;; git grep
  1523. ("gitgrep"
  1524. (eq 0
  1525. (shell-command "git rev-parse --git-dir"))
  1526. "git --no-pager -c color.grep=false grep -nH -e ")
  1527. ;; grep
  1528. ("grep"
  1529. t
  1530. ,(concat "find . "
  1531. "-path '*/.git' -prune -o "
  1532. "-path '*/.svn' -prune -o "
  1533. "-type f -print0 | "
  1534. "xargs -0 grep -nH -e "))
  1535. )
  1536. "Alist of rgrep command.
  1537. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1538. condition to choose COMMAND when evaluated.")
  1539. (defvar my-rgrep-default nil
  1540. "Default command name for my-rgrep.")
  1541. (defun my-rgrep-grep-command (&optional name alist)
  1542. "Return recursive grep command for current directory or nil.
  1543. If NAME is given, use that without testing.
  1544. Commands are searched from ALIST."
  1545. (if alist
  1546. (if name
  1547. ;; if name is given search that from alist and return the command
  1548. (nth 2 (assoc name
  1549. alist))
  1550. ;; if name is not given try test in 1th elem
  1551. (let ((car (car alist))
  1552. (cdr (cdr alist)))
  1553. (if (eval (nth 1 car))
  1554. ;; if the condition is true return the command
  1555. (nth 2 car)
  1556. ;; try next one
  1557. (and cdr
  1558. (my-rgrep-grep-command name cdr)))))
  1559. ;; if alist is not given set default value
  1560. (my-rgrep-grep-command name my-rgrep-alist)))
  1561. (defun my-rgrep (command-args)
  1562. "My recursive grep. Run COMMAND-ARGS."
  1563. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  1564. nil)))
  1565. (if cmd
  1566. (list (read-shell-command "grep command: "
  1567. cmd
  1568. 'grep-find-history))
  1569. (error "My-Rgrep: Command for rgrep not found")
  1570. )))
  1571. (compilation-start command-args
  1572. 'grep-mode))
  1573. ;; (defun my-rgrep-symbol-at-point (command-args)
  1574. ;; "My recursive grep. Run COMMAND-ARGS."
  1575. ;; (interactive (list (read-shell-command "grep command: "
  1576. ;; (concat (my-rgrep-grep-command)
  1577. ;; " "
  1578. ;; (thing-at-point 'symbol))
  1579. ;; 'grep-find-history)))
  1580. ;; (compilation-start command-args
  1581. ;; 'grep-mode))
  1582. (defmacro define-my-rgrep (name)
  1583. "Define rgrep for NAME."
  1584. `(defun ,(intern (concat "my-rgrep-"
  1585. name)) ()
  1586. ,(format "My recursive grep by %s."
  1587. name)
  1588. (interactive)
  1589. (let ((my-rgrep-default ,name))
  1590. (if (called-interactively-p 'any)
  1591. (call-interactively 'my-rgrep)
  1592. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1593. )
  1594. (define-my-rgrep "ack")
  1595. (define-my-rgrep "ag")
  1596. (define-my-rgrep "gitgrep")
  1597. (define-my-rgrep "grep")
  1598. (define-my-rgrep "global")
  1599. (define-key ctl-x-map "s" 'my-rgrep)
  1600. ;; (defun make ()
  1601. ;; "Run \"make -k\" in current directory."
  1602. ;; (interactive)
  1603. ;; (compile "make -k"))
  1604. (defalias 'make 'compile)
  1605. (define-key ctl-x-map "c" 'compile)
  1606. ;;; emacs.el ends here