Fork me on GitHub
#emacs
<
2020-09-17
>
Chris22:09:34

Hi guys, I switched from doom emacs to building my own emacs from the ground up. Today I set up everything related to Clojure. However, somehow clojure-mode won‘t allow my to indent code by myself when I press TAB. The reason why I believe clojure-mode is causing this is because after removing clojure-mode I was able to use TAB again. Has anybody encountered that? Is this standard behavior? Because in doom emacs it was possible to manually indent with TAB in clojure source files. I‘m using evil-mode as well in case that‘s related to this issue.

dpsutton22:09:29

to find out what command is run by a keybinding, try C-c h tab. for me its company-indent-or-complete-common. personally i wouldn't want to indent with tab as newlines should already be correctly aligned. and for formatting i hit M-q to format the current top level form

Chris22:09:24

For me that is the command: indent-for-tab-command

dpsutton22:09:14

and that's not indenting?

Chris22:09:05

No, but only in Clojure source files. When I try to TAB on an empty line then nothing happens.

dpsutton22:09:25

and if you disable clojure-mode can you indent?

Chris22:09:45

Yes, I tried to delete clojure mode and afterwards it works

dpsutton22:09:03

i was thinking with just m-x clojure-mode would turn it off

dpsutton22:09:23

is it the same function when clojure-mode is enabled?

dpsutton22:09:43

C-c h tab with clojure-mode is the same as a non-clojure mode buffer?

Chris22:09:45

Yes, they are the same ... hmm

dpsutton22:09:03

ok. so i did C-h f indent-for-tab-command and it mentions > The function called to actually indent the line or insert a tab is given by the variable ‘indent-line-function’.

dpsutton22:09:16

and in clojure-mode this is

(defun clojure-indent-line ()
  "Indent current line as Clojure code."
  (if (clojure-in-docstring-p)
      (save-excursion
        (beginning-of-line)
        (when (and (looking-at "^\\s-*")
                   (<= (string-width (match-string-no-properties 0))
                       (string-width (clojure-docstring-fill-prefix))))
          (replace-match (clojure-docstring-fill-prefix))))
    (lisp-indent-line)))

Chris22:09:29

Does that mean that actually „lisp-indent-line“ is called when outside of docstrings ?

dpsutton22:09:49

yes exactly

Chris22:09:27

I see! Thanks! I already spent quite some time on that, thanks to you I have a new direction which I can check.

dpsutton22:09:08

can you post a form with | where your cursor is and what the form looks like before you indent it?

Chris23:09:54

I don‘t completely understand. At the moment I can‘t do any indentation by myself

dpsutton23:09:19

for instance, when i type

(let [thing 1])
when i press enter after the 1 i get it automatically indented
(let [thing 1
      <cursor>])

dpsutton23:09:33

i don't indent anything, it just indents for me

Chris23:09:41

Oh yes, that works quite well for me too

dpsutton23:09:59

yeah. so i was wondering how you get into a state where indentation is necessary

dpsutton23:09:24

and if i erase all of the spaces introduced for me and hit tab, it indents it back to the correct level

Chris23:09:15

Maybe it is a bad habit. But sometimes I am in this situation:

(defn some-fn)
|

dpsutton23:09:49

to me the only valid indentation level there is against the margin where your cursor is

Chris23:09:25

Then I would press TAB and enter [] and parinfer would put the end parentheses from above to the next line

dpsutton23:09:07

oh i see. i never use parinfer but i can see why its not indenting. not sure how to help you with that though

Chris23:09:53

I probably should just get used to the automatic indentation, seems to be generally a better way of writing Clojure

Chris23:09:13

Thanks for your help !