Skip to content

Commit a3bcfd2

Browse files
racket-hash-lang: Change the non-sexp lang syntax-table; closes #741
1 parent 142c36c commit a3bcfd2

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

racket-common.el

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -380,22 +380,6 @@ repeatedly."
380380
(racket--escape-string-or-comment)
381381
(backward-up-list 1))
382382

383-
(defconst racket--plain-syntax-table
384-
(let ((table (make-syntax-table)))
385-
;; Modify entries for characters for parens, strings, and
386-
;; comments, setting them to word syntax instead. (For the these
387-
;; raw syntax descriptor numbers, see Emacs Lisp Info: "Syntax
388-
;; Table Internals".)
389-
(map-char-table (lambda (key value)
390-
(when (memq (car value) '(4 5 7 10 11 12))
391-
(aset table key '(2))))
392-
table)
393-
table)
394-
"A syntax-table that makes no assumptions that characters are
395-
delimiters for parens, quotes, comments, etc. Just whitespace and
396-
word syntax, so the user has /some/ basic navigation as opposed
397-
to it being one opaque blob.")
398-
399383
(provide 'racket-common)
400384

401385
;; racket-common.el ends here

racket-hash-lang.el

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,44 @@ re-tokenization has progressed sufficiently.")
197197

198198
(defvar-local racket-hash-lang-mode-lighter "#lang")
199199

200+
(defconst racket--agnostic-syntax-table
201+
(let ((table (make-syntax-table)))
202+
;; From Emacs Lisp Info node "Syntax Table Internals":
203+
;;
204+
;; Code Class
205+
;; 0 whitespace
206+
;; 1 punctuation
207+
;; 2 word
208+
;; 3 symbol
209+
;; 4 open parenthesis
210+
;; 5 close parenthesis
211+
(map-char-table (lambda (key code+char)
212+
(unless (<= 0 (car code+char) 5)
213+
(aset table key '(3))))
214+
table)
215+
table)
216+
"Like `standard-syntax-table' but even simpler.
217+
218+
The only syntax categories in this table are whitespace,
219+
punctuation, word, symbol, and open/close parens. Chars with any
220+
other syntax are changed to symbol syntax.
221+
222+
For example we change all string-quote syntax to symbol, because
223+
the chars used to delimit strings vary among programming
224+
languages. Although that example happens to be the only practical
225+
difference from `standard-syntax-table', today, we still make a
226+
generalized pass over it to be sure.
227+
228+
Note: Open/close paren syntax is preserved on the theory that,
229+
although the /meaning/ of those characters may vary among langs,
230+
their use as paired delimiters is likely universal, and it is
231+
useful to support various Emacs features such as
232+
rainbow-delimiters.
233+
234+
Note: `standard-syntax-table' is a better choice for spans lexed
235+
as \"text\" tokens, because ?\" is definitely a string delimiter
236+
in English.")
237+
200238
;;;###autoload
201239
(define-derived-mode racket-hash-lang-mode prog-mode
202240
'racket-hash-lang-mode-lighter
@@ -226,7 +264,7 @@ A discussion of the information provided by a Racket language:
226264
(add-hook 'kill-buffer-hook
227265
#'racket-mode-maybe-offer-to-kill-repl-buffer
228266
nil t)
229-
(set-syntax-table racket--plain-syntax-table)
267+
(set-syntax-table racket--agnostic-syntax-table)
230268
;; Tell `parse-partial-sexp' to consider syntax-table text
231269
;; properties.
232270
(setq-local parse-sexp-lookup-properties t)
@@ -415,7 +453,7 @@ lang's attributes that we care about have changed."
415453
;; properties we add from tokens.
416454
(set-syntax-table (if (plist-get plist 'racket-grouping)
417455
racket-mode-syntax-table
418-
racket--plain-syntax-table))
456+
racket--agnostic-syntax-table))
419457
;; Similarly for `forward-sexp-function'. The
420458
;; drracket:grouping-position protocol doesn't support a nuance
421459
;; where a `forward-sexp-function' should signal an exception
@@ -566,7 +604,7 @@ that need be set."
566604
(put-face beg end (racket--sexp-comment-face (get-face-at beg))))
567605
('parenthesis (when (facep 'parenthesis)
568606
(put-face beg end 'parenthesis)))
569-
('text (put-stx beg end racket--plain-syntax-table)
607+
('text (put-stx beg end (standard-syntax-table))
570608
(put-face beg end racket-hash-lang-text))
571609
(kind
572610
(if-let (face (cdr (assq kind racket-hash-lang-token-face-alist)))

0 commit comments

Comments
 (0)