.dir-locals.el 6.2 KB

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