clojure-emacs / clojure-emacs/clojure-mode

Better way to maintain custom indentation

Abierto
#464 5 comentarios 1 reacción 0 asignados Ver en GitHub
feature request help wanted
Lenguaje dominante
Emacs Lisp
Estrellas
1k
Forks
249
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

## Problem

Sometimes, it is desirable to indent specific forms in a non-standard(?) way. Below is a couple of use-case exhibit to better illustrate the issue.
```clojure
;;;; om

;; default
(dom/div #js{:className "container"}
(dom/ul #js{:className "list"}
(dom/li #js{:className "item"} "Hello")))

;; better
(dom/div #js{:className "container"}
(dom/ul #js{:className "list"}
(dom/li #js{:className "item"} "Hello")))

;; this is ok too?
(dom/div #js{:className "container"}
(dom/ul #js{:className "list"}
(dom/li #js{:className "item"} "Hello")))

;;;; re-frame

;; default
(reg-cofx :now
(fn [cofx _]
(assoc cofx :now (js/Date.))))

;; better
(reg-cofx :now
(fn [cofx _]
(assoc cofx :now (js/Date.))))

;;;; Fulcro

;; default
(defmutation something
"docstring"
[args]
(action [{:keys [state]}]
(do-something-to state))
(remote [env]
(some-logic env)))

;; better
(defmutation something
"docstring"
[args]
(action [{:keys [state]}]
(do-something-to state))
(remote [env]
(some-logic env)))
```

## Current Solutions

Currently, the most practical solution is to maintain individual/per-project list of symbol-indentation lookup table. A relatively small example is shown below, but imagine that for `om`, one would need to list every single dom element in the file.
https://github.com/metabase/metabase/blob/master/.dir-locals.el

## Other Solutions

This issue has been reported a couple times in the past and some suggestions have been voiced and/or implemented, but I feel that we have not really solved this problem.

https://github.com/clojure-emacs/clojure-mode/issues/398
The idea here is to infer indentation based on arg list. The concern was that it is unreliable.

https://github.com/clojure-emacs/clojure-mode/issues/309
Metadata based indentation is technically a good solution. This requires buy-in from library maintainer and at least in one case was shot down as seen here https://github.com/omcljs/om/issues/728 . These are Cognitect staff, so I feel it will be very unlikely we will be getting any metadata support in core libraries. I speculate that quite a number of library authors and Cognitect staffs are using Cursive and simply don't have this problem.

## Proposed Solutions

Maybe we can brainstorm for a better way to handle this?
- Maybe an option that allow user to override indentation and trigger auto-indent of current form with a keystroke?
- Shorten the symbol lookup table by allowing regex pattern matching?
- Infer indentation based on other uses in the project/file? User will only have to fix indentation once and emacs will try to conform to the file's current indentation rule. Not sure what to do if there is only one use in a project/file.
- I'm sure clojure-mode users will have other ideas?

Thank you for contributing!

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Start by reviewing the indentation examples in the issue, the referenced .dir-locals.el configuration, and the linked discussions in issues 398 and 309. The work is not yet scoped to a specific entry point or test; it would first need an agreed mechanism and clear acceptance criteria for custom indentation.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
clojure, emacs-lisp
Área
tooling
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.