[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/racket-mode edc3d4a563 2/2: Respect end user function key
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/racket-mode edc3d4a563 2/2: Respect end user function key bindings; fixes #714 |
Date: |
Sun, 25 Aug 2024 13:00:30 -0400 (EDT) |
branch: elpa/racket-mode
commit edc3d4a56344de747ef91253515d2a985224fb19
Author: Greg Hendershott <git@greghendershott.com>
Commit: Greg Hendershott <git@greghendershott.com>
Respect end user function key bindings; fixes #714
---
racket-hash-lang.el | 7 +++----
racket-mode.el | 25 ++++++++++++-------------
racket-util.el | 33 +++++++++++++++++++++++++++++++++
3 files changed, 48 insertions(+), 17 deletions(-)
diff --git a/racket-hash-lang.el b/racket-hash-lang.el
index d7ae192673..41f6b8fc63 100644
--- a/racket-hash-lang.el
+++ b/racket-hash-lang.el
@@ -20,9 +20,6 @@
`((("C-c C-c"
"C-c C-k") ,#'racket-run-module-at-point)
("C-c C-z" ,#'racket-edit-switch-to-repl)
- ("<f5>" ,#'racket-run-and-switch-to-repl)
- ("M-C-<f5>" ,#'racket-racket)
- ("C-<f5>" ,#'racket-test)
("C-c C-t" ,#'racket-test)
("C-c C-l" ,#'racket-logger)
("C-c C-o" ,#'racket-profile)
@@ -45,7 +42,8 @@
("C-M-f" ,#'racket-hash-lang-forward)
("C-M-u" ,#'racket-hash-lang-up)
("C-M-d" ,#'racket-hash-lang-down)
- ("C-M-q" ,#'racket-hash-lang-C-M-q-dwim))))
+ ("C-M-q" ,#'racket-hash-lang-C-M-q-dwim)
+ ,@racket--f5-bindings)))
(easy-menu-define racket-hash-lang-mode-menu racket-hash-lang-mode-map
"Menu for `racket-hash-lang-mode'."
@@ -222,6 +220,7 @@ 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 racket--f5-bindings)
(racket-call-racket-repl-buffer-name-function)
(add-hook 'kill-buffer-hook
#'racket-mode-maybe-offer-to-kill-repl-buffer
diff --git a/racket-mode.el b/racket-mode.el
index 1023149063..1fce796f59 100644
--- a/racket-mode.el
+++ b/racket-mode.el
@@ -44,33 +44,31 @@
(defvar racket-mode-map
(racket--easy-keymap-define
- '((("C-c C-c"
+ `((("C-c C-c"
"C-c C-k") racket-run-module-at-point)
- ("C-c C-z" racket-edit-switch-to-repl)
- ("<f5>" racket-run-and-switch-to-repl)
- ("M-C-<f5>" racket-racket)
- ("C-<f5>" racket-test)
- ("C-c C-t" racket-test)
- ("C-c C-l" racket-logger)
- ("C-c C-o" racket-profile)
+ ("C-c C-z" ,#'racket-edit-switch-to-repl)
+ ("C-c C-t" ,#'racket-test)
+ ("C-c C-l" ,#'racket-logger)
+ ("C-c C-o" ,#'racket-profile)
("M-C-x" racket-send-definition)
("C-x C-e" racket-send-last-sexp)
("C-c C-r" racket-send-region)
("C-c C-e f" racket-expand-file)
- ("C-c C-e x" racket-expand-definition)
+ ("C-c C-e x" ,#'racket-expand-definition)
("C-c C-e e" racket-expand-last-sexp)
("C-c C-e r" racket-expand-region)
- ("C-c C-x C-f" racket-open-require-path)
- ("TAB" indent-for-tab-command)
+ ("C-c C-x C-f" ,#'racket-open-require-path)
+ ("TAB" ,#'indent-for-tab-command)
("M-C-u" racket-backward-up-list)
- ("C-c C-p" racket-cycle-paren-shapes)
+ ("C-c C-p" ,#'racket-cycle-paren-shapes)
("M-C-y" racket-insert-lambda)
("C-c C-d" racket-documentation-search)
(("C-c C-s"
"C-c C-.") racket-describe-search)
("C-c C-f" racket-fold-all-tests)
("C-c C-u" racket-unfold-all-tests)
- ((")" "]" "}") racket-insert-closing)))
+ ((")" "]" "}") racket-insert-closing)
+ ,@racket--f5-bindings))
"Keymap for Racket mode.")
(easy-menu-define racket-mode-menu racket-mode-map
@@ -135,6 +133,7 @@
"Major mode for editing Racket source files.
\\{racket-mode-map}"
+ (racket--polite-user-f-keys racket-mode-map racket--f5-bindings)
;;; Syntax
(set-syntax-table racket-mode-syntax-table)
(setq-local multibyte-syntax-as-symbol t)
diff --git a/racket-util.el b/racket-util.el
index 249d1bad43..4684225b2f 100644
--- a/racket-util.el
+++ b/racket-util.el
@@ -203,6 +203,39 @@ as if the user had C-g to quit."
s))
sap)))
+(defconst racket--f5-bindings
+ '(("<f5>" racket-run-and-switch-to-repl)
+ ("M-C-<f5>" racket-racket)
+ ("C-<f5>" racket-test))
+ "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.
+
+On the other hand, Emacs convention reserves <f5> for user
+bindings. See issue #714.
+
+On the third hand, we want to initialize the major mode's keymaps
+with these, for use by doc/generate.el, to document the default
+bindings.
+
+Solution: Append these in the keymap initialization, and also
+call `racket--polite-user-f-keys' in the major mode
+initialization function. That adds/remove the binding based on
+whether it would shadow an end user binding in the global map.")
+
+(defun racket--polite-user-f-keys (major-mode-keymap keys+cmds)
+ "Politely bind/unbind KEYS+CMDS in MAJOR-MODE-KEYMAP."
+ (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