spacemacs
spacemacs copied to clipboard
Org-babel adds extra indentation on each edit with `o` or `O`
Description :octocat:
Org-babel adds extra indentation to code blocks unnecessarily.
Reproduction guide :beetle:
- Start Emacs
- Open an org file. Ensure that you have run (setq org-startup-indented t)
- Make a code block, e.g.
#+BEGIN_SRC python ... #+END_SRC - Write some code in that code block
- Press
oin evil mode to "open" a new line below the current one and enter insert mode - Notice that the whole code block has been indented two spaces, unnecessarily
Observed behaviour: :eyes: :broken_heart:
Code blocks auto-indent on every o or O edit operation
Expected behaviour: :heart: :smile: Code block indentation wouldn't auto-indent; indentation would stay the same inside code blocks once editing begins.
System Info :computer:
- OS: gnu/linux
- Emacs: 26.3
- Spacemacs: 0.300.0
- Spacemacs branch: develop (rev. 6f029cc05)
- Graphic display: t
- Distribution: spacemacs
- Editing style: vim
- Completion: helm
- Layers:
(ruby elm
(auto-completion :variables auto-completion-enable-snippets-in-popup t)
csv yaml shell-scripts javascript html helm nixos
(haskell :variables haskell-font-lock-symbols t haskell-completion-backend 'dante dante-command-line
'("nix-shell" "--run" "ghci"))
(keyboard-layout :variables kl-layout 'colemak-hnei)
emacs-lisp bibtex
(mu4e :variables mu4e-account-alist t)
(elfeed :variables rmh-elfeed-org-files
(list "~/Dropbox/Org/RSS.org"))
git markdown python ipython-notebook org ranger
(shell :variables shell-default-shell 'ansi-term)
(spell-checking :variables spell-checking-enable-by-default nil)
syntax-checking themes-megapack)
- System configuration features: XPM JPEG TIFF GIF PNG RSVG SOUND DBUS GSETTINGS GLIB NOTIFY LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 XDBE XIM MODULES THREADS LIBSYSTEMD
Confirmed.
This is what I'm seeing in an org-mode buffer, when pressing o on the print line:
Before
* test
#+begin_src python
print("test")
#+end_src
After
* test
#+begin_src python
print("test")
#+end_src
I'm also getting this message:
Can’t guess python-indent-offset, using defaults: 4
but it might be working as expected: https://stackoverflow.com/questions/18778894/emacs-24-3-python-cant-guess-python-indent-offset-using-defaults-4
Windows 1903
#### System Info :computer:
- OS: windows-nt
- Emacs: 26.3
- Spacemacs: 0.300.0
- Spacemacs branch: develop (rev. c9c5637ac)
- Graphic display: t
- Distribution: spacemacs
- Editing style: vim
- Completion: helm
- Layers:
```elisp
(autohotkey auto-completion command-log emacs-lisp git github helm imenu-list
(markdown :variables markdown-live-preview-engine 'vmd markdown-command "vmd")
multiple-cursors org
(shell :variables shell-default-shell 'shell shell-default-height 30 shell-default-position 'bottom)
spell-checking syntax-checking treemacs version-control)
```
- System configuration features: XPM JPEG TIFF GIF PNG RSVG SOUND NOTIFY ACL GNUTLS LIBXML2 ZLIB TOOLKIT_SCROLL_BARS THREADS LCMS2
I think org-src-preserve-indentation is the variable you want to set to not add this extra indentation. I put that in my dotspacemacs/user-config:
(setq org-src-preserve-indentation t)
In fact my personal full default settings are:
;; src block indentation / editing / syntax highlighting
(setq org-src-fontify-natively t
org-src-window-setup 'current-window ;; edit in current window
org-src-strip-leading-and-trailing-blank-lines t
org-src-preserve-indentation t ;; do not put two spaces on the left
org-src-tab-acts-natively t)
Confirmed. yogsototh's suggestion works.
There's also a variable for setting the default indentation:
(setq org-edit-src-content-indentation 0)
source: https://emacs.stackexchange.com/questions/9472/org-mode-source-block-doesnt-respect-parent-buffer-indentation
Added both duianto and yogsototh to my spacemacs user config and the issue appears fixed for me too. Upvoted both as well. I'm no emacs expert though and can't confirm whether everyone will have the same success. Thanks all
You can try to disable `evil-auto-indent' in org-mode:
(add-hook 'org-mode-hook
(lambda () (setq evil-auto-indent nil)))
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!