1. Frank Fischer
  2. evil
  3. Issues
Issue #272 resolved

Evil works incorrectly with yasnippet near the end of buffer

Anonymous created an issue

When using Evil in company with (yasnippet https://github.com/capitaomorte/yasnippet), if I expand the snippet below in the last line of buffer,

# name: ... if ...
# key: ifx
# --
$0 if ${1:condition};

the buffer looks like (^ indicates the cursor):

^ if @arr;

Then I press <escape> to return to evil's normal state, Evil will complain something like this "and: Args out of range: 85, 103". The current buffer still remains in insert state, though cursor's face changes to normal-state's. If I presss <escape> again, this time it works.

the stack backtrace:

Debugger entered--Lisp error: (args-out-of-range 85 103)
  buffer-substring-no-properties(85 103)
  (and evil-current-insertion (buffer-substring-no-properties (car evil-current-insertion) (cdr evil-current-insertion)))
  (setq evil-last-insertion (and evil-current-insertion (buffer-substring-no-properties (car evil-current-insertion) (cdr evil-current-insertion))))
  evil-stop-track-last-insertion()
  run-hooks(evil-insert-state-exit-hook)
  (let ((evil-state (quote insert))) (run-hooks (quote evil-insert-state-exit-hook)) (setq evil-state nil) (evil-esc-mode -1) (evil-normalize-keymaps) (cond ((evil-insert-state-p) (add-hook (quote pre-command-hook) (function evil-insert-repeat-hook)) (unless evil-want-fine-undo (evil-start-undo-step t))) (t (remove-hook (quote pre-command-hook) (function evil-insert-repeat-hook)) (setq evil-insert-repeat-info evil-repeat-info) (evil-set-marker 94 nil t) (unless evil-want-fine-undo (evil-end-undo-step t)) (when evil-move-cursor-back (when (or (evil-normal-state-p evil-next-state) (evil-motion-state-p evil-next-state)) (evil-move-cursor-back))))))
  (cond ((and (numberp arg) (< arg 1)) (setq evil-previous-state evil-state evil-state nil) (let ((evil-state (quote insert))) (run-hooks (quote evil-insert-state-exit-hook)) (setq evil-state nil) (evil-esc-mode -1) (evil-normalize-keymaps) (cond ((evil-insert-state-p) (add-hook (quote pre-command-hook) (function evil-insert-repeat-hook)) (unless evil-want-fine-undo (evil-start-undo-step t))) (t (remove-hook (quote pre-command-hook) (function evil-insert-repeat-hook)) (setq evil-insert-repeat-info evil-repeat-info) (evil-set-marker 94 nil t) (unless evil-want-fine-undo (evil-end-undo-step t)) (when evil-move-cursor-back (when (or ... ...) (evil-move-cursor-back))))))) (t (unless evil-local-mode (evil-local-mode 1)) (let ((evil-next-state (quote insert)) input-method-activate-hook input-method-deactivate-hook) (evil-change-state nil) (setq evil-state (quote insert)) (evil-add-to-alist (quote evil-previous-state-alist) (quote insert) evil-previous-state) (let ((evil-state (quote insert))) (evil-normalize-keymaps) (if t (evil-esc-mode 1) (evil-esc-mode -1)) (if (quote t) (activate-input-method evil-input-method) (deactivate-input-method)) (unless evil-no-display (evil-refresh-cursor (quote insert)) (evil-refresh-mode-line (quote insert)) (when (evil-called-interactively-p) (redisplay))) (cond ((evil-insert-state-p) (add-hook (quote pre-command-hook) (function evil-insert-repeat-hook)) (unless evil-want-fine-undo (evil-start-undo-step t))) (t (remove-hook (quote pre-command-hook) (function evil-insert-repeat-hook)) (setq evil-insert-repeat-info evil-repeat-info) (evil-set-marker 94 nil t) (unless evil-want-fine-undo (evil-end-undo-step t)) (when evil-move-cursor-back (when ... ...)))) (run-hooks (quote evil-insert-state-entry-hook)) (when (and evil-echo-state arg (not evil-no-display) evil-insert-state-message) (if (functionp evil-insert-state-message) (funcall evil-insert-state-message) (evil-echo "%s" evil-insert-state-message)))))))
  evil-insert-state(-1)
  funcall(evil-insert-state -1)
  (progn (funcall func (if state (and message 1) -1)))
  (if (and (functionp func) (or message (not (eq state evil-state)))) (progn (funcall func (if state (and message 1) -1))))
  (when (and (functionp func) (or message (not (eq state evil-state)))) (funcall func (if state (and message 1) -1)))
  (let ((func (evil-state-property (or state evil-state) :toggle))) (when (and (functionp func) (or message (not (eq state evil-state)))) (funcall func (if state (and message 1) -1))))
  evil-change-state(nil)
  (let ((evil-next-state (quote normal)) input-method-activate-hook input-method-deactivate-hook) (evil-change-state nil) (setq evil-state (quote normal)) (evil-add-to-alist (quote evil-previous-state-alist) (quote normal) evil-previous-state) (let ((evil-state (quote normal))) (evil-normalize-keymaps) (if t (evil-esc-mode 1) (evil-esc-mode -1)) (if (quote nil) (activate-input-method evil-input-method) (deactivate-input-method)) (unless evil-no-display (evil-refresh-cursor (quote normal)) (evil-refresh-mode-line (quote normal)) (when (evil-called-interactively-p) (redisplay))) (cond ((evil-normal-state-p) (add-hook (quote post-command-hook) (function evil-normal-post-command) nil t)) (t (remove-hook (quote post-command-hook) (function evil-normal-post-command) t))) (run-hooks (quote evil-normal-state-entry-hook)) (when (and evil-echo-state arg (not evil-no-display) evil-normal-state-message) (if (functionp evil-normal-state-message) (funcall evil-normal-state-message) (evil-echo "%s" evil-normal-state-message)))))
  (cond ((and (numberp arg) (< arg 1)) (setq evil-previous-state evil-state evil-state nil) (let ((evil-state (quote normal))) (run-hooks (quote evil-normal-state-exit-hook)) (setq evil-state nil) (evil-esc-mode -1) (evil-normalize-keymaps) (cond ((evil-normal-state-p) (add-hook (quote post-command-hook) (function evil-normal-post-command) nil t)) (t (remove-hook (quote post-command-hook) (function evil-normal-post-command) t))))) (t (unless evil-local-mode (evil-local-mode 1)) (let ((evil-next-state (quote normal)) input-method-activate-hook input-method-deactivate-hook) (evil-change-state nil) (setq evil-state (quote normal)) (evil-add-to-alist (quote evil-previous-state-alist) (quote normal) evil-previous-state) (let ((evil-state (quote normal))) (evil-normalize-keymaps) (if t (evil-esc-mode 1) (evil-esc-mode -1)) (if (quote nil) (activate-input-method evil-input-method) (deactivate-input-method)) (unless evil-no-display (evil-refresh-cursor (quote normal)) (evil-refresh-mode-line (quote normal)) (when (evil-called-interactively-p) (redisplay))) (cond ((evil-normal-state-p) (add-hook (quote post-command-hook) (function evil-normal-post-command) nil t)) (t (remove-hook (quote post-command-hook) (function evil-normal-post-command) t))) (run-hooks (quote evil-normal-state-entry-hook)) (when (and evil-echo-state arg (not evil-no-display) evil-normal-state-message) (if (functionp evil-normal-state-message) (funcall evil-normal-state-message) (evil-echo "%s" evil-normal-state-message)))))))
  evil-normal-state(1)
  call-interactively(evil-normal-state nil nil)

Comments (2)

  1. Frank Fischer repo owner

    Guard last-insertion tracker against invalid buffer regions (fix #272)

    If a buffer modification is done without calling after-change-functions, then the tracked insertion information may be invalid. There is no way to detect that this happens, but at least we can ensure that invalid regions do not cause an error.

    → <<cset dfafe0874b65>>

  2. Frank Fischer repo owner

    Guard last-insertion tracker against invalid buffer regions (fix #272)

    If a buffer modification is done without calling after-change-functions, then the tracked insertion information may be invalid. There is no way to detect that this happens, but at least we can ensure that invalid regions do not cause an error.

    → <<cset dfafe0874b65>>

  3. Log in to comment