From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Richard Subject: Re: Bug: [PATCH] Make org-narrow-to-subtree usable out of Org mode [8.2.7b (release_8.2.7b-6-g07d470 @ /home/youngfrog/sourcetrees/org-mode/lisp/)] Date: Wed, 30 Jul 2014 16:51:35 +0200 Message-ID: <87fvhi5288.fsf@yahoo.fr> References: <87fvht9tdo.fsf@yahoo.fr> <87bnsfrycn.fsf@nicolasgoaziou.fr> <878uni7unf.fsf@geodiff-mac3.ulb.ac.be> <87tx66lur9.fsf@nicolasgoaziou.fr> <87r41a6dfw.fsf@geodiff-mac3.ulb.ac.be> <87mwbtxuob.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55530) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XCVEG-0006BV-So for emacs-orgmode@gnu.org; Wed, 30 Jul 2014 10:51:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XCVEA-0003ZK-Va for emacs-orgmode@gnu.org; Wed, 30 Jul 2014 10:51:44 -0400 In-Reply-To: <87mwbtxuob.fsf@bzg.ath.cx> (Bastien's message of "Mon, 28 Jul 2014 16:18:10 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bastien Cc: Nicolas Richard , emacs-orgmode@gnu.org Hello Bastien, Bastien writes: > I think it's fine to bind `org-narrow-to-subtree' in narrow-map. > It's basically to enjoy the `C-x n prefix', which is natural here. I agree, but it is not compatible with keeping it only for org-mode buffers while using something else for some other modes, which is what you suggest next : > I applied your patch, but a good continuation would be to have > C-h n s bound to `outline-narrow-to-subtree' in outline-mode and > to `org-narrow-to-subtree' in org-mode, instead of just relying > on one single function. > This requires simplifying `org-narrow-to-subtree' and creating > `outline-narrow-to-subtree' in emacs. > > What do you think? I think backporting narrow-to-subtree to outline is a very good move. (Other things would be cool in outline, e.g. why does it not have outline-cycle ? But that's a longer story, I guess.) Another possibility : wouldn't it make sense to hijack narrow-to-defun for this ? In fact, it used to be that way, but then it was changed in 76fa979225a2a31f7be6d366c48750d4f7abe458 (and then reverted, and then the revert was reverted, and I have no idea why). Looking more closely, the current behaviour is partly buggy, e.g. with a file like : * one ** two ** three * four When point is on the second line and C-M-e is used, we end up on the first line ! I see two reasons for this or similar failures : - One is a bug in org-forward-heading-same-level (I provide a patch below). - The other is because org-backward-element doesn't fully satisfy the "beginning-of-defun usual protocol" since it sometimes signals an error. Here's a test for catching the bug in org-forward-heading-same-level: (org-test-with-temp-text "\ * one * two " (goto-line 2) (org-forward-heading-same-level -1) (should (bobp))) And here's the patch for org-forward-heading-same-level. Modified lisp/org.el diff --git a/lisp/org.el b/lisp/org.el index 0e15710..741c9b5 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -23328,9 +23333,10 @@ non-nil it will also look at invisible ones." 're-search-forward)) (count (if arg (abs arg) 1)) (result (point))) - (while (and (prog1 (> count 0) - (forward-char (if (and arg (< arg 0)) -1 1))) - (funcall f org-outline-regexp-bol nil 'move)) + (while (and (> count 0) + (progn + (forward-char (if (and arg (< arg 0)) -1 1)) + (funcall f org-outline-regexp-bol nil 'move))) (let ((l (- (match-end 0) (match-beginning 0) 1))) (cond ((< l level) (setq count 0)) ((and (= l level) Want a git-format-patch one ? Also, here's a test where I don't know what should happen (currently signals a user-error) : (org-test-with-temp-text "\ one * two " (goto-line 2) (org-backward-element) (should t)) -- Nico.