@@ -540,36 +540,51 @@ M.translate_invalid_key_behavior = function(invalid_surround)
540540 return invalid
541541end
542542
543+ -- Translates `alias` into the internal form.
544+ --- @param user_alias false | string | string[] The user-provided ` alias` .
545+ --- @return string | string[] | nil @The translated ` alias` .
546+ M .translate_alias = function (user_alias )
547+ if not user_alias then
548+ return nil
549+ end
550+ return user_alias
551+ end
552+
543553-- Translates the user-provided configuration into the internal form.
544554--- @param user_opts user_options The user-provided options.
545555--- @return options @The translated options.
546556M .translate_opts = function (user_opts )
547557 local input = require (" nvim-surround.input" )
548558 local opts = {}
549559 for key , value in pairs (user_opts ) do
550- if key == " surrounds" then
560+ if key == " surrounds" or key == " aliases " then
551561 elseif key == " indent_lines" then
552562 opts [key ] = value or function () end
553563 else
554564 opts [key ] = value
555565 end
556566 end
557- if not user_opts .surrounds then
558- return opts
559- end
560-
561- opts .surrounds = {}
562- for char , user_surround in pairs (user_opts .surrounds ) do
563- char = input .replace_termcodes (char )
564- -- Special case translation for `invalid_key_behavior`
565- if type (user_surround ) ~= " nil" then
566- if char == " invalid_key_behavior" then
567- opts .surrounds [char ] = M .translate_invalid_key_behavior (user_surround )
568- else
569- opts .surrounds [char ] = M .translate_surround (char , user_surround )
567+ if user_opts .surrounds then
568+ opts .surrounds = {}
569+ for char , user_surround in pairs (user_opts .surrounds ) do
570+ char = input .replace_termcodes (char )
571+ -- Special case translation for `invalid_key_behavior`
572+ if type (user_surround ) ~= " nil" then
573+ if char == " invalid_key_behavior" then
574+ opts .surrounds [char ] = M .translate_invalid_key_behavior (user_surround )
575+ else
576+ opts .surrounds [char ] = M .translate_surround (char , user_surround )
577+ end
570578 end
571579 end
572580 end
581+ if user_opts .aliases then
582+ opts .aliases = {}
583+ for char , user_alias in pairs (user_opts .aliases ) do
584+ char = input .replace_termcodes (char )
585+ opts .aliases [char ] = M .translate_alias (user_alias )
586+ end
587+ end
573588 return opts
574589end
575590
0 commit comments