Browse Source

New function org-narrow-to-block.

* org.el (org-narrow-to-block): New function to narrow to block.
Bound this function to `C-x n b'.
* org.texi (Dynamic blocks, Structure editing): Mention
the function `org-narrow-to-block'.

This is inspired by a request by Leonidas Tsampros.
Bastien Guerry 14 years ago
parent
commit
b3c3746d92
2 changed files with 24 additions and 0 deletions
  1. 5 0
      doc/org.texi
  2. 19 0
      lisp/org.el

+ 5 - 0
doc/org.texi

@@ -1370,6 +1370,8 @@ sorting will be case-sensitive.  With two @kbd{C-u C-u} prefixes, duplicate
 entries will also be removed.
 @orgcmd{C-x n s,org-narrow-to-subtree}
 Narrow buffer to current subtree.
+@orgcmd{C-x n b,org-narrow-to-block}
+Narrow buffer to current block.
 @orgcmd{C-x n w,widen}
 Widen buffer to remove narrowing.
 @orgcmd{C-c *,org-toggle-heading}
@@ -14118,6 +14120,9 @@ example @code{before-save-hook}.  @code{org-update-all-dblocks} is
 written in a way such that it does nothing in buffers that are not in
 @code{org-mode}.
 
+You can narrow the current buffer to the current dynamic block (like any
+other block) with @code{org-narrow-to-block}.
+
 @node Special agenda views, Extracting agenda information, Dynamic blocks, Hacking
 @section Special agenda views
 @cindex agenda views, user-defined

+ 19 - 0
lisp/org.el

@@ -7547,6 +7547,22 @@ If yes, remember the marker and the distance to BEG."
 	      (if (and (org-on-heading-p) (not (eobp))) (backward-char 1))
 	      (point))))))
 
+(defun org-narrow-to-block ()
+  "Narrow buffer to the current block."
+  (interactive)
+  (let ((bstart "^[ \t]*#\\+begin")
+	(bend "[ \t]*#\\+end")
+	(case-fold-search t) ;; allow #+BEGIN 
+	b_start b_end)
+    (if (org-in-regexps-block-p bstart bend)
+	(progn
+	  (save-excursion (re-search-backward bstart nil t)
+			  (setq b_start (match-beginning 0)))
+	  (save-excursion (re-search-forward  bend nil t)
+			  (setq b_end (match-end 0)))
+	  (narrow-to-region b_start b_end))
+      (error "Not in a block"))))
+
 (eval-when-compile
   (defvar org-property-drawer-re))
 
@@ -16364,6 +16380,9 @@ BEG and END default to the buffer boundaries."
 (if (boundp 'narrow-map)
     (org-defkey narrow-map "s" 'org-narrow-to-subtree)
   (org-defkey org-mode-map "\C-xns" 'org-narrow-to-subtree))
+(if (boundp 'narrow-map)
+    (org-defkey narrow-map "b" 'org-narrow-to-block)
+  (org-defkey org-mode-map "\C-xnb" 'org-narrow-to-block))
 (org-defkey org-mode-map "\C-c\C-f"    'org-forward-same-level)
 (org-defkey org-mode-map "\C-c\C-b"    'org-backward-same-level)
 (org-defkey org-mode-map "\C-c$"    'org-archive-subtree)