clojure-mode icon indicating copy to clipboard operation
clojure-mode copied to clipboard

How to define-clojure-indent on all keywords at once?

Open raxod502 opened this issue 8 years ago • 4 comments

It looks like define-clojure-indent (and put-clojure-indent) only allow defining the indentation rules for individual symbols. I wish for all keywords to be indented like this:

(:keyword
  map)

Unfortunately, there seems to be no way to do that except by listing every possible keyword explicitly:

(define-clojure-indent
  (:import 0)
  (:require 0)
  ... lots more ...
  (:use 0))

The problems with that approach are obvious, I think.

Since this isn't a bug report, I don't think environment information will be helpful (although I install the latest versions of my Emacs packages from MELPA). I am happy to report such information if need be, though.

raxod502 avatar Dec 15 '16 18:12 raxod502

There's a variable for general indentation behaviour. See https://github.com/clojure-emacs/clojure-mode/blob/master/README.md#indentation-of-function-forms It looks like what you want is to set it to always-indent.

However, the specific define-clojure-indent still take precedence over the generic variable, so you may still need to do the following for every symbol already defined in clojure-mode.el.

(define-clojure-indent
  (:import nil)) 

Malabarba avatar Dec 16 '16 10:12 Malabarba

I actually want clojure-indent-style to be set at :align-arguments. The problem is that keywords don't seem to be recognized as function forms—perhaps intentionally?

raxod502 avatar Dec 16 '16 14:12 raxod502

I also noticed this just today when someone complained on a PR of mine. The difference I believe @raxod502 is talking about can be seen where :align-arguments is configured, and (for example) this happens:

;; what I expect
(get
  {:my-key "some value"} :my-key)

;; what I don't expect
(:my-key
 {:my-key "some value"})

;; what I think it should do
(:my-key
  {:my-key "some value"})

Is this behaviour intended?

j0ni avatar Oct 26 '17 19:10 j0ni

Nope, we just didn't think of this scenario. PRs welcome!

bbatsov avatar Sep 25 '18 03:09 bbatsov