Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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