Skip to content
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 lem:this-command-keys and lem:universal-argument-of-this-command #986

Merged
merged 4 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/command.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,30 @@
(defvar *this-command*
"The command now being executed.")

(defvar *this-command-keys* '()
"List containing the key sequence that invoked the present command.")

(defvar *universal-argument* nil
"The raw prefix argument for the current command.")

(defun this-command ()
"Return the command now being executed."
*this-command*)

(defun this-command-keys ()
"Return the list of key sequence that invoked the present command."
(reverse *this-command-keys*))

(defun universal-argument-of-this-command ()
"Return the universal argument of this command now being executed."
*universal-argument*)

(defgeneric execute (mode command argument))

(defun call-command (this-command universal-argument)
"Call first argument as the command, passing remaining arguments to it."
(let ((*this-command* (ensure-command this-command)))
(let ((*this-command* (ensure-command this-command))
(*universal-argument* universal-argument))
(unless *this-command*
(editor-error "~A: command not found" this-command))
(run-hooks *pre-command-hook*)
Expand Down
5 changes: 4 additions & 1 deletion src/input.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
(defun unread-key (key)
(when *key-recording-p*
(pop *record-keys*))
(pop *this-command-keys*)
(push key *unread-keys*))

(defun read-command ()
Expand All @@ -91,7 +92,9 @@
(last-read-key-sequence))

(defun unread-key-sequence (kseq)
(setf *unread-keys* (nconc *unread-keys* kseq)))
(prog1 (setf *unread-keys* (nconc *unread-keys* kseq))
(setf *this-command-keys*
(nthcdr (length kseq) *this-command-keys*))))

(defun execute-key-sequence (key-sequence)
(let ((*unread-keys* key-sequence))
Expand Down
2 changes: 2 additions & 0 deletions src/internal-packages.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@
:*post-command-hook*
:command-name
:this-command
:this-command-keys
:universal-argument-of-this-command
:execute
:call-command
:all-command-names)
Expand Down
3 changes: 2 additions & 1 deletion src/interp.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
#'editor-abort-handler)
(editor-condition
#'editor-condition-handler))
(read-command-and-call))
(let ((*this-command-keys* '()))
(read-command-and-call)))
(editor-condition (c)
(restart-case (error c)
(lem-restart:message ()
Expand Down
5 changes: 4 additions & 1 deletion src/lem.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ Options:
5000)
(add-hook (variable-value 'before-save-hook :global)
(lambda (buffer)
(process-file buffer))))))
(process-file buffer)))
(add-hook *input-hook*
(lambda (event)
(push event *this-command-keys*))))))

(defun teardown ()
(teardown-frames))
Expand Down