2021年8月27日金曜日

Emacs の python-mode. なう。

もう、イヤというほど見直してるので、 「なう」にした。で、少し落ち着いてきたと感じているので、 区切りということで、アップ。(どうせ、すぐ変更だろうけど)

あくまで、初心者が「落ち着いてきた」と感じたレベル。 使いこなしているはずもない。

  • 環境は、Debian(bullseye)+emacs(27.1)。
  • project ディレクトリ配下に 作業毎にサブディレクトを作成している。
  • projectilel, pipenv を使いはじめた。
  • python-mode は、elpa から(buildin でない)取得したものを使用。
  • lsp は lsp-mode で、python のクライアントは、lsp-pylsp。
  • tag jump は、lsp から xref を使う。時々探せない時があるので、そんな時は、gtags。
  • flymake ではなく、flycheck。設定は lsp まかせ。
  • 補完は、lsp ではなく、company を直接使ってる、はず。
  • python-shell は使ってない。 画面が狭いし、shell のツールがうまく使えてないから。 必要な場合は、i3-wm の WS を切り替えて、terminal で作業。 たまに、pop-shell を使ってるかも。
  • フォールディングは、origami。使いこなせてない。 私は narrow-to-defun でよいかも。
  • indent は、auto で動くやつは使わない。 python では使わないものだと、どこかで見た記憶がある。 black を時々マニュアルで起動して、整形している。
  • lsp-ui-peak は、画面が大きければ便利かもと思う。 私の場合は、taq jump で行き来すれば大差ないのでは、と感じている。
(leaf python-mode :ensure t
  :mode ("\\.py\\'")
  :interpreter ("python")
  :mode-hydra (python-mode
               (:separator "-" :quit-key "q" :title "python(pylsp)-mode")
               ("LSP-UI"
                (("C" lsp "LSP cue")
                 ("R" lsp-restart-workspace "restart workspace")
                 ("L" lsp-lens-mode "Lens mode")
                 ("H" lsp-describe-session "describe-session")
                 )
                ;; document ;; Show object documentation at point
                "LSP doc, flycheck"
                (("D" lsp-ui-doc-enable "toggle")
                 ("dd" lsp-describe-thing-at-point "describe ap")
                 ("ds" lsp-ui-doc-show "show doc")
                 ("dh" lsp-ui-doc-glance "hide doc")
                 ;; flycheck
                 ("cc" lsp "Ceck")
                 ("cl" lsp-ui-flycheck-list "list" :exit t)
                 )
                "Peak"
                (("P" lsp-ui-peek-enable "toggle")
                 ("pd" lsp-ui-peek-find-definitions "definitions" :exit t)
                 ("pr" lsp-ui-peek-find-references  "references" :exit t)
                 ("pi" lsp-ui-peek-find-implementation "implement" :exit t)
                 ("pb" lsp-ui-peek-jump-backward "back")
                 ("pf" lsp-ui-peek-jump-forward "forwa")
                 )
                "Xref"
                (("xd" xref-find-definitions "find def" :exit t)
                 ("xr" xref-find-references "find ref" :exit t)
                 ("xw" xref-find-definitions-other-window "find def OW" :exit t)
                 ("xnl" xref-next-line "next line")
                 ("xng" xref-next-group "next group")
                 )
                ;; ("s" lsp-signature-help)
                "LSP others"
                (("f" lsp-format-buffer "lsp format")
                 ("d" lsp-describe-thing-at-point "describe ap")
                 ("r" lsp-rename "lsp rename" :exit t)
                 ("m" lsp-ui-imenu "ui-imenu" :exit t)
                 )
                ;;
                "Origami"
                (("oO" origami-mode "origami-mode")  ;;
                 ("o:" origami-recursively-toggle-node "recursively toggle")
                 ("oa" origami-toggle-all-nodes        "toggle all node")
                 ("ot" origami-toggle-node             "toggle node")
                 ("oo" origami-show-only-node          "show only current")
                 ("ou" origami-undo                    "undo")
                 ("or" origami-redo                    "redo")
                 ("oR" origami-reset                   "reset")
                 )
                )
               )
  :custom
  (py-company-pycomplete-p . nil)
  ;;
  :config
  ;;
  (python-mode)
  (flymake-mode nil)
  (setq auto-complete-mode nil)
  ;;
  (setq electric-indent-local-mode nil)
  (setq py-smart-indentation nil)      ;; new  ver. 6.2.4
  (setq python-indent-guess-indent-offset-verbose nil)
  ;; Non-nil means to emit a warning when indentation guessing fails.

  ;; (leaf py-isort :ensure t)

  ;;(leaf python-docstring :ensure t
  ;;  :config
  ;;  (python-docstring-install)
  ;;  )

  (setq flycheck-python-flake8-executable "~/.pyenv/shims/flake8")
  ;; (setq flycheck-flake8rc (concat (getenv "HOME") "/.flake8"))

  (setq flycheck-python-pylint-executable "~/.pyenv/shims/pylint")
  ;; (setq flycheck-pylintrc  (concat (getenv "HOME") "/.config/pylintrc"))

  (setq flycheck-python-mypy-executable "~/.pyenv/shims/mypy")
  ;; (setq flycheck-python-mypy-ini (concat (getenv "HOME") "/.mypy.ini"))
  ;;
  :defer-config
  (setq auto-complete-mode -1)

  (leaf pyvenv :ensure t :require t)
  (leaf pipenv :ensure t :require t
    :init
    ;; (setq
    ;;  pipenv-projectile-after-switch-function #'pipenv-projectile-after-switch-extended)
    (setq pipenv-with-flycheck nil)
    )
  ;;
  (leaf python-environment :ensure t :require t
    :doc "Required by: jedi-core"
    )

  (leaf company-jedi :ensure t :require t
    :init
    (leaf jedi-core :ensure t :require t
      :commands (jedi:setup)
      :hook
      (python-mode-hook . (lambda ()
                            (jedi:setup)
                            (set (make-local-variable 'company-backends)
                                 '(company-jedi company-dabbrev-code company-ispell))))
      :config
      (setq jedi:tooltip-method nil)  ;; pos-tip and/or popup, nil is minibuffer
      (setq jedi:complete-on-dot t)
      (setq jedi:use-shortcuts nil) ;; M-. and M-,
      )
    )

  (leaf lsp-pylsp :ensure nil :require t
    :doc "Fork of the python-language-server project."
    :config
    (setq lsp-pylsp-plugins-black-enabled t)
    (setq lsp-pylsp-plugins-pylint-enabled t)
    ;;(setq lsp-pylsp-plugins-flake8-enabled t)
    )

  )

0 件のコメント:

コメントを投稿

Emacs の lsp の設定、なう(202310)

前回さらしてから、さらに1年。そう、3年めになる。 が、今回は一段と自信がない。 環境は、 Debian GNU/Linux 12 (bookworm) + emacs(29.1)。consult + company。 embark は未だに使ってない。 用途は、メモ と ...