Doom-emacs: [REQUEST] Standardized hot-key for common command for all/most languages

Created on 20 Sep 2019  ·  2Comments  ·  Source: hlissner/doom-emacs

Describe the feature
A shared/standardized set of key binding for common commands/operation of different language major mode (e.g. jump-to-definition, jump-back, compile, run, evaluate)

Status Quo
Currently, each language has its own key binding, e.g:

  • for TypeScript: C-c C-t is bound to tide-jump-to-definition ; C-t is bound to jump-back to previously marked buffer
  • for Golang: C-c C-j is bind to godef-jump; C-o is bound to jump-back to previously marked buffer
  • for Rust: no hot key defined for racer-find-definition

Wish list
Ideally, developers should not have to remember different sets of hot keys for different languages, and it would be nice to

  1. standardize the binding
  2. expose customization interface for devs to change those command to hot-key of their own choices (idk, if they come from vscode, then they might already get used to some hotkeys)

caveats
As for downside of this is that this standardization layer might cause conflicts in hot keys with the native language.el, so would be nice to have a pop-up buffer for resolving conflict if accidentally customize the bindings into one.

question keybinds resolved

Most helpful comment

A standard already exists for many of these commands, defined in the :config (default +bindings) module. Most of them are available under the leader prefix (which is SPC for evil users and C-c for non-evil users). Here are a few of them:

For evil users (scheme inspired by vim conventions)

  • Goto definition: gd (or SPC c d) -- this will invoke racer-find-definition in rust, godef-jump in go, tide-jump-to-definition in typescript, and so on. They will also fall back to more naive backends, if those fail.
  • Goto references: gD (or SPC c D)
  • Look up documentation: K (or SPC c k)
  • Jump forward/back in jumplist: C-i / C-o (ala the vim jumplist)
  • Evaluate code: gr (operator), gR (from normal mode, this evaluates the buffer. From visual mode, it replaces the selection with its return value)
  • Compile: there's SPC c c for compile and SPC p c for projectile-compile. The former runs the compile command in the current directory, and the latter runs it in the project's root.

Source

For non-evil users:

  • Goto definition: C-c g d -- this will invoke racer-find-definition in rust, godef-jump in go, tide-jump-to-definition in typescript, and so on. They will also fall back to more naive backends, if those fail.
  • Goto references: C-c g D
  • Look up documentation: C-c g k
  • Jump back in jumplist: M-, (this is an Emacs default, as far as I know, there is no jump forward, however. I'm open to suggestions for places to bind better-jump-forward -- we use the better-jump package to provide a universal jumplist)
  • Evaluate code: C-c e (evaluates line or region)
  • Compile: C-c p c = projectile-compile (C-c p is the prefix for project commands)

Source


I apologize there isn't much documentation on the matter (I'm working on it), but there are many more; more than I can list here.

All 2 comments

A standard already exists for many of these commands, defined in the :config (default +bindings) module. Most of them are available under the leader prefix (which is SPC for evil users and C-c for non-evil users). Here are a few of them:

For evil users (scheme inspired by vim conventions)

  • Goto definition: gd (or SPC c d) -- this will invoke racer-find-definition in rust, godef-jump in go, tide-jump-to-definition in typescript, and so on. They will also fall back to more naive backends, if those fail.
  • Goto references: gD (or SPC c D)
  • Look up documentation: K (or SPC c k)
  • Jump forward/back in jumplist: C-i / C-o (ala the vim jumplist)
  • Evaluate code: gr (operator), gR (from normal mode, this evaluates the buffer. From visual mode, it replaces the selection with its return value)
  • Compile: there's SPC c c for compile and SPC p c for projectile-compile. The former runs the compile command in the current directory, and the latter runs it in the project's root.

Source

For non-evil users:

  • Goto definition: C-c g d -- this will invoke racer-find-definition in rust, godef-jump in go, tide-jump-to-definition in typescript, and so on. They will also fall back to more naive backends, if those fail.
  • Goto references: C-c g D
  • Look up documentation: C-c g k
  • Jump back in jumplist: M-, (this is an Emacs default, as far as I know, there is no jump forward, however. I'm open to suggestions for places to bind better-jump-forward -- we use the better-jump package to provide a universal jumplist)
  • Evaluate code: C-c e (evaluates line or region)
  • Compile: C-c p c = projectile-compile (C-c p is the prefix for project commands)

Source


I apologize there isn't much documentation on the matter (I'm working on it), but there are many more; more than I can list here.

Ah, I forgot to talk about customizing your own keybinds. Emacs provides a library for doing so that you can use from ~/.doom.d/config.el, such as define-key KEYMAP KEY DEFINITION, e.g.

(after! elisp-mode  ; run this code after the elisp-mode package is loaded
  (define-key emacs-lisp-mode-map "x" #'dosomething))

Doom also provides the map! macro to make things a little easier, particularly for evil users.

(map! :after python   ; binds these after the python package has loaded
      :map python-mode-map
      "x" #'dosomething
      "y" #'dosomethingelse
      "z" #'anotherthing)

You can find documentation on these with SPC h f <functionname> (or C-h f <functionname> for non-evil users). The documentation buffer will include examples on how to use them and links to their definition.

You can also find out what's bound to a key sequence with SPC h k <keysequence> or C-h k <keysequence>.

Hope that helps!

Was this page helpful?
0 / 5 - 0 ratings