How can I refactor C++ source code using emacs?

前端 未结 9 786
孤独总比滥情好
孤独总比滥情好 2021-01-30 06:34

I\'m interested mostly in C++ and method/class name/signature automatic changes.

相关标签:
9条回答
  • 2021-01-30 07:25

    I've been using cquery for my C++ completion which uses Microsoft LSP for IDE <-> Tool communication. cquery server satisfies the requests of the LSP protocol using a clang backend.

    lsp-emacs is the package that sits between emacs and the cquery backend (cquery-emacs) which exposes an lsp-rename function. As a completion system, cquery has been very reliable and fast by the way, highly recommended.

    Give it a try, follow the getting-started guide on the cquery github: https://github.com/cquery-project/cquery/wiki/Emacs

    Once you've got cquery setup:

    1. Hover your cursor over an identifier (class, var, whatever) you'd like to rename.
    2. M-x lsp-rename
    3. Enter the new name for the identifier.
    4. Do C-x s (save some buffers), which will prompt you to save all the buffers that were touched by the refactor.

    You should probably go through all modified buffers and check what was done after refactoring with any tool/language.

    0 讨论(0)
  • 2021-01-30 07:26

    I totally agree that find-and-replace work fine. However , a really nice feature of cedet is 'semantic-symref-list'.

    With the cursor on a method, run this command, and you will be presented with a buffer that lists all of the places in your code that reference this tag.

    You can still use find-and-replace tricks, and this will confirm that you have changed all the references.

    0 讨论(0)
  • 2021-01-30 07:30

    For somewhere in between refactoring tools and simple regex, since Emacs 22 you can embed arbitrary elisp expressions in your replacement text, which allows you to do incredibly powerful text manipulation. Steve Yegge wrote a good article on this a while ago.

    0 讨论(0)
提交回复
热议问题