[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Customizable fixed indentation column
From: |
Panagiotis Vlantis |
Subject: |
Re: Customizable fixed indentation column |
Date: |
Sun, 17 May 2020 15:42:12 +0300 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 |
Hello,
On 5/14/20 4:52 PM, Nicolas Goaziou wrote:
Hello,
Panagiotis Vlantis <address@hidden> writes:
This is my first time using the mailing list so please point out if
I am going about this the wrong way.
Thank you for the patch.
You are welcome.
After searching a bit, I didn't find a way to specify a custom fixed
indentation column in org sections; the current implementation
automatically aligns content at the beginning of the line when
`org-adapt-indentation' is set to nil, which I find somewhat
restrictive (e.g., in this case, one should be careful when using
lists beginning with '*' characters).
Starting list items with "*" is a terrible idea, indeed. However, it is
unlikely to break the document because list promotion commands handle
this case.
I'm not convinced the current implementation is restrictive. OOC, do you
know any text-related mode that allows indenting contents at any column?
Also please note that if your first line is indented, all indentation
below will follow.
Maybe restrictive was a bad way to put it. Nonetheless, I find being
able to align contents at a column other than the first handy since it
is easy to visually distinguish between staff without steadily losing
usable space as the node level increases. This is especially noticeable
when one follows a fixed line width layout and somehow ends up with 7
levels deep headings (not a good practice, I know :)) I have to admit
that I am not aware of any text-related mode with this kind of feature
either, although such customization (i.e., adaptive vs fixed
indentation) is rather convenient in source code editing modes (e.g.,
`cc-mode', etc).
To that end, I modified the current implementation accordingly (and
added some tests) in order to allow one to set the desired indentation
column to something other than the 0th, where section contents will be
aligned at if adaptive indentation is disabled.
I don't know if others will find this feature useful but I'll go and
include the patch here anyway. If you find this worth merging but
should be modified somehow before that, I would be happy to do so.
Instead of creating a new variable, what about overloading
`org-adapt-indentation'? If it is a whole number, use it as indentation.
`nil' becomes an alias for 0.
WDYT?
I tried out your suggestion and overloaded `org-adapt-indentation'
instead of introducing a new variable. The corresponding patch can be
seen below. Clearly, I am in no position to tell which implementation is
better, although the latter feels a bit more complicated than the first.
What is your opinion on this?
Regards,
--
Nicolas Goaziou
Best regard,
Panagiotis Vlantis
From 7e46937d1b188f913093f0ae66914803f51441e7 Mon Sep 17 00:00:00 2001
From: Panagiotis Vlantis <address@hidden>
Date: Sun, 17 May 2020 14:36:21 +0300
Subject: [PATCH] org: Enable selection of custom indentation column
* lisp/org.el (org-adapt-indentation): Allow integer values to specify
custom indentation column.
(org--get-expected-indentation): Properly handle case when
`org-adapt-indentation' is integer.
(org-add-planning-info): Properly indent newly added planning info when
`org-adapt-indentation' is integer.
* testing/lisp/test-org.el (test-org/get-property-block,
test-org/insert-property-drawer, test-org/indent-line,
test-org/indent-region, test-org/add-planning-info, test-org/deadline,
test-org/schedule, test-org/set-property): Modify tests depending on
indentation and add more tests.
Introduce variable and modify indentation mechanism accordingly in
order to allow the user to specify a custom indentation column (other
than zero) to be used instead of adaptive indentation.
---
lisp/org.el | 47 ++++++----
testing/lisp/test-org.el | 190 ++++++++++++++++++++++++++++++++++++++-
2 files changed, 220 insertions(+), 17 deletions(-)
diff --git a/lisp/org.el b/lisp/org.el
index dcd446745..487a81617 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -1575,27 +1575,34 @@ lines to the buffer:
(defcustom org-adapt-indentation t
"Non-nil means adapt indentation to outline node level.
-When this variable is set to t, Org assumes that you write
+When this variable is non-nil, Org assumes that you write
outlines by indenting text in each node to align with the
headline (after the stars).
-When this variable is set to 'headline-data, only adapt the
-indentation of the data lines right below the headline, such as
-planning/clock lines and property/logbook drawers.
+In the special case this variable is set to 'headline-data,
+only adapt the indentation of the data lines right below the headline,
+such as planning/clock lines and property/logbook drawers.
+
+In the special case this variable is set to an integer value N,
+section contents will be indented to the N-th column instead,
+independently of the the corresponding outline node's level.
The following issues are influenced by this variable:
-- The indentation is increased by one space in a demotion
- command, and decreased by one in a promotion command. However,
+- When this variable is set to a non-nil, non-integer value,
+ the indentation is increased by one space in a demotion command,
+ and decreased by one in a promotion command. However,
in the latter case, if shifting some line in the entry body
would alter document structure (e.g., insert a new headline),
indentation is not changed at all.
- Property drawers and planning information is inserted indented
- when this variable is set. When nil, they will not be indented.
+ when this variable is non-nil. When nil, they will not be indented.
-- TAB indents a line relative to current level. The lines below
- a headline will be indented when this variable is set to t.
+- TAB indents a line relative to current level or at
+ the specified column. The lines below
+ a headline will be indented when this variable is set to
+ a non-nil value.
Note that this is all about true indentation, by adding and
removing space characters. See also \"org-indent.el\" which does
@@ -1606,8 +1613,11 @@ time in Emacs."
(const :tag "Adapt indentation for all lines" t)
(const :tag "Adapt indentation for headline data lines"
'headline-data)
- (const :tag "Do not adapt indentation at all" nil))
- :safe #'booleanp)
+ (const :tag "Do not adapt indentation at all" nil)
+ integer)
+ :safe #'(lambda (x) (or (booleanp x)
+ (eq x 'headline-data)
+ (integerp x))))
(defvaralias 'org-special-ctrl-a 'org-special-ctrl-a/e)
@@ -10642,7 +10652,9 @@ WHAT entry will also be removed."
(end-of-line)
(insert "\n")
(when org-adapt-indentation
- (indent-to-column (1+ (org-outline-level)))))
+ (indent-to-column (if (integerp org-adapt-indentation)
+ (max org-adapt-indentation 0)
+ (1+ (org-outline-level))))))
(t nil)))
(when what
;; Insert planning keyword.
@@ -18737,9 +18749,14 @@ ELEMENT."
(cl-case type
((diary-sexp footnote-definition) 0)
((headline inlinetask nil)
- (if (not org-adapt-indentation) 0
- (let ((level (org-current-level)))
- (if level (1+ level) 0))))
+ (let ((level (org-current-level)))
+ (if level
+ (if org-adapt-indentation
+ (if (integerp org-adapt-indentation)
+ (max org-adapt-indentation 0)
+ (1+ level))
+ 0)
+ 0)))
((item plain-list) (org-list-item-body-column post-affiliated))
(t
(goto-char start)
diff --git a/testing/lisp/test-org.el b/testing/lisp/test-org.el
index d22446a09..de9f9baf2 100644
--- a/testing/lisp/test-org.el
+++ b/testing/lisp/test-org.el
@@ -455,6 +455,12 @@
(let ((org-adapt-indentation nil))
(org-get-property-block nil 'force))
(buffer-string))))
+ (should
+ (equal "* H\n :PROPERTIES:\n :END:\n"
+ (org-test-with-temp-text "* H"
+ (let ((org-adapt-indentation 5))
+ (org-get-property-block nil 'force))
+ (buffer-string))))
(should
(equal ":PROPERTIES:\n:END:\n"
(org-test-with-temp-text ""
@@ -475,6 +481,12 @@
(org-test-with-temp-text ""
(let ((org-adapt-indentation nil)) (org-insert-property-drawer))
(buffer-string))))
+ (should
+ (equal ":PROPERTIES:\n:END:\n"
+ (org-test-with-temp-text ""
+ (let ((org-adapt-indentation 5))
+ (org-insert-property-drawer))
+ (buffer-string))))
;; Insert drawer in document header with existing comment and
;; keyword.
(should
@@ -506,6 +518,12 @@
(org-test-with-temp-text "* H\nParagraph<point>"
(let ((org-adapt-indentation nil)) (org-insert-property-drawer))
(buffer-string))))
+ (should
+ (equal "* H\n :PROPERTIES:\n :END:\nParagraph"
+ (org-test-with-temp-text "* H\nParagraph<point>"
+ (let ((org-adapt-indentation 5))
+ (org-insert-property-drawer))
+ (buffer-string))))
(should
(equal "* H\nDEADLINE: <2014-03-04
tue.>\n:PROPERTIES:\n:END:\nParagraph"
(org-test-with-temp-text
@@ -524,6 +542,12 @@
(org-test-with-temp-text "* H"
(let ((org-adapt-indentation nil)) (org-insert-property-drawer))
(buffer-string))))
+ (should
+ (equal "* H\n :PROPERTIES:\n :END:\n"
+ (org-test-with-temp-text "* H"
+ (let ((org-adapt-indentation 5))
+ (org-insert-property-drawer))
+ (buffer-string))))
;; Skip inlinetasks before point.
(when (featurep 'org-inlinetask)
(should
@@ -852,6 +876,12 @@
(org-test-with-temp-text "* H\n<point>A"
(let ((org-adapt-indentation nil)) (org-indent-line))
(org-get-indentation))))
+ (should
+ (= 5
+ (org-test-with-temp-text "* H\n<point>A"
+ (let ((org-adapt-indentation 5))
+ (org-indent-line))
+ (org-get-indentation))))
;; Indenting preserves point position.
(should
(org-test-with-temp-text "* H\nA<point>B"
@@ -1086,6 +1116,13 @@
(org-adapt-indentation nil))
(org-indent-region (point) (point-max)))
(buffer-string))))
+ (should
+ (equal "* H\n :PROPERTIES:\n :key: value\n :END:"
+ (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:
value\n:END:"
+ (let ((org-property-format "%-10s %s")
+ (org-adapt-indentation 2))
+ (org-indent-region (point) (point-max)))
+ (buffer-string))))
(should
(equal "* H\n:PROPERTIES:\n:key:\n:END:"
(org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
@@ -1093,6 +1130,13 @@
(org-adapt-indentation nil))
(org-indent-region (point) (point-max)))
(buffer-string))))
+ (should
+ (equal "* H\n :PROPERTIES:\n :key:\n :END:"
+ (org-test-with-temp-text "* H\n<point>:PROPERTIES:\n:key:\n:END:"
+ (let ((org-property-format "%-10s %s")
+ (org-adapt-indentation 5))
+ (org-indent-region (point) (point-max)))
+ (buffer-string))))
;; Indent plain lists.
(should
(equal "- A\n B\n - C\n\n D"
@@ -4665,6 +4709,15 @@ Text.
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)>" "" (buffer-string)
nil nil 1))))
+ ;; Create deadline when `org-adapt-indentation' is nil.
+ (should
+ (equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
+ (org-test-with-temp-text "* H\nParagraph<point>"
+ (let ((org-adapt-indentation 5))
+ (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
+ (replace-regexp-in-string
+ "\\( [.A-Za-z]+\\)>" "" (buffer-string)
+ nil nil 1))))
;; Update deadline when `org-adapt-indentation' is non-nil.
(should
(equal "* H\n DEADLINE: <2015-06-25>\nParagraph"
@@ -4689,6 +4742,19 @@ Paragraph<point>"
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)>" "" (buffer-string)
nil nil 1))))
+ ;; Update deadline when `org-adapt-indentation' is nil.
+ ;; (current mechanism respects existing indentation).
+ (should
+ (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
+ (org-test-with-temp-text "\
+* H
+DEADLINE: <2015-06-24 Wed>
+Paragraph<point>"
+ (let ((org-adapt-indentation 5))
+ (org-add-planning-info 'deadline "<2015-06-25 Thu>"))
+ (replace-regexp-in-string
+ "\\( [.A-Za-z]+\\)>" "" (buffer-string)
+ nil nil 1))))
;; Schedule when `org-adapt-indentation' is non-nil.
(should
(equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
@@ -4707,6 +4773,15 @@ Paragraph<point>"
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)>" "" (buffer-string)
nil nil 1))))
+ ;; Schedule when `org-adapt-indentation' is nil.
+ (should
+ (equal "* H\n SCHEDULED: <2015-06-25>\nParagraph"
+ (org-test-with-temp-text "* H\nParagraph<point>"
+ (let ((org-adapt-indentation 5))
+ (org-add-planning-info 'scheduled "<2015-06-25 Thu>"))
+ (replace-regexp-in-string
+ "\\( [.A-Za-z]+\\)>" "" (buffer-string)
+ nil nil 1))))
;; Add deadline when scheduled.
(should
(equal "\
@@ -4799,6 +4874,29 @@ Paragraph<point>"
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)>" "" (buffer-string)
nil nil 1))))
+ ;; Remove closed when `org-adapt-indentation' is nil.
+ (should
+ (equal "* H\nDEADLINE: <2015-06-25>\nParagraph"
+ (org-test-with-temp-text "\
+* H
+CLOSED: [2015-06-25 Thu] DEADLINE: <2015-06-25 Thu>
+Paragraph<point>"
+ (let ((org-adapt-indentation 5))
+ (org-add-planning-info nil nil 'closed))
+ (replace-regexp-in-string
+ "\\( [.A-Za-z]+\\)>" "" (buffer-string)
+ nil nil 1))))
+ (should
+ (equal "* H\nParagraph"
+ (org-test-with-temp-text "\
+* H
+ CLOSED: [2015-06-25 Thu]
+Paragraph<point>"
+ (let ((org-adapt-indentation 5))
+ (org-add-planning-info nil nil 'closed))
+ (replace-regexp-in-string
+ "\\( [.A-Za-z]+\\)>" "" (buffer-string)
+ nil nil 1))))
;; Remove closed entry and delete empty line.
(should
(equal "\
@@ -4838,6 +4936,15 @@ Paragraph<point>"
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)>" "" (buffer-string)
nil nil 1))))
+ (should
+ (equal "* H\n DEADLINE: <2012-03-29>"
+ (org-test-with-temp-text "* H"
+ (let ((org-adapt-indentation 5)
+ (org-last-inserted-timestamp nil))
+ (org-deadline nil "<2012-03-29 Tue>"))
+ (replace-regexp-in-string
+ "\\( [.A-Za-z]+\\)>" "" (buffer-string)
+ nil nil 1))))
(should
(equal "* H\nDEADLINE: <2014-03-04>"
(org-test-with-temp-text "* H\nDEADLINE: <2012-03-29>"
@@ -4857,6 +4964,15 @@ Paragraph<point>"
(org-deadline nil "+1y"))
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
+ (should
+ (equal "* H\n DEADLINE: <2015-03-04>"
+ (org-test-at-time "2014-03-04"
+ (org-test-with-temp-text "* H"
+ (let ((org-adapt-indentation 5)
+ (org-last-inserted-timestamp nil))
+ (org-deadline nil "+1y"))
+ (replace-regexp-in-string
+ "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1)))))
;; Preserve repeater.
(should
(equal "* H\nDEADLINE: <2012-03-29 +2y>"
@@ -4866,6 +4982,14 @@ Paragraph<point>"
(org-deadline nil "<2012-03-29 Tue +2y>"))
(replace-regexp-in-string
"\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
+ (should
+ (equal "* H\n DEADLINE: <2012-03-29 +2y>"
+ (org-test-with-temp-text "* H"
+ (let ((org-adapt-indentation 5)
+ (org-last-inserted-timestamp nil))
+ (org-deadline nil "<2012-03-29 Tue +2y>"))
+ (replace-regexp-in-string
+ "\\( [.A-Za-z]+\\) " "" (buffer-string) nil nil 1))))
;; Remove CLOSED keyword, if any.
(should
(equal "* H\nDEADLINE: <2012-03-29>"
@@ -4952,6 +5076,15 @@ Paragraph<point>"
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)>" "" (buffer-string)
nil nil 1))))
+ (should
+ (equal "* H\n SCHEDULED: <2012-03-29>"
+ (org-test-with-temp-text "* H"
+ (let ((org-adapt-indentation 5)
+ (org-last-inserted-timestamp nil))
+ (org-schedule nil "<2012-03-29 Tue>"))
+ (replace-regexp-in-string
+ "\\( [.A-Za-z]+\\)>" "" (buffer-string)
+ nil nil 1))))
(should
(equal "* H\nSCHEDULED: <2014-03-04>"
(org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
@@ -4961,6 +5094,15 @@ Paragraph<point>"
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)>" "" (buffer-string)
nil nil 1))))
+ (should
+ (equal "* H\nSCHEDULED: <2014-03-04>"
+ (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29>"
+ (let ((org-adapt-indentation 5)
+ (org-last-inserted-timestamp nil))
+ (org-schedule nil "<2014-03-04 Thu>"))
+ (replace-regexp-in-string
+ "\\( [.A-Za-z]+\\)>" "" (buffer-string)
+ nil nil 1))))
;; Accept delta time, e.g., "+2d".
(should
(equal "* H\nSCHEDULED: <2015-03-04>"
@@ -4989,6 +5131,14 @@ Paragraph<point>"
(org-schedule nil "<2012-03-29 Tue>"))
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
+ (should
+ (equal "* H\nSCHEDULED: <2012-03-29>"
+ (org-test-with-temp-text "* H\nCLOSED: [2017-01-25 Wed]"
+ (let ((org-adapt-indentation 5)
+ (org-last-inserted-timestamp nil))
+ (org-schedule nil "<2012-03-29 Tue>"))
+ (replace-regexp-in-string
+ "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
;; With C-u argument, remove SCHEDULED keyword.
(should
(equal "* H\n"
@@ -5041,6 +5191,18 @@ Paragraph<point>"
(org-schedule nil "2012-03-29"))
(replace-regexp-in-string
"\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
+ (should
+ (equal "* H1\n SCHEDULED: <2012-03-29>\n* H2\n SCHEDULED:
<2012-03-29>"
+ (org-test-with-temp-text "* H1\n* H2"
+ (let ((org-adapt-indentation 5)
+ (org-last-inserted-timestamp nil)
+ (org-loop-over-headlines-in-active-region t))
+ (transient-mark-mode 1)
+ (push-mark (point) t t)
+ (goto-char (point-max))
+ (org-schedule nil "2012-03-29"))
+ (replace-regexp-in-string
+ "\\( [.A-Za-z]+\\)>" "" (buffer-string) nil nil 1))))
(should-not
(equal "* H1\nSCHEDULED: <2012-03-29>\n* H2\nSCHEDULED: <2012-03-29>"
(org-test-with-temp-text "* H1\n* H2"
@@ -5153,14 +5315,38 @@ Paragraph<point>"
(equal
":PROPERTIES:\n:TEST: t\n:END:\n"
(org-test-with-temp-text ""
- (let ((org-property-format "%s %s"))
+ (let ((org-property-format "%s %s")
+ (org-adapt-indentation 0))
+ (org-set-property "TEST" "t"))
+ (buffer-string))))
+ (should
+ (equal
+ ":PROPERTIES:\n:TEST: t\n:END:\n"
+ (org-test-with-temp-text ""
+ (let ((org-property-format "%s %s")
+ (org-adapt-indentation nil))
+ (org-set-property "TEST" "t"))
+ (buffer-string))))
+ (should
+ (equal
+ ":PROPERTIES:\n:TEST: t\n:END:\n"
+ (org-test-with-temp-text ""
+ (let ((org-property-format "%s %s")
+ (org-adapt-indentation 5))
(org-set-property "TEST" "t"))
(buffer-string))))
(should
(equal
"* H\n:PROPERTIES:\n:TEST: t\n:END:\n"
(org-test-with-temp-text "* H"
- (let ((org-adapt-indentation nil)
+ (let ((org-adapt-indentation nil) (org-property-format "%s %s"))
+ (org-set-property "TEST" "t"))
+ (buffer-string))))
+ (should
+ (equal
+ "* H\n :PROPERTIES:\n :TEST: t\n :END:\n"
+ (org-test-with-temp-text "* H"
+ (let ((org-adapt-indentation 5)
(org-property-format "%s %s"))
(org-set-property "TEST" "t"))
(buffer-string)))))
--
2.26.2