I have a code for changing a paragraph of auto filled text into a paragraph with one sentence per line, where each sentence stretches out in its full length. This code is perfect when composing and analyzing prose.

However, the code has one annoying and unintended side effect if I use it with org-mode. If my text has any starred headlines, these will collapses when I use the code. Then I loose track of where my writing point is.

The code is attached below. I am grateful for any help removing this side effect.

(defun myfun-split-para-at-sentence-ends ()
  "Split current paragraph into lines with one sentence each.
Then turn off `auto-fill-mode'."
  (let ((mode  major-mode))
         (progn (text-mode)
                  (let ((emacs-lisp-docstring-fill-column  t)
                        (fill-column                       (point-max)))
                  (let ((bop  (progn (backward-paragraph) (point)))
                        (eop  (progn (forward-paragraph)  (point))))
                    (goto-char bop)
                    (while (< (point) eop)
                      (insert "\n")))))
      (funcall mode)))
  (auto-fill-mode -1))

(define-minor-mode split-para-mode 
    "Toggle between a filled paragraph and one split into sentences."
  nil nil nil
  (if (not split-para-mode)
    (auto-fill-mode 1)
(global-set-key "\C-s" 'split-para-mode)

The problem occurs because you're restarting org-mode, and by default when it starts it will set the global state to "overview" where only the top level headlines are visible. This can be configured through the variable ‘org-startup-folded’ or on a per-file basis, as described by https://www.gnu.org/software/emacs/manual/org.html#Initial-visibility.

I'm no expert in mode writing, but perhaps it might be better to try and rework your code so that it doesn't try to change the major mode at all?

  • thanks a lot! Such a small change can make so much improvement in my daily work :) – myotis Apr 3 '17 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.