8

Starting with Emacs 24.4, when I type a line beginning with white space (a typical way to denote a new paragraph) and at the end of it I hit RETURN, the white space disappears. This problem appears also with 'emacs -Q'. My .emacs file uses a rather plain text-mode paragraphing scheme, namely,

(setq default-major-mode 'text-mode)
(add-hook 'text-mode-hook 'paragraph-indent-minor-mode)

which has been working without problems for a dozen years. The bug appeared when I installed the current (24.4) version.

Basically, I type:

   This is a line beginning with four spaces

and as soon as I type RETURN my line immediately becomes

This is a line beginning with four spaces

That is, the indentation vanishes. I'd much appreciate some advice. Should I post a bug?

jimmij
  • 361
  • 6
  • 12
user13049
  • 81
  • 1
  • 2
  • 2
    Absolutely `M-x report-emacs-bug`. – phils Dec 31 '14 at 13:21
  • You have correctly identified this annoyance, er, shiny new feature! I do this in my init file: `(when (fboundp 'electric-indent-mode) (electric-indent-mode -1))`. That works with any Emacs version. – Drew Dec 31 '14 at 15:38

3 Answers3

6

In Emacs 24.4, electric-indent-mode is enabled by default. It seems like that's what's causing this problem in combination with paragraph-indent-minor-mode. You can avoid that by turning off Electric Indent mode everywhere (M-x electric-indent-mode) or just in the local buffer (M-x electric-indent-local-mode).

legoscia
  • 39,593
  • 22
  • 116
  • 167
1

The following will try to keep electric-indent-mode from stepping on the toes of paragraph-indent-minor-mode. It doesn't attempt to be robust in all situations, but I suspect it's entirely sufficient in your situation.

(defvar-local my-local-electric-indent-status :unknown)

(defun my-local-electric-indent-disable ()
  "Make `electric-indent-mode' ineffective in the current buffer."
  (setq my-local-electric-indent-status electric-indent-mode)
  (electric-indent-local-mode -1))

(defun my-local-electric-indent-restore ()
  "Restore original status of `electric-indent-mode' in the current buffer."
  (unless (eq my-local-electric-indent-status :unknown)
    (electric-indent-local-mode my-local-electric-indent-status)))

(add-hook 'paragraph-indent-minor-mode-on-hook #'my-local-electric-indent-disable)
(add-hook 'paragraph-indent-minor-mode-off-hook #'my-local-electric-indent-restore)

If you're not running at least Emacs 24.3, replace the defvar-local with:

(defvar my-local-electric-indent-status :unknown)
(make-variable-buffer-local 'my-local-electric-indent-status)
phils
  • 71,335
  • 11
  • 153
  • 198
-1

;;(global-set-key "\em" 'newline) ;;for emacs 23

global-set-key "\em" 'electric-newline-and-maybe-indent) ;;for emacs 24