Selaa lähdekoodia

Give drawers their own invisibility spec

* lisp/org.el (org-mode): Add special invisibility spec for drawers.
(org-show-set-visibility): Handle new invisibility spec.
(org-clean-visibility-after-subtree-move): Fix argument for
`org-cycle-hide-drawers'.  `overview' is a no-op.
(org-cycle-hook):
(org-cycle-internal-local):
(org-flag-drawer):
(org-move-subtree-down):
(org-show-entry):
* lisp/org-agenda.el (org-agenda-clock-in):
* lisp/org-clock.el (org-clock-goto):
* lisp/org-feed.el (org-feed-update):
* lisp/org-inlinetask.el (org-inlinetask-toggle-visibility): Do not hide
  drawers when expanding a headline.

Drawers and headlines visibility are now unrelated.  As a consequence,
there is no need to hide drawers every time a headline is expanded.
Nicolas Goaziou 8 vuotta sitten
vanhempi
commit
4403d4685e
5 muutettua tiedostoa jossa 22 lisäystä ja 34 poistoa
  1. 0 1
      lisp/org-agenda.el
  2. 0 1
      lisp/org-clock.el
  3. 0 1
      lisp/org-feed.el
  4. 1 2
      lisp/org-inlinetask.el
  5. 21 29
      lisp/org.el

+ 0 - 1
lisp/org-agenda.el

@@ -9338,7 +9338,6 @@ ARG is passed through to `org-deadline'."
 	  (widen)
 	  (goto-char pos)
 	  (org-show-context 'agenda)
-	  (org-cycle-hide-drawers 'children)
 	  (org-clock-in arg)
 	  (setq newhead (org-get-heading)))
 	(org-agenda-change-all-lines newhead hdmarker))

+ 0 - 1
lisp/org-clock.el

@@ -1778,7 +1778,6 @@ With prefix arg SELECT, offer recently clocked tasks for selection."
     (goto-char m)
     (org-show-entry)
     (org-back-to-heading t)
-    (org-cycle-hide-drawers 'children)
     (recenter org-clock-goto-before-context)
     (org-reveal)
     (if recent

+ 0 - 1
lisp/org-feed.el

@@ -407,7 +407,6 @@ it can be a list structured like an entry in `org-feed-alist'."
 	  (goto-char inbox-pos)
 	  (outline-hide-subtree)
 	  (org-show-children)
