Better way to maintain custom indentation

Ouverte
#464 5 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
25/100
Type d'issue
Fonctionnalité
Clarté
À clarifier
Activité
À l'abandon
Stack technique
clojure, emacs-lisp
Domaine
tooling

Piste de recherche

Commencez par examiner les exemples d’indentation dans l’issue, la configuration .dir-locals.el référencée et les discussions liées dans les issues 398 et 309. Le travail n’est pas encore cadré autour d’un point d’entrée ou d’un test précis ; il faudrait d’abord convenir d’un mécanisme et de critères d’acceptation clairs pour l’indentation personnalisée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

feature request help wanted

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.

;;;; 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!

Langage dominant
Emacs Lisp
Étoiles
1k
Forks
249
Merge moyen
1 j 6 h
PR mergées (30 j)
6

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de clojure-emacs/clojure-mode

Toutes les issues de clojure-emacs/clojure-mode

Issues similaires

Plus d'issues DevTools

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.