@@ -448,24 +448,36 @@ function OrgMappings:org_return()
448
448
end
449
449
end
450
450
451
- if not config .old_cr_mapping or vim .tbl_isempty (config .old_cr_mapping ) then
451
+ local old_mapping = config .old_cr_mapping
452
+
453
+ if not old_mapping or vim .tbl_isempty (old_mapping ) then
452
454
return vim .api .nvim_feedkeys (utils .esc (' <CR>' ), ' n' , true )
453
455
end
454
456
455
- local rhs = config .old_cr_mapping .rhs
457
+ local rhs = old_mapping .rhs
458
+
459
+ if old_mapping .expr > 0 then
460
+ rhs = vim .api .nvim_eval (rhs )
461
+ end
456
462
457
- if config . old_cr_mapping .script > 0 then
458
- rhs = rhs :gsub (' <SID>' , string.format (' <SNR>%d_' , config . old_cr_mapping .sid ))
463
+ if old_mapping .script > 0 then
464
+ rhs = rhs :gsub (' <SID>' , string.format (' <SNR>%d_' , old_mapping .sid ))
459
465
if rhs :match (' ^<CR>' ) then
460
466
rhs = rhs :gsub (' <CR>' , ' ' )
461
467
vim .api .nvim_feedkeys (utils .esc (' <CR>' ), ' n' , true )
462
468
end
463
469
464
- return vim .api .nvim_feedkeys (utils .esc (rhs ), ' ' , true )
465
- end
470
+ if rhs :match (' ^' .. utils .esc (' <CR>' )) then
471
+ rhs = rhs :gsub (' ^' .. utils .esc (' <CR>' ), ' ' )
472
+ vim .api .nvim_feedkeys (utils .esc (' <CR>' ), ' n' , true )
473
+ end
466
474
467
- if config .old_cr_mapping .expr > 0 then
468
- rhs = vim .api .nvim_eval (rhs )
475
+ if old_mapping .expr > 0 and rhs :match (' ^' .. utils .esc (' <c-r>' ) .. ' =' ) then
476
+ rhs = rhs :gsub (' ^' .. utils .esc (' <c-r>' ) .. ' =' , ' ' ):gsub (utils .esc (' <CR>' ) .. ' $' , ' ' )
477
+ rhs = vim .api .nvim_eval (rhs )
478
+ end
479
+
480
+ return vim .api .nvim_feedkeys (utils .esc (rhs ), ' ' , true )
469
481
end
470
482
471
483
return vim .api .nvim_feedkeys (utils .esc (rhs ), ' n' , true )
0 commit comments