superbignut / Emacs-Rust-Configuration

Basic Emacs configuration for Rust.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Static Badge Static Badge Static Badge Static Badge

前言:

  • 1. 简介:

    这是一个面向新手 我自己 的用于写Rust 和 cpp 的 Emacs 配置,目前只有3个配置文件。

    • init.el 包含了最基本的配置和一些修改。
    • lisp/treemacs.el 是treemacs官方配置,只修改了两行
    • lisp/rust.el 内容主要来自参考11参考12,并使用 tree-sitter 强化了代码高亮。
  • 2. 主要插件:

    • lsp-mode
    • rust-mode / rustic
    • lsp-ui
    • tree-sitter
  • 3. Emacs截图:

Normal

Error

  • 4. 配置参考:

    1. Emacs欢迎界面上的Emacs tutorial。包含了Emacs的最基本按键和功能
    2. B站/知乎上的《Emacs高手修炼手册》一步一步配置出Emacs的基本功能
    3. NykMa个人网站上的《Emacs 自力求生指南》有他对的Emacs配置的详细说明
    4. 子龙山人的《21天学会Emacs》
    5. Github的Awesome系列 awesome-elisp,其中的 Emacs In A Box - Elisp Programming
    6. 国内的 Emacs圈子 Emacs-China
    7. 官方的Emacs手册 GNU Emacs manual
    8. 官方的Elisp参考手册 Emacs Lisp Reference Manual
    9. 官方的不那么硬核的 An Introduction to Programming in Emacs Lisp
    10. tuhdo的一系列教程 Emacs mini manual series,甚至还有Helm教程
    11. Robert Krahn的 Emacs-Rust 入门级详细配置,包括lsp,rustic,lsp-ui
    12. Lsp Mode 官网 里面有详细的各种语言的配置和参考链接
    13. clangd 官网 的说明和 Troubleshooting
  • 5. My-Trouble and Debug C++

    1. 在配置c++的时候,缺少 json文件导致 Emacs 无法识别项目结构,类似于在vscode中的 json一样。

      解决办法在LSP-MODE和CLANGD中都有指出,我是使用CMAKE构建项目的,所以可以直接生成 json文件 :

             cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1
      
    2. json配置好后,项目结构没问题,但发现系统文件之类都无法被识别。 解决办法是Stack Overflow 中提到的:

             $ clang -v
                     Ubuntu clang version 14.0.0-1ubuntu1.1
                     Target: x86_64-pc-linux-gnu
                     Thread model: posix
                     InstalledDir: /usr/bin
                     Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/10
                     Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/11
                     Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/12
                     Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
                     Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/13
      

      查看clangd的使用的GCC的版本,Selected 一行中可以看到我这里的是 13,进而安装相应的库:

             sudo apt install libstdc++-13-dev
      
    3. 对 c++ 进行 debug的话,就回到 vscode中,这里就不在 Emacs 中折腾了,参考 vscode官网,launch.json 配置如下:

             {
                     "version": "0.2.0",
                     "configurations": [
      
                     {
                             "name": "My-Debug",
                             "type": "cppdbg",
                             "request": "launch",
                             "program": "${workspaceFolder}/test",   // Change here.
                             "args": [],
                             "stopAtEntry": false, 
                             "cwd": "${workspaceFolder}",            // Change here.
                             "environment": [],
                             "MIMode": "gdb",
                             "setupCommands": [
                             {
                                     "description": "Enable pretty-printing for gdb",
                                     "text": "-enable-pretty-printing",
                                     "ignoreFailures": true
                             },
                             {
                                     "description": "Set Disassembly Flavor to Intel",
                                     "text": "-gdb-set disassembly-flavor intel",
                                     "ignoreFailures": true
                             }
                             ]
                     }
                     ]
             }
      

      值的注意的是,为了编译出可调试的版本,在CMake构建项目时,需要额外的参数而不是单纯的 cmake ..

             cmake -DCMAKE_BUILD_TYPE=Debug ..
      

      而 make 和 g++ 则是要 添加 -g

             g++ -g main.cpp -o main
      

About

Basic Emacs configuration for Rust.


Languages

Language:Emacs Lisp 100.0%