-
-
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
Changes from 4 commits
799ba06
4908b54
0373861
3adc019
24701af
47092a2
91ed998
8be7571
ac6dea8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
||
(defmethod global-mode-region-beginning ((global-mode (eql :|emacs|)) &optional (buffer (current-buffer))) | ||
(region-beginning buffer)) | ||
|
||
(defun region-beginning (&optional (buffer (current-buffer))) | ||
"Return the integer value of point or mark, whichever is smaller." | ||
(point-min (buffer-point buffer) | ||
(buffer-mark buffer))) | ||
|
||
(defgeneric global-mode-region-end (global-mode &optional buffer)) | ||
|
||
(defmethod global-mode-region-end ((global-mode (eql :|emacs|)) &optional (buffer (current-buffer))) | ||
(region-end buffer)) | ||
|
||
(defun region-end (&optional (buffer (current-buffer))) | ||
"Return the integer value of point or mark, whichever is larger." | ||
(point-max (buffer-point buffer) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,8 @@ | |
:display-xref-locations | ||
:display-xref-references | ||
:find-root-directory | ||
:buffer-root-directory) | ||
:buffer-root-directory | ||
:set-region-point) | ||
#+sbcl | ||
(:lock t)) | ||
(in-package :lem/language-mode) | ||
|
@@ -153,8 +154,11 @@ | |
(uncomment-region) | ||
(comment-region))) | ||
|
||
(defun set-region-point (start end) | ||
(cond | ||
(defgeneric set-region-point (start end global-mode)) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 |
||
(defmethod set-region-point ((start point) (end point) (global-mode (eql :|emacs|))) | ||
(declare (ignore global-mode)) | ||
(cond | ||
((buffer-mark-p (current-buffer)) | ||
(move-point start (cursor-region-beginning (current-point))) | ||
(move-point end (cursor-region-end (current-point)))) | ||
|
@@ -166,7 +170,7 @@ | |
(alexandria:when-let ((line-comment (variable-value 'line-comment :buffer))) | ||
(with-point ((start (current-point)) | ||
(end (current-point))) | ||
(set-region-point start end) | ||
(set-region-point start end (lem-core::current-global-mode-keyword-name)) | ||
(loop | ||
(skip-whitespace-forward start) | ||
(when (point>= start end) | ||
|
@@ -183,7 +187,7 @@ | |
(when line-comment | ||
(with-point ((start (current-point) :right-inserting) | ||
(end (current-point) :left-inserting)) | ||
(set-region-point start end) | ||
(set-region-point start end (lem-core::current-global-mode-keyword-name)) | ||
(skip-whitespace-forward start) | ||
(when (point>= start end) | ||
(insert-string (current-point) line-comment) | ||
|
@@ -210,7 +214,7 @@ | |
(when line-comment | ||
(with-point ((start (current-point) :right-inserting) | ||
(end (current-point) :right-inserting)) | ||
(set-region-point start end) | ||
(set-region-point start end (lem-core::current-global-mode-keyword-name)) | ||
(let ((p start)) | ||
(loop | ||
(parse-partial-sexp p end nil t) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,10 @@ | |
(defun current-global-mode () | ||
*current-global-mode*) | ||
|
||
(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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
(defun all-active-modes (buffer) | ||
(mapcar #'ensure-mode-object | ||
(append (buffer-minor-modes 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.
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 👍