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

Evil navigation #66

Open
sorawee opened this issue Jul 26, 2020 · 0 comments
Open

Evil navigation #66

sorawee opened this issue Jul 26, 2020 · 0 comments

Comments

@sorawee
Copy link
Contributor

sorawee commented Jul 26, 2020

Hello. First of all, thanks for this amazing package!

I'm personally used to a navigation in normal and visual state where backward-sexp is analogous to evil-backward-word-begin and forward-sexp is analogous to evil-forward-word-end. To elaborate, I want:

abc def
^ >
(abc def) ghi
^       >
(abc def) ghi
        ^   >

where ^ is the current position of the point and > is where the point should be after the forward-sexp operation. Similarly, I want:

abc def
    < ^
ghi (abc def)
    <       ^
ghi (abc def)
<   ^

where ^ is the current position of the point and < is where the point should be after the backward-sexp operation.

IIUC, none of the functionalities that lispyville provides does something like this, due to the off-by-one error from the mismatch between Emacs's point system and Vim's point system. Therefore, I wrote my own:

(defun significantp (old-point new-point)
  (not (or (equal old-point new-point)
           (equal (1+ old-point) new-point))))

(evil-define-motion my/lispyville-forward-sexp (count)
  "This is an evil motion equivalent of `forward-sexp'."
  (let ((original-point (point)))
    (when (nth 3 (syntax-ppss))
      (forward-char))
    (condition-case nil
        (forward-sexp (or count 1))
      (error nil))
    (unless (significantp original-point (point))
      (goto-char (1+ original-point))
      (condition-case nil
          (forward-sexp (or count 1))
        (error nil)))
    (backward-char)))

(evil-define-motion my/lispyville-backward-sexp (count)
  "This is an evil motion equivalent of `backward-sexp'."
  (let ((original-point (point)))
    (when (nth 3 (syntax-ppss (1+ (point))))
      (backward-char))
    (condition-case nil
        (backward-sexp (or count 1))
      (error nil))
    (unless (significantp original-point (point))
      (goto-char original-point)
      (condition-case nil
          (backward-sexp (or count 1))
        (error nil)))))

If you think it's useful, feel free to adapt it. Any suggestion would be appreciated, too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants