-
-
Save g-gundam/0c06e910cc4a29f9b9444537f526f2e2 to your computer and use it in GitHub Desktop.
LEM: Part 2 of Trying to Improve `vi-mode`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defpackage :levi | |
(:use :cl) | |
(:import-from :lem | |
#:define-command) | |
(:import-from :lem-core | |
#:current-major-mode-at-point | |
#:define-key | |
#:define-keys | |
#:message) | |
(:import-from :lem/buffer/internal | |
#:current-point) | |
) | |
(in-package :levi) | |
;;; overriding *normal-keymap* | |
(defgeneric handle-return (mode) | |
(:documentation "Mode-specific actions for hitting Return.")) | |
(define-command route-return () () | |
(let ((mode (current-major-mode-at-point (current-point)))) | |
(message (prin1-to-string mode)) | |
(handle-return mode))) | |
(defgeneric handle-f (mode) | |
(:documentation "Mode-specific actions for hitting f.")) | |
(define-command route-f () () | |
(let ((mode (current-major-mode-at-point (current-point)))) | |
(message (prin1-to-string mode)) | |
(handle-f mode))) | |
(defgeneric handle-g (mode) | |
(:documentation "Mode-specific actions for hitting g.")) | |
(define-command route-g () () | |
(let ((mode (current-major-mode-at-point (current-point)))) | |
(message (prin1-to-string mode)) | |
(handle-g mode))) | |
(defgeneric handle-l (mode) | |
(:documentation "Mode-specific actions for hitting l.")) | |
(define-command route-l () () | |
(let ((mode (current-major-mode-at-point (current-point)))) | |
;;(message (prin1-to-string mode)) ; a message on every "l" is too annoying even in development | |
(handle-l mode))) | |
(defgeneric handle-r (mode) | |
(:documentation "Mode-specific actions for hitting r.")) | |
(define-command route-r () () | |
(let ((mode (current-major-mode-at-point (current-point)))) | |
(message (prin1-to-string mode)) | |
(handle-r mode))) | |
(defgeneric handle-s (mode) | |
(:documentation "Mode-specific actions for hitting s.")) | |
(define-command route-s () () | |
(let ((mode (current-major-mode-at-point (current-point)))) | |
(message (prin1-to-string mode)) | |
(handle-s mode))) | |
(define-keys lem-vi-mode:*normal-keymap* | |
("Return" 'levi::route-return) | |
("f" 'levi::route-f) | |
("g" 'levi::route-g) | |
("l" 'levi::route-l) | |
;;("r" 'levi::route-r) | |
;;("s" 'levi::route-s) | |
) | |
;;; really problematic bindings that break vi-mode severely | |
;; - uncomment the levi: version to try anyway | |
;; - uncomment the line after it to reset it to its default behavior | |
;; - Use `M-x emacs-mode` if vi-mode becomes too broken. | |
;;(define-key lem-vi-mode:*normal-keymap* "r" 'levi::route-r) | |
;;(define-key lem-vi-mode:*normal-keymap* "r" 'lem-vi-mode/commands:vi-replace-char) | |
;;(define-key lem-vi-mode:*normal-keymap* "s" 'levi::route-s) | |
;;(define-key lem-vi-mode:*normal-keymap* "s" 'lem-vi-mode/commands:vi-substitute) | |
;;; color-theme-selector-mode | |
(defmethod handle-return ((mode (eql 'lem-core::color-theme-selector-mode))) | |
"Return handler for color-theme-selector-mode" | |
(lem-core::color-theme-selector-select)) | |
;;; filer-mode | |
(defmethod handle-return ((mode (eql 'lem/filer::filer-mode))) | |
"Return handler for filer-mode" | |
(lem/filer::filer-select)) | |
;;; dashboard-mode | |
(defmethod handle-return ((mode (eql 'lem-dashboard::dashboard-mode))) | |
"Return handler for dashboard-mode" | |
(lem-dashboard::dashboard-open-selected-item)) | |
(defmethod handle-f ((mode (eql 'lem-dashboard::dashboard-mode))) | |
"f handler for dashboard-mode" | |
(lem-dashboard::dashboard-move-to-recent-files)) | |
(defmethod handle-g ((mode (eql 'lem-dashboard::dashboard-mode))) | |
"g handler for dashboard-mode" | |
(lem-dashboard::open-lem-github)) | |
(defmethod handle-l ((mode (eql 'lem-dashboard::dashboard-mode))) | |
"l handler for dashboard-mode" | |
(lem-lisp-mode/internal:lisp-scratch)) | |
(defmethod handle-r ((mode (eql 'lem-dashboard::dashboard-mode))) | |
"r handler for dashboard-mode" | |
(lem-dashboard::dashboard-move-to-recent-projects)) | |
(defmethod handle-s ((mode (eql 'lem-dashboard::dashboard-mode))) | |
"s handler for dashboard-mode" | |
(lem-dashboard::open-lem-docs)) | |
;;; default actions | |
(defmethod handle-return ((mode symbol)) | |
"Return handler that does the default action." | |
(lem-vi-mode/commands::vi-return)) | |
(defmethod handle-f ((mode symbol)) | |
"f handler that does the default action." | |
(lem-vi-mode/commands::vi-find-char)) | |
;; FIXME - g in *normal-keymap* has many sequences like "g J" and "g u". | |
;; How could I handle that? | |
;; Do I have to make a handler for every sequence that starts with "g"? | |
(defmethod handle-g ((mode symbol)) | |
"g handler that does the default action." | |
(message "I don't know what to do here.")) | |
(defmethod handle-l ((mode symbol)) | |
"l handler that does the default action." | |
(lem-vi-mode/commands::vi-forward-char)) | |
;; FIXME - vi-replace-char wants 4 parameters. What should I do? | |
(defmethod handle-r ((mode symbol)) | |
"r handler that does the default action." | |
(lem-vi-mode/commands:vi-replace-char)) | |
;; FIXME - vi-substitute wants 3 parameters. | |
(defmethod handle-s ((mode symbol)) | |
"s handler that does the default action." | |
(lem-vi-mode/commands:vi-substitute)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Part 1 can be found here: lem-project/lem#1515 .