Skip to content

Commit caf783b

Browse files
authored
Merge pull request #396 from vspinu/prefix
Fix prefix syntaxes
2 parents 3e5652c + db5273c commit caf783b

File tree

4 files changed

+85
-38
lines changed

4 files changed

+85
-38
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
## master (unreleased)
44

55
### Bugs fixed
6-
6+
* [#394](https://github.com/clojure-emacs/clojure-mode/issues/394): `?` character is now treated as prefix when outside symbols.
7+
* [#394](https://github.com/clojure-emacs/clojure-mode/issues/394): `#` character now has prefix syntax class.
78
* Fixed indentation of `definterface` to match that of `defprotocol`.
89
* [#389](https://github.com/clojure-emacs/clojure-mode/issues/389): Fixed the indentation of `defrecord` and `deftype` multiple airity protocol forms.
910

clojure-mode.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,15 +254,15 @@ Out-of-the box clojure-mode understands lein, boot and gradle."
254254

255255
(defvar clojure-mode-syntax-table
256256
(let ((table (copy-syntax-table emacs-lisp-mode-syntax-table)))
257-
(modify-syntax-entry ?~ "' " table)
258257
(modify-syntax-entry ?\{ "(}" table)
259258
(modify-syntax-entry ?\} "){" table)
260259
(modify-syntax-entry ?\[ "(]" table)
261260
(modify-syntax-entry ?\] ")[" table)
261+
(modify-syntax-entry ?? "_ p" table) ; prefix outside of symbols
262+
(modify-syntax-entry ?~ "'" table)
262263
(modify-syntax-entry ?^ "'" table)
263264
(modify-syntax-entry ?@ "'" table)
264-
;; Make hash a usual word character
265-
(modify-syntax-entry ?# "_ p" table)
265+
(modify-syntax-entry ?# "'" table)
266266
table)
267267
"Syntax table for Clojure mode.
268268
Inherits from `emacs-lisp-mode-syntax-table'.")

test/clojure-mode-indentation-test.el

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -602,40 +602,6 @@ x
602602
(insert "{:a 2, ,:c 4}")
603603
(call-interactively #'clojure-align)
604604
(should (string= (buffer-string) "{:a 2, :c 4}"))))
605-
606-
;;; Misc
607-
608-
(defun non-func (form-a form-b)
609-
(with-temp-buffer
610-
(clojure-mode)
611-
(insert form-a)
612-
(save-excursion (insert form-b))
613-
(clojure--not-function-form-p)))
614-
615-
(ert-deftest non-function-form ()
616-
(dolist (form '(("#?@ " "(c d)")
617-
("#?@" "(c d)")
618-
("#? " "(c d)")
619-
("#?" "(c d)")
620-
("" "[asda]")
621-
("" "{a b}")
622-
("#" "{a b}")
623-
("" "(~)")))
624-
(should (apply #'non-func form)))
625-
(dolist (form '("(c d)"
626-
"(.c d)"
627-
"(:c d)"
628-
"(c/a d)"
629-
"(.c/a d)"
630-
"(:c/a d)"
631-
"(c/a)"
632-
"(:c/a)"
633-
"(.c/a)"))
634-
(should-not (non-func "" form))
635-
(should-not (non-func "^hint" form))
636-
(should-not (non-func "#macro" form))
637-
(should-not (non-func "^hint " form))
638-
(should-not (non-func "#macro " form))))
639605

640606
(provide 'clojure-mode-indentation-test)
641607

test/clojure-mode-syntax-test.el

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
;;; clojure-mode-syntax-test.el --- Clojure Mode: syntax related tests -*- lexical-binding: t; -*-
2+
3+
;; Copyright (C) 2015-2016 Bozhidar Batsov <[email protected]>
4+
5+
;; This file is not part of GNU Emacs.
6+
7+
;; This program is free software; you can redistribute it and/or modify
8+
;; it under the terms of the GNU General Public License as published by
9+
;; the Free Software Foundation, either version 3 of the License, or
10+
;; (at your option) any later version.
11+
12+
;; This program is distributed in the hope that it will be useful,
13+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
;; GNU General Public License for more details.
16+
17+
;; You should have received a copy of the GNU General Public License
18+
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
;;; Commentary:
21+
22+
;; The unit test suite of Clojure Mode
23+
24+
;;; Code:
25+
26+
(require 'clojure-mode)
27+
(require 'ert)
28+
29+
(defun non-func (form-a form-b)
30+
(with-temp-buffer
31+
(clojure-mode)
32+
(insert form-a)
33+
(save-excursion (insert form-b))
34+
(clojure--not-function-form-p)))
35+
36+
(ert-deftest non-function-form ()
37+
(dolist (form '(("#?@ " "(c d)")
38+
("#?@" "(c d)")
39+
("#? " "(c d)")
40+
("#?" "(c d)")
41+
("" "[asda]")
42+
("" "{a b}")
43+
("#" "{a b}")
44+
("" "(~)")))
45+
(should (apply #'non-func form)))
46+
(dolist (form '("(c d)"
47+
"(.c d)"
48+
"(:c d)"
49+
"(c/a d)"
50+
"(.c/a d)"
51+
"(:c/a d)"
52+
"(c/a)"
53+
"(:c/a)"
54+
"(.c/a)"))
55+
(should-not (non-func "" form))
56+
(should-not (non-func "^hint" form))
57+
(should-not (non-func "#macro" form))
58+
(should-not (non-func "^hint " form))
59+
(should-not (non-func "#macro " form))))
60+
61+
(ert-deftest clojure-syntax-prefixed-symbols ()
62+
(dolist (form '(("#?@aaa" . "aaa")
63+
("#?aaa" . "?aaa")
64+
("#aaa" . "aaa")
65+
("'aaa" . "aaa")))
66+
(with-temp-buffer
67+
(clojure-mode)
68+
(insert (car form))
69+
(equal (symbol-name (symbol-at-point)) (cdr form)))))
70+
71+
(ert-deftest clojure-syntax-skip-prefixes ()
72+
(dolist (form '("#?@aaa" "#?aaa" "#aaa" "'aaa"))
73+
(with-temp-buffer
74+
(clojure-mode)
75+
(insert form)
76+
(backward-word)
77+
(backward-prefix-chars)
78+
(should (bobp)))))
79+
80+
(provide 'clojure-mode-syntax-test)

0 commit comments

Comments
 (0)