Skip to content

Instantly share code, notes, and snippets.

@twlz0ne
Last active January 21, 2018 08:19
Show Gist options
  • Save twlz0ne/046857700740c75fa69a1e8f3d8d12ff to your computer and use it in GitHub Desktop.
Save twlz0ne/046857700740c75fa69a1e8f3d8d12ff to your computer and use it in GitHub Desktop.
Test lsp-flycheck
;;; Usage: /path/to/emacs -nw -Q -l /path/to/test-lsp-flycheck.el
;;; Date: 2018-01-09_14.09.39
(toggle-debug-on-error)
(global-set-key (kbd "C-h") 'delete-backward-char)
(global-set-key (kbd "M-h") 'backward-kill-word)
(global-set-key (kbd "<f1>") 'help-command)
(define-key isearch-mode-map "\C-h" 'isearch-delete-char)
;; ------------------------------------------------------------------
(setq package-user-dir
(concat
user-emacs-directory
(format "elpa--%s/%s" (file-name-base load-file-name) emacs-version)))
(unless (load (concat user-emacs-directory "elpa.el") t)
(setq package-archives
'(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/"))))
(package-initialize)
(defun require-packages (&rest packages)
(dolist (pkg packages)
(unless (package-installed-p pkg)
(package-refresh-contents)
(package-install pkg))
(require pkg)))
;; ------------------------------------------------------------------
(defun make-test-file ()
(let (;; (test-file (make-temp-file "test-lsp-flycheck--" nil ".py"))
(test-file "/tmp/test-lsp-flycheck.py"))
(with-temp-buffer
(insert
(format
"\"\"\"docstring\"\"\"
# Press any key to pause idle-timer
# ens of %s.py" (file-name-base test-file)))
(write-region (point-min) (point-max) test-file))
test-file))
(require-packages
'lsp-mode
'lsp-ui
'lsp-python
'pyenv-mode)
(add-hook 'prog-major-mode 'lsp-prog-major-mode-enable)
(add-hook 'python-mode-hook 'lsp-python-enable)
(add-hook 'lsp-mode-hook 'lsp-ui-mode)
(add-hook 'after-init-hook 'global-flycheck-mode)
(setq python-indent-guess-indent-offset nil)
(setq python-shell-exec-path (list (concat (getenv "HOME") "/.pyenv/shims/")))
(add-to-list 'exec-path "~/.pyenv/shims")
(pyenv-mode)
(pyenv-mode-set (car (reverse (pyenv-mode-versions))))
(delete-other-windows)
(toggle-frame-maximized)
(with-eval-after-load 'lsp-mode
(require 'lsp-flycheck))
(defvar idle-timer-secs 1)
(defun keypress-end ()
(execute-kbd-macro (kbd "<end>"))
(message "keypress: <end>")
(setq idle-timer-secs (1+ idle-timer-secs))
(run-with-idle-timer idle-timer-secs nil 'keypress-home))
(defun keypress-home ()
(execute-kbd-macro (kbd "<home>"))
(message "keypress: <home>")
(setq idle-timer-secs (1+ idle-timer-secs))
(run-with-idle-timer idle-timer-secs nil 'keypress-end))
(add-hook 'after-init-hook
(lambda ()
(find-file (make-test-file))
(global-display-line-numbers-mode)
(run-with-idle-timer idle-timer-secs nil 'keypress-end)
;; line wrapped when cursor at <home>
))
(run-hooks 'after-init-hook)
;;; test-lsp-flycheck.el ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment