Code Monkey home page Code Monkey logo

Comments (6)

lacygoill avatar lacygoill commented on June 11, 2024 1

Understood. I don't have much experience with <script>, but here is a new attempt:

diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim
index 8145728..ae915b5 100644
--- a/ftplugin/ruby.vim
+++ b/ftplugin/ruby.vim
@@ -157,8 +157,8 @@ function! s:map(mode, flags, map) abort
 endfunction
 
 cmap <buffer><script><expr> <Plug><ctag> substitute(RubyCursorTag(),'^$',"\022\027",'')
-cmap <buffer><script><expr> <Plug><cfile> substitute(RubyCursorFile(),'^$',"\022\006",'')
-let b:undo_ftplugin .= "| sil! cunmap <buffer> <Plug><ctag>| sil! cunmap <buffer> <Plug><cfile>"
+cmap <buffer><script><expr> <SID><cfile> substitute(RubyCursorFile(),'^$',"\022\006",'')
+let b:undo_ftplugin .= "| sil! cunmap <buffer> <Plug><ctag>| sil! cunmap <buffer> <SID><cfile>"
 
 if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
   nmap <buffer><script> <SID>:  :<C-U>
@@ -206,7 +206,7 @@ if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
           \."| sil! exe 'xunmap <buffer> iM' | sil! exe 'xunmap <buffer> aM'"
   endif
 
-  call s:map('c', '', '<C-R><C-F> <Plug><cfile>')
+  call s:map('c', '', '<C-R><C-F> <SID><cfile>')
 
   cmap <buffer><script><expr> <SID>tagzv &foldopen =~# 'tag' ? '<Bar>norm! zv' : ''
   call s:map('n', '<silent>', '<C-]>       <SID>:exe  v:count1."tag <Plug><ctag>"<SID>tagzv<CR>')
@@ -219,10 +219,10 @@ if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
   call s:map('n', '<silent>', '<C-W>}      <SID>:exe v:count1."ptag <Plug><ctag>"<CR>')
   call s:map('n', '<silent>', '<C-W>g}     <SID>:exe        "ptjump <Plug><ctag>"<CR>')
 
-  call s:map('n', '<silent>', 'gf           <SID>c:find <Plug><cfile><CR>')
-  call s:map('n', '<silent>', '<C-W>f      <SID>c:sfind <Plug><cfile><CR>')
-  call s:map('n', '<silent>', '<C-W><C-F>  <SID>c:sfind <Plug><cfile><CR>')
-  call s:map('n', '<silent>', '<C-W>gf   <SID>c:tabfind <Plug><cfile><CR>')
+  call s:map('n', '<script><silent>', 'gf           <SID>c:find <SID><cfile><CR>')
+  call s:map('n', '<script><silent>', '<C-W>f      <SID>c:sfind <SID><cfile><CR>')
+  call s:map('n', '<script><silent>', '<C-W><C-F>  <SID>c:sfind <SID><cfile><CR>')
+  call s:map('n', '<script><silent>', '<C-W>gf   <SID>c:tabfind <SID><cfile><CR>')
 endif
 
 let &cpo = s:cpo_save

It adds <script> to make gf and friends less recursive, and replaces all <Plug><cfile> with <SID><cfile>.
I tested the patch on my machine, and can confirm it correctly fixes the gf behavior.

from vim-ruby.

lacygoill avatar lacygoill commented on June 11, 2024

But I can suggest trying to enter the command-line with instead of a colon.

I forgot that this plugin could be used alone, and not necessarily as part of the Vim runtime files. In that case, <Cmd> might be too recent for an old Vim (it was introduced in patch 8.2.1978).

I guess another solution would be to introduce an intermediate non-recursive mapping. Being non-recursive would disallow any expansion of abbreviations.

from vim-ruby.

tpope avatar tpope commented on June 11, 2024

But I can suggest trying to enter the command-line with instead of a colon.

I forgot that this plugin could be used alone, and not necessarily as part of the Vim runtime files. In that case, <Cmd> might be too recent for an old Vim (it was introduced in patch 8.2.1978).

Correct.

I guess another solution would be to introduce an intermediate non-recursive mapping. Being non-recursive would disallow any expansion of abbreviations.

Correct again. You could cmap <buffer> <SID><cfile> <Plug><cfile>, then use <script> maps to call that rather than the <Plug><cfile> directly.

from vim-ruby.

lacygoill avatar lacygoill commented on June 11, 2024

You could cmap <buffer> <SID><cfile> <Plug><cfile>, then use <script> maps to call that rather than the <Plug><cfile> directly.

All right, so here is an attempt at a better fix using your suggested mapping:

