Skip to content

Commit

Permalink
Respect end user <f5> key bindings; fixes #714
Browse files Browse the repository at this point in the history
  • Loading branch information
greghendershott committed Aug 20, 2024
1 parent 3cb49c5 commit 936c4d8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions racket-hash-lang.el
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ A discussion of the information provided by a Racket language:
\\{racket-hash-lang-mode-map}
"
(racket--polite-user-f-keys racket-hash-lang-mode-map
'(("<f5>" racket-run-and-switch-to-repl)
("M-C-<f5>" racket-racket)
("C-<f5>" racket-test)))
(racket-call-racket-repl-buffer-name-function)
(add-hook 'kill-buffer-hook
#'racket-mode-maybe-offer-to-kill-repl-buffer
Expand Down
4 changes: 4 additions & 0 deletions racket-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@
"Major mode for editing Racket source files.
\\{racket-mode-map}"
(racket--polite-user-f-keys racket-mode-map
'(("<f5>" racket-run-and-switch-to-repl)
("M-C-<f5>" racket-racket)
("C-<f5>" racket-test)))
;;; Syntax
(set-syntax-table racket-mode-syntax-table)
(setq-local multibyte-syntax-as-symbol t)
Expand Down
18 changes: 18 additions & 0 deletions racket-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,24 @@ as if the user had C-g to quit."
s))
sap)))

(defun racket--polite-user-f-keys (major-mode-keymap keys+cmds)
"Politely bind/unbind KEYS+CMDS in MAJOR-MODE-KEYMAP.
On the one hand we want to allow `racket-mode-map' and
`racket-hash-lang-mode-map' to bind <f5> as a convenience for
users coming from DrRacket. OTOH Emacs convention reserves <f5>
for user bindings. See issue #714."
(dolist (k+c keys+cmds)
(let ((key (kbd (car k+c)))
(cmd (cadr k+c)))
;; Avoid shadowing a binding user has made in the global map.
(if (lookup-key (current-global-map) key)
(define-key major-mode-keymap key nil)
;; Unless user has modified binding in major-mode-keymap,
;; restore our binding there.
(unless (lookup-key major-mode-keymap key)
(define-key major-mode-keymap key cmd))))))

(provide 'racket-util)

;; racket-util.el ends here

0 comments on commit 936c4d8

Please sign in to comment.