diff --git a/modules/expand-abbrev-command-window.lisp b/modules/expand-abbrev-command-window.lisp index 15ad1bb..fa38323 100644 --- a/modules/expand-abbrev-command-window.lisp +++ b/modules/expand-abbrev-command-window.lisp @@ -32,23 +32,49 @@ will replace 'foo' with 'bar'. So the whole list is like: '((\"foo\" \"bar\") (\"old\" \"new\") ...)") -(defun abbrev-re (abbrev) + +(defun expand-abbrev-abbrev-re (abbrev) (first abbrev)) -(defun abbrev-replace (abbrev) +(defun expand-abbrev-abbrev-replace (abbrev) (second abbrev)) +(defparameter *expand-abbrev-actual-rewriting-rules* + (mapcar (lambda (a) (list (create-scanner (expand-abbrev-abbrev-re a)) + (expand-abbrev-abbrev-replace a))) + *expand-abbrev-rewriting-rules*)) + +(defparameter *expand-abbrev-stop-rewrite* nil) + (defun expand-abbrev-command-hook-fn (command-window) (let ((expanded (command-window:command-line command-window))) - (loop for expansion in *expand-abbrev-rewriting-rules* - when (scan (abbrev-re expansion) expanded) - do - (setf expanded (regex-replace (abbrev-re expansion) - expanded - (abbrev-replace expansion)))) - (setf (command-window:command-line command-window) expanded) - (point-tracker:move-point-to-end command-window expanded)) + (when (null *expand-abbrev-stop-rewrite*) + (if (scan "^\\\\." expanded) + (progn + (setf *expand-abbrev-stop-rewrite* t) + (setf expanded (subseq expanded 1))) + (loop for expansion in *expand-abbrev-actual-rewriting-rules* + when (scan (expand-abbrev-abbrev-re expansion) expanded) + do + (setf expanded (regex-replace (expand-abbrev-abbrev-re expansion) + expanded + (expand-abbrev-abbrev-replace expansion))))) + (setf (command-window:command-line command-window) expanded) + (point-tracker:move-point-to-end command-window expanded))) command-window) +(defun expand-abbrev-command-fire-hook (x) + (declare (ignore x)) + (setf *expand-abbrev-stop-rewrite* nil)) + +(defun expand-abbrev-command-delete-hook (x) + (expand-abbrev-command-fire-hook x)) + (hooks:add-hook 'hooks:*after-char-to-command-window* #'expand-abbrev-command-hook-fn) + +(hooks:add-hook 'hooks:*before-fire-string-event-command-window* + #'expand-abbrev-command-fire-hook) + +(hooks:add-hook 'hooks:*after-delete-char-from-command-window* + #'expand-abbrev-command-delete-hook) diff --git a/src/command-window.lisp b/src/command-window.lisp index 6e3f359..86c80ae 100644 --- a/src/command-window.lisp +++ b/src/command-window.lisp @@ -498,9 +498,13 @@ command line." (move-suggestion-page-right command-window)) ((eq :backspace event) (setf command-line (delete-at-point command-window command-line :direction :left)) + (when 'hooks:*after-char-to-command-window* + (hooks:run-hook 'hooks:*after-delete-char-from-command-window* command-window)) (show-candidate-completion command-window)) ((eq :dc event) (setf command-line (delete-at-point command-window command-line :direction :right)) + (when 'hooks:*after-char-to-command-window* + (hooks:run-hook 'hooks:*after-delete-char-from-command-window* command-window)) (show-candidate-completion command-window)) ((eq :left event) (move-point-left command-window)) @@ -525,6 +529,9 @@ command line." ((characterp event) (cond ((char= #\Newline event) + (when 'hooks:*before-fire-string-event-command-window* + (hooks:run-hook 'hooks:*before-fire-string-event-command-window* + command-window)) (insert-in-history prompt command-line) (fire-user-input-event command-window) (setf command-line nil) diff --git a/src/hooks.lisp b/src/hooks.lisp index 35dea99..9102ac8 100644 --- a/src/hooks.lisp +++ b/src/hooks.lisp @@ -111,3 +111,9 @@ open the links") (defparameter *after-char-to-command-window* '() "Run this hooks after a character has been typed by the user on the command window.") + +(defparameter *before-fire-string-event-command-window* '() + "Run this hooks before sending user input to the program (command window only).") + +(defparameter *after-delete-char-from-command-window* '() + "Run this hooks after deleting a character from the input of the command-window.") diff --git a/src/package.lisp b/src/package.lisp index 7889fca..9596de4 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -1555,7 +1555,9 @@ :*skip-message-hook* :*after-saving-message* :*before-displaying-links-hook* - :*after-char-to-command-window*)) + :*after-char-to-command-window* + :*before-fire-string-event-command-window* + :*after-delete-char-from-command-window*)) (defpackage :keybindings (:use