Skip to content

Commit eccf228

Browse files
krisctlprabhakk-mw
authored andcommitted
Adds support for alternate syntax to display help for magic commands using the ? symbol.
1 parent 625f973 commit eccf228

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/jupyter_matlab_kernel/magic_execution_engine.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ def get_magics_from_cell(cell_code):
145145
params = magic_dict["params"].strip()
146146
if params:
147147
magic_dict["params"] = re.split("\s+", params)
148+
# transform ? parameter into a help magic, such that %%file? becomes %%help file
149+
if params.startswith("?"):
150+
# Ignore additional parameters after the ? parameter
151+
magic_dict["params"] = [magic_dict.get("name", "")]
152+
magic_dict["name"] = "help"
148153
else:
149154
magic_dict["params"] = []
150155
magic_dict["line_number"] = line_number

src/jupyter_matlab_kernel/magics/README.md

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
# Magic Commands for MATLAB Kernel
22

3-
You can use magic commands with the MATLAB kernel. You can use the predefined magic commands in this folder, and you can implement your own by following the steps below.
3+
This guide shows how to use magic commands with the MATLAB kernel for added functionality.
44

55
## Get Started
66

7-
Magic commands for the MATLAB kernel are prefixed with two percentage symbols `%%` without whitespaces. For example, to list available magic commands, run `%%lsmagic`
7+
Magic commands for the MATLAB kernel are prefixed with two percentage symbols `%%` without whitespaces. For example, to list available magic commands, run `%%lsmagic`. To read the documentation of a magic command, use the help command `?` or `help`, for example `%%lsmagic?` or `%%help lsmagic`.
88

9-
Note that magic commands will only work at the beginning of cells, and will not work with MATLAB variables.
10-
11-
The magic commands `help` and `file` accept additional parameters. For example, to display information about a magic command, run `%%help` followed by the name of the magic as an argument: `%%help time`
9+
Note that magic commands only work at the beginning of cells.
1210

1311
This table lists the predefined magic commands you can use:
1412

1513

1614
|Name|Description|Additional Parameters|Constraints|Example command|
1715
|---|---|---|---|---|
18-
|lsmagic|List predefined magic commands.|||`%%lsmagic`|
19-
|help|Display information about provided magic command. | Name of magic command.|| `%%help file`|
20-
|time|Display time taken to execute a cell.|||`%%time`|
21-
|file|Save contents of cell as a file in the notebook folder. You can use this command to define and save new functions. For details, see the section below on how to [Create New Functions Using the %%file Magic Command](#create-new-functions-using-the-the-file-magic-command)|Name of saved file|The file magic command will save the contents of the cell, but not execute them in MATLAB|`%%file myfile.m`|
16+
|`?` and `help`| Display documentation of given magic command.|Name of magic command.||`%%lsmagic?` or `%%help lsmagic`|
17+
|`lsmagic`|List predefined magic commands.|||`%%lsmagic`|
18+
|`time`|Display time taken to execute a cell.|||`%%time`|
19+
|`file`|Save contents of cell as a file in the notebook folder. You can use this command to define and save new functions. For details, see the section below on how to [Create New Functions Using the %%file Magic Command](#create-new-functions-using-the-the-file-magic-command)|Name of saved file.|The file magic command will save the contents of the cell, but not execute them in MATLAB.|`%%file myfile.m`|
2220

2321

2422
To request a new magic command, [create an issue](https://github.com/mathworks/jupyter-matlab-proxy/issues/new/choose).

0 commit comments

Comments
 (0)