[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 315417582f 1/4: lisp/org.el (org-mode): Force `tab-
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 315417582f 1/4: lisp/org.el (org-mode): Force `tab-width' to be 8 |
Date: |
Tue, 5 Dec 2023 09:58:39 -0500 (EST) |
branch: externals/org
commit 315417582f320c0ce37de02bf9bd81d425f3fa0b
Author: Ihor Radchenko <yantar92@posteo.net>
Commit: Ihor Radchenko <yantar92@posteo.net>
lisp/org.el (org-mode): Force `tab-width' to be 8
* lisp/org-macs.el (org-current-text-column): Assert `tab-width' to be
8 to ensure consistency of the parser across user configurations.
* etc/ORG-NEWS (~tab-width~ value is now assumed to be 8): Document
the breaking change.
This breaking change is made to standardize Org mode format for list
items. With variable `tab-width', indentation in lists may depend on
user settings leading to inconsistent Org documents when open by
different users.
Link:
https://orgmode.org/list/2c9a6cbd-21c0-45bf-8fbb-4f7eccac4ae7@app.fastmail.com
---
etc/ORG-NEWS | 34 ++++++++++++++++++++++++++++++++++
lisp/org-macs.el | 13 ++++++++++---
lisp/org.el | 3 +++
3 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index aef7e11841..bde25abc41 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -19,6 +19,40 @@ When =FILE= does not exist, the reference is searched in the
current
file, using the verbatim reference. This way,
=:var table=tbl:example= will be searched inside the current buffer.
+*** ~tab-width~ value is now assumed to be 8
+
+Org mode now assumes tab width to be 8 characters, when calculating
+list and other indentation. ~tab-width~ is also set to 8 when Org
+major mode is loaded.
+
+This is done to improve consistency of the markup for lists, where
+indentation affects list items.
+
+Users with non-default values of ~tab-width~ should avoid overriding
+the value of 8 set by Org mode. If the custom ~tab-width~ value is
+_smaller_ than 8, the existing Org documents can be converted to the
+new standard tab width using the following helper command:
+
+#+begin_src emacs-lisp
+(defun org-compat-adjust-tab-width-in-buffer (old-width)
+ "Adjust visual indentation from `tab-width' equal OLD-WIDTH to 8."
+ (interactive "nOld `tab-width': ")
+ (cl-assert (derived-mode-p 'org-mode))
+ (unless (= old-width 8)
+ (org-with-wide-buffer
+ (goto-char (point-min))
+ (let (bound
+ (repl (if (< old-width 8)
+ (make-string old-width ?\s)
+ (concat "\t" (make-string (- old-width 8) ?\s)))))
+ (while (re-search-forward "^ *\t" nil t)
+ (skip-chars-forward " \t")
+ (setq bound (point-marker))
+ (forward-line 0)
+ (while (search-forward "\t" bound t)
+ (replace-match repl)))))))
+#+end_src
+
*** New export option ~org-export-expand-links~
The new option makes Org expand environment variables in link and INCLUDE
paths.
diff --git a/lisp/org-macs.el b/lisp/org-macs.el
index fd0f508c54..a8112d8245 100644
--- a/lisp/org-macs.el
+++ b/lisp/org-macs.el
@@ -1148,9 +1148,16 @@ Return width in pixels when PIXELS is non-nil."
(/ pixel-width symbol-width)))))))
(defmacro org-current-text-column ()
- "Like `current-column' but ignore display properties."
- `(string-width (buffer-substring-no-properties
- (line-beginning-position) (point))))
+ "Like `current-column' but ignore display properties.
+Throw an error when `tab-width' is not 8.
+
+This function forces `tab-width' value because it is used as a part of
+the parser, to ensure parser consistency when calculating list
+indentation."
+ `(progn
+ (unless (= 8 tab-width) (error "Tab width in Org files must be 8, not
%d." tab-width))
+ (string-width (buffer-substring-no-properties
+ (line-beginning-position) (point)))))
(defun org-not-nil (v)
"If V not nil, and also not the string \"nil\", then return V.
diff --git a/lisp/org.el b/lisp/org.el
index e5223934de..2030f566e9 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -4846,6 +4846,9 @@ The following commands are available:
\\{org-mode-map}"
(setq-local org-mode-loading t)
+ ;; Force tab width - indentation is significant in lists, so we need
+ ;; to make sure that it is consistent across configurations.
+ (setq-local tab-width 8)
(org-load-modules-maybe)
(when org-agenda-file-menu-enabled
(org-install-agenda-files-menu))