Skip to content

Commit

Permalink
Revert "move definitions"
Browse files Browse the repository at this point in the history
This reverts commit e8c8945.
  • Loading branch information
cxxxr committed Jul 17, 2023
1 parent 18ad053 commit 3b543f3
Showing 1 changed file with 58 additions and 60 deletions.
118 changes: 58 additions & 60 deletions modes/lisp-mode/repl.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,53 @@
argument)
(lisp-eval-async '(micros:clear-printed-objects)))

(defvar *lisp-repl-shortcuts* '())

(defmacro with-repl-prompt (() &body body)
`(let ((lem/prompt-window:*prompt-completion-window-shape* nil))
,@body))

(defun repl-prompt-for-string (prompt &rest args)
(with-repl-prompt ()
(apply #'prompt-for-string
prompt
:gravity :cursor
:use-border nil
args)))

(defun prompt-for-shortcuts ()
(let* ((*lisp-repl-shortcuts* *lisp-repl-shortcuts*)
(names (mapcar #'car *lisp-repl-shortcuts*)))
(cdr (assoc (repl-prompt-for-string
"Command: "
:completion-function (lambda (x) (completion-strings x names))
:test-function (lambda (name) (member name names :test #'string=))
:history-symbol 'mh-lisp-repl-shortcuts)
*lisp-repl-shortcuts* :test #'equal))))

(define-command lisp-repl-shortcut (n) ("p")
(with-point ((point (current-point)))
(if (point>= (lem/listener-mode:input-start-point (current-buffer)) point)
(let ((fun (prompt-for-shortcuts)))
(when fun
(funcall fun)))
(let ((c (insertion-key-p (last-read-key-sequence))))
(insert-character point c n)))))

(defmacro define-repl-shortcut (name lambda-list &body body)
(if (and (not (null lambda-list))
(symbolp lambda-list))
`(progn
(setf *lisp-repl-shortcuts*
(remove ,(string-downcase name) *lisp-repl-shortcuts* :key 'first :test 'equal))
(push (cons ,(string-downcase name) ',lambda-list) *lisp-repl-shortcuts*)
',name)
`(progn
(setf *lisp-repl-shortcuts*
(remove ,(string-downcase name) *lisp-repl-shortcuts* :key 'first :test 'equal))
(push (cons ,(string-downcase name) ',name) *lisp-repl-shortcuts*)
(defun ,name ,lambda-list ,@body))))

(defun repl-buffer ()
(get-buffer "*lisp-repl*"))

Expand Down Expand Up @@ -422,66 +469,6 @@
(string
(insert-string point token :attribute current-attribute))))))

(define-command backward-prompt () ()
(when (equal (current-buffer) (repl-buffer))
(move-to-previous-virtual-line (current-point))
(lem:previous-single-property-change (lem:current-point) :field)))

(define-command forward-prompt () ()
(when (equal (current-buffer) (repl-buffer))
(move-to-next-virtual-line (current-point))
(lem:next-single-property-change (lem:current-point) :field)
(lem:next-single-property-change (lem:current-point) :field)))


;;; repl-shortcut
(defvar *lisp-repl-shortcuts* '())

(defmacro with-repl-prompt (() &body body)
`(let ((lem/prompt-window:*prompt-completion-window-shape* nil))
,@body))

(defun repl-prompt-for-string (prompt &rest args)
(with-repl-prompt ()
(apply #'prompt-for-string
prompt
:gravity :cursor
:use-border nil
args)))

(defun prompt-for-shortcuts ()
(let* ((*lisp-repl-shortcuts* *lisp-repl-shortcuts*)
(names (mapcar #'car *lisp-repl-shortcuts*)))
(cdr (assoc (repl-prompt-for-string
"Command: "
:completion-function (lambda (x) (completion-strings x names))
:test-function (lambda (name) (member name names :test #'string=))
:history-symbol 'mh-lisp-repl-shortcuts)
*lisp-repl-shortcuts* :test #'equal))))

(define-command lisp-repl-shortcut (n) ("p")
(with-point ((point (current-point)))
(if (point>= (lem/listener-mode:input-start-point (current-buffer)) point)
(let ((fun (prompt-for-shortcuts)))
(when fun
(funcall fun)))
(let ((c (insertion-key-p (last-read-key-sequence))))
(insert-character point c n)))))

(defmacro define-repl-shortcut (name lambda-list &body body)
(if (and (not (null lambda-list))
(symbolp lambda-list))
`(progn
(setf *lisp-repl-shortcuts*
(remove ,(string-downcase name) *lisp-repl-shortcuts* :key 'first :test 'equal))
(push (cons ,(string-downcase name) ',lambda-list) *lisp-repl-shortcuts*)
',name)
`(progn
(setf *lisp-repl-shortcuts*
(remove ,(string-downcase name) *lisp-repl-shortcuts* :key 'first :test 'equal))
(push (cons ,(string-downcase name) ',name) *lisp-repl-shortcuts*)
(defun ,name ,lambda-list ,@body))))

(define-repl-shortcut sayonara ()
(if (self-connection-p *connection*)
(message "Can't say sayonara because it's self connection.")
Expand Down Expand Up @@ -521,3 +508,14 @@
(define-repl-shortcut quickload ()
(let ((system (prompt-for-system "Quickload System: ")))
(listener-eval (prin1-to-string `(ql:quickload ,system)))))

(define-command backward-prompt () ()
(when (equal (current-buffer) (repl-buffer))
(move-to-previous-virtual-line (current-point))
(lem:previous-single-property-change (lem:current-point) :field)))

(define-command forward-prompt () ()
(when (equal (current-buffer) (repl-buffer))
(move-to-next-virtual-line (current-point))
(lem:next-single-property-change (lem:current-point) :field)
(lem:next-single-property-change (lem:current-point) :field)))

0 comments on commit 3b543f3

Please sign in to comment.