mirror of
https://codeberg.org/cage/tinmop/
synced 2025-02-10 07:20:35 +01:00
- allowed switching off abbreviations on the command-window.
This commit is contained in:
parent
5c8e1d5828
commit
8d086ba6c4
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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.")
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user