Skip to content

Commit 94f440e

Browse files
arichiardibbatsov
authored andcommitted
Extract keyword words for completion
The patch copies functionality from cider so that now inf-clojure can detect and extract keywords (colons included) when a symbol at point is not found.
1 parent dcb523b commit 94f440e

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

inf-clojure.el

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,19 +1344,38 @@ you might want to use in your customization."
13441344
:safe #'functionp
13451345
:package-version '(inf-clojure . "2.1.0"))
13461346

1347-
(defconst inf-clojure-clojure-expr-break-chars " \t\n\"\'`><,;|&{()[]@\\^")
1347+
(defconst inf-clojure-clojure-expr-break-chars "^[] \"'`><,;|&{()[@\\^]"
1348+
"Regexp are hard.
1349+
1350+
This regex has been built in order to match the first of the
1351+
listed chars. There are a couple of quirks to consider:
1352+
1353+
- the ] is always a special in elisp regex so you have to put it
1354+
directly AFTER [ if you want to match it as literal.
1355+
- The ^ needs to be escaped with \\^.
1356+
1357+
Tests and `re-builder' are your friends.")
1358+
1359+
(defun inf-clojure--kw-to-symbol (kw)
1360+
"Convert the keyword KW to a symbol.
1361+
1362+
This guy was taken from CIDER, thanks folks."
1363+
(when kw
1364+
(replace-regexp-in-string "\\`:+" "" kw)))
13481365

13491366
(defun inf-clojure-completion-bounds-of-expr-at-point ()
13501367
"Return bounds of expression at point to complete."
13511368
(when (not (memq (char-syntax (following-char)) '(?w ?_)))
13521369
(save-excursion
1353-
(let ((end (point)))
1354-
(skip-chars-backward (concat "^" inf-clojure-clojure-expr-break-chars))
1355-
(let ((chars (thing-at-point 'symbol)))
1356-
(when (> (length chars) 0)
1357-
(let ((first-char (substring-no-properties chars 0 1)))
1358-
(when (string-match-p "[^0-9]" first-char)
1359-
(cons (point) end)))))))))
1370+
(let* ((end (point))
1371+
(skipped-back (skip-chars-backward inf-clojure-clojure-expr-break-chars))
1372+
(start (+ end skipped-back))
1373+
(chars (or (thing-at-point 'symbol)
1374+
(inf-clojure--kw-to-symbol (buffer-substring start end)))))
1375+
(when (> (length chars) 0)
1376+
(let ((first-char (substring-no-properties chars 0 1)))
1377+
(when (string-match-p "[^0-9]" first-char)
1378+
(cons (point) end))))))))
13601379

13611380
(defun inf-clojure-completion-expr-at-point ()
13621381
"Return expression at point to complete."

0 commit comments

Comments
 (0)