2015-10-26 00:56:00 +00:00
|
|
|
;;; org-indent.el --- Dynamic indentation for Org -*- lexical-binding: t; -*-
|
2016-01-02 13:13:41 +00:00
|
|
|
|
2017-01-06 01:19:23 +00:00
|
|
|
;; Copyright (C) 2009-2017 Free Software Foundation, Inc.
|
2009-06-30 05:24:57 +00:00
|
|
|
;;
|
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
|
|
|
;; Homepage: http://orgmode.org
|
|
|
|
;;
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;;
|
2009-08-08 04:34:24 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2009-06-30 05:24:57 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2009-08-08 04:34:24 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
;;
|
2009-06-30 05:24:57 +00:00
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
2009-08-08 04:34:24 +00:00
|
|
|
;;
|
2009-06-30 05:24:57 +00:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
2009-08-08 04:34:24 +00:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
;;
|
2009-06-30 05:24:57 +00:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
;; This is an implementation of dynamic virtual indentation. It works
|
|
|
|
;; by adding text properties to a buffer to make sure lines are
|
|
|
|
;; indented according to outline structure.
|
2011-07-24 13:33:48 +00:00
|
|
|
;;
|
|
|
|
;; The process is synchronous, toggled at every buffer modification.
|
|
|
|
;; Though, the initialization (indentation of text already in the
|
|
|
|
;; buffer), which can take a few seconds in large buffers, happens on
|
2011-08-21 13:01:04 +00:00
|
|
|
;; idle time.
|
2011-07-24 13:33:48 +00:00
|
|
|
;;
|
2010-07-16 21:22:01 +00:00
|
|
|
;;; Code:
|
|
|
|
|
2009-06-30 05:24:57 +00:00
|
|
|
(require 'org-macs)
|
|
|
|
(require 'org-compat)
|
|
|
|
(require 'org)
|
2010-07-16 21:22:01 +00:00
|
|
|
|
2015-11-06 12:04:20 +00:00
|
|
|
(require 'cl-lib)
|
2009-06-30 05:24:57 +00:00
|
|
|
|
2010-12-10 13:13:05 +00:00
|
|
|
(declare-function org-inlinetask-get-task-level "org-inlinetask" ())
|
|
|
|
(declare-function org-inlinetask-in-task-p "org-inlinetask" ())
|
2011-02-27 14:52:36 +00:00
|
|
|
(declare-function org-list-item-body-column "org-list" (item))
|
2012-03-19 20:38:12 +00:00
|
|
|
(defvar org-inlinetask-show-first-star)
|
2010-12-10 13:13:05 +00:00
|
|
|
|
2009-06-30 05:24:57 +00:00
|
|
|
(defgroup org-indent nil
|
|
|
|
"Options concerning dynamic virtual outline indentation."
|
2010-03-23 07:31:55 +00:00
|
|
|
:tag "Org Indent"
|
2009-06-30 05:24:57 +00:00
|
|
|
:group 'org)
|
|
|
|
|
2011-07-21 17:02:35 +00:00
|
|
|
(defvar org-indent-inlinetask-first-star (org-add-props "*" '(face org-warning))
|
|
|
|
"First star of inline tasks, with correct face.")
|
org-indent: changes to the internals of initialization
* lisp/org-indent.el (org-indent-agent-timer,
org-indent-agentized-buffers, org-indent-agent-resume-timer,
org-indent-agent-process-duration, org-indent-agent-resume-delay):
new variables.
(org-indent-initial-marker): more accurate doc-string.
(org-indent-initial-timer, org-indent-initial-resume-timer,
org-indent-initial-process-duration, org-indent-initial-resume-delay,
org-indent-initial-lock): removed variables.
(org-indent-mode): set up an agent to watch current buffer, or add it
to the list of already watched buffers.
(org-indent-initialize-agent): new function.
(org-indent-initialize-buffer): now requires a mandatory buffer
argument.
(org-indent-add-properties): reflect changes to variables. The resume
timer is now global.
This change was introduced because a buffer killed while initializing
couldn't cancel its own initialization timer. Now, a global agent
watches for buffers, starting or resuming their initialization when
appropriate. It can cancel its own timer, thus killing itself, when no
more buffers are being watched.
2011-08-18 21:13:00 +00:00
|
|
|
(defvar org-indent-agent-timer nil
|
|
|
|
"Timer running the initialize agent.")
|
|
|
|
(defvar org-indent-agentized-buffers nil
|
|
|
|
"List of buffers watched by the initialize agent.")
|
|
|
|
(defvar org-indent-agent-resume-timer nil
|
|
|
|
"Timer to reschedule agent after switching to other idle processes.")
|
2011-08-21 13:01:04 +00:00
|
|
|
(defvar org-indent-agent-active-delay '(0 2 0)
|
|
|
|
"Time to run agent before switching to other idle processes.
|
|
|
|
Delay used when the buffer to initialize is current.")
|
|
|
|
(defvar org-indent-agent-passive-delay '(0 0 400000)
|
|
|
|
"Time to run agent before switching to other idle processes.
|
|
|
|
Delay used when the buffer to initialize isn't current.")
|
|
|
|
(defvar org-indent-agent-resume-delay '(0 0 100000)
|
org-indent: changes to the internals of initialization
* lisp/org-indent.el (org-indent-agent-timer,
org-indent-agentized-buffers, org-indent-agent-resume-timer,
org-indent-agent-process-duration, org-indent-agent-resume-delay):
new variables.
(org-indent-initial-marker): more accurate doc-string.
(org-indent-initial-timer, org-indent-initial-resume-timer,
org-indent-initial-process-duration, org-indent-initial-resume-delay,
org-indent-initial-lock): removed variables.
(org-indent-mode): set up an agent to watch current buffer, or add it
to the list of already watched buffers.
(org-indent-initialize-agent): new function.
(org-indent-initialize-buffer): now requires a mandatory buffer
argument.
(org-indent-add-properties): reflect changes to variables. The resume
timer is now global.
This change was introduced because a buffer killed while initializing
couldn't cancel its own initialization timer. Now, a global agent
watches for buffers, starting or resuming their initialization when
appropriate. It can cancel its own timer, thus killing itself, when no
more buffers are being watched.
2011-08-18 21:13:00 +00:00
|
|
|
"Minimal time for other idle processes before switching back to agent.")
|
2015-12-05 10:55:02 +00:00
|
|
|
(defvar org-indent--initial-marker nil
|
org-indent: changes to the internals of initialization
* lisp/org-indent.el (org-indent-agent-timer,
org-indent-agentized-buffers, org-indent-agent-resume-timer,
org-indent-agent-process-duration, org-indent-agent-resume-delay):
new variables.
(org-indent-initial-marker): more accurate doc-string.
(org-indent-initial-timer, org-indent-initial-resume-timer,
org-indent-initial-process-duration, org-indent-initial-resume-delay,
org-indent-initial-lock): removed variables.
(org-indent-mode): set up an agent to watch current buffer, or add it
to the list of already watched buffers.
(org-indent-initialize-agent): new function.
(org-indent-initialize-buffer): now requires a mandatory buffer
argument.
(org-indent-add-properties): reflect changes to variables. The resume
timer is now global.
This change was introduced because a buffer killed while initializing
couldn't cancel its own initialization timer. Now, a global agent
watches for buffers, starting or resuming their initialization when
appropriate. It can cancel its own timer, thus killing itself, when no
more buffers are being watched.
2011-08-18 21:13:00 +00:00
|
|
|
"Position of initialization before interrupt.
|
|
|
|
This is used locally in each buffer being initialized.")
|
2009-08-03 08:11:38 +00:00
|
|
|
(defvar org-hide-leading-stars-before-indent-mode nil
|
2010-07-16 21:22:01 +00:00
|
|
|
"Used locally.")
|
2011-07-23 12:25:27 +00:00
|
|
|
(defvar org-indent-modified-headline-flag nil
|
2013-02-23 12:47:44 +00:00
|
|
|
"Non-nil means the last deletion operated on a headline.
|
2011-07-23 12:25:27 +00:00
|
|
|
It is modified by `org-indent-notify-modified-headline'.")
|
2011-02-27 14:52:36 +00:00
|
|
|
|
2009-06-30 05:24:57 +00:00
|
|
|
|
2015-08-20 11:58:00 +00:00
|
|
|
(defcustom org-indent-boundary-char ?\s
|
2009-06-30 05:24:57 +00:00
|
|
|
"The end of the virtual indentation strings, a single-character string.
|
|
|
|
The default is just a space, but if you wish, you can use \"|\" or so.
|
|
|
|
This can be useful on a terminal window - under a windowing system,
|
2015-08-20 11:58:00 +00:00
|
|
|
it may be prettier to customize the `org-indent' face."
|
2009-06-30 05:24:57 +00:00
|
|
|
:group 'org-indent
|
|
|
|
:type 'character)
|
|
|
|
|
|
|
|
(defcustom org-indent-mode-turns-off-org-adapt-indentation t
|
2010-07-16 21:22:01 +00:00
|
|
|
"Non-nil means setting the variable `org-indent-mode' will \
|
|
|
|
turn off indentation adaptation.
|
2009-06-30 05:24:57 +00:00
|
|
|
For details see the variable `org-adapt-indentation'."
|
|
|
|
:group 'org-indent
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defcustom org-indent-mode-turns-on-hiding-stars t
|
2010-07-16 21:22:01 +00:00
|
|
|
"Non-nil means setting the variable `org-indent-mode' will \
|
|
|
|
turn on `org-hide-leading-stars'."
|
2009-06-30 05:24:57 +00:00
|
|
|
:group 'org-indent
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defcustom org-indent-indentation-per-level 2
|
|
|
|
"Indentation per level in number of characters."
|
|
|
|
:group 'org-indent
|
|
|
|
:type 'integer)
|
|
|
|
|
2015-08-20 11:58:00 +00:00
|
|
|
(defface org-indent '((t (:inherit org-hide)))
|
2011-08-18 13:44:46 +00:00
|
|
|
"Face for outline indentation.
|
|
|
|
The default is to make it look like whitespace. But you may find it
|
|
|
|
useful to make it ever so slightly different."
|
|
|
|
:group 'org-faces)
|
|
|
|
|
2017-06-19 10:24:16 +00:00
|
|
|
(defvar org-indent--text-line-prefixes nil
|
|
|
|
"Vector containing line prefixes strings for regular text.")
|
|
|
|
|
|
|
|
(defvar org-indent--heading-line-prefixes nil
|
|
|
|
"Vector containing line prefix strings for headlines.")
|
|
|
|
|
|
|
|
(defvar org-indent--inlinetask-line-prefixes nil
|
|
|
|
"Vector containing line prefix strings for inline tasks.")
|
|
|
|
|
|
|
|
(defconst org-indent--deepest-level 50
|
|
|
|
"Maximum theoretical headline depth.")
|
|
|
|
|
|
|
|
(defun org-indent--compute-prefixes ()
|
|
|
|
"Compute prefix strings for regular text and headlines."
|
|
|
|
(setq org-indent--heading-line-prefixes
|
|
|
|
(make-vector org-indent--deepest-level nil))
|
|
|
|
(setq org-indent--inlinetask-line-prefixes
|
|
|
|
(make-vector org-indent--deepest-level nil))
|
|
|
|
(setq org-indent--text-line-prefixes
|
|
|
|
(make-vector org-indent--deepest-level nil))
|
|
|
|
(dotimes (n org-indent--deepest-level)
|
|
|
|
(let ((indentation (if (<= n 1) 0
|
|
|
|
(* (1- org-indent-indentation-per-level)
|
|
|
|
(1- n)))))
|
|
|
|
;; Headlines line prefixes.
|
|
|
|
(let ((heading-prefix (make-string indentation ?*)))
|
|
|
|
(aset org-indent--heading-line-prefixes
|
|
|
|
n
|
|
|
|
(org-add-props heading-prefix nil 'face 'org-indent))
|
|
|
|
;; Inline tasks line prefixes
|
|
|
|
(aset org-indent--inlinetask-line-prefixes
|
|
|
|
n
|
2017-06-23 11:52:16 +00:00
|
|
|
(cond ((<= n 1) "")
|
|
|
|
((bound-and-true-p org-inlinetask-show-first-star)
|
|
|
|
(concat org-indent-inlinetask-first-star
|
|
|
|
(substring heading-prefix 1)))
|
|
|
|
(t (org-add-props heading-prefix nil 'face 'org-indent)))))
|
2017-06-19 10:24:16 +00:00
|
|
|
;; Text line prefixes.
|
|
|
|
(aset org-indent--text-line-prefixes
|
|
|
|
n
|
|
|
|
(concat (org-add-props (make-string (+ n indentation) ?\s)
|
|
|
|
nil 'face 'org-indent)
|
|
|
|
(and (> n 0)
|
|
|
|
(char-to-string org-indent-boundary-char)))))))
|
|
|
|
|
2011-08-18 13:44:46 +00:00
|
|
|
(defsubst org-indent-remove-properties (beg end)
|
|
|
|
"Remove indentations between BEG and END."
|
2013-02-25 10:44:27 +00:00
|
|
|
(org-with-silent-modifications
|
|
|
|
(remove-text-properties beg end '(line-prefix nil wrap-prefix nil))))
|
2011-08-18 13:44:46 +00:00
|
|
|
|
2009-06-30 05:24:57 +00:00
|
|
|
;;;###autoload
|
|
|
|
(define-minor-mode org-indent-mode
|
|
|
|
"When active, indent text according to outline structure.
|
|
|
|
|
2011-02-20 12:44:00 +00:00
|
|
|
Internally this works by adding `line-prefix' and `wrap-prefix'
|
2011-07-24 13:33:48 +00:00
|
|
|
properties, after each buffer modification, on the modified zone.
|
|
|
|
|
|
|
|
The process is synchronous. Though, initial indentation of
|
|
|
|
buffer, which can take a few seconds on large buffers, is done
|
2013-01-30 10:18:24 +00:00
|
|
|
during idle time."
|
|
|
|
nil " Ind" nil
|
|
|
|
(cond
|
|
|
|
(org-indent-mode
|
|
|
|
;; mode was turned on.
|
2015-11-05 16:47:38 +00:00
|
|
|
(setq-local indent-tabs-mode nil)
|
2015-12-05 10:55:02 +00:00
|
|
|
(setq-local org-indent--initial-marker (copy-marker 1))
|
2013-01-30 10:18:24 +00:00
|
|
|
(when org-indent-mode-turns-off-org-adapt-indentation
|
2015-11-05 16:47:38 +00:00
|
|
|
(setq-local org-adapt-indentation nil))
|
2013-01-30 10:18:24 +00:00
|
|
|
(when org-indent-mode-turns-on-hiding-stars
|
2015-11-05 16:47:38 +00:00
|
|
|
(setq-local org-hide-leading-stars-before-indent-mode
|
|
|
|
org-hide-leading-stars)
|
|
|
|
(setq-local org-hide-leading-stars t))
|
2017-06-19 10:24:16 +00:00
|
|
|
(org-indent--compute-prefixes)
|
Remove final parts of XEmacs compatibility code
* lisp/org-compat.el: Declare `org-add-hook', `org-decompose-region',
`org-detach-overlay', `org-file-equal-p', `org-float-time',
`org-indent-line-to', `org-indent-to-column', `org-looking-at-p',
`org-looking-back', `org-propertize', `org-re' and
`org-select-frame-set-input-focus' as obsolete.
(org-overlay-display, org-overlay-before-string, org-find-overlays):
Move to "org.el"
(org-xemacs-key-equivalents, org-xemacs-p): Remove variables.
(org-region-active-p): Drop XEmacs support.
(org-xemacs-without-invisibility): Remove macro.
(org-get-x-clipboard-compat): Remove function.
* lisp/org-macs.el (org-match-string-no-properties): Remove function.
* lisp/ob-core.el:
* lisp/org-agenda.el:
* lisp/org-archive.el:
* lisp/org-clock.el:
* lisp/org-colview.el:
* lisp/org-crypt.el:
* lisp/org-element.el:
* lisp/org-faces.el:
* lisp/org-feed.el:
* lisp/org-footnote.el:
* lisp/org-habit.el:
* lisp/org-id.el:
* lisp/org-indent.el:
* lisp/org-inlinetask.el:
* lisp/org-lint.el:
* lisp/org-list.el:
* lisp/org-mouse.el:
* lisp/org-pcomplete.el:
* lisp/org-src.el:
* lisp/org-table.el:
* lisp/org-timer.el:
* lisp/org.el:
* lisp/ox-ascii.el:
* lisp/ox-odt.el:
* lisp/ox.el:
* contrib/lisp/org-notify.el:
* contrib/lisp/ox-taskjuggler.el:
* contrib/lisp/org-wikinodes.el:
* testing/lisp/test-org-src.el:
* testing/lisp/test-org.el: Silence byte-compiler.
2016-05-26 10:18:00 +00:00
|
|
|
(add-hook 'filter-buffer-substring-functions
|
2017-06-19 10:24:16 +00:00
|
|
|
(lambda (fun start end delete)
|
|
|
|
(org-indent-remove-properties-from-string
|
|
|
|
(funcall fun start end delete)))
|
|
|
|
nil t)
|
Remove final parts of XEmacs compatibility code
* lisp/org-compat.el: Declare `org-add-hook', `org-decompose-region',
`org-detach-overlay', `org-file-equal-p', `org-float-time',
`org-indent-line-to', `org-indent-to-column', `org-looking-at-p',
`org-looking-back', `org-propertize', `org-re' and
`org-select-frame-set-input-focus' as obsolete.
(org-overlay-display, org-overlay-before-string, org-find-overlays):
Move to "org.el"
(org-xemacs-key-equivalents, org-xemacs-p): Remove variables.
(org-region-active-p): Drop XEmacs support.
(org-xemacs-without-invisibility): Remove macro.
(org-get-x-clipboard-compat): Remove function.
* lisp/org-macs.el (org-match-string-no-properties): Remove function.
* lisp/ob-core.el:
* lisp/org-agenda.el:
* lisp/org-archive.el:
* lisp/org-clock.el:
* lisp/org-colview.el:
* lisp/org-crypt.el:
* lisp/org-element.el:
* lisp/org-faces.el:
* lisp/org-feed.el:
* lisp/org-footnote.el:
* lisp/org-habit.el:
* lisp/org-id.el:
* lisp/org-indent.el:
* lisp/org-inlinetask.el:
* lisp/org-lint.el:
* lisp/org-list.el:
* lisp/org-mouse.el:
* lisp/org-pcomplete.el:
* lisp/org-src.el:
* lisp/org-table.el:
* lisp/org-timer.el:
* lisp/org.el:
* lisp/ox-ascii.el:
* lisp/ox-odt.el:
* lisp/ox.el:
* contrib/lisp/org-notify.el:
* contrib/lisp/ox-taskjuggler.el:
* contrib/lisp/org-wikinodes.el:
* testing/lisp/test-org-src.el:
* testing/lisp/test-org.el: Silence byte-compiler.
2016-05-26 10:18:00 +00:00
|
|
|
(add-hook 'after-change-functions 'org-indent-refresh-maybe nil 'local)
|
|
|
|
(add-hook 'before-change-functions
|
2017-06-19 10:24:16 +00:00
|
|
|
'org-indent-notify-modified-headline nil 'local)
|
2013-01-30 10:18:24 +00:00
|
|
|
(and font-lock-mode (org-restart-font-lock))
|
|
|
|
(org-indent-remove-properties (point-min) (point-max))
|
|
|
|
;; Submit current buffer to initialize agent. If it's the first
|
|
|
|
;; buffer submitted, also start the agent. Current buffer is
|
|
|
|
;; pushed in both cases to avoid a race condition.
|
|
|
|
(if org-indent-agentized-buffers
|
|
|
|
(push (current-buffer) org-indent-agentized-buffers)
|
org-indent: changes to the internals of initialization
* lisp/org-indent.el (org-indent-agent-timer,
org-indent-agentized-buffers, org-indent-agent-resume-timer,
org-indent-agent-process-duration, org-indent-agent-resume-delay):
new variables.
(org-indent-initial-marker): more accurate doc-string.
(org-indent-initial-timer, org-indent-initial-resume-timer,
org-indent-initial-process-duration, org-indent-initial-resume-delay,
org-indent-initial-lock): removed variables.
(org-indent-mode): set up an agent to watch current buffer, or add it
to the list of already watched buffers.
(org-indent-initialize-agent): new function.
(org-indent-initialize-buffer): now requires a mandatory buffer
argument.
(org-indent-add-properties): reflect changes to variables. The resume
timer is now global.
This change was introduced because a buffer killed while initializing
couldn't cancel its own initialization timer. Now, a global agent
watches for buffers, starting or resuming their initialization when
appropriate. It can cancel its own timer, thus killing itself, when no
more buffers are being watched.
2011-08-18 21:13:00 +00:00
|
|
|
(push (current-buffer) org-indent-agentized-buffers)
|
2013-01-30 10:18:24 +00:00
|
|
|
(setq org-indent-agent-timer
|
|
|
|
(run-with-idle-timer 0.2 t #'org-indent-initialize-agent))))
|
|
|
|
(t
|
|
|
|
;; mode was turned off (or we refused to turn it on)
|
|
|
|
(kill-local-variable 'org-adapt-indentation)
|
|
|
|
(setq org-indent-agentized-buffers
|
|
|
|
(delq (current-buffer) org-indent-agentized-buffers))
|
2015-12-05 10:55:02 +00:00
|
|
|
(when (markerp org-indent--initial-marker)
|
|
|
|
(set-marker org-indent--initial-marker nil))
|
2013-01-30 10:18:24 +00:00
|
|
|
(when (boundp 'org-hide-leading-stars-before-indent-mode)
|
2015-11-05 16:47:38 +00:00
|
|
|
(setq-local org-hide-leading-stars
|
|
|
|
org-hide-leading-stars-before-indent-mode))
|
2013-01-30 10:18:24 +00:00
|
|
|
(remove-hook 'filter-buffer-substring-functions
|
|
|
|
(lambda (fun start end delete)
|
|
|
|
(org-indent-remove-properties-from-string
|
|
|
|
(funcall fun start end delete))))
|
|
|
|
(remove-hook 'after-change-functions 'org-indent-refresh-maybe 'local)
|
|
|
|
(remove-hook 'before-change-functions
|
|
|
|
'org-indent-notify-modified-headline 'local)
|
|
|
|
(org-with-wide-buffer
|
|
|
|
(org-indent-remove-properties (point-min) (point-max)))
|
|
|
|
(and font-lock-mode (org-restart-font-lock))
|
|
|
|
(redraw-display))))
|
2009-06-30 05:24:57 +00:00
|
|
|
|
|
|
|
(defun org-indent-indent-buffer ()
|
2011-07-25 10:43:38 +00:00
|
|
|
"Add indentation properties to the accessible part of the buffer."
|
2009-06-30 05:24:57 +00:00
|
|
|
(interactive)
|
Use (derived-mode-p 'org-mode) instead of (eq major-mode 'org-mode).
* org.el (org-show-hierarchy-above, org-cycle)
(org-global-cycle, org-files-list, org-store-link)
(org-link-search, org-open-file, org-display-outline-path)
(org-refile-get-location, org-update-all-dblocks)
(org-change-tag-in-region, org-entry-properties)
(org-save-all-org-buffers, org-revert-all-org-buffers)
(org-buffer-list, org-cdlatex-mode)
(org-install-agenda-files-menu, org-end-of-subtree)
(org-speedbar-set-agenda-restriction): Use (derived-mode-p
'org-mode) instead of (eq major-mode 'org-mode).
* org-timer.el (org-timer-set-timer): Ditto.
* org-table.el (orgtbl-mode, org-table-align, orgtbl-mode): Ditto.
* org-src.el (org-edit-src-exit, org-edit-src-code)
(org-edit-fixed-width-region, org-edit-src-exit): Ditto.
* org-remember.el (org-remember-handler): Ditto.
* org-mouse.el (dnd-open-file, org-mouse-insert-item): Ditto.
* org-macs.el (org-get-limited-outline-regexp): Ditto.
* org-lparse.el (org-replace-region-by): Ditto.
* org-latex.el (org-latex-to-pdf-process)
(org-replace-region-by-latex): Ditto.
* org-indent.el (org-indent-indent-buffer): Ditto.
* org-id.el (org-id-store-link, org-id-update-id-locations)
(org-id-store-link): Ditto.
* org-html.el (org-export-html-preprocess)
(org-replace-region-by-html): Ditto.
* org-footnote.el (org-footnote-normalize)
(org-footnote-goto-definition)
(org-footnote-create-definition, org-footnote-normalize): Ditto.
* org-docbook.el (org-replace-region-by-docbook): Ditto.
* org-ctags.el (find-tag): Ditto.
* org-colview.el (org-columns-redo)
(org-columns-display-here, org-columns-edit-value)
(org-columns-redo): Ditto.
* org-colview-xemacs.el (org-columns-redo)
(org-columns-display-here, org-columns-edit-value)
(org-columns-redo): Ditto.
* org-capture.el (org-capture-insert-template-here)
(org-capture, org-capture-finalize)
(org-capture-set-target-location)
(org-capture-insert-template-here): Ditto.
* org-ascii.el (org-replace-region-by-ascii): Ditto.
* org-archive.el (org-archive-subtree): Ditto.
* org-agenda.el (org-agenda)
(org-agenda-get-restriction-and-command)
(org-agenda-get-some-entry-text, org-search-view)
(org-tags-view, org-agenda-get-day-entries)
(org-agenda-format-item, org-agenda-goto, org-agenda-kill)
(org-agenda-archive-with, org-agenda-switch-to): Ditto.
2012-04-20 18:03:45 +00:00
|
|
|
(if (not (derived-mode-p 'org-mode))
|
2011-07-25 10:43:38 +00:00
|
|
|
(error "Not in Org mode")
|
2012-08-11 17:10:44 +00:00
|
|
|
(message "Setting buffer indentation. It may take a few seconds...")
|
2011-07-25 10:43:38 +00:00
|
|
|
(org-indent-remove-properties (point-min) (point-max))
|
|
|
|
(org-indent-add-properties (point-min) (point-max))
|
2011-07-21 14:14:58 +00:00
|
|
|
(message "Indentation of buffer set.")))
|
2009-06-30 05:24:57 +00:00
|
|
|
|
|
|
|
(defun org-indent-remove-properties-from-string (string)
|
2011-07-06 18:49:55 +00:00
|
|
|
"Remove indentation properties from STRING."
|
2009-06-30 05:24:57 +00:00
|
|
|
(remove-text-properties 0 (length string)
|
|
|
|
'(line-prefix nil wrap-prefix nil) string)
|
|
|
|
string)
|
|
|
|
|
org-indent: changes to the internals of initialization
* lisp/org-indent.el (org-indent-agent-timer,
org-indent-agentized-buffers, org-indent-agent-resume-timer,
org-indent-agent-process-duration, org-indent-agent-resume-delay):
new variables.
(org-indent-initial-marker): more accurate doc-string.
(org-indent-initial-timer, org-indent-initial-resume-timer,
org-indent-initial-process-duration, org-indent-initial-resume-delay,
org-indent-initial-lock): removed variables.
(org-indent-mode): set up an agent to watch current buffer, or add it
to the list of already watched buffers.
(org-indent-initialize-agent): new function.
(org-indent-initialize-buffer): now requires a mandatory buffer
argument.
(org-indent-add-properties): reflect changes to variables. The resume
timer is now global.
This change was introduced because a buffer killed while initializing
couldn't cancel its own initialization timer. Now, a global agent
watches for buffers, starting or resuming their initialization when
appropriate. It can cancel its own timer, thus killing itself, when no
more buffers are being watched.
2011-08-18 21:13:00 +00:00
|
|
|
(defun org-indent-initialize-agent ()
|
|
|
|
"Start or resume current buffer initialization.
|
|
|
|
Only buffers in `org-indent-agentized-buffers' trigger an action.
|
|
|
|
When no more buffer is being watched, the agent suppress itself."
|
|
|
|
(when org-indent-agent-resume-timer
|
|
|
|
(cancel-timer org-indent-agent-resume-timer))
|
2011-08-21 13:01:04 +00:00
|
|
|
(setq org-indent-agentized-buffers
|
2015-11-06 12:04:20 +00:00
|
|
|
(cl-remove-if-not #'buffer-live-p org-indent-agentized-buffers))
|
2011-08-21 13:01:04 +00:00
|
|
|
(cond
|
|
|
|
;; Job done: kill agent.
|
|
|
|
((not org-indent-agentized-buffers) (cancel-timer org-indent-agent-timer))
|
|
|
|
;; Current buffer is agentized: start/resume initialization
|
|
|
|
;; somewhat aggressively.
|
|
|
|
((memq (current-buffer) org-indent-agentized-buffers)
|
|
|
|
(org-indent-initialize-buffer (current-buffer)
|
|
|
|
org-indent-agent-active-delay))
|
|
|
|
;; Else, start/resume initialization of the last agentized buffer,
|
|
|
|
;; softly.
|
|
|
|
(t (org-indent-initialize-buffer (car org-indent-agentized-buffers)
|
|
|
|
org-indent-agent-passive-delay))))
|
org-indent: changes to the internals of initialization
* lisp/org-indent.el (org-indent-agent-timer,
org-indent-agentized-buffers, org-indent-agent-resume-timer,
org-indent-agent-process-duration, org-indent-agent-resume-delay):
new variables.
(org-indent-initial-marker): more accurate doc-string.
(org-indent-initial-timer, org-indent-initial-resume-timer,
org-indent-initial-process-duration, org-indent-initial-resume-delay,
org-indent-initial-lock): removed variables.
(org-indent-mode): set up an agent to watch current buffer, or add it
to the list of already watched buffers.
(org-indent-initialize-agent): new function.
(org-indent-initialize-buffer): now requires a mandatory buffer
argument.
(org-indent-add-properties): reflect changes to variables. The resume
timer is now global.
This change was introduced because a buffer killed while initializing
couldn't cancel its own initialization timer. Now, a global agent
watches for buffers, starting or resuming their initialization when
appropriate. It can cancel its own timer, thus killing itself, when no
more buffers are being watched.
2011-08-18 21:13:00 +00:00
|
|
|
|
2011-08-21 13:01:04 +00:00
|
|
|
(defun org-indent-initialize-buffer (buffer delay)
|
|
|
|
"Set virtual indentation for the buffer BUFFER, asynchronously.
|
|
|
|
Give hand to other idle processes if it takes longer than DELAY,
|
|
|
|
a time value."
|
org-indent: changes to the internals of initialization
* lisp/org-indent.el (org-indent-agent-timer,
org-indent-agentized-buffers, org-indent-agent-resume-timer,
org-indent-agent-process-duration, org-indent-agent-resume-delay):
new variables.
(org-indent-initial-marker): more accurate doc-string.
(org-indent-initial-timer, org-indent-initial-resume-timer,
org-indent-initial-process-duration, org-indent-initial-resume-delay,
org-indent-initial-lock): removed variables.
(org-indent-mode): set up an agent to watch current buffer, or add it
to the list of already watched buffers.
(org-indent-initialize-agent): new function.
(org-indent-initialize-buffer): now requires a mandatory buffer
argument.
(org-indent-add-properties): reflect changes to variables. The resume
timer is now global.
This change was introduced because a buffer killed while initializing
couldn't cancel its own initialization timer. Now, a global agent
watches for buffers, starting or resuming their initialization when
appropriate. It can cancel its own timer, thus killing itself, when no
more buffers are being watched.
2011-08-18 21:13:00 +00:00
|
|
|
(with-current-buffer buffer
|
|
|
|
(when org-indent-mode
|
|
|
|
(org-with-wide-buffer
|
|
|
|
(let ((interruptp
|
|
|
|
;; Always nil unless interrupted.
|
|
|
|
(catch 'interrupt
|
2015-12-05 10:55:02 +00:00
|
|
|
(and org-indent--initial-marker
|
|
|
|
(marker-position org-indent--initial-marker)
|
2016-04-20 15:20:46 +00:00
|
|
|
(equal (marker-buffer org-indent--initial-marker)
|
|
|
|
buffer)
|
2015-12-05 10:55:02 +00:00
|
|
|
(org-indent-add-properties org-indent--initial-marker
|
2011-08-21 13:01:04 +00:00
|
|
|
(point-max)
|
|
|
|
delay)
|
org-indent: changes to the internals of initialization
* lisp/org-indent.el (org-indent-agent-timer,
org-indent-agentized-buffers, org-indent-agent-resume-timer,
org-indent-agent-process-duration, org-indent-agent-resume-delay):
new variables.
(org-indent-initial-marker): more accurate doc-string.
(org-indent-initial-timer, org-indent-initial-resume-timer,
org-indent-initial-process-duration, org-indent-initial-resume-delay,
org-indent-initial-lock): removed variables.
(org-indent-mode): set up an agent to watch current buffer, or add it
to the list of already watched buffers.
(org-indent-initialize-agent): new function.
(org-indent-initialize-buffer): now requires a mandatory buffer
argument.
(org-indent-add-properties): reflect changes to variables. The resume
timer is now global.
This change was introduced because a buffer killed while initializing
couldn't cancel its own initialization timer. Now, a global agent
watches for buffers, starting or resuming their initialization when
appropriate. It can cancel its own timer, thus killing itself, when no
more buffers are being watched.
2011-08-18 21:13:00 +00:00
|
|
|
nil))))
|
2015-12-05 10:55:02 +00:00
|
|
|
(move-marker org-indent--initial-marker interruptp)
|
org-indent: changes to the internals of initialization
* lisp/org-indent.el (org-indent-agent-timer,
org-indent-agentized-buffers, org-indent-agent-resume-timer,
org-indent-agent-process-duration, org-indent-agent-resume-delay):
new variables.
(org-indent-initial-marker): more accurate doc-string.
(org-indent-initial-timer, org-indent-initial-resume-timer,
org-indent-initial-process-duration, org-indent-initial-resume-delay,
org-indent-initial-lock): removed variables.
(org-indent-mode): set up an agent to watch current buffer, or add it
to the list of already watched buffers.
(org-indent-initialize-agent): new function.
(org-indent-initialize-buffer): now requires a mandatory buffer
argument.
(org-indent-add-properties): reflect changes to variables. The resume
timer is now global.
This change was introduced because a buffer killed while initializing
couldn't cancel its own initialization timer. Now, a global agent
watches for buffers, starting or resuming their initialization when
appropriate. It can cancel its own timer, thus killing itself, when no
more buffers are being watched.
2011-08-18 21:13:00 +00:00
|
|
|
;; Job is complete: un-agentize buffer.
|
|
|
|
(unless interruptp
|
|
|
|
(setq org-indent-agentized-buffers
|
|
|
|
(delq buffer org-indent-agentized-buffers))))))))
|
2011-07-21 14:20:26 +00:00
|
|
|
|
2015-08-20 11:58:00 +00:00
|
|
|
(defun org-indent-set-line-properties (level indentation &optional heading)
|
2011-07-27 13:48:16 +00:00
|
|
|
"Set prefix properties on current line an move to next one.
|
|
|
|
|
2015-08-20 11:58:00 +00:00
|
|
|
LEVEL is the current level of heading. INDENTATION is the
|
|
|
|
expected indentation when wrapping line.
|
|
|
|
|
|
|
|
When optional argument HEADING is non-nil, assume line is at
|
|
|
|
a heading. Moreover, if is is `inlinetask', the first star will
|
|
|
|
have `org-warning' face."
|
2017-06-19 10:24:16 +00:00
|
|
|
(let* ((line (aref (pcase heading
|
|
|
|
(`nil org-indent--text-line-prefixes)
|
|
|
|
(`inlinetask org-indent--inlinetask-line-prefixes)
|
|
|
|
(_ org-indent--heading-line-prefixes))
|
|
|
|
level))
|
2015-08-20 11:58:00 +00:00
|
|
|
(wrap
|
|
|
|
(org-add-props
|
2017-06-19 10:24:16 +00:00
|
|
|
(concat line
|
2017-06-20 07:53:26 +00:00
|
|
|
(if heading (concat (make-string level ?*) " ")
|
|
|
|
(make-string indentation ?\s)))
|
2015-08-20 11:58:00 +00:00
|
|
|
nil 'face 'org-indent)))
|
2011-07-28 18:47:45 +00:00
|
|
|
;; Add properties down to the next line to indent empty lines.
|
2015-08-20 11:58:00 +00:00
|
|
|
(add-text-properties (line-beginning-position) (line-beginning-position 2)
|
2011-07-27 13:48:16 +00:00
|
|
|
`(line-prefix ,line wrap-prefix ,wrap)))
|
2015-08-20 11:58:00 +00:00
|
|
|
(forward-line))
|
2011-07-27 13:48:16 +00:00
|
|
|
|
2011-08-21 13:01:04 +00:00
|
|
|
(defun org-indent-add-properties (beg end &optional delay)
|
2011-07-21 14:20:26 +00:00
|
|
|
"Add indentation properties between BEG and END.
|
|
|
|
|
2011-08-21 13:01:04 +00:00
|
|
|
When DELAY is non-nil, it must be a time value. In that case,
|
|
|
|
the process is asynchronous and can be interrupted, either by
|
|
|
|
user request, or after DELAY. This is done by throwing the
|
|
|
|
`interrupt' tag along with the buffer position where the process
|
|
|
|
stopped."
|
2011-07-21 14:20:26 +00:00
|
|
|
(save-match-data
|
|
|
|
(org-with-wide-buffer
|
|
|
|
(goto-char beg)
|
|
|
|
(beginning-of-line)
|
2015-08-21 12:44:26 +00:00
|
|
|
;; Initialize prefix at BEG, according to current entry's level.
|
2011-07-21 14:20:26 +00:00
|
|
|
(let* ((case-fold-search t)
|
|
|
|
(limited-re (org-get-limited-outline-regexp))
|
2015-08-21 12:44:26 +00:00
|
|
|
(level (or (org-current-level) 0))
|
2011-08-21 13:01:04 +00:00
|
|
|
(time-limit (and delay (time-add (current-time) delay))))
|
2015-08-21 12:44:26 +00:00
|
|
|
;; For each line, set `line-prefix' and `wrap-prefix'
|
|
|
|
;; properties depending on the type of line (headline, inline
|
|
|
|
;; task, item or other).
|
2013-02-25 10:44:27 +00:00
|
|
|
(org-with-silent-modifications
|
|
|
|
(while (and (<= (point) end) (not (eobp)))
|
|
|
|
(cond
|
|
|
|
;; When in asynchronous mode, check if interrupt is
|
|
|
|
;; required.
|
|
|
|
((and delay (input-pending-p)) (throw 'interrupt (point)))
|
|
|
|
;; In asynchronous mode, take a break of
|
|
|
|
;; `org-indent-agent-resume-delay' every DELAY to avoid
|
|
|
|
;; blocking any other idle timer or process output.
|
|
|
|
((and delay (time-less-p time-limit (current-time)))
|
|
|
|
(setq org-indent-agent-resume-timer
|
|
|
|
(run-with-idle-timer
|
2015-08-20 11:58:00 +00:00
|
|
|
(time-add (current-idle-time) org-indent-agent-resume-delay)
|
2013-02-25 10:44:27 +00:00
|
|
|
nil #'org-indent-initialize-agent))
|
|
|
|
(throw 'interrupt (point)))
|
|
|
|
;; Headline or inline task.
|
|
|
|
((looking-at org-outline-regexp)
|
2015-08-21 12:44:26 +00:00
|
|
|
(let* ((nstars (- (match-end 0) (match-beginning 0) 1))
|
Remove final parts of XEmacs compatibility code
* lisp/org-compat.el: Declare `org-add-hook', `org-decompose-region',
`org-detach-overlay', `org-file-equal-p', `org-float-time',
`org-indent-line-to', `org-indent-to-column', `org-looking-at-p',
`org-looking-back', `org-propertize', `org-re' and
`org-select-frame-set-input-focus' as obsolete.
(org-overlay-display, org-overlay-before-string, org-find-overlays):
Move to "org.el"
(org-xemacs-key-equivalents, org-xemacs-p): Remove variables.
(org-region-active-p): Drop XEmacs support.
(org-xemacs-without-invisibility): Remove macro.
(org-get-x-clipboard-compat): Remove function.
* lisp/org-macs.el (org-match-string-no-properties): Remove function.
* lisp/ob-core.el:
* lisp/org-agenda.el:
* lisp/org-archive.el:
* lisp/org-clock.el:
* lisp/org-colview.el:
* lisp/org-crypt.el:
* lisp/org-element.el:
* lisp/org-faces.el:
* lisp/org-feed.el:
* lisp/org-footnote.el:
* lisp/org-habit.el:
* lisp/org-id.el:
* lisp/org-indent.el:
* lisp/org-inlinetask.el:
* lisp/org-lint.el:
* lisp/org-list.el:
* lisp/org-mouse.el:
* lisp/org-pcomplete.el:
* lisp/org-src.el:
* lisp/org-table.el:
* lisp/org-timer.el:
* lisp/org.el:
* lisp/ox-ascii.el:
* lisp/ox-odt.el:
* lisp/ox.el:
* contrib/lisp/org-notify.el:
* contrib/lisp/ox-taskjuggler.el:
* contrib/lisp/org-wikinodes.el:
* testing/lisp/test-org-src.el:
* testing/lisp/test-org.el: Silence byte-compiler.
2016-05-26 10:18:00 +00:00
|
|
|
(type (or (looking-at-p limited-re) 'inlinetask)))
|
2015-08-21 12:44:26 +00:00
|
|
|
(org-indent-set-line-properties nstars 0 type)
|
|
|
|
;; At an headline, define new value for LEVEL.
|
|
|
|
(unless (eq type 'inlinetask) (setq level nstars))))
|
2013-02-25 10:44:27 +00:00
|
|
|
;; List item: `wrap-prefix' is set where body starts.
|
|
|
|
((org-at-item-p)
|
2015-08-21 12:44:26 +00:00
|
|
|
(org-indent-set-line-properties
|
|
|
|
level (org-list-item-body-column (point))))
|
|
|
|
;; Regular line.
|
|
|
|
(t
|
|
|
|
(org-indent-set-line-properties level (org-get-indentation))))))))))
|
2009-06-30 05:24:57 +00:00
|
|
|
|
2011-07-23 12:25:27 +00:00
|
|
|
(defun org-indent-notify-modified-headline (beg end)
|
2011-07-24 13:33:48 +00:00
|
|
|
"Set `org-indent-modified-headline-flag' depending on context.
|
2009-06-30 05:24:57 +00:00
|
|
|
|
2011-02-27 14:52:36 +00:00
|
|
|
BEG and END are the positions of the beginning and end of the
|
|
|
|
range of deleted text.
|
2009-06-30 05:24:57 +00:00
|
|
|
|
2011-02-27 14:52:36 +00:00
|
|
|
This function is meant to be called by `before-change-functions'.
|
2011-07-21 14:20:26 +00:00
|
|
|
Flag will be non-nil if command is going to modify or delete an
|
|
|
|
headline."
|
|
|
|
(when org-indent-mode
|
|
|
|
(setq org-indent-modified-headline-flag
|
2016-01-02 13:10:49 +00:00
|
|
|
(org-with-wide-buffer
|
|
|
|
(goto-char beg)
|
|
|
|
(save-match-data
|
|
|
|
(or (and (org-at-heading-p) (< beg (match-end 0)))
|
|
|
|
(re-search-forward
|
|
|
|
(org-with-limited-levels org-outline-regexp-bol) end t)))))))
|
2011-02-27 14:52:36 +00:00
|
|
|
|
2015-10-26 00:56:00 +00:00
|
|
|
(defun org-indent-refresh-maybe (beg end _)
|
2011-02-27 14:52:36 +00:00
|
|
|
"Refresh indentation properties in an adequate portion of buffer.
|
|
|
|
BEG and END are the positions of the beginning and end of the
|
|
|
|
range of inserted text. DUMMY is an unused argument.
|
|
|
|
|
|
|
|
This function is meant to be called by `after-change-functions'."
|
2009-06-30 05:24:57 +00:00
|
|
|
(when org-indent-mode
|
2011-02-27 14:52:36 +00:00
|
|
|
(save-match-data
|
2013-02-23 12:47:44 +00:00
|
|
|
;; If a headline was modified or inserted, set properties until
|
2011-07-23 12:25:27 +00:00
|
|
|
;; next headline.
|
2016-01-02 13:10:49 +00:00
|
|
|
(org-with-wide-buffer
|
|
|
|
(if (or org-indent-modified-headline-flag
|
|
|
|
(save-excursion
|
|
|
|
(goto-char beg)
|
|
|
|
(beginning-of-line)
|
|
|
|
(re-search-forward
|
|
|
|
(org-with-limited-levels org-outline-regexp-bol) end t)))
|
|
|
|
(let ((end (save-excursion
|
|
|
|
(goto-char end)
|
|
|
|
(org-with-limited-levels (outline-next-heading))
|
|
|
|
(point))))
|
|
|
|
(setq org-indent-modified-headline-flag nil)
|
|
|
|
(org-indent-add-properties beg end))
|
|
|
|
;; Otherwise, only set properties on modified area.
|
|
|
|
(org-indent-add-properties beg end))))))
|
2009-06-30 05:24:57 +00:00
|
|
|
|
|
|
|
(provide 'org-indent)
|
|
|
|
|
2012-10-02 06:50:46 +00:00
|
|
|
;; Local variables:
|
|
|
|
;; generated-autoload-file: "org-loaddefs.el"
|
|
|
|
;; End:
|
|
|
|
|
2009-06-30 05:24:57 +00:00
|
|
|
;;; org-indent.el ends here
|