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

normal-state interacts poorly with eval-last-sexp #17

Closed
TheBB opened this issue Sep 15, 2011 · 5 comments
Closed

normal-state interacts poorly with eval-last-sexp #17

TheBB opened this issue Sep 15, 2011 · 5 comments

Comments

@TheBB
Copy link
Member

TheBB commented Sep 15, 2011

Originally reported by: Anonymous


When a sexp closes at the end of a line, you can't use eval-last-sexp in normal-state to evaluate it because you can't get to the end of the line.

My solution is this command:

(evil-define-command my-evil-eval-sexp-at-point ()
  "Eval sexp at point. Like eval-last-sexp, but one to the right."
  :repeat nil
  (interactive)
  (save-excursion
    (if (not (eolp)) (forward-char))
    (call-interactively 'eval-last-sexp)))

but I haven't used it much yet, and I don't know if there are edge cases. I have it on :eval and ;v.


@TheBB
Copy link
Member Author

TheBB commented Sep 24, 2011

Original comment by Frank Fischer (Bitbucket: lyro, GitHub: lyro):


You may try the following code which advices some function when evil
is activated. If you use at least 35ff006 those modifications should
be activated if and only if evil is active. If those modifications
work they could go into evil's code.

;;; eval-last-sexp
(defadvice eval-last-sexp (around evil)
  "Last sexp ends at point."
  (when (evil-normal-state-p)
    (save-excursion
      (unless (or (eobp) (eolp)) (forward-char))
      ad-do-it)))

;;; pp-eval-last-sexp
(defadvice pp-eval-last-sexp (around evil)
  "Last sexp ends at point."
  (when (evil-normal-state-p)
    (save-excursion
      (unless (or (eobp) (eolp)) (forward-char))
      ad-do-it)))

@TheBB
Copy link
Member Author

TheBB commented Sep 28, 2011

Original comment by Anonymous:


Thinks. I had to change them slightly so that they continued to work in insert-mode (I'm not sure if that was the intent, but I like it like that). But I have discovered one edge case (which also affects my solution): save-excursion means you can't move the cursor when doing eval-last-sexp in normal-mode. My current fix is to advise the "find the last sexp" functions instead:

(defadvice preceding-sexp (around evil)
  "In normal-state, last sexp ends at point."
  (if (evil-normal-state-p)
      (save-excursion
	(unless (or (eobp) (eolp)) (forward-char))
	ad-do-it)
    ad-do-it))

(defadvice pp-last-sexp (around evil)
  "In normal-state, last sexp ends at point."
  (if (evil-normal-state-p)
      (save-excursion
	(unless (or (eobp) (eolp)) (forward-char))
	ad-do-it)
    ad-do-it))

(I'm not sure why both of these functions exist.) I haven't noticed any problems with this. It's possible that if someone uses these functions noninteractively, things would break; in that case, I can't think of a better solution than "reimplement [pp-]eval-last-sexp". But in core, they don't seem to be used anywhere bad: just a helper function of eval-last-sexp, and pp-eval-last-sexp and pp-macroexpand-last-sexp, respectively.

@TheBB
Copy link
Member Author

TheBB commented Oct 4, 2011

Original comment by Frank Fischer (Bitbucket: lyro, GitHub: lyro):


Make `evil-last-sexp' work with closing parenthesis under point (fixed #17)

This is done by advicing preceeding-sexp' and pp-last-sexp'.

2 similar comments
@TheBB
Copy link
Member Author

TheBB commented Nov 9, 2011

Original comment by Frank Fischer (Bitbucket: lyro, GitHub: lyro):


Make `evil-last-sexp' work with closing parenthesis under point (fixed #17)

This is done by advicing preceeding-sexp' and pp-last-sexp'.

@TheBB
Copy link
Member Author

TheBB commented Nov 9, 2011

Original comment by Frank Fischer (Bitbucket: lyro, GitHub: lyro):


Make `evil-last-sexp' work with closing parenthesis under point (fixed #17)

This is done by advicing preceeding-sexp' and pp-last-sexp'.

@TheBB TheBB closed this as completed Jan 19, 2017
shadowrylander pushed a commit to syvlorg/aiern that referenced this issue Jun 28, 2021
Create them with docstrings and allow them to optionally set the default
states instead of keymaps (fixes emacs-evil#17).
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

1 participant