1

I want to inspect the lisp code that handle auto-indentation. By "auto-indent" I mean the indentation that automatically puts the beginning of a line at the right position in files such as .c, .cpp, and .java.

How do I find the code?

Dan
  • 32,584
  • 6
  • 98
  • 168
Igorzovisk
  • 121
  • 1

1 Answers1

2

To query the value of a variable or function in Emacs, you can use the default keybindings of C-h v VARIABLE and C-h f FUNCTION, respectively. If you're not sure what to look for, M-x apropos SOMETHING will help you look for functions and variables that contain SOMETHING in their names.

In your case, look up the variable indent-line-function, whose docstring reads:

Documentation: Function to indent the current line. This function will be called with no arguments. If it is called somewhere where auto-indentation cannot be done (e.g. inside a string), the function should simply return noindent. Setting this function is all you need to make TAB indent appropriately. Don't rebind TAB unless you really need to.

That variable will tell you which function to inspect. For example, in lisp-interaction-mode (i.e., the default mode in the *scratch* buffer), the value is lisp-indent-line. The help window should be hyperlinked, and, at the top, it will tell you:

lisp-indent-line is an interactive compiled Lisp function in lisp-mode.el. ...

You should be able to click on lisp-mode.el, and Emacs will open up that file at the function in question.

Dan
  • 32,584
  • 6
  • 98
  • 168