Skip to content

Instantly share code, notes, and snippets.

@tomalexander
Created August 7, 2019 14:52
Show Gist options
  • Save tomalexander/e5fa6c2511006142d53713f87cf50077 to your computer and use it in GitHub Desktop.
Save tomalexander/e5fa6c2511006142d53713f87cf50077 to your computer and use it in GitHub Desktop.
Emacs lsp-mode save hook call process region issue
#!/usr/bin/env python3
#
def main():
print("foo bar")
FROM alpine:3.10.1
RUN apk --no-cache add bash emacs python3 py3-setuptools
RUN pip3 install python-language-server black
RUN mkdir -p /root/demo_python_project/.git
COPY dot_emacs /root/.emacs
COPY demo.py /root/demo_python_project/demo.py
CMD /usr/bin/emacs /root/demo_python_project/demo.py
;; Disable TLS 1.3 due to bug in emacs 26
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(package-initialize)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/")
)
(when (not package-archive-contents)
(package-refresh-contents))
(unless (package-installed-p 'use-package)
(package-install 'use-package))
(defun python-fmt ()
"Run black."
(let (
(originalcolumn (current-column))
(originalline (count-lines 1 (point)))
)
(call-process-region (point-min) (point-max) "black" t t t "--quiet" "--fast" "-")
(beginning-of-line)
(with-no-warnings (goto-line originalline))
(move-to-column originalcolumn)
)
(message "Ran black")
)
(use-package python-mode
:mode "\\.py\\'"
:ensure t
:hook ((python-mode . lsp)
(python-mode . (lambda () (add-hook 'before-save-hook 'python-fmt nil 'local)))
)
)
(use-package lsp-mode
:ensure t
:commands lsp
:config
(require 'lsp-clients)
(setq lsp-enable-snippet nil)
(setq lsp-auto-guess-root t)
(setq lsp-log-io t) ;; Log traffic to lsp-log buffer
(setq lsp-response-timeout 30)
)
[Trace - 02:45:18 PM] Sending notification 'textDocument/didChange'.
Params: {
"textDocument": {
"uri": "file:///root/demo_python_project/demo.py",
"version": 2
},
"contentChanges": [
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 6,
"character": 0
}
},
"rangeLength": 60,
"text": ""
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment