10
10
; ; Artur Malabarba <bruce.connor.am@gmail.com>
11
11
; ; URL: http://github.com/clojure-emacs/clojure-mode
12
12
; ; Keywords: languages clojure clojurescript lisp
13
- ; ; Version: 5.9.0
13
+ ; ; Version: 5.9.1
14
14
; ; Package-Requires: ((emacs "25.1"))
15
15
16
16
; ; This file is not part of GNU Emacs.
@@ -439,7 +439,7 @@ ENDP and DELIM."
439
439
(t )))))
440
440
441
441
(defconst clojure--collection-tag-regexp " #\\ (::[a-zA-Z0-9._-]*\\ |:?\\ ([a-zA-Z0-9._-]+/\\ )?[a-zA-Z0-9._-]+\\ )"
442
- " Collection reader macro tag regexp.
442
+ " Collection reader macro tag regexp.
443
443
It is intended to check for allowed strings that can come before a
444
444
collection literal (e.g. '[]' or '{}'), as reader macro tags.
445
445
This includes #fully.qualified/my-ns[:kw val] and #::my-ns{:kw
@@ -1090,6 +1090,12 @@ will align the values like this:
1090
1090
:safe #'booleanp
1091
1091
:type 'boolean )
1092
1092
1093
+ (defcustom clojure-align-reader-conditionals nil
1094
+ " Whether to align reader conditionals, as if they were maps."
1095
+ :package-version '(clojure-mode . " 5.10" )
1096
+ :safe #'booleanp
1097
+ :type 'boolean )
1098
+
1093
1099
(defcustom clojure-align-binding-forms
1094
1100
'(" let" " when-let" " when-some" " if-let" " if-some" " binding" " loop"
1095
1101
" doseq" " for" " with-open" " with-local-vars" " with-redefs" )
@@ -1104,6 +1110,10 @@ will align the values like this:
1104
1110
:safe #'listp
1105
1111
:type '(repeat string))
1106
1112
1113
+ (defvar clojure--beginning-of-reader-conditional-regexp
1114
+ " #\\ ?@(\\ |#\\ ?("
1115
+ " Regexp denoting the beginning of a reader conditional." )
1116
+
1107
1117
(defun clojure--position-for-alignment ()
1108
1118
" Non-nil if the sexp around point should be automatically aligned.
1109
1119
This function expects to be called immediately after an
@@ -1118,32 +1128,36 @@ For instance, in a map literal point is left immediately before
1118
1128
the first key; while, in a let-binding, point is left inside the
1119
1129
binding vector and immediately before the first binding
1120
1130
construct."
1121
- ; ; Are we in a map?
1122
- (or (and (eq (char-before ) ?{ )
1123
- (not (eq (char-before (1- (point ))) ?\# )))
1124
- ; ; Are we in a cond form?
1125
- (let* ((fun (car (member (thing-at-point 'symbol ) clojure-align-cond-forms)))
1126
- (method (and fun (clojure--get-indent-method fun)))
1127
- ; ; The number of special arguments in the cond form is
1128
- ; ; the number of sexps we skip before aligning.
1129
- (skip (cond ((numberp method) method)
1130
- ((null method) 0 )
1131
- ((sequencep method) (elt method 0 )))))
1132
- (when (and fun (numberp skip))
1133
- (clojure-forward-logical-sexp skip)
1134
- (comment-forward (point-max ))
1135
- fun)) ; Return non-nil (the var name).
1136
- ; ; Are we in a let-like form?
1137
- (when (member (thing-at-point 'symbol )
1138
- clojure-align-binding-forms)
1139
- ; ; Position inside the binding vector.
1140
- (clojure-forward-logical-sexp)
1141
- (backward-sexp )
1142
- (when (eq (char-after ) ?\[ )
1143
- (forward-char 1 )
1144
- (comment-forward (point-max ))
1145
- ; ; Return non-nil.
1146
- t ))))
1131
+ (let ((point (point )))
1132
+ ; ; Are we in a map?
1133
+ (or (and (eq (char-before ) ?{ )
1134
+ (not (eq (char-before (1- point)) ?\# )))
1135
+ ; ; Are we in a reader conditional?
1136
+ (and clojure-align-reader-conditionals
1137
+ (looking-back clojure--beginning-of-reader-conditional-regexp (- (point ) 4 )))
1138
+ ; ; Are we in a cond form?
1139
+ (let* ((fun (car (member (thing-at-point 'symbol ) clojure-align-cond-forms)))
1140
+ (method (and fun (clojure--get-indent-method fun)))
1141
+ ; ; The number of special arguments in the cond form is
1142
+ ; ; the number of sexps we skip before aligning.
1143
+ (skip (cond ((numberp method) method)
1144
+ ((null method) 0 )
1145
+ ((sequencep method) (elt method 0 )))))
1146
+ (when (and fun (numberp skip))
1147
+ (clojure-forward-logical-sexp skip)
1148
+ (comment-forward (point-max ))
1149
+ fun)) ; Return non-nil (the var name).
1150
+ ; ; Are we in a let-like form?
1151
+ (when (member (thing-at-point 'symbol )
1152
+ clojure-align-binding-forms)
1153
+ ; ; Position inside the binding vector.
1154
+ (clojure-forward-logical-sexp)
1155
+ (backward-sexp )
1156
+ (when (eq (char-after ) ?\[ )
1157
+ (forward-char 1 )
1158
+ (comment-forward (point-max ))
1159
+ ; ; Return non-nil.
1160
+ t )))))
1147
1161
1148
1162
(defun clojure--find-sexp-to-align (end )
1149
1163
" Non-nil if there's a sexp ahead to be aligned before END.
@@ -1152,10 +1166,14 @@ Place point as in `clojure--position-for-alignment'."
1152
1166
(let ((found))
1153
1167
(while (and (not found)
1154
1168
(search-forward-regexp
1155
- (concat " {\\ |(" (regexp-opt
1156
- (append clojure-align-binding-forms
1157
- clojure-align-cond-forms)
1158
- 'symbols ))
1169
+ (concat (when clojure-align-reader-conditionals
1170
+ (concat clojure--beginning-of-reader-conditional-regexp
1171
+ " \\ |" ))
1172
+ " {\\ |("
1173
+ (regexp-opt
1174
+ (append clojure-align-binding-forms
1175
+ clojure-align-cond-forms)
1176
+ 'symbols ))
1159
1177
end 'noerror ))
1160
1178
1161
1179
(let ((ppss (syntax-ppss )))
@@ -1955,7 +1973,8 @@ This will skip over sexps that don't represent objects, so that ^hints and
1955
1973
(clojure-forward-logical-sexp 1 )
1956
1974
(clojure-backward-logical-sexp 1 )
1957
1975
(looking-at-p first-form))
1958
- (scan-error nil )))
1976
+ (scan-error nil )
1977
+ (end-of-buffer nil )))
1959
1978
1960
1979
(defun clojure-sexp-starts-until-position (position )
1961
1980
" Return the starting points for forms before POSITION.
@@ -1992,10 +2011,11 @@ testing, give an easy way to turn this new behavior off."
1992
2011
(setq haystack (cdr haystack))))
1993
2012
found))
1994
2013
1995
- (defun clojure-beginning-of-defun-function ()
2014
+ (defun clojure-beginning-of-defun-function (&optional n )
1996
2015
" Go to top level form.
1997
2016
Set as `beginning-of-defun-function' so that these generic
1998
- operators can be used."
2017
+ operators can be used. Given a positive N it will do it that
2018
+ many times."
1999
2019
(let ((beginning-of-defun-function nil ))
2000
2020
(if (and clojure-toplevel-inside-comment-form
2001
2021
(clojure-top-level-form-p " comment" ))
@@ -2013,8 +2033,8 @@ operators can be used."
2013
2033
(clojure-sexp-starts-until-position
2014
2034
clojure-comment-end))))
2015
2035
(progn (goto-char sexp-start) t )
2016
- (progn ( beginning-of-defun ) t ))))
2017
- (progn ( beginning-of-defun ) t ))))
2036
+ (beginning-of-defun n ))))
2037
+ (beginning-of-defun n ))))
2018
2038
2019
2039
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2020
2040
; ;
0 commit comments