summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBozhidar Batsov <bozhidar@batsov.com>2019-01-05 12:43:13 +0200
committerBozhidar Batsov <bozhidar@batsov.com>2019-01-05 12:43:13 +0200
commita4ed7a4152f8a6514dd3fd82532aa5a2bdba024f (patch)
tree7e10afdc18ed798a82d46598bcf2c0fc2e60e04d
parent5dc098d240041611bde1a24e4ee4dacac22bc595 (diff)
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.
-rw-r--r--CHANGELOG.md4
-rw-r--r--README.md9
-rw-r--r--clojure-mode.el42
-rw-r--r--test/clojure-mode-indentation-test.el10
4 files changed, 38 insertions, 27 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc07489..d9d21fc 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,10 @@
* [#489](https://github.com/clojure-emacs/clojure-mode/issues/489): Inserting parens before comment form doesn't move point.
* [#500](https://github.com/clojure-emacs/clojure-mode/pull/500): Fix project.el integration.
+### Changes
+
+* Change the accepted values of `clojure-indent-style` from keywords to symbols.
+
## 5.9.1 (2018-08-27)
* [#485](https://github.com/clojure-emacs/clojure-mode/issues/485): Fix a regression in `end-f-defun`.
diff --git a/README.md b/README.md
index 867983f..a229119 100644
--- a/README.md
+++ b/README.md
@@ -112,7 +112,7 @@ want multi-line docstrings to be indented at all (which is pretty common in most
The indentation of function forms is configured by the variable
`clojure-indent-style`. It takes three possible values:
-- `:always-align` (the default)
+- `always-align` (the default)
```clj
(some-function
@@ -124,7 +124,7 @@ The indentation of function forms is configured by the variable
2)
```
-- `:always-indent`
+- `always-indent`
```clj
(some-function
@@ -136,7 +136,7 @@ The indentation of function forms is configured by the variable
2)
```
-- `:align-arguments`
+- `align-arguments`
```clj
(some-function
@@ -148,6 +148,9 @@ The indentation of function forms is configured by the variable
2)
```
+**Note:** Prior to clojure-mode 5.10 the configuration options for `clojure-indent-style` used to be
+keywords, but now they are symbols. Keywords will still be supported at least until clojure-mode 6.
+
#### Indentation of macro forms
The indentation of special forms and macros with bodies is controlled via
diff --git a/clojure-mode.el b/clojure-mode.el
index add3381..7940b80 100644
--- a/clojure-mode.el
+++ b/clojure-mode.el
@@ -10,7 +10,7 @@
;; Artur Malabarba <bruce.connor.am@gmail.com>
;; URL: http://github.com/clojure-emacs/clojure-mode
;; Keywords: languages clojure clojurescript lisp
-;; Version: 5.10.0-snapshot
+;; Version: 5.10.0
;; Package-Requires: ((emacs "25.1"))
;; This file is not part of GNU Emacs.
@@ -94,7 +94,7 @@
"Face used to font-lock Clojure character literals."
:package-version '(clojure-mode . "3.0.0"))
-(defcustom clojure-indent-style :always-align
+(defcustom clojure-indent-style 'always-align
"Indentation style to use for function forms and macro forms.
There are two cases of interest configured by this variable.
@@ -112,7 +112,7 @@ already use special indentation rules.
The possible values for this variable are keywords indicating how
to indent function forms.
- `:always-align' - Follow the same rules as `lisp-mode'. All
+ `always-align' - Follow the same rules as `lisp-mode'. All
args are vertically aligned with the first arg in case (A),
and vertically aligned with the function name in case (B).
For instance:
@@ -122,30 +122,27 @@ to indent function forms.
merge
some-coll)
- `:always-indent' - All args are indented like a macro body.
+ `always-indent' - All args are indented like a macro body.
(reduce merge
some-coll)
(reduce
merge
some-coll)
- `:align-arguments' - Case (A) is indented like `lisp', and
+ `align-arguments' - Case (A) is indented like `lisp', and
case (B) is indented like a macro body.
(reduce merge
some-coll)
(reduce
merge
some-coll)"
- :safe #'keywordp
- :type '(choice (const :tag "Same as `lisp-mode'" :always-align)
- (const :tag "Indent like a macro body" :always-indent)
+ :safe #'symbolp
+ :type '(choice (const :tag "Same as `lisp-mode'" 'always-align)
+ (const :tag "Indent like a macro body" 'always-indent)
(const :tag "Indent like a macro body unless first arg is on the same line"
- :align-arguments))
+ 'align-arguments))
:package-version '(clojure-mode . "5.2.0"))
-(define-obsolete-variable-alias 'clojure-defun-style-default-indent
- 'clojure-indent-style "5.2.0")
-
(defcustom clojure-use-backtracking-indent t
"When non-nil, enable context sensitive indentation."
:type 'boolean
@@ -1370,6 +1367,10 @@ spec."
(let ((function (thing-at-point 'symbol)))
(clojure--get-indent-method function))))
+(defun clojure--keyword-to-symbol (keyword)
+ "Convert KEYWORD to symbol."
+ (intern (substring (symbol-name keyword) 1)))
+
(defun clojure--normal-indent (last-sexp indent-mode)
"Return the normal indentation column for a sexp.
Point should be after the open paren of the _enclosing_ sexp, and
@@ -1395,19 +1396,22 @@ accepted by `clojure-indent-style'."
;; Here we have reached the start of the enclosing sexp (point is now at
;; the function name), so the behaviour depends on INDENT-MODE and on
;; whether there's also an argument on this line (case A or B).
- (let ((case-a ; The meaning of case-a is explained in `clojure-indent-style'.
+ (let ((indent-mode (if (keywordp indent-mode)
+ ;; needed for backwards compatibility
+ ;; as before clojure-mode 5.10 indent-mode was a keyword
+ (clojure--keyword-to-symbol indent-mode)
+ indent-mode))
+ (case-a ; The meaning of case-a is explained in `clojure-indent-style'.
(and last-sexp-start
(< last-sexp-start (line-end-position)))))
(cond
- ;; For compatibility with the old `clojure-defun-style-default-indent', any
- ;; value other than these 3 is equivalent to `always-body'.
- ((not (memq indent-mode '(:always-align :align-arguments nil)))
+ ((eq indent-mode 'always-indent)
(+ (current-column) lisp-body-indent -1))
;; There's an arg after the function name, so align with it.
(case-a (goto-char last-sexp-start)
(current-column))
;; Not same line.
- ((eq indent-mode :align-arguments)
+ ((eq indent-mode 'align-arguments)
(+ (current-column) lisp-body-indent -1))
;; Finally, just align with the function name.
(t (current-column)))))))
@@ -1479,7 +1483,7 @@ This function also returns nil meaning don't specify the indentation."
(+ lisp-body-indent containing-form-column))
;; Further non-special args, align with the arg above.
((> pos (1+ method))
- (clojure--normal-indent last-sexp :always-align))
+ (clojure--normal-indent last-sexp 'always-align))
;; Special arg. Rigidly indent with a large indentation.
(t
(+ (* 2 lisp-body-indent) containing-form-column)))))
@@ -1493,7 +1497,7 @@ This function also returns nil meaning don't specify the indentation."
(cond
;; Preserve useful alignment of :require (and friends) in `ns' forms.
((and function (string-match "^:" function))
- (clojure--normal-indent last-sexp :always-align))
+ (clojure--normal-indent last-sexp 'always-align))
;; This should be identical to the :defn above.
((and function
(string-match "\\`\\(?:\\S +/\\)?\\(def[a-z]*\\|with-\\)"
diff --git a/test/clojure-mode-indentation-test.el b/test/clojure-mode-indentation-test.el
index 51af55c..613e692 100644
--- a/test/clojure-mode-indentation-test.el
+++ b/test/clojure-mode-indentation-test.el
@@ -58,7 +58,7 @@ values of customisable variables."
(let ((fname (intern (format "indentation/%s" description))))
`(ert-deftest ,fname ()
(let* ((after ,after)
- (clojure-indent-style :always-align)
+ (clojure-indent-style 'always-align)
(expected-cursor-pos (1+ (s-index-of "|" after)))
(expected-state (delete ?| after))
,@var-bindings)
@@ -238,14 +238,14 @@ values of customisable variables."
(declare (indent 1))
(when (stringp style)
(setq forms (cons style forms))
- (setq style :always-align))
+ (setq style 'always-align))
`(ert-deftest ,(intern (format "test-backtracking-%s" name)) ()
(progn
,@(mapcar (lambda (form)
`(with-temp-buffer
(clojure-mode)
(insert "\n" ,(replace-regexp-in-string "\n +" "\n " form))
- (let ((clojure-indent-style ,style))
+ (let ((clojure-indent-style (quote ,style)))
(indent-region (point-min) (point-max)))
(should (equal (buffer-string)
,(concat "\n" form)))))
@@ -463,7 +463,7 @@ x
3))")
(def-full-indent-test align-arguments
- :align-arguments
+ 'align-arguments
"(some-function
10
1
@@ -473,7 +473,7 @@ x
2)")
(def-full-indent-test always-indent
- :always-indent
+ 'always-indent
"(some-function
10
1