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

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