Using Emacs as an IDE

后端 未结 18 1736
清酒与你
清酒与你 2020-11-29 14:29

Currently my workflow with Emacs when I am coding in C or C++ involves three windows. The largest on the right contains the file I am working with. The left is split into

相关标签:
18条回答
  • 2020-11-29 15:07

    There are corners of emacs that once discovered make you more productive in ways you never thought of. As others have mentioned, using tags is a fantastic and fast way to zoom around your source code and using M-/ (dabbrev-expand) often does exactly what you expect when completing a variable name.

    Using occur is useful to get a buffer with all occurences of a regular expression in a buffer. That's really handy when refactoring code and looking for fragments of code or uses of variables, or if you use TODO markers in your source files and you want to visit them all.

    flush-lines, sort-numeric-fields, replace-regexp and rectangle functions can be really useful for taking a dump from some tool and converting it to useful data such as an elisp program or a comma delimited spreadsheet.

    I wrote a page about IDE like things you can do with emacs

    http://justinsboringpage.blogspot.com/2007/09/11-visual-studio-tricks-in-emacs.html

    Learning elisp is a another great way to answer for yourself what else emacs can do beyond what a typical IDE can do.

    For example I've blogged about writing Perforce helper functions like blame (writing your own means you can make it behave exactly as you want)...

    http://justinsboringpage.blogspot.com/2009/01/who-changed-line-your-working-on-last.html

    I've also written code that dynamically creates comments for a function at point, that matches the coding standards I'm working with.

    None of my elisp code is particularly great, and most of it exists already in libraries, but it's really useful to be able to make emacs do custom stuff that just comes up during a working day.

    0 讨论(0)
  • 2020-11-29 15:09

    Okay, everyone here is giving perfect hints to make emacs a great IDE.

    But anyone should keep in mind that, when you customize your emacs with a lot of extension (especially with the ones for type-checking on the fly, function definition lookups etc) your emacs will load very, very slow for an editor.

    To workaround this, I would highly recommend to use emacs in server mode.

    It is pretty simple to use, no need to customize your init file. You just need to start emacs in daemon mode;

    emacs --daemon
    

    This will create an emacs server, then you can connect it either from terminal, or from gui. I'd also recommend to create some aliases to make it easy to call.

    alias ec="emacsclient -t"
    alias ecc="emacsclient -c &"
    # some people also prefer this but no need to fight here;
    alias vi="emacsclient -t"
    

    This way, emacs will fire up even faster than gedit, promise.

    The one possible problem here, if you are running emacs daemon from your casual user, you probably can't connect emacs server as root.

    So, if you need to open a file that has root access; use tramp instead. Just run your emacs client with your normal user and open files like this;

    C-x C-f
    /sudo:root@localhost/some/file/that/has/root/access/permissions
    # on some linux distro it might be `/su:root@...` 
    

    This made my life easier, I can open my heavy customized python IDE in miliseconds this way. You may also want to add emacs --daemon to your system startup, or create a desktop file for emacsclient. Thats up to you.

    More on emacs daemon and emacs client can be found at wiki;

    http://www.emacswiki.org/emacs/EmacsAsDaemon

    http://www.emacswiki.org/emacs/EmacsClient

    0 讨论(0)
  • 2020-11-29 15:10

    In the recent years, Clang became an important part of the Emacs C++ support. Atila Neves had a talk on CppCon 2015: "Emacs as a C++ IDE"

    It is a 16 minute talk, where he shows solutions for the following topics:

    • Jump to definition
    • Auto-completion
    • On-the-fly syntax highlighting
    • Find file in project

    Slides can be found here.

    0 讨论(0)
  • 2020-11-29 15:15

    For version control, there are several things that you can use, depending on what version control system you use. But some of the functionality is common to all of them.

    vc.el is the built-in way to handle version control at a file level. It has backends for most version control systems. For instance, the Subversion backend comes with Emacs, and there are git backends and others available from other sources.

    The most useful command is C-x v v (vc-next-action) that does the appropriate next action for the file you are visiting. This might mean updating from the repository or commiting your changes, vc.el also rebinds C-x C-q to check in and out files if you are using a system that needs it (like RCS).

    Other very useful commands are C-x v l and C-x v = that show you the log and current diff for the file you are using.

    But for real productivity, you should avoid using the single-file vc.el commands other than for simple things. There are several packages that can give you an overview of the status of your whole tree, and give you more power, and not to mention the ability to create coherent commits spanning several files.

    Most of these are heavily influenced or based on the original pcl-cvs/pcvs for CVS. There are even two of them that comes with subversion, psvn.el and dsvn.el. There are packages for git etc.

    0 讨论(0)
  • 2020-11-29 15:15

    A starting point (which may be non-obvious) for exploring the VC features of Emacs is M-x vc-next-action.

    It does the "next logical version control operation" on the current file, depending on the state of the file and the VC backend. So if the file is not under version control, it registers it, if the file has been changed, the changes are submitted etc.

    It takes a little getting used to, but I find it very useful.

    Default keybinding is C-x v v

    0 讨论(0)
  • 2020-11-29 15:15

    Try lsp-mode. Now you can use other IDE functionality inside emacs connecting to server. Look for more info: lsp-mode

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