diff --git a/runtime/ftplugin/ruby.vim b/runtime/ftplugin/ruby.vim
index 4a476fd8c..6e11b569a 100644
--- a/runtime/ftplugin/ruby.vim
+++ b/runtime/ftplugin/ruby.vim
@@ -159,6 +159,10 @@ endfunction
 
 cmap <buffer><script><expr> <Plug><ctag> substitute(RubyCursorTag(),'^$',"\022\027",'')
 cmap <buffer><script><expr> <Plug><cfile> substitute(RubyCursorFile(),'^$',"\022\006",'')
+cmap <buffer> <SID><cfile> <Plug><cfile>
+cnoremap <buffer> <SID>find find<Space>
+cnoremap <buffer> <SID>sfind sfind<Space>
+cnoremap <buffer> <SID>tabfind tabfind<Space>
 let b:undo_ftplugin .= "| sil! cunmap <buffer> <Plug><ctag>| sil! cunmap <buffer> <Plug><cfile>"
 
 if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
@@ -220,10 +224,10 @@ if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
   call s:map('n', '<silent>', '<C-W>}      <SID>:exe v:count1."ptag <Plug><ctag>"<CR>')
   call s:map('n', '<silent>', '<C-W>g}     <SID>:exe        "ptjump <Plug><ctag>"<CR>')
 
-  call s:map('n', '<silent>', 'gf           <SID>c:find <Plug><cfile><CR>')
-  call s:map('n', '<silent>', '<C-W>f      <SID>c:sfind <Plug><cfile><CR>')
-  call s:map('n', '<silent>', '<C-W><C-F>  <SID>c:sfind <Plug><cfile><CR>')
-  call s:map('n', '<silent>', '<C-W>gf   <SID>c:tabfind <Plug><cfile><CR>')
+  call s:map('n', '<silent>', 'gf           <SID>c:<SID>find<SID><cfile><CR>')
+  call s:map('n', '<silent>', '<C-W>f      <SID>c:<SID>sfind<SID><cfile><CR>')
+  call s:map('n', '<silent>', '<C-W><C-F>  <SID>c:<SID>sfind<SID><cfile><CR>')
+  call s:map('n', '<silent>', '<C-W>gf   <SID>c:<SID>tabfind<SID><cfile><CR>')
 endif
 
 let &cpo = s:cpo_save

It does fix the issue on my machine, but maybe it can be simplified further.

from vim-ruby.

lacygoill avatar lacygoill commented on June 11, 2024

Sorry, the previous patch was obtained from the Vim runtime files. New patch obtained from the vim-ruby plugin:

diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim
index 8145728..a6a3a29 100644
--- a/ftplugin/ruby.vim
+++ b/ftplugin/ruby.vim
@@ -158,6 +158,10 @@ endfunction
 
 cmap <buffer><script><expr> <Plug><ctag> substitute(RubyCursorTag(),'^$',"\022\027",'')
 cmap <buffer><script><expr> <Plug><cfile> substitute(RubyCursorFile(),'^$',"\022\006",'')
+cmap <buffer> <SID><cfile> <Plug><cfile>
+cnoremap <buffer> <SID>find find<Space>
+cnoremap <buffer> <SID>sfind sfind<Space>
+cnoremap <buffer> <SID>tabfind tabfind<Space>
 let b:undo_ftplugin .= "| sil! cunmap <buffer> <Plug><ctag>| sil! cunmap <buffer> <Plug><cfile>"
 
 if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
@@ -219,10 +223,10 @@ if !exists("g:no_plugin_maps") && !exists("g:no_ruby_maps")
   call s:map('n', '<silent>', '<C-W>}      <SID>:exe v:count1."ptag <Plug><ctag>"<CR>')
   call s:map('n', '<silent>', '<C-W>g}     <SID>:exe        "ptjump <Plug><ctag>"<CR>')
 
-  call s:map('n', '<silent>', 'gf           <SID>c:find <Plug><cfile><CR>')
-  call s:map('n', '<silent>', '<C-W>f      <SID>c:sfind <Plug><cfile><CR>')
-  call s:map('n', '<silent>', '<C-W><C-F>  <SID>c:sfind <Plug><cfile><CR>')
-  call s:map('n', '<silent>', '<C-W>gf   <SID>c:tabfind <Plug><cfile><CR>')
+  call s:map('n', '<silent>', 'gf           <SID>c:<SID>find<SID><cfile><CR>')
+  call s:map('n', '<silent>', '<C-W>f      <SID>c:<SID>sfind<SID><cfile><CR>')
+  call s:map('n', '<silent>', '<C-W><C-F>  <SID>c:<SID>sfind<SID><cfile><CR>')
+  call s:map('n', '<silent>', '<C-W>gf   <SID>c:<SID>tabfind<SID><cfile><CR>')
 endif
 
 let &cpo = s:cpo_save

from vim-ruby.

tpope avatar tpope commented on June 11, 2024

The goal is to use <script>, which will prevent abbreviations from expanding and eliminate the need for per-command SID maps. Something like this:

call s:map('n', '<script><silent>', 'gf           <SID>c:find <SID><cfile><CR>')

from vim-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.