t9md / atom-vim-mode-plus

vim-mode improved
https://atom.io/packages/vim-mode-plus
MIT License
1.4k stars 112 forks source link

Put delete-right command in register _ (blackhole) #659

Closed tobiasandersen closed 7 years ago

tobiasandersen commented 7 years ago

Hi, thanks for the amazing work you've done here, I'm incredibly impressed!

I'm trying to put the delete-right (i.e. the x key) command's deleted character into the _ (blackhole) register. I've tried modifying the example in this guide, but without any luck. Could you point me in the right direction?

Thanks again!

PaulPorfiroff commented 7 years ago

@tobiasandersen, I was doing similar customizations and got some troubles with copy pasted code. Here's a hotfix for an issue you might have come across:

consumeService = (packageName, providerName, fn) ->
  # Test if package has already been activated
  if atom.packages.isPackageActive(packageName)
    pack = atom.packages.getActivePackage(packageName)
    service = pack.mainModule[providerName]()
    fn(service)
    return

  disposable = atom.packages.onDidActivatePackage (pack) ->
    if pack.name is packageName
      service = pack.mainModule[providerName]()
      fn(service)
      disposable.dispose()

If that didn't help, then I guess showing your init script, keymap and config would clean things up a bit.

t9md commented 7 years ago

@tobiasandersen

You want to delete by x without mutating register right? For that purpose, as you are understanding, use blackhole register(_). Most straight forward way to do this is use this tips.

https://github.com/t9md/atom-vim-mode-plus/wiki/TIPS#delete-without-saving-to-register

After that when you type \ x , you can do x without updating register.

Don't like two keystroke? then paste this into your init.coffee and restart Atom. Good luck!!

consumeService = (packageName, providerName, fn) ->
  disposable = atom.packages.onDidActivatePackage (pack) ->
    if pack.name is packageName
      service = pack.mainModule[providerName]()
      fn(service)
      disposable.dispose()

consumeService 'vim-mode-plus', 'provideVimModePlus', (service) ->
  {Base} = service
  DeleteRight = Base.getClass('DeleteRight')
  class DeleteRightWithBackholeRegister extends DeleteRight
    @commandPrefix: 'vim-mode-plus-user'
    @registerCommand()
    execute: ->
      @vimState.register.setName('_')
      super
t9md commented 7 years ago

@PaulPorfiroff you need to workaround the package-already-activated situation?

I haven't hit that situation ever. My consumeService definition never failed so want to make sure what wasn't work in your environment.

PaulPorfiroff commented 7 years ago

@t9md, yeah, did-activate-package event didn't fire in my case.

My environment is listed below.

Don't know if that's the cause, but paul-porfiroff-utils package is throwing exception on activation, as I left some work partially done and uncommented. Will fix it now and try again, though I don't think that's a real excuse for an issue.

Atom version:

$ atom-beta --version
Atom    : 1.13.0-beta8
Electron: 1.3.13
Chrome  : 52.0.2743.82
Node    : 6.5.0

Installed packages:

$ apm list
Built-in Atom Packages (89)
├── about@1.5.2
├── archive-view@0.61.1
├── atom-dark-syntax@0.27.0
├── atom-dark-ui@0.51.0
├── atom-light-syntax@0.28.0
├── atom-light-ui@0.43.0
├── autocomplete-atom-api@0.10.0
├── autocomplete-css@0.11.1
├── autocomplete-html@0.7.2
├── autocomplete-plus@2.31.0
├── autocomplete-snippets@1.11.0
├── autoflow@0.27.0
├── autosave@0.23.1
├── background-tips@0.26.0
├── base16-tomorrow-dark-theme@1.1.0
├── base16-tomorrow-light-theme@1.1.1
├── bookmarks@0.41.0
├── bracket-matcher@0.82.1
├── command-palette@0.38.0
├── deprecation-cop@0.54.1
├── dev-live-reload@0.47.0
├── encoding-selector@0.22.0
├── exception-reporting@0.38.1
├── find-and-replace@0.198.0
├── fuzzy-finder@1.3.0
├── git-diff@1.1.0
├── go-to-line@0.31.0
├── grammar-selector@0.48.1
├── image-view@0.58.0
├── incompatible-packages@0.26.1
├── keybinding-resolver@0.35.0
├── language-c@0.52.1
├── language-clojure@0.21.0
├── language-coffee-script@0.47.0
├── language-csharp@0.12.1
├── language-css@0.36.2
├── language-gfm@0.86.0
├── language-git@0.13.0
├── language-go@0.42.0
├── language-html@0.44.1
├── language-hyperlink@0.16.0
├── language-java@0.22.0
├── language-javascript@0.119.0
├── language-json@0.18.0
├── language-less@0.29.3
├── language-make@0.22.2
├── language-mustache@0.13.0
├── language-objective-c@0.15.1
├── language-perl@0.35.0
├── language-php@0.37.0
├── language-property-list@0.8.0
├── language-python@0.45.0
├── language-ruby@0.68.5
├── language-ruby-on-rails@0.25.0
├── language-sass@0.52.0
├── language-shellscript@0.22.3
├── language-source@0.9.0
├── language-sql@0.21.1
├── language-text@0.7.1
├── language-todo@0.28.0
├── language-toml@0.18.0
├── language-xml@0.34.8
├── language-yaml@0.26.0
├── line-ending-selector@0.5.0
├── link@0.31.1
├── markdown-preview@0.158.0
├── metrics@0.53.1
├── notifications@0.64.1
├── one-dark-syntax@1.2.0
├── one-dark-ui@1.3.2
├── one-light-syntax@1.2.0
├── one-light-ui@1.3.2
├── open-on-github@1.2.0
├── package-generator@1.0.0
├── settings-view@0.238.0
├── snippets@1.0.2
├── solarized-dark-syntax@1.0.2
├── solarized-light-syntax@1.0.2
├── spell-check@0.67.1
├── status-bar@1.4.0
├── styleguide@0.46.0
├── symbols-view@0.113.0
├── tabs@0.98.0
├── timecop@0.33.1
├── tree-view@0.208.0
├── update-package-dependencies@0.10.0
├── welcome@0.34.0
├── whitespace@0.32.2
└── wrap-guide@0.38.1

Dev Packages (4) /home/paulporfiroff/.atom/dev/packages
├── atom-hot-package-loader@0.5.1
├── language-tiddlywiki5@0.3.0
├── mix-selections@0.0.1
└── tiddlywiki5-tools@0.1.0

Community Packages (29) /home/paulporfiroff/.atom/packages
├── Termrk@0.3.1
├── atom-beautify@0.29.16
├── atom-hot-package-loader@0.5.1
├── atom-remove-keybindings-collisions@0.1.0
├── atomic-chrome@0.3.0
├── docblockr@0.9.1
├── editorconfig@2.2.0
├── expand-region@0.2.6
├── indent-helper@0.2.0
├── language-pug@0.0.19
├── language-tiddlywiki5@0.3.0
├── language-ts@1.0.2
├── linter@1.11.21
├── linter-coffeelint@1.2.1
├── linter-eslint@8.0.0
├── linter-tslint@0.13.1
├── live-archive@0.1.15
├── open-plus@0.10.1
├── open-recent@5.0.0
├── paner@0.4.0
├── paul-porfiroff-utils@0.0.0
├── permute@0.1.1
├── project-manager@3.3.3
├── quick-highlight@0.8.1
├── remove-all-keybindings@0.2.0
├── theme-switch@0.4.0
├── todo-show@1.9.0
├── vim-mode-plus@0.80.0
└── vmp-gutter-annotate-mark@0.3.2

└── (empty)

config.cson:

"*":
  Termrk:
    transitionDuration: 0
  "atom-beautify":
    coffeescript:
      end_with_newline: true
      indent_size: 2
      max_preserve_newlines: 2
    css:
      convert_quotes: "single"
      preserve_newlines: true
      selector_separator_newline: true
    general:
      _analyticsUserId: "f702681d-10ac-4834-bc94-7bcfabed2ec9"
      analytics: false
      beautifyEntireFileOnSave: false
    js:
      end_with_newline: true
      jslint_happy: true
      max_preserve_newlines: 2
  "atom-ctags":
    autoBuildTagsWhenActive: true
    cmd: "ctags"
    cmdArgs: "--exclude=@.ctagsignore"
    disableComplete: true
  "atom-hot-package-loader":
    detectTargetOnStart: true
  "autocomplete-plus":
    backspaceTriggersAutocomplete: true
  core:
    audioBeep: false
    autoHideMenuBar: true
    closeEmptyWindows: false
    disabledPackages: [
      "spell-check"
      "welcome"
      "update-package-dependencies"
      "atom-hot-package-loader"
      "remove-all-keybindings"
      "background-tips"
      "atom-remove-keybindings-collisions"
      "whitespace"
    ]
    packagesWithKeymapsDisabled: [
      "maximize-panes"
      "change-case"
      "open-plus"
      "atom-ctags"
      "symbols-view"
      "atom-hot-package-loader"
      "project-manager"
      "expand-region"
      "split-diff"
      "imdone-atom"
      "atom-beautify"
      "docblockr"
      "align-regexp"
    ]
    projectHome: "~/Projects"
    telemetryConsent: "no"
  "disable-keybindings":
    allBundledPackages: true
    allCommunityPackages: true
  editor:
    atomicSoftTabs: false
    fontFamily: "Monoid"
    fontSize: 16
    showIndentGuide: true
    showInvisibles: true
  "exception-reporting":
    userId: "62152e7b-d4f4-6969-4b29-f6ed5fc113fa"
  linter:
    errorPanelHeight: 22
    showErrorPanel: false
    showErrorTabFile: false
    showErrorTabProject: false
  "linter-eslint":
    disableWhenNoEslintConfig: false
  "markdown-preview":
    useGitHubStyle: true
  "one-dark-ui":
    layoutMode: "Compact"
  "open-recent":
    ignoredNames: false
    listDirectoriesAddedToProject: true
  "paul-porfiroff-utils":
    translateKeybindings: true
  "quick-highlight":
    highlightSelectionDelay: 37
  "remove-all-keybindings": {}
  tabs:
    enableVcsColoring: true
  "theme-switch":
    profiles: [
      "one-dark-ui one-dark-syntax"
      "one-light-ui one-light-syntax"
    ]
  "todo-show":
    showInTable: [
      "Type"
      "Text"
      "File"
    ]
    sortBy: "Type"
  "vim-mode-plus":
    autoSelectPersistentSelectionOnOperate: false
    clearHighlightSearchOnResetNormalMode: true
    clearPersistentSelectionOnResetNormalMode: true
    flashOnOperate: true
    flashOnSearch: true
    flashOnUndoRedo: false
    flashScreenOnSearchHasNoMatch: false
    hideTabBarOnMaximizePane: false
    incrementalSearch: true
    showHoverSearchCounter: true
    statusBarModeStringStyle: "long"
    stayOnDelete: true
    stayOnTransformString: true
    stayOnYank: true
    useClipboardAsDefaultRegister: true
    wrapLeftRightMotion: true
  whitespace:
    ignoreWhitespaceOnCurrentLine: false
    removeTrailingWhitespace: true
".gfm.source":
  editor:
    softWrap: true
    softWrapAtPreferredLineLength: true
".tw5":
  whitespace:
    removeTrailingWhitespace: false
PaulPorfiroff commented 7 years ago

Welp, as stupid as it is, disabling my package causing an error notification made things work fine. Still don't think that's an excuse.

t9md commented 7 years ago

So when you paste on your init.coffee then it show true on chrome dev console?

console.log atom.packages.isPackageActive('vim-mode-plus')

You are using macOS?

Btw, 1.13 is already become stable and current bate is 1.14. better to update.:smile:

PaulPorfiroff commented 7 years ago

So when you paste

Yes, that's an output if I put it into consumeService() in init script.

You are using macOS?

No, I use openSUSE Leap 42.2 here.

Btw, 1.13 is already become stable and current bate is 1.14. better to update.

You're right, not always catching up with the newest versions. Will try to reproduce this thing after update, cause that really an issue (unexpected behaviour) of Atom, not your init code in guide.

t9md commented 7 years ago

OK thanks, activation possible to comes BEFORE init.coffee evaluation?. Not sure, package activation is done as promise, so packges.activagte() return immediately. So I thought init.coffee processed BEFORE vmp activation.

Anyway I'll update consumeService utility on wiki to save situation you suffered.

PaulPorfiroff commented 7 years ago

So I thought init.coffee processed BEFORE vmp activation.

Yeah, expected that too.

Anyway I'll update consumeService utility on wiki to save situation you suffered.

Thanks.

t9md commented 7 years ago

Updated consumeService utility on wiki here.

https://github.com/t9md/atom-vim-mode-plus/wiki/ExtendVimModePlusInInitFile#overview

PaulPorfiroff commented 7 years ago

I've just updated my atoms and both, 1.13.0 and 1.14.0-beta2, work as expected with original consumeService() even if my package throwing an exception is enabled. So, for newer versions there seem to be no issue anymore.

t9md commented 7 years ago

OK, thanks for checking. Anyway taking care of already-activated situation seems no harm and worth to know. So thanks!

tobiasandersen commented 7 years ago

Thanks for the help, but I'm still unable to get this working. I think we're talking about the same thing, but just to clarify:

If I stand on the first character of a line and do yy, followed by " _ x, the first character will disappear, but the next time I press e.g. p, the whole line will be pasted.

This is what I want as the default behavior for x. So if I did the exact same thing, but instead of " _ x, I just do x, I'd expect the same result.

I removed everything in my init.coffee except those to blocks you gave me. What's a good way to troubleshoot this?

PaulPorfiroff commented 7 years ago

@tobiasandersen, have you remapped x key to the new 'vim-mode-plus-user:delete-right-with-backhole-register' command? Try running it from the Command Palette directly.

t9md commented 7 years ago

@tobiasandersen Ya, we are talking about SAME thing, and your expectation is correct. For troubleshoot, follow @PaulPorfiroff 's instruction.

tobiasandersen commented 7 years ago

Oh, I'm new to Atom and didn't even understand this created a new command. Mapping it in my keymap solved it, thanks for your help guys!

t9md commented 7 years ago

Finally you did it and learned how atom-keymap system works, congrats 🎉 !!

snide commented 6 years ago

Sorry to add to the noise. This used to work for me (many months ago), but I think @t9md removed the blackhole register commands to use a more generic system. I'm able to get a \ d map to delete without yanking, but I can no longer get a plain d to delete without the yank. Is there a new way to handle this then the way described above?

t9md commented 6 years ago

@snide

I updated wiki for TIPS and linked custom operation to be more explicit(and also fixed some bug).

https://github.com/t9md/atom-vim-mode-plus/wiki/TIPS#delete-without-saving-to-register

Does this make sense to you?

snide commented 6 years ago

@t9md Yes. I sent you an edit for the wiki (to clear up some wording) as well as some bountysource love. Thank you for maintaining this fantastic plugin.

t9md commented 6 years ago

WOW, Thank you for wording fix and bounty! 😍