emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Fix org-narrow-to-subtree smaller than subtree
@ 2020-05-30 13:29 Kevin Liu
  2020-05-30 13:35 ` Kevin Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin Liu @ 2020-05-30 13:29 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 273 bytes --]

I noticed that when I narrow to a subtree and then hit org-mark-element,
I can’t kill the text because the narrow is actually 1 char smaller.
This seemed like an unpleasant workaround, and I think the behavior can
be changed without any real negative consequences.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Narrow-to-whole-subtree-instead-of-1-char-less.patch --]
[-- Type: text/x-patch, Size: 1895 bytes --]

From 61260469a9ad37ad4011cc489dc4372b02491b4d Mon Sep 17 00:00:00 2001
From: nivekuil <mail@nivekuil.com>
Date: Tue, 26 May 2020 23:17:43 -0700
Subject: [PATCH] Narrow to whole subtree instead of 1 char less

---
 lisp/org.el                       | 1 -
 testing/lisp/test-org-datetree.el | 4 ++--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 0808fc210..e9771512d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7749,7 +7749,6 @@ If yes, remember the marker and the distance to BEG."
        (narrow-to-region
 	(progn (org-back-to-heading t) (point))
 	(progn (org-end-of-subtree t t)
-	       (when (and (org-at-heading-p) (not (eobp))) (backward-char 1))
 	       (point)))))))
 
 (defun org-toggle-narrow-to-subtree ()
diff --git a/testing/lisp/test-org-datetree.el b/testing/lisp/test-org-datetree.el
index 5557d5e23..f7247766a 100644
--- a/testing/lisp/test-org-datetree.el
+++ b/testing/lisp/test-org-datetree.el
@@ -58,7 +58,7 @@
   ;; Sort new entry in right place.
   (should
    (string-match
-    "\\`\\* 2012\n\\*\\* 2012-02 .*\n\\*\\*\\* 2012-02-01 .*\n\n\\*\\* 2012-03 .*\n\\*\\*\\* 2012-03-29 .*\\'"
+    "\\`\\* 2012\n\\*\\* 2012-02 .*\n\\*\\*\\* 2012-02-01 .*\n\\*\\* 2012-03 .*\n\\*\\*\\* 2012-03-29 .*\\'"
     (org-test-with-temp-text "* 2012\n** 2012-03 month\n*** 2012-03-29 day"
       (let ((org-datetree-add-timestamp nil))
 	(org-datetree-find-date-create '(3 29 2012))
@@ -161,7 +161,7 @@
   ;; Sort new entry in right place.
   (should
    (string-match
-    "\\`\\* 2015\n\\*\\* 2015-W01\n\\*\\*\\* 2014-12-31 .*\n\n\\*\\* 2015-W36\n\\*\\*\\* 2015-09-01 .*\\'"
+    "\\`\\* 2015\n\\*\\* 2015-W01\n\\*\\*\\* 2014-12-31 .*\n\\*\\* 2015-W36\n\\*\\*\\* 2015-09-01 .*\\'"
     (org-test-with-temp-text "* 2015"
       (let ((org-datetree-add-timestamp nil))
 	(org-datetree-find-iso-week-create '(9 1 2015))
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix org-narrow-to-subtree smaller than subtree
  2020-05-30 13:29 [PATCH] Fix org-narrow-to-subtree smaller than subtree Kevin Liu
@ 2020-05-30 13:35 ` Kevin Liu
  2020-05-30 16:05   ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin Liu @ 2020-05-30 13:35 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 90 bytes --]


Oh, of course I attached the wrong patch again.  Wish mu4e-compose could preview these.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Make-narrowed-subtree-same-size-as-the-subtree-not-1.patch --]
[-- Type: text/x-patch, Size: 3547 bytes --]

From 5f7cf68f92d3fa82d01646f7f1e12a4d18bad2fb Mon Sep 17 00:00:00 2001
From: nivekuil <mail@nivekuil.com>
Date: Sat, 30 May 2020 00:11:19 -0700
Subject: [PATCH] Make narrowed subtree same size as the subtree, not 1 char
 less

Right now a narrowed subtree is one char smaller than the actual
subtree.  (org-mark-element) on a narrowed subtree will select a
region 1 char out of bounds, for example.  There doesn't seem like a
good reason for this to be the case.

* lisp/org.el (org-toggle-narrow-to-subtree):  Just
use (org-end-of-subtree) as the end of the subtree.
* testing/lisp/test-ob.el (test-ob/parse-header-args2):  Since we're no
longer subtracting the narrowed subtree size by 1, the subtree text
here is now 1 character longer.  I think this is reasonable and
shouldn't be surprising enough to ruin anyone's day.  If it isn't,
then (org-end-of-subtree) should be changed rather than org-narrow-to-subtree.
* testing/lisp/test-org-datetree.el (test-org-datetree/find-date-create):
(test-org-datetree/find-iso-week-create):  No more double
newlines between months in datetree, but this just seems like
incidental behavior more than deliberate behavior to begin with.
---
 lisp/org.el                       | 4 +---
 testing/lisp/test-ob.el           | 2 +-
 testing/lisp/test-org-datetree.el | 4 ++--
 3 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 0808fc210..f69919b20 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -7748,9 +7748,7 @@ If yes, remember the marker and the distance to BEG."
       (org-with-limited-levels
        (narrow-to-region
 	(progn (org-back-to-heading t) (point))
-	(progn (org-end-of-subtree t t)
-	       (when (and (org-at-heading-p) (not (eobp))) (backward-char 1))
-	       (point)))))))
+	(progn (org-end-of-subtree t t) (point)))))))
 
 (defun org-toggle-narrow-to-subtree ()
   "Narrow to the subtree at point or widen a narrowed buffer."
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 7c44622ef..2a2a66952 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -233,7 +233,7 @@ this is simple"
     (should (string-match (regexp-quote "this is simple")
 			  (org-babel-ref-resolve "simple-subtree")))
     (org-babel-next-src-block)
-    (should (= 14 (org-babel-execute-src-block)))))
+    (should (= 15 (org-babel-execute-src-block)))))
 
 (ert-deftest test-ob/inline-src-blocks ()
   (should
diff --git a/testing/lisp/test-org-datetree.el b/testing/lisp/test-org-datetree.el
index 5557d5e23..f7247766a 100644
--- a/testing/lisp/test-org-datetree.el
+++ b/testing/lisp/test-org-datetree.el
@@ -58,7 +58,7 @@
   ;; Sort new entry in right place.
   (should
    (string-match
-    "\\`\\* 2012\n\\*\\* 2012-02 .*\n\\*\\*\\* 2012-02-01 .*\n\n\\*\\* 2012-03 .*\n\\*\\*\\* 2012-03-29 .*\\'"
+    "\\`\\* 2012\n\\*\\* 2012-02 .*\n\\*\\*\\* 2012-02-01 .*\n\\*\\* 2012-03 .*\n\\*\\*\\* 2012-03-29 .*\\'"
     (org-test-with-temp-text "* 2012\n** 2012-03 month\n*** 2012-03-29 day"
       (let ((org-datetree-add-timestamp nil))
 	(org-datetree-find-date-create '(3 29 2012))
@@ -161,7 +161,7 @@
   ;; Sort new entry in right place.
   (should
    (string-match
-    "\\`\\* 2015\n\\*\\* 2015-W01\n\\*\\*\\* 2014-12-31 .*\n\n\\*\\* 2015-W36\n\\*\\*\\* 2015-09-01 .*\\'"
+    "\\`\\* 2015\n\\*\\* 2015-W01\n\\*\\*\\* 2014-12-31 .*\n\\*\\* 2015-W36\n\\*\\*\\* 2015-09-01 .*\\'"
     (org-test-with-temp-text "* 2015"
       (let ((org-datetree-add-timestamp nil))
 	(org-datetree-find-iso-week-create '(9 1 2015))
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix org-narrow-to-subtree smaller than subtree
  2020-05-30 13:35 ` Kevin Liu
@ 2020-05-30 16:05   ` Nicolas Goaziou
  2020-05-31  1:54     ` Kevin Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Goaziou @ 2020-05-30 16:05 UTC (permalink / raw)
  To: Kevin Liu; +Cc: emacs-orgmode

Hello,

Kevin Liu <kevin@nivekuil.com> writes:

> Right now a narrowed subtree is one char smaller than the actual
> subtree.  (org-mark-element) on a narrowed subtree will select a
> region 1 char out of bounds, for example.  There doesn't seem like a
> good reason for this to be the case.

There is a good reason for this. If you insert text at (point-max), you
break the following headline.

OTOH `org-mark-element' should pay attention to buffer boundaries.

Regards,

-- 
Nicolas Goaziou


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix org-narrow-to-subtree smaller than subtree
  2020-05-30 16:05   ` Nicolas Goaziou
@ 2020-05-31  1:54     ` Kevin Liu
  2020-05-31 12:23       ` Nicolas Goaziou
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin Liu @ 2020-05-31  1:54 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode


> There is a good reason for this. If you insert text at (point-max), you
> break the following headline.
>
> OTOH `org-mark-element' should pay attention to buffer boundaries.

Good point.  `org-mark-element` uses (org-element-property); I wonder if
it makes sense to have the actual :end property of a subtree be the same
as its narrowed boundary?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix org-narrow-to-subtree smaller than subtree
  2020-05-31  1:54     ` Kevin Liu
@ 2020-05-31 12:23       ` Nicolas Goaziou
  0 siblings, 0 replies; 5+ messages in thread
From: Nicolas Goaziou @ 2020-05-31 12:23 UTC (permalink / raw)
  To: Kevin Liu; +Cc: emacs-orgmode

Hello,

Kevin Liu <kevin@nivekuil.com> writes:

> Good point.  `org-mark-element` uses (org-element-property); I wonder if
> it makes sense to have the actual :end property of a subtree be the same
> as its narrowed boundary?

I don't think so. This is an issue in narrowing, not in the parser.

I fixed the bug in `org-element-mark'. Thank you.

Regards,

-- 
Nicolas Goaziou


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-05-31 12:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-30 13:29 [PATCH] Fix org-narrow-to-subtree smaller than subtree Kevin Liu
2020-05-30 13:35 ` Kevin Liu
2020-05-30 16:05   ` Nicolas Goaziou
2020-05-31  1:54     ` Kevin Liu
2020-05-31 12:23       ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).