Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Last active March 15, 2018 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amirrajan/46aa41fa79401dd22fc36e55ccb40d41 to your computer and use it in GitHub Desktop.
Save amirrajan/46aa41fa79401dd22fc36e55ccb40d41 to your computer and use it in GitHub Desktop.

How to determine what happens when you press a key (in this case ENTER). And by extension why Emacs' introspection capabilities are so awesome.

Step 1:

Make sure you are in ruby-mode. You can use the following command to determine what mode you are in:

:describe-mode

If you're not using Evil mode, then:

M-x describe-mode

"Meta X" is invoked by pressing option+x on the Mac. Note: Even with Evil mode, you need to know how to invoke a command through Meta X. So memorize this key.

Step 2:

Once you have verified that you are in ruby-mode type:

def hello

Your cursor should be right after the o in hello.

Step 3:

Here is the coup de gra. Go into Evil's insert mode (if you're not already). Press Option+x, then type describe-key. Again, it is important that you are in insert mode so that you get the correct information.

You will be prompted with the following in the mini buffer:

Describe key (or click or menu item):

Press the enter key. At which point you will get something like this:

RET runs the command newline-and-indent (found in global-map), which
is an interactive compiled Lisp function in ‘simple.el’.

It is bound to RET.

(newline-and-indent)

Insert a newline, then indent according to major mode.
Indentation is done using the value of ‘indent-line-function’.
In programming language modes, this is the same as TAB.
In some text modes, where TAB inserts a tab, this command indents to the
column specified by the function ‘current-left-margin’.

[back]

So for correct indentation, you want to make sure that newline-and-indent is actually called.

From this screen you can navigate through the values, through some of the docs, even source code to figure out why it isn't working.

Watch the short screen capture: https://s3.us-east-2.amazonaws.com/amirrajan/streams/describe-key.mp4

I get stuck on the "customize variable screen"... I forgot to press "q" to quit that screen outside of a textbox... god I hate Emacs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment