mirror of
				https://github.com/NotAShelf/nvf.git
				synced 2025-10-31 19:12:38 +00:00 
			
		
		
		
	vim.maps rewrite (#352)
* feat: rewrite vim.maps * modules/mappings: enable silent by default * docs: add entry for vim.maps rewrite * lib/binds: improve code, adjust functions to new api
This commit is contained in:
		
					parent
					
						
							
								fd65c83956
							
						
					
				
			
			
				commit
				
					
						b71bf75dcd
					
				
			
		
					 5 changed files with 150 additions and 274 deletions
				
			
		
							
								
								
									
										121
									
								
								lib/binds.nix
									
										
									
									
									
								
							
							
						
						
									
										121
									
								
								lib/binds.nix
									
										
									
									
									
								
							|  | @ -4,69 +4,68 @@ | |||
|   inherit (lib.types) nullOr str; | ||||
|   inherit (lib.attrsets) isAttrs mapAttrs; | ||||
| 
 | ||||
|   binds = rec { | ||||
|     mkLuaBinding = key: action: desc: | ||||
|       mkIf (key != null) { | ||||
|         "${key}" = { | ||||
|           inherit action desc; | ||||
|           lua = true; | ||||
|           silent = true; | ||||
|   mkLuaBinding = mode: key: action: desc: | ||||
|     mkIf (key != null) { | ||||
|       ${key} = { | ||||
|         inherit mode action desc; | ||||
|         lua = true; | ||||
|         silent = true; | ||||
|       }; | ||||
|     }; | ||||
| 
 | ||||
|   mkExprBinding = mode: key: action: desc: | ||||
|     mkIf (key != null) { | ||||
|       ${key} = { | ||||
|         inherit mode action desc; | ||||
|         lua = true; | ||||
|         silent = true; | ||||
|         expr = true; | ||||
|       }; | ||||
|     }; | ||||
| 
 | ||||
|   mkBinding = mode: key: action: desc: | ||||
|     mkIf (key != null) { | ||||
|       ${key} = { | ||||
|         inherit mode action desc; | ||||
|         silent = true; | ||||
|       }; | ||||
|     }; | ||||
| 
 | ||||
|   mkMappingOption = description: default: | ||||
|     mkOption { | ||||
|       type = nullOr str; | ||||
|       inherit default description; | ||||
|     }; | ||||
| 
 | ||||
|   # Utility function that takes two attrsets: | ||||
|   # { someKey = "some_value" } and | ||||
|   # { someKey = { description = "Some Description"; }; } | ||||
|   # and merges them into | ||||
|   # { someKey = { value = "some_value"; description = "Some Description"; }; } | ||||
|   addDescriptionsToMappings = actualMappings: mappingDefinitions: | ||||
|     mapAttrs (name: value: let | ||||
|       isNested = isAttrs value; | ||||
|       returnedValue = | ||||
|         if isNested | ||||
|         then addDescriptionsToMappings actualMappings.${name} mappingDefinitions.${name} | ||||
|         else { | ||||
|           inherit value; | ||||
|           inherit (mappingDefinitions.${name}) description; | ||||
|         }; | ||||
|       }; | ||||
|     in | ||||
|       returnedValue) | ||||
|     actualMappings; | ||||
| 
 | ||||
|     mkExprBinding = key: action: desc: | ||||
|       mkIf (key != null) { | ||||
|         "${key}" = { | ||||
|           inherit action desc; | ||||
|           lua = true; | ||||
|           silent = true; | ||||
|           expr = true; | ||||
|         }; | ||||
|       }; | ||||
|   mkSetBinding = mode: binding: action: | ||||
|     mkBinding mode binding.value action binding.description; | ||||
| 
 | ||||
|     mkBinding = key: action: desc: | ||||
|       mkIf (key != null) { | ||||
|         "${key}" = { | ||||
|           inherit action desc; | ||||
|           silent = true; | ||||
|         }; | ||||
|       }; | ||||
|   mkSetExprBinding = mode: binding: action: | ||||
|     mkExprBinding mode binding.value action binding.description; | ||||
| 
 | ||||
|     mkMappingOption = description: default: | ||||
|       mkOption { | ||||
|         type = nullOr str; | ||||
|         inherit default description; | ||||
|       }; | ||||
|   mkSetLuaBinding = mode: binding: action: | ||||
|     mkLuaBinding mode binding.value action binding.description; | ||||
| 
 | ||||
|     # Utility function that takes two attrsets: | ||||
|     # { someKey = "some_value" } and | ||||
|     # { someKey = { description = "Some Description"; }; } | ||||
|     # and merges them into | ||||
|     # { someKey = { value = "some_value"; description = "Some Description"; }; } | ||||
|     addDescriptionsToMappings = actualMappings: mappingDefinitions: | ||||
|       mapAttrs (name: value: let | ||||
|         isNested = isAttrs value; | ||||
|         returnedValue = | ||||
|           if isNested | ||||
|           then addDescriptionsToMappings actualMappings."${name}" mappingDefinitions."${name}" | ||||
|           else { | ||||
|             inherit value; | ||||
|             inherit (mappingDefinitions."${name}") description; | ||||
|           }; | ||||
|       in | ||||
|         returnedValue) | ||||
|       actualMappings; | ||||
| 
 | ||||
|     mkSetBinding = binding: action: | ||||
|       mkBinding binding.value action binding.description; | ||||
| 
 | ||||
|     mkSetExprBinding = binding: action: | ||||
|       mkExprBinding binding.value action binding.description; | ||||
| 
 | ||||
|     mkSetLuaBinding = binding: action: | ||||
|       mkLuaBinding binding.value action binding.description; | ||||
| 
 | ||||
|     pushDownDefault = attr: mapAttrs (_: mkDefault) attr; | ||||
|   }; | ||||
| in | ||||
|   binds | ||||
|   pushDownDefault = attr: mapAttrs (_: mkDefault) attr; | ||||
| in { | ||||
|   inherit mkLuaBinding mkExprBinding mkBinding mkMappingOption addDescriptionsToMappings mkSetBinding mkSetExprBinding mkSetLuaBinding pushDownDefault; | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 diniamo
				diniamo