Skip to content

Commit

Permalink
racket-hash-lang-mode: Bind C-M-q to racket-hash-lang-C-M-q-dwim
Browse files Browse the repository at this point in the history
Use token class to decide whether to do prog-indent-sexp,
fill-paragraph, fill-comment, or nothing.

This should avoid users needing to do the kind of configuration as in
issue #661. Furthermore it can vary smartly within e.g. a Scribble doc
to support three possible behaviors based on location. (In my
dog-fooding so far this works well.)
  • Loading branch information
greghendershott committed Sep 4, 2023
1 parent 91971ad commit 2dbb8d7
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion racket-hash-lang.el
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ re-tokenization has progressed sufficiently.")
("C-M-b" ,#'racket-hash-lang-backward)
("C-M-f" ,#'racket-hash-lang-forward)
("C-M-u" ,#'racket-hash-lang-up)
("C-M-d" ,#'racket-hash-lang-down))))
("C-M-d" ,#'racket-hash-lang-down)
("C-M-q" ,#'racket-hash-lang-C-M-q-dwim))))

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

Expand Down Expand Up @@ -572,6 +573,22 @@ not a complete expression, in which case `newline-and-indent'."
(racket-repl-submit prefix)
(newline-and-indent)))

(defun racket-hash-lang-C-M-q-dwim (&optional prefix)
"Depending on token at point, indent expression or fill."
(interactive "P")
(racket--cmd/async nil
`(hash-lang
classify
,racket--hash-lang-id
,racket--hash-lang-generation
,(point))
(pcase-lambda (`(,_beg ,_end ,type))
(cl-case type
((whitespace) (user-error "ambiguous; did nothing"))
((text) (fill-paragraph prefix))
((comment) (fill-comment-paragraph prefix))
(otherwise (prog-indent-sexp prefix))))))

(provide 'racket-hash-lang)

;; racket-hash-lang.el ends here

0 comments on commit 2dbb8d7

Please sign in to comment.