Better way to maintain custom indentation

オープン
#464 コメント 5 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
clojure, emacs-lisp
領域
tooling

調査の方向性

まず、issue 内のインデント例、参照されている .dir-locals.el 設定、および issue 398 と 309 にリンクされた議論を確認します。作業はまだ特定のエントリーポイントやテストに範囲を限定されていないため、まずカスタムインデントのための合意された仕組みと明確な受け入れ基準が必要です。

索引モデルが issue の本文から書いたものです。

説明

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!

主要言語
Emacs Lisp
スター
1k
フォーク
249
平均マージ
1日 6時間
マージ済み PR(30日)
6

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

clojure-emacs/clojure-mode のほかの issue

clojure-emacs/clojure-mode の issue をすべて見る

似ている issue

DevTools の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。