Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

EDN lists indented function style #610

Copy link
Copy link
Open
@ryantate

Description

@ryantate
Issue body actions

Expected behavior

When editing an EDN buffer (file ending .edn), clojure mode should treat all paren forms as lists rather than functions, since EDN is a data format.

Thus if you choose to format a list with, say, key-value style pairs, default indentation should Just Work, like for vectors:

(:key1 :value1
 :key2 :value2
 :key3 :value3)

Actual behavior

EDN buffers are treated like Clojure code. Though this is mostly correct, it indents list contents like function calls rather than lists when each line contains more than 1 item:

(:key1 :value1
       :key2 :value2
       :key3 :value3)

I don't see any configuration vars to change this behavior. There are options for functional indent style, but no buffer-local way to redefine what is classified as a function (that I can see). All the function indent styles will keep the keys from lining up as they would in a vector, map, etc.

Steps to reproduce the problem

Find new file, /tmp/foo.edn. Type one of the above forms.

Workaround

I work around this by redefining a function in my init.el. Only the string-match clause in the or is new:

(require 'clojure-mode)
(defun clojure--not-function-form-p ()
  "Non-nil if form at point doesn't represent a function call."
  (or (string-match "\\.edn$" (or (buffer-file-name) (buffer-name)))
      (member (char-after) '(?\[ ?\{))
      (save-excursion ;; Catch #?@ (:cljs ...)
        (skip-chars-backward "\r\n[:blank:]")
        (when (eq (char-before) ?@)
          (forward-char -1))
        (and (eq (char-before) ?\?)
             (eq (char-before (1- (point))) ?\#)))
      ;; Car of form is not a symbol.
      (not (looking-at ".\\(?:\\sw\\|\\s_\\)"))))

Environment & Version information

clojure-mode version

clojure-mode (version 5.13.0)

Emacs version

GNU Emacs 27.2 (build 1, x86_64-redhat-linux-gnu, GTK+ Version 3.24.30, cairo version 1.17.4)
of 2021-08-07

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.