Emacs: Keybindings for lsp and flycheck

This commit is contained in:
Joseph Ferano 2024-10-05 14:25:56 +07:00
parent 2b2e55dcf8
commit 06ea611d53
2 changed files with 54 additions and 34 deletions

View File

@ -553,6 +553,21 @@ Ligatures... are they that useful?
Emacs is an great operating system, if only it had a good text editor...
*** COMMENT Hydra
#+begin_src emacs-lisp
(require 'hydra)
(defhydra hydra-navigate (global-map "<f2>")
"Window Navigation"
("q" nil "quit")
("d" joe/smooth-scroll-half-page-down "half page down")
("u" joe/smooth-scroll-half-page-up "half page up")
("e" joe/smooth-scroll-short-down "line down")
("y" joe/smooth-scroll-short-up "line up")
("n" next-line "line down")
("p" previous-line "line up")
("M-r" move-to-window-line-top-bottom "Reposition cursor"))
#+end_src
*** Text editing
#+begin_src emacs-lisp
@ -636,10 +651,15 @@ weren't working, until I randomly saw this in someone's init.el
(advice-add 'drag-stuff-up :after 'indent-region-advice)
(advice-add 'drag-stuff-down :after 'indent-region-advice)
(define-key prog-mode-map (kbd "M-h") #'drag-stuff-left)
(define-key prog-mode-map (kbd "M-j") #'drag-stuff-down)
(define-key prog-mode-map (kbd "M-k") #'drag-stuff-up)
(define-key prog-mode-map (kbd "M-l") #'drag-stuff-right)
#+end_src
Traditional vim indenting with =<<= and =>>= is too slow
#+begin_src emacs-lisp
;; (define-key prog-mode-map (kbd "M-l") 'indent-rigidly-right-to-tab-stop)
;; (define-key prog-mode-map (kbd "M-h") 'indent-rigidly-left-to-tab-stop)
#+end_src
Simple function more quickly align text
@ -679,21 +699,6 @@ Fill region is great, except when you don't need it...
;; Handy key definition
(define-key global-map (kbd "C-M-q") #'unfill-region)
#+end_src
*** COMMENT Hydra
#+begin_src emacs-lisp
(require 'hydra)
(defhydra hydra-navigate (global-map "<f2>")
"Window Navigation"
("q" nil "quit")
("d" joe/smooth-scroll-half-page-down "half page down")
("u" joe/smooth-scroll-half-page-up "half page up")
("e" joe/smooth-scroll-short-down "line down")
("y" joe/smooth-scroll-short-up "line up")
("n" next-line "line down")
("p" previous-line "line up")
("M-r" move-to-window-line-top-bottom "Reposition cursor"))
#+end_src
*** COMMENT Multiple Cursors
#+begin_src emacs-lisp
@ -2234,26 +2239,25 @@ These help speed eglot up apparently [[https://www.reddit.com/r/emacs/comments/1
(add-hook 'lsp-mode-hook #'joe/lsp-mode-hook)
(define-key global-map (kbd "C-c l l") #'lsp)
(define-key lsp-command-map (kbd "c") #'flymake-mode)
(setq lsp-ui-doc-position 'at-point)
(setq lsp-ui-doc-show-with-mouse nil)
(require 'flycheck)
(setq flycheck-check-syntax-automatically '())
(setq flycheck-keymap-prefix (kbd "C-c e"))
(add-hook 'after-save-hook #'flycheck-clear)
;; All this changes because we are using eglot now
(when (boundp 'evil-mode)
(evil-global-set-key 'normal (kbd "M-e") #'flycheck-buffer)
(evil-global-set-key 'normal (kbd "M-n") #'flycheck-next-error)
(evil-global-set-key 'normal (kbd "M-p") #'flycheck-previous-error)
(evil-global-set-key 'normal (kbd "M-d") #'lsp-ui-doc-glance)
(evil-global-set-key 'normal (kbd "SPC cs") 'consult-lsp-symbols)
(evil-global-set-key 'normal (kbd "SPC cd") 'joe/consult-lsp-diagnostics)
(evil-global-set-key 'normal (kbd "SPC cf") 'consult-lsp-file-symbols))
(evil-global-set-key 'normal (kbd "M-r") #'lsp-rename)
(evil-global-set-key 'insert (kbd "M-i") #'lsp-signature-activate)
(evil-global-set-key 'normal (kbd "gD") #'xref-find-definitions-other-window)
(evil-global-set-key 'normal (kbd "SPC la") #'lsp-execute-code-action)
(evil-global-set-key 'normal (kbd "SPC lt") #'lsp-find-type-definition)
(evil-global-set-key 'normal (kbd "SPC lr") #'lsp-find-references)
(evil-global-set-key 'normal (kbd "SPC ld") #'lsp-find-definition)
(evil-global-set-key 'normal (kbd "SPC ls") #'consult-lsp-symbols)
(evil-global-set-key 'normal (kbd "SPC lD") #'consult-lsp-diagnostics)
(evil-global-set-key 'normal (kbd "SPC lf") #'consult-lsp-file-symbols))
;; This function allows us to extract Rust's true function signature
;; (cl-defmethod lsp-clients-extract-signature-on-hover (contents (_server-id (eql rust-analyzer)))
@ -2272,16 +2276,22 @@ These help speed eglot up apparently [[https://www.reddit.com/r/emacs/comments/1
;; (require 'lsp-ui)
#+end_src
*** COMMENT Flycheck
*** Flycheck
#+begin_src emacs-lisp
;; TODO Add wrapping to these functions
(require 'flycheck)
(setq flycheck-check-syntax-automatically '())
(setq flycheck-keymap-prefix (kbd "C-c e"))
(defun joe/flycheck-buffer-and-next () (interactive) (flycheck-buffer) (flycheck-next-error))
(defun joe/flycheck-buffer-and-previous () (interactive) (flycheck-buffer) (flycheck-previous-error))
(when (boundp 'evil-mode)
(evil-global-set-key 'normal (kbd "M-e") #'flycheck-next-error)
(evil-global-set-key 'normal (kbd "M-E") #'flycheck-previous-error)
(evil-global-set-key 'normal (kbd "<leader>ee") 'flycheck-mode)
(evil-global-set-key 'normal (kbd "<leader>el") #'flycheck-list-errors)
(evil-global-set-key 'normal (kbd "<leader>ce") #'consult-lsp-diagnostics))
(evil-global-set-key 'normal (kbd "M-E") #'joe/flycheck-buffer-and-previous)
(evil-global-set-key 'normal (kbd "M-e") #'joe/flycheck-buffer-and-next)
(evil-global-set-key 'normal (kbd "C-M-e") #'flycheck-clear)
(evil-global-set-key 'insert (kbd "C-M-e") #'flycheck-clear))
#+end_src
*** Compilation
#+begin_src emacs-lisp

View File

@ -0,0 +1,10 @@
# -*- mode: snippet -*-
# name: Unity Serializable class
# key: serc
# --
[Serializable]
public class ${1:className}
{
public $0
}