From 424322a12918b5529bd9beb45c1e5b6c9758672c Mon Sep 17 00:00:00 2001 From: Gerard Vermeulen Date: Tue, 28 Dec 2021 08:40:13 +0100 Subject: [PATCH] Add 'org-narrow-to-table' to 'narrow-or-widen-dwim' --- README.org | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/README.org b/README.org index 01a664e..da54958 100644 --- a/README.org +++ b/README.org @@ -1463,12 +1463,20 @@ Narrowing means focusing in on some portion of the buffer and widening means focussing out on the whole buffer. This allows to concentrate temporarily on for instance a particular function or paragraph by removing clutter. The "Do What I Mean" [[https://endlessparentheses.com/emacs-narrow-or-widen-dwim.html][narrow-or-widen-dwim]] function allows to toggle between narrowed and -widened buffer states. +widened buffer states. Here, the function =narrow-or-widen-dwim= operates also +on tables by means of =org-narrow-to-table=. #+caption[Configure =narrow-or-widen-dwim=]: #+caption: Configure =narrow-or-widen-dwim=. -#+label: lst:configure-narrow-or-widen-dwim +#+name: lst:configure-narrow-or-widen-dwim #+begin_src emacs-lisp + (defun org-narrow-to-table () + "Narrow buffer to current table." + (interactive) + (if (org-table-p) + (narrow-to-region (org-table-begin) (org-table-end)) + (user-error "Not in a table"))) + (defun narrow-or-widen-dwim (p) "Widen if buffer is narrowed, narrow-dwim otherwise. Dwim means: region, org-src-block, org-subtree, or defun, @@ -1486,6 +1494,7 @@ widened buffer states. ((derived-mode-p 'org-mode) (or (ignore-errors (org-edit-src-code)) (ignore-errors (org-narrow-to-block)) + (ignore-errors (org-narrow-to-table)) (org-narrow-to-subtree))) ((derived-mode-p 'latex-mode) (LaTeX-narrow-to-environment)) @@ -1493,6 +1502,7 @@ widened buffer states. (TeX-narrow-to-group)) (t (narrow-to-defun)))) + (define-key ctl-x-map (kbd "n t") #'org-narrow-to-table) (define-key ctl-x-map (kbd "C-n") #'narrow-or-widen-dwim) #+end_src