diff options
| author | Ihor Radchenko <yantar92@posteo.net> | 2023-10-20 13:10:30 +0300 |
|---|---|---|
| committer | Ihor Radchenko <yantar92@posteo.net> | 2023-12-05 14:11:23 +0100 |
| commit | 315417582f320c0ce37de02bf9bd81d425f3fa0b (patch) | |
| tree | 7dcec4a97b93210bbb7effe0ef16d6a673f91a27 | |
| parent | 23378177c2ead82f6bc6e05e6b1ad6d4478109e3 (diff) | |
| download | org-mode-315417582.tar.gz | |
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
| -rw-r--r-- | etc/ORG-NEWS | 34 | ||||
| -rw-r--r-- | lisp/org-macs.el | 13 | ||||
| -rw-r--r-- | lisp/org.el | 3 |
3 files changed, 47 insertions, 3 deletions
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index aef7e11..bde25ab 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 fd0f508..a8112d8 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 e522393..2030f56 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)) |
