-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add bqn-comint-bring
#80
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -266,6 +266,7 @@ BQN buffers (or recreate them)." | |
(when bqn-glyph-map-modifier | ||
(set-keymap-parent bqn-mode-map | ||
(make-composed-keymap prog-mode-map bqn--glyph-map))) | ||
(keymap-set bqn-mode-map "C-c C-z" #'bqn-comint-bring) | ||
(when bqn-use-input-method | ||
(activate-input-method "BQN-Z")) | ||
(setq-local syntax-propertize-function bqn--syntax-propertize) | ||
|
@@ -304,11 +305,28 @@ BQN buffers (or recreate them)." | |
:type 'boolean | ||
:group 'bqn) | ||
|
||
(defun bqn--comint-prefix () | ||
"The prefix for BQNs comint buffers." | ||
(concat "*" bqn-comint--process-name "-")) | ||
|
||
(defconst bqn--comint-suffix "*" | ||
"The suffix for BQNs comint buffers.") | ||
|
||
(defun bqn--comint-buffer-name () | ||
"Return the name of the comint buffer associated to the current buffer. | ||
Note that the comint buffer may not exist yet, use `bqn-comint-buffer' | ||
to create it." | ||
(let* ((pref (bqn--comint-prefix)) | ||
(buf (or (buffer-file-name) (buffer-name)))) | ||
(if (string-prefix-p pref buf) | ||
buf | ||
(concat pref buf bqn--comint-suffix)))) | ||
Comment on lines
+319
to
+323
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One could also use some internal state to keep track of comint buffer–buffer associations, but I figured since this is the only state that's currently needed this would be a bit overkill |
||
|
||
;;;###autoload | ||
(defun bqn-comint-buffer () | ||
"Run an inferior BQN process inside Emacs and return its buffer." | ||
(interactive) | ||
(let ((buf-name (concat "*" bqn-comint--process-name "*"))) | ||
(let ((buf-name (bqn--comint-buffer-name))) | ||
;; same buffer name as auto-created when passing nil below | ||
(if-let ((buf (get-buffer buf-name))) | ||
(if (comint-check-proc buf) | ||
|
@@ -432,13 +450,25 @@ bqn-comint-process-session and echoes the result." | |
(interactive) | ||
(bqn-comint-eval-region (point-min) (point-max))) | ||
|
||
(defun bqn-comint-bring () | ||
"Toggle between the comint buffer and its associated buffer." | ||
(interactive) | ||
(let* ((comint (bqn-comint-buffer)) | ||
(buf (thread-last | ||
(buffer-name comint) | ||
(string-remove-prefix (bqn--comint-prefix)) | ||
(string-remove-suffix bqn--comint-suffix) | ||
get-file-buffer))) | ||
(pop-to-buffer (if (equal (current-buffer) comint) buf comint)))) | ||
|
||
(define-derived-mode bqn-comint-mode comint-mode "BQN interactive" | ||
"Major mode for inferior BQN processes." | ||
:syntax-table bqn--syntax-table | ||
:group 'bqn | ||
(when bqn-glyph-map-modifier | ||
(set-keymap-parent bqn-comint-mode-map | ||
(make-composed-keymap comint-mode-map bqn--glyph-map))) | ||
(keymap-set bqn-comint-mode-map "C-c C-z" #'bqn-comint-bring) | ||
(when bqn-use-input-method | ||
(activate-input-method "BQN-Z")) | ||
(setq-local syntax-propertize-function bqn--syntax-propertize) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split the keymap modifications because I think it is a little bit controversial to bind keys "by default".
https://github.com/positron-solutions/user-keys?tab=readme-ov-file#please-package-authors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought a little bit about this, but since keybindings of the form
C-c C-«letter»
are reserved for major modes I figured it was fine. I think that it helps with discoverability, personally, and unbinding a keybinding from a keymap is not all that difficult. Though I don't feel too strongly either way and am fine with dropping this part if you'd preferEDIT: I now see that the link you posted talks about this in some length in another place. As I said, no strong opinions from me