.dir-locals.el 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. ;; .. hint::
  7. ;;
  8. ;; If you get ``*** EPC Error ***`` (even after a jedi:install-server) in
  9. ;; your emacs session, mostly you have jedi-mode enabled but the python
  10. ;; enviroment is missed. The python environment has to be next to the
  11. ;; ``<repo>/.dir-locals.el`` in::
  12. ;;
  13. ;; ./local/py3
  14. ;;
  15. ;; To setup such an environment, build target::
  16. ;;
  17. ;; $ make pyenv.install
  18. ;;
  19. ;; Some buffer locals are referencing the project environment:
  20. ;;
  21. ;; - prj-root --> <repo>/
  22. ;; - nvm-dir --> <repo>/.nvm
  23. ;; - python-environment-directory --> <repo>/local
  24. ;; - python-environment-default-root-name --> py3
  25. ;; - python-shell-virtualenv-root --> <repo>/local/py3
  26. ;; When this variable is set with the path of the virtualenv to use,
  27. ;; `process-environment' and `exec-path' get proper values in order to run
  28. ;; shells inside the specified virtualenv, example::
  29. ;; (setq python-shell-virtualenv-root "/path/to/env/")
  30. ;; - python-shell-interpreter --> <repo>/local/py3/bin/python
  31. ;;
  32. ;; Jedi, flycheck & other python stuff should use the 'python-shell-interpreter'
  33. ;; from the local py3 environment.
  34. ;;
  35. ;; Other useful jedi stuff you might add to your ~/.emacs::
  36. ;;
  37. ;; (global-set-key [f6] 'flycheck-mode)
  38. ;; (add-hook 'python-mode-hook 'my:python-mode-hook)
  39. ;;
  40. ;; (defun my:python-mode-hook ()
  41. ;; (add-to-list 'company-backends 'company-jedi)
  42. ;; (require 'jedi-core)
  43. ;; (jedi:setup)
  44. ;; (define-key python-mode-map (kbd "C-c C-d") 'jedi:show-doc)
  45. ;; (define-key python-mode-map (kbd "M-.") 'jedi:goto-definition)
  46. ;; (define-key python-mode-map (kbd "M-,") 'jedi:goto-definition-pop-marker)
  47. ;; )
  48. ((nil
  49. . ((fill-column . 80)
  50. (indent-tabs-mode . nil)
  51. (eval . (progn
  52. (add-to-list 'auto-mode-alist '("\\.html\\'" . jinja2-mode))
  53. ;; project root folder is where the `.dir-locals.el' is located
  54. (setq-local prj-root
  55. (locate-dominating-file default-directory ".dir-locals.el"))
  56. (setq-local python-environment-directory
  57. (expand-file-name "./local" prj-root))
  58. ;; to get in use of NVM enviroment, install https://github.com/rejeep/nvm.el
  59. (setq-local nvm-dir (expand-file-name "./.nvm" prj-root))
  60. ;; use 'py3' enviroment as default
  61. (setq-local python-environment-default-root-name
  62. "py3")
  63. (setq-local python-shell-virtualenv-root
  64. (expand-file-name
  65. python-environment-default-root-name python-environment-directory))
  66. (setq-local python-shell-interpreter
  67. (expand-file-name
  68. "bin/python" python-shell-virtualenv-root))))))
  69. (makefile-gmake-mode
  70. . ((indent-tabs-mode . t)))
  71. (yaml-mode
  72. . ((eval . (progn
  73. ;; flycheck should use the local py3 environment
  74. (setq-local flycheck-yaml-yamllint-executable
  75. (expand-file-name "bin/yamllint" python-shell-virtualenv-root))
  76. (setq-local flycheck-yamllintrc
  77. (expand-file-name ".yamllint.yml" prj-root))
  78. (flycheck-checker . yaml-yamllint)))))
  79. (json-mode
  80. . ((eval . (progn
  81. (setq-local js-indent-level 4)
  82. (flycheck-checker . json-python-json)))))
  83. (js-mode
  84. . ((eval . (progn
  85. ;; use nodejs from the (local) NVM environment (see nvm-dir)
  86. (nvm-use-for-buffer)
  87. (setq-local js-indent-level 2)
  88. (flycheck-mode)
  89. ))))
  90. (python-mode
  91. . ((eval . (progn
  92. (setq-local python-environment-virtualenv
  93. (list (expand-file-name "bin/virtualenv" python-shell-virtualenv-root)
  94. ;;"--system-site-packages"
  95. "--quiet"))
  96. (setq-local pylint-command
  97. (expand-file-name "bin/pylint" python-shell-virtualenv-root))
  98. ;; pylint will find the '.pylintrc' file next to the CWD
  99. ;; https://pylint.readthedocs.io/en/latest/user_guide/run.html#command-line-options
  100. (setq-local flycheck-pylintrc
  101. ".pylintrc")
  102. ;; flycheck & other python stuff should use the local py3 environment
  103. (setq-local flycheck-python-pylint-executable
  104. python-shell-interpreter)
  105. ;; use 'M-x jedi:show-setup-info' and 'M-x epc:controller' to inspect jedi server
  106. ;; https://tkf.github.io/emacs-jedi/latest/#jedi:environment-root -- You
  107. ;; can specify a full path instead of a name (relative path). In that case,
  108. ;; python-environment-directory is ignored and Python virtual environment
  109. ;; is created at the specified path.
  110. (setq-local jedi:environment-root
  111. python-shell-virtualenv-root)
  112. ;; https://tkf.github.io/emacs-jedi/latest/#jedi:server-command
  113. (setq-local jedi:server-command
  114. (list python-shell-interpreter
  115. jedi:server-script))
  116. ;; jedi:environment-virtualenv --> see above 'python-environment-virtualenv'
  117. ;; is set buffer local! No need to setup jedi:environment-virtualenv:
  118. ;;
  119. ;; Virtualenv command to use. A list of string. If it is nil,
  120. ;; python-environment-virtualenv is used instead. You must set non-nil
  121. ;; value to jedi:environment-root in order to make this setting work.
  122. ;;
  123. ;; https://tkf.github.io/emacs-jedi/latest/#jedi:environment-virtualenv
  124. ;;
  125. ;; (setq-local jedi:environment-virtualenv
  126. ;; (list (expand-file-name "bin/virtualenv" python-shell-virtualenv-root)
  127. ;; "--python"
  128. ;; "/usr/bin/python3.4"
  129. ;; ))
  130. ))))
  131. )