emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] (org-remove-occur-highlights) Implements option to remove highlights between points
@ 2020-09-21  2:02 Nicholas Savage
  2020-09-22  5:22 ` Kyle Meyer
  0 siblings, 1 reply; 3+ messages in thread
From: Nicholas Savage @ 2020-09-21  2:02 UTC (permalink / raw)
  To: Emanuel Berg via General discussions about Org-mode.

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

I realize now that I messed up sending this patch yesterday so it didn't show up on updates.orgmode.org. I just wanted to repost it with a correct subject to make sure it didn't get lost. My original message follows.

--

I posted earlier about why org-remove-occur-highlights ignored it's options of beg and end. I'm fairly sure it was so they could be implemented later. I wanted to use this functionality, so I've implemented it. This should not change any current behaviour. If beg and end are nil, it will run the same way as before. This is called as part of org-sparse-tree, and my changes do not affect that. When beg and end are non-nil, it checks which overlays are between those two points and deletes them. I've ensured that 'make test' still passes and believe I've formatted my changelog entry as required.

If I'm missing something about how this should be working, please let me know.

My copyright paperwork with FSF is currently in progress, but I wanted to put this out there to get comments as necessary.

Thanks,
Nick

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org.el-Implements-option-to-remove-highlights-betwee.patch --]
[-- Type: text/x-patch; name="0001-org.el-Implements-option-to-remove-highlights-betwee.patch", Size: 3044 bytes --]

From 3213a8d50af0a99be43bf1f91c5621a6474548dd Mon Sep 17 00:00:00 2001
From: nick <nick@nicksavage.ca>
Date: Thu, 17 Sep 2020 21:49:43 -0400
Subject: [PATCH] org.el: Implements option to remove highlights between points

* lisp/org.el (org-remove-occur-highlights): Implements BEG and END in
order to allow the option of removing highlights between a range of
points and adjust the shown context.

org-remove-occur-highlights has long had two options, BEG and END,
that were ignored. This change checks first 1) are BEG and END are
nil (as would be expected with the vast majority of current
behaviour)? If yes, there is no change in behaviour. Otherwise, it
removes only the highlights between BEG and END and updates
org-occur-highlights to contain the remaining highlights.
---
 lisp/org.el | 41 ++++++++++++++++++++++++++++++++---------
 1 file changed, 32 insertions(+), 9 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 053635c85..f509b8049 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11106,18 +11106,41 @@ match is found."
     (overlay-put ov 'org-type 'org-occur)
     (push ov org-occur-highlights)))
 
-(defun org-remove-occur-highlights (&optional _beg _end noremove)
+(defun org-remove-occur-highlights (&optional beg end noremove)
   "Remove the occur highlights from the buffer.
-BEG and END are ignored.  If NOREMOVE is nil, remove this function
-from the `before-change-functions' in the current buffer."
+When BEG and END are set, removes the overlay and hides the items
+between those two points. It does this by going through each overlay
+and comparing whther or not they are within the two points. If BEG and
+END are not set, erases all overlays and sets related variables to
+nil. If NOREMOVE is nil, remove this function from the
+`before-change-functions' in the current buffer."
   (interactive)
   (unless org-inhibit-highlight-removal
-    (mapc #'delete-overlay org-occur-highlights)
-    (setq org-occur-highlights nil)
-    (setq org-occur-parameters nil)
-    (unless noremove
-      (remove-hook 'before-change-functions
-		   'org-remove-occur-highlights 'local))))
+    ; if only one of BEG and END are set, set both to nil
+    (when (or (and beg (not end)) (and (not beg) end))
+      (setq beg nil end nil))
+    (cond
+     ((and (not beg) (not end))
+      (mapc #'delete-overlay org-occur-highlights)
+      (setq org-occur-highlights nil)
+      (setq org-occur-parameters nil)
+      (unless noremove
+	(remove-hook 'before-change-functions
+		     'org-remove-occur-highlights 'local)))
+     ((> end beg)
+      (org-overview)
+      (setq temp-overlays '())
+      (dolist (overlay org-occur-highlights)
+	(let ((overlay-point (overlay-start overlay)))
+
+	  (if (and (> overlay-point beg) (< overlay-point end))
+	      (delete-overlay overlay)
+	    (progn
+	      (save-excursion
+		(goto-char overlay-point)
+		(org-show-set-visibility 'ancestors)
+		(add-to-list 'temp-overlays overlay))))))
+      (setq org-occur-highlights temp-overlays)))))
 
 ;;;; Priorities
 
-- 
2.20.1


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

* Re: [PATCH] (org-remove-occur-highlights) Implements option to remove highlights between points
  2020-09-21  2:02 [PATCH] (org-remove-occur-highlights) Implements option to remove highlights between points Nicholas Savage
@ 2020-09-22  5:22 ` Kyle Meyer
  2020-12-14  6:32   ` Bastien
  0 siblings, 1 reply; 3+ messages in thread
From: Kyle Meyer @ 2020-09-22  5:22 UTC (permalink / raw)
  To: Nicholas Savage; +Cc: emacs-orgmode

Nicholas Savage writes:

> I realize now that I messed up sending this patch yesterday so it
> didn't show up on updates.orgmode.org. I just wanted to repost it with
> a correct subject to make sure it didn't get lost. My original message
> follows.

This topic is now split across three separate threads:

  https://orgmode.org/list/d4e1e166-8da2-4c1f-8d90-1671a6541992@www.fastmail.com
  https://orgmode.org/list/54ebdcc2-c17a-445a-9599-2bfc90e64e5d@www.fastmail.com
  https://orgmode.org/list/b204da05-85f3-43af-bbf0-ed7149b300af@www.fastmail.com

Please avoid doing that in the future.  It invites confusion and
redundant responses.

> I posted earlier about why org-remove-occur-highlights ignored it's
> options of beg and end. I'm fairly sure it was so they could be
> implemented later.

At least one reason that those parameters exist is to allow
org-remove-occur-highlights to be used as a member of
before-change-functions.  I suspect it's _the_ reason.

> I wanted to use this functionality, so I've
> implemented it. This should not change any current behaviour. If beg
> and end are nil, it will run the same way as before. This is called as
> part of org-sparse-tree, and my changes do not affect that. When beg
> and end are non-nil, it checks which overlays are between those two
> points and deletes them. I've ensured that 'make test' still passes
> and believe I've formatted my changelog entry as required.
>
> If I'm missing something about how this should be working, please let
> me know.

Thanks for sending the patch.  Unfortunately, it breaks the
org-remove-highlights-with-change functionality, which depends on
org-remove-occur-highlights not paying attention to the BEG and END
arguments.

Take this Org file:

--8<---------------cut here---------------start------------->8---
* a
|
target

--8<---------------cut here---------------end--------------->8---

Call org-sparse-tree and enter "target" as the regular expression.
Then, with point at "|", hit, say, C-o.  When
org-remove-highlights-with-change is non-nil, the highlighting should go
away.  With your patch, it doesn't.

It might be worth stepping back and describing what your use case for
this change is, and considering other ways to address it (not
necessarily as a change to Org itself).


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

* Re: [PATCH] (org-remove-occur-highlights) Implements option to remove highlights between points
  2020-09-22  5:22 ` Kyle Meyer
@ 2020-12-14  6:32   ` Bastien
  0 siblings, 0 replies; 3+ messages in thread
From: Bastien @ 2020-12-14  6:32 UTC (permalink / raw)
  To: Kyle Meyer; +Cc: Nicholas Savage, emacs-orgmode

Kyle Meyer <kyle@kyleam.com> writes:

> It might be worth stepping back and describing what your use case for
> this change is, and considering other ways to address it (not
> necessarily as a change to Org itself).

Since the problem needs to be revisited, I've closed this patch.

Nicholas, feel free to tackle the initial issue differently and
to provide another patch in another dedicated thread.  Thanks!

-- 
 Bastien


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

end of thread, other threads:[~2020-12-14  6:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-21  2:02 [PATCH] (org-remove-occur-highlights) Implements option to remove highlights between points Nicholas Savage
2020-09-22  5:22 ` Kyle Meyer
2020-12-14  6:32   ` Bastien

Code repositories for project(s) associated with this 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).