emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 04/38] Remove functions from org.el that are now moved elsewhe


From: Ihor Radchenko
Subject: [PATCH v2 04/38] Remove functions from org.el that are now moved elsewhere
Date: Wed, 20 Apr 2022 21:24:29 +0800

---
 lisp/org.el | 1272 ++-------------------------------------------------
 1 file changed, 40 insertions(+), 1232 deletions(-)

diff --git a/lisp/org.el b/lisp/org.el
index 2353c6594..855f0813d 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1179,90 +1179,6 @@ (defgroup org-structure nil
   :tag "Org Structure"
   :group 'org)
 
-(defgroup org-reveal-location nil
-  "Options about how to make context of a location visible."
-  :tag "Org Reveal Location"
-  :group 'org-structure)
-
-(defcustom org-show-context-detail '((agenda . local)
-                                    (bookmark-jump . lineage)
-                                    (isearch . lineage)
-                                    (default . ancestors))
-  "Alist between context and visibility span when revealing a location.
-
-\\<org-mode-map>Some actions may move point into invisible
-locations.  As a consequence, Org always exposes a neighborhood
-around point.  How much is shown depends on the initial action,
-or context.  Valid contexts are
-
-  agenda         when exposing an entry from the agenda
-  org-goto       when using the command `org-goto' (`\\[org-goto]')
-  occur-tree     when using the command `org-occur' (`\\[org-sparse-tree] /')
-  tags-tree      when constructing a sparse tree based on tags matches
-  link-search    when exposing search matches associated with a link
-  mark-goto      when exposing the jump goal of a mark
-  bookmark-jump  when exposing a bookmark location
-  isearch        when exiting from an incremental search
-  default        default for all contexts not set explicitly
-
-Allowed visibility spans are
-
-  minimal        show current headline; if point is not on headline,
-                 also show entry
-
-  local          show current headline, entry and next headline
-
-  ancestors      show current headline and its direct ancestors; if
-                 point is not on headline, also show entry
-
-  ancestors-full show current subtree and its direct ancestors
-
-  lineage        show current headline, its direct ancestors and all
-                 their children; if point is not on headline, also show
-                 entry and first child
-
-  tree           show current headline, its direct ancestors and all
-                 their children; if point is not on headline, also show
-                 entry and all children
-
-  canonical      show current headline, its direct ancestors along with
-                 their entries and children; if point is not located on
-                 the headline, also show current entry and all children
-
-As special cases, a nil or t value means show all contexts in
-`minimal' or `canonical' view, respectively.
-
-Some views can make displayed information very compact, but also
-make it harder to edit the location of the match.  In such
-a case, use the command `org-reveal' (`\\[org-reveal]') to show
-more context."
-  :group 'org-reveal-location
-  :version "26.1"
-  :package-version '(Org . "9.0")
-  :type '(choice
-         (const :tag "Canonical" t)
-         (const :tag "Minimal" nil)
-         (repeat :greedy t :tag "Individual contexts"
-                 (cons
-                  (choice :tag "Context"
-                          (const agenda)
-                          (const org-goto)
-                          (const occur-tree)
-                          (const tags-tree)
-                          (const link-search)
-                          (const mark-goto)
-                          (const bookmark-jump)
-                          (const isearch)
-                          (const default))
-                  (choice :tag "Detail level"
-                          (const minimal)
-                          (const local)
-                          (const ancestors)
-                           (const ancestors-full)
-                          (const lineage)
-                          (const tree)
-                          (const canonical))))))
-
 (defcustom org-indirect-buffer-display 'other-window
   "How should indirect tree buffers be displayed?
 
@@ -1454,130 +1370,6 @@ (defcustom org-bookmark-names-plist
   :group 'org-structure
   :type 'plist)
 
-(defgroup org-cycle nil
-  "Options concerning visibility cycling in Org mode."
-  :tag "Org Cycle"
-  :group 'org-structure)
-
-(defcustom org-cycle-skip-children-state-if-no-children t
-  "Non-nil means skip CHILDREN state in entries that don't have any."
-  :group 'org-cycle
-  :type 'boolean)
-
-(defcustom org-cycle-max-level nil
-  "Maximum level which should still be subject to visibility cycling.
-Levels higher than this will, for cycling, be treated as text, not a headline.
-When `org-odd-levels-only' is set, a value of N in this variable actually
-means 2N-1 stars as the limiting headline.
-When nil, cycle all levels.
-Note that the limiting level of cycling is also influenced by
-`org-inlinetask-min-level'.  When `org-cycle-max-level' is not set but
-`org-inlinetask-min-level' is, cycling will be limited to levels one less
-than its value."
-  :group 'org-cycle
-  :type '(choice
-         (const :tag "No limit" nil)
-         (integer :tag "Maximum level")))
-
-(defcustom org-hide-block-startup nil
-  "Non-nil means entering Org mode will fold all blocks.
-This can also be set in on a per-file basis with
-
-#+STARTUP: hideblocks
-#+STARTUP: showblocks"
-  :group 'org-startup
-  :group 'org-cycle
-  :type 'boolean)
-
-(defcustom org-cycle-global-at-bob nil
-  "Cycle globally if cursor is at beginning of buffer and not at a headline.
-
-This makes it possible to do global cycling without having to use `S-TAB'
-or `\\[universal-argument] TAB'.  For this special case to work, the first \
-line of the buffer
-must not be a headline -- it may be empty or some other text.
-
-When used in this way, `org-cycle-hook' is disabled temporarily to make
-sure the cursor stays at the beginning of the buffer.
-
-When this option is nil, don't do anything special at the beginning of
-the buffer."
-  :group 'org-cycle
-  :type 'boolean)
-
-(defcustom org-cycle-level-after-item/entry-creation t
-  "Non-nil means cycle entry level or item indentation in new empty entries.
-
-When the cursor is at the end of an empty headline, i.e., with only stars
-and maybe a TODO keyword, TAB will then switch the entry to become a child,
-and then all possible ancestor states, before returning to the original state.
-This makes data entry extremely fast:  M-RET to create a new headline,
-on TAB to make it a child, two or more tabs to make it a (grand-)uncle.
-
-When the cursor is at the end of an empty plain list item, one TAB will
-make it a subitem, two or more tabs will back up to make this an item
-higher up in the item hierarchy."
-  :group 'org-cycle
-  :type 'boolean)
-
-(defcustom org-cycle-emulate-tab t
-  "Where should `org-cycle' emulate TAB.
-nil         Never
-white       Only in completely white lines
-whitestart  Only at the beginning of lines, before the first non-white char
-t           Everywhere except in headlines
-exc-hl-bol  Everywhere except at the start of a headline
-If TAB is used in a place where it does not emulate TAB, the current subtree
-visibility is cycled."
-  :group 'org-cycle
-  :type '(choice (const :tag "Never" nil)
-                (const :tag "Only in completely white lines" white)
-                (const :tag "Before first char in a line" whitestart)
-                (const :tag "Everywhere except in headlines" t)
-                (const :tag "Everywhere except at bol in headlines" 
exc-hl-bol)))
-
-(defcustom org-cycle-separator-lines 2
-  "Number of empty lines needed to keep an empty line between collapsed trees.
-If you leave an empty line between the end of a subtree and the following
-headline, this empty line is hidden when the subtree is folded.
-Org mode will leave (exactly) one empty line visible if the number of
-empty lines is equal or larger to the number given in this variable.
-So the default 2 means at least 2 empty lines after the end of a subtree
-are needed to produce free space between a collapsed subtree and the
-following headline.
-
-If the number is negative, and the number of empty lines is at least -N,
-all empty lines are shown.
-
-Special case: when 0, never leave empty lines in collapsed view."
-  :group 'org-cycle
-  :type 'integer)
-(put 'org-cycle-separator-lines 'safe-local-variable 'integerp)
-
-(defcustom org-pre-cycle-hook nil
-  "Hook that is run before visibility cycling is happening.
-The function(s) in this hook must accept a single argument which indicates
-the new state that will be set right after running this hook.  The
-argument is a symbol.  Before a global state change, it can have the values
-`overview', `content', or `all'.  Before a local state change, it can have
-the values `folded', `children', or `subtree'."
-  :group 'org-cycle
-  :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.
-The function(s) in this hook must accept a single argument which indicates
-the new state that was set by the most recent `org-cycle' command.  The
-argument is a symbol.  After a global state change, it can have the values
-`overview', `contents', or `all'.  After a local state change, it can have
-the values `folded', `children', or `subtree'."
-  :group 'org-cycle
-  :package-version '(Org . "9.4")
-  :type 'hook)
-
 (defgroup org-edit-structure nil
   "Options concerning structure editing in Org mode."
   :tag "Org Edit Structure"
@@ -1704,29 +1496,6 @@ (defcustom org-special-ctrl-o t
   :group 'org-edit-structure
   :type 'boolean)
 
-(defcustom org-catch-invisible-edits nil
-  "Check if in invisible region before inserting or deleting a character.
-Valid values are:
-
-nil              Do not check, so just do invisible edits.
-error            Throw an error and do nothing.
-show             Make point visible, and do the requested edit.
-show-and-error   Make point visible, then throw an error and abort the edit.
-smart            Make point visible, and do insertion/deletion if it is
-                 adjacent to visible text and the change feels predictable.
-                 Never delete a previously invisible character or add in the
-                 middle or right after an invisible region.  Basically, this
-                 allows insertion and backward-delete right before ellipses.
-                 FIXME: maybe in this case we should not even show?"
-  :group 'org-edit-structure
-  :version "24.1"
-  :type '(choice
-         (const :tag "Do not check" nil)
-         (const :tag "Throw error when trying to edit" error)
-         (const :tag "Unhide, but do not do the edit" show-and-error)
-         (const :tag "Show invisible part and do the edit" show)
-         (const :tag "Be smart and do the right thing" smart)))
-
 (defcustom org-yank-folded-subtrees t
   "Non-nil means when yanking subtrees, fold them.
 If the kill is a single subtree, or a sequence of subtrees, i.e. if
@@ -1769,7 +1538,6 @@ (defcustom org-M-RET-may-split-line '((default . t))
                           (const default))
                   (boolean)))))
 
-
 (defcustom org-insert-heading-respect-content nil
   "Non-nil means insert new headings after the current subtree.
 \\<org-mode-map>
@@ -3986,15 +3754,6 @@ (defcustom org-columns-skip-archived-trees t
   :group 'org-properties
   :type 'boolean)
 
-(defcustom org-cycle-open-archived-trees nil
-  "Non-nil means `org-cycle' will open archived trees.
-An archived tree is a tree marked with the tag ARCHIVE.
-When nil, archived trees will stay folded.  You can still open them with
-normal outline commands like `show-all', but not with the cycling commands."
-  :group 'org-archive
-  :group 'org-cycle
-  :type 'boolean)
-
 (defcustom org-sparse-tree-open-archived-trees nil
   "Non-nil means sparse tree construction shows matches in archived trees.
 When nil, matches in these trees are highlighted, but the trees are kept in
@@ -4024,51 +3783,6 @@ (defcustom org-sparse-tree-default-date-type nil
   :package-version '(Org . "8.3")
   :group 'org-sparse-trees)
 
-(defun org-cycle-hide-archived-subtrees (state)
-  "Re-hide all archived subtrees after a visibility state change.
-STATE should be one of the symbols listed in the docstring of
-`org-cycle-hook'."
-  (when (and (not org-cycle-open-archived-trees)
-             (not (memq state '(overview folded))))
-    (save-excursion
-      (let* ((globalp (memq state '(contents all)))
-             (beg (if globalp (point-min) (point)))
-             (end (if globalp (point-max) (org-end-of-subtree t))))
-       (org-hide-archived-subtrees beg end)
-       (goto-char beg)
-       (when (looking-at-p (concat ".*:" org-archive-tag ":"))
-         (message "%s" (substitute-command-keys
-                        "Subtree is archived and stays closed.  Use \
-`\\[org-force-cycle-archived]' to cycle it anyway.")))))))
-
-(defun org-force-cycle-archived ()
-  "Cycle subtree even if it is archived."
-  (interactive)
-  (setq this-command 'org-cycle)
-  (let ((org-cycle-open-archived-trees t))
-    (call-interactively 'org-cycle)))
-
-(defun org-hide-archived-subtrees (beg end)
-  "Re-hide all archived subtrees after a visibility state change."
-  (org-with-wide-buffer
-   (let ((case-fold-search nil)
-        (re (concat org-outline-regexp-bol ".*:" org-archive-tag ":")))
-     (goto-char beg)
-     ;; Include headline point is currently on.
-     (beginning-of-line)
-     (while (and (< (point) end) (re-search-forward re end t))
-       (when (member org-archive-tag (org-get-tags nil t))
-        (org-flag-subtree t)
-        (org-end-of-subtree t))))))
-
-(defun org-flag-subtree (flag)
-  (save-excursion
-    (org-back-to-heading t)
-    (org-flag-region (line-end-position)
-                    (progn (org-end-of-subtree t) (point))
-                    flag
-                    'outline)))
-
 (defalias 'org-advertized-archive-subtree 'org-archive-subtree)
 
 ;; Declare Column View Code
@@ -6032,6 +5746,7 @@ (defun org-remove-empty-overlays-at (pos)
                                        (overlay-end o))))
         (delete-overlay o))))
 
+;; FIXME: This function is unused.
 (defun org-show-empty-lines-in-parent ()
   "Move to the parent and re-show empty lines before visible headlines."
   (save-excursion
@@ -6072,826 +5787,11 @@ (defun org-first-headline-recenter ()
        (set-window-start window (line-beginning-position))))))
 
 
-;;; Visibility (headlines, blocks, drawers)
-
-;;;; Headlines visibility
-
-(defun org-show-entry ()
-  "Show the body directly following its heading.
-Show the heading too, if it is currently invisible."
-  (interactive)
-  (save-excursion
-    (org-back-to-heading-or-point-min t)
-    (org-flag-region
-     (line-end-position 0)
-     (save-excursion
-       (if (re-search-forward
-           (concat "[\r\n]\\(" org-outline-regexp "\\)") nil t)
-          (match-beginning 1)
-        (point-max)))
-     nil
-     'outline)
-    (org-cycle-hide-drawers 'children)))
-
-(defun org-hide-entry ()
-  "Hide the body directly following its heading."
-  (interactive)
-  (save-excursion
-    (org-back-to-heading-or-point-min t)
-    (when (org-at-heading-p) (forward-line))
-    (org-flag-region
-     (line-end-position 0)
-     (save-excursion
-       (if (re-search-forward
-           (concat "[\r\n]" org-outline-regexp) nil t)
-           (line-end-position 0)
-        (point-max)))
-     t
-     'outline)))
-
-(defun org-show-children (&optional level)
-  "Show all direct subheadings of this heading.
-Prefix arg LEVEL is how many levels below the current level
-should be shown.  Default is enough to cause the following
-heading to appear."
-  (interactive "p")
-  (unless (org-before-first-heading-p)
-    (save-excursion
-      (org-with-limited-levels (org-back-to-heading t))
-      (let* ((current-level (funcall outline-level))
-            (max-level (org-get-valid-level
-                        current-level
-                        (if level (prefix-numeric-value level) 1)))
-            (end (save-excursion (org-end-of-subtree t t)))
-            (regexp-fmt "^\\*\\{%d,%s\\}\\(?: \\|$\\)")
-            (past-first-child nil)
-            ;; Make sure to skip inlinetasks.
-            (re (format regexp-fmt
-                        current-level
-                        (cond
-                         ((not (featurep 'org-inlinetask)) "")
-                         (org-odd-levels-only (- (* 2 org-inlinetask-min-level)
-                                                 3))
-                         (t (1- org-inlinetask-min-level))))))
-       ;; Display parent heading.
-       (org-flag-heading nil)
-       (forward-line)
-       ;; Display children.  First child may be deeper than expected
-       ;; MAX-LEVEL.  Since we want to display it anyway, adjust
-       ;; MAX-LEVEL accordingly.
-       (while (re-search-forward re end t)
-         (unless past-first-child
-           (setq re (format regexp-fmt
-                            current-level
-                            (max (funcall outline-level) max-level)))
-           (setq past-first-child t))
-         (org-flag-heading nil))))))
-
-(defun org-show-subtree ()
-  "Show everything after this heading at deeper levels."
-  (interactive)
-  (org-flag-region
-   (point) (save-excursion (org-end-of-subtree t t)) nil 'outline))
-
-;;;; Blocks and drawers visibility
-
-(defun org--hide-wrapper-toggle (element category force no-error)
-  "Toggle visibility for ELEMENT.
-
-ELEMENT is a block or drawer type parsed element.  CATEGORY is
-either `block' or `drawer'.  When FORCE is `off', show the block
-or drawer.  If it is non-nil, hide it unconditionally.  Throw an
-error when not at a block or drawer, unless NO-ERROR is non-nil.
-
-Return a non-nil value when toggling is successful."
-  (let ((type (org-element-type element)))
-    (cond
-     ((memq type
-           (pcase category
-             (`drawer '(drawer property-drawer))
-             (`block '(center-block
-                       comment-block dynamic-block example-block export-block
-                       quote-block special-block src-block verse-block))
-             (_ (error "Unknown category: %S" category))))
-      (let* ((post (org-element-property :post-affiliated element))
-            (start (save-excursion
-                     (goto-char post)
-                     (line-end-position)))
-            (end (save-excursion
-                   (goto-char (org-element-property :end element))
-                   (skip-chars-backward " \t\n")
-                   (line-end-position))))
-       ;; Do nothing when not before or at the block opening line or
-       ;; at the block closing line.
-       (unless (let ((eol (line-end-position)))
-                 (and (> eol start) (/= eol end)))
-         (let* ((spec (if (eq category 'block) 'org-hide-block 'outline))
-                (flag
-                 (cond ((eq force 'off) nil)
-                       (force t)
-                       ((eq spec (get-char-property start 'invisible)) nil)
-                       (t t))))
-           (org-flag-region start end flag spec))
-         ;; When the block is hidden away, make sure point is left in
-         ;; a visible part of the buffer.
-         (when (invisible-p (max (1- (point)) (point-min)))
-           (goto-char post))
-         ;; Signal success.
-         t)))
-     (no-error nil)
-     (t
-      (user-error (if (eq category 'drawer)
-                     "Not at a drawer"
-                   "Not at a block"))))))
-
-(defun org-hide-block-toggle (&optional force no-error element)
-  "Toggle the visibility of the current block.
-
-When optional argument FORCE is `off', make block visible.  If it
-is non-nil, hide it unconditionally.  Throw an error when not at
-a block, unless NO-ERROR is non-nil.  When optional argument
-ELEMENT is provided, consider it instead of the current block.
-
-Return a non-nil value when toggling is successful."
-  (interactive)
-  (org--hide-wrapper-toggle
-   (or element (org-element-at-point)) 'block force no-error))
-
-(defun org-hide-drawer-toggle (&optional force no-error element)
-  "Toggle the visibility of the current drawer.
-
-When optional argument FORCE is `off', make drawer visible.  If
-it is non-nil, hide it unconditionally.  Throw an error when not
-at a drawer, unless NO-ERROR is non-nil.  When optional argument
-ELEMENT is provided, consider it instead of the current drawer.
-
-Return a non-nil value when toggling is successful."
-  (interactive)
-  (org--hide-wrapper-toggle
-   (or element (org-element-at-point)) 'drawer force no-error))
-
-(defun org-hide-block-all ()
-  "Fold all blocks in the current buffer."
-  (interactive)
-  (org-show-all '(blocks))
-  (org-block-map 'org-hide-block-toggle))
-
-(defun org-hide-drawer-all ()
-  "Fold all drawers in the current buffer."
-  (let ((begin (point-min))
-       (end (point-max)))
-    (org--hide-drawers begin end)))
-
-(defun org-cycle-hide-drawers (state)
-  "Re-hide all drawers after a visibility state change.
-STATE should be one of the symbols listed in the docstring of
-`org-cycle-hook'."
-  (when (derived-mode-p 'org-mode)
-    (cond ((not (memq state '(overview folded contents)))
-          (let* ((global? (eq state 'all))
-                 (beg (if global? (point-min) (line-beginning-position)))
-                 (end (cond (global? (point-max))
-                            ((eq state 'children) (org-entry-end-position))
-                            (t (save-excursion (org-end-of-subtree t t))))))
-            (org--hide-drawers beg end)))
-         ((memq state '(overview contents))
-          ;; Hide drawers before first heading.
-          (let ((beg (point-min))
-                (end (save-excursion
-                       (goto-char (point-min))
-                       (if (org-before-first-heading-p)
-                           (org-entry-end-position)
-                         (point-min)))))
-            (when (< beg end)
-              (org--hide-drawers beg end)))))))
-
-(defun org--hide-drawers (begin end)
-  "Hide all drawers between BEGIN and END."
-  (save-excursion
-    (goto-char begin)
-    (while (re-search-forward org-drawer-regexp end t)
-      (let* ((pair (get-char-property-and-overlay (line-beginning-position)
-                                                 'invisible))
-            (o (cdr-safe pair)))
-       (if (overlayp o) (goto-char (overlay-end o)) ;invisible drawer
-         (pcase (get-char-property-and-overlay (point) 'invisible)
-           (`(outline . ,o) (goto-char (overlay-end o))) ;already folded
-           (_
-            (let* ((drawer (org-element-at-point))
-                   (type (org-element-type drawer)))
-              (when (memq type '(drawer property-drawer))
-                (org-hide-drawer-toggle t nil drawer)
-                ;; Make sure to skip drawer entirely or we might flag it
-                ;; another time when matching its ending line with
-                ;; `org-drawer-regexp'.
-                (goto-char (org-element-property :end drawer)))))))))))
-
-;;;; Visibility cycling
-
-(defvar-local org-cycle-global-status nil)
-(put 'org-cycle-global-status 'org-state t)
-(defvar-local org-cycle-subtree-status nil)
-(put 'org-cycle-subtree-status 'org-state t)
-
-(defun org-show-all (&optional types)
-  "Show all contents in the visible part of the buffer.
-By default, the function expands headings, blocks and drawers.
-When optional argument TYPE is a list of symbols among `blocks',
-`drawers' and `headings', to only expand one specific type."
-  (interactive)
-  (let ((types (or types '(blocks drawers headings))))
-    (when (memq 'blocks types)
-      (org-flag-region (point-min) (point-max) nil 'org-hide-block))
-    (cond
-     ;; Fast path.  Since headings and drawers share the same
-     ;; invisible spec, clear everything in one go.
-     ((and (memq 'headings types)
-          (memq 'drawers types))
-      (org-flag-region (point-min) (point-max) nil 'outline))
-     ((memq 'headings types)
-      (org-flag-region (point-min) (point-max) nil 'outline)
-      (org-cycle-hide-drawers 'all))
-     ((memq 'drawers types)
-      (save-excursion
-       (goto-char (point-min))
-       (while (re-search-forward org-drawer-regexp nil t)
-         (let* ((pair (get-char-property-and-overlay (line-beginning-position)
-                                                     'invisible))
-                (o (cdr-safe pair)))
-           (if (overlayp o) (goto-char (overlay-end o))
-             (pcase (get-char-property-and-overlay (point) 'invisible)
-               (`(outline . ,o)
-                (goto-char (overlay-end o))
-                (delete-overlay o))
-               (_ nil))))))))))
-
-;;;###autoload
-(defun org-cycle (&optional arg)
-  "TAB-action and visibility cycling for Org mode.
-
-This is the command invoked in Org mode by the `TAB' key.  Its main
-purpose is outline visibility cycling, but it also invokes other actions
-in special contexts.
-
-When this function is called with a `\\[universal-argument]' prefix, rotate \
-the entire
-buffer through 3 states (global cycling)
-  1. OVERVIEW: Show only top-level headlines.
-  2. CONTENTS: Show all headlines of all levels, but no body text.
-  3. SHOW ALL: Show everything.
-
-With a `\\[universal-argument] \\[universal-argument]' prefix argument, \
-switch to the startup visibility,
-determined by the variable `org-startup-folded', and by any VISIBILITY
-properties in the buffer.
-
-With a `\\[universal-argument] \\[universal-argument] \
-\\[universal-argument]' prefix argument, show the entire buffer, including
-any drawers.
-
-When inside a table, re-align the table and move to the next field.
-
-When point is at the beginning of a headline, rotate the subtree started
-by this line through 3 different states (local cycling)
-  1. FOLDED:   Only the main headline is shown.
-  2. CHILDREN: The main headline and the direct children are shown.
-               From this state, you can move to one of the children
-               and zoom in further.
-  3. SUBTREE:  Show the entire subtree, including body text.
-If there is no subtree, switch directly from CHILDREN to FOLDED.
-
-When point is at the beginning of an empty headline and the variable
-`org-cycle-level-after-item/entry-creation' is set, cycle the level
-of the headline by demoting and promoting it to likely levels.  This
-speeds up creation document structure by pressing `TAB' once or several
-times right after creating a new headline.
-
-When there is a numeric prefix, go up to a heading with level ARG, do
-a `show-subtree' and return to the previous cursor position.  If ARG
-is negative, go up that many levels.
-
-When point is not at the beginning of a headline, execute the global
-binding for `TAB', which is re-indenting the line.  See the option
-`org-cycle-emulate-tab' for details.
-
-As a special case, if point is at the very beginning of the buffer, if
-there is no headline there, and if the variable `org-cycle-global-at-bob'
-is non-nil, this function acts as if called with prefix argument \
-\(`\\[universal-argument] TAB',
-same as `S-TAB') also when called without prefix argument."
-  (interactive "P")
-  (org-load-modules-maybe)
-  (unless (or (run-hook-with-args-until-success 'org-tab-first-hook)
-             (and org-cycle-level-after-item/entry-creation
-                  (or (org-cycle-level)
-                      (org-cycle-item-indentation))))
-    (let* ((limit-level
-           (or org-cycle-max-level
-               (and (boundp 'org-inlinetask-min-level)
-                    org-inlinetask-min-level
-                    (1- org-inlinetask-min-level))))
-          (nstars
-           (and limit-level
-                (if org-odd-levels-only
-                    (1- (* 2 limit-level))
-                  limit-level)))
-          (org-outline-regexp
-           (format "\\*%s " (if nstars (format "\\{1,%d\\}" nstars) "+"))))
-      (cond
-       ((equal arg '(16))
-       (setq last-command 'dummy)
-       (org-set-startup-visibility)
-       (org-unlogged-message "Startup visibility, plus VISIBILITY properties"))
-       ((equal arg '(64))
-       (org-show-all)
-       (org-unlogged-message "Entire buffer visible, including drawers"))
-       ((equal arg '(4)) (org-cycle-internal-global))
-       ;; Show-subtree, ARG levels up from here.
-       ((integerp arg)
-       (save-excursion
-         (org-back-to-heading)
-         (outline-up-heading (if (< arg 0) (- arg)
-                               (- (funcall outline-level) arg)))
-         (org-show-subtree)))
-       ;; Global cycling at BOB: delegate to `org-cycle-internal-global'.
-       ((and org-cycle-global-at-bob
-            (bobp)
-            (not (looking-at org-outline-regexp)))
-       (let ((org-cycle-hook
-              (remq 'org-optimize-window-after-visibility-change
-                    org-cycle-hook)))
-         (org-cycle-internal-global)))
-       ;; Try CDLaTeX TAB completion.
-       ((org-try-cdlatex-tab))
-       ;; Inline task: delegate to `org-inlinetask-toggle-visibility'.
-       ((and (featurep 'org-inlinetask)
-            (org-inlinetask-at-task-p)
-            (or (bolp) (not (eq org-cycle-emulate-tab 'exc-hl-bol))))
-       (org-inlinetask-toggle-visibility))
-       (t
-       (let ((pos (point))
-             (element (org-element-at-point)))
-         (cond
-          ;; Try toggling visibility for block at point.
-          ((org-hide-block-toggle nil t element))
-          ;; Try toggling visibility for drawer at point.
-          ((org-hide-drawer-toggle nil t element))
-          ;; Table: enter it or move to the next field.
-          ((and (org-match-line "[ \t]*[|+]")
-                (org-element-lineage element '(table) t))
-           (if (and (eq 'table (org-element-type element))
-                    (eq 'table.el (org-element-property :type element)))
-               (message (substitute-command-keys "\\<org-mode-map>\
-Use `\\[org-edit-special]' to edit table.el tables"))
-             (org-table-justify-field-maybe)
-             (call-interactively #'org-table-next-field)))
-          ((run-hook-with-args-until-success
-            'org-tab-after-check-for-table-hook))
-          ;; At an item/headline: delegate to `org-cycle-internal-local'.
-          ((and (or (and org-cycle-include-plain-lists
-                         (let ((item (org-element-lineage element
-                                                          '(item plain-list)
-                                                          t)))
-                           (and item
-                                (= (line-beginning-position)
-                                   (org-element-property :post-affiliated
-                                                         item)))))
-                    (org-match-line org-outline-regexp))
-                (or (bolp) (not (eq org-cycle-emulate-tab 'exc-hl-bol))))
-           (org-cycle-internal-local))
-          ;; From there: TAB emulation and template completion.
-          (buffer-read-only (org-back-to-heading))
-          ((run-hook-with-args-until-success
-            'org-tab-after-check-for-cycling-hook))
-          ((run-hook-with-args-until-success
-            'org-tab-before-tab-emulation-hook))
-          ((and (eq org-cycle-emulate-tab 'exc-hl-bol)
-                (or (not (bolp))
-                    (not (looking-at org-outline-regexp))))
-           (call-interactively (global-key-binding (kbd "TAB"))))
-          ((or (eq org-cycle-emulate-tab t)
-               (and (memq org-cycle-emulate-tab '(white whitestart))
-                    (save-excursion (beginning-of-line 1) (looking-at "[ 
\t]*"))
-                    (or (and (eq org-cycle-emulate-tab 'white)
-                             (= (match-end 0) (point-at-eol)))
-                        (and (eq org-cycle-emulate-tab 'whitestart)
-                             (>= (match-end 0) pos)))))
-           (call-interactively (global-key-binding (kbd "TAB"))))
-          (t
-           (save-excursion
-             (org-back-to-heading)
-             (org-cycle))))))))))
-
-(defun org-cycle-internal-global ()
-  "Do the global cycling action."
-  ;; Hack to avoid display of messages for .org  attachments in Gnus
-  (let ((ga (string-match-p "\\*fontification" (buffer-name))))
-    (cond
-     ((and (eq last-command this-command)
-          (eq org-cycle-global-status 'overview))
-      ;; We just created the overview - now do table of contents
-      ;; This can be slow in very large buffers, so indicate action
-      (run-hook-with-args 'org-pre-cycle-hook 'contents)
-      (unless ga (org-unlogged-message "CONTENTS..."))
-      (org-content)
-      (unless ga (org-unlogged-message "CONTENTS...done"))
-      (setq org-cycle-global-status 'contents)
-      (run-hook-with-args 'org-cycle-hook 'contents))
-
-     ((and (eq last-command this-command)
-          (eq org-cycle-global-status 'contents))
-      ;; We just showed the table of contents - now show everything
-      (run-hook-with-args 'org-pre-cycle-hook 'all)
-      (org-show-all '(headings blocks))
-      (unless ga (org-unlogged-message "SHOW ALL"))
-      (setq org-cycle-global-status 'all)
-      (run-hook-with-args 'org-cycle-hook 'all))
-
-     (t
-      ;; Default action: go to overview
-      (run-hook-with-args 'org-pre-cycle-hook 'overview)
-      (org-overview)
-      (unless ga (org-unlogged-message "OVERVIEW"))
-      (setq org-cycle-global-status 'overview)
-      (run-hook-with-args 'org-cycle-hook 'overview)))))
 
+;; FIXME: It was in the middle of visibility section. Where should it go to?
 (defvar org-called-with-limited-levels nil
   "Non-nil when `org-with-limited-levels' is currently active.")
 
-(defun org-cycle-internal-local ()
-  "Do the local cycling action."
-  (let ((goal-column 0) eoh eol eos has-children children-skipped struct)
-    ;; First, determine end of headline (EOH), end of subtree or item
-    ;; (EOS), and if item or heading has children (HAS-CHILDREN).
-    (save-excursion
-      (if (org-at-item-p)
-         (progn
-           (beginning-of-line)
-           (setq struct (org-list-struct))
-           (setq eoh (point-at-eol))
-           (setq eos (org-list-get-item-end-before-blank (point) struct))
-           (setq has-children (org-list-has-child-p (point) struct)))
-       (org-back-to-heading)
-       (setq eoh (save-excursion (outline-end-of-heading) (point)))
-       (setq eos (save-excursion
-                   (org-end-of-subtree t t)
-                   (unless (eobp) (forward-char -1))
-                   (point)))
-       (setq has-children
-             (or
-              (save-excursion
-                (let ((level (funcall outline-level)))
-                  (outline-next-heading)
-                  (and (org-at-heading-p t)
-                       (> (funcall outline-level) level))))
-              (and (eq org-cycle-include-plain-lists 'integrate)
-                   (save-excursion
-                     (org-list-search-forward (org-item-beginning-re) eos 
t))))))
-      ;; Determine end invisible part of buffer (EOL)
-      (beginning-of-line 2)
-      (while (and (not (eobp))         ;this is like `next-line'
-                 (get-char-property (1- (point)) 'invisible))
-       (goto-char (next-single-char-property-change (point) 'invisible))
-       (and (eolp) (beginning-of-line 2)))
-      (setq eol (point)))
-    ;; Find out what to do next and set `this-command'
-    (cond
-     ((= eos eoh)
-      ;; Nothing is hidden behind this heading
-      (unless (org-before-first-heading-p)
-       (run-hook-with-args 'org-pre-cycle-hook 'empty))
-      (org-unlogged-message "EMPTY ENTRY")
-      (setq org-cycle-subtree-status nil)
-      (save-excursion
-       (goto-char eos)
-       (outline-next-heading)
-       (when (org-invisible-p) (org-flag-heading nil))))
-     ((and (or (>= eol eos)
-              (not (string-match "\\S-" (buffer-substring eol eos))))
-          (or has-children
-              (not (setq children-skipped
-                         org-cycle-skip-children-state-if-no-children))))
-      ;; Entire subtree is hidden in one line: children view
-      (unless (org-before-first-heading-p)
-       (run-hook-with-args 'org-pre-cycle-hook 'children))
-      (if (org-at-item-p)
-         (org-list-set-item-visibility (point-at-bol) struct 'children)
-       (org-show-entry)
-       (org-with-limited-levels (org-show-children))
-       (org-show-set-visibility 'tree)
-       ;; Fold every list in subtree to top-level items.
-       (when (eq org-cycle-include-plain-lists 'integrate)
-         (save-excursion
-           (org-back-to-heading)
-           (while (org-list-search-forward (org-item-beginning-re) eos t)
-             (beginning-of-line 1)
-             (let* ((struct (org-list-struct))
-                    (prevs (org-list-prevs-alist struct))
-                    (end (org-list-get-bottom-point struct)))
-               (dolist (e (org-list-get-all-items (point) struct prevs))
-                 (org-list-set-item-visibility e struct 'folded))
-               (goto-char (if (< end eos) end eos)))))))
-      (org-unlogged-message "CHILDREN")
-      (save-excursion
-       (goto-char eos)
-       (outline-next-heading)
-       (when (org-invisible-p) (org-flag-heading nil)))
-      (setq org-cycle-subtree-status 'children)
-      (unless (org-before-first-heading-p)
-       (run-hook-with-args 'org-cycle-hook 'children)))
-     ((or children-skipped
-         (and (eq last-command this-command)
-              (eq org-cycle-subtree-status 'children)))
-      ;; We just showed the children, or no children are there,
-      ;; now show everything.
-      (unless (org-before-first-heading-p)
-       (run-hook-with-args 'org-pre-cycle-hook 'subtree))
-      (org-flag-region eoh eos nil 'outline)
-      (org-unlogged-message
-       (if children-skipped "SUBTREE (NO CHILDREN)" "SUBTREE"))
-      (setq org-cycle-subtree-status 'subtree)
-      (unless (org-before-first-heading-p)
-       (run-hook-with-args 'org-cycle-hook 'subtree)))
-     (t
-      ;; Default action: hide the subtree.
-      (run-hook-with-args 'org-pre-cycle-hook 'folded)
-      (org-flag-region eoh eos t 'outline)
-      (org-unlogged-message "FOLDED")
-      (setq org-cycle-subtree-status 'folded)
-      (unless (org-before-first-heading-p)
-       (run-hook-with-args 'org-cycle-hook 'folded))))))
-
-;;;###autoload
-(defun org-global-cycle (&optional arg)
-  "Cycle the global visibility.  For details see `org-cycle'.
-With `\\[universal-argument]' prefix ARG, switch to startup visibility.
-With a numeric prefix, show all headlines up to that level."
-  (interactive "P")
-  (cond
-   ((integerp arg)
-    (org-content arg)
-    (setq org-cycle-global-status 'contents))
-   ((equal arg '(4))
-    (org-set-startup-visibility)
-    (org-unlogged-message "Startup visibility, plus VISIBILITY properties."))
-   (t
-    (org-cycle '(4)))))
-
-(defun org-set-startup-visibility ()
-  "Set the visibility required by startup options and properties."
-  (cond
-   ((eq org-startup-folded t)
-    (org-overview))
-   ((eq org-startup-folded 'content)
-    (org-content))
-   ((eq org-startup-folded 'show2levels)
-    (org-content 2))
-   ((eq org-startup-folded 'show3levels)
-    (org-content 3))
-   ((eq org-startup-folded 'show4levels)
-    (org-content 4))
-   ((eq org-startup-folded 'show5levels)
-    (org-content 5))
-   ((or (eq org-startup-folded 'showeverything)
-       (eq org-startup-folded nil))
-    (org-show-all)))
-  (unless (eq org-startup-folded 'showeverything)
-    (when org-hide-block-startup (org-hide-block-all))
-    (org-set-visibility-according-to-property)
-    (org-cycle-hide-archived-subtrees 'all)
-    (org-cycle-hide-drawers 'all)
-    (org-cycle-show-empty-lines t)))
-
-(defun org-set-visibility-according-to-property ()
-  "Switch subtree visibility according to VISIBILITY property."
-  (interactive)
-  (let ((regexp (org-re-property "VISIBILITY")))
-    (org-with-point-at 1
-      (while (re-search-forward regexp nil t)
-       (let ((state (match-string 3)))
-         (if (not (org-at-property-p)) (outline-next-heading)
-           (save-excursion
-             (org-back-to-heading t)
-             (org-flag-subtree t)
-             (org-reveal)
-             (pcase state
-               ("folded"
-                (org-flag-subtree t))
-               ("children"
-                (org-show-hidden-entry)
-                (org-show-children))
-               ("content"
-                (save-excursion
-                  (save-restriction
-                    (org-narrow-to-subtree)
-                    (org-content))))
-               ((or "all" "showall")
-                (outline-show-subtree))
-               (_ nil)))
-           (org-end-of-subtree)))))))
-
-(defun org-overview ()
-  "Switch to overview mode, showing only top-level headlines."
-  (interactive)
-  (org-show-all '(headings drawers))
-  (save-excursion
-    (goto-char (point-min))
-    (when (re-search-forward org-outline-regexp-bol nil t)
-      (let* ((last (line-end-position))
-             (level (- (match-end 0) (match-beginning 0) 1))
-             (regexp (format "^\\*\\{1,%d\\} " level)))
-        (while (re-search-forward regexp nil :move)
-          (org-flag-region last (line-end-position 0) t 'outline)
-          (setq last (line-end-position))
-          (setq level (- (match-end 0) (match-beginning 0) 1))
-          (setq regexp (format "^\\*\\{1,%d\\} " level)))
-        (org-flag-region last (point) t 'outline)))))
-
-(defun org-content (&optional arg)
-  "Show all headlines in the buffer, like a table of contents.
-With numerical argument N, show content up to level N."
-  (interactive "p")
-  (org-show-all '(headings drawers))
-  (save-excursion
-    (goto-char (point-max))
-    (let ((regexp (if (and (wholenump arg) (> arg 0))
-                      (format "^\\*\\{1,%d\\} " arg)
-                    "^\\*+ "))
-          (last (point)))
-      (while (re-search-backward regexp nil t)
-        (org-flag-region (line-end-position) last t 'outline)
-        (setq last (line-end-position 0))))))
-
-(defvar org-scroll-position-to-restore nil
-  "Temporarily store scroll position to restore.")
-(defun org-optimize-window-after-visibility-change (state)
-  "Adjust the window after a change in outline visibility.
-This function is the default value of the hook `org-cycle-hook'."
-  (when (get-buffer-window (current-buffer))
-    (let ((repeat (eq last-command this-command)))
-      (unless repeat
-       (setq org-scroll-position-to-restore nil))
-      (cond
-       ((eq state 'content)  nil)
-       ((eq state 'all)      nil)
-       ((and org-scroll-position-to-restore repeat
-            (eq state 'folded))
-       (set-window-start nil org-scroll-position-to-restore))
-       ((eq state 'folded) nil)
-       ((eq state 'children)
-       (setq org-scroll-position-to-restore (window-start))
-       (or (org-subtree-end-visible-p) (recenter 1)))
-       ((eq state 'subtree)
-       (unless repeat
-         (setq org-scroll-position-to-restore (window-start)))
-       (or (org-subtree-end-visible-p) (recenter 1)))))))
-
-(defun org-clean-visibility-after-subtree-move ()
-  "Fix visibility issues after moving a subtree."
-  ;; First, find a reasonable region to look at:
-  ;; Start two siblings above, end three below
-  (let* ((beg (save-excursion
-               (and (org-get-previous-sibling)
-                    (org-get-previous-sibling))
-               (point)))
-        (end (save-excursion
-               (and (org-get-next-sibling)
-                    (org-get-next-sibling)
-                    (org-get-next-sibling))
-               (if (org-at-heading-p)
-                   (point-at-eol)
-                 (point))))
-        (level (looking-at "\\*+"))
-        (re (when level (concat "^" (regexp-quote (match-string 0)) " "))))
-    (save-excursion
-      (save-restriction
-       (narrow-to-region beg end)
-       (when re
-         ;; Properly fold already folded siblings
-         (goto-char (point-min))
-         (while (re-search-forward re nil t)
-           (when (and (not (org-invisible-p))
-                      (org-invisible-p (line-end-position)))
-             (outline-hide-entry))))
-       (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.
-The region to be covered depends on STATE when called through
-`org-cycle-hook'.  Lisp program can use t for STATE to get the
-entire buffer covered.  Note that an empty line is only shown if there
-are at least `org-cycle-separator-lines' empty lines before the headline."
-  (when (/= org-cycle-separator-lines 0)
-    (save-excursion
-      (let* ((n (abs org-cycle-separator-lines))
-            (re (cond
-                 ((= n 1) "\\(\n[ \t]*\n\\*+\\) ")
-                 ((= n 2) "^[ \t]*\\(\n[ \t]*\n\\*+\\) ")
-                 (t (let ((ns (number-to-string (- n 2))))
-                      (concat "^\\(?:[ \t]*\n\\)\\{" ns "," ns "\\}"
-                              "[ \t]*\\(\n[ \t]*\n\\*+\\) ")))))
-            beg end)
-       (cond
-        ((memq state '(overview contents t))
-         (setq beg (point-min) end (point-max)))
-        ((memq state '(children folded))
-         (setq beg (point)
-               end (progn (org-end-of-subtree t t)
-                          (line-beginning-position 2)))))
-       (when beg
-         (goto-char beg)
-         (while (re-search-forward re end t)
-           (unless (get-char-property (match-end 1) 'invisible)
-             (let ((e (match-end 1))
-                   (b (if (>= org-cycle-separator-lines 0)
-                          (match-beginning 1)
-                        (save-excursion
-                          (goto-char (match-beginning 0))
-                          (skip-chars-backward " \t\n")
-                          (line-end-position)))))
-               (org-flag-region b e nil 'outline))))))))
-  ;; Never hide empty lines at the end of the file.
-  (save-excursion
-    (goto-char (point-max))
-    (outline-previous-heading)
-    (outline-end-of-heading)
-    (when (and (looking-at "[ \t\n]+")
-              (= (match-end 0) (point-max)))
-      (org-flag-region (point) (match-end 0) nil 'outline))))
-
-;;;; Reveal point location
-
-(defun org-show-context (&optional key)
-  "Make sure point and context are visible.
-Optional argument KEY, when non-nil, is a symbol.  See
-`org-show-context-detail' for allowed values and how much is to
-be shown."
-  (org-show-set-visibility
-   (cond ((symbolp org-show-context-detail) org-show-context-detail)
-        ((cdr (assq key org-show-context-detail)))
-        (t (cdr (assq 'default org-show-context-detail))))))
-
-(defun org-show-set-visibility (detail)
-  "Set visibility around point according to DETAIL.
-DETAIL is either nil, `minimal', `local', `ancestors',
-`ancestors-full', `lineage', `tree', `canonical' or t.  See
-`org-show-context-detail' for more information."
-  ;; Show current heading and possibly its entry, following headline
-  ;; or all children.
-  (if (and (org-at-heading-p) (not (eq detail 'local)))
-      (org-flag-heading nil)
-    (org-show-entry)
-    ;; 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))
-       (delete-overlay o)))
-    (unless (org-before-first-heading-p)
-      (org-with-limited-levels
-       (cl-case detail
-        ((tree canonical t) (org-show-children))
-        ((nil minimal ancestors ancestors-full))
-        (t (save-excursion
-             (outline-next-heading)
-             (org-flag-heading nil)))))))
-  ;; Show whole subtree.
-  (when (eq detail 'ancestors-full) (org-show-subtree))
-  ;; Show all siblings.
-  (when (eq detail 'lineage) (org-show-siblings))
-  ;; Show ancestors, possibly with their children.
-  (when (memq detail '(ancestors ancestors-full lineage tree canonical t))
-    (save-excursion
-      (while (org-up-heading-safe)
-       (org-flag-heading nil)
-       (when (memq detail '(canonical t)) (org-show-entry))
-       (when (memq detail '(tree canonical t)) (org-show-children))))))
-
-(defvar org-reveal-start-hook nil
-  "Hook run before revealing a location.")
-
-(defun org-reveal (&optional siblings)
-  "Show current entry, hierarchy above it, and the following headline.
-
-This can be used to show a consistent set of context around
-locations exposed with `org-show-context'.
-
-With optional argument SIBLINGS, on each level of the hierarchy all
-siblings are shown.  This repairs the tree structure to what it would
-look like when opened with hierarchical calls to `org-cycle'.
-
-With a \\[universal-argument] \\[universal-argument] prefix, \
-go to the parent and show the entire tree."
-  (interactive "P")
-  (run-hooks 'org-reveal-start-hook)
-  (cond ((equal siblings '(4)) (org-show-set-visibility 'canonical))
-       ((equal siblings '(16))
-        (save-excursion
-          (when (org-up-heading-safe)
-            (org-show-subtree)
-            (run-hook-with-args 'org-cycle-hook 'subtree))))
-       (t (org-show-set-visibility 'lineage))))
-
 
 ;;; Indirect buffer display of subtrees
 
@@ -7642,6 +6542,36 @@ (defun org-move-subtree-up (&optional arg)
   (interactive "p")
   (org-move-subtree-down (- (prefix-numeric-value arg))))
 
+(defun org-clean-visibility-after-subtree-move ()
+  "Fix visibility issues after moving a subtree."
+  ;; First, find a reasonable region to look at:
+  ;; Start two siblings above, end three below
+  (let* ((beg (save-excursion
+               (and (org-get-previous-sibling)
+                    (org-get-previous-sibling))
+               (point)))
+        (end (save-excursion
+               (and (org-get-next-sibling)
+                    (org-get-next-sibling)
+                    (org-get-next-sibling))
+               (if (org-at-heading-p)
+                   (point-at-eol)
+                 (point))))
+        (level (looking-at "\\*+"))
+        (re (when level (concat "^" (regexp-quote (match-string 0)) " "))))
+    (save-excursion
+      (save-restriction
+       (narrow-to-region beg end)
+       (when re
+         ;; Properly fold already folded siblings
+         (goto-char (point-min))
+         (while (re-search-forward re nil t)
+           (when (and (not (org-invisible-p))
+                      (org-invisible-p (line-end-position)))
+             (org-fold-heading nil))))
+       (org-cycle-hide-drawers 'all)
+       (org-cycle-show-empty-lines 'overview)))))
+
 (defun org-move-subtree-down (&optional arg)
   "Move the current subtree down past ARG headlines of the same level."
   (interactive "p")
@@ -16945,6 +15875,14 @@ (defun org-remove-inline-images ()
 (defvar org-self-insert-command-undo-counter 0)
 (defvar org-speed-command nil)
 
+(defun org-fix-tags-on-the-fly ()
+  "Align tags in headline at point.
+Unlike `org-align-tags', this function does nothing if point is
+either not currently on a tagged headline or on a tag."
+  (when (and (org-match-line org-tag-line-re)
+            (< (point) (match-beginning 1)))
+    (org-align-tags)))
+
 (defun org-self-insert-command (N)
   "Like `self-insert-command', use overwrite-mode for whitespace in tables.
 If the cursor is in a table looking at whitespace, the whitespace is
@@ -17012,80 +15950,6 @@ (defun org-self-insert-command (N)
          (setq org-self-insert-command-undo-counter
                (1+ org-self-insert-command-undo-counter))))))))
 
-(defun org-check-before-invisible-edit (kind)
-  "Check if editing kind KIND would be dangerous with invisible text around.
-The detailed reaction depends on the user option `org-catch-invisible-edits'."
-  ;; First, try to get out of here as quickly as possible, to reduce overhead
-  (when (and org-catch-invisible-edits
-            (or (not (boundp 'visible-mode)) (not visible-mode))
-            (or (get-char-property (point) 'invisible)
-                (get-char-property (max (point-min) (1- (point))) 'invisible)))
-    ;; OK, we need to take a closer look.  Do not consider
-    ;; invisibility obtained through text properties (e.g., link
-    ;; fontification), as it cannot be toggled.
-    (let* ((invisible-at-point
-           (pcase (get-char-property-and-overlay (point) 'invisible)
-             (`(,_ . ,(and (pred overlayp) o)) o)))
-          ;; Assume that point cannot land in the middle of an
-          ;; overlay, or between two overlays.
-          (invisible-before-point
-           (and (not invisible-at-point)
-                (not (bobp))
-                (pcase (get-char-property-and-overlay (1- (point)) 'invisible)
-                  (`(,_ . ,(and (pred overlayp) o)) o))))
-          (border-and-ok-direction
-           (or
-            ;; Check if we are acting predictably before invisible
-            ;; text.
-            (and invisible-at-point
-                 (memq kind '(insert delete-backward)))
-            ;; Check if we are acting predictably after invisible text
-            ;; This works not well, and I have turned it off.  It seems
-            ;; better to always show and stop after invisible text.
-            ;; (and (not invisible-at-point) invisible-before-point
-            ;;  (memq kind '(insert delete)))
-            )))
-      (when (or invisible-at-point invisible-before-point)
-       (when (eq org-catch-invisible-edits 'error)
-         (user-error "Editing in invisible areas is prohibited, make them 
visible first"))
-       (if (and org-custom-properties-overlays
-                (y-or-n-p "Display invisible properties in this buffer? "))
-           (org-toggle-custom-properties-visibility)
-         ;; Make the area visible
-         (save-excursion
-           (when invisible-before-point
-             (goto-char
-              (previous-single-char-property-change (point) 'invisible)))
-           ;; Remove whatever overlay is currently making yet-to-be
-           ;; edited text invisible.  Also remove nested invisibility
-           ;; related overlays.
-           (delete-overlay (or invisible-at-point invisible-before-point))
-           (let ((origin (if invisible-at-point (point) (1- (point)))))
-             (while (pcase (get-char-property-and-overlay origin 'invisible)
-                      (`(,_ . ,(and (pred overlayp) o))
-                       (delete-overlay o)
-                       t)))))
-         (cond
-          ((eq org-catch-invisible-edits 'show)
-           ;; That's it, we do the edit after showing
-           (message
-            "Unfolding invisible region around point before editing")
-           (sit-for 1))
-          ((and (eq org-catch-invisible-edits 'smart)
-                border-and-ok-direction)
-           (message "Unfolding invisible region around point before editing"))
-          (t
-           ;; Don't do the edit, make the user repeat it in full visibility
-           (user-error "Edit in invisible region aborted, repeat to confirm 
with text visible"))))))))
-
-(defun org-fix-tags-on-the-fly ()
-  "Align tags in headline at point.
-Unlike `org-align-tags', this function does nothing if point is
-either not currently on a tagged headline or on a tag."
-  (when (and (org-match-line org-tag-line-re)
-            (< (point) (match-beginning 1)))
-    (org-align-tags)))
-
 (defun org-delete-backward-char (N)
   "Like `delete-backward-char', insert whitespace at field end in tables.
 When deleting backwards, in tables this function will insert whitespace in
@@ -17197,16 +16061,6 @@ (defvar org-ctrl-c-ctrl-c-final-hook nil
 it should do its thing and then return a non-nil value.  If the
 context is wrong, just do nothing and return nil.")
 
-(defvar org-tab-first-hook nil
-  "Hook for functions to attach themselves to TAB.
-See `org-ctrl-c-ctrl-c-hook' for more information.
-This hook runs as the first action when TAB is pressed, even before
-`org-cycle' messes around with the `outline-regexp' to cater for
-inline tasks and plain list item folding.
-If any function in this hook returns t, any other actions that
-would have been caused by TAB (such as table field motion or visibility
-cycling) will not occur.")
-
 (defvar org-tab-after-check-for-table-hook nil
   "Hook for functions to attach themselves to TAB.
 See `org-ctrl-c-ctrl-c-hook' for more information.
@@ -18135,25 +16989,6 @@ (defun org-mode-restart ()
     (org-reset-file-cache))
   (message "%s restarted" major-mode))
 
-(defun org-flag-above-first-heading (&optional arg)
-  "Hide from bob up to the first heading.
-Move point to the beginning of first heading or end of buffer."
-  (goto-char (point-min))
-  (unless (org-at-heading-p)
-    (outline-next-heading))
-  (unless (bobp)
-    (org-flag-region 1 (1- (point)) (not arg) 'outline)))
-
-(defun org-show-branches-buffer ()
-  "Show all branches in the buffer."
-  (org-flag-above-first-heading)
-  (outline-hide-sublevels 1)
-  (unless (eobp)
-    (outline-show-branches)
-    (while (outline-get-next-sibling)
-      (outline-show-branches)))
-  (goto-char (point-min)))
-
 (defun org-kill-note-or-show-branches ()
   "Abort storing current note, or show just branches."
   (interactive)
@@ -20966,14 +19801,6 @@ (defun org-goto-sibling (&optional previous)
        (goto-char pos)
        nil))))
 
-(defun org-show-siblings ()
-  "Show all siblings of the current headline."
-  (save-excursion
-    (while (org-goto-sibling) (org-flag-heading nil)))
-  (save-excursion
-    (while (org-goto-sibling 'previous)
-      (org-flag-heading nil))))
-
 (defun org-goto-first-child (&optional element)
   "Goto the first child, even if it is invisible.
 Return t when a child was found.  Otherwise don't move point and
@@ -21002,25 +19829,6 @@ (defun org-goto-first-child (&optional element)
            (progn (goto-char (match-beginning 0)) t)
          (goto-char pos) nil)))))
 
-(defun org-show-hidden-entry ()
-  "Show an entry where even the heading is hidden."
-  (save-excursion
-    (org-show-entry)))
-
-(defun org-flag-heading (flag &optional entry)
-  "Flag the current heading.  FLAG non-nil means make invisible.
-When ENTRY is non-nil, show the entire entry."
-  (save-excursion
-    (org-back-to-heading t)
-    ;; Check if we should show the entire entry
-    (if (not entry)
-       (org-flag-region
-        (line-end-position 0) (line-end-position) flag 'outline)
-      (org-show-entry)
-      (save-excursion
-       (and (outline-next-heading)
-            (org-flag-heading nil))))))
-
 (defun org-get-next-sibling ()
   "Move to next heading of the same level, and return point.
 If there is no such heading, return nil.
-- 
2.35.1



-- 
Ihor Radchenko,
PhD,
Center for Advancing Materials Performance from the Nanoscale (CAMP-nano)
State Key Laboratory for Mechanical Behavior of Materials, Xi'an Jiaotong 
University, Xi'an, China
Email: yantar92@gmail.com, ihor_radchenko@alumni.sutd.edu.sg



reply via email to

[Prev in Thread] Current Thread [Next in Thread]