-	  (org-cycle-hide-drawers 'children)
 
 	  ;; Hooks and messages
 	  (when org-feed-save-after-adding (save-buffer))

+ 1 - 2
lisp/org-inlinetask.el

@@ -324,8 +324,7 @@ If the task has an end part, also demote it."
      ((= end start))
      ;; Inlinetask was folded: expand it.
      ((eq (get-char-property (1+ start) 'invisible) 'outline)
-      (outline-flag-region start end nil)
-      (org-cycle-hide-drawers 'children))
+      (outline-flag-region start end nil))
      (t (outline-flag-region start end t)))))
 
 (defun org-inlinetask-hide-tasks (state)

+ 21 - 29
lisp/org.el

@@ -1414,7 +1414,6 @@ the values `folded', `children', or `subtree'."
   :type 'hook)
 
 (defcustom org-cycle-hook '(org-cycle-hide-archived-subtrees
-			    org-cycle-hide-drawers
 			    org-cycle-show-empty-lines
 			    org-optimize-window-after-visibility-change)
   "Hook that is run after `org-cycle' has changed the buffer visibility.
@@ -5393,6 +5392,7 @@ The following commands are available:
   (org-install-agenda-files-menu)
   (when org-descriptive-links (add-to-invisibility-spec '(org-link)))
   (add-to-invisibility-spec '(org-hide-block . t))
+  (add-to-invisibility-spec '(org-hide-drawer . t))
   (setq-local outline-regexp org-outline-regexp)
   (setq-local outline-level 'org-outline-level)
   (setq bidi-paragraph-direction 'left-to-right)
@@ -6859,11 +6859,6 @@ Use `\\[org-edit-special]' to edit table.el tables"))
 	(org-show-entry)
 	(org-with-limited-levels (org-show-children))
 	(org-show-set-visibility 'canonical)
-	;; FIXME: This slows down the func way too much.
-	;; How keep drawers hidden in subtree anyway?
-	;; (when (memq 'org-cycle-hide-drawers org-cycle-hook)
-	;;   (org-cycle-hide-drawers 'subtree))
-
 	;; Fold every list in subtree to top-level items.
 	(when (eq org-cycle-include-plain-lists 'integrate)
 	  (save-excursion
@@ -7048,11 +7043,10 @@ This function is the default value of the hook `org-cycle-hook'."
 	  (goto-char (point-min))
 	  (while (re-search-forward re nil t)
 	    (when (and (not (org-invisible-p))
-		       (save-excursion
-			 (goto-char (point-at-eol)) (org-invisible-p)))
+		       (org-invisible-p (line-end-position)))
 	      (outline-hide-entry))))
-	(org-cycle-show-empty-lines 'overview)
-	(org-cycle-hide-drawers 'overview)))))
+	(org-cycle-hide-drawers 'all)
+	(org-cycle-show-empty-lines 'overview)))))
 
 (defun org-cycle-show-empty-lines (state)
   "Show empty lines above all visible headlines.
@@ -7161,16 +7155,15 @@ show that drawer instead."
 			 (org-element-at-point)))))
     (when (memq (org-element-type drawer) '(drawer property-drawer))
       (let ((post (org-element-property :post-affiliated drawer)))
-	(save-excursion
-	  (outline-flag-region
-	   (progn (goto-char post) (line-end-position))
-	   (progn (goto-char (org-element-property :end drawer))
-		  (skip-chars-backward " \r\t\n")
-		  (line-end-position))
-	   flag))
+	(org-flag-region
+	 (save-excursion (goto-char post) (line-end-position))
+	 (save-excursion (goto-char (org-element-property :end drawer))
+			 (skip-chars-backward " \t\n")
+			 (line-end-position))
+	 flag 'org-hide-drawer)
 	;; When the drawer is hidden away, make sure point lies in
 	;; a visible part of the buffer.
-	(when (and flag (> (line-beginning-position) post))
+	(when (invisible-p (max (1- (point)) (point-min)))
 	  (goto-char post))))))
 
 (defun org-subtree-end-visible-p ()
@@ -8087,16 +8080,16 @@ case."
 	 (setq beg (point))))
      ;; Find insertion point, with error handling
      (while (> cnt 0)
-       (or (and (funcall movfunc) (looking-at org-outline-regexp))
-	   (progn (goto-char beg0)
-		  (user-error "Cannot move past superior level or buffer limit")))
+       (unless (and (funcall movfunc) (looking-at org-outline-regexp))
+	 (goto-char beg0)
+	 (user-error "Cannot move past superior level or buffer limit"))
        (setq cnt (1- cnt)))
      (when (> arg 0)
        ;; Moving forward - still need to move over subtree
        (org-end-of-subtree t t)
        (save-excursion
 	 (org-back-over-empty-lines)
-	 (unless (bolp) (insert "\n"))))
+	 (or (bolp) (newline))))
      (setq ne-ins (org-back-over-empty-lines))
      (move-marker ins-point (point))
      (setq txt (buffer-substring beg end))
@@ -8117,7 +8110,7 @@ case."
      (when (and (< arg 0)
 		(org-first-sibling-p)
 		(> ne-ins ne-beg))
-       ;; Move whitespace back to beginning.
+       ;; Move whitespace back to beginning
        (save-excursion
 	 (goto-char ins-end)
 	 (let ((kill-whole-line t))
@@ -8127,10 +8120,9 @@ case."
      (if folded
 	 (outline-hide-subtree)
        (org-show-entry)
-       (org-show-children)
-       (org-cycle-hide-drawers 'children))
+       (org-show-children))
      (org-clean-visibility-after-subtree-move)
-     ;; Move back to the initial column we were at.
+     ;; move back to the initial column we were at
      (move-to-column col))))
 
 (defvar org-subtree-clip ""
@@ -13286,7 +13278,8 @@ information."
     ;; If point is hidden within a drawer or a block, make sure to
     ;; expose it.
     (dolist (o (overlays-at (point)))
-      (when (memq (overlay-get o 'invisible) '(org-hide-block outline))
+      (when (memq (overlay-get o 'invisible)
+		  '(org-hide-block org-hide-drawer outline))
 	(delete-overlay o)))
     (unless (org-before-first-heading-p)
       (org-with-limited-levels
@@ -23744,8 +23737,7 @@ Show the heading too, if it is currently invisible."
 	      (concat "[\r\n]\\(" org-outline-regexp "\\)") nil t)
 	     (match-beginning 1)
 	   (point-max)))
-       nil)
-      (org-cycle-hide-drawers 'children))))
+       nil))))
 
 (defun org-make-options-regexp (kwds &optional extra)
   "Make a regular expression for keyword lines.