mirror of https://codeberg.org/cage/tinmop/
- added a module to expand abbreviations for the command window.
This commit is contained in:
parent
3caed6b13b
commit
5c8e1d5828
|
@ -0,0 +1,54 @@
|
|||
;; tinmop module to expand abbreviations on the command window
|
||||
;; Copyright © 2021 cage
|
||||
|
||||
;; This program is free software: you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation, either version 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
(in-package :modules)
|
||||
|
||||
(defparameter *expand-abbrev-rewriting-rules* '(("^\\^g" "gemini://"))
|
||||
"Before displaying messages that module will rewrites the first
|
||||
element of each item of this list with the second
|
||||
|
||||
Example
|
||||
|
||||
(\"foo\" \"bar\")
|
||||
^^^
|
||||
first
|
||||
^^^
|
||||
second
|
||||
|
||||
will replace 'foo' with 'bar'.
|
||||
|
||||
So the whole list is like: '((\"foo\" \"bar\") (\"old\" \"new\") ...)")
|
||||
|
||||
(defun abbrev-re (abbrev)
|
||||
(first abbrev))
|
||||
|
||||
(defun abbrev-replace (abbrev)
|
||||
(second abbrev))
|
||||
|
||||
(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))
|
||||
command-window)
|
||||
|
||||
(hooks:add-hook 'hooks:*after-char-to-command-window*
|
||||
#'expand-abbrev-command-hook-fn)
|
|
@ -21,7 +21,7 @@
|
|||
:initform ()
|
||||
:initarg :command-line
|
||||
:accessor command-line
|
||||
:documentation "A list of keys so far inserted by the user")
|
||||
:documentation "A list of keys so far inserted by the user, or the input string, depending on the mode.")
|
||||
(echo-character
|
||||
:initform nil
|
||||
:initarg :echo-character
|
||||
|
@ -539,6 +539,9 @@ command line."
|
|||
(win-show suggestions-win)
|
||||
(setf command-line
|
||||
(insert-at-point command-window event command-line))
|
||||
(when 'hooks:*after-char-to-command-window*
|
||||
(hooks:run-hook 'hooks:*after-char-to-command-window*
|
||||
command-window))
|
||||
(show-candidate-completion command-window)))))))
|
||||
command-window)
|
||||
|
||||
|
|
|
@ -108,3 +108,6 @@ Each function takes 1 parameter: the database row for the saved status.")
|
|||
(defparameter *before-displaying-links-hook* '()
|
||||
"Run this hooks before sending the list of URLs to the window that allow the user to
|
||||
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.")
|
||||
|
|
|
@ -1554,7 +1554,8 @@
|
|||
:*before-sending-message*
|
||||
:*skip-message-hook*
|
||||
:*after-saving-message*
|
||||
:*before-displaying-links-hook*))
|
||||
:*before-displaying-links-hook*
|
||||
:*after-char-to-command-window*))
|
||||
|
||||
(defpackage :keybindings
|
||||
(:use
|
||||
|
|
Loading…
Reference in New Issue