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

Disable evil-escape by default #6936

Closed
sliedes opened this issue Aug 27, 2016 · 15 comments
Closed

Disable evil-escape by default #6936

sliedes opened this issue Aug 27, 2016 · 15 comments
Labels
- Mailling list - Discussion Evil-escape stale marked as a stale issue/pr (usually by a bot)

Comments

@sliedes
Copy link

sliedes commented Aug 27, 2016

Description

When spacemacs is open in a text terminal (emacs -nw at least in either konsole or gnome-terminal) and in insert mode, using the terminal's paste feature to paste the text mkfd from X clipboard results in only mk being inserted. This does not happen with vanilla emacs (emacs -nw -q) nor in spacemacs in windowed mode (emacs without -nw).

Reproduction guide

  • Start emacs -nw in konsole or gnome-terminal
  • Press q to close the splash screen
  • Press i to enter the insert mode
  • In a different terminal/browser/whatever, select the text mkfd and copy it to clipboard
  • Test paste clipboard contents to another terminal to ensure that the contents are indeed mkfd
  • Use the terminal's paste feature to paste the string to spacemacs

Observed behaviour:
Text mk is inserted.

Expected behaviour:
Text mkfd is inserted.

System Info

  • OS: gnu/linux
  • Emacs: 24.5.1
  • Spacemacs: 0.105.22
  • Spacemacs branch: master (rev. 9f9faa4)
  • Graphic display: nil
  • Distribution: spacemacs
  • Editing style: vim
  • Completion: helm
  • Layers:
(auto-completion emacs-lisp haskell syntax-checking)
@NJBS
Copy link
Contributor

NJBS commented Aug 27, 2016

This is a side-effect of evil-escape on terminals.

Duplicate of #5268

@TheBB
Copy link
Collaborator

TheBB commented Aug 27, 2016

Yeah, you should probably paste from the clipboard instead of streaming characters in the terminal. That will usually not end well.

Note that Emacs can't access the system clipboard when running in terminal mode though. May just be one of those things that you have to stomach.

@sliedes
Copy link
Author

sliedes commented Aug 27, 2016

Are you sure it is a good idea to have this enabled by default? It's certainly surprising to have characters eaten from the middle of a base64 encoded string in a URL (which is what happened to me), and I've never heard of this feature before.

Note that this also has quite obvious security implications. If pasted text can run arbitrary commands, you must never paste text you do not trust or have audited...

@TheBB
Copy link
Collaborator

TheBB commented Aug 27, 2016

Note that this also has quite obvious security implications. If pasted text can run arbitrary commands, you must never paste text you do not trust or have audited...

Pasted text can't run arbitrary commands. Streamed characters into the terminal can, and they can do that regardless of what you're running. Try opening vim, going to insert state and then pasting ^[:!echo oh looks like i can run shell commands^M or equivalent.

If you have xclip installed, here's a hack that allows Emacs (at least, evil) to access the X clipboard(s). I don't know if it works with the standard Emacs copy/paste.

(defun bb/x-get-selection (orig-fun &optional type data-type)
  (condition-case nil
      (funcall orig-fun type data-type)
    (error
     (when (and (executable-find "xclip")
                (memq type '(PRIMARY CLIPBOARD)))
       (let ((type (if (eq 'PRIMARY type) "primary" "clipboard")))
         (shell-command-to-string
          (format "xclip -selection %s -o" type)))))))
(advice-add 'x-get-selection :around 'bb/x-get-selection)

@sliedes
Copy link
Author

sliedes commented Aug 27, 2016

But a terminal can help you there; xterm and gnome-terminal won't let you paste many control characters (like ESC). (To my dismay, I realized konsole does let them through.) Also getting such strings to the clipboard via a web page is probably much more difficult than getting a string containing "fd" there.

@TheBB
Copy link
Collaborator

TheBB commented Aug 27, 2016

Yep, all true. If there's widespread support for disabling evil-escape by default, we can discuss it, but I don't expect there to be.

@TheBB TheBB changed the title Pasting text in terminal mode (emacs -nw) eats characters Disable evil-escape by default Aug 27, 2016
@sliedes
Copy link
Author

sliedes commented Aug 27, 2016

One option might be to disable it only when running in terminal mode?

@amosbird
Copy link
Contributor

Doesn't bracketed paste mode take care of such issue?

@TheBB
Copy link
Collaborator

TheBB commented Aug 28, 2016

Yeah, it should. How easily accessable is it?

@amosbird
Copy link
Contributor

Well, I did nothing to set things up and haven't encountered a problem since using emacs-25rc and urxvt.

@TheBB
Copy link
Collaborator

TheBB commented Aug 28, 2016

Just asking because I don't see any functions by that name.

@bmag
Copy link
Collaborator

bmag commented Aug 28, 2016

The plot thickens: Tried the repro steps on Emacs 25.1-rc2, develop branch, hybrid editing style, gnome-terminal. Encountered the expected behavior, no bug. Then I tried with vim editing style instead of hybrid, and I encountered the bug.

As for bracketed-paste, the package isn't used in Emacs 25.1. From spacemacs-editing/packages.el:

(setq spacemacs-editing-packages
      '( ;; ... snipped ...
        (bracketed-paste :toggle (version<= emacs-version "25.0.92"))
        ;; ... snipped ...
        ))

@bmag
Copy link
Collaborator

bmag commented Aug 28, 2016

Something on our side is causing the trouble. With this repro I see no bug:

  1. emacs -Q -nw -L /path/to/elpa/evil-escape-<timestamp>/ -L /path/to/elpa/evil-<timestamp>/
  2. evaluate in scratch buffer:
(require 'evil)
(require 'evil-escape)
(evil-mode)
(evil-escape-mode)
  1. enter insert state with i
  2. use terminal to paste mkfd from clipboard

Observed behvaior: mkfd is insterted into the buffer, state remains insert-state.

(the numbering is supposed to be 1,2,3,4 of course, not 1,2,1,2, but GitHub is acting dumb and stubborn)

@parthsdoshi
Copy link

This doesn't seem to happen with emacs 25.2.1 with vim editing style. Typing fd quickly will take me back to normal mode but I can paste mkfd just fine. I'm on macOS running spacemacs through iTerm 2.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Mailling list - Discussion Evil-escape stale marked as a stale issue/pr (usually by a bot)
Projects
Mailing list
  
Other
Development

No branches or pull requests

6 participants