Skip to content
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

Merged
merged 9 commits into from
Jan 13, 2024

Conversation

Sasanidas
Copy link
Member

  • 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

- 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
@Sasanidas
Copy link
Member Author

Interesting, the linter is triggering "simple-warning: The function EQL is called with one argument, but wants exactly two."
But the eql in that case is a method specializer, which AFAIK it's a correct way to use it
https://github.com/lem-project/lem/actions/runs/7118673847/job/19382116290?pr=1176#step:4:390

@Sasanidas
Copy link
Member Author

I just removed the key specifier and seem to work now 👍

@Sasanidas Sasanidas changed the title Add region comment support for vi-mode Add region comment support for vi-mode and region commands Dec 6, 2023
@Sasanidas
Copy link
Member Author

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 lem-base package that at this point, is already locked, I also had to unlock it to add the methods and then lock it away.

There is the improvement of exporting some symbols that are called with double dots ::

@Sasanidas
Copy link
Member Author

An interesting "bug" is that given the nature of the vi-mode region, when calling a region command with M-x doesn't work, because it removes the overlay. So in order to get the correct region, the command has to be bind to a key combination.

@Sasanidas
Copy link
Member Author

This PR is ready to be merge, any reason why not to merge it? (ping @cxxxr )



(eval-when (:compile-toplevel :load-toplevel)
(sb-ext:unlock-package :lem-base)
Copy link
Collaborator

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.

Copy link
Member Author

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 👍

@Sasanidas Sasanidas requested a review from vindarel January 3, 2024 17:43
src/mode.lisp Outdated
Comment on lines 107 to 109
(defun current-global-mode-keyword-name ()
(alexandria:make-keyword
(mode-name (current-global-mode))))
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 157 to 158
(defgeneric set-region-point (start end global-mode))

Copy link
Member

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?

Copy link
Member Author

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

Comment on lines 260 to 262
(eval-when (:compile-toplevel :load-toplevel)
#+sbcl
(sb-ext:unlock-package :lem-base)
Copy link
Member

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.

Copy link
Member Author

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 👍

@@ -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))
Copy link
Member

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.

Copy link
Member Author

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.

@Sasanidas
Copy link
Member Author

So, I think I address most of issues, these are the changes I made:

  • I extract the functions to a package called lem-generics, the idea of this package is to have generics with a default behaviour that other packages can extend (like in this case).

  • As point out, I changed the methods to accept the global-mode itself instead of the keyword, now that the function is not in the base package.

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)

@Sasanidas Sasanidas requested a review from cxxxr January 10, 2024 15:21
@cxxxr cxxxr merged commit e769293 into lem-project:main Jan 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants