lsp -- Emacs lsp client usage

lsp-java

  • jdtls 安装

    1. lsp-install-server 命令
    2. 手动安装

  • eglot 配置

    • M-x eglot
    • 输入 jdtls 项目根目录

      • eg: e:/programs/jdtls/
    • 我的配置

      • eg:

         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        
        (use-package eglot
          :ensure t
          :config
          (defconst my/jdtls-project-root (expand-file-name (concat user-emacs-directory ".cache/lsp/eclipse.jdt.ls/")))
          (defconst my/jdtls-jar-file-pattern "^org\.eclipse\.equinox\.launcher_[1-9].*\.jar$")
        
          (defun my/jdtls-find-executable-jar-file (dir file-pattern)
            (car (directory-files-recursively dir file-pattern)))
        
          (defun my/eclipse-jdt-contact (interactive)
            (let ((cp (getenv "CLASSPATH"))
                  (path_seprator ":"))
              (if (eq system-type 'windows-nt)
                  (setq path_seprator ";"))
              (setenv "CLASSPATH" (concat cp path_seprator (my/jdtls-find-executable-jar-file my/jdtls-project-root my/jdtls-jar-file-pattern)))
              (message (getenv "CLASSPATH"))
              (unwind-protect
                  (eglot--eclipse-jdt-contact nil)
                (setenv "CLASSPATH" cp))))
        
          (setcdr (assq 'java-mode eglot-server-programs) #'my/eclipse-jdt-contact)
          (add-hook 'java-mode-hook 'eglot-ensure)
          )
  • lsp-mode 配置

Efficient Cpp

unordered_map

查找

  • map.find(key) != map.end() 快于 map.get(key)

Efficient Python

dict

查找

  • 速度

    • key in our_dict > our_dict[key] > our_dict.get(key)
      • in: 查找 key 更快
      • [] 下标索引 优于 dict.get() 索引
      • dic.get() 具有安全保护,背后逻辑更耗时

use-package

教程

autoload

  • 使用 :commands 关键字

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    
    (use-package color-moccur
      :commands (isearch-moccur isearch-all) ;; 自动 autoload
      :bind (("M-s O" . moccur)
             :map isearch-mode-map
             ("M-o" . isearch-moccur)
             ("M-O" . isearch-moccur-all))
      :init
      (setq isearch-lazy-highlight t)
      :config
      (use-package moccur-edit))

key-binding 绑定

  • 参考

  • 功能

    • :bind

      • command 绑定
    • :bind-keymap

      • keymap 绑定
  • 使用 :bind 关键字

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    
    (use-package color-moccur
      :commands (isearch-moccur isearch-all)
      :bind (("M-s O" . moccur) 			;; 全局绑定
    
             :map isearch-mode-map			;; mode 内绑定
             ("M-o" . isearch-moccur)
             ("M-O" . isearch-moccur-all))
      :init
      (setq isearch-lazy-highlight t)
      :config
      (use-package moccur-edit))

特性

  • 自动创建 autoload