Trying out Emacs
I've been using Emacs for 1 year and 8 months(ever since I become a developer) and I think Emacs is an awesome editor. Although people may feel it's not so friendly for beginners who are unfamiliar with such kind of old-school text editor(indeed Emacs is more than 40-year-old ), I'll say no pain no gain. Not only your coding efficiency will be improved, but also complexities for workflows such as Deployment will be tremendously reduced.
Here I'm going to introduce some of my favorite packages in Emacs. You can enjoy them without having a good knowledge of Lisp.
Magit
Magit is a great interface for git. It helps me get rid of the long-heavy-difficult git commands.
install
M-x package-refresh-contents RET
M-x package-install RET magit RET
usage
You can check the usages by M-x magit-status
to enter the status buffer, then h
to see the key-bindings for git commands.
For example, if you want to do a cherry-pick, it really easy in Magit:
M-x magit-status
-
A
, you'll buffer with cherry-pick subcommands like this:
-
A
, it'll ask for the commit id to be picked:
- Paste the commit id and then
RET
If you want to view the raw git commands, M-x magit-process-buffer
. There are records for each git command and its status done in Magit.
lsp-mode
Before using lsp-mode
, I was using GTag and CTag for C++ development. I'm forced to switch to lsp because I started to develop in Rust and lsp appears as the only reliable code navigation plugin(at least for Emacs), which turns out far beyond my expectation.
install
I've had a painful time to get lsp-mode
installed for various reasons.
- If you are using Emacs 26.3, things will be easy.
- If you are using Emacs 26.2 and behind a proxy, you may come up with authentication errors. There is a workaround https://www.reddit.com/r/emacs/comments/3cfk3f/setting_proxy/.
M-x package-install RET lsp-mode RET
usage
- Code navigation:
lsp-find-definition
is one of the most impressive features is code navigation. Take Rust for example, not only within the crate, but also the external crate, which is really helpful because you don't need to search for the document in browser. It'll take you to the source code directly. - Real-time Diagnostics/linting:
M-x package-install RET flycheck RET
counsel-tramp
tramp
a remote file editing package for Emacs which I heavily rely on when edit config files on servers. But please take care when you operate as sudo
.
install
M-x package-install counsel-tramp
usage
- add server host name in your
~/.ssh/config
M-x counsel-tramp
- choose the server in the list. it's something like
/ssh:test-hostname1:
or/ssh:test-hostname1|sudo:root@test-hostname1:/
- then you can edit files on
test-hostname1
on your local Emacs.
Conclusion
There are many other excellent packages I haven't introduced, maybe I'll introduce more of them in other posts.
-
magit
: a must-have mode if you use git in your workflow. -
lsp-mode
: provide easy-to-use code navigation, real-time diagnostics, formatting etc. -
counsel-tramp
: a great tool for editing remote files.