-
Notifications
You must be signed in to change notification settings - Fork 132
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
Allow custom 'word', 'symbol' definitions #596
Conversation
Here is an example of how this could be used to get 'word' behavior closer to Vim's: (defun forward-vimlike-word (&optional arg)
"Alternate `forward-word'. Essentially the same idea as Vim's 'e'."
(interactive "^p")
(setq arg (or arg 1))
(cl-destructuring-bind (sign move-func char-func)
(if (>= arg 0)
'(1 skip-syntax-forward char-after)
'(-1 skip-syntax-backward char-before))
(with-syntax-table (standard-syntax-table)
(let ((distance sign))
(while (and distance (> (abs distance) 0) (> (* arg sign) 0))
(setq distance
(when-let ((next-char (funcall char-func))
(next-syntax (char-syntax next-char)))
(cond ((eq next-syntax ?w)
(funcall move-func "w"))
((eq next-syntax ?\ )
(prog1
(funcall move-func " ")
(forward-vimlike-word sign)))
(t
(funcall move-func "^w ")))))
(setq arg (- arg sign)))
(and distance (> (abs distance) 0))))))
(put 'vimlike-word 'forward-op #'forward-vimlike-word)
(setq meow--word-thing 'vimlike-word) |
911aeee
to
bf91bee
Compare
Looks good and works well. This is a useful abstraction to have! All the other meow commands are already dependent on thingatpt, i think this is good too. Your old docstring seems better than the one you force pushed? If you feel like it's redundant I think it should at least have some words explaining that you can define your own things to customize behavior. Ideally, you should add a section in CUSTOMIZATIONS.org as well. It would be nice to include your vim word example in the docs. I believe you also need to modify the forward-word calls in beacon mode. This section: Lines 219 to 225 in 99e08c9
I briefly tested replacing the forward word calls with forward-thing and it seems to work. |
614f9a3
to
58944d1
Compare
I wrote a new one. I also added a section to
Good catch. Done. |
58944d1
to
b0c31c2
Compare
I force-pushed to rename the variables to |
While fixing a few places where I forgot to replace |
Allows users to customize the behavior of the commands related to marking and moving by words and symbols. Make all commands related to words and symbols rely on `forward-thing' and `bounds-of-thing-at-point'. Then, define the 'thing's that these functions are called on in `meow-word-thing' and `meow-symbol-thing'. Now the user can define their own things and make Meow use them by setting these variables. Meow users may find Emacs' default notions of 'word' and 'symbol' to be unsatisfactory for modal editing. For example, word movements tend to skip over non-alphanumeric characters, meaning that `meow-next-word' and `meow-back-word' will skip them when not expanding a selection. This commit allows users to redefine these notions via `thingatpt'. With this change, every Meow motion is now customizable. The only exception is `meow-line'; it should not be necessary to change its behavior since Meow already provides `meow-visual-line'.
2a1268f
to
3660038
Compare
Force-pushed again to fix some typos (sigh). It should all work now. |
In addition to all commands related to words and symbols now relying `forward-thing' and `bounds-of-thing-at-point', which use the things defined in `meow-word-thing' and `meow-symbol-thing', this commit consolidates the logic used by these commands into `meow-mark-thing', `meow-next-thing', `meow--fix-thing-selection-mark', `meow--forward-thing-1', and `meow--backward-thing-1'. This results in much less code duplication.
3660038
to
f77341b
Compare
Force-pushed a small fix - the function to add word beacons no longer requires |
@DogLooksGood review? looks good to me. |
Hope this can be merged soon. I had other ideas for PRs but I've been holding off on them, because I'd probably want to use the abstractions introduced in this one... |
Fixes regression from #596. Picks between a bound and the mark correctly when the mark is within bounds of the thing being selected.
Allows users to customize the behavior of the commands related to marking and moving by words and symbols.
Make all commands related to words and symbols rely on
forward-thing
andbounds-of-thing-at-point
. Then, define the 'thing's that these functions are called on inmeow--word-thing
andmeow--symbol-thing
. Now the user can define their own things and make Meow use them by setting these variables.Meow users may find Emacs' default notions of 'word' and 'symbol' to be unsatisfactory for modal editing. For example, word movements tend to skip over non-alphanumeric characters, meaning that
meow-next-word
andmeow-back-word
will skip them when not expanding a selection. This commit allows users to redefine these notions viathingatpt
.With this change, every Meow motion is now customizable. The only exception is
meow-line
; it should not be necessary to change its behavior since Meow already providesmeow-visual-line
.