From 3213a8d50af0a99be43bf1f91c5621a6474548dd Mon Sep 17 00:00:00 2001 From: nick 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