Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(defun narrow-or-widen-dwim (p)
;; fixed to behave correctly in org-src buffers; taken from:
"Widen if buffer is narrowed, narrow-dwim otherwise.
Dwim means: region, org-src-block, org-subtree, or defun,
whichever applies first. Narrowing to org-src-block actually
calls `org-edit-src-code'.
With prefix P, don't widen, just narrow even if buffer is
already narrowed."
(interactive "P")
(declare (interactive-only))
(cond ((and (not p) (buffer-narrowed-p))
((and (not p) (org-src-edit-buffer-p))
(narrow-to-region (region-beginning) (region-end)))
((derived-mode-p 'org-mode)
(cond ((ignore-errors (org-edit-src-code)) t)
((ignore-errors (org-narrow-to-block) t))
((ignore-errors (org-narrow-to-element) t))
(t (org-narrow-to-subtree))))
((derived-mode-p 'latex-mode)
(t (narrow-to-defun))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.