I'm working on a plotly dash app where there are a number of nested blocks of code like the following:
dbc.Row(
[
dbc.Col(
[
<some long code>
]
),
dbc.Col(
[
<another piece of code>
]
),
]
),
I would like to be able to fold the code between two matching bracket or parentheses symbols. My init file has the following configuration for hs
(taken from the hide show emacswiki page) and it does what I want if I switch to R-mode
(i.e. fold the code using C-+
when the cursor is at a symbol) . Then, of course, all the python functionalities are off. Is there a way to fold the code between brackets within python mode. Ideally a custom mode/function that I can toggle when working with dash apps. Thanks
(defun toggle-selective-display (column)
(interactive "P")
(set-selective-display
(or column
(unless selective-display
(1+ (current-column))))))
(defun toggle-hiding (column)
(interactive "P")
(if hs-minor-mode
(if (condition-case nil
(hs-toggle-hiding)
(error t))
(hs-show-all))
(toggle-selective-display column)))
;; Define Keybindings for hiding/showing code
(global-set-key (kbd "C-+") 'toggle-hiding)
(global-set-key (kbd "C-\\") 'toggle-selective-display)
(add-hook 'ess-r-mode-hook (lambda () (hs-minor-mode 1)))
(add-hook 'python-mode-hook (lambda () (hs-minor-mode 1)))