-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add region comment support for vi-mode and region commands #1176
Add region comment support for vi-mode and region commands #1176
Conversation
- Change `set-region-point` to a generic to facilitate extension - Add help function `current-global-mode-keyword-name` on lem-core - Add implementations of `set-region-point` for emacs and vi-mode global mode
Interesting, the linter is triggering "simple-warning: The function EQL is called with one argument, but wants exactly two." |
I just removed the key specifier and seem to work now 👍 |
So, I expanded the issue, adding support for other modes when using the region option "r". The thing is, vi-mode has another way of understanding a region but both vi-mode and emacs-mode have the understanding of the beginning of their "regions", so with generics I can get the current global-mode and dispatch the correct one. In some cases, I decided not to change the original function with a generic mostly for performance reasons (https://github.com/lem-project/lem/pull/1176/files#diff-2240c3cc423763222d7a831b2ed8631486b6f41f5f9cf384b0af0954a2d252b4L264). Given that the region management is from the There is the improvement of exporting some symbols that are called with double dots |
An interesting "bug" is that given the nature of the vi-mode region, when calling a region command with |
This PR is ready to be merge, any reason why not to merge it? (ping @cxxxr ) |
extensions/vi-mode/visual.lisp
Outdated
|
||
|
||
(eval-when (:compile-toplevel :load-toplevel) | ||
(sb-ext:unlock-package :lem-base) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we want a SBCL feature flag? Or see https://quickdocs.org/cl-package-locks which defines lock/unlock for 4 implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh indeed, nice catch, I'm not sure If I want to add another package, but I'll use a flag for that expression 👍
src/mode.lisp
Outdated
(defun current-global-mode-keyword-name () | ||
(alexandria:make-keyword | ||
(mode-name (current-global-mode)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you need to use current-global-mode-keyword-name instead of current-global-mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/ext/language-mode.lisp
Outdated
(defgeneric set-region-point (start end global-mode)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be better to define a new method (e.g. set-region-point-using-global-mode) that takes global-mode as an argument, with set-region-point as the default value. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, we can change the name of the function to reflect it, and at this point we can use the global-mode symbol so that's a good option too
extensions/vi-mode/visual.lisp
Outdated
(eval-when (:compile-toplevel :load-toplevel) | ||
#+sbcl | ||
(sb-ext:unlock-package :lem-base) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot accept this kind of barbaric behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair, I also think it's kind of ugly, but I would have to change a lot of how lem is written to accommodate an improvement approach. I'll dig around and see what I can do, thanks for the feedback 👍
src/base/basic.lisp
Outdated
@@ -257,11 +257,21 @@ The thrid argument PROP is a property to remove." | |||
(count-characters (buffer-start-point buffer) | |||
(buffer-end-point buffer)))) | |||
|
|||
(defgeneric global-mode-region-beginning (global-mode &optional buffer)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The concept of global-mode does not exist at the time of loading lem-base.
This causes interdependencies between lem-base and lem-core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's why I'm using keywords to dispatch the global modes, as in this stage lem/base doesn't have the concept yet. But we can always work with keywords.
So, I think I address most of issues, these are the changes I made:
With these changes, the functionality remain the same, but the code should be more in line with the Lem codebase. (ping @cxxxr for the review) |
set-region-point
to a generic to facilitate extensioncurrent-global-mode-keyword-name
on lem-coreset-region-point
for emacs and vi-mode global mode