Skip to content

Commit 266ea17

Browse files
committed
Extract a complex regex into a constant
1 parent f98d548 commit 266ea17

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

clojure-mode.el

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,24 +1304,26 @@ no namespaces above point, return the first one in the buffer."
13041304
(re-search-forward clojure-namespace-name-regex nil t)))
13051305
(match-string-no-properties 4)))))
13061306

1307+
(defconst clojure-def-type-and-name-regex
1308+
(concat "(\\(?:\\(?:\\sw\\|\\s_\\)+/\\)?"
1309+
;; Declaration
1310+
"\\(def\\(?:\\sw\\|\\s_\\)*\\)\\>"
1311+
;; Any whitespace
1312+
"[ \r\n\t]*"
1313+
;; Possibly type or metadata
1314+
"\\(?:#?^\\(?:{[^}]*}\\|\\(?:\\sw\\|\\s_\\)+\\)[ \r\n\t]*\\)*"
1315+
;; Symbol name
1316+
"\\(\\(?:\\sw\\|\\s_\\)+\\)"))
1317+
13071318
(defun clojure-find-def ()
13081319
"Find the var declaration macro and symbol name of the current form.
13091320
Returns a list pair, e.g. (\"defn\" \"abc\") or (\"deftest\" \"some-test\")."
1310-
(let ((re (concat "(\\(?:\\(?:\\sw\\|\\s_\\)+/\\)?"
1311-
;; Declaration
1312-
"\\(def\\(?:\\sw\\|\\s_\\)*\\)\\>"
1313-
;; Any whitespace
1314-
"[ \r\n\t]*"
1315-
;; Possibly type or metadata
1316-
"\\(?:#?^\\(?:{[^}]*}\\|\\(?:\\sw\\|\\s_\\)+\\)[ \r\n\t]*\\)*"
1317-
;; Symbol name
1318-
"\\(\\(?:\\sw\\|\\s_\\)+\\)")))
1319-
(save-excursion
1320-
(unless (looking-at re)
1321-
(beginning-of-defun))
1322-
(when (search-forward-regexp re nil t)
1323-
(list (match-string-no-properties 1)
1324-
(match-string-no-properties 2))))))
1321+
(save-excursion
1322+
(unless (looking-at clojure-def-type-and-name-regex)
1323+
(beginning-of-defun))
1324+
(when (search-forward-regexp clojure-def-type-and-name-regex nil t)
1325+
(list (match-string-no-properties 1)
1326+
(match-string-no-properties 2)))))
13251327

13261328

13271329
;;; Sexp navigation

0 commit comments

Comments
 (0)