Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Cell Macros (similar to IPython cell magics but easily user-definable) #937

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

cduck
Copy link

@cduck cduck commented Jul 20, 2020

Adds the ability to apply macros to the contents of an entire cell in IJulia. The use case that prompted me to implement this can be seen here.

Simple use case (assume soft scope is disabled):

### Cell 1 ###
using SoftGlobalScope

### Cell 2 ###
@@softscope
x=0
for i in 1:10 x+=i end
x

Equivalent to:

@softscope begin  # :toplevel block
    x=0
    for i in 1:10 x+=i end
    x
end

Features:

  • Runs any number of macros listed at the beginning of a cell. The lowest macro is run first.
  • Expressions on the same line as a cell macro are included as arguments. The cell contents are the last argument.
  • Automatically runs the macros in IJulia.cell_macros afterward. If soft scope is enabled, var"@softscope" is included here.
  • Include @@noauto in the cell to disable the automatic macros for that cell. (Useful for debugging or recovering from pushing a bad macro.)
  • Tab completion works just like for regular macros.

I'm relatively new to Julia so please give me suggestions if my code style or macro usage could be improved. I can add tests and documentation if needed.

@cduck
Copy link
Author

cduck commented May 6, 2021

Bump.

@stevengj
Copy link
Member

I'm not sure we want to encourage people to use syntax in Jupyter notebooks that can't be copied-and-pasted to other Julia code. They can always use regular macros, string macros, etcetera…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants