reddit / emacs

org-mode: Suppress indentation of list items and code blocks

dotancohen · 2022-09-19 08:00
I use Emacs 27.1 with org-mode and Evil. Currently my setup has these two indentation features: 1. Headings and content are _displayed_ indented, even though there is no leading whitespace on the line. 2. When editing a code block, leading whitespace is added to the new line and sometimes the entire code block has leading whitespace added to it. I would like to keep the first feature (which I think is provided by `evil-auto-indent`). I would like to disable the second feature, which I could not figure out with much experimentation and googling. Of specific interest is the `org-indent-mode` setting, which when set to `t` seems to be the feature that provides feature 1. But what is providing feature 2? I've tried playing with `org-adapt-indentation` but I'm not sure if I should be setting it as `(setq org-adapt-indentation nil)` or possibly `(org-adapt-indentation nil)` and no matter what I do I still get that leading whitespace added to code blocks. **How do I preserve the virtual indention yet prevent the insertion of whitespace?** The relevant parts of my `~/.emacs` file are: ; Open only a single window. ; https://stackoverflow.com/questions/29915133/how-can-i-open-the-files-only-in-a-specific-window-in-emacs (setq inhibit-splash-screen t) ; Start maximized (add-to-list 'default-frame-alist '(fullscreen . maximized)) ; Vim Emulation ; https://emacs.amodernist.com/ (unless (package-installed-p 'evil) (package-refresh-contents) (package-install 'evil)) ; Proper Tab-key behaviour in org-mode ; Must be set before enabling evil ; https://stackoverflow.com/questions/22878668/emacs-org-mode-evil-mode-tab-key-not-working (setq evil-want-C-i-jump nil) ; Enable Evil (require 'evil) (evil-mode 1) ; Enable org-evil ; https://github.com/GuiltyDolphin/org-evil (require 'org-evil) ; Have _ be considered part of a word in evil ; https://emacs.stackexchange.com/questions/9583/how-to-treat-underscore-as-part-of-the-word ; https://github.com/emacs-evil/evil/issues/721 (modify-syntax-entry ?_ "w") ; esc quits pretty much anything (like pending prompts in the minibuffer) ; https://modulitos.com/blog/lightning-intro-to-emacs-using-evil-mode-and-org-mode/ (define-key evil-normal-state-map [escape] 'keyboard-quit) (define-key evil-visual-state-map [escape] 'keyboard-quit) (define-key minibuffer-local-map [escape] 'minibuffer-keyboard-quit) (define-key minibuffer-local-ns-map [escape] 'minibuffer-keyboard-quit) (define-key minibuffer-local-completion-map [escape] 'minibuffer-keyboard-quit) (define-key minibuffer-local-must-match-map [escape] 'minibuffer-keyboard-quit) (define-key minibuffer-local-isearch-map [escape] 'minibuffer-keyboard-quit) ; Ctrl-C W Toggle word wrap ; https://emacs.stackexchange.com/questions/30171/how-do-i-toggle-soft-wrapped-lines-in-org-mode (global-set-key (kbd "C-c w") 'toggle-truncate-lines) ; Run these options only in org-mode ; https://modulitos.com/blog/lightning-intro-to-emacs-using-evil-mode-and-org-mode/ (add-hook 'org-mode-hook (lambda() ; Reenable <sTAB ; https://github.com/syl20bnr/spacemacs/issues/11798 (require 'org-tempo) ; Indent org-mode files nicely ; https://modulitos.com/blog/lightning-intro-to-emacs-using-evil-mode-and-org-mode/ (local-set-key (kbd "C-c C-c") 'org-table-align) (local-set-key (kbd "C-c C-f") 'org-table-calc-current-TBLFM) (org-indent-mode t) ; Proper RTL in org-mode ; https://emacs.stackexchange.com/questions/71371/rtl-text-with-left-alignment-and-reversed-line-wrapping-in-org-mode ;(setq bidi-paragraph-direction 'right-to-left) (setq bidi-paragraph-direction nil) ; Proper wrapping! (visual-line-mode 1) ; Evil: Edit mode on new Org mode heading ; https://www.reddit.com/r/emacs/comments/uw01gz/evil_edit_mode_on_new_org_mode_heading/ ; https://emacs.stackexchange.com/questions/71637/evil-edit-mode-on-new-org-mode-heading (add-hook 'org-insert-heading-hook (apply-partially #'evil-insert 1)) ) ) (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(blink-cursor-mode nil) '(package-selected-packages '(csv-mode org-evil dash))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(default ((t (:family "Source Code Pro" :foundry "ADBO" :slant normal :weight normal :height 143 :width normal)))))
zelphirkaltstahl · 2022-09-19 10:01
(note: Source code blocks on Reddit use 4 spaces indent to appear as such. Unfortunately no tripple backticks.)
dotancohen · 2022-09-19 10:24
Though the triple backspaces displayed fine for me (Reddit website) I suppose that it might not work for those using alternative APIs. I've updated the post with indentation in lieu of the code fences. Thanks.
duien · 2022-09-19 14:52
I think the variable you need to set is `(setq org-src-preserve-indentation t)` to get rid of the extra white space that’s added inside code blocks.
dotancohen · 2022-09-20 13:06
Thank you. Setting that variable did in fact stop another very annoying feature: the reindentation of an entire Code Block when I add a new line to it. But this newly added line still has leading whitespace. I tried googling `org-src-preserve-indentation` in the hopes of finding similar variables that might suppress this leading whitespace, but found none.
thoomfish · 2022-09-20 17:09
Triple backquotes also don't work for people on old.reddit.com.
duien · 2022-09-22 21:29
I think maybe I don't understand exactly what you're trying to get rid of, then. Is the indentation you want to get rid of something that's actually inserted into the file or is it only how it's displayed? If you're able to share a screenshot that highlights the specific bit that's a problem, that would be helpful.