Match magics
(self, text)
| 1240 | return [x+'/' if os.path.isdir(x) else x for x in matches] |
| 1241 | |
| 1242 | def magic_matches(self, text): |
| 1243 | """Match magics""" |
| 1244 | # Get all shell magics now rather than statically, so magics loaded at |
| 1245 | # runtime show up too. |
| 1246 | lsm = self.shell.magics_manager.lsmagic() |
| 1247 | line_magics = lsm['line'] |
| 1248 | cell_magics = lsm['cell'] |
| 1249 | pre = self.magic_escape |
| 1250 | pre2 = pre+pre |
| 1251 | |
| 1252 | explicit_magic = text.startswith(pre) |
| 1253 | |
| 1254 | # Completion logic: |
| 1255 | # - user gives %%: only do cell magics |
| 1256 | # - user gives %: do both line and cell magics |
| 1257 | # - no prefix: do both |
| 1258 | # In other words, line magics are skipped if the user gives %% explicitly |
| 1259 | # |
| 1260 | # We also exclude magics that match any currently visible names: |
| 1261 | # https://github.com/ipython/ipython/issues/4877, unless the user has |
| 1262 | # typed a %: |
| 1263 | # https://github.com/ipython/ipython/issues/10754 |
| 1264 | bare_text = text.lstrip(pre) |
| 1265 | global_matches = self.global_matches(bare_text) |
| 1266 | if not explicit_magic: |
| 1267 | def matches(magic): |
| 1268 | """ |
| 1269 | Filter magics, in particular remove magics that match |
| 1270 | a name present in global namespace. |
| 1271 | """ |
| 1272 | return ( magic.startswith(bare_text) and |
| 1273 | magic not in global_matches ) |
| 1274 | else: |
| 1275 | def matches(magic): |
| 1276 | return magic.startswith(bare_text) |
| 1277 | |
| 1278 | comp = [ pre2+m for m in cell_magics if matches(m)] |
| 1279 | if not text.startswith(pre2): |
| 1280 | comp += [ pre+m for m in line_magics if matches(m)] |
| 1281 | |
| 1282 | return comp |
| 1283 | |
| 1284 | def magic_config_matches(self, text:str) -> List[str]: |
| 1285 | """ Match class names and attributes for %config magic """ |
nothing calls this directly
no test coverage detected