Skip to content

Commit a4ed7a4

Browse files
committed
Clean up the indentation config logic
* Converted the type of `clojure-indent-style` to symbol for consistency with Emacs configuration practices. * Removed some legacy code related to clojure-defun-style-default-indent.
1 parent 5dc098d commit a4ed7a4

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
* [#489](https://github.com/clojure-emacs/clojure-mode/issues/489): Inserting parens before comment form doesn't move point.
1515
* [#500](https://github.com/clojure-emacs/clojure-mode/pull/500): Fix project.el integration.
1616

17+
### Changes
18+
19+
* Change the accepted values of `clojure-indent-style` from keywords to symbols.
20+
1721
## 5.9.1 (2018-08-27)
1822

1923
* [#485](https://github.com/clojure-emacs/clojure-mode/issues/485): Fix a regression in `end-f-defun`.

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ want multi-line docstrings to be indented at all (which is pretty common in most
112112
The indentation of function forms is configured by the variable
113113
`clojure-indent-style`. It takes three possible values:
114114

115-
- `:always-align` (the default)
115+
- `always-align` (the default)
116116

117117
```clj
118118
(some-function
@@ -124,7 +124,7 @@ The indentation of function forms is configured by the variable
124124
2)
125125
```
126126

127-
- `:always-indent`
127+
- `always-indent`
128128

129129
```clj
130130
(some-function
@@ -136,7 +136,7 @@ The indentation of function forms is configured by the variable
136136
2)
137137
```
138138

139-
- `:align-arguments`
139+
- `align-arguments`
140140

141141
```clj
142142
(some-function
@@ -148,6 +148,9 @@ The indentation of function forms is configured by the variable
148148
2)
149149
```
150150

151+
**Note:** Prior to clojure-mode 5.10 the configuration options for `clojure-indent-style` used to be
152+
keywords, but now they are symbols. Keywords will still be supported at least until clojure-mode 6.
153+
151154
#### Indentation of macro forms
152155

153156
The indentation of special forms and macros with bodies is controlled via

clojure-mode.el

+23-19
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
;; Artur Malabarba <[email protected]>
1111
;; URL: http://github.com/clojure-emacs/clojure-mode
1212
;; Keywords: languages clojure clojurescript lisp
13-
;; Version: 5.10.0-snapshot
13+
;; Version: 5.10.0
1414
;; Package-Requires: ((emacs "25.1"))
1515

1616
;; This file is not part of GNU Emacs.
@@ -94,7 +94,7 @@
9494
"Face used to font-lock Clojure character literals."
9595
:package-version '(clojure-mode . "3.0.0"))
9696

97-
(defcustom clojure-indent-style :always-align
97+
(defcustom clojure-indent-style 'always-align
9898
"Indentation style to use for function forms and macro forms.
9999
There are two cases of interest configured by this variable.
100100
@@ -112,7 +112,7 @@ already use special indentation rules.
112112
The possible values for this variable are keywords indicating how
113113
to indent function forms.
114114
115-
`:always-align' - Follow the same rules as `lisp-mode'. All
115+
`always-align' - Follow the same rules as `lisp-mode'. All
116116
args are vertically aligned with the first arg in case (A),
117117
and vertically aligned with the function name in case (B).
118118
For instance:
@@ -122,30 +122,27 @@ to indent function forms.
122122
merge
123123
some-coll)
124124
125-
`:always-indent' - All args are indented like a macro body.
125+
`always-indent' - All args are indented like a macro body.
126126
(reduce merge
127127
some-coll)
128128
(reduce
129129
merge
130130
some-coll)
131131
132-
`:align-arguments' - Case (A) is indented like `lisp', and
132+
`align-arguments' - Case (A) is indented like `lisp', and
133133
case (B) is indented like a macro body.
134134
(reduce merge
135135
some-coll)
136136
(reduce
137137
merge
138138
some-coll)"
139-
:safe #'keywordp
140-
:type '(choice (const :tag "Same as `lisp-mode'" :always-align)
141-
(const :tag "Indent like a macro body" :always-indent)
139+
:safe #'symbolp
140+
:type '(choice (const :tag "Same as `lisp-mode'" 'always-align)
141+
(const :tag "Indent like a macro body" 'always-indent)
142142
(const :tag "Indent like a macro body unless first arg is on the same line"
143-
:align-arguments))
143+
'align-arguments))
144144
:package-version '(clojure-mode . "5.2.0"))
145145

146-
(define-obsolete-variable-alias 'clojure-defun-style-default-indent
147-
'clojure-indent-style "5.2.0")
148-
149146
(defcustom clojure-use-backtracking-indent t
150147
"When non-nil, enable context sensitive indentation."
151148
:type 'boolean
@@ -1370,6 +1367,10 @@ spec."
13701367
(let ((function (thing-at-point 'symbol)))
13711368
(clojure--get-indent-method function))))
13721369

1370+
(defun clojure--keyword-to-symbol (keyword)
1371+
"Convert KEYWORD to symbol."
1372+
(intern (substring (symbol-name keyword) 1)))
1373+
13731374
(defun clojure--normal-indent (last-sexp indent-mode)
13741375
"Return the normal indentation column for a sexp.
13751376
Point should be after the open paren of the _enclosing_ sexp, and
@@ -1395,19 +1396,22 @@ accepted by `clojure-indent-style'."
13951396
;; Here we have reached the start of the enclosing sexp (point is now at
13961397
;; the function name), so the behaviour depends on INDENT-MODE and on
13971398
;; whether there's also an argument on this line (case A or B).
1398-
(let ((case-a ; The meaning of case-a is explained in `clojure-indent-style'.
1399+
(let ((indent-mode (if (keywordp indent-mode)
1400+
;; needed for backwards compatibility
1401+
;; as before clojure-mode 5.10 indent-mode was a keyword
1402+
(clojure--keyword-to-symbol indent-mode)
1403+
indent-mode))
1404+
(case-a ; The meaning of case-a is explained in `clojure-indent-style'.
13991405
(and last-sexp-start
14001406
(< last-sexp-start (line-end-position)))))
14011407
(cond
1402-
;; For compatibility with the old `clojure-defun-style-default-indent', any
1403-
;; value other than these 3 is equivalent to `always-body'.
1404-
((not (memq indent-mode '(:always-align :align-arguments nil)))
1408+
((eq indent-mode 'always-indent)
14051409
(+ (current-column) lisp-body-indent -1))
14061410
;; There's an arg after the function name, so align with it.
14071411
(case-a (goto-char last-sexp-start)
14081412
(current-column))
14091413
;; Not same line.
1410-
((eq indent-mode :align-arguments)
1414+
((eq indent-mode 'align-arguments)
14111415
(+ (current-column) lisp-body-indent -1))
14121416
;; Finally, just align with the function name.
14131417
(t (current-column)))))))
@@ -1479,7 +1483,7 @@ This function also returns nil meaning don't specify the indentation."
14791483
(+ lisp-body-indent containing-form-column))
14801484
;; Further non-special args, align with the arg above.
14811485
((> pos (1+ method))
1482-
(clojure--normal-indent last-sexp :always-align))
1486+
(clojure--normal-indent last-sexp 'always-align))
14831487
;; Special arg. Rigidly indent with a large indentation.
14841488
(t
14851489
(+ (* 2 lisp-body-indent) containing-form-column)))))
@@ -1493,7 +1497,7 @@ This function also returns nil meaning don't specify the indentation."
14931497
(cond
14941498
;; Preserve useful alignment of :require (and friends) in `ns' forms.
14951499
((and function (string-match "^:" function))
1496-
(clojure--normal-indent last-sexp :always-align))
1500+
(clojure--normal-indent last-sexp 'always-align))
14971501
;; This should be identical to the :defn above.
14981502
((and function
14991503
(string-match "\\`\\(?:\\S +/\\)?\\(def[a-z]*\\|with-\\)"

test/clojure-mode-indentation-test.el

+5-5
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ values of customisable variables."
5858
(let ((fname (intern (format "indentation/%s" description))))
5959
`(ert-deftest ,fname ()
6060
(let* ((after ,after)
61-
(clojure-indent-style :always-align)
61+
(clojure-indent-style 'always-align)
6262
(expected-cursor-pos (1+ (s-index-of "|" after)))
6363
(expected-state (delete ?| after))
6464
,@var-bindings)
@@ -238,14 +238,14 @@ values of customisable variables."
238238
(declare (indent 1))
239239
(when (stringp style)
240240
(setq forms (cons style forms))
241-
(setq style :always-align))
241+
(setq style 'always-align))
242242
`(ert-deftest ,(intern (format "test-backtracking-%s" name)) ()
243243
(progn
244244
,@(mapcar (lambda (form)
245245
`(with-temp-buffer
246246
(clojure-mode)
247247
(insert "\n" ,(replace-regexp-in-string "\n +" "\n " form))
248-
(let ((clojure-indent-style ,style))
248+
(let ((clojure-indent-style (quote ,style)))
249249
(indent-region (point-min) (point-max)))
250250
(should (equal (buffer-string)
251251
,(concat "\n" form)))))
@@ -463,7 +463,7 @@ x
463463
3))")
464464

465465
(def-full-indent-test align-arguments
466-
:align-arguments
466+
'align-arguments
467467
"(some-function
468468
10
469469
1
@@ -473,7 +473,7 @@ x
473473
2)")
474474

475475
(def-full-indent-test always-indent
476-
:always-indent
476+
'always-indent
477477
"(some-function
478478
10
479479
1

0 commit comments

Comments
 (0)