-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathorg-transclusion-indent-mode.el
92 lines (74 loc) · 3.42 KB
/
org-transclusion-indent-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
;;; org-transclusion-indent-mode.el --- support org-indent-mode -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2024 Free Software Foundation, Inc.
;; This program is free software: you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by the
;; Free Software Foundation, either version 3 of the License, or (at your
;; option) any later version.
;; This program 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.
;; You should have received a copy of the GNU General Public License along
;; with this program. If not, see <http://www.gnu.org/licenses/>.
;; Author: Noboru Ota <[email protected]>
;; Created: 22 August 2021
;; Last modified: 21 January 2024
;;; Commentary:
;; This file is part of Org-transclusion
;; URL: https://github.com/nobiot/org-transclusion
;;; Code:
(require 'org-indent)
(declare-function org-transclusion-within-transclusion-p
"org-transclusion")
(add-hook 'org-transclusion-after-add-functions
#'org-translusion-indent-add-properties)
(defun org-translusion-indent-add-properties (beg end)
"BEG END."
(when org-indent-mode
(advice-add #'org-indent-set-line-properties
:override
#'org-transclusion-indent-set-line-properties-ad)
(org-indent-add-properties beg end)
(advice-remove #'org-indent-set-line-properties
#'org-transclusion-indent-set-line-properties-ad)))
(defun org-transclusion-indent-set-line-properties-ad (level indentation &optional heading)
"Set prefix properties on current line an move to next one.
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 it is `inlinetask', the first star will
have `org-warning' face."
(let* ((line (aref (pcase heading
(`nil org-indent--text-line-prefixes)
(`inlinetask org-indent--inlinetask-line-prefixes)
(_ org-indent--heading-line-prefixes))
level))
(wrap
(org-add-props
(concat line
(if heading (concat (make-string level ?*) " ")
(make-string indentation ?\s)))
nil 'face 'org-indent)))
;; Org-transclusion's addition begin
(when (org-transclusion-within-transclusion-p)
(setq line
(concat line
(propertize
"x"
'display
'(left-fringe org-transclusion-fringe-bitmap
org-transclusion-fringe))))
(setq wrap
(concat line
(propertize
"x"
'display
'(left-fringe org-transclusion-fringe-bitmap
org-transclusion-fringe)))))
;; Org-transclusion's addition end
;; Add properties down to the next line to indent empty lines.
(add-text-properties (line-beginning-position) (line-beginning-position 2)
`(line-prefix ,line wrap-prefix ,wrap)))
(forward-line))
(provide 'org-transclusion-indent-mode)
;;; org-transclusion-indent-mode.el ends here