.dir-locals-template.el 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. ;;; .dir-locals.el
  2. ;;
  3. ;; Per-Directory Local Variables:
  4. ;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
  5. ;;
  6. ;; For full fledge developer tools install emacs packages:
  7. ;;
  8. ;; M-x package-install ...
  9. ;;
  10. ;; magit gitconfig
  11. ;; nvm lsp-mode lsp-pyright lsp-eslint
  12. ;; pyvenv pylint pip-requirements
  13. ;; jinja2-mode
  14. ;; json-mode
  15. ;; company company-jedi company-quickhelp company-shell
  16. ;; realgud
  17. ;; sphinx-doc markdown-mode graphviz-dot-mode
  18. ;; apache-mode nginx-mode
  19. ;;
  20. ;; To setup a developer environment, build target::
  21. ;;
  22. ;; $ make node.env.dev pyenv.install
  23. ;;
  24. ;; Some buffer locals are referencing the project environment:
  25. ;;
  26. ;; - prj-root --> <repo>/
  27. ;; - nvm-dir --> <repo>/.nvm
  28. ;; - python-environment-directory --> <repo>/local
  29. ;; - python-environment-default-root-name --> py3
  30. ;; - python-shell-virtualenv-root --> <repo>/local/py3
  31. ;; When this variable is set with the path of the virtualenv to use,
  32. ;; `process-environment' and `exec-path' get proper values in order to run
  33. ;; shells inside the specified virtualenv, example::
  34. ;; (setq python-shell-virtualenv-root "/path/to/env/")
  35. ;; - python-shell-interpreter --> <repo>/local/py3/bin/python
  36. ;;
  37. ;; Python development:
  38. ;;
  39. ;; Jedi, flycheck & other python stuff should use the 'python-shell-interpreter'
  40. ;; from the local py3 environment.
  41. ;;
  42. ((nil
  43. . ((fill-column . 80)
  44. (indent-tabs-mode . nil)
  45. (eval . (progn
  46. (add-to-list 'auto-mode-alist '("\\.html\\'" . jinja2-mode))
  47. ;; project root folder is where the `.dir-locals.el' is located
  48. (setq-local prj-root
  49. (locate-dominating-file default-directory ".dir-locals.el"))
  50. (setq-local python-environment-directory
  51. (expand-file-name "./local" prj-root))
  52. ;; to get in use of NVM environment, install https://github.com/rejeep/nvm.el
  53. (setq-local nvm-dir (expand-file-name "./.nvm" prj-root))
  54. ;; use nodejs from the (local) NVM environment (see nvm-dir)
  55. (nvm-use-for-buffer)
  56. (ignore-errors (require 'lsp))
  57. (setq-local lsp-server-install-dir (car (cdr nvm-current-version)))
  58. (setq-local lsp-enable-file-watchers nil)
  59. ;; use 'py3' environment as default
  60. (setq-local python-environment-default-root-name
  61. "py3")
  62. (setq-local python-shell-virtualenv-root
  63. (expand-file-name
  64. python-environment-default-root-name python-environment-directory))
  65. (setq-local python-shell-interpreter
  66. (expand-file-name
  67. "bin/python" python-shell-virtualenv-root))))))
  68. (makefile-gmake-mode
  69. . ((indent-tabs-mode . t)))
  70. (yaml-mode
  71. . ((eval . (progn
  72. ;; flycheck should use the local py3 environment
  73. (setq-local flycheck-yaml-yamllint-executable
  74. (expand-file-name "bin/yamllint" python-shell-virtualenv-root))
  75. (setq-local flycheck-yamllintrc
  76. (expand-file-name ".yamllint.yml" prj-root))
  77. (flycheck-checker . yaml-yamllint)))))
  78. (json-mode
  79. . ((eval . (progn
  80. (setq-local js-indent-level 4)
  81. (flycheck-checker . json-python-json)))))
  82. (js-mode
  83. . ((eval . (progn
  84. (ignore-errors (require 'lsp-eslint))
  85. (setq-local js-indent-level 2)
  86. ;; flycheck should use the eslint checker from developer tools
  87. (setq-local flycheck-javascript-eslint-executable
  88. (expand-file-name "node_modules/.bin/eslint" prj-root))
  89. ;; (flycheck-mode)
  90. (if (featurep 'lsp-eslint)
  91. (lsp))
  92. ))))
  93. (python-mode
  94. . ((eval . (progn
  95. (ignore-errors (require 'jedi-core))
  96. (ignore-errors (require 'lsp-pyright))
  97. (ignore-errors (sphinx-doc-mode))
  98. (setq-local python-environment-virtualenv
  99. (list (expand-file-name "bin/virtualenv" python-shell-virtualenv-root)
  100. ;;"--system-site-packages"
  101. "--quiet"))
  102. (setq-local pylint-command
  103. (expand-file-name "bin/pylint" python-shell-virtualenv-root))
  104. (if (featurep 'lsp-pyright)
  105. (lsp))
  106. ;; pylint will find the '.pylintrc' file next to the CWD
  107. ;; https://pylint.readthedocs.io/en/latest/user_guide/run.html#command-line-options
  108. (setq-local flycheck-pylintrc
  109. ".pylintrc")
  110. ;; flycheck & other python stuff should use the local py3 environment
  111. (setq-local flycheck-python-pylint-executable
  112. python-shell-interpreter)
  113. ;; use 'M-x jedi:show-setup-info' and 'M-x epc:controller' to inspect jedi server
  114. ;; https://tkf.github.io/emacs-jedi/latest/#jedi:environment-root -- You
  115. ;; can specify a full path instead of a name (relative path). In that case,
  116. ;; python-environment-directory is ignored and Python virtual environment
  117. ;; is created at the specified path.
  118. (setq-local jedi:environment-root
  119. python-shell-virtualenv-root)
  120. ;; https://tkf.github.io/emacs-jedi/latest/#jedi:server-command
  121. (setq-local jedi:server-command
  122. (list python-shell-interpreter
  123. jedi:server-script))
  124. ;; jedi:environment-virtualenv --> see above 'python-environment-virtualenv'
  125. ;; is set buffer local! No need to setup jedi:environment-virtualenv:
  126. ;;
  127. ;; Virtualenv command to use. A list of string. If it is nil,
  128. ;; python-environment-virtualenv is used instead. You must set non-nil
  129. ;; value to jedi:environment-root in order to make this setting work.
  130. ;;
  131. ;; https://tkf.github.io/emacs-jedi/latest/#jedi:environment-virtualenv
  132. ;;
  133. ;; (setq-local jedi:environment-virtualenv
  134. ;; (list (expand-file-name "bin/virtualenv" python-shell-virtualenv-root)
  135. ;; "--python"
  136. ;; "/usr/bin/python3.4"
  137. ;; ))
  138. ))))
  139. )