Two problems:
org-indent-mode
is a minor mode and like all minor modes is enabled by calling with a positive argument and disabled by calling it with a negative argument - see its doc string withC-h f org-indent-mode
. So you have to call it like this:(org-indent-mode -1)
to disable it.org-to-tree-indirect-buffer
leaves the current buffer unchanged, i.e. that of the original Org mode file. However, you need to turn offorg-indent-mode
not in the original buffer but in the generated indirect buffer. Fortunately, it saves that indirect buffer in the global variableorg-last-indirect-buffer
, so you can usewith-current-buffer
to temporarily switch to the indirect buffer and disableorg-indent-mode
there.
The final form of the function would then look like this (EDIT: the fontification of the buffer was lost when executing the original form of the following function, so I added an explicit
call to font-lock-fontify-buffer
to restore it, although this is probably a workaround, not the real solution. However, I still cannot reproduce the OP's problem where he loses org-indent-mode
in the original buffer) /EDIT):
(defun my-org-to-indirect-buffer ()
"Run `some-command' and `some-other-command' in sequence."
(interactive)
(org-tree-to-indirect-buffer)
;; turn off org-indent-mode in the indirect buffer
(with-current-buffer org-last-indirect-buffer (org-indent-mode -1))
;; the original buffer loses fontification for some reason, so we restore it explicitly
(font-lock-fontify-buffer))
One more problem might be the key binding: why do you bind it in the global map? Presumably you only need it in an Org mode buffer, so why not restrict it to the mode-specific keymap? Something like this:
(define-key org-mode-map (kbd "C-c f") #'my-org-to-indirect-buffer)