Say I have a buffer with code (in this case Python) organized as follows:
.. cell 1 ..
##
.. cell 2 ..
# this is a comment
### this is also a comment
.. still cell 2 ..
##
.. cell 3 (code that is indented)
The sequence of characters ##
is meant to delimit cells
(code regions/blocks) in the buffer. The caracter #
starts a comment in Python, so ##
is treated as a comment by the language. Similar constructions could be built in e.g. Elisp with ;;
or other programming languages.
I would like to define an Emacs command that when invoked, it defines the current cell
(i.e. the cell
on which point/cursor currently sits.) to be the Emacs region
(i.e. it highlights the cell).
How can I do this in Emacs?
For reference:
- The is akin to the notion of cells or code sections in MATLAB
- Here is a thread for implementing this functionality in Vim.