Implementation of code symbol search jump in Emacs based on opengrok

Time:2021-4-11

background

I’ve been busy for a long time and haven’t written anything. Today I’ll introduce an Emacs script that I did before. In the company, we mainly use C + + as the production language, and usually use Mac to work, but the code development is on the remote server. The company’s code is extremely huge, which is not inferior to the Linux kernel code, and the source code level depends on dozens of projects. As an old user of spacemacs, I usually use it as the main production tool. Although the source code is on the remote server, I still use the spacemacs with GUI on the local MAC for development. Through oxfs, it is very easy to hook the file system on the server to the local for development without jamming.

In the development process, in order to have a better code jump experience, I tried grep, ripgrep, cscope, cquery, and CCLS, which are not easy to use in my remote development mode. Either the search is inaccurate, or it is too slow, or it is difficult to capture the compiled database of clang. The version of scons used by the company is too old, and it is not easy to upgrade. It’s better to be able to handle it with a few orders. That’s what I want.

opengrok

As soon as I have time, I will go to search for a better plan to see if everyone has one. By chance, I found opengrok and looked at the home page of the project to compare the similar tools. It’s really amazing.

Provides function definition, reference search, full-text search, file search, and even Web UI, browse the source code directly through the browser, and jump at will. It’s very convenient. The last picture gives you a feeling.



At the beginning, I used opengrok to browse some unfamiliar code. When writing code, I used it to find some dependent function definitions, view parameters, etc., which was quite convenient. After a long time, I still feel troublesome. If only I could jump the shortcut key in spacemacs. With this idea, we should first investigate whether others have done similar things. After several rounds of Google, some people have made Emacs adapt to opengrok, and the only thing that can be used is basically Emacs eopengrok.el The project encapsulates the opengrok command line in Emacs to achieve the functions I want.

There is a fatal problem. The code I edited is on the remote development machine. Opengrok must be deployed on the development machine. It’s troublesome for me to call the opengrok command on the development machine locally. I have to write conversion scripts to solve the problems of inconsistent directories at both ends. In addition, opengrok is developed based on Java, and all kinds of environments on the development machine are old and not easy to move, which is really troublesome.

opengrok-restful

When I failed, I found that opengrok provided restful API. Suddenly, I thought that Emacs could interact with opengrok directly by using restful API. When I searched for symbols and definitions locally, I only interacted with the developer once through HTTP, which was too clear and simple.

After a period of violent development, it can be basically formed and used. The project has submitted the code to GitHub. I hope that interested children’s shoes can also try to use it~

https://github.com/RainMark/opengrok-restful

At present, the basic implementation of the various projects between the project search, symbol definition, reference, file search, personal usual use feeling is OK, take a look at the previous figure.


Recommended Today

Review of SQL Sever basic command

catalogue preface Installation of virtual machine Commands and operations Basic command syntax Case sensitive SQL keyword and function name Column and Index Names alias Too long to see? Space Database connection Connection of SSMS Connection of command line Database operation establish delete constraint integrity constraint Common constraints NOT NULL UNIQUE PRIMARY KEY FOREIGN KEY DEFAULT